akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
using namespace std;


char table[5010][5010];

vector<int> e[5010],e2[5010];

int done[5010];
vector<int> tpr;
void dfs(int x,int s){
	if( done[x] ) return;
	else done[x] = true;
	
	if(s != x){
		table[x][s] = 1;
		table[s][x] = 2;
	}
	for(int i = 0 ; i < e[x].size() ; i++){
		dfs(e[x][i],s);
	}
}

void dfs2(int x){
	if( done[x] ) return;
	else done[x] = true;
	
	for(int i = 0 ; i < e2[x].size() ; i++){
		dfs2(e2[x][i]);
	}
	tpr.push_back(x);
}
int main(){
	int n,m;
	cin >> n >> m;
	for(int i = 0 ; i < m ; i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		e[b].push_back(a);
		e2[a].push_back(b);
		table[a][b] = 1;
		table[b][a] = 2;
	}
	for(int i = 0 ; i < n ; i++){
		dfs(i,i);
		memset(done,0,sizeof(done));
	}
	for(int i = 0 ; i < n ; i++)
		dfs2(i);
	
	int f = 0;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < n ; j++){
			if( i != j ){
				if( table[i][j] == 0 ){
					f |= 1;
				}
			}
		}
	}
	for(int i = 0 ; i < n ; i++){
		for(int j = i+1 ; j < n ; j++){
			int a = tpr[j];
			int b = tpr[i];
			table[a][b] = 1;
			table[b][a] = 2;
		}
	}
	vector< pair<int,int> > v;
	for(int i = 0 ; i < n ; i++){
		int cnt = 0;
		for(int j = 0 ; j < n ; j++)
			if( table[i][j] == 1 ) cnt++;
		v.push_back(make_pair(cnt,i));
	}
	sort(v.rbegin(),v.rend());
	for(int i = 0 ; i < n ; i++)
		cout << v[i].second+1 <<  endl;
	cout << f << endl;
	
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 100100100;

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<vector<char> > ss(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> ss[i][j];

  deque<P> deq;
  deq.push_front(P(ch, cw));
  vector<vector<int> > magics(h, vector<int>(w, INF));
  vector<P> walks = {P(1, 0), P(0, 1), P(-1, 0), P(0, -1)};
  magics[ch][cw] = 0;
  while (!deq.empty()) {
    int i = deq.front().first;
    int j = deq.front().second;
    int mag = magics[i][j];
    deq.pop_front();
    for (auto p : walks) {
      int a = i + p.first;
      int b = j + p.second;
      if (0 <= a && a < h && 0 <= b && b < w) {
        if (ss[a][b] == '.' && mag < magics[a][b]) {
          magics[a][b] = mag;
          deq.push_front(P(a, b));
        }
      }
    }
    for (int a = -2; a <= 2; a++) {
      for (int b = -2; b <= 2; b++) {
        if (0 <= a + i && a + i < h && 0 <= b + j && b + j < w) {
          if (ss[a + i][b + j] == '.' && mag + 1 < magics[a + i][b + j]) {
            magics[a + i][b + j] = mag + 1;
            deq.push_back(P(a + i, b + j));
          }
        }
      }
    }
  }
  if (magics[dh][dw] != INF) {
    cout << magics[dh][dw] << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 8508
/*
 
*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <deque>
 
#define ll long long
#define cint const int
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
 
using namespace std;
 
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, long long> pil;
typedef pair <int, string> pis;
typedef pair <int, char> pic;
typedef pair <long long, int> pli;
typedef pair <long long, string> pls;
typedef pair <long long, char> plc;
typedef pair <string, int> psi;
typedef pair <string, long long> psl;
typedef pair <string, char> psc;
typedef pair <char, int> pci;
typedef pair <char, long long> pcl;
typedef pair <char, string> pcs;
 
int n;
 
int main () {
	cin >> n;
	cout << pow(n, 2);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// typedef pair<ll,ll> Pair;
// ll mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll t,i,j,k,temp,temp2,n,m,x,y;
    cin >> x >> y >> n >> m >> k;
    vector <ll> a;
    vector <ll> b;
    vector <ll> c;
    ll ans=0;
    for(i=0;i<n;i++){
        cin >> temp;
        a.push_back(temp);
    }
    for(i=0;i<m;i++){
        cin >> temp;
        b.push_back(temp);
    }
    for(i=0;i<k;i++){
        cin >> temp;
        c.push_back(temp);
    }
    sort(a.begin(),a.end(), greater<>());
    sort(b.begin(),b.end(), greater<>());
    sort(c.begin(),c.end(), greater<>());
    for(i=0;i<x;i++){
        ans+=a[i];
    }
    for(i=0;i<y;i++){
        ans+=b[i];
    }
    for(i=0;i<k;i++){
        if(x>0&&y>0){
            if(c[i]<=min(a[x-1],b[y-1])){
                break;
            }
            if(a[x-1]<=b[y-1]){
                ans+= c[i]-a[x-1];
                x--;
            }
            else{
                ans+=c[i]-b[y-1];
                y--;
            }
        }
        else if(x>0){
            if(c[i]<=a[x-1]) break;
            else{
                ans+= c[i]-a[x-1];
                x--;
            }
        }
        else if(y>0){
            if(c[i]<=b[y-1]) break;
            else{
                ans+= c[i]-b[y-1];
                y--;
            }
        }
        else break;
    }
    cout << ans;
}


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

int main() {
    int h, a, b;
    cin >> h >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++) {
        if (h%i == 0) ans++;
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
	int  al,as, flag=0, aa[26]={0};
	char a[101];

scanf("%s",a);  


al=strlen(a);   


for(int i=0;i<al;i++)
{
	as=a[i]-97;
	aa[as]++;
}


for(int i=0;i<26;i++)
{
	if(aa[i] % 2 == 1 )
 	{
 	 flag=1 ; break;
 }
}

if (flag == 1) printf("No\n");
else printf("Yes\n");

return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

long M;

int comp(const void *a,const void *b){
        return *(long *)b-*(long *)a;
}

long getmaxsum(long l[],int N){
        int i,j;
        long maxsum=0;

        for(i=0,j=N-1;j-i>=0;i++){
                while(l[i]+l[j-1]<M && j-i>=0)
                        j--;
                if(maxsum<l[i]+l[j])
                        maxsum=l[i]+l[j];
        }

        return maxsum;
}

main(){
        int i,j,k;

        long N,N2;

        long l[1000+500500+1];
        long maxpt;

        while(1){
                scanf("%ld %ld",&N,&M);
                if(N==0)break;
                for(i=0;i<N;i++)
                        scanf("%ld",&l[i]);

                for(i=0,k=N;i<N;i++)
                        for(j=i;j<N;j++)
                                if(l[i]+l[j]<M)
                                        l[k++]=l[i]+l[j];
                l[k++]=0;
                N=k;

                qsort((void *)l,(size_t)N,sizeof(long),comp);

                printf("%ld\n",getmaxsum(l,N));

        }
        return 0;
}

Measured memory_bytes: 8812
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static class Dice {
		private int[] label;
		
		public static int ABOVE_INDEX = 0;
		public static int FRONT_INDEX = 1;
		public static int RIGHT_INDEX = 2;
		public static int LEFT_INDEX = 3;
		public static int BACK_INDEX = 4;
		public static int BELOW_INDEX = 5;
		
		public Dice(int[] num) {
			label = num;
		}
		
		public void roll(char op) {
			int tmp;
			
			switch (op) {
				case 'E':
					tmp = label[0];
					label[0] = label[3];
					label[3] = label[5];
					label[5] = label[2];
					label[2] = tmp;
					break;
				case 'N':
					tmp = label[0];
					label[0] = label[1];
					label[1] = label[5];
					label[5] = label[4];
					label[4] = tmp;
					break;
				case 'S':
					tmp = label[0];
					label[0] = label[4];
					label[4] = label[5];
					label[5] = label[1];
					label[1] = tmp;
					break;
				case 'W':
					tmp = label[0];
					label[0] = label[2];
					label[2] = label[5];
					label[5] = label[3];
					label[3] = tmp;
					break;
			}
		}
		
		public void horizontalRotation() {
			int tmp = label[1];
			label[1] = label[3];
			label[3] = label[4];
			label[4] = label[2];
			label[2] = tmp;
		}

		public void putDown(int aboveNum, int frontNum) {
			int i;
			for (i = 0; i < 4; i++) {
				roll('N');
				if (getAboveNum() == aboveNum) {
					break;
				}
			}
			
			if (i == 4) {
				for (i = 0; i < 4; i++) {
					roll('E');
					if (getAboveNum() == aboveNum) {
						break;
					}
				}
			}
			
			for (i = 0; i < 4; i++) {
				horizontalRotation();
				if (getNum(FRONT_INDEX) == frontNum) {
					break;
				}
			}
		}
		
		public int getAboveNum() {
			return label[0];
		}

		public int getNum(int index) {
			if (index >= label.length) {
				throw new IllegalArgumentException();
			}
			
			return label[index];
		}
	}
	
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] nums = new int[6];
		List<Integer> ans = new ArrayList<Integer>(); 
		
		for (int i = 0; i < nums.length; i++) {
			nums[i] = scan.nextInt();
		}

		Dice dice = new Dice(nums);
		int q = scan.nextInt(); 
		
		for (int i = 0; i < q; i++) {
			int above = scan.nextInt();
			int front = scan.nextInt();
			dice.putDown(above, front);
			ans.add(dice.getNum(Dice.RIGHT_INDEX));
		}

		for (Integer n : ans) {
			System.out.println(n);
		}

		scan.close();
	}

}

Measured memory_bytes: 17380
n,p = map(int,input().split())
res10000 = res5000 = res1000 = -1
x = y = 0
end = False
for x in range(n+1):
    if end:
        break
    for y in range(n+1-x):
        if x*10000+y*5000+ (n-(x+y))*1000 == p:
            res10000 = x
            res5000 = y
            res1000 = n-(x+y)
            end = True
print('{} {} {}'.format(res10000,res5000,res1000))

Measured memory_bytes: 3064
import sys


args = str(input()).split(" ")

A = int(args[0])
B = int(args[1])
flag = int(args[2])

divided_num = A
if A > B:
    divided_num = B

while flag > 0:
    if ((A % divided_num) == 0) and ((B % divided_num) == 0):
        result = divided_num
        flag = flag - 1
    divided_num = divided_num - 1

print(result)


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

int main() {
  int N, K, f;
  f = 0;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    
    if(a <= K / 2){
      f += 2 * a;
    }
    
    else{
      if(a < K){
        f += 2 * (K - a);
      }
      
      else{
        f += 2 * (a - K);
      }
    }
  }
  
  cout << f << endl;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	int A=0,B=0,AB=0,O=0,tmp;
	char buf[3];

	while(scanf("%d,%s",&tmp,buf)!=EOF){
		if(buf[0] == 'B'){
			B += 1;
		}else if(buf[0] == 'O'){
			O += 1;
		}else if(buf[0] == 'A' && buf[1] == '\0'){
			A += 1;
		}else{
			AB += 1;
		}
	}

	printf("%d\n%d\n%d\n%d\n",A,B,AB,O);

	return 0;
}

Measured memory_bytes: 2588
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

ll modpow(ll n,ll k){
	ll ret=1;
	for(int i=0;i<k;i++)ret=ret*n%MOD;
	return ret%MOD;
}

int main(){
	init();
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		for(int j=0;i+j<s.length();j++){
			string t;
			for(int k=0;k<i;k++)t.push_back(s[k]);
			for(int k=i+j;k<s.length();k++)t.push_back(s[k]);
			if(t=="keyence"){
				cout<<"YES"<<endl;
				return 0;
			}

		}
	}
	cout<<"NO"<<endl;
}



Measured memory_bytes: 256
<?php
$str = trim(fgets(STDIN));
$k = trim(fgets(STDIN));
$n = strlen($str);
for($i = 0; $i < $n; $i++){
    for($j = 1; $j <= min($n - $i,5); $j++){
        $map[substr($str, $i, $j)] = true;
    }
}
ksort($map);
$array = array_keys($map);
for($i = 0; $i < $k; $i++){
    $str = array_shift($array);
}
echo $str;


Measured memory_bytes: 6648
k = int(input())
p = [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]
print(p[k - 1])

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val (H, W) = listOfLong()
    var ans = Long.MAX_VALUE
    if (H * W % 3 == 0L) return println(0)
    fun solv(H: Long, W: Long) {
        for (h in 1 until H) {
            val d1 = h * W
            for (n in 0 .. 1) {
                val d2 =
                    if (n == 0) (H - h) * (W / 2) // Ｔ型
                    else (H - h) / 2 * W  // 三型
                val d3 = (H * W) - d1 - d2
                val d = listOf(d1, d2, d3).sorted()
                ans = Math.min(ans, d.last() - d.first())
            }
        }
    }
    solv(H, W)
    if (W != H) solv(W, H)
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


Measured memory_bytes: 47308
N,L = map(int,input().split())

A = []

for i in range(1,N+1):
    A.append(L+i-1)

if A[0] > 0:
    A[0] = 0

elif A[N-1] < 0:
    A[N-1] = 0

else:
    pass

print(sum(A))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb push_back
ifstream in("ciclueuler.in");
ofstream out("ciclueuler.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005


int n,a[200005];

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    if(n%2){
        for(int i=n;i>=1;i-=2) cout << a[i] << ' ';
        for(int i=2;i<n;i+=2) cout << a[i] << ' ';
    }
    else{
        for(int i=n;i>1;i-=2) cout << a[i] << ' ';
        for(int i=1;i<n;i+=2) cout << a[i] << ' ';
    }
}


Measured memory_bytes: 2944
def f():
    c = None
    s = None
    ans = []
    for i, t in enumerate(sorted(data.items(), key=lambda x: x[1], reverse=True)):
        ans.append(t[0])
        if c is None:
            c = t[1]
            s = i
        else:
            if c != t[1] and 4 <= i:
                ans = ans[:s]+sorted(ans[s:i])+ans[i:]
                break
            elif c != t[1]:
                ans = ans[:s]+sorted(ans[s:i])+ans[i:]
                c = t[1]
                s = i
    else:
        ans = ans[:s]+sorted(ans[s:i+1])+ans[i+1:]
    return ' '.join(ans[:5])

while True:
    n = int(raw_input())
    if n == 0: break
    lis = [raw_input() for i in range(n)]
    key = raw_input()
    data = {}
    for line in lis:
        for string in line.split():
            if string[0] == key:
                if not string in data:
                    data[string] = 1
                else:
                    data[string] += 1
    if data:
        print f()
    else:
        print 'NA'

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

int main(void)
{
    int N, Y;
    cin >> N >> Y;
    bool flag = true;
    int x,y,z;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N-i; j++)
        {
            x = i;
            y = j;
            z = N - i - j;
            if (i*10000+j*5000+z*1000 == Y && z >= 0)
            {
                cout << x << " " << y << " " << z << endl;   
                flag = false;
                return 0;
            }
        }
    }
    
    if (flag)
    {
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int h, w;
    cin>>h>>w;
    vector<vector<char>> hoge(h, vector<char>(w));
    int step = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
        cin>>hoge.at(i).at(j);
        if(hoge.at(i).at(j)=='#') step++; 
        }
    }
    
    if(step==h+w-1){
        cout<<"Possible"<<endl;
    }else{
        cout<<"Impossible"<<endl;
    }
}


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

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for (auto item : s)
        cout << item;
cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <math.h>

using namespace std;

vector <int> a (4 , 0);

int main() {
    for(int i = 1 ; i <= 3 ; i++) cin >> a[i];
    sort(a.begin() + 1 , a.end() , greater <int>()) ;
    int res = 0;
    for(int i = 2 ; i <= 3 ; i++)
        res = res + (a[i - 1] - a[i]);
    cout << res;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

int A,B,ans=1;
scanf("%d%d",&A,&B);
char S[A+B+2];

for (int i = 0; i < A+B+2; i++){
    scanf("%c",&S[i]);
}

for (int i = 1; i < A+B+2; i++){
    if ((i<A) && !(S[i]>= 48 && S[i]<= 57)){ ans = 0;break;}
    if (i==A+1 && !(S[A+1]=='-')){ ans = 0; break;}
    if (A+1<i && !(S[i]>= 48 && S[i]<= 57)){  ans = 0; break;}
}
ans > 0 ? puts("Yes") : puts("No");

return 0;

}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int l[200005], r[200005];

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n, m; cin >> n >> m;

	vector<pii> v(m);
	rep(i, 0, m) cin >> v[i].first >> v[i].second;
	rep(i, 1, n + 1) l[i] = r[i] = i;
	sort(all(v));
	rep(i, 0, m) {
		int p = v[i].second;
		int nl = l[p], nr = r[p + 1];
		r[p] = nr; l[p + 1] = nl;
	}

	rep(i, 1, n + 1) {
		cout << (r[i] - l[i] + 1) << " \n"[i == n];
	}
}



Measured memory_bytes: 5188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int A = ni();
        int B = ni();
        int C = ni();
        if(A+B>=C){
            out.println("Yes");
        }else{
            out.println("No");
        }
 
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);

    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 32980
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cmath>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;



int main() {
    Int N;
    cin >> N;

    vvi route = vvi(N+1);
    map<int,int> appear_counts;
    vector<pair<int,int>>memory;

    rep(i,N-1){
        Int x,y;
        cin >> x >> y;
        route[x].push_back(y);
        appear_counts[x]+=1;
        appear_counts[y]+=1;
        memory.push_back(make_pair(x,y));
    }

    int max_appear =0;
    rep(i,N+1){
        max_appear = max(appear_counts[i],max_appear);
    }

    cout << max_appear << endl;

    map<int,map<int,int>> ans;
    map<int,int> outer_used;
    queue<int> next;
    next.push(1);
    while(!next.empty()){
        Int now = next.front();
        next.pop();
        int color_num = 1;
        rep(i,route[now].size()){
            Int now_connector = route[now][i];
            if(color_num == outer_used[now]){
                color_num++;
            }
            ans[now][now_connector] = color_num;
            ans[now_connector][now] = color_num;
            outer_used[now_connector] = color_num;
            
            next.push(now_connector);
            color_num++;
        }
    }

    rep(i,N-1){
        cout << ans[memory[i].first][memory[i].second] << endl;
    }

    return 0;
}

Measured memory_bytes: 33524
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    int D; cin >> D;
    vector<int> C(26); vector<vector<int>> S(D, vector<int>(26));
    REP(i, 0, 26) cin >> C[i];
    REP(i, 0, D) REP(j, 0, 26) cin >> S[i][j];


    vector<int> T(D);
    REP(i, 0, D) {
        int max_idx = 0;
        REP(j, 0, 26) {
            if (S[i][max_idx] < S[i][j]) max_idx = j;
        }
        T[i] = max_idx + 1;
    }

    vector<vector<int>> last(26, vector<int>(D, 0));
    vector<ll> ret(26, 0);
    REP(i, 0, D) {
        ret[T[i] - 1] += S[i][T[i] - 1];
        last[T[i] - 1][i] = i + 1;
        REP(j, 0, 26) {
            if (i > 0 && !last[j][i]) last[j][i] = last[j][i - 1];
            ret[j] -= C[j] * (i + 1 - last[j][i]);
        }
    }

	auto start = std::chrono::system_clock::now();
    const ll limit = 1950*1000;

    ll best = accumulate(ALL(ret), 0LL);
    mt19937_64 mt(random_device{}());
    uniform_int_distribution<int> day(0, D - 1);
    uniform_int_distribution<int> con(0, 25);
    while (1) {
        std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
        double elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now-start).count();
        if(elapsed > limit) break;

        int d = day(mt);
        int next = con(mt);
        int prev = T[d] - 1;
        T[d] = next + 1;
        last[prev].assign(D, 0);
        last[next].assign(D, 0);
        ret[prev] = 0;
        ret[next] = 0;
        REP(i, 0, D) {
            if (T[i] == prev + 1 || T[i] == next + 1) {
                ret[T[i] - 1] += S[i][T[i] - 1];
                last[T[i] - 1][i] = i + 1;
            }
            if (i > 0) {
                if (!last[prev][i]) last[prev][i] = last[prev][i - 1];
                if (!last[next][i]) last[next][i] = last[next][i - 1];
            }
            ret[prev] -= C[prev] * (i + 1 - last[prev][i]);
            ret[next] -= C[next] * (i + 1 - last[next][i]);
        }
        if (best >= accumulate(ALL(ret), 0LL)) {
            T[d] = prev + 1;
        } else {
            best = accumulate(ALL(ret), 0LL);
        }
        // cout << best << endl;
    }
    
    for (auto t : T) cout << t << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  map<string, int> mp;
  for(int i = 0; i < n; ++i) {
    string s; cin >> s;
    mp[s]++;
  }
  int mx = 0;
  vector<string> res;
  for(auto &x: mp) {
    if(x.second > mx) {
      mx = x.second;
      res.clear();
    }
    if(x.second == mx) {
      res.push_back(x.first);
    }
  }
  sort(res.begin(), res.end());
  for(auto x: res) cout << x << '\n';
  return 0;
}


Measured memory_bytes: 25584
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[114514][3];
int ans[114514][3];
signed main(){
	ic(n)
	int sum=0;
	rep(0,i,n)rep(0,j,3)cin>>a[i][j];
	rep(1,i,n+1){
		rep(0,j,3){
			if(j==0){
				ans[i][j]=max(ans[i-1][1],ans[i-1][2]);
				ans[i][j]+=a[i-1][j];
			}
			else if(j==1){
				ans[i][j]=max(ans[i-1][0],ans[i-1][2]);
				ans[i][j]+=a[i-1][j];
			}
			else{
				ans[i][j]=max(ans[i-1][0],ans[i-1][1]);
				ans[i][j]+=a[i-1][j];
			}	
		}
	}
	c(max({ans[n][0],ans[n][1],ans[n][2]}))
}				
		                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           	                                         


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

typedef long double ld;
typedef long long ll;

using namespace std;

const ll inf = 1e18;
struct Segment {
    int l;
    int r;
    int c;
    bool operator<(const Segment &rhs) {
        return l < rhs.l;
    }
};

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cout << setprecision(20);
    int l, n;
    cin >> l >> n;
    vector<Segment> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].l >> a[i].r >> a[i].c;
    }
    sort(a.begin(), a.end());
    ll ans = inf;
    set<pair<ll, int>> len;
    int dist = 0;
    int j1 = 0;
    len.insert(make_pair(0, 1));
    auto lol = make_pair(inf, l);
    len.insert(lol);
    while (!len.empty()) {
        if (dist >= len.begin()->second) {
            len.erase(len.begin());
            continue;
        }
        pair<ll, int> x = *len.begin();
        int pos = x.second;
        dist = pos;
        ll cost = x.first;
        int j2 = j1;
        while (j2 < n && a[j2].l <= pos) {
            if (a[j2].r > pos) {
                ll ccost = a[j2].c + cost;
                if (a[j2].r == l) {
                    ans = min(ans, ccost);
                }
                len.insert(make_pair(ccost, a[j2].r));
            }
            j2++;
        }
        j1 = j2;
    }
    if (ans == inf) {
        cout << "-1";
    } else {
        cout << ans;
    }
    return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans, n;
int F[100005], S[100005];
vector<int> G[100005];

void bfs(int s, int *p) {
    for (int i=1; i<=n; i++) p[i] = -1;
    queue<int> q;
    p[s] = 0;
    q.push(s);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : G[u]) {
            if (p[v]==-1) {
                p[v] = p[u] + 1;
                q.push(v);
            }
        }
    }
}

int main(void) {
    cin >> n;
    rep(i, 0, n-1) {
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].pb(b);
        G[b].pb(a);
    }

    bfs(1, F);
    bfs(n, S);

    int fen = 0;
    for(int i=1; i<=n; i++) if (F[i]<=S[i]) fen++;

    int sun = n - fen;
    if (fen>sun) puts("Fennec");
    else puts("Snuke");


	return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	constexpr int num = 26;
	int D;
	vector<int> c(num);
	vector<int> t;
	vector<int> last(num);
	vector<vector<int>> s; 
	
	cin>>D;
	
	s.resize(D, vector<int>(num));
	t.resize(D, 0);
	
	for(int i = 0; i < num; i++){
		cin>>c[i];
	}
	
	for(int i = 0; i < D; i++){
		for(int j = 0; j < num; j++){
			cin>>s[i][j];
			
			if(s[i][t[i]] < s[i][j]) {
				t[i] = j;
			}
		}
	}
	
	for(int i = 0; i < D; i++){
		cout<<t[i]+1<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3756
using System;

namespace atcorder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            atcorder.ABD.Run();
        }
    }
    public class ABD
    {
        public ABD()
        {
        }
        public static void Run(){
            int N = int.Parse(Console.ReadLine());
            Console.WriteLine(N <= 999 ? "ABC" : "ABD");
        }
    }
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a;
    cin >> x >> a;
    if(x < a)
        cout  << 0 << endl;
    else
        cout << 10 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll
//#define endl '\n'

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    vi v(n);
    REP(i, n) {
        cin >> v[i];
    }
    sort(ALL(v));
    cout << accumulate(v.begin(), v.begin() + m, 0ll) << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
}
int main() {
	int n, k, ans = 0;
	int t, a[200010] = {};
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &t);
		a[t-1]++;
	}
	qsort(a, n+1, sizeof(int), comp);
	for (int i = k; i < n; i++)
	{
		ans += a[i];
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1404
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
char ch;
char temp;
int main()
{
  while(cin >>ch){
    if(ch <'D')
      ch +=23;
    else
      ch -=3;
    cout <<ch;
  }
  cout<<endl;
  

  return 0;
}

Measured memory_bytes: 1132
#include <iostream>

using namespace std;

bool f(int a, int b) {
    if (a % 3 == 0) {
        return true;
    }
    if (b % 3 == 0) {
        return true;
    }
    if ((a + b) % 3 == 0) {
        return true;
    }
    return false;
}

int main() {

    int a, b;
    cin >> a >> b;

    if (f(a, b)) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n,a[205];
multiset<ll>s;
int main()
{
	SPEED;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i],s.insert(a[i]);
	ll k=*max_element(a+1,a+n+1);
	ll l=1,r=k+1;
	for(int i=k;r>=l;i--,r--,l++)
	{
		auto j=s.find(i);
		if(j==s.end())
			return cout<<"Impossible"<<endl,0;
		s.erase(j);
		if(r!=l)
		{
			j=s.find(i);
			if(j==s.end())
				return cout<<"Impossible"<<endl,0;
			s.erase(j);
		}
	}
	if(s.size()==0)
		return cout<<"Possible"<<endl,0;
	ll m=*s.begin();
	if(k%2)
	{
		if(m<1+(k+1)/2)
			return cout<<"Impossible"<<endl,0;
	}
	else
	{
		if(m<k/2+1)
			return cout<<"Impossible"<<endl,0;
	}
	cout<<"Possible"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

int H,W;
int C[10][10];
int A[210][210];
ll sum = 0;

int main(){
  scanf("%d %d",&H, &W);
  REP(i,10)REP(j,10){
    scanf("%d",&C[i][j]);
  }
  REP(i,H)REP(j,W){
    scanf("%d",&A[i][j]);
  }

  REP(k,10)REP(i,10)REP(j,10){
    C[i][j] = min(C[i][j], C[i][k]+C[k][j]);
  }
  REP(i,H)REP(j,W){
    if(A[i][j]>=0)
      sum += C[A[i][j]][1];
  }
  printf("%lld\n",sum);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())

bool f(int n) {
    string s = to_string(n);
    bool res = true;
    for(int i=0; i<s.size()/2; i++){
        if(s[i]!=s[s.size()-i-1]) res = false;
    }
    return res;
}

int main()
{
    int a,b; cin >> a >> b;
    int cnt=0;
    for(int i=a; i<=b; i++){
        if(f(i)) cnt++;
    }
    cout << cnt << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,w1;
	
	cin>>n>>w1;
	long long int v[n];
	int w[n];
	for(int i=0;i<n;i++)
	cin>>w[i]>>v[i];
	//int dp[101][100001];
	long long int dp[n+1][w1+1];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w1;j++)
		{
		
		dp[i][j]=0;
	}
	}
	dp[0][0]=0;
	
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=w1;j++)
		{
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j>=w[i])
			dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
			
		}
	}
	cout<<dp[n][w1];
}

Measured memory_bytes: 79104
a_list = ['A', 'B', 'C', 'D', 'E', 'F']
x, y = input().split()
if int(a_list.index(x)) > int(a_list.index(y)):
    print('>')
elif int(a_list.index(x)) < int(a_list.index(y)):
    print('<')
else:
    print('=')


Measured memory_bytes: 2940
program main
	implicit none
    integer::a,b,c,d
    read(*,*)a,b,c,d
    if(a+b==c+d)then
    	write(*,*)'Balanced'
    else if(a+b>c+d)then
    	write(*,*) 'Left'
    else
    	write(*,*) 'Right'
    end if
    stop
end program main

Measured memory_bytes: 2796
# Engines
import cmath
import math
N = int(input())
Engines = []
ans = 0

sumx, sumy = 0, 0
for _ in range(N):
    x, y = map(int, input().split())
    z = complex(x, y)
    arg_deg = cmath.phase(z)
    sumx += x
    sumy += y
    Engines.append((arg_deg, x, y))
ans = max(ans, math.hypot(sumx, sumy))
Engines.sort()
for i in range(N):
    for j in range(i, N):
        sub_x = 0
        sub_y = 0
        for k in range(i, j+1):
            deg, dx, dy = Engines[k]
            sub_x += dx
            sub_y += dy
        ans = max(ans, math.hypot(sub_x, sub_y))
        ans = max(ans, math.hypot(sumx-sub_x, sumy-sub_y))
print(ans)

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

using namespace std;

long long n;
string s;

int main() {
    ios_base::sync_with_stdio(0);

    cin >> n;

    do {
        n--;
        s += ((n % 26) + 'a');
        n /= 26;
    } while(n);

    reverse(s.begin(), s.end());
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3656
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back
#define inf (1<<29)

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;

        int x = 0;
        int n; cin >> n;
        string s; cin >> s;
        vi ans;
        rep(i,sz(s)){
            if(s[i]=='I')x+=1;
            ans.pb(x);
            if(s[i]=='D')x-=1;
            ans.pb(x);
        }
        cout<<maxv(ans)<<endl;

return 0;
}








Measured memory_bytes: 256
n, k = map(int, input().split())
s = list(input())

if s[k - 1] == "A":
    s[k - 1] = "a"
elif s[k - 1] == "B":
    s[k - 1] = "b"
else:
    s[k - 1] = "c"

print("".join(s))


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

using namespace std;

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

string s;

int main(){
    cin >> s;
    string tmps = "";

    bool flag = true;
    REP(i, s.size()){
        tmps = s[s.size()-i-1] + tmps;
        if(tmps == "dream"|| tmps == "dreamer" || tmps == "erase" || tmps == "eraser"){
            tmps = "";
        }
        if(tmps.size()>7){
            flag = false;
            break;
        }
    }

    if(tmps.size()>0) flag = false;

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
using namespace std;
// typedef vector<vector<ll> > matrix;
// const ll S = 3e5 + 20;
// const ll N = 1e6 + 1;
// const ll PRIME = 1e9 + 7;
const ll MAX = 1e6;

void solve()
{
    int a[5];
    fr(i, 5)
    {
        cin >> a[i];
    }
    fr(i, 5)
    {
        if (a[i] == 0)
            cout << i + 1;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    // cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }
}


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

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

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

    int max = 0;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += p[i];
        if (p[i] > max) {
            max = p[i];
        }
    }
    sum = sum - max/2;
    cout << sum << endl;
}


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

const ll p = 1e9+7;

string s;

ll dp[300005][9][2][2];

void add(int x, int t) {
	if (x == 1) {
		if (t == 0)
			dp[1][2][0][1]++;
		else
			dp[1][4][1][0]++;
		return;
	}

	if (t == 0) {
		for (int i = 0; i < 7; ++i)
			for (int j = 0; j < 2; ++j)
				for (int k = 0; k < 2; ++k) {
					ll y = dp[x-1][i][j][k];
					if (j == 1 && k == 1)
						continue;
					if (j == 1) {
						if (i > 0)
							dp[x][i-1][0][1] = (dp[x][i-1][0][1] + y)%p;
					} if (j == 0) {
						if (k == 0)
							dp[x][min(i+1, 6)][0][1] = (dp[x][min(i+1, 6)][0][1] + y)%p;
						else
							if (i > 0)
								dp[x][i-1][0][0] = (dp[x][i-1][j][0] + y)%p;
					}
				}
	} else {
		for (int i = 0; i < 7; ++i)
			for (int j = 0; j < 2; ++j)
				for (int k = 0; k < 2; ++k) {
					ll y = dp[x-1][i][j][k];
					if (j == 1 && k == 1)
						continue;
					if (j == 1) {
						dp[x][min(i+1, 6)][1][0] = (dp[x][min(i+1, 6)][1][0] + y)%p;
					} else {
						if (k == 0)
							dp[x][min(i+1, 6)][0][1] = (dp[x][min(i+1, 6)][0][1] + y)%p;
						if (k == 1)
							dp[x][min(i+1, 6)][1][0] = (dp[x][min(i+1, 6)][1][0] + y)%p;
					}
				}		
	}
}

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

	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == '0')
			add(i+1, 0);
		if (s[i] == '1')
			add(i+1, 1);
		if (s[i] == '?') {
			add(i+1, 1);
			add(i+1, 0);
		}
	}

	ll ans = 0;
	for (int i = 0; i < 7; ++i)
		for (int j = 0; j < 2; ++j)
			for (int k = 0; k < 2; ++k)
				if (i >= 4)
					ans = (ans + dp[s.length()][i][j][k])%p;

	cout << ans << endl;
}

Measured memory_bytes: 85140
#include <cstdio>

using namespace std;

int main(){
	int w,h,n;
	int d[17][17];
	bool f[17][17];
	int a,b;
	while(1){
		scanf("%d %d %d",&w,&h,&n);
		if(w == 0 && h == 0){
			break;
		}
		for(int i=0;i<=16;i++){
			for(int j=0;j<=16;j++){
				d[i][j] = 0;
				f[i][j] = true;
			}
		}
		for(int i=0;i<n;i++){
			scanf("%d %d",&a,&b);
			f[a][b] = false;
		}
		d[0][1] = 1;
		
		for(int y=1;y<=h;y++){
			for(int x=1;x<=w;x++){
				if(f[x][y]){
					d[x][y] = d[x-1][y] + d[x][y-1];
				}
			}
		}
		/*
		for(int y=h;y>0;y--){
			for(int x=1;x<=w;x++){
				if(f[x][y]){
					printf("%2d ",d[x][y]);
				}else{
					printf("-- ");
				}
			}
			printf("\n");
		}
		*/
		printf("%d\n",d[w][h]);
	}
}

