akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <sstream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

int n;
int x[55],y[55],xx[55],yy[55];

ll mask[111][111];
int col[111][111];
typedef pair<int,int> P;

inline bool valid(int x, int y){
    return 0 <= x && x < 111 && 0 <= y && y < 111;
}

int solve(){
    vi xs, ys;
    rep(i,n){
        xs.push_back(x[i]);
        xs.push_back(xx[i]);
        ys.push_back(y[i]);
        ys.push_back(yy[i]);
    }
    xs.push_back(-1);
    ys.push_back(-1);
    sort(all(xs));
    sort(all(ys));
    xs.erase(unique(all(xs)), xs.end());
    ys.erase(unique(all(ys)), ys.end());

    memset(mask,0,sizeof(mask));
    rep(i,n){
        int x1=lower_bound(all(xs), x[i])-xs.begin();
        int x2=lower_bound(all(xs), xx[i])-xs.begin();
        int y1=lower_bound(all(ys), y[i])-ys.begin();
        int y2=lower_bound(all(ys), yy[i])-ys.begin();
        // printf("%d %d ", x1,x2);
        // printf("%d %d\n", y1,y2);
        loop(x,x1,x2){
            loop(y,y2,y1){
                mask[y][x]|=1LL<<i;
            }
        }
    }

    int cnt = 0;
    memset(col,0,sizeof(col));
    int dx[]={0,0,1,-1};
    int dy[]={1,-1,0,0};
    rep(i,111)rep(j,111)if(col[i][j]==0){
        cnt++;
        stack<P> s; s.push(P(j,i));
        while(s.size()){
            int x,y;
            tie(x,y) = s.top(); s.pop();
            if(col[y][x]) continue;
            col[y][x] = cnt;
            rep(d,4){
                int nx,ny;
                tie(nx,ny) = P(x+dx[d], y+dy[d]);
                if(!valid(nx,ny)) continue;
                if(mask[y][x]!=mask[ny][nx]) continue;
                if(col[ny][nx]) continue;
                s.push(P(nx,ny));
            }
        }
        // for(int i=ys.size();i>=0;i--){
        //     rep(j,xs.size()+1){
        //         cout << col[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        // puts("-");
    }
    return cnt;
}

int main(){
    int cnt = 0;
    while(cin>>n && n){
        cnt++;
        rep(i,n)cin>>x[i]>>y[i]>>xx[i]>>yy[i];
        if(cnt==18){
            auto fp = fopen("badcase.txt","w");
            fprintf(fp,"%d\n",n);
            rep(i,n){
                fprintf(fp,"%d %d %d %d\n", x[i],y[i],xx[i],yy[i]);
            }
        }
        cout << solve() << endl;
    }
}

Measured memory_bytes: 1508
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;
  map<string, int> memo;
  rep(i,N){
    string S;
    cin >> S;
    memo[S] ++;
  }
  int mx = 0;
  for (auto p : memo) mx = max(mx, p.second);  //最大値をmxに入れる
  for (auto p : memo){
    if (p.second != mx) continue;
    cout << p.first << endl;
  }
  return 0;
}


Measured memory_bytes: 19220
N = int(input())
A = [0] * N
B = [0] * N
c = 0

for i in range(N):
  A[i] = int(input()) - 1

k = 0
while B[k] == 0 and k != 1:
  B[k] = 1
  k = A[k]
  c += 1

if k == 1:
  print(c)
else:
  print(-1)

