akhauriyash/Code-Regression huggingface dataset:
/*A - Registration*/
#include <bits/stdc++.h>
using namespace std;

int main(){

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

	string s;
	string t;

	cin >> s >> t;

	bool same = true;

	for (int i = 0; i < s.size() ; ++i)
	{
		if(s[i] != t[i])
			same = false;
	}

	if(same)
		cout << "Yes";
	else
		cout << "No";
	
	return 0;
}

Measured memory_bytes: 3588
class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 2**((self.n-1).bit_length())
        self.op = op # operation
        self.e = e # identity element
        self.v = [None]*(2*self.N-1)
        
        # construction
        for i in range(self.N):
            self.v[i + self.N - 1] = lst[i] if i < self.n else self.e
        for i in range(self.N - 2, -1, -1):
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2])
        
    # update a_i to be x 
    def update(self, i, x):
        i += self.N - 1
        self.v[i] = x
        while i > 0:
            i -= 1
            i >>= 1
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i+2])
    
    # returns answer for the query interval [l, r)
    def query(self, l, r):
        assert l < r
        left = l + self.N - 1
        right = r + self.N - 1
        L = self.e
        R = self.e
        while left < right:
            if left % 2 == 0: # left is even
                L = self.op(L, self.v[left])
                left += 1
            if right % 2 == 0: # right is even
                right -= 1
                R = self.op(self.v[right], R)
            left -= 1
            left >>= 1
            right >>= 1
        return self.op(L, R)

N = int(input())
*A, = map(int, input().split())
total = sum(A)
st = SegmentTree(A, lambda x,y:x+y, 0)
ans = 10**18
for i in range(N-1):
    snuke = st.query(0, i+1)
    arai = total - snuke
    ans = min(ans, abs(arai - snuke))
print(ans)

Measured memory_bytes: 23804
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long
#define BS 50
signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n),bit(BS,0);
  for(int i=0;i<n;++i){
    cin>>a[i];
    for(int j=0,t=a[i];t>0;++j,t>>=1)bit[j]+=t&1;
  }
  
  vector<bool> grd(BS,false),lim(grd);
  for(int i=0;i<BS;++i)grd[i]=bit[i]*2<n;
  for(int i=0,t=k;t>0;++i,t>>=1)lim[i]=t&1;
  
  int r=0;
  auto f=[](vector<bool>& v,vector<int>& a){
    int x=0,s=0;
    for(int i=BS-1;i>0;--i,x<<=1,x+=v[i]);
    for(auto& i:a)s+=(i^x);
    return s;
  };
  for(int i=0;i<BS;++i){
    int j=BS-1-i;
    if(grd[j]&&lim[j]){
      grd[j]=false;
      r=max(r,f(grd,a));
      grd[j]=true;
    }
    if(lim[j]&&!grd[j])break;
    if(!lim[j]&&grd[j])grd[j]=false;
  }
  cout<<max(r,f(grd,a));
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  int n;
  cin>>n;
  string tmp;
  bool ans=false;
  for(int i=0;i<n;i++){
    cin>>tmp;
    if(tmp=="Y"){
      ans=true;
      break;
    }
  }
  if(ans){
    cout<<"Four"<<endl;
  }else{
    cout<<"Three"<<endl;
  }
}


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

int main(){
  int N, tmp;
  cin >> N;
  int result[N];
  for (int i = 0; i < N; i++){
    cin >> tmp;
    result[tmp - 1] = i + 1;
  }
  for (int i = 0; i < N; i++){
    cout << result[i];
    if(i != N-1) cout << " ";
  }
  return 0;
}

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


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

int n, m;
bool g[705][705];
int cnt[2];
int color[705];
bool f[2][705];

bool dfs(int u,int c) {
	color[u] = c; cnt[c]++;
	for (int v = 1; v <= n; ++v) if (g[u][v]) {
		if (~color[v]) {
			if (color[u] == color[v]) return 0;
		}
		else {
			if (!dfs(v, c ^ 1)) return 0;
		}
	}
	return 1;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) color[i] = -1;
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) g[i][j] = i != j;
	for (int i = 1; i <= m; ++i) {
		int u, v; cin >> u >> v;
		g[u][v] = 0, g[v][u] = 0;
	}
	f[0][0] = 1;
	for (int u = 1; u <= n; ++u) if (color[u] == -1) {
		cnt[0] = cnt[1] = 0;
		if (!dfs(u, 0)) return cout << -1 << '\n',0;
		for (int i = 0; i <= n - cnt[0]; ++i) f[1][i + cnt[0]] |= f[0][i];
		for (int i = 0; i <= n - cnt[1]; ++i) f[1][i + cnt[1]] |= f[0][i];
		for (int i = 0; i <= n; ++i) f[0][i] = f[1][i], f[1][i] = 0;
	}
	int mn = n * (n - 1) / 2;
	for (int i = 0; i <= n; ++i) if (f[0][i]) mn = min(mn, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	cout << mn << '\n';
}

