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

using namespace std;

long long evaluate(vector<char> &formula) {
	long long result = 0, acc = 0;
	for (char c : formula) {
		if (c == '.') {
			continue;
		}
		else if (c == '+') {
			result += acc;
			acc = 0;
		}
		else {
			acc *= 10;
			acc += c - '0';
		}
	}
	return result;
}

long long solve(string &s) {
	if (s.size() == 1) {
		return s[0] - '0';
	}
	vector<char> formula;
	for (char c : s) {
		formula.push_back(c);
		formula.push_back('.');
	}
	formula.back() = '+';
	int lim = (1 << (s.size()-1));
	long long result = 0;
	int carryover = 0;
	for (int i = 0; i < lim; i++) {
		/*int tmp = i;
		for (int j = 0; j < s.size()-1; j++, tmp /= 2) {
			if (tmp % 2) {
				formula[2*j+1] = '.';
			}
			else {
				formula[2*j+1] = '+';
			}
		}*/
		result += evaluate(formula);
		if (formula[formula.size()-3] == '.') {
			formula[formula.size()-3] = '+';
			carryover = 0;
		}
		else {
			formula[formula.size()-3] = '.';
			carryover = 1;
		}
		for (int j = formula.size()-5; j >= 0 && carryover > 0; j -= 2) {
			if (formula[j] == '.') {
				formula[j] = '+';
				carryover = 0;
			}
			else {
				formula[j] = '.';
				carryover = 1;
			}
		}
	}
	return result;
}

int main() {
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	cout << solve(s) << '\n';
	return 0;
}

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let s=read::<String>().chars().collect::<Vec<char>>();
    let t=read::<String>().chars().collect::<Vec<char>>();
    if s.len()!=t.len(){
        println!("{}",if s.len()<t.len(){"LESS"}else{"GREATER"})
    }
    else{
        for i in 0..s.len(){
            if s[i]!=t[i]{
                println!("{}",if s[i]<t[i]{"LESS"}else{"GREATER"});
                return;
            }
        }
        println!("EQUAL");
    }
}


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

using namespace std;

