akhauriyash/Code-Regression huggingface dataset:
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");

string a ,b,c;
int n;
cin>>n;
cin>>a>>b>>c;
// int arr[]={0,1,2};
vector<string>vs;
vs.pb(a);
vs.pb(b);
vs.pb(c);
int arr[101][26];
memset(arr,0,sizeof(arr));
forn(i,3)
{
  string a;
  a=vs[i];
  forn(j,n)
  {
    arr[j][a[j]-'a']++;
  }
}

string opt="";
forn(i,n)
{int mx=0,ch=0;
  forn(j,26)
  {
    if(mx<arr[i][j])
    {
      mx=arr[i][j];
      ch=j;
    }
  }
  opt+='a'+ch;

}
int cont=0;
forn(i,n)
{
  if(vs[0][i]!=opt[i])
  cont++;
  if(vs[1][i]!=opt[i])
  cont++;
  if(vs[2][i]!=opt[i])
  cont++;
}
cout<<cont;
// cout<<opt;

    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int i,a, b;
	int g = 0;
	scanf("%d%d", &a, &b);
	for (i = a; i <= b; i++) {
		if ((i % 10 == i / 10000) && ((i / 1000) % 10 == (i % 100) / 10))g++;
	}
	printf("%d", g);
	return 0;
}
 

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int total;
  total = A*B*C;
  if (total == 175) { cout << "YES"; }
  else if (total != 175) {cout << "NO"; }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <utility>
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
const lli inf = 1e18;

int main(){
	int n;
	cin >> n;
	vector<pair<pair<string, int>, int> > a(n);
	for(int i=0; i<n; i++){
		cin >> a[i].first.first >> a[i].first.second;
		a[i].first.second = -a[i].first.second;
		a[i].second = i+1;
	}
	sort(a.begin(), a.end());
	for(int i=0; i<n; i++){
		cout << a[i].second << endl;
	}
	return 0;
}

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

const int N = 3000 + 10, mod = 998244353;
int n, s, a[N], dp[2][N];

int sum(int a, int b) {
	return ((1LL * a + b) % mod + mod) % mod;
}

int mul(int a, int b) {
	return ((1LL * a * b) % mod + mod) % mod;
}

int pw(int a, int b) {
	int res = 1, tmp = a;
	while (b) {
		if (b & 1)
			res = mul(res, tmp);
		tmp = mul(tmp, tmp);
		b >>= 1;
	}
	return res;
}

int divide(int a, int b) {
	return mul(a, pw(b, mod - 2));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> s;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	dp[0][0] = pw(2, n);
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= s; j++)
			dp[i & 1][j] = sum(dp[~i & 1][j], (a[i - 1] <= j? divide(dp[~i & 1][j - a[i - 1]], 2): 0));
	cout << dp[n & 1][s] << "\n";
}


Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
using namespace std;