Measured memory_bytes: 768
import sys
t={'o':1,'x':-1,'s':0}
for l in sys.stdin:
 d=[t[s]for s in l.strip()]
 a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])]
 print('o'if 3 in a else'x'if -3 in a else'd')

Measured memory_bytes: 5572
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    if (p[i] < p[i + 1] and p[i+1] <p[i+2]) or (p[i + 2] < p[i + 1] and p[i+ 1] < p[i]) :
        ans+=1
print(ans)

Measured memory_bytes: 9088
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
const int INF = (int)2e9 + 1;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, temp;
  cin >> N;
  int n2 = 1 << N;

  vector<int> seq;
  vector<int> slime;
  vector<int> birth;

  for (int i = 0; i < n2; i++) {
    cin >> temp;
    seq.push_back(temp);
  }
  sort(seq.begin(), seq.end());  //昇順
  slime.push_back(seq.back());
  seq.pop_back();
  sort(seq.begin(), seq.end(), greater<int>());  //降順

  for (int i = 0; i < N; i++) {
    int cnt = 0, idx2 = 1 << i;
    for (int j = 0; cnt < idx2 && j < seq.size(); j++) {
      if (seq[j] >= slime.back()) continue;
      birth.push_back(seq[j]);
      seq[j] = -INF;
      birth.push_back(slime.back());
      slime.pop_back();
      cnt++;
    }
    if (!slime.empty()) {
      puts("No");
      return 0;
    }
    while (!birth.empty()) {
      slime.push_back(birth.back());
      birth.pop_back();
    }
    sort(seq.begin(), seq.end(), greater<int>());  //降順
    sort(slime.begin(), slime.end());              //昇順
    if (i != N - 1) {
      for (int j = 0; j < cnt; j++) {
        seq.pop_back();
      }
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 4212
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int c[3][3];
    REP(i, 3)
    {
        REP(j, 3)
        {
            cin >> c[i][j];
        }
    }

    REP(i, 3)
    {
        REP(j, 3)
        {
            if (!((c[i][j] - c[(i + 1) % 3][j]) == (c[i][(j + 1) % 3] - c[(i + 1) % 3][(j + 1) % 3]) &&
                  (c[i][j] - c[(i + 1) % 3][j]) == (c[i][(j + 2) % 3] - c[(i + 1) % 3][(j + 2) % 3])))
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    REP(i, 3)
    {
        REP(j, 3)
        {
            if (!((c[j][i] - c[j][(i + 1) % 3]) == (c[(j + 1) % 3][i] - c[(j + 1) % 3][(i + 1) % 3]) &&
                  (c[j][i] - c[j][(i + 1) % 3]) == (c[(j + 2) % 3][i] - c[(j + 2) % 3][(i + 1) % 3])))
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

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

int main(){
  int x,y; cin>>x>>y;
  int p[3] = {300000,200000,100000};
  
  int sum=0;
  if(x<4){sum = sum+p[x-1];}
  if(y<4){sum = sum+p[y-1];}
  if(x==1&&y==1){sum = sum+400000;}
  
  cout << sum;
  
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const ll MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}


int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) cout<< "YES" <<endl;
  else cout<< "NO" <<endl;
}


Measured memory_bytes: 256
/*
	Time created : 10/14/2019 04:05 pm.
	Name : D - Disjoint Set of Common Divisors
	Author : Minh Duc Phung - Team4 - ITPTIT
*/
#include<bits/stdc++.h>

#define fi first  
#define se second
#define mp make_pair
#define pb push_back
 
using namespace std;
typedef long long i64;
typedef pair < int,int > pii;
typedef vector <int> vi;
typedef vector <vi> vii;

const int N = 1e5+5;
const i64 mod = 1e9+7;
const i64 inf = LLONG_MAX;

inline i64 gcd(i64 a, i64 b) {i64 r; while(b){ r = a % b; a = b; b = r;} return a;}
inline i64 modPow(i64 n, i64 k) {i64 r=1; for(;k;k>>=1,n=n*n%mod){if(k&1)r=r*n%mod;}return r;}
inline i64 C(int k, int n){i64 r=1;for(int i=1;i<=k;i++,n--)r=r*n%mod*modPow(i,mod-2)%mod;return r%mod;}
inline int prime(int x){if(x < 2 ) return 0;if(x <=3) return 1;if(x%2 == 0 || x%3 == 0) return 0;int i = 5;
                        while(i * i <= x){if(x%i == 0 || x%(i+2) == 0) return 0;i += 6;}return 1;}

int dx[] = {-1,0,0,1};
int dy[] = {0,-1,1,0};
i64 a , b ;
vi ua,ub,uc,kq;

void input(){
    cin >> a >> b;
}

void solve(){
    long long  t=gcd(a,b);
    long long  k=gcd(a,b);
    long long  sum=1;
    for(long long  i=2;i*i<=k;i++){
        if (t%i==0){t=t/i;sum++;}
        while(t%i==0){t=t/i;}
    }
    if (t!=1) sum++;
    cout <<sum;
    
}
int main(){
	//freopen("INPUT.in", "r", stdin);
    //freopen("OUTPUT.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin>>t;
	while(t--){input(); solve();}
	return 0;
}

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n, k;
	cin >> n >> k;	
	n %= k;
	cout << min(n, k-n) << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const string NAME = "Thebai";
long long m, n, p, k;

int main()
{
    cin >>m >>n >>p >>k;
    if(k <=m)
    	cout <<k;
    else if(k <= m+n)
    		cout <<m;
    else 
    	cout <<m - (k - m - n);
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void){
  double w;
  while(scanf("%lf",&w)!=EOF){
    if(w>91)
      puts("heavy");
    else if(w>81)
      puts("light heavy");
    else if(w>75)
      puts("middle");
    else if(w>69)
      puts("light middle");
    else if(w>64)
      puts("welter");
    else if(w>60)
      puts("light welter");
    else if(w>57)
      puts("light");
    else if(w>54)
      puts("feather");
    else if(w>51)
      puts("bantam");
    else if(w>48)
      puts("fly");
    else
      puts("light fly");
  }
  return 0;
}

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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int d,g; cin>>d>>g;
  vector<int> p(d, 0);
  vector<int> c(d, 0);
  vector<int> t(d, 0);
  for (int i=0; i<d; i++) {
    cin >> p[i] >> c[i];
    t[i] = p[i]*(i+1)*100 + c[i];
  }

  int ans=inf;
  for (int i=0; i<(1<<d); i++) {
    int s=0;
    int num=0;
    int maxp=-1;
    for (int j=0; j<d; j++) {
      if ((i>>j) & 1) {
        s += t[j];
        num += p[j];
      } else {
        maxp = j;
      }
    }
    if (s < g) {
      int s1 = 100 * (maxp+1);
      int need = (g - s + s1 - 1) / s1;
      if (need >= p[maxp]) continue;
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

ll w[105],v[105];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n,W;
  cin>>n>>W;
  forn(i,0,n) cin>>w[i]>>v[i];
  vector <ll> dp(W+1,0),new_dp(W+1,0);
  for(ll i=0;i<n;i++){
    for(ll weight=1;weight<=W;weight++){
      ll a=0,b=0;
      if(weight-w[i]>=0)
        a=dp[weight-w[i]]+v[i];
      if(weight>=0)
        b=dp[weight];
      new_dp[weight]=max(a,b);
    }
    dp=new_dp;
    /*cout<<i<<" : ";
    for(auto it:dp)
      cout<<it<<" ";
    cout<<endl;*/
  }
  ll ans=new_dp[W];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int W,H,x,y;

int check(){
    double mx=W/2.0,my=H/2.0;
    if((x>=mx-EPS&&x<=mx+EPS)&&(y>=my-EPS&&y<=my+EPS)){
        return 1;
    }
    return 0;
}

signed main(){

    in(W,H,x,y);
    out(W*H/2.0,check());

    return 0;
}


Measured memory_bytes: 256
N,M=map(int, input().split())
u=[0]*M
v=[0]*M
for i in range(M):
  u[i],v[i] = map(int, input().split())
S,T=map(int, input().split())

edges = []
for i in range(M):
  edges.append([u[i]*3-3, v[i]*3-2])
  edges.append([u[i]*3-2, v[i]*3-1])
  edges.append([u[i]*3-1, v[i]*3-3])

def edges_to_pt(edges,n):
  '''
  input
    edges: 枝の[始点,終点]を格納した2次元配列　edges=[[0,1],[1,2],[2,0]]
    n:  頂点数 n=3

  output
    pt: 各点との結合場所を格納した2次元配列 pt=[[1],[2],[0]]
  '''
  pt = [[] for i in range(n)]
  while edges:
    temp_edge = edges.pop()
    pt[temp_edge[0]].append(temp_edge[1])
  return pt

def bfs(pt,v):
  '''
  input
    pt: 各点との結合場所を格納した2次元配列　pt=[[1, 2, 3], [0], [5, 0], [6, 0], [6], [2], [3, 4]]
    v: 初期点 v=0

  output
    d: 初期点からの距離を格納した配列 d=[0, 1, 1, 1, 3, 2, 2]
  '''
  n=len(pt)
  d=[-1]*n
  d[v]=0
  q=[v]
  c=1
  while q:
    q1=[]
    for i in q:
      for j in pt[i]:
        if d[j]==-1:
          d[j]=c
          q1.append(j)
    q=q1
    c+=1
  return d

pt = edges_to_pt(edges,3*N)
ans = bfs(pt,3*S-3)[3*T-3] // 3

if ans == -1:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 114988
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  string S;
  cin >> S;
  int x,y;
  cin >> x >> y;
  vector<int> t;
  int cnt = 0;
  for(int i=0; i<S.size(); i++){
    if(S[i] == 'T'){
      if(cnt != 0) t.push_back(cnt);
      t.push_back(0);
      cnt = 0;
    }else{
      cnt++;
      if(i == S.size()-1) t.push_back(cnt);
    }
  }
  const ll MAXN = 8020;
  vector<vector<bool>> dp_x(MAXN,vector<bool> (MAXN*2,false)),dp_y(MAXN,vector<bool> (MAXN*2,false));
  dp_x[0][8000] = true;
  dp_y[0][8000] = true;
  bool flag = false;
  bool xy = true;
  int cnt_x=0,cnt_y=0;
  for(int i=0; i<t.size(); i++){
    if(t[i] == 0){
      xy = !xy;
    }else if(xy){
      cnt_x++;
      for(int j=0; j<MAXN*2; j++){
        if(dp_x[cnt_x-1][j]){
          if(j+t[i] < MAXN*2) dp_x[cnt_x][j+t[i]] = true;
          if(j-t[i] >= 0 and flag) dp_x[cnt_x][j-t[i]] = true;
        }
      }
    }else if(!xy){
      cnt_y++;
      for(int j=0; j<MAXN*2; j++){
        if(dp_y[cnt_y-1][j]){
          if(j+t[i] < MAXN*2) dp_y[cnt_y][j+t[i]] = true;
          if(j-t[i] >= 0) dp_y[cnt_y][j-t[i]] = true;
        }
      }
    }
    if(!flag) flag = true;
  }
  cout << ((dp_x[cnt_x][x+8000] and dp_y[cnt_y][y+8000]) ? "Yes" : "No") << endl;
  return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy";
    else if(s == "Cloudy") cout << "Rainy";
    else cout << "Sunny";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath> 

const int Maxv = 605; 
int Map[Maxv][Maxv][2], d[5], n, m, cnt; 
bool vis[Maxv][Maxv][2];

inline void dfs(int x, int y, int a, int b){
    if (x < 0 || x > m || y < 0 || y > m || vis[x][y][a]) {
        return; 
    }
    vis[x][y][a] = true; 
    Map[x][y][a] = b; 
    for (int i = 0; i * i <= d[a]; i++) {
        int j = sqrt(d[a] - i * i); 
        if (i * i + j * j != d[a]) {
            continue; 
        }
        dfs(x + i, y + j, a, 3 - b); 
        dfs(x - i, y + j, a, 3 - b); 
        dfs(x + i, y - j, a, 3 - b); 
        dfs(x - i, y - j, a, 3 - b); 
    }
}

int main(){
    scanf("%d%d%d", &n, &d[0], &d[1]); 
    m = 2 * n - 1; 
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= m; j++) {
            if (!vis[i][j][0]) {
                dfs(i, j, 0, 1); 
            }
            if (!vis[i][j][1]) {
                dfs(i, j, 1, 1); 
            }
        }
    }
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= m; j++) {
            if (Map[i][j][0] == 1 && Map[i][j][1] == 1) {
                printf("%d %d\n", i, j); 
                cnt++; 
                if (cnt == n * n) {
                    return 0; 
                }
            }
        }
    }
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n, a[N];

int main() {

	FAST;

	int n;
	cin >> n;
	intt sum = 0;
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= n; j ++) {
			for (int k = 1; k <= n; k ++) {
				sum += __gcd(__gcd(i, j), k);
			}
		}
	}
	cout << sum << '\n';
	return 0;
}

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

int main(void){
        int res;
        long long int ns,x;

        cin >> x;
        ns=x/11;
        res=x-11*ns;
        if(res==0){
                ns=ns*2;
        }else if(res<7){
                ns=ns*2+1;
        }else{
                ns=(ns+1)*2;
        }
        cout << ns << endl;
        return 0;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
S = [list(map(int, input())) for _ in range(H)]


def add(j):
    for i in range(g):
        now[i] += c[i][j]
    for i in range(g):
        if now[i] > K:
            return False
    return True


ans = 10**30
for i in range(2 ** (H-1)):
    g = 0
    id = [-1]*H
    for j in range(H):  # このループが一番のポイント
        id[j] = g
        if (i >> j & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            g += 1
    g += 1

    c = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            c[id[i]][j] += S[i][j]

    num = g-1
    now = [0]*g
    for j in range(W):
        if not add(j):
            num += 1
            now = [0]*g
            if not add(j):
                num = 10**30
                continue

    ans = min(ans, num)

print(ans)


Measured memory_bytes: 56668
n = int(input())
a = list(map(int, input().split()))

def print_space(li):
    for i in range(len(li)-1):
        print(li[i], end=' ')
    else:
        print(li[-1])

def InsertionSort(li):
    print_space(li)
    for i in range(1, n):
        v = li[i]
        j = i - 1
        while j >= 0 and li[j] > v:
            li[j+1] = li[j]
            j -= 1
        else:
            li[j+1] = v
        print_space(li)
            

InsertionSort(a)




Measured memory_bytes: 5976
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i).sort

if a[0] == 0 
  puts(0)
  return
end

ans = 1

a.each do |x|
  ans *= x
  if ans > 1000000000000000000
    puts(-1)
    return
  end
end

puts(ans)



Measured memory_bytes: 24968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int main(){
  cin >> n >> m;
  map<int, bool> ma;
  ll acount = 0;
  ll fcount = 0;
  vector<int> v(n, 0);
  for(int i=0 ; i<m ; i++){
    int p;  string s;
    cin >> p >> s;
    p--;

    if(ma.count(p)==0){
      if(s == "AC"){
        ma[p] = true;
        acount++;
      }else{
        ma[p] = false;
        fcount++;
        v[p]++;
      }
    }else if(!ma[p]){
      if(s == "AC"){
        ma[p] = true;
        acount++;
      }else{
        fcount++;
        v[p]++;
      }
    }
  }
  for(int i=0 ; i<n ; i++){
    if(!ma[i]){
      fcount -= v[i];
    }
  }
  cout << acount << " " << fcount << endl;
  return 0;
}


Measured memory_bytes: 5376
<?php
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner();
$s = $sc->next();

$A = $s[0] . $s[1];
$B = $s[2] . $s[3];
$isYYMM = $B >= '01' && $B <= '12';
$isMMYY = $A >= '01' && $A <= '12';
switch (true) {
    case $isYYMM && $isMMYY:
        $result = 'AMBIGUOUS';
        break;
    case $isYYMM && !$isMMYY:
        $result = 'YYMM';
        break;
    case !$isYYMM && $isMMYY:
        $result = 'MMYY';
        break;
    default:
        $result = 'NA';
        break;
}

out::println($result);

Measured memory_bytes: 3828
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
#define EPS 1E-6
int main()
{
	int n,m,d;
	scanf("%d%d%d",&n,&m,&d);
	double ans=2.0*(n-d)/n*(m-1)/n;
	if(d==0)
		ans/=2;
	printf("%.10lf\n",ans);
}

Measured memory_bytes: 128
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let nk: Vec<u32> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];

    let mut ans = 0.0;
    for i in 0..n {
        let mut t = i+1;
        let mut p = 1.0 / (n as f64);
        while t < k {
            p /= 2.0;
            t *= 2;
        }
        ans += p;
    }

    println!("{:.*}", 12, ans);
}