#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long

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

	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	if(s.size() == a + b + 1) {
		if(s[a] == '-') {
			int cnt = 0;
			for(int i = 0; i < s.size(); i++) {
				if(int(s[i]) - 48 < 0 || int(s[i]) - 48 > 9) {
					if(i != a) {
						cnt++;
					}
				}
			}
			if(cnt == 0) {
				cout << "Yes\n";
			} else {
				cout << "No\n";
			}
		} else {
			cout << "No\n";
		}
	} else {
		cout << "No\n";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define MAX_E 2000
#define MAX_V 1000
#define INF 1000000
using namespace std;

typedef struct {
  int from, to, cost;
} edge;

edge es[MAX_E];

int d[MAX_V];

bool bellman_ford(int v, int e, int start) {
  d[start] = 0;
  for (int i = 0; i < v; i++) {
    for (int j = 0; j < e; j++) {
      edge temp = es[j];
      if (d[temp.from] == INF) continue;
      if (d[temp.to] > d[temp.from] + temp.cost) {
	d[temp.to] = d[temp.from] + temp.cost;
	if (i == v - 1) return true;
      }
    }
  }
  return false;
}

void init() {
  for (int i = 0; i < MAX_V; i++) {
    d[i] = INF;
  }
}

int main() {
  int v, e, r;
  cin >> v >> e >> r;
  for (int i = 0; i < e; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    edge temp;
    temp.from = s;
    temp.to = t;
    temp.cost = d;
    es[i] = temp;
  }

  init();

  if (bellman_ford(v, e, r) == true) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }
  for (int i = 0; i < v; i++) {
    if (d[i] == INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
from collections import deque, Counter
from itertools import chain, combinations
import json
import numpy as np


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    # A = [int(a) for a in input().split()]
    c = Counter(S)
    vs = c.most_common(N)

    v = sorted([a[0] for a in vs if vs[0][1] == a[1]])
    for a in v:
        print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 58096
import sys
N, M = map(int, input().split())
ok = [True] * (N + 1)
for _ in range(M):
    a = int(sys.stdin.readline())
    ok[a] = False
ans = 0
if N == 1:
    ans = 1
else:
    counts = [0] * (N + 1)
    if ok[1]:
        counts[1] = 1
    if ok[2]:
        counts[2] = counts[1] + 1
    for s in range(3, N + 1):
        if ok[s]:
            count = counts[s-1] + counts[s-2]
            count %= 1000000007
            counts[s] = count
    ans = counts[N]
print(ans)

Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n;
	cin >> n;
	if(n % 2 == 0){
		cout << (n / 2) * (n / 2) << endl;
	}else{
		cout << (n / 2) * ((n / 2)+1) << endl;

	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] list = new int[n];
        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }

        int ans = 0;
        for (int i = 1; i < n - 1; i++) {
            if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
                ans++;
            }
            if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

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

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

int main(void){
	int n;
	cin>>n;
	vector<ll> A,B;
	ll a,b;
	rep(i,n+1){
		cin>>a;
		A.push_back(a);
	}
	rep(i,n){
		cin>>b;
		B.push_back(b);
	}
	ll ans = 0;
	rep(i,n){
		if(A[i] >= B[i]){
			A[i] -= B[i];
			ans += B[i];
		}else{
			A[i+1] -= B[i] - A[i];
			ans += A[i];
			ans += B[i] - A[i];
			if(A[i+1] < 0){
				ans += A[i+1];
				A[i+1] = 0;

			}
			A[i] = 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    string S; getline(cin,S);                     //空白を含む一行を読み取りたいとき
    rep(i,S.size()){
        if(isalpha(S[i])){                        //数字かどうかはisdigit(char)で　
            if(islower(S[i])) S[i]=toupper(S[i]);
            else S[i]=tolower(S[i]);              //小文字を大文字大文字を小文字に
        }
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>

using namespace std;

int main() {
  int R, G;
  cin >> R;
  cin >> G;

  cout << 2 * G - R << endl;

  return 0;
}

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

int main() {
	string N;
	cin >> N;
	string res = "No";
	if (N[0]=='7') res = "Yes";
	if (N[1]=='7') res = "Yes";
	if (N[2]=='7') res = "Yes";
	cout << res << "\n";
}


Measured memory_bytes: 3624
a = list(map(int,'1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')))
k = int(input())
print(a[k-1])


Measured memory_bytes: 2940
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N, D;
  cin >> N >> D;

  int X[N][D];
  rep(i, N) {
    rep(j, D) { cin >> X[i][j]; }
  }

  int result = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; j++) {
      double d = 0;
      rep(k, D) { d += pow(X[i][k] - X[j][k], 2); }
      d = sqrt(d);
      if (int(d) == d) {
        result++;
      }
    }
  }
  cout << result << endl;

  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int A[N], B[N];
    for(int i = 1; i <= N; i++){
        B[i] = 0;
    }
    for(int i = 1; i < N; i++){
        cin >> A[i];
        B[A[i]]++;
    }
    for(int i = 1; i <= N; i++){
        cout << B[i] << endl;
    }
}


Measured memory_bytes: 5156
N=int(input())
a_list=list(map(int,input().split()))
Q=int(input())

N_list=[0]*(100001)
sumn=0

for a in a_list:
    N_list[a]+=1
    sumn+=a


for i in range(Q):
    b,c=map(int,input().split())
    henka=(c-b)*N_list[b]

    sumn+=henka

    N_list[c]+=N_list[b]
    N_list[b]=0

    print(sumn)



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

struct UnionFind {
  vector<int> par;
  vector<int> rank;
  
  UnionFind(int N) : par(N), rank(N) {
    for (int i=0; i<N; i++) {
      par.at(i) = i;
      rank.at(i) = 0;
    }
  }
  
  int root (int x) {
    if (par[x]==x) {
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }
  
  void unite (int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx==ry) {return;}
    if (rank[rx] < rank[ry]) {
      par[rx] = ry;
    }
    else {
      par[ry] = rx;
      if (rank[rx]==rank[ry]) {
        rank[rx]++;
      }
    }
  }
  
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};


int main() {
  int N, M;
  cin >> N >> M;
  vector<int> V(N, 0);
  vector<int> A(M);
  vector<int> B(M);
  for (int i=0; i<M; i++) {
    cin >> A[i] >> B[i];
  }
  
  UnionFind uf(N);
  int a, b;
  for (int i=0; i<M; i++) {
    a=A[i]-1;
    b=B[i]-1;
    if (!uf.same(a, b)) {
      uf.unite(a, b);
    }
  }
  
  int m=0;
  for (int i=0; i<N; i++) {
    V[uf.root(i)]++;
  }
  for (int i=0; i<N; i++) {
    m=max(m,V[i]);
  }
  cout << m << endl;
}

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

using ll = long long;

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> res(M+1);
        for(int i = 0 ; i < N; ++i) {
            int d, v;
            cin >> d >> v;
            res[d] = max(res[d], v);
        }
        cout << accumulate(res.begin(), res.end(), 0) << endl;
    }
}


