akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,ans,x,a[25],b[25],c[25];
int main(){
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int i=1;i<n;i++)
		c[i]=read();
	for(int i=1;i<=n;i++){
		if(a[i]==x+1)ans+=c[x];
		ans+=b[a[i]],x=a[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n, m=0;
  cin >> n;
  vector<int> a(n), ans(n, 0);
  rep(i, n) cin >> a.at(i);
  for(int i = n; i > 0; i--) {
    if(i > (n / 2)) {
      ans.at(i-1) = a.at(i-1);
    }else{
      int sum = 0;
      for(int j = 2 * i; j <= n; j += i) sum += ans.at(j-1);
      if((sum % 2) != a.at(i-1)){ ans.at(i-1) = 1;
      }else{ ans.at(i-1) = 0;}
    }
    if(ans.at(i-1) == 1) m++;
  }
  cout << m << endl;
  for(int i = 0; i < n; i++){
    if(ans.at(i) == 1) cout << i+1 << " ";
  }
}

Measured memory_bytes: 2432
import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const x = Number(inputs[0]);

  let a = 0;
  let num = 0;

  if (x === 0) {
    showLog(0, 0);
    return;
  }

  while (num !== x) {
    a++;
    for (let b = -1 * a; b < a; b++) {
      num = calc(a, b);
      if (num === x) {
        showLog(a,b);
        return;
      }
    }
  }
}

function showLog(a: number, b: number): void {
  console.log(a + ' ' + b);
}

function calc(a: number, b: number): number {
  return Math.pow(a, 5) - Math.pow(b, 5);
}


Measured memory_bytes: 32064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
string s;
int r[200];
ll a1(int& it);
ll a2(int& it);
ll fac(int& it);
ll a0(int& it){	//+
	ll ret=a1(it);
	while(r[s[it]]==0){
		if(s[it]=='+'){
			it++;
			ret+=a1(it);
		}else if(s[it]=='-'){
			it++;
			ret-=a1(it);
		}else{
			it++;
			ret*=a1(it);
		}
	}
	return ret;
}
ll a1(int& it){	//+
	ll ret=a2(it);
	while(r[s[it]]==1){
		if(s[it]=='+'){
			it++;
			ret+=a2(it);
		}else if(s[it]=='-'){
			it++;
			ret-=a2(it);
		}else{
			it++;
			ret*=a2(it);
		}
	}
	return ret;
}
ll a2(int& it){	//+
	ll ret=fac(it);
	while(r[s[it]]==2){
		if(s[it]=='+'){
			it++;
			ret+=fac(it);
		}else if(s[it]=='-'){
			it++;
			ret-=fac(it);
		}else{
			it++;
			ret*=fac(it);
		}
	}
	return ret;
}
ll num(int& it){
	ll ret=0;
	while(isdigit(s[it])){
		ret*=10;
		ret+=s[it]-'0';
		it++;
	}
	return ret;
}
ll fac(int& it){
	if(s[it]=='('){
		it++;
		ll ret=a0(it);
		it++;
		return ret;
	}else{
		return num(it);
	}
}
int main(){
	rep(i,200) r[i]=-1;
	ll ans=0;
	bool fst=1;
	cin>>s;
	s+="$";
	int it=0;
	rep(i,3) rep(j,3) rep(k,3){
		r['+']=i,r['-']=j,r['*']=k;
		ll tmp=a0(it);
		it=0;
//		show(tmp);
		if(fst||ans<tmp) ans=tmp;
		fst=0;
	}
	cout<<ans<<endl;
}

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

int n, m, p;
int t[10][10][10];
int h[10][10];

bool check(){
  for(int sx = 0; sx < n; sx++){
    for(int sy = 0; sy < n; sy++){
      for(int sz = 0; sz < n; sz++){
        if(t[sx][sy][sz] == -1) continue;

        for(int dx = -1; dx <= 1; dx++){
          for(int dy = -1; dy <= 1; dy++){
            for(int dz = -1; dz <= 1; dz++){
              if(dx == 0 && dy == 0 && dz == 0) continue;

              bool flg = true;
              int x = sx;
              int y = sy;
              int z = sz;

              for(int i = 0; i < m; i++){
                if(x < 0 || n <= x || y < 0 || n <= y || z < 0 || n <= z){
                  flg = false;
                  break;
                }
                if(t[x][y][z] != t[sx][sy][sz]){
                  flg = false;
                  break;
                }

                x += dx;
                y += dy;
                z += dz;
              }

              if(flg){
                return true;
              }

            }
          }
        }
      }
    }
  }

  return false;
}