Measured memory_bytes: 4352
import sys

input = sys.stdin.readline
# coding: utf-8
# Your code here!
n = int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()

def bin_chisaimono(b):
    if a[0][0] >= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == n - 1 and a[0][pc] < b:
            return n
        elif a[0][pc] < b <= a[0][pc + 1]:
            return pc + 1
        elif a[0][pc] >= b:
            pr = pc -1
        else:
            pl = pc + 1


def bin_okimono(b):
    if a[2][n - 1] <= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == 0 and a[2][pc] > b:
            return n
        elif a[2][pc - 1] <= b < a[2][pc]:
            return n - pc
        elif a[2][pc] <= b:
            pl = pc + 1
        else:
            pr = pc - 1


cnt = 0
for i in range(n):
    cnt += bin_chisaimono(a[1][i]) * bin_okimono(a[1][i])
print(cnt)


Measured memory_bytes: 23312
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-10;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int a[n+1];
    rep(i,1,n+1)cin>>a[i];
    a[0]=0;
    sort(a,a+n);
    int ans=0;
    rep(i,1,n+1){
        if(a[i-1]%2!=a[i]%2)ans^=n-i+1;
    }
    if(ans)cout<<"first"<<endl;
    else cout<<"second"<<endl;
}






Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

vector<char> ta;
string s;