Measured memory_bytes: 3100
#include<stdio.h>
int main(void)
{
	int i,j,sum,s[5],t[5],t2[5],a,b,c,d,e,min;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	min=10;
	for(i=0;i<5;i++){
		s[0]=a;
		s[1]=b;
		s[2]=c;
		s[3]=d;
		s[4]=e;
	}
	for(i=0;i<5;i++){
		t2[i]=s[i]/10;
		t[i]=s[i]%10;
		if(t[i]==0){
			t[i]=11;
		}
		if(min>=t[i]){
			min=t[i];
		}
	}
	for(i=0;i<5;i++){
		if(s[i]%10==0){
			sum+=s[i];
		}
		else{
			s[i]=(((s[i]/10)+1)*10);
			sum+=s[i];
		}
	}
	min=10-min;
	printf("%d\n",sum-min);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

int main() {
    ll n; cin >> n;
    string s = "";
    while(n>=1){
        n--;
        s += (char)(n%26 + 97);
        n /= 26;
    }
    int N = s.size();
    for(int i = N-1; i >= 0; i--){
        cout << s[i];
    }
}




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

#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define puf push_front
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10); x/=10;} reverse(all(res)); return res;}

void solve() {
  ll n,a,b; cin>>n>>a>>b;
  ll ans=0;
  REP(i,1,n+1){
    vi F=calc(i); ll sum=0;
    rep(j,(ll)F.size()){
      sum+=F[j];
    }
    if(a<=sum&&sum<=b) ans+=i;
  }
  out(ans);
}

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


Measured memory_bytes: 256
N = int(input())
def yaku(n):
    cnt = 0
    for k in range(1,n+1):
        if n%k==0:
            cnt += 1
    return cnt

cnt = 0
for n in range(1,N+1):
    if n%2==1 and yaku(n)==8:
        if yaku(n)==8:
            cnt += 1

print(cnt)

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;

  int64_t ab = 0, ba = 0, fb = 0, bafb = 0;

  for (int64_t i = 0; i < n; i++) {
    std::string s;
    std::cin >> s;
    if (s.front() == 'B' && s.back() == 'A') {
      bafb++;
    } else if (s.front() == 'B') {
      fb++;
    } else if (s.back() == 'A') {
      ba++;
    }

    for (int64_t j = 0; j < s.size() - 1; j++) {
      if (s[j] == 'A' && s[j + 1] == 'B') {
        ab++;
      }
    }
  }

  ab += std::max<int64_t>(bafb - 1, 0);
  if (bafb != 0) {
    if (ba != 0) {
      ab++;
      ba--;
    }
    if (fb != 0) {
      ab++;
      fb--;
    }
  }

  ab += std::min(ba, fb);
  std::cout << ab << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;
	for (int i = 0; i * 4 <= 100; i++)
	{
		for (int j = 0; j * 7 + i * 4 <= 100; j++)
		{
			if (N == i * 4 + j * 7)
			{
				cout << "Yes" << endl;
				return;
			}
		}
	}
	cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
local mmi, mma = math.min, math.max
local n = io.read("*n")
local edge = {}
local len = {}
local parent = {}
local childcnt = {}
local valmin, valmax = {}, {}
for i = 1, n do
  edge[i] = {}
  len[i] = -1
  parent[i] = 0
  childcnt[i] = 0
  valmin[i], valmax[i] = false, false
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  edge[a][b], edge[b][a] = true, true
end
local k = io.read("*n")
local startpos, startval = 0, 0
for i = 1, k do
  local pos, val = io.read("*n", "*n")
  valmin[pos], valmax[pos] = val, val
  if i == 1 or val < startval then
    startpos, startval = pos, val
  end
end
local valid = true
len[startpos] = 0
local tasks = {startpos}
for i = 1, n do
  local src = tasks[i]
  for dst, _u in pairs(edge[src]) do
    if len[dst] < 0 then
      childcnt[src] = childcnt[src] + 1
      parent[dst] = src
      len[dst] = len[src] + 1
      if valmax[dst] then
        if (valmax[dst] + valmax[startpos] + len[dst]) % 2 == 1 then
          valid = false break
        end
        if valmax[startpos] + len[dst] < valmax[dst] then
          valid = false break
        end
      else
        valmax[dst] = valmax[startpos] + len[dst]
        valmin[dst] = valmax[startpos] + (len[dst] % 2)
      end
      table.insert(tasks, dst)
    end
  end
  if not valid then break end
