akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<Pii,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int N,M,p;
int d[10010];
int main(){
    cin >> N >> M >> p;
    rep(i,M){
        scanf("%d",&d[i]);
        d[i] = (d[i]-p+N)%N;
    }
    sort(d,d+M);
    int ans = INF;
    rep(i,M){
        ans = min(ans,d[i]+min(d[M-1]-d[i],i==M-1?d[i]-d[0]:N+d[i]-d[i+1]));
        ans = min(ans,N-d[i]+min(d[i]-d[0],i==0?d[M-1]-d[i]:N+d[i-1]-d[i]));
    }
    printf("%d\n",ans*100);
    return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Vector vector<ll>
vector<Vector> dp;
#define rr(f) f.begin(),f.end()
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	ll t = 1;
	ll i, j, k, l, r;
	//cin>>t;
	while(t-->0)
	{
	    ll n; cin>>n; cin>>k;
	    Vector v(n),dp(n+1,0);
	    for(i=0; i<n; i++) cin>>v[i];
	    for(i=n-2; i>=0; i--)
	    {
	        
	        dp[i] = 1<<30;
	        for(j=i+1; j<min(n,i+k+1); j++)
	        {
	            dp[i] = min(dp[i] , abs(v[j]-v[i]) + dp[j]);
	        }
	    }
	    cout<<dp[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> A(2 * n);
    rep(i, 2 * n) cin >> A[i];

    int mi = 0;
    rep(p, n) {
        int sum = 0;
        for (int i = 0; i <= p; i++) {
            sum += A[i];
        }
        for (int i = p; i < n; i++) {
            sum += A[n + i];
        }
        mi = max(mi, sum);
    }

    put(mi);
    

    return 0;
}

Measured memory_bytes: 3620
n = int(input())
for i in range(n):
    t, x, y = map(int, input().split())

    if i == 0:
        if x + y != t:
            print('No')
            exit()
        else:
            bx = x
            by = y
            bt = t
    else:
        d = abs(x - bx) + abs(y - by)
        dt = t - bt
        bx = x
        by = y
        bt = t

        # print(d, dt)
        if d > dt:
            print('No')
            exit()

        elif d % 2 == 1 and dt % 2 == 0:
            print('No')
            exit()
        elif d % 2 == 0 and dt % 2 == 1:
            print('No')
            exit()
print('Yes')


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

using namespace std;

int main() {
	int n, r = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		r += a - 1;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 

ll mod = 1e9+7;

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

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

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

ll power(ll a,ll b)
{
	ll r = 1;
	while(b>0)
	{
		if(b%2==1)
		{
			r = mul(r,a);
		}
		a = mul(a,a);
		b = b/2;
	}
	return r;
}
	

int main()
{	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
		
	
	ll n,k;
	cin>>n>>k;
	
	ll ans = 0;
	ll gcd[k];
	for(ll i=k;i>=1;i--)
	{
		gcd[i] = power((k/i),n);
		for(ll j=2*i;j<=k;j+=i)
		{
			gcd[i] = sub(gcd[i],gcd[j]);
		}
		ans = add(ans,mul(gcd[i],i));
	}
	
	cout<<ans<<endl;
	
}


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

using namespace std;

typedef long long ll;

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

	int n, m;
	cin >> n >> m;

	int max_x = 101010;
	vector<int> val(max_x, 0);

	rep(i, n){
		int x;
		cin >> x;
		val[x]++;
	}

	vector<int> cnt(m, 0), pair(m, 0);
	rep(i, max_x){
		cnt[i % m] += val[i];
		pair[i % m] += val[i] / 2 * 2;
	}

	ll ans = cnt[0] / 2;
	if(m % 2 == 0){
		for(int i = 1; i < m / 2; i++){
			if(cnt[i] > cnt[m - i]){
				swap(cnt[i], cnt[m - i]);
				swap(pair[i], pair[m - i]);
			}

			ans += cnt[i];
			int sng = cnt[m - i] - pair[m - i];
			if(cnt[i] > sng) {
				ans += (pair[m - i] - (cnt[i] - sng)) / 2;
			}else{
				ans += pair[m - i] / 2;
			} 
		} 
		ans += cnt[m / 2] / 2;
	}else{
		for(int i = 1; i <= m / 2; i++){
			if(cnt[i] > cnt[m - i]){
				swap(cnt[i], cnt[m - i]);
				swap(pair[i], pair[m - i]);
			}

			ans += cnt[i];
			int sng = cnt[m - i] - pair[m - i];
			if(cnt[i] > sng) {
				ans += (pair[m - i] - (cnt[i] - sng)) / 2;
			}else{
				ans += pair[m - i] / 2;
			}
		} 
	}
	
	cout << ans << endl;
}


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

int main(void){
    
    string T;
    cin >> T;
    
    for(int i =0; i < T.size();i++){
        if(T[i]=='?')T[i]='D';
    }
    cout << T <<endl;
    
}


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

int main()
{
	string S; cin >> S;
	string ans = "Yes";
	rep(i, S.size()) {
		if(((i%2==1) && (S[i]=='R'))||((i%2==0) && (S[i]=='L'))) ans = "No";
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;

string sol(double n){
    if(n<=48.00)return "light fly";
    if(n<=51.00)return "fly";
    if(n<=54.00)return "bantam";
    if(n<=57.00)return "feather";
    if(n<=60.00)return "light";
    if(n<=64.00)return "light welter";
    if(n<=69.00)return "welter";
    if(n<=75.00)return "light middle";
    if(n<=81.00)return "middle";
    if(n<=91.00)return "light heavy";
    return "heavy";
    
}

int main(){
    double n;
    while(cin>>n){
        cout<<sol(n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  int a=0;
  for(int i=0;i<n;i++){
    if(s.at(i)=='I'){a++;ans=max(ans,a);}
    else{a--;}
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,m,d[100],hi,lo,c,md;
	while(cin>>n,n){
		hi=n-1,lo=c=0;
		for(int i=0;i<n;i++)cin>>d[i];
		cin>>m;
		while(hi>=lo){
			c++;
			md=(hi+lo)/2;
			if(d[md]<m)lo=md+1;
			else if(d[md]>m)hi=md-1;
			else break;
		}
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
n, k = list(map(int, input().split()))
s = input()
#尺取り法
right = -1
left = -1
now_k = 0
while right + 1 < n and s[right + 1] == '1': 
    right += 1
#初めのrightの位置を決める
while now_k < k:
    now_k += 1
    while right + 1 < n and s[right + 1] == '0':
        right += 1
    while right + 1 < n and s[right + 1] == '1':
        right += 1
#今の時点で、rightがいい感じの場所にいる。
ans = (right + 1)
while right + 1 < n:
    while right + 1 < n and s[right + 1] == '0':
        right += 1
    while right + 1 < n and s[right + 1] == '1':
        right += 1
    while left + 1 < n and s[left + 1] == '1':
        left += 1
    while left + 1 < n and s[left + 1] == '0':
        left += 1
    left += 1
    ans = max(ans, right - left + 1)
print(ans)



Measured memory_bytes: 41712
#include<bits/stdc++.h>
#define ll long long
#define dd double
using namespace std;
const ll MOD = 1e9 + 7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x;
  cin>>x;
  if(x==0){
  	cout<<"1"<<endl;
  }
  else{
  	cout<<"0"<<endl;
  }



  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int n,k,d,m;
int main()
{
	scanf("%d%d",&n,&k);
	scanf("%d",&d);
	m=d;
	for(int i=2,x;i<=n;i++)
	{
		scanf("%d",&x),d=gcd(d,x);
		if(x>m)m=x;
	}
	if(k>m)printf("IMPOSSIBLE\n");
	else if(k%d==0)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}


Measured memory_bytes: 764
// Author : Mohamed sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int N = 1e9+7, M = 2e5+9;
int a[M], n;
ll pre[M];
ll get_ans()
{
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)ans = (ans + a[i] * a[j])%N;
	}
	return ans % N;
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	pre[0] = a[0];
	for (int i = 1; i < n; i++)pre[i] = (pre[i-1] + a[i])%N;
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		ll sum = pre[n-1] - pre[i];
		sum = (sum + N)%N; 
		ans = (ans + 1LL * a[i] * sum)%N;
	}
	cout << ans << '\n';
	
	
	
}


Measured memory_bytes: 5928
#include <bits/stdc++.h>
using namespace std;
int h, w,cnt;
char c;
int main() {
	cin>>h>>w;
  	for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
       		cin>>c;
          	if(c=='#')cnt++;
        }
    }
  cout<<(cnt==h+w-1?"Possible":"Impossible")<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll n;
    cin >>n;
    vll a(n);
    vll r(n);
    rep(i, n) {
        cin >>a[i];
        r[a[i]-1] = i+1;
    }
    rep(i, n) {
        cout <<r[i] << " ";
    }
    
    
   
}


Measured memory_bytes: 4748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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; }

int main () {
  int a, b, k;
  cin >> a >> b >> k;

  int cnt = 0;
  for (int i = min(a,b); i >= 1; --i) {
    if (a%i==0 && b%i==0) cnt++;
    if (cnt == k) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<ll, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  ll n;
  cin>>n;
  ll ans=0;
  
  rep(i,n-1){
    ans+=(n-1)/(i+1);
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18+18;
const ll MAX = 100005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;


int main(){
    int N, R;
    cin>>N>>R;
    if(N>9){
        cout<<R;
    }
    else{
        cout<<R+100*(10-N);
    }
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        a:i32,
        b:i32,
        c:i32,
        d:i32
    }
    println!(
        "{}",
        if (b + c - 1) / b <= (a + d - 1) / d {
            "Yes"
        } else {
            "No"
        }
    )
}


Measured memory_bytes: 2144
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int calc(int a,int b,int w)
{
	int ai=a/w,aj=a%w;
	int bi=b/w,bj=b%w;
	return abs(ai-bi)+abs(aj-bj);
}

int main()
{
	for(int n,a,b,c,d;cin>>n>>a>>b>>c>>d;){
		a--,b--,c--,d--;
		int res=INFTY;
		for(int w=1;w<=n;w++)
			res=min(res,calc(a,b,w)+calc(c,d,w));
		cout<<res<<endl;
	}
	
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	string A;
	cin>>A;
	int N=A.size();
	vector<int> B(N+1);
	B[0]=1;
	rep(i, 1, N+1) B[i]=B[i-1]*3LL%MOD;
	function<int(int)> f=[&](int i) {
		if(i==N) return 1;
		return A[i]=='1' ? (f(i+1)*2%MOD+B[N-i-1])%MOD : f(i+1);
	};
	cout<<f(0);
}

Measured memory_bytes: 7120
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main(void){
      long n;
      cin >> n;
      vector<long> v(n);
      for(int i = 0;i < n;i++){
            cin >> v[i];
      }
      sort(v.begin(),v.end());
      long ans = 0;
      for(int i = 0;i < n - 2;i++){
            for(int j = i + 1;j < n - 1;j++){
                  for(int k = j + 1;k < n;k++){
                        long a = v[i];
                        long b = v[j];
                        long c = v[k];
                        if(a < b && b < c){
                              if(a + b > c){
                                    ans++;
                              }
                        }
                  }
            }
      }
      cout << ans << endl;
}


Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    C1 = input()
    C2 = input()
    
    if C1[0] == C2[2] and C1[1] == C2[1] and C1[2] == C2[0]:
        print("YES")
    else:
        print("NO")
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38512
def test():
    import numpy as np
    N = 10000
    print(N)
    A = np.random.randint(0, 10, [N])
    print(count(N,A))


def count(N, A):
    #i < j
    #A[i] + A[j] == j - i
    #A[i] + i == j - A[j]
    left = dict()
    right = dict()
    for i in range(N):
        l = i+1 + A[i]
        r = i+1 - A[i]
        left[l] = left.get(l, 0) + 1
        right[r] = right.get(r, 0) + 1

    counter = 0
    for k, v in left.items():
        if k in right:
            counter += right[k] * v

    return counter

def main():
    #test()
    N = int(input())
    A = list(map(int, input().split()))

    result = count(N,A)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 56768
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//17:00~

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	
	llint n,L,i,ans=0,gen=0;cin>>n>>L;
	vector<pair<llint,int>>koma(n);
	for(i=0;i<n;i++){cin>>koma[i].fir>>koma[i].sec;koma[i].sec*=2;koma[i].sec--;}
	SO(koma);
	for(i=0;i<n;i++){gen-=(koma[i].fir-i-1)*koma[i].sec;}ans=gen;
	for(i=n-1;i>=0;i--){gen+=(L-n)*koma[i].sec;maxeq(ans,gen);}
	cout<<ans<<endl;
	return 0;
}



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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] l = new int[m];
    int[] r = new int[m];
    int l_max = 0;
    int r_min = 100000;
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    }
    System.out.println(r_min-l_max+1>0?r_min-l_max+1:0);
  }
}