#define N_MAX   (100000)

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> x;
    ll result = 1LL<<60;

    for (int i = 0; i < N; i++) {
        ll num;
        cin >> num;
        x.push_back(num);
    }

    for (int i = 0; i + K -1 < N; i++) {
        ll dirL = x.at(i);
        ll dirR = x.at(i + K - 1);
        result = min(result, min(abs(dirL), abs(dirR)) + dirR -dirL);
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main() {
	long long l, r, i, j; cin >> l >> r;
	long long ans = 100000;
	if (r - l > 2030) {
		cout << 0 << endl;
		return 0;
	}
	for (i = l; i < r; i++) {
		for (j = i + 1; j <= r; j++) {
			ans = min(ans, i % 2019 * j % 2019);
			if (ans == 0)break;
		}
		if (ans == 0)break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
#define endl '\n'
#define int long long
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int MAXN = 30005;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
map<int,int> mp; int res=0,nxt[MAXN][10];
char ss[MAXN];
void dfs(int now,int cnt){
    if(cnt==3) { res++;return; }
    for(int i=0;i<10;i++){
        if(nxt[now][i]){
            dfs(nxt[now][i],cnt+1);
        }
    }
}
signed main(){
#ifndef ONLINE_JUEDE
    //freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
#endif // ONLINE_JUEDE
    int n; cin>>n>>(ss+1);
    int len=strlen(ss+1);
    for(int i=len;i>=0;i--){
        for(int j=0;j<10;j++){
            if(mp[j]) nxt[i][j]=mp[j];
        }
        mp[ss[i]-'0']=i;
    }
    dfs(0,0);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
const ll N=205;
const ll mod=1e9+7;
ll dfn[N],low[N],tot;
struct node{
    int u,v,nxt,rev;
    bool vis;
}edge[N];
int head[N],mcnt;
void add_edge(int u,int v,int rev){
    mcnt++;
    edge[mcnt].u=u;
    edge[mcnt].v=v;
    edge[mcnt].nxt=head[u];
    edge[mcnt].rev=rev;
    head[u]=mcnt;
}
int s[N],top;
ll scc[N],sccc;
bool vis[N];
ll p[N];
ll n,m,k;
ll gcd(ll x,ll y){
    ll t;
    while(y){
        t=x%y;
        x=y;
        y=t;
    }
    return x;
}
ll ksm(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y>>=1;
    }
    return res;
}
ll polya(ll x){
    ll res=0;
    for(int i=1;i<=x;i++)
        res+=ksm(k,gcd(x,i)),res%=mod;
    res*=ksm(x,mod-2);
    res%=mod;
    return res;
}
ll u1[N],v1[N];
ll fact[N+1],inv[N+1];
ll ans=1;
void pre(){
    fact[0]=1;
    for(int i=1;i<=N;i++)
        fact[i]=(fact[i-1]*i)%mod;
    inv[N]=ksm(fact[N],mod-2);
    for(int i=N-1;i>=1;i--)
        inv[i]=(inv[i+1]*(i+1))%mod;
    inv[0]=1;
}
ll C(ll x,ll y){
    return fact[x]*inv[y]%mod*inv[x-y]%mod;
}
void dfs(ll u,ll fa){
    tot++;
    dfn[u]=low[u]=tot;
    for(int i=head[u];i;i=edge[i].nxt){
        ll v=edge[i].v;
        if(v==fa||edge[i].vis)
            continue ;
        s[++top]=i;
        edge[i].vis=1;
        edge[edge[i].rev].vis=1;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>=dfn[u]){
                bool cir=1;
                int cnt=0;
                ll sum=0;
                int x;
                int sz=0;
                for(int j=top;s[j+1]!=i;sz++,j--)
                    if(vis[edge[s[j]].v])
                        cir=0;
                    else
                        vis[edge[s[j]].v]=1;
                    if(sz==1){
                    ans*=k;
                    ans%=mod;
                }
                else if(cir){
                    ans*=polya(sz);
                    ans%=mod;
                }
                else{
                    ans*=C(sz+k-1,k-1);
                    ans%=mod;
                }
                while(s[top+1]!=i){
                    vis[edge[s[top]].v]=0;
                    top--;
                }
            }
        }
        else
            low[u]=min(low[u],dfn[v]);
    }
}
int main()
{
    scanf("%lld%lld%lld",&n,&m,&k);
    for(ll i=1;i<=m;i++){
        ll u,v;
        scanf("%lld%lld",&u,&v);
        add_edge(u,v,mcnt+2);
        add_edge(v,u,mcnt);
        u1[i]=u;
        v1[i]=v;
    }
    pre();
    for(ll i=1;i<=n;i++)
        if(!dfn[i])
            dfs(i,-1);
    printf("%lld\n",ans);
}


Measured memory_bytes: 888
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int A[4]={0},ans=0;
	scanf("%d%d%d",&A[1],&A[2],&A[3]);
	sort(A+1,A+4);
	ans+=A[3]-A[2];
	A[1]+=A[3]-A[2];
	A[2]=A[3];
	if(A[1]==A[3]){
		printf("%d\n",ans);
		return 0;
	}
	ans+=(A[3]-A[1])/2;
	A[1]+=(A[3]-A[1])/2*2;
	if(A[1]==A[3]){
		printf("%d\n",ans);
		return 0;
	}
	printf("%d\n",ans+2);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,sum=0;
	cin>>n;
	for(i=1;i<=n-2;i++)
	{
		int s=n-i;
		for(j=1;j*j<=s;j++)
		{
			if(s%j==0)
			{
				if(s/j!=j)sum+=2;
				else sum+=1;
			}
		}
	}
	cout<<sum+1<<endl;
 } 

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; long ans = 0, pos = 1;
	for(int i = 0; i < n; i++){
		int a; cin >> a;
		
		ans += (a - 1) / pos;
		if(pos == a or pos == 1) pos++;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>
#include <time.h>
#include <assert.h>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 998244353//1000000007
#define N 100005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;}
template<typename U> U gcd(U a, U b){
    if(a == 0)return b;
    if(b == 0)return a;
    if(a >= b)return gcd(a % b, b);
    else return gcd(a, b % a);
}
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}
int pow(int a, ll b, int c){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % c;
        a = 1LL * a * a % c;
        b >>= 1;
    }
    return ans;
}

int vis[N], sg[N], dp[3][N], p[N], now, mx[3];
vi g[N];
int main(){
  int T, m, i, j, k, n, K;
  scanf("%d", &n);
  p[0] = 1;
  p[1] = pow(10, 18);
  rep(i, 2, n+1)p[i] = 1LL * p[i-1] * p[1] % mod;
  rep(it, 0, 3){
    scanf("%d", &m);
    rep(i, 0, n)g[i].clear();
    while(m--){
      scanf("%d%d", &i, &j);
      i--, j--;
      if(i > j)swap(i, j);
      g[i].pb(j);
    }
    per(i, 0, n){
      now++;
      sg[i] = 0;
      for(auto &v : g[i])vis[sg[v]] = now;
      while(vis[sg[i]] == now)sg[i]++;
      Max(mx[it], sg[i]);
      add(dp[it][sg[i]], p[i+1]);
    }
  }
  ll ans = 0;
  rep(i, 0, mx[0]+1){
    rep(j, 0, mx[1]+1){
      ans = ans + 1LL * dp[0][i] * dp[1][j] % mod * dp[2][i^j] % mod;
    }
  }
  ans %= mod;
  printf("%lld\n", ans);
}


