akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dx[4] = {1, -1, 0,  0};
const int dy[4] = {0,  0, 1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

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

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;
    
    mii sum;
    v_int a(n);

    irep2(i, 1, n) {
        cin >> a[i-1];
        sum[i+a[i-1]]++;
    }
    
    ll ans = 0;
    irep2(i, 1, n) {
        ans += sum[i-a[i-1]]; 
    }
    cout << ans << endl;
    return 0;
}

/*atcoder*/


Measured memory_bytes: 21084
#include<iostream>
#include<cstdlib>

using namespace std;

int main(){
  int d, n;
  cin >> d >> n;
  int t[d+1], c[n][3];
  for(int i = 1; i < d+1; i++) cin >> t[i];
  for(int i = 0; i < n; i++) cin >> c[i][0] >> c[i][1] >> c[i][2];

  int dp[n][d+1];
  for(int i = 0; i < n; i++) dp[i][0] = -1;
  for(int i = 0; i < n; i++){
    if(c[i][0] <= t[1] && t[1] <= c[i][1]){
      //dp[i][1] = c[i][2];
      dp[i][1] = 0;
    }else{
      dp[i][1] = -1;
    }
  }

  for(int i = 2; i < d+1; i++){
    for(int j = 0; j < n; j++){
      if(!(c[j][0] <= t[i] && t[i] <= c[j][1])){
        dp[j][i] = -1;
      }else{
        int max = -1;//, index;
        for(int k = 0; k < n; k++){
          if(dp[k][i-1] == -1) continue;
          if(max < dp[k][i-1] + abs(c[j][2] - c[k][2])){
            max = dp[k][i-1] + abs(c[j][2] - c[k][2]);
            //index = k;
          }
        }
        dp[j][i] = max;
      }
    }
  }

  /*cout << endl;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d+1; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  int max = -1;
  for(int j = 0; j < n; j++){
    if(max < dp[j][d]) max = dp[j][d];
  }
  cout << max << endl;
}



Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define INF 2147483647
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;



int main(){
	 
	 int n;
	 cin>>n;
	 if(n==22)cout<<"Christmas Eve Eve Eve"<<endl;
	 if(n==23)cout<<"Christmas Eve Eve"<<endl;
	 if(n==24)cout<<"Christmas Eve"<<endl;
	 if(n==25)cout<<"Christmas"<<endl;



}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int m = cin.Int();
			var ab = new Tuple<int, int>[m];
			for (int i = 0; i < m; i++) {
				int a = cin.Int();
				int b = cin.Int();
				int flag = 0;
				for (int j = 0; j < b; j++) {
					flag |= 1 << (cin.Int() - 1);
				}

				ab[i] = new Tuple<int, int>(a, flag);
			}

			int max = 1000000;
			int[] dp = new int[1 << n];
			for (int i = 0; i < 1 << n; i++) {
				dp[i] = max;
			}

			dp[0] = 0;

			for (int i = 0; i < 1 << n; i++) {
				for (int j = 0; j < m; j++) {
					int flag = i | ab[j].Item2;
					dp[flag] = Math.Min(dp[flag], dp[i] + ab[j].Item1);
				}
			}

			if (dp[(1 << n) - 1] == max) {
				dp[(1 << n) - 1] = -1;
			}

			Console.WriteLine(dp[(1 << n) - 1]);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13248
# a1 + a2 + a3 ... + an = M
# ai の 最大公約数をDとする
# ai = xi * D　のはず。 D * x0 + D * x1 ... + D * xn = M
# まとめて D(x1 + x2 + .... + xn) = M
# 変形し、D = M / (x1 + x2 + .... + xn)
# (x1 + ... xn) = K とすると、Kを最小化するとDが最大化する
# M / K が割り切れる必要があるので、KはMの約数のいずれか
# K >= N。なぜなら xi >= 1 なので、Kは最低でも数字の個数 N になる
# つまり、約数のうちで N 以上の最初の値が K になる
# ex: 3 14
# 14 の約数 {1, 2, 7}
# K >= N なので、　K >= 3
# K = 7 で確定。つまり D = M/K = 2 でAnswer

N, M = map(int, input().split())
M_ROOT = int(M ** 0.5)
k = M
for i in range(1, M_ROOT + 1):
    if M % i == 0:
        if i >= N:
            print(M // i)
            exit()
        d = M // i
        if d < k and d >= N:
            k = d
print(M // k)

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;

ll rui(ll a,ll b){
    if(b==1) return a%mod;
    else if(b==0) return 1;
    else if(b%2==0) return (rui(a,b/2)*rui(a,b/2))%mod;
    else return (rui(a,b-1)*a)%mod;
}


int main(){
    
    int H,W,K;cin>>H>>W>>K;
    vector<vector<int>> S(H,vector<int>(W+1,-1)),T(H,vector<int>(W+1,-1));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char a;cin>>a;
            T[i][j]=(a-'0');
        }
    }
    
    int ans=0;
    
    for(int y=0;y<H;y++){
    for(int z=0;z<W;z++){
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W+1;j++){
                S[i][j]=T[i][j];
            }
        }
        S[y][z]=-1;
        for(int i=H-2;i>=0;i--){
            if(S[i][z]==-1) continue;
            int now=i;
            while(1){
                if(now!=H-1&&S[now+1][z]==-1){
                    swap(S[now][z],S[now+1][z]);
                    now++;
                }else break;
            }
        }
        
        int score=0,cnt=0;
        bool flag=true;
        while(flag){
            flag=false;
            int sum=0;
            for(int i=0;i<H;i++){
                int ren;
                if(S[i][0]!=-1) ren=1;
                else ren=0;
                for(int j=1;j<W+1;j++){
                    if(S[i][j]==S[i][j-1]&&S[i][j]!=-1) ren++;
                    else{
                        if(ren>=K){
                            sum+=ren*S[i][j-1];
                            for(int p=j-ren;p<j;p++){
                                S[i][p]=-1;
                            }
                        }
                        if(S[i][j]==-1) ren=0;
                        else ren=1;
                    }
                }
            }
            if(sum>0) flag=true;
            score+=rui(2,cnt)*sum;
            cnt++;
            //cout<<z<<" "<<sum<<endl;
            for(int j=0;j<W;j++){
                for(int i=H-2;i>=0;i--){
                    if(S[i][j]==-1) continue;
                    int now=i;
                    while(1){
                        if(now!=H-1&&S[now+1][j]==-1){
                            swap(S[now][j],S[now+1][j]);
                            now++;
                        }else break;
                    }
                }
            }
        }
        ans=max(ans,score);
    }
    }
    cout<<ans<<endl;
    
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ul unsigned long long int
#define vi vector<int>
#define vl vector<int64_t>
#define all(x) x.begin(),x.end()
#define pb push_back
#define fo(x,a,b) for(int x=a; x<b; x++)
#define rfo(x,a,b) for(int x=a; x>=b; x--)
#define fi first
#define sec second
#define mp make_pair
int sgn(int x) { return x>0 ? 1 : ( x<0 ? -1 : 0); }
typedef pair<int,int> pairs;
double pi = 3.14159265358979323846;
ll mod = 1000000007;
void solve()
{
    ll n;
    cin>>n;
    vi a(n);
    fo(i,0,n) cin>>a[i];
    sort(all(a));
    bool vis[1000001]={false};
    bool g1=true;
    int gcd=a[0];
    vi pri(1000001,0);
    pri[1]=1;
    fo(i,2,1000001)
    {
        if(!pri[i])
        {
            pri[i]=i;
            for(int j=2*i; j<1000001; j+=i)
            {
                pri[j]=i;
            }
        }
    }
    fo(i,0,n)
    {
        gcd = __gcd(a[i],gcd);
        if(g1)
        {
            while(a[i]>1)
            {
                int temp = pri[a[i]];
                if(!vis[temp])
                {
                    vis[temp]=1;
                    a[i]/=temp;
                    while(a[i]%temp==0) { a[i]/=temp; }
                }
                else { g1=0; break; }
            }
        }
    }
    if(g1) cout<<"pairwise coprime";
    else if(gcd==1) cout<<"setwise coprime";
    else cout<<"not coprime";
    cout<<"\n";
    return;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    //cin>>t;
    //while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 11884
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	ll ans =0;
	for (int z=1;z<=n;z++){
		if (z % 3 == 0) continue;
		if (z % 5 == 0) continue;
		ans += z;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3660
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, K = MAP()
    A = LIST()

    for i in range(N-K):
        print("Yes" if A[i] < A[i+K] else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 32932
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const long long inf=0x3f3f3f3f3f3f3f3f;
int n;
long long s1[510][510],s2[510][510],dp[510][510],ans=inf;
long long get1(int x,int y){return s1[y][y]-s1[x][y]-s1[y][x]+s1[x][x];}
long long get2(int w,int x,int y){return s2[y][w]-s2[x][w];}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(i!=j)scanf("%d",i<j?&s1[i][j]:&s2[i][j]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)s1[i][j]+=s1[i][j-1],s2[i][j]+=s2[i][j-1];
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)s1[i][j]+=s1[i-1][j],s2[i][j]+=s2[i-1][j];
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	for(int i=0;i<n;++i)
		for(int j=0;j<i+(!i);++j)
			for(int k=i+1;k<=n;++k)
				dp[k][i]=min(dp[k][i],dp[i][j]+get1(i,k)+get2(j,i,k));
//	for(int i=1;i<=n;++i)
//	{
//		for(int j=0;j<i;++j)printf("%lld ",dp[i][j]);
//		printf("\n");
//	}
	for(int i=0;i<n;++i)ans=min(ans,dp[n][i]);
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    ll n; cin >> n;
    Vl x(n);
    rep(i, 0, n) cin >> x[i];
    Vl y = x;
    sort(ALL(y));
    ll mid1 = y[y.size()/2 - 1], mid2 = y[y.size()/2];
    rep(i, 0, n){
        if(x[i] <= mid1) cout << mid2 << endl;
        else if(x[i] >= mid2) cout << mid1 << endl;
    }
}

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

    solve();
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define INF 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<19;
	int dp[1<<20];
	segtree(){
		memset(dp,0,sizeof(dp));
	}
	void update(int k,int v){
		k+=N-1;
		dp[k]=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=min(dp[k*2+1],dp[k*2+2]);
		}
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return INF;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		return min(vl,vr);
	}
};

class rsegtree{
public:
	static const int N=1<<19;
	int dp[1<<20];
	int lazy[1<<20];
	rsegtree(){
		memset(dp,0,sizeof(dp));
	}

	void lazy_eval(int k){
		dp[k]+=lazy[k];
		if(k<N-1){
			lazy[k*2+1]+=lazy[k];
			lazy[k*2+2]+=lazy[k];
		}
		lazy[k]=0;
	}
	void lazy_upd(int k){
		dp[k]=min(dp[k*2+1],dp[k*2+2]);
	}

	void update(int a,int b,int v,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return;
		if(a<=l && r<=b){
			lazy[k]+=v;
			lazy_eval(k);
			return;
		}
		int mid=(l+r)/2;
		update(a,b,v,k*2+1,l,mid);
		update(a,b,v,k*2+2,mid,r);
		lazy_upd(k);
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return INF;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		lazy_upd(k);
		return min(vl,vr);
	}
};

segtree seg;
rsegtree rseg;
int n,q;
string str;
int type[300005];

int main(void){
	scanf("%d%d",&n,&q);
	cin >> str;
	for(int i=0;i<n;i++){
		if(str[i]=='('){
			type[i]=1;
			seg.update(i,INF);
			rseg.update(i+1,n+1,1);
		}else{
			type[i]=-1;
			seg.update(i,i);
			rseg.update(i+1,n+1,-1);
		}
	}
	for(int i=0;i<q;i++){
		int a;
		scanf("%d",&a);
		a--;
		type[a]=-type[a];
		if(type[a]==-1){
			seg.update(a,a);
			rseg.update(a+1,n+1,-2);
			int v=seg.query(0,n);
			printf("%d\n",v+1);
			seg.update(v,INF);
			rseg.update(v+1,n+1,2);
			type[v]=-type[v];
		}else{
			seg.update(a,INF);
			rseg.update(a+1,n+1,2);
			int l=0,r=a+1;
			while(l+1<r){
				int mid=(l+r)/2;
				rseg.update(mid,n+1,-2);
				if(rseg.query(mid,n+1)>=0)r=mid;
				else l=mid;
				rseg.update(mid,n+1,2);
			}
			printf("%d\n",r);
			seg.update(r-1,r-1);
			rseg.update(r,n+1,-2);
			type[r-1]=-type[r-1];
		}
	}
	return 0;
}


Measured memory_bytes: 15216
#include<iostream>
#include<cmath>
using namespace std;
bool prime(int i){
  int j = 2;
  while (i>j){
    if(i%j == 0){
      return false;
    }
    j++;
  }
  return true;
}
int main(){
  int n;
  cin >> n;
  while(prime(n) == false){
    n++;
  }
  cout << n << endl;
  return 0;
}

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

typedef long long LL;
const int MAX = 1000000;
const LL MOD = 1000000007;

long long fact[MAX];
long long inv[MAX];



LL mod_pow(LL x,LL n){
    LL ret = 1;

    while(n){
        if(n & 1)ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }

    return ret;
}

LL mod_P(int n,int k){
    return fact[n] * inv[n - k] % MOD;
}

LL mod_C(int n,int k){
    return mod_P(n,k) * inv[k] % MOD;
}

void init(){
    fact[0] = inv[0] = 1;
    for(int i = 1;i < MAX;i++){
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = mod_pow(fact[i],MOD - 2);
    }
}

int main(){
    init();
    int X,Y;

    cin >> X >> Y;

    int x = X;
    int y = Y;
    int xc = 0;
    int yc = 0;

    while(x > 0 && y > 0){
        if(x > y){
            x -= 2;
            y -= 1;
            xc++;
        }else{
            x -= 1;
            y -= 2;
            yc++;
        }
    }

    if(x != 0 || y != 0){
        cout << 0 << endl;
    }else{
        cout << mod_P(xc + yc,xc + yc) * inv[xc] % MOD * inv[yc] % MOD << endl;
    }

    return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vector<pair<string, pi>> in;
	rep(i, n){
		string s; int p; cin >> s >> p;
		in.emplace_back(s, pi(p, i));
	}
	sort(all(in), []
		(pair<string, pi> a, pair<string, pi> b){
			if(a.first != b.first) return a.first < b.first;
			return a.second.first > b.second.first;
		});
	rep(i, n) cout << in[i].second.second + 1 << endl;
	
	return 0;
}

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

int main(void) {
  string s;
  cin >> s;
  int findA,findB;
  for (int i = 0; i < s.length(); i++) {
    if(s[i] == 'A') {
      findA = i;
      break;
    }
  }
  for(int i = s.length() - 1; i >= 0; i--) {
    if(s[i] == 'Z') {
      findB = i;
      break;
    }
  }
  cout << findB - findA +1 << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		for(int i = 1; ; i++){
			int a = scan.nextInt();
			if(a == 0) break;
			System.out.printf("Case %d: %d\n", i, a);
		}
	}
}

Measured memory_bytes: 53492
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
N = int(input())
edge = np.array([list(input()) for _ in range(N)]).astype(int)

def is_bipartite(N, edge):
    color = [-1]*N
    graph = [np.nonzero(i)[0].tolist() for i in edge]

    node = [0]
    color[0] = 0
    while node:
        s = node.pop()
        col_s = color[s]
        for t in graph[s]:
            col_t = color[t]
            if col_t == -1:
                color[t] = 1-col_s
                node.append(t)
            elif col_t == col_s:
                return False
            else:
                continue
    return True


if is_bipartite(N, edge):
    wf = floyd_warshall(edge).astype(int)
    ans = wf.max()+1
else:
    ans = -1

print(ans)


Measured memory_bytes: 27604
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {

	string str;
	int k;

	cin >> k;
	cin >> str;

	rep(i, str.size()) {
		str.at(i) = str.at(i) + k;
		if (str.at(i) > 'Z') {
			int j = str.at(i) - 'Z' - 1;
			str.at(i) = 'A' + j;
		}
	}

	cout << str << endl;


	return 0;
}

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

long howmany_rewrite(string S) {
  int cnt = 1;
  long ans = 0;
  for (int i = 1; i < S.length(); i++) {
    if (S[i - 1] == S[i]) {
      cnt++;
    } else { // S[i - 1] != S[i]
      ans += (cnt / 2);
      cnt = 1;
    }
  }
  if (cnt != 1)
    ans += (cnt / 2);
  
  return ans;
}

int main() {
  string S; cin >> S;
  int K; cin >> K;
  
  long ans1 = howmany_rewrite(S);
  
  string S2 = S + S;
  long ans2 = howmany_rewrite(S2);
  
  string S3 = S + S + S;
  long ans3 = howmany_rewrite(S3);
  
  long ans;
  if (ans2 - ans1 == ans3 - ans2) {
    ans = ans1 + (ans2 - ans1) * (K - 1);
  } else {
    ans = S.length() * K / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]
import sys
ans = 0
if A[0] != 0:
    print(-1)
    sys.exit()
for i in range(1,N):
    if A[i] - A[i-1] == 1:
        ans += 1
    elif A[i] <= A[i-1]:
        ans += A[i]
    else:
        print(-1)
        sys.exit()
    
print(ans)

Measured memory_bytes: 11048
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int x; cin >> x;

    std::vector<bool> v(x+1,false);
    v[x] = true;

    for(int i=x; i>0; i--){
        if(v[i]){
            if(i-100 >= 0) v[i-100] = true;
            if(i-101 >= 0) v[i-101] = true;
            if(i-102 >= 0) v[i-102] = true;
            if(i-103 >= 0) v[i-103] = true;
            if(i-104 >= 0) v[i-104] = true;
            if(i-105 >= 0) v[i-105] = true;
        }
    }

    cout << v[0] << endl;

    return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n; 
    vector <int> v;
    for (int i=1;i*i<=n;i++){
    	if (n%i==0)
    		v.emplace_back(max(i,n/i));
    }
    int ans=100;
    for (auto &it: v) 
    	ans = min(ans,sz(to_string(it))); 
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{

string s, t;
cin>>s>>t;

int len =  s.length() - t.length() + 1; 

int arr[ len ] = {0} , i,j;


for(i=0 ; i<len ; i ++){
	
	int count = 0;
	for(j=0;j<t.length();j++){
		if(t[j] == s[i+j]){
			count++;
		}
	}
	
	arr[i] = count;
	
}
//
//for(i=0;i<len;i++){
//	cout<<arr[i]<<" ";
//}

sort(arr , arr+len);
cout<<t.length() - arr[len-1];


   return 0;
}



Measured memory_bytes: 3628
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int i,d[9],a[3],b[3];
  for(i=0;i<9;i++){
    cin>>d[i];
  }
  b[0]=0;
  a[0]=d[0];
  for(i=1;i<3;i++){
    b[i]=d[i]-a[0];
    a[i]=d[i*3]-b[0];
  }

  //check
  for(i=0;i<9;i++){
    if(d[i]!=(a[i/3]+b[i%3])){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = (int)1e5+5;

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

    int n;
    cin>>n;
    ll sum = 0;
    for(int i=1;i<=n;i++) {
        if(i%3 && i%5) {
            sum += i;
        }
    }
    cout<<sum;
}


Measured memory_bytes: 3660
#include<stdio.h>
#define MAX 100000

int A[MAX],num;

int main()
{
  int i,q;
  scanf("%d",&num);
  for(i=0; i<num; i++) scanf("%d",&A[i]);

  q=parti(0,num-1);

  for(i=0;i<num;i++)
    {
      if(i!=0) printf(" ");
      if(i==q)printf("[");
      printf("%d",A[i]);
      if(i==q)printf("]");
    }
  printf("\n");
  return 0;
}

int parti(int p ,int r)
{
  int i,j,x,y;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j]<=x)
	{
	  i++;
	  y = A[i];
	  A[i] = A[j];
	  A[j]=y;
	}
    }
  y=A[i+1];
  A[i+1]=A[r];
  A[r]=y;
  return i+1;
}

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

int main() {
  int n,a,b,c,d;
  cin >> n;

  a = n % 10;
  b = n / 10 % 10;
  c = n / 100 % 10;
  d = n / 1000;
  
  if ((a == b && b == c) || (b == c && c == d)) {
      cout << "Yes" << endl;
  } else {
      cout <<  "No" << endl;  
  }
}

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

int main(){

  int n;

  int a[15][15];
  int num;
  int ok;
  int x,y;

  while(cin>>n , n){
    num = 1; ok=n*n; x=y=n/2; y++;
    for(int i=0; i<n; i++)for(int j=0; j<n; j++)a[i][j]=0;

    while(ok>0){
      if(a[y][x]==0){
	a[y][x]=num;
	num++;
	ok--;
      }
      else{
	x-=2;
      }
      y++;x++;
      if(x<0){x = n-1;}
      y%=n; x%=n; 
    }
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++)
	printf("%4d",a[i][j]);
      cout << endl;
    }
	

  }

  return 0;
}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double n=sc.nextDouble();
        double sum=0;
        for(int i=0;i<n;i++) {
        	sum+=1/sc.nextDouble();
        }
        
        System.out.println(1/sum);
    }
}


Measured memory_bytes: 23252
import qualified Data.List as L

combinations :: Int -> [a] -> [[a]]
combinations r xs = filter ((== r) . length) $ L.subsequences xs

count :: (a -> Bool) -> [a] -> Integer
count f = sum . map g . map f
    where
        g True = 1
        g False = 0

solve :: [Int] -> IO ()
solve [n,s] = print $ count isOK $ combinations n [0..9]
    where
        isOK xs = sum xs == s
solve _ = undefined

main :: IO ()
main = getContents
    >>= mapM_ solve . takeWhile (/= [0,0]) . map (map read) . map words . lines

Measured memory_bytes: 4096
#include<stdio.h>
#include <string.h>
#include <math.h>


int main() {
	int l, r, d;
	int result = 0;

	scanf("%d%d%d", &l, &r, &d);

	for (int i = l; i <= r; i++) {
		if (i % d == 0) {
			result++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N;
  ;
}
void solve() {
  cout << (N < 1200 ? "ABC" : "ARC") << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<string>
    #include<cstring>
    #include<algorithm>
    #include<cstdio> 
    #define ll long long
    using namespace std;
    int main(){
        char s[20000];
        cin>>s;
        for(int i=0;i<strlen(s)-8;i++)
        cout<<s[i];
        return 0;
    }

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[M];
        for(int i=0;i<N;i++) x[i] = sc.nextInt();
        for(int i=0;i<M;i++) y[i] = sc.nextInt();
        Arrays.sort(x);
        Arrays.sort(y);
        String ans = "War";
        if(X<Y&&x[N-1]<Math.min(Y,y[0])&&y[0]>Math.max(x[N-1],X)) ans = "No War";
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

ll maxsum(const vector<int> &a, const vector<int> &b, int n) {
    ll res = 0;
    REP(i, a.size()) {
        if ((a[i] & n) == a[i]) {
            res += b[i];
        }
    }
    return res;
}

int main() {
    int n, k; scanf("%d %d", &n, &k);
    vector<int> a(n), b(n);
    REP(i, n) scanf("%d %d", &a[i], &b[i]);
    ll ans = 0;
    while (k != -1) {
        ans = max(ans, maxsum(a, b, k));
        k = ((k + 1) & k) - 1;
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 1024
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 105;
int a[MAXN];

void solve(){
    int n,k; cin>>n>>k;

    int ans = n%k;
    ans = min(ans,abs((k-ans)%k));
    cout<<ans<<endl;
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}



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

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef set<int> Edges;
typedef vector<Edges> Graph;

int n, m;
Graph g;
map<int, int> memo[32];
int last[100];
vector<int> order;
bool visit[100];

inline int Get(int alive, int i) {
  return (alive >> i) & 1;
}

void Use(int &alive, int f) {
  FORIT(it, g[f]) {
    alive = alive & (~(1 << *it));
  }
}

int calc(const int alive, int depth) {
  if (alive == 0) { return 0; }
  if (depth == n) { return n; }
  if (memo[depth].count(alive)) { return memo[depth][alive]; }
  int nalive = alive;
  int ret = n;
  int f = order[depth];
  int sum = 0;
  FORIT(it, g[f]) {
    if (Get(alive, *it) == 0) { continue; }
    if (last[*it] == f) {
      Use(nalive, f);
      return memo[depth][alive] = calc(nalive, depth + 1) + 1;
    }
    sum++;
  }
  if (sum == 0) { return memo[depth][alive] = calc(nalive, depth + 1); }
  ret = min(ret, calc(nalive, depth + 1));
  Use(nalive, f);
  ret = min(ret, calc(nalive, depth + 1) + 1);
  return memo[depth][alive] = ret;
}

int main() {
  while (scanf("%d %d", &n, &m), n|m) {
    g = Graph(n);
    REP(i, 32) { memo[i].clear(); }
    MEMSET(last, -1);
    order.clear();
    MEMSET(visit, false);
    REP(i, n) { g[i].insert(i); }
    REP(i, m) {
      int f, t;
      scanf("%d %d", &f, &t);
      g[f].insert(t);
      g[t].insert(f);
    }

    REP(i, n) {
      if (visit[i]) { continue; }
      queue<int> que;
      que.push(i);
      while (!que.empty()) {
        int f = que.front();
        que.pop();
        if (visit[f]) { continue; }
        visit[f] = true;
        order.push_back(f);
        FORIT(it, g[f]) {
          que.push(*it);
        }
      }
    }

    REP(i, n) {
      int f = order[i];
      FORIT(it, g[f]) {
        last[*it] = f;
      }
    }

    int alive = (1 << n) - 1;
    int ans = calc(alive, 0);
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 1280
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * Bange Hills Tower
 */
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N, t;
		N = sc.nextInt();
		t = sc.nextInt();

		BigDecimal tan = new BigDecimal(0);

		for (int i = 0; i < N; i++) {
			BigDecimal x, h, _tan;
			x = new BigDecimal(sc.next());
			h = new BigDecimal(sc.next());
			_tan = h.divide(x, 10, BigDecimal.ROUND_HALF_UP);
			if (tan.compareTo(_tan) < 0) {
				tan = _tan;
			}
		}

		System.out.println(tan.multiply(new BigDecimal(t)).toString());
	}
}