Measured memory_bytes: 54716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		int D = Integer.parseInt(st.nextToken());
		int T = Integer.parseInt(st.nextToken());
		int S = Integer.parseInt(st.nextToken());
		
		String ans = (D <= T * S) ? "Yes" : "No";
		
		System.out.println(ans);
	}

}

Measured memory_bytes: 32644
<?php
fscanf(STDIN, "%d", $N);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$b = array_pad(array(), $N, null);

for ($i = $N; $i > 0; $i--) {
	if ($N / 2 > $i) {
		$tmp = $a[$i * 2 - 1];
		$st = $i * 3;
		$dj = $i * 2;
	} else {
		$tmp = 0;
		$st = $i * 2;
		$dj = $i;
	}
    for ($j = $st; $j <= $N; $j += $dj) {
        $tmp += $b[$j - 1];
    }
    $b[$i - 1] = ($tmp - $a[$i - 1] + 10) % 2;
}
$ans = [];
for ($i = 0; $i < $N; $i++) {
	if ($b[$i] === 1 ) $ans[] = $i + 1; 
}
printf("%d\n", count($ans));
echo implode(' ', $ans);


Measured memory_bytes: 32368
n, m = map(int,input().split())

sl = list(input())
abl = [list(map(int,input().split())) for _ in range(m)]


