akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* Trie */

struct ACNode{
  int val;
  ACNode *next[26], *failure;
  
  ACNode():val(0) { memset(next,0,sizeof(next)); }
  
  void insert(char *s){
    if(!*s){ val++; return; }
    int al = *s-'a';
    if(next[al]==NULL) next[al] = new ACNode;
    next[al]->insert(s+1);
  }

  ACNode *nextNode(char c){
    int al = c - 'a';
    if (next[al]) return next[al];
    return failure == this ? this : failure->nextNode(c);
  }
};

struct AhoCorasick{
  ACNode *node;

  AhoCorasick(){node = new ACNode;}
  
  void insert(char *s) {
    node->insert(s);
  }
  
  void build() {
    queue<ACNode*> que;
    que.push(node);
    
    node->failure = node;
    
    while(que.size()){
      ACNode *p = que.front();
      que.pop();
      
      for(int i=0;i<26;i++){
        if(p->next[i]){
          ACNode *failure = p->failure;
          while(!failure->next[i] && failure != node){
            failure = failure->failure;
          }
          if (failure->next[i] && failure != p){
            p->next[i]->failure = failure->next[i];
            p->next[i]->val += failure->next[i]->val;
          }else{
            p->next[i]->failure = node;
          }
          que.push(p->next[i]);
        }
      }
    }
  }
};



int main(){
  char s[SIZE], p[SIZE];
  int n;
  AhoCorasick ac;
  
  scanf("%s%d", s, &n);
  
  for(int i=0;i<n;i++){
    scanf("%s", p);
    ac.insert(p);
  }

  ac.build();

  ACNode *now = ac.node;
  int ans = 0;
  for(int i=0;s[i] != '\0';i++){
    now = now->nextNode(s[i]);
    if(now->val){
      ans++;
      now = ac.node;
    }
  }

  printf("%d\n", ans);
  
  return 0;
}




Measured memory_bytes: 22960
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool into(int);
  int n,k,a;
  vector<int> w;
int main(){
  int l=0,r=0,m;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> a;
    r+=a;
    w.push_back(a);
  }
  r+=1;
  while(l<r){
    m=(l+r)/2;
    if(into(m)==true)r=m;
    else l=m+1;
  }
  cout << r << endl;
  return 0;
}
bool into(int p){
  vector<int> b(k,0);
  int j=0;
  for(int i=0;i<n;){
    if(j==k){
      return false;
    }
    if(b[j]+w[i]>p){
      j++;
      continue;
    }
    else{
      b[j]+=w[i];
      i++;
    }
  }
  return true;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    int mz,mt;
    cin >> mz;
    bool okflag1,okflag2;
    vector<pair<int,int>> lz(mz),lt,muki(mz-1),mukit;
    for(int i=0;i<mz;i++) cin >> lz[i].first >> lz[i].second;
    muki[0]={abs(lz[0].first-lz[1].first)+abs(lz[0].second-lz[1].second),0};
    for(int i=0;i<mz-2;i++){
      if(lz[i].first==lz[i+1].first){
        muki[i+1]={(lz[i].second>lz[i+1].second?1:-1)*(lz[i+2].first>lz[i+1].first?1:-1),abs(lz[i+1].first-lz[i+2].first)};
      }else{
        muki[i+1]={-(lz[i].first>lz[i+1].first?1:-1)*(lz[i+2].second>lz[i+1].second?1:-1),abs(lz[i+1].second-lz[i+2].second)};
      }
    }
    for(int i=0;i<n;i++){
      cin >> mt;
      lt=vector<pair<int,int>>(mt);
      for(int i=0;i<mt;i++) cin >> lt[i].first >> lt[i].second;
      if(mz!=mt) continue;
      mukit=vector<pair<int,int>>(mt-1);
      okflag1=okflag2=true;
      mukit[0]={abs(lt[0].first-lt[1].first)+abs(lt[0].second-lt[1].second),0};
      for(int i=0;i<mz-2;i++){
        if(lt[i].first==lt[i+1].first){
          mukit[i+1]={(lt[i].second>lt[i+1].second?1:-1)*(lt[i+2].first>lt[i+1].first?1:-1),abs(lt[i+1].first-lt[i+2].first)};
        }else{
          mukit[i+1]={-(lt[i].first>lt[i+1].first?1:-1)*(lt[i+2].second>lt[i+1].second?1:-1),abs(lt[i+1].second-lt[i+2].second)};
        }
      }
      for(int i=0;i<mz-1;i++){
        if(muki[i]!=mukit[i]){
          okflag1=false;
          break;
        }
      }
      mukit[0]={abs(lt[mt-1].first-lt[mt-2].first)+abs(lt[mt-1].second-lt[mt-2].second),0};
      for(int i=0;i<mz-2;i++){
        if(lt[mt-1-i].first==lt[mt-2-i].first){
          mukit[i+1]={(lt[mt-1-i].second>lt[mt-2-i].second?1:-1)*(lt[mt-3-i].first>lt[mt-2-i].first?1:-1),abs(lt[mt-2-i].first-lt[mt-3-i].first)};
        }else{
          mukit[i+1]={-(lt[mt-1-i].first>lt[mt-2-i].first?1:-1)*(lt[mt-3-i].second>lt[mt-2-i].second?1:-1),abs(lt[mt-2-i].second-lt[mt-3-i].second)};
        }
      }
      for(int i=0;i<mz-1;i++){
        if(muki[i]!=mukit[i]){
          okflag2=false;
          break;
        }
      }
      if(okflag1||okflag2) cout << i+1 << endl;
      continue;
    }
    cout << "+++++" << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

    vector<bool> used(1000000010, false);
    rep(i, n){
        if(!used.at(a.at(i))){
            used.at(a.at(i)) = true;
        }
        else{
            cout << "NO" << endl; 
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 123904
#import<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef struct{LL a;LL b;}H;
LL h,i,j,m,n,a[1005],b[1005],c[10005];
H w[1005];
int C(H x,H y){return x.a*y.b>y.a*x.b||x.a*y.b==y.a*x.b&&x.a<y.a;}
main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>n;
	for(;i<n;i++)cin>>a[i]>>b[i];
	//sort(w,w+n,C);
	for(i=0;i++<h;)
	{
		for(j=0,m=999999999;j<n;j++)
		{
			if(a[j]>i)m=min(m,b[j]);
			else m=min(m,c[i-a[j]]+b[j]);
		}
		c[i]=m;
	}
	cout<<c[h];
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;

	vl p(n), c(n);
	FOR(i,0,n) cin >> p[i], p[i]--;
	FOR(i,0,n) cin >> c[i];
	
	ll res = *max_element(all(c));
	FOR(i,0,n) {
		ll j = i, sum = 0, len = 0;
		do {
			sum += c[j], j = p[j], len++;
		} while (j != i);
		
		ll r = k >= 2*len ? 2*len + k%len : k;
		ll base = ((k-r)/len) * max(sum,0LL), add = -oo;
		sum = 0;
		FOR(t,0,r) {
			sum += c[j], j = p[j];
			add = max(add,sum);
		}
		res = max(res, base+add);
	}
	cout << res << endl;
}



Measured memory_bytes: 3740
q,h,s,d = map(int, input().split())
n = int(input()) * 100
#値の更新をしていく
h = min(h,q*2)
s = min(s,h*2)
d = min(d,s*2)
ans = 0
count = 0
count = n//200
ans += count * d
n -= count*200

count = n//100
ans += count * s
n -= count*100

count = n//50
ans += count * h
n -= count*50

count = n//25
ans += count * q
n -= count*25
print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
string n;
cin >> n;
int ans1;
int len = (int)n.size();
int ans = len;
for (int i=0;i<len-1;i++) {
if (n[i]!=n[i+1]) {
ans1 = max(i+1, len-i-1);
ans = min(ans, ans1);
}}
cout << ans;
return 0;
}

Measured memory_bytes: 512
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    
    ll X,Y;cin>>X>>Y;
    cout<<(ll)floor((long double)(log2((long double)(Y/X))))+1LL<<endl;
  
    return 0;
}



