akhauriyash/Code-Regression huggingface dataset:
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i%j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> grid(h, vector<char>(w));
    rep(y, h) rep(x, w) cin >> grid[y][x];

    set<int> empty_row = [&] {
        set<int> ans;
        rep(y, h) {
            bool ok = [&] {
                rep(x, w) {
                    if (grid[y][x] == '#') return false;
                }
                return true;
            }();
            if (ok) ans.insert(y);
        }
        return ans;
    }();

    vector<vector<char>> grid2;
    rep(y, h) if (!contain(empty_row, y)) grid2.push_back(grid[y]);

    h = grid2.size();

    set<int> empty_column = [&] {
        set<int> ans;
        rep(x, w) {
            bool ok = [&] {
                rep(y, h) {
                    if (grid2[y][x] == '#') return false;
                }
                return true;
            }();
            if (ok) ans.insert(x);
        }
        return ans;
    }();

    vector<vector<char>> grid3(h);
    rep(y, h) {
        rep(x, w) {
            if (contain(empty_column, x)) continue;
            grid3[y].push_back(grid2[y][x]);
        }
    }

    w = grid3[0].size();
    rep(y, h) {
        rep(x, w) cout << grid3[y][x];
        cout << endl;
    }

}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;

int main(int argc, char *argv[])
{
	int n;
	string s;

	cin >> n >> s;

	const int l=s.length();
	for (int i=0;i<l;i++)
	{
		s[i]=((s[i]-'A'+n) %26)+'A';
	}

	cout << s<< endl;
	return 0;
}



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




int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, n, k, ans = 1e9;
    bool zeroexist = false;
    cin >> n >> k;
    vector<int> p,m;
    p.push_back(0);

    rep(i, n){
        cin >> a;
        if(a>0)
            p.push_back(a);
        if(a<0)
            m.push_back(a);
        if(a==0)
            zeroexist = true;
    }
    
    m.push_back(0);
    reverse(m.begin(), m.end());

    if(zeroexist)
        rep(i,k+1)
        {
            if(i<p.size()&&k-i-1<m.size()) 
                ans = min(min(p[i], 0 - m[k - i - 1]) + p[i] - m[k - i - 1], ans);
        }
    else
        rep(i, k+1)
        {
            if (i < p.size() && k - i< m.size())
                ans = min(min(p[i], 0 - m[k - i]) + p[i] - m[k - i], ans);
        }

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

Measured memory_bytes: 1020
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

class Main {
	public static void main(String args[]) throws IOException {
		@SuppressWarnings("resource")
		Scanner cin = new Scanner(System.in);
		ArrayList<String> inLines = new ArrayList<String>();
		for (; cin.hasNext();) {
			inLines.add(cin.nextLine());
		}
		Solver solver = new Solver();
		solver.solve(inLines);
	}
}

class Solver {

	public void solve(ArrayList<String> inLines) {
		int N = Integer.parseInt(inLines.get(0));
		String[] strArr = inLines.get(1).split(" ");
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i = 0; i < N; i++) {
			int An = Integer.parseInt(strArr[i]);
			if (map.containsKey(An))
				map.put(An, map.get(An) + 1);
			else
				map.put(An, 1);
		}
		int cnt = 0;
		for (int key : map.keySet()) {
			if (map.get(key) % 2 == 0) {
				cnt++;
			}
		}
		if (cnt % 2 == 0)
			System.out.println(map.size());
		else
			System.out.println(map.size() - 1);
	}
}


