akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdint>
#include<algorithm>

using u32 = std::uint_fast32_t;

int main() {
	u32 a, b, c;
	std::cin >> a >> b >> c;
	std::cout << std::min(b / a, c) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)
#define MAX ((ull)(1e9)+1)

int main(){
	int n;
	cin >> n;
	vector<pair<int, int>> v1, v2;
	for(int i=0; i<n; i++){
		int a, b;
		cin >> a >> b;
		v1.push_back(make_pair(a, b));
	}
	sort(v1.begin(), v1.end());
	for(int i=0; i<n; i++){
		int c, d;
		cin >> c >> d;
		v2.push_back(make_pair(c, d));
	}
	sort(v2.begin(), v2.end());
	int ans=0;
	vector<bool> b(n, false);
	for(int i=n-1; i>=0; i--){
		int y_min_idx=-1;
		for(int j=0; j<n; j++){
			if(v1[i].first<v2[j].first && v1[i].second<v2[j].second && b[j]==false){
				if(y_min_idx==-1 || v2[j].second<v2[y_min_idx].second) y_min_idx=j;
			}
		}
		if(y_min_idx!=-1){
			b[y_min_idx]=true;
			ans++;
		}
	}
	cout << ans << endl;
 	return 0;
}

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

int main() {
    long long int n, i, j, k, ans=0, march[5]={0,0,0,0,0};
    string s;
    cin >> n;
    while(cin >> s) {
        if(s[0] == 'M') march[0]++;
        if(s[0] == 'A') march[1]++;
        if(s[0] == 'R') march[2]++;
        if(s[0] == 'C') march[3]++;
        if(s[0] == 'H') march[4]++;
    }
    
    for(i=0; i<5; i++) {
        for(j=i+1; j<5; j++) {
            for(k=j+1; k<5; k++) {
                if(march[i] > 0 && march[j] > 0 && march[k] > 0) {
                    ans += march[i] * march[j] * march[k];
                }
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    double v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v,v+n);
    for(int i=0;i<n-1;i++){
        v[i+1]=(v[i]+v[i+1])/2;
    }
    cout<<fixed<<setprecision(15)<<v[n-1]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,M,L,S,T;
#define INF ( 1<<28 )
struct edge{
  int to,c;
};
struct state{
  int id,s,c;
  bool operator>(const state &st) const{
    return c > st.c;
  }
};
vector<edge> G[22];
int W[333][333];
int J[20];
int E[20];
int h[21][(1<<16)];
void solve(){
  fill(h[0],h[L+1],T+1);
  priority_queue<state,vector<state>,greater<state> > q;
  q.push( (state){L,0,0} );
  h[L][0] = 0;
  while( !q.empty() ){
    state st = q.top(); q.pop();
    int id = st.id;
    int bi = st.s;
    int c = st.c;
    //   cout << id <<  " " << bitset<6>(bi) << " " << c << endl;
    // cout << "JE " << J[id] << " " << E[id] << endl;
     if( id < L && (bi&(1<<id))==0 ){
      int sbi = (bi |(1<<id));
      if( h[id][sbi] > c + E[id] ){
	h[id][sbi] = c + E[id];
	q.push( (state){id,sbi,c+E[id]} );
      }
    } 
    for(int i=0;i<(int)G[id].size();i++){
      edge &e = G[id][i];
      if( h[e.to][bi] > e.c + c ){
	h[e.to][bi] = e.c + c;
	q.push( (state){e.to,bi,e.c+c} );
      }
    }
  }
  int res = 0;
  for(int i=0;i<(1<<L);i++){
    //    cout << S << " " << bitset<10>(i) << " "<< h[L][i] << endl;
    if( h[L][i] <= T ){
      res = max(res,__builtin_popcount(i));
    }
  }
  cout << res << endl;
}

int main(){
  while(cin >> N >> M >> L >> S >> T && ( N||M||L||S||T ) ){
    --S;
    fill(W[0],W[N],INF);
    for(int i=0;i<M;i++){
      int a,b,c;
      cin >> a>> b >> c ;
      --a;--b;
      W[a][b] = c;
      W[b][a] = c;
    }
    for(int i=0;i<N;i++) W[i][i] = 0;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	for(int k=0;k<N;k++)
	  W[j][k] = min(W[j][k],W[j][i] + W[i][k]);
    for(int i=0;i<L;i++){
      int j,e;
      cin >> j >> e;
      --j;
      J[i] = j;
      E[i] = e;
    }
    J[L] = S;
    for(int i=0;i<=L;i++){
      for(int j=i+1;j<=L;j++){
	int c = W[J[i]][J[j]];
	if( c < INF ) {
	  G[i].push_back( (edge){j,c} );
	  G[j].push_back( (edge){i,c} );
	}
      }
    }
  
    solve();

    for(int i=0;i<=L;i++) G[i].clear();
  }
}

Measured memory_bytes: 26008
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i,n) cin >> s.at(i);
    sort(s.begin(), s.end());
    string res;
    rep(i,n) res += s.at(i);
    cout << res << endl;
}


Measured memory_bytes: 256
def one(x):
    if x == 1:
        ret = 14
        return ret
    else:
        ret = x
        return ret

a, b = map(int, input().split())
if one(a) > one(b):
    print("Alice")
elif one(a) < one(b):
    print("Bob")
else:
    print("Draw")

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

int n;
int arr[21];

int main () {
	int cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 1; i <= n - 2; i++) {
		if (arr[i - 1] < arr[i] and arr[i] < arr[i + 1])
			cnt++;
		else if (arr[i - 1] > arr[i] and arr[i] > arr[i + 1])
			cnt++;
	}
	cout << cnt << "\n";
	return 0;
}

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