Measured memory_bytes: 512
#include <stdio.h>
#define MAX 100000
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[MAX];
int D[MAX];
int getD(int);
void print(int);


int main()
{
  int n, k, node, c[MAX];
  int i, j;

  scanf("%d", &n);

  for(i=0; i<n; i++){
	T[i].parent = NIL;
	T[i].left = NIL;
	T[i].right = NIL;
  }

  for(i=0; i<n; i++){
	scanf("%d%d", &node, &k);
	for(j=0; j<k; j++){
	  scanf("%d", &c[j]);
	  
	  
	  T[c[j]].parent = node;
	  if(j==0) T[node].left = c[0];
	  else T[c[j-1]].right = c[j];
	}
  }
  
  for(i=0; i<n; i++){
	D[i] = getD(i);
  }

  for(i=0; i<n; i++){
	print(i);
  }

  return 0;
}

int getD(int i)
{
  int k=0;
  
  while(T[i].parent>=0){
	i = T[i].parent;
	k++;
  }

  return k;
}

void print(int i)
{
  int j, count=0;
  
  printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, D[i]);
  
  if(T[i].parent == NIL){
    printf("root, [");
  }
  else if(T[i].left == NIL){
    printf("leaf, [");
  }
  else{
    printf("internal node, [");
  }
  i = T[i].left;
  while(i != NIL){
    if(count==0) printf("%d", i);
    else printf(", %d", i);
	
    i = T[i].right;
    count++;  
  }
   
  printf("]\n");
   
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main() {
    int a, b, c;

    cin >> a >> b >> c;

    if (a == b) {
        cout << c << endl;
    } 
    else if (b == c) {
        cout << a << endl;
    }
    else {
        cout << b << endl;
    }
}

Measured memory_bytes: 256
N, T = map(int, input().split())
c = []
t = []
for i in range(N):
    tmp1, tmp2 = map(int, input().split())
    c.append(tmp1)
    t.append(tmp2)

tmp_min = 10**5

for i in range(N):
    if t[i]<=T and tmp_min>c[i]:
        tmp_min = c[i]

if tmp_min == 10**5:
    print('TLE')
else:
    print(int(tmp_min))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

