akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ljc 1000000007
using namespace std;
ll n,m,L,inv[1010101],fac[1010101];
ll f[1010101],sumf[1010101];
inline ll fast_pow(ll a,ll b,ll p){
	ll t=1;
	while (b){
		if (b&1ll) t=t*a%p;
		b>>=1ll;a=a*a%p;
	}
	return t;
}
inline ll C(ll n,ll m){
	if (n<0||m<0) return 0;
	if (m>n) return 0;
	return fac[n]*inv[m]%ljc*inv[n-m]%ljc;
}
signed main(){
	cin>>n>>m>>L;
	inv[0]=inv[1]=fac[1]=fac[0]=1;
	ll M=max(n,max(m,L));
	for (ll i=2;i<=3*M+2;i++) fac[i]=fac[i-1]*i%ljc;
	for (ll i=2;i<=3*M+2;i++) inv[i]=(ljc-(ljc/i)*inv[ljc%i]%ljc)%ljc;
	for (ll i=2;i<=3*M+2;i++) inv[i]=inv[i-1]*inv[i]%ljc;
	if (m>L) swap(m,L); 
	ll ans=0,inv3=fast_pow(3,ljc-2,ljc);
	for (ll t=0,sum=1,pw=fast_pow(3,m+L,ljc);t<=m+L;t++){
		ans=(ans+pw*C(n+t-1,n-1)%ljc*sum%ljc)%ljc;
		if (t<m) sum=sum*2%ljc;
		else if (m<=t&&t<L) sum=(2*sum%ljc-C(t,m)+ljc)%ljc;
		else sum=(2*sum%ljc-C(t,m)-C(t,t-L)+2*ljc)%ljc;
		pw=pw*inv3%ljc;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 16640
N = int(input())
a = [int(e) for e in input().split()]

su = [0] * 9
for e in a:
    if e >= 3200:
        su[8] += 1
    else:
        su[e//400] += 1
mi = 0
for e in su[:8]:
    if e != 0:
        mi += 1
ma = mi+su[8]
mi = max(1, mi)
print(mi, ma)

Measured memory_bytes: 3064
s = list(input())
c = None
f = None

for i in range(len(s)):
    if c == None and s[i] == 'C':
        c = i
    
    if s[i] == 'F':
        f = i
        if c != None:
            break

if c == None or f == None:
    print('No')
else:
    if c > f:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,a,b;
int height(int x){
    int res;
    res = (x * (1+x))/2;
    return res;
}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b;
    cout<<height(b-a-1)-a<<newl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100005;

int n,cnt,last[N],sg[N];
struct edge{int to,next;}e[N*2];

int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

void addedge(int u,int v)
{
    e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
    e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;
}

void dfs(int x,int fa)
{
    for (int i=last[x];i;i=e[i].next)
    {
        if (e[i].to==fa) continue;
        dfs(e[i].to,x);
        sg[x]^=sg[e[i].to]+1;
    }
}

int main()
{
    n=read();
    for (int i=1;i<n;i++)
    {
        int x=read(),y=read();
        addedge(x,y);
    }
    dfs(1,0);
    if (sg[1]) puts("Alice");
    else puts("Bob");
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    int N,M;
    cin >> N >> M;
    if(N == 0) {
        if(M == 0 || M == 1) {
            cout << 0 << endl;
        }
        else cout << COM(M,2) << endl;
    }
    else if(M == 0 || M == 1) {
        cout << COM(N,2) << endl;
    } else {
        cout << COM(N,2) + COM(M,2) << endl;
    }
}

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

//  a^b % m
long long powmod(long long a, long long b, long long m)
{
    long long r = 1;
    for (; b>0; b>>=1, a=a*a%m)
        if (b&1)
            r = r*a%m;
    return r;
}

int main()
{
    int N;
    cin>>N;
    vector<vector<int>> E(N);
    for (int i=0; i<N-1; i++)
    {
        int a, b;
        cin>>a>>b;
        E[a-1].push_back(b-1);
        E[b-1].push_back(a-1);
    }

    vector<vector<int>> V(N);
    vector<vector<long long>> P(N);
    for (int i=0; i<N; i++)
    {
        V[i] = vector<int>(E[i].size()+1, -1);
        P[i] = vector<long long>(E[i].size()+1);
    }

    long long M = 1000000007LL;
    vector<long long> F(N+1);
    F[0] = 1;
    for (int i=1; i<=N; i++)
        F[i] = F[i-1]*i%M;
    vector<long long> IF(N+1);
    for (int i=0; i<=N; i++)
        IF[i] = powmod(F[i], M-2, M);

    function<void(int, int)> f1 = [&](int c, int p)
    {
        int pi;
        if (p==-1)
            pi = (int)E[c].size();
        else
            for (int i=0; i<(int)E[c].size(); i++)
                if (E[c][i]==p)
                    pi = i;
        if (V[c][pi]!=-1)
            return;

        int v = 0;
        long long pp = 1;

        for (int e: E[c])
            if (e!=p)
            {
                f1(e, c);
                int ei = 0;
                for (int i=0; i<(int)E[e].size(); i++)
                    if (E[e][i]==c)
                        ei = i;
                v += V[e][ei];
                pp *= P[e][ei];
                pp %= M;
                pp *= IF[V[e][ei]];
                pp %= M;
            }
        V[c][pi] = v + 1;
        P[c][pi] = pp*F[v]%M;
    };
    f1(0, -1);

    function<void(int, int)> f2 = [&](int c, int p)
    {
        if (p!=-1)
        {
            int pi=0;
            for (int i=0; i<(int)E[c].size(); i++)
                if (E[c][i]==p)
                    pi = i;

            long long tp = P[p][P[p].size()-1];

            tp *= IF[N-1];
            tp %= M;
            tp *= F[V[c][pi]];
            tp %= M;
            tp *= F[N-V[c][pi]-1];
            tp %= M;
            tp *= powmod(P[c][pi], M-2, M);
            tp %= M;

            P[c][P[c].size()-1] = P[c][pi]*IF[V[c][pi]-1]%M*F[N-1]%M*IF[N-V[c][pi]]%M*tp%M;
        }

        for (int e: E[c])
            if (e!=p)
                f2(e, c);
    };
    f2(0, -1);

    for (int i=0; i<N; i++)
        cout<<P[i][P[i].size()-1]<<endl;
}


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

using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define reep(i,a,b) for(int i=a; i<b; i++)
#define INF 0x3f3f3f3f


int wf[310][310];
int dist[17][17];
int dp[17][1<<17];

typedef vector<int> vint;

int main(){
	int n,m,l,s,t;
	while(cin>>n>>m>>l>>s>>t,n){
		rep(i,n) rep(j,n) wf[i][j] = INF;
		rep(i,n) wf[i][i] = 0;
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			a--,b--;
			wf[a][b] = wf[b][a] = c;
		}
		rep(k,n) rep(i,n) rep(j,n){
			wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
		}
		vint ramen(l+1);
		vint cost(l+1);
		rep(i,l){
			cin>>ramen[i]>>cost[i];
			ramen[i]--;
		}
		s--;
		ramen[l] = s;
		cost[l] = 0;
		rep(i,l+1){
		rep(j,l+1){
				dist[i][j] = wf[ramen[i]][ramen[j]];		
			}
		}
		rep(i,l+1){
			rep(j,1<<(l+1)){
				dp[i][j] = INF;
			}
		}
		dp[l][0] = 0;
		rep(i,1<<(l+1)){
			rep(j,l+1){
				rep(k,l+1){
					int state = i|(1<<k);
					dp[k][state] = min(dp[k][state], dp[j][i]+dist[j][k]+cost[k]);
				}
			}
		}						
		int ans = 0;
		rep(i,1<<(l+1)){
			if(dp[l][i] <= t){
				ans = max(ans, (int)__builtin_popcount(i));
			}
		}
		cout<<ans-1<<endl;
	}
}

Measured memory_bytes: 12088
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#include<cstdio>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include<set>
#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)
#define INF9                1000000010
#define INF18               1000000000000000010
#define dist(ax,ay,bx,by)   sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
#define gcd(a,b)            __gcd(a,b)
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define m_p(a,b)            make_pair(a,b)
#define sqr(a)              ((a)*(a))
#define pb                  push_back
#define bpll(a)             __builtin_popcountll(a)
#define MX                  200006
#define PI                  acos(-1)
#define mod                  1000000007
#define cnt_bin(n)          __builtin_clzll(0ll) - __builtin_clzll(n)

typedef long long lli;
using namespace std;

bool mark[2005];
vector<lli>primes;
lli n, m, k;

bool check(lli n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    return mark[n]==false;
}

void sieve(lli n)
{
    for(lli i=3; i*i<=n; i+=2)
    {
        if(mark[i]==false)
        {
            for(lli j=i*i; j<=n; j+=2*i) mark[j]=true;
        }
    }
}

map<lli, lli>mp;

vector<lli>ara;

int main()
{
    // READ;
    sieve(2000);

    for(lli i=0; i<2000; i++)
    {
        if(check(i)) primes.push_back(i);
    }

    lli n;
    scanf("%lld", &n);

    lli gc= 0;

    for(lli i=0; i<n; i++)
    {
        lli a;
        scanf("%lld", &a);
        ara.push_back(a);
        gc= gcd(gc, a);
    }

    bool found= true;

    for(lli x=0; x<n; x++)
    {
        lli num= ara[x];

        for(lli i=0; i<primes.size() && primes[i]*primes[i]<=num; i++)
        {
            if(num%primes[i]==0)
            {
                mp[primes[i]]++;
                if(mp[primes[i]]>1) found=false;

                while(num%primes[i]==0)
                {
                    num/=primes[i];
                }
            }
        }

        if(num>1)
        {
            mp[num]++;
            if(mp[num]>1) found=false;
        }
    }

    if(found) cout<<"pairwise coprime"<<endl;
    else if(gc==1) cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;

    return 0;
}


Measured memory_bytes: 16008
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fucking interest
*******************************
Higher, higher, even higher, to the point you won’t even be able to see me
https://www.a2oj.com/Ladder16.html
*******************************
NEVER DO 300IQ CONTESTS EVER
300IQ AS WRITER = EXTRA NONO
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int x: arr)
            res += x;
         int left = 0;
         int right = res;
         for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         }
         System.out.println(res);
      }
   }

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