Measured memory_bytes: 34928
#include<stdio.h>
int main()
{
    char s[20];
    scanf("%s", s);
    if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n,m;
int add[1<<15];
int dp[1<<15][15];
int i,j,k,p;
int x,y,z;
int mp[15][15];
int main()
{
	cin>>n>>m;
	while (m--)
	{
		cin>>x>>y>>z;
		mp[x-1][y-1]=z;
		mp[y-1][x-1]=z;
	}
	for (i=0;i<(1<<n);i++)
	{
		for (j=0;j<n;j++)
		{
			if ((1<<j)&i)
			{
				for (k=j+1;k<n;k++)
				{
					if ((1<<k)&i)
					{
						//cout<<j<<' '<<k<<endl;
						add[i]+=mp[k][j];
					}
				}
			}
		}
	}
	memset(dp,-1,sizeof(dp));
	dp[1][0]=0;
	for (i=1;i<(1<<n);i++)
	{
		for (j=0;j<n;j++)
		{
			if ((1<<j)&i)
			{
				if (dp[i][j]!=-1)
				{
					for (k=0;k<n;k++)
					{
						if (!((1<<k)&i))
						{
							if (mp[j][k])
							{
								dp[i|(1<<k)][k]=max(dp[i|(1<<k)][k],dp[i][j]+mp[j][k]);
							}
						}
					}
					int bj=((((1<<n)-1)^i)|(1<<j));
					for (k=bj;;k=((k-1)&bj))
					{
						dp[i|k][j]=max(dp[i|k][j],dp[i][j]+add[k]);
						if (!k) break;
					}
				}
			}
		}
	}
	int ans=0;
	for (i=1;i<(1<<n);i++) ans=max(ans,dp[i][n-1]);
	//cout<<add[(1<<n)-1]<<endl; 
	cout<<add[(1<<n)-1]-ans<<endl;
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
int main() {
    long long N, M;
    std::cin >> N >> M;
    if (N * 2LL >= M) {
        std::cout << M / 2LL << "\n";
        return 0;
    }
    std::cout << N + (M - 2LL * N) / 4LL << "\n";
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
vector<vector<int>> cc;
Vll a;
void dfs(int u) {
  seen[u] = true;
  cc.back().push_back(a[u]);
  for (auto v : G[u]) { 
    if (seen[v]) continue;
    dfs(v);
  }
}

int main() {
  int N, M; cin >> N >> M;
  a = Vll(N);
  rep(i, N) cin >> a[i];

  G.assign(N, V());
  for (int i = 0; i < M; ++i) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  seen.assign(N, false);
  for (int u = 0; u < N; ++u) {
    if (seen[u]) continue;
    cc.push_back(V());
    dfs(u);
  }
  int k = cc.size();

  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  Vll z;
  for (auto e : cc) {
    sort(all(e));
    reverse(all(e));
    ans += e.back();
    e.pop_back();
    z.insert(z.end(), all(e));
  }

  if (z.size() < k-2) {
    cout << "Impossible" << endl;
    return 0;
  }

  sort(all(z));
  rep(i, k-2) ans += z[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10036
def main():
  n,k,*a = map(int,open(0).read().split())
  c = [0]
  visit = [False]*n
  visit[0] = True
  for i in range(n):
    nt = a[c[-1]]-1
    if visit[nt]:
      ws = c.index(nt)
      wst = c[:ws]
      wrt = c[ws:]
      wr = len(wrt)
      break
    else:
      c.append(nt)
      visit[nt] = True
  if ws > k:
    ans = wst[k]
  else:
    ans = wrt[(k-ws)%wr]
  print(ans+1)
main()

Measured memory_bytes: 31692
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	sum := 0
	for i := 1; i <= N; i++ {
		if i%3 == 0 || i%5 == 0 {

		} else {
			sum += i
		}
	}
	fmt.Println(sum)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1760
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  ll n,k;cin>>n>>k;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  vector<int> num0(62,0);
  vector<int> num1(62,0);
  rep(i,n){
    rep(j,62){
      if(a[i]&(1ull<<j))num1[j]++;
      else num0[j]++;
    }
  }
  ll x=0;
  vector<ll> pow2(62,0);
  for(int i=0;i<62;i++){
    ll buf=0;
    buf|=(1ull<<i);
    pow2[i]=buf;
  }
  for(int i=60;i>=0;i--){
    if(num0[i]>num1[i]){
      if(pow2[i]<=k){
        k-=pow2[i];
        x+=pow2[i];
      }
    }
  }
  ll sum=0;
  rep(i,n){
    sum+=a[i]^x;
  }
  cout<<sum<<endl;
  //cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
    char str[105];

    while(scanf("%s",str)==1)
    {
        int len=strlen(str);

        int ami=0;

        for(int i=0; i<len; i++)
        {
            if(str[i]=='C')
            {
                int flag=0;

                for(int j=i+1; j<len; j++)
                {
                    if(str[j]=='F')
                    {
                        printf("Yes\n");

                        flag=1;

                        break;
                    }
                }

                if(flag==0)
                    printf("No\n");

                ami=1;

                break;
            }
        }

        if(ami==0)
            printf("No\n");
    }

    return (0);
}


Measured memory_bytes: 256
import sys
f = sys.stdin

ope = {'North':(1,5,2,3,0,4)
      ,'East' :(3,1,0,5,4,2)
      ,'West' :(2,1,5,0,4,3)
      ,'South':(4,0,2,3,5,1)
      ,'Right':(0,2,4,1,3,5)
      ,'Left' :(0,3,1,4,2,5)}
while True:
    n = int(f.readline())
    if n == 0:
        break
    xi = [1,2,3,4,5,6]
    ret = 1
    for _ in range(n):
        xi = [xi[i] for i in ope[f.readline().strip()]]
        ret += xi[0]
    
    print(ret)
        

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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ans = 0;
    int n = sc.nextInt();
    long d = sc.nextInt();
    for (int cnt = 0; cnt < n; cnt++) {
      long x = sc.nextInt();
      long y = sc.nextInt();
      if (x * x + y * y <= d * d) {
        ans++;
      }
    }
    System.out.println(ans);
    sc.close();
  }
}

Measured memory_bytes: 60276
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX_N = 1000000; // いくつまで調べるか
bool prime[MAX_N + 1]; // 添字が素数ならtrue、それ以外はfalse
void sieve()
{
  prime[0] = prime[1] = false; // 例外処理
  // 配列prime の初期化
  for(int i = 2; i <= MAX_N; ++i)
    prime[i] = true;
  // 素数でないものを調べる
  for(int i = 2; i <= MAX_N; ++i)
    if(prime[i])
      for(int j = i * 2; j <= MAX_N; j += i)
	prime[j] = false;
}
int is_prime(int n)
{
  return prime[n];
  }//*/

/*bool is_prime(int n)
{
  if(n == 1)return false;
  for(int i = 2; i < n; ++i)
    if(n % i == 0)return false;
  return true;
  }*/

int main()
{
  sieve();
  int a,d,n;
  for(;;){
    cin >> a >> d >> n;
    if(d==0)return 0;
    int now,count=0;
    int tmp;
    for(int i=a;i<1000000;i+=d){
      if(is_prime(i))count++;
      if(count==n){printf("%d\n",i);break;}
    }
  }
}

Measured memory_bytes: 2120
def main():
	n = int(input())
	a = tuple(map(int,(input().split())))
	b = tuple(map(int,(input().split())))

	li = list(range(1,n+1))

	import itertools
	p = list(itertools.permutations(li))

	print(abs(int(p.index(a)) - int(p.index(b))))

	
 
if __name__ == '__main__':
	main()

Measured memory_bytes: 44656
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
string s;
set < int > ch[26];

int main(){
    cin >> n >> s;
    s = " " + s;
    for(int i = 1; i <= n; i++){
        ch[s[i] - 'a'].insert(i);
    }
    int q;
    cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            int idx;
            char x;
            cin >> idx >> x;
            ch[s[idx] - 'a'].erase(idx);
            s[idx] = x;
            ch[x - 'a'].insert(idx);
        } else {
            int cnt = 0;
            int l , r;
            cin >> l >> r;
            for(int i = 0; i < 26; i++){
                if(ch[i].lower_bound(l) == ch[i].end())
                    continue;
                int idx = *ch[i].lower_bound(l);
                if(l <= idx && idx <= r)
                    cnt++;
            }
            cout << cnt << endl;
        }
    }
}

