akhauriyash/Code-Regression huggingface dataset:
using System.Collections.Generic;
using System;

public class Cat
{
    public int s { get; set; }
    public int L { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var w = int.Parse(line[0]);
            var q = int.Parse(line[1]);
            if (w == 0 && q == 0) break;
            var d = new Dictionary<int, Cat>();
            var hei = new int[w];
            for (int i = 0; i < q; i++)
            {
                string[] s = Console.ReadLine().Trim().Split(' ');
                switch (s[0])
                {
                    case "s":
                        var cid = int.Parse(s[1]);
                        var cw = int.Parse(s[2]);
                        var spcount = 0;
                        for (int j = 0; j < w; j++)
                        {
                            if (hei[j] == 0)
                            {
                                spcount++;
                                if (spcount == cw)
                                {
                                    d[cid] = new Cat { s = j - cw + 1, L = cw };
                                    for (int k = 0; k < cw; k++)
                                        hei[k + j - cw + 1] = 1;
                                    Console.WriteLine(j - cw + 1);
                                    goto end;
                                }
                            }
                            else spcount = 0;
                        }
                        Console.WriteLine("impossible");
                        end:;
                        break;
                    case "w":
                        cid = int.Parse(s[1]);
                        for (int j = 0; j < d[cid].L; j++)
                            hei[j + d[cid].s] = 0;
                        break;
                }
            }
            Console.WriteLine("END");
        }
    }
}