int main(){
  while(cin >> n >> m >> p, n || m || p){
    memset(t, -1, sizeof(t));
    memset(h, 0, sizeof(h));

    int turn = -1;

    for(int i = 0; i < p; i++){
      int x, y;
      cin >> x >> y;

      x--;
      y--;

      if(turn != -1) continue;
      t[x][y][ h[x][y] ] = i % 2;
      h[x][y]++;
      if(check()){
        turn = i + 1;
      }
    }

    if(turn == -1)         cout << "Draw" << endl;
    else if(turn % 2 == 0) cout << "White " << turn << endl;
    else                   cout << "Black " << turn << endl;
  }
}

Measured memory_bytes: 1168
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long f[]=new long[10000005];
		for(int i=1;i<10000005;i++) {
			for(int j=i;j<10000005;j+=i) {
				if(j%i==0) {
					f[j]++;
				}
			}
		}
		long sum=0;
		for(int i=1;i<=n;i++) {
			sum+=i*f[i];
		}
		System.out.println(sum);
	}
	
	

}

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

const std::string END_OF_TEXT = "END_OF_TEXT";

int main(void)
{
	std::string cards, cardsShuffled;
	while (std::cin >> cards, cards != "-")
	{
		int shuffleNum;
		std::cin >> shuffleNum;
		int h = 0;
		for (int i = 0; i < shuffleNum; i++)
		{
			int temp;
			std::cin >> temp;
			h += temp;
		}
		h %= cards.size();
		cardsShuffled = cards.substr(h, cards.size() - h) + cards.substr(0, h);
		std::cout << cardsShuffled << '\n';
		cards.clear();
		cardsShuffled.clear();
	}
	return 0;
}

Measured memory_bytes: 3080
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN  = 2001;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int main() {
	#ifdef WIN32
	//freopen("a.in", "r", stdin);
	#endif
	int a = read(), b = read();
	if(a + b > 16) {puts(":("); return 0;}
	if(a > 8 || b > 8) {puts(":("); return 0;}
	puts("Yay!");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int inf = 1e9;
    int h, n;
    cin >> h >> n;

    vector<int> dp(100000,inf);
    dp[0] = 0;
    rep( i, n ) {
        int a,b;
        cin >> a >> b;
        rep(j,h+1) {
            dp[j] =  min( dp[j], dp[max(0,j-a)] + b );
        }
    }

    cout << dp[h] << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll long long
#define INF 10000000000000000LL
#define pll pair<long long , long long>
const int MAX=1e5+10;
const int MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
vector<int>adj[MAX];
double dp[3000][3000];
int vis[3000][3000];
int n;
double pb[3000];
double solve(int idx, int h){
	if(idx==n){
		return 2*h>=n;
	}
	if(vis[idx][h])
		return dp[idx][h];
	vis[idx][h]=true;
	double res=pb[idx]*solve(idx+1, h+1)+(1-pb[idx])*solve(idx+1,h);
	return dp[idx][h]=res;

}
int main() 
{ 
	//ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);	
//	#ifndef ONLINE_JUDGE
	//freopen("inp.txt" ,"r", stdin );
//	freopen("out.txt", "w", stdout);
	//#endif
	cout<<setprecision(15);
	cin>>n;
	
	for(int i=0;i<n;i++)
		cin>>pb[i];
	cout<<solve(0 ,0);
	
	
	
}

Measured memory_bytes: 107008
#include <iostream>
#include <cmath>

using namespace std;

int f(int n)
{
    if (n == 0)
    return 1;
    else
    return n*f(n-1);
}

int main()
{
    int n;
    int p[10], q[10];
    int px = 0, qx = 0;
    bool py[10], qy[10];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        py[i] = false;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> q[i];
        qy[i] = false;
    }
    for (int i = 0; i < n-1; i++)
    {
        int j = 0, l = 0;
        int k = p[i] - 1;
        while(1)
        {
            if(py[j] == false)
            {
                if (j == k)
                {
                    py[j] = true;
                    break;
                }
                l++;
            }
            j++;
        }
        px += l*f(n-i-1);
    }
    px++;
    for (int i = 0; i < n-1; i++)
    {
        int j = 0, l = 0;
        int k = q[i] - 1;
        while(1)
        {
            if(qy[j] == false)
            {
                if (j == k)
                {
                    qy[j] = true;
                    break;
                }
                l++;
            }
            j++;
        }
        qx += l*f(n-i-1);
    }
    qx++;
    cout << abs(px-qx) << endl;
    return 0;
}

Measured memory_bytes: 256
#https://atcoder.jp/contests/dp/tasks/dp_d
#2019-01-13
import numpy as np
N, W = map(int, input().split())
w, v = [], []
for i in range(N):
    a, b = map(int, input().split())
    w += [a]
    v += [b]