Measured memory_bytes: 33780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(a) a.begin(),a.end()

int main(){
    ll N, A, B, C, cnt = 0, ans = 0;
    vector<ll> V(10);
    string S;
    cin >> A >> S;
    if(A >= 3200)  cout << S << endl;
    else cout << "red\n";
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <climits>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

void solve(void){
    int n, k, t;
    ll sum = 0LL;
    cin >> t;
    rep(t, meaningless) {
        sum = 0LL;
        cin >> n >> k;
        vector <int> difs(n);
        int pre, tmp; cin >> pre;
        rep(n-1, i) {
            cin >> tmp;
            difs.pb(tmp-pre);
            sum += tmp-pre;
            pre = tmp;
        }
        sort(all(difs));
        reverse(all(difs));
        rep(k-1, i) sum -= difs[i];
        cout << max(sum, 0LL) << '\n';
    }
}

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



Measured memory_bytes: 4172
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int d;
    cin >> d;
    vector c(26, 0);
    for (int i=0; i<26; i++) cin >> c[i];
    int csum = accumulate(c.begin(), c.end(), 0);
    vector<vector<int>> s(d, vector<int>(26, 0));
    for (int i=0; i<d; i++) {
        for (int j=0; j<26; j++)
            cin >> s[i][j];
    }


    vector<int> t(d, 0);
    for (int i=0; i<d; i++) cin >> t[i];


    int ans = 0;
    vector contest(26, -1);
    for (int i=0; i<d; i++) {
        ans += s[i][t[i]-1];
        contest[t[i]-1] = i;

        for (int j=0; j<26; j++) {
            ans -= c[j] * abs(contest[j] - i);
        }

        cout << ans << endl;
    }

}

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    int ans = -1, mask = 0;
    for(int i=0; i<n; i++){
        cin >> c[i];
        for(int j=0; j<m; j++)
            cin >> a[i][j];
    }
    for(int msk=0; msk<(1<<n); msk++){
        int now = 0;
        vector<int> level(m, 0);
        for(int i=0; i<n; i++)
            if((1<<i)&msk)
                now += c[i];
        for(int i=0; i<n; i++)
        if((1<<i)&msk){
            for(int j=0; j<m; j++)
                level[j]+=a[i][j];
        }
        bool bl = 1;
        for(auto z: level)
        if(z<x){
            bl = 0;
            break;
        }
        if(bl)
            ans = (ans==-1?now:min(ans, now));
    }
    cout << ans << '\n';
    return 0;
}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 2*1e13;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,m;
ll a,b;
vector<PLL> p;
struct union_find{
    vector<int> par;
    int par_siz;
    union_find(int n) : par(n){
        par_siz = n;
        for(ll i=0;i<n;i++)par[i]=-1; //init
    }
    int root(int x){
        if(par[x]<0)return x;
        else return par[x] = root(par[x]);
    }
    void unite(int p1,int p2){
        int pa1 = root(p1),pa2 = root(p2);
        if(pa1==pa2)return;
        if(par[pa1]>par[pa2]){ // |pa1| < |pa2|
            par[pa2] += par[pa1];
            par[pa1] = pa2;
        }else{ // |pa1| >= |pa2|
            par[pa1] += par[pa2];
            par[pa2] = pa1;
        }
        par_siz--;
    }
    int size(int x){ return (-1)*par[root(x)]; }
    int par_size(){return par_siz;}
    bool same(int p1,int p2){ return root(p1) == root(p2); }
};


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    Vi ans;
    cin>>n>>m;
    rep(i,m){
        cin>>a>>b;
        p.pb(mp(a-1,b-1));
    }
    reverse(all(p));
    union_find uf(n);
    ans.pb(n*(n-1)/2);
    rep(i,m){
        ll tmp = ans[i];
        if(uf.same(p[i].first,p[i].second))tmp -= 0;
        else tmp -= uf.size(p[i].first)*(uf.size(p[i].second));
        uf.unite(p[i].first,p[i].second);
        ans.pb(tmp);
    }
    rep(i,m){
        print(ans[m-i-1]);
    }
    return 0;
}

