akhauriyash/Code-Regression huggingface dataset:
// In God We Trust


# include <bits/stdc++.h>

# define INF 1 << 31 - 1
# define pb push_back
# define fi first
# define se second
#include <algorithm>


using namespace std;




signed main()
{
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; i ++){
    cout << s[i];
    cout << t[i];
  }
  cout << endl;
}

 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
  
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ld a,b;
    cin>>a>>b;
    ll an=trunc(a*b);
    cout<<an<<endl;
    return 0;   
}

Measured memory_bytes: 3748
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math


n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
res = ''
for el in s:
    tmp = (ord(el)-65+n) % 26
    res += chr(tmp+65)

print(res)


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ull bin(ull a, ull b)
{
    if(a%mod==0) return 0;
    ull res = 1;
    a %= mod;
    while(b)
    {
        if(b&1) res = (res*a)%mod;
        b >>= 1;
        a *= a;
        a%=mod;
    }
    return res%mod;
}

int h, n;
vector<pii> vec;
ll rem[10005][1001];

int solve(int ind, int cur = 0, int mag = 0)
{
    if(cur>=h) return 0;
    if(ind>=n) return 1e9;

    ll& cur2 = rem[cur][ind];
    if(cur2==-1)
    {
        cur2 = min(solve(ind, cur+vec[ind].first) + vec[ind].second, solve(ind+1, cur));
    }
    return cur2;
}

int main()
{
    memset(rem, -1, sizeof(rem));
    cin>>h>>n;
    for(int i = 0; i<n; ++i)
    {
        int a, b;
        cin>>a>>b;
        vec.push_back({a, b});
    }

    cout<<solve(0)<<endl;
}

Measured memory_bytes: 79232
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    bool solve() {
        Int H, W;
        cin >> H >> W;
        if (H == 0) return false;
        map<char, pair<Int, Int>> mp;

        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                char c;
                cin >> c;
                mp[c] = make_pair(i, j);
            }
        }
        string s;
        cin >> s;
        Int ans = 0;
        Int h = 0, w = 0;
        auto dist = [&](Int nh, Int nw) {
            return abs(nh - h) + abs(w - nw);
        };

        for (auto e : s) {
            auto p = mp[e];
            Int nh = p.first;
            Int nw = p.second;
            Int d = dist(nh, nw);
            h = nh;
            w = nw;
            ans += d + 1;
        }
        cout << ans << endl;

        return true;
    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    while (Solve().solve());

    return 0;
}



Measured memory_bytes: 3116
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main()
{
    string s; cin >> s;
    int anum = 99999,znum=0;
    int i=0;
    while(s[i]){
        if(s[i]=='A' && anum == 99999) anum = i;
        if(s[i]=='Z') znum = i;
        i++;
    }
    cout << znum-anum+1 ;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	long long int n, m, ans;
	scanf("%lld %lld", &n, &m);

	if(n==1 && m==1){
		ans=1;
	}else if(n==1 && m!=1){
		ans=m-2;
	}else if(n!=1 && m==1){
		ans=n-2;
	}else{
		ans=(n-2)*(m-2);
	}

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

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> A;
  for (int i = 1; i <= N; i++) {
    string S;
    int P;
    cin >> S >> P;
    A.emplace_back(S, -P, i);
  }
  sort(A.begin(), A.end());
  rep(i, N) {
    cout << get<2>(A[i]) << '\n';
  }
  return 0;
}

Measured memory_bytes: 3588
//
//  main.cpp
//  adsfdsgsg
//
//  Created by h3037175 on 2017/07/31.
//  Copyright ?? 2017??´ h3037175. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <math.h>
#include<algorithm>
#include <utility>
#define nan -100000
using namespace std;
int main() {
    int ans=0,a;
    for(int i=0;i<3;i++){
        cin>>a;
        ans+=a;
    }
    cout<<ans<<endl;
    return 0;
}

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

int r, D;
int calc(long long x) {
  return r*x - D;
}

