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

using namespace std;
typedef long long ll;

int N;
int L[8];
int A, B, C;

int dfs(int i, int a, int b, int c) {
	if(i == N) {
		if(!a || !b || !c) return 1e9;
		return abs(a - A) + abs(b - B) + abs(c - C);
	}
	
	int val = 1e9;
	val = min(val, dfs(i+1, a + L[i], b, c) + (a?10:0));
	val = min(val, dfs(i+1, a, b + L[i], c) + (b?10:0));
	val = min(val, dfs(i+1, a, b, c + L[i]) + (c?10:0));
	val = min(val, dfs(i+1, a, b, c));
	
	return val;
}

int main() {
	cin >> N >> A >> B >> C;
	
	for(int i = 0; i < N; i++) cin >> L[i];
	int val = dfs(0, 0, 0, 0);
	cout << val;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>

#define ll long long
#define endl \'n'
using namespace std;

const int INF = 0x3f3f3f3f;
int a[10];

bool isok(int n)
{
    while(n)
    {
        if(a[n%10])
            return 0;
        n/=10;
    }
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, in;
    cin >> n >> k;
    for(int i=0; i<k; i++)
    {
        cin >> in;
        a[in]=1;
    }
    for(;;)
    {
        if(isok(n))
        {
            cout << n;
            return 0;
        }
        n++;
    }
}



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

typedef long long ll;

int main () {
	int N;
	cin >> N;
	switch (N%10) {
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			cout << "hon" << endl;
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			cout << "pon" << endl;
			break;
		case 3:
			cout << "bon" << endl;
			break;
	}
	return 0;
}


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

signed main(void)
{
	int a, b, c, sum;
	cin >> a >> b >> c;

	sum = 0;
	for (int i = 0; i < 100; i++)
	{
		if ((b * i + c) % a == 0)
		{
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using GraphI = vector<vector<int>>;
using GraphC = vector<vector<char>>;
using pint = pair<int, int>;

int main() {
  string S;
  cin >> S;
  int n = S.size();
  sort(S.begin(), S.end());
  char p = S[0];
  rep(i, 1, n) {
    if (p == S[i]) {
      cout << "no" << endl;
      return 0;
    }
    p = S[i];
  }

  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>

using namespace std;

#define long long long
#define ft(i, a, b) for (int i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (int i = (long)a ; i >= (long)b ; i--)

const int MAXN = 1e5 + 5;
const long oo = 1e15;

long ans , n , m;
long dp[MAXN] , w[MAXN] , v[MAXN];

void Solve() {
    ft(i , 1 , n) {
        fd(j , m , w[i]) {
            dp[j] = max(dp[j] , dp[j - w[i]] + v[i]);
            ans = max(ans , dp[j]);
        }
    }
    cout << ans;
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> n >> m;
    ft(i , 1 , n) cin >> w[i] >> v[i];
}

int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	string YYMM="";
	YYMM+=s[2];
	YYMM+=s[3];
	string MMYY = "";
	MMYY+=s[0];
	MMYY+=s[1];
//	cout<<"month1:"<<MMYY<<","<<"month2:"<<YYMM<<endl;a
	if((YYMM>"00"&&YYMM<="12")&&(MMYY>"00a"&&MMYY<="12"))
	{
		cout<<"AMBIGUOUS\n";
		return 0;
	}
	if(YYMM>"00"&&YYMM<="12")
	{
		cout<<"YYMM\n";
		return 0;
	}
	if(MMYY>"00"&&MMYY<="12")
	{
		cout<<"MMYY\n";
		return 0;
	}
	cout<<"NA\n";
	return 0;
}

Measured memory_bytes: 256
# Problem: https://atcoder.jp/contests/abc091/tasks/abc091_b
# Python 2nd Try

import sys
from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(blueCard, redCard):
    result = 0
    cardDict = defaultdict(int)
    for j in range(0, len(blueCard), +1):
        cardDict[blueCard[j]] += 1
    for j in range(0, len(redCard), +1):
        cardDict[redCard[j]] -= 1
    # print("{}".format(list(cardDict.keys())))
    cardList = list(cardDict.keys())
    for j in range(0, len(cardList), +1):
        if result < cardDict[cardList[j]]:
            result = cardDict[cardList[j]]

    # algorithm
    return result


if __name__ == "__main__":
    N = II()
    blueCard = list()
    for _ in range(0, N, +1):
        strings = sys.stdin.readline().strip('\n')
        blueCard.append(strings)
    M = II()
    redCard = list()
    for _ in range(0, M, +1):
        strings = sys.stdin.readline().strip('\n')
        redCard.append(strings)
#    print("Blue:{}".format(blueCard))
#    print("Red {}".format(redCard))
    print("{}".format(solver(blueCard, redCard)))


Measured memory_bytes: 9420
import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T scan(T=long)(){return readln.chomp.to!T;}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);}
alias Queue=DList;auto enq(T)(ref Queue!T q,T e){q.insertBack(e);}T deq(T)(ref Queue!T q){T e=q.front;q.removeFront;return e;} 
alias Stack=SList;auto push(T)(ref Stack!T s,T e){s.insert(e);}T pop(T)(ref Stack!T s){T e=s.front;s.removeFront;return e;} 
struct UnionFind(T){T[T]u;ulong[T] rank;@property{bool inc(T e){return e in u;}auto size(){return u.keys.length;}auto dup(){T[] child=u.keys;T[] parent=u.values;auto res=UnionFind!T(child);child.each!(e=>res.add(e));size.iota.each!(i=>res.unite(child[i],parent[i]));return res;}}this(T e){e.add;}this(T[] es){es.each!(e=>e.add);}auto add(T a,T b=a){assert(b.inc);u[a]=a;rank[a];if(a!=b)unite(a,b);}auto find(T e){if(u[e]==e)return e;return u[e]=find(u[e]);}auto same(T a,T b){return a.find==b.find;}auto unite(T a,T b){a=a.find;b=b.find;if(a==b)return;if(rank[a]<rank[b])u[a]=b;else{u[b]=a;if(rank[a]==rank[b])rank[a]++;}}}
struct PriorityQueue(T,alias less="a<b"){BinaryHeap!(T[],less) heap;@property{bool empty(){return heap.empty;}auto length(){return heap.length;}auto dup(){return PriorityQueue!(T,less)(array);}T[] array(){T[] res;auto tp=heap.dup;foreach(i;0..length){res~=tp.front;tp.removeFront;}return res;}void push(T e){heap.insert(e);}void push(T[] es){es.each!(e=>heap.insert(e));}}T look(){return heap.front;}T pop(){T tp=look;heap.removeFront;return tp;}this(T e){ heap=heapify!(less,T[])([e]);}   this(T[] e){ heap=heapify!(less,T[])(e);}}
//END OF TEMPLATE

void main(){
    ulong n,k;
    scan(n,k);
    ulong sum;
    foreach(l;k..n+2){
        sum=(sum+l*(n-l+1)+1)%(10^^9+7);
    }   
    sum.writeln;
}


Measured memory_bytes: 3664
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int length;
char buf[101];
bool is_mu[100];

bool is_musei_siin(char ch){

	switch(ch){
	case 'k':
	case 's':
	case 't':
	case 'h':
	case 'p':return true;
	default:break;
	}
	return false;
}

void func(){

	for(length = 0; buf[length] != '\0'; length++){
		is_mu[length] = false;
	}

	bool is_pre_boin_mu = false,pre_musei_siin,next_musei_siin;
	char next_boin;
	int next_boin_loc;

	for(int i = 0; i < length; i++){
		if(buf[i] == 'i' || buf[i] == 'u'){

			if(is_pre_boin_mu){
				is_pre_boin_mu = false;
				continue;
			}

			pre_musei_siin = false;
			next_musei_siin = false;
			if(i > 0 && is_musei_siin(buf[i-1]) == true){
				pre_musei_siin = true;
			}else if(i > 1 && buf[i-1] == 'y' && is_musei_siin(buf[i-2]) == true){
				pre_musei_siin = true;
			}
			if(!pre_musei_siin)continue;

			if(buf[i+1] == '\0' || is_musei_siin(buf[i+1]) == true){
				next_musei_siin = true;
			}
			if(next_musei_siin){
				is_mu[i] = true;
				is_pre_boin_mu = true;
			}

		}else if(buf[i] == 'a' || buf[i] == 'o'){
			if(is_pre_boin_mu){
				is_pre_boin_mu = false;
				continue;
			}

			pre_musei_siin = false;
			next_musei_siin = false;
			if(i > 0 && is_musei_siin(buf[i-1]) == true){
				pre_musei_siin = true;
			}else if(i > 1 && buf[i-1] == 'y' && is_musei_siin(buf[i-2]) == true){
				pre_musei_siin = true;
			}
			if(!pre_musei_siin)continue;

			if(buf[i+1] == '\0' || is_musei_siin(buf[i+1]) == true){
				next_musei_siin = true;
			}

			if(!next_musei_siin)continue;

			next_boin = '@';

			//次の母音を探す
			for(int k = i+1; buf[k] != '\0'; k++){
				if(buf[k] == 'a' || buf[k] == 'i' || buf[k] == 'u' || buf[k] == 'e' || buf[k] == 'o'){
					next_boin = buf[k];
					next_boin_loc = k;
					break;
				}
			}

			if(next_boin == '@' || buf[i] != next_boin)continue; //次に母音がない、または異なる母音ならSKIP

			if((next_boin_loc == i+2) || (buf[i+2] == 'y' && next_boin_loc == i+3)){
				is_mu[i] = true;
				is_pre_boin_mu = true;
			}
		}else if(buf[i] == 'e'){
			is_pre_boin_mu = false;
		}
	}

	for(int i = 0; i < length; i++){
		if(is_mu[i]){
			printf("(%c)",buf[i]);
		}else{
			printf("%c",buf[i]);
		}
	}
	printf("\n");
}

int main(){

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		func();
	}

	return 0;
}



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

long long MOD = 1e9 + 7;

long long modPow(long long x, long long a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    long long t = modPow(x, a / 2);
    return (t * t) % MOD;
}

long long modInv(long long x) {
    return modPow(x, MOD - 2);
}

long long modPerm(long long n, long long k) {
    long long ret = 1;
    for (long long i = 0; i < k; i++) {
        ret = (ret * (n - i)) % MOD;
    }
    return ret;
}

int main(){
    long long x, y;
    cin >> x >> y;
    int ans = 0;
    if((x + y) % 3 == 0){
        //  m: (i+1, j+2) の移動回数, n: (i+2, j+1) の移動回数
        // m + n = (x + y) / 3
        // m - n = -x + y
        long long m = (-x + 2*y) / 3, n = (2*x - y) / 3;
        if(m >= 0 && n >= 0) {
            long long tmp = (modPerm(m, m) * modPerm(n, n)) % MOD;
            ans = (modPerm(m+n, m+n) * modInv(tmp)) % MOD;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define gc getchar()
#define ll long long
#define int long long
#define ri register int
#define rc register char
#define rb register bool
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
using namespace std;
    
const int N=200000+10,inf=1e18;
int n,q,pre,nw,tag[N<<2];
ll tr1[N<<2],tr2[N<<2];
 
il int read()
{
    rc ch=gc;ri x=0;rb y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
il void pushdown(int nw) 
{
    if (!tag[nw])return;
    tag[ls(nw)] += tag[nw];
    tag[rs(nw)] += tag[nw];
    tr1[ls(nw)] += tag[nw];
    tr2[ls(nw)] += tag[nw];
    tr1[rs(nw)] += tag[nw];
    tr2[rs(nw)] += tag[nw];
    tag[nw] = 0;
}
void modify(ri nw,ri l,ri r,ri to,ll dat)
{
	if(l==r){tr1[nw]=min(tr1[nw],dat-to),tr2[nw]=min(tr2[nw],dat+to);return;}
	pushdown(nw);ri mid=(l+r)>>1;to<=mid?modify(nw<<1,l,mid,to,dat):modify(nw<<1|1,mid+1,r,to,dat);
	tr1[nw]=min(tr1[nw<<1],tr1[nw<<1|1]);tr2[nw]=min(tr2[nw<<1],tr2[nw<<1|1]);
}
ll query1(ri nw,ri l,ri r,ri to_l,ri to_r)
{
	if(to_l<=l && r<=to_r)return tr1[nw];
	pushdown(nw);ri mid=(l+r)>>1;ll ret=inf;
	if(to_l<=mid)ret=query1(nw<<1,l,mid,to_l,to_r);
	if(mid<to_r)ret=min(ret,query1(nw<<1|1,mid+1,r,to_l,to_r));
	return ret;
}
ll query2(ri nw,ri l,ri r,ri to_l,ri to_r)
{
	if(to_l<=l && r<=to_r)return tr2[nw];
	pushdown(nw);ri mid=(l+r)>>1;ll ret=inf;
	if(to_l<=mid)ret=query2(nw<<1,l,mid,to_l,to_r);
	if(mid<to_r)ret=min(ret,query2(nw<<1|1,mid+1,r,to_l,to_r));
	return ret;
}
ll query(ri nw,ri l,ri r)
{
	if(l==r)return tr1[nw]+l;
	pushdown(nw);ri mid=(l+r)>>1;return min(query(nw<<1,l,mid),query(nw<<1|1,mid+1,r));
}

signed main() 
{
//	freopen("2558.in","r",stdin);
    n = read(), q = read(), pre = read();memset(tr1, 63, sizeof(tr1));memset(tr2, 63, sizeof(tr2));modify(1,1,n,read(),0);
    while(q--)
	{
        int nw=read();ll dat=min(query1(1,1,n,1,nw)+nw,query2(1,1,n,nw,n)-nw);
        tag[1]+=abs(nw-pre);tr1[1]+=abs(nw-pre);tr2[1]+=abs(nw-pre);modify(1,1,n,pre,dat);
        pre=nw;
    }
    printf("%lld\n",query(1,1,n));
	return 0;
}

Measured memory_bytes: 18816
#include <stdio.h>
int main(void) {
    int height,width,i,j;
    while (1) {
        scanf("%d %d",&height,&width);
        if (height==0&&width==0) break;
        for (i=0; i<height; i++) {
            for (j=0; j<width; j++) {
                if ((i+j)%2==0) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

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

int main() {
  int N, A, B;
  cin >> N;
  A = 0;
  B = 0;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++)
      cin >> vec.at(i);
    
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end()); // 大きい順に並んでいる
  
    for (int i = 0; i < N; i++){
      
      if (i%2 == 0) {// Aliceがとるぶん
        A += vec.at(i);
      }
      else
        B += vec.at(i);
    }  
  
  cout << A-B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int d, t, s;

    cin >> d >> t >> s;
    if (t*s>=d)
        cout << "Yes";
    else cout << "No";
}

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

int main() {
  int A,B;
  cin >> A >> B;
  if (A !=1 && B !=1){
   if (A<B){
    cout << "Bob" << endl;
   }
   else if(A>B){
    cout << "Alice" << endl;
   }
   else {
     cout << "Draw" << endl;
   }
  }
  else if (A ==1 && B ==1){
    cout << "Draw" << endl;
   }
  else if (A ==1 && B !=1){
    cout << "Alice" << endl;
   }
  else {
    cout << "Bob" << endl;
  }
 
}

Measured memory_bytes: 256
import sys
n, m = map(int, input().split())
a_list = [input() for _ in range(n)]
b_list = [input() for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        new_list = [a_list[k][j:j+m] for k in range(i,i+m)]
        if(new_list == b_list):
            print('Yes')
            sys.exit()
print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
#define ull unsigned long long
#define ALL(v) ((v).begin()), ((v).end())
#define INCREASING(v) sort(ALL(v))
#define DECREASING(v) INCREASING(v), reverse(ALL(v))
#define SZ(v)   ((int)((v).size()))
#define LP(c,x,n)  for(int c=x;c<n;c++)
#define LO(c,n,x)  for(int c=n;c>=x;c--)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define PI ( 2 * acos(0.0))
#define EPS 1e-8
#define INF 1.0/0.0
#define Yala_Besor3a ios_base::sync_with_stdio(0),ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ReadFile freopen("delivery.in","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
using namespace std;
const int OO = 0x3f3f3f3f,NegOO= -1*OO,N =1e5+5,mod =998244353 ;
int n;
int A[N][3];
int dp[N][3];
int solve(int i,int pre)
{
    if(i==n)return 0;
    int &rf=dp[i][pre];
    if(~rf)return rf;
    LP(c,0,3)
    {
        if(i==0)rf=max(rf,A[i][c]+solve(i+1,c));
        if(i!=0&&c!=pre)rf=max(rf,A[i][c]+solve(i+1,c));
    }
    return rf;
}
int main()
{
    cin>>n;
    LP(c,0,n)cin>>A[c][0]>>A[c][1]>>A[c][2];
    memset(dp,-1, sizeof(dp));
    cout<<solve(0,0)<<endl;
    return 0;
}

Measured memory_bytes: 10368
n , m , l = map( int,input().split())

A = [[0]*m]*n
B = [[0]*l]*m
#C = [[0]*l]*n エラーが起きてしまう
C = [[ 0 for x in range(l) ] for y in range(n)]

a = [[1, 2, 3], [4, 5, 6]]
a[1][1] = 7

for i in range(n):
    A[i] =  list( map( int,input().split()) )

for i in range(m):
    B[i] =  list( map( int,input().split()) )

for ni in range(n):
    
    for li in range(l):
        C_count = 0
        for mi in range(m):
            C_count += A[ni][mi] * B[mi][li]
        C[ni][li] = C_count

for a in C:
    print(*a, sep=' ')


Measured memory_bytes: 7072
H_1, M_1, H_2, M_2, K = map(int, input().split())

oki = (H_2 - H_1) * 60

if M_1 <= M_2:
  oki += M_2 - M_1
else:
  oki -= M_1 - M_2
  
print(oki-K)

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

using namespace std;

int main() {
	string abc = "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba";
	abc += abc;
	int n;
	string a;
	int number[105] = {0};
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> number[i];
		}
		cin >> a;
		int counter = 0;
		for (int i = 0; i < a.size(); i++) {
			for (int j = 0; j < 52; j++) {
				if (a[i] == abc[j]) {
					cout << abc[j+number[counter]];
				}
			}
			counter++;
			if (counter >= n) {
				counter = 0;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

string str[500];
ll far[500][500],mrk[500][500],n,m;

ll get(ll x,ll y)
{
	if(x>=1 && x<=n && y>=1 && y<=m && str[x][y-1] == '.')
		return 1;
	else
		return 0;
}

queue<pi> pq;

ll check(ll p,ll q)
{

	ll i,j,x,y,ans = 0;

	if(str[p][q-1] == '#')
		return 0;

	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)
		{
			far[i][j] = 1e9;
			mrk[i][j] = 0;
		}

	far[p][q] = 0;
	x = p;
	y = q;

	pq.push(pi(p,q));
	while(!pq.empty())
	{
		p = (pq.front()).ff;
		q = (pq.front()).ss;
		pq.pop();
		
		if(mrk[p][q])
			continue;
		
		ans = max(ans,far[p][q]);

		mrk[p][q] = 1;
		if(get(p+1,q))
		{
			far[p+1][q] = min(far[p+1][q],far[p][q]+1);
			if(far[p+1][q] == far[p][q] + 1)
				pq.push(pi(p+1,q));
		}
		if(get(p-1,q))
		{
			far[p-1][q] = min(far[p-1][q],far[p][q]+1);
			if(far[p-1][q] == far[p][q] + 1)
				pq.push(pi(p-1,q));
		}
		if(get(p,q+1))
		{
			far[p][q+1] = min(far[p][q+1],far[p][q]+1);
			if(far[p][q+1] == far[p][q] + 1)
				pq.push(pi(p,q+1));
		}
		if(get(p,q-1))
		{
			far[p][q-1] = min(far[p][q-1],far[p][q]+1);
			if(far[p][q-1] == far[p][q] + 1)
				pq.push(pi(p,q-1));
		}
	}

	return ans;
}

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

	ll i,j,ans = 0;

	cin >> n >> m;

	for(i=1;i<=n;++i)
	{
		cin >> str[i];
	}

	for(i=1;i<=n;++i)
	{
		for(j=1;j<=m;++j)
			ans = max(ans,check(i,j));
	}

	cout << ans << "\n";
	return 0;
}

	

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	int H, A;
	cin >> H >> A;
	if ((H >= 1 && H <= 10000) && (A >= 1 && A <= 10000))
	{
		if (H % A == 0)
			cout << H / A << endl;
		else
			cout << (H / A )+ 1 << endl;
	}
	else
		cout << "Wrong inputs" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n;
	cin >> n;
    int a[n];
    int b[n];
    int c[n-1];
    int ans=0;
    fr(i,n){
      cin>>a[i];
    }
    fr(i,n){
      cin>>b[i];
      ans+=b[i];
    }
    fr(i,n-1){
      cin>>c[i];
    }
    fr(i,n-1){
      if(a[i+1]==a[i]+1)ans+=c[a[i]-1];
    }
      cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<stdlib.h>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;


int main(void) {
	string s;
	cin >> s;
	if (s[0] == 'Y'&&s[1] == 'A'&&s[2] == 'K'&&s[3] == 'I'&&s.size()>=4) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	

	return 0;
}

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

using namespace std;

int main(void) {
  double a, b, x;
  cin >> a >> b >> x;
  
  double theta = 0.0;
  
  if(a*a*b <= 2.0*x) {
    theta = atan(2.0*(a*a*b - x)/(a*a*a))*180.0/M_PI;
  } else {
    theta = atan(a*b*b/2.0/x)*180.0/M_PI;
  }
  
  printf("%.10lf\n", theta);
  return 0;
}

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


int main(){
    int a,b;
    cin>>a>>b;

    if(a>8 || b>8)cout<<":("<<endl;
    else cout<<"Yay!"<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>

#define INT_MAX 2000000000
#define MOD 1000000007
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vsort(x) sort(x.begin(),x.end())

using int64 = uint64_t;


using namespace std;

int main() {

	int i, j, k;
	string s;
	cin >> s;
	if (s[0] == 'a' | s[0] == 'i' | s[0] == 'u' | s[0] == 'e' | s[0] == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,j,n) for (int i = j; i < (n); ++i)
#define INF 1e+10
#define MAX_V 100000
using namespace std;
typedef long long ll;
using edge = struct 
{
    int to;
    ll cost;
};
vector<edge> tree[MAX_V];
ll depth[MAX_V];

void dfs(int v, int p, ll d){
    depth[v] = d;
    for(auto &e :tree[v]){
        if(e.to == p) continue;
        dfs(e.to,v,d+e.cost);
    }
}

int main() {
    int n;
    cin >> n;
    for (int i=0; i<n-1; ++i) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }
    
    int q,k;
    cin >> q >>k;
    k--;
    dfs(k, -1, 0);

    int x[q],y[q];
    rep(i,q){
        cin>>x[i]>>y[i];
        x[i]--;
        y[i]--;
    }

    rep(i,q){
        cout<<depth[x[i]]+depth[y[i]]<<endl;
    }
}


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

int balls[100005];

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

int main(){
    int N, K, maks = 0, fpb;

    cin >> N >> K;
    for(int i=1; i<=N; i++){
        cin >> balls[i];

        if (balls[i] > maks) maks = balls[i];

        if (i == 1) fpb = balls[i];
        if (i >= 2 && fpb != 1){
            fpb = findFPB(balls[i], fpb);
        }
    }

    if(K > maks){
        cout << "IMPOSSIBLE" << endl;
    } else if(K % fpb == 0){
        cout << "POSSIBLE" << endl;
    } else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 3896
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

struct UnionFind {
    vector<pair<long long, long long>> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(long long N) : par(N) { //最初は全てが根であるとして初期化
        for(long long i = 0; i < N; i++) {
          par[i].first = i;
          par[i].second = 1;
        }
    }

    long long root(long long x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x].first == x) return x;
        return par[x].first = root(par[x].first);
    }

    void unite(long long x, long long y) { // xとyの木を併合
        long long rx = root(x); //xの根をrx
        long long ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if(par[rx].second <= par[ry].second) {
          par[rx].second += par[ry].second;
          par[ry].first = rx;
        } else {
          par[ry].second += par[rx].second;
          par[rx].first = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        }
    }

    bool same(long long x, long long y) { // 2つのデータx, yが属する木が同じならtrueを返す
        long long rx = root(x);
        long long ry = root(y);
        return rx == ry;
    }
};

long long N, M;
pair<long long, long long> p[100000];

int main() {
  cin >> N >> M;
  for(long long i = 0; i < M; i++) {
    cin >> p[i].first >> p[i].second;
    p[i].first--;p[i].second--;
  }

  UnionFind tree(N);

  long long ans[100001] = {0};
  ans[0] = N * (N-1) / 2;

  for(long long i = M - 1; i >= 1; i--) {
    long long s = p[i].first, t = p[i].second;
    if(!tree.same(s, t)) {
      long long rs, rt;
      rs = tree.root(s);
      rt = tree.root(t);
      long long n = tree.par[rs].second * tree.par[rt].second;
      // cout << s << " " << t << endl;
      // cout << rs << " " << rt << " " << n << endl;
      ans[M-i] = ans[M-i-1] - n;
    } else {
      ans[M-i] = ans[M-i-1];
    }
    tree.unite(s, t);
  }

  for(long long i = M-1; i >= 0; i--) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 5248
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = []
    while N > 0:
        N -= 1
        c = N % 26
        ans.append(chr(ord('a')+c))
        N //= 26
    return ''.join(reversed(ans))


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 76952
/*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<int>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=1e5+5;
bool comp(string a,string b)
{
    string ab=a+b;
    string ba=b+a;

    if(ab<ba)
    return 1;
    else
    return 0;
}
int main()
{
      int n;
      scn(n);

      int l;
      scn(l);
      vector<string> s;

      rep(i,0,n)
      {
          string a;
          cin>>a;
          s.pb(a);
      }

      sort(s.begin(),s.end(),comp);

      for(auto it: s)
      cout<<it;
}



Measured memory_bytes: 3668
using System;
using System.Collections.Generic;

namespace ITP1_7_A
{
	class Program
	{
		class Student
		{
			public int M { get; set; } = 0;
			public int F { get; set; } = 0;
			public int R { get; set; } = 0;

			public Student(int m, int f, int r)
			{
				M = m;
				F = f;
				R = r;
			}

			public char Judge()
			{
				if(M == -1 || F == -1) {
					return 'F';
				}

				int total = M + F;

				if(total >= 80) {
					return 'A';
				}

				if(65 <= total && total < 80) {
					return 'B';
				}

				if(50 <= total && total < 65) {
					return 'C';
				}

				if(30 <= total && total < 50) {
					if(R >= 50) {
						return 'C';
					}
					else {
						return 'D';
					}
				}

				return 'F';
			}
		}

		static void Main(string[] args)
		{
			List<Student> students = new List<Student>();

			while(true) {
				string[] vs = Console.ReadLine().Split(' ');
				int m = int.Parse(vs[0]);
				int f = int.Parse(vs[1]);
				int r = int.Parse(vs[2]);

				if(m == -1 && f == -1 && r == -1) {
					break;
				}

				students.Add(new Student(m, f, r));
			}

			foreach(Student student in students) {
				Console.WriteLine(student.Judge());
			}
		}
	}
}



Measured memory_bytes: 15972
#include <iostream>
#include <string>
#include <algorithm>
#define N 1000
using namespace std;
 
int lcs(string S1,string S2){
    int c[N+1][N+1];
    int S1_size = S1.size();
    int S2_size = S2.size();
     
    for(int i=1;i<S1_size;i++) c[i][0] = 0;
    for(int i=1;i<S2_size;i++) c[0][i] = 0;
     
    S1 = ' '+S1;
    S2 = ' '+S2;
     
    int max_lcs=0;
    for(int j=1;j<=S1_size;j++){
        for(int k=1;k<=S2_size;k++){
            if(S1[j]==S2[k]){
                c[j][k] = c[j-1][k-1] + 1;
            }else{
                c[j][k] = max(c[j-1][k],c[j][k-1]);
            }
            max_lcs = max(max_lcs,c[j][k]);
        }
    }
    return max_lcs;
}
 
int main() {
    // your code goes here
    int q;
    string str1,str2;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>str1>>str2;
        cout<<lcs(str1,str2)<<endl;
    }
    return 0;
}

Measured memory_bytes: 7072
//verma_ankit484

#include<bits/stdc++.h>

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const ll mod = (ll) 1e9+7;

using namespace std;

ll n;
vector<ll> vc;

ll dp[100003];

ll rec(ll k) {
  if (dp[k] != -1) return dp[k];
  if (k == 0) return dp[k] = 0;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (k >= vc[i]) {
      ans = ans | !(rec(k-vc[i]));
    }
  }
  return dp[k] = ans;
}

int main() {
  IOS
  #ifdef AV
  freopen("int.txt", "r", stdin);
  #endif
  memset(dp, -1, sizeof(dp));
  ll k;
  cin >> n >> k;
  vc.resize(n);
  for (ll i = 0; i < n; i++) {
    cin >> vc[i];
  }
  ll ans = rec(k);
  ans == 1? cout << "First\n" : cout << "Second\n";
  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,C;cin>>N>>C;
  vector<vector<int>> D(C,vector<int>(C));
  vector<vector<int>> c(N,vector<int>(N));
  for(int i=0;i<C;i++){
    for(int j=0;j<C;j++)cin>>D[i][j];//iは行
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++)cin>>c[i][j];//iは行
  }
  //%3==0の座標で, 現状の色がiいくつあるのか 3*C
  vector<vector<int>> T(3,vector<int>(C,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      T[(i+j)%3][c[i][j]-1]++;
    }
  }
  //各座標グループに対して, この色に変えるなら合計でいくらかかるのか
  vector<vector<int>> S(3,vector<int>(C,0));
  for(int i=0;i<3;i++){
    for(int j=0;j<C;j++){
      for(int k=0;k<C;k++){
        S[i][k]+=D[j][k]*T[i][j];
      }  
    }
  }
  int ans=INT_MAX;
  for(int i=0;i<C;i++){
    for(int j=0;j<C;j++){
      for(int k=0;k<C;k++){
        if(i==j||j==k||k==i)continue;
        int tmp=S[0][i]+S[1][j]+S[2][k];
        if(tmp<ans)ans=tmp;
      }  
    }
  }
  
  cout<<ans;
}

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

using ll = long long;

int A[20], B[20];

int main(){
    int N, M, C;
    cin >> N >> M >> C;
    int ans = 0;
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N; i++) {
        ll sum = 0;
        for (int j = 0; j < M; j++) {
            cin >> A[j];
            sum += A[j]*B[j];
        }
        if (sum > -C) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
char a[30005];
int dp[30001][4];
int last[10][30001];
void sol() {
  int n;
  cin >> n;
  for(int i=1; i<=n; i++) {
    cin >> a[i];
  }
  a[0] = '.';
  a[n+1] = '\0';
  for(int j=0; j<10; j++) {
    for(int i=1; i<=n; i++) {
      if(j == a[i] - 48) {
        last[j][i] = i;
      }
      else {
        last[j][i] = last[j][i-1];
      }
    }
  }
  /*for(int j=0; j<10; j++) {
    for(int i=1; i<=n; i++) {
      cout << j << "," << i << ":";
      cout << last[j][i] << "\n";
    }
  }*/
  for(int i=0; i<=n; i++) {
    dp[i][0] = 1;
  }
  for(int i=1; i<=n; i++) {
    for(int j=0; j<=3; j++) {
      if(j) {
        dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
        int v = last[a[i]-48][i-1];
        if(v > 0) {
          dp[i][j] -= dp[v-1][j-1];
        }
        
      }
      //cout << i << "," << j << ":";
      //cout << dp[i][j] << "\n";
    }
  }
  cout << dp[n][3];
  
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


Measured memory_bytes: 3584
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

K,N = imn()
A = iln()

max = 0
max_index = 0
for i in range(1, N):
    diff = abs(A[i]) - abs(A[i-1]) 
    if max < diff:
        max = diff
        max_index = i
diff = A[0] + (K-A[-1])
if max < diff:
    max = diff
    max_index = 0

if max_index == 0:
    print(A[-1] - A[0])
else:
    print(A[-1]-A[0]-max+diff)


     

Measured memory_bytes: 27020
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void Process(int n, vector<vi>& g, vi& color, vi& pot, int v, int d, int c) {
  vector<ii> q = {make_pair(v, d)};
  for (int i = 0; i < q.size(); ++i) {
    int at = q[i].first;
    int curPot = q[i].second;
    if (curPot <= pot[at]) continue;
    if (color[at] == 0) color[at] = c;
    pot[at] = curPot;
    if (curPot == 0) continue;
    for (int to : g[at]) q.push_back(make_pair(to, curPot - 1));
  }
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<vi> g(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int q;
  cin >> q;
  vi v(q), d(q), c(q);
  for (int i = 0; i < q; ++i) {
    cin >> v[i] >> d[i] >> c[i];
    v[i]--;
  }
  vi color(n), dist(n, -1);
  for (int i = q - 1; i >= 0; i--) Process(n, g, color, dist, v[i], d[i], c[i]);
  for (int i = 0; i < n; ++i) cout << color[i] << endl;
  return 0;
}


Measured memory_bytes: 14680
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
typedef long double ld;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int a[500010],n,b[500010],c[500010];
LL ans;
int main(){
	scanf("%d",&n);
	FOR(i,1,n) getint(a[i]);
	FOR(i,1,n) getint(b[i]);
	FOR(i,1,n) getint(c[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	FOR(i,1,n){
		int l=lower_bound(a+1,a+n+1,b[i])-a-1;
		int r=n-(upper_bound(c+1,c+n+1,b[i])-c)+1;
		ans+=(LL)l*r;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2944
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var list = myconv(input[1],4);
  var get = 1;
  var output = 0;
  for(var i = 0; i < N; i++){
    if(list[i] == get){
       get++;
    }else{
      output++;
    }
  }
  if(output == N){
     myout("-1");
  }else{
    myout(output);
  }
}

Main(myin());

Measured memory_bytes: 22244
#include <cstdio>
#include <iostream>
#define M 50200

using namespace std;

int main() {

	int n, min, max, s[M];
	bool x[M];

	for(int i=2; i<=M; i++) {
		x[i]=false;
	}
	for(int i=2; i<224; i++) {
		if(x[i])
			continue;
		for(int j=i*2; j<M; j+=i) {
			if(!x[j])
				x[j]=true;
		}
	}
	for(int i=2; i<M; i++) {
		s[i]=0;
	}

	s[2]=2;
	for(int i=3; i<M; i+=2) {
		if(!x[i])
			s[i]=i;
	}

	while(scanf("%d", &n)!=EOF) {
		max=0;
		for(int i=3; ; i+=2) {
			if(s[i]>n) {
				max=s[i];
				for(int j=i; j!=0; j--) {
					if(s[j]<n&&s[j]!=0) {
						min=s[j];
						break;
					}
				}
			}
			if(max!=0)
				break;
		}
		cout << min << " " << max << endl;
	}
	

	return 0;

}

Measured memory_bytes: 0
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
B = [(i + 1) + A[i] for i in range(N)]
C = [(i + 1) - A[i] for i in range(N)]
d = defaultdict(int)
for b in B:
    d[b] += 1
ans = 0
for c in C:
    ans += d[c]
print(ans)

Measured memory_bytes: 66168
N,M = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }
E = M.times.map{ gets.split.map(&:to_i) }
E.each do |from,to|
  G[from] << to
end

ACTIVE = Array.new(N + 1)
USED = Array.new(N + 1)

def active?(v); ACTIVE[v]; end
def activate!(v);  ACTIVE[v] = true; end
def inactivate!(v); ACTIVE[v] = false; end
def turn_active!(v); active?(v) ? inactivate(v) : activate!(v); end
def used?(v); USED[v]; end
def use!(v); USED[v] = true; end

def cycle_exists?
  stack = []
  (1 .. N).each do |s|
    next if used?(s)
    
    use!(s)
    stack << s
    
    until stack.empty?
      u = stack.pop
      
      if active?(u)
        inactivate!(u)
        next
      end
      
      activate!(u)
      stack << u
      
      G[u].each do |v|
        if active?(v)
          # found cycle
          cycle = stack.select{|r| active?(r) }.drop_while{|r| r != s}
          return cycle
        elsif !used?(v)
          use!(v)
          stack << v
        end
      end
    end
  end
  return false
end

def smaller_cycle?(cycle)
  stack = nil
  smaller_not_found = cycle.each_with_index.none? do |from, i|
    to = (i + 1 == cycle.size ? cycle[0] : cycle[i + 1])
    to_ = G[from].find{|to_| cycle.include?(to_) && to_ != to }
    stack = [from, to_] if to_
  end
  return false if smaller_not_found
  
  
  ACTIVE.fill(false)
  USED.fill(true)
  cycle.each{|u| USED[u] = false }
  
  use!(stack[0])
  use!(stack[1])
  activate!(stack[0])

  until stack.empty?
    u = stack.pop
    
    if active?(u)
      inactivate!(u)
      next
    else
      activate!(u)
      stack << u
    end
    
    G[u].each do |v|
      if active?(v)
        cycle_ = stack.select{|r| active?(r) }.drop_while{|r| r != v }
        return cycle_
      elsif !used?(v)
        use!(v)
        stack << v
      end
    end
  end
  
end

cycle = cycle_exists?
if !cycle
  puts -1
else
  loop do
    smaller = smaller_cycle?(cycle)
    if smaller  
      cycle = smaller
    else
      break
    end
  end
  puts cycle.size
  puts cycle
end


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

int main()
{
    int n;
    string str;
    char t[100];

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> str;

        for( int j = 0; j < 100; j++ )
            t[j] = '0';        

        int k = 50;
        for( int j = 0; j < str.size(); j++ )
        {
            if( t[k] != str[j] )
                t[k] = str[j];

            if( j + 1 < str.size() && str[j+1] == '-' )
                k++;
            else if( j + 1 < str.size() )
                k--;
            else;

            j += 2;
        }
            
        for( int j = 0; j < 100; j++ )
            if( t[j] != '0' )
                cout << t[j];
        cout << endl;
    }


    return 0;
}



Measured memory_bytes: 3080
import java.util.Scanner;
import java.util.Comparator;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        int[] x = new int[N];
        int[] y = new int[N];
        for(int i=0;i<N;++i){
            x[i]=scan.nextInt();
            y[i]=scan.nextInt();
        }

        for(int i=0;i<N;++i){
            List<Double> thetas = new ArrayList<>();
            for(int j=0;j<N;++j){
                if(i==j)continue;
                thetas.add(Math.atan2(y[j]-y[i], x[j]-x[i]));
            }
            thetas.sort(Comparator.naturalOrder());
            thetas.add(thetas.get(0)+2*Math.PI);
            double ans = 0;
            for(int k=0;k<N-1;++k)ans = Math.max(ans, thetas.get(k+1)-thetas.get(k)-Math.PI);

            System.out.println(ans/(Math.PI*2));
        }
    }
}

Measured memory_bytes: 22212
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void D();

int main()
{
	D();
	fflush(stdout);
	return 0;
}

static void D()
{
	int N;
	getval(N);

	LLONG total = 0;
	std::vector<LLONG> ai(N);
	for (int i = 0; i < N; i++) {
		getval(ai[i]);
		total += ai[i];
	}

	std::sort(ai.begin(), ai.end(), std::greater<LLONG>());
	
	LLONG ans = ai[0];
	int idx = 1, cnt = 0;
	for (int i = 2; i < N; i++) {
		ans += ai[idx];
		cnt++;
		if (cnt == 2) {
			idx++;
			cnt = 0;
		}
	}

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


Measured memory_bytes: 4792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int main(){
	double a, b, c;
	std::cin >> a >> b >> c;
	double theta = c * PI / 180;
	double Csize = sqrt(a * a + b * b - 2 * a * b * cos(theta));
	double h = b * sin(theta);
	double s = a * h / 2;
	printf("%.10lf %.10lf %.10lf\n", s, a + b + Csize, h);
	return 0;
}

Measured memory_bytes: 1240
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('b1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, K = read_int_list()
    res = 0
    while N > 0:
      N //= K
      res += 1
    print(res)

main()


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

int main(){
  int th,ta;
  int ah,aa;
  cin >> th >> ta >> ah >> aa;
  for(int i=0; ; i++){
    if(i%2==0){
      ah = ah - ta;
    } else {
      th = th - aa;
    }
    if(th <= 0 || ah <= 0)break;
  }
  if(th <= 0){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

ll dp[105][105][505];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll W;
    cin >> n >> W;
    vector<ll> w(n), v(n);
    cin >> w[0] >> v[0];
    ll w0 = w[0];
    for(int i = 1; i < n; ++i){
        cin >> w[i] >> v[i];
        w[i] -= w0;
    }
    w[0] = 0;
    ll ans = 0;
    rep(i,n)rep(j,n)rep(k,501){
        if((j+1)*w0 + (k+w[i]) <= W){
            chmax(dp[i+1][j+1][k+w[i]], dp[i][j][k] + v[i]);
            chmax(ans, dp[i+1][j+1][k+w[i]]);
        }
        chmax(dp[i+1][j][k], dp[i][j][k]);
        chmax(ans, dp[i+1][j][k]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 42632