from collections import defaultdict
dic = defaultdict(list)

in_edge = [[0, 0] for i in range(n)]
for a, b in abl:
    dic[a-1].append(b-1)
    dic[b-1].append(a-1)
    if sl[b-1] == "A":
        in_edge[a-1][0] += 1
    else:
        in_edge[a - 1][1] += 1
    if a != b:
        if sl[a-1] == "A":
            in_edge[b - 1][0] += 1
        else:
            in_edge[b - 1][1] += 1

used = [0 for i in range(n)]
removes = []
for idx, (a,b) in enumerate(in_edge):
    if a == 0 or b == 0:
        removes.append(idx)
        used[idx] = 1

ans = 0
while removes:
    ans += 1
    v = removes.pop()
    for w in dic[v]:
        if v != w:
            if sl[v] == "A":
                in_edge[w][0] -= 1
                if in_edge[w][0] == 0 and used[w] == 0:
                    removes.append(w)
                    used[w] = 1
            else:
                in_edge[w][1] -= 1
                if in_edge[w][1] == 0 and used[w] == 0:
                    removes.append(w)
                    used[w] = 1

if ans == n:
    print("No")
else:
    print("Yes")

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

int main() {
    int n, k;
    cin >> n >> k;
    int p[n];
    rep(i, n) cin >> p[i];
    sort(p, p + n);

    int ans = 0;
    rep(i, k) ans += p[i];

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


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << "[line : " << __LINE__ <<"]"<< pp(x)
#define dg2(x,y) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y)
#define dg3(x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x , y) memset(x , y , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

int mat[4000][4000];
int dp[4000][4000][5];
int N , M , K;
int take(int x,int y) {
  if(x > N || y > M) return 0;
  return mat[x][y];
}
int cal(int i ,int j , int r) {
  if(i >= N) return 0;
  if(j >= M) return 0;
  if(dp[i][j][r] != -1) return dp[i][j][r];
  int ans = 0;
  ans = max({ans , cal(i , j + 1, r), cal(i+1 , j , 0)});
  if(r < 3) {
    ans = max(ans , cal(i , j + 1, r + 1) + mat[i][j]);
    ans = max(ans , cal(i + 1, j , 0) + mat[i][j]);
  }
  return dp[i][j][r] = ans;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M >> K;
  clr(dp , -1);
  for(int i = 0; i < K; i++) {
    int r , c, v;
    cin >> r >> c >> v;
    r--,c--;
    mat[r][c] = v;
  }   
  int ans = cal(0, 0, 0);
  cout << ans << '\n';
}

Measured memory_bytes: 709180
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, k;
    scanf("%d %d %d", &a, &b, &k);
    for(int i = a; i <= min(b, a + k - 1); i++) printf("%d\n", i);
    for(int i = max(a + k, b - k + 1 ); i <= b; i++) printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);

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