Measured memory_bytes: 7168
A, B = gets.split.map(&:to_i)

if B == 0
  ans = 0
else
  len = Math.log2(B).floor + 1
  xorA = (len-1).downto(0).map do |i|
    if i == 0
      a = A % 4; b = B % 4
      [0, 1, 0, 1, 0, 1, 0, 1][a, (4+b)-a+1].reduce(&:+) % 2
    else
      a = A % (2**(i+1)); b = B % (2**(i+1))
      ((a <= 2**i ? 2**i : 2**(i+1) - a) + (b < 2**i ? 0 : b - 2**i + 1)) % 2
    end
  end
  ans = xorA.join("").to_i(2)
end

print("#{ans}\n")

Measured memory_bytes: 1788
import java.io.*;
import java.util.*;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Printer pr = new Printer(System.out);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();

		pr.println(Math.min(n, k) * x + Math.max(0, n - k) * y);

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 9552
#include<stdio.h>

long long min(long long x,long long y)
{
	if (x>y) return y;else return x;
}

int main()
{
	long long n,red,blue;
	scanf("%lld%lld%lld",&n,&blue,&red);
	long long group;
	group=n/(blue+red);
	long long ans;
	ans=group*blue+min(blue,n%(blue+red));
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), X = sc.nextInt();
		sc.close();

		int ans = 0;
		for (int i = 0; i <= A; i++) {
			for (int j = 0; j <= B; j++) {
				for (int k = 0; k <= C; k++) {
					int sum = i * 500 + j * 100 + k * 50;
					if (sum == X) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
}


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

const int M=5e5+5;

char s[M];

int n,q;

struct SegT
{
	int cnt[M*2][26];
	int P,V1,V2;
	void update(int o,int l,int r)
	{
		if(V1!=-1) cnt[o][V1]--;
		cnt[o][V2]++;
		if(l==r)
			return;
		int mid=(l+r)>>1;
		int ls=o+1,rs=o+((mid-l+1)<<1);
		if(P<=mid) update(ls,l,mid);
		else update(rs,mid+1,r);
	}
	int L,R;
	int ncnt[26];
	void query(int o,int l,int r)
	{
		if(L<=l&&r<=R)
		{
			for(int i=0;i<26;i++)
				ncnt[i]+=cnt[o][i];
			return;
		}
		int mid=(l+r)>>1;
		int ls=o+1,rs=o+((mid-l+1)<<1);
		if(L<=mid) query(ls,l,mid);
		if(mid<R) query(rs,mid+1,r);
	}
	int query(int l,int r)
	{
		L=l; R=r;
		memset(ncnt,0,sizeof(ncnt));
		query(0,1,n);
		int ans=0;
		for(int i=0;i<26;i++)
			if(ncnt[i]) ans++;
		return ans;
	}
}segt;

char cq[10];

int main()
{
	scanf("%d%s%d",&n,s+1,&q);
	segt.V1=-1;
	for(int i=1;i<=n;i++)
	{
		segt.P=i;
		segt.V2=s[i]-'a';
		segt.update(0,1,n);
	}
	int con,l,r;
	while(q--)
	{
		scanf("%d",&con);
		if(con==1)
		{
			scanf("%d%s",&l,cq);
			segt.P=l;
			segt.V1=s[l]-'a';
			segt.V2=cq[0]-'a';
			segt.update(0,1,n);
			s[l]=cq[0];
		}
		else
		{
			scanf("%d%d",&l,&r);
			printf("%d\n",segt.query(l,r));
		}
	}
	return 0;
}

Measured memory_bytes: 102400
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int x, y;
	while(cin >> x >> y) {
		vector<int> a = {300000, 200000, 100000};
		if(x == 1 and y == 1) {
			cout << 400000 + 300000 * 2 << endl;
		} else {
			x--;
			y--;
			int ans = 0;
			if(x < 3) {
				ans += a[x];
			}
			if (y < 3) {
				ans += a[y];
			}
			cout << ans << endl;
		}
	}
	return 0;
}


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

#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll   long long 
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;


#define md          1000000007
#define fmd         998244353 
#define M           2000011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}


ll F[M],iv[M];
void prec(){
    F[0]=iv[0]=1;
    for(int i=1;i<M;++i){
        F[i]=F[i-1]*i%md;F[i]%=md;
        iv[i]=iv[i-1]*exp(i,md-2)%md;iv[i]%=md;
    }
}
ll chose(ll n,ll k){
    if(n<k)return 0;
    ll r=F[n];r=r*iv[k];r%=md;r=r*iv[n-k];return r%md;
}

ll f(ll n,ll m){if(n<0||m<0)return 0;
    ll ans=0;
    for(ll i=0;i<=n;++i){
        ans+=chose(i+m+1,i+1);
        ans%=md;
    }return ans;
}

int solve(){
    ll n,i,j,k,m,x,y,z;
    ll r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    ll ans=f(r2,c2);
    ans=ans-f(r2,c1-1);
    ans=ans-f(r1-1,c2);
    ans=ans+f(r1-1,c1-1);ans%=md;
    cout<<(ans+md)%md<<"\n"; 


    // trace(f(2,2));



	die();

}
 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif

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

    int t;
    t=1;;
    prec();
    // cin>>t;
 
    while(t--){

        solve();
    }
 
 
 
 


#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

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

const unsigned long long bigp=(1ULL<<61)-1ULL;
const unsigned long long smallp=(1ULL<<31)-1ULL;
const unsigned long long smallpplus=(1ULL<<31);
const unsigned long long smallpminus=(1ULL<<30)-1ULL;

unsigned long long b=1000000007;

class hash_mod{
    public:
    unsigned long long val;
    unsigned long long val_u, val_d;
    unsigned long long another_u, another_d;
    unsigned long long m, m_u, m_d;

    void remainder(){
        val_u=(val>>61);
        val_d=val&bigp;
        if(val_u + val_d <bigp) val= val_u + val_d;
        else val= (val_u + val_d) -bigp;
    }

    void update(unsigned long long v){
        val=v;
        remainder();
    }

    void addition(unsigned long long another){
        val+=another;
        remainder();
    }

    void subtraction(unsigned long long another){
        val+=bigp;
        val-=another;
        remainder();
    }

    void multiple(unsigned long long another){
        val_u=(val>>31);
        val_d=val&smallp;
        another_u=(another>>31);
        another_d=another&smallp;
        m=val_u*another_d + val_d*another_u;
        m_u=(m>>30);
        m_d=m&smallpminus;
        val=0;
        val+=val_u*another_u*(2ULL);
        val+=m_u + m_d*smallpplus;
        val+=val_d*another_d;
        remainder();
    }
};

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

    unsigned long long i,j;

    unsigned long long N,M;
    N=S.length();
    M=T.length();
    while(S.length()<M) S+=S;
    S+=S;

    char c='a';
    c--;

    hash_mod T_hash;
    T_hash.update(0ULL);
    for(i=0; i<M; i++){
        T_hash.multiple(b);
        T_hash.addition((unsigned long long)(T[i]-c));
    }

    hash_mod sub, b_pow;
    b_pow.update(1ULL);
    for(i=0; i<M-1; i++){
        b_pow.multiple(b);
    }

    bool in[N], out[N], visited[N];
    for(i=0; i<N; i++){
        in[i]=0;
        out[i]=0;
        visited[i]=0;
    }
    
    hash_mod S_hash;
    S_hash.update(0ULL);
    for(i=0; i<M; i++){
        S_hash.multiple(b);
        S_hash.addition((unsigned long long)(S[i]-c));
    }
    if(S_hash.val==T_hash.val){
        out[0]=1;
        in[M%N]=1;
    }
    for(i=M; i<N+M; i++){
        sub.update((unsigned long long)(S[i-M]-c));
        sub.multiple(b_pow.val);
        S_hash.subtraction(sub.val);
        S_hash.multiple(b);
        S_hash.addition((unsigned long long)(S[i]-c));
        if(S_hash.val==T_hash.val){
            out[i-(M-1)]=1;
            in[(i+1)%N]=1;
        }
    }
    //dfs
    unsigned long long ans=0, val;
    for(i=0; i<N; i++){
        if(out[i]==1&&in[i]==0){
            visited[i]=1;
            val=1;
            j = (i+M)%N;
            while(out[j]==1){
                visited[j]=1;
                val++;
                j = (j+M)%N;
            }
            ans=max(ans,val);
        }
    }
    bool loop=0;
    for(i=0; i<N; i++){
        if(visited[i]==0&&out[i]==1){
            loop=1;
        }
    }

    //output
    if(loop==1){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    system("pause");
    return 0;
}


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

int main(){
	int n ; cin >> n ;
	vector<int> t(n) ;
	int sum = 0 ;
	for(int i=0;i<n;i++){
		cin >> t.at(i) ;
		sum += t.at(i) ;
	}
	int m ; cin >> m ;
	for(int i=0;i<m;i++){
		int p,x ;
		cin >> p >> x ;
		cout << sum-t.at(p-1)+x << endl ;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF (int)1e9

using namespace std;

// 縦, 横, 答え
int H, W, ans;
// マップ
char s[50][50];
// 距離マップ
vector< vector<int> > dmap;

void bfs(){
	int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};

	// 座標キュー(y座標, x座標, 距離)
	queue< pair<pair<int, int>, int> > q;
	// 初期位置を追加
	q.push(make_pair(make_pair(0, 0), 0));
	
	// キューが空になるまでループ
	while(!q.empty()){
		// 現在のマス情報を取得
		pair< pair<int, int>, int > now = q.front();
		q.pop();
		int now_y = now.first.first, now_x = now.first.second, cost = now.second;
		
		for(int i = 0; i < 4; ++i){
			int y = now_y + dy[i], x = now_x + dx[i];
			if(0 <= y && y < H && 0 <= x && x < W && s[y][x] == '.' && dmap[y][x] == INF){
				dmap[y][x] = cost + 1;
				q.push(make_pair(make_pair(y, x), cost + 1));
			}
		}
	}
}

int main(){
	// 入力
	cin >> H >> W;
	for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) cin >> s[i][j];

	// 距離マップの初期化
	dmap = vector< vector<int> >(H);
	for(int i = 0; i < H; ++i) dmap[i] = vector<int>(W, INF);
	dmap[0][0] = 0;

	bfs();

	int white = 0;
	for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) if(s[i][j] == '.') white++; 
	int min_cost = dmap[H-1][W-1];

	ans = white - min_cost - 1;

	if(min_cost == INF) ans = -1;

	cout << ans << endl;
}

