akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int h[N];
    rep(i,N) cin >> h[i];
    int ans=0;
    rep(i,N){
        int x=i;
        while(h[i]>0){
                int x=i;
                while(true){
                    if(h[x]>0) {
                     h[x]--;
                        x++;
                    }else break;
                }
                ans++;
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

template<class T>bool chmax(T &a, const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}

template<class T>bool chmin(T &a, const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}

int main(){
	cout<<fixed;
	int n;
	cin>>n;
	VD a(n);
	rep(i,n)cin>>a.at(i);
	double ans=0;
	rep(i,n){
		ans+=1/a.at(i);
	}
	ans=1/ans;
	cout<<setprecision(9)<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
dic = {}
ans = 0
for i in range(n):
    x = sorted(list(input()))
    s = "".join(x)
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
        
for j in dic.values():
    if j >= 2:
        ans += j * (j-1) // 2
print(ans)

Measured memory_bytes: 17804
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    ANS = [sl() for _ in range(M)]

    keys = set()
    for p, S in ANS:
        keys.add(p)

    ret = {key: False for key in keys}
    acwa = {key:[0, 0] for key in keys}
    for p, S in ANS:
        if ret[p]: continue
        if S == 'WA':
            acwa[p][1] += 1
        if S == 'AC':
            acwa[p][0] += 1
            ret[p] = True

    ac, wa = 0, 0
    for key in keys:
        if ret[key]:
            ac += acwa[key][0]
            wa += acwa[key][1]
    print(ac, wa)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61132
// 2015/05/19 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

// ユークリッドの互除法（再帰を使わない）
int gcd(int x, int y)
{
	if(x<y){
		swap(x, y);
	}

	while(y>0){
		int r = x%y;
		x = y;
		y = r;
	}

	return x;
}

int main()
{
	int x, y;
	cin >> x >> y;

	cout << gcd(x, y) << endl;

	return 0;
}

Measured memory_bytes: 1160
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 s=sc.Ia;
		var a=new int[s[0]];
		for(int i = 0;i<s[1];i++) {
			a[i]=s[2];
		}
		for(int i = s[1];i<s[0];i++) {
			if(s[2]==(int)1e9){
				a[i]=1;
			}
			else{a[i]=(int)1e9;}
		}
		Console.WriteLine("{0}",String.Join(" ",a));
	}
}
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: 29404
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n,m,num;
    cin >> n >> m;
    if(m/2<n) num=m/2;
    else num=(n*2+m)/4;
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val A = Integer.parseInt(sc.next())
    val B = Integer.parseInt(sc.next())
    val C = Integer.parseInt(sc.next())

    println(Math.min(B / A, C))
  }
}

Measured memory_bytes: 27324
// code author: Dhruva Mahajan
 
// Ideas are cheap, execution is everything.
 
#include<bits/stdc++.h> 
using namespace std;
 
#define ll long long  
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define testcase(t) int t;cin>>t;while(t--)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	
	fastio;

	ll n,m;
	cin>>n>>m;
	if(m<n){
		cout<<"No"<<endl;
	}
	else cout<<"Yes"<<endl;



	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A, B, K;
int main() {
	cin >> K;
	cin >> A >> B;
	bool ok = 0;
	for (int i = A; i <= B; ++i) {
		if (i % K == 0)
			ok = 1;
	}
	if (ok)
		cout << "OK";
	else
		cout << "NG";
}

Measured memory_bytes: 3636
import java.io.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	}
}

Measured memory_bytes: 25452
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define SORT(x) sort((x).begin(),(x).end())
int main(void){
    
    string S;
    int n;
    cin >>S >>n;
    
    for(int i=0; i<4; i++){
        if(S[i]=='+'){
            n++;
        }else{n--;}
    }
    
    cout <<n <<endl;
    
    
}


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

using namespace std;

int h, w, k;
bool s[10][1000];
int ans = 1e8;