Measured memory_bytes: 5104
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define xx          exit(0);
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) {
    return (ll)(log(x) / log(base));
}
vec v[100005]; ll m,n, in[100005],out[100005];
void dfs1(ll x, ll pr, ll m)
{
	ll y=v[x].size(),z;
	in[x]=1;
	rep(i,0,y){
		z=v[x][i];
		if(z!=pr){
			dfs1(z,x,m);
			in[x] = (in[x]*(1+in[z]))%m;
		}
	}
}
void dfs2(ll x, ll pr, ll m)
{
	vec s;
	ll y=v[x].size(),z,j;
	rep(i,0,y){
		z=v[x][i];
		if(z!=pr) s.pb((1+in[z])%m);
	}
	ll n=s.size();
	ll pre[n+1],suf[n+2];
	pre[0]=1; suf[n+1]=1;
	repi(i,1,n) pre[i] = (pre[i-1]*s[i-1])%m;
	per(i,n,1) suf[i] = (suf[i+1]*s[i-1])%m;
	j=0;
	rep(i,0,y){
		z=v[x][i];
		if(z!=pr){
			out[z] = (1+(out[x]*((pre[j]*suf[j+2])%m))%m)%m;
			j++;
			dfs2(z,x,m);
		}
	}
	s.clear();
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll k,i,j,w;
    	cin>>n>>m;
    	rep(i,0,n-1){
		    cin>>j>>k;
    		v[j].pb(k);
    		v[k].pb(j);
		}
		dfs1(1,0,m);
		out[1]=1;
		dfs2(1,0,m);
		repi(i,1,n){
			cout<<(in[i]*out[i])%m<<'\n';
		}
	}
	return 0;
}

Measured memory_bytes: 25508
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  string s;
  cin >> s;
  int res = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+') res++;
    if (s[i] == '-') res--;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	vector<ll>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	stack<ll>s;
	ll ans=0;
	s.push(v[n-1]);
	for(int i=n-2;i>=0;i--){
		//cout<<v[i]<<endl;
		if(s.top()<=v[i]){
			ans=max(ans,(ll)s.size());
			s.push(v[i]);
		}
		else{
			while(!s.empty()){
				s.pop();
			}
			s.push(v[i]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	string s;
	cin>>s;
	int n = s.length(), i=0,j=n-1;
	while(i<j){
		if(s[i]=='A' and s[j]=='Z') break;
		if(s[i]!='A') i++;
		if(s[j]!='Z') j--;
	}
	printf("%d\n",j-i+1);
	return 0;
}

Measured memory_bytes: 640