DP = np.zeros(W+1, dtype=int)
# i 円以下で買える商品の最大価値
for i in range(N):
    DP[w[i]:] = np.maximum(DP[:-w[i]]+ v[i], DP[w[i]:])
print(DP[-1])

Measured memory_bytes: 21896
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    string a,b;
    cin >> a >> b;
    
    if(a[0] != b[2] )
    {
        cout << "NO";
    }
    else if(a[1] != b[1])
    {
        cout << "NO";
    }
    else if(a[2] != b[0])
    {
        cout << "NO";
    }
    if(a[0] == b[2] and a[1] == b[1] and a[2] == b[0])
    {
        cout << "YES";
    }
}

Measured memory_bytes: 3032
#import sys

#input1 = [6,5,3,1,3,4,3]

#input2 = [3,4,3,2]

# Input Select Flag
#inputselflag = 1

#if inputselflag == 1:
#    inputs = input1[1:]
#elif inputselflag == 2:
#    inputs = input2[1:]
#else:
#    sys.exit()

# Calc
#for i in range(1, len(inputs)-1):
    #print(inputs[i-1])
    #result.append([inputs[i+1] - inputs[i]])
   #for j in range(i+1, len(inputs)):
        #print(inputs[j])
        #print(inputs[i])
        #print('\n')
        #result.append([inputs[j] - inputs[i]])
        #print(result[j-1])

import sys

def main():
    inputs = int(sys.stdin.readline().rstrip())
    maxv = -100000000000
    minv = int(sys.stdin.readline().rstrip())

    # Calc idel
    for i in range(1, inputs):
        compv = int(sys.stdin.readline())
        if compv - minv > maxv:
            maxv = compv - minv
        if compv < minv:
            minv = compv
        

    bigprice = maxv
    print(bigprice)



if __name__ == '__main__':
    main()


Measured memory_bytes: 5620
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W = MAP()

if H%3 == 0 or W%3 == 0:
    print(0)
    exit()

def divide_3(a, b):
    diff1, diff2 = INF, INF
    for i in range(-1, 2):
        p1 = (a//3+i) * b
        left_1 = H*W - p1
        p2 = b//2 * (a - (a//3+i))
        p3 = left_1 - p2
        diff_1 = max(p1, p2, p3) - min(p1, p2, p3)
        diff1 = min(diff1, diff_1)

        q1 = (ceil(a/3)+i) * b
        left_2 = H*W - q1
        q2 = b//2 * (a - (ceil(a/3)+i))
        q3 = left_2 - q2
        diff_2 = max(q1, q2, q3) - min(q1, q2, q3)
        diff2 = min(diff2, diff_2)

    return min(diff1, diff2, a, b)

print(min(divide_3(H, W), divide_3(W, H)))



Measured memory_bytes: 10492
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end


class Dice
  attr_accessor:node,:top,:s,:e,:num
  def initialize(arr)
    @node=Array.new(6){|i| i+1}
    @num=arr
    @top=1
    @s=2
    @e=3
  end

  def reverse_num(x)
    return 7-x
  end

  def S()
    top=@top
    s=@s
    e=@e
    @top=reverse_num(s)
    @s=top
  end

  def E()
    top=@top
    s=@s
    e=@e
    @top=reverse_num(e)
    @e=top
  end

  def W()
    top=@top
    s=@s
    e=@e
    @top=e
    @e=reverse_num(top)
  end

  def N()
    top=@top
    s=@s
    e=@e
    @top=s
    @s=reverse_num(top)
  end
end

a=get_i
b=get_i
dice1=Dice.new(a)
dice2=Dice.new(b)
4.times do
  4.times do
    break if dice1.num[dice1.s-1]==dice2.num[dice2.s-1]
    dice2.S
  end
  4.times do
    break if dice1.num[dice1.top-1]==dice2.num[dice2.top-1]
    dice2.W
  end
  break if dice1.num[dice1.s-1]==dice2.num[dice2.s-1] and dice1.num[dice1.top-1]==dice2.num[dice2.top-1]
  dice2.W
  dice2.S
end
if ((dice1.num[dice1.s-1]==dice2.num[dice2.s-1]) and (dice1.num[dice1.top-1]==dice2.num[dice2.top-1]) and (dice1.num[dice1.e-1]==dice2.num[dice2.e-1]))
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 8896
n = int(raw_input())
v = map(int, raw_input().split())
new_v = sorted(v)
pre_v = new_v[0]
out = 0.0
for i in range(1,n):
    out = (pre_v + float(new_v[i]))/2.0
    pre_v = (pre_v + float(new_v[i]))/2.0
print(out)

Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  int n;
  cin >> n;
  int v[n], c[n];
  for(int i = 0; i < n; i++)
    cin >> v[i];
  for(int i = 0; i < n; i++)
    cin >> c[i];
  int ans = 0;
  for(int i = 0; i < n; i++){
    int temp = v[i] - c[i];
    if(temp > 0) ans += temp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))
    ans = 0
    min_diff = 1000
    for i in range(N):
        temp = T - H[i] * 0.006
        diff = abs(A - temp)
        if diff < min_diff:
            min_diff = diff
            ans = i + 1
    print(ans)


