akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<iomanip>
#include<bitset>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod
#define N 5010
ll n;
vector<ll> g[N];
ll rui[N];
ll dp[N][N][2],cop[N][2],siz[N];
void dfs(ll x,ll from){
    siz[x]=1;
    for(int i=0;i<N;i++)for(int k=0;k<2;k++)dp[x][i][k]=0;
    dp[x][1][0]=1;
    for(auto y:g[x])if(y!=from){
	dfs(y,x);
	for(int j=0;j<N;j++)for(int k=0;k<2;k++)cop[j][k]=0;
	for(int i=0;i<=siz[y];i++)for(int r=0;r<2;r++){
	    for(int j=0;j<=siz[x];j++)for(int k=0;k<2;k++){
		mad(cop[i+j][(k+r)%2],dp[x][j][k]*dp[y][i][r]);
	    }
	}
	for(int j=0;j<N;j++)for(int k=0;k<2;k++)dp[x][j][k]=cop[j][k];
	siz[x]+=siz[y];
    }
    for(int i=2;i<N;i+=2)for(int k=0;k<2;k++){
	mad(dp[x][0][k^1],dp[x][i][k]*rui[i-1]);
    }/*
    cout<<"x=:"<<x<<endl;
    cout<<"k=0:";for(int i=0;i<=siz[x];i++)cout<<dp[x][i][0]<<" "; cout<<endl;
    cout<<"k=1:";for(int i=0;i<=siz[x];i++)cout<<dp[x][i][1]<<" "; cout<<endl;*/
}
int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
	ll a,b; cin>>a>>b;
	g[a].push_back(b);
	g[b].push_back(a);
    }
    rui[1]=1;
    for(ll i=3;i<N;i+=2)rui[i]=rui[i-2]*i%mod;
    dfs(1,0);
    ll ans=(dp[1][0][1]-dp[1][0][0])%mod;
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}



Measured memory_bytes: 392704
from collections import Counter
n = int(input())
d_1 = Counter()
d_2 = Counter()
A = map(int, input().split())
for i, a in enumerate(A):
    i += 1
    d_1[i - a] += 1
    d_2[i + a] += 1

c = 0
for k, v in d_1.items():
    if d_2[k] > 0:
        c += v * d_2[k]
print(c)

Measured memory_bytes: 138736
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<LL,LL> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
    LL k=read(),x=7%k,t=1;
    while(1)
    {
        if(!x) break;
        if(t>1000000) break;
        x=x*10+7;
        x%=k;
        t++;
    }
    if(!x) cout<<t;
    else cout<<"-1";

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath> 

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool prime[10000000];
void Eratosthenes(int n) {
    rep(i,n) prime[i] = true;
    prime[1] = false;

    REP(i,2,(int)sqrt(n)) {
        if(prime[i]) {
            for(int j=0;i*(j+2)<n;j++) {
                prime[i*(j+2)] = 0;
            }
        }
    }
}