Measured memory_bytes: 256
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = id
printer = id

solver (a:b:c:d:es) = 
  if a==b || b==c || c==d then "Bad\n" else "Good\n"

Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <string>
#include <limits.h>

using namespace std;

int main(void) {
 
    
    string s; cin >> s;
    string s1;
    string s2;

    
    while (true) {
        
        s.pop_back();
        
        int size = static_cast<int>(s.size());
        int mid = size / 2;
        
        if (size % 2 == 1) { continue; }
        
        s1.clear();
        s2.clear();
        
        for (int i = 0; i < mid; ++i) {
            
            s1.push_back(s[i]);
            
        }
        
        for (int i = mid; i < size; ++i) {
            
            s2.push_back(s[i]);
            
        }
        
        if (s1 == s2) { break; }
        
    }
    
    cout << (s1.size() * 2) << endl;
    
    return 0;
    
    
}

















Measured memory_bytes: 256
while True:
    (n, m, p) = [int(x) for x in input().split()]
    if n==0 and m==0 and p==0:
        exit()
    X = []
    for i in range(n):
        X.append(int(input()))
    if X[m-1] == 0:
        print(0)
    else:
        print(int(sum(X)*(100-p)/X[m-1]))

Measured memory_bytes: 6732
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define N 1001
#define MOD 1000000007
int acs(const void* a, const void* b) { return *(int*)a - *(int*)b; }//1,2,3,4
int des(const void* a, const void* b) { return *(int*)b - *(int*)a; }//9,8,7,6
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; }//a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); }//aaa,aab
//temmie_のsnippet

