akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


int main() {
	ll x,n;
	cin >> x >> n;
	cout << x + (n / 2) << endl;
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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


int main()
{
	int a, b;
	cin >> a >> b;
	if(a + b == 15) cout << '+' << endl;
	else if(a * b == 15) cout << '*' << endl;
	else cout << 'x' << endl;

	return 0;
}


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

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

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
i = 10**9
s = 0
z = 0
c = 0
for b in a:
  if b < 0:
    s += 1
  elif b == 0:
    z += 1
  if abs(b) < i:
    i = abs(b)
  c += abs(b)
if z > 0 or s%2 == 0:
  print(c)
else:
  print(c-2*i)

Measured memory_bytes: 14412
import sys 
A = [input().split() for l in range(3)]
N = int(input())

b = ['0'] * N
for i in range(0,N):
    b[i] = input()

for i in range(0,3):
    for j in range(0,3):
        if A[i][j] in b:
            A[i][j] = '0'

for i in range(0,3):
    count = 0
    for j in range(0,3):
        if A[i][j] == '0':
            count += 1
    if count == 3:
        print('Yes')
        sys.exit()

for j in range(0,3):
    count = 0
    for i in range(0,3):
        if A[i][j] == '0':
            count += 1
    if count == 3:
        print('Yes')
        sys.exit()

if A[0][0] == '0' and A[1][1] == '0' and A[2][2] == '0':
    print('Yes')
    sys.exit()
elif A[0][2] == '0' and A[1][1] == '0' and A[2][0] == '0':
    print('Yes')
    sys.exit()
else:
    print('No')
    sys.exit()

 





    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
int n,m,i,j,mod=1e9+7,vis[100005],icr[100005],a[100005],cnt[100005],ans,f[100005],g[100005];
vector<int> bi[100005];
vector<int> seq,nxt;
int qp(int x,int y)
{
	int z=1;
	while(y){
		if(y&1){
			z=1ll*z*x%mod;
		}
		y/=2;
		x=1ll*x*x%mod;
	}
	return z;
}
void solve(int x)
{
	int st=x;
	for(;;){
		int y=x,z,lst=0,l1=0,l2=0;
		for(;;){
			l1++;lst=y;y=a[y];vis[y]=1;
			if(bi[y].size()==2) break;
		}
		z=bi[y][0]^bi[y][1]^lst;vis[z]=1;
		l2=1;
		while(!bi[z].empty()){
			z=bi[z][0];l2++;vis[z]=1;
		}
		if(l2>l1){
			puts("0");
			exit(0);
		}
		if(l2<l1) ans=2ll*ans%mod;
		if(y==st) return;x=y;
	}
}
int main()
{
	scanf("%d",&n);
	fz1(i,n){
		scanf("%d",&a[i]);
		bi[a[i]].push_back(i);
	}
	fz1(i,n)if(!vis[i]){
		int x=i;while(!vis[x]){
			vis[x]=i;x=a[x];
		}
		if(vis[x]!=i) continue;
		while(!icr[x]){
			icr[x]=1;x=a[x];
		}
	}
	fz1(i,n){
		if(icr[i]){
			if(bi[i].size()>2){
				puts("0");
				return 0;
			}
		}
		else{
			if(bi[i].size()>1){
				puts("0");
				return 0;
			}
		}
	}
	ans=1;
	memset(vis,0,sizeof(vis));
	fz1(i,n)if(bi[i].size()==2&&!vis[i]){
		solve(i);
	}
	fz1(i,n)if(!vis[i]){
		int x=i,c=0;while(!vis[x]){
			vis[x]=1;x=a[x];c++;
		}
		cnt[c]++;
	}
	fz1(i,n){
		f[0]=1;if((i&1)&&i>1) f[1]=2; else f[1]=1;
		fz(j,2,cnt[i]){
			if((i&1)&&i>1) f[j]=(f[j-1]+f[j-1]+1ll*f[j-2]*(j-1)%mod*i)%mod; else f[j]=(f[j-1]+1ll*f[j-2]*(j-1)%mod*i)%mod;
		}
		ans=1ll*ans*f[cnt[i]]%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8064
import java.util.Scanner;

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

        double w = sc.nextDouble();
        double h = sc.nextDouble();
        double x = sc.nextDouble();
        double y = sc.nextDouble();

        double ans = w * h / 2.0;
        boolean isMulti = x*2==w && y*2==h;

        System.out.print(ans + " ");
        System.out.println(isMulti ? "1" : "0");
    }
}

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

int main( void )
{

        int a,i,j;
        scanf("%d",&a);
        double x[a],y[a],z[3],b=0,c=0;
        for(i=0;i<a;i++){
            scanf("%lf",&x[i]);
        }
        for(i=0;i<a;i++){
            scanf("%lf",&y[i]);
        }
        for(i=0;i<3;i++){
            for(j=0;j<a;j++){
                z[i]+=fabs(pow((x[j]-y[j]),i+1));
            }
        }
        for(i=0;i<a;i++){
            b=fabs(x[i]-y[i]);
            if(b>c)c=b;
        }
        printf("%lf\n",z[0]);
        printf("%lf\n",sqrt(z[1]));
        printf("%lf\n",pow(z[2],1.0/3.0));
        printf("%lf\n",c);
        
    return 0;
}

Measured memory_bytes: 716
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    int now = 0;
    for(int i = 0; i < s.length(); ++i)
    {
        if(s[i] == 'D') now--;
        else now++;
        ans = max(ans, now);
    }
    cout << ans;
    return 0;
}


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