int main() {
  int x2000;
  cin >> r  >> D >> x2000;

  long long tmp = x2000;
  for (int i = 0; i < 10; ++i) {
    tmp = calc(tmp);
    cout << tmp << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int n,cnt=0;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  while (true){
    bool flag = false;
    for(int i = 0; i < n; i++){
      if(a[i] % 2 != 0){
	flag =true;
      }
    }
    if(flag){
      break;
    }
    for(int i = 0; i < n; i++){
      a[i]/=2;
    }
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 22 21:05:46 2020

@author: NEC-PCuser
"""

N = int(input())

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

ans = 0
before_people = A[0]
for i in range(1, len(A)):
	if before_people > A[i]:
		ans += (before_people - A[i])
	else:
		before_people = A[i]

print(ans)

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

#define IL inline 
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f; 
}

int n;
int a[150];
int main() {
	n = read();
	int ans = INT_MAX;
	for (int i = 1; i <= n; ++i) a[i] = read();
	for (int i = -100; i <= 100; ++i) {
		int now = 0;
		for (int j = 1; j <= n; ++j) 
			now += (i - a[j]) * (i - a[j]);
		ans = min(ans, now);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  long long N;
  cin >> N;
  map<long long,int> P;
  for(long long i = 2; i*i <= N; ++i){
    if(N%i) continue;
    while(N%i == 0){
      ++P[i];
      N /= i;
    }
  }
  if(N != 1) ++P[N];
  int ans = 0;
  for(auto [p, e] : P){
    for(int i = 1; i < 100; ++i){
      if(e < i) break;
      ++ans;
      e -= i;
    }
  }
  cout << ans << endl;
}


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

int main() {
    int init=0;
    char a;
	for(int i=0;i<4;i++){
	    scanf("%c",&a);
	    if(a=='-') init+=-1;
	    else init+=1;
	}
	printf("%d", init);
	return 0;
}


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

int n,a;


int main(){
  cin>>n>>a;
  int s=n/500;
  
  if( n<500 && a>=n ){
    cout<<"Yes"<<endl;
  }
  
  else if ( 500*s<n<500*(s+1) && a>=n-500*s){
    cout<<"Yes"<<endl;
  }
  
  else if ( 0==n%500){
    cout<<"Yes"<<endl;
  }
  
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
 using namespace std;
ll n,t,m,c1,c2,c,x,y,sum,mn=999999999,avg,pos,dif,j,dis,mx,xi,yi,q;
vector<ll>v;
set<ll>s;
map<ll , ll >mp;
bool PE(int x)
{
for (int i=2;i*i<=x;i++)
if (x%i==0)
return false;
return true;
}
bool PR(string s)
{
int n=s.length();
for(int i=0;i<n/2;i++)
if(s[i]!=s[n-i-1])
return false;
return true;
}

int main(void)
{ SpeeD;
cin>>n>>m;
if (n>m)cout<<"safe";
else cout<<"unsafe";
}


Measured memory_bytes: 3656
#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>
#include<bitset>
using namespace std;
typedef long long ll;
ll a;
ll b;
long long xorA(long long x){
    if(x%4==0) return x;
    else if(x%4==1) return  1;
    else if(x%4==2) return x+1;
    else return 0;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a>>b;
    long long ans=xorA(a-1)^xorA(b);
    cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int data[100];
	int c;
	int sum;
	int i;
	int number;
	_Bool finish = 0;
	while(1) {
		i = sum = 0;
		while(1){
			if ((c = getchar()) != EOF) {
				if (c == '\n')
					break;
				else if (c == 'I')
					data[i] = 1;
				else if (c == 'V')
					data[i] = 5;
				else if (c == 'X')
					data[i] = 10;
				else if (c == 'L')
					data[i] = 50;
				else if (c == 'C')
					data[i] = 100;
				else if (c == 'D')
					data[i] = 500;
				else if (c == 'M')
					data[i] = 1000;
			}
			else {
				finish = 1;
				break;
			}
			i++;
		}
		if (finish)
			break;
		number = i;
		for (i = 0; i < number; i++) {
			if( i+1 < number && data[i] < data[i+1]) {
				sum += data[i+1] - data[i];
				i++;
			}
			else
				sum += data[i];
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 520
#include <iostream>

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

    if (a < b)
    {
        std::cout << "a < b" << std::endl;
    } 
    else if (a > b)
    {
        std::cout << "a > b" << std::endl;
    }
    else
    {
        std::cout << "a == b" << std::endl;

    }

    return 0;
}



Measured memory_bytes: 3092
from sys import *
N,M = map(int,stdin.readline().split())
items = list(map(int, stdin.readline().split()))
total = sum(items)
items.sort(reverse = True)
count = 0
for item in items[0:M]:
    if item < total * (1/(4*M)):
        print("No")
        exit()
print("Yes")


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

int main()
{
  ll n;
  cin >> n;
  ll ara[n+10];
  for(ll i=0; i<n; i++)
  {
      cin >> ara[i];

  }
  ll sum = 0;
  for(ll i=1; i<n; i++)
  {
      if(ara[i]<ara[i-1])
      {
          sum += ara[i-1] - ara[i];
          ara[i] = ara[i-1];
      }

  }
  cout << sum << endl;


}


Measured memory_bytes: 5192
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = list()
for i in range(len(a)):
  l.append(1) if a[i] >= (sum(a) * (1/(4*m))) else l.append(0)
print('Yes') if sum(l) >= m else print('No')

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

int main(){
  int n, num;
  int ans = 1000000;
  cin >> n;
  vector<int> W(n + 1);
  W[0] = 0;
  for (int i = 1; i < n + 1; i++){
    cin >> num;
    W[i] = W[i - 1] + num;
  }
  rep(i ,n + 1){
    ans = min(ans, abs((W[n] - W[i]) - W[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int L, R, D;
  cin>>L>>R>>D;
  L += (D-L%D)%D;
  R -= R%D;
  cout<<(R-L)/D+1<<endl;
}


Measured memory_bytes: 3536
import java.util.Scanner;

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

		int K = scan.nextInt();
		int ans = 0;

		for(int i = 1;i <= K;i++) {
			for(int j = 1;j <= K;j++) {
				for(int k = 1;k <= K;k++) {
					ans += gcd(i,gcd(j,k));
				}
			}
		}

		System.out.println(ans);

	}

	static int gcd(int a,int b) {
		int temp;
		while((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}

}

Measured memory_bytes: 27224
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
using namespace std;

#define max_n 100001
#define max_m 50
#define max_w 1000
#define max_h 1000
#define max_k 10000
#define max_l 10000
#define INF 9999999

typedef long long lint;

int main()
{
    int x=0;
    cin>>x;
    int count=0;
    int a=0;
    for(int i=1;i<INF;i++){
        a+=i;
        count++;
        if(a>=x){
            break;
        }
    }
    cout<<count<<endl;
    return 0;
}


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

lli gcd(lli a, lli b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

lli lcm(lli a, lli b) {
    return a * b / gcd(a, b);
}

lli div_count(lli low, lli high, lli div) {
    lli count = 0;
    count += (high / div) - (low / div);
    if (low % div == 0)
        count += 1;
    return count;
}

void trace(lli num) {
    cout << "trace << " << num << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    lli a, b, c, d, count = 0;
    cin >> a >> b >> c >> d;

    count += (b - a + 1);
    count -= div_count(a, b, c);
    count -= div_count(a, b, d);
    count += div_count(a, b, lcm(c, d));
    cout << count << endl;

    // trace(b - a + 1);
    // trace(div_count(a, b, c));
    // trace(div_count(a, b, d));
    // trace(div_count(a, b, lcm(c, d)));
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
 int W,H;
 int x,y,r;
 scanf ("%d%d%d%d%d",&W,&H,&x,&y,&r);
 if(0<=x-r && 0<=y-r && x+r<=W && y+r<=H){
 printf("Yes\n");
 }else{
 printf("No\n");
 }
 return 0;
 }

Measured memory_bytes: 584
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n,x;
  cin >> n >> x;

  vector<ll> p(n),l(n);
  rep(i,n) cin >> p[i];

  rep(i,n)
  {
    l[i] = abs(p[i]-x);
  }

  ll ans = 0;

  if(n == 1)
  {
    ans = l[0];
  }
  else
  {
    ans = GCD(l[0],l[1]);
  }
  

  rep(i,n)
  {
    ans = GCD(ans,l[i]);
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 1792
N = int(input())
S = [0 for i in range(N)]
for i in range(N):
    S[i] = input()

# 各文字列中のABの個数をカウント
L = [0 for i in range(N)]
for i in range(N):
    l = len(S[i])
    count = 0
    for j in range(l-1):
        if S[i][j] == 'A' and S[i][j+1] == 'B':
            count += 1
    L[i] = count

# a = 'B...A', b = 'B...notA', c = 'notB...A'
a, b, c = 0, 0, 0
for i in range(N):
    l = len(S[i])
    if S[i][0] == 'B' and S[i][l-1] == 'A':
        a += 1
    elif S[i][0] == 'B':
        b += 1
    elif S[i][l-1] == 'A':
        c += 1

Lsum = sum(L)
if a != 0 and b != 0 and c != 0:
    print(Lsum + (a+1) + min(b-1, c-1))
elif a != 0 and b == 0 and c != 0:
    print(Lsum + a)
elif a != 0 and b != 0 and c == 0:
    print(Lsum + a)
elif a != 0 and b == 0 and c == 0:
    print(Lsum + a -1)
elif a == 0 and b != 0 and c != 0:
    print(Lsum + min(b, c))
else:
    print(Lsum)

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


int main() {
  int h,w;
  cin >> h>>w;
  vector<vector<char>>s(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
      cin>>s.at(i).at(j);
    }
  }
  vector<vector<int>>x(h,vector<int>(w));
  rep(i,h){
    int co=0;
    rep(j,w){
      if(s.at(i).at(j)=='.'){
        co++;
        x.at(i).at(j)=co;
      }
      else{
        co=0;
      }
    }
    for(int j=w-2;j>=0;j--){
      if(x.at(i).at(j)!=0&&x.at(i).at(j+1)>0){
        x.at(i).at(j)=x.at(i).at(j+1);
      }
    }
  }
  
  vector<vector<int>>y(h,vector<int>(w));
  rep(i,w){
    int co=0;
    rep(j,h){
      if(s.at(j).at(i)=='.'){
        co++;
        y.at(j).at(i)=co;
      }
      else{
        co=0;
      }
    }
    for(int j=h-2;j>=0;j--){
      if(y.at(j).at(i)!=0&&y.at(j+1).at(i)>0){
        y.at(j).at(i)=y.at(j+1).at(i);
      }
    }
  }
  int ans=0;
  rep(i,h){
    rep(j,w){
      ans=max(ans,x.at(i).at(j)+y.at(i).at(j)-1);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 35584
#define M 10001
n[M];main(i,j){n[0]=n[1]=1;for(i=2;i<M;i++)if(!n[i])for(j=i*2;j<M;j+=i)n[j]=1;for(;scanf("%d",&i),i;printf("%d %d\n",i-2,i))for(;n[i-2]||n[i];i--);exit(0);}

Measured memory_bytes: 636
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;
const int MAXN = 234567;
bool visit[MAXN];
vector<int> G[MAXN];

int dfs(int cur) {
    visit[cur] = 1;
    int sum = 0;
    for (auto i : G[cur]) {
        if (visit[i]) continue;
        sum += dfs(i);
    }
    return sum + 1;
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (visit[i]) continue;
        ans = max(ans, dfs(i));
    }
    printf("%d\n", ans);

    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


Measured memory_bytes: 24944
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,a[1000],ans;
int main(void){
    while(1){
    cin>>n;
    if(n==0)return 0;
    ans=1000000;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n-1;i++){
        ans=min(ans,a[i+1]-a[i]);
    }
    cout<<ans<<endl;
    }
}



Measured memory_bytes: 3024
input = readlines()

n, x = input.shift.chomp.split("\s").map{|x| x.to_i}
list = input.shift.chomp.split("\s").map{|x| x.to_i}

cnt = 1
tmp = 0
list.each do |l|
  tmp += l
  cnt += 1 if tmp <= x
end

puts cnt


Measured memory_bytes: 14148
N, T = map(int, input().split())
A = list(map(int, input().split()))
min_A = 1000000001
max_diff = 0
ans = 0
for i in A:
    min_A = min(min_A, i)
    if i - min_A == max_diff:
        ans += 1
    if i - min_A > max_diff:
        max_diff = i - min_A
        ans = 1
print(ans)

Measured memory_bytes: 62832
#coding: euc-jp
class Main
  def self.main
    s = read
    n = s.length
    count = 0
    col = s[0].to_i
    1.upto (n-1) do |i|
      col = (col + 1) % 2
      count += 1 if s[i].to_i != col
    end
    count = count <= n / 2 ? count : n - count
    puts count
  end

  def self.read
    gets.chomp
  end
end

Main.main


Measured memory_bytes: 2044
def read():
    return int(input())


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


def readmap():
    return map(int, input().split())


N = read()
A, B = readmap()
P = readlist()

a = 0
b = 0
c = 0

for p in P:
    if p <= A:
        a += 1
    elif p <= B:
        b += 1
    else:
        c += 1

print(min(a,b,c))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
int main()
{
	string s,t;
	cin>>s>>t;
	ll cnt = 0;
	for(int i=0;i<s.size();i++)cnt+=(s[i] == t[i]);
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3616
N,K=map(int,input().split())
A=list(map(int,input().split()))

dic={}

i=0
dic[1]=i
next_town=1

while True:
    next_town=A[next_town-1]
    K -=1
    i +=1
    if K==0:
        print(next_town)
        break
    elif next_town in dic:
        lp_st=dic[next_town]
        lp_len=i-lp_st

        L=K%lp_len

        if L==0:
            print(next_town)
            break
        else:
            K=L

    else:
        dic[next_town]=i


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

int main ()
{
  ios::sync_with_stdio(false);
  string s1;
  string s2;
  cin >> s1 >> s2;
  if (s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]) {
    cout << "YES" << "\n";
  } else {
    cout << "NO" << "\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    ll dp[2000][100];
    ll i,j,k,x,d,a;
    ll inf = 1 << 30;
    ll ans=inf;
    vector<PP> v[200]; 
    for(i=0;i<200;i++) v[i].clear();
    ll c=0;
    for(i=0;i<n;i++){
      cin >> k;
      for(j=0;j<k;j++){
	cin >> x >> d;
	v[i].push_back(PP(c,P(x,d)));
	c++;
      }
    }
    //cout << c << endl;
    fill(dp[0],dp[1999],inf);
    for(i=0;i<v[0].size();i++){
      dp[v[0][i].first][0]=0;
    }
    for(i=0;i<v[1].size();i++){
      dp[v[1][i].first][1]=0;
    }
    for(i=0;i<n;i++){
      for(j=0;j<v[i].size();j++){
	
	for(a=0;a<=m;a++){
	  
	  if(dp[v[i][j].first][a]==inf) continue;
	  
	  for(k=0;k<v[i+1].size();k++){
	    dp[v[i+1][k].first][a]=min(dp[v[i+1][k].first][a],
				       dp[v[i][j].first][a]
				       +abs(v[i+1][k].second.first-v[i][j].second.first)
				       *(v[i+1][k].second.second+v[i][j].second.second));		       
	  }
	  for(k=0;k<v[i+2].size();k++){
	    dp[v[i+2][k].first][a+1]=min(dp[v[i+2][k].first][a+1],
				       dp[v[i][j].first][a]
				       +abs(v[i+2][k].second.first-v[i][j].second.first)
				       *(v[i+2][k].second.second+v[i][j].second.second));
	  }
	}
      }
    }
    ans=inf;
    for(i=0;i<v[n-1].size();i++){
      for(j=0;j<=m;j++){
	ans=min(ans,dp[v[n-1][i].first][j]);
      }
    }
    for(i=0;i<v[n-2].size();i++){
      for(j=0;j<=m-1;j++){
	ans=min(ans,dp[v[n-2][i].first][j]);
      }
    }
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2836
A = int(input())
B = int(input())
C = int(input())
X = int(input())

A_max = int(X / 500) if int(X / 500) <= A else A
B_max = 0
C_max = 0
X_tmp_a = X
X_tmp_b = X
count = 0

for a in range(A_max + 1):
    X_tmp_a = X - 500 * a
    B_max = int(X_tmp_a / 100) if int(X_tmp_a / 100) <= B else B
    for b in range(B_max + 1):
        X_tmp_b = X_tmp_a - 100 * b
        if int(X_tmp_b / 50) <= C:
            C_max = int(X_tmp_b / 50)
            count += 1

print(count)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,A,B,C,D;
char S[200010]; 
int main(){
  cin>>N>>A>>B>>C>>D;
  A--;B--;C--;D--;
  rep(i,N) cin>>S[i];
  if(C<D){
    bool f=true;
    for(int i=A;i<D;i++){
      if(S[i]=='#'&&S[i+1]=='#'){
	f=false;
	break;
      }
    }
    if(f) prin("Yes");
    else prin("No");
  }
  else{
    bool f=true,ff=false;
    for(int i=A+1;i<C;i++){
      if(S[i]=='#'&&S[i+1]=='#'){
	f=false;
	break;
      }
    }
    for(int i=B-1;i<D;i++){
      if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.'){
	ff=true;
	break;
      }
    }
    //    prin2(f,ff);
    if(f&&ff) prin("Yes");
    else prin("No");
  }
      

  return 0;
}


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

ans, tmp = 0, 10000000
for i in range(n):
    if abs(a - (t - h[i] * 0.006)) < tmp:
        tmp = abs(a - (t - h[i] * 0.006))
        ans = i

print(ans + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n, i, temp, A[3][3], j, k;
bool cond, vis[3][3];
int main()
{
    memset(vis, false, sizeof(vis));
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin >> A[i][j];
        }
    }
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> temp;
        for(j=0;j<3;j++)
        {
            for(k=0;k<3;k++)
            {
                if(A[j][k]==temp)
                    vis[j][k] = true;
            }
        }
    }
    for(i=0;i<3;i++)
    {
        if(vis[i][0] && vis[i][1] && vis[i][2]) cond = true;
        if(vis[0][i] && vis[1][i] && vis[2][i]) cond = true;
    }
    if(vis[1][1] && vis[2][2] && vis[0][0]) cond = true;
    if(vis[0][2] && vis[1][1] && vis[2][0]) cond = true;
    if(cond)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3612
n = int(input())
s = [input() for _ in range(n)]
cnt = [float('inf')] * 26
for i in range(n):
    tmp = [0] * 26
    for j in s[i]:
        tmp[ord(j) - ord('a')] += 1
    for k in range(26):
        cnt[k] = min(cnt[k], tmp[k])
ans = ''
for i in range(26):
    for j in range(cnt[i]):
        ans += chr(ord('a') + i)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

ll sigma(ll n)
{
    return n*(n+1)/2;
}
int main()
{
    ll N;
    cin >> N;
    ll ans = sigma(N) + 15*sigma(N/15) - 3*sigma(N/3) - 5*sigma(N/5);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	int D;
	int X;
	int a[100];
	int i;
	int k;
	int t;
	int c=0;
	cin>>N>>D>>X;
	for(i=0;i<N;++i)
	{
		cin>>a[i];
	}
	for	(k=0;k<N;++k)
	{
		t=0;
		while(1)
		{
			if(t*a[k]+1<=D)
			{
				++c;
				//cout<<k<<", "<<c<<", "<<t<<", "<<a[k]<<endl;
			}
			else
			{
				//cout<<"break:"<<k<<", "<<c<<", "<<t<<", "<<a[k]<<endl;
				break;	
			}	
			t++;
		}	
	}	
	c+=X;
	cout<<c;
} 

Measured memory_bytes: 256
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()
ans = min(w , h)
for x in range(1, w):
    blocks = [h * x, h // 2 * (w - x), (h - h // 2) * (w - x)]
    ans = min(ans, max(blocks) - min(blocks))
for y in range(1, h):
    blocks = [w * y, w // 2 * (h - y), (w - w // 2) * (h - y)]
    ans = min(ans, max(blocks) - min(blocks))
print(ans)

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> S;
    for (int i = 0, s = 0, w; i < N; ++i) {
        cin >> w;
        S.push_back(s += w);
    }

    int ans = 1<<30;
    for (int i = 0; i < N-1; ++i) {
        int d = S[i] - (S[N-1] - S[i]);
        if (d < 0) d *= -1;
        ans = min(ans, d);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
//using Graph = vector<vector<int>>;

signed main(){
  int N, M;
  cin >> N >> M;

  vector<vector<int>> G(N, vector<int>(N, INF));
  vector<pair<int, int>> E(M);
  vector<int> cost(M);
  for( int i = 0; i < N; i++ ) G.at(i).at(i) = 0;
  for( int i = 0; i < M; i++ ){
    int A, B, C;
    cin >> A >> B >> C;
    A--; B--;
    G.at(A).at(B) = C;
    G.at(B).at(A) = C;
    E.at(i) = {A, B};
    cost.at(i) = C;
  }

  for (int k = 0; k < N; k++){       // 経由する頂点
    for (int i = 0; i < N; i++) {    // 始点
      for (int j = 0; j < N; j++) {  // 終点
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }

  vector<bool> fg(M, true);
  for( int i = 0; i < M; i++ ){
    for( int s = 0; s < N; s++ ){
      for( int t = s+1; t < N; t++ ){
        //s, t = 最短経路を見る二頂点
        int A = G[s][E.at(i).first] + cost.at(i) + G[E.at(i).second][t];
        int B = G[s][E.at(i).second] + cost.at(i) + G[E.at(i).first][t];
        if( A == G[s][t] || B == G[s][t] ) fg.at(i) = false;
      }
    }
  }
  int ans = 0;
  for( int i = 0; i < M; i++ ){
    if( fg.at(i) ) ans++;
  }
  cout << ans << endl;

 }


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		List<long> L = new List<long>();
		for(int i=0;i<N;i++) L.Add(X[i]);
		bool z = X.Contains(0);
		if(z == false){
			L.Add(0);
		} else {
			K--;
		}
		
		L.Sort();
		if(K == 0) {
			Console.WriteLine(0);
			return;
		}
		
		int idx = -1;
		int NN = L.Count;
		for(int i=0;i<NN;i++){
			if(L[i] == 0) idx = i;
		}
//Console.WriteLine(String.Join(" ", L));		
		long min = (long) 1e18;
		for(int j = idx - K; j <= idx + K; j++){
			if(j < 0 || j >= NN) continue;
			long c = Math.Abs(L[j]);
			if(j == idx - K || j == idx + K){
				min = Math.Min(c, min);
				continue;
			}
			c += Math.Abs(L[j]);
			int rest = K - Math.Abs(j - idx);
			int nj = j < idx ? idx + rest : idx - rest;
			if(nj < 0 || nj >= NN) continue;
			c += Math.Abs(L[nj]);
//Console.WriteLine("{0} {1}",j, c);
			min = Math.Min(min, c);
			
		}
		
		
		Console.WriteLine(min);
		
		
		
	}
	int N,K;
	long[] X;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		X = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 30300
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()

a = A[1] - A[0]

for i in range(1,N):
    b = A[i] - A[i-1]
    c = max(a,b)
    a = c

d = K - A[-1] + A[0]

e = max(c,d)

print(K-e)

Measured memory_bytes: 26436
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Work> works = new ArrayList<>();
        while (true) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            int w = sc.nextInt();
            if (s == 0 && t == 0 && w == 0) {
                break;
            }
            works.add(new Work(s, t, w));
        }
        int l = sc.nextInt();
        int[][] fees = new int[l][m + 1];
        for (int i = 0; i < l; i++) {
            for (int j = 1; j <= m; j++) {
                fees[i][j] = sc.nextInt();
            }
        }
        int[][] matrix = new int[l][n + 1];
        for (Work w : works) {
            for (int i = 0; i < l; i++) {
                matrix[i][w.person] += fees[i][w.type] * w.count;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < l; i++) {
            for (int j = 1; j <= n; j++) {
                if (j != 1) {
                    sb.append(" ");
                }
                sb.append(matrix[i][j]);
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
    
    static class Work {
        int person;
        int type;
        int count;
        
        public Work(int person, int type, int count) {
            this.person = person;
            this.type = type;
            this.count = count;
        }
    }
}


Measured memory_bytes: 299732
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

struct data{
	int lid,rid;
	int id;
	int l,r;
	data(){}
	data(int iid,int ll,int rr,int lll,int rrr){
		id=iid;
		lid=ll;
		rid=rr;
		l=lll;
		r=rrr;
	}
};

vector<data> dat;
map<int,int> id;
vector<int> iddata;
vector<int> place[10001];
int n;
int st,en;

int main(void){
	while(1){
		dat.clear();
		id.clear();
		iddata.clear();
		for(int i=0;i<=10000;i++)place[i].clear();
		st=-1;
		en=-1;
		scanf("%d%*c",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			char c;
			scanf("%c",&c);
			if(c=='W'){
				int l,s;
				scanf("%d %d%*c",&l,&s);
				if(id.find(l)==id.end()){
					id[l]=iddata.size();
					iddata.push_back(l);
				}
				if((dat.size()==0 || st==-1)){
					dat.push_back(data(id[l],-1,-1,0,s));
					st=dat.size()-1;
					en=dat.size()-1;
					place[id[l]].push_back(dat.size()-1);
				}else{
					int v=0;
					int nv=st;
					if(dat[st].l>0){
						dat.push_back(data(id[l],-1,st,0,min(s,dat[st].l)));
						place[id[l]].push_back(dat.size()-1);
						dat[st].lid=dat.size()-1;
						s-=min(s,dat[st].l);
						st=dat.size()-1;
					}
					nv=dat[nv].rid;
					while(s>0 && nv!=-1){
						if(dat[nv].l!=dat[dat[nv].lid].r){
							dat.push_back(data(id[l],dat[nv].lid,nv,dat[dat[nv].lid].r,dat[dat[nv].lid].r+min(s,dat[nv].l-dat[dat[nv].lid].r)));
							place[id[l]].push_back(dat.size()-1);
							s-=min(s,dat[nv].l-dat[dat[nv].lid].r);
							dat[dat[nv].lid].rid=dat.size()-1;
							dat[nv].lid=dat.size()-1;
						}
						nv=dat[nv].rid;
					}
					if(s>0){
						dat.push_back(data(id[l],en,-1,dat[en].r,dat[en].r+s));
						place[id[l]].push_back(dat.size()-1);
						dat[en].rid=dat.size()-1;
						en=dat.size()-1;
					}
				}
			}
			if(c=='D'){
				int l;
				scanf("%d%*c",&l);
				if(id.find(l)==id.end())continue;
				for(int i=0;i<place[id[l]].size();i++){
					data d=dat[place[id[l]][i]];
					if(d.lid==-1)st=d.rid;
					if(d.rid==-1)en=d.lid;
					if(d.rid!=-1)dat[d.rid].lid=d.lid;
					if(d.lid!=-1)dat[d.lid].rid=d.rid;
				}
				place[id[l]].clear();
			}
			if(c=='R'){
				int p;
				scanf("%d%*c",&p);
				int nv=st;
				if(nv!=-1){
					while(dat[nv].r<=p){
						nv=dat[nv].rid;
						if(nv==-1)break;
					}
				}
				if(nv!=-1)printf("%d\n",(dat[nv].l<=p && p<dat[nv].r)?iddata[dat[nv].id]:-1);
				else printf("-1\n");
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 48124
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
inline int BobEven(int n,int *A)
{
    int mid=n/2;
    int Ans=A[mid+1]-A[1];
    for(int i=2;i<=mid;i++)
        Ans=min(Ans,A[mid+i]-A[i]);
    return Ans;
}
inline int AliceOdd(int n,int *A)
{
    int mid=n/2;
    for(int i=mid+1;i<n;i++)A[i]=A[i+1];
    return BobEven(n-1,A);
}
inline bool Check(int n,int *A,int v)
{
    int cnt=0;
    for(int i=1,j=1;i<=n;i=j+1,j=i,cnt++)
        while(j<n && A[j+1]-A[i]<v)j++;
    return (cnt>(n/2));
}
inline int AliceEven(int n,int *A)
{
    int L=1,R=A[n]-A[1];
    while(L+1<R)
    {
        int mid=(L+R)>>1;
        if(Check(n,A,mid))L=mid;
        else R=mid-1;
    }
    return Check(n,A,R)?R:L;
}
inline int BobOdd(int n,int *A)
{
    return min(AliceEven(n-1,A),AliceEven(n-1,A+1));
}
int n;
int A[maxn];
int main()
{
// 233
    int n,Ans;
    string S;
    cin>>n>>S;
    for(int i=1;i<=n;i++)
        cin>>A[i];
    if(S[0]=='A')Ans=n&1?AliceOdd(n,A):AliceEven(n,A);
    else Ans=n&1?BobOdd(n,A):BobEven(n,A);
    cout<<Ans<<endl;
    return 0;
}
 

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] s = reader.readLine().split(" ");
        for (int i = 0; i < s.length; i++) {
            if (s[i].equals("0")) {
                System.out.println(i+1);
                break;
            }
        }
    }
}


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

int main(){
  int N;
  int k;

  while(true){
    cin >> N;

    if(N == 0) break;
    

    bool work = false;
    int cnt = 0;
    for(int i=0;i<N;++i){
      cin >> k;
      if(k >= 2){
	work = true;
      }
      if(k>=1){
	++cnt;
      }
    }
    if(!work){
      cout << "NA" << endl;
      continue;
    }

    cout << cnt + 1 << endl;
    
  }
  
  return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 2000000000;

ll n;
int ans = INF;

int func(int a, int b){
  string s = to_string(a);
  string t = to_string(b);
  a = s.size();
  b = t.size();
  return max(a, b);
}
  
int main(){
  cin >> n;
  for(int i = 1; i <= sqrt(n)+1; i++){
    if(n%i==0) ans = min(ans, func(i,n/i));
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int n; string s; cin >> n >> s;
    int res = 0;

    vector<vector<int>> dp(n+1, vector<int>(n+1, 0));
    //dp[i][j] = i文字目からとj文字目からとで最長の長さ
    //loopは前からか後ろからか
    per(i, n) {
        for(int j = n - 1; j > i; --j) {
            if(s[i] == s[j]) chmax(dp[i][j], dp[i+1][j+1] + 1);
            chmax(res, min(dp[i][j], j - i));
        }
    }
    cout << res << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 98176
import math

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

ans = 0
for i in range(N):
  for j in range(i+1, N):
    dis = 0
    for d in range(D):
      dis += (X[i][d] - X[j][d])**2
    dis = math.sqrt(dis)
    ans += dis.is_integer()

print(ans)

Measured memory_bytes: 8980
#include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<queue>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define ll long long
#define maxn 100005
#define eps 0.0000001
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000") ///在c++中是防止暴栈用的
struct eg
{
    int e,next;
    eg (int x=0,int y=0)
    {
        e=x;
        next=y;
    }
}edge[maxn<<1];

int head[maxn];
int tot,a,b;
int d1[maxn],dn[maxn];

void init()
{
    memset(d1,0xf,sizeof(d1));
    memset(dn,0xf,sizeof(dn));
    memset(head,-1,sizeof(head));
    tot=0;
}

void add_edge(int a,int b)
{
    edge[tot]=eg(b,head[a]);
    head[a]=tot++;
}

struct node
{
    int u,d;
    node(int x=0,int y=0)
    {
        u=x;
        d=y;
    }
};

void Bfs(int u)
{
    int vis[maxn];
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    if(u==1) d1[u]=0;
    else dn[u]=0;

    queue<node> q;
    q.push(node(u,0));
    while(!q.empty())
    {
        node tp=q.front();
        q.pop();
        for(int i=head[tp.u];i!=-1;i=edge[i].next)
        {
            int p=edge[i].e;
            if(vis[p]) continue;
            vis[p]=1;
            if(u==1) d1[p]=min(d1[p],tp.d+1);
            else dn[p]=min(dn[p],tp.d+1);
            q.push(node(p,tp.d+1));
        }
    }
}

int main()
{
    init();
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        add_edge(a,b);
        add_edge(b,a);
    }
    Bfs(n);
    Bfs(1);

    ///for(int i=1;i<=n;i++) cout<<d1[i]<<" ";puts("");
    ///for(int i=1;i<=n;i++) cout<<dn[i]<<" ";puts("");

    int cnt1=0,cntn=0;
    for(int i=1;i<=n;i++)
    {
        if(d1[i]<=dn[i]) cnt1++;
        else cntn++;
    }
    if(cnt1<=cntn) puts("Snuke");
    else puts("Fennec");

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n, m,k,a,b;
    int maxcnt = 0;
    cin >> n >> m >> k;
    vector<ll>booka, bookb;
    vector<ll>bookasum(n+1,0), bookbsum(m+1,0);
    rep(i, n) {
        cin >> a;
        booka.push_back(a);
        bookasum[i + 1] = a + bookasum[i];
    }

    rep(i, m) {
        cin >> b;
        bookb.push_back(b);
        bookbsum[i + 1] = b + bookbsum[i];
    }
    for (int i = 0;i <= n && bookasum[i] <= k;i++) {
        auto itr = upper_bound(all(bookbsum), k - bookasum[i]);
        if (bookbsum.begin() != itr)itr--;
        //tmpcnt = itr - bookbsum.begin();
        //if (bookbsum.begin() != itr)tmpcnt--;
        maxcnt = max(maxcnt, int(i + itr - bookbsum.begin()));
        //maxcnt = max(maxcnt, int(i + tmpcnt));
    }

    cout << maxcnt << endl;
    return 0;

}


Measured memory_bytes: 11052
#include<stdio.h>

void gcd(int *, int *);

int main(){
  int gcd = 1, a, b, i, number, temp;

  scanf("%d%d",&a,&b);
  
  if(a < b){
    temp = a;
    a = b;
    b = temp;
  }
    while(b > 0){
      number = a % b;
      a = b;
      b = number;
    }
    
    printf("%d\n", a);

    return 0;
}

Measured memory_bytes: 592