akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
    void solve (){
        int total=0;
        int n;
        cin>>n;
        for(int i=1;i<n;i++){
            for(int j=1;j*i<n;j++)
                total++;
        }
        cout<<total;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

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

using namespace std;

int main(){
	int H,n;
  cin>>H>>n;
  int arr[n];
  int sum=0;
  for(int i=0; i<n; i++){
  	cin>>arr[i];
    sum+=arr[i];
  }
  
  if(sum>=H){
  	cout<<"Yes";
  }
  else{
  	cout<<"No";
  }
}

Measured memory_bytes: 640
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from math import factorial
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

dicts = {}

N=one_int()

A = many_int()

# 辞書作成
for a in A:
    if a in dicts:
        dicts[a] += 1
    else:
        dicts[a] = 1

# 2個選ぶ組み合わせ計算
dicts_less ={}
sums = 0
for k, v in dicts.items():
    if v>=2:
        sums += comb(v,2)
    if v<2:
        dicts_less[k]=0
    elif v==2:
        dicts_less[k]=comb(v,2) - 0
    else:
        dicts_less[k]=comb(v,2) - comb(v-1,2)

for a in A:
    print(int(sums - dicts_less[a]))

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

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

  int count = 0;
  int a,b,d,e;

  for ( int i = A; i < B + 1; i++){
	a = i % 10;
   	b = i /10 % 10;
    d = i /1000 % 10;
    e = i /10000;
    
    if (a==e && b==d){
      count ++;
    }
  }
    cout << count << endl;
}
  

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

const int D=60;
const int MAX_N=200005;
int to[D+1][MAX_N];

int main(){
    ll n,k;
    cin >>n>>k;
    for (int i = 0; i < n; ++i) {
        cin >>to[0][i];
        to[0][i]--;
    }
    for (int j = 0; j < D; ++j) {
        for (int i = 0; i < n; ++i) {
            to[j+1][i]=to[j][to[j][i]];
        }
    }
    ll key=0;
    for (int i = 0; i<D ;++i) {
        if(k>>i&1){
            key=to[i][key];
        }
    }
    cout <<key+1<<endl;
    return 0;
}

Measured memory_bytes: 51264
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct Node
{
    vector<int> edges;
    int edge_count[2] = {0, 0};
    bool valid = true;
    char label;

    bool IsDeadEnd() const
    {
        return (edge_count[0] < 1 || edge_count[1] < 1);
    }
};

using Graph = vector<Node>;

void AddEdge(Graph &g, int x, int y)
{
    g[x].edges.push_back(y);
    g[x].edge_count[g[y].label - 'A'] += 1;

    g[y].edges.push_back(x);
    g[y].edge_count[g[x].label - 'A'] += 1;
}

void RemoveDeadEnds(Graph &g)
{
    queue<int> q;
    for (size_t i = 0; i < g.size(); i += 1) {
        if (g[i].IsDeadEnd()) {
            g[i].valid = false;
            q.push(i);
        }
    }

    while (!q.empty()) {
        auto node = q.front();
        q.pop();

        auto label_index = g[node].label - 'A';
        for (const auto &next : g[node].edges) {
            if (!g[next].valid) {
                continue;
            }
            g[next].edge_count[label_index] -= 1;
            if (g[next].IsDeadEnd()) {
                g[next].valid = false;
                q.push(next);
            }
        }
    }
}

int CompSize(const Graph &g, int node, vector<bool> &visited)
{
    auto size = 1;
    visited[node] = true;

    for (const auto &next : g[node].edges) {
        if (g[next].valid && !visited[next]) {
            size += CompSize(g, next, visited);
        }
    }
    return size;
}

int MaxCompSize(const Graph &g)
{
    vector<bool> visited(g.size(), false);
    auto res = 0;

    for (size_t i = 0; i < g.size(); i += 1) {
        if (g[i].valid && !visited[i]) {
            res = max(res, CompSize(g, i, visited));
        }
    }
    return res;
}