void solve(ll &c, ll &x, ll &node, ll depth) {
	while(x-depth >= c-1) {
		cout<<node-1<<" "<<node<<"\n";
		node++;
		c--;
		x -= depth;
		depth++;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	//cin>>t;
	while(t--){
		int n;
        cin>>n;
        cout<<lcm(n,360)/n<<"\n";
 	}
 	return 0;
}


Measured memory_bytes: 3548
import numpy as np
x,n = map(int,input().split())
if n!=0:
    p = list(map(int,input().split()))
    q = [i for i in range(-101,201)]
    r = set(q)-set(p)

    a = np.array(list(r))
    f = [x]*(len(list(r)))
    b = np.array(f)

    c = a-b
    d  = np.abs(c)
    e = np.argmin(d)

    print(int(c[int(e)])+x)
else:
    print(x)

Measured memory_bytes: 27188
n=int(input())
for i in range(1,n+1):
	if i%3==0:
		print(" "+str(i),end="")
	else:
		temp=i
		while temp>0:
			if temp%10==3:
				print(" "+str(i),end="")
				break
			else:
				temp=int(temp/10)
print("")



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

const int N = 1e5 + 10;
const long long mod = 998244353;

int a[N], cnt[N];

long long mod_pow(long long x, long long n){
	long long ret = 1;
	while (n){
		if (n & 1) ret = ret * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return ret;
}

int main(){
	int n;
	long long ans;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	if (a[1]){
		printf("0\n");
		return 0;
	}
	for (int i = 2; i <= n; i++){
		if (!a[i]){
			printf("0\n");
			return 0;
		}
	}
	for (int i = 1; i <= n; i++) cnt[a[i]]++;
	ans = 1;
	for (int i = 1; i <= n - 1; i++){
		ans *= mod_pow(cnt[i - 1], cnt[i]);
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
int n,d;
ll f[200020],g[200020],ans,a[200020];
int main(){
	scanf("%d%d",&n,&d);
	FOR(i,1,n) scanf("%lld",a+i);
	f[1]=a[1];
	FOR(i,2,n) f[i]=min(f[i-1]+d,a[i]);
	g[n]=a[n];
	ROF(i,n-1,1) g[i]=min(g[i+1]+d,a[i]);
	FOR(i,2,n-1) ans+=min(f[i],g[i])+a[i];
	ans+=1ll*d*(n-1)+a[1]+a[n];
	printf("%lld\n",ans);
}

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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
  int n,m;
  cin>>n>>m;
  char a[n][n];
  char b[m][m];
  rep(i,n)rep(j,n)cin>>a[i][j];
  rep(i,m)rep(j,m)cin>>b[i][j];
  rep(i,n-m+1){
    rep(j,n-m+1){
      int bo=1;
      for(int x=i;x<=i+m-1;++x){
        for(int y=j;y<=j+m-1;++y){
          if(a[x][y]!=b[x-i][y-j])bo=0;
        }
      }
      if(bo){cout<<"Yes"<<endl;
            exit(0);}
    }
  }
  cout<<"No"<<endl;
}


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

using namespace std;

bool check(int a) {
  int cnt = 0;
  for (int i = 1; i <= a; ++i) {
    if ((a % i) == 0) {++cnt;}
  }
  return cnt == 8;
}

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

  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    ans += check(i);
  }
  cout << ans << "\n";
  
}


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

using namespace std;

int main(){
	long long n, ans = (long long)(-1 * 1e18);
	cin >> n;
	vector<vector<int>> f(n, vector<int>(10)), p(n, vector<int>(11));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> f[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 11; j++){
			cin >> p[i][j];
		}
	}
	for(int i = 1; i < (1 << 10); i++){
		vector<int> c(n, 0);
		long long t = 0;
		for(int j = 0; j < 10; j++){
			int bi = 1 << j;
			if(i & bi){
				for(int k = 0; k < n; k++){
					if(f[k][j]) c[k]++;
				}
			}
		}
		for(int j = 0; j < n; j++){
			t += p[j][c[j]];
		}
		ans = max(ans, t);
	}
	cout << ans << endl;
	return 0;
}

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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int N;

    cin>>N;

    cout<<pow(N,3)<<endl;


    return 0;
}

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

int main(){
    int N,i;
    cin >> N;

    double A[N],sum=0,ans=0;
    for(i=0; i<N; i++){
        cin >> A[i];
    }

    for(i=0; i<N; i++){
        sum += 1/A[i];
    }

    ans = 1/sum;

    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

vector<vector<ii>> adjlist;
vector<int> subtree;
vector<ll> dist;

void visit(int v) {
  subtree[v] = 1;
  for (auto w : adjlist[v]) {
    if (!subtree[w.first]) {
      visit(w.first);
      subtree[v] += subtree[w.first];
    }
  }
}

void dists(int v, int blocked, ll d) {
  dist[v] = d;
  for (auto w : adjlist[v]) {
    if (dist[w.first] == -1 && w.first != blocked) {
      dists(w.first, blocked, d + w.second);
    }
  }
}

int main() {
  // Read input.
  int n;
  scanf("%d", &n);
  adjlist.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    adjlist[a].push_back(ii(b, c));
    adjlist[b].push_back(ii(a, c));
  }

  // DFS for centroids.
  subtree.assign(n, 0);
  visit(0);

  // Find centroid.
  int centroid = 0, centroid1, centroid2;
  int parent = -1;
  int edge;
  bool doubleCentroid = false;
  do {
    int maxi = 0, maxChild, maxEdge;
    for (auto w : adjlist[centroid]) {
      if (w.first == parent) continue;
      if (subtree[w.first] > maxi) {
        maxi = subtree[w.first];
        maxChild = w.first;
        maxEdge = w.second;
      }
    }
    if (2 * maxi >= n) {
      parent = centroid;
      centroid = maxChild;

      if (2 * subtree[centroid] == n) {
        doubleCentroid = true;
        centroid1 = parent;
        centroid2 = centroid;
        edge = maxEdge;
        break;
      }
    } else break;
  } while (true);

  dist.assign(n, -1);
  ll result = 0;
  if (doubleCentroid) {
    dists(centroid1, centroid2, 0);
    dists(centroid2, centroid1, 0);
    for (int i = 0; i < n; i++) {
      result += 2 * dist[i];
    }
    result += (n - 1LL) * edge;
  } else {
    dists(centroid, -1, 0);
    for (int i = 0; i < n; i++) {
      result += 2 * dist[i];
    }
    int mini = 0x3FFFFFFF;
    for (auto w : adjlist[centroid]) {
      mini = min(mini, w.second);
    }
    result -= mini;
  }
  printf("%lld\n", result);

  return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define enter putchar('\n')
#define space putchar(' ')
#define fi first
#define se second
#define MAXN 300005
//#define ivorysi
#define pii pair<int,int>
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
    }
    res *= f;
}