int main(){
  ll n, d = 0;
  cin >> n;
  ll a[n], b[n];
  priority_queue<P> que;
  rep(i,n) cin >> a[i];
  rep(i,n) {
    cin >> b[i];
    que.push(P(b[i],i));
  }
  while(!que.empty()) {
    P p = que.top();
    que.pop();
    int l = (p.second-1+n) % n, r = (p.second+1) % n;
    ll s = b[l] + b[r];
    ll c = min(b[p.second]/s,(b[p.second]-a[p.second])/s);
    if(c > 0) {
      b[p.second] -= s*c;
      que.push(P(b[p.second],p.second));
      d += c;
    } 
  }
  rep(i,n) {
    if(a[i] != b[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << d << endl;
  return 0;
}

Measured memory_bytes: 8944
#include <bits/stdc++.h>
using namespace std;
struct num
{
    int data;
    int n;
}a[200005];
bool cmp(num x,num y)
{
    return x.data<y.data;
}
int main()
{
    int N,i,j,l,r,b[200005];
    memset(b,0,sizeof(b));
    memset(a,0,sizeof(a));
    scanf("%d",&N);
    for(i=1;i<=N;i++)
        {scanf("%d",&a[i].data);
        a[i].n=i;
        }
    sort(a+1,a+N+1,cmp);
    r=a[N/2+1].data;
    l=a[N/2].data;
    for(i=1;i<=N;i++)
    {
        if(i<=N/2)
            b[a[i].n]=r;
        else
             b[a[i].n]=l;
    }
    for(i=1;i<=N;i++)
    {
        printf("%d",b[i]);
        if(i!=N)
            printf("\n");
    }
    return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
   	cin>>s;
   	string s1 = "YAKI";
   	bool passed= (s.size() >= s1.size() ?  true : false);
   	for(int i=0;i<s1.size()&&i<s.size();i++) {
       if(s1[i]!=s[i]){
       		passed=false;
	   		break;
	   }
   }
   cout<<(passed ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
char s[200010];
int main()
{
	scanf("%s",s+1);int n=strlen(s+1);
	int now=0;
	for(int i=1;i<=n;i++)
		if(((s[i]-'0')&1)==(i&1))now++;
	int ans=now;now=0;
	for(int i=1;i<=n;i++)
		if(((s[i]-'0')&1)!=(i&1))now++;
	ans=min(ans,now);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int a,b,c,i,ans = 0;
	scanf("%d %d %d",&a,&b,&c);
	for (i=a; i<=b; i++) {
		if(c%i == 0) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 596
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int arr[5], res=0;


    loop(i, 0, 4){
        cin>>arr[i];
        if(arr[i] == 0){
            if(i == 0)
                res = 1;
            else
                res = arr[i-1]+1;

            break;
        }

    }
    cout<<res;


}



Measured memory_bytes: 3628
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int MAX_X = 10010;
    for(int i=0; i<MAX_X; i++){
        int x;
        cin >> x;
        if(x == 0){
            break;
        }else{
            printf("Case %d: %d\n", i+1, x);
        }
    }
}


Measured memory_bytes: 3080
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

int main(){

    
    cin >> N;
    cin >> K;

    ll d;
    ll MEM[N+1]={};

    rep(ki,K){
        cin >> d;
        rep(di,d){
            int tmp;
            cin >> tmp;
            MEM[tmp]=1;
        }
    }
    ll cnt=0;
    for( int ni = 1 ; ni <=N ; ni++ ){
        if(MEM[ni]==0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3640
k = int(input())
cur = 7
t = cur%k
flag = False
for i in range(1,k+1):
    if t == 0:
        print(i)
        flag = True
        break
    else:
        t = (10*t)%k
        t += 7
        t %= k
if not flag:
    print(-1)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {

  ll H, A;
  cin >> H >> A;

  ll ans = 0;
  if ( H % A == 0 ) {
    ans  = (H / A);
  }
  else {
    ans  = (H / A) + 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
        int x;
        for(int i=1; i<=10000; i++){
            cin >> x;
            if(x !=0){
                cout << "Case " << i << ": " << x << endl;     
                }
        else{
            break;
        }
        }
        return 0;
}


Measured memory_bytes: 3104
S = input()
K = int(input())

def a(SS):
    count = 0
    samestr = 0
    for i in range(len(SS)-1):
        if SS[i] == SS[i+1]:
            samestr += 1
        else:
            count += ((samestr+1)//2)
            samestr = 0
    count += ((samestr+1)//2)
    return count


if not len(set(S)) == 1:
    singlec = a(S)
    if K == 1:
        print(singlec)
    else:
        doublec = a(S+S)
        sac = doublec - singlec*2
        result = singlec*K + sac*(K-1)
        print(result)
else:
    print( (len(S)*K)//2 )

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 1

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    ll ans = 0;
    map<string, int> mp;
    string str;
    for (int i = 1; i <= n; i++)
    {
        cin >> str;
        sort(str.begin(), str.end());
        ans += mp[str];
        mp[str]++;
    }
    cout << ans << endl;
}

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

typedef long long ll;
ll MOD = 1000000007;

int main()
{
    int N, D, cnt = 0, ans = 0;
    cin >> N >> D;
    int X[10][10];
    vector <int> b;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    while (1) {
        if (cnt*cnt > 10 * 1600) break;
        b.push_back(cnt*cnt);
        cnt++;
    }


    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            cnt = 0;
            for (int k = 0; k < D; k++) {
                int x = X[i][k] - X[j][k];
                cnt += x * x;
            }
            for (int l = 0; l < b.size(); l++) {
                if (cnt == b[l]) {
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100
static const int dx[4] = {1, 0, -1, 0};
static const int dy[4] = {0, -1, 0, 1};
int w, h, sx, sy, gx, gy, G[MAX+2][MAX+2];
bool dfs( int x, int y, int color ){
 if ( color == 0 || G[x][y] != color ) return false;
 if ( x == gx && y == gy ) return true;
 G[x][y] = 0;
 for ( int r = 0; r < 4; r++ ){
if ( dfs(x + dx[r], y + dy[r], color) ) return true;
 }
 return false;
}
main(){
 int n, c, d, px, py, ww, hh;
 while( cin >> w >> h && w ){
cin >> sx >> sy >> gx >> gy >> n;
for ( int y = 0; y < h+2; y++ )
 for ( int x = 0; x < w+2; x++ ) G[x][y] = 0;
for ( int i = 1; i <=n; i++ ){
 cin >> c >> d >> px >> py;
 if ( d == 0 ) { ww = 4; hh = 2; }
 else { ww = 2; hh = 4; }
 for ( int y = 0; y <= hh-1; y++ )
for ( int x = 0; x <= ww-1; x++ ) G[px+x][py+y] = c;
}
if ( dfs(sx, sy, G[sx][sy]) ) cout << "OK" << endl;
else cout << "NG" << endl;
 }
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)

int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
int dxx[]={1,1,0,-1,-1,-1,0,1};
int dyy[]={0,-1,-1,-1,0,1,1,1};
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;


int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  int ho=a-c,ge=b-d;
  int hoge;
  int geho;
  int e=c+ge;
  int f=d-ho;
  int g=e+ho;
  int h=f+ge;

  cout <<e<<" "<<f<<" "<<g<<" "<<h<<endl;

  

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int[] a = new int[N];
        for (int i=0;i<N;i++) {
            a[i] = sc.nextInt();
        }
        for (int i=0;i<N-1;i++) {
            if (a[i]+a[i+1]>=L) {
                System.out.println("Possible");
                for (int j=0;j<i;j++) {
                    System.out.println(j+1);
                }
                for (int j=N-2;j>=i;j--) {
                    System.out.println(j+1);
                }
                return;
            }
        }
        System.out.println("Impossible");
    }
}


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

int main() {
	std::size_t n, c, k;
	std::cin >> n >> c >> k;

	std::vector<std::size_t> ts;
	ts.reserve(n);
	for (std::size_t i = 0; i < n; ++i) {
		std::size_t t;
		std::cin >> t;
		ts.emplace_back(t);
	}
	std::sort(std::begin(ts), std::end(ts));

	std::size_t required = 0;
	std::size_t boarded = 0;
	std::size_t acceptable_max = 0;
	for (std::size_t t : ts) {
		if (t > acceptable_max || boarded >= c) {
			++required;
			acceptable_max = t + k;
			boarded = 0;
		}
		++boarded;
	}
	std::cout << required << std::endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    map<int,int> count;
    rep(i, N) count[A[i]]++;
    int ans = 0;
    rep(j, N){
        vector<int> primes;
        int a = A[j];
        if(count[a] > 1) continue;
        int i = 1;
        while(i * i <= a){
            if(a % i == 0){
                primes.push_back(i);
                primes.push_back(a/i);
            }
            i++;
        }
        bool judge = true;
        rep(x, primes.size()){
            if(primes[x] == a) continue;
            if(count[primes[x]] > 0){
                judge = false;
                break;                
            }
        }
        if(judge) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 32740
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
#define mp make_pair
#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (int)1e18
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;
string s;
int n;


 
signed main()
{
    haha
    int a,b,c;
    cin>>a>>b>>c;
    int s1=4*a*b;
    int s2=(c-a-b)*(c-a-b);
  
    if(s1<s2 && c>(a+b))
    cout<<"Yes";
    else
    cout<<"No";
    
  
 
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  int N, A, B;
  cin >> N >> A >> B;

  int A_p = N*A; //Aプランの料金
  if(A_p < B) //Aプランの方が安い
    cout << A_p << endl;
  else //Aプランの方が高い
    cout << B << endl;
  
  return 0;
}


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

int main(){
    int m, f, r;
    while (1){
        scanf("%d %d %d", &m, &f, &r);
        if (m==-1 && f==-1 && r==-1) break;
        
        if (m==-1 || f==-1) printf("F");
        else if (m+f >= 80) printf("A");
        else if (m+f >=65 && m+f < 80) printf("B");
        else if (m+f >=50 && m+f < 65) printf("C");
        else if (m+f >=30 && m+f < 50){
            if (r >= 50) printf("C");
            else printf("D");
        }
        else if (m+f < 30) printf("F");
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
using namespace std;
int main()
{
	int a[3];
	int i;
	int j;
	int tmp;
	for (i = 0;i < 3; i++)
	{
		cin >> a[i];
	}
//昇順
	for (i = 0; i < 3; ++i) 
	{
		for (j = i + 1; j < 3; ++j) {
			if (a[i] > a[j]) {
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}

	cout << a[0]<< " " << a[1] << " " << a[2] << endl;

}


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> A.at(i).at(j);
    }
  }
  
  for(int i = 0; i < H; i++){
    bool blank = true;
    for(int j = 0; j < W; j++){
      if(A.at(i).at(j) == '#'){
        blank = false;
        break;
      }
    }
    if(blank == true){
      for(int j = 0; j < W; j++){
        A.at(i).at(j) = '*';
      }
    }
  }
  
  for(int j = 0; j < W; j++){
    bool blank = true;
    for(int i = 0; i < H; i++){
      if(A.at(i).at(j) == '#'){
        blank = false;
        break;
      }
    }
    if(blank == true){
      for(int i = 0; i < H; i++){
        A.at(i).at(j) = '*';
      }
    }
  }
  
  
  for(int i = 0; i < H; i++){
    bool blank = true;
    for(int j = 0; j < W; j++){
      if(A.at(i).at(j) != '*'){
        cout << A.at(i).at(j);
        blank = false;
      }
    }
    if(blank == false) cout << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
int n,k;

ll dfs(int x, int r){
    if(r==0) return 1;

    ll ret = 0;
    for(int i=2; x*i<=n; ++i) ret += dfs(x*i, r-1);
    return ret;
}

int main(){
    cin >>n >>k;
    ll ans = 0;
    for(int i=1; i<=n; ++i) ans += dfs(i,k-1);
    cout << ans << endl;
    return 0;
}



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

int main(){
  int W, H, N;
  cin >> W >> H >> N;
  int x[N], y[N], a[N];
  rep(i, N){
    cin >> x[i] >> y[i] >> a[i];
  }
  int p=0, q=W, r=0, s=H;
  rep(i, N){
    if(a[i] == 1)
      p = max(x[i], p);
    if(a[i] == 2)
      q = min(x[i], q);
    if(a[i] == 3)
      r = max(y[i], r);
    if(a[i] == 4)
      s = min(y[i], s);
  }
  int ansW = max(0, q-p);
  int ansH = max(0, s-r);
  cout << ansW*ansH << endl;
 
}

Measured memory_bytes: 256
#include<stdio.h>
#define X 10000
int main(){
  int S[X],T[X],N,Q,n,q,count=0;
  scanf("%d",&N);
  for(n = 0 ; n < N ; n++) scanf("%d",&S[n]);
  scanf("%d",&Q);
  for(q = 0 ; q < Q ; q++){
     scanf("%d",&T[q]);
    S[N]=T[q];
    for(n = 0 ; n < N ; n++){
      if(S[n] == S[N]){
	count++;
	break;
      }
      
    }

  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2048
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int ans = 0;
    if (n >= 2) {
      ans += n * (n - 1) / 2;
    }
    if (m >= 2) {
      ans += m * (m - 1) / 2;
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 210, inf = 1e9;

int n, g[N][N], col[N], ans, f[N][N];
char s[N];
queue<int> que;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

bool dfs1(int now) {
    for (R int i = 1; i <= n; ++i) {
        if (!g[now][i]) continue;
        if (col[i]) {
            if (col[i] == col[now]) return 0;
            continue;
        }
        col[i] = col[now] ^ 1;
        if (!dfs1(i)) return 0;
    }
    return 1;
}

int main() {
    read(n);
    for (R int i = 1; i <= n; ++i) {
        scanf("%s", s + 1);
        for (R int j = 1; j <= n; ++j)
            g[i][j] = s[j] - '0';
    }
    if ((col[1] = 2) && !dfs1(1)) return printf("-1\n"), 0;
    
    for (R int i = 1; i <= n; ++i) {
        memset(col, 0, sizeof (col));
        while (que.size()) que.pop();
        que.push(i), col[i] = 1;
        while (que.size()) {
            int now = que.front();
            que.pop(), ans = max(ans, col[now]);
            for (R int j = 1; j <= n; ++j) {
                if (!g[now][j] || col[j]) continue;
                col[j] = col[now] + 1, que.push(j);
            }
        }
    }/*
    for (R int i = 1; i <= n; ++i) {
        for (R int j = 1; j <= n; ++j)
            f[i][j] = g[i][j] ? 1 : inf;
        f[i][i] = 0;
    }
    for (R int i = 1; i <= n; ++i)
        for (R int j = 1; j <= n; ++j)
            for (R int k = 1; k <= n; ++k)
                f[j][k] = min(f[j][i] + f[i][k], f[j][k]);
    for (R int i = 1; i <= n; ++i)
        for (R int j = 1; j <= n; ++j)
            if (f[i][j] != inf) ans = max(ans, f[i][j]);*/
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	int ans =0 ;
	for(int i = 1; i <= n ; i ++)
		for(int j = 1; j <= n ;j ++)
			for(int k = 1 ; k <= n ; k ++)
				ans ++;
			printf("%d", ans);
	return 0;
}


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

int main(void) {
  int n, m; cin >> n >> m;
  vector<int> xt(n+1); cin >> xt[0];
  vector<int> yt(m+1); cin >> yt[0];
  for (int i=1; i<n+1; i++) cin >> xt.at(i);
  for (int i=1; i<m+1; i++) cin >> yt.at(i);
  sort(xt.begin(), xt.end());
  sort(yt.begin(), yt.end());
  
  if (xt[n] >= yt[0]) {
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }
  
  return 0;
}

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


int main(){
    int n, m, A[100][100], b[100], c[100];

    cin >> n >> m;
    for ( int i = 0; i < n; i++)
        for (int j = 0; j < m ; j++) cin >> A[i][j];
    for (int i = 0; i < m; i++) cin >> b[i];

    for( int i = 0;i < n; i++){
        c[i] = 0;
        for (int j = 0; j < m; j++){
            c[i] += A[i][j]*b[j];
    }
}

for ( int i =0; i < n; i++) cout << c[i] << endl;

return 0;
}

Measured memory_bytes: 3096
fun main() {
    val (X, N) = readLine()!!.split(" ").map { it.toInt() }
    var P = readLine()!!

    if(P.isEmpty()){
        println(X)
        return
    }
    val p = P.split(" ").map { it.toInt() }
    
    var i = 0
    while (true){
        if(!p.contains(X - i)){
            println(X - i)
            return
        }
        if(!p.contains(X + i)){
            println(X + i)
            return
        }
        i++
    }
}

Measured memory_bytes: 36512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}

struct SegmentTree{
private:
    ll unit = 0;
    ll op(ll a,ll b){return a | b;}
    ll n;
    vector<ll> node;

public:
SegmentTree(vector<ll> v){
    ll sz = (ll)v.size();
    n = 1;while(n<sz) n *= 2;
    node.resize(2*n-1,unit);
    for(ll i=0;i<sz;i++) node[i+n-1]=v[i];
    for(ll i=n-2;i>=0;i--) node[i]=op(node[2*i+1],node[2*i+2]);
}

    void update(ll x,ll val){
        x += n-1;
        node[x] = val;
        while(x>0){
            x = (x-1)/2;
            node[x] = op(node[2*x+1],node[2*x+2]);
        }
    }

    ll query(ll a,ll b,ll k = 0,ll l = 0,ll r = -1){
        if (r<0) r = n;
        if (r<=a || b<=l) return unit;
        if (a<=l && r<=b) return node[k];
        ll vl = query(a,b,2*k+1,l,(l+r)/2);
        ll vr = query(a,b,2*k+2,(l+r)/2,r);
        return op(vl,vr);
    }
};

int main(){
    ll N;cin >> N;
    string S ; cin >> S;
    ll Q;cin >> Q;
    vector<ll> sd(N); rep(i,N) sd[i] = 1<<(S[i] - 'a'); 
    SegmentTree st(sd);
    rep(i,Q){
        ll q;cin >> q;
        if(q==1){
            ll idx;cin >> idx;
            char c;cin >>c;
            st.update(idx-1,1<<(c-'a'));
        }else{
            ll l,r;cin >> l >> r;
            cout << __builtin_popcount(st.query(l-1,r)) << endl;
        }
    }
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  if(S.at(2)==S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" << endl;
  
}


// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;

#define loop(i,n) for(i64 i = 0; i < (n); ++i)
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";

i64 h,w,n;
int main() 
{ 
    fastInOut
    cin>>h>>w>>n;
    cout<<((n%(max(h,w)))==0?(n/max(h,w)):(n/max(h,w))+1);
   return 0; 
} 

Measured memory_bytes: 256
using System;
using System.IO;

class Solve
{
    static void Main(string[] args) {
        var arr = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
        int N = arr[0], K = arr[1];
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var dp = new int[N] ;
        var len = dp.Length;
        for (int i = 0; i < len; i++) dp[i] = int.MaxValue;
        dp[0] = 0;
        dp[1] = Math.Abs(h[1] - h[0]);
        for (int i = 1; i < N; i++) {
            for (int j = 1; j <= K; j++) {
                if (i - j >= 0) dp[i] = Math.Min(dp[i], dp[i - j] + Math.Abs(h[i] - h[i - j]));
            }
        }
        var answer = dp[^1];
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 35780
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

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

	int n,l;
	cin>>l>>n;
	vi in(n+2);
	rep(i,n)cin>>in[i+1];
	in[n+1]=l;
	vi x(n+1),y(n+1);
	rep(i,n)x[i+1]=x[i]+in[i+1];
	rep(i,n)y[i+1]=y[i]+l-in[n-i];
	int out=0;
	rep(i,n+1){
		if(i<=n-i){
			cmax(out,2*(x[i]+y[n-i]-y[n-i-i])-in[i]);
			cmax(out,2*(x[i]+y[n-i]-y[n-i-i-1])-(l-in[i+1]));
		}
		if(i>=n-i){
			cmax(out,2*(x[i]+y[n-i]-x[i-n+i])-(l-in[i+1]));
			cmax(out,2*(x[i]+y[n-i]-x[i-n+i-1])-in[i]);
		}
		
	}
	cout<<out<<endl;
}






Measured memory_bytes: 4992
import java.io.*;

public class Main{
	public static void main(String[] argv) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while((line = br.readLine()) != null){
			StringBuffer reverse = new StringBuffer().append(line);
			System.out.print(reverse.reverse()+"\n");
		}
	}
}

Measured memory_bytes: 15016
from typing import Tuple


def cross(a: Tuple[int, int], b: Tuple[int, int]) -> float:
    return float(a[0] * b[1] - a[1] * b[0])


if __name__ == "__main__":
    q = int(input())
    for _ in range(q):
        x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(lambda x: int(x),
                                                             input().split())
        if x_p1 < x_p0:
            x_p0, x_p1 = x_p1, x_p0
            y_p0, y_p1 = y_p1, y_p0
        if x_p3 < x_p2:
            x_p2, x_p3 = x_p3, x_p2
            y_p2, y_p3 = y_p3, y_p2

        min_x1, max_x1 = x_p0, x_p1
        min_y1, max_y1 = (y_p0, y_p1) if y_p0 < y_p1 else (y_p1, y_p0)
        min_x2, max_x2 = x_p2, x_p3
        min_y2, max_y2 = (y_p2, y_p3) if y_p2 < y_p3 else (y_p3, y_p2)

        if any((max_x1 < min_x2, max_x2 < min_x1, max_y1 < min_y2, max_y2 < min_y1)):
            print(0)
            continue

        s01 = (x_p1 - x_p0, y_p1 - y_p0)
        s02 = (x_p2 - x_p0, y_p2 - y_p0)
        s03 = (x_p3 - x_p0, y_p3 - y_p0)
        s21 = (x_p1 - x_p2, y_p1 - y_p2)
        s20 = (x_p0 - x_p2, y_p0 - y_p2)
        s23 = (x_p3 - x_p2, y_p3 - y_p2)

        print(int(cross(s01, s02) * cross(s01, s03) < 1e-6
              and cross(s23, s20) * cross(s23, s21) < 1e-6))



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

int main() {
    int h, n, a;
    cin >> h >> n;
    int s = 0;
    for (int i = 0; i < n; ++i) {
      cin >> a;
      s += a;
    }
    if (h <= s) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n,i,j,m,f;
	char a[256],b[256],x;
	while(1){
	scanf("%d ",&n);
	if(n==0){
		break;
        }

	for(i=0;i<n;i++){
		scanf("%s %s",&a[i],&b[i]);
	}
	
	scanf("%d ",&m);
	for(i=0;i<m;i++){
		scanf("%s",&x);
		f=0;
		for(j=0;j<n;j++){
		 if(x==a[j]){
			printf("%c",b[j]);
			f=1;
			break;
		 }
	    }
	 if(f==0){
	    printf("%c",x);
	 }
	}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1008
N, M = map(int, input().split())
list = []
for i in range(M):
    L, R = map(int, input().split())
    list.append([L,R])
anslist = [list[0][0],list[0][1]]
arukadouka = True
cnt = 0
for i in range(1,M):
    if arukadouka == True:
        if anslist[0] > list[i][1]:
            arukadouka = False
        elif anslist[1] < list[i][0]:
            arukadouka = False
        elif list[i][0] == list[i][1]:
            anslist[0] = list[i][0]
            anslist[1] = list[i][1]
        else:
            if (anslist[0]<=list[i][0]) and (anslist[1]<=list[i][1]):
                anslist[0] = list[i][0]
            elif (anslist[0]<=list[i][0]) and (anslist[1]>=list[i][1]):
                anslist[0] = list[i][0]
                anslist[1] = list[i][1]
            elif (anslist[0]>=list[i][0]) and (anslist[1]<=list[i][1]):
                pass
            elif (anslist[0]>=list[i][0]) and (anslist[1]>=list[i][1]):
                anslist[1] = list[i][1]
        cnt += 1
if arukadouka == True:
    ans = anslist[1]-anslist[0]+1
else:
    ans = 0
print(ans)

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    rep(i, N) cin >> x[i];

    int ans = 1e9;

    for (int left = 0; left + K <= N; left++) {
        // xi〜xi+Kまで。
        
        int right = left + K - 1;

        int dist = x[right] - x[left];

        // 先にleftから。
        ans = min(ans, dist + abs(x[left]));

        // 先にrightから。
        ans = min(ans, dist + abs(x[right]));

    }

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

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 58) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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 V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

int main() {
  int N, Q;
  string S;
  cin >> N >> S >> Q;

  int bit[500000] = {};
  for(int i = 0; i < N; i++) {
    bit[i] = S[i] - 'a';
    bit[i] = 1 << bit[i];
  }

  for(int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if(t == 1) {
      int k;
      char c;
      cin >> k >> c;
      --k;
      bit[k] = c - 'a';
      bit[k] = 1 << bit[k];
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      int tap = 0;
      for(int k = l; k < r; k++) tap |= bit[k];
      cout << __builtin_popcount(tap) << endl;
    }
  }
}



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

int main() {
  int N;
  cin >> N;
  
  ll int result = 0;
  
  for(int i = 1; i <= N; ++i) {
    if(i % 3 != 0 && i % 5 != 0) {
      result += i;
    }
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;
	vector<int> A( N+1 );
	for( int i = 1; i <= N; ++i ) { cin >> A[i]; }

	vector<vector<long>> dp( N+1, vector<long>( 2 ) );
	dp[0][0] = 0;
	dp[0][1] = -INT_MAX;

	for( int i = 1; i <= N; ++i ) {
		dp[i][0] = max( dp[i-1][0] + A[i], dp[i-1][1] - A[i] );
		dp[i][1] = max( dp[i-1][0] - A[i], dp[i-1][1] + A[i] );
	}

	cout << dp[N][0] << endl;

	return 0;
}


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

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

  string S;
  cin >> S;

  int ans = 0;
  int tmp = 0;

  REP(i, S.size()) {
    if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      tmp += 1;
    } else {
      ans = max(ans, tmp);
      tmp = 0;
    }
  }

  ans = max(ans, tmp);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256