akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

int main (){
	string s;
	cin>>s;
	int cant=0;
	int saco=0;
	forn(i, s.size()){
		if(s[i]=='S')cant++;
		if(s[i]=='T' && cant>0){
			saco++;
			cant--;
		}
	}
	cout<<s.size()-2*saco<<endl;
	
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n, a;

int main() {
    while (cin >> n) {
        if (n == 0) break;
        vint taro, hana;
        for (int i = 0; i < n; ++i) {
            cin >> a; --a;
            taro.PB(a);
        }
        sort(ALL(taro));
        for (int i = 0; i < n*2; ++i) {
            if (!binary_search(ALL(taro), i)) hana.PB(i);
        }
    
        int turn = 0, num = -1;
        while (!taro.empty() && !hana.empty()) {
            //COUT(taro); COUT(hana); COUT(num); cout << endl;
            if (turn == 0) {
                int id = lower_bound(ALL(taro), num) - taro.begin();
                if (id >= taro.size()) {
                    turn = 1; num = -1;
                }
                else {
                    num = taro[id];
                    taro.erase(taro.begin() + id);
                    turn = 1;
                }
            }
            else if (turn == 1) {
                int id = lower_bound(ALL(hana), num) - hana.begin();
                if (id >= hana.size()) {
                    turn = 0; num = -1;
                }
                else {
                    num = hana[id];
                    hana.erase(hana.begin() + id);
                    turn = 0;
                }
            }  
        }
        
        cout << hana.size() << endl;
        cout << taro.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 1220
// ABC 153-E
// 2020.1.26 bal4u

#include <stdio.h>

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define INF 0x5fffffff
int N;
int dp[20010];

int main()
{
	int i, H, ans;
	
	H = in(), N = in();
	for (i = 1; i < 20010; ++i) dp[i] = INF;
	while (N--) {
		int A = in(), B = in();
		for (i = 0; i <= H; ++i) if (dp[i] < INF) {
			if (dp[i] + B < dp[i+A]) dp[i+A] = dp[i] + B;
		}
	}
	ans = INF;
	for (i = H; i <= H+10000; ++i) if (dp[i] < ans) ans = dp[i];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        x: isize,
    }
    for i in -1000isize..1001 {
        for j in -1000isize..1001 {
            if i * i * i * i * i - j * j * j * j * j == x {
                println!("{} {}", i, j);
                return;
            }
        }
    }
}


Measured memory_bytes: 2172
#include<iostream>
#include<cmath>
using namespace std;


int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    
    int count = 0;
    int minj;

   for(int i=0; i<n; i++){
     minj = i;
     for(int j=i; j<n; j++){
       if(a[j] < a[minj]){
         minj = j;
       }
     }
     if(a[i] != a[minj]){
        int tmp = a[i];
        a[i] = a[minj];
        a[minj] = tmp;
        count++;
     }
   }

    for(int i=0; i<n; i++){
        cout << a[i];
        if(i!=n-1){
            cout << " ";
        }
    }

    cout << endl;
    cout << count << endl;
    
    return 0;
}



Measured memory_bytes: 3104
#include<stdio.h>
#define NOT_FREE -1
#define FREE 1
#define N 8

int k,v[N][N];
int col[N],row[N],dneg[2*N-1],dpos[2*N-1];

void print(){
  int i,j;
  
  for(i=0;i<N;i++)for(j=0;j<N;j++)if(v[i][j] && row[i]!=j)return;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      printf("%s",((row[i]==j)?"Q":"."));
   
    }
   printf("\n");
  }
}

void queen(int i){
  int j;
  
  if(i==N){
    print();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)continue;

    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;

    queen(i+1);

    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
  
}

int main(){
  int i,j,r,c;

  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(j=0;j<2*N-1;j++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }

  for(i=0;i<N;i++)for(i=0;i<N;i++)v[i][j]=0;

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    v[r][c]=1;
  }
  queen(0);
  
  return 0;
}



Measured memory_bytes: 2056
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void)
{
    int n, x, t;
    scanf("%d%d%d", &n, &x, &t);
    int ans = n / x;
    if (n % x != 0)
        ans++;
    printf("%d\n", ans * t);
    return 0;
}

Measured memory_bytes: 1732
N, K = map(int, input().split())
ans = 0.0
for i in range(1, N + 1):
    # 何回(s)連続表が出ればよいかを確認
    w = i
    s = 0
    while w < K:
        w *= 2
        s += 1

    # サイコロの目iが出る確率　×　i回連続表が出る確率　を足していく
    ans += (1 / N) * (1 / 2) ** s

print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define TRACE
 