template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N;
int p[MAXN],v[MAXN],cnt,id[MAXN],dir[MAXN];
bool vis[MAXN];
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(p[i]);
    int la = 1;
    while(1) {
        while(p[la] == la && la <= N) ++la;
        if(la > N) break;
        int ed = la;
        while(1) {
            if(ed <= N && ((ed - la) & 1) && p[ed] == ed) ++ed;
            else if(ed <= N && !((ed - la) & 1) && p[ed] != ed) ++ed;
            else break;
        }
        --ed;
        if(p[ed] == ed) --ed;
        if(ed == la) {puts("No");return;}
        cnt = 0;
        for(int i = la ; i <= ed ; ++i) v[++cnt] = p[i];
        sort(v + 1,v + cnt + 1);
        for(int i = 1 ; i <= cnt ; ++i) {
            if(v[i] != i + la - 1) {puts("No");return;}
        }
        cnt = 0;
        for(int i = la ; i <= ed ; i += 2) {
            v[++cnt] = p[i];
            id[p[i]] = cnt;
        }
        sort(v + 1,v + cnt + 1);
        for(int i = la ; i <= ed ; i += 2) {
            int t = lower_bound(v + 1,v + cnt + 1,p[i]) - v;
            if(t <= id[p[i]]) dir[i] = 0;
            else dir[i] = 1;
        }
        int L = 0,R = 0;
        for(int i = la ; i <= ed ; i += 2) {
            if(dir[i] == 0) {
                if(p[i] < L) {puts("No");return;}
                L = p[i];
            }
            else {
                if(p[i] < R) {puts("No");return;}
                R = p[i];
            }
        }
        la = ed + 1;
    }
    puts("Yes");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 4992
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut arr:Vec<usize> = (0..n).map(|_| read()).collect();
    let mut ans = 0;
    loop {
        if arr.clone().into_iter().max().unwrap() == 0 {
            break;
        }
        let mut i = 0;
        while i < n {
            if arr[i] == 0 {
                i += 1;
            } else {
                 ans += 1;
                 while i < n && arr[i] > 0 {
                     arr[i] -= 1;
                     i += 1;
                 }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2120
# greedy is all you need
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce


def score(D, C, S, T):
    last = [-1] * 26
    # scores = [0]
    score = 0
    for d in range(D):
        # scores.append(scores[-1] + S[d][T[d]])
        score += S[d][T[d]]
        last[T[d]] = d
        for i in range(26):
            # scores[-1] -= C[i] * (d - last[i])
            score -= C[i] * (d - last[i])  # この場で一番罰則が大きいやつを使うとか？
    return score


D = a_int()
C = ints()
S = read_tuple(D)


def maximizer(newT, bestT, bestscore):
    tmpscore = score(D, C, S, newT)
    if tmpscore > bestscore:
        return newT, tmpscore
    else:
        return bestT, bestscore

# editorialよりd日目の改善は、改善せずにd+n_days経過したときの関数にしたほうが
# 最終的なスコアと相関があるんじゃない？


def make_T(n_days):
    T = []
    last = [-1] * 26
    for d in range(D):
        ma = -INF
        for i in range(26):
            tmp = S[d][i]
            for j in range(n_days):
                tmp += C[i] * (d + j - last[i])
            if tmp > ma:
                t = i
                ma = tmp
        last[t] = d  # Tを選んだあとで決める
        T.append(t)
    return T


T = make_T(0)
sco = score(D, C, S, T)
for i in range(1, 26):
    T, sco = maximizer(make_T(i), T, sco)

# print(score(D, C, S, T))
print(*mina(*T, sub=-1), sep='\n')


Measured memory_bytes: 75964
#include <bits/stdc++.h>
#define MP make_pair
using namespace std;
template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
int main(){
    int n;
    cin>>n;
    cout<<n/3<<endl;
    return 0;
}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2012

#include <stdio.h>
#define min(a,b) ((a<b)?(a):(b))

int main(void) {
	while(1) {
		
		int e;
		int mmin = 10000000;
		
		scanf("%d", &e);
		if ( e == 0 ) { break; }
		
		for(int z=0; z<=100; z++) {
			for(int y=0; y<=1000; y++) {
				int x = e - z*z*z - y*y;
				if ( x<0 ) { break; }
				
				int sum = x+y+z;
				if ( mmin > sum ) { mmin = sum; }
			}
		}
		
		printf("%d\n", mmin);
	}
}

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

int main(){
  int n,m;
  cin >> n >> m;
  int l=0,r=n;
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    l=max(l,a);
    r=min(r,b);
  }
  cout << max(0,r-l+1) << endl;
}

Measured memory_bytes: 256
# all credits to iehn submission #3972219 - how the duck did he manage to fit in time?..
def main():
    s = [ord(c) - 97 for c in input()]
    t = [ord(c) - 97 for c in input()]
    sl = len(s)
    tl = len(t)
    rr = [[0] * (tl) for _ in range(sl)]
    t0 = t[0]
    for i in range(sl):
        if s[i] == t0:
            for k in range(i,sl):
                rr[k][0] = 1
            break
 
    rr0 = rr[0]
    s0 = s[0]
    for j in range(tl):
        if s0 == t[j]:
            for k in range(j,tl):
                rr0[k] = 1
            break
 
    ta = [(i,t[i]) for i in range(1, tl)]
    for i in range(1, sl):
        rri = rr[i]
        rri1 = rr[i-1]
        si = s[i]
        for j, tj in ta:
            if si == tj:
                rri[j] = rri1[j-1] + 1
            else:
                rri[j] = rri1[j]
                if rri[j] < rri[j-1]:
                    rri[j] = rri[j-1]
 
    i = sl-1
    j = tl-1
    r = []
    while i >= 0 and j >= 0:
        if s[i] == t[j]:
            r.append(s[i] + 97)
            i -= 1
            j -= 1
            continue
        if rr[i][j] == 0:
            break
        if i > 0 and rr[i-1][j] == rr[i][j]:
            i -= 1
        else:
            j -= 1
 
    return ''.join(map(chr,r[::-1]))
 
 
print(main())

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

int main(){
  int n;
  cin >> n;
  int ans=n*(n-1)/2-n/2;
  cout << ans << endl;
  int a[ans],b[ans];
  int k=0;
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      if(i+j!=n/2*2+1){
        a[k]=i; b[k]=j; k++;
      }
    }
  }
  for(int i=0;i<ans;i++) cout << a[i] << " " << b[i] << endl;
}

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