int main() { string d;
  cin >> d;
  if(d.at(0)==d.at(1) && d.at(1)==d.at(2)){
    cout << "Yes" << endl;
  }
  else if (d.at(1)==d.at(2) && d.at(2)==d.at(3)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
cost = [2,5,5,4,5,6,3,7,6]
# dp[i]: ちょうどi本のマッチを使うときの最大の桁数
dp = [-float('inf')]*(N+1)
dp[0] = 0
for i in range(1,N+1):
    for a in A:
        if i - cost[a-1] >= 0:
            dp[i] = max(dp[i],dp[i-cost[a-1]] + 1)
ans = ""
# dp[N]桁は確定,あとは大きいものを上に持ってくる
remain = dp[N]
match = N
while match > 0:
    # 降順にソートしたAで大きいものから見る
    for a in A:
        # (左辺)： 仮にaを選ぶとcost[a-1]本のマッチを消費する
        # 今持っているマッチの本数はmatchなので操作後のマッチの本数はmatch-cost[a-1]
        # (右辺)： 仮にaを選んだとして,残り作らなければならない桁数
        # match < cost[a-1]: 今持っているマッチの本数 < 作るのに必要な本数
        # (左辺) == (右辺): aを選んでも残りの下の桁に影響がない
        if match - cost[a-1] < 0:
            continue
        if dp[match-cost[a-1]] == remain - 1:
            ans += str(a)
            remain -= 1
            match -= cost[a-1]
            break
print(ans)

Measured memory_bytes: 3420
#include <iostream>
using namespace std;
int main() {
	int N, K;
	int x[100010];
	int min = 2000000000;
	int tmp;
	int tmp1 = 2000000000;

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

	for (int i = 0; i <= N - K; i++)
	{
		//左ターン
		if (x[i] < 0) {
			if (x[i + K - 1] <= 0) {
				tmp = -x[i];
			}
			else {
				tmp = x[i + K - 1] + (-x[i] * 2);
			}
		}
		else {
			tmp = x[i + K - 1];
		}

		//右ターン
		if (x[i + K - 1] > 0) {
			if (x[i] < 0) {
				tmp1 = x[i + K - 1] * 2 + (-x[i]);
			}
		}


		if (tmp<min)
		{
			min = tmp;
		}
		if (tmp1<min)
		{
			min = tmp1;
		}
	}

	cout << min << endl;
}

Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int u = h, d = 0, l = 0, r = w;
    imfor(i, n) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            l = max(l, x);
        }
        else if (a == 2) {
            r = min(r, x);
        }
        else if (a == 3) {
            d = max(d, y);
        }
        else {
            u = min(u, y);
        }
    }
    int ans = max(0, u - d) * max(0, r - l);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cassert>
#include<string>
#include<cmath>
#include<climits>
#include<cfloat>
#include<algorithm>
#include<vector>
using namespace std;
#define MAX 500000

typedef pair<int, int> P;

int N;
P A[MAX];

bool compare_y(P a, P b){
  return a.second < b.second;
}

int closest_pair(P *a, int n){
  if ( n <= 1 ) return INT_MAX;
  int m = n / 2;
  int x = a[m].first;
  int d = min(closest_pair(a, m), closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare_y);
  
  vector<P> b;
  for ( int i = 0; i < n; i++ ){
    if ( fabs(a[i].first - x) >= d ) continue;
    for ( int j = 0; j < b.size(); j++ ){
      int dx = a[i].first - b[b.size() - j - 1].first;
      int dy = a[i].second - b[b.size() - j -1 ].second;
      if ( dy >= d ) break;
      d = min(d, dx*dx + dy*dy);
    }
    b.push_back(a[i]);
  }
  return d;
}