int main(){
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			ta.push_back('0');
		}
		if (s[i] == '1') {
			ta.push_back('1');
		}
		if (ta.size() > 0 && s[i] == 'B') {
			ta.pop_back();
		}
	}
	for (int i = 0; i < ta.size(); i++) {
		cout << ta[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<long long,int> P;
static const int INF=1<<24;

string s;

int main(){
	while(getline(cin,s)){
		rep(i,s.size()){
			if(s[i]>='a'&&s[i]<='z'){
				s[i]-='a';
			}
			else if(s[i]==13){
				s[i]=200;
			}
		}
		for(int i=0;;i++){
			bool f=false;
			//cout<<s.size()<<endl;
			rep(j,s.size()-3){
				if(s[j]=='t'-'a'&&s[j+1]=='h'-'a'&&((s[j+2]==0&&s[j+3]=='t'-'a')||(s[j+2]=='i'-'a'&&s[j+3]=='s'-'a')||s[j+2]=='e'-'a')){
					f=true;
					break;
				}
			}
			if(s[s.size()-3]=='t'-'a'&&s[s.size()-2]=='h'-'a'&&s[s.size()-1]=='e'-'a') f=true;
			if(f) break;
			else{
				rep(j,s.size()){
					if(s[j]<='z'-'a'&&s[j]>=0){
						s[j]=(s[j]+1)%('z'-'a'+1);
					}
				}
			}
		}
		rep(i,s.size()){
			if(s[i]<='z'-'a'&&s[i]>=0){
				s[i]+='a';
			}
			else if(s[i]==200){
				s[i]=13;
			}
		}
		cout<<s<<endl;
			
	}
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=1000000009;

int main()
{
    int n,d;cin>>n>>d;
    int i=1+d,c=1,k=0;
    while(i<=n)
    {
        if(i+d<n)c++;
        i+=(2*d+1);
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int s=0, t=0, e=0, d=0;
	while (true) {
		int a[3];
		cin >> a[0] >> a[1] >> a[2];
		sort(a, a + 3);
		if (a[0] + a[1] <= a[2]) break;
		long long b = a[0] * a[0] + a[1] * a[1];
		long long c = a[2] * a[2];
		s++;
		if (b == c) t++;
		else if (b < c) d++;
		else e++;
	}
	cout << s << " " << t << " " << e << " " << d << endl;
}

Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i=0; i<n; i++) {
        cin >> d[i];
    }
    int sum = 0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int k, x;
    cin >> k >> x;
    rep(i, x-k+1, x+k){
        cout << i << endl;
    }
}

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;

  int N = S.length();
  bool ans = false;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (S[(i + j) % N] != T[j]) break;
      if (j == N - 1) ans = true;
    }
  }

  cout << ( (ans) ? "Yes" : "No" ) << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int a, b;
  cin >> a >> b;
  int n = b - a;
  int sum = n * (n + 1) / 2;
  cout << sum - b << endl;
  return 0;
}