#ifdef TRACE
template<class T, class U>
ostream& operator<<(ostream& out, const pair<T,U>& a){out<<"["<<a.first<<" "<<a.second<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const vector<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const set<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const multiset<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const map<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const multimap<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
#define pra(a,n) cerr<<#a<<" : ";for(int i=0;i<n;++i)cerr<<a[i]<<" ";cerr<<endl;
#define praa(a,n,m) cerr<<#a<<" : "<<endl;for(int i=0;i<n;++i){for(int j=0;j<m;++j)cerr<<a[i][j]<<" ";cerr<<endl;}
#define pr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
} 
#else
#define pr(...)
#define pra(a,n)
#define praa(a,n,m)
#endif
#define int long long

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

	vector<int> a(n + 1), pre(n + 1), kdone(n + 1), positives(n + 1);

	for(int i = 1; i <= n; i++)	{
		cin >> a[i];
		pre[i] = pre[i - 1] + a[i];
		positives[i] = positives[i - 1] + ((a[i] > 0) ? a[i] : 0);
	}

	kdone[k] = max(0LL, pre[k]);

	for(int i = k + 1; i <= n; i++)	{
		kdone[i] = max(positives[i - k] + max(pre[i] - pre[i - k], 0LL), kdone[i - 1] + positives[i] - positives[i - 1]);
	}

	cout << kdone[n] << "\n";
}

#undef int
int main()	{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("", "r", stdin);
	//freopen("", "w", stdout);
	Main();
}



























Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
typedef long long ll;
#define  pii pair<int,int>
#define  pll pair<ll,ll>
#define  vi vector<int>


using namespace std;
const int maxn=3e5+100;
const int inf=(int)1e9+7;
int n;

vector<pair<int,char> > x[maxn],y[maxn],le[2*maxn],ri[2*maxn];
int ans=inf;
void work(vi v1,vi v2,int aa){

    if(!v2.empty()&&!v1.empty()){
        vector<int>::iterator it1,it2;
        sort(v2.begin(),v2.end());
        sort(v1.begin(),v1.end());
        it2=v2.begin(),it1=v1.begin();
        for(auto p1:v1){
            for(auto p2:v2){
                if(p2<p1)continue;
                else {
                    ans=min(ans,abs(p1-p2)*10/aa);
                    break;
                }
            }
        }
        
        /*while(*it1!=*v1.end()&&*it2!=*v2.end()){
            while(*it2!=*v2.end()&&*it2<*it1)++it2;
            if(*it2==*v2.end())break;
            ans=min(ans,abs(*it1-*it2)*10/aa);
            ++it1;
        }*/
    }
}
int main(){
//	freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int xx,yy;char c;
    rep(i,1,n){
        scanf("%d%d %c",&xx,&yy,&c);

        x[xx].push_back(make_pair(yy,c));
        y[yy].push_back(make_pair(xx,c));
        le[xx-yy+200000].push_back(make_pair(xx,c));
        ri[xx+yy].push_back(make_pair(xx,c));
    }
    rep(i,0,200000){
        if(!x[i].empty()){
            vector<int>up,down;
            for(auto p:x[i]){
                if(p.second=='U')up.push_back(p.first);
                if(p.second=='D')down.push_back(p.first);
            }
            work(up,down,2);
        }
        if(!y[i].empty()){
            vector<int>right,left;
            for(auto p:y[i]){
                if(p.second=='R')right.push_back(p.first);
                if(p.second=='L')left.push_back(p.first);
            }
            work(right,left,2);
        }
    }

    rep(i,0,400000){
        if(!le[i].empty()){
            vector<int> right,down,left,up;
            for(auto p:le[i]){
                if(p.second=='D')down.push_back(p.first);
                else if(p.second=='R')right.push_back(p.first);
                else if(p.second=='U')up.push_back(p.first);
                else if(p.second=='L')left.push_back(p.first);
            }
            work(right,down,1);
            work(up,left,1);
        }
        if(!ri[i].empty()) {
            vector<int> right, up,left, down;
            for (auto p:ri[i]) {
                if (p.second == 'U')up.push_back(p.first);
                else if (p.second == 'R')right.push_back(p.first);
                else if (p.second == 'D')down.push_back(p.first);
                else if (p.second == 'L')left.push_back(p.first);
            }
            work(right, up,1);
            work(down, left,1);
        }
    }
    if(ans==inf)printf("SAFE");
    else  printf("%d",ans);




    return 0;
}

Measured memory_bytes: 67508
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    System.out.println(Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c));

  }
}