int main(){
    ll N,K;
    cin >> N >>K;
    ll count=0;

    for(ll i=K;i<=N+1;i++)
    {
        ll max=(N)*(N+1)/2 - (N-i+1)*(N-i)/2;

        ll min=(i-1)*(i)/2;
        count += max-min+1;
    }
    if(count >= (ll) (pow(10,9)+7))
        count = count%((ll) pow(10,9)+7);
    count = (ll) count;

    std::cout << count;

    return 0;
}


Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
struct data
{
	int a0,a1,id;
	friend bool operator < (data a,data b){return 1ll*a.a1*b.a0==1ll*a.a0*b.a1?a.id<b.id:1ll*a.a1*b.a0<1ll*a.a0*b.a1;}
	friend data operator + (data a,data b){return data{a.a0+b.a0,a.a1+b.a1,a.id};}
}c[200020];
int n,p[200020],v[200020],f[200020];
long long ans;
set<data>s;
int find(int x)
{
	if(x!=f[x])return f[x]=find(f[x]);
	return x;
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;++i)scanf("%d",&p[i]);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&v[i]);
		if(v[i]==0)c[i]=data{1,0,i};
		else c[i]=data{0,1,i};
		s.insert(c[i]);
		f[i]=i;
	}
	int x,y;
	while(s.size())
	{
		x=s.begin()->id;s.erase(s.begin());
		if(x==1)continue;
	//	printf("%d\n",x);
		y=find(p[x]);f[x]=y;
		s.erase(c[y]);
		ans+=1ll*c[y].a1*c[x].a0;
		c[y]=c[y]+c[x];
		s.insert(c[y]);
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 17408
#include <iostream>
#include <algorithm>
#define rng(x1, y1, x2, y2) (sum[y2][x2] + sum[y1][x1] - sum[y2][x1] - sum[y1][x2])
using namespace std;
int H, W, ra, o, a[40][40], sum[40][40], dp[40][40][40][40];
inline int solve(int x1, int y1, int x2, int y2) {
	if (dp[y1][x1][y2][x2]) return dp[y1][x1][y2][x2];
	int ret = 1048576 + rng(x1, y1, x2, y2);
	for (int i = x1 + 1; i < x2; i++) {
		int petl = rng(x1, y1, i, y2), petr = rng(i, y1, x2, y2);
		if (min(petl, petr) >= o) {
			int resl = solve(x1, y1, i, y2);
			int resr = solve(i, y1, x2, y2);
			int res = ((resl + resr) >> 20 << 20) + min(resl & 1048575, resr & 1048575);
			ret = max(ret, res);
		}
	}
	for (int i = y1 + 1; i < y2; i++) {
		int petl = rng(x1, y1, x2, i), petr = rng(x1, i, x2, y2);
		if (min(petl, petr) >= o) {
			int resl = solve(x1, y1, x2, i);
			int resr = solve(x1, i, x2, y2);
			int res = ((resl + resr) >> 20 << 20) + min(resl & 1048575, resr & 1048575);
			ret = max(ret, res);
		}
	}
	return dp[y1][x1][y2][x2] = ret;
}
int main() {
	while (scanf("%d%d%d", &H, &W, &ra), H) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) scanf("%d", &a[i][j]);
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				for (int k = i + 1; k <= H; k++) {
					for (int l = j + 1; l <= W; l++) dp[i][j][k][l] = 0;
				}
			}
		}
		o = sum[H][W] - ra;
		int ret = solve(0, 0, W, H);
		printf("%d %d\n", (ret >> 20), ((ret - o) & 1048575));
	}
}

Measured memory_bytes: 9148
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>

using namespace std;