Measured memory_bytes: 256
// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 1e5+500;
const ll MOD = 1e9+7;
using namespace std;

int main()
{
    int x;
    cin >> x;
    if (x==3 or x==5 or x==7)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    int P[N];
    map<int, int> m;
    for(int i=0; i<N; i++){
        cin >> P[i];
        P[i]--;
        m[P[i]] = i;
    }


    vector<vector<int>> v(N);
    v[0].push_back(0);
    int ind = 0;
    for(int i=0; i<N-1; i++){
        if(m[i]<m[i+1]){
            v[ind].push_back(i+1);
        }else{
            ind++;
            v[ind].push_back(i+1);
        }
    }

    int len = 0;
    for(int i=0; i<N; i++){
        int t = v[i].size();
        len = max(t, len);
    }

    cout << N-len << endl;

    return 0;
}


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


struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

void solve(){

	int n,k ;
	cin>>n>>k ;

	vector<int> l(k),r(k) ;

	rep(i,k){
		cin>>l[i]>>r[i] ;
	}

	vector<mint> dp(n+1) ;
	vector<mint> dpsum(n+1) ;

	dp[1]=1 ;
	dpsum[1]=1 ;

	for(int i=2;i<=n;i++){

		for(int j=0;j<k;j++){

			int li=i-r[j] ;
			int ri=i-l[j] ;

			if(ri<0)
				continue ;

			li=max(li,1) ;

			dp[i]+=dpsum[ri]-dpsum[li-1] ;

		}
	
	dpsum[i]=dp[i]+dpsum[i-1] ;

	}


 	cout<<dp[n] ;

}