int main() {
  int64_t K,N;
  cin >> K >>N;
  int64_t count=0;
  for(;;){
    K = K/N;
    count ++;
    if(K==0)break;
    
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) ;
#define MOD 1000000007
#define ll long long 
#define pb push_back
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define ff first
#define ss second

using namespace std;



int main(){   

fastio
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt","w", stdout);
#endif
int n ;
string s;
cin>>n>>s;

vector<int> r , g;
unordered_map<int, bool> b;

for(int i =0 ; i< n ; i++){
	if(s[i]=='R')r.pb(i);
	if(s[i]=='G')g.pb(i);
	if(s[i]=='B')b[i]=true;
}

ll ans = r.size()*g.size()*b.size();

for(auto i : r)
	for(auto j : g){
      if((i+j)%2 ==0  && b[(i+j)/2])ans--;
      if(b[2*i -j])ans--;
      if(b[2*j -i])ans--;
	}

cout<<ans;

return 0;
}


Measured memory_bytes: 4140
#include<iostream>
#include<queue>
#include<iomanip>
#include<cstring>

using namespace std;

int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      double data[n][n];
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  cin>>data[i][j];

      queue<pair<pair<int,int>,double> >qu;
      for(int i=0;i<n;i++)
	  qu.push(make_pair(make_pair(1,i),1.0));

      double ans=0;
      double dp[m+2][n];
      memset(dp,0,sizeof(dp));
      while(!qu.empty())
	{
	  int cnt=qu.front().first.first;
	  int num=qu.front().first.second;
	  double score=qu.front().second;
	  qu.pop();
	  if(dp[cnt][num]>=score)
	    continue;
	  dp[cnt][num]=score;
	  if(cnt>=m)
	    {
	      ans=max(ans,score);
	      continue;
	    }
	  for(int i=0;i<n;i++)
	    {
	      qu.push(make_pair(make_pair(cnt+1,i),score*data[num][i]));
	    }
	}
      //      cout<<fixed<<setprecision(2)<<(1.231)<<endl;
      //      cout<<fixed<<setprecision(2)<<(1.235)<<endl;

      cout<<fixed<<setprecision(2)<<(ans)<<endl;
    }

}

Measured memory_bytes: 56964
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {

    while(1){
        int n;
        cin>>n;
        if(!n)break;
        vi v(n);
        rep(i,n){
            cin>>v[i];
            v[i]%=52;
        }
        string s;
        cin>>s;
        rep(i,s.size()){
            int d = v[i%n];
            if(s[i]>='a'&&s[i]<='z'){
                if(s[i]-'a'-d>=0){
                    s[i]-=d;
                }else{
                    d-=s[i]-'a'+1;
                    if(d>=26){
                        d-=26;
                        s[i]='z'-d;
                    } else {
                        s[i]='Z'-d;
                    }
                }
            }
            else if(s[i]>='A'&&s[i]<='Z'){
                if(s[i]-'A'-d>=0){
                    s[i]-=d;
                }else{
                    d-=s[i]-'A'+1;
                    if(d>=26){
                        d-=26;
                        s[i]='Z'-d;
                    } else {
                        s[i]='z'-d;
                    }
                }
            }
        }
        fin(s);
    }
}


Measured memory_bytes: 3216
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}