Measured memory_bytes: 0
#include<stdio.h>

const int FALSE = 0;
const int TRUE = 1;
int main(){
    int N;
    scanf("%d", &N);

    int d[100];

    for(int i = 0; i < 100; i++){
        d[i] = -1;
    }

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

    int cnt[110];
    for(int i = 0; i < 110; i++){
        cnt[i] = -1;
    }

    int pos = 0;
    int hit;
    for(int i = 0; i < N; i++){
        hit = FALSE;
        for(int j = 0; j < pos; j++){
            if(d[i] == cnt[j]){
                hit = TRUE;
            }
        }
        if(!hit){
            cnt[pos++] = d[i];
        }

    }

    printf("%d\n", pos);
}


Measured memory_bytes: 128
n,t=map(int,input().split())
h=list(map(int,input().split()))

wait=[0]*len(h)
for i in range(len(wait)-1):
  wait[i]=h[i+1]-h[i]
wait[len(wait)-1]=t

ans=0
for i in range(len(wait)):
  ans+=min(wait[i],t)

print(ans)

Measured memory_bytes: 26832
#include<bits/stdc++.h>
using namespace std;
#define int long  long
#define double long double
int t,n,a;
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    t=1;
   // cin>>t;
    while(t--)
    {
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a;
            if(a&1 && i&1) ans++;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3560
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ctr = Counter(A)

if len(ctr) >= 3:
    print('No')
    exit()
if len(ctr) == 1:
    k,v = list(ctr.items())[0]
    if k == 1:
        print('Yes')
    elif N <= k:
        print('No')
    elif N >= 2*k:
        print('Yes')
    else:
        print('Yes' if k==N-1 else 'No')

else:
    (k1,v1),(k2,v2) = list(sorted(ctr.items()))
    if k2-k1 != 1 or k2 >= N:
        print('No')
    elif v1 > k1:
        print('No')
    else:
        print('Yes' if v2//2 + v1 >= k2 else 'No')

Measured memory_bytes: 18656