if __name__ == '__main__':
    main()


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

#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)


typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

template <class T>
using pqueue = priority_queue<T>;
template <class T>
using rpqueue = priority_queue<T, vector<T>, greater<T> >;


int sint() { int x; scanf("%d", &x); return x; }
ll sll() { ll x; scanf("%lld", &x); return x; }
double sdb() { double x; scanf("%lf", &x); return x; }

int arr[4000] = {};
ll memo[3100][3100][2] = {};

ll dp(int l, int r, int pos) {
	if(l > r) {
		return 0;
	} else if(memo[l][r][pos] != -1) {
		return memo[l][r][pos];
	} else if(pos) {
		return memo[l][r][pos] = min(dp(l+1, r, 1-pos)-arr[l], dp(l, r-1, 1-pos)-arr[r]);
	} else {
		return memo[l][r][pos] = max(dp(l+1, r, 1-pos)+arr[l], dp(l, r-1, 1-pos)+arr[r]);
	}
}

int main() {
	memset(memo, -1, sizeof(memo));
	
	int n = sint();
	for(int i = 0; i < n; i++) {
		arr[i] = sint();
	}
	
	printf("%lld\n", dp(0, n-1, 0));
}

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N; ll A, B;
    cin >> N >> A >> B;
    ll X[N];
    rep(i, N) cin >> X[i];
    ll ans = 0;
    rep(i, N-1){
        if(A*(X[i+1]-X[i]) >= B){
            ans += B;
        }
        else{
            ans += A*(X[i+1]-X[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
    char ch=getchar(); int f=1; t=0;
    while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
    do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n,k;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(k); n--; k--;
	if (n%k==0) printf("%d\n",n/k);
	else printf("%d\n",n/k+1);
	return 0;
}

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

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		int N = in.nextInt();
		int K = in.nextInt();
		int cnt = 0;
		for(int i=0;i<N;i++) {
			if ( in.nextInt() >= K) cnt++;
		}

		System.out.println(cnt);
	}

	public static class MyScanner{
		Scanner sc = new Scanner(System.in);
		String nextLine() {return sc.nextLine();}
		String next() {return sc.next();}
		int nextInt() {return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next());}
	}
}

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

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

using namespace std;