Measured memory_bytes: 44888
#include<bits/stdc++.h>
using namespace std;
int main(){
int X; int Y;
  cin>>X>>Y;
  int K=0;
  if(Y%2!=0)
    K++;
  if(Y>4*X||Y<2*X)
    K++;
  if(K==0)
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3600
import collections

N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
    l = []
    l.append(A[i])
    l.append(B[i])
    l.append(C[i])
    c = collections.Counter(l)
    c_len = len(c)
    if c_len == 2:
        ans += 1
    elif c_len == 3:
        ans += 2

print(ans)


Measured memory_bytes: 3572
//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                     unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795

using namespace std;

void INPUT() 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/*
    
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible 
*/





void solve()
{ 
        ll n;
        cin >> n;
        
        vll v(n);
        
        fo(i,0,n-1) cin >> v[i];

        sort(all(v),greater<ll>());

        ll ans = 0LL;

        ans += v[0];

        ll left = n-2, val;
        int id;

        fo(i,1,n-1)
        {
          if(left == 0) break;
          
          if(left>=2LL)
          {
            val = v[i]+v[i];
            ans += val;
            left--;
            left--;
          }
          else
          {
            ans += v[i];
            break;
          } 


     }
     
        cout << ans << endl;
       
}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
    //cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 4776
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		// スペース区切りの整数の入力
		for(int i=1;i<=a;i++){
			list.add(sc.nextInt());
		}

		int count =0;
		for(int j=0;j<a;j++){
// System.out.println("j"+j);

			if(j==a-1){
				int value = list.get(j);
				if(value==list.get(j-1)){
					count++;
				}
			}
			else if(j!=0){
							int value = list.get(j);
			if(value==list.get(j-1)){
				if(value==list.get(j+1)){
					

					if(list.get(j+1)==value+1){
						list.set(j,j-1);
					}else{
						list.set(j,j+1);
					}

					count++;
				}else{
					if(list.get(j+1)==value+1){
						list.set(j,j-1);
					}else
					{
						list.set(j,j+1);
					}
					count++;
				}
			}

				
							}
							// System.out.println("count"+count);
		}
		// System.out.println(list);
		System.out.println(count);
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long  long
#define INF 0x3f3f3f3f
#define pll pair<long long , long long>
const int MAX=1e6+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
vector<int>adj[MAX];
int prime[MAX];
int main() 
{
	
	long long int ans =0;
	int n;
	cin>>n;
	long long int dp[n+1];
	dp[1]=1;
	memset(dp, 0 , sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j =i;j<=n;j+=i)
			dp[j]+=1;
	}
	for(int i=1;i<=n;i++){
		ans = ans + dp[n-i];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 34888
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;

  int k;
  cin >> k;

  int size = s.size();
  vector<string> list;


  for (int i = 0; i < size; i++) {
    for (int j = 1; (j <=k && (i + j) <= size);j++) {
      list.push_back(s.substr(i,j));
    }
  }

  sort(list.begin(), list.end());

  string previous = list[0];
  for (int i = 1, j=1; i < k;j++) {
    if (list[j] !=previous) {
      i++;
      previous = list[j];
    }
  }
      
  cout << previous << endl;
  return 0;
}


Measured memory_bytes: 1660
n = int(input())
s = input()

max = 0
for i in range(n-1):
    cnt = 0
    a = set(s[:i])
    b = set(s[i:])
    for j in a:
        if (j in b):
            cnt += 1
    if(max < cnt):
        max = cnt
print(max)

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

int main() {
	string s;
	cin >> s;

	int i, j, k;
	int num, sub;
	int min = 1e8;
	for (i = 0; i < s.length()-2; i++) {
		j = i + 1;
		k = j + 1;

		num = (s.at(i)-'0')*100 + (s.at(j)-'0')*10 + s.at(k)-'0';
		sub = abs(753 - num);
		if (sub < min) {
			min = sub;
		}
	}
	cout << min << endl;
	return 0;
}





Measured memory_bytes: 256
#include<cstdio>

int main(){
	unsigned N;
	scanf("%u\n", &N);
	unsigned long long a=0, b=0, c=0, d=0, e=0;
	for (unsigned i = 0; i < N; ++i)	{
		char tmp[15];
		scanf("%s", tmp);
		if(tmp[0] == 'M') a++;
		if(tmp[0] == 'A') b++;
		if(tmp[0] == 'R') c++;
		if(tmp[0] == 'C') d++;
		if(tmp[0] == 'H') e++;
	}
	unsigned long long answer = a*(b*(c+d+e)+c*(d+e)+d*e)+b*(c*(d+e)+d*e)+c*d*e;
	printf("%llu\n", answer);
	return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

bool isPrime(int n) {
    if (1 == n)
        return false;
    else if (2 == n)
        return true;
    else if (n % 2 == 0)
        return false;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return false;
    }
    return true;
}

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

    int cnt = 0;
    while (n--) {
        int num;
        cin >> num;
        if (isPrime(num))
            cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll


int n;

signed main(){
  cin>>n;
  int ans = 0;
  rep(i,n){
    int a;
    cin>>a;
    ans = ans|a;
  }


  if(ans%2){
    cout<<"first"<<endl;
  }
  else{
    cout<<"second"<<endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  string S;
  cin >>S;
  int year = (S[0]-48)*10000000 +(S[1]-48)*1000000+(S[2]-48)*100000+(S[3]-48)*10000+(S[5]-48)*1000+(S[6]-48)*100+(S[8]-48)*10+(S[9]-48)*1;
  if(year<=20190430){
    cout<<"Heisei"<<endl;
  }
  else{
    cout<<"TBD"<<endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  int ans=0;
  for(int i=0;i<k;i++)
  {
   ans+=a[i];
  }
  cout<<ans;
}

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

using graph=vector<vector<int>>;

void add_undirected_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
	G[v].emplace_back(u);
}

vector<vector<int>> connected_components(const graph& G){
	int n=G.size();
	vector<vector<int>> res;
	vector<bool> vis(n);
	rep(u,n) if(!vis[u]) {
		vis[u]=true;
		res.emplace_back();
		queue<int> Q; Q.emplace(u);
		while(!Q.empty()){
			int v=Q.front(); Q.pop();
			res.back().emplace_back(v);
			for(int w:G[v]) if(!vis[w]) {
				vis[w]=true;
				Q.emplace(w);
			}
		}
	}
	return res;
}

int main(){
	int n; scanf("%d",&n);
	graph G(n);
	vector<bool> to(n);
	rep(u,n){
		int v; scanf("%d",&v); v--;
		if(v<0) to[u]=true;
		else    add_undirected_edge(G,u,v);
	}

	int namori=0;
	vector<int> a; // 木の頂点数のリスト
	for(auto C:connected_components(G)){
		bool b=true;
		for(int u:C) if(to[u]) b=false;
		if(b) namori++;
		else  a.emplace_back(C.size());
	}
	int k=a.size();

	vector<mint> dp(k+1);
	dp[0]=1;
	rep(i,k) for(int j=k;j>0;j--) dp[j]+=a[i]*dp[j-1];

	mint ans=pow(mint(n-1),k)*(n-namori);
	for(int i=1;i<=k;i++){
		mint c=dp[i]; // i 個の木を使ってできるサイクルの総数
		if(i==1) c-=k;
		ans-=c*fact(i-1)*pow(mint(n-1),k-i);
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 4124
n, m = map(int, input().split())
H = list(map(int, input().split()))
X=[[] for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  X[a-1].append(b)
  X[b-1].append(a)
t=0
for i in range(n):
  E=[0]+list(H[k-1] for k in X[i])
  if max(E) < H[i]:
    t+=1
print(t)

Measured memory_bytes: 30608
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def gcd(x, y):
  while y:
    x, y = y, x % y
  return x

def lcm(x, y):
  return x * y // gcd(x, y)

l = 1
for a in A:
  l = lcm(l, a)
  
answer = 0
for a in A:
  answer = (answer + l * pow(a, MOD - 2, MOD))
  
print(answer % MOD)

Measured memory_bytes: 43484
#include <iostream>
#include <cmath>
#define ll long long int

using namespace std;
int a[2001];

int main(int argc, char const* argv[])
{
	int n, z, w;
	cin >> n >> z >> w;
	for(int i = 0; i < n; i++){
			cin >> a[i];
	}
	if(n == 1){
			cout << abs(a[0] - w) << endl;
	}else{
			cout << max(abs(a[n-1] - w), abs(a[n-1]-a[n-2])) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
s = [i+1 for i in range(n)]
ans = []
coun = 0
for i in range(n):
        if p[i] != s[i]:
                coun+=1
if coun == 2 or coun==0:
        print("YES")
else:
        print("NO")

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

using namespace std;

int main(){
    
    int N, M;
    cin >> N >> M;
    priority_queue<long int> A;
    
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A.push(a);
    }
    
    
    for (int i = 0; i < M; i++) {
        int b = A.top();
        b = b/2;
        A.pop();
        A.push(b);
    }
    
    
    long int ans = 0;
    
    for (int i = 0; i < N; i++) {
        
        
        //cout << A.top() << endl;
        
        ans += A.top();
        A.pop();
    }
    
    cout << ans << endl;
    
    
    
    
    
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a; string s; cin>>a>>s;
    if (a>=3200) print(s);
    else print("red");
    return 0;
}

Measured memory_bytes: 256
c11,c12,c13 = list(map(int,input().split()))
c21,c22,c23 = list(map(int,input().split()))
c31,c32,c33 = list(map(int,input().split()))
a1 = 0
b1 = c11-a1
b2 = c12-a1
b3 = c13-a1
a2 = c21-b1
a3 = c31-b1
if a2+b2==c22 and a3+b2==c32 and a2+b3==c23 and a3+b3==c33:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
from collections import deque
n,m = map(int,input().split())
e = [[] for i in range(n)]
d = [1]*n
s = [0]*n
t = [[] for i in range(n)]
for i in range(n+m-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    t[b].append(a)
    s[b] += 1


ans = [-1]*n
p = s.index(0)
ans[p] = 0
q = deque([])
q.append(p)
s = set()

while q:
    now = q.popleft()
    s.add(now)
    for nex in e[now]:
        if ans[nex] == -1:
            check = True
            for j in t[nex]:
                if j not in s:
                    check = False
                    break
            if check:
                ans[nex] = now+1
                q.append(nex)
for i in ans:
    print(i)





Measured memory_bytes: 46940
(defun main ()
  (let* ((n (read))
         (s (read-line))
         (res (* (count #\R s) (count #\G s) (count #\B s))))
     (dotimes (i n)
       (dotimes (j n)
         (if (and (< i j)
                  (< (- (* 2 j) i) n)
                  (char/= (aref s i) (aref s j)) (char/= (aref s i) (aref s (- (* 2 j) i)))
                  (char/= (aref s j) (aref s (- (* 2 j) i))))
             (decf res))))
    (format t "~d~%" res)))

(main)


Measured memory_bytes: 24388
n, a, b = gets.strip.split.map(&:to_i)

def digit_sum n
  sum = 0
  while n > 0 do
    sum += n % 10
    n /= 10
  end
  sum
end

ans = (1..n)
  .map { |i| [i, digit_sum(i)] }
  .select { |d| a <= d[1] && d[1] <= b }
  .inject(0) { |sum, d| sum + d[0] }


  puts ans

Measured memory_bytes: 2300
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int t[4001][4001];
int tt[4001][4001];

int bsum(int x1, int y1, int x2, int y2)
{
  return tt[y2][x2] - tt[y2][x1] - tt[y1][x2] + tt[y1][x1];
}

int main()
{
  int n, k;

  cin >> n >> k;
  int k2 = 2 * k;

  for(int i = 0; i < n; i++){
    char c;
    int x, y;
    cin >> x >> y >> c;
    if(c == 'W') y += k;

    x %= k2;
    y %= k2;

    t[y][x]++;
    t[y+k2][x]++;
    t[y][x+k2]++;
    t[y+k2][x+k2]++;
  }

  for(int i = 0; i < k2 * 2; i++){
    for(int j = 0; j < k2 * 2; j++){
      tt[j+1][i+1] += t[j][i] + tt[j+1][i] + tt[j][i+1] - tt[j][i];
    }
  }

  int ans = 0;
  for(int i = 0; i < k2; i++){
    for(int j = 0; j < k2; j++){
      int x = j + k, y = i + k;
      int sum = bsum(j, i, x, y) + bsum(x, y, x + k, y + k);
      ans = max(ans, sum);
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 125312
#include<iostream>
#include<map>
#include<vector>
#include<iterator>
#include<algorithm>


using namespace std;
int main()
{ int n;
 cin>>n;
 int m;
 map<int,int>::iterator it;
 int k=1;
 map<int ,int> a;
 for (int i=0;i<n;i++)
 { cin>>m;
   a.insert({m,i+1});
 }
 for( it=a.begin();it!=a.end();it++)
 {cout<<it->second<<" ";}



return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>

using namespace std;

#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;
constexpr int MOD = 1000000007;
constexpr int MAX_SIZE = 100001;

void solve() {
  string S, T;
  cin >> S >> T;
  vector<vector<int>> dp(S.size() + 1, vector<int>(T.size() + 1));
  vector<vector<int>> choice(S.size() + 1, vector<int>(T.size() + 1));
  for(int i = 0; i <= S.size(); i++){
    for(int j = 0; j <= T.size(); j++){
      if(i == 0 || j == 0) {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = dp[i - 1][j];
      choice[i][j] = 1;
      if(dp[i][j - 1] > dp[i][j]){
        choice[i][j] = -1;
        dp[i][j] = dp[i][j - 1];
      }
      if(S[i - 1] == T[j - 1]){
        if(dp[i - 1][j - 1] + 1 > dp[i][j]){
          choice[i][j] = 0;
          dp[i][j] = dp[i - 1][j - 1] + 1;
        }
      }
    }
  }
  //cout << dp[S.size()][T.size()];
  int X = S.size();
  int Y = T.size();
  string ans;
  while(X > 0 && Y > 0){
    if(choice[X][Y] == 1){
      X--;
    }
    else if(choice[X][Y] == -1){
      Y--;
    }
    else {
      ans += S[X - 1];
      X--, Y--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}


Measured memory_bytes: 73580
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
 int s,res;
 int index;
 vector<int> a;
 scanf("%d",&s);
 for(int i=0;i<1000000;i++){
   a.push_back(s);
   if(s%2==0)
     s=s/2;
   else
     s=3*s+1;
   for(int j:a){
     if(j==s){
      printf("%d\n",i+2);
       a.clear();
      return 0;
     }
   }
 }
  a.clear();
 return 0;
}

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

int main() {
  ll X, K, D;
  cin >> X >> K >> D;

  ll ans = 0;
  ll y = abs(X) / D;
  if (y >= K) {
    ans = abs(X) - K * D; 
  } else {
    ll Z = abs(X) % D;
    if ((K-y) % 2 == 0) ans = Z; 
    else ans = abs(Z-D);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    int fcnt = 0;
    int evencnt = 0;
    int oddcnt = 0;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        if(a%4==0) fcnt++;
        else if(a%2!=0) oddcnt++;
        else evencnt++;
    }
    //cout << fcnt << endl;
    //cout << oddcnt << endl;
    //cout << evencnt << endl;
    if(fcnt>=oddcnt) cout << "Yes" << endl;
    else if(evencnt==0 && fcnt>0 && fcnt+1 == oddcnt) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std; 

int main()
{
	int n=0;
	string a,b;
	cin>>a;
	cin>>b;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]==b[i])
			n++;
	}
	cout<<n<<endl;
	
	return 0;		
}




Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10**10
 
class ExtendedBellmanFord:
    def __init__(self, edge):
        self.f_edge = edge
        self.b_edge = [[] for _ in range(len(edge))]
        for src, es in enumerate(edge):
            for dst, cost in es:
                self.b_edge[dst].append((src, -cost))

    def bellman_ford(self, mask, start):
        dist = [INF] * n
        dist[start] = 0
        for _ in range(n):
            update = False
            for i, es in enumerate(self.f_edge):
                if not mask[i]:
                    continue
                for to, cost in es:
                    if not mask[to]:
                        continue
                    if dist[i] != INF and dist[i] + cost < dist[to]:
                        dist[to] = dist[i] + cost
                        update = True
            if not update:
                return dist
        else:
            # Minus loops detected
            return -INF

    def calc(self, start, end):
        visited = [False] * n
        visited[start] = True
        st = [start]
        while st:
            node = st.pop()
            for to, _ in self.f_edge[node]:
                if not visited[to]:
                    visited[to] = True
                    st.append(to)
        rvisited = [False] * n
        rvisited[end] = True
        st = [end]
        while st:
            node = st.pop()
            for to, _ in self.b_edge[node]:
                if not rvisited[to]:
                    rvisited[to] = True
                    st.append(to)
        mask = [forward and backward for forward, backward in zip(visited, rvisited)]
        dist = self.bellman_ford(mask, start)
        if dist == -INF:
            return -INF
        else:
            return dist[end]

if __name__ == "__main__":
    n, m, p = [int(item) for item in input().split()]
    edge = [[] for _ in range(n)]
    for i in range(m):
        a, b, c = [int(item) for item in input().split()]
        a -= 1; b -= 1; c -= p
        c *= -1
        edge[a].append((b, c))
    
    EBF = ExtendedBellmanFord(edge)
    ret = EBF.calc(0, n-1)
    if ret == -INF:
        print(-1)
    else:
        print(max(0, -ret))

Measured memory_bytes: 52440
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

#define int long long int

int32_t main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> arr(n + 1, vector<int>(2, 0));
  for (int i = 1; i < m + 1; i++) {
    int p;
    string s;
    cin >> p >> s;
    if (arr[p][0] != 1) {
      if (s == "WA") {
        arr[p][1]++;
      } else {
        arr[p][0] = 1;
      }
    }
  }
  int c = 0;
  int p = 0;
  for (int i = 1; i < n + 1; i++) {
    if (arr[i][0] == 1) {
      c++;
      p = p + arr[i][1];
    }
  }
  cout << c << " " << p;
  return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
    int n;
    vector<int> p;

    cin >> n;

    p.resize(n);

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

    sort(p.begin(), p.end());

    p.back() /= 2;

    cout << accumulate(p.begin(), p.end(), 0) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e9+1;

int main(){
    ll m;
    cin >> m;
    cout << (24-m)+24 << endl;
    return 0;
} 


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int H, W;
  scanf("%d %d", &H, &W);
 
  int a, b;
 
  while(H!=0 || W!=0){
    for(a=0; a<H; a++){
      if(a==0 || a==H-1){
	for(b=0; b<W; b++){
	  printf("#");
	}
      }else{
	for(b=0; b<W; b++){
	  if(b==0 || b==W-1){
	    printf("#");
	  }else{
	    printf(".");
	  }
	}
      }
      printf("\n");
    }
      printf("\n");
      scanf("%d %d", &H, &W);
  }
  return 0;
}

Measured memory_bytes: 572
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(len(a)):
    if i == 0:
        tmp = a[i] - 1
        ans += b[tmp]
    else:
            tmp = a[i] - 1
            ans += b[tmp]
            if a[i-1] + 1 == a[i]:
                ans += c[tmp-1]
print(ans)

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

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int start = 0, end = n - 1, count = 0;
    while(start < end) {
        if(s[start] == 'W') {
            while(s[end] == 'W') {
                end--;
                if(start == end) {
                    cout << count;
                    return 0;
                }
            }
            s[end] = 'W';
            count++;
        }
        start++;
    }
    cout << count;
	return 0;
}


Measured memory_bytes: 3728
// Ver19.03
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll a, b, c, x, sum, ans = 0;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &x);
  for (int i = 0; i <= a; i++)
  {
    for (int j = 0; j <= b; j++)
    {
      for (int k = 0; k <= c; k++)
      {
        sum = 500 * i + 100 * j + 50 * k;
        if (sum == x)
          ans++;
      }
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 128
n,a,b=map(int, input().split())
s=input()

for i in range(n):

    if (a>0 or b>0) and s[i]=='a':
        print('Yes')
        if a>0 and b>=0:
            a-=1
        else:
            b-=1

    elif b>0 and s[i]=='b':
        print('Yes')
        b-=1
    else:
        print('No')

Measured memory_bytes: 54488
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;

int main()
{
  int N, L; cin >> N >> L;
  int m = 1<<30, s = 0;
  for (int i = 1; i <= N; ++i) {
    s += L+i-1;

    if (abs(m) > abs(L+i-1)) {
      m = L+i-1;
    }
  }

  cout << s-m << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string s, t;
    cin >> s >> t;
    string ans = "No";
    if (s == t) ans = "Yes";
    for (int i = s.size() - 1; i >= 0; i--) {
        if (t[0] == s[i]) {
            string u = "";
            for (int j = i; j < s.size(); j++) {
                u += s[j];
            }
            for (int j = 0; j < i; j++) {
                u += s[j];
            }
            if (u == t) ans = "Yes";
        }
    }
    cout << ans << endl;
}


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

int main(){

    string s; cin>>s;

    int count,ans=0;

    for(int i=0; i<s.size(); i++){
        count=0;
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
            count++;
            for(int j = i+1; j<s.size(); j++){
                if(s[j] == 'A' || s[j] == 'T' || s[j] == 'C' || s[j] =='G')count++;
                else break;    
                

            }
            ans = max(count,ans);
        }
    }

    cout<<ans<<endl;

    return 0;    
}


Measured memory_bytes: 256
//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1e9+7;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int A[200005],B[200005];
vi W;
int32_t main()
{
    speed
    int n;
    cin>>n;
    string napis;
    cin>>napis;
    int x=0;
    for(auto v:napis)
        if(v=='1')
            x++;
    int a=x+1,b=x-1;
    reverse(napis.begin(),napis.end());
    int m1=1,m2=1;
    int suma1=0,suma2=0;
    for(int i=0; i<n; i++)
    {
        A[i]=m1;
        B[i]=m2;
        if(napis[i]=='1')
        {
            suma1+=m1,suma2+=m2;
            suma1%=a;
            if(b>0)
                suma2%=b;
        }
        m1*=2;
        m1%=a;
        if(b>0)
        {
            m2*=2;
            m2%=b;
        }
    }
    for(int i=0; i<n; i++)
    {
        int aktual,ile=x;
        if(napis[i]=='1')
        {
            ile--;
            if(!ile)
               W.pb(0);
            else
            {
                aktual=suma2-B[i];
                aktual+=ile;
                aktual%=ile;
                int wynik=1;
                while(aktual)
                {
                    ile=__builtin_popcount(aktual);
                    aktual=aktual%ile;
                    wynik++;
                }
                W.pb(wynik);
            }
        }
        else
        {
            ile++;
            aktual=suma1+A[i];
            aktual%=ile;
          //  cout<<i<<" "<<ile<<" "<<suma1<<" "<<A[i]<<endl;
            int wynik=1;
            while(aktual)
            {
                ile=__builtin_popcount(aktual);
                aktual=aktual%ile;
                wynik++;
            }
            W.pb(wynik);
        }
    }
    reverse(W.begin(),W.end());
    for(auto v:W)
        cout<<v<<"\n";
    return 0;
}


Measured memory_bytes: 5976
#!/usr/bin/env python3
import sys

A, B = [int(s) for s in input().split()]
if B == 1:
    print(0)
    sys.exit()

if A >= B:
    print(1)
    sys.exit()

cnt = A
tap = 1
while (cnt < B):
    cnt += (A-1)
    tap += 1

print(tap)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int main(){
  int a=700;
  rep(i,0,3){
    char s;
    cin>>s;
    if(s=='o')a+=100;
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll V;
ll d[MAX_N];
struct edge { ll to, cost; };
typedef pair<ll, ll> P;
vector<edge> G[MAX_N];
priority_queue <P, vector<P>, greater<P>> que;
void dijkstra(ll s) {
	fill(d + 1, d + V + 1, INF);
	d[s] = 0;

	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first)continue;
		rep(i, 0, G[v].size()) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
ll root;
ll parent[MAX_N];
ll depth[MAX_N];

void dfs(ll v, ll p, ll d) {
	parent[v] = p;
	depth[v] = d;
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i].to != p) dfs(G[v][i].to, v, d + 1);
	}
}
int lca(int u, int v) {
	while (depth[u] > depth[v])u = parent[u];
	while (depth[v] > depth[u])v = parent[v];
	while (u != v) {
		v = parent[v];
		u = parent[u];
	}
	return u;
}
int main() {
	cin >> V;
	rep(i, 1, V) {
		ll s, t, d; cin >> s >> t >> d;
		G[s].push_back(*(new edge{ t,d }));
		G[t].push_back(*(new edge{ s,d }));
	}

	//dfs(1, -1, 0);
	dijkstra(1);

	repe(i, 1, V) {
		//ll w = lca(1, i);
		ll distance = d[1] + d[i];// -2 * d[w];

		cout << ((distance & 1) ? 1 : 0) << endl;
	}

	return 0;
}


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

int main(){
int A,B; cin >> A >> B;
string S; cin >> S;
bool flag = false;
if(S[A] == '-'){
  flag = true;
  for(int i = 0; i < A; i++){
    if(S[i] == '-'){
    flag = false;
    }
  }
  for(int j = A+1; j < A+B+1; j++){
    if(S[j] == '-'){
    flag = false;
    }
  }
}
if(flag){
  cout << "Yes" << endl;
}
else{
  cout << "No" << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

VVI C;
vector<vector<bool>> used;
int MH, MW;
int dh[] = {0, 0, -1, 1, -1, -1, 1, 1};
int dw[] = {-1, 1, 0, 0, -1, 1, -1, 1};
bool inside(int h, int w) {
    return 0 <= h && h < MH && 0 <= w && w < MW;
}
bool dfs(int h, int w) {
    if (used[h][w]) return false;
    used[h][w] = true;
    REP(i, 8) {
        int nh = h + dh[i], nw = w + dw[i];
        if (!inside(nh, nw)) continue;
        if (C[nh][nw] == 1) dfs(nh, nw);
    }
    return true;
}
void solve(int w, int h) {
    MH = h; MW = w;
    C.resize(h, VI(w));
    used.resize(h, vector<bool>(w, false));
    REP(i, h)REP(j, w) cin >> C[i][j];
    int cnt = 0;
    REP(i, h)REP(j, w) {
        if (C[i][j] == 1) cnt += dfs(i, j);
    }
    cout << cnt << endl;
    used.clear();
    C.clear();
    return;
}

int main(void) {
    int n, p, m, w, h;
    string s;
    int a, b, c;
    while (cin >> w >> h) {
        if (w == 0 && h == 0) return 0;
        solve(w, h);
        //return 0;
    }
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main(){
  int res=1, N, K, i;
  cin >> N >> K;
  for (i=1; i<N+1; i++) {
    if (res <= K) res*=2;
    else res+=K;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
L=[]
count=0
t=0
for i in range(N):
	L.append(int(input()))
while(1):
	count+=1
	if count>N+10:
		print(-1)
		exit()
	if L[t]==2:
		print(count)
		exit()
	else:
		t=L[t]-1

Measured memory_bytes: 13052
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
	long long a,b,c;
	while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF)
	{
		if(a>b&&b>c)
		printf("%lld\n",(b*c)/2);
		if(b>a&&b>c)
		printf("%lld\n",(a*c)/2);
		if(c>a&&c>b)
		printf("%lld\n",(a*b)/2);
	}
	return 0;
 } 

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

int main () {
  
  int n,k;
  cin >> n >> k;
  int a = 1;
  
  for (int i = 0;i<n;i++){
    
    if (a+k < 2*a) {
      a = a+k;
    }
    else {
      a = 2*a;
    }
  }
  cout << a <<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

std::vector<int> factors;
void factorize(int n){
   for (int i = 1; i*i <= n; ++i)
   {
      if(n%i)continue;
      factors.pb(i);
      if(i != n/i){
         factors.pb(n/i);
      }
   }
   sort(factors.begin(), factors.end());
}

int32_t main(){_

   int n;
   cin>>n;
   
   factorize(n);

   int ans = inf;
   for (int i = 0; i < sz(factors); ++i)
   {
      int x = factors[i];
      int y = n / factors[i];
      smin(ans, x+y-2);
   }
   
   cout<<ans;

   return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
    char s[6];
    scanf("%s",&s);
    if(s[0]=='S')printf("Cloudy\n");
    if(s[0]=='C')printf("Rainy\n");
    if(s[0]=='R')printf("Sunny\n");
    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

struct SegmentTree{
    SegmentTree(int n){
        size = 1;
        while(size < n){
            size *= 2;
        }
    }
    void propagate(int k){
        if(data2[k] != 0){
            data[k] += data2[k];
            if(k < size){
                data2[k*2] += data2[k];
                data2[k*2+1] += data2[k];
            }
            data2[k] = 0;
        }
    }
    void update(ll x, int l, int r){
        _update(1, 0, size, x, l, r);
    }
    inline void _update(int k, int a, int b, ll x, int l, int r){
        propagate(k);

        if(b <= l || r <= a){return;}
        if(l <= a && b <= r){
            data2[k] = x;
            propagate(k);
        }else{
            int mid = (a + b) / 2;
            _update(k * 2, a, mid, x, l, r);
            _update(k * 2 + 1, mid, b, x, l, r);
            data[k] = min(data[k*2], data[k*2+1]);
        }
    }
    ll minimum(int l, int r){
        return _minimum(1, 0, size, l, r);
    }
    inline ll _minimum(int k, int a, int b, int l, int r){
        propagate(k);

        if(b <= l || r <= a){return D;}
        if(l <= a && b <= r){return data[k];}
        int mid = (a + b) / 2;
        ll vl = _minimum(k * 2, a, mid, l, r),
            vr = _minimum(k * 2 + 1, mid, b, l, r);
        return min(vl, vr);
    }
    
    int size;
    ll data[400100], data2[400100];
    const ll D = numeric_limits<ll>::max() / 2;
};

int N, Q;
SegmentTree segtree(100000);

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> Q;

    for(int i=0;i<Q;++i){
        int type, s, t;

        std::cin >> type >> s >> t;

        if(type == 0){
            ll x;
            std::cin >> x;

            segtree.update(x, s, t + 1);
        }else{
            std::cout << segtree.minimum(s, t + 1) << std::endl;
        }
    }
}



Measured memory_bytes: 6356
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

class UnionFind
{
    std::vector<int> data;

  public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(int x)
    {
        return -data[root(x)];
    }
};

int main()
{
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    int ans = n - m;
    for(int i = 0; i < m; i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        if(uf.find(a,b)) ans++;
        uf.unite(a,b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
using namespace std;




int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,m,n,k;
     ll t;
     ll s=0;
     cin>>n;
     for(i=1;i<=n;i++)
     {
         for(j=1;j<=n;j++)
         {
             for(k=1;k<=n;k++)
             {
                 s+=__gcd(i,__gcd(j,k));
             }
         }
     }
    cout<<s;
}


Measured memory_bytes: 3632
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n, m = ns()
    e = [[] for _ in range(n)]
    for _ in range(m):
        l, r, d = ns()
        l, r = l - 1, r - 1
        e[l].append([r, d])
        e[r].append([l, -d])

    visited = [False] * n
    dist_mat = [INF] * n

    for i in range(n):
        if visited[i]:
            continue
        que = collections.deque()
        que.append([i, 0])
        visited[i] = True
        dist_mat[i] = 0
        while que:
            idx, dist = que.popleft()
            for ei, di in e[idx]:
                if visited[ei]:
                    if dist + di == dist_mat[ei]:
                        continue
                    else:
                        print("No")
                        exit(0)
                else:
                    visited[ei] = True
                    dist_mat[ei] = dist + di
                    que.append([ei, dist + di])

    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 85868