main(){
  cin >> N;
  assert (2 <= N && N <= 500000);
  for  ( int i = 0; i < N; i++ ){
    cin >> A[i].first >> A[i].second;
  }

  sort(A, A + N );
  //printf("%.10lf\n", closest_pair(A, N));
  printf("%d\n", closest_pair(A, N));
}

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

using namespace std;

int main() {
    
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N), C(M), D(M), ans(N);
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
    }
    
    for(int i = 0; i < M; i++){
        cin >> C[i] >> D[i];
    }
    
    for(int i = 0; i < N; i++){
        int dist = 1e9;
        int index = -1;
        for(int j = 0; j < M; j++){
            if(dist > abs(A[i] - C[j]) + abs(B[i] - D[j])){
                index = j;
                dist = abs(A[i] - C[j]) + abs(B[i] - D[j]);
            }
        }
        ans[i] = index;
    }
    
    for(int i = 0; i < N; i++){
        cout << ans[i] + 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		String n =sc.next();
		int m = Integer.parseInt(n);
		int cnt = 0;
		for (int i = 1; i <= m;i++) {
			if(i%2 ==1) {
				cnt++;
			}
		}
		BigDecimal bdcnt = new BigDecimal(cnt);
		BigDecimal bdm = new BigDecimal(m);
		BigDecimal ans = bdcnt.divide(bdm,10,RoundingMode.HALF_UP);
		System.out.println("" +  ans);
      
      
	}

}

Measured memory_bytes: 22100
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=(1ll*ans*10+7)%n;
		if(ans==0){cout<<i<<endl;return 0;}
	}
	puts("-1");
}

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

int main() {
  int a, b;
  cin >> a >> b;
  a = a == 1 ? 14 : a;
  b = b == 1 ? 14 : b;
  cout << (a == b ? "Draw" : (a > b ? "Alice" : "Bob")) << endl;
}

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

using namespace std;

using int64 = long long;

int main() {
  int T;
  cin >> T;
  while(T--) {
    int64 A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A < B || B > D) {
      cout << "No" << endl;
      continue;
    }
    auto x = __gcd(B, D);
    int64 low = A - (A - C - 1) / x * x;
    if(low < B) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		int c = a+b;
		
		if(c==3) {
			System.out.println(3);
		}
		if(c==4) {
			System.out.println(2);
		}
		if(c==5) {
			System.out.println(1);
		}
		
		
		
		
	}

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int len = (int)s.length();
  string ans = "AC";
  int count = 0;
  if(s[0] != 'A'){
    ans = "WA";
  }
  else{
    for(int i = 1; i < len; ++i){
      if(isupper(s[i]) && s[i] != 'C'){
          ans = "WA";
          //cout << ans << '\n';
      }
      if(s[i] == 'C'){
        //cout << i << '\n';
        if(i == 1 || i == len - 1) ans = "WA";
        count++;
      }
    }
  }
  if(count != 1) ans = "WA";
  cout << ans << '\n';
}

Measured memory_bytes: 3640
M=10**9+7
r=tuple(tuple((j-i)*4%13 for i in range(10))for j in range(13))
d=[1]+[0]*12
for c in input():
  if c>"9":
    d=[(sum(d[i] for i in j))%M for j in r]
  else:
    d=[d[((j-int(c))*4%13)] for j in range(13)]
    
print(d[5])

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF 100000000
#define MOD 10007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

//#define DEBUG

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

int main_(){
  int x,y;
  cin>>x>>y;
  cout<<gcd(x,y)<<endl;
  return 0;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  vector<string>test;
  /*
   * input for debug
   */
  for(int i=0;i<test.size();++i){
    stringbuf buf;
    streambuf*out=cout.rdbuf(&buf);
    cout<<test[i]<<flush;
    cout.rdbuf(out);
    streambuf*in=cin.rdbuf(&buf);
    main_();
    cin.rdbuf(in);
    cout<<endl;
  }
#else
  main_();
#endif

  return 0;
}



Measured memory_bytes: 3180
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Vector as V
--import qualified Data.Function.Memoize as Memo
import Debug.Trace as De

getIntList = map read . words <$> getLine