int n;
ll a[100005], b[100005];


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
    }

    ll ans = 0;
    for(int i=n;i>=1;i--){
        ll val = a[i]+ans;
        if(val % b[i] != 0)
            ans += b[i] - val%b[i];
    }

    cout<<ans;
    return 0;
}



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

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

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, D;

	cin >> N >> D;

	int X[N][D];

	rep(n, N)
		rep(d, D)
			cin >> X[n][d];

	double sq;
	int sum, total = 0;
	rep(i, N) {
		repp(n, i+1, N) {
			sum = 0;
			rep(d, D)
				sum += abs(X[i][d] - X[n][d]) * abs(X[i][d] - X[n][d]);

			sq = sqrt(sum);
			if (ceil(sq) == floor(sq)) total++;
		}
	}

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define N 10001
int isprime(int n)
{
    int flag=1,i;
    for(i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            flag=0;
            break;
        }
    }
    return flag;
}
int main()
{
    int num[N],i,n;
    while(scanf("%d",&n)!=EOF)
    {
        int s=0;
        for(i=1;i<=n;i++)
            scanf("%d",&num[i]);
        for(i=1;i<=n;i++)
        {
            if(isprime(num[i]))
                s++;
        }
        printf("%d\n",s);
    }
}



Measured memory_bytes: 2036
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

void solve() {
    int n;
    cin >> n;
    priority_queue<double, vector<double>, greater<double>> q;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        q.push(x);
    }
    for (int i = 0; i < n - 1; i++) {
        auto x = q.top();
        q.pop();
        auto y = q.top();
        q.pop();
        q.push((x + y) / 2);
    }
    cout << q.top() << endl;
}