char s[1000005];
int a[1000005];
int ans=0;
int main()
{
	scanf("%s",s);
	memset(a,0,sizeof(a));
	int tot=-1;
	int now=0;
	for (int i=0;i<=strlen(s);i++)
	{
		if (i==0||s[i]!=s[i-1])
		{
			a[++tot]=now;
			now=0;
		}
		now++;
	}
	int len=strlen(s);
	/*for (int i=1;i<=tot;i++)
	{
		ans=max(min(a[i-1]+a[i]+a[i+1],min(sum,len-sum-a[i])),ans);
		ans=max(min(a[i-1]+a[i],sum),ans);
		ans=max(min(a[i]+a[i+1],len-sum-a[i]),ans);
		sum+=a[i];
	}*/
	int sum=0;
	for (int i=1;i<=tot;i++)
	{
		if (sum+a[i]>=len-sum)
		{
			ans=len-sum;
			break;
		}
		sum+=a[i];
	}
	sum=0;
	for (int i=tot;i>=1;i--)
	{
		if (sum+a[i]>=len-sum)
		{
			ans=max(ans,len-sum);
			break;
		}
		sum+=a[i];
	}
	printf("%d",ans);
}

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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    // 別々に買うパターン
    int p1 = A * X + B * Y;
    // 個数が少なくなるようにセット（AB）を多くするパターン
    int p2 = 0;
    if (X > Y) {
        p2 = C * Y * 2 + A * (X - Y);
    } else if (X < Y) {
        p2 = C * X * 2 + B * (Y - X);
    } else {
        p2 = C * (X + Y);
    }
    // 個数を超過してもセットで買うパターン
    int p3 = C * max(X, Y) * 2;

    int ans = min(min(p1, p2), p3);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
const int N = 8003;
string s;
int x, y;
vector <pii> a, b;
bool canx[N][2 * N], fCanx[2 * N];
bool cany[N][2 * N], fCany[2 * N];
void make(string s, vector <pii> &a, vector <pii> &b) {
    a.clear(); b.clear();
    int cnt = 0, flip = 0;
    s += 'T';
    for (auto x: s) {
        if (x == 'T') {
            if (!flip) {
                if (a.size() == 0)
                    a.push_back(make_pair(cnt, cnt));
                else
                    a.push_back(make_pair(cnt, -cnt));
            }
            else b.push_back(make_pair(cnt, -cnt));
            cnt = 0;
            flip = 1 - flip;
        } else cnt++;
    }
}
void canReach(vector <pii> c, bool can[N][2 * N], bool fcan[2 * N]) {
    memset(can, 0, sizeof(can));
    can[0][N] = true;
    int n = c.size();
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 2 * N; j++)
            if (can[i - 1][j]) {
                can[i][j + c[i - 1].first] = can[i][j + c[i - 1].second] = true;
            }
    }
    for (int j = 0; j < 2 * N; j++)
        fcan[j] = can[n][j];
}
string resp(int x, int y) {
    if (fCanx[x + N] && fCany[y + N]) return "Yes";
    else return "No";
}
void process (string s, vector <pii> &a, vector <pii> & b) {
    make(s, a, b);
    canReach(a, canx, fCanx);
    canReach(b, cany, fCany);
}
int main() {
    try {
        cin >> s;
        process(s, a, b);
        cin >> x >> y;
        cout << resp(x, y);
    } catch (exception ex) {
    }
    return 0;
}


Measured memory_bytes: 125824
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
# include <climits>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define yes(b) std::cout<< (b ? "Yes" : "No")
#define YES(b) std::cout<< (b ? "YES" : "NO")
const ll INF = 1LL << 50;
using namespace std;
/*int ketawa(ll num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}
*/
bool keta(ll num, vector<int> v) {
	int dig;
	while (num) {
		dig = num % 10;
		for (auto& i : v) {
			if (dig == i) {
				return false;
			}
		}
		num = num / 10;
	}
	return true;
}

ll func(ll a, ll b, ll c, ll d,int n) {
	return ((c / (d - b) + n)*(d - b)) + (a % (d - b));
}
int main(void) {
	int N, M;
	cin >> N >> M;

	const int NMAX = 1000;
	const int MMAX = 2000;
	int a[MMAX], b[MMAX];
	ll c[MMAX];

	for (int i = 0; i < M; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		c[i] = -c[i];

	}

	ll dist[NMAX];

	for (int i = 0; i < N; ++i) {
		dist[i] = INF;

	}

	dist[0] = 0;


	for (int loop = 0; loop < N - 1; ++loop) {
		for (int i = 0; i < M; ++i) {

			if (dist[a[i] - 1] == INF) continue;

			if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
				dist[b[i] - 1] = dist[a[i] - 1] + c[i];

			}

		}

	}

	ll ans = dist[N - 1];


	bool negative[NMAX];

	for (int i = 0; i < N; ++i) {
		negative[i] = false;

	}

	for (int loop = 0; loop < N; ++loop) {
		for (int i = 0; i < M; ++i) {
			if (dist[a[i] - 1] == INF) continue;

			if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
				dist[b[i] - 1] = dist[a[i] - 1] + c[i];
				negative[b[i] - 1] = true;

			}

			if (negative[a[i] - 1] == true) {
				negative[b[i] - 1] = true;

			}

		}

	}


	if (negative[N - 1])
		cout << "inf" << endl;
	else
		cout << -ans << endl;

	return 0;

}


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

int main()
{
	ll a,b;
	cin >> a >> b;
	if(a*b<=0)
	{
		cout<<"Zero"<<endl;
		return 0;
	}
	if(a<b)swap(a,b);
	if(a>0&&b>0)
	{
		cout<<"Positive"<<endl;
		return 0;
	}
	ll k = min(b,-1LL)-min(a,-1LL);
	if(k&1)
	{
		cout<<"Positive"<<endl;
	}
	else
	{
		cout<<"Negative"<<endl;
	}

	
	return 0;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pi 3.1415926535897932384626
ll x[100];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    x[0]=2;
    x[1]=1;
    for(int i = 2;i<= n;i++)
    {
        x[i]=x[i-1]+x[i-2];
    }
    cout<<x[n]<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, n);
  Cins(int, n, a);

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ps = [input().split() for i in range(m)]