listToTriple abc =(a,b,c)
    where [a,b,c]=abc
main :: IO ()

fir (a,_,_)=a
sec (_,b,_)=b
trd (_,_,c)=c

culc:: Int -> V.Vector Int -> Int
culc n av = solve 0 (n-1)
    where 
        dp=V.generate n (\i -> V.generate n (solve i))
        solve :: Int -> Int -> Int
        solve l r 
            | l==r = av V.! l
            | otherwise = max ((av V.! l)-( (dp V.! (l+1)) V.! r)) ((av V.! r)- ( (dp V.! l) V.! (r-1)) )
            

main = do
    nstr <-getLine
    inas <- getIntList 
    let av=(V.fromList inas) ::V.Vector Int
    let n = read nstr
    putStrLn(show (culc n av))
    


    



Measured memory_bytes: 790948
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

dx = [0, 0, 1, 1, 1, -1, -1, -1]
dy = [1, -1, 1, 0, -1, 1, 0, -1]

for h in range(H):
  for w in range(W):
    if S[h][w] == "#":
      continue
    cnt = 0
    for i in range(8):
      y = h + dy[i]
      x = w + dx[i]
      if 0 <= y < H and 0 <= x < W:
        if S[y][x] == "#":
          cnt += 1
    S[h][w] = str(cnt)
for s in S:
  print("".join(s))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n, 0);
    vector<bool> ac(n, 0);
    for(int i = 0; i < m; i++) {
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC") {
            ac[p] = true;
        } else if(!ac[p]) {
            cnt[p]++;
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        if(ac[i]) {
            ans += cnt[i];
        }
    }
    cout << count(ALL(ac), 1) << ' ' << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << max(a * b, c * d) << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

int main(){
	std::ios::sync_with_stdio(false); cin.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	long long ans = max({1ll*b*d, 1ll*b*c, 1ll*a*d, 1ll*a*c});
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int a,b,c,d;
	double e;
	
	scanf("%d %d",&a, &b);
	c = a/b;
	d = a%b;
	e = (double)a/(double)b;
	printf("%d %d %lf\n",c, d, e);
	return 0;
}
	


Measured memory_bytes: 2144
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n;
vector<ll> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<ll> count(n, 0), count1(n, 0);
    a.resize(n);
    rep(i, n) cin >> a[i];
    rep(i, n)
    {
        if (i + a[i] < n)
            count[i + a[i]]++;
        if (i - a[i] >= 0)
            count1[i - a[i]]++;
    }
    ll ans = 0;
    rep(i, n)
    {
        ans += count[i] * count1[i];
    }
    cout << ans << "\n";
}


Measured memory_bytes: 7920
n, l = map(int, input().split())

apples = []
apples_abs = []
for i in range(n):
    apples += [l + i]
    apples_abs += [abs(l + i)]

if min(apples_abs) in apples:
    print(sum(apples) - min(apples_abs))
else:
    print(sum(apples) + min(apples_abs))

Measured memory_bytes: 3060
#include <stdio.h>

char s[105];

int main(){
	int k;
	scanf("%d",&k);
	scanf("%s",s);
	int n = 0;
	int i;
	for(i=0;s[i];i++){
		++n;
	}
	if(n>k){
		for(i=0;i<k;i++){
			printf("%c",s[i]);
		}
		printf("...");
	}
	else{
		printf("%s",s);
	}
}


Measured memory_bytes: 1724
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
p = list(map(int, input().split()))

count = 0
min_p = p[0] + 1
for i in range(0,n):
    if p[i] == 1:
        count += 1
        break
    if min_p > p[i]:
        min_p = p[i]
        count += 1


print(count)

Measured memory_bytes: 24744
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;



int main(){
    int n;
    string in;
    pair<pair<string, int>, int> p[110];
    int point;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> in >> point;
        p[i] = make_pair(make_pair(in, -point), i);
    }
    sort(p, p+n);    
    for(int i = 0; i < n; i++){
        cout << p[i].second + 1 << endl;
    }
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class Math {
    ll mod = 1e9+7;
  public:
    template<typename T1, typename T2>
    ll gcd(T1 a, T2 b){
        if(b==0) return a;
        return gcd(b, a%b);
    }

    template<typename T1, typename T2>
    ll lcm(T1 a, T2 b){
        return a*(b/gcd(a, b));
    }

    template<typename T>
    int keta(T num){
        T k=0;
        while(num>0){
            num/=10;
            k++;
        }
        return k;
    }

    template<typename T1, typename T2>
    ll powmod(T1 num1, T2 num2){
        ll res = 1;
        while(num2 > 0){
            res *= num1;
            res %= mod;
            num2--;
        }
        return res%mod;
    }

    template<typename T1, typename T2>
    ll powl(T1 a, T2 b){
        ll res = 1;
        while(b > 0){
            res *= a;
            b--;
        }
        return res;
    }
};

