akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL


struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
};
  
typedef struct node * Node;
  
Node root;

void Insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
    
  while(x!=NIL){
    y=x;
  
    if(z->key<x->key){
      x=x->left;
    }
    else x=x->right;
  }
  z->parent=y;
    
  if(y==NIL){
    root=z;
  }
  else if(z->key<y->key){
    y->left=z;
  }
  else y->right=z;
}
 

  
void preorder(Node u){
  printf(" %d",u->key);
  if(u!=NIL){
    if(u->left!=NIL){
      preorder(u->left);
    }
    if(u->right!=NIL){
      preorder(u->right);
    }
  }
}
  
void inorder(Node u){
    
  if(u!=NIL){
    if(u->left!=NIL){
      inorder(u->left);
    }
    printf(" %d",u->key);
      
    if(u->right!=NIL){
      inorder(u->right);
    }
  }
}
  
void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
    
  while(x!=NIL){
    y=x;
  
    if(z->key<x->key){
      x=x->left;
    }
    else x=x->right;
  }
  z->parent=y;
    
  if(y==NIL){
    root=z;
  }
  else if(z->key<y->key){
    y->left=z;
  }
  else y->right=z;
}
  
Node Search(Node u,int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k<u->key){
    return Search(u->left,k);
  }
  else return Search(u->right,k);
}
  
