akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define LEN 100005
 
typedef struct{
  char name[100];
  int t;
}P;
 
P Q[LEN];
int head,tail;
 
void enqueue(P x){
  Q[tail] = x;
  tail = (tail+1) % LEN;
}
P dequeue(){
  P x = Q[head];
  head = (head+1)%LEN;
  return x;
}
int min(int a,int b){
  return a<b ? a:b;
}
 
int main(){
  int n,q;
  int time,c;
  int i;
  P que;
   
  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s%d",Q[i].name,&Q[i].t);
  }
 
  head=1;
  tail=n+1;
 
  while(head!=tail){
    que=dequeue();
    c=min(q,que.t);
    que.t -= c;
    time += c;
    if(que.t>0){
      enqueue(que);
    }else{
      printf("%s %d\n",que.name,time);
    }
  }
   
   
  return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>

using namespace std;

#define INF 1<<30
#define LINF 1ll<<60ll
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)


int main(){
    int n,k;
    cin>>n>>k;
    cout<<(n+k-3)/(k-1)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// pow mod
mint powm(ll a, ll n) {
  mint res = 1;
  mint x = a;
  while (n > 0) {
    if (n & 1) res *= x;
    x *= x;
    n >>= 1;
  }
  return res;
}


int main() {
  ll n;
  cin >> n;

  mint ans = powm(10, n) - powm(8, n) - ((powm(9, n) - powm(8, n)) * (mint)2);
  cout << ans.x << endl;
  
  return 0;
}


Measured memory_bytes: 3544
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

main :: IO ()
main = do
  [n,m,c] <- readInts
  bs <- readInts
  ds <- replicateM n readInts
  print $ length $ filter (>0) $ map (solve c bs) ds
 
solve :: Int -> [Int] -> [Int] -> Int
solve c bs ds = sum (zipWith (*) bs ds) + c

-- util
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

int pwr(int a, int b)
{
	if (b == 0) return 1;
	int c = pwr(a, b / 2);
	if (b % 2 == 1) return c * c * a;
	return c * c;
}


void solve()
{
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	double ha = 0.5 * (h * 60 + m);
	double ma = 6 * m;
	double angle = abs(ha - ma);
	angle = min(360 - angle, angle);

	angle *= (3.141592653589793238462643 / 180);


	double c = (pwr(a, 2) + pwr(b, 2));

	double x = cos(angle) * 2 * a * b;

	c -= x;
	c = sqrt(c);
	cout << fixed << setprecision(20) << c << endl;


	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 4152
#include <iostream>
#include<iomanip>
#include <cstring>
#include <stack>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;
vector<pair<double,int> > member;
const double eps=1e-9;
typedef pair<int,int> p;
double dp[3000][3000];
int main()
{
  int n,m,k;
  while(cin >> n >> m >> k && n)
    {
      double ans=0.0;
      double tmp=1.0/double(m+0.0);
      memset(dp,0,sizeof(dp));
      dp[0][0]=1.0;
      if(n==1)
	{
	  for(int i=1;i<=m;i++)
	    {
	      if(i-k<=0)
		{
		  ans+=tmp;
		}
	      else
		{
		  ans+=tmp*(i-k);
		}
	    }
	  cout << fixed << setprecision(12) << ans << endl;
	}
      else
	{
	  for(int i=1;i<=n;i++)
	    {
	      for(int j=1;j<=m;j++)
		{
		  for(int k=0;k<=i*m;k++)
		    {
		      dp[i][k+j]+=dp[i-1][k]*tmp;
		    }
		}
	    }
	  for(int i=n;i<=m*n;i++)
	    {
	      if(i-k<=0)
		{
		  ans+=dp[n][i];
		}
	      else
		{
		  ans+=dp[n][i]*(i-k);
		}
	    }
	  cout << fixed << setprecision(12) << ans << endl;
	}
    }
  return 0;
}
      



Measured memory_bytes: 73576
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}

int main(){
    int n; cin >> n;
    vector<int> check(0);
    int ans = 1;
    int tmp = n;
    cout << n << ":";
    for(int i = 2; i*i <= tmp; i++){

        while (n % i == 0){
            cout << " " << i;
            n /= i;
        }
    }
    if (n != 1) cout << " " << n;
    cout << endl;
}
  




Measured memory_bytes: 3104
n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))

count = 0
for i in range(n):
    diff = a[i] - b[i]
    if diff >= 0:
        count += b[i]
    else:
        count += a[i]
        _diff = a[i+1] + diff
        if _diff >= 0:
            count += abs(diff)
            a[i+1] = _diff
        else:
            count += a[i+1]
            a[i+1] = 0