end
if not valid then print("No")
else
  tasks = {}
  for i = 1, n do
    if childcnt[i] == 0 then
      table.insert(tasks, i)
    end
  end
  for i = 1, n - 1 do
    local c = tasks[i]
    local p = parent[c]
    local newp_min = mma(valmin[p], valmin[c] - 1)
    local newp_max = mmi(valmax[p], valmax[c] + 1)
    if newp_max < newp_min then
      valid = false
      break
    end
    valmin[p] = newp_min
    valmax[p] = newp_max
    childcnt[p] = childcnt[p] - 1
    if childcnt[p] == 0 then
      table.insert(tasks, p)
    end
  end
  if not valid then print("No")
  else
    local val = {}
    for i = 1, n do val[i] = 0 end
    val[startpos] = valmin[startpos]
    tasks = {startpos}
    for i = 1, n do
      local src = tasks[i]
      for dst, _u in pairs(edge[src]) do
        if len[src] < len[dst] then
          if valmin[dst] <= val[src] - 1 then
            val[dst] = val[src] - 1
          else
            val[dst] = val[src] + 1
          end
          table.insert(tasks, dst)
        end
      end
    end
    print("Yes")
    for i = 1, n do
      print(val[i])
    end
  end
end


Measured memory_bytes: 22964
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    string s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
    replace(s.begin(),s.end(),',',' ');
    istringstream t(s);
    string u;
    int cnt=0;
    while(t>>u){
        cnt++;
        if(cnt==n){
            cout<<u<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,ans = 0,a[4] = {};
    int i = 0;
    cin >> n;
    while(n > 0){
        int tmp = (n%10);
        if(tmp == 2) ans++;
        n /= 10;
    }
    cout << ans << endl;
    return 0;
}


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

const int MAXN = 100010;
const int mod = 1000000007;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
const int U = 3;
struct mat {
	int A[U][U];
	friend mat operator * (mat a, mat b) {
		mat res;
		for (int i = 0; i != U; ++i)
			for (int j = 0; j != U; ++j) {
				LL t = 0;
				for (int k = 0; k != U; ++k)
					t += (LL) a.A[i][k] * b.A[k][j];
				res.A[i][j] = t % mod;
			}
		return res;
	}
} I, now, A, B;
mat pow(mat a, int b, mat res = I) {
	for (; b; b >>= 1, a = a * a) if (b & 1) res = a * res;
	return res;
}
int n, m, X[MAXN];
int main() {
	for (int i = 0; i != U; ++i) I.A[i][i] = 1;
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> m;
	for (int i = 1; i <= m; ++i) std::cin >> X[i], ++X[i];
	B.A[2][0] = 1, B.A[2][1] = 2, B.A[2][2] = 1;
	B.A[1][0] = 1, B.A[1][1] = 1;
	B.A[0][0] = 1;
	A = B;
	A.A[0][2] += 1; A.A[1][2] += 1; A.A[2][2] += 1;
	now.A[0][0] += 1; now.A[1][0] += 1; now.A[2][0] += 1;
	int lst = 1;
	for (int i = 1; i <= m; ++i) {
		now = pow(A, X[i] - 1 - lst, now);
		now = B * now;
		lst = X[i];
	}
	now = pow(A, n - lst, now);
	std::cout << now.A[2][0] << std::endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

 
int main (int argv, char *argc[]){
    int a, b, c;
    int idx=0;
    int count=0;
    scanf("%d %d %d", &a, &b, &c);
    #ifdef debug
        printf("count before for:%d\n", count);
    #endif
    /* cの約数割り出し */
    for(idx = a; b >= idx; idx++){
        if(!(c % idx))count++;
        if(idx > c) break;
        #ifdef debug
            printf("idx:%d\n", idx);
            printf("count:%d\n", count);
        #endif
    }
     
    printf("%d\n", count);  
    return 0;
}

Measured memory_bytes: 596
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	all := make([]int, N)
	preall := make([]int, N)
	ReadN(all, 0, N)
	copy(preall, all)
	sort.Ints(all)

	s := all[N/2]
	m := N - 1 - N/2

	for i := 0; i < len(preall); i++ {
		if s > preall[i] {
			fmt.Println(s)
		} else {
			fmt.Println(all[m])
		}
	}
}

func ReadN(all []int, i, n int) {
	if n == 0 {
		return
	}
	if m, err := Scan(&all[i]); m != 1 {
		panic(err)
	}
	ReadN(all, i+1, n-1)

}

func Scan(a *int) (int, error) {
	return fmt.Scan(a)
}

func remove(ints []int, index int) []int {
	result := []int{}
	for i := 0; i < len(ints); i++ {
		if i != index {
			result = append(result, ints[i])
		}
	}
	return result
}


Measured memory_bytes: 37504
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let xs: Vec<i64> = sc.chars().iter().map(|&c|
        ((c as u8) - ('0' as u8)) as i64
    ).collect();
    for iset in 0..8 {
        let mut r = xs[0];
        r += if iset & 1 > 0 { xs[1] } else { -xs[1] };
        r += if iset & 2 > 0 { xs[2] } else { -xs[2] };
        r += if iset & 4 > 0 { xs[3] } else { -xs[3] };
        if r == 7 {
            println!("{}{}{}{}{}{}{}=7",
                xs[0],
                if iset & 1 > 0 { '+' } else { '-' },
                xs[1],
                if iset & 2 > 0 { '+' } else { '-' },
                xs[2],
                if iset & 4 > 0 { '+' } else { '-' },
                xs[3]
            );
            return;
        }
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int h, w, x, y;
	cin >> h >> w >> x >> y;
	int answer = x*w + y*h - x*y;
	answer = h*w - answer;
	cout << answer << endl;
}


Measured memory_bytes: 256
W,H,N = map(int,input().split())

grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

left = 0
right = W
up = H
down = 0

for i in range(N):
  if grid[i][2] == 1:
    left = max(left,grid[i][0])
  elif grid[i][2] == 2:
    right = min(right,grid[i][0])
  elif grid[i][2] == 3:
    down = max(down,grid[i][1])
  elif grid[i][2] == 4:
    up = min(up,grid[i][1])
  
if (right>left)and(up>down):
  print((right-left)*(up-down))
else:
  print(0)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define eb emplace_back
#define INF 1e9

using namespace std;
typedef long long ll;

int loc[505050], arr[505050], k, tarr[505050], ans[505050];
set <int> st;

void dnc(int s, int e) {
	if(s == e) return;
	int m = s + e >> 1;
	dnc(s, m), dnc(m+1, e);

	int d1 = s, d2 = m+1, d = s;
	st.clear();
	for(int i = s; i <= m; i++) {
		st.insert(loc[i]);
	}
	while(d1 <= m && d2 <= e) {
		if(*st.begin() >= loc[d2] + k) {
			tarr[d++] = loc[d2++];
		}
		else {
			st.erase(loc[d1]);
			tarr[d++] = loc[d1++];
		}
	}
	while(d1 <= m) tarr[d++] = loc[d1++];
	while(d2 <= e) tarr[d++] = loc[d2++];
	for(int i = s; i <= e; i++) {
		loc[i] = tarr[i];
	}
}

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

	int n;
	cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> arr[i];
		loc[arr[i]] = i;
	}
	dnc(1, n);

	for(int i = 1; i <= n; i++) {
		ans[loc[i]] = i;
	}
	for(int i = 1; i <= n; i++) {
		cout << ans[i] << ' ';
	}
}