ans_ac = 0
ans_wa = 0
flag = 0
number = 0
ok = ["n" for i in range(n)]
count_wa = [0 for i in range(n)]
count = 0
for i in range(m):
    if ok[int(ps[i][0])-1] == "n":
        if ps[i][1] == "WA":
            count_wa[int(ps[i][0])-1] += 1
        else:
            ans_ac += 1
            ans_wa += count_wa[int(ps[i][0])-1]
            ok[int(ps[i][0])-1] = "OK"
 #   print(ok)
 #   print(count_wa)
    
print(ans_ac,ans_wa)

Measured memory_bytes: 74200
#include <stdio.h>

// 行列AとベクトルBを読み込んで、A*B=Cを計算してCを出力
// 入力として、Aの大きさと、A,Bの値を受け取る
int main()
{
	int iCnt1, iCnt2;
	int iInputValue;
	int iInputN, iInputM;
	int** aiArrayA;
	int* aiVecB;
	int* aiVecC;

	scanf("%d %d", &iInputN, &iInputM);

	aiArrayA = (int** ) malloc(sizeof(int *) * iInputN);
	for (iCnt1 = 0; iCnt1 < iInputN; iCnt1++)
	{
		aiArrayA[iCnt1] = (int* ) malloc(sizeof(int) * iInputM);
	}

	aiVecB = (int*) malloc(sizeof(int) * iInputM);
	aiVecC = (int*) malloc(sizeof(int) * iInputM);
	
	for (iCnt1 = 0; iCnt1 < iInputN; iCnt1++)
	{
		for (iCnt2 = 0; iCnt2 < iInputM; iCnt2++)
		{
			scanf("%d", &aiArrayA[iCnt1][iCnt2]);
		}
	}

	for (iCnt1 = 0; iCnt1 < iInputM; iCnt1++)
	{
		scanf("%d", &aiVecB[iCnt1]);
	}

	for (iCnt1 = 0; iCnt1 < iInputN; iCnt1++)
	{
		aiVecC[iCnt1] = 0;
		for (iCnt2 = 0; iCnt2 < iInputM; iCnt2++)
		{
			aiVecC[iCnt1] += aiArrayA[iCnt1][iCnt2] * aiVecB[iCnt2];
		}
		printf("%d\n", aiVecC[iCnt1]);
	}
	
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
int main (){

  int m,f,r,b;

  while(1){

    cin >>m>>f>>r;
    b=m+f;

    if(m == -1 && f == -1 && r == -1) break;

    if( b  >= 80 && m != -1 && f != -1){
      cout <<"A\n";
    }else if( b  >= 65 && b < 80 && m != -1 && f != -1){
      cout <<"B\n";
    }else if( ( b >= 50 && b  < 65 ) || r >= 50 && m != -1 && f != -1){
      cout <<"C\n";
    }else if( b >= 30 && b < 50 && m != -1 && f != -1){
      cout <<"D\n";
    }else if( b < 30 || f == -1 || m == -1){
      cout <<"F\n";
    }

  }

}

    

Measured memory_bytes: 1120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
const ll MOD=1e9+7;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s,t;cin>>s>>t;
    if(s==t)return cout<<"Yes" , 0;
    for(ll i=0;i<s.size();i++){
        char c = s.back();s.pop_back();
        s = c + s;
        if(s==t)return cout<<"Yes" , 0;
    }
    cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
vector<int>v;
for(int i = 0; i < 3; i++){
int a;cin >> a;
v.push_back(a);
}
sort(v.begin(),v.end());
for(int i = 0; i < 2; i++){
cout << v[i] << " ";
}
cout << v[2] << endl;
}

Measured memory_bytes: 1220
////
////  main.cpp
////  L2-005
////
//
#include <cstring>
#include <vector>
#include <iostream>
#include <unordered_map>
#include<algorithm>
#include <set>
#include <list>
#include<stdio.h>
#include <cmath>
#include <unordered_set>
using namespace std;
using ll=long long;
char buf[1024];
int MAXN;
int MAXVALUE=-1;
int N;
bool test(const string &s){
    static unordered_set<string> d;
    int cnt=0;
    unordered_map<char, int> mm;
    string res;
    for(auto i:s){
        if (mm.count(i)) {
            res+=to_string(mm[i]);
        }else{
            mm[i]=cnt++;
            res+=to_string(cnt++);
        }
    }
    if (d.count(res)) {
        return false;
    }else{
        d.insert(res);
        return true;
    }
}
void dfs(int now){
    if (now==MAXN) {

        string s(buf,MAXN);
        cout<<s<<endl;
        return ;
    }

    for(int i=0;i<=MAXVALUE+1;i++){
        buf[now]='a'+i;
        int nM=MAXVALUE;
        MAXVALUE=std::max(i,MAXVALUE);
        dfs(now+1);
        MAXVALUE=nM;
    }
}

int main(){
    cin>>MAXN;
    dfs(0);
    
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
    int a,b,mi=1,mj=1;
    cin >> a >> b;
    if(((a/100)*100+(a/1000-(a/10000)*10)*10+a/10000)>=a) mi=0;
    if(((b/100)*100+(b/1000-(b/10000)*10)*10+b/10000)<=b) mj=0;
    cout << (b/100)-(a/100)+1-mi-mj;
}

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