int main(void) {
    FAST_IO;
    
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////
const string MINUSINF = "-";

void chmax(string &a, string b) {
	if (a == MINUSINF)a = b;
	else if (a.size() < b.size())a = b;
	else if (a.size() == b.size()) {
		if (a < b)a = b;
	}
}//&を付けることで変数を書き換えられるよ！

ll match[10] = { 2,5,5,4,5,6,3,7,6 };
string dp[11000];//dp[N]でマッチをN本使ってできる数値の最大値
int main() {
	int N, M; cin >> N >> M;
	vector<int>A(M);
	for (int i = 0; i < M; ++i)cin >> A[i];
	for (int i = 0; i < 11000; ++i) {
		dp[i] = MINUSINF;
	}
	dp[0] = "";
	for (int i = 0; i <= N; ++i) {
		if (dp[i] == MINUSINF)continue;
		for (auto a : A) {
			chmax(dp[i + match[a - 1]], dp[i] + (char)('0' + a));
		}
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 43776
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n;
long long k;
pair<int,int> p[100010];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>p[i].first>>p[i].second;
	}
	sort(p,p+n);
	long long cnt=0;
	for(int i=0;i<n;i++){
		cnt+=p[i].second;
		if(cnt>=k){
			cout<<p[i].first<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#define s(a,b) (t=a,a=b,b=t)
char p[9],m;a,b,c,d,e,f,t,r,q;main(n){while(scanf("%d",&n),n){r=a=1,b=6,c=2,d=5,e=3,f=4;while(n--){scanf("%s",p);m=*p;if(m==76||m==82){s(c,e);s(d,f);q=m^76?s(e,f):s(c,d);}else if(m==78||m==83){s(a,c);s(b,d);q=m^83?s(c,d):s(a,b);}else{s(a,e);s(b,f);q=m^69?s(e,f):s(a,b);}r+=a;}printf("%d\n",r);}}

Measured memory_bytes: 0
h,w=map(int,input().split())
M=[]
for i in range(h):
    M.append(list(map(int,input().split())))

ANS=[]
cnt=0
for i in range(h):
    for j in range(w):
        if M[i][j]%2==1:
            for x,y in [(0,1),(1,0)]:
                if (0<=i+x and i+x<h) and (0<=j+y and j+y<w):
                    M[i+x][j+y]+=1
                    cnt+=1
                    ANS.append([i+1,j+1,x+i+1,y+j+1])
                    break
print(cnt)
for i in range(cnt):
    print(*ANS[i])

Measured memory_bytes: 30296
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    ll n,k;
    cin >> n >> k;vector<ll>a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    for(int i=k;i<n;i++){
        if(a.at(i-k)<a.at(i)){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
}
    



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

int main() {
  int K, X;
  cin >> K >> X;
  X -= K;
  for(int i = 0; i < 2 * K - 1; i++) {
    X += 1;
    cout << X << " ";
  }
  cout << endl;
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, k;
    cin >> n >> k;

    ll a[n] = {};
    rep(i,n) cin >> a[i];

    ll ans = 1001001001001001001;

    rep(i,1<<n){
        bitset<20> f(i);
        if(__builtin_popcount(i) != k) continue;
        ll tmp = 0;
        int now = 0;
        rep(j,n){
            if(a[j] > now){
                now = a[j];
            }else{
                if(f[j] == 0) continue;
                tmp += now + 1 - a[j];
                now = now + 1;
            }
        }
        ans = min(ans, tmp);
    }
    
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3564
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int wordNum = sc.nextInt();
        sc.nextLine();
        String words = sc.nextLine();
        char[] charText = new char[wordNum];
        int halfNum = wordNum/2;

        if(wordNum%2!=0){
            System.out.println("No");
        }else{
            charText=words.toCharArray();
            for(int j=0;j<halfNum;j++){
                if(charText[j]!=charText[j+halfNum]){
                    System.out.println("No");
                    return;
                }
            }
            System.out.println("Yes");
        }
    }
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,a,b;cin>>n>>a>>b;

  ll setc = (n/(a+b));
  ll result = setc*a;

  ll remain = n-setc*(a+b);
  if(remain >= a)result += a;
  else result += remain;

  cout<<result;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0]
for _ in range(N):
    A.append(int(input()))
S = set()
i = 1
cnt = 0
while i != 2 and not i in S:
    S.add(i)
    i = A[i]
    cnt += 1
if i == 2:
    print(cnt)
else:
    print(-1)

Measured memory_bytes: 13216
<?PHP 
$input = fgets(STDIN);
$value = sscanf($input, '%s %s %s');

$poor = false;
if ($value[0] === $value[1] && $value[1] !== $value[2])  $poor = true;
if ($value[1] === $value[2] && $value[2] !== $value[0])  $poor = true;
if ($value[0] === $value[2] && $value[0] !== $value[1])  $poor = true;

if($poor) {
    echo "Yes\n";
}else {
    echo "No\n";
}


Measured memory_bytes: 4604
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);


int n;
vector<int> a;

void solve() {
    unordered_map<int, int> mp;
    rep(i, n) mp[a[i]]++;
    vector<pair<ll, ll> > v(mp.begin(), mp.end());
    // sort from bigger.
    sort(v.begin(), v.end(), [](pair<ll, ll> a, pair<ll, ll> b) { return a.second > b.second; });
    vector<int> only_one;
    stack<int> twos;
    each(i, v) {
        if (i.second == 1) only_one.emplace_back(i.first);
        else if (i.second % 2 != 0) only_one.emplace_back(i.first);
        else if (i.second % 2 == 0) twos.push(i.first);
    }
    int minus = 0;
    while (twos.size() >= 2) {
        only_one.emplace_back(twos.top());
        twos.pop();
        only_one.emplace_back(twos.top());
        twos.pop();
    }
    cout << only_one.size() - minus << endl;
}

int main() {
    cin >> n;
    a.resize(n);
    rep(i, n)cin >> a[i];
    solve();
    return 0;
}

Measured memory_bytes: 7332
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  int a, b;
  cin >> a >> b;
  REP(i, max(a, b)) { cout << min(a, b); }
  cout << endl;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int t[] = {60, 80, 100, 120, 140, 160};
int v[] = {2, 5, 10, 15, 20, 25};
int c[] = {600, 800, 1000, 1200, 1400, 1600};

int main()
{
    for(int n, m; cin >> n && n && !(m = 0); cout << m << endl) while(n--)
	{
		int x, y, h, w;
		cin >> x >> y >> h >> w;
		
		rep(j, 6) if(x + y + h <= t[j] && w <= v[j])
		{
			m += c[j];
			break;
		}
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s;

    int ans[26] = {};
    while (getline(cin, s))
    {
        rep(i, s.length())
        {
            if (s[i] >= 'a' && s[i] <= 'z')
            {
                ans[s[i] - 'a']++;
            }
            else if (s[i] >= 'A' && s[i] <= 'Z')
            {
                ans[s[i] - 'A']++;
            }
        }
    }

    rep(i, 26)
    {
        cout << char('a' + i) << " : " << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstring>
using namespace std;

string s="CODEFESTIVAL2016",s1;
int ans;

int main()
{
	cin>>s1;
	for(int i=0;i<s.length();++i) if(s1[i]!=s[i]) ans++;
	cout<<ans<<endl;
    return 0;
} 

Measured memory_bytes: 384
dishes = 5.times.map do
  gets.chomp.to_i
end

a = dishes.map do |i|
  (i % 10) == 0 ? i : (i + 10 - i % 10)
end.inject(:+)

b = dishes.map do |i|
  (i % 10) == 0 ? 0 : 10 - i % 10
end.max

puts a - b


Measured memory_bytes: 1788
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n;
	while (cin>>n,n){
		vector<int> dia(24 * 60 * 60, 0);
		REP(i,n){
			int start;
			int goal;
			string s;
			cin >> s;
			start=atoi(s.substr(0, 2).c_str()) * 60 * 60 + atoi(s.substr(3, 2).c_str()) * 60 + atoi(s.substr(6, 2).c_str());
			cin >> s;
			goal = atoi(s.substr(0, 2).c_str()) * 60 * 60 + atoi(s.substr(3, 2).c_str()) * 60 + atoi(s.substr(6, 2).c_str());
			for (int i = start; i < goal; i++){
				dia[i]++;
			}
		}
		int ans=0;
		REP(i, dia.size()){
			ans = max(ans, dia[i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3484
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  vector<int> a(n + 2);
  a[0] = 0;
  a[n + 1] = 0;
  for(int i = 1;i < n + 1;i++)cin >> a[i];
  ll all = 0;
  for(int i = 0;i < n + 1;i++){
    all += abs(a[i] - a[i + 1]);
  }
  for(int i = 1;i < n + 1;i++){
    cout << all - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << endl;
  }
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		
		int c = 0;
		if(A>=13) {
			c = B;
		}else if(A>=6) {
			c = B/2;
		}else {
			c = 0;
		}
		
		System.out.println(c);
		
		sc.close();
		
	}

}

Measured memory_bytes: 21588
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;


Int gcd(Int a, Int b)
{
	if (a % b == 0){
		return(b);
	}
	else{
		return(gcd(b, a % b));
	}
}

int main() {

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

	Int N;
	cin >> N;

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

	vector<Int> L(N);
	vector<Int> R(N);

	//Lの作成
	L[0] = a[0];
	for (Int i = 0; i < N-1; i++) {
		if (i == 0)L[i + 1] = gcd(a[i], a[i + 1]);
		else L[i + 1] = gcd(L[i], a[i + 1]);
	}

	//Rの作成
	R[N - 1] = a[N - 1];
	for (Int i = N-1; i >= 1; i--) {
		if (i == N-1)R[i - 1] = gcd(a[i], a[i - 1]);
		else R[i - 1] = gcd(R[i], a[i - 1]);
	}

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		if (i == 0) {
			ans = max(ans, R[1]);
			continue;
		}
		if (i == N - 1) {
			ans = max(ans, L[N - 2]);
			continue;
		}
		ans = max(ans, gcd(L[i - 1], R[i + 1]));
	}

	cout << ans;

}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int rev_mod(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

int main(){
	long long int X, Y;
	cin >> X >> Y;
	if((X + Y) % 3 != 0 || X * 2 < Y || Y * 2 < X){
		cout << 0 << endl;
		return 0;
	}
	long long int n = (X + Y) / 3;
	long long int diff = X - Y;
	long long int k = (n - diff) / 2;
	long long int ans = 1;
	for(int i = 1; i <= n; i++){
		ans *= i;
		ans %= MOD;
	}
	for(int i = 1; i <= k; i++){
		ans *= rev_mod(i);
		ans %= MOD;
	}
	for(int i = 1; i <= n - k; i++){
		ans *= rev_mod(i);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include <iomanip>

using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  
  int ans=0;
  
  if(n==1){
    ans=m*(m-1)/2;
  }else if(m==1){
    ans=n*(n-1)/2;
  }else{
    ans=n*(n-1)/2 + m*(m-1)/2;
  }
  
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007

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

  int N; cin>>N;
  vector<vector<int>> A(2, vector<int>(N));
  rep(i,2) rep(j,N) cin>>A[i][j];

  int res = 0;
  rep(i, N) {
    int sum = A[0][0];
    int ni=0, nj=0;
    rep(j, N) {
      if(i==j) ++ni;
      else ++nj;
      sum+=A[ni][nj];
    }
    res = max(res, sum);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

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

int howdiv(int n,int d){
  if(n%d) return 0;
  else return 1+howdiv(n/d,d);
}

int main(){
  int n;
  cin >> n;
  vector<ll> primes(0);
  for(ll i=2;i<1000;i++){
    if(isPrime(i))primes.push_back(i);
  }
  int m = primes.size();
  ll dp[1001][m] = {0};
  rep1(i,1000){
    rep(j,m){
      dp[i][j] = dp[i-1][j] + howdiv(i,primes[j]);
    }
  }
  ll ans = 1;
  rep(j,m){
    ans *= (dp[n][j]+1);
    ans %= 1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1536
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n, ans, i int64
	ans = 0

	fmt.Sscan(getNextLine(scanner), &n)

	orgN := n

	divs := make([]int64, 0)

	for i = 1; i*i <= n; i++ {
		if n%i == 0 {
			divs = append(divs, i)
			if n > i*i {
				divs = append(divs, n/i)
			}
		}
	}

	for j := 0; j < len(divs); j++ {
		if divs[j] == 1 {
			continue
		}
		if orgN/(divs[j]-1) == orgN%(divs[j]-1) {
			ans += divs[j] - 1
		}
	}
	fmt.Println(ans)
}


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

#define ll long long
#define arrInput(arr, end)       \
    for (ll i = 0; i < end; i++) \
        cin >> arr[i];

#define MOD 1000000007

ll fastpow(ll a, ll n, ll m)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
            res = (res * a) % m;
        n >>= 1;
        a = (a * a) % m;
    }
    return res;
}

ll add(ll a, ll b, ll m)
{
    return (a % m + b % m) % m;
}

ll sub(ll a, ll b, ll m)
{
    return ((a - b) % m + m) % m;
}

ll mul(ll a, ll b, ll m)
{
    return (a % m * b % m) % m;
}

ll div(ll a, ll b, ll m)
{
    return mul(a, fastpow(b, m - 2, m), m);
}

ll productSum(ll a[], ll n)
{
    ll arSum = 0;
    for (int i = 0; i < n; i++)
        arSum = add(arSum, a[i], MOD);

    ll arSumSq = mul(arSum, arSum, MOD);

    ll indSqSum = 0;
    for (int i = 0; i < n; i++)
        indSqSum = add(indSqSum, mul(a[i], a[i], MOD), MOD);

    return div(sub(arSumSq, indSqSum, MOD), 2, MOD);
}

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

    ll arr[n];
    arrInput(arr, n);

    cout << productSum(arr, n) << endl;

    return 0;
}


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

using namespace std;

#define INF 100000
#define MAXN 25000
#define MAXD 200

struct Edge
{
    int t, c, r;
};

char grid[MAXD+5][MAXD+5];
int w, h;
int prv[MAXN+5], vis[MAXN+5];
vector<Edge> edge[MAXN+5];

int get(int r, int c)
{
    if (r < 0 || r >= h || c < 0 || c >= w) return w*h*2+1;
    return 2*(r*w+c);
}

int add(int f, int t, int c)
{
    Edge a = { t, c, (int)edge[t].size() };
    Edge b = { f, 0, (int)edge[f].size() };
    edge[f].push_back(a);
    edge[t].push_back(b);
}

int maxflow(int n, int s, int t)
{
    int mf = 0;
    while (true) {
        queue<int> Q;
        Q.push(s);
        fill(vis, vis+n, false);
        vis[s] = true;
        while (!Q.empty()) {
            int v = Q.front();
            Q.pop();
            for (int i = 0; i < edge[v].size(); ++i) {
                Edge &e = edge[v][i];
                if (!vis[e.t] && e.c > 0) {
                    vis[e.t] = true;
                    prv[e.t] = e.r;
                    Q.push(e.t);
                }
            }
        }
        if (!vis[t]) break;
        int flow = INF;
        for (int v = t; v != s; v = edge[v][prv[v]].t) {
            Edge &e = edge[v][prv[v]];
            Edge &r = edge[e.t][e.r];
            flow = min(flow, r.c);
        }
        for (int v = t; v != s; v = edge[v][prv[v]].t) {
            Edge &e = edge[v][prv[v]];
            Edge &r = edge[e.t][e.r];
            e.c += flow;
            r.c -= flow;
        }
        mf += flow;
    }
    return min(mf, INF);
}

int main()
{
    scanf("%d%d", &h, &w);
    int s = 2*h*w, t = 2*h*w+1;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) grid[i][j] = s[j];
    }

    int dr[] = {1,-1,0,0}, dc[] = {0,0,-1,1};
    for (int r = 0; r < h; ++r) {
        for (int c = 0; c < w; ++c) {
            int idx = get(r,c);
            if (grid[r][c] == 'X') {
                add(s, idx, INF);
                add(idx, idx+1, INF);
            }
            else add(idx, idx+1, 1);
            for (int d = 0; d < 4; ++d) {
                int nr = r+dr[d], nc = c+dc[d];
                int nidx = get(nr, nc);
                add(idx+1, nidx, INF);
            }
        }
    }
    int f = maxflow(2*h*w+2, s, t);
    printf("%d\n", (f == INF) ? -1 : f);
    return 0;
}


Measured memory_bytes: 3328
import copy

N, K = map(int, input().split())
a = list(map(int, input().split()))

ans = [0] * N
def loop():
    global a
    ruir = [0] * (N + 1)
    ruil = [0] * (N + 1)
    for i in range(N):
        ruir[i] += 1
        tmp = i + a[i]
        if tmp < N:
           ruir[tmp + 1] -= 1
    for i in range(N):
        ruir[i + 1] += ruir[i]

    for i in reversed(range(N)):
        if a[i] - 0.5 > -1:
            ruil[i - 1] += 1
            tmp = i - a[i]
            if tmp > 0:
                ruil[tmp - 1] -= 1
    for i in reversed(range(N)):
        ruil[i - 1] += ruil[i]
    cnt = 0
    for i in range(N):
        add = ruir[i] + ruil[i]
        if add > N:
            add = N
        if add == N:
            cnt +=1
        ans[i] = add
    if cnt == N:
        print(*ans)
        exit()
    a = copy.deepcopy(ans)

for i in range(K):
    loop()
print(*ans)

Measured memory_bytes: 179388
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int n,m,cnt=0;
int head[410000],nxt[410000],to[410000],val[410000];
int ma=0,mi=0;
int q[1000000],dis[100100],f[100100],vis[100100];
void addedge(int x,int y,int z)
{
    cnt++;
    nxt[cnt]=head[x];
    head[x]=cnt;
    to[cnt]=y;
    val[cnt]=z;
}
bool spfa(int x)
{
    int l=0,r=1;
    q[1]=x;vis[x]=1;dis[x]=0;
    while(l<r)
    {
        int u=q[++l];
        for(int i=head[u];i!=-1;i=nxt[i])
        {
            int v=to[i];
            if(dis[v]==12345678987654321)
            {
                dis[v]=dis[u]+val[i];
                ma=max(ma,dis[v]);
                mi=min(mi,dis[v]);
                if(ma-mi>1e9) return 0;
                vis[v]=1;
                if(!f[v]) q[++r]=v,f[v]=1;
            }
            else if(dis[v]!=dis[u]+val[i]) return 0;
        }
        f[u]=0;
    }
    return 1;
}
signed main()
{
    memset(head,-1,sizeof(head));
    for(int i=1;i<=100000;i++)
        dis[i]=12345678987654321;
    scanf("%lld%lld",&n,&m);
    if(!m) {printf("Yes");return 0;}
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%lld%lld%lld",&x,&y,&z);
        addedge(x,y,z);
        addedge(y,x,-z);
    }
    for(int i=1;i<=n;i++)
        if(!vis[i]) {if(!spfa(i)) {printf("No");return 0;}}
    printf("Yes");
    return 0;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

vector <int >prime_factorize( ll N ){
	vector <int > vec;
	int lim = sqrt( N ) + 1;
	rep( i, 2, N + 1 ){
		if (i >= lim){
			vec.push_back( N );
			break;
        }
		if (N % i == 0){
			vec.push_back( i );
			while(N % i == 0)
				N /= i;
		}
	}
	return vec;
}
int main( void ){
	// initialize();
	int N;
	cin >> N;
    vector<int> inputs(N), vec(N-1);
    rep(i,0,N)
        scanf("%d", &inputs[i]);
    int GCD = __gcd(inputs[0], inputs[1]);
    vec[0] = GCD;
    rep(i,2,N){
        GCD = __gcd(GCD, inputs[i]);
        vec[i-1];
    }
    if (GCD != 1){
        printf("not coprime\n");
        return 0;
    }
    vector<bool> used((int)(1e6+5), false);
    for(auto input:inputs){
        const auto &vec = prime_factorize( input );
        for(auto v:vec){
            if (used[v]){
                printf("setwise coprime\n");
                return 0;
            }
            used[v] = true;
        }
    }
    printf("pairwise coprime\n");

}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 11020
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  string s;
  int k;
  cin>>s>>k;
  set<string> memo;
  int l=s.size();
  for(int i=1;i<=min(l,5);i++){
    for(int j=0;j<=l-i;j++){
      memo.insert(s.substr(j,i));
    }
  }
  auto itr=memo.begin();
  for(int i=0;i<k-1;i++) itr++;
  cout<<*itr<<endl;
  return 0;
}



Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
int main(){
 int H,W;
  cin>>H>>W;
  vector<vector<char>>in(H,vector<char>(W));
  for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
      cin>>in[i][j];
    }
  }
  vector<vector<char>>out(H,vector<char>(W,'o'));
  vector<int>m(H);
  //空白行のマーク
  for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
      if(in[i][j]=='#') {
        m[i]=1;
        break;
      }
      if(j==W-1){
        for(int k=0;k<W;k++){
          out[i][k]='x';
        }
      }
    }
  }
  //空白列のマーク
  for(int j=0;j<W;j++){
	for(int i=0;i<H;i++){
      if(in[i][j]=='#') break;
      if(i==H-1){
        for(int k=0;k<H;k++){
          out[k][j]='x';
        }
      }
    }
  }
  
  for(int i=0;i<H;i++){
	for(int j=0;j<W;j++) {
      if(out[i][j]=='o') cout<<in[i][j];
      if(j==W-1&&m[i]==1) cout<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int n;
int a;
int visit[51][51][2501] = {};
long long memo[51][51][2501] = {};
vector<int> x;

long long dfs(int d, int num, int sum){
  if(d == n) return (num * a == sum ? 1 : 0 );
  if(visit[d][num][sum] == 1) return memo[d][num][sum];

  long long cnt = 0;
  // カード足さない
  cnt += dfs(d+1, num, sum);
  // カード足す
  cnt += dfs(d+1, num+1, sum+x[d]);

  visit[d][num][sum] = 1;
  memo[d][num][sum] = cnt;
  return cnt;
}

int main(){
  cin >> n >> a;
  x.resize(n);
  for(int i = 0; i < n; i++)
    cin >> x[i];
  // 0枚で0のときに1になる
  cout << dfs(0,0,0) - 1 << endl;
}


Measured memory_bytes: 16256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b,c,d;
    int ans=mod;
    int mia=mod,mib=mod;
    int g[100010];
    int h[100010];
    cin >>a>>b>>n;
    for(int i=0;i<a;i++){
      cin >>g[i];
      mia=min(mia,g[i]);
    }
    for(int i=0;i<b;i++){
      cin >>h[i];
      mib=min(mib,h[i]);
    }
    ans=mia+mib;
    for(int i=0;i<n;i++){
      int x,y,c;
      cin >>x>>y>>c;
      ans=min(ans,g[x-1]+h[y-1]-c);
    }
    cout <<ans<<'\n';
    return (0);
}


Measured memory_bytes: 1024
#include "iostream"
using namespace std;
int main() {
	long long N;
	cin >> N;
	long long ans = 0;
	for (long long i = 0; i < N; i++) {
		long long l, r;
		cin >> l>>r;
		long long xd = r - l + 1;
		ans = ans + xd;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// Aizu Vol-10 1009: Greatest Common Divisor
// 2017.8.18 bal4u@uu

#include <stdio.h>

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

int main()
{
	int a, b;

	while (scanf("%d%d", &a, &b) == 2) printf("%d\n", gcd(a, b));
	return 0;
}

Measured memory_bytes: 596
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	int x;
	cin>>x;
	int ans=2*(x/11);
	if(x%11!=0) ans++;
	if(x%11>6) ans++;
	cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll ;
typedef long double ld ;
#define FAST(IO) ios_base::sync_with_stdio(false);cin.tie(NULL);
#define r return
/*fixed << setprecision(9) useful float shit*/
#define e "\n"
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define loop(n) for(ll i=0;i<n;i++)
#define gcd __gcd
#define mod 1000000007
ll n , a[100010] , dp[100010];
ll solve(ll i){
    if(i==n)return 0 ;
    if(i==n-1)return 0;
    if(dp[i]!=-1)return dp[i] ;
    if(i==n-2)return dp[i]= abs(a[i]-a[i+1])+ solve(i+1) ;
    return dp[i]=min(abs(a[i]-a[i+1])+solve(i+1) , abs(a[i]-a[i+2])+solve(i+2)) ;
}
int main(){
    FAST(IO)
    memset(dp , -1 , sizeof(dp)) ;
    cin >> n ;
    loop(n)cin >> a[i] ;
    cout << solve(0);
     r 0 ;
}


Measured memory_bytes: 3328