Measured memory_bytes: 24216
#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>

using namespace std;

char s[13][10],c[10];
int N,m,val[256],cont[256],ans;
int mx[(1 << 10)][10],mn[(1 << 10)][10];

int get_min(int mask, int d){
    if(mask == (1 << m) - 1) return 0;
    
    int &ret = mn[mask][d];
    
    if(ret == -1){
        ret = INT_MAX;
        
        if(m - __builtin_popcount(mask) < 10 - d) ret = get_min(mask,d + 1);
        
        for(int x = 0;x < m;++x)
            if((mask & (1 << x)) == 0)
                ret = min(ret,get_min(mask ^ (1 << x),d + 1) + cont[ c[x] ] * d);
    }
    
    return ret;
}

int get_max(int mask, int d){
    if(mask == (1 << m) - 1) return 0;
    
    int &ret = mx[mask][d];
    
    if(ret == -1){
        ret = INT_MIN;
        
        if(m - __builtin_popcount(mask) < 10 - d) ret = get_max(mask,d + 1);
        
        for(int x = 0;x < m;++x)
            if((mask & (1 << x)) == 0)
                ret = max(ret,get_max(mask ^ (1 << x),d + 1) + cont[ c[x] ] * d);
    }
    
    return ret;
}

void solve(int d, int mask, int sum){
    if(sum + get_min(mask,d) > 0 || sum + get_max(mask,d) < 0) return;
    if(m - __builtin_popcount(mask) > 10 - d) return;
    
    if(mask == (1 << m) - 1){
        if(sum == 0) ++ans;
        return;
    }
    
    solve(d + 1,mask,sum);
    
    for(int i = 0;i < m;++i){
        if((mask & (1 << i)) == 0){
            val[ c[i] ] = d;
            solve(d + 1,mask | (1 << i),sum + cont[ c[i] ] * d);
        }
    }
}