int main(){

		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){
 
			solve() ;

		}

}

Measured memory_bytes: 6392
import java.util.*;

class Main {
	Scanner sc;
	
	private void calc() {
		sc = new Scanner(System.in);
		int X = sc.nextInt();
		
	lp:
		while (true) {
			int n = (int)Math.sqrt(X);
			for (int i = 2; i <= n; i++) {
				if (X%i == 0) {
					X++;
					continue lp;
				}
			}
			System.out.println(X);
			break;
		}
	}

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

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

struct Edge {
	int v, u, w;
};

int N, M, L, LL;
//10의 n승
vector<Edge> res;
int Binary[30];

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

	cin >> L;
	L--; LL = L;
	int cnt = 0;
	while (L) {
		Binary[cnt++] = (L % 2);
		L /= 2;
	}

	if (LL == (1 << cnt) - 1) {
		for (int i = 1; i <= cnt; ++i) {
			res.push_back({ i, i + 1, 0 });
			res.push_back({ i, i + 1, (1 << (i - 1)) });
		}
		cout << cnt + 1 << ' ' << res.size() << '\n';
		for (auto ans : res) {
			cout << ans.v << ' ' << ans.u << ' ' << ans.w << '\n';
		}
		return 0;
	}
	N = cnt;
	for (int i = 1; i < N; ++i) {
		res.push_back({ i, i + 1, 0 });
		res.push_back({ i, i + 1, (1 << (i - 1)) });
	}