class CSnack {
public:
	void solve(std::istream& in, std::ostream& out) {
        int a, b;
        in >> a >> b;

        Math mt;

        out << mt.lcm(a, b) << endl;
	}
};


int main() {
	CSnack solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import bisect

def snukefestival(n , a , b , c):

    ans = 0
    a.sort()
    b.sort()
    c.sort()

    for i in b:
        ab = bisect.bisect_left(a , i)
        cb = bisect.bisect_right(c , i)
        ans += ab * (len(b) - cb)

    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int , input().split()))
    print(snukefestival(n , a , b , c))

if __name__ == '__main__':
    main()

Measured memory_bytes: 105444
#include <iostream>

using namespace std;

int main(){
  int A, B;

  cin >> A >> B;

  if(A > B){
    if(A != 1 && B == 1){
      cout << "Bob";
    }else cout << "Alice";
  } else if(A < B){
    if(A == 1 && B != 1){
      cout << "Alice";
    }else cout << "Bob";
  } else {
    cout << "Draw";
  } 

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int l, r;
  cin >> l >> r;
  int mini;
  if((l + 2019) <= r){
    mini=0;
  }else{
    l = l % 2019;
    r = r % 2019;
    mini = 2018;
    int rem;
    for(int i = l; i <= r; ++i){
      rem = (i * i)%2019;
      for(int j = i + 1; j <= r; ++j){
        rem += i;
        if(rem > 2018) rem -= 2019;
        if(rem < mini) mini = rem;
      }
    }
  }

  printf("%d\n", mini);
  return 0;
}

Measured memory_bytes: 764
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int x, a;
	cin >> x >> a;
	if(x < a) cout << "0" << endl;
	else cout << "10" << endl;
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
 
#dp[S] = A[S], -inf で初期化　Sの部分集合TのうちA[T]が(最大のもの, 次に大きいもの)　を入れていく
 
dp = [[A[S], -float('inf') ] for S in range(1 << N)]
for i in range(N):
    for T in range( 1 << N):
        if (T >> i) & 1 == 1: # Tがiを含むとき
            merge = dp[T] + dp[T ^ (1 << i)]
            merge.sort(reverse = True)
            dp[T] =merge[:2]
ans = -float('inf')
for S in range(1, 1 << N , 1):
    ans = max(ans, sum(dp[S]))
    print(ans)