ll mulmod(ll x, ll y)
{
	return (x * y) % mod;
}

ll submod(ll x, ll y)
{
	return (x - y + 100 * mod) % mod;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r/2);
		return mulmod(y, y);
	}
	else
	{
		ll y = power(n, (r-1)/2);
		return n * mulmod(y, y) % mod;
	}
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);
	
	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i-1], i);
	}
	
	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	// n (n-1) ... (n-r)
	if ( r == n || r == 0 ) { return 1; }

	ll ans = 1;
	//for (ll i = 0; i < r; i++)
	//	ans = mulmod(ans, n - i);

	// return mulmod(ans, inv[r]);
	return mulmod(perm[n], mulmod(inv[n-r], inv[r]));
}

ll solve(void)
{
	ll n, k;
	cin >> n >> k;
	vector<ll> A(n), B;
	map<ll,ll> m, r, l;


	for (auto& a: A)
		cin >> a;


	init_inv(10e5+2);
	sort(A.begin(), A.end());

	for (auto a : A)
	{
		m[a] = (m.find(a) == m.end()) ? 1 : (m[a] + 1);
	}
	
	ll ps = 0, ns = 0;

	// (n - (i+1))
	for (ll i = 0;  k <= n - i; i++)
	{
		ll c = ncr(n - i - 1, k - 1);
		
		ns = (mulmod(A[i], c) + ns) % mod;
	}

	for (ll i = n - 1; k - 1 <= i; i--)
	{
		ll c = ncr(i, k - 1);
		ps = (mulmod(A[i], c) + ps) % mod;
	}

	cout << submod(ps,ns) << endl;

	return 0;
}