int poww(int x, int w)
{
    int a = x;
    while (w > 0)
    {
        a *= x;
        w--;
    }
    return a;
}

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

    cin >> h >> w >> k;

    for (int i = 0; i < h; i++)
    {
        string st;
        cin >> st;
        for (int j = 0; j < w; j++)
            s[i][j] = (st[j] == '1');
    }

    for (int i = 0; i < poww(2, h - 1); i++)
    {
        int curr = __builtin_popcount(i);
        vector<int> v(__builtin_popcount(i) + 1, 0);

        for (int j = 0; j < w - 1; j++)
        {
            bool z = false;
            int xd_next = 0;
            int vc = 0;
            bool incr = false;
            for (int t = 0; t < h; t++)
            {
                v[vc] += s[t][j];
                xd_next += s[t][j + 1];
                if (v[vc] + xd_next > k)
                {
                    if (!incr)
                    {
                        curr++;
                        incr = true;
                    }
                    z = true;
                }
                if ((i >> t) & 1)
                {
                    vc++;
                    xd_next = 0;
                }
            }
            bool broken = false;
            if (z)
            {
                for (int t = 0; t <= __builtin_popcount(i); t++)
                {
                    if (v[t] > k)
                    {
                        broken = true;
                        curr = 1e8;
                    }
                    v[t] = 0;
                }
            }
            if (broken)
                break;
        }
        ans = min(ans, curr);
    }

    cout << ans;

    return 0;
}


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


int main() {
  int num_500, num_100, num_50, price;
  cin >> num_500 >> num_100 >> num_50 >> price;
  
  int ans = 0;
  
  for(int i = 0; i <= num_500; i++){
    for(int j = 0; j <= num_100; j++){
      for( int k = 0; k <= num_50; k++){
        if(price == (i*500 + j*100 + k*50) ) ans++;
      }
    }
  }
  
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;





public class Main
{

	static OutputStream outputStream = System.out;
	static PrintWriter out = new PrintWriter(outputStream);	

	static class node implements Comparable<node>
	{
		int data;int indx;

		node(int i,int o)
		{
			data=i;indx=o;
		}
		public int compareTo(node n)
		{
			if(this.indx!=n.indx) return n.indx-this.indx;
			return n.data-this.data;
		}
	}
	
	


	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		// int t=Integer.parseInt(br.readLine());

		String[] s=br.readLine().split(" ");

		int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]);


		PriorityQueue<Integer> pq=new PriorityQueue<Integer>();

		s=br.readLine().split(" ");

		for(int i=0;i<n;i++) pq.add(Integer.parseInt(s[i]));

		node[] a=new node[m];

		for(int i=0;i<m;i++)
		{
			s=br.readLine().split(" ");
			a[i]=new node(Integer.parseInt(s[0]),Integer.parseInt(s[1]));
		}

		Arrays.sort(a);

		for(int i=0;i<m;i++)
		{
			if(pq.peek()<a[i].indx)
			{
				while(pq.peek()<a[i].indx && a[i].data-->0)
				{
					pq.poll();
					pq.add(a[i].indx);
				}
			}
		}

		long sum=0;

		while(pq.size()>0) sum+=pq.poll();

		out.println(sum);
		
		out.close();

	}
}

Measured memory_bytes: 62388
#include<stdio.h>

int main (void)
{
int n,i,max,min;
int a[n+1];

scanf("%d",&n);

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

max = a[0];
min  = a[0];

for(i = 0;i<n;i++)
{
max = (max>a[i]?max:a[i]);
min = (min<a[i]?min:a[i]);
}
printf("%d",max - min);

return 0;
}

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

int main(void) {
  #ifdef DEBUG
    freopen("input.txt", "r", stdin);
  #endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N;
  cin >> N;
  int cake = 0;
  while (1) {
    int dollars = N - cake * 4;
    if (dollars < 0) {
      cout << "No" << endl;
      break;
    } else if (!(dollars % 7)) {
      cout << "Yes" << endl;
      break;
    }
    cake++;
  }
  return 0;
}


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