int main() {
    int n;
    Eratosthenes(1000000);

    while(cin >> n) {
        vector<int> a(n);
        rep(i,n) {
            a[i] = i+1;
        }

        vector<int> b(a.rbegin(), a.rend());

        int ans = 0;
        rep(i,n) {
            if(prime[a[i]] && prime[b[i]]) {
                ans++;
            }
        }

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

Measured memory_bytes: 2248
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	int a=0;
	int b=0;
	long long int x;
	for(int i=0;i<n;i++){
		scanf("%lld",&x);
		if(x%2==0)a++;
		else b++;
	}
	a=a+b/2;
	b=b%2;
	if(a>1)a=1;
	if(a+b==1)printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
while 1:
  x = input()
  if x == "0":
    break
  a = 0
  b = 0
  for i in range(1,len(x)):
    if x[i] == "A":
      a += 1
    else:
      b += 1
  if a > b:
    a += 1
  else:
    b += 1
  print(a,b)    


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

int main(void)
{
    string S;
    cin >> S;

    if ((S[2] == S[3]) && (S[4] == S[5])) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def divisors(m):
    ds = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ds.append(i)
            if i != m // i:
                ds.append(m // i)

    return sorted(ds)


n = int(input())
minf = 1e9
for d in divisors(n):
    minf = min(minf, max(len(str(d)), len(str(n // d))))

print(minf)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int mod = (int)1e9+7;

int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, l, q;
	cin >>n ;
	VI x(n);
	rep(i,n) cin >> x[i];
	cin >> l >>q;

	vector<array<int,20>> ds(n+2, array<int,20>{});
	
	rep(i,n){
		int tmp = upper_bound(all(x), x[i]+l) - x.begin() -1;
		ds[i][0] =tmp;
	}
	rep(i, 19) rep(j,n){
		ds[j][i+1] = ds[ds[j][i]][i];
	}
	while(q--){
		int a,b;
		cin >>a  >>b;
		a--;b--;
		if(a>b) swap(a,b);
		
		int hi=n, lw=0;
		while(hi - lw > 1){
			int md= (hi + lw) >> 1;
			int cur = a;
			rep(i,20) if(md>>i &1) cur = ds[cur][i];
			if( cur >= b )  hi = md; else lw = md;
		}
		cout << hi <<"\n";
		
		
	}	
	
	//rep(i,n){ rep(j,10) cout <<ds[i][j] <<" ";cout<<"\n";}
	return 0;
}


Measured memory_bytes: 9088
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	ll N;
	scll(N);
	map<ll, ll> cnt;
	ll tot = 0;
	for (int i = 0; i < N; ++i) {
		ll tmp;
		scll(tmp);
		tot += tmp;
		++cnt[tmp];
	}
	ll Q;
	scll(Q);
	while (Q--) {
		ll A, B;
		scll(A), scll(B);
		ll berubah = cnt[A];
		tot -= berubah * A;
		tot += berubah * B;
		cnt[A] -= berubah;
		cnt[B] += berubah;
		printf("%lld\n", tot);
	}
	return 0;
}

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

ll modPow(int a, int n){
    if(n==1) return a % p;
    if(n%2 == 1) return (a * modPow(a, n-1)) % p;
    ll x = modPow(a, n/2);
    return (x * x) % p;
}

ll modCombine(ll a, ll b){
    b = min(b, a-b);
    ll y=1;
    for(ll i=1;i<=b;i++){
        y = (y*i) % p;
    }
    y = modPow(y,p-2);
    ll x = 1;
    for(ll i=a-b+1;i<=a;i++){
        x = (x*i) % p;
    }
    return (x * y) % p;
}

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll c1 = (modPow(2, n) - 1) % p;
    ll c2 = modCombine(n,a);
    ll c3 = modCombine(n,b);
    ll res = (c1 - c2 - c3 + p + p) % p;
    cout << res << endl;
    return 0;
}

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

int main(){
  int s,w;
  cin >> s >> w;
  if(s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3644
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)2e5 + 228;

using namespace std;

struct Block
{
	int l, r, ch;
};

int n, a[N];

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	scanf("%d", &n);
	forn(i, n)
		scanf("%d", &a[i]);
	//~solve
	int l = 0, r = n + 1;
	while(l < r - 1)
	{
		int ans = (l + r) >> 1;
		vector < Block > t;
		bool good = true;
		t.pb({1, a[1], 1});
		for (int i = 2; i <= n; i++)
		{
			vector < Block > v;
			if (a[i] > a[i - 1])
			{	
				v = t;
				v.pb({a[i - 1] + 1, a[i], 1});
			}
			else
			{
				for (int j = (int)t.size() - 1; j >= 0; j--)
				{
					if (t[j].ch == ans)
						continue;
					if (t[j].l > a[i])
						continue;
					for (int k = 0; k < j; k++)
						v.pb(t[k]);
					int pos = min(a[i], t[j].r);
					if (pos > t[j].l)
						v.pb({t[j].l, pos - 1, t[j].ch});
					v.pb({pos, pos, t[j].ch + 1});
					if (pos < a[i])
						v.pb({pos + 1, a[i], 1});
					break;
				}       
			}
			if (v.empty())
			{
				good = false;
				break;
			}
			t.clear();
			int ll = 1;
			for (int i = 0; i < (int)v.size(); i++)
			{
				if (i == (int)v.size() - 1 || v[i].ch != v[i + 1].ch)
				{
					t.pb({ll, v[i].r, v[i].ch});
					ll = v[i].r + 1;
				}
			}
		}
		if (good)
			r = ans;
		else	
			l = ans;
	}
	cout << r << endl;
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  string s1,s2; cin >> s1 >> s2;
  int a,b; cin >> a >> b;
  string s3; cin >> s3;
  if(s3==s1) a--;
  else b--;
  
  cout << a << " " << b;  
  

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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





int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int h1,h2,m1,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans = h2*60 + m2 - h1*60-m1-k;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
function spilitInput(input) {
  var splited = [];
  var rows = input.split('\n');
  for (var i = 0; i < rows.length; i += 1) {
    splited.push(rows[i].split(' '));
  }
  return splited;
}
function Main(input) {
  var splited = spilitInput(input);
  var N = splited[0][0];
  
  var counter = 0;
  for (var A = 1; A < N; A += 1) {
  for (var B = 1; (A * B) < N; B += 1) {
    counter += 1;
  }
  }

  console.log(counter);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

long long MOD = 1000000000 + 7;
long long fact[2000000]={1};
long long invfact[2000000]={1};

long long nCr(int n, int r){
    long long ans = (fact[n] * invfact[r] % MOD) * invfact[n-r] % MOD; 
    return ans;
}

long long power(long long a, long long b){
    long long res = 1;

    while(b > 0){
        if(b&1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main(void)
{
    for(int i = 1; i < 2000000; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
    
    invfact[2000000-1] = power(fact[2000000-1], MOD-2);
    for(int i = 2000000-1; i > 0; i--){
        invfact[i-1] = invfact[i] * i % MOD; 
    }


    long long K;
    string S;

    cin >> K >> S;

    int slen = S.length();

    int tlen = slen + K;
    long long ans = 0;
    for(int i = slen; i <= tlen; i++){
        ans += power(26 , (tlen - i)) * power(25, (tlen - slen - (tlen - i ) )) % MOD * nCr((tlen - (tlen - i ) -1), slen-1 ) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 36504
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  set<ll> g;
  rep(i,3){
    ll k;
    cin>>k;
    g.insert(k);
  }
  if(g.size()==2){
    COUT("Yes");
  }
  else COUT("No");
}
  

Measured memory_bytes: 256
N=gets.to_i
A=gets.split.map(&:to_i)

MOD=10**9+7

ans=0

(0...60).each do |i|
	count=[0,0]
	A.each do |a|
		count[a[i]]+=1 
	end
	ans=(ans+count[0]*count[1]*(1<<i))%MOD
end
p ans

Measured memory_bytes: 34820
n=int(input())
t=[0]*(n+1)
x=[0]*(n+1)
y=[0]*(n+1)
for i in range(n):
    t[i+1],x[i+1],y[i+1] = map(int,input().split())

flag=True
for i in range(n):
    time=t[i+1]-t[i]
    dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i])
    if dist>time:
        flag=False
    if dist%2 != time%2:
        flag=False
if flag == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11636
#include <cstdio>

#define MOD 1000000007

#define MAXN 200000

#define D 2001

const int q=D+D+1;

int d[q][q];
int fact[2*q], invFact[2*q];
int a[MAXN+1], b[MAXN+1];

inline int lgput(int a, int n){
    int r=1;
    while(n){
        if(n%2) r=1LL*a*r%MOD;
        n/=2;
        a=1LL*a*a%MOD;
    }
    return r;
}

inline int comb(int n, int k){
    return 1LL*fact[n]*invFact[n-k]%MOD*invFact[k]%MOD;
}

int main(){
    int n;
    scanf("%d", &n);

    for(int i=1; i<=n; i++)
        scanf("%d%d", &a[i], &b[i]);

    for(int i=1; i<=n; i++)
        d[D-a[i]][D-b[i]]++;

    for(int i=1; i<q; i++){
        for(int j=1; j<q; j++){
            d[i][j]+=d[i-1][j]+d[i][j-1];
            if(d[i][j]>=MOD) d[i][j]-=MOD;
        }
    }

    int ans=0;
    for(int i=1; i<=n; i++){
        ans+=d[D+a[i]][D+b[i]];
        if(ans>=MOD) ans-=MOD;
    }

    fact[0]=1;
    for(int i=1; i<2*q; i++)
        fact[i]=1LL*fact[i-1]*i%MOD;
    invFact[2*q-1]=lgput(fact[2*q-1], MOD-2);
    for(int i=2*q-2; i>=0; i--)
        invFact[i]=1LL*invFact[i+1]*(i+1)%MOD;

    for(int i=1; i<=n; i++){
        ans-=comb(2*a[i]+2*b[i], 2*a[i]);
        if(ans<0) ans+=MOD;
    }

    ans=1LL*ans*lgput(2, MOD-2)%MOD;

    printf("%d\n", ans);

    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int K,X;
  cin>>K>>X;
  for(int i=-1000000;i<=1000000;i++){
    if(X-K<i&&i<X+K)cout<<i<<" ";
  }
  cout<<endl;
  return 0;
}


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

#define MAX 100000

int n;
vector<int> elist[MAX];
int group[MAX]; //or bool visited

void dfs(int v,int groupParent){
    group[v] = groupParent;
    for (int i :elist[v]){
        if(group[i] == -1)dfs(i,groupParent);
    }
}

void assignGroup(){
    for (int i = 0; i < n; ++i) group[i] = -1;
    for (int i = 0; i < n; ++i) if(group[i] == -1)dfs(i,i);
}

int main(){
    //freopen("in", "r", stdin);
    int m;
    cin >> n >> m;
    //NOTE : vertex id is 0 ~ n-1
    for (int i = 0; i < m; ++i){
        int s,t;
        cin >> s >> t;
        elist[s].push_back(t);
        elist[t].push_back(s);
    }
    assignGroup();
    int q;
    cin >> q;
    for (int j = 0; j < q; ++j) {
        int s,t;
        cin >> s >> t;
        string result = group[s] == group[t] ? "yes" : "no";
        cout << result << endl;
    }

    return 0;
}

Measured memory_bytes: 12108
#include <cstdio>

using namespace std;

int main(){
  char strs[8][8];
  for(int i = 0; i < 8; i++){
    scanf("%s", strs[i]);
  }
  printf("90\n");
  for(int i = 0; i < 8; i++){
    for(int j = 7; j >= 0; j--){
      printf("%c", strs[j][i]);
    }
    printf("\n");
  }
  printf("180\n");
  for(int i = 7; i >= 0; i--){
    for(int j = 7; j >= 0; j--){
      printf("%c", strs[i][j]);
    }
    printf("\n");
  }
  printf("270\n");
  for(int i = 7; i >= 0; i--){
    for(int j = 0; j < 8; j++){
      printf("%c", strs[j][i]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 948
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            out.println(N * N * N);
        }

    }
}



Measured memory_bytes: 22736
/// @file

#include <cmath>
#include <iostream>
#include <map>
#include <vector>

namespace {

bool run(std::istream& is, std::ostream& os);
}  // unnamed namespace

/// @brief エントリポイント
#ifdef _TEST
static int run()
#else
int main()
#endif
{
  try {
    if (run(std::cin, std::cout) == false) {
      std::cerr << "main funciton error.\n";
      return EXIT_FAILURE;
    }
  } catch (const std::exception& e) {
    std::cerr << "catch exception\n";
    std::cerr << e.what() << "\n";
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

namespace {

/// @brief 実行処理
bool run(std::istream& is, std::ostream& os)
{
  int n;
  int m;
  int c;
  is >> n >> m >> c;

  std::vector<int> bList(m);
  for (auto& v: bList) is >> v;

  int correctAnswerNum(0);
  for (int i = 0; i < n; ++i) {
    std::vector<int> aList(m);
    for (auto& v: aList) is >> v;

    int sum(c);
    for (int j = 0; j < m; ++j) sum += aList[j] * bList[j];

    if (sum > 0) ++correctAnswerNum;
  }

  os << correctAnswerNum << "\n";

  return true;
}
}  // unnamed namespace


Measured memory_bytes: 256
#include <iostream>

int MAX_S = 101;

int main(int argc, char** argv) {
    int N;
    scanf("%d", &N);

    int sum = 0;
    int min = MAX_S; // larger than max of si
    int n;

    for(int i = 0; i < N; ++i) {
        scanf("%d", &n);
        if ((n % 10) != 0) {
            if (n < min) {
                min = n;
            }
        }
        sum += n;
    }

    if ((sum % 10) == 0) {
        if (min < MAX_S) {
            std::cout << (sum-min) << std::endl;
        } else {
            std::cout << 0 << std::endl;
        }
    } else {
        std::cout << sum << std::endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define endl            "\n"
#define forn(i,n)       for(int i=0; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zeus()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    zeus();

    int a; cin >> a;
    float b; cin >> b;

    int ans = 0;

    ans += a * (int)b;

    b = b - (int)b;
    //cout << b << endl;
    ans += (int)(a * b);


    cout << ans << endl;




}





Measured memory_bytes: 3740
def chmin(a, b):
    if a > b:
        return b
    else:
        return a


N = int(input())
h = list(map(int, input().split()))

# dp[i]: i番目の足場への最小の移動コスト
dp = [float("inf")] * N * 10

for i in range(N):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = abs(h[1] - h[0])
    else:
        dp[i] = chmin(abs(h[i] - h[i - 1]) + dp[i - 1],
                      abs(h[i] - h[i - 2]) + dp[i - 2])
print(dp[N - 1])


Measured memory_bytes: 80584
using System;

namespace ITP1_9_A {
    class Program {
        static void Main(string[] args) {
            string s = Console.ReadLine();
            int count = 0;
            while(true) {
                string str = Console.ReadLine();
                if(str == "END_OF_TEXT") break;
                string Lowstr = str.ToLower();
                string[] strArray = Lowstr.Split(' ');
                for(int i = 0; i < strArray.Length; i++) {
                    if(strArray[i] == s) count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9048
n, t = map(int, input().split())
ct = [list(map(int, input().split())) for i in range(n)]
ct.sort(key=lambda x : x[0])
for i in range(n):
    if ct[i][1] <= t :
        ans = ct[i][0]
        break
else:
    ans = 'TLE'
print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int MOD = 1e9 + 7;

int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};

void solve()
{
    int n;
    cin >> n;
    vector<int> v(200000, 0);
    rep(i, n)
    {
        int a;
        cin >> a;
        v[a]++;
    }
    int ans = -1;
    REP(i, 1, 199999)
    {
        int score = v[i - 1] + v[i] + v[i + 1];
        ans = max(ans, score);
    }
    P(ans);
}

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


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

const int MAX_S = 500000;

int tmp[MAX_S];

int merge_sort(const int N, int start, int end, int (*s)[MAX_S]) {
    int count = 0;

    assert(end - start >= 0);
    if (end - start == 0 || end - start == 1) {
        return count;
    }

    int mid = (start + end) / 2;
    count += merge_sort(N, start, mid, s);
    count += merge_sort(N, mid, end, s);

    int ti = 0;
    int left = start;
    int right = mid;
    while (left < mid && right < end) {
        if ((*s)[left] < (*s)[right]) {
            tmp[ti] = (*s)[left];
            left++;
            ti++;
        } else {
            tmp[ti] = (*s)[right];
            right++;
            ti++;
        }
        count++;
    }
    while (left < mid) {
        tmp[ti] = (*s)[left];
        left++;
        ti++;
        count++;
    }
    while (right < end) {
        tmp[ti] = (*s)[right];
        right++;
        ti++;
        count++;
    }

    for (int i = 0; i < end - start; i++) {
        (*s)[start + i] = tmp[i];
    }

    return count;
}

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

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

    int count = merge_sort(N, 0, N, &s);

    cout << s[0];
    for (int i = 1; i < N; i++) {
        cout << " " << s[i];
    }
    cout << endl;

    cout << count << endl;

    return 0;
}



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

#define ll long long
#define int long long
#define loop(i,s,e) for(int i=s;i<e;i++)
#define rloop(i,s,e) for(int i=e;i>=s;i--)
#define fr first
#define sc second
#define pb push_back
#define  vii vector<int>
#define vll vector<ll>
#define vpii vector<pair<int ,int >>
#define vpll vector<pair<ll, ll> >
#define  pii pair<int,int>
#define lb(v,x) lower_bound(v.begin(),v.end(),x);
#define ub(v,x) upper_bound(v.begin(),v.end(),x);
const long mod =1e9+7;
const int N = 2e5+10;
const long long inf= 1e18;

ll gcd(ll a ,ll b){if(b==0) return a;return gcd(b,a%b);}
ll mul(ll a ,ll b){return (a%mod * b%mod )%mod;}
ll mpower(ll a, ll b){if(b==0) return 1;ll temp=mpower(a,b/2);if(b%2==0){return mul(temp,temp);}else{	return mul(mul(temp,temp) , a);}}
ll inv(ll a){return mpower(a,mod-2);}
ll ncr(ll n, ll r){if(r==0)return 1;ll ans=n%mod;ans=mul(ans,ncr(n-1,r-1));ans=mul(ans,inv(r));	return ans;}
ll power(ll a, ll b){if(b==0) return 1;ll temp=power(a,b/2);if(b%2==0)return temp*temp;else return temp*temp*a;}
ll add(ll a, ll b){return (a%mod + b%mod)%mod;}


void solve()
{
   int x;cin>>x;
   int f=0;
   loop(i,-500,500)
   {
       loop(j,-500,500)
       {
           if(power(i,5)-power(j,5)==x)
           {
               cout<<i<<" "<<j;
               f=1;
               break;
           }
       }
       if(f)break;
   }
   

    
}

int32_t main()
{
	ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;//cin>>t;
	while(t--){
        solve();
	}
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll x;
    cin >> x;
    bool dp[x+1]={};
    dp[0] = 1;
    for(i=0;i<=5;i++){
        for(j=0;j<=x-(100+i);j++){
            dp[j+100+i] |=dp[j];
        }
    }
    cout << dp[x] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s;
        cin >> s;
        if(s == "0")
            return 0;
        int n = s.size();

        int ret = 0;
        vector<int> dp(11, 0);
        for(int i=0; i<n; ++i){
            vector<int> nextDp(11, 0);
            for(int j=0; j<11; ++j){
                int a = j * 10 + (s[i] - '0');
                nextDp[a%11] += dp[j];
            }
            if(s[i] != '0')
                ++ nextDp[s[i]-'0'];

            dp.swap(nextDp);
            ret += dp[0];
        }

        cout << ret << endl;
    }
}

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

int main(){
  int n,m;
  cin >> n >> m;
  if(n>m){
    rep(i,n){
      printf("%d",m);
    }
  }else{
    rep(i,m){
      printf("%d",n);
    }
  }
}

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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _ % MOD
#define __ %= MOD

#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))

#define swap(a, b) \
	{              \
		a = a + b; \
		b = a - b; \
		a = a - b; \
	}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

#define pv(a)                                 \
	{                                         \
		rep(i, a.size()) cout << a[i] << " "; \
		cout << endl;                         \
	}
#define mark(v) cout << "Here--" << v << endl;

const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y & 1)
			res = res * x;
		y = y >> 1;
		x = x * x;
	}
	return res;
} // modular exponent

ll dp[10005][105][2];

ll solve(string &k, ll D, ll pos, ll d, bool limit)
{
	ll ub = (limit) ? k[pos] - '0' : 9;
	if (dp[pos][d][limit] != -1)
		return dp[pos][d][limit];
	if (pos == k.size() - 1)
	{
		ll ans = 0;
		for (ll x = 0; x <= ub; x++)
		{
			if (x % D == d)
				ans++;
		}
		return ans;
	}
	ll ans = 0;
	for (int x = 0; x <= ub; x++)
	{
		ans = (ans + solve(k, D, pos + 1, (D + d - x % D) % D, limit && (x == ub))) % MOD;
	}
	return dp[pos][d][limit] = ans;
}

int main()
{
	ios_base::sync_with_stdio(false); // don't use printf and scanf
	cin.tie(NULL);					  // cout<<fixed<<setprecision
	memset(dp, -1, sizeof(dp));
	string k;
	cin >> k;
	ll D;
	cin >> D;
	ll ans = (MOD + solve(k, D, 0, 0, 1) - 1) % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 21168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
using Tuple = tuple<int, int, int>;

ll modnum = 1e9+7;

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

    ll maximum = (n*(n+1))/2;

    ll ans = 1;
    for(ll i=k; i < n+1; i++) {
        ll minsum =  min(maximum,  (i*(i-1))/2);

        ll start = n-i+1;
        ll end = n;

        ll maxsum =  min(maximum,  (end-start+1) * (end+start)/2);

//        cout << minsum << endl;
//        cout << maxsum << endl;

        ans += maxsum - minsum + 1;
        ans %= modnum;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3636
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
s,w = map(int,input().split())
if w >= s:
  print("unsafe")
else:
  print("safe")


Measured memory_bytes: 27192
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#define N_MAX 20
using namespace std;
double calculator();
typedef struct data{
  double ll,aa,bb;
} d;
vector<d> V;
int N,M;
double l[N_MAX],a[N_MAX],b[N_MAX],ans;

int main(){
  cin>>N>>M;
  for(int i=0;i<N;i++) cin>>l[i]>>a[i]>>b[i];
  ans=0;
  for(int i=0;i<(1<<N);i++){
    if(M==__builtin_popcount(i)){
      V.clear();
      for(int j=0;j<N;j++){
	if(i&(1<<j)){
	  d t;
	  t.ll=l[j],t.aa=a[j],t.bb=b[j];
	  V.push_back(t);
	}
      }
      ans=max(ans,calculator());
    }
  }
  printf("%.20f\n",ans);
  return 0;
}

double calculator(){
  double ret=0;
  for(int i=0;i<V.size();i++){
    for(int j=i+1;j<V.size();j++){
      double a=fabs(V[j].ll-V[i].ll);
      double b=fabs(V[j].aa-V[i].aa);
      double c=fabs(V[j].bb-V[i].bb);
      ret+=(a*a+b*b+c*c);
    }
  }
  return ret;
}

Measured memory_bytes: 1268
#include <iostream>
#include <chrono>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <queue>

#define MAX(a, b) a > b ? a : b
constexpr auto NMAX = (int)1e5 + 20;

using namespace std;

typedef unsigned long long ull;

int n, m, sum;
vector<int> votes;

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		int aux;
		cin >> aux;
		votes.push_back(aux);
		sum += aux;
	}

	int cntr = 0;

	for (int vote : votes) {
		if (vote * 4 * m >= sum)
			cntr++;
	}
	if (cntr >= m)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> mean(H);
  
  for(int i = 0;i < H;i++){
    cin >> mean[i];
  }
  for(int j = 0;j < W + 2;j++){
    cout << '#';
  }
  cout << endl;
  for(int k = 0;k < H;k++){
    cout << '#' << mean[k] << '#' << endl;
  }
  for(int l = 0;l < W + 2 ;l++){
    cout << '#' ;
  }
  cout << endl;
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    int N,L;
    cin >> N >> L;
    int total=0;
    int abs_min = L;
    for (int i=1; i<N+1; i++) {
        int aji = L + i - 1;
        total += aji;
        if (abs(abs_min) > abs(aji)) {
            abs_min = aji;
        }
    }
    
    cout << total - abs_min << endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int nil = -1;
const int MAX_N = 256;

struct Node {
  int l, r, cnt;
  Node() {
    l = r = nil;
    cnt = 0;
  }
};

Node v[MAX_N];
int nodeIndex;

int parse(const char *s, int n, int root) {
  v[root].cnt++;
  if (s[++n] != ',') {
    if (v[root].l == nil) v[root].l = ++nodeIndex;
    n = parse(s, n, v[root].l);
  }
  if (s[++n] != ')') {
    if (v[root].r == nil) v[root].r = ++nodeIndex;
    n = parse(s, n, v[root].r);
  }
  return n+1;
}

void print(int root, int cnt) {
  if (v[root].cnt < cnt) return;
  putchar('(');
  if (v[root].l != nil) print(v[root].l, cnt);
  putchar(',');
  if (v[root].r != nil) print(v[root].r, cnt);
  putchar(')');
}

int main() {
  char op[5], t1[1024], t2[1024];
  while (scanf("%s %s %s", op, t1, t2) == 3) {
    for (int i=0;i<MAX_N;i++) v[i] = Node();
    nodeIndex = 0;
    parse(t1, 0, 0);
    parse(t2, 0, 0);
    print(0, (op[0]=='u'?1:2)); putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 2584
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int ans = 0;
int N;

void dfs(string now, bool t, bool f,bool s) {
    if(now!="" && stol(now) > N) return;
    if(t&&f&&s) ++ans;
    dfs(now+"3",true,f,s);
    dfs(now+"5",t,true,s);
    dfs(now+"7",t,f,true);
}

int main() {
    cin >> N;
    dfs("",false,false,false);
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N):
    if P[i] == i + 1:
        res += 1
        if i < N - 1:
            P[i], P[i + 1] = P[i + 1], P[i]

print(res)


Measured memory_bytes: 14008
import java.util.*;
public class Main {
    Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        new Main();
    }
 
    public Main() {
        new AOJ0262().doIt();
    }
 
    class AOJ0262{
        int n,m;
        int[] masu;
        boolean visit[],visit2[],visit3[];
        int s,g;
        
        boolean dfs(int index){//スタート地点から行けるかどうか。
        	visit2[index] = true;
        	if(index==g)return true;
        	for(int i=1;i<=m;i++){
        		int next = i+index;
        		if(next<s)next = s;
        		if(next>g)next = g;
        		next+=masu[next];
        		if(next<s)next = s;
        		if(next>g)next = g;
        		if(visit2[next])continue;
        		if(dfs(next))return true;
        	}
        	return false;
        }
        
        void start(int index){//スタートする場所
//        	System.out.println(index);
        	visit[index] = true;
    		visit2 = new boolean[n+2];
        	visit3[index] = dfs(index);
        	for(int i=1;i<=m;i++){
        		int next = i+index;
        		if(next<s)next = s;
        		if(next>g)next = g;
        		next+=masu[next];
        		if(next<s)next = s;
        		if(next>g)next = g;
        		if(visit[next])continue;
        		start(next);
        	}
        }

        boolean solve(){
        	visit = new boolean[n+2];
        	visit3 = new boolean[n+2];
        	start(0);
        	for(int i=0;i<=n;i++)if(visit[i]&&!visit3[i])return false;//そのマスからstartしていてゴールしていない
        	return true;
        }
        
        
        
        void doIt(){
            while(true){
                m = in.nextInt();
                if(m==0)break;
                n = in.nextInt();
                masu = new int[n+2];
                for(int i=1;i<=n;i++)masu[i] = in.nextInt();
                s=0;g=n+1;
                System.out.println(solve()? "OK":"NG");
            }
        }
    }
 
}

Measured memory_bytes: 51864
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

pair<int, int> to[200000];
int he[100001], jisuu[100001], A[100001], saidai[100001];
ll goukei[100001];

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


	int N = getint();
	rep1(i, N) A[i] = getint();
	int k = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		jisuu[a]++;
		jisuu[b]++;
		to[k] = mp(b, he[a]);
		he[a] = k++;
		to[k] = mp(a, he[b]);
		he[b] = k++;
	}

	if (N == 2) {
		if (A[1] == A[2]) printf("YES");
		else printf("NO");
		return 0;
	}

	int q[100000], x = 0;
	rep1(i, N) if (jisuu[i] == 1) jisuu[i] = 0;
	int n = N;
	rep1(i, N) if (jisuu[i] == 0) {
		int p = to[he[i]].first;
		goukei[p] += A[i];
		chmax(saidai[p], A[i]);
		jisuu[p]--;
		if (jisuu[p] == 1) q[x++] = p;
		n--;
	}

	bool OK = 1;
	for (int y = 0; y < n - 1; y++) {
		int i = q[y];
		for (int j = he[i]; j; j = to[j].second) {
			int p = to[j].first;
			if (jisuu[p]) {
				jisuu[p]--;
				if (jisuu[p] == 1) q[x++] = p;

				ll tmp = A[i] * 2 - goukei[i];
				chmax(saidai[i], int(tmp));
				goukei[p] += tmp;
				chmax(saidai[p], int(tmp));
				if (tmp < 0 || saidai[i] > A[i]) OK = 0;
			}
		}
		jisuu[i] = 0;
	}

	int i = q[n - 1];
	if (saidai[i] > A[i] || goukei[i] != A[i] * 2) OK = 0;

	if (OK) printf("YES");
	else printf("NO");

	Would you please return 0;
}

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

vector<int> v(303030);
ll n,k,m,x,y;
string s,t;

int main() {
  cin >> x >> y;
  int ans=0;
  while(x<=y) x*=2,ans++;
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
using namespace std;

main(){
    int n;cin>>n;
    if(n==2)
        return cout<<1,0;
    vector<int> vec;
    int ans=0,divcnt=0;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            int t=n;
            while(t%i==0)
                t/=i;
            if(t%i==1)
                ans++;
            divcnt++;
            if(i*i!=n){
                int t=n;
                while(t%(n/i)==0)
                    t/=(n/i);
                if(t%(n/i)==1)
                    ans++;
                divcnt++;
            }
        }
    }
    for(int i=2;i*i<=n-1;i++){
        if((n-1)%i==0){
            ans++;
            if(i*i!=n-1)
                ans++;
        }
    }
    cout<<ans+2;
    // n-1-divcnt
}


Measured memory_bytes: 256
#167_d
n, k = map(int, input().split())
a = list(map(int, input().split()))

r = []
check = [0]*len(a)
now = 1
count = 0

while True:
    r.append(now)
    now = a[now - 1]
    
    if check[now - 1] == 1:
        roop = r[r.index(now):]
        break
    check[now - 1] += 1
    
if len(r) - 1 >= k: #ループに入らないとき
    print(r[k])
else:#ループに入ったとき
    print(roop[(k-len(r)) % len(roop)])

Measured memory_bytes: 32352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll H;
    cin >>H;
    ll cnt = 0;
    while(H){
        cnt++;
        H/=2;
    }
    ll ans = 0;
    rep(i,cnt){
        ans += pow(2,i);
    }
    cout << ans << endl;


    return 0;
    

}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int n,r;
    cin>>n>>r;

    if( n >= 10 )
    {
        cout<<r,nl;
    }
    else
    {
        cout<<(r + 100*(10-n)),nl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 892
import java.util.Scanner;
import java.util.Arrays;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] balls = new int[NUM];
        int sum = 0;
        for(int i = 0; i < NUM; i++){
            balls[i] = scan.nextInt();
            sum += balls[i];
        }

        // search
        int halfSum = 0;
        int answer = Integer.MAX_VALUE;
        for(int i = 0; i < NUM-1; i++){
            halfSum += balls[i];
            if(Math.abs((sum - halfSum) - halfSum) < answer){
                answer = Math.abs((sum - halfSum) - halfSum);
            }
        }

        // answer
        System.out.println(answer);

    }
}

Measured memory_bytes: 23636
import Data.List

solve :: [Int] -> Int
solve = sum . map ((\x -> x * (x - 1) `quot` 2) . length) . group . sort . scanl (+) 0

destruct :: [Int] -> [Int]
destruct (_:xs) = xs

main :: IO ()
main = print . solve . destruct . map read . words =<< getContents

Measured memory_bytes: 34044
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

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

  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  ll sum = 0;
  int num_of_minus = 0;
  ll min_abs = 1e+10;

  rep(i, N) {
    sum += abs(A[i]);
    num_of_minus += (A[i] < 0);
    chmin(min_abs, abs(A[i]));
  }

  if (num_of_minus % 2 == 1) {
    sum -= 2 * min_abs;
  }

  cout << sum << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int n, k;
string s;
int main() {
    cin>>n>>k;
    if(n%k==0) cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}

Measured memory_bytes: 768