int main(){
    bool used[256],first[256];
    
    while(true){
        scanf("%d",&N);
        
        if(N == 0) break;
        
        memset(used,false,sizeof used);
        memset(first,false,sizeof first);
        memset(cont,0,sizeof cont);
        
        for(int i = 0;i < N;++i){
            scanf("%s",s[i]);
            int L = strlen(s[i]);
            
            if(L > 1) first[ s[i][0] ] = true;
            
            for(int j = L - 1,pow10 = 1;j >= 0;--j,pow10 *= 10){
                used[ s[i][j] ] = true;
                cont[ s[i][j] ] += (i == N - 1? -pow10 : pow10);
            }
        }
        
        m = 0;
        
        for(int i = 'A';i <= 'Z';++i)
            if(used[i]) c[m++] = i;
        
        memset(mn,-1,sizeof mn);
        memset(mx,-1,sizeof mx);
        
        ans = 0;
        
        solve(1,0,0);
        
        for(int i = 0;i < m;++i){
            if(!first[ c[i] ]){
                val[ c[i] ] = 0;
                solve(1,(1 << i),0);
            }
        }
        
        printf("%d\n",ans);
    }
    
    return 0;
}

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

int main() {
  string A, B;
  cin >> A >> B;
  
  int N = A.size();
  
  string S = B.erase(N);
  
  if (A == S) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b;
	c=a*b;
	if(c%2==0)
		printf("Even\n");
	else
		printf("Odd\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 51000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  Vec(P,pint,M,pint(0,0));
  rep(i,0,M)cin >> P[i].first >> P[i].second;
  A=pow(10,N);
  if(N==1)B=0;
  else B=pow(10,N-1);
  C=INF;
  rep(i,B,A){
    S=to_string(i);
    flag=1;
    rep(j,0,M){
      T=to_string(P[j].second);
      if(S[P[j].first-1]!=T[0]){
        flag=0;
        break;
      }
    }
    if(flag){
      C=i;
      break;
    }
  }
  if(C!=INF)Out(C);
  else Out(-1);
}

Measured memory_bytes: 512
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n,a,b,c = gets.chomp.split.map(&:to_i)
ans = Array.new(n)
ss = []
n.times do |i|
  ss.push gets.chomp
end

n.times do |i|
  s = ss[i]
  if s == 'AB'
    if a == 0 && b == 0
      puts 'No'
      exit
    end
    if a > b || (a == 1 && b == 1 && c == 0 && i < n - 1 && ss[i+1] == 'BC')
      a -= 1
      b += 1
      ans[i] = 'B'
    else
      a += 1
      b -= 1
      ans[i] = 'A'
    end
  elsif s == 'BC'
    if b == 0 && c == 0
      puts 'No'
      exit
    end
    if b > c || (a == 0 && b == 1 && c == 1 && i < n - 1 && ss[i+1] == 'AC')
      b -= 1
      c += 1
      ans[i] = 'C'
    else
      b += 1
      c -= 1
      ans[i] = 'B'
    end
  else
    if a == 0 && c == 0
      puts 'No'
      exit
    end
    if a > c || (a == 1 && b == 0 && c == 1 && i < n - 1 && ss[i+1] == 'BC')
      a -= 1
      c += 1
      ans[i] = 'C'
    else
      a += 1
      c -= 1
      ans[i] = 'A'
    end
  end
end

puts 'Yes'
ans.each do |line|
  puts line
end

Measured memory_bytes: 29696
// https://atcoder.jp/contests/agc006/tasks/agc006_b
#include <bits/stdc++.h>
using namespace std;
#define TEMPLATE
#ifdef BTK
#define DEBUG if (1)
#else
#define CIN_ONLY if (1)
struct cww {
    cww() {
        CIN_ONLY {
            ios::sync_with_stdio(false);
            cin.tie(0);
        }
    }
} star;
#define DEBUG if (0)
#endif
#define ALL(v) (v).begin(), (v).end()
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T>
inline bool chmin(T& l, T r) {
    bool a = l > r;
    if (a) l = r;
    return a;
}
template <typename T>
inline bool chmax(T& l, T r) {
    bool a = l < r;
    if (a) l = r;
    return a;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& it : v) is >> it;
    return is;
}
template <typename T>
inline T& unused_var(T& v) {
    return v;
}
class reverse_range {
  private:
    struct I {
        int x;
        int operator*() { return x - 1; }
        bool operator!=(I& lhs) { return x > lhs.x; }
        void operator++() { --x; }
    };
    I i, n;

  public:
    reverse_range(int n) : i({0}), n({n}) {}
    reverse_range(int i, int n) : i({i}), n({n}) {}
    I& begin() { return n; }
    I& end() { return i; }
};
class range {
  private:
    struct I {
        int x;
        int operator*() { return x; }
        bool operator!=(I& lhs) { return x < lhs.x; }
        void operator++() { ++x; }
    };
    I i, n;