int main() {
	int x,n,p,q[109];
	rep(i,107)q[i]=1;
	scanf("%d%d", &x,&n);
	rep(i,n){scanf("%d",&p);q[p]=0;}
	int ans=109,len;
	rep(i,105)if(q[i]&&ans>abs(i-x)){ans=mi(ans,abs(i-x));len=i;}
	printf("%d", len);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> data(N + 1), B(N);
  for(int i = 0; i < N + 1; i++)cin >> data.at(i);
  for(int i = 0; i < N; i++)cin >> B.at(i);
  long long count = 0;
  for(int i = N - 1; i >= 0; i--){
    if(data.at(i + 1) <= B.at(i)){
      count += data.at(i + 1);
      B.at(i) -= data.at(i + 1);
      data.at(i + 1) = 0;
    } else {
      data.at(i + 1) -= B.at(i);
      count += B.at(i);
      B.at(i) = 0;
      continue;
    }
    if(data.at(i) <= B.at(i)){
      count += data.at(i);
      B.at(i) -= data.at(i);
      data.at(i) = 0;
    } else {
      data.at(i) -= B.at(i);
      count += B.at(i);
      B.at(i) = 0;
      continue;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
input1 = gets.chomp.split
input2 = gets.chomp.split
i = 0
kyori = input2[i].to_i + input1[0].to_i - input2[input1[1].to_i - 1].to_i
while i< input1[1].to_i do
  if (input2[i].to_i - input2[i-1].to_i) > kyori then
    kyori = input2[i].to_i - input2[i-1].to_i
  end
  i += 1
end
puts input1[0].to_i - kyori

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

int main() {
  int a,b;
  cin>> a >> b;
  
  if ((a+b)%2==1) {
    cout<< "IMPOSSIBLE" <<endl;
  }
  
  else {
    cout<< (a+b)/2 <<endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define ll long long
#define umapii unordered_map <int,int>
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define endl '\n'
#define all(v) (v).begin(),(v).end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define MP(a,b) make_pair(a,b)
#define debug(x)       cerr<< #x << " : " << x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[i].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;
int a[14][14];
int c[14];
int main(){
    IOS;
    int n , m , x;
    cin >> n >> m >> x;
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    int ans = inf;
    for(int mask = 0; mask < (1 << n); ++mask){
        int cc = 0;
        vector<int> al(m, 0);
        for(int i = 0; i < n; i++){
            if(! (mask & (1 << i)) ) continue;
            cc += c[i];
            for (int j = 0; j < m; j++){
                al[j] += a[i][j];
            }
        }
        bool bad = false;
        for(int j = 0; j < m; j++){
            if(al[j] < x) bad = true;
        }
        if(bad) continue;
        ans = min(ans , cc);
    }
    if(ans == inf){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    #ifdef LOCAL
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
    // g++ -DLOCAL -std=c++17 f.cpp
}


Measured memory_bytes: 3644
# coding: utf-8
# Your code here!
h,w,a,b=map(int,input().split())
MOD=10**9+7
fac=[0]*2*10**5
finv=[0]*2*10**5
inv=[0]*2*10**5
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,2*10**5):
    fac[i]=(fac[i-1]*i)%MOD
    inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i]=finv[i-1]*inv[i]%MOD
def COM(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
ans=0
for i in range(b,w):   
    ans+=COM(h-a-1+i,i)*COM(a-1+w-i-1,w-i-1)
    ans=ans%MOD
print(ans)

Measured memory_bytes: 26740
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
using Graph = vector<vector<int>>;

int main() {
  int N;
  cin >> N;
  set<int> s;
  FOR(i,0,N) {
    int x;
    cin >> x;
    s.insert(x);
  }
  cout << s.size() << endl;
    
  return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

template<typename t1, class t2>
void input(t1 count,t2 array) {
	for(t1 i = 0;i < count;i++) {
		cin >> array[i];
	}
}

template<typename t1, class t2>
void output(t1 count,t2 array) {
	for(t1 i = 0;i < count;i++) {
		cout << array[i];
		if(i != count - 1) cout << " ";
	}
	cout << endl;
}

int n,s[100000],t[50000],q,c;

class bitset{
private:
	unsigned char* data;
public:
	bitset(unsigned int size) {
		data = new unsigned char[size / 8 + 1];
		memset(data,0,size / 8 + 1);
	}
	bool get(unsigned int index) {
		return data[index / 8] & (1 << (index % 8));
	}
	void set(unsigned int index) {
		data[index / 8] = data[index / 8] | (1 << (index % 8));
	}
};

unsigned int hs(string s) {
	unsigned int res = 0;
	for(int i = s.size()-1;i >= 0;i--) {
		res = res * 5;
		switch(s[i]) {
		case 'A':
			res += 1;
			break;
		case 'C':
			res += 2;
			break;
		case 'G':
			res += 3;
			break;
		case 'T':
			res += 4;
			break;
		}
	}
	return res;
}

int main(int argc,char** argv) {
	cin >> n;
	string s[2];
	bitset b(pow(5,12));
	for(int i = 0; i < n;i++) {
		cin >> s[0] >> s[1];
		if(s[0] == "insert") b.set(hs(s[1]));
		else {
			if(b.get(hs(s[1]))) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
}



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

int main() {
    // 20 =    x2 x3 x4
    // 11 = x1    x3 x4
    //  9 = x1 x2    x4
    // 24 = x1 x2 x3   
    //
    //   20 ^ 11 ^  9 ^ 24
    // = x1 ^ x2 ^ x3 ^ x4
    //
    // 20 ^ x1 = 20 ^ 11 ^  9 ^ 24
    // x1 = 11 ^ 9 ^ 24

    uint32_t n;
    cin >> n;

    vector<uint64_t> a(n);
    uint64_t all = 0; // x1 ^ x2 ^ ... ^ xn-1 ^ xn
    for (auto &e : a) {
        cin >> e;
        all ^= e;
    }

    for (auto &e : a) {
        cout << (all ^ e) << endl;
    }
}



Measured memory_bytes: 4820
//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
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; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s.back()=='s')s+="es";
    else s+='s';
    cout<<s<<"\n";
}

Measured memory_bytes: 3664
package main

import "fmt"

func main() {
        var n, tmp, full int
        fmt.Scan(&n)

        exists := map[int]struct{}{}
        for i := n; i > 0; i-- {
                fmt.Scan(&tmp)
                if g := grade(tmp); g == -1 {
                        full++
                } else {
                        exists[g] = struct{}{}
                }
        }
        min, max := len(exists), len(exists)+full
        if min == 0 && full > 0 {
                min = 1
        }
        fmt.Printf("%d %d\n", min, max)
}

func grade(rate int) int {
        for k := 1; k < 9; k++ {
                if rate < k*400 {
                        return k
                }
        }
        return -1
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//debug
#define vecprint(v) rep(i,v.size())cout << v[i] << " ";cout << endl;
#define setprint(s) for(auto i=s.begin();i!=s.end();i++)cout << *i << " ";cout << endl;
#define mappairprint(s) for(auto i=s.begin();i!=s.end();i++)cout << i->first << " " << i->second << endl;cout << endl;
//reader
#define r1(a) cin>>(a)
#define r2(a,b) cin>>(a)>>(b)
#define r3(a,b,c) cin>>(a)>>(b)>>(c)
//writer
#define w1(a) cout<<(a)<<" "
#define w2(a,b) cout<<(a)<<" "<<(b)<<" "
#define w3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "
#define wl1(a) cout<<(a)<<endl
#define wl2(a,b) cout<<(a)<<" "<<(b)<<endl
#define wl3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
//variable definition
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
//roop
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define all(c) c.begin(),c.end()
//term
#define elif else if
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
using namespace std;
using ll = long long;
//const
constexpr double PI = 3.141592653589793238462643383279;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};


int main() {
  //input
  int n;
  cin >> n;
  
  int a[n];
  rep(i,n) cin >> a[i];
  
  //process
  int ret = 0;
  rep(i,n) {
    if((i+1) % 2 == 1 && a[i] % 2 == 1) ret++;
  }
  
  //output
  cout << ret << endl;
}

Measured memory_bytes: 3596
if __name__ == "__main__":
    while True:
        n,p = list(map(int,input().strip().split()))
        if n == 0 and p ==0:break
        cup = p
        candidates = [0 for i in range(n)]
        current = 0
        while True:
            if cup == 0:
                cup = candidates[current]
                candidates[current] = 0

            else:
                cup = cup -1
                candidates[current] += 1
                if cup == 0 and candidates[current] == p:break
            if current ==n-1: current = 0
            else: current +=1
        print(current)

Measured memory_bytes: 7700
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[][] lst = new int[10][12];
        int b,f,r,v;
        for(int i=0;i<n;i++){
            b=sc.nextInt();f=sc.nextInt();
            r=sc.nextInt();v=sc.nextInt();
            lst[r-1][(b-1)*3+f-1]+=v;
        }
        for(int i=0;i<12;i++){
            if (i%3==0 && i>0){
                for(int x=0;x<20;x++){System.out.print("#");}
                System.out.println();
            }
            for(int j=0;j<10;j++){
                System.out.printf(" %d",lst[j][i]);
            }
            System.out.println();
        }
    }
}


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

int n,a[200010],b[200010];

bool check(int k)
{
	for (int i=1; i<2*n; i++)  b[i]=(a[i]>=k);
	for (int i=1; i<n; i++)
		{
			if ((b[n]^b[n+i])!=(i&1))  return b[n+i];
			if ((b[n]^b[n-i])!=(i&1))  return b[n-i];
		}
	return b[n]^(!(n&1));
}

void work()
{
	scanf("%d",&n);
	for (int i=1; i<2*n; i++)  scanf("%d",&a[i]);
	int l=1,r=2*n,mid;
	for (; r-l>1; (check(mid=(l+r)>>1)?l:r)=mid);
	printf("%d",l);
}

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


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz=3e3+5, mod=998244353;

ll n, s, ans, a[sz], dp[sz][sz];

ll fnc(ll pos, ll rem)
{
    if(rem<0) return 0;
    if(!rem) return n-pos+1;
    if(pos==n) return 0;
    if(dp[pos][rem]!=-1) return dp[pos][rem];

    ll x = fnc(pos+1, rem-a[pos]);
    ll y = fnc(pos+1, rem);
    if(rem == s) ans += (pos+1) * x % mod, ans %= mod;
    return dp[pos][rem] = (x + y) % mod;
}

int main()
{
    cin >> n >> s;
    for(ll i=0; i<n; i++) scanf("%lld", &a[i]);
    memset(dp, -1, sizeof(dp));
    fnc(0, s);
    cout << ans << endl;
}


Measured memory_bytes: 70912
import queue


class HW(object):
    def __init__(self, height: int, width: int):
        self.h = height
        self.w = width


h, w = map(int, input().split())
maze = [input() for i in range(h)]

cnt = 0
visited = [[0] * w for j in range(h)]


def bfs() -> int:
    q = queue.Queue()
    start = HW(0, 0)
    goal = HW(h - 1, w - 1)
    q.put([start.h, start.w])
    visited[start.h][start.w] = 1

    while q.qsize() > 0:
        tmp = q.get()
        now = HW(tmp[0], tmp[1])
        if now.h == goal.h and now.w == goal.w:
            return cnt - visited[now.h][now.w]

        for k in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
            nxt = HW(now.h + k[0], now.w + k[1])
            if not 0 <= nxt.h < h or not 0 <= nxt.w < w:
                continue
            elif maze[nxt.h][nxt.w] == '#':
                continue
            elif visited[nxt.h][nxt.w] == 0:
                q.put([nxt.h, nxt.w])
                visited[nxt.h][nxt.w] = visited[now.h][now.w] + 1
    return -1


def main() -> None:
    global cnt
    for i in range(h):
        cnt += maze[i].count('.')

    cnt = bfs()
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4080
#include<iostream>
using namespace std;
int main(){
	int n,ans=1;
	int max1=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		int temp=i;
		int cnt=0;
		while(temp%2==0){
			temp/=2;
			cnt++;
		}
		if(cnt>max1){
			max1=cnt;
			ans=i;
		}
		
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int ans = 0;

  string temp;
  int a = s.size();
  int z = 0;
  for (size_t i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      if (i < a) a = i;
    }
    if (s[i] == 'Z') {
      if (i > z) z = i;
    }
  }
  cout << z - a + 1 << endl;
  return 0;
}

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

int main() {
    ll a,b,c,d; cin >> a >> b >> c >> d;
    cout << max(0LL,min({d-a,b-c,b-a,d-c})) << endl;
}

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

int main() {
	int N, flag = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		if (s == "Y") flag = 1;
	}
	if (flag == 0) cout << "Three" << endl;
	else cout << "Four" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,d,x=0;
	scanf("%d %d",&n,&d);
	x=n/(d+d+1);
	if(n%(d+d+1)!=0){
		x=x+1;
	}	
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 1724
import sys

def main():

    # sys.stdin=open('input148e.txt')

    n = int(input())
    c = 0

    if n % 2 == 1:
        print(0)
        exit()

    r = 10
    while r <= n:
        c += n // r
        r = r * 5
    print(c) 

if __name__ == '__main__':
    main()


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

#define LL long long

using namespace std;
const int maxn=2*123456;
struct he{
    LL x,y,vx,vy;
    LL val;
}edge[maxn];
int n,m;
vector<LL> V;
int k;
LL ai[maxn];
int a,b,c;
map<LL,int> M;
bool cmp(he a,he b){
    ///if(a.val!=b.val)return a.val<b.val;
    if(a.vx!=b.vx)return a.vx<b.vx;
    return a.vy>b.vy;
}
int main(){
   // cout<<LONG_LONG_MAX<<endl;
    while(scanf("%d%d%d%d",&a,&b,&c,&k)!=EOF){
        int t=max(a,b);
        t=max(t,c);
        int sum=a+b+c-t;
        sum+=pow(2,k)*t;
        
        printf("%d\n",sum);
    }
    
    
    return 0;
}


Measured memory_bytes: 256
s=input()
def rr(a): #圧縮された要素を保持
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append([l,a[i]])
            l=1
    ll.append([l,a[-1]])
    return ll
ss=rr(s)
ans=[0]*len(s)
count=0
for i in range(0,len(ss),2):
    r,l=ss[i][0],ss[i+1][0]
    count+=r
    ans[count]+=r//2+(l+1)//2
    ans[count-1]+=(r+1)//2+l//2
    count+=l
print(*ans)

Measured memory_bytes: 19284
#include <iostream>

using namespace std;

int main()
{
    long long int a,b,k;
    cin >> a >> b;
    if((a+b)%2==0){
        k=(a+b)/2;
        cout << k << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    string str;
    getline(cin , str);
    
    for(int i=0;i<str.size();i++){
        for(int j=0;j<str.size();j++){
            if(i!=j&&str[i]==str[j]){
                cout << "no" <<"\n";
                return 0;
            }
            
        }
    }
    cout << "yes" << "\n";
    return 0;
    
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    long int n;
    long int sum = 0;
    scanf("%ld", &n);
    long int a[n],max;
    for (long int i = 0; i < n; i++)
    {
        scanf("%ld", &a[i]);
    }
    max = a[0];
    for (long int i = 1; i < n; i++)
    {
        if(max > a[i])
        {
            sum += max - a[i];
        }
        if(max < a[i])
        {
            max = a[i];
        }
    }
    printf("%ld", sum);
    return 0;
}

Measured memory_bytes: 3248
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    auto N = aryread();
    N.sort();
    writeln((N == [1, 4, 7, 9]) ? "YES" : "NO");
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    S = readstr()
    ans = 0
    for i in range(0, len(S)):
        s = S[:i]
        if s * 2 in S and s * 2 != S:
            ans = len(s * 2)

    print(ans)


if __name__ == "__main__":
    main()


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

int main (){
  int N, L, a = 0;
  cin >> N;
  L = N;
  for(int i = 0;i < 8; i++){
    a += L % 10;
    L /= 10;
  }
  if (N % a)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[]A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(Console.ReadLine());
		}
		var list = new List<int>();
      	int ct = 0;
		for(var i=0;i<N;i++){
          	int min = 0;
          	int max = ct;
          	while(min<max){
             int  m = (min+max)/2;
              if(list[m]>=A[i]){
                	min = m+1;
              } else {
                	max = m;
              }
            }
          	if(min==ct){
				list.Add(A[i]);
				ct++;
			} else {
              	list[min] = A[i];
            }
          	//for(var j=0;j<list.Count;j++){
            //  	Console.Error.Write(list[j]+" ");
            //}
          	//Console.Error.WriteLine();
		}
		Console.WriteLine(list.Count);
	}
}

Measured memory_bytes: 17316
import sys

input = sys.stdin.readline

n, x = map(int, input().split())
l_list = list(map(int, input().split()))

count = 1

current = 0

for l in l_list:
    current += l
    count += 1
    if current > x:
        break

if current > x:
    print(count - 1)
else:
    print(count)


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

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> vec(M);
  for(int i=0; i<M; i++){
    cin >> vec.at(i);
  }
  
  int toll_a = 0;
  int toll_b = 0;
  for(int j=0; j<M; j++){
    for(int k=0; k<X; k++){
     if(k == vec.at(j)){
       toll_a++;
     }
    }
    for(int l=X; l<N; l++){
     if(l == vec.at(j)){
       toll_b++;
     }
    }
  }
  
  cout << min(toll_a,toll_b) << endl;
  
}

Measured memory_bytes: 256