	res.push_back({ 1, N, LL });
	for (int i = 0; i < N-1; ++i) {
		if (Binary[i]) {
			LL -= (1 << i);
			res.push_back({ i+1, N, LL });
		}
	}

	cout << N << ' ' << res.size() << '\n';
	for (auto ans : res) {
		cout << ans.v << ' ' << ans.u << ' ' << ans.w << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e9;
typedef pair<int, int> pi;
const ll MOD = (ll)1e9 + 7;
ll dp[4001][2001];
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for (int i = 0; i <= 4000; i++) {
		for (int j = 0; j <= 2000; j++) {
			if (j == 0)dp[i][j] = 1;
			else if (i == 0)dp[i][j] = 0;
			else {
				dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
			}
		}
	}
    int s;
    cin >> s;
	ll ns = s;
	ll ans = 0;
	ll n = 0;
	while (1) {
		s -= 3;
		n++;
		if (s < 0)break;
		ll pl = dp[n + ns - n * 3 - 1][ns - n * 3];
		ans = (ans + pl) % MOD;
	}
	cout << ans;
}

Measured memory_bytes: 66152
def LRS(str): 
  
    n = len(str) 
    LCSRe = [[0 for x in range(n + 1)]  
                for y in range(n + 1)] 
  
    res = ""
    res_length = 0
  
    index = 0
    for i in range(1, n + 1): 
        for j in range(i + 1, n + 1): 
              
            if (str[i - 1] == str[j - 1] and
                LCSRe[i - 1][j - 1] < (j - i)): 
                LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1
  