int main()
{
    int nodes, edges;
    cin >> nodes >> edges;
    cin.get();

    Graph graph(nodes);
    for (auto &node : graph) {
        cin >> node.label;
    }

    for (auto i = 0; i < edges; i += 1) {
        int x, y;
        cin >> x >> y;
        AddEdge(graph, x - 1, y - 1);
    }

    RemoveDeadEnds(graph);
    cout << (MaxCompSize(graph) > 1 ? "Yes" : "No") << "\n";

    return 0;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

int main(){
  double L;
  double ans,x,y;
  ans = 0;
  cin>>L;
  x = L/3;
  y = L/3;
  ans = x*y*(L-x-y);
  prt_dbl(10,ans);
}


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

#define ll long long

int main()
{
    ll i, j, k, n, ans;
    string s;

    cin >> n >> s;

    ll count[n][3];

    memset(count, 0, sizeof(count));
    if(s[n-1]=='R')
        count[n-1][0]=1;
    if(s[n-1]=='G')
        count[n-1][1]=1;
    if(s[n-1]=='B')
        count[n-1][2]=1;

    for(i=n-2; i>=0; i-=1)
    {
        count[i][0]=count[i+1][0];
        count[i][1]=count[i+1][1];
        count[i][2]=count[i+1][2];
        if(s[i]=='R')
            count[i][0]+=1;
        else if(s[i]=='G')
            count[i][1]+=1;
        else
            count[i][2]+=1;
    }

    ans=0;
    //RGB | RBG
    for(i=0; i<n-2; i+=1)
    {
        if(s[i]=='R')
        {
            for(j=i+1; j<n-1; j+=1)
            {
                k=j+j-i;
                if(s[j]=='G')
                {
                    ans+=count[j][2];
                    if(k<n && s[k]=='B')
                        ans-=1;
                }
                if(s[j]=='B')
                {
                    ans+=count[j][1];
                    if(k<n && s[k]=='G')
                        ans-=1;
                }
            }
        }
    }
    //GRB | GBR
    for(i=0; i<n-2; i+=1)
    {
        if(s[i]=='G')
        {
            for(j=i+1; j<n-1; j+=1)
            {
                k=j+j-i;
                if(s[j]=='R')
                {
                    ans+=count[j][2];
                    if(k<n && s[k]=='B')
                        ans-=1;
                }
                if(s[j]=='B')
                {
                    ans+=count[j][0];
                    if(k<n && s[k]=='R')
                        ans-=1;
                }
            }
        }
    }
    //BRG | BGR
    for(i=0; i<n-2; i+=1)
    {
        if(s[i]=='B')
        {
            for(j=i+1; j<n-1; j+=1)
            {
                k=j+j-i;
                if(s[j]=='G')
                {
                    ans+=count[j][0];
                    if(k<n && s[k]=='R')
                        ans-=1;
                }
                if(s[j]=='R')
                {
                    ans+=count[j][1];
                    if(k<n && s[k]=='G')
                        ans-=1;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;

vector<vector<ll>> a[101010];

void dfs(ll pre,ll now,ll num){


}
ll tmp;

int main(){
ll N;
cin>>N;
vector<ll> a(N);
for(ll i=0;i<N;i++){
  cin>>a[i];
}
sort(ALL(a));
while(1){
tmp=a[0];
for(ll i=1;i<N;i++){
  if((a[i]%a[0])!=0)
  a[i]%=a[0];
}
sort(ALL(a));
if(a[0]==tmp)
break;
}


cout<<a[0]<<endl;
return 0;
}


Measured memory_bytes: 3456
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read_<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read_().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    let mut array: Vec<i32> = vec![];
    for _ in 0..n {
        array.push(sc.read());
    }

    let mut max = 0;
    let mut max_i = 0;
    for i in 0..n {
        if array[i as usize] > max {
            max = array[i as usize];
            max_i = i;
        }
    }

    let mut max_2 = 0;
    for i in 0..n {
        if i == max_i {
            continue;
        }

        if max_2 < array[i as usize] {
            max_2 = array[i as usize];
        }
    }

    for i in 0..n {
        if max_i == i {
            println!("{}", max_2);
        } else {
            println!("{}", max);
        }
    }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N+1);
  rep(i, 0, N) cin >> A[i];
  rep(i, 0, N) B[i+1] = (B[i] + A[i]) % M;
  long long ans = 0;
  map<int, int> mp;
  rep(i, 0, N + 1) {
    mp[B[i]]++;
    ans += mp[B[i]] - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3968
n,l = map(int,input().split())
if (l <= 0) and ((l+n-1) >= 0):
  print( ((2*l+n-1)*n)//2 )
else:
  if l > 0:
    print( int(((l+1 + l+n-1)/2)*(n-1)) )
  else:
    print( int( ((l + l+n-2)/2)*(n-1) ) )

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main () {
	char a[11], b[11], c[11];
	scanf("%s %s %s", &a, &b, &c);
	
	if ( a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0]) {
		puts ("YES");
	}
	else {
		puts ("NO");
	}
	return 0;
}

Measured memory_bytes: 1624
k, n = map(int, input().split())
a = list(map(int, input().split()))
num = 0
for i in range(n-1):
    x = a[i+1]-a[i]
    num = max(x, num)
f = (k - a[n-1]) + a[0]
if num >= f:
    print(k - num)
else:
    print(k - f)

Measured memory_bytes: 32388
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=100001;

int MAX_X,MAX_Y,N;
vector<P> bound; //軸座標,数
bool appear[MAX_N];

bool on_bound(int &x1,int &y1,int &x2,int &y2){
  return ((x1==0 || x1==MAX_X)||(y1==0 || y1==MAX_Y))&&((x2==0 || x2==MAX_X)||(y2==0 || y2==MAX_Y));
}

int axis(int x,int y){
  if(y==0) return x;
  else if(x==MAX_X) return y+MAX_X;
  else if(y==MAX_Y) return (MAX_X-x)+MAX_X+MAX_Y;
  else return (MAX_Y-y)+MAX_X*2+MAX_Y;
}

int main(){
  cin >> MAX_X >> MAX_Y >> N ;
  rep(i,N){
    int x1,x2,y1,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    if(on_bound(x1,y1,x2,y2)){
      bound.push_back(P(axis(x1,y1),i));
      bound.push_back(P(axis(x2,y2),i));
    }
  }
  sort(ALL(bound));
  bool ans=true;
  fill(appear,appear+N,false);
  stack<int> st;
  rep(i,bound.size()){
    int now = bound[i].second;
    if(!appear[now]){
      appear[now]=true;
      st.push(now);
    }else{
      int next=st.top();
      st.pop();
      if(next!=now){
        ans=false;
        break;
      }
    }
  }
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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





int main(){
  while(1){
  int n;
  cin>>n;
  if(n==0){break;}
  int sum=0;
  int count=0;
  for(int i=n-1;i>=1;i--){
    sum+=i;
    if(sum%(n-i+1)==0 && i-sum/(n-i+1)>0){count++;}
  }

  cout<<count<<endl;

  }
  return 0;
}



Measured memory_bytes: 3072
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())), dtype=int)
idx = np.argsort(X)
Xs = X[idx]
ans = [None for _ in range(N)]
for i in range(N // 2):
    ans[idx[i]] = Xs[N // 2]
for i in range(N // 2, N):
    ans[idx[i]] = Xs[N // 2 - 1]
for i in range(N):
    print(ans[i])

Measured memory_bytes: 34180
#include <stdio.h>
#include <math.h>
int main(void){
    int a, b, C;
    double S, L, h;

    scanf("%d %d %d", &a, &b, &C);
    double c = C * M_PI / 180;
    S = (double) a * b * sin(c) / 2;
    L = (double) a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(c));
    h = (double) b * sin(c);

    printf("%.4f\n%.4f\n%.4f\n", S, L, h);

    return 0;
}


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

int main( void ) {
    ios::sync_with_stdio( false );
    int n;
    string s;
    cin >> n >> s;
    int sum = 0, maxn = n + 1;
    for( int i = 0; i < n; ++i )
        if( s[ i ] == '.' ) ++sum;
    for( int i = 0; i < n; ++i ) {
        if( s[ i ] == '.' ) --sum;
        else ++sum;
        maxn = min( maxn, sum );
    }
    sum = 0;
    for( int i = 0; i < n; ++i )
        if( s[ i ] == '#' ) ++sum;
    for( int i = n - 1; i >= 0; --i ) {
        if( s[ i ] == '#' ) --sum;
        else ++sum;
        maxn = min( maxn, sum );
    }
    cout << maxn << '\n';
    return 0;
}


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

using namespace std;
typedef long long ll;

// #define DEBUG


bool search(int p, int k, int n, int a[])
{
    bool ret = true;
    vector<int> cargo;
    for (int i = 0; i < k; i++)
        cargo.push_back(p);
    for (int i = 0; i < n; i++)
    {
        if (cargo.empty())
        {
            ret = false;
            break;
        }
        while (!cargo.empty() && cargo.back() < a[i])
            cargo.pop_back();

        if (!cargo.empty())
            cargo.back() -= a[i];

        if (cargo.empty())
        {
            ret = false;
            break;
        }
    }
    return ret;
}

void m_binsearch(int k, int n, int a[])
{
    int ng, ok, mid;
    ng = 0, ok = 1e9 + 1;
    while (ok - ng > 1)
    {
        mid = (ok + ng) / 2;
        if (search(mid, k, n, a))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << endl;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, k;
    cin >> n >> k;
    int a[n];

    for (int i = 0; i < n; i++)
        cin >> a[i];

    m_binsearch(k, n, a);

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		if(n<2||m<2){
			if(n<2&&m<2){
				cout<<0;
				return 0;
			}
			if(n<2){
				cout<<(m*(m-1))/2;
				return 0;
			}
			else
			cout<<(n*(n-1))/2;
			return 0;
		}
		int z=n*n+m*m-n-m;
		cout<<z/2;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans;
int main(int argc, char* argv[]){
  long int a=0,b,c;
  //scanf("%ld %ld %ld",&a,&b,&c);
  char d[3];
  scanf("%c%c%c",&d[0],&d[1],&d[2]);
  for (int i = 0; i < 3; i++) {
    if (d[i]=='o') {
      a++;
    }
  }
  printf("%ld\n",100*a+700);
}


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

using namespace std;

using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i=0;i<N;i++)
    {
        cin >> p.at(i);
    }

    vector<int> q(N);
    for(int i=0;i<N;i++)
    {
        q.at(i) = i+1;
    }

    int dif = 0;

    for(int i=0;i<N;i++)
    {
        if(p.at(i)!=q.at(i))
        {
            dif++;
        }
    }

    if(dif < 3)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    int N;
  	cin>>N;
    double D=2*N*3.1415;
    cout<<D<<endl;
}


Measured memory_bytes: 3800
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;


int main() {

	long long a, b; cin >> a >> b;
	a = max((long long)0, a - 1);

	if (a % 4 == 0) {

	}
	else if (a % 4 == 1) {
		a = 1;
	}
	else if (a % 4 == 2) {
		a++;
	}
	else if (a % 4 == 3) {
		a = 0;
	}

	if (b % 4 == 0) {

	}
	else if (b % 4 == 1) {
		b = 1;
	}
	else if (b % 4 == 2) {
		b++;
	}
	else if (b % 4 == 3) {
		b = 0;
	}



	cout << (a ^ b) << endl;









}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

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

    ll n;
    cin >> n;
    vector<string> A(n);
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        sort(A[i].begin(), A[i].end());
    }
    vector<ll> chr(26, INT_MAX);
    for (int i = 0; i < n; i++)
    {
        vector<ll> tmp(26, 0);
        for (int j = 0; j < A[i].length(); j++)
        {
            tmp[A[i][j] - 'a']++;
        }
        for (int a = 0; a < 26; a++)
            chr[a] = min(chr[a], tmp[a]);
    }
    for (int i = 0; i < 26; i++)
    {
        while (chr[i] > 0)
        {
            cout << char('a' + i);
            chr[i]--;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,var[4],chs[100100],bck[100100][4];
string str[100100];
void bao(int id){
	if(id==n+1){
		cout<<"Yes"<<endl;
		for(int i=1;i<=n;i++) cout<<(char)(chs[i]+'A'-1)<<endl;
		exit(0);
	}
	int x=str[id][0]-'A'+1;
	int y=str[id][1]-'A'+1;
	if(var[x]>=bck[id][x]){
		var[x]--;
		var[y]++;
		chs[id]=y;
		bao(id+1);
		var[y]--;
		var[x]++;
		return;
	}
	if(var[y]>=bck[id][y]){
		var[y]--;
		var[x]++;
		chs[id]=x;
		bao(id+1);
		var[x]--;
		var[y]++;
		return;
	}
	if(var[x]){
		var[x]--;
		var[y]++;
		chs[id]=y;
		bao(id+1);
		var[y]--;
		var[x]++;
	}
	if(var[y]){
		var[y]--;
		var[x]++;
		chs[id]=x;
		bao(id+1);
		var[x]--;
		var[y]++;
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>var[1]>>var[2]>>var[3];
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	int xx,yy;
	for(int i=n;i>=1;i--){
		xx=str[i][0]-'A'+1;
		yy=str[i][1]-'A'+1;
		bck[i][1]=bck[i+1][1];
		bck[i][2]=bck[i+1][2];
		bck[i][3]=bck[i+1][3];
		bck[i][xx]++;
		bck[i][yy]++;
	}
	bao(1);
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 16468
#include <stdio.h>

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

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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int) (v).size()

int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, w;
  cin >> n >> w;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  long long dp[n + 1][w + 1];
  memset(dp, 0, sizeof dp);
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= w - a[i - 1]; j++) 
      dp[i][j + a[i - 1]] = max(dp[i][j + a[i - 1]], dp[i - 1][j] + b[i - 1]);
    for (int j = 0; j <= w; j++) 
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= w; j++)
      res = max(res, dp[i][j]);
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 82452
#include <cstdio>
#include <iostream>
#include <queue>

std::priority_queue <int> pq1;
std::priority_queue <int, std::vector<int>, std::greater<int> > pq2;
long long sum1 = 0, sum2 = 0, sum = 0;

int main()
{
	int q; scanf("%d", &q);
	for(int i = 1; i <= q; i++)
	{
		int opt, a, b; scanf("%d", &opt);
		if(opt == 1)
		{
			scanf("%d%d", &a, &b);
			sum += b;
			if(pq1.size() == 0) pq1.push(a), sum1 += a;
			else
			{
				if((pq1.size() + pq2.size()) & 1)
				{
					if(a >= pq1.top()) pq2.push(a), sum2 += a;
					else pq2.push(pq1.top()), sum2 += pq1.top(), sum1 -= pq1.top(), pq1.pop(), pq1.push(a), sum1 += a;
				}
				else
				{
					if(a <= pq2.top()) pq1.push(a), sum1 += a;
					else pq1.push(pq2.top()), sum1 += pq2.top(), sum2 -= pq2.top(), pq2.pop(), pq2.push(a), sum2 += a;
				}
			}
		}
		else
		{
			long long ans = sum2 - sum1 + sum;
			if((pq1.size() + pq2.size()) & 1) ans += pq1.top();
			printf("%d %lld\n", pq1.top(), ans);
		}
	}
}

Measured memory_bytes: 3452
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Maximum Volume
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int CNT = 100;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int l;
  scanf("%d", &l);

  double x = (double)l / 3;
  printf("%.12lf\n", x * x * x);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in ("0 "+input()+" 0").split()]
ans = sum(abs(a[i+1]-a[i]) for i in range(n+1))
for i in range(n):
    print(ans-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))


Measured memory_bytes: 14172
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var x = -1

	s := strings.Split(nextLine(), " ")
	A, _ := strconv.Atoi(s[0])
	B, _ := strconv.Atoi(s[1])

	if A < 10 && B < 10 {
		x = A * B
	}

	fmt.Printf("%d\n", x)
}


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

#define MOD (1000 * 1000 * 1000 + 7)
#define INF (1LL << 60)
#define pb push_back
#define po pop_back
#define fi first
#define se second

typedef long long ll;
typedef long double ld;

#define maxn 105
#define maxw 100005
ll A[maxn][2];
ll dp[maxw];

int main() {
    int N, W;
    scanf("%d%d", &N, &W);

    for (int i = 1; i <= N; ++i)
        scanf("%lld%lld", &A[i][0], &A[i][1]);

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

    ll m = 0;
    for (int i = 1; i <= W; ++i) {
        m = max(m, dp[i]);
    }

    printf("%lld\n", m);
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string s;
  cin >> s;
  vector<int> cnt(26);
  REP(i,SZ(s)) cnt[s[i]-'a']++;
  int ans = 1000;
  REP(i,26){
	if(!cnt[i]) continue;
	char c = 'a' + i;
	string crt = s;
	while(true){
	  bool ok = true;
	  REP(i,SZ(crt))
		if(crt[i] != c)
		  ok = false;
	  if(ok) break;
	  string nxt = crt.substr(0, SZ(crt)-1);
	  REP(j,SZ(crt)-1){
		if(crt[j] == c || crt[j+1] == c)
		  nxt[j] = c;
	  }
	  crt = nxt;
	}
	mini(ans, SZ(s) - SZ(crt));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	vp in(n);
	int ma=0;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		in[i]={-b,a};
		ma=max(ma,a);
	}
	sort(all(in));
	int co=0;
	rep(i,n){
		int t=-in[i].first;
		if(t<ma)break;
		co++;
		m-=t;
		if(m<=0)break;
	}
	if(m>0)co+=(m+ma-1)/ma;
	cout<<co<<endl;
}











Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
vector<int> x, y, z;

void push(int a, int b, int c) {
    x.push_back(a);
    y.push_back(b);
    z.push_back(c);
}

void ans() {
    cout << 20 << " " << x.size() << endl;
    for (int i = 0; i < x.size(); i++) {
        cout << 20 - x[i] << " " << 20 - y[i] << " " << z[i] << endl;
    }
}

int main() {
    int L; cin >> L;
    bool flag = false;
    int cnt = 0;
    vector<int> c(20, 0);
    for (int i = 0; i <= 19; i++) {
        c[i] = (1 << i);
        if (i < 19) push(i+1, i, 0);
    }
    int max_k = -1;
    while (cnt < L) {
        int k; 
        for (k = 0; k < 19; k++) {
            if (cnt + c[k+1] > L) {
                break;
            }
        }
        if (cnt == 0) max_k = k+1;
        else push(19, k, cnt);
        cnt += c[k];
    }
    for (int i = 0; i < max_k-1; i++) {
        push(i+1, i, (1 << i));
    }
    ans();
    return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;



int main() {

	int h, w, k;
	cin >> h >> w >> k;

	VVC v(h, VC(w));

	REP(i, h)REP(j, w)cin >> v[i][j];

	VVI ans(h, VI(w, -1));

	int cur = 0;
	int num = 1;
	REP(i, h) {
		bool b = false;
		bool c = true;
		REP(j, w) {
			if (v[i][j] == '#')b = true;
		}
		if (!b)continue;
		
		REP(j, w) {
			if (v[i][j] == '#') {
				for (int k = j; k >= 0; k--) {
					if (k!=j&&v[i][k] == '#')break;
					if (ans[i][k] != -1)break;
					ans[i][k] = num;
				}
				FOR(k, j+1, w) {
					if (v[i][k] == '#')break;
					if (ans[i][k] != -1)break;
					ans[i][k] = num;
				}
				num++;
			}
		}
	}

	REP(j, w) {

		REP(i, h) {
			if (ans[i][j] != -1) {
				for (int k = i - 1; k >= 0; k--) {
					if (ans[k][j] == -1) {
						ans[k][j] = ans[i][j];
					}
					else break;
				}
				FOR(k, i + 1, h) {
					if (ans[k][j] == -1) {
						ans[k][j] = ans[i][j];
					}
					else break;
				}
			}
		}
	}



	REP(i, h) {
		REP(j, w)cout << ans[i][j] << ' ';
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        cout<<c<<endl;
    }
    else if(a==c){
        cout<<b<<endl;
    }
    else if(b==c){
        cout<<a<<endl;

    }
}

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

using namespace std;

class ParseError{};
struct Result{
    int p, val;
    Result(int a, int b) : p(a), val(b) {}
};
struct Parser{
    map<char, int> order_dict;
    Parser(){
        order_dict['*'] = 5;
        order_dict['+'] = 4;
        order_dict['-'] = 4;
        order_dict['&'] = 3;
        order_dict['^'] = 2;
        order_dict['|'] = 1;
    }
    int eval(string s){
        Result r = expr(s, 0, 0);
        if(r.p != s.size()) throw ParseError();
        return r.val;
    }
    int calc(int a, int b, char c){
        //printf("%d%c%d\n", a, c, b);
        if(c == '*') return a * b;
        if(c == '+') return a + b;
        if(c == '-') return a - b;
        if(c == '&') return a & b;
        if(c == '^') return a ^ b;
        if(c == '|') return a | b;
        assert(false);
    }
    Result expr(string s, int k, int order){
        if(order == 5) return term(s, k);
        Result r = expr(s, k, order + 1);
        while(order_dict[ s[r.p] ] == order + 1){
            Result t = expr(s, r.p + 1, order + 1);
            r.val = calc(r.val, t.val, s[r.p]);
            r.p = t.p;
        }
        return r;
    }
    Result term(string s, int k){
        if(s[k] == '('){
            Result r = expr(s, k + 1, 0);
            if(s[r.p++] != ')') throw ParseError();
            return r;
        }else if(isdigit(s[k])){
            if(s[k] == '0') throw ParseError();
            int val = 0;
            while(isdigit(s[k])){
                val = val * 10 + s[k++] - '0';
            }
            return Result(k, val);
        }else {
            throw ParseError();
        }
    }
    bool valid(string s){
        try{
            eval(s);
            return true;
        }catch(...){
            return false;
        }
    }
};
Parser P;

int dfs(const string& s, int n, int type){
    string cs = "()*+-&^|0123456789";
    vector<string> next;
    if(n == 0){
        try{
            return P.eval(s);
        }catch(...){
            return (type == 0 ? INT_MAX : INT_MIN);
        }
    }
    // add 
    for(int i = 0; i <= s.size(); i++){
        for(char c : cs) if(s[i] != c){
            string ns = s.substr(0, i) + string(1, c) + s.substr(i);
            next.push_back(ns);
        }
    }
    // delete
    for(int i = 0; i < s.size(); i++){
        string ns = s.substr(0, i) + s.substr(i + 1);
        next.push_back(ns);
    }
    int res = (type == 0 ? INT_MIN : INT_MAX);
    for(string ns : next) if(true && P.valid(ns)) {
        //cout << s << "->" << ns << endl;
        if(type == 0){
            res = max(res, dfs(ns, n - 1, type ^ 1));
        }else{
            res = min(res, dfs(ns, n - 1, type ^ 1));
        }
    }
    return res;
}

int main(){
    int N;
    while(cin >> N && N > 0){
        if(N % 2 == 0) N = 2;
        else N = 1;
        string s;
        cin >> s;
        cout << dfs(s, N, 0) << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    int A[N];
    long long sum_a = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum_a += A[i];
    }
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if(A[i] >= (double)sum_a/(double)(4*M))
        {
            cnt++;
        }
    }
    if(cnt >= M)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
    
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for (int i=1; i<10; i++) {
			for (int j=1; j<10; j++) {
				if (N == i*j) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


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

int main() {
  string s;
  cin>>s;
  string t = "CODEFESTIVAL2016";
  int n = s.length();
  int cnt = 0;
  for (int i=0; i<n; i++) {
    if (s[i] != t[i]) {
      ++cnt;
    }
  }
  cout<<cnt<<endl;

}

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

int main()
{
    int n;
    cin >> n;
    vector<string> x(n);
    for (int i = 0; i < n; i++)
        cin >> x[i];

    for (int i = 0; i < n - 1; i++)
    {
        if (x[i].back() != x[i + 1].front())
        {
            cout << "No" << endl;
            return 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (x[i] == x[j])
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
cnt = 0
for i in range(1,N+1,2):
    ans=0
    for j in range(1,i+1):
        if i % j == 0:
            ans += 1
        else:
            pass
    if ans == 8:
        cnt += 1
    else:
        pass
print(cnt)

Measured memory_bytes: 81196
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define f(n) for(int i=0;i<n;++i)
#define REP(i,n) for(long long i = 0;i < n;++i)
int main(){
	int n,t;
	cin >> n >> t;
	vector<int> a;
	REP(i,n){
		int hoge;
		cin >> hoge;
		a.push_back(hoge);
	}
	int now_minnest = a[0];
	int cnt = 0;
	int now_value = 1;
	for(int i = 1;i < n;++i){
		now_minnest = min(now_minnest,a[i]);
		if(now_value < a[i] - now_minnest){
			cnt = 1;
			now_value = a[i] - now_minnest;
		}else if(now_value == a[i] - now_minnest){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int W, H, x, y;
    cin >> W >> H >> x >> y;

    double area = (double)W * (double)H / 2.0;
    char XYisCenter = '0';
    if (W%2 == 0 and H%2 == 0 and W/2 == x and H/2 == y) XYisCenter = '1';

    printf("%.15lf %c\n", area, XYisCenter);
}

Measured memory_bytes: 256
using System;//外
using System.Linq;//Linq
public class ABC{

    public static void Main(){
        var line = Console.ReadLine();
        var l = line.Split(' ').Select(s => int.Parse(s)).ToArray();//.Split(' ').Select(s => ).ToArray
        int n = l[0];
        int a = l[1];
        int b = l[2];
        int ans;
        if (n*a<b){
            ans = n*a;
        }
        else{
            ans = b;
        }
        
        Console.WriteLine(ans);
        }
       
    }



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

int main() {
    int64_t H, W;
    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    cout << (H * W + 1) / 2 << endl;
}

Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n = n_in()
s = s_in()


from collections import Counter

c=Counter(s)

res = c['R']*c['G']*c['B']


for i in range(n):
    d = 1
    while i+d+d < n:
        if s[i] != s[i+d] and s[i+d] != s[i+d+d] and s[i] != s[i+d+d]:
            res -= 1

        d += 1
    

print(res)


Measured memory_bytes: 83192
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    rep(i,0,3) if(s[i]=='7'){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No";



}

Measured memory_bytes: 3636
#include <cstdio>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

map<string,bool> memo;
int cnt=0;

string f[30] = {
	"aaa", "aab", "aac", "aad", "aae", "aaf", "aag", "aah", "aai", "aaj",
	"aak", "aal", "aam", "aan", "aao", "aap", "aaq", "aar", "aas", "aat",
	"aau", "aav", "aaw", "aax", "aay", "aaz", "aba", "abb", "abc", "abd"
};

char talk(char begin, string s=""){
	if( s.empty() ){
		string s;
		s.push_back( begin );
		s += f[ cnt++ ];
		s.push_back( 'a' );
		printf("?%s\n", s.c_str() ); fflush(stdout);
		return s[s.size()-1];
	}else{
		printf("?%s\n", s.c_str() ); fflush(stdout);
		memo[s] = true;
		return s[s.size()-1];
	}
}

bool AI_talk(char begin, char& end){
	char str[10];
	scanf("%s", str);
	string s( str );
	if( memo.count(s) || s[0] != begin ){
		return false;
	}
	end = s[s.size()-1];
	return memo[s] = true;
}

int main(){
	char begin1, begin2, end1, end2;
	begin2 = talk( 'a' , "a" );
	bool flag = AI_talk( begin2 , begin1 );
	if( flag == false ){
		printf("!OUT\n"); fflush(stdout);
		return 0;
	}
	
	while( true ){
		begin2 = talk( begin1 );
		bool flag = AI_talk( begin2 , begin1 );
		if( flag == false ){
			printf("!OUT\n"); fflush(stdout);
			break;
		}
	}
}

Measured memory_bytes: 0
#define DBG 1

#include<bits/stdc++.h>
 
#define fi first
#define se second
 
#define mp make_pair
#define pb push_back
 
#define all(x) (x).begin(), (x).end()
 
#define F return

#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)

#define debug(x) if(DBG) cerr << #x << " is " << x << '\n';

typedef long long ll;

using namespace std;                             

typedef pair<int, int> pii;
typedef pair<ll, ll> pll; 

typedef vector<int> vi;
typedef vector<ll> vl;
 
const int MAXN = 2e5 + 500;
const int INF = 1e9 + 23;
    
const int MOD = 1e9 + 7;

int n;

void solve() {
	cin >> n;
	
	int cur = 1;
	
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		if (x == cur) cur++;
	}
	if (cur == 1) cout << -1;
	else cout << n - cur + 1;
}
         
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int tt = 1;
	
	while (tt--) {
		solve();
	}

    // you should actually read the stuff at the bottom
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
*/



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

// Comb[k][2]
// (1,2) (2,3) (3,4) (4,1)

// N=6 k=4
// (1,2,3) (1,4,5) (2,4,6) (3,5,6)

// N=3 k=3
// (1,2)

int N;
int p[100010];
std::vector<int> vs[100010];

int main()
{
  scanf( "%d", &N );

  int k = 1;

  while( k*(k-1)/2 < N )
    ++k;

  if( k*(k-1)/2 != N )
  { puts("No"); return 0; }

  int q = 1;
  rep( j, k )
  {
    rep( i, k-1-p[j] )
    {
      vs[j].push_back( q );
      vs[i+j+1].push_back( q );
      ++p[i+j+1];
      ++q;
    }

    p[j] = k-1;
  }

  puts("Yes");

  printf( "%d\n", k );
  rep( i, k )
  {
    printf( "%d", k-1 );

    rep( j, k-1 )
      printf( " %d", vs[i][j] );

    puts("");
  }

  return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

// iの倍数の箱に入ってるボールの総数
int sum[200005];

int main(){
    int N;
    cin >> N;
    vector<int> a(N+1, 0);
    for(int i = 1; i <= N; ++i){
        cin >> a[i];
    }
    
    vector<int> ans;
    for(int i = N; i >= 1; --i){
        int temp = 0;
        for(int j = i; j <= N; j += i){
            temp += sum[j];
        }
        if(temp % 2 != a[i]){
            sum[i]++;
            ans.push_back(i);
        }
    }
    
    for(int i = 1; i <= N; ++i){
        cerr << sum[i] << " ";
    }
    
    int n = ans.size();
    cout << n << endl;
    if(n>0){
        for(int i = n-1; i >= 0; --i){
            cout << ans[i] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 2936
using System;

class Program
{
	static int N;
	static bool[] can_use;
	
	static void Main()
	{
		int K;
		can_use = new bool[10];
		for(int i = 0 ; i < 10 ; i++ )can_use[i]=true;
		
		var input = Console.ReadLine().Split(' ');
		N = int.Parse(input[0]);
		K = int.Parse(input[1]);
		
		input = Console.ReadLine().Split(' ');
		for(int i = 0 ; i < K ; i++ )
		{
			var temp = int.Parse(input[i]);
			can_use[temp] = false;
		}
		
		int result = start_with(0);
		Console.WriteLine(result);
	}
	
	static int start_with(int now)
	{
		if( now >= N )
			return now;
		int min = int.MaxValue;
		
		if( can_use[0] )
		{
			if( now != 0 ){
				min = start_with(now * 10 + 0);
			}
		}
		
		for(int i = 1 ; i < 10 ; i++ ){
			if( can_use[i] ){
				int result = start_with(now*10+i);
				
				if( result < min ){
					min = result;
				}
			}
		}
		
		return min;
	}
}


Measured memory_bytes: 2648
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cstring>
#include <algorithm>
#include <vector>
//#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
using namespace std;
#define fin << '\n'
#define finl << '\n';
#define finn cout << '\n'
#define unless(flg) if(!(flg))
#define alles(obj) obj.begin(), obj.end()
// bashise
#define elif else if
#define echo cout <<
#define read cin >>
// javaise
#define bash push_back
#define makePair make_pair
#define isEmpty empty
// germanise
#define drucken(obj) cout << obj << '\n'
#define lesen(obj) cin >> obj
#define fur for
#define wenn if
#define sonst else
#define Zahl int
// type-define
#define String string
#define Stack stack
#define Queue queue
#define pQueue priority_queue
#define Vector vector
#define Pair pair
#define Map map
typedef long long llong;
typedef bool boolean;
typedef Pair<int,int> Pii;
typedef Vector<int> Vi;
// utils
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
boolean isMovable(int x,int y,int w,int h){return (x>=0&&y>=0&&x<w&&y<h);};
const int INF = 1 << 29;

Vi vi;
int  ans[200100];

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

    int n;
    read n;
    for ( int i = 0; i < n; i++ ) {
        int a;
        read a;
        vi.bash(a);
    }
    reverse(alles(vi));
    int pos = 0;
    for ( int i = 0; i < n/2; i++ ) {
        ans[i] = vi[pos++];
        ans[n-i-1] = vi[pos++];
    }
    if ( n&1 ) {
        ans[n/2] = vi[pos++];
    }
    echo ans[0];
    for ( int i = 1; i < n; i++ ) { 
        echo ' ' << ans[i];
    }
    echo endl;

    return 0;
}


Measured memory_bytes: 3828
# include <bits/stdc++.h>  
using namespace std;  
const int N = 1e5+3;  
char s[N], t[N];  
int sp[N], tp[N];  
int main()  
{  
    int q, a, b, c,d;  
    scanf("%s%s%d",s+1,t+1,&q);  
    for(int i=1; s[i]; ++i)  
        sp[i] = sp[i-1]+s[i]-'A'+1;  
    for(int i=1; t[i]; ++i)  
        tp[i] = tp[i-1]+t[i]-'A'+1;  
    while(q--)  
    {  
        scanf("%d%d%d%d",&a,&b,&c,&d);  
        if((sp[b]-sp[a-1])%3 == (tp[d]-tp[c-1])%3)  
            puts("YES");  
        else  
            puts("NO");  
    }  
    return 0;  
    } 

Measured memory_bytes: 1536
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
function main()
  n=parse(Int,readline())
  a=[parse(Int,readline()) for i=1:n]
  ans=0
  now=1
  while now != 2
    ans+=1
    pre=now
    now=a[now]
    a[pre]=0
    if a[now]==0
      ans=-1
      break
    end
  end
  println(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 168840