Measured memory_bytes: 9584
#include<stdio.h>
#include<limits.h>
#include<vector>
#include<algorithm>
#define PB push_back
int S(int x){return x*x;}
int main()
{
	int a,b,r,s,i,j,k;
	while(scanf("%d%d",&a,&b),a)
	{
		std::vector<int>A,B;
		for(i=1;i*i<=a;++i)if(a%i==0)A.PB(i);
		for(i=1;i*i<=b;++i)if(b%i==0)B.PB(i);
		r=INT_MAX;
		for(i=0;i<A.size();++i)for(j=0;j<B.size();++j)
		{
			int c[]={A[i],a/A[i],B[j],b/B[j]};
			std::sort(c,c+4);
			for(s=k=0;k<3;++k)s+=S(c[k]-c[k+1]);
			r=std::min(r,s);
		}
		printf("%d\n",r);
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int n;
    cin >> n;

    int cnt = 1;
    rep(i, n){
        int a;
        cin >> a;


        if(a % 2 == 0) cnt *= 2;
    }

    int ans = pow(3, n) - cnt;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=1010;
//Ford-Fulkerson
struct edge{
    int to,cap,rev;
};

vector<edge>G[MAX];
vector<bool>used(MAX);

void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,(int)G[to].size()});
    G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
    if(v==t)return f;
    used[v]=true;
    for(auto &e:G[v]){
        if(!used[e.to]&&e.cap>0){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow=0;
    while(1){
        for(int i=0;i<MAX;i++)used[i]=0;
        int f=dfs(s,t,inf);
        if(f==0)return flow;
        flow+=f;
    }
}


signed main(){
    ll h,w;cin>>h>>w;
    vector<string>g(h);
    rep(i,h){
        cin>>g[i];
    }
    ll s=0,t=h+w+1;
    ll sx,sy,tx,ty;
    rep(i,h){
        rep(j,w){
            if(g[i][j]=='S'){
                sx=i,sy=j;
                add_edge(0,i+1,inf);
                add_edge(0,h+j+1,inf);
            }
            if(g[i][j]=='T'){
                tx=i,ty=j;
                add_edge(i+1,h+w+1,inf);
                add_edge(j+h+1,h+w+1,inf);
            }
            if(g[i][j]=='o'){
                add_edge(i+1,h+j+1,1);
                add_edge(h+j+1,i+1,1);
            }
        }
    }
    if(sx==tx||sy==ty){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=max_flow(s,t);
    cout<<ans<<endl;
}

Measured memory_bytes: 4608
def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

    ans = T
    end = T
    for ti in t[1:]:
        if end < ti:
            ans += T
        else:
            ans += T - (end - ti)
        end = ti + T
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 26708
#include <iostream>
using namespace std;
using ll = long long int;

int main(){
    ll n;
    cin >> n;
    long long int ans = 0;
    for(ll i = 1; i*i <= n; i++){
        if(n%i == 0 && n/i-1 > 0 && n%(n/i-1)==i){
            ans += n/i-1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int A, B, K;	cin >> A >> B >> K;
	if ((B - A + 1) > K * 2) {
		for (int i = 0; i < K; ++i) {
			cout << A + i << endl;
		}
		for (int i = 0; i < K; ++i) {
			cout << B - (K - 1 - i) << endl;
		}
	}
	else {
		for (int i = A; i <= B; ++i) {
			if (i <= A + K || i >= B - K) {
				cout << i << endl;
			}
		}
	}
	cin >> A;
	return 0;
}

Measured memory_bytes: 256
import sys

line = input()
n = int(line)

word_list = []
line = input()
word_list.append(line)
prefix = line[-1:]
#print("prefix =" + prefix)

ans = "Yes"
for i in range(1, n):
    line = input()

    if line in word_list:
        ans = "No"
    
    word_list.append(line)

    atama = line[:1]
    #print("atama = " + atama)

    if atama != prefix:
        ans = "No"

    prefix = line[-1:]
    #print("prefix =" + prefix)

    if i == 0:
        continue

print(ans)


Measured memory_bytes: 3060
//To all well wishers,I own this code
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;

signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int n;
    cin>>n;
    vector<int> a(n);
    f(i,n)cin>>a[i];
    sort(all(a));
    double ans=a[0];
    for(int i=1;i<n;i++)
    {
        ans=(ans+a[i])/2.0;
    }
    print(ans)
    return 0;
}




Measured memory_bytes: 3780
#include <stdio.h>
#include <string.h>
#define MAX1 100
#define MAX2 200
int main(void)
{
	char s[MAX1], p[MAX1], ss[MAX2]={0};
	scanf("%s", s);
	scanf("%s", p);
	strcat(ss, s);
	strcat(ss, s);
	if(strstr(ss, p) != NULL){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
    return 0;
}

Measured memory_bytes: 532
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,k = LI()
    p = LI()
    for i,x in enumerate(p):
        if x%2 == 0:
            x = x//2+0.5
        else:
            x = x//2+1
        p[i] = x

    nowsum = sum(p[:k])
    ans = nowsum
    for i in range(k,n):
        nowsum = nowsum - p[i-k] + p[i]
        # print(p,lst)
        ans = max(ans,nowsum)
    
    print(ans)
main()            


Measured memory_bytes: 101444
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String ans = "";
    for (int i = 0; i < 3; i++){
      String s = sc.next();
      String ss[] = s.split("");
      ans += ss[i];
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 39140
#include<stdio.h>

int main(){
    int N,K,Q;
    int A[100002],Sc[100002],Sc_cor[100002];
    int i,j;
    scanf("%d %d %d",&N,&K,&Q);
    for(i = 1 ; i <= N ; i++){
        Sc[i] = K;
        Sc_cor[i] = 0;
    }
    for(i = 1 ; i <= Q ; i++){
        scanf("%d", &A[i]);
        Sc_cor[A[i]]++;
    }
    for(i = 1 ; i <= N ; i++){
        if((Sc[i] - (Q - Sc_cor[i]) ) <= 0){
            printf("No\n");
        }else{
            printf("Yes\n");
        }
    }

    
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;

int main() {
   
long long N;
vector<long long> A(1000001);
vector<long long> B(1000001);
cin >>N;

fx(N){
cin>>A.at(x);
if(x>0){
B.at(x)=B.at(x-1)+A.at(x);
}else{
	B.at(x)=A.at(x);
}
}
long long min=10000000000000;
long long MAX=B.at(N-1);
fx(N-1){
	if(abs(MAX-B.at(x)-B.at(x))<min){
		min=abs(MAX-B.at(x)-B.at(x));
	}
	
}

ce(min);

}

Measured memory_bytes: 15872
# 2019/09/16
# 解説のやつ
import sys
input=sys.stdin.readline

n,k,q=map(int,input().split())
res=[k-q]*n

for i in range(q):
    res[int(input())-1]+=1

for e in res:
    print('Yes' if e>0 else 'No')

Measured memory_bytes: 6580
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

namespace {
    class Dice {
    private:
        int n1;
        int n2;
        int n3;
        int n4;
        int n5;
        int n6;
    public:
        Dice(int _n1, int _n2, int _n3, int _n4, int _n5, int _n6):
            n1(_n1), n2(_n2), n3(_n3), n4(_n4), n5(_n5), n6(_n6) {}
        ~Dice() = default;

        int right(int top, int front) const {
            vector<int> f = {top, front};
            vector<int> r = {front, top};

            vector<int> v1{n1, n2, n6, n5, n1};
            if (v1.end() != search(v1.begin(), v1.end(), f.begin(), f.end())) {
                return n3;
            }
            if (v1.end() != search(v1.begin(), v1.end(), r.begin(), r.end())) {
                return n4;
            }


            vector<int> v2{n1, n3, n6, n4, n1};
            if (v2.end() != search(v2.begin(), v2.end(), f.begin(), f.end())) {
                return n5;
            }
            if (v2.end() != search(v2.begin(), v2.end(), r.begin(), r.end())) {
                return n2;
            }

            vector<int> v3{n2, n3, n5, n4, n2};
            if (v3.end() != search(v3.begin(), v3.end(), f.begin(), f.end())) {
                return n1;
            }
            if (v3.end() != search(v3.begin(), v3.end(), r.begin(), r.end())) {
                return n6;
            }
            return -1;
        }

        bool identical(const Dice& other) {
            return other.right(n1,n2) == n3 &&
                   other.right(n5,n6) == n4;
        }
    };
}

int main() {
    int n1,n2,n3,n4,n5,n6;

    cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    Dice d1(n1,n2,n3,n4,n5,n6);

    cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    Dice d2(n1,n2,n3,n4,n5,n6);

    if (d1.identical(d2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
    int n; cin >> n;
    int a[n];
    int tmp;
    int cnt = 0;

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

    bool flag=true;
    while(flag){
        flag = false;
        for(int j=n-1;j>0;j--){
            if(a[j]<a[j-1]){
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = true;
                cnt++;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << a[i];
        if(i!=n-1){
            cout << " ";
        }
    }
    cout << endl << cnt << endl;
}


Measured memory_bytes: 3100
#include<stdio.h>

#define MAX  10001

int C[MAX] = {0};

void countSort(int A[], int B[], int n)
{
	int i;

	for (i = 0; i < n; i++)
	{
		C[A[i]] += 1;
	}
	for (i = 1; i < MAX; i++)
	{
		C[i] += C[i - 1];
	}
	for (i = n - 1; i >= 0; i--)
	{
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}
}

int main()
{
	int A[2000005], B[2000005];
	int n,i;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &A[0] + i);
	}

	countSort(A,B,n);

	printf("%d", B[1]);

	for (i = 2; i <= n; i++)
	{
		printf(" %d", B[i]);
	}
	printf("\n");
    
	return 0;
}


Measured memory_bytes: 18400
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys

sys.setrecursionlimit(210000)
MAX_VAL = 1000000000


def search(idx, books, reqs):
  if max(reqs) <= 0:
    return 0

  if idx >= len(books):
    return MAX_VAL

  cost0 = search(idx + 1, books, reqs)

  reqs = [r - s for r, s in zip(reqs, books[idx][1:])]
  cost1 = search(idx + 1, books, reqs) + books[idx][0]

  return min(cost0, cost1)


def main():
  N, M, X = map(int, input().split())
  books = [list(map(int, input().split())) for _ in range(N)]
  reqs = [X] * M
  cost = search(0, books, reqs)

  if cost < MAX_VAL:
    print(cost)
  else:
    print(-1)


if __name__ == '__main__':
  main()


Measured memory_bytes: 68516
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;

int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<pii,int>> a(m);
  REP(i,m){
    cin >> a[i].first.first >> a[i].first.second;
    a[i].second = i;
  } 
  sort(ALL(a));
  
  vector<pair<int,pii>> ans(m);
  REP(i,m){
    ans[i].second.first = a[i].first.first;
    ans[i].first = a[i].second;
  }
  int b = 1,j = 0;
  for (int i = 0; i < m; i++) {
    if (b == a[i].first.first) {
      ans[i].second.second = j++;
    }else{
      b = a[i].first.first;
      ans[i].second.second = 0;
      j = 1;
    }
  }
  sort(ALL(ans));
  REP(i,m){
    printf("%06d%06d\n",ans[i].second.first,ans[i].second.second+1);
  }
}

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

Measured memory_bytes: 1028
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define int long long
#define MAX 1000000000000000000LL
int inf=100000000000007;
using namespace std;
typedef pair<int,int> P;
string alph="abcdefghijklmnopqrstuvwxyz";
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
    int n; cin>>n;
    string s;
    int al[26][55]={};
    for(int i=0; i<n; i++){
        cin>>s;
        for(int j=0; j<s.length();j++){
            for(int k=0; k<26;k++){
                if(s[j]==alph[k])al[k][i]++;
            }
        }
    }
    for(int i=0;i<26;i++){
        int mini=100;
        for(int j=0; j<n;j++){
            mini=min(mini,al[i][j]);
        }
        for(int j=0; j<mini; j++){
            cout<<alph[i];
        }
    }
    cout<<endl;
    return 0;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;	
  	
    sort(s.begin(), s.end());
  	
    string t;
    cin >> t;
    sort(t.begin(), t.end(), greater<int>());

    if(s < t){
        cout << "Yes"<< endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

long sum(long n, long p = 1000000007)
{
    if (n < 0)
    {
        return 0;
    }
    long ans = n;
    ans *= n + 1;
    ans /= 2;
    ans %= p;
    return ans;
}

int main()
{
    long n, k;
    cin >> n >> k;
    long ans = 0;
    long p = 1000000007;
    for (long i = k; i <= n + 1; i++)
    {
        long max = sum(n) - sum(n - i);
        // cout << sum(i) << endl;
        long min = sum(i - 1);
        ans += max - min + 1;
        // cout << i << " " << ans << endl;
        while (ans < 0)
        {
            ans += p;
        }
        ans %= p;
    }

    // scanf("%d", &x);
    // printf("%d\n", x * x * x);
    cout << ans << endl;
}

Measured memory_bytes: 3636
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include "bits/stdc++.h"
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN];
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    int now = 1, res = 0;
    FOR(i,1,n)
        if (a[i] == now) {
            now++;
        }
        else res++;
    if (now == 1) res = -1;
    cout << res;
    return 0;
}

Measured memory_bytes: 1024
//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


namespace {
	// printElems(&a[0], &a[n]);　みたいな感じで使う。
	void printElems(const int* begin, const int* end)
	{
		for (const int* p = begin; p != end; ++p) {
			cout << *p << ' ';
		}
		cout << endl;
	}
}

#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n+1; i++)
#define repr(i,n) for(ll i=n-1; i>=0; i--)
#define repr1(i,n) for(ll i=n; i>0; i--)
#define FOR(i,j,n) for(ll i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(ll i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const ll BIG = 1LL<<60;
const string yes = "Yes";
const string no = "No";

//----------------------------------------------

int a[100];
int b[100];
int c[100];
int d[100];
int ans = 0;
int m,q;


void dfs(vi v, int dep,int la, int n){
	vi tmpv;
	for(auto x : v) tmpv.push_back(x);
	if(dep < n){
		for(int i = la; i <= m; i++){
			tmpv.push_back(i);
			dfs(tmpv,dep+1,i,n);
			tmpv.pop_back();
		}
	}
	if(dep == n){
		int anstmp = 0;
		rep(i,q){
			if(v[b[i]]-v[a[i]] == c[i]) anstmp+=d[i];
		}
		ans = max(ans,anstmp);
	}
}

int main(){
	int n;
	cin >> n >> m >> q;
	rep(i,q){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	vi vtmp;

	dfs(vtmp,0,1,n);
	prints(ans);



	return 0;
}




Measured memory_bytes: 3628
import math
import sys
def gcd(l: list):
    n=len(l)
    gcd=math.gcd(l[0],l[1])
    for i in range(2,n):
        gcd=math.gcd(l[i],gcd)

    return gcd

n, x=map(int,input().split())
x_list=list(map(int,input().split()))

if n==1:
    print(abs(x_list[0]-x))
    sys.exit()


y=[0]*n
for i in range(n):
    y[i]=abs(x_list[i]-x)

print(gcd(y))

Measured memory_bytes: 20480
def nibun_right(a, x, lo=0, hi=None):
 if lo < 0:
  raise ValueError('lo must be non-negative')
 if hi is None:
  hi = len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
lst.sort()
DMG=[0]*(N+1)
ans=0
for i in range(N):
 renji=nibun_right(lst,lst[i][0]+2*D)
 Z=max(int((lst[i][1]-1)/A)+1-DMG[i],0)
 DMG[i]+=Z
 DMG[renji]-=Z
 ans+=Z
 DMG[i+1]+=DMG[i]
print(ans)


Measured memory_bytes: 72912
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
  
	set<int> s;
	int q;
	cin >> q;
	while(q--){
		int op, el;
		cin >> op >> el;
		if(op == 1)cout << s.count(el) << '\n';
		else if(op == 2)s.erase(el);
		else s.insert(el), cout << s.size() << '\n';
	}
    return 0;
}



Measured memory_bytes: 12480
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    int N; cin>>N;
    vector<ll> A(N,0);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    ll a=A[0];
    for(int i=1;i<N;i++){
        a=__gcd(a,A[i]);
    }
    cout<<a;
    return 0;
}

Measured memory_bytes: 1024
n=int(input())

a=[int(input()) for i in range(n)]

dic={}

for i in range(n):
    if a[i] not in dic:
        dic[a[i]]=1
    else:
        dic[a[i]]+=1

ans=0

for val in dic.values():
    if val%2==1:
        ans+=1

print(ans)

Measured memory_bytes: 16268
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define hoge cout << hoge << endl;
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,f,g,h,w;
ll x[1000005],y[1000005],z[1000005];
ll dp[8000][6000];
bool flag,dame;
ll dan[100],pate[100];



void solve(ll n,ll k){
	//pe(n);p(k);
	if(k <= 0)return;
	if(k >= dan[n]){
		ans += pate[n];
		return;
	}
	if(n == 0){
		ans += 1;
		return;
	}else{
		solve(n-1,k-1);
		if(k >= dan[n-1] + 2)ans += 1;
		solve(n-1,k-2-dan[n-1]);
	}
	return;
}



int main(){
	cin >> n >> k;
	dan[0] = 1;
	pate[0] = 1;
	for(i=1;i<=50;i++){
		dan[i] = 2 * dan[i-1] + 3;
		pate[i] = 2 * pate[i-1] + 1;
	}
	solve(n,k);
	p(ans);
	return 0;
}

Measured memory_bytes: 24832
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long
#define MAX_N 212345

using namespace std;

long long MOD=998244353;

long long fact[MAX_N];
void factorial(int N){
    fact[0]=1;
    for(int i=0; i<N; i++){
        fact[i+1]=(i+1)*fact[i]%MOD;
    }
}

map<long long, long long> inv;
long long inverse(long long x){
    if (inv.count(x)){
        return inv[x];
    }
    long long p=MOD-2;
    long long ret=1;
    long long tmp=x;
    while(p>0){
        if(p%2==1)ret=ret*tmp%MOD;
        tmp=tmp*tmp%MOD;
        p/=2;
    }
    inv[x]=ret;
    return ret;
}

long long comb(int a, int b){
    long long ret=fact[a]*inverse(fact[a-b])%MOD;
    return ret*inverse(fact[b])%MOD;
}

ll pw[MAX_N];
ll N, M, K;
void pow_(){
    pw[0]=1;
    for(int i=0; i<MAX_N-1; i++){
        pw[i+1]=pw[i]*(M-1)%MOD;
    }
}

int main(){
    cin >> N >> M >> K;
    
    ll ans=0;
    pow_();
    factorial(MAX_N-1);
    for(int i=0; i<=K; i++){
        ans+=comb(N-1,i)*pw[N-1-i]%MOD;
        ans%=MOD;
    }
    ans*=M;
    ans%=MOD;
    cout << ans << endl;
}

Measured memory_bytes: 19388
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include<climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////

int N;
int ans;
int i,j,si,ni;
int main(){
    scanf("%d",&N);
    for (ni = 1; ni < N;ni*=9);
    for (si = 1; si < N;si*=6);
        ans = 100000;
    for (i = 0; i<=N;i+=9){
        int sum = 0;
        int n = i;
        j = ni;
        while(n){
            while(j<=n){
                n -= j;
                sum++;
            }
            j /= 9;
        }
        n = N - i;
        j = si;
        while(n){
            while(j<=n){
                n -= j;
                sum++;
            }
            j /= 6;
        }
        ans = sum < ans ? sum : ans;
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 256
from sys import stdin

N, X, Y = map(int, stdin.readline().split())
k = [0] * N

X -= 1
Y -= 1
for start in range(N - 1):
    for end in range(start + 1, N):

        if start < X:
            if end <= X:
                distance = end - start
                k[distance] += 1
            elif X < end < Y:
                if end <= (X + Y) / 2:
                    distance = end - start
                    k[distance] += 1
                else:
                    distance = (X - start) + 1 + (Y - end)
                    k[distance] += 1
            else:
                distance = (X - start) + 1 + (end - Y)
                k[distance] += 1

        elif X <= start < Y:
            if end < Y:
                tmp = (start - X) + 1 + (Y - end)
                distance = min(end - start, tmp)
                k[distance] += 1
            else:
                tmp = (start - X) + 1 + (end - Y)
                distance = min(end - start, tmp)
                k[distance] += 1

        else:
            distance = end - start
            k[distance] += 1

for _ in range(1, N):
    print(k[_])


Measured memory_bytes: 47708
import math


class SegmentTree:
    __slots__ = ["elem_size", "tree_size", "tree"]

    def __init__(self, a: list, default: int):
        real_size = len(a)
        self.elem_size = 1 << math.ceil(math.log2(real_size))
        self.tree_size = 2 * self.elem_size + 1
        self.tree = [default] * (self.elem_size - 1) + a + [default] * (self.elem_size - real_size)

    def get_range_index(self, x, y, k=0, l_end=0, r_end=None):
        '''[x, y], tree[k], [l_end, r_end)'''
        if r_end is None:
            r_end = self.elem_size

        if l_end == x and y == r_end-1:
            return [k]

        mid = (l_end + r_end) // 2
        left_y = y if y < mid-1 else mid-1
        right_x = x if x > mid else mid

        left = self.get_range_index(x, left_y, 2*k+1, l_end, mid) if x <= left_y else []
        right = self.get_range_index(right_x, y, 2*k+2, mid, r_end) if right_x <= y else []
        return left + right

    def get_value(self, x, y):
        tree = self.tree
        index_list = self.get_range_index(x, y)

        return sum(tree[n] for n in index_list)

    def update_tree(self, k: int):
        tree = self.tree

        while k > 0:
            k = (k-1) // 2
            left, right = tree[2*k+1], tree[2*k+2]
            tree[k] = left + right

    def set_value(self, i: int, value: int, op: str):
        k = self.elem_size - 1 + i
        if op == "=":
            self.tree[k] = value
        elif op == "+":
            self.tree[k] += value
        self.update_tree(k)


n, q = map(int, input().split())
rsq = SegmentTree([0]*n, 0)
ans = []
for _ in [0]*q:
    c, x, y = map(int, input().split())
    if c == 0:
        rsq.set_value(x-1, y, "+")
    else:
        ans.append(rsq.get_value(x-1, y-1))
print("\n".join([str(n) for n in ans]))

Measured memory_bytes: 18528
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,max,i,ele,min=INT_MAX,sum=0;
    vector<int> a;
    cin>>n>>max;
    
    for(i=0;i<n;i++)
    {
        cin>>ele;
        sum+=ele;
        if(ele<min) min=ele;
        
    }
    max-=sum;
    
    if(max<0){
        cout<<0;
        return 0;
    }
    else{
        cout<<n+max/min;
    }
    
	return 0;
}


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


using namespace std;
using ll = long long;



int main()
{
	int N;
	ll sum = 0;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		if (i % 5 != 0 && i % 3 != 0) {
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

const int MAX_N = 1e5 + 5;

struct Edge {int to, cost;};

int N, Q, K;
vector<Edge> G[MAX_N];
bool inque[MAX_N];
long long d[MAX_N];


void addEdge(int a, int b, int c)
{
  G[a].push_back((Edge){b, c});
  G[b].push_back((Edge){a, c});
}

void spfa(int s)
{
  queue<int> que;
  que.push(s);
  memset(d, 0x3f, sizeof d);
  memset(inque, 0, sizeof inque);
  inque[s] = true;
  d[s] = 0;
  while (!que.empty()) {
    int v = que.front(); que.pop();
    inque[v] = false;
    for (int i = 0; i < G[v].size(); ++i) {
      Edge &e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        if (!inque[e.to]) {
          inque[e.to] = true;
          que.push(e.to);
        }
      }
    }
  }
}

int main()
{
  //freopen("in.txt", "r", stdin);
  while (scanf("%d", &N) != EOF) {
    for (int i = 0; i < N; ++i) G[i].clear();
    for (int i = 1; i < N; ++i) {
      int a, b, c; scanf("%d%d%d", &a, &b, &c);
      --a; --b;
      addEdge(a, b, c);
    }
    scanf("%d%d", &Q, &K);
    --K;
    spfa(K);
    //for (int i = 0; i < N; ++i) printf("d[%d]=%lld\n", i, d[i]);
    while (Q--) {
      int a, b; scanf("%d%d", &a, &b); --a; --b;
      printf("%lld\n", d[a] + d[b]);
    }
  }
  return 0;
}


Measured memory_bytes: 8820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010

/*
辺が橋である⇔その辺がないとグラフが非連結になる
辺の個数はM個で50個以下なので
全探索してみてもいい気がする・・・

なんかバグると思って
ずっと悩んでたら入力が無限にされると思ってたwww
最初に入力保存してなきゃダメでしょ、初歩的なミス
*/

int par[MAX_N];//親の番号
int siz[MAX_N];//木のサイズ
//int rnk[MAX_N];

void init(int n)
{
  //根の定義・・・par[i]=iの時iを根という
  //最初全てが根
  for (int i=0;i<=n;i++){
    par[i]=i;
    siz[i]=1;
  }
}

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

//x,yが同じ集合に属しているか、つまり同じ根に繋がっているか
bool same(int x,int y){
  return ( root(x)==root(y) );
}

//x,yの属する集合を合併する
bool merge(int x, int y) {
  x=root(x);
  y=root(y);
  if (x==y) return false;
  par[y]=x;
  return true;
}

int treesize(int x)
{
  return (siz[root(x)]); 
}

int main()
{
  int N,M;cin>>N>>M;
  
  //i番目の辺がない時を考える
  //辺が全部ある時は連結グラフなので非連結になったらカウント
  int count = 0;
  
  vector<int> a(M+1),b(M+1);
  for (int i=1;i<=M;i++)
    cin>>a[i]>>b[i]; 
  
  for (int i=1;i<=M;i++)
  {
    //i番目の辺がなかった時のグラフを考える
    init(N);//UnionFind初期化
    
    for (int j=1;j<=M;j++)
    {
      if (j!=i) merge(a[j],b[j]);
    }
    
    map<int,int> m;
    for (int j=1;j<=N;j++)
    {
      m[root(j)]++;
      //cout<<"root("<<j<<")="<<root(j)<<endl;
    }
  
    if (m.size()>=2)
    {
      //cout<<"橋の番号:"<<i<<endl;
      count++;//橋をカウント
    }
  }
  cout<<count<<endl;
} 


Measured memory_bytes: 256
import itertools

a_lst = list(map(int, input().split()))

choice_lst = list(itertools.permutations(a_lst, 3))

cost_lst = []
for i in range(len(choice_lst)):
    cost = 0
    for j in range(3):
        tmp_cost = choice_lst[i][j]
        if j == 0:
            continue
        else:
            cost += abs(choice_lst[i][j] - choice_lst[i][j - 1])
    cost_lst.append(cost)

minimum = min(cost_lst)
print(minimum)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);
long long int combination(long long int,long long int);
long long int series_sum(long long int);

int main(){
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF){
        cout<<intlog(a+b)+1<<endl;
    }
}
template <typename T>T intlog(T x){
    string a=to_string(x);
    return a.length()-1;
}



Measured memory_bytes: 3300
#include <stdio.h>

int main(){
  int N;
  int L[200];
  int i,j,temp;


  scanf("%d",&N);
  N = 2*N;
  for(i = 0;i < N; i++){
    scanf("%d", & L[i]);
  }

  for(j = 0;j<N;j++){
    for(i = 0; i < N-1 ; i++){
      if(L[i]>L[i+1]){
	temp = L[i];
	L[i]=L[i+1];
	L[i+1]=temp;
      }
	
    }
  }
  temp = 0;
  for(i = 0; i < N ; i+=2){
    temp+=L[i];
  }
  printf("%d\n",temp);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>

int main(int argc, char const *argv[]) {
  int N;
  scanf("%d", &N);
  if (N % 7 == 0 || N % 4 == 0) {
    printf("Yes\n");
    return 0;
  }
  int n = N / 7;
  for (int i = 1; i <= n; i++) {
    int k = N - 7*i;
    if (k % 4 == 0) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct edge{int to; int cost;};
vector<vector<edge>> graph(0);
vector<int> d(0);
const int MAX_dist=1e9;

void init(int n){
    graph.resize(n);
    d.resize(n,MAX_dist);
}

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    d[s]=0;
    que.emplace(0,s);
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,graph[v].size()){
            edge e=graph[v][i];
            if(d[e.to]>d[v]+e.cost){
            d[e.to]=d[v]+e.cost;
            que.emplace(d[e.to],e.to);
            }
        }
    }
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int h,w;
    cin>>h>>w;
    init(10);
    int x;
    rep(i,10)rep(j,10){
        cin>>x;
        graph[j].push_back({i,x});
    }
    dijkstra(1);
    map<int,int> a;
    rep(i,h)rep(j,w){
        cin>>x;
        a[x] ++;
    }
    int ans=0;
    rep(i,10){
        ans += d[i]*a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
a = Array.new(5) { gets.to_i }
a.sort_by! { |x| (x - 1) % 10 }
s = 0
a.each_with_index do |x, i|
  if i > 0
    s += (1 + (x - 1) / 10) * 10
  else
    s += x
  end
end
puts s

Measured memory_bytes: 14160
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in();
	cout << (a + b + 1) / 2 << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

x = [set() for _ in range(n)]
for a, b in ab:
    x[a-1].add(b-1)
    x[b-1].add(a-1)
    
ans = 0
for i, xx in enumerate(x):
    for xxx in xx:
        if h[i] <= h[xxx]:
            break
    else:
        ans += 1
        
print(ans)

Measured memory_bytes: 63512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
	int n;
	cin >> n;
	cout<<a[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())


def num2alpha(num):
    if num <= 26:
        return chr(64+num)
    elif num % 26 == 0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num % 26)


print(num2alpha(n).lower())


Measured memory_bytes: 61824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N)
    {
        cin >> A[i];
    }

    sort(A.begin(), A.end());

    int ans = 0;
    rep(i, K)
    {
        ans += A[i];
    }

    cout << ans << endl;
}


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

using namespace std;
using ll = long long;



int main()
{
    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k; k--;
    cout << v[k] << endl;
}

Measured memory_bytes: 256
from time import time
from random import random

limit_secs = 2
start_time = time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

def calc_score():
    score = 0
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
        score += max(10 ** 6 + S, 0)
    return score

def solution():
    return [i % 26 for i in range(D)]

t = solution()
score = calc_score()
while time() - start_time + 0.15 < limit_secs:
    d = int(random() * D)
    q = int(random() * 26)
    old = t[d]
    t[d] = q
    new_score = calc_score()
    if new_score < score:
        t[d] = old
    else:
        score = new_score
print('\n'.join(str(e + 1) for e in t))


Measured memory_bytes: 79140
//DPまとめ S Digit Sum
//https://atcoder.jp/contests/dp/tasks/dp_s
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

ll dp[10010][2][110];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=len(s);
    int d;
    cin>>d;
    dp[0][0][0]=1;
    rep(i,n)rep(j,2)rep(k,d){
      int x=s[i]-'0';
      for(int l=0;l<=(j?9:x);l++) (dp[i+1][j||l<x][(k+l)%d]+=dp[i][j][k])%=mod;
    }
    cout<<(dp[n][0][0]+dp[n][1][0]-1+mod)%mod<<endl;
}

Measured memory_bytes: 17408
import java.util.Scanner;

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

		int n = sc.nextInt();
		int lB = 0;
		int rA = 0;
		int lrBA = 0;

		int ans = 0;
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			boolean isLeftB = false;
			boolean isRightA = false;
			if (s.charAt(0) == 'B')
				isLeftB = true;
			if (s.charAt(s.length()-1) == 'A')
				isRightA = true;

			if (isLeftB && isRightA)
				lrBA++;
			else if (isLeftB)
				lB++;
			else if (isRightA)
				rA++;

			for (int j = 0; j < s.length(); j++) {
				if (s.indexOf("AB", j) >= 0) {
					ans++;
					j = s.indexOf("AB", j);
				} else {
					break;
				}
			}
		}

		if (lrBA == 0) {
			ans += Math.min(lB, rA);
		} else {
			if (lB == 0 && rA == 0)
				ans += lrBA - 1;
			else
				ans += lrBA += Math.min(rA, lB);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 30016
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> num(N);
	for (int i = 0; i < N; ++i) cin >> num[i];
	sort(num.begin(), num.end());
	if (num[N / 2 - 1] < num[N / 2]) {
		cout << num[N / 2] - num[N / 2 - 1] << endl;
	} else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	for(;;){
        int w,v;

        cin>>w;


        if(w==-1)break;
        else if(w<=10)v=1150;
        else if(w<=20)v=1150+125*(w-10);
        else if(w<=30)v=2400+140*(w-20);
        else if(w>30)v=3800+160*(w-30);

        cout<<4280-v<<endl;




	}
	return 0;
}

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

int N;

int first = 100;
int last = 100;


string ans = "F";

bool isRight = true;

int main(){

	/*char dumup[201];
	char *up;
	up = dumup + 100;

	char dumdown[201];
	char *down;
	down = dumdown + 100;
	
	cin >> N;
	memset(dumup,'.',sizeof(dumup));
	memset(dumdown,'.',sizeof(dumdown));*/

	char up[201];
	char down[201];
	memset(up,'.',sizeof(up));
	memset(down,'.',sizeof(down));
	
	cin >> N;
	
	while(1){
		
		char intup = '.';
		char intdown = '.';
		for(int i=0;i<4;i++){
			if(i==0){
				intup = '.';
				intdown = '.';
			}else if(i==1){
				intup = '#';
				intdown = '.';
			}else if(i==2){
				intup = '.';
				intdown = '#';
			}else{
				intup = '#';
				intdown = '#';
			}
			
			for(int j=first;j<last;j++){
				cout << up[j];
			}
			cout << intup << endl;
			for(int j=first;j<last;j++){
				cout << down[j];
			}
			cout << intdown << endl;
			
			fflush(stdout);
			
			cin >> ans;
			if(ans == "T"){
				up[last] = intup;
				down[last] = intdown;
				last++;
				break;
			}else if(ans == "F" && i == 3){
				isRight = false;
				break;
			}else if(ans == "end"){
				return 0;
			}
		}
		if(!isRight) break;
	}
	while(last - first != N){
		char intup = '.';
		char intdown = '.';
		for(int i=0;i<4;i++){
			if(i==0){
				intup = '.';
				intdown = '.';
			}else if(i==1){
				intup = '#';
				intdown = '.';
			}else if(i==2){
				intup = '.';
				intdown = '#';
			}else{
				intup = '#';
				intdown = '#';
			}
			
			cout << intup;
			for(int j=first;j<last;j++){
				cout << up[j];
			}
			cout << endl;
			cout << intdown;
			for(int j=first;j<last;j++){
				cout << down[j];
			}
			cout << endl;
			fflush(stdout);
			
			cin >> ans;
			
			if(ans == "T"){
				up[first-1] = intup;
				down[first-1] = intdown;
				first--;
				break;
			}else if(ans == "end"){
				isRight = true;
				break;
			}
		}
		if(isRight) break;
	}
	return 0;
}

Measured memory_bytes: 724