Measured memory_bytes: 23168
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))

M = [0]*N

#漸化式を作る
L = [0]*N
R = [0]*N

for i in range(1,N):
    L[i] = gcd(L[i-1],A[i-1])
    R[N-1-i] = gcd(R[N-i],A[N-i])

for j in range(N):
    M[j] = gcd(L[j],R[j])

print(max(M))

Measured memory_bytes: 16140
import collections
N=int(input())
A=[int(x) for x in input().rstrip().split()]
A_c=collections.Counter(A)
cnt=0

for i in A_c.values():
  cnt+=(i*(i-1))//2


for i in A:
  x=A_c[i]
  if x==1:
    print(cnt)
  else:
    print(cnt-x+1)

Measured memory_bytes: 26772
Q = int(input())
PN, i = [2] + [x for x in range(3, 10**5, 2)], 1
while PN[i] < (10**5) ** 0.5:
    x, j = PN[i], -1
    while PN[j] != x:
        if PN[j] % x == 0:
            PN.pop(j)
        j -= 1
    i += 1

PNf = [0, 1] + [0] * (10**5 // 2)
ans = [0, 1] + [0] * (10**5 // 2)
i, j, temp = 2, 2, 1
while i < len(PN):
    x = PN[i]
    while x != j * 2 + 1:
        ans[j] = temp
        j += 1
    PNf[j] = 1
    if j % 2 == 0 and PNf[j//2] == 1:
        temp += 1
    i += 1
    ans[j] = temp
    j += 1

ans = ans[:j] + [temp] * (10**5 // 2 - j)

for _ in range(Q):
    l, r = map(int, input().split())
    if l == 1:
        print(ans[r//2])
    else:
        print(ans[r//2] - ans[l//2 - 1])



Measured memory_bytes: 6684
package main

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

func main() {
	a := nextInt()
	b := nextInt()
	c := nextInt()

	if b-a == c-b {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

// ---------- Util.


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int A[300005];
pll P[100005];

int main()
{
	int N;
	cin >> N;
	REP(i, 3 * N)
	{
		cin >> A[i];
	}

	//! frontは小さい順、backはでかい順に取り出す
	priority_queue<int, vector<int>, greater<int>> F;
	priority_queue<int, vector<int>> B;
	ll fs = 0, bs = 0;
	REP(i, N)
	{
		F.push(A[i]);
		fs += A[i];
		B.push(A[3 * N - 1 - i]);
		bs += A[3 * N - 1 - i];
	}

	REP(i, N + 1)
	{
		P[i] = pll(0, 0);
	}

	REP(i, N + 1)
	{
		P[i].first = fs;
		P[N - i].second = bs;

		if (F.top() < A[N + i])
		{
			fs -= F.top(); F.pop();
			fs += A[N + i];
			F.push(A[N + i]);
		}

		if (B.top() > A[2 * N - 1 - i])
		{
			bs -= B.top(); B.pop();
			bs += A[2 * N - 1 - i];
			B.push(A[2 * N - 1 - i]);
		}
	}

	ll ms = -INF;
	REP(i, N + 1)
	{
		ms = std::max(ms, P[i].first - P[i].second);
	}
	cout << ms << endl;
	return 0;
}

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

using namespace std;

int N, L, ans = 0;
int a[210];

bool cmp(int x,int y)
{
	return abs(x)<abs(y);
}
int main()
{
	cin >> N >> L;
	for(int i = 1; i <= N; i++)
		a[i] = L + i - 1;
	sort(a + 1, a + N + 1, cmp);
	for(int i = 2; i <= N; i++)
		ans += a[i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
//結局は2つの数の和の最小値
#include<stdio.h>
int main(void)
{
  int a2b,b2c,c2a,result,sum1,sum2,sum3;
  char str[16];
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d%d",&a2b, &b2c, &c2a);
  sum1 = a2b + b2c;
  sum2 = b2c + c2a;
  sum3 = c2a + a2b;
  result = sum1;
  if (result > sum2)
  {
    result = sum2;
  }
  if (result > sum3)
  {
    result = sum3;
  }
  printf("%d", result);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int h,w,c,g;
int main(void){
    scanf("%d%d%d",&h,&w,&c);
    g=gcd(max(h,w),min(h,w));
    printf("%d\n",h/g*w/g*c);
}



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

int main() {
  int N, M, X;
  cin >> N >> M >> X;

  vector<int> C(N);
  vector<vector<int>> A(N, vector<int> (M));
  rep(i, N) {
    cin >> C.at(i);
    rep(j ,M) cin >> A.at(i).at(j);
  }

  int answer = 1000000000;
  rep(s, 1 << N) {
    int cost = 0;
    vector<int> A_sum(M);
    rep(i, N) {
      if (s >> i & 1) {
        cost += C.at(i);
        rep(j, M) A_sum.at(j) += A.at(i).at(j);
      }
    }
    bool ans = true;
    rep(j, M) if (A_sum.at(j) < X) ans = false;
    if (ans) {
      answer = min(answer, cost);
    }
  }
  if (answer == 1000000000) cout << -1 << endl;
  else cout << answer << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void){
        int num[10000], i, j=0;
        for(i=0;i<10000;i++){
                scanf("%d", &num[i]);
                if(num[i]==0)
                        break;
                j++;
        }
        for(i=0;i<j;i++)
                printf("Case %d: %d\n", i+1, num[i]);
        return 0;
}

Measured memory_bytes: 1748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  long double a, b, c;
  cin >> a >> b >> c;
  if (sqrt(a) + sqrt(b) + EPS < sqrt(c)) yn;
  return 0;
}

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

using namespace std;

long long gcd(long long a,long long b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
int main(void){
    int N;
    cin>>N;
    vector<long long> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N-1;i++){
        A[i+1]=gcd(A[i],A[i+1]);
    }
    cout<<A[N-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<vector>

using namespace std;

#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()

template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}

int main(){
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	int x = tx-sx;
	int y = ty-sy;

	rep(i,y) cout << 'U';
	rep(i,x) cout << 'R';
	rep(i,y) cout << 'D';
	rep(i,x) cout << 'L';
	cout << 'L';
	rep(i,y+1) cout << 'U';
	rep(i,x+1) cout << 'R';
	cout << "DR";
	rep(i,y+1) cout << 'D';
	rep(i,x+1) cout << 'L';
	cout << 'U' << endl;
}

Measured memory_bytes: 256
n = int(input())
dat = []
for _ in range(n):
    dat.append(int(input()))
dat.sort()
# 1 2 3 4 5
# 1 2 3 4

if n & 1 == 0:
    x1 = n // 2
    x2 = x1 - 1
    res = 0
    for i in range(n):
        if i < x2:
            res += (dat[i]) * -2
            continue
        if i == x2:
            res += (dat[i]) * -1
            continue
        if i == x1:
            res += (dat[i])
            continue
        if i > x1:
            res += (dat[i]) * 2
            continue
    print(res)
else:
    xc = n // 2
    xl = xc - 1
    xr = xc + 1

    res = 0
    for i in range(n):
        if i < xl:
            res += (dat[i]) * -2
            continue
        if i == xl:
            res += (dat[i]) * -1
            continue
        if i == xc:
            res += (dat[i]) * -1
            continue
        if i > xc:
            res += (dat[i]) * 2
            continue

    res2 = 0
    for i in range(n):
        if i < xc:
            res2 += (dat[i]) * -2
            continue
        if i == xc:
            res2 += (dat[i]) * 1
            continue
        if i == xr:
            res2 += (dat[i]) * 1
            continue
        if i > xr:
            res2 += (dat[i]) * 2
            continue

    print(max(res, res2))



Measured memory_bytes: 81000
def myAnswer(N:int,M:int,K:list,A:list) -> int:
   kinds = [0 for i in range(M)]
   total = 0
   for a in A:
      for k in a:
         kinds[k-1]+=1
   for kind in kinds:
      if(kind == N):
         total+=1
   return total



def modelAnswer():
   tmp=1
def main():
   N,M = map(int,input().split())
   K =[]
   A = []
   for _ in range(N):
      tmp = list(map(int,input().split()))
      K.append(tmp.pop(0))
      A.append(tmp)
   print(myAnswer(N,M,K,A))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
    int i,N,j,t,cnt=0;
    int array[100]={};
    //入力表示
    scanf("%d", &N);
    for(i=0; i <= N-1; i++) scanf("%d", &array[i]);

    //大小比較交換
    for(i=0; i<N-1; i++){
        for(j=N-1; j>i; j--){
            if(array[j]<array[j-1]){
                t=array[j];
                array[j]=array[j-1];
                array[j-1]=t;
                cnt++;
            }
        }
    }

    //結果出力
    for(i=0; i<N; i++){
        if(i!=0)printf(" ");
        printf("%d",array[i]);
    }
    printf("\n%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<string,string> pss;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
typedef complex<ld> point;
#define MAXN 505

int d[MAXN][MAXN];
bool mk[MAXN][MAXN];
int hay[MAXN][MAXN];

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

    int n;
    cin >> n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            d[i][j]=min(min(i,j),min(n-i-1,n-j-1));
            hay[i][j]=1;
        }
    ll res=0;
    for(int i=0;i<n*n;i++)
    {
        int a;
        cin >> a;
        a--;
        int x=a/n;
        int y=a%n;
        res+=d[x][y];
        queue<pii> q;
        mk[x][y]=1;
        hay[x][y]=0;
        q.push(pii(x,y));
        vector<pii> pos;
        while(!q.empty())
        {
            pii p=q.front();
            pos.push_back(p);
            q.pop();

            x=p.f;
            y=p.s;
            int v=d[x][y]+hay[x][y];
            if(x && !mk[x-1][y] && d[x-1][y]>v)
            {
                d[x-1][y]=v;
                mk[x-1][y]=1;
                q.push(pii(x-1,y));
            }
            if(y && !mk[x][y-1] && d[x][y-1]>v)
            {
                d[x][y-1]=v;
                mk[x][y-1]=1;
                q.push(pii(x,y-1));
            }
            if(x<n-1 && !mk[x+1][y] && d[x+1][y]>v)
            {
                d[x+1][y]=v;
                mk[x+1][y]=1;
                q.push(pii(x+1,y));
            }
            if(y<n-1 && !mk[x][y+1] && d[x][y+1]>v)
            {
                d[x][y+1]=v;
                mk[x][y+1]=1;
                q.push(pii(x,y+1));
            }
        }

        for(auto p : pos)
            mk[p.f][p.s]=0;
    }
    db(res)
    return 0;
}
/**
3
1 3 7 9 5 4 6 8 2
4
6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8
**/


Measured memory_bytes: 13352
#include <iostream>

bool f[100001];
int c[100001];
int n, l, r;

using namespace std;

int main(){
  for (int i=2; i<=100000; i++) {
    if (!f[i])
      for (int j=2*i; j<=100000; j+=i)
	f[j] = true;
  }
  
  for (int i=3; i<=100000; i+=2) {
    if (!f[i] && !f[(i+1)/2])
      c[i] += 1;
  }

  for (int i=3; i<=100000; i++) {
    c[i] += c[i-1];
  }

  cin >> n;
  while(n--) {
    cin >> l >> r;
    cout << c[r]-c[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

string s;
int tot;
long long ans;

int main(){
	cin>>s;
	for(int i=int(s.size())-1;i>=0;--i){
		if(s[i-1]=='B'&&s[i]=='C') ++tot;
		else if(s[i]=='A') ans+=tot;
		else if(!(s[i]=='B'&&s[i+1]=='C')) tot=0;
	}
	cout<<ans;
} 

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    li a, b;
    cin >> a >> b;
    li c, d;
    cin >> c >> d;
    li e, f;
    cin >> e >> f;

    set<li> cd;
    rep(ic, 3000) {
        rep(id, 3000) {
            li sato = ic * c + id * d;
            if (sato > f) {
                break;
            }
            cd.insert(sato);
        }
    }

    PI res = {100 * a, 0};
    rep(ia, 31) {
        rep(ib, 31) {
            li mizu = ia * 100 * a + ib * 100 * b;
            if (mizu > f) {
                break;
            }
            li lim = e * mizu / 100;
            for (auto sato : cd) {
                if (sato + mizu > f) {
                    break;
                }
                if (sato > lim) {
                    break;
                }
                li score_before = res.S * (mizu + sato);
                li score_after = sato * (res.F + res.S);
                if (score_after > score_before) {
                    res = {mizu, sato};
                }
            }

        }
    }
    cout << res.F + res.S << " " << res.S << endl;

    return 0;
}

Measured memory_bytes: 3740
#include <iostream>
using namespace std;
int max(int a, int b) {
	if (b < a) {
		b = a;
	}
	return b;
}
int min(int a, int b) {
	if (b > a) {
		b=a;
	}
	return b;
}
int main() {
	int s, n, t, sum=0, ave, maxi=0, mini=1000;
	while (1) {
		cin >> n;
		if (n == 0)break;
		for (t = 0; t < n; t++) {
			cin >> s;
			sum = sum + s;
			maxi = max(s,maxi);
			mini = min(s,mini);
		}
		sum = sum - maxi - mini;
		ave = sum / (n-2);
		cout << ave << endl;
		maxi = max(0,0), mini = min(1000,1000),sum=0;
	}
	return 0;
}


Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<iterator>
using ll = long long;
using namespace std;
ll N;
vector<string> S(300),T(300);
int main()
{
	cin >> N;
	for (size_t i = 0; i < N; i++)
	{
		cin >> S[i];
	}
	for (size_t i = 0; i < N; i++)
	{
		T[i] = S[i] + S[i].substr(0,S[i].size()-1);
	}
	ll ans = 0;
	for (size_t i = 0; i < N; i++)
	{
		bool f = true;
		for (int j = 0; j < N; j++)
		{
			for (size_t k = j+1; k < N; k++)
			{
				if (T[j][k + i] != T[k][j + i]) {
					f = false;
					goto END;
				}
			}
		}
	END:
		if (f) {
			ans += N;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    /*vector<string> slimes(N);
    for (int i=0;i<N;i++){
        cin >> slimes.at(i);
    }
*/	string slimes;
  	cin >> slimes;
    bool flag = 1;

    while (flag == 1){
    bool flagg = 1;
    for (int j = 0;j < slimes.size()-1;j++){
        if (slimes.at(j) == slimes.at(j+1)){
            char dna = slimes.at(j);
          	slimes.at(j) = 'f';
            slimes.erase(slimes.begin()+j+1);
            slimes.at(j) = dna;
            flagg = 0;
        }
    }
    if (flagg == 1){
        flag = 0;
    }
    }

    int count = slimes.size();

    cout << count << endl;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{ long long a,b,c,n,s;
cin>>a>>b;
s=a+b;
if(s&1)
    cout<<"IMPOSSIBLE"<<endl;
else{
 n=(s/2);
 cout<<n<<endl;
}




return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
string s;
int main() {
	cin >> s;
	int fx = 0;
	for (int i = 0; i < s.size(); i++) {
		fx += s[i] - '0';
	}
	if (atoi(s.c_str()) % fx == 0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 256