print(count)

Measured memory_bytes: 19156
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define nl "\n"
#define fout(x) fixed<<setprecision(x)
#define one(x) __builtin_popcountll(x)
#define F first
#define S second
#define or_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(), order_of_key()
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << fout(10)<<x;}
void __print(double x) {cerr << fout(10)<<x;}
void __print(long double x) {cerr << fout(10)<<x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int mod=1e9+7;
const double eps=1e-9;
const double PI=acos(-1.0);
 
//ll qpow(ll n,ll k){ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1)ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

// ****************************************************


ll arr[300005];

int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++) scanf("%lld", &arr[i]);
	ll ans=0;
	for(int k=0; k<=60; k++){
		int one=0, zero=0;
		for(int i=0; i<n; i++){
			if(arr[i] & (1ll<<k)) one++;
			else zero++;
		}
		ll t1=(one*1ll*zero)%mod;
		ll t2=(1ll<<k)%mod;
		ans=(ans+((t1*t2)%mod))%mod;
		// ans=(ans+((one*1ll*zero)%mod*(1ll<<k)%mod)%mod)%mod;
	}
	printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>

#pragma GCC optimize(2)

#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

int gi() {
	int f = 1, x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + ch - '0';
		ch = getchar();
	}
	return f * x;
}

int h, w;
int main() {
	h = gi(), w = gi();
	int n = gi();
	
	cout << n / (max(h, w)) + (n % max(h, w) != 0) << endl; 

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int i;
	int N=read();
	int ans=0;
	int a[100010]={0},b[100010]={0};
	int sum[N+3]={0};
	
	sum[0] = 1; //include me
	
	REP(i,N){
		a[read()] ++;
		b[read()+1] --;
	}
	
	for(i=1;i<=N+1;i++){
		sum[i] += sum[i-1] + a[i] + b[i];
		//cout << sum[i] << endl;
	}
	
	for(i=1;i<=N+1;i++){
		if(sum[i]>=i){
			ans = i-1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5488
n = int(input())
s = [input() for _ in range(n)]

for i in range(n):
    s[i] = [s[i][j] for j in range(len(s[i]))]
    s[i].sort()
    s[i] = ''.join(s[i])

s.sort()
s.append("x")
ans = 0
x = 0
y = "x"
for i in range(len(s)):
    if s[i] == y:
        x += 1
    else:
        ans += x * (x-1) // 2
        y = s[i]
        x = 1

print(ans)


Measured memory_bytes: 10584
#include <iostream>

int main(){
  std::string pre, actual;
  std::cin >> pre;
  std::cin >> actual;
  int count = 0;
  for(int i=0; i<3; i++){
    if(pre[i] == actual[i]){
      count ++;
    }
  }
  std::cout << count << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

bool palindrome(string s)
{
    string r = s;

    reverse(r.begin(), r.end());

    return r == s;
}

int main()
{
    string s;

    cin >> s;

    int n = s.length();

    bool ans = false;
    
    if (palindrome(s))
    {
        string t = s.substr(0, (n-1)/2);
        string u = s.substr(((n+3)/2)-1, n);

        if (palindrome(t) && palindrome(u))
            ans = true;
    }

    if (ans)
        cout << "Yes";
    else
        cout << "No";

    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi acos(-1)
int main(){
    int n,m;
    cin>>n>>m;
    int a[m],sum=0;
    for(int i=0;i<m;i++) cin>>a[i],sum+=a[i];
    if(sum>n) puts("-1");
    else cout<<n-sum;
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int P = 1e9 + 7;
int Pow(int a,int t){
    int r=1;for(;t;t>>=1,a=1ll*a*a%P)if(t&1)r=1ll*r*a%P;
    return r;
}
void pp(int &a,int b){
    a += b;
    if(a >= P) a -= P;
}
int n , K;

int main(){
    cin >> n >> K;
    int ans = 0;
    if(n == -1){
        ans = 1ll * Pow(K , n/2+1) * n % P;
        pp(ans , P - 1ll * K * (n - 1) % P);
    } else {
        int x = n / 2;
        set<int> S;
        map<int,int> Mp;
        for(int i=1;i*i<=n;++i) if(n % i == 0) S.insert(i) , S.insert(n / i);
        for(auto e : S){
            int t = 0;
            if(n % 2 == 0 && x % e == 0) t = Pow(K , e);
            else t = Pow(K , (e + 1) / 2);
            for(auto f : Mp) if(e % f.fi == 0) pp(t , P - f.se);
            pp(ans , 1ll * t * e % P);
            Mp[e] = t;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

bool prime[1000001];

int main() {
	for(int i=2; i*i<=1000000; i++) {
		if(!prime[i]) {
			for(int j=i+i; j<=1000000; j+=i) {
				prime[j] = true;
			}
		}
	}
	prime[0] = prime[1] = true;
	int a, d, n;
	while(cin >> a >> d >> n, a||d||n) {
		int cnt = 0;
		while(cnt<n) {
			if(!prime[a]) cnt++;
			if(n==cnt) break;
			a += d;
		}
		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, W;
    cin >> n >> W;
    int w[n];
    long long int v[n];
    for(int i = 0; i<n; i++)
        cin >> w[i] >> v[i];

    long long int knap[W+1];
    int flag[W+1][n];

    knap[0] = 0;
     for(int j = 0; j<n; j++)
        flag[0][j] = 0;
    
    for(int i = 1; i<=W;i++){
        knap[i] = 0;
        int max = -1;
        for(int j = 0; j<n; j++)
            flag[i][j] = 0;
        for(int j = 0; j<n; j++){
            if(i-w[j] >= 0 && !flag[i-w[j]][j] )
                if(knap[i] < knap[i-w[j]] + v[j]){
                    max = j;
                    knap[i] =  knap[i-w[j]] + v[j];
                }
        }
        if(max != -1){
            for(int j = 0; j<n; j++)
                flag[i][j] = flag[i-w[max]][j];
            flag[i][max] = 1;
        }
    }
    // cout <<endl;

    // for(int i = 0; i<W+1;i++){
    //     for(int j = 0; j<n;j++)
    //         cout << flag[i][j]<< " ";
    //     cout << endl;
    // }
    // cout << endl;
    // for(int i = 0; i<W;i++)
    //         cout << knap[i] << endl;

    // cout <<endl;
    long long int mx=0;
    for(int i = 0; i<=W ;i++)
        mx = max(knap[i], mx);
    cout << mx << endl;
    return 0;

}

Measured memory_bytes: 40064
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	char z[8][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
	char t[4];
	while(~scanf("%s",t))
	{
		int ans=7;
  		for(int i=0;i<7;i++)
		{
			ans-=1;
			if(strcmp(t,z[i])==0)
			break;
		}
		if(ans!=0)
		cout<<ans<<endl;
		else
		cout<<7<<endl;
	}
}

Measured memory_bytes: 760
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  long long int now,ans=1,i,n,x,h;
  pair<long long int,long long int> p[100010];
  scanf("%lld\n",&n);
  for(i=0;i<n;i++){
    scanf("%lld %lld\n",&x,&h);
    p[i].second=x-h;
    p[i].first=x+h;
  }
  sort(p,p+n);
  now=p[0].first;
  for(i=0;i<n;i++){
    if(p[i].second>=now){
      now=p[i].first;
      ans++;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <functional>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-10;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(true) {
        int n; cin >> n;
        vector<int> a(n);
        if(n == 0) break;
        REP(i,n) cin >> a[i];

        int ans = -1e9;
        REP(i,n) {
            int sum = 0;
            rep(j,i,n) {
                sum += a[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 3140
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let mut a = read![[i64]];

    // 操作列
    let mut ops = vec![];

    // 絶対値が最大の要素を探す。
    let z = (0..N).max_by_key(|&i| a[i].abs()).unwrap();

    // 最大の絶対値を他の要素に加算することで、「すべて0以上」または「すべて0以下」にする。
    for i in 0..N {
        if i != z {
            ops.push((z, i));
            a[i] += a[z];
        }
    }

    // 累積和を取る。
    if a[0] >= 0 {
        for i in 0..N - 1 {
            ops.push((i, i + 1));
            a[i + 1] += a[i];
            debug_assert!(a[i] <= a[i + 1]);
        }
    } else {
        for i in (1..N).rev() {
            ops.push((i, i - 1));
            a[i - 1] += a[i];
            debug_assert!(a[i - 1] <= a[i]);
        }
    }

    println!("{}", ops.len());
    for (x, y) in ops {
        println!("{} {}", x + 1, y + 1);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
long double distance(pair<int, int> p1, pair<int, int> p2)
{
    long double a = (p1.first - p2.first) * (p1.first - p2.first);
    long double b = (p1.second - p2.second) * (p1.second - p2.second);
    return sqrtl(a + b);
}

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> li;
    long double result = 0;

    for (int i = 0; i < n; i++) {
        pair<int, int> item;
        cin >> item.first >> item.second;
        li.push_back(item);
    }

    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (i == j) {
                continue;
            }
            result += distance(li[i], li[j]);
        }
    }

    cout << setprecision(10) << std::fixed << result * (long double)2.0 / (long double)n;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;

int main(){
 int m,r,f;

 while(1){
  cin >> m >> r >>f;
 
  if(m == -1 && r == -1 && f == -1){
   break;
  } else if(m == -1 || r == -1){
   cout << "F" << endl;
  } else if(m + r >= 80 ){
   cout << "A" << endl;
  } else if(m + r >= 65){
   cout << "B" << endl;
  } else if((m + r >= 50) || ((m + r >= 30)&&(f >= 50)) ){
   cout << "C" << endl;
  } else if(m + r >= 30){
   cout << "D" << endl;
  }else{
   cout << "F" << endl;
  }
 }

 return 0;
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-

text = list(input())
txt_stuck = []

for i in text:
    if i == 'S':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck == []:
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'T':
        txt_stuck.append(i)
    elif i == 'T' and txt_stuck[-1] == 'S':
        txt_stuck.pop()

print(len(txt_stuck))

Measured memory_bytes: 6436
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            string[] str = s.Split(' ');
            string[] strB = s.Split(' '), strS = s.Split(' ');


            BubbleSort(strB,n);
            isStable(str, strB, n);

            SelectionSort(strS,n);
            isStable(str, strS, n);

        }

        static void BubbleSort(string [] str, int n)
        {
            int p1 = 0, p2 = 0;

            for (int i = 0; i < n; i++)
            {
                p1 = p2;
                for (int j = n - 1; j > p1; j--)
                    if (int.Parse(str[j - 1][1].ToString()) > int.Parse(str[j][1].ToString())) { string tmp = str[j]; str[j] = str[j - 1]; str[j - 1] = tmp; p2 = j; }
                if (p1 == p2) break;
            }

            Console.WriteLine(string.Join(" ", str));
        }
         static void SelectionSort(string[] str, int n)
        {
            for (int i = 0; i < n; i++)
            {
                int mini = i;
                for (int j = i + 1; j < n; j++)
                    if (int.Parse(str[j][1].ToString()) < int.Parse(str[mini][1].ToString())) mini = j;
                if (i != mini) { string tmp = str[i]; str[i] = str[mini]; str[mini] = tmp; }
            }
            Console.WriteLine(string.Join(" ", str));
        }

        static void isStable(string [] x, string [] y, int n)
        {
            bool stable = true;

            for(int i=0;i<n-1;i++)
            {
                if (y[i][1] == y[i + 1][1])
                {
                    int indexA = Array.IndexOf(x, y[i]);
                    int indexB = Array.IndexOf(x, y[i + 1]);
                    if (indexA > indexB) { stable = false; break; }
                }
            }
            Console.WriteLine(stable?"Stable":"Not stable");
        }
    }
}

Measured memory_bytes: 8900
#include <iostream>
#include <cstdio>
#include <cmath>

int main()
{
	int n; std::cin >> n;
	for (int i=0; i<n; i++) {
		int h, m;
		scanf("%d:%d", &h, &m);
		float dh = 30.0 * (float)h + 0.5 * (float)m;
		float dm = 6.0 * (float)m;
		float d = std::abs(dm - dh);
		if ((0.0 <= d && d < 30.0) || (330.0 < d && d <= 360.0)) std::cout << "alert" << std::endl;
		else if ((30.0 <= d && d < 90.0) || (270.0 < d && d <= 330.0)) std::cout << "warning" << std::endl;
		else std::cout << "safe" << std::endl;
	}
	
	return 0;
}




Measured memory_bytes: 3116
from collections import deque

N,Q=map(int,input().split())
to=[[] for _ in range(N)]
count=[0]*N
for _ in range(N-1):
    a,b=map(int, input().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
for _ in range(Q):
    p,x=map(int, input().split())
    count[p-1]+=x
q = deque()
q.append(0)
p=[True]*N
while q:
    i = q.pop()
    if p[i]:
        p[i]=False
        for j in to[i]:
            if p[j]:
                count[j]+=count[i]
                q.append(j)
print(*count)



Measured memory_bytes: 105364
#import<cstdio>
#define r(a)for(int i=0;i<a;i++)
#define s(n)scanf("%d",&n);
#define c(a,b)a=a<b?a:b
int w,n,m,d[999],p[999];main(){s(n)s(m)r(n)s(d[i])r(n)p[i]=1e9;r(m){s(w)r(n)c(p[i],p[i+1]+w*d[n-i-1]);}printf("%d\n",*p);}

Measured memory_bytes: 1032
A,B=map(int,input().split())
res=[]
for n in range(1,1251):
    a=n*0.08; b=n*0.1
    if (A<=a<A+1)&(B<=b<B+1):
        res.append(n)
print(-1 if len(res)==0 else min(res))

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp21 {
    class Program {
        static void Main(string[] args) {
            string s = Console.ReadLine();
            int A = int.Parse(s.Split(' ')[0]);
            int B = int.Parse(s.Split(' ')[1]);
            

            if ((A + B) % 2 == 0) {
                Console.WriteLine((A + B) / 2);
            } else {
                Console.WriteLine("IMPOSSIBLE");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k;
    cin>>n>>k;
    ll res=0;
    rep(i,n){
        ll a;
        cin>>a;
        if(a>=k)res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3648
import sys

def gcd(a,b):
	while a%b :
		a,b=b,a%b
	return b
	
def lcm(a,b) :
	return a*b/gcd(a,b)
	
for ab in sys.stdin:
	a,b = map(int,ab.split())
	a,b = max(a,b),min(a,b)
	print "%d" % gcd(a,b),
	print "%d" % lcm(a,b)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  char x, y;
  cin >> x >> y;
  if (x < y) cout << "<" << endl;
  else if (x == y) cout << "=" << endl;
  else cout << ">" << endl;
}

Measured memory_bytes: 256
while True:
    try:
        a, b, c, d, e, f = map(int, input().strip("\n").split(" "))
        z = a * e - b * d
        if z == 0:
            break
        x = (c * e - b * f)
        y = (f * a - c * d)
        x /= z
        y /= z
        # zero toshite atsukau
        if -0.0004 < x < 0.0004:
            x = abs(x)
        if -0.0004 < y < 0.0004:
            y = abs(y)
        print("{0:.3f} {1:.3f}".format(x, y))

    except EOFError:
        break  # escape from while loop

Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int t = n, s = t % 10;
    while (t / 10) {
        t /= 10;
        s += t % 10;
    }
    if (n % s == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int N;
vector<int> A(200001);

void solve(){
    map<int, ll> mp;
    for(int i = 1; i <= N; ++i){
        mp[A[i]]++;
    }
    ll sum = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        sum += itr->second * (itr->second - 1) / 2;
    }
    for(int i = 1; i <= N; ++i){
        cout << sum - max(0LL, mp[A[i]] - 1) << endl;
    }
}
int main(){
    cin >> N;
    for(int i = 1; i <= N; ++i){
        cin >> A[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 10240
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int n, k, ans, l[50];

int main() {
    cin >> n >> k;
    rep(i, n) cin >> l[i];
    
    sort(l, l + n, greater<int>());
    rep(i, k) ans += l[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
if s[-1] == "1":
  print(-1)
  exit()
s = s[:-1]
if s != s[::-1] or s[0] == "0":
  print(-1)
  exit()
s += "1"
n = len(s)
now = 1
for i, t in enumerate(s, 1):
  if t == "1":
    for j in range(now, i):
      print(j, i)
      now = i

Measured memory_bytes: 9208
n,m = map(int,input().split())
ans = [1, n]
for i in range(m):
    l,r = map(int,input().split())
    if r < ans[0] or ans[1] < l:
        print(0)
        exit()
    elif ans[0] <= l and r <= ans[1]:
        ans = [l,r]
    else:
        ans = [max(ans[0], l), min(ans[1], r)]
print(ans[1]-ans[0] + 1)




Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

ll N,K;
int p[maxn],c[maxn];
ll sc[maxn];
int fa[maxn],sz[maxn];
bool vis[maxn];
int id = 0;

void dfs(int x){
	fa[x] = id;
	sz[id] += 1;
	sc[id] += c[x];
	vis[x] = 1;
	int nx = p[x];
	if(!vis[nx]){
		dfs(nx);
	}
}
void solve(){
	for(int i = 1;i<=N;i++){
		if(!vis[i]){
			id++;
			dfs(i);
		}
	}
	ll ans = -2e18;
	for(int i = 1;i<=N;i++){
		int id = fa[i];
		ll cur = 0;
		ll k = K;
		if(k > sz[id]){
			if(sc[id] > 0){
				cur += (k/sz[id]-1) * sc[id];
			}
			k = k%sz[id] + sz[id];
		}
		for(int j = 1,nx = p[i];j<=k;j++,nx = p[nx]){
			cur += c[nx];
			ans = max(ans,cur);
		}
		
	}
	cout<<ans<<'\n';
}
int main(){
	// debug;
	ios;

	cin>>N>>K;
	for(int i = 1;i<=N;i++) cin>>p[i];
	for(int i = 1;i<=N;i++) cin>>c[i];
	solve();
	
	return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
 
long rec(long n) {
	if(n == 1) return 1;
	else return 2 * rec(n / 2) + 1;
}
 
int main(void) {
	long h;
	scanf("%ld", &h);
	printf("%ld\n", rec(h));
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;

int main(){
  string r, g, b;
  cin >> r >> g >> b;
  string A=r+g+b;
  int Ans=stoi(A);
  if(Ans%4==0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  string s;
  i64 k, n;
  cin >> s >> k;
  n = s.size();

  for (i64 i = 0; i < n; ++i) {
    i64 c = s[i], d = (1 + 'z' - c) % 26;
    if (k >= d) {
      s[i] = 'a';
      k -= d;
    }
  }
  
  s[n - 1] = (s[n - 1] - 'a' + k) % 26 + 'a';

  cout << s << '\n';
  return 0;
}


Measured memory_bytes: 512
input_a = input()
if input_a[0] != 'A':
    print("WA")
elif input_a.count('C')==0:
    print("WA")
elif input_a.count('C')>1:
    print("WA")
elif input_a.index('C') <=1:
    print("WA")
elif input_a.index('C') ==len(input_a)-1:
    print('WA')
elif input_a.count('C') ==1:
    if input_a.replace('A','a').replace('C','c').islower():
        print('AC')
    else:
        print('WA')

Measured memory_bytes: 3060
#![allow(non_snake_case)]

fn main() {
    // let s = std::io::stdin();
    // let mut sc = Scanner { stdin: s.lock() };
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let D:usize = sc.read();
    let C:Vec<i64> = sc.vec(26);
    let S: Vec<Vec<i64>> = (0..D).map(|_| sc.vec(26)).collect();
    let mut past: Vec<i64> = (0..26).map(|_| -1).collect();
    let mut ANS:Vec<usize> = Vec::new();
    let mut point:i64 = 0;
    for i in 0..D{
        let mut m:i64 = -1000000000;
        let mut ind:usize = 0;
        for j in 0..26{
            let mut temp_point:i64 = point+S[i][j];
            for k in 0..26{
                temp_point -= C[k]*((i as i64)-past[k]);
            }
            if m < temp_point{
                ind = j;
                m = temp_point;
            }
        }
        ANS.push(ind);
        point = m;
        past[ind] = i as i64;
    }

    for i in 0..D{
        println!("{}", ANS[i]+1);
    }
    // for i in 0..D{
    //     ans += S[i][T[i]-1];
    //     past[T[i]-1] = i as i64;
    //     for j in 0..26{
    //         ans -= C[j]*((i as i64)-past[j]);
    //     }
    //     println!("{}", ans);
    // }
}

struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);


impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
}





Measured memory_bytes: 2256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}



int main() {
	long double a, b;
	cin >> a >> b;
	long double ans = a * b;
	cout << (ll)ans << endl;
	return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <vector>
#define INF 1e9+7
using namespace std;
typedef long long int ll;

int main() {

	int a[100];
	int N = 0, ans = 0;
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < N-1; i++) {
		if (a[i] == a[i + 1]) { ans += 1; a[i + 1] = 0; }
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
mini=[]

for i in range(max(a)-min(a)+1):
    mini.append(int(0))
    for j in range(n):
        mini[i]=mini[i]+(i+min(a)-a[j])**2
        if min(mini)<mini[i]:
            break

print(min(mini))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define sc scanf
#define pr printf
using namespace std;
typedef long long ll;
const int N = 100000+100;
bool ans[N];
char str[N];
bool hander_ans(int n);
bool is_right(int n);
int main()
{
    int i,j,n;
    while(~sc("%d",&n))
    {
        sc(" %s",str);

        ans[0] = 0 , ans[1] = 0;
        if(hander_ans(n)) continue;

        ans[0] = 0 , ans[1] = 1;
        if(hander_ans(n)) continue;

        ans[0] = 1 , ans[1] = 0;
        if(hander_ans(n)) continue;

        ans[0] = 1 , ans[1] = 1;
        if(hander_ans(n)) continue;

        pr("-1\n");
    }
    return 0;
}
bool hander_ans(int n)
{
    int i,j;
    for(i=2; i<n; i++)
    {
        if(ans[i-1] == 0)
        {
            if(str[i-1] == 'o')
                ans[i] = ans[i-2];
            else
                ans[i] = !ans[i-2];
        }
        else
        {
            if(str[i-1] == 'o')
                ans[i] = !ans[i-2];
            else
                ans[i] = ans[i-2];
        }
    }
    int flag = 0;
    if(ans[n-1] == 0)
    {
        if(str[n-1] == 'o' && ans[0] == ans[n-2]) flag = 1;
        if(str[n-1] == 'x' && ans[0] != ans[n-2]) flag = 1;
    }
    else
    {
        if(str[n-1] == 'o' && ans[0] != ans[n-2]) flag = 1;
        if(str[n-1] == 'x' && ans[0] == ans[n-2]) flag = 1;
    }

    if(ans[0] == 0)
    {
        if(str[0] == 'o' && ans[1] == ans[n-1]) flag += 1;
        if(str[0] == 'x' && ans[1] != ans[n-1]) flag += 1;
    }
    else
    {
        if(str[0] == 'o' && ans[1] != ans[n-1]) flag += 1;
        if(str[0] == 'x' && ans[1] == ans[n-1]) flag += 1;
    }
    if(flag == 2)
    {
        for(i=0; i<n; i++)
          if(ans[i]) pr("W");
          else pr("S");
         pr("\n");
         return 1;
    }
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] ar = new int[n];
		for (int i=0;i<n;i++) {
			ar[i] = s.nextInt();
		}
		System.out.println(lcm(ar));
	}
	public static int gcd(int x, int y) {if (y==0) {return x;}return gcd(y,x%y);}
	public static int lcm(int... x) {
		int tmp=x[0];
		for (int i=1;i<x.length;i++) {
			int gcd = gcd(tmp,x[i]);
			tmp = tmp*x[i]/gcd;
		}
		return tmp;
	}

}

Measured memory_bytes: 26416
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct UnionFind {
  vector<int> par;

  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for (int i = 0; i < N; i++)
    cin >> P[i];

  UnionFind tree(N);

  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    tree.unite(x - 1, y - 1);
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (tree.same(i, P[i] - 1)) cnt++;
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  ll g[2],s[2],d[2];
  cin>>g[0]>>s[0]>>d[0];
  cin>>g[1]>>s[1]>>d[1];
  ll M = N;
  for(ll x=0;g[0]*x<=N;x++){
    for(ll y=0;g[0]*x+s[0]*y<=N;y++){
      ll z=0;
      if(d[1]-d[0]>0){
        z=(N-(g[0]*x+s[0]*y))/d[0];
      }
      M = max(M,(g[1]-g[0])*x+(s[1]-s[0])*y+(d[1]-d[0])*z+N);
      //debug(ans);
    }
  }
  ll ans=M;
  if(d[0]-d[1]<=0){
    for(ll x=0;g[1]*x<=M;x++){
      ll y=0;
      if(s[0]-s[1]>0){
        y=(M-g[1]*x)/s[1];
      }
      ans = max(ans,(g[0]-g[1])*x+(s[0]-s[1])*y+M);
    }
  }else if(g[0]-g[1]<=0){
    for(ll x=0;s[1]*x<=M;x++){
      ll y=0;
      if(d[0]-d[1]>0){
        y=(M-s[1]*x)/d[1];
      }
      ans = max(ans,(s[0]-s[1])*x+(d[0]-d[1])*y+M);
    }
  }else if(s[0]-s[1]<=0){
    for(ll x=0;d[1]*x<=M;x++){
      ll y=0;
      if(g[0]-g[1]>0){
        y=(M-d[1]*x)/g[1];
      }
      ans = max(ans,(d[0]-d[1])*x+(g[0]-g[1])*y+M);
    }
  }else{
    for(ll x=0;d[1]*x<=M;x++){
      for(ll y=0;d[1]*x+g[1]*y<=M;y++){
        ll z=0;
        if(s[0]-s[1]>0){
          z=(M-(d[1]*x+g[1]*y))/s[1];
        }
        ans = max(ans,(d[0]-d[1])*x+(g[0]-g[1])*y+(s[0]-s[1])*z+M);
        //debug(ans);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int n,m,f,i,a,b,x[200000],y[2000000];
int main()
{
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		if(a==1)x[b]=1;
		if(b==n)y[a]=1;
	}
	f=0;
	for(i=1;i<=n+1;i++){
		//printf("%d %d\n",x[i],y[i]);
		if((x[i]==1)&&(y[i]==1)){
			f=1;
			puts("POSSIBLE");
			break;
		}
	}
	
	if(f==0){
		puts("IMPOSSIBLE");
	}
	
	return 0;
}

Measured memory_bytes: 3456
import itertools

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

v = (a, b, c, d, e)
if all(abs(v1 - v2) <= k for v1, v2 in itertools.product(v, repeat=2)):
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define M_PI       3.14159265358979323846
#define Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define 	pb	push_back 
#define 	ff	first 
#define 	ss	second 
#define sz(x) (int)x.size()
#warning Remeber to change t
using namespace std;
typedef long long ll;
inline void setIO(string name="") {
	#ifndef ONLINE_JUDGE 
	freopen((name+".in").c_str(), "r", stdin); 
	freopen((name+".out").c_str(), "w", stdout);
	#endif
	}

int main(){
	Speed_UP
	ll ti;
	ti=1;
	while(ti--){
    string s,t;
    cin>>s>>t;
    ll n=sz(t);
    ll ans=sz(t);
    for(int i=0;i<=(sz(s)-n);i++){
      ll c=0;
      //cout<<s[i]<<"\n";
      for(int j=i;j<=i+n-1;j++){
        //cout<<s[j-i];
        if(s[j]!=t[j-i])
          c++;
      }
      ans=min(ans,c);
    }
    cout<<ans;
		
		
		
	}





}


Measured memory_bytes: 3652
#include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

const ll M=1000000007;
const int dx[]={2,1,-1,-2,-2,-1,1,2},dy[]={-1,-2,-2,-1,1,2,2,1};

int h,w,B[50][16];

int cnt[50][16]; // 攻撃されうる回数

ll dfs(int i,int j,int parity){
	if(i==h) return 1;
	if(j==w) return dfs(i+1,0,parity);

	if((i+j)%2!=parity) return dfs(i,j+1,parity); // 黒マス or 白マスのみ見る

	// マス (i, j) での値を mod 3 で 0 にできなければ探索打ち切り ( (i, j) を攻撃するマスがないかもしれないので必要 )
	if(cnt[i][j]==0 && B[i][j]%3!=0
	|| cnt[i][j]==1 && B[i][j]%3==1) return 0;

	ll res=0;
	// マス (i, j) にナイトを置かない
	rep(k,8){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w) cnt[y][x]--;
	}
	bool ok=true;
	rep(k,8){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w){
			if(cnt[y][x]==0 && B[y][x]%3!=0
			|| cnt[y][x]==1 && B[y][x]%3==1) ok=false;
		}
	}
	if(ok) res+=dfs(i,j+1,parity);

	// マス (i, j) にナイトを置く
	rep(k,8){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w) B[y][x]++;
	}
	ok=true;
	rep(k,8){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w){
			if(cnt[y][x]==0 && B[y][x]%3!=0
			|| cnt[y][x]==1 && B[y][x]%3==1) ok=false;
		}
	}
	if(ok) res+=dfs(i,j+1,parity);

	rep(k,8){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w) cnt[y][x]++, B[y][x]--;
	}

	return res;
}

int main(){
	scanf("%d%d",&h,&w);
	rep(i,h) rep(j,w) scanf("%d",B[i]+j);

	rep(i,h) rep(j,w) rep(k,8) {
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w) cnt[y][x]++;
	}

	ll ans;
	if(h==1 || w==1){ // コーナーケース
		bool ok=true;
		rep(i,h) rep(j,w) if(B[i][j]!=0) ok=false;
		if(ok){
			ans=1;
			rep(i,h*w) ans=2*ans%M;
		}
		else ans=0;
	}
	else{
		ans=dfs(0,0,0)*dfs(0,1,1)%M;
	}
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
const int inf=1e9;
int main()
{
    int n,k,s;
    scanf("%d%d%d",&n,&k,&s);
    for(int i=0;i<k;i++)
        printf("%d%c",s,i==n-1?'\n':' ');
    if(s!=inf) s=inf;
    else s=1;
    for(int i=k;i<n;i++)
        printf("%d ",s,i==n-1?'\n':' ');
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define INF (1 << 30)
#define MAX (1 << 20)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    char a;

    cin >> a;

    cout << (char)(a + 1) << endl;

    return 0;
}

Measured memory_bytes: 256