main(){
  int n, i, x;
  char str[20];
    
  scanf("%d",&n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s",str);
  
    if (str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    } 
    else if (str[0]=='p'){
      inorder(root);
      printf("\n");
        
      preorder(root);
      printf("\n");
    }
    else if(str[0]=='f'){
      scanf("%d",&x);
      Node s=Search(root,x);
      if (s!= NIL ) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

 
 



Measured memory_bytes: 20448
#include<iostream>
#include <string>
#include <algorithm>

int main()
{
  std::string s;
  std::cin >> s;
  
  std::reverse(s.begin(), s.end());

  const struct word_def
  {
    std::string str;
    int length;
  } words[4] =
  {
    {"maerd", 5},
    {"remaerd", 7},
    {"esare", 5},
    {"resare", 6},
  };

  std::string::size_type length = s.size();
  std::string::size_type index = 0;
  while(index < length)
  {
    bool b = false;
    for(auto w : words)
    {
      if(index + w.length <= length && s.substr(index, w.length) == w.str)
      {
        index += w.length;
        b = true;
        break;
      }
    }
    if(!b)
    {
      break;
    }
  }
  
  printf("%s", (index < length) ? "NO" : "YES");
  
  return 0;
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();
        if (e - a > k) {
            System.out.println(":(");
            return;
        }
        System.out.println("Yay!");
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 20820
#include <stdio.h>

int main(void) {

   int M,D;
   
   scanf("%d%d",&M,&D);
   
   int i,j;
   int ans = 0;
   for (i = 1; i <= M; i++) {
      for (j = 1; j <= D; j++) {
         
         int d1 = j%10;
         int d2 = j/10;
         
         if (d1 >= 2 && d2 >= 2 && d1*d2 == i) {
            ans++;
         }
         
      }
   }
   
   printf("%d\n",ans);
   
   
   return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G ((c=A[a]+A[P[a]]+C[a])%k?c:0)+M(
typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L M(L f){return f?B[f]+M(f^f&-f):0;}
L S(L a,L i){for(a=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=a;}
L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)
    d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}
L K(L f){a=X[f];n=X[b];return Z[a]>Z[n]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}
main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(n=0);Z[a=H[P[n]]-n?n:0];*Z=++n)for(;!O[a];S(a=H[a],O[a]=++b))X[a]=n;
       for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int ans=0;
	for(int i=1;i<=n;++i){
		int sum=0;
		for(int j=1;j<=i;j+=2){
			if(i%j==0)++sum;
		}
		if(sum==8)++ans;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    string str; cin >> str;

    int bit = 0;
    for (; bit < 16; ++bit) {
        int sum = str[0] - '0';
        for (int j = 1; j < 4; ++j) {
            if (bit & 1 << (3 - j)) sum += str[j] - '0';
            else                    sum -= str[j] - '0';
        }

        if (sum == 7) break;
    }

    cout << str[0];
    for (int i = 1; i < 4; ++i) {
        if (bit & 1 << (3 - i)) cout << '+';
        else                    cout << '-';
        cout << str[i];
    }

    cout << "=7" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int i, hand[6]={};
    
    while(1){
    int x[4]={0, 0, 0, 0};
    for(i=1; i<=5; i++){
        cin >> hand[i];
        if(hand[i] == 1) x[1]=1;  //グー
        else if(hand[i] == 2) x[2]=1; //チョキ
        else if(hand[i] == 3) x[3]=1; //パー
        else return 0;
    }
    
    if(x[1] == 1){ //グーが出た
        if(x[2] == 1){ //チョキが出た
            if(x[3] == 1){ //パーが出た
                //あいこ
                for(i=1; i<=5; i++){
                    cout << '3' << endl;
                }
            }
            else{   //グーとチョキだけ
                for(i=1; i<=5; i++){
                    if(hand[i] == 1) cout << 1 << endl; //勝ち
                    else cout << '2' << endl; //負け
                    }
            }
        }
        else{ //チョキは出ない
            if(x[3] == 1){ //グーとパーだけ
                for(i=1; i<=5; i++){
                    if(hand[i] == 3) cout << 1 << endl; //勝ち
                    else cout << '2' << endl; //負け
                }
            }
            else{ //パーも出ない＝グーだけ
                for(i=1; i<=5; i++){
                    cout << '3' << endl; //あいこ
                }
            }
        }
    }
    else{ //グーは出ない
        if(x[2] == 1){ //チョキが出た
            if(x[3] == 1){ //パーが出た
                for(i=1; i<=5; i++){
                    if(hand[i] == 2) cout << 1 << endl; //勝ち
                    else cout << '2' << endl; //負け
                }
            }
            else{ // パーが出ない＝チョキだけ
                for(i=1; i<=5; i++){
                    cout << '3' << endl; //あいこ
                }
            }
        }
        else{ //チョキもでない＝パーだけ
            for(i=1; i<=5; i++){
                cout << '3' << endl; //あいこ
            }
        }
    }
    }
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
//#define int long long
#define print(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = (1LL << 30);
const ll MOD = 1000000007;

//=============================================================
string S, T;

void solve()
{
  bool isOK = true;

  set<pair<char, char>> s2t;
  rep(i, S.size())
  {
    s2t.insert(make_pair(S[i], T[i]));
  }

  bool exs1[26]  = {};
  bool exs2[26]  = {};

  for (auto x : s2t)
  {
    if (exs1[x.second - 'a'])
    {
      isOK = false;
      break;
    }
    else
      exs1[x.second - 'a'] = true;

    if (exs2[x.first - 'a']) {
      isOK = false;
      break;
    }
    else exs2[x.first - 'a'] = true;
  }
  cout << (isOK ? "Yes" : "No") << endl;
}
signed main()
{
  cin >> S;
  cin >> T;
  if (S.size() != T.size())
    return -1;
  solve();
  return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int H,W,N; cin >> H >> W >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  vector<vector<int>> c(H, vector<int>(W));

  int k = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i % 2 == 0) {
        c[i][j] = k + 1;
        a[k]--;
        if (a[k] == 0) k++;
      } else {
        c[i][W-1-j] = k + 1;
        a[k]--;
        if (a[k] == 0)k++;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cout << c[i][j] << " ";
    cout << endl;
  }
}

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

// headers {{{
using namespace std;
// using namespace rel_ops;
 
const double pi=acos(-1.0);
const double eps=1e-11;
const int INF=0x7FFFFFFF;
template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}
template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline bool bit(T a, int b) {return (a>>b)&1;}
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(long long n) { return __builtin_popcountll(n); }
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define eb(args...) emplace_back(args)
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ff first
#define ss second
#define sz(g) int(g.size())
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
#ifdef LOCAL
#define dout cerr 
void out() { dout << endl; }
template<typename A, typename... B> void out(A a, B... b) { dout << ' ' << a; out(b...); }
#define dbg(args...) dout << __LINE__ << ":(" << #args << ") -> ", out(args)
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
constexpr bool local = true;
#else
#define dbg(...)
#define dout if(true);else cerr
#define out(...)
#define show(...)
constexpr bool local = false;
#endif
// }}}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    char ch;
    while (cin >> ch) {
        if (ch>='A' && ch<='Z') cout << "A\n";
        else cout <<"a\n";

    }
    return 0;
}



Measured memory_bytes: 3648
from collections import Counter
N = int(input())

A = list(map(int, input().split()))
c = Counter(A)
s = c.most_common()[0][0]
idx_s = [i for i,x in enumerate(A) if x == s]
l = idx_s[0]
r = idx_s[1]

MOD = 10**9+7
fac = [1,1] + [0]*N
finv = [1,1] + [0]*N
inv = [0,1] + [0]*N
for i in range(2,N+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD
 
def nCr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

for i in range(1,N+2):
    print((nCr(N+1, i) - nCr(l+N+1-(r+1), i-1)) % MOD)

Measured memory_bytes: 27860
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 305
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
struct Node {
	int id;
	string name;
	int score;
	Node() {}
	Node(int id, string name, int score) : id(id), name(name), score(score) {}
};

bool mycomp(Node& a, Node& b) {
	if (a.name.compare(b.name) != 0) return a.name.compare(b.name) < 0;
	return a.score > b.score;
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int N;
	scanf("%d", &N);
	vector <Node> vs(N);
	for (int i = 0; i < N; i++) {
		char str[MAX_N];
		int score;
		scanf("%s %d", str, &score);
		vs[i] = Node(i + 1, string(str), score);
	}
	sort(ALL(vs), mycomp);
	for (Node& nd : vs) printf("%d\n", nd.id);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  R s;
  set<int> se;
  se.in('A');
  se.in('C');
  se.in('G');
  se.in('T');
  ll l=0,ans=0;
  rep(r,s.size()) {
    if(!se.count(s[r])) l=r+1;
    ans=max(ans,r-l+1);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}



Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int i,j,n;
	double debt = 100000;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		j = debt*1.05;
		double d = debt*1.05 / 1000;
		j = j / 1000;
		if ((d - (double)j) == 0.00) {
			debt = j * 1000;
		}
		else  {
			j = j+1;
			debt = j * 1000;

		}

	}

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

Measured memory_bytes: 588
#backfront
N=int(input())
lists=[]
for _ in range(N):
    x=int(input())
    lists.append((_,x))
lists.sort(key=lambda x:x[1])
lists.append((-10000000000000000,"end"))

cnt=0
now=-1
maxi=0
for i in range(N+1):
    p=lists[i][0]
    if now<p:
        cnt+=1
        now=p
    elif now>p:
        maxi=max(maxi,cnt)
        cnt=1
        now=p
print(N-maxi)


Measured memory_bytes: 33468
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String a= sc.next();
       String b=sc.next();
       String c=sc.next();
       int l1= a.length();
       int l2= b.length();
       if(a.charAt(l1-1)==b.charAt(0)&& b.charAt(l2-1)==c.charAt(0)) {
       System.out.println("YES");
       } else {
       System.out.println("NO");
       }
 }
 }
          

Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int n=input.nextInt();
		int back,i,j=1;
		while(true)
		{
			i=j*1000;
			if(i>=n)
			{
				back=i-n;
				break;
			}
			j++;
			
		}
	      System.out.println(back);

	}

}