int main(){
    string s; cin>>s;
    long long k; cin>>k;
    int n = s.size();
    char state = ' ';
    long long unit=0, ans;
    for(int i=0; i<n; i++){
        if(state == s[i]){
            state = ' ';
            unit++;
        }
        else state = s[i];
    }
    ans = unit*k;
    char b=s[0], e=s[n-1];
    long long bs=0, es=0;
    int idx1=0, idx2=n-1;
    if(b==e){
        while(s[idx1]==b){
            bs++;
            idx1++;
        }
        while(s[idx2]==e){
            es++;
            idx2--;
        }
    }
    ans -= (floor(bs/2)+floor(es/2)-floor((bs+es)/2))*(k-1);
    if(idx1==n) ans=floor((n*k)/2);
    cout << ans << endl;
}

Measured memory_bytes: 3600
import math

n,m=map(int,input().split())
a=list(map(int,input().split()))

if n==1:
  a1=a[0]//2
  ans_m=m//a1
  if ans_m==0:
    print(0)
  else:
    print((ans_m-1)//2+1)
  
else:
  x=a[0]
  ch=0
  ch1=0
  while x%2==0:
    x=x//2
    ch+=1
  dob=2**ch
  for i in a:
    if i%dob==0 and i%(dob*2)!=0:
      ch1+=1
  if ch1!=n:
    print(0)
  else:
    ans=a[0]//2
    for j in range(1,n):
      ans=(ans*(a[j]//2))//math.gcd(ans,a[j]//2)
    ans_m=m//ans
    if ans_m==0:
      print(0)
    else:
      print((ans_m-1)//2+1)
    
      


Measured memory_bytes: 20276
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int x,h,m,s;
    cin >> x;
    h=x/3600;
    m=(x%3600)/60;
    s=x%60;
    cout << h;
    cout << ":";
    cout << m;
    cout << ":";
    cout << s;
    cout << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define deg_to_rad(deg) (((deg)/360)*2*PI)

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;
// cout << fixed << setprecision(10) << middle << endl;

int main() {
    // input, ready
    int A,B;
    cin >> A >> B;

    // output
    cout << A*B << endl;

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	ll w;
	cin>>s>>w;
	vector<string> ans;
	string buf="";
	REP(i,(ll)s.size()) {
		buf+=s[i];
		if(buf.size()==w) {
			ans.pb(buf);
			buf="";
		}
	}
	if(buf!="") ans.pb(buf);
	string ansans="";
	REP(i,ans.size()) ansans+=ans[i][0];
	cout<<ansans<<endl;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string N;
	std::cin >> N;
	if (N[0] == '9' || N[1] == '9')
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  bitset<4000001> bs(1);
  rep(i,N) bs=bs|(bs<<A[i]);
  int sum=0;
  rep(i,N) sum+=A[i];
  rep(i,4000001){
    if(i>=(sum+1)/2 and bs[i]){
      cout<<i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    
    vector<int> s(m);
    vector<char> c(m);
    rep(i, m) cin >> s[i] >> c[i];
    rep(x, 1000) {
        string x_str = to_string(x);
        if(x_str.size() != n) continue;
        bool ok = true;
        rep(i,m) {
            if(x_str[s[i]-1] != c[i]) ok = false;
        }
        if(ok) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    /*
    int st = 1, end;
    if( n == 1){
        st = 0;
        end = 9;
    } else {
        rep(i,n-1) st*=10;
        end = st*10-1;
    }

    auto bit_num = [](int n,int bit) {
        int dig = 1;
        rep(i,bit-1) dig*=10;
        return (n%(dig*10))/dig;
    };
    for(int i = st; i <= end; i++) {
        bool end = false;
        rep(j,m) {
            if(bit_num(i,n-s[j]+1) != c[j]) end = true;;
        }
        if(end) continue;
        cout << i << endl;
        return 0;
    }
    cout << -1 << endl;
    */
}


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

using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

constexpr lint INF = 1'010'000'000'000'000'017LL;
constexpr lint MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(lint i = (start); i < end; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }

lint mod(lint val, lint m){ lint res = val % m; if(res < 0) res += m; return res;}
lint modinv(lint a, lint m) { lint b = m, u = 1, v = 0; while (b) { lint t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u;}
lint modpow(lint a, lint n, lint mod) { lint res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
lint gcd(lint a, lint b){ if(a < b) swap(a, b); if(b == 0) return a; return gcd(b, a%b);}
lint lcm(lint a, lint b){ return a * b / gcd(a, b);}


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

void Main()
{
    lint N;
    string S;
    cin >> N;
    cin >> S;

    REP(i, (lint)S.length()){
        S[i] += N;
        if(S[i] > 'Z'){
            S[i] -= 'Z' - 'A' + 1;
        }
    }
    cout << S << endl;
}

//---------------------------------------------------------------
int main()
{
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

K = int(input())
answer = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for h in range(1,K+1):
            answer += gcd(i,j,h)
print(answer)

Measured memory_bytes: 69896
import sys
input = sys.stdin.readline
from functools import lru_cache

size = [0] * 51

@lru_cache(100000)
def rec(l, x):
	global size
	# print(l, x)
	if l == 0:
		# print(x)
		return x
	mid = size[l] // 2 + 1
	if x == size[l]:
		return 2 * rec(l-1, size[l-1]) + 1
	elif x == mid:
		return rec(l-1, size[l-1]) + 1
	elif x == 1:
		return 0
	elif x > mid:
		return rec(l-1, size[l-1]) + rec(l-1, x-size[l-1]-2) + 1
	else:
		return rec(l-1, x-1)

def main():
	global size
	n, x = map(int, input().strip().split())
	size[0] = 1
	for i in range(1, 51):
		size[i] = 2 * size[i-1] + 3
	# print(rec(1, size[1]))
	print(rec(n, x))

if __name__ == '__main__':
	main()


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

using namespace std;

#define ll long long
#define ar array



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

    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0;i < (int)n; i++){
      cin >> arr[i];
    }
    map<int,int> maps;
    for(int i = 0;i < (int)n; i++){
        maps[arr[i]] = i+1;    
    }       
    for(auto itr : maps){
      cout << itr.second << " ";
    }
    return 0;
}


Measured memory_bytes: 8288
use proconio::input;

const D: usize = 365;
const V: usize = 26;

fn main() {
    input! {
        d: usize,
        cc: [i32; V],
        ss: [[i32; V]; d],
    }
    assert_eq!(d, D);

    let mut last = vec![0; V];
    for d in 0..D {
        let day = d as i32 + 1;
        let mut best_score = std::i32::MIN;
        let mut best_v = 0;
        for i in 0..V {
            let gain = ss[d][i] + cc[i] * (day - last[i]);
            if gain > best_score {
                best_score = gain;
                best_v = i;
            }
        }
        last[best_v] = day;
        println!("{}", best_v + 1);
    }
}


Measured memory_bytes: 2260
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){
  int n, i, j;
  int a, b, c;
  int* DP[3];
  int* activities[3];
  //inizializzazione
  scanf("%d", &n);
  for(i=0; i<3; i++){
    DP[i] = new int[n];
    activities[i] = new int[n];
  }
  for(i=0; i<n; i++){
    DP[0][i] = 0;
    DP[1][i] = 0;
    DP[2][i] = 0;

    scanf("%d %d %d", &a, &b, &c);
    activities[0][i] = a;
    activities[1][i] = b;
    activities[2][i] = c;

  }
  DP[0][0] = activities[0][0];
  DP[1][0] = activities[1][0];
  DP[2][0] = activities[2][0];

  for(i=1; i<n; i++){
    for(j=0; j<3; j++){
      if(j==0){
        DP[j][i] = activities[j][i] + max(DP[1][i-1], DP[2][i-1]);
      } else if(j==1){
        DP[j][i] = activities[j][i] + max(DP[0][i-1], DP[2][i-1]);
      } else { //j==2
        DP[j][i] = activities[j][i] + max(DP[1][i-1], DP[0][i-1]);
      }
    }
  }

  int m = 0;
  for(j=0; j<3; j++){
    m = max(DP[j][n-1], m);
  }
  printf("%d", m);
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<string>
#define rep(i,a,b) for(long long int i=(a);i<(b);i++)
#define se(a) a.begin(),a.end()
#define ll long long int
#define mll map<ll,ll>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e16
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll a[25][25],allmask,dp[22][2100000];
ll n;
ll solve(ll index,ll mask)
{
	if(mask==allmask)
	return 1;
	if(index>=n)
	{
//		cout<<mask<<endl;
		return 0;
	}
	if(dp[index][mask]!=-1)
	return dp[index][mask];
	ll ans=0;
	for(int i=0;i<n;i++)
	if(a[index][i])
	{
		if(mask&(1<<i))
		continue;
		ans=(ans+solve(index+1,mask|(1<<i)))%mod;
	}
//	return ans;
	return dp[index][mask]=ans;
}
int main()
{
	boost;
	cin>>n;
	rep(i,0,n)
	rep(j,0,n)
	cin>>a[i][j];
	allmask=(1<<n)-1;
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,0)<<endl;
}

Measured memory_bytes: 361216
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define F first
#define S second
#define X real()
#define Y imag()
#define PB push_back 
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef complex<int> cld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut,pr> ppr;
typedef pair<string,ut> ps;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int SIZE=1001;
const int INF=1<<30;
int dist[SIZE];
Vpr edge;
int isWin[SIZE][SIZE];
int main(){
	int R,C,K;
	char c;
	cin >>R >> C >> K;
	REP(i,R)
		REP(j,C){
			scanf(" %c",&c);
			if(c=='#')
				isWin[i][j]=1;
		}
	REP(i,R)
		REP(j,C){
			if(isWin[i][j]){
				isWin[i+1][j]=max(isWin[i+1][j],isWin[i][j]-1);
				isWin[i][j+1]=max(isWin[i][j+1],isWin[i][j]-1);
			}
			else{
				isWin[i+1][j]=max(isWin[i+1][j],K);
				isWin[i][j+1]=max(isWin[i][j+1],K);
			}
		}
	if(isWin[R-1][C-1])
		cout <<"Chieno" << endl;
	else
		cout <<"Cacao" << endl;
}


Measured memory_bytes: 5100
import java.util.*;

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

        HashSet<Integer> set = new HashSet<>();
        boolean ans = true;

        for (int i = 0; i < n; i++) {
            if(!set.add(sc.nextInt())){
                ans = false;
            }
        }

        System.out.println(ans ? "YES" : "NO");
    }
}

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<" : "<<x<<endl
#define ALL(v) (v).begin(),(v).end()

typedef vector<short> vi;

int main(){
  string s,t;
  cin>>s>>t;
  int n=s.size(),m=t.size();
  int ans = 0;
  FOR(l,1,min(n,m)+1){
    set<vi> S;
    vi op(26,0);
    REP(i,l-1)op[s[i]-'a']++;
    FOR(i,l-1,n){
      op[s[i]-'a']++;
      S.insert(op);
      op[s[i+1-l]-'a']--;
    }
    op = vi(26,0);
    REP(i,l-1)op[t[i]-'a']++;
    FOR(i,l-1,m){
      op[t[i]-'a']++;
      if(S.count(op)){
        ans = l;
        break;
      }
      op[t[i+1-l]-'a']--;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 3752
n = gets.to_i
t, a = gets.split.map { |i| i.to_i }
h = gets.split.map { |i| i.to_i }

min_x = 100000
ans = -1
n.times do |i|
	if (a - (t - h[i] * 0.006)).abs < min_x
		min_x = [(a - (t - h[i] * 0.006)).abs, min_x].min
		ans = i
	end
end

p ans+1


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 素因数分解 O(√n)
// たとえば 60 = 2^2 x 3 x 5 だったら {(2, 2), (3, 1), (5, 1)} を返す
// 素因数の個数はlogn
vector<pair<ll,ll>> prime_factorize(ll n){
    vector<pair<ll,ll>> res;
    for(ll p=2;p*p<=n;p++){
        if(n%p!=0) continue;
        int num=0; // 指数
        while(n%p==0){
            num++;
            n/=p;
        }
        res.push_back({p,num});
    }
    if(n!=1) res.push_back({n,1});
    return res;
}

vector<int> num(1010);

int main() {
    int n;
    cin>>n;

    if(n==1){
        cout<<1<<endl;
        return 0;
    }

    for(int i=2;i<=n;i++){
        auto pf=prime_factorize(i);
        for(auto u : pf){
            num[u.first]+=u.second;
        }
    }

    ll ans=1;
    rep(i,1010){
        ans=(ans*(num[i]+1))%MOD;
    }
    
    cout<<ans<<endl;
}



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

int main()
{
  int n;
  cin >> n;
  map<string, int> m = { {"AC", 0}, {"WA", 0}, {"TLE", 0}, {"RE", 0} };
  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    m[s]++;
  }
	cout << "AC" << " x " << m["AC"] << endl;
	cout << "WA" << " x " << m["WA"] << endl;
	cout << "TLE" << " x " << m["TLE"] << endl;
	cout << "RE" << " x " << m["RE"] << endl;
}


Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 計算
		String result = "Alice";
		if(a == b){
		    result = "Draw";
		}else{
		    if(b == 1 || (a < b && a != 1)) result = "Bob";
		}
		
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



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

main() {
  int H, W;
  string s;
  cin >> H >> W;
  for(int i=0; i<W+2; i++){
    cout << '#';
  }
  cout << endl;
  for(int x=0; x<H; x++){
    cin >> s;
    cout << '#' << s << '#' << endl;
  }
  for(int y=0; y<W+2; y++){
    cout << '#';
  }
  cout << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
using ll = long long;
int fib[100];
int main(){
  ll n;
  cin >> n;
  fib[0] = 1;
  fib[1] = 1;
  for (ll i = 0; i < n; i++) {
    fib[i+2] = fib[i+1] + fib[i];
  }

  cout << fib[n] << endl;
  
  return 0;
}


Measured memory_bytes: 3084
#include <cstdio>

using namespace std;

int paper[10][10];

void dropInk(int ary[][2], int size, int x, int y)
{
        int nx, ny;

        for (int i = 0; i < size; i++) {
                nx = x + ary[i][0];
                ny = y + ary[i][1];
                if ((0 <= nx && nx < 10) && (0 <= ny && ny < 10)) {
                        paper[nx][ny]++;
                }
        }
}

int main()
{
        int sm[5][2] = {{-1, 0}, {1, 0}, {0, -1},
                                   {0, 0}, {0, 1}},
                md[9][2] = {{-1, -1}, {-1, 0}, {-1, 1},
                                   {0, -1}, {0, 0}, {0, 1},
                                   {1, -1}, {1, 0}, {1, 1}},
                lr[13][2] = {{-2, 0}, {-1, -1}, {-1, 0}, {-1, 1},
                                        {0, -2}, {0, -1}, {0, 0}, {0, 1}, {0, 2},
                                        {1, -1}, {1, 0}, {1, 1}, {2, 0}};
        int x, y, s;

        for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                        paper[i][j] = 0;
                }
        }
        while (scanf("%d%*c%d%*c%d", &x, &y, &s) != EOF) {
                switch (s) {
                case 1:
                        dropInk(sm, 5, x, y);
                        break;
                case 2:
                        dropInk(md, 9, x, y);
                        break;
                default:
                        dropInk(lr, 13, x, y);
                        break;
                }
        }

        int noInk = 0, most = 0;
        for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                        if (!paper[i][j]) {
                                noInk++;
                        }
                        else if (paper[i][j] > most){
                                most = paper[i][j];
                        }
                }
        }
        printf("%d\n%d\n", noInk, most);

        return 0;
}

Measured memory_bytes: 2584
#include<iostream>
#include<vector>

using namespace std;

int main(int argc,char* argv[])
{
  int N, S, sum = 0, Ans = 100001;
  cin >> N >> S;
  vector<int> values(N);
  for(int i = 0; i < N; i++) {cin >> values[i];}
  auto ipt = values.begin();
  auto jpt = values.begin();
  while(jpt != values.end()){
    sum += *jpt;
    jpt++;
    while(sum >= S){
      Ans = min(Ans, int(jpt-ipt));
      sum -= *ipt;
      ipt++;
    }
    if(Ans == 1) break;
  }
  if(Ans == 100001) cout << 0 << endl;
  else cout << Ans << endl;
}

Measured memory_bytes: 3148
## 1<=N<=3 0<=M<=5
N,M = map(int,input().split())
out = -1

## make directory ##
digit_val = {}
for i in range(1,M+1):
  digit_val[i] = list(map(int,input().split()))

if M == 0:
  if N == 1:
    print(0)
  else:
    out = 10 ** (N-1)
    print(out)
  exit()

for i in range(0,1000):
  str_ans = str(i)
  length = len(str_ans)
  i_count = 0 
  ## 桁数が同じか確認 ##
  if length == N:
    #print(i)
    ## 一致確認 ##
    for s in range(1,len(digit_val)+1):
      ## 指示値 ##
      digit = digit_val[s][0]
      val = digit_val[s][1]

      if int(str_ans[digit-1]) == val:
        i_count = i_count + 1
  if i_count == M:
    out = i
    break

if N == 1 and str(out)[0] == 0:
  print(0)
elif str(out)[0] == 0:
  print(-1)
else:
  print(out)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.Vector;

public class Main {

	public static void main(String[] arg) {
		Scanner ob=new Scanner(System.in);
		char c=ob.next().charAt(0);
		int x=(int )c;
		x=x+1;
		System.out.println((char)x);
	}
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> v;
    for(ll i=2;i*i<=n;i++)
    {
        if((n%i)>0) continue;
        v.push_back(0);
        while((n%i)==0)
        {
            v.back()++;
            n/=i;
        }
    }
    if(n>1) v.push_back(1);
    ll res=0;
    for(ll x:v)
    {
        for(ll i=1;x>=i;i++)
        {
            res++;
            x-=i;
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3644
import math

rows, dis = map(int, input().split())
points = [list(map(int, input().split())) for i in range(rows)]

counter = 0
for p in points:
  x, y = p
  d = math.sqrt(x**2 + y**2)
  
  if d <= dis:
    counter += 1
print(counter)

Measured memory_bytes: 45468
# this is a copy and paste.
# just for test
def honponbon(n)
  i = n.to_s[-1]
  return 'hon' if %w[2 4 5 7 9].include? i
  return 'pon' if %w[0 1 6 8].include? i
  'bon'
end

i = gets.chomp.to_i
puts honponbon(i)


Measured memory_bytes: 14352
#include<iostream>
using namespace std;
int n,a[100];

int slove(int i,int m);
int main()
{
	int i,qn,q;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	cin >> qn;
	for(i=0;i<qn;i++){
		cin >>q;
		if ( slove(0,q)){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}	
}

int slove(int i,int m)
{
	int res;
	if (m==0) return 1;
	if (i>=n) return 0;
	res =slove(i+1,m) || slove(i+1,m-a[i]);
	return res;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    string s, t;
    cin >> s >> t;

    int ans = 0;
    REP(i, 3) if(s[i] == t[i]) ans++;

    cout << ans << endl;

    return 0;
}


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

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sum = 0
prev = b[0]
for i in range(0, len(a)):
	if i == 0:
		sum += b[a[i]-1]
		prev = a[i]
	else:
		if (a[i] == prev+1):
			sum += b[a[i]-1]
			sum += c[a[i]-2]
			prev = a[i]
		else:
			sum += b[a[i]-1]
			prev = a[i]

print(sum)

Measured memory_bytes: 3064
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const char letters[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
int diff[62];char pw[129],query[129];
static inline int ask(void){int x;printf("? %s\n",query);fflush(stdout);return !scanf("%d",&x)?-1:x;}
int main(void)
{
  int total=0,len=0;
  rep(i,62){rep(j,128){query[j]=letters[i];}query[128]=0;diff[i]=128-ask();total+=diff[i];}
  rep(i,62)
  {
    if(len==0){len=diff[i];rep(j,diff[i])pw[j]=letters[i];}
    else
    {
      for(int k=diff[i],l=0;k>=1;k--)
      {
        int r=len;
        while(l<r)
        {
          int mid=(l+r+1)/2;
          rep(j,mid)query[j]=pw[j];
          rep(j,k)query[mid+j]=letters[i];
          query[mid+k]=0;
          if(ask()==total-mid-k)l=mid;else r=mid-1;
        }
        len++;rep(j,len-l){pw[len-j]=pw[len-j-1];}pw[l]=letters[i];
      }
    }
  }
  pw[len]=0;return printf("! %s\n",pw),0;
}

Measured memory_bytes: 3796
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);

		int n = sc.nextInt();
		int cost = (int)Math.ceil(n / 1000.0);
		//System.out.println(cost);
		pr.println((cost * 1000) - n);
		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 32884
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int h,w; cin>>h>>w;
  string s[h],ans[h]; rep(i,h) cin>>s[i], ans[i]=s[i];
  int dx[8]={1,1,0,-1,-1,-1,0,1}, dy[8]={0,1,1,1,0,-1,-1,-1};
  int cnt=0;
  rep(i,h){
    rep(j,w){
      cnt = 0;
      if(ans[i][j]=='#') continue;
      rep(d,8){
        if(i+dx[d]<0||i+dx[d]>=h||j+dy[d]<0||j+dy[d]>=w) continue;
        if(s[i+dx[d]][j+dy[d]]=='#') cnt++;
      }
      ans[i][j] = '0'+cnt;
    }
  }
  rep(i,h){
    rep(j,w) cout<<ans[i][j];
    cout<<endl;
  }


  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
     
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        Dice[] list = new Dice[n];
        for(int i = 0; i < n; i++) {
            list[i] = new Dice(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
        }
        for(int i = 0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                if(solv(list[i],list[j],0)) {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
    public static boolean solv(Dice f, Dice dice,int count) {
        if(dice.Top == f.Top && dice.S == f.S && dice.Bottom == f.Bottom && dice.E == f.E && dice.N == f.N && dice.W == f.W) return true;
        if(count == 6) return false;
        Dice tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnN();
        if(solv(f,tmp,count+1)) {
            return true;
        }
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        if(solv(f,tmp,count+1)) {
            return true;
        }
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnE();
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnW();
        if(solv(f,tmp,count+1)) {
            return true;
        }
         
        return false;
    }
     
     
     
}
 
class Dice {
    int Top; //1
    int Bottom; //6
    int N; //   5
    int S; //   2
    int W; //左 4
    int E; //右 3
    Dice(int a, int b, int c, int d, int e, int f) {
        Top = a;
        S = b;
        E = c;
        W = d;
        N = e;
        Bottom = f;
    }
    public void TurnN() {
        int tmp = Top;
        Top = S;
        S = Bottom;
        Bottom = N;
        N = tmp;
    }
    public void TurnW() {
        int tmp = Top;
        Top = E;
        E = Bottom;
        Bottom = W;
        W = tmp;
    }
    public void TurnE() {
        int tmp = Top;
        Top = W;
        W = Bottom;
        Bottom = E;
        E = tmp;
    }
    public void TurnS() {
        int tmp = Top;
        Top = N;
        N = Bottom;
        Bottom = S;
        S = tmp;
    }
     
}


Measured memory_bytes: 94332
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

vector<int> adj[100001];
queue<int> topsort;
int indeg[100001];
int dp[100001];

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

    int n, m, a, b;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        adj[a].push_back(b);
        indeg[b]++;
    }
    
    for(int i = 1; i <= n; i++) if(!indeg[i]) topsort.push(i);
    int node;
    while(topsort.size()){
        node = topsort.front();
        topsort.pop();
        for(unsigned int i = 0; i < adj[node].size(); i++){
            dp[adj[node][i]] = max(dp[node]+1, dp[adj[node][i]]);
            indeg[adj[node][i]]--;
            if(!indeg[adj[node][i]]) topsort.push(adj[node][i]);
        }
    }

    int maxi = -1;
    for(int i = 1; i <= n; i++) maxi = max(maxi,dp[i]);
    cout << maxi;

    return 0;

}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    string S;
    cin >> S;
    int K;
    cin >> K;

    int first_not1 = -1;
    string ans;
    REP(i, S.size()){
        if(S[i] != '1'){
            first_not1 = i;
            ans = S[i];
            break;
        }
    }

    if(first_not1 == -1 || K <= first_not1){
        cout << 1;
    }else{
        cout << ans;
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256