Measured memory_bytes: 22400
for e in iter(input,'0 0'):
 r,_=map(int,e.split())
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=c if c>r//2else r-c
  a=max(a,b)
 print(a)


Measured memory_bytes: 6916
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
  cin >> s;
  cout << s[0] << s.size()-2 << s[s.size()-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	int H,W;
	int i,j;

	while(1){
		
		scanf("%d %d",&H,&W);
		if(H==0 && W==0)break;
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				printf("#");
			}
		printf("\n");
		if(i==H-1)printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 572
import collections
n = int(input())
a = list(map(int,input().split()))

a_cnt = collections.Counter(a)
#print(a_cnt)
cnt = 0
for item in a_cnt.items():
    if item[0]<item[1]:
        cnt += item[1]-item[0]
    elif item[0]>item[1]:
        cnt += item[1]
print(cnt)

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

int a, b, c, d;

int main()
{
    cin >> a >> b >> c >> d;
    if ((abs(b - a) <= d && abs(c - b) <= d) || abs(a - c) <= d)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a[11],b[11],c[11][11];
int main()
{
	for (int i=1;i<=3;i++)
		for (int j=1;j<=3;j++)scanf("%d",&c[i][j]);
	for (int i=0;i<=100000;i++)
	{
		a[1]=i;
		b[1]=c[1][1]-a[1];
		a[2]=c[2][1]-b[1];
		b[2]=c[2][2]-a[2];
		a[3]=c[3][2]-b[2];
		b[3]=c[3][3]-a[3];
		if ((a[1]+b[2]==c[1][2])&&(a[1]+b[3]==c[1][3])&&(a[2]+b[3]==c[2][3])&&(a[3]+b[1]==c[3][1]))
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { x++; return *this; }
    mint operator++(int) { mint ret = x; x++; return ret; }
    mint& operator--() { x--; return *this; }
    mint operator--(int) { mint ret = x; x--; return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<mint> dp(n, 1);
  REP(i, n - 1) {
    char c;
    cin >> c;
    vector<mint> ndp(n - i - 1);
    if (c == '<') {
      mint sum = 0;
      REP(j, n - i - 1) {
        sum += dp[j];
        ndp[j] = sum;
      }
    } else {
      mint sum = 0;
      RREP(j, n - i - 1) {
        sum += dp[j + 1];
        ndp[j] = sum;
      }
    }
    swap(dp, ndp);
  }
  cout << dp[0] << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

count = 0
pre = -10
for i in range(n):
    food = a[i]
    count += b[food - 1]
    if pre + 1 == food:
        count += c[food - 2]

    pre = food

print(count)


Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 10000000
#define NIL -1

typedef struct Node{
  int p,l,r;
}Node;

Node T[MAX];
int n,D[MAX];

void printer(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);
  if(T[u].p==NIL)printf("root, ");
  else if (T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL)rec(T[u].r,p);
  if(T[u].l!=NIL)rec(T[u].l,p+1);
}

int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p = NIL;
    T[i].r = NIL;
    T[i].l = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL){
      r=i;
    }
  }
  

  rec(r,0);
  
  for(i=0;i<n;i++)printer(i);
  
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i, N) cin >> A[i];
    copy(A.begin(), A.end(), B.begin());
    sort(B.rbegin(), B.rend());
    int Max       = B[0];
    int MaxCount  = 0;
    int secondMax = 0;

    rep(i, N) {
        if (B[i] == Max) {
            MaxCount += 1;
            continue;
        }
        else
            secondMax = B[i];
        break;
    }

    rep(i, N) {
        if (MaxCount >= 2){
          cout << Max << endl;
        } else if(MaxCount == 1 && A[i] == Max){
          cout << secondMax << endl;
        } else {
          cout << Max << endl;
        }
    }
}

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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define int long long