  public:
    range(int n) : i({0}), n({n}) {}
    range(int i, int n) : i({i}), n({n}) {}
    I& begin() { return i; }
    I& end() { return n; }
    reverse_range operator!() { return reverse_range(*i, *n); }
};
using LL = long long;

int pos[212345];
int used[212345];
int main() {
    int N, x;
    cin >> N >> x;
    if (x == 1 || x == 2 * N - 1) {
        cout << "No" << endl;
        return 0;
    }
    else {
        cout << "Yes" << endl;
    }
    pos[N]      = x - 1;
    pos[N - 1]  = x;
    pos[N - 2]  = x + 1;
    used[x - 1] = used[x] = used[x + 1] = 1;
    if (N >= 3) {
        if (x == 2 * N - 2) {
            pos[N - 3]  = x - 2;
            used[x - 2] = 1;
        }
        else {
            pos[N + 1]  = x + 2;
            used[x + 2] = 1;
        }
    }
    int p = 0;
    for (int i : range(1, 2 * N)) {
        if (used[i]) continue;
        while (pos[p] != 0) p++;
        pos[p++] = i;
    }
    for (int i : range(2 * N - 1)) {
        cout << pos[i] << endl;
    }
    return 0;
}

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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i)=0; (i)<n; ++(i))
#define rep1(i,n) for(int (i)=1; (i)<=n; ++(i))
#define repU(i,bottom,ceiling) for(int (i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i,ceiling,bottom) for(int (i) = (ceiling); (i) >= (bottom); --(i))
#define pub push_back
#define pob pop_back
#define prf printf
#define scf scanf
#define mkp make_pair
#define fir first
#define sec second
#define clr(a) memset((a),0,sizeof(a))

typedef long long ll;
typedef double db;

const vector<pair<int,int>> DIR = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF = -1 + (1<<30);
const int MOD = (int)1e9 + 7;

template<typename T> inline T gcd(T a,T b){ if(a % b){ return gcd(b,a % b); }else{ return b; } }

template<typename T> inline T lcm(T a,T b){ return a / gcd(a,b) * b; }

inline long long Pow(const long long n,long long m,const int mod = MOD){
	long long res = 1,pow = n;
	while(m) {
		if(m & 1) res = (res * pow) % mod;
		pow = (pow * pow) % mod;
		m >>= 1;
	}
	return res;
}

inline vector<long long> Frac(const int range,const int mod = MOD){
	vector<long long> frac;
	frac.push_back(1);
	for(int i = 1; i <= range; ++i) frac.push_back((long long)frac.back() * i % mod);
	return frac;
}

inline long long Comb(const int n,const int m,const int mod = MOD){
	if(n < m || m < 0) return 0;
	vector<long long> frac(Frac(n,mod));
	long long rev = Pow((long long)frac[m] * frac[n-m] % mod,mod-2,mod);
	return rev * frac[n] % mod;
}

template<typename T> inline bool v_find(const vector<T> v,const T obj){
	auto itr = find(v.begin(), v.end(), obj);
	size_t index = distance(v.begin(),itr);
	if (index != v.size()) { return true; }
	return false; 
}

template<typename T> inline bool v_erase(vector<T> &v,const T obj){
	auto itr = find(v.begin(), v.end(), obj);
	size_t index = distance(v.begin(),itr);
	if (index != v.size()) {
		v.erase(itr);
		return true;
	}
	return false;	
}

template<class T,class U> inline auto LB(const T v,const U in){ return lower_bound(v.begin(),v.end(),in); }

template<class T,class U> inline auto UB(const T v,const U in){ return upper_bound(v.begin(),v.end(),in); }

inline unsigned long long nextsub(unsigned long long sub){
	unsigned long long tem = sub + (sub & -sub);
	unsigned long long btm = (~(tem) & sub) / (sub & -sub);
	return btm | tem;
}

inline void solve(){
	int n,a[200001];
	cin>>n;
	rep(i,n) cin>>a[i];
	rep(i,n){
		if(i<(n+1)/2) cout<<a[n-2*i-1]<<' ';
		else{
			if(n&1){
				cout<<a[2*(i-(n-1)/2)-1]<<' ';
			}else{
				cout<<a[2*(i-n/2)]<<' ';
			}
		}
	}
	return;
}