Measured memory_bytes: 147848
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    result = 0
    for i in range(n):
        current_b = B_list[i]
        rest_b = current_b - A_list[i]
        if rest_b > 0:
            result += A_list[i]
            rest_next_a = A_list[i+1] - rest_b
            if rest_next_a > 0:
                result += rest_b
                A_list[i+1] = rest_next_a
            else:
                result += A_list[i+1]
                A_list[i+1] = 0

        else:
            result += current_b

    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 24444
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, m;
    cin >> n >> m;
    vector<int> cnt(n, 0);
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        ++cnt[--a], ++cnt[--b];
    }
    for(int i = 0; i < n; ++i){
        if(cnt[i] % 2 != 0){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}

Measured memory_bytes: 640
Imports System
 
Module DontBeLate
  Public Sub Main()
    Dim Vals = Console.ReadLine().Split(" ")
    If Val(Vals(0)) / Val(Vals(1)) <= Val(Vals(2)) Then
      Console.WriteLine("Yes")
    Else
      Console.WriteLine("No")
    End If
  End Sub
End Module

Measured memory_bytes: 26468
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll mod = 1e9 + 7;
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * c, max(a * d, max(c * b, b * d))) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    multimap<string, int> s;
    int q, a, b;
    string key, key2;
    cin >> q;
    rep(i, q) {
        cin >> a >> key;
        if(a == 0) {
            cin >> b;
            s.insert(make_pair(key, b));
        } else if(a == 1) {
            if(s.find(key) != s.end()) {
                auto p = s.equal_range(key);
                while(p.first != p.second) {
                    cout << p.first->second << "\n";
                    p.first++;
                }
            }
        } else if(a == 2) {
            s.erase(key);
        } else {
            cin >> key2;
            auto p1 = s.lower_bound(key);
            auto p2 = s.upper_bound(key2);
            while(p1 != p2) {
                cout << p1->first << " " << p1->second << "\n";
                p1++;
            }
        }
    }
}


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

    string s;
    cin >> s;

    int ans = 100;
    for(char ch = 'a'; ch <= 'z'; ch++){
        int dif = 0;
        int tmp_ans = 0;
        for (auto c : s){
            if(c != ch){
                dif++;
            }
            else{
                tmp_ans = max(tmp_ans, dif);
                dif = 0;
            }
        }
        tmp_ans = max(tmp_ans, dif);
        ans = min(ans, tmp_ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

void solve() {
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    loop(i, n)
        cin >> a[i];
    int ans = 0;
    for (int del = 0; del <= k; ++del) {
        int R = min(k - del, n);
        for (int i = 0; i <= R; ++i) {
            int sum = 0;
            vector <int> ret;
            for (int j = 0; j < i; ++j) {
                sum += a[j];
                ret.pb(a[j]);
            }
            for (int j = n - 1; j >= n - (R - i); --j) {
                sum += a[j];
                ret.pb(a[j]);
            }
            sort(all(ret));
            for (int j = 0; j < del && j < ret.size() && ret[j] < 0; ++j)
                sum -= ret[j];
            ans = max(ans, sum);
        }
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

int main()
{
	map<int, int> m;
	map<int, int>::iterator it;
	int n, i, j;
	int a, b, c;
	int t;
	while (cin>>n, n) {
		m.clear();
		for (i = 0; i < n; i++) {
			cin>>c;
			t = 0;
			for (j = 0; j < 4; j++) {
				cin>>a>>b;
				t += a*60 + b;
			}
			m[t] = c;
		}
		it = m.begin();
		cout<<(*it).second<<endl;
		cout<<(*++it).second<<endl;
		cout<<(*----m.end()).second<<endl;
	}
	return 0;
}

Measured memory_bytes: 976
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}


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

int main() {
	int h, w;
	while (cin >> h >> w) {
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) cout << "#";
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


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

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

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

    ll ans = 0LL;
    vector< vector< int > > dp(K + 1, vector< int >(K + 1));
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            int ab = max(dp[a][b], dp[b][a]);
            if (ab == 0) {
                int ret = gcd(a, b);
                dp[a][b] = ret;
                dp[b][a] = ret;
                ab = ret;
            }
            for (int c = 1; c <= K; ++c) {
                int abc = max(dp[ab][c], dp[c][ab]);
                if (abc == 0) {
                    int ret = gcd(ab, c);
                    dp[ab][c] = ret;
                    dp[c][ab] = ret;
                    abc = ret;
                }
                ans += (ll)abc;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
using ui = unsigned int;
using ll = long long;
using vll = vector<ll>;
static const ll M = 1e9 + 7;

ll solve(const vector<string> &rows) {
    const int H = rows.size();
    const int W = rows.front().size();
    
    // count of paths to reach [row r] [column c]
    vector<vll> dp(H, vll(W, 0));
    dp[0][0] = 1;
    for (int c = 1; c < W && rows[0][c] != '#'; ++c) dp[0][c] = 1;
    for (int r = 1; r < H && rows[r][0] != '#'; ++r) dp[r][0] = 1;
    
    for (int r = 1; r < H; ++r) {
        for (int c = 1; c < W; ++c) {
            if (rows[r][c] == '#') continue;
            dp[r][c] = (dp[r][c] + dp[r - 1][c] + dp[r][c - 1]) % M;
        }
    }
    
    return dp.back().back();
}

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

    ui H, W;
    cin >> H >> W;
    vector<string> rows(H, "");
    for (auto &row : rows) {
        cin >> row;
        assert(row.size() == W);
    }
    
    cout << solve(rows) << endl;
    
    return 0;
}


Measured memory_bytes: 9216
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nBuf,int N){
    char *buf,*ptr;

    buf=(char*)malloc(nBuf*sizeof(char));
    my_gets(buf,nBuf,stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}

int CmpInt(const void *a, const void *b){        //a-bを返す(qsortなら昇順)
    return *((int*)a)- *((int*)b);
}

int N;
int A[100000];

unsigned bp(int n){
    return (n<=0)? (1u) : ( (bp(n-1)*2u)%(1000000007u) );
}


int main(void){

    scanf("%d%*c",&N);
    InputIntAry(A,600000,N);

    qsort(A,N,sizeof(int),CmpInt);
    if(N%2==0){
        for(int i=0;i<N/2;i++){
            if(A[2*i]!=2*i+1 || A[2*i+1]!=2*i+1){
                puts("0");
                return 0;
            }
        }
    }
    else{
        if(A[0]!=0){
            puts("0");
            return 0;
        }
        for(int i=0;i<N/2;i++){
            if(A[2*i+1]!=2*(i+1) || A[2*i+2]!=2*(i+1)){
                puts("0");
                return 0;
            }
        }
    }

    printf("%u\n",bp(N/2));
    return 0;
}

Measured memory_bytes: 1724
#include <stdio.h>
int main(void){
  int x=0, N, max=0;
  char c;
  scanf("%d ", &N);
  for(int i= 0; i<N; i++){
    scanf("%c", &c);
    if(c=='I'){x++;}
    else{x--;}
    if(x>max) max = x;
  }
  printf("%d", max);
}

Measured memory_bytes: 128
//       |----|       /\      |    |   -----   |
//       |   /       /  \     |    |     |     |
//       |--/       /----\    |----|     |     |
//       |   \     /      \   |    |     |     |
//       |    \   /        \  |    |   -----   -------

//https://www.geeksforgeeks.org/longest-sub-array-sum-k/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define double long double

int32_t main()
{
    IOS;
    int a,b,q;
    cin>>a>>b>>q;
    int arr[a],brr[b];
    set<int> s1,s2;
    for(int i=0;i<a;i++)
    {
    	cin>>arr[i];
    	s1.insert(arr[i]);
    }
    for(int i=0;i<b;i++)
    {
    	cin>>brr[i];
    	s2.insert(brr[i]);
    }
    s1.insert(-1e18);
    s2.insert(-1e18);
    s1.insert(1e18);
    s2.insert(1e18);
    sort(arr,arr+a);
    sort(brr,brr+b);
    while(q--)
    {
    	int x;cin>>x;
    	int temp=x;
    	int mini=1e18;


    	int sum=0;
    	auto it=s1.lower_bound(x+1);it--;
    	sum+=x-*it;
    	x=*it;
    	it=s2.lower_bound(x+1);it--;
    	sum+=x-*it;
    	mini=min(mini,sum);
    	sum-=x-*it;
    	it=s2.lower_bound(x);
    	sum+=*it-x;
    	mini=min(mini,sum);

    	x=temp;
    	sum=0;
    	it=s2.lower_bound(x+1);it--;
    	sum+=x-*it;
    	x=*it;
    	it=s1.lower_bound(x+1);it--;
    	sum+=x-*it;
    	mini=min(mini,sum);
    	sum-=x-*it;
    	it=s1.lower_bound(x);
    	sum+=*it-x;
    	mini=min(mini,sum);

    	x=temp;
    	sum=0;
     	it=s1.lower_bound(x);
    	sum+=abs(x-*it);
    	x=*it;
    	it=s2.lower_bound(x+1);it--;
    	sum+=x-*it;
    	mini=min(mini,sum);
    	sum-=x-*it;
    	it=s2.lower_bound(x);
    	sum+=*it-x;
    	mini=min(mini,sum);

    	x=temp;
    	sum=0;
    	it=s2.lower_bound(x);
    	sum+=abs(x-*it);
    	x=*it;
    	it=s1.lower_bound(x+1);it--;
    	sum+=x-*it;
    	mini=min(mini,sum);
    	sum-=x-*it;
    	it=s1.lower_bound(x);
    	sum+=*it-x;
    	mini=min(mini,sum);
    	cout<<mini<<endl;


    }
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m,i,j,k,ans;
    cin>>n>>m>>k;
    ll temp=max(n,m);
    ans=k/temp;
    if(k%temp!=0)
        ans+=1;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main(){
    int n;
    cin>>n;
    vector<string> s(n); 
    for(int i=0; i<n; i++) cin>>s[i];
    map<string,int> m;
    for(int i=0; i<n; i++){
        m[s[i]]++;
    }
    int max_size=0;
    vector<string> t;
    for(auto i:m){
        if(i.second==max_size){
            t.push_back(i.first);
        }else if(i.second>max_size){
            t.resize(0);
            max_size=i.second;
            t.push_back(i.first);
        }
    }
    sort(t.begin(),t.end());
    for(auto i : t){
        cout<<i<<endl;
    }
}


Measured memory_bytes: 28404
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
#define eps 1e-6
const int maxn = 1e5 + 10;
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
char str[maxn];
int arr[30][maxn], N, Q[maxn];
int compare(int pos, int a, int b, int c, int d)
{
    int tmp = (arr[pos][b] - arr[pos][a]) * (d - c) - (arr[pos][d] - arr[pos][c]) * (b - a);
    return tmp;
}
void check(int& s, int& e, int pos)
{
    int h = 1, t = 0, now = 0;
    for (ri i = 2; i <= N; ++i) {
        //insert now;
        while (h < t && compare(pos, Q[t - 1], Q[t], Q[t], i) >= 0) {
            t--;
        }
        Q[++t] = now++;
        while (h < t && compare(pos, Q[h], i, Q[h + 1], i) <= 0) {
            h++;
        }
        double slope = (arr[pos][i] - arr[pos][Q[h]]) * 1.0 / (i - Q[h]);
        if (slope - 0.5 > eps) {
            s = Q[h] + 1, e = i;
            return;
        }
    }
}
signed main()
{
    scanf("%s", str + 1);
    N = strlen(str + 1);
    if (N < 2) {
        writesp(-1), writeln(-1);
        return 0;
    }
    for (ri i = 1; i <= 26; ++i) {
        for (ri j = 1; j <= N; ++j) {
            arr[i][j] = arr[i][j - 1] + (str[j] == 'a' + i - 1);
        }
    }
    for (ri i = 1; i <= 26; ++i) {
        int s = -1, e = -1;
        check(s, e, i);
        if (s != -1) {
            writesp(s), writeln(e);
            return 0;
        }
    }
    writesp(-1), writeln(-1);
    return 0;
}

Measured memory_bytes: 22144
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := bufio.NewScanner(stdin)

	/* 単語ごとに入力するならこれ */
	sc.Split(bufio.ScanWords)

	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	b, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	c, _ := strconv.Atoi(sc.Text())

  ret := c - (a - b)
  if ret > 0 {
    fmt.Println(ret)
  } else {
    fmt.Println(0)
  }
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define sz 101010 
}
using namespace my_std;

int n,m;
int a[sz<<1];

bool check(int p)
{
	rep(i,p+1,n+n) if (a[i]+a[n+n-i+p+1]<m) return 0;
	return 1;
}
int calc(int p)
{
	int ret=0;
	rep(i,1,p) ret=max(ret,a[i]+a[p-i+1]);
	rep(i,p+1,n+n) ret=max(ret,a[i]+a[n+n-i+p+1]-m);
	return ret;
}

int main()
{
	cin>>n>>m;
	rep(i,1,n*2) scanf("%d",&a[i]);
	sort(a+1,a+n+n+1);
	int l=0,r=n,pos;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (check(mid*2)) pos=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<calc(pos*2);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
#define ll long long 
# define skorost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std ;
 
ll z , o , ans ;

int N = 1e4 + 15820 ;

int main(){ skorost ;

	int a , b , c , k ;

	cin >> a >> b >> c >> k ;

	int u  = min( a , k ) ;

	ans += u ;

	k -= u ;

	int h = min( b , k ) ;

	k -= h ;

	int r = min( c , k ) ;

	ans -= r ;

	cout << ans << endl ;

}

Measured memory_bytes: 3652
N = 1407; K = 38
ans = []
for i in range(K):
    tmp = [1] + list(range((K-1)*i+2, (K-1)*(i+1)+2))
    ans.append(tmp)
for i in range(1, K):
    for j in range(K-1):
        tmp = [i+1]
        for k in range(K-1):
            tmp.append(K+((j + (i-1)*k) % (K-1))+k*(K-1) + 1)
        ans.append(tmp)
print(N, K)
for l in ans:
    print(*l)


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int AC=0;
	int WA=0;
	int TLE=0;
	int RE=0;
	while(n--)
	{
	    string s;
	    cin>>s;
	    if(s=="AC")
	    AC++;
	    else if(s=="WA")
	    WA++;
	    else if(s=="TLE")
	    TLE++;
	    else if(s=="RE")
	    RE++;
	}
	cout<<"AC"<<" "<<"x"<<" "<<AC<<endl;
	cout<<"WA"<<" "<<"x"<<" "<<WA<<endl;
	cout<<"TLE"<<" "<<"x"<<" "<<TLE<<endl;
	cout<<"RE"<<" "<<"x"<<" "<<RE<<endl;
}


Measured memory_bytes: 3624