typedef pair<int, int> ii;

const int N = 60;
const int mod = 1e9 + 7;

int n;
int s[2][N], f[N][4][4];

void add(int &x, int &y)    { x = (x + y) % mod; }

signed main(){
//    freopen("test.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cout.tie(0);

    cin >> n;
    FOR(j, 0, 1)    {
        FOR(i, 1, n)    {
            char x; cin >> x;
            s[j][i] = x - 'a' + 1;
        }
    }
    f[0][0][0] = 1;
    FOR(i, 0, n - 1) if(s[0][i] != s[0][i + 1]) {
        FOR(col1, 0, 3) FOR(col2, 0, 3) {
            if(s[0][i + 1] == s[1][i + 1])  {
                FOR(nxt, 1, 3) if(nxt != col1 && nxt != col2) add(f[i + 1][nxt][nxt], f[i][col1][col2]);
            } else {
                FOR(n1, 1, 3) FOR(n2, 1, 3) if(n1 != col1 && n2 != col2 && n1 != n2)
                    add(f[i + 2][n1][n2], f[i][col1][col2]);
            }
        }
    }
//    cout << f[2][1][1] << ' ' << f[2][2][1];
    int ans = 0;
    FOR(i, 1, 3) FOR(j, 1, 3) add(ans, f[n][i][j]);
    cout << ans;
}


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

