akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cstdlib>
#include <stack>
#include <random>

using namespace std;

typedef long long ll;


int two[21];
int a[200200][20];
int dp[200200][20];

int k[20];

bool check()
{
    for (int i = 0; i < 20; i++)
        if (k[i] > 1)
            return false;
    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    two[0] = 1;
    for (int i = 1; i < 21; i++)
        two[i] = two[i - 1] * 2;
    int n, x;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        for (int j = 19; j >= 0; j--)
            if (x >= two[j])
            {
                a[i][j]++;
                x -= two[j];
            }
    }
    ll ans = 0;
    int l = 0, r = 0;
    for (int i = 0; i < 20; i++)
        k[i] = a[0][i];
    while (l < n)
    {
        while (check() && r < n)
        {
            r++;
            for (int i = 0; i < 20; i++)
                k[i] += a[r][i];
        }
        ans += r - l;
        for (int i = 0; i < 20; i++)
            k[i] -= a[l][i];
        l++;
    }
    cout << ans;
    return 0;
}
















Measured memory_bytes: 17152
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int n;
	long long a[100] = {};
	long long ans = 0;

	a[0] += 2;
	a[1] += 1;

	cin >> n;

	for (int i = 2; i < 100; i++) {
		a[i] += a[i - 2] + a[i - 1];
	}
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}

	ans += a[n - 2] + a[n - 1];
	
	
	cout << ans << endl;
	

	


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