Measured memory_bytes: 27084
from collections import deque
n,m = map(int,input().split())
path = [set() for _ in range(n)]
pathr= [set() for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    path[a-1].add(b-1)
    pathr[b-1].add(a-1)

def bfs(start):
    que = deque()
    d = [1e100]*n
    for i in path[start]:
        que.append(i)
        d[i] = 1
    while que:
        p = que.popleft()
        for nxt in path[p]:
            if d[nxt] == 1e100:
                que.append(nxt)
            d[nxt] = min(d[nxt], d[p] + 1)
    if d[start] == 1e100:
        return [0] * (n+1)
    ret = [0]*d[start]
    ret[-1] = start
    now = start
    for i in range(d[start] - 1)[::-1]:
        for p in pathr[now]:
            if d[p] == i+1:
                now = p
                ret[i] = now
                break
    return ret
ans = [0]*(n+1)
for i in range(n):
    tmp = bfs(i)
    if len(ans) > len(tmp):
        ans = tmp
if len(ans) > n:
  print(-1)
else:
    print(len(ans))
    for i in ans:
        print(i+1)


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

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

  int a, b;
  cin >> a >> b;
  if(b%a==0)cout << a+b << endl;
  else cout << b-a << endl;

  return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	ll ans=INF*INF;
	for(ll i=-100; i<=100; i++) {
		ll cost=0;
		REP(j,n) {
			cost+=(i-a[j])*(i-a[j]);
		}
		ans=min(cost,ans);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;cin >> n;
    string ans = "APPROVED";
    for (int i = 0; i < n; i++)
    {
        int a;cin >> a;
        if(a%2 == 0){
            if(!(a%3 == 0 || a%5 == 0)){
                ans = "DENIED";
                break;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

class Field{
private:
	int v[14][14]; //only 2-11 will be used.
public:
	Field(){
		int i, j;
		for(i=0;i<14;i++){
			for(j=0;j<14;j++){
				v[i][j] = 0;
			}
		}
	}

	void Drop(int x, int y, int s){
		x += 2;
		y += 2;

		if(s == 1){
			v[x][y]++; v[x-1][y]++; v[x+1][y]++; v[x][y-1]++; v[x][y+1]++;
		}else if(s == 2){
			int i, j;
			for(i=x-1;i<=x+1;i++){
				for(j=y-1;j<=y+1;j++){
					v[i][j]++;
				}
			}
		}else{
			int i, j;
			for(i=x-1;i<=x+1;i++){
				for(j=y-1;j<=y+1;j++){
					v[i][j]++;
				}
			}
			v[x-2][y]++; v[x+2][y]++; v[x][y-2]++; v[x][y+2]++;
		}
	}

	void printResult(){
		int i, j;
		int num = 0;
		int max = 0;

		for(i=2;i<=11;i++){
			for(j=2;j<=11;j++){
				if(v[i][j] == 0){
					num++;
				}
				if(max < v[i][j]){
					max = v[i][j];
				}
			}
		}
		cout << num << endl;
		cout << max << endl;
	}
};

int main(void){
	Field field;
	int x, y ,size;

	while(cin >> x){
		cin.ignore();
		cin >> y;
		cin.ignore();
		cin >> size;
		field.Drop(x, y, size);
	}

	field.printResult();
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

char s[111];
bool b[111][111];

int main(){
	scanf("%s" , s);
	int n = 0;
	while(s[n] > 0) ++n;
	int ans = 1234567;
	repp(c,'a','z'+1){
		repp(i,0,n) fill(b[i],b[i]+n,0);
		repp(i,0,n){
			b[0][i] = s[i] == c;
		}
		repp(k,0,n){
			int x = 0;
			repp(i,0,n){
				if(b[k][i]) ++x;
			}
			if(x + k == n){
				ans = min(ans,k);
				break;
			}
			repp(i,0,n-k-1){
				b[k+1][i] = (b[k][i] || b[k][i+1]);
			}
		}
	}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 256
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

class range {
  class Index {
    int x;
  public:
    Index(int x) : x(x) {}
    int operator*() const { return x; }
    bool operator!=(Index &r) { return x < r.x; }
    void operator++() { ++x; }
  };
  Index i, n;
public:
  range(int n) : i(0), n(n) {}
  range(int i, int n) : i(i), n(n) {}
  Index &begin() { return i; }
  Index &end() { return n; }
};

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha;
  cout.imbue(loc);

  string s, res;
  cin >> s;
  for (char c: s) {
    if (c == 'B') {
      if (!res.empty()) res.pop_back();
    }
    else res += c;
  }
  cout << res << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	string s;
	int ans = 0;
	while (cin >> s) {
		s += ' ';
		string num;
		rep(i, s.size()) {
			if ('0' <= s[i] && s[i] <= '9') num += s[i];
			else {
				ans += atoi(num.c_str());
				num.clear();
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M, p;
	cin >> N >> M >> p;
	VI D(M);
	REP(i, M) {
		cin >> D[i];
		D[i] += (N - p);
		D[i] %= N;
		//cout << D[i] << endl;
	}
	SORT(D);
	int ans = INF;
	REP(i, M) {
		int cnt = 0;
		cnt += D[i] * 2;
		if (i != M - 1) {
			cnt += (N - D[i + 1]);
		}
		else {
			cnt /= 2;
		}
		ans = min(cnt, ans);
		//cout << cnt << endl;
	}
	for (int i = M - 1; i >= 0; i--) {
		int cnt = 0;
		cnt += (N - D[i]) * 2;
		if (i != 0) {
			cnt += D[i - 1];
		}
		else {
			cnt /= 2;
		}
		ans = min(ans, cnt);
		//cout << cnt << endl;
	}
	
	cout << 100*ans << endl;
	return 0;
}




Measured memory_bytes: 3260
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;
	
	if (a <= b) cout << a << "\n";
	else cout << a - 1 << "\n";

	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  long m=1000;
  for(int i=0;i<n-1;i++){
    if(v[i]<v[i+1]){
      long x=(m/v[i])*(v[i+1]-v[i]);
      m+=x;
    }
  }
  cout<<m;
}


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

int main(){
  ll N,sum=0;
  cin >> N;
  for(ll i=1;i*i<=N;i++){
    if(N%i==0){
      ll j = N/i;
      if((j-1)>i){
        sum += (j-1);
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  A
//
//  Created by Hashizo on 2019/06/29.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#undef INT_MAX
#undef INT_MIN

#define INT_MAX	2147483647
#define INT_MIN	(-INT_MAX  -1)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REPLACE(s, f, t) regex_replace(s, regex(f), t)

int main(int argc, const char * argv[]) {
	char s[4];
	cin >> s;

	
	if(s[0] != s[1]) {
		if(s[0] != s[2]) {
			if(s[0] != s[3]) {
				cout << "No" << endl;
				return 0;
			}
			else if (s[1] == s[2]) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		else if (s[1] == s[3]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	else if (s[2] == s[3]) {
		if (s[0] == s[3]) {
			cout << "No" << endl;
			return 0;
		}
		else {
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if (n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a, int b){
	if(b == 0){
		return a;
	}
	else{
		return gcd(b, a % b);
	}
}

signed main(){
	int A, B;
	scanf("%lld%lld", &A, &B);
	printf("%lld\n", A * B / gcd(A, B));
	return 0;
}

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

int N, d[100000];


int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    sort(d, d + N);
    int ans = 0;
    for(int K = 0; K <= 100000; K++){
        auto it = lower_bound(d, d + N, K);
        if((it - d) * 2 == N){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <deque>
#include <array>
#include <cmath>

using namespace std;

int main()
{
  int n;

  cin >> n;

  if (n / 100 == 7 || n / 10 % 10 == 7 || n % 10 == 7)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  vector<int> as(1, s);
  for (int i = 2; i <= 1000000; i++) {
    int a = as.at(i - 2);
    if (a % 2 == 0) { a /= 2; }
    else { a = 3 * a + 1; }
    for (int j = 0; j < as.size(); j++) {
      if (as.at(j) == a) {
        cout << i << endl;
        return 0;
      }
    }
    as.push_back(a);
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main() {

	int N;
	scanf("%d",&N);
	
	int play[3][N];
	for( int i=0; i<N; i++ ) {
		scanf("%d %d %d", &play[0][i], &play[1][i], &play[2][i] );
	}
	
	
	long long dp[3][N];
	for(int i=0; i<3; i++ ) {
		dp[i][0]=play[i][0];
	}
	
	for(int i=1; i<N; i++ ) {
		for(int j=0;j<3;j++ ){
			int sakoda = dp[ (j+1)%3 ] [i-1] ;
			int ikemen = dp[ (j+2)%3 ] [i-1] ;
			if(sakoda > ikemen){
				dp[j][i] = sakoda + play[j][i];
			} else {
				dp[j][i] = ikemen + play[j][i];
			}
		}
	}
	
	if(dp[0][N-1] > dp[1][N-1] && dp[0][N-1] > dp[2][N-1] ) {
		printf("%lld",dp[0][N-1]);
		return 0;
	}
	if(dp[1][N-1] > dp[0][N-1] && dp[1][N-1] > dp[2][N-1] ){
		printf("%lld",dp[1][N-1]);
		return 0;
	}		
	
	printf("%lld",dp[2][N-1] );
	return 0;
}		
	

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

const ll MOD = 1e9+7;

template<int MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0) v += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator - () const noexcept {
    return val ? MOD - val : 0;
  }
  constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp& operator += (const Fp& r) noexcept {
    val += r.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  constexpr Fp& operator -= (const Fp& r) noexcept {
    val -= r.val;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr Fp& operator *= (const Fp& r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp& operator /= (const Fp& r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr bool operator == (const Fp& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator != (const Fp& r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
    return is >> x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
  }
  friend constexpr Fp<MOD> modinv(const Fp<MOD> &a) noexcept {
    return modpow(a, MOD - 2);
  }
};

using mint = Fp<MOD>;

int main () {
  string S;
  cin >> S;

  vector<vector<mint>> dp(S.size()+1, vector<mint>(4, 0));

  // 0: 全パターン
  // 1: Aを含む
  // 2: ABを含む
  // 3: ABCを含む
  dp[0][0] = 1;
  rep(i,S.size()) {
    if(S[i] == 'A' || S[i] == '?')  {
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][0] + dp[i][1];
      dp[i+1][2] += dp[i][2];
      dp[i+1][3] += dp[i][3];
    }
    if(S[i] == 'B' || S[i] == '?') {
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][1];
      dp[i+1][2] += dp[i][1] + dp[i][2];
      dp[i+1][3] += dp[i][3];
    }
    if(S[i] == 'C' || S[i] == '?') {
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][1];
      dp[i+1][2] += dp[i][2];
      dp[i+1][3] += dp[i][3] + dp[i][2];
    }
  }

  cout << dp[S.size()][3] << endl;

  return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<char> C(2*N);
    vector<int> A(2*N);
    vector<int> P(2*(N+1));
    vector<vector<int>> W(2*(N+1), vector<int>(N+2)), B(W);
    for (int i = 0; i < 2*N; i++) {
        cin >> C[i] >> A[i];
        if (C[i] == 'W') {
            P[A[i]] = i;
            W[i][A[i]] = 1;
        } else {
            P[A[i]+N+1] = i;
            B[i][A[i]] = 1;
        }
    }
    for (int i = 0; i < 2*N; i++) {
        for (int j = N-1; j >= 0; j--) {
            W[i][j] += W[i][j+1];
            B[i][j] += B[i][j+1];
        }
    }
    for (int i = 0; i < 2*N-1; i++) {
        for (int j = 0; j <= N; j++) {
            W[i+1][j] += W[i][j];
            B[i+1][j] += B[i][j];
        }
    }
    vector<vector<int>> dp(N+1, vector<int>(N+1, 1e9));
    dp[0][0] = 0;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            if (i + 1 <= N) {
                int pos = P[i+1];
                int cnt = W[pos][i+1+1] + B[pos][j+1];
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + cnt);
            }
            if (j + 1 <= N) {
                int pos = P[j+1+N+1];
                int cnt = W[pos][i+1] + B[pos][j+1+1];
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + cnt);
            }
        }
    }
    cout << dp[N][N] << endl;
    return 0;
}

Measured memory_bytes: 78848
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long q = sc.nextInt();
        long h = sc.nextInt();
        long s = sc.nextInt();
        long d = sc.nextInt();
        long n = sc.nextInt();

        d = LongStream.of(d, s * 2, h * 4, q * 8).min().getAsLong();
        s = LongStream.of(s, h * 2, q * 4).min().getAsLong();
        System.out.println((n / 2) * d + (n % 2) * s);
    }
}



Measured memory_bytes: 28624
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    map<ll,ll> mp;
    rep(i, n){
        mp[a[i]]++;
    }
    ll ans = 0;
    for(auto &i : mp){
        if(i.second > 1) continue;
        bool ok = true;
        for(ll j = 1; j * j <= i.first; j++){
            if(j == 1){
                if(mp.find(1) != mp.end()){
                    if(i.first == 1) break;
                    ok = false;
                    break;
                } else {
                    continue;
                }
            }
            if(i.first % j == 0){
                if(mp.find(j) != mp.end() || mp.find(i.first / j) != mp.end()){
                    ok = false;
                }
            }
        }
        if(ok){
            ans++;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 17160
#include<bits/stdc++.h>
using namespace std;
int main(){
	string S;
	cin >>S;
	int N=S.size();
	int flag1=0;
	int flag2=0;
	int flag3=0;
	for (int i=0;i<(N-1)/2;i++){
	if(S.at(i)!=S.at(((N-1)/2)-i-1)){
		flag1++;
	}
	
	}
	int c=0;
	for(int i=((N+3)/2)-1;i<N;i++){
			if(S.at(i)!=S.at(N-c-1)){
				flag2++;
			}
			c++;
	}
	for(int i=0;i<N;i++){
		if(S.at(i)!=S.at(N-1-i)){
		flag3++;
		}
	}
	if(flag1==0 && flag2==0 && flag3==0){
	cout <<"Yes"<<endl;
	}else{
		cout <<"No"<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n),b(m),c(m);
  queue<ll> e;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  vector<pair<ll,ll>> d(m);
  for(int i=0;i<m;i++){
    cin >> b[i] >> c[i];
    d[i]=make_pair(c[i],b[i]);
  }
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  ll cnt=0;
  for(int i=0;i<m;i++){
    for(int j=0;j<d[i].second;j++){
      e.push(d[i].first);
      cnt++;
      if(cnt==n){
        break;
      }
    }
    if(cnt==n){
      break;
    }
  }
  ll sum=0;
  for(int i=0;i<n;i++){
    if(e.front()>a[i]){
      sum+=e.front();
      e.pop();
    }
    else{
      sum+=a[i];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 4992
s=str(input())
acont=0 #0101...
bcont=0 #1010...
for i in range(len(s)):
	if i%2==0:
		if s[i]=="0":
			bcont+=1
		else:
			acont+=1
	if i%2==1:
		if s[i]=="0":
			acont+=1
		else:
			bcont+=1
print(min(acont,bcont))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  int ans = 0;
  stack<char> st;
  rep(i, s.size()) {
    if(st.empty() || st.top() == s[i]) {
      st.push(s[i]);
      continue;
    }
    st.pop();
    ans += 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
(defun read-fixnum+ (&optional (in *standard-input*))
  (declare (optimize (speed 3) (safety 0) (debug 0)))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let ((result (loop (let ((byte (%read-byte)))
                          (cond ((<= 48 byte)
                                 (return (- byte 48)))
                                ((zerop byte) ; #\Nul
                                 (return-from read-fixnum+ 0)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return nil))))
      result)))

(defun main ()
  (declare (optimize (speed 3) (safety 0) (debug 0)))
  (let ((n (read))
        (ptime 0)
        (px 0)
        (py 0))
    (declare ((unsigned-byte 32) n ptime px py))
    (dotimes (i n (write-line "Yes"))
      (let ((time (read-fixnum+))
            (x (read-fixnum+))
            (y (read-fixnum+)))
        (declare ((unsigned-byte 32) time x y))
        (let ((l1 (+ (abs (- x px)) (abs (- y py))))
              (dt (- time ptime)))
          (unless (and (<= l1 dt) (evenp (+ l1 dt)))
            (write-line "No")
            (return-from main))
          (setf ptime time px x py y))))))

#-swank(main)


Measured memory_bytes: 16736
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <stack>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, x, n) for (int i = x; i < n; ++i)

typedef std::vector<int> v;
typedef std::vector<std::vector<int>> vv;
typedef unsigned long long ull;

int main(void)
{
    int n;
    scanf("%d", &n);
    v aa(n);
    REP(i, n - 1)
    {
        int a;
        scanf("%d", &a);
        ++aa[a - 1];
    }
    REP(i, n)
    {
        printf("%d\n", aa[i]);
    }
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int kaijou(int n) {
    if (n > 1) {
        return n * kaijou(n-1);
    } else {
        return 1;
    }
}
int countSmallerNum(vector<int> v, int n) {
    int count = 0;
    for (int i=0; i<v.size(); i++) {
        if (v[i] < n) {
            count++;
        }
    }
    return count;
}
int main() {
    int n;
    cin >> n;
    vector<int> v1, v2;
    for (int i=1; i<=n; i++) {
        v1.push_back(i);
        v2.push_back(i);
    }
    int a = 1, b = 1;
    for (int i=0; i<n; i++) {
        int p;
        cin >> p;
        int count = countSmallerNum(v1, p);
        a += count*kaijou(n-i-1);
        v1.erase(v1.begin()+count);
    }
    for (int i=0; i<n; i++) {
        int q;
        cin >> q;
        int count = countSmallerNum(v2, q);
        b += count*kaijou(n-i-1);
        v2.erase(v2.begin()+count);
    }
    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
def main():
    x, y = map( int, input().split())
    if x == 0:
        if y > 0:
            print(y-x)
        else:
            print(x-y+1)
    elif x > 0:
        if y > x:
            print(y-x)
        elif y > 0:
            print(x-y+2)
        else:
            print(abs(x+y)+1)
    else:
        if y == 0:
            print(-x)
        elif y > 0:
            print( abs(x+y)+1)
        elif x < y:
            print(y-x)
        else:
            print(x-y+2)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
    LL N;
    cin >> N;
    LL x=0,t;
    t=N;
    while(t){
        x+=t%10;
        t/=10;
    }
    if(N%x==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

struct str {
    int64_t B;
    int64_t C;
};

int compare (const void *a, const void *b)
{
    if(*(int64_t *)a - *(int64_t *)b < 0)
        return -1;
    if(*(int64_t *)a - *(int64_t *)b > 0)
        return 1;
    return 0;
}

int comparestr (const void *a, const void *b)
{
    if(((struct str *)a)->C - ((struct str *)b)->C < 0)
        return 1;
    if(((struct str *)a)->C - ((struct str *)b)->C > 0)
        return -1;
    return 0;
}

int main (int argc, char const *argv[])
{
    int64_t N, M, A[(int)1e5];
    struct str BC[(int)1e5];
    int64_t ans = 0;

    scanf("%"PRId64"%"PRId64, &N, &M);
    for (int i = 0; i < N; i++) {
        scanf("%"PRId64, &A[i]);
    }
    for (int i = 0; i < M; i++) {
        scanf("%"PRId64"%"PRId64, &BC[i].B, &BC[i].C);
    }

    qsort(A, N, sizeof(uint64_t), compare);
    qsort(BC, M, sizeof(struct str), comparestr);

    for (int i = 0, j = 0; i < N; i++) {
        if (A[i] > BC[j].C) break;
        A[i] = BC[j].C;
        BC[j].B--;
        if (BC[j].B == 0) j++;
    }

    for (int i = 0; i < N; i++) {
        ans += A[i];
    }

    printf("%"PRId64"\n", ans);
}


Measured memory_bytes: 4084