int main(){
    ll n;
    cin>>n;
    ll minv=1000000000005;
    for(ll i=1;i<=sqrt(n);i++){
        ll j=n/i;
        if(j*i==n) minv=min(minv,i+j-2);
    }
    cout<<minv<<"\n";
    return 0;
}


Measured memory_bytes: 3680
N = int(input())
X = list(map(int, input().split()))

sort_x = sorted(X, key= lambda x: x)

mid_left = sort_x[N // 2 - 1]
mid_right = sort_x[N // 2]

for i in X:
    if i <= mid_left:
        print(mid_right)
    else:
        print(mid_left)


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

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define line printf("\n")
#define pq priority_queue
#define rep(k,i,j) for(int k = (int)i;k<(int)j;k++)
#define repd(k,i,j) for(int k = (int)i;k>=(int)j;k--)
#define ll long long
#define ALL(a) a.begin(),a.end()
#define vi vector<int> 

using namespace std;

double EPS = 1e-9;
int INF = 1e9+7;;
long long INFLL = 1e17;
double pi = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

clock_t first_attempt = clock();
inline void cek_time(){
	clock_t cur = clock()- first_attempt;
	cerr<<"TIME : "<<(double) cur/CLOCKS_PER_SEC<<endl;
}
inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of template

int n,m;

const int maxn = 2e5+5;
ll fak[maxn];
int main(){
	scanf("%d%d",&n,&m);
	
	fak[0] = 1;
	rep(k,1,maxn)fak[k] = fak[k-1]*k%INF;
	if(n>m)swap(n,m);
	
	ll ret;
	if(n==m){
		ret = 2*fak[n]*fak[m]%INF;
	}
	else if(m-n==1){
		ret = fak[n]*fak[m]%INF;
	}
	else ret = 0;
	printf("%lld\n",ret);
	
	return 0;
}


Measured memory_bytes: 1920
s, t = input(), input()

cant = 0
sr = [0]*26
tr = [0]*26
for i in range(len(s)):
        x = ord(s[i]) - ord('a')
        y = ord(t[i]) - ord('a')
        if s[i]!=t[i]:
                if sr[x]!=0 and sr[x]!=t[i] or tr[y]!=0 and tr[y]!=s[i]: cant = 1
        sr[x] = t[i]
        tr[y] = s[i]
print("YNeos"[cant::2])

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

#define INF INT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

ll ww[100005];
ll v[100005];
ll dp[105][100005];

using namespace std;

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

    ll n,w;
    cin >> n >> w;
   
    REP(i,n)cin >> ww[i] >> v[i];

    REP(i,n){
        REP(j,w+1){
            if(j-ww[i] < 0){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j],dp[i][j-ww[i]]+v[i]);
            }
        }
    }

    // for(int j = 0;j < n+1;j++){
    //     cout << "j;" << j << endl;
    //     for(int i = 0;i < w;i++){
    //         cout << dp[j][i] << endl;
    //     }
    // }
    ll ans = 0;
    REP(i,w+1)ans = max(ans,dp[n][i]);
    cout << ans << endl;
    return 0;
}    

Measured memory_bytes: 79360
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = input()
print(N.count("2"))