Measured memory_bytes: 35376
#include<iostream>
#include<cstdio>
#include<cstring>
#define endl '\n'
using namespace std;
int main()
{
    char s[7];
    cin>>s;
    int flag = 0;
    for(int i = 0; i<7; i++)
    {
        if(s[2] == s[3] && s[4] == s[5])
            flag = 1;
    }
    if(flag)
        cout<<"Yes"<<endl;
    else if(!flag)
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma  GCC optimize("Ofast")

//#ifdef  DEBUG
//#define _GLIBCXX_DEBUG
//#endif

// -Ofast
// -O3
// -O2
// -fsanitize=address
// -fsanitize=undefined

// add_compile_options()

#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <cassert>
#include <random>

using namespace std;
//using namesparsace __gnu_pbds;

void solve();

int main() {
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    solve();
    return 0;
}

#define ld double
#define int long long

const int maxN = 2e5 + 10, maxK = 1e4 + 10, inf = 1e15 + 10, mod = 999999, base = 223;

int x;

void solve() {
    cin >> x;
    for (int i = 1; i < 1000000; i++) {
        if ((360 * i) % x == 0) {
            cout << (360 * i) / x;
            return;
        }
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  ll x,k,d;
  cin >> x >> k >> d;
  if (x < 0) x = -x; 
  
  if (((x/d) - 1 ) > k) cout << x - d*k << endl;
  else if (((x/d) -1) == k) cout << x - ((x/d)-1)*d << endl;
  else {
    if ((x/d) == k) cout << x - k*d << endl;
    else{
      if (abs(x-(x/d)*d) < abs(x-((x/d)+1)*d)){
        if ((k-(x/d))%2 == 0) cout << abs(x-(x/d)*d) << endl;
        else cout << abs(x-((x/d)+1)*d) << endl;
      }
      else{
        if ((k-((x/d)+1))%2 == 0) cout << abs(x-((x/d)+1)*d)<< endl;
        else cout << abs(x-(x/d)*d) << endl;
        }
      }
    }

  return 0;
}


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

struct dice{
	int top;
	int front;
	int left;
	int right;
	int back;
	int bottom;
};
//??\?????§??????dice???struct dice??¨?????????????????????(??????????????????)
dice ClockwiseTop(dice X){
	dice Y;
	Y.top    = X.top;
	Y.front  = X.right;
	Y.left   = X.front;
	Y.right  = X.back;
	Y.back   = X.left;
	Y.bottom = X.bottom;
	return Y;
}

dice ClockwiseFront(dice X){
	dice Y;
	Y.top    = X.left;
	Y.front  = X.front;
	Y.left   = X.bottom;
	Y.right  = X.top;
	Y.back   = X.back;
	Y.bottom = X.right;
	return Y;
}

dice ClockwiseRight(dice X){
	dice Y;
	Y.top    = X.front;
	Y.front  = X.bottom;
	Y.left   = X.left;
	Y.right  = X.right;
	Y.back   = X.top;
	Y.bottom = X.back;
	return Y;
}

dice ClockwiseLeft(dice X){
	X = ClockwiseRight(X);
	X = ClockwiseRight(X);
	X = ClockwiseRight(X);
	return X;
}

dice ClockwiseBack(dice X){
	X = ClockwiseFront(X);
	X = ClockwiseFront(X);
	X = ClockwiseFront(X);
	return X;
}

dice Enter(dice X){
	cin >> X.top;
	cin >> X.front;
	cin >> X.right;
	cin >> X.left;
	cin >> X.back;
	cin >> X.bottom;
	return X;
}

int main(){
	//????????????????????¢?????°????????\?????????
	dice X = Enter(X);
	//?????¢??????????????\?????????
	string Rotation;
	cin >> Rotation;
	//????????????????????¢?????????
	for(int i = 0; i < Rotation.size(); i++){
		if(Rotation[i] == 'N') X = ClockwiseRight(X);
		if(Rotation[i] == 'E') X = ClockwiseFront(X);
		if(Rotation[i] == 'S') X = ClockwiseLeft(X);
		if(Rotation[i] == 'W') X = ClockwiseBack(X);
	}
	//?????¢??????????????¨?????????
	cout << X.top << endl;
	return 0;
}

Measured memory_bytes: 1204
'use strict'
const main = (input: string) => {
    const std: string = input;
    const [a, b] = std.split(' ').map(Number);
    const sum = a+b;
    if (sum % 2 !== 0) {
        return console.log('IMPOSSIBLE');
    }
    console.log(sum / 2);
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  


Measured memory_bytes: 7372
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

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

N, M = s_inpl()
A, B = [], []
for _ in range(N):
    a, b = s_inpl()
    A.append(a)
    B.append(b)

A_sind = np.argsort(A)
ans = 0
cnt = 0
for i in A_sind:
    cnt += B[i]
    ans += A[i] * B[i]

    if cnt >= M:
        ans -= (cnt - M) * A[i]
        break

print(ans)


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

int main()
{
    int N;
    cin >> N;
    int count=0;
    string S;
    cin >> S;
    for(int i=0; i<N-2; i++)
    {
        if(S.at(i)=='A')
            {
                if(S.at(i+1)=='B')
                {
                    if(S.at(i+2)=='C')
                    {
                        count++;
                    }
                }
            }
    }
    cout << count <<endl;
}

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

int main() {
  long long N,X,T;
  cin >> N >> X >> T;
  if (N%X==0) {
    cout << (N/X)*T << endl;
  }
  if (N%X!=0) {
    cout << (N/X+1)*T << endl;
  }
}

Measured memory_bytes: 3588
import itertools
n=int(input())
p=tuple(list(map(int,input().split())))
q=tuple(list(map(int,input().split())))
lst=list(itertools.permutations(range(1,n+1)))
for i in range(len(lst)):
  if lst[i]==p:
    a=i
  if lst[i]==q:
    b=i
print(abs(a-b))


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

int main(){
  ll N;cin>>N;
  vector<ll> v(5,0);
  rep(i,N){
    string s;cin>>s;
    if(s[0]=='M') v[0]++;
    if(s[0]=='A') v[1]++;
    if(s[0]=='R') v[2]++;
    if(s[0]=='C') v[3]++;
    if(s[0]=='H') v[4]++;
  }
  ll ans=0;
  ans += v[0]*v[1]*v[2]+v[0]*v[1]*v[3]+v[0]*v[1]*v[4]+v[0]*v[2]*v[3]+v[0]*v[2]*v[4]+v[0]*v[3]*v[4]+ \
  v[1]*v[2]*v[3]+v[1]*v[2]*v[4]+v[1]*v[3]*v[4]+v[2]*v[3]*v[4];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 25
using namespace std;
int n,a,l[N],r[N],par[N],sib[N],deg[N],dep[N],height[N],z[N];
bool used[N];
 
int dfs(int x,int d){
  dep[x]=d;
  if(l[x]==-1&&r[x]==-1)return 1;
  if(z[x]!=2)z[x]=1;
  if(l[x]!=-1)height[x]=max(height[x],dfs(l[x],d+1));
  if(r[x]!=-1)height[x]=max(height[x],dfs(r[x],d+1));
  return height[x]+1;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    cin>>l[a]>>r[a];
    if(l[a]!=-1)deg[a]++,used[l[a]]=true,par[l[a]]=a,sib[l[a]]=r[a];
    if(r[a]!=-1)deg[a]++,used[r[a]]=true,par[r[a]]=a,sib[r[a]]=l[a];
  }
  for(int i=0;i<n;i++)
    if(!used[i])par[i]=-1,sib[i]=-1,z[i]=2,dfs(i,0);
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<par[i]<<", sibling = "<<sib[i];
    cout<<", degree = "<<deg[i]<<", depth = "<<dep[i]<<", height = "<<height[i];
    if(!z[i])cout<<", leaf"<<endl;
    if(z[i]==1)cout<<", internal node"<<endl;
    if(z[i]==2)cout<<", root"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define zero 200000
int main()
{
	int n;
	int *numbers;
	int *commands;
	numbers=(int *)malloc(sizeof(int)*400000);
	commands=(int *)malloc(sizeof(int)*200000);
	int i;
	while(scanf("%d",&n)!=-1)
	{
		int mode=1;
		int i1=0,i2=1;
		for(i=0;i<n;i++)scanf("%d",&commands[i]);
		for(i=0;i<n;i++)
		{
			if(mode)
			{
				numbers[zero+i1]=commands[i];
				i1++;
				mode=0;	
			}
			else
			{
				numbers[zero-i2]=commands[i];
				i2++;
				mode=1;
			}
		}
		if(mode)
		{
			for(i=zero-i2+1;i<zero+i1;i++)
			{
				printf("%d ",numbers[i]);
			}
		}
		else
		{
			for(i=zero+i1-1;i>=zero-i2+1;i--)
			{
				printf("%d ",numbers[i]);
			}
		}
		printf("\n");
	}
} 


Measured memory_bytes: 3712
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = input()

if S[0] == 'A' and S[2:-1].count('C') == 1:
    S2 = S.replace('A', '').replace('C', '')
    if len(S2) == len(S) - 2 and S2.islower():
        print("AC")
        sys.exit(0)
print("WA")

Measured memory_bytes: 7976
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int x,y,s;
    while(cin >> x >> y >> s) {
        if(x == 0 && y == 0 && s == 0) break;

        int ans = 0;
        REP(i,1,s+1) {
            REP(j,1,s+1) {
                int a = i * (100 + x) / 100;
                int b = j * (100 + x) / 100;

                if(a + b == s) {
                    int c = i * (100 + y) / 100;
                    int d = j * (100 + y) / 100;

                    ans = max(ans,c + d);
                }
            }

        }

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

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dp[201010][2];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[10][10];
bool flag[10][10];
bool flag2[10][10];

ll pcnt(ll x) {
	return __builtin_popcountll(x);
}

ll f(ll x) {
	if (x == 0)return 0;
	return f(x % pcnt(x)) + 1;
}

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	vector<ll>x(n);
	ll pc = 0;
	rep(i, n) {
		x[i] = s[i] - '0';
		pc += x[i];
	}
	vector<ll>ans(n);
	rep(b, 2) {
		ll npc = pc;
		if (b == 0)npc++;
		else {
			npc--;
		}
		if (npc <= 0)continue;
		ll r0 = 0;
		rep(i, n) {
			r0= (r0 * 2) % npc;
			r0 += x[i];
		}
		ll k = 1;
		for (ll i = n - 1;i >= 0;--i) {
			if (x[i] == b) {
				ll r = r0;
				if (b == 0)r = (r + k) % npc;
				else {
					r = (r - k + npc) % npc;
				}
				ans[i] = f(r) + 1;
			}
			k = (k * 2) % npc;
		}
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 6744
#
# abc175 b
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
4 4 9 7 5"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6
4 5 4 3 3 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
9 4 6 1 9 6 10 6 6 8"""
        output = """39"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """2
1 1"""
        output = """0"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    L = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                if L[i] == L[j] or L[j] == L[k] or L[i] == L[k]:
                    continue
                if abs(L[j] - L[k]) < L[i] < L[j] + L[k]:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16336
#include <complex>
#include <iostream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main() {
  int i;
  cin >> i;
  cout << ceil(i / 2.0)-1 << endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 100010;
const double EPS = 1e-12;
const double LIM = 1e9;
const int LIM2 = 80;
int _w;

int dcmp( double x ) {
	return fabs(x) < EPS ? 0 : (x < 0 ? -1 : 1);
}

int n, k[MAXN];
double a[MAXN], b[MAXN], c[MAXN];
double p;
int tmp[MAXN];

namespace BIT {
	int c[MAXN];
	int lowbit( int x ) {
		return x & (-x);
	}
	void init() {
		memset(c, 0, sizeof c);
	}
	void add( int p ) {
		for( ; p <= n; p += lowbit(p) )
			++c[p];
	}
	int sum( int p ) {
		int s = 0;
		for( ; p; p -= lowbit(p) )
			s += c[p];
		return s;
	}
	int sum( int l, int r ) {
		return sum(r) - sum(l-1);
	}
}

bool cmpx( int i, int j ) {
	double yi = (c[i] - a[i] * p) / b[i];
	double yj = (c[j] - a[j] * p) / b[j];
	return dcmp(yi - yj) < 0;
}
void checkx( double x, ll &lcnt, ll &rcnt ) {
	for( int i = 0; i < n; ++i ) tmp[i] = i;
	p = x, sort(tmp, tmp+n, cmpx);
	lcnt = 0, rcnt = 0;
	BIT::init();
	for( int i = 0; i < n; ++i ) {
		lcnt += BIT::sum( 1, k[tmp[i]] );
		rcnt += BIT::sum( k[tmp[i]], n );
		BIT::add( k[tmp[i]] );
	}
}
double solvex() {
	ll half = (ll)n*(n-1)/2;
	half = (half>>1) + (half&1);
	double low = -LIM, high = LIM;
	for( int i = 0; i < LIM2; ++i ) {
		double mid = (low+high)/2;
		ll lcnt, rcnt;
		checkx(mid, lcnt, rcnt);
		if( lcnt >= half ) high = mid;
		else low = mid;
	}
	return low;
}

bool cmpy( int i, int j ) {
	double xi = (c[i] - b[i] * p) / a[i];
	double xj = (c[j] - b[j] * p) / a[j];
	return dcmp(xi - xj) < 0;
}
void checky( double y, ll &lcnt, ll &rcnt ) {
	for( int i = 0; i < n; ++i ) tmp[i] = i;
	p = y, sort(tmp, tmp+n, cmpy);
	lcnt = rcnt = 0;
	BIT::init();
	for( int i = 0; i < n; ++i ) {
		rcnt += BIT::sum( k[tmp[i]], n );
		lcnt += BIT::sum( 1, k[tmp[i]] );
		BIT::add( k[tmp[i]] );
	}
}
double solvey() {
	ll half = (ll)n*(n-1)/2;
	half = (half>>1) + (half&1);
	double low = -LIM, high = LIM;
	for( int i = 0; i < LIM2; ++i ) {
		double mid = (low+high)/2;
		ll lcnt, rcnt;
		checky(mid, lcnt, rcnt);
		if( lcnt >= half ) high = mid;
		else low = mid;
	}
	return low;
}

bool cmpkx( int i, int j ) {
	double ki = -a[i] / b[i];
	double kj = -a[j] / b[j];
	return dcmp(ki - kj) < 0;
}
bool cmpky( int i, int j ) {
	double ki = -b[i] / a[i];
	double kj = -b[j] / a[j];
	return dcmp(ki - kj) < 0;
}

int main() {
	_w = scanf( "%d", &n );
	for( int i = 0; i < n; ++i )
		_w = scanf( "%lf%lf%lf", a+i, b+i, c+i );
	for( int i = 0; i < n; ++i ) tmp[i] = i;
	sort(tmp, tmp+n, cmpkx);
	for( int i = 0; i < n; ++i ) k[tmp[i]] = i+1;
	double x = solvex();
	for( int i = 0; i < n; ++i ) tmp[i] = i;
	sort(tmp, tmp+n, cmpky);
	for( int i = 0; i < n; ++i ) k[tmp[i]] = i+1;
	double y = solvey();
	printf( "%.15lf %.15lf\n", x, y );
	return 0;
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n;
	cin >> n;
	ll a[n], b[n];
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];
	ll dif[n];
	REP(i, n) dif[i] = a[i]-b[i];
	sort(dif, dif+n);
	ll need = 0, ans = 0;
	REP(i, n){
		if(dif[i] < 0){
			need -= dif[i];
			ans++;
		}
	}
	REP(i, n){
		if(need > 0 && dif[n-1-i] > 0){
			need -= dif[n-1-i];
			ans++;
		}
	}
	if(need > 0) cout << -1 << endl;
	else cout << ans << endl;
} 

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;cin>>n;
    if(n==2){cout<<1<<endl;return 0;}
    int ans=2;
    for(ll i=2;i*i<=n;i++){
        if((n-1)%i==0)ans+=(i*i==n-1)?1:2;
        else if(n%i==0){
            ll x=n;
            while(x%i==0)x/=i;
            if(x%i==1)ans++;
        }
    }cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n,m;
	int sum[1010] ={};
	
	scanf("%d%d",&n,&m);
	
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		
		sum[a-1]++;
		sum[b-1]--;
	}
	
	int ans=0;
	
	for(int i=0;i<n;i++){
 		sum[i+1] += sum[i];
		ans += !!sum[i] * 2;
	}
	
	printf("%d\n",ans+(n+1));
	
	return 0;
}

Measured memory_bytes: 2752
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <unordered_map>
#include <assert.h>
using namespace std;

#define ran(i, a, b) for ((i) = (a); (i) < (b); (i)++)
#define rep(i, a) ran ((i), 0, (a))
#define rep1(i, a) ran ((i), 1, (a)+1)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
#define _0 first
#define _1 second
#define _pb(x) push_back(x)
#define _mp(x, y) make_pair(x, y)
#if defined(SHIROKO1_LOCAL) && !defined(NDEBUG)
#define DEBUG(...) fprintf(stderr, "[DEBUG] " __VA_ARGS__)
#else
#define DEBUG(...) ((void)0)
#endif

static vii Es[100100];
static ll kdist[100100];
static int N;

static void dfs(int i, int p = -1, ll d = 0)
{
	DEBUG("%i --> %i\n", p, i);
	assert(!kdist[i]);
	kdist[i] = d;
	for (ii e : Es[i]) if (e._0 != p) {
		dfs(e._0, i, d + e._1);
	}
}

int main()
{
	int q;
	int i;
	cin >> N;
	rep (i, N-1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		Es[a]._pb(_mp(b, c));
		Es[b]._pb(_mp(a, c));
	}
	cin >> q >> i;
	dfs(i-1);
	while (q--) {
		int a, b;
		cin >> a>> b;
		a--;
		b--;
		cout << kdist[a] + kdist[b] << endl;
	}
	return 0;
}


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

int main(){
    string s;
    int k;
    cin >> s >> k;
    int c = 1;
    for(int i = 0; i < k; i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<string.h>
using namespace std;
//const int sss[10] = { 0, 6, 5, 4, 3, 2, 1 };
struct DICE
{
	int f[8];
};
DICE dice;

int  ch(char a)
{
	int s[60];
	for (int i = 1; i < 7; i++)
	{
		s[i] = dice.f[i];
	}
		int k = a;
	switch (k)
	{
	case 78://N
		dice.f[1] = s[2];
		dice.f[2] = s[6];
		dice.f[6] = s[5];
		dice.f[5] = s[1];
		break;
	case 69:
		dice.f[1] = s[4];
		dice.f[4] = s[6];
		dice.f[6] = s[3];
		dice.f[3] = s[1];
		break;
	case 83://S
		dice.f[2] = s[1];
		dice.f[1] = s[5];
		dice.f[5] = s[6];
		dice.f[6] = s[2];
		break;
	case 87:
		dice.f[4] = s[1];
		dice.f[1] = s[3];
		dice.f[3] = s[6];
		dice.f[6] = s[4];
		break;
	}
	return 0;
}
int ch2(int ue,int mae)
{
	int x;
	for (int i = 1; i < 7; i++)
		if (dice.f[i] == ue)
		{
			x = i;
			break;
		}
	switch (x)
	{
	case 1:break;
	case 2:ch('N');
		break;
	case 3:ch('W');
		break;
	case 4:ch('E');
		break;
	case 5:ch('S');
		break;
	case 6:ch('N');ch('N');
		break;
	}
	for (int i = 1; i < 7; i++)
		if (dice.f[i] == mae)
		{
		x = i;
		break;
		}

	switch (x)
	{
	case 2:
		return dice.f[3];
		break;
	case 3:
		return dice.f[5];
		break;
	case 4:
		return dice.f[2];
		break;
	case 5:
		return dice.f[4];
		break;
	}
}
int main()
{
	
	for (int i = 1; i < 7; i++)cin >> dice.f[i];
/*	char d[10000];
	cin >> d;
	int z = strlen(d);
	for (int i = 0; i <z; i++)
	{
		int a=ch(d[i]);
	}
	cout << dice.f[1]<<endl;
	*/
	
	int num;
	cin >> num;
	while (num--)
	{
		int w, e;
		cin >> w >> e;
		cout<<ch2(w, e)<<endl;
	}
}

Measured memory_bytes: 1164
#include<stdio.h>
int main(){
  int ans=1,min,i,n,a[200010];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  min=a[0];
  for(i=1;i<n;i++){
    if(a[i]<min){
      ans++;
      min=a[i];
    }
  }
  printf("%d\n",ans);
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n, k;
	cin >> n >> k;

	int a[n];
	rep(i, n) cin >> a[i];

	bool dp[k+1];
	// dp[i]:石が残りi個のとき、先手が勝てるか
	rep(i, k+1) dp[i] = false;

	for(int i = 1; i <= k; i++){
		for(int j = 0; j < n; j++){
			if(i >= a[j]){
				dp[i] |= !dp[i-a[j]];
			}
		}
	}

	cout << (dp[k] ? "First" : "Second") << endl;
}


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

int main() {
  // ここにプログラムを追記
  int N,K;
  cin >> N >> K;

  int n=0;
  int x,sum=0;
  while(n<N){
   cin >> x;
    if(x <= K-x){
      sum += x*2;
    }else if(x > K-x){
      sum += (K-x)*2;
    }
    n++;
  }
  
  cout << sum << endl;
  
}

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

using namespace std;

int main(){
    int d,n;
    cin>>d>>n;
    int hoge=pow(100,d);
    if(n==100) n=101;
    
    cout<<hoge*n<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn=1e6+10;
const LL mod=1e4+7;
const double pi=acos(-1.0);
inline LL read()
{
	LL X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

int main()
{
    int n,k;
    cin>>n>>k;
   // printf("%d %d\n",n,k);
    priority_queue<int,vector<int>,greater<int> > q;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        q.push(x);
    }
    //printf("%d\n",q.size());
    int tot=0;
    int res=0;
    while(!q.empty()){
        int pre=q.top();
        q.pop();
      //  printf("%d\n",pre);
        res+=pre;
        tot++;
        if(tot>=k){
            break;
        }
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include <set>
#include<map>
#include <unordered_map>
#include <vector>

using namespace std;
const int N = 3e5+10;
typedef long long ll;
typedef  pair<ll,ll>PII;


int n;
string s1,s2,ans;

int a[N];
int d[N];
int pos[N];

int main(){

    cin>>n;
    int ans=0,k=1;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]==k){
            k++;
            ans++;
        }
    }
    if(ans==0) cout<<-1;
    else cout<<n-ans;

}


Measured memory_bytes: 1024
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

solve :: VU.Vector Int -> Int -> Int
solve xs k
    | VU.length xs < k = 10^9 
    | i >= 0 = min (dist + (abs $ 0 - i)) (solve (VU.tail xs) k)
    | j <= 0 = min (dist + (abs $ 0 - j)) (solve (VU.tail xs) k)
    | otherwise = min (dist + min (abs $ 0 - i) (abs $ 0 - j)) (solve (VU.tail xs) k)
    where
        grids = VU.take k xs
        i = grids VU.! 0
        j = grids VU.! (k-1) 
        dist = abs $ i - j 

main = do
    [n,k] <- map read . words <$> getLine
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    print $ solve xs k

Measured memory_bytes: 3452
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();  //配列aの長さ
		int arrayB [] = new int[n-1];  //配列Bの宣言

		//配列Bの入力
		for(int i=0 ; i<n-1 ; i++) {
			arrayB[i] = sc.nextInt();
		}

		int total = 0;  //配列Aの要素の総和

		for(int i=0 ; i<n ; i++) { //配列Aの要素数分回す
			if(i==0) {  //0番目と最後はそれぞれ配列Bの数字をそのまま足す
				total += arrayB[i];
			}
			else if(i==n-1) {
				total += arrayB[n-2];
			}
			else {  //途中の要素は1つ前の要素と比べて小さい方を足す
				total += Math.min(arrayB[i-1], arrayB[i]);
			}
		}
		System.out.print(total);
		sc.close();
	}
}

Measured memory_bytes: 21972
use std::cmp::Ordering;
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();

    println!(
        "a {} b",
        match a.cmp(&b) {
            Ordering::Less => "<",
            Ordering::Greater => ">",
            Ordering::Equal => "==",
        }
    );
}


Measured memory_bytes: 5028
N = int(input())
A = [int(i)-1 for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
rslt = B[A[0]]
for i in range(1, N):
    rslt += B[A[i]]
    if A[i-1] + 1 == A[i]:
        rslt += C[A[i]-1]
print(rslt)

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int n,m,p;
int arr[7][7][7];


bool ok(){
  rep(i,n)rep(j,n)rep(k,n){
    if(!arr[i][j][k]) continue;
    for(int x=-1;x<=1;++x)
      for(int y=-1;y<=1;++y)
        for(int z=-1;z<=1;++z){
          if((x|y|z)==0) continue;
          int cnt=0;
          int cx=i,cy=j,cz=k;
          while(true){
            if(arr[i][j][k]==arr[cx][cy][cz]) ++cnt;
            else break;
            cx+=x;
            cy+=y;
            cz+=z;
            if(min(cx,min(cy,cz))<0 || max(cx,max(cy,cz))>=n) break;
          }
          if(cnt>=m) return true;
        }
  }
  return false;
}

void solve(){
  int x[p],y[p];
  rep(i,p) cin >> x[i] >> y[i];
  memset(arr,0,sizeof(arr));
  
  rep(i,p){
    int cx=x[i]-1,cy=y[i]-1;
    int z=n-1;
    while(z>=0){
      if(arr[cx][cy][z]) break;
      --z;
    }
    ++z;
    arr[cx][cy][z]=i%2+1;
    if(ok()){
      cout << (i%2==0?"Black ":"White ") << i+1 << endl;
      return;
    }
  }
  
  cout << "Draw" << endl;
}

int main(int argc, char *argv[])
{
  while(cin >> n >> m >> p && n|m|p) solve();
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int N,ans;
    int A[20],B[20],C[20];

    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    REP(i,N){
        cin >> B[i];
    }
    REP(i,N-1){
        cin >> C[i];
    }
    ans=0;

    REP(i,N){
        ans += B[A[i]-1];
        if(i < N-1 && A[i+1] == A[i]+1){
            ans+=C[A[i]-1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll dp[5005][5005][2];
ll tmp[5005][2];
vector<int> G[5005];
ll comb[5005];
int siz[5005];

int dfs(int v,int p){
	int val=1;
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i];
		if(nv==p)continue;
		val+=dfs(G[v][i],v);
	}
	return siz[v]=val;
}

void solve(int v,int p){
	dp[v][1][0]=1;
	int cnt=1;
	for(int lo=0;lo<G[v].size();lo++){
		int nv=G[v][lo];
		if(nv==p)continue;
		solve(nv,v);
		int sz=siz[nv];
		for(int i=0;i<=cnt+sz;i++){
			for(int j=0;j<2;j++){
				tmp[i][j]=0;
			}
		}
		for(int i=0;i<=cnt;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<=sz;k++){
					for(int l=0;l<2;l++){
						tmp[i+k][(j+l)%2]+=dp[v][i][j]*dp[nv][k][l]%MOD;
						tmp[i+k][(j+l)%2]%=MOD;
						if(k%2==0){
							tmp[i][(j+l+1)%2]+=(dp[v][i][j]*dp[nv][k][l]%MOD)*comb[k]%MOD;
							tmp[i][(j+l+1)%2]%=MOD;
						}
					}
				}
			}
		}
		for(int i=0;i<=cnt+sz;i++){
			for(int j=0;j<2;j++){
				dp[v][i][j]=tmp[i][j];
			}
		}
		cnt+=sz;
	}
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	comb[2]=1;
	for(int i=4;i<=n;i+=2){
		comb[i]=(ll)comb[i-2]*(i-1)%MOD;
	}
	dfs(0,-1);
	solve(0,-1);
	ll ans=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<2;j++){
			ll val=dp[0][i][j];
			val=val*comb[i]%MOD;
			if(j==0){
				ans+=val;
			}else{
				ans-=val;
			}
			ans+=MOD;
			ans%=MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 391296
#include<stdio.h>

int main(void){
    char ch;
    
    while(1){
        scanf("%c",&ch);
        if(ch=='\n'){
            printf("%c",ch);
            break;
        }else{
            if('a'<=ch&&ch<='z'){
                ch-='a'-'A';
                printf("%c",ch);
            }else if('A'<=ch&&ch<='Z'){
                ch+='a'-'A';
                printf("%c",ch);
            }else{
                printf("%c",ch);
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll MINF = LLONG_MIN;
const int INT_INF = INT_MAX;

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s.at(i) == t.at(i))
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256