typedef long long ll;
int N;
int A[101010];
ll ans = 0;
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d", &A[i]);

	ans = A[0] - 1;
	int num = 2;
	rep(i, 1, N) {
		if (A[i] < num) continue;

		if (A[i] == num) {
			num++;
			continue;
		}

		ans += A[i] / num;
		if (A[i] % num == 0) ans--;
	}

	cout << ans << endl;
}

Measured memory_bytes: 768
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        long x = sc.nextLong();
        long y = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long xc = (x % c == 0) ? x / c : x / c + 1;
        long yc = y / c;
        long xd = (x % d == 0) ? x / d : x / d + 1;
        long yd = y / d;

        long lcm = lcm(c, d);

        long comx = (x % lcm == 0) ? x / lcm : x / lcm + 1;
        long comy = y / lcm;

//        System.out.println(xc);
//        System.out.println(yc);
//        System.out.println(xd);
//        System.out.println(yd);
//        System.out.println(lcm);
//        System.out.println(comx);
//        System.out.println(comy);

        System.out.println(y - x + 1 - ((yc - xc + 1) + (yd - xd + 1) - (comy - comx + 1)));


    }

    long lcm(long c, long d) {
        return c * d / gcd(c, d);
    }

    long gcd(long c, long d) {
        if (c < d) return gcd(d, c);
        if (d == 0) return c;
        return gcd(d, c % d);
    }

}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c){
    stack<int> S;
    S.push(r);
    color[r] = c;
    while( !S.empty() ){
        int u = S.top(); S.pop();
        for (int i=0; i<G[u].size(); i++){
            int v = G[u][i];
            if (color[v] == NIL){
                color[v] = c;
                S.push(v);
            }
        }
    }
}


void assignColor(){
    int id = 1;
    for (int i=0; i<n; i++) color[i] = NIL;
    for (int u=0; u<n; u++){
        if (color[u] == NIL) dfs(u, id++);
    }
}

int main(){
    int s, t, m, q;

    cin >> n >> m;

    for (int i=0; i<m; i++){
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >> q;

    for (int i=0; i<q; i++){
        cin >> s >> t;
        if (color[s] == color[t]){
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 7060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            int input = Integer.parseInt(br.readLine());

            int result = input * input * 3;

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 23252
N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]

for i in range(N):
    L[i] = [L[i][0]+L[i][1], L[i][0], L[i][1]]
    
L.sort()
ans = 0
x = -10**10
for i in range(N):
    if x <= L[i][1]-L[i][2]:
        ans += 1
        x = L[i][0]

print(ans)

Measured memory_bytes: 72536
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
	double A, B;
	int H, M;
	cin >> A >> B >> H >> M;

	const int minutes = H * 60 + M;

	double Ax = A * cos(2 * M_PI * minutes / 720);
	double Ay = A * sin(2 * M_PI * minutes / 720);
	double Bx = B * cos(2 * M_PI * minutes / 60);
	double By = B * sin(2 * M_PI * minutes / 60);

	cout << fixed << setprecision(9) << sqrt((Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By)) << endl;
	return 0;
}


Measured memory_bytes: 4092
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

int main(){
	ll n;
	while(scanf("%lld",&n),n){
		ll ans=0,st=0,pre=0;
		while(n--){
			char c;
			scanf(" %c%*c",&c);
			if(c=='l')st^=1;
			else st^=2;
			if((st^pre)==3){
				ans++;
				pre^=3;
			}
		}
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define X first
#define Y second
#define LL long long
#define MP make_pair
#define PB push_back
#define SZ(a) (LL)(a.size())
const LL INF = 1000 * 1000 * 1000 + 47;
const LL LINF = INF * (LL)INF;
using namespace std;
const int MAX = 3005;
//int f[100005];

int N , mod;
int ways[MAX];
int ways2[MAX][MAX];

int pw2pw2[MAX * MAX ];
int pw2[MAX * MAX];
int c[MAX][MAX];
int add(int a, int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a , int b)
{
	return a - b < 0 ? a - b + mod : a - b;
}
int mult(int a , int b)
{
	return a * (LL)b % mod;
}
void init()
{
	ways2[0][0] = 1;
	for(int i = 0; i <= N; i++)
	{
		for(int j = 0; j <= i; j++)
		{
			ways2[i + 1][j] = add(ways2[i + 1][j] , mult(ways2[i][j] , j + 1));
			ways2[i + 1][j + 1] = add(ways2[i + 1][j + 1] , ways2[i][j]);
		}
	}
	for(int i = 0; i < MAX; i++)
	{
		c[i][0] = 1;
		for(int j = 1; j <= i; j++)
			c[i][j] = add(c[i - 1][j - 1] , c[i - 1][j]);
	}
	pw2[0] = 1;
	pw2pw2[0] = 2;
	for(int i = 1; i < MAX * MAX; i++)
	{
		pw2[i] = mult(pw2[i - 1] , 2);
		pw2pw2[i] = mult(pw2pw2[i - 1] , pw2pw2[i - 1]);
	}
	
}
int main() 
{
	ios_base::sync_with_stdio(0);
	
	cin >> N >> mod;
	init();
	for(int i = 0; i <= N; i++)
	{
		for(int j = 0; j <= i; j++)
			ways[i] = add(ways[i] , mult(ways2[i][j] , mult(pw2[j * (N - i)] , pw2pw2[N - i])));
		//cout << ways[i] << endl;
	}
	int ans = 0;
	for(int i = 0; i <= N; i++)
		if(i & 1)
			ans = sub(ans , mult(ways[i] , c[N][i]));
		else
			ans = add(ans , mult(ways[i] , c[N][i]));
	cout << ans;
	
}


Measured memory_bytes: 140032