Measured memory_bytes: 5148
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(a);
    Int(b);
    while (a && b) {
        vb bloss(7368799, false);
        for (int i = a, cnt = 0; cnt < b; i++) {
            if (!bloss[i]) {
                for (int j = 1; j * i < 7368799; j++) {
                    bloss[i*j] = true;
                }
                cnt++;
            }
        }
        for (int i = a; i < bloss.size(); i++) {
            if (!bloss[i]) {
                cout << i << endl;
                break;
            }
        }
        cin >> a >> b;
    }
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n, q; cin >> n >> q;
	vector<int> s(n),t(n),x(n); rep(i, n) cin >> s[i] >> t[i] >> x[i];
	vector<int> d(q); rep(i, q) cin >> d[i];

	set<pair<int, int>> st; rep(i, q) st.insert(make_pair(d[i], i));

	vector<tuple<int, int, int>> v;
	rep(i, n) v.push_back(make_tuple(x[i], s[i] - x[i],t[i] - x[i]));
	sort(v.begin(), v.end());

	vector<int> ans(q, -1);
	rep(i, n) {
		int x, l, r; tie(x, l, r) = v[i];
		auto it = st.lower_bound(make_pair(l, -1)); // O(log q)
		while (it != st.end()) {
			if (it->first < r) {
				ans[it->second] = x;
				st.erase(it++);
			} else {
				break;
			}
		}
	}

	for (auto u : ans) {
		printf("%d\n", u);
	}

	return 0;
}


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

int main ()
{
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++)
        for (int j = 1; j <= 9; j++)
    if (i * j == n) {
        cout << "Yes " << endl;
        return 0;
    }
    cout << "No " << endl;
    return 0;
}


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

int main () {
  int n, m;
  int a[50], b[50];
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> a[i] >> b[i];

  int count[50] = {0};

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define N 10000

int main(){
  int n,num[N],i,j,count=0;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&num[i]);

  for(i=0;i<n;i++){
    if(num[i]==2)continue;
    if(num[i]%2==0){
      count+=1;
      continue;
    }
    for(j=3;j<=sqrt(num[i]);j+=2){
      if(num[i]%j==0){
	count+=1;
	break;
      }
    }
  }
  printf("%d\n",n-count);
  
  return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1400010;
inline int read()
{
	int a = 0, f = 1; char c = getchar();
	while(c > '9' || c < '0') { if(c == '-') f = -1; c = getchar(); }
	while(c >= '0' && c <= '9') { a = a * 10 + c - '0'; c = getchar(); }
	return a * f;
}
int n, m;
int a[MAXN], pre[MAXN], Ans[MAXN];
struct node
{
	int l, r, id;
}ask[MAXN];
inline bool cmp(const node &a, const node &b)
{
	return a.r < b.r;
}
int c[MAXN];
inline int lowbit(int x)
{
	return x & (-x);
}
inline void add(int x, int dt)
{
	while(x <= 1000000)
	{
		c[x] += dt;
		x += lowbit(x);
	}
}
inline int sum(int x)
{
	int ans = 0;
	while(x)
	{
		ans += c[x];
		x -= lowbit(x);
	}
	return ans;
}
int main()
{
	n = read(); m = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	for (int i = 1; i <= m; i++) ask[i].l = read(), ask[i].r = read(), ask[i].id = i;
	sort(ask + 1, ask + m + 1, cmp);	
	int nr = 0;
	for (int i = 1; i <= m; i++)
	{
		while(nr < ask[i].r)
		{
			nr++;
			if(pre[a[nr]]) add(pre[a[nr]], -1);
			pre[a[nr]] = nr;
			add(nr, 1);
		}
		Ans[ask[i].id] = sum(nr) - sum(ask[i].l - 1);
	}
	for (int i = 1; i <= m; i++)
		printf("%d\n", Ans[i]);
	return 0;
}

Measured memory_bytes: 17412
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
const long long MOD = 1e9+7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){  
    char a;
    cin >> a;
    cout << alpha[1+(a-'a')] << endl;
}


Measured memory_bytes: 256