signed main(){
    char c; cin>>c;
    if(c=='A')cout<<'T'<<endl;
    else if(c=='T')cout<<'A'<<endl;
    else if(c=='C')cout<<'G'<<endl;
    else cout<<'C'<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

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

  if(a % 2 != b % 2){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  int k = (a+b)/2;
  cout << k << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue> 
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int main(){
    int x;
    scanf("%d", &x);
    ll a = 0, b = 0;
    for(int i = 0; i<=10000; ++i){
        ll cura = (1ll * i * i * i * i * i);
        ll y = -(x - cura); 
        int bst = y > 0? 1: -1, ad = y > 0? 1: -1; 
        if(~ad)while(1ll * bst * bst * bst * bst * bst <= y){bst += ad;}
        else while(1ll * bst * bst * bst * bst * bst >= y){bst += ad; }
        bst -= ad;
        ll X = cura - (1ll * bst * bst * bst * bst * bst);
        if(X == x)return printf("%d %d\n", i, bst), 0;
    }
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    bool ans = true;
    if (n % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    rep(i, n / 2) {
        if (s[i] != s[i + n / 2]) {
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	if a == b && a != c || a == c && a != b || b == c && b != a {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int p = 7 % k;
    int np = 0;
    boolean[] b = new boolean[k];
    b[p] = true;
    int cnt = 1;

    if ((k == 7) || (k == 1)) {
      System.out.println(1);
      return;
    }

    while (true) {
      cnt++;
      np = ((p * 10) + 7) % k;
      if (np == 0) {
        System.out.println(cnt);
        return;
      } else if (b[np]) {
        System.out.println(-1);
        return;
      } else {
        b[np] = true;
        p = np;
      }
    }

  }
}

Measured memory_bytes: 36560
#include <iostream>
using namespace std;
 
int main() {
    
    int N;
    cin >> N;
    
    int j=0;
    for (int i=0 ; i<N ; i++){
        string S;
        cin >> S;
        if (S == "Y"){
            j++;
        }
    }
 
    if ( j>0 ){
        cout << "Four" <<endl;
    }
    else {
        cout << "Three" <<endl;
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int arr[100001],max_v,max_t,last_t,last_v,sum;
int num;
int main()
{
	cin>>num>>max_v>>max_t;
	for(int i=1;i<=num;i++)
	{
		cin>>arr[i];
		//arr[i]=arr[i]+max_t;
	}
	sort(arr+1,arr+1+num);
	last_t=-99999999;
	for(int i=1;i<=num;i++)
	{
		if(arr[i]+max_t>=last_t&&arr[i]<=last_t&&last_v>0)
		{
			last_v--;
		}
		else
		{
			last_t=arr[i]+max_t;
			last_v=max_v-1;
			sum++;
		}
	}
    cout<<sum;
	return 0;	
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > s(n);
    vector<pair<int, int> > p(m);
    rep(i, n)
    {
        cin >> s[i].first;
        cin >> s[i].second;
    }
    rep(i, m)
    {
        cin >> p[i].first;
        cin >> p[i].second;
    }
    rep(i, n)
    {
        int min_p = 0;
        int min_d = INT_MAX;
        rep(j,m)
        {
            int  hoge = abs(s[i].first - p[j].first) + abs(s[i].second - p[j].second);
            if(DEBUG) cout<<j<<"DEBUG"<<hoge<<min_d<<endl;
            if (hoge<min_d){
                min_d=hoge;
                min_p=j+1;
            }
        }
        cout<<min_p<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
  long long n, p;
  scanf("%lld %lld", &n, &p);
  if (n == 1) 
  {
    printf("%lld\n", p);
    return 0;
  }

  long long ans=0;
  for (long long i=2; pow(i, n)<=p; i++)
  {
    if (p%i == 0)
    {
      int tmpcnt=0;
      long long tmp = p;
      while(tmp%i == 0)
      {
        tmp/=i;
        tmpcnt++;
        if (tmpcnt>=n ) break;
      }
      if (tmpcnt >= n) ans = i;
    }
  }

  if (ans == 0) printf("1\n");
  else printf("%lld\n", ans);
}


Measured memory_bytes: 384
import java.util.Scanner;


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

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

        double rad = Math.toRadians(deg);

        double S = a * b * Math.sin(rad) / 2.0;
        double L = a + b + Math.sqrt(Math.pow(a * Math.cos(rad) - b * 1.0, 2.0) + Math.pow(a * Math.sin(rad), 2.0));
        double h = 2.0 * S / (double)a;

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

        sc.close();
    }
}



Measured memory_bytes: 26540
function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var num = parseInt(line[0]);
    var amari = parseInt(line[1]);
    var data = input[1].split(" ");
    var even = 0;
    var odd = 0;
    for(var i = 0; i<data.length; i++){
        data[i] = parseInt(data[i]);
        if(data[i]%2===0){
            even++;
        } else {
            odd++;
        }
    }
    
    function fact(num) {
        var ans = 1;
        for(var i = 1; i<=num; i++){
            ans*=i;
        }
        return ans;
    }
    
    function combi(total,a) {
        return Math.round(fact(total)/(fact(a)*fact(total-a)));
    }

    var evenCombi = Math.pow(2,even);
    
    var oddCombi = 0
    if(amari===0){
        for(var i = 0;i<=odd;i+=2){
            oddCombi += combi(odd,i);
        }
    } else {
        for(var i = 1;i<=odd;i+=2){
            oddCombi += combi(odd,i);
        }
    }
    
    console.log(evenCombi*oddCombi);
 
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
#include <iostream>
using namespace std;
int main(void){
    int W,a,b;
    cin>>W>>a>>b;
    if(a+W<=b){
        cout<<b-(a+W)<<endl;
    }
    else if(b+W<a){
        cout<<a-(b+W)<<endl;
    }
    else{
        cout<<'0'<<endl;
    }
}


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

using namespace std;

int main(void) {
	int x, n;
	cin >> x >> n;
	if (n == 0) {
		cout << x;
		return 0;
	}
	vector<int> p(n);//元の数字、abs
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

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

	vector<int> p_nocp;//abs、元の数字
	int now = 0;
	for (int i = 0; i < 102; i++) {
		if (i != p[now]) {
			p_nocp.push_back(i);
		}
		else {
			if (now < n - 1)now++;
		}
	}

	sort(p_nocp.begin(), p_nocp.end());
	//出てないやつのコピーおわり

	//for (int i = 0; i < 100 - n; i++) cout << p_nocp[i] << ", "; //debag

	int ans = 300;
	for (int i = 0; i < p_nocp.size(); i++) {
		if (abs(ans - x) > abs(p_nocp[i] - x)) {
			ans = p_nocp[i];
		}
		else if (abs(ans - x) == abs(p_nocp[i] - x)) {
			ans = min(p_nocp[i], ans);
		}
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	char s[20];
	scanf("%s", s);
	int i;
	for (i = 0; i < a; i++)
	{
		if (s[i]<'0' || s[i]>'9')
		{
			printf("No\n");
			return 0;
		}
	}
	if (s[a] != '-')
	{
		printf("No\n");
		return 0;
	}
	for (i = a + 1; i < a + b + 1; i++)
	{
		if (s[i]<'0' || s[i]>'9')
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
l = sorted(list(map(int, input().split())), reverse = True)
ali = 0
bob = 0
if n % 2 == 1:
    ali = l[n-1]
for i in range(n//2):
    ali += l[i*2]
    bob += l[i*2+1]
print(ali - bob)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define ms_valtype int

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a - b;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int min(int a, int b){
	return a <= b ? a : b;
}

int main(){
	int N, i;
	scanf("%d", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	sort(A, N);
	int now = 0, ans;
	for(i = 0; i < N - 1; i++){
		if(now < min(A[i], A[N - 1] - A[i])){
			now = min(A[i], A[N - 1] - A[i]);
			ans = A[i];
		}
	}
	printf("%d %d\n", A[N - 1], ans);
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, m;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    ll ave = pow(2, m);
    int point = 1900 * m + 100 * (n - m);

    cout << ll(point * ave) << "\n";
}

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

using namespace std;

int main()
{
    int n; cin >> n;
    int t[n], x[n], y[n];

    bool traveling = true;

    for (int i = 0; i < n; i++) {
        cin >> t[i] >> x[i] >> y[i];
        int dt = 0, ds = 0;
        if (i == 0) {
            dt = t[i];
            ds = x[i] + y[i];
        } else {
            dt = t[i] - t[i - 1];
            ds = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        }
        // 旅行がプラン実行が不可能な場合
        if (dt < ds)                         traveling = false;
        else if (ds % 2 == 0 && dt % 2 != 0) traveling = false;
        else if (ds % 2 != 0 && dt % 2 == 0) traveling = false;
    }

    if (traveling) cout << "Yes" << endl;
    else           cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(vec) vec.begin(),vec.end()
int main() {
  int N,C,K;  cin >> N >> C >> K;
  vector<int> T(N);
  rep(i,N) cin >> T.at(i);
  sort(all(T));

  int bus = 1;
  int psng = 0;
  int bustime = T.at(0)+ K;  //1台目の時間6
  rep(i,N){
      if (T.at(i) <= bustime && psng < C) psng++;
      else{
        bus++;
        psng=1;
        bustime = T.at(i) + K;
//        cout << i+1 <<" bus " << bus << "-" << bustime << endl;
      }
  }
  cout << bus << endl;
}


Measured memory_bytes: 3688
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str=sc.next();
		
		if(str.endsWith("2")||
		str.endsWith("4")||
		str.endsWith("5")||
		str.endsWith("7")||
		str.endsWith("9")
		){
			System.out.println("hon");
		}
		else if(str.endsWith("0")||
		str.endsWith("1")||
		str.endsWith("6")||
		str.endsWith("8")
		){	System.out.println("pon");
		}
		else{
			System.out.println("bon");
		}
	}
}


Measured memory_bytes: 35732
# -*- coding: utf-8 -*-

## Library

from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

S=input()

## Logic

ans=0
for i in range(0,len(S)):
    if S[i]=="1":
        ans+=1

print(ans)


Measured memory_bytes: 64108
def solve(N, K, S):
    X = [0]
    for i in range(1, N):
        if S[i-1] != S[i]:
            X.append(i)
    X.append(N)

    m = None
    for i in range(len(X)-1):
        j = i + 2 * K
        if S[X[i]] == '1':
            j += 1
        j = min(j, len(X)-1)
        #print("    ",repr(S[X[i]]), j, "m=%d"%(X[j]-X[i]),"X[%d]:%d-X[%d]"%(j,X[j],i))
        m = max(0 if m is None else m, X[j] - X[i])
    if m is None:
        return N
    return m

N, K = map(int, input().split())
S = input().strip()
N = len(S)
print(solve(N, K, S))



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

using namespace std;

bool flag;
int a[10];

void dfs(int ap, int b, int c){
 
  if(!ap){
    flag = true;
    return;
  }
  else{
    if(a[10 - ap] > b){
      return dfs(ap - 1, a[10 - ap], c); 
    }
    else if(a[10 - ap] > c){
      return dfs(ap - 1, b, a[10 - ap]); 
    }
    else{
      return;
    }
  }

}

int main(){

  int n;

  cin >> n;

  for(int i = 0; i < n; ++i){
    
    flag = false;
    
    for(int j = 0; j < 10; ++j){
      cin >> a[j];
    }
    
    dfs(10, 0, 0);

    cout << (flag ? "YES" : "NO") << endl;

  }

}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int main(){
	while(1){
		int w, h;
		cin >> w >> h;
		if(!w&&!h) break;

		vector<int> v(w*h, 1);
		vector<vector<int> > cost( w*h, vector<int>(w*h, 1000));
		rep(i, w*h){
			cost[i][i] = 0;
		}

		rep(j, h){
			rep(i, w-1){
				int wall;
				cin >> wall;
				if(!wall)cost[j*w+i][j*w+i+1] = cost[j*w+i+1][j*w+i] = 1; 
			}
			if(j == h-1) break;
			rep(i, w){
				int wall;
				cin >> wall;
				if(!wall)cost[j*w+i][j*w+i+w] = cost[j*w+i+w][j*w+i] = 1;
			}
		}


		vector<int> best(w*h, 1000);

		queue<int> q;
		best[0] = 1;
		q.push(0);
		while(!q.empty()){
			int p = q.front();
			q.pop();
			rep(i, w*h){
				if(best[p] + cost[p][i] < best[i]){
					best[i] = best[p] + cost[p][i];
					q.push(i);
				}
			}
		}

		cout << (best[w*h-1]==1000?0:best[w*h-1]) << endl;

		//cout << endl;
		//rep(i, w*h){
		//	rep(j, w*h){
		//		printf("%5d", cost[i][j]);
		//	}
		//	cout << endl;
		//}

		//cout << "***";
	}

	return 0;
}

Measured memory_bytes: 4240
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO ;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            String []s=Console.ReadLine().Split(' ');
            int X=int.Parse(s[0]);
            int A=int.Parse(s[1]);
            int n;;
            if(X>=A){
                n=10;
            }else{
                n=0;
            }
            Console.WriteLine(n);

                


        }
    }
}

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

struct node {
  int id;
  int weight;
  struct node *next;
};
struct node **list;
int *maxdis, *premaxdis;

void Insert(int, int, int);
void Dfs(int, int);
void RevDfs(int, int);
int main(void)
{
  int i, n, s, t, w;
  scanf("%d", &n);
  maxdis = (int*)calloc(n, sizeof(int));
  premaxdis = (int*)calloc(n, sizeof(int));
  list = (struct node**)malloc(sizeof(struct node*) * n);
  for (i = 0; i < n; i++) list[i]= NULL;
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d %d", &s, &t, &w);
    Insert(s, t, w);
  }
  Dfs(s, -1);
  RevDfs(s, -1);
  for (i = 0; i < n ;i++) {
    printf("%d\n", maxdis[i]);
    free(list[i]);
  }
  free(list);
  free(maxdis);
  free(premaxdis);
}
void Insert(int a, int b, int w)
{
  struct node *p = (struct node*)malloc(sizeof(struct node));
  p->id = b;
  p->weight = w;
  p->next = list[a];
  list[a] = p;
  p = (struct node*)malloc(sizeof(struct node));
  p->id = a;
  p->weight = w;
  p->next = list[b];
  list[b] = p;
}
void Dfs(int root, int fa)
{
  struct node *i;
  for (i = list[root]; i != NULL; i = i->next) {
    if (i->id != fa) {
      Dfs(i->id, root);
      if (maxdis[i->id] + i->weight > maxdis[root]) {
        premaxdis[root] = maxdis[root];
        maxdis[root] = maxdis[i->id] + i->weight;
      } else if (maxdis[i->id] + i->weight > premaxdis[root]) {
        premaxdis[root] = maxdis[i->id] + i->weight;
      }
    }
  }
}
void RevDfs(int leaf, int fa)
{
  struct node *i;
  for (i = list[leaf]; i != NULL; i = i->next) {
    if (i->id != fa) {
      if (maxdis[i->id] + i->weight == maxdis[leaf]) {
        if (premaxdis[leaf] + i->weight > maxdis[i->id]) {
          premaxdis[i->id] = maxdis[i->id];
          maxdis[i->id] = premaxdis[leaf] + i->weight;
        } else if (premaxdis[leaf] + i->weight > premaxdis[i->id]) {
          premaxdis[i->id] = premaxdis[leaf] + i->weight;
        }
      }else {
        if (maxdis[leaf] + i->weight > maxdis[i->id]) {
          premaxdis[i->id] = maxdis[i->id];
          maxdis[i->id] = maxdis[leaf] + i->weight;
        } else if (maxdis[leaf] + i->weight > premaxdis[i->id]) {
          premaxdis[i->id] = maxdis[leaf] + i->weight;
        }
      }
      RevDfs(i->id, leaf);
    }
  }
}


Measured memory_bytes: 3100
#include<stdio.h>

int main(){
    int n,m,a[1000];
    int i,j,sum,max;
     
    while(scanf("%d %d",&n,&m)){
        if(n==0&&m==0)
        break;
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        max=0;
        for(i=0;i<n;i++){
            for(j=i+1;j<n;j++){
                sum=a[i]+a[j];
                if(sum>max&&sum<=m)
                max=sum;
            }
        }
        if(max==0)
        printf("NONE\n");
        else
        printf("%d\n",max);
    }
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>  
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define REP(i, a, op1, n, op2) for(int i=a; i op1 (int)(n); op2 ## op2 i)
#define cout(val) cout << (val) << endl

using namespace std;  

int main(){
    int k, s, x, y, z, temp, count = 0;
    cin >> k >> s;
    k++;
    for(x=0; x<k; x++){
        for(y=0; y<k; y++){
            temp = s - x - y;
            if(temp < 0) break;
            if(temp < k){
                ++count;
            }
        }
    }
    cout(count);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LOCAL 0
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;ans%=mod;}b/=2;a*=a;a%=mod;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
const int INF=0x3f3f3f3f;
#define Pa pair<int,int>
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define ld long double
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}

int main()
{
    int a[4][4];
    int b1,b2,b3,a21,a22,a23,a31,a32,a33;
    
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++) si(a[i][j]);
    }
    
    for(int a1=0;a1<=100;a1++){
        b1=a[1][1]-a1;
        b2=a[1][2]-a1;
        b3=a[1][3]-a1;
        a21=a[2][1]-b1;
        a22=a[2][2]-b2;
        a23=a[2][3]-b3;
        a31=a[3][1]-b1;
        a32=a[3][2]-b2;
        a33=a[3][3]-b3;
        if(a21==a22 && a22==a23 && a31==a32 && a32==a33){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    s = input()
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    print(s[0:3])


resolve()

Measured memory_bytes: 61804
import math

n,k = map(int,input().split())
a = [int(i) for i in input().split()]

a.sort()
r = a[n-1]
l = 0


def calc(t,x):
    return (t-1) // x


while r - l > 1:
    mid = (r+l)//2
    count = 0
    for i in a:
        count += calc(i,mid)
    if count > k:
        l = mid
    else:
        r = mid

print(r)


Measured memory_bytes: 31064
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    long answer =0;
    //それぞれの幸福度をゆうせんど付きキューに入れて管理
    Queue<Long> p = new PriorityQueue<Long>(Collections.reverseOrder());
    Queue<Long> q = new PriorityQueue<Long>(Collections.reverseOrder());
    Queue<Long> r = new PriorityQueue<Long>(Collections.reverseOrder());
    Queue<Long> N = new PriorityQueue<Long>(Collections.reverseOrder());
    
    for(int i=0;i<A;i++){
      p.add(sc.nextLong());
    }
    for(int i=0;i<B;i++){
      q.add(sc.nextLong());
    }    
    for(int i=0;i<C;i++){
      r.add(sc.nextLong());
    }
    for(int i=0;i<X;i++){
      N.add(p.poll());
    }
    for(int i=0;i<Y;i++){
      N.add(q.poll());
    }
    for(int i=0;i<C;i++){
      N.add(r.poll());
    }
    for(int i=0;i<X+Y;i++){
      answer = answer + N.poll();
    }
    System.out.println(answer);
  }
  

  
}

Measured memory_bytes: 101048
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,Ma,Mb = LI()
a,b,c = LIR(N,3)

n = N//2

d1 = defaultdict(lambda:5000)
d2 = defaultdict(lambda:5000)

for bit in range(1<<n):
    L = bit.bit_length()
    val_a = 0
    val_b = 0
    cost = 0
    for i in range(L):
        if bit>>i&1:
            val_a += a[n-1-i]
            val_b += b[n-1-i]
            cost += c[n-1-i]
    if cost < d1[(val_a,val_b)]:
        d1[(val_a,val_b)] = cost

for bit in range(1<<(N-n)):
    L = bit.bit_length()
    val_a = 0
    val_b = 0
    cost = 0
    for i in range(L):
        if bit>>i&1:
            val_a += a[N-1-i]
            val_b += b[N-1-i]
            cost += c[N-1-i]
    if cost < d2[(val_a,val_b)]:
        d2[(val_a,val_b)] = cost

vals = []
now = 1
while True:
    if Ma*now <= sum(a) and Mb*now <= sum(b):
        vals.append((Ma*now,Mb*now))
        now += 1
    else:
        break

ans = 5000
for k in d1.keys():
    for v in vals[::-1]:
        left_a = v[0]-k[0]
        left_b = v[1]-k[1]
        if left_a < 0 or left_b < 0:
            break
        if d1[k]+d2[(left_a,left_b)] < ans:
            ans = d1[k]+d2[(left_a,left_b)]

if ans == 5000:
    print(-1)
else:
    print(ans)

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

int main()
{

	ll n;
	string s;
	cin>>n>>s;
	ll count = 0;
	for(int i  = 0 ; i < n - 2 ; i++)
	{
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
		{
			count++;
		}
	}
	
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {

	int N;
	cin >> N;
	double an = 0;
	vector<double> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
		an += 1 / vec.at(i);
	}
	
	
	cout <<1/an<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef int number;

int c;
string str;

number Z();
number Expr();
number Factor();
number Term();
number Num();

void debug(string str) {
//  cout << str << endl;
}

number Z() {
  debug("Z: " + str.substr(c));
  number ans = Expr();
  c++; // read =
  debug("Z(" + to_string(ans) + "): " + str.substr(c));
  return ans;
}

number Expr() {
  debug("Expr: " + str.substr(c));
  number val = Factor();
  int p;
  while (p = c, (str[p] == '+' || str[p] == '-')) {
    if (str[c] == '+') {
      c++; // read +
      number expr = Expr();
      val += expr;
    } else {
      // c++; // read -
      number expr = Expr();
      // val -= expr;
      val += expr;
    }
  }
  debug("Expr(" + to_string(val) + "): " + str.substr(c));
  return val;
}

number Factor() {
  debug("Factor: " + str.substr(c));
  number val = Term();
  int p;
  while (p = c, (str[p] == '*' || str[p] == '/')) {
    if (str[c] == '*') {
      c++; // read *
      number factor = Term();
      val *= factor;
    } else {
      c++; // read /
      number factor = Term();
      val /= factor;
    }
  }
  debug("Factor(" + to_string(val) + "): " + str.substr(c));
  return val;
}

number Term() {
  debug("Term: " + str.substr(c));
  if (str[c] == '-') {
    c++; // read -
    number term = Term();
    return -term;
  } else if (str[c] == '(') {
    c++; // read (
    number expr = Expr();
    c++; // read )
    return expr;
  } else {
    number num = Num();
    return num;
  }
}

number Num() {
  debug("Num: " + str.substr(c));
  number val = 0;
  while (isdigit(str[c])) {
    val = val * 10 + (str[c] - '0');
    c++;
  }
  debug("Num(" + to_string(val) + "): " + str.substr(c));
  return val;
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    c = 0;
    cin >> str;
    cout << Z() << endl;
  }
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int a,b,c,d;
  int h1,h2;
  int k1,k2;
  cin >> h1 >> h2;
  cin >> k1 >> k2;
  cin >> a >> b >> c >> d;
  int hiroshi = h1 * a + h2 * b + (h1 / 10) * c + (h2 / 20) * d;
  int kenjiro = k1 * a + k2 * b + (k1 / 10) * c + (k2 / 20) * d;

  if(hiroshi == kenjiro){
    cout << "even" <<endl;
  }
  else if(hiroshi < kenjiro){
    cout << "kenjiro" << endl;
  }
  else{
    cout << "hiroshi" << endl;
  }
}



Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
using namespace std;
#define N 5001
#define M 201
int n,m,a[N],w[N][M];
int s[M][N],t[M];long long c[N];
int main(){
	scanf("%d%d",&n,&m);int i,j,l,r,v;
	long long res,ans=0;
	for(i=1;i<n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)scanf("%d",&w[i][j]);
	for(l=n;l>=1;l--)
	{
		for(i=1;i<=m;i++)
		{
			while(t[i]&&(w[v=s[i][t[i]]][i]<=w[l][i]))
			{c[v]-=w[v][i];if(t[i]>1)c[s[i][t[i]-1]]+=w[v][i];--t[i];}
			s[i][++t[i]]=l;c[l]+=w[l][i];if(t[i]>1)c[s[i][t[i]-1]]-=w[l][i];
		}res=0;
		for(r=l;r<=n;r++)
		{res+=c[r];ans=max(ans,res);res-=a[r];}
	}printf("%lld",ans);return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string s;
	cin>>s;
	if(s[0]=='R' && s[1]=='R' && s[2]=='R'){
		cout<<3<<"\n";
	}
	else if(s[0]=='R' && s[1]=='R'){
		cout<<2<<"\n";
	}
	else if(s[1]=='R' && s[2]=='R'){
		cout<<2<<"\n";
	}
	else if(s[0]=='R' || s[1]=='R' || s[2]=='R'){
		cout<<1<<"\n";
	}
	else{
		cout<<0<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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 = 1001001001;
const int mod = 1000000007;

int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> l(Q), r(Q);
    rep(i, Q) cin >> l[i] >> r[i];
    vector<int> v(S.size(), 0);
    // 累積和
    int cnt = 0;
    char before = S[0];
    // ACのカウントを格納する
    for(int i = 1; i < S.size(); i++){
        if(before == 'A' && S[i] == 'C'){
            cnt++;
        }
        v[i] = cnt;
        before = S[i];
    }
    rep(i, Q){
        cout << v[r[i] - 1] - v[l[i] - 1] << endl;
    }

//    rep(i, v.size()){
//        cout << v[i] << " ";
//    }
//    cout << endl;

    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
typedef unsigned long long ull;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,line) memset(v,line,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define P 1000000007
#define endl '\n'
const int dx[] = {1,-1,0,0,1,-1,1,-1};
const int dy[] = {0,0,1,-1,1,-1,-1,1};
const int dxhorse[] = {-2,-2,-1,-1,1,1,2,2};
const int dyhorse[] = {1,-1,2,-2,2,-2,1,-1};

int main(int argc, char const *argv[])
{

	int k, s, ans=0, z;cin>>k>>s;

	for (int i = 0; i <= k; ++i)
	{
		for (int j = 0; j <= k; ++j)
		{
			z=s-i-j;
			ans+=i+j+z==s && z>=0 && z<=k; 
		}
	}
	cout<<ans;
}	

Measured memory_bytes: 256
n = int(input())
l = [int(x) for x in input().split()]

isNotCorrect = False

for i in range(n):
    num = l[i]
    if(num%2==0 and not (num%3==0 or num%5==0)):
        isNotCorrect = True

if(isNotCorrect):
    print('DENIED')
else:
    print('APPROVED')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  ll n, m; cin >> n >> m;
  ll res = 1;
  for (ll i = 1; i*i <= m; i++) {
    if (m%i == 0) {
      if (i*n <= m) res = max(res, i);
      if (m/i != i) {
        if (m/i*n <= m) res = max(res, m/i);
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 710;
const int MAX_M = MAX_N * MAX_N / 2;
int N, M;
int A[MAX_M], B[MAX_M];

int graph[MAX_N][MAX_N] = {};
int group[MAX_N] = {};
int bipertite[MAX_N] = {};

int count[MAX_N][2] = {};

bool can_make[MAX_N][MAX_N] = {};

bool dfs(int n, int g, int b) {
    if (group[n] == 0) {
        group[n] = g;
        bipertite[n] = b;
    } else if (bipertite[n] == -b) {
        return false;
    } else {
        return true;
    }

    for (int i = 1; i <= N; i++) {
        if (i != n && graph[n][i] == 0) {
            if (!dfs(i, g, -b)) {
                return false;
            }
        }
    }
    return true;
}



int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= M; i++) {
        std::cin >> A[i] >> B[i];
    }

    for (int i = 1; i <= M; i++) {
        graph[A[i]][B[i]] = 1;
        graph[B[i]][A[i]] = 1;
    }

    for (int i = 1; i <= N; i++) {
        if (group[i] == 0){
            if (!dfs(i, i, 1)) {
                std::cout << "-1" << std::endl;
                return 0;
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        if (bipertite[i] == 1) {
            count[group[i]][0]++;
        } else {
            count[group[i]][1]++;
        }
    }

    can_make[0][0] = true;

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            if (can_make[i-1][j]) {
                can_make[i][j + count[i][0]] = true;
                can_make[i][j + count[i][1]] = true;
            }
        }
    }

    for (int i = N/2; i <= N; i++) {
        if (can_make[N][i]) {
            int j = N - i;

            std::cout << i * (i - 1) / 2 + j * (j - 1) / 2 << std::endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4608
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		string s=sc.S;
		s=" "+s;
		long ans=0;
		var h=new int[n+1][];
		for(int i = n;i>=0;i--) {
			h[i]=new int[10];
			if(i!=n){
				for(int j = 0;j<10;j++) {
					h[i][j]=h[i+1][j];
				}
				h[i][s[i+1]-'0']=i+1;
			}
		}
		for(int i = 0;i<10;i++) {
			if(h[0][i]!=0){
				for(int j = 0;j<10;j++) {
					if(h[h[0][i]][j]!=0){
						for(int k = 0;k<10;k++) {
							if(h[h[h[0][i]][j]][k]!=0){
								ans++;
							}
						}
					}
				}
			}
		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 15456
// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

const int mod = 1000000007;
const int inf = 1000000007;

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


Measured memory_bytes: 3624
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn :: IO Int
  if n == 0
    then return ()
    else do
    ns <- replicateM n
          (map read . words <$> getLine) :: IO [[Int]]
    let mins = map minimum ns
        maxs = map maximum (transpose ns)
        anss = filter (`elem` mins) maxs
--    print mins
--    print maxs
    print $ if null anss then 0 else head anss
    main

Measured memory_bytes: 4092
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
int main() {
  map<int, int> cnt;
  int n;
  cin >> n;
  vector<int> a(n);
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    if (!cnt.count(b)) {
      cout << sum << endl;
      continue;
    }
    sum += (ll)(c - b) * cnt[b];
    cnt[c] += cnt[b];
    cnt.erase(b);
    cout << sum << endl;
  }
}

Measured memory_bytes: 6236
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, D, A;
  cin >> N >> D >> A;
  vector<pair<int, int>> M(N);
  for (int i = 0; i < N; i++){
    int X, H;
    cin >> X >> H;
    M[i] = make_pair(X, (H + A - 1) / A);
  }
  sort(M.begin(), M.end());
  vector<int> imos(N + 1, 0);
  long long ans = 0;
  for (int i = 0; i < N; i++){
    if (i > 0){
      imos[i] += imos[i - 1];
    }
    M[i].second -= imos[i];
    if (M[i].second > 0){
      ans += M[i].second;
      auto itr = upper_bound(M.begin(), M.end(), make_pair(M[i].first + D * 2 + 1, -1));
      imos[i] += M[i].second;
      imos[itr - M.begin()] -= M[i].second;
    }
  }
  cout << ans << endl;
}

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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

ld r;

int main()
{
	cin >> r;
	cout << setprecision(15) << fixed << r * 2 * M_PI;
	return 0;
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vector<vector<int>> g(n);
    for (int i = 0; i+1 < n; i++) {
        g[i].emplace_back(i+1);
        g[i+1].emplace_back(i);
    }
    
    g[x].emplace_back(y);
    g[y].emplace_back(x);
    
    vector<vector<int>> dist;
    for (int s = 0; s < n; s++) {
        queue<int> que; que.emplace(s);
        vector<int> res(n, -1); res[s] = 0;
        while (not que.empty()) {
            int v = que.front(); que.pop();
            for (const auto &u : g[v]) {
                if (res[u] != -1) continue;
                res[u] = res[v] + 1;
                que.emplace(u);
            }
        }
        dist.emplace_back(res);
    }
    
    vector<int> ans(n, 0);
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            ans[dist[i][j]]++;
        }
    }
    
    for (int i = 1; i < n; i++) cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 16128
# import bisect
# import heapq
# import math
# import random
# from fractions import gcd
# from collections import Counter, defaultdict, deque
# from decimal import Decimal
# from functools import lru_cache, reduce
# from itertools import combinations, combinations_with_replacement, product, permutations
# from operator import add, mul, sub, itemgetter
# import numpy as np

import sys
sys.setrecursionlimit(10000)

def read_int(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return int(read)

def read_int_n(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return [int(x) for x in read.split()]

def read_float(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return float(read)

def read_float_n(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return [float(x) for x in read.split()]

def read_str(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return str(read)

def read_str_n(read=None):
	if read == None:
		read = sys.stdin.readline().strip()
	return [str(x) for x in read.split()]	
	
def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(A):
	ans = 'YES'
	for i in range(1, 5):
		if A.count(i) > 2:
			ans = 'NO'
	return ans

def main():
	t = '''2 1
	3 2
	4 3'''.splitlines()
	
	a1, b1 = read_int_n()
	a2, b2 = read_int_n()
	a3, b3 = read_int_n()
	A = [a1, b1, a2, b2, a3, b3]
	
	print(slv(A))

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char c = sc.next().toCharArray()[0];
        int code = (int) c;
        if (code >= 122) {
            code = 97;
        } else {
            code++;
        }
        System.out.println((char) code);
    }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int d[100001],a[100001],sum[100001];
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		char c;
		cin>>c;
		d[i]=c-'0';
	}
	for(int i=1;i<=n;i++)
	{
		a[i]=d[i-1]^d[i];
	}
	sum[0]=0;
	for(int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+a[i];
	}
	int b=0;
	int maxn=0;
	for(int i=1;i<=n;i++)
	{
		b^=a[i];
		int x=upper_bound(sum,sum+n+1,2*k-(!b)+sum[i])-sum;
		maxn=max(maxn,x-i);
	}
	cout<<maxn<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
inline int min(int x,int y,int z){return min(x,min(y,z));}
inline int max(int x,int y,int z){return max(x,max(y,z));}
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z){return add(add(x,y),z);}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y){return 1LL*x*y%mod;}
inline int mul(int x,int y,int z){return mul(mul(x,y),z);}
#define N 600005
int a[N],t[15][N];
char s[N];
int id[N],n;
void upd(int &x)
{
	if(x==1) x=2;
	else if(x==2) x=1;
}
signed main()
{
	cin>>n;
	scanf("%s",s+1);
	int m=strlen(s+1);
	int cur=1;
	for(int i=0;i<n;i++)
	{
		cur*=3;
		for(int j=0;j<cur;j++)
		{
			int x=j;
			for(int k=0;k<i;k++) x/=3;
			a[j]=x;
		}
		bool op=0;
		for(int j=1;j<=m;j++)
		{
			if(s[j]=='S') op^=1;
			else
			{
				int u=id[j],tmp=0;
				for(int k=0;k<3;k++)
				{
					int v=k*(cur/3)+u;
					if(op) upd(a[v]);
					if(a[v]==2) tmp=k,a[v]=0;
					else a[v]++;
					if(op) upd(a[v]);
				}
				id[j]+=tmp*(cur/3);
			}
		}
		if(op) for(int j=0;j<cur;j++) upd(a[j]);
		for(int j=0;j<cur;j++) t[i][j]=a[j];
		// for(int j=1;j<=cur;j++) printf("%d ",t[i][j]);
		// cout<<"\n";
	}
	for(int i=0;i<cur;i++)
	{
		int ans=0,tmp=1;
		for(int j=0;j<n;j++)
		{
			tmp*=3;
			ans+=t[j][i%tmp]*(tmp/3);
		}
		printf("%d ",ans);
	}
	return 0;
}




Measured memory_bytes: 10236
#include "bits/stdc++.h"

using namespace std;

int main() {
int n;
cin >>n;
int iti =n%10;
n/=10;
int ni =n%10;
n/=10;
int sann=n%10;
n/=10;
int yonn=n%10;
int zennhann =yonn*10+sann;
int kouhann =ni*10+iti;
if(zennhann>=1&&zennhann<=12&&kouhann>=1&&kouhann<=12)cout <<"AMBIGUOUS"<<endl;
else if(zennhann>=1&&zennhann<=12)cout <<"MMYY"<<endl;
else if(kouhann>=1&&kouhann<=12)cout <<"YYMM"<<endl;
else cout <<"NA"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int n,a[10000],add,add0,i,j,blank;

  while(1){

  scanf("%d",&n);
  if(n == 0) break;
  add=0;
  add0=0;
  for(i = 0; i < n; i++){

    scanf("%d",&a[i]);
    if(a[i] > 1) add++;
    if(a[i] == 0) add0++;

  }

  n -= add0;

  if(add == 0){

    printf("NA\n");
    continue;

  }

  printf("%d\n",n+1);

  }

  return 0;

}

Measured memory_bytes: 652