                if (LCSRe[i][j] > res_length): 
                    res_length = LCSRe[i][j] 
                    index = max(i, index) 
                  
            else: 
                LCSRe[i][j] = 0
  
    if (res_length > 0): 
        for i in range(index - res_length + 1, 
                                    index + 1): 
            res = res + str[i - 1] 
  
    return res 
  
n = int(input())
s = input()

print(len(LRS(s))) 
  

Measured memory_bytes: 245768
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


int32_t main()
{


   
    IOS


    int n;
    cin >> n;

    cout << n + n*n + n*n*n;
    return 0;
}


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

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 2e2;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> gr(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        gr[x].push_back(y);
        gr[y].push_back(x);
    }
    vector<int> visited(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {

        if (visited[i]) continue;
        int cnt = 0;
        visited[i] = true;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            cnt++;
            int v = q.front();
            q.pop();
            for (auto u : gr[v]) {
                if (visited[u]) continue;
                visited[u] = true;
                q.push(u);
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans;
    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    long long int n;
    cin>>n;
    long long int m = 100;
    int ans = 0;
    while(m<n){
        m += m/100;
        ans++;
    }

    cout<<ans;


    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int N, M, Q,Ans=0;
vector<int> A(50), B(50), C(50), D(50), V(10);
void dfs(int E, int F){
  if(E==N){
    int Sum=0;
    rep(i, Q)if (V.at(B.at(i))-V.at(A.at(i))==C.at(i)) Sum+=D.at(i);
    Ans=max(Ans, Sum);
    return;
  }
  for(int i=F; i<=M; i++){
    V.at(E)=i;
    dfs(E+1,i);
  }
}
int main(){
  cin >> N >> M >> Q;
  rep(i,Q){
    cin >> A.at(i) >> B.at(i) >> C.at(i) >> D.at(i);
    A.at(i)--;
    B.at(i)--;
  }
  dfs(0,1);
  cout << Ans << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
int a[10000000];
int G[105][105];

int main()
{
    int h,w;
    while(cin>>h>>w)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;++i)
            cin>>a[i];
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) cout<<G[i][j]<<" ";
                else cout<<G[i][j]<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;

int main(){
	string n,r;
	char b;
	int h,w;
	cin >> h;
	cin >> w;
	
	r="snuke";

    
    for (int j=0;j<h;j++){
    	for(int i=0;i<w;i++){
			cin >> n;
    		if (r==n){
    			b = 'A'+i;
    			cout << b << j+1 << endl;
    			
    			
			}
		}
	}

	return 0;
}

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

#define fi first
#define se second

#define mkp(x, y) (make_pair(x, y))

int main() {
	pair<int,int> primary;
	int n;
	pair<int,int> move[] = {
		mkp(-1, -2), mkp(0, -2), mkp(1, -2),
		mkp(-2, -1), mkp(-2, 0), mkp(-2, 1),
		mkp(2, -1), mkp(2, 0), mkp(2, 1),
		mkp(-1, 2), mkp(0, 2), mkp(1, 2), };

	while(cin >> primary.fi >> primary.se, primary.fi || primary.se) {
		cin >> n;
		queue<pair<int,int> > que;
		que.push(mkp(primary.fi, primary.se));

		for(int i = 0; i < n; i++) {
			pair<int,int> pivot;
			set<pair<int, int> > visited;
			queue<pair<int,int> > next_que;

			cin >> pivot.fi >> pivot.se;

			while(!que.empty()) {
				pair<int,int> pos;
				pos = que.front(); que.pop();

				for(int j = 0; j < sizeof(move) / sizeof(move[0]); j++) {
					int x, y;
					x = pos.fi + move[j].fi;
					y = pos.se + move[j].se;
					if((0 <= x && x <= 9) && (0 <= y && y <= 9)) {
						if((pivot.fi - 1 <= x && x <= pivot.fi + 1) && (pivot.se - 1 <= y && y <= pivot.se + 1)) {
							if(visited.find(mkp(x,y)) == visited.end()) {
								next_que.push(mkp(x,y));
							}
							visited.insert(mkp(x,y));
						}
					}
				}
			}

			que = next_que;
		}

		if(!que.empty()) {
			cout << "OK" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Jun 21 21:15:42 JST 2020
 **/

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    Int all = 0;
    REP(i, n) std::cin >> a[i], all ^= a[i];
    REP(i, n) { std::cout << (all ^ a[i]) << " "; }
    std::cout << std::endl;
}


Measured memory_bytes: 4760