int main() {

	int a, b, k;

	cin >> a >> b >> k;

	for (int i = a; i <= b; i++) {
		if (i <= a + k - 1 || b - k + 1 <= i)
			cout << i << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 2000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
typedef unsigned long long int ull;

using namespace std;

int main(void){
  int N,M,ans=0;
  cin >> N >> M;
  pair<int,int> route[M];
  bool check[N+10]={};
  rep(i,M) cin >> route[i].first >> route[i].second;
  rep(i,M) if(route[i].first==1) check[route[i].second]=1;
  rep(i,M) if(check[route[i].first]==1 && route[i].second==N) ans=1;
  if(ans==0) cout << "IMPOSSIBLE" << endl;
  else cout <<"POSSIBLE" << endl;
}

Measured memory_bytes: 2048
N,M,X= map(int,input().split())
gates = [int(i) for i in input().split()]
# X to N
count1 = 0
for i in range(X,N):
    if i in set(gates):
        count1 += 1
    
# X to 0
count2 = 0
for i in range(0,X):
    if i in set(gates):
        count2+= 1
print(min(count1,count2))

Measured memory_bytes: 3064
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#if __cplusplus >= 201103
#include <numeric>
#endif
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

//#if __cplusplus >= 201103
typedef long long ll;
//#endif
typedef pair<int, int> P;
typedef pair<int, P> IP;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

const int INF = 100000000;
//#if __cplusplus >= 201103
const ll LINF = 10000000000000000ll;
//#endif
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
// }}}

int n;

void init()
{
}

void solve()
{
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int par = 0;
    REP(i, n){
        int val;
        cin >> val;
        if(val % 2 != 0) par = (par + 1) % 2;
    }
    cout << (par == 0 || (par == 1 && n == 1) ? "YES" : "NO") << endl;
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    ll A,B,C,D,N;
    ll ans=0;
    string S;
    bool F;
int main(){
    cin>>A>>B>>C;
    cout<<C<<" "<<A<<" "<<B<<endl;



    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define r0 return 0;
#define f(k,i,n,j) for(ll k=i;k<=n;k=k+j)
#define cin(a) cin>>a;
#define loop while(t--)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define mod (1e9+7)
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
signed main()
{
    crap;
    int n;
    cin>>n;
    if(n&1)
    cout<<n/2+1<<endl;
    else
    cout<<n/2<<endl;
    
}

Measured memory_bytes: 256
A, B, C = $stdin.read.chomp.split(" ").map(&:to_i)

def gcd(a, b)
  if b == 0
    return a
  end
  gcd(b, a%b)
end

def divs(n)
  res = []
  i = 1
  while i * i <= n do

    if n % i == 0
      res << i
      if i != 0 && i * i != n
        res << n / i
      end
    end
    i += 1
  end
  res
end

a = A > B ? A : B
b = A > B ? B : A

g = gcd(a, b)
ds = divs(g).sort_by{|x| -1 * x}

puts ds[C-1]



Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(){
    int H, W, N; cin >> H >> W >> N;
    vector<vector<int>> xs(W+1);
    set<pair<int, int>> S;
    for(int i=0;i<N;i++){
        int X, Y; cin >> X >> Y;
        xs[Y].push_back(X);
        S.emplace(X, Y);
    }
    int x = 1, y = 1;
    int res = H;
    if(!xs[1].empty()) res = *min_element(xs[1].begin(), xs[1].end()) - 1;
    for(int i=1;;i++){
        if(x == H || S.count(make_pair(x+1, y))){
            res = min(i, res);
            break;
        }
        x++;
        if(y < W && !S.count(make_pair(x, y+1))){
            y++;
            for(auto& t : xs[y]) if(x < t) res = min(t-1, res);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 18176
N = int(input())
A_l = list(map(int,input().split()))
B_l = list(map(int,input().split()))
C_l = list(map(int,input().split()))

ans = 0
for i in range(N-1):
    ans += B_l[A_l[i]-1]
    if(A_l[i]+1 == A_l[i+1]):
        ans += C_l[A_l[i]-1]
ans += B_l[A_l[N-1]-1]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define dob double
#define int long long int
#define ss size()
using namespace std;
const int M=1e9+7,maxn=100011;
std::vector<int> adj[maxn];
std::vector<int> v1;
int ans,n,k,m,x,y,q,par[maxn],h[maxn],mach[maxn],sk[maxn],dp[110][maxn];
bool mark[maxn];


int32_t main(){
    cin>>n>>m;
    int a[n+1],b[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    for(int i=0;i<=n;i++)
        for(int j=0;j<maxn;j++)
            dp[i][j]=1000000010;
    for(int i=0;i<=n;i++)
        dp[i][0]=0;
    dp[1][b[1]]=a[1];
    for(int i=1;i<=n;i++)
        for(int j=1;j<maxn;j++){
            dp[i][j]=dp[i-1][j];
            if(j-b[i]>=0)
                dp[i][j]=min(dp[i][j],dp[i-1][j-b[i]]+a[i]);
        }
    for(int j=0;j<maxn;j++)
        if(dp[n][j]<=m)
            ans=j;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 83584
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<complex>
#include<bitset>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, x;
int Ans[200200];

signed main() {
    cin >> N >> x;
    if (x == 1 || x == 2 * N - 1) {
        cout << "No" << endl;
        return 0;
    }
    if (N == 2) {
        cout << "Yes\n1\n2\n3\n";
        return 0;
    }
    if (N == 3) {
        if (x == 2) {
            cout << "Yes\n5\n3\n2\n1\n4\n";
            return 0;
        }
    }
    rep(i, 2 * N - 1)Ans[i + 1] = i + 1;
    swap(Ans[x], Ans[N]);
    if (x == 2 * N - 2) {
        swap(Ans[2 * N - 1], Ans[N + 1]);
        swap(Ans[1], Ans[N - 1]);
        swap(Ans[2], Ans[N + 2]);
    } else {
        swap(Ans[1], Ans[N + 1]);
        swap(Ans[2 * N - 1], Ans[N - 1]);
        swap(Ans[2 * N - 2], Ans[N + 2]);
    }
    cout << "Yes" << endl;
    rep(i, 2 * N - 1) {
        cout << Ans[i + 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = ((int)(n) - 1); i >= 0; i--)
#define repn(i, n) for(int i = 1; i <= (int)(n); i++)
#define reprn(i, n) for(int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
using llint = long long int;
using lint = long int;

#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
	int n, k;
	string s;
	cin >> n >> s >> k;
	auto star = s[k - 1];
	rep(i, s.length()) {
		if (s[i] != star) {
			s[i] = '*';
		}
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,l[2000],ans;

signed main() {
    scanf("%lld", &n);
    rep(i,n) scanf("%lld", &l[i]);
    sort(l,l+n);
    rep(i,n) repo(j,i+1,n) repo(k,j+1,n) if (l[k] < l[i]+l[j]) ans++;
    printf("%lld\n", ans);
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    string s;
    cin>>s;
    
    s.pop_back();
    
    if(s.size()%2==1){
        s.pop_back();
    }
    
    while(s.size()!=2){
        
        string ss=s.substr(0, s.size()/2);
        //cout<<ss<<endl;
        
        if(s==(ss+ss)){
            break;
        }else{
            s.pop_back();
            s.pop_back();
        }
    }
    
    cout<<s.size()<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 

const int mod = 1000000007;
const int inf = 1e9;

int main(){
    int n;
    cin >> n;
    int dp[n+1][3];
    int a[n+1], b[n+1], c[n+1];
    repn(i, 1, n){cin >> a[i] >> b[i] >> c[i];}
    rep(i, 0, 3) dp[0][i] = 0;
    repn(i, 1, n){
        dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2]+a[i]);
        dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2]+b[i]);
        dp[i][2] = max(dp[i-1][0]+c[i], dp[i-1][1]+c[i]);
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]});
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

int main() {

    // NこKまで
    ll N,K;cin>>N>>K;

    //累積和
    ll dpsum[K];
    //それぞれについて
    ll dp[K];

// Nが大きい方から順番に処理していく
    ll ans = 0;
    for(ll i = K; i > 0; i-- ){
      dpsum[i] = modpow(K/i, N, MOD);
      dp[i] = dpsum[i];
      for(ll j = i*2; j <= K; j += i){
        dp[i] = (dp[i] + MOD - dp[j] ) %MOD;
      }
      ans += dp[i]*i%MOD;
      ans %= MOD;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 5152
N=int(input())
A=list(map(int,input().split()))
d={}
sum=0
d[sum]=1
for i in range(N):
    sum+=A[i]
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
ans=0
for x in d:
        ans+=d[x]*(d[x]-1)//2 # 1*0//2=0
print(ans)

Measured memory_bytes: 38644
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	string S; cin >> S;
	map<string, int> x;
	x["SUN"] = 7;
	x["MON"] = 6;
	x["TUE"] = 5;
	x["WED"] = 4;
	x["THU"] = 3;
	x["FRI"] = 2;
	x["SAT"] = 1;
	cout << x[S] << endl;
}





Measured memory_bytes: 256
#import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#threading.Thread(target=main).start()
import threading
threading.stack_size(2**26)
sys.setrecursionlimit(10**8)
mod=(10**9)+7
#fact=[1]
#for i in range(1,1000001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*1000001
#ifact[1000000]=pow(fact[1000000],mod-2,mod)
#for i in range(1000000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod
from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import math
import heapq
from random import randint as rn
from Queue import Queue as Q
def modinv(n,p):
    return pow(n,p-2,p)
def ncr(n,r,p):
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t
def ain():
    return map(int,sin().split())
def sin():
    return stdin.readline().strip()
def GCD(x, y):
   while(y):
       x, y = y, x % y
   return x
"""**************************************************************************"""
n,k=ain()
h=ain()
d=[10**18]*n
d[0]=0
for i in range(1,n):
    for j in range(1,min(k+1,i+1)):
        d[i]=min(d[i-j]+abs(h[i]-h[i-j]),d[i])
print d[-1]


Measured memory_bytes: 44264
n, x = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
ans = 0
(0..as.size-2).each do |i|
  sum = as[i] + as[i + 1]
  if sum > x
    d = [as[i + 1], sum - x].min
    as[i + 1] -= d
    sum -= d
    ans += d
  end
  if sum > x
    d = sum - x
    as[i] -= d
    ans += d
  end
end
p ans

Measured memory_bytes: 11140
#include <bits/stdc++.h>
#include<iostream>
#include<queue>
#include<string>
#include <vector>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;


int main() {
  //int long long total=0,H,W,i,j;
  int N,a,b,c;
  //cin>>ans.at(0)>>ans.at(1)>>ans.at(2);
  cin>>N;
  a=N/100;
  b=(N-a*100)/10;
  c=N-(100*a)-(10*b);

  if(a==1){
    a=9;
  }
  else if(a==9) a=1;
  if(b==1){
    b=9;
  }
  else if(b==9) b=1;
  if(c==1){
    c=9;
  }
  else if(c==9) c=1;
  cout<<a<<b<<c;
  return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, p;
    cin >> n >> p;

    string s;
    cin >> s;
    
    long long ans = 0;
    if (p == 2 || p == 5){
        for (int i = 0; i < n; i++){
            if ((s[i] - '0') % p == 0)
                ans += i + 1;
        }
    }
    else{
        map<int, int> mp;
        mp[0] = 1;
        int sum = 0, ten = 1;
        for (int i = n - 1; i >= 0; i--){
            sum = (sum + (s[i] - '0') * ten) % p;
            ans += mp[sum];
            mp[sum] += 1;
            ten = (ten * 10) % p;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 916
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		Arrays.setAll(A, i -> sc.nextInt());
		for(int i = 0; i < N-K; i++) {
			if(A[i] < A[i+K])
				System.out.println("Yes");
			else
				System.out.println("No");
		}
	}

}


Measured memory_bytes: 60484
<?php
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($L,$R,$d) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

for($i=1;$i<100;$i++) {
  for($j=1;$j<100;$j++) {
    for($k=1;$k<100;$k++) {
      $a = $i*$i+$j*$j+$k*$k+$i*$j+$j*$k+$k*$i;
      if (isset($map[$a])) {
        $map[$a]++;
      }
      else {
        $map[$a]=1;
      }
    }
  }
}
for($i=1;$i<=$N;$i++) {
  printf("%d\n",$map[$i]);
}

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

using namespace std;
using ll = long long;

int n, W;
vector<ll> v, w;
map<ll, ll> memo[110];

ll rec(int i, ll c) {
  if (memo[i].count(c) > 0) {
    return memo[i][c];
  }
  int ret;
  if (i == n) {
    ret = 0;
  } else if (c < w[i]) {
    ret = rec(i + 1, c);
  } else {
    ret = max(rec(i + 1, c), rec(i + 1, c - w[i]) + v[i]);
  }
  memo[i][c] = ret;
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> W;
  v = vector<ll>(n);
  w = vector<ll>(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }
  cout << rec(0, W) << endl;
  return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  vector<int> X(3);
  for(int i=0; i<3; i++){
    cin >> X[i];
  }
  int ans=1;
  if(X[0]%2==X[1]%2 && X[0]%2!=X[2]%2){
    X[0]++;
    X[1]++;
  }else if(X[1]%2==X[2]%2 && X[0]%2!=X[1]%2){
    X[1]++;
    X[2]++;
  }else if(X[0]%2==X[2]%2 && X[1]%2!=X[0]%2){
    X[0]++;
    X[2]++;
  }else{
    ans--;
  }
  sort(X.begin(),X.end());
  ans += (X[2]-X[1]+X[2]-X[0])/2;
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    string s;
    cin >> s;
    int n = s.size();
    int x = n + 1, y = -1;
    rep(i, n) {
        if (s[i] == 'C') {
            x = i;
            break;
        }
    }
    rrep(i, n) {
        if (s[i] == 'F') {
            y = i;
            break;
        }
    }

    if (x < y) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

using namespace std;

int main()
{
    string s;

    cin >> s;

    int n = s.length();

    int i = 0;
    int j = n-1;

    int ans = 0;

    while (i <= j)
    {
        if (s[i] != s[j])
            ans++;

        i++;
        j--;
    }

    cout << ans << "\n";

    return 0;
}

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

using namespace std;
static const int INF = (1 << 21);

char T[100011];

int main() {
	string S;	
	int P[100011] = { 0 };
	cin >> S;
	int j = 0;
	for (unsigned int i = 0;i < S.length();i++) {
		if (S[i] != 'x') {
			T[j] = S[i];
			P[j] = i;
			j++;
		}
	}
	for (unsigned int i = 0;i < S.length();i++) {
		if (S[i] != S[S.length() - 1 - i]) break;
		if (i == S.length() - 1)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	
	for (unsigned int i = 0;i < strlen(T);i++) {
		if (T[i] != T[strlen(T) - 1 - i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	int f = 0;
	if (strlen(T) % 2 == 0 && S[P[(strlen(T)+1) / 2 -1] + 1] == 'x') {
		f = +1;
		int j=1;
		while (S[P[strlen(T) / 2 - 1] + 1 + j] == 'x') {
			f++;
			j++;
			if (P[strlen(T) / 2 - 1] + 1 + j == S.length()) break;
		}
	}
	for (unsigned int i = 0;i < (strlen(T)+1)/2;i++) {
		if (P[i] > 0)
			if (S[P[i] - 1] == 'x'&&S[P[strlen(T) - 1 - i] + 1] == 'x') {
				f += 2;
				int j = 1;
				if(P[i]>2)
				while (S[P[i] - 1 - j] == 'x'&&S[P[strlen(T) - 1 - i] + 1 + j] == 'x') {
					f+=2;
					j++;
					if (P[i] == j) break;
				}
			}
	}

	cout << S.length() - strlen(T) - f << endl;

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
int main(){
	vector<int>num(3);
	for(int i=0;i<3;i++)cin>>num[i];
	sort(num.begin(),num.end());
	cout<<num[0]+num[1]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    if(A == 1 && B != 1) cout << "Alice" << endl;
    else if(A != 1 && B == 1) cout << "Bob" << endl;
    else if(A == B) cout << "Draw" << endl;
    else if(A > B) cout << "Alice" << endl;
    else if(A < B) cout << "Bob" << endl; 
    return 0; 
}

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

typedef struct{
    long long st;
    long long fi;
    long long kr;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

void calcdif(rs g[],mkj x[],long long nc,long long ndif,long long dif[]){
    long long i;
    for(i=x[nc].st;i<x[nc].st+x[nc].kz;i++){
        if(dif[g[i].fi] != -1){continue;}
        dif[g[i].fi]=ndif+g[i].kr;
        calcdif(g,x,g[i].fi,dif[g[i].fi],dif);
    }
}

int main(void){
    long long n,a[131072],b[131072],c[131072],i;
    long long q,k;
    long long z[131072],y[131072];
    long long dif[131072];
    rs g[262144];
    mkj x[131072];
    scanf("%lld",&n);
    for(i=0;i<n-1;i++){
        scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
        g[2*i].st=a[i];g[2*i].fi=b[i];g[2*i].kr=c[i];
        g[2*i+1].st=b[i];g[2*i+1].fi=a[i];g[2*i+1].kr=c[i];
    }
    qsort(g,2*n,sizeof(rs),sortfnc);
    makemkj(g,x,2*n);
    scanf("%lld%lld",&q,&k);
    for(i=0;i<=131071;i++){dif[i]=-1;}
    dif[k]=0;
    calcdif(g,x,k,0,dif);
    for(i=1;i<=q;i++){
        scanf("%lld%lld",&z[i],&y[i]);
        printf("%lld\n",dif[z[i]]+dif[y[i]]);
    }
    return 0;
}

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

struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}
 
    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }
 
    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }
 
    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }
 
    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }
 
    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }
 
  private:
    int _n;
    std::vector<int> parent_or_size;
};

int main(){
    int n, q; cin >> n >> q;
    dsu data(n);
    while (q--) {
        int t, u, v; cin >> t >> u >> v;
        if (t) cout << (data.same(u,v) ? 1 : 0) << "\n";
        else data.merge(u,v);
    }
    return 0;
}

Measured memory_bytes: 4052
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.nextLine();
		String[] xArray = sc.nextLine().split(" ");
		String[] yArray = sc.nextLine().split(" ");

		String ans = "War";
		int xMax = Integer.parseInt(xArray[0]);
		int yMin = Integer.parseInt(yArray[0]);

		for (int i = 1; i < xArray.length; i++) {
		int xa = Integer.parseInt(xArray[i]);
			if (xa > xMax) {
				xMax = xa;
			}
		}

		for (int i = 1; i < yArray.length; i++) {
			int ya = Integer.parseInt(yArray[i]);
			if (ya < yMin) {
				yMin = ya;
			}
		}

		if(x <= xMax && xMax < yMin && yMin <= y){
			ans ="No War";
		}

		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 22604
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [u32; n]
    }

    let mut m: BTreeMap<u32, u32> = BTreeMap::new();

    for &i in a.iter() {
        *m.entry(i).or_insert(0) += 1;
    }

    let mut values: Vec<u32> = m.values().cloned().collect();
    values.sort();

    let d = if values.len() >= k {
        values.len() - k
    } else {
        0
    };

    let ans = values[0..d].iter().fold(0, |sum, x| sum + x);
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;

int main(){
  ll l,r;
  cin>>l>>r;
  if(r-l>3000)cout<<0<<endl;
  else{
      ll ans=2018;
      for(ll i=l;i<=r;i++)for(ll j=i+1;j<=r;j++){
	  ans=min(ans,i*j%2019);
      }
      cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAXN 100000 + 10
#define ll long long int
ll N[MAXN];
ll dp[MAXN];
#define INF 0x3f3f3f3f;
int main()
{
    ll n,k;
    cin>>n>>k;
    for(int i = 0;i < n;++i)
        cin>>N[i],dp[i] = INF;
    dp[0] = 0;
    for(int i = 0;i < n;++i)
        for(int j = i - k;j <= i;++j)
            if(j >= 0)
            dp[i] = min(dp[i] ,dp[j]+ abs(N[i] - N[j]));
    cout<<dp[n - 1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
N, *XL = map(int, open(0).read().split())

A = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2))

ans = 0
cur = -10 ** 9
for t, s in A:
    if cur <= s:
        cur = t
        ans += 1

print(ans)

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

int main() {
  int w,h,x,y,r;
  cin >>w>>h>>x>>y>>r;
  
  if(x-r<0 || x+r>w || y-r<0 || y+r>h) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 3108