inline void input(){

	return;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	solve();
	return 0;
}





Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#define int long long
using namespace std;
const int N = 3e5 + 5;
const int mod[2] = {999988679, 999988609}, b[2] = {370728, 370732}, ib[2] = {396903752, 462741403};
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
char s[N];
int n, ans, a[2][N], d[2][N];
unordered_map <int, int> t;
signed main() {
	n = read(); scanf("%s", s + 1);
	for(int j = 0; j <= 1; ++ j) a[j][0] = 0, d[j][0] = 1;
	for(int i = 1, v[2] = {1, 1}; i <= n; ++ i) {
		for(int j = 0; j <= 1; ++ j) {
			a[j][i] = a[j][i - 1];
			if(s[i] == '+') a[j][i] = (a[j][i] + v[j]) % mod[j];
			if(s[i] == '-') a[j][i] = (a[j][i] + mod[j] - v[j]) % mod[j];
			if(s[i] == '>') v[j] = v[j] * b[j] % mod[j];
			if(s[i] == '<') v[j] = v[j] * ib[j] % mod[j];
			d[j][i] = v[j];
		}
	}
	for(int i = n; i >= 0; -- i) {
		ans += t[(a[0][i] + a[0][n] * d[0][i]) % mod[0] + (a[1][i] + a[1][n] * d[1][i]) % mod[1] * mod[0]];
		++ t[a[0][i] + a[1][i] * mod[0]];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 39332
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  ll n,h,w;
  cin >> n >> h >> w;
  int ans=0;
  ll a,b;
  rep(i,n){
    cin >> a >> b;
    if(a>=h && b >=w){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {

    string S;
    cin >> S;

    if (S == "RRR") cout << 3 << endl;
    else if (S == "SRR" || S == "RRS") cout << 2 << endl;
    else if (S == "SSS") cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  string ans = "Good";
  
  for (int i = 0; i < 3; i++) {
    if (s[i] == s[i+1]) {
      ans = "Bad";
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8,cnt; 

int main(){
	
	ll n,k;
	cin>>n>>k;
	ll a[k];
	for(ll i=0; i<k; i++){
		cin>>a[i];
	}
	for(ll i=n; i<=100000; i++){
		string s=to_string(i);
		bool ok=true;
		for(ll j=0; j<s.size(); j++){
			for(ll h=0; h<k; h++){
				string g=to_string(a[h]);
				if(s[j]==g[0]){
					ok=false;
					break;
				}
			}
		}
		if(ok==true){
			cout<<i;
			return 0;
		}
	}
}


Measured memory_bytes: 256
//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e9+7;
const ll INF= 1e18;
long double PI=3.1415926;

map<ll,ll>mp;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    #ifndef ONLINE_JUDGE
	freopen("inp.txt", "r", stdin);
	freopen("out.tex", "w", stdout);
    #endif

    ll n;
    cin>>n;
    ll a[n];
    for(ll x=0; x<n; x++){
        cin>>a[x];
    }
    sort(a,a+n);
    ll sum=0;
    for(ll x=0; x<n; x++){
        ll p=sqrt(a[x]);
        ll ans=0;
        for(ll y=1; y<=p; y++){
            if(a[x]%y==0){
                if(mp[y]!=0||mp[a[x]/y]!=0){
                    ans++;
                }
            }
        }
        mp[a[x]]++;
        ll r=sum;
        if(ans==0){
            sum++;
        }
        if(x<n-1&&a[x]==a[x+1]&&sum-r==1){sum--;}
    }
    cout<<sum<<"\n";
    mp.clear(); 
    return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
string s;

int main() {
    cin >> s;
    string ss = s.substr(0, 3);
    cout << ss << endl;
    return 0;
}

Measured memory_bytes: 3552
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($y = 0; $y < $H; $y++){
    fscanf(STDIN, "%s", $str);
    $map[$y] = str_split($str);
    for($x = 0; $x < $W; $x++){
        if($map[$y][$x] == "#"){
            $list[$y][$x] = 1;
        }
    }
}
$count = 0;
while($list){
    $nextList = [];
    foreach($list as $y => $xs)foreach($xs as $x => $_){
        if($x){
            if($map[$y][$x-1] == "."){
                $nextList[$y][$x-1] = $map[$y][$x-1] = "#";
            }
        }
        if($y){
            if($map[$y-1][$x] == "."){
                $nextList[$y-1][$x] = $map[$y-1][$x] = "#";
            }
        }
        if($x < $W-1){
            if($map[$y][$x+1] == "."){
                $nextList[$y][$x+1] = $map[$y][$x+1] = "#";
            }
        }
        if($y < $H-1){
            if($map[$y+1][$x] == "."){
                $nextList[$y+1][$x] = $map[$y+1][$x] = "#";
            }
        }
    }
    $list = $nextList;
    if($list)$count++;
}
echo $count;


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

int main()
{
	int a , b , x , y;
	
	cin >> a >> b;
	x = (a + b) / 2;
	y = (a + b) % 2;

	if (y == 0) {
		y = 0;
	}
	else {
		y = 1;
	}

	cout << x + y << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
int n, a[N];
int main(){
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	int ans = 0;
	for (int i = 1; i <= n; i++)
	for (int j = i + 1; j <= n; j++)
	for (int k = j + 1; k <= n; k++)
	{
		if (a[i] == a[j] || a[i] == a[k] || a[j] == a[k]) continue;
		if (a[i] + a[j] > a[k]) ans++;
	}
	cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    ll n,i;
    cin>>n;
    ll arr[n+1];
    for(i=1;i<=n;i++)
        cin>>arr[i];
    ll dp[n+1];
    dp[1] = 0;
    dp[2] = abs(arr[2]-arr[1]);
    for(i=3;i<=n;i++)
    {
        dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    pair<int, int> ans{INF<int>, INF<int>};
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        ans = min(ans, {-b, a});
    }
    printf("%d %d\n", ans.second, -ans.first);
    return 0;
}


Measured memory_bytes: 3188
N,K = map(int,(input().split()))
A = list(map(int,input().split()))

def f(X):
    return sum([X ^ a for a in A])

if K==0:
    print(f(0))
else:
    l = len(bin(K)[2:])
    a_bit = [N - 2*sum([(a & (1<<i))>>i for a in A]) for i in range(l)]
    k_bit = [a > 0 for a in a_bit]
    k = 0
    for i,b in enumerate(k_bit[::-1],1):
        if b and (k + (1<<(l-i)) <= K):
            k += (1<<(l-i))
    print(f(k))

Measured memory_bytes: 15144
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N = II()
    A = LI()

    """
    A_i = (X_i + X_i+1) / 2 より
    2 * A_i = X_i + X_i+1
    
    また、答えのリストをXとすると、sum(A) == sum(X)　より
    X0 = sum(X) - (X1 + X2 + .. XN)
       = sum(A) - (2A1 + 2A3 + ... 2A_N-1)
       = sum(A) - 2 * (A1 + A3 + ... A_N-1)
    """
    sma = 0
    for i in range(1, N, 2):
        sma += A[i]

    ans = [-1] * N
    ans[0] = sum(A) - 2 * sma

    """
    X_i+1 = 2A_i - X_i 
    """
    for i in range(1, N):
        ans[i] = 2 * A[i-1] - ans[i-1]
    print(*ans)


if __name__ == '__main__':
    solve()


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

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

    int ans=0;
    ll now=1;
    while(now<=n)
    {
        now*=2;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define yn(f) cout << (f ? "Yes" : "No") << endl;

int n,x,y,ans[2000];
vector<int> v[2000];

#define P pair<int,int>

void kr(int s) {
    priority_queue<P, vector<P>, greater<P>> pq;
    bool visited[2000]={};
    pq.push(mp(0,s));
    while(pq.size()) {
        int c = pq.top().fi, idx = pq.top().se;pq.pop();
        if (visited[idx]) continue;
        visited[idx] = true;
        if (s < idx) ans[c]++;
        for(auto i : v[idx]) pq.push(mp(c+1, i));
    }
}

signed main() {
    cin >> n >> x >> y;
    rep(i,n-1) v[i].pb(i+1), v[i+1].pb(i);
    --x, --y;
    v[x].pb(y);
    v[y].pb(x);
    rep(i,n-1) kr(i);
    rep11(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.regex.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner input=new Scanner(System.in);
		String str=input.nextLine();
		String pattern="A?KIHA?BA?RA?$";
		if(Pattern.matches(pattern,str)) System.out.println("YES");
		else System.out.println("NO");
   }
}

Measured memory_bytes: 21588
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(void) {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i, n) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(i, n) rep(j, i) {
    int ng = -1;
    int ok = j;
    while(abs(ok - ng) > 1) {
      int mid = (ok + ng) / 2;
      if(L[mid] + L[j] > L[i])
        ok = mid;
      else
        ng = mid;
    }
    ans += j - ok;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
//const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  vll b(n);
  map<ll, ll> mp;
  mp[0]++;
  b[0] = a[0];
  mp[b[0]]++;
  for (ll i = 1; i < n; i++) {
    b[i] = b[i - 1] + a[i];
    mp[b[i]]++;
  }
  ll ans = 0;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    ll x = (i -> second);
    if (x >= 2) {
      ans += x * (x - 1) / 2;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int a,b,c;cin>>a>>b>>c;
  for(int i=1;i<1000000;i++){
    if(a*i%b==c){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 3596
/* Manish Pant - insider_pants */
    
#include <bits/stdc++.h>
using namespace std;
    
#define F first
#define S second
#define endl "\n"
#define pb push_back
    
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
    
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ", "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; } 

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

string s;

void solve()
{
    deque<char> dq;
    for(char i:s) dq.pb(i);

    int dir = 0;
    int q; cin>>q;
    while(q--)
    {
        int t; cin>>t;
        if(t == 1) dir ^= 1;
        else if(t == 2)
        {
            int a; char c; cin>>a>>c;
            a--;
            if(!(a ^ dir)) dq.push_front(c);
            else dq.pb(c);
        }
    }

    if(dir == 0) for(int i = 0; i < dq.size(); i++) cout<<dq[i];
    else for(int i = dq.size() - 1; i >= 0; i--) cout<<dq[i];
    cout<<endl;
}

int main()
{
    fast();
    cin>>s;
    solve();
}

Measured memory_bytes: 976
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>

using namespace std;

void Solution()
{
    int a, b;
    
    cin>>a>>b;
    
    cout<<a * b<<" "<<2 * (a + b)<<endl;
}



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

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std; 
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ld long double
#define fi first 
#define se second 
#define mp make_pair
#define pb push_back
#define ull unsigned long long int
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define mo 1000000007
/*int const nmax = 1000006; 
vector<int> v[nmax]; 
void dfs(int i , int p)
{
	for(int j = 0; j<v[i].size(); j++)
	{
		int node = v[i][j]; 
		if(node!=p)
		{
			dfs(node,i); 
		}
	}
}*/
/////////////////////////////
ll gcd(ll a ,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll poww(ll a,ll n){if(n==0)return 1;ll p=poww(a,n/2);p=(p*p)%mo;if(n%2)p=(a*p)%mo;return p;}
////////////////////////////////////////////////////
ll n , m , q;ll ans ; ll a[50][4];
int arr[10];
void func(int i , int v)
{
	if(i<n)
	{
		for(int j = v; j<=m; j++)
		{
			arr[i]=j; 
			func(i+1,j); 
		}
		return; 
	}

	ll temp =0; 
	for(int j = 0 ; j<q;j++)
	{
		if(arr[a[j][1]-1]-arr[a[j][0]-1]==a[j][2])
		{
			temp+=a[j][3];
		}
	}
	ans = max(ans,temp);
}
void solve()
{

cin>>n>>m>>q; 
lp(i,0,q)
{
	cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3]; 
}

ans = 0 ; 
func(0,1); 
cout<<ans<<endl; 
}
int main()
{ ios; 

ll t =1; 
 while(t--)
	solve(); 
	return 0 ; 
}

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

int main()
{
    int A;
    cin>>A;
    char op;
    cin>>op;
    int B;
    cin>>B;
    if(op=='+'){
        cout<<A+B<<endl;
    }else{
        cout<<A-B<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.stream.IntStream;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    ArrayList<String> arrayWordList = new ArrayList<>();
    int n = sc.nextInt();
    String ans = "Yes";

    for (int i = 0; i < n; i++) {
      String word = sc.next();
      if (arrayWordList.contains(word)) {
        ans = "No";
        break;
      }
      if (i > 0) {
        String beforeWord = arrayWordList.get(i - 1);
        char beforeLastChar = beforeWord.toCharArray()[beforeWord.length() - 1];
        char thisFirstChar = word.toCharArray()[0];
        if (beforeLastChar != thisFirstChar) {
          ans = "No";
          break;
        }
      }
      arrayWordList.add(word);
    }
    out.println(ans);
    out.close();
  }

  /*
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int N = 1;
			double v = sc.nextDouble();
			for( ; ; N++){
				if ((N-1)*98 >= v*v) break;
			}
			System.out.println(N);
		}
		sc.close();
	}
}

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


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

    int A[5];
    rep(i,5){
    cin >> A[i];
    }
    int fa=10000;
    vector<int> P={0,1,2,3,4};
    do{
        int ans=0;
        rep(i,5){
            while(ans%10!=0) ans++;
            ans+=A[P[i]];
        }
        fa=min(fa,ans);
    }while(next_permutation(P.begin(),P.end()));
    cout << fa << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    // i文字目からとj文字目からそれぞれ始まる最長共通接頭辞（重なってても良い）
    vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
    for(int i = n - 1; i >= 0; i--) {
        for(int j = n - 1; j >= 0; j--) {
            if(s[i] == s[j]) {
                dp[i][j] = dp[i + 1][j + 1] + 1;
                ans = max(ans, min(dp[i][j], j - i));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 99968