akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int N, A;
VI V;
ll dp[51][51][2503];

ll dfs(int idx, int num, int sum) {
    if (idx == N) {
        if (num == 0 && sum == 0) return dp[idx][num][sum] = 1;
        else return dp[idx][num][sum] = 0;
    }
    if (sum < 0) return dp[idx][num][sum] = 0;
    if (dp[idx][num][sum] != -1) return dp[idx][num][sum];
    return dp[idx][num][sum] = dfs(idx+1, num-1, sum - V[idx]) + dfs(idx+1, num, sum);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> N >> A;
    V.resize(N);
    REP(i, N) cin >> V[i];
    sort(all(V));
    ll res = 0;
    memset(dp, -1, sizeof(dp));
    for (int i = 1; i <= N; i++) {
        res += dfs(0, i, A * i);
    }
    cout << res << endl;

}

Measured memory_bytes: 51072
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        long count = 0;
        for (long i = k; i < n + 2; i++){
            long min = (i * (i - 1)) / 2;
            long max = (n * i) + i - ((i * (i + 1)) / 2);
            count += max - min + 1;
        }
        System.out.println((int) (count % (Math.pow(10, 9) + 7)));
    }
}


Measured memory_bytes: 35708
import bisect

def main():    
    n = int(input())
    L = list(int(x) for x in input().split())
    ans = 0
    c = 0

    L.sort()

    for i in range(n-2):
        for j in range(i+1, n):
            c = L[i]+L[j]
            l = j
            r = bisect.bisect_left(L, c, lo=l) -1
            ans += (r-l)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        for(int i = 1;i <= n;i++){
            if(a <= dighitSum(i) && dighitSum(i) <= b){
                ans += i;
            }
        }
        System.out.println(ans);
    }
    public static int dighitSum(int x){
        int ans = 0;
        while(x != 0){
           ans += x % 10;
           x /= 10;
        }
        return ans;
    }
}


Measured memory_bytes: 23764
import java.util.*;

class Main {
	public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        
        int[][] a = {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}};
        int[][] bb = {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}};
        int[][] c = {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}};
        int[][] d = {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}};
        
        int num = sc.nextInt();
        int b,f,r,v;
        for(int i = 0;i < num;i++){
            b = sc.nextInt();
            f = sc.nextInt();
            r = sc.nextInt();
            v = sc.nextInt();
            switch(b){
                case 1:
                    a[f - 1][r - 1] += v;
                    break;
                case 2:
                    bb[f - 1][r - 1] += v;
                    break;
                case 3:
                    c[f - 1][r - 1] += v;
                    break;
                case 4:
                    d[f - 1][r - 1] += v;
                    break;
            }
        }

        for(int i = 0;i < 3;i++){
            for(int j = 0;j < 10;j++){
                System.out.print(" "+a[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");

        for(int i = 0;i < 3;i++){
            for(int j = 0;j < 10;j++){
                System.out.print(" "+bb[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");

        for(int i = 0;i < 3;i++){
            for(int j = 0;j < 10;j++){
                System.out.print(" "+c[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");

        for(int i = 0;i < 3;i++){
            for(int j = 0;j < 10;j++){
                System.out.print(" "+d[i][j]);
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 29676
#include <stdio.h>

int main() {
	long long a, b, k;

	scanf("%lld%lld%lld", &a, &b, &k);
	if (a >= k)
		printf("%lld %lld\n", a - k, b);
	else if (b >= k - a)
		printf("0 %lld\n", b - (k - a));
	else
		printf("0 0\n");
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int i,j,k;
  int n;
  int N;
  int hako[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&hako[i]);
  }
  for(k=0;k<N-1;k++){
    printf("%d ",hako[k]);
  }
  printf("%d",hako[N-1]);
  printf("\n");

  for(i=1;i<N;i++){
    n = hako[i];
    j = i-1;
    while(j >=0 && hako[j]>n){
      hako[j+1] = hako[j];
      j--;
    }
    hako[j+1]=n;

   
    for(k=0;k<N-1;k++){
      printf("%d ",hako[k]);
    }
    printf("%d",hako[N-1]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int result = 0;
  rep(i, N) {
    int a; cin >> a;
    while(a%2==0){ result++; a/=2; }
  }
  cout << result << endl;
  return 0;
}

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

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

using namespace std;

ll f(ll n){
  if(n<2)return 1;
  return n*f(n-2);
}

int main(){
  ll n;cin>>n;
  if(n%2==1){
    cout<<0;return 0;
  }

  ll result=0;
  n/=2;
  while(n>0){
    result += n/5;
    n/=5;
  }

  cout<<result;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

using P1 = array<int, 26>;
using P2 = array<char, 365>;
const double b = 2.3;
int ii = 365;
struct state{

    array<int, 26> prv;
    array<char, 365> ans;
    int val1, val2;
    bool operator<(const state &a) const { return val1+val2*b > a.val1+a.val2*b; }
    state(P1 a, P2 b, int x, int y) : prv(a), ans(b), val1(x), val2(y) {};
};


int main() {
    int d;
    cin >> d;
    array<int, 26> A{};
    for (auto &&k : A) cin >> k;
    vector<array<int, 26>> v(d);
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < 26; ++j) {
            scanf("%d", &v[i][j]);
        }
    }
    vector<int> ans(d);
    int W = 410;
    vector<state> a;
    a.emplace_back(P1{}, P2{}, 0, 0);
    fill(a[0].prv.begin(),a[0].prv.end(), -1);
    for (int i = 0; i < d; ++i) {
        ii--;
        priority_queue<state> Q;
        for (auto &&s : a){
            s.val2 = 0;
            for (int l = 0; l < 26; ++l) {
                s.val1 -= (i-s.prv[l])*A[l];
                s.val2 -= (i-s.prv[l])*A[l];
            }
            for (int k = 0; k < 26; ++k) {
                state ss(s);
                ss.ans[i] = k;
                ss.val1 += v[i][k]+s.prv[k]*A[k];
                ss.val2 += s.prv[k]*A[k];
                ss.prv[k] = i;
                ss.val1 -= s.prv[k]*A[k];
                ss.val2 -= s.prv[k]*A[k];
                Q.emplace(ss);
                if(Q.size() > W) Q.pop();
            }
        }
        a.clear();
        while(!Q.empty()) a.emplace_back(Q.top()), Q.pop();
    }
    sort(a.begin(),a.end(), [&](state a, state b){ return a.val1 < b.val1; });
    for (auto &&m : a.back().ans) {
        printf("%d\n", m+1);
    }
    return 0;
}

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

using namespace std;

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0] == 5 && a[1] == 5 && a[2] == 7) {
        return cout<<"YES",0;
    }
    puts("NO");

    return 0;
}


Measured memory_bytes: 3576
import java.util.Arrays;
import java.util.Scanner;

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

			int n = sc.nextInt();
			
			double[] v = new double[n];
			for(int i = 0 ; i < n ; i++ ) {
				v[i] = sc.nextDouble();
			}
			
			Arrays.sort(v);
			
			double result = v[0];
			for(int i = 1 ; i < n ; i++) {
				result = (result + v[i]) / 2;
			}
			
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 23252
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int H=stdIn.nextInt();
		int A=stdIn.nextInt();
		if(H%A==0)
			System.out.println(H/A);
		else
			System.out.println(H/A+1);
	}
}


Measured memory_bytes: 23380
import java.awt.*;
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int t=sc.nextInt();
        int x=sc.nextInt();
        System.out.println(t*x);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

Measured memory_bytes: 25380
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n = int(input())
    print((n+1)//2)

if __name__ == '__main__':
    main()


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

int main(){
  int h,w;
  cin >>h >> w;
  string s;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cin >> s;
      if(s=="snuke"){
	char a='A'+j;
	cout << a << i+1 << endl;
	return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<vector>
using namespace std;
int n, color[100001];
vector<int> G[100001];
void dfs(int r, int c){
	stack<int> s;
	s.push(r);
	color[r]=c;
	while(!s.empty()){
		int u=s.top();
		s.pop();
		for(int i=0; i<G[u].size(); i++){
			int v=G[u][i];
			if(color[v]==-1){
				color[v]=c;
				s.push(v);
			}
		}
	}
}

void assignColor(){
	int id=1;
	for(int i=0; i<n; i++)
		color[i]=-1;
	for(int u=0; u<n; u++){
		if(color[u]==-1){
			dfs(u, id);
			id++;
		}
	}
}

int main(){
	int s,t,m,q;
	cin>>n>>m;
	for(int i=0; i<m; i++){
		cin>>s>>t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	assignColor();
	cin>>q;
	for(int i=0; i<q; i++){
		cin>>s>>t;
		if(color[s]==color[t])
			cout<<"yes"<<endl;
		else
			cout<<"no"<<endl;
	}
	return 0;
}


Measured memory_bytes: 9012
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int m,k;
int bill[100000];

void probability(int n,int sum)
{
  for(int i=1;i<=m;i++){
    if(n==1){
      int def=sum+i-k;
      if(def>0) bill[def]++;
      else bill[1]++;
    } else probability(n-1,sum+i);
  }
}

int main()
{
  int n;

  for(;;){
    cin>>n>>m>>k;
    if(!(n|m|k)) break;
    for(int i=0;i<=n*m-k;i++) bill[i]=0;
    probability(n,0);
    double sum=0;
    for(int i=1;i<=n*m-k;i++)
      sum+=bill[i]/pow(m,n)*i;
    printf("%.9f\n", sum);
  }
}


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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     ll a,b;
     cin >> a >> b;
     ll ans=a*b;
     cin >> a >> b;
     ans=max(a*b,ans);
     cout << ans;
  }


  int main(){
    IOS
       solve();
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 256
#%%
N = int(input())
A = list(map(int, input().split()))

#%%
ans = 0
sum = 0
right = 0
for left in range(N):
    temp = 0
    while right < N and sum ^ A[right] == sum + A[right]:
        sum = sum ^ A[right]
        right += 1
    if left == right:
        right += 1
    else:
        sum = sum ^ A[left]
    ans += right - left
    
print(ans)


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

int x, n;
vector<int> p;
vector<int> not_p(200);
vector<int> not_p2(200);

int main() {
    cin >> x >> n;
    p.resize(n);
    for (int i = 0; i < 200; i++) {
        not_p.at(i) = abs(i + 1 - x);
    }
    for (int i = 0; i < 200; i++) {
        not_p2.at(i) = abs(-1 * i - x);
    }

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        p.at(i) = a;
        not_p.at(a - 1) = 10000;
    }

    int min_abs = 1000;
    int min_i = 0;
    for (int i = 0; i < 200; i++) {
        if (min_abs > not_p.at(i)) {
            min_abs = not_p.at(i);
            min_i = i;
        }
    }

    bool negative = false;

    for (int i = 0; i < 200; i++) {
        if (min_abs >= not_p2.at(i)) {
            min_abs = not_p2.at(i);
            min_i = i;
            negative = true;
        }
    }

    if (negative) {
        min_i = -1 * min_i;
    }
    else {
        min_i++;
    }

    cout << min_i << endl;


}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

int main() {
	ll x;
	cin >> x;
	int year = 0;
	ll yen = 100;
	while (1) {
		year++;
		yen *= 1.01;
		if (yen >= x) {
			cout << year << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define vi vector<int>
#define rep(i, xtz, n) for(int i=xtz; i<n; i++)
#define repx(i, xtz, n) for(int i=xtz; i>n; i--)
#define lli long long int

using namespace std;

int main(){
    //freopen("i.in", "r", stdin);
    string s1, s2;
    cin>>s1>>s2;
    int size1 = s1.size();
    int size2 = s2.size();
    vector<vector<int>> dp(size1+1, vector<int>(size2+1, 0));
    int cur=0;
    vector<char> vec;
    rep(i, 0, size1+1){
        rep(j, 0, size2+1){
            if(i==0 || j==0) dp[i][j] = 0;
            else if(s1[i-1] == s2[j-1]) dp[i][j] = dp[i-1][j-1]+1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    int i = size1, j = size2;
    while(i > 0 && j > 0){
        if(s1[i-1] == s2[j-1]) {vec.push_back(s1[i-1]); i--; j--;}
        else if(dp[i-1][j] > dp[i][j-1]) i--;
        else j--;
    }
    if(!vec.size()) cout<<"";
    else repx(i, vec.size()-1, -1) cout<<vec[i];
    //cout<<vec.size();
}

Measured memory_bytes: 35584
def findGCD(a,b):
    if a%b == 0:
        return b
    else:
        return findGCD(b,a%b)


def judge(a,b,c,d):
    if a<b or d<b:
        return False
    elif c >= b:
        return True
    else:
        g = findGCD(b,d)
        thr = b-g+a%g
        if thr > c:
            return False
        else:
            return True
        
T = int(input())
ABCD = []
for i in range(T):
    ABCD.append(list(map(int, input().split())))
        
for a,b,c,d in ABCD:
    if judge(a,b,c,d):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3188
typedef long long ll;
#include "bits/stdc++.h"
using namespace std;
int main() {
	int n,m;
	cin >> n >> m;
	vector<int> x(m);
	for (int i = 0; i < m; i++)
	{
		cin >> x[i];
	}
	
	sort(x.begin(), x.end());
	
	vector<int> isolation(m);
	for (int i = 1; i < m; i++)
	{
		isolation[i] = abs(x[i] - x[i - 1]);
	}

	sort(isolation.rbegin(), isolation.rend());
	int cnt = 0;
	for (int i = n - 1; i < m; i++)
	{
		cnt += isolation[i];
	}

	cout << cnt << endl;
	
}

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

int main(void){
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<ll> s(A), t(B);
  for(auto& _s: s) cin >> _s;
  for(auto& _t: t) cin >> _t;

  vector<ll> s_rev(s), t_rev(t);
  reverse(s_rev.begin(), s_rev.end());
  reverse(t_rev.begin(), t_rev.end());

  vector<vector<ll>> l{s, s_rev, t, t_rev};

  for(int loop = 0; loop < Q; loop++){
    const ll INF = 10000000000*10;
    ll x; cin >> x;
    ll ans = INF;
    for(int first = 0; first < (int)l.size(); first++){
      int first_row = first / 2;
      int first_column = first % 2;
      for(int second_off = 0; second_off < 2; second_off++){
        int second_row = (first / 2 + 1) % 2;
        int second_column = second_off;
        int second = second_row*2 + second_off;

        /*
        auto first_comp = [](ll a, ll b){return greater<ll>()(a, b);};
        auto second_comp = [](ll a, ll b){return greater<ll>()(a, b);};

        if(first_column == 1){
          first_comp = [](ll a, ll b){return greater<ll>()(a, b);};
        }else{
          first_comp = [](ll a, ll b){return less<ll>()(a, b);};
        }
        if(second_column == 1){
          second_comp = [](ll a, ll b){return greater<ll>()(a, b);};
        }else{
          second_comp = [](ll a, ll b){return less<ll>()(a, b);};
        }
        */

        int first_idx;
        ll first_pos;
        if(first_column == 1){
          auto it = lower_bound(l[first].begin(), l[first].end(), x, greater<ll>());
          if(it == l[first].end()) continue;
          first_pos = *it;
        }else{
          auto it = lower_bound(l[first].begin(), l[first].end(), x, less<ll>());
          if(it == l[first].end()) continue;
          first_pos = *it;
        }



        int second_idx;
        ll second_pos;
        if(second_column == 1){
          auto it = lower_bound(l[second].begin(), l[second].end(), first_pos, greater<ll>());
          if(it == l[second].end()) continue;
          second_pos = *it;
        }else{
          auto it = lower_bound(l[second].begin(), l[second].end(), first_pos, less<ll>());
          if(it == l[second].end()) continue;
          second_pos = *it;
        }


        ll cost = abs(x - first_pos) + abs(first_pos - second_pos);
        ans = min(ans, cost);
      }
    }
    cout << ans << endl;
  }
}


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

const int BITS = 29;

int N;
vector<int> A, B;

void stable_sort_by_bit(vector<int> &numbers, int bit) {
    int ones = 0;

    for (auto number : numbers)
        ones += number >> bit & 1;

    int positions[2] = {0, N - ones};
    vector<int> new_numbers(N);

    for (auto number : numbers)
        new_numbers[positions[number >> bit & 1]++] = number;

    swap(numbers, new_numbers);
}

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

    cin >> N;
    A.resize(N);
    B.resize(N);

    for (auto &a : A)
        cin >> a;

    for (auto &b : B)
        cin >> b;

    long long answer = 0;

    for (int bit = 0; bit < BITS; bit++) {
        long long full = (1LL << bit) - 1;
        long long ones = 0;

        for (int i = 0, j = N; i < N; i++) {
            while (j > 0 && (A[i] & full) + (B[j - 1] & full) > full)
                j--;

            ones += N - j;
        }

        long long a_ones = 0, b_ones = 0;

        for (int i = 0; i < N; i++) {
            a_ones += A[i] >> bit & 1;
            b_ones += B[i] >> bit & 1;
        }

        ones += N * (a_ones + b_ones);

        if (ones % 2 != 0)
            answer |= 1LL << bit;

        stable_sort_by_bit(A, bit);
        stable_sort_by_bit(B, bit);
    }

    cout << answer << '\n';
}


Measured memory_bytes: 2672
x, k, d = map(int, input().split())

x = abs(x)
n = x // d
a = abs(x - n*d)
b = abs(x - (n+1)*d)
if k <= n:
    print(abs(x-k*d))
    exit()
if (k - n) % 2 == 0:
    print(a)
else:
    print(b)



Measured memory_bytes: 9180
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    cout << s.substr(0, 4) << " " << s.substr(len-8) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

const int NMAX=400010; // we can calculate nCk until n is equal to NMAX
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}

int main()
{
  int n,k; cin >> n >> k;
  Make_Fact();
  Make_InvFact();

  if(n-1 <= k) {
    cout << Comb(2*n-1, n).x << "\n";
  }
  else {
    mint res = Comb(2*n-1, n);
    for(int i = k + 1; i <= n-1; ++i) {
      res -= Comb(n, i) * Comb(n-1, i);
    }
    cout << res.x << "\n";
  }
  return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll a,b,x;
  cin >> a >> b >> x;
  string ans;
  if(a+b<x || x<a) ans = "NO";
  else ans = "YES";

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
   int K, A, B;
   cin >> K >> A >> B;
   int m = A % K;
   int n = K - m;
   if(m == 0) {
     cout << "OK" <<endl;
     return 0;
   }
   int l = A + n;
   if(A <= l && l <= B) cout << "OK" <<endl;
   else cout << "NG" <<endl;
 }

Measured memory_bytes: 3608
N,K = map(int,input().split())
P = [int(x) for x in input().split()]
L = []
l = 0
for i in range(N):
    l += P[i]
    L.append(l)
ANS = []
ANS.append(L[K-1])
for i in range(N-K):
    ANS.append(L[i+K] - L[i])
ans = max(ANS) + K
print(ans/2)

Measured memory_bytes: 25160
//
//  main.c
//  Practice
//
//  Created by hoshino on 2015/10/19.
//  Copyright ?? 2015??´ hoshino. All rights reserved.
//

#include <stdio.h>

int main(void) {
    int x;
    scanf("%d", &x);


    printf("%d\n", x*x*x);
    // insert code here...
    
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

int main(void){
	vector<int> v;
	int n;cin >> n;
	for(int i=0;i<n;i++){
		int a;cin >> a;
		v.push_back(a);
	}

	for(int i=1;i<v.size();i++){
		for(int k=0;k<n;k++){
					cout << v[k];
					if(k!=n-1)cout << " ";
				}
				cout << endl;
		int key = v[i];
		int j = i -1;
		while(j>=0 && v[j]>key){
			v[j+1] = v[j];
			j--;
		}
		v[j+1] = key;

	}
	for(int k=0;k<n;k++){
				cout << v[k];
				if(k!=n-1)cout << " ";
			}
			cout << endl;
	
	return 0;
}

Measured memory_bytes: 1220
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			scanner.nextInt();
			int m = scanner.nextInt();
			int n = 2 * m + 1;
			int[][] a = new int[n / 2][2];
			int diff = 1 - (m & 1);
			IntStream.range(0, n / 4).forEach(i -> {
				a[i][0] = i + 1;
				a[i][1] = n / 2 - i + diff;
			});
			IntStream.range(n / 4, n / 2).forEach(i -> {
				a[i][0] = i + n / 4 + 2;
				a[i][1] = n - (i - n / 4);
			});
			IntStream.range(0, m).forEach(i -> System.out.println(a[i][0] + " " + a[i][1]));
		}
	}
}


Measured memory_bytes: 58584
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,Z,W;
    cin >> N >> Z >> W;
    vl A(N);
    rep(i,N){
        cin >> A[i];
    }
    if(N==1){
        cout << abs(A[0]-W);
        return 0;
    }
    cout << max({abs(A[N-1]-W),abs(A[N-1]-A[N-2])});
}

Measured memory_bytes: 3632
S=input()
total=0

for i in range(len(S)):
    if  i%2==0:
        if  (S[i]=='R')or(S[i]=='U')or(S[i]=='D'):
            pass
        else:
            total+=1
    else:
        if  (S[i]=='L')or(S[i]=='U')or(S[i]=='D'):
            pass
        else:
            total+=1

if  total==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1) {
    f[0] = f[1] = -1;
    for(ll i = 2; i <= n; ++i) {
      if(f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for(ll j = i * i; j <= n; j += i) {
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while(x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for(int p : fl) {
      if(res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ll n = 1e5 + 1;
  vl a(n);
  Sieve s(1e5 + 1);
  rep2(i, 1, n) {
    if(i % 2 == 0) continue;
    if(s.isPrime(i) && s.isPrime((i + 1) / 2)) a[i] = 1;
  }
  vl cum(n + 1, 0);
  rep(i, n) cum[i + 1] = cum[i] + a[i];
  ll q;
  cin >> q;
  rep(i, q) {
    ll l, r;
    cin >> l >> r;
    cout << cum[r + 1] - cum[l] << '\n';
  }
}

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

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define FOR(i,a,b) for(int i = a ; i < b ; ++i) 
# define F0R(i,b) for(int i = 0 ; i < b ; ++i) 

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



const ll inf = 1e9 ; 
const int MxN = 500001; 
const int mod = 1e9+7 ; 


int n ; ll k ; 
vt<int> a(MxN) ; 


void solve() {
	cin >> n >> k ; 
	FOR(i,1,n+1) cin >> a[i] ; 
	vt<int> b ;
	set<int> ans;
	int i = a[1] ;
	map<int,int> m1 ; 
	int cnt = 0 ; 
	while(1) {
		if(m1[i] == 1)
			break ;
		b.pb(i) ;  
		m1[i]++; 
		cnt++ ;
		if(cnt == k) {
			cout << i ;
			return ;  
		}
		i = a[i] ; 
	}
	//cout << i << endl ;
	int j = 0 ;
	while(1) {
		if(b[j] == i)
			break; 
		else{ 
			j++ ;
			k--; 
		}

	}
	vt<int> c ;
	//cout << j << endl ; 
	while(j < b.size()) {
		c.pb(b[j]) ; 
		j++;
	}
	//for(int x : c) cout << x << ' ' ; 
	k = k % c.size() ;
	
	if(k==0) 
		cout << *c.rbegin();  
	else
	cout << c[k-1] ; 




}

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

	int t =1; 
	//cin >> t ;
	while(t--) solve() ; 
	
	return 0 ; 
	
}



Measured memory_bytes: 13704
N = int(input())
p = list(map(int, input().split()))

psort = [0] * N
for i in range(N):
    psort[i] = p[i]
psort.sort()

cnt = 0
for i in range(N):
    if p[i] != psort[i]:
        cnt += 1

if cnt <= 2:
    print('YES')
else:
    print('NO')


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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 9e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

ll N;
VL d;

signed main() {
    cin >> N;
    REP(i, N) d.emplace_back(IN());
    sort(All(d));
    ll ans = 0;
    REP(i, (ll)1e5 + 1) {
        ll l = lower_bound(All(d), i) - d.begin();
        if(l == N - l) {
            ans++;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1400
N,K = list(map(int,input().split()))
x = list(map(int,input().split()))

s = 0
e = K - 1

re = min(abs(x[s]) + abs(x[s] - x[e]), abs(x[e]) + abs(x[e] - x[s]))
while e < N:
    tmp = min(abs(x[s]) + abs(x[s] - x[e]), abs(x[e]) + abs(x[e] - x[s]))
    re = min (re, tmp)
    s += 1
    e += 1
    
print(re)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> vec(32);
  vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << vec[N-1] << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <climits>
using namespace std;
int main(int argc, char *argv[])
{
  int A,B,C,X,Y;
  int ANum,BNum,CNum;
  int result = INT_MAX;

  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
  cin >> Y; 
  int loopMax = max(X,Y);  
  for (int i = 0; i <= loopMax; i++) {
    int tmpResult = 0;
    CNum = i * 2;
    ANum = max((X-i),0);
    BNum = max((Y-i),0);
    tmpResult = A*ANum+B*BNum+C*CNum;

    if (result > tmpResult) {
      result = tmpResult;
    }
  }
  cout << result << "\n";
  return 0;
}


Measured memory_bytes: 256
#C
N, M = list(map(int, input().split()))
ins = False
ans = [0]*N
ok = True
for i in range(M):
    s, c = list(map(int, input().split()))
    if N != 1 and s==1 and c==0:
        ok = False
    if ans[s-1]==0 or ans[s-1]==c:
        ans[s-1] = c
    else:
        ok = False
    if s == 1:
        ins = True
    else:
        ins = False
answer = []
if ok == True:
    for i in range(len(ans)):
        answer.append(str(ans[i]))
    #if N != 1 and ins==False:
    if N != 1 and answer[0]=='0':
        answer[0]='1'
    if N == 1 and M == 0:
        print(0)
    else:
        print(''.join(answer))
else:
    print('-1')


Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class Test
{	
    public static void Main()
	{
	    string s = Console.ReadLine();
	    s = s.Replace(" ", "");
	    int n = int.Parse(s);
	    
	    if(n%4 == 0) Console.WriteLine("YES");
	    else Console.WriteLine("NO");
	} 
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define V vector
#define SI size()
#define pb push_back
#define mk make_pair
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Test int test;cin>>test;while(test--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
using namespace std;
const int mod = 1e9+7;
int main() {
    Fast
    int n;
    cin>>n;
    int t = n%1000;
    if(t != 0){
        t = 1000 - t;
    }
    cout<<t;
}


Measured memory_bytes: 3652
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
  int H,W;scanf("%d %d",&H,&W);
  char C[H+1][W+1];
  for(int i=1;i<H+1;i++)for(int j=1;j<W+1;j++)cin>>C[i][j];
  for(int i=1;i<2*H+1;i++)
  {
    for(int j=1;j<W+1;j++)cout<<C[(i+1)/2][j];
    cout<<endl;
  }
}

Measured memory_bytes: 3744
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	d,g=MI()
	P=[]
	C=[]
	for _ in range(d):
		p,c=MI()
		P.append(p)
		C.append(c)
	#print(P,C)

	ans=10**10

	for i in range(1<<d):
		cnt=0
		gg=0
		for j in range(d):
			if i&1<<j:
				cnt+=P[j]
				gg+=P[j]*100*(j+1)+C[j]
		#print(i,cnt,gg)

		for j in reversed(range(d)):
			if not i&1<<j:
				if gg+(P[j]-1)*100*(j+1)>=g:
					cnt+=max(0,-((-g+gg)//(100*(j+1))))
					gg=g
					break
				else:
					cnt+=P[j]-1
					gg+=(P[j]-1)*100*(j+1)

		if gg>=g:
			ans=min(ans,cnt)
	print(ans)

















if __name__ == "__main__":
	main()


Measured memory_bytes: 74072
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007




int main(){
	vector<string> s(3);
	while(cin>>s[0]){
		if(s[0]=="0")break;
		cin>>s[1]>>s[2];
		vector<pair<int,int> > v(3,pii(0,0));
		for(int i=0; i<3; i++){
			if(i>0){
				if(s[i][0]=='A')v[i-1].fi+=1;
				else v[i-1].se+=1;
			}
			for(int j=1; j<s[i].size(); j++){
				if(s[i][j]=='A')v[i].fi+=1;
				else v[i].se+=1;
			}
			if(i==2){
				if(v[i].fi>v[i].se)v[i].fi+=1;
				else v[i].se+=1;
			}
		}
		for(int i=0; i<3; i++){
			cout<<v[i].fi<<" "<<v[i].se<<endl;
		}
	}
}

Measured memory_bytes: 1196
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, m, i, j, x, y, l, count;
    int[][] f;
    String s;

    f = new int[21][21];

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      count = 0;
      for(i = 0;i < 21;i++)for(j = 0;j < 21;j++)f[i][j] = 0;

      for(i = 0;i < n;i++){
        x = sc.nextInt(); y = sc.nextInt(); f[y][x]++;
      }

      m = sc.nextInt(); x = 10; y = 10; f[y][x]--;
      for(i = 0;i < m;i++){
        s = sc.next(); l = sc.nextInt();
        if("N".equals(s))for(j = 0;j < l;j++)f[++y][x]--;
        if("E".equals(s))for(j = 0;j < l;j++)f[y][++x]--;
        if("W".equals(s))for(j = 0;j < l;j++)f[y][--x]--;
        if("S".equals(s))for(j = 0;j < l;j++)f[--y][x]--;
      }

      for(i = 0;i < 21;i++)for(j = 0;j < 21;j++)if(f[i][j] > 0)count++;
      if(count > 0)out.println("No");
      else out.println("Yes");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 35472
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
c = a[0]
ch = -(-a[0]//2)
minD = 10**9
x = -1
for i in range(n):
    dif = abs(a[i]-ch)
    if minD>=dif:
        minD=dif
        x = a[i]
print(c,x)

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  long double a;
  cin >> a;
  long double b;
  cin >> b;
  long double res = a * b;
  cout << (long long) res << '\n';
  return 0;
}

Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int min(int a,int b){return a<b?a:b;}
int p[101],m[101][101];
int main()
{	int n;
	cin>>n;
	for(int i=1;i<=n;i++)//总共有n+1个有效数据
		cin>>p[i-1]>>p[i];//保证只有n个有效的数据重复的不管
	for(int i=1;i<=n;i++)
		m[i][i]=0;
	for(int l=2;l<=n;l++)//这个l状态积累量
	{
		for(int i=1;i<=n-l+1;i++)
		{	int j=i+l-1;
			m[i][j]=(1<<21);//极大取极小,这个地方要有括号
			for(int k=i;k<=j-1;k++)//从i开始,对l开始累加
			{
				m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}

		}
	}
	cout<<m[1][n]<<endl;
	return 0;
}


Measured memory_bytes: 3112
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

H, W = input_nums()

horizontal = 0
ans = 0

if W % 2 == 0:
    horizontal = W // 2
    ans = horizontal * H
else:
    horizontal = W // 2 + 1
    if H % 2 == 0:
        ans = ((horizontal * 2) - 1) * (H // 2)
    else:
        ans = ((horizontal * 2) - 1) * (H // 2 + 1) - (horizontal - 1)
if H == 1 or W == 1:
    ans = 1
print(ans)



Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    const int dur = h2 * 60 + m2 - (h1 * 60 + m1);
    const int ans = dur - k;

    cout << ans << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;

ull mod = 1e9 + 7;

ull sum_n(ull x) {
	return (x * (x + 1)) / 2;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ull n, k;
	cin >> n >> k;
	
	ull ans = 0ULL;
	
	for (ull i = k; i <= n + 1; ++i) {
		ull min_e = sum_n(i - 1);
		ull max_e = sum_n(n) - sum_n(n - i);
		
		if (max_e < min_e) {
			cerr << "houston we have a problem\n";
			cerr << n << ", " << i << ", " << min_e << ", " << max_e << endl;
			exit(1);
		}
		
		ull p = (max_e - min_e + 1) % mod;
		ans = (ans +  p) % mod;
	}
	
	
	cout << ans % mod << endl;
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define M 1000000007LL
 
ll kai(ll n){
  ll an = 1;
 while(n){
   an <<=1;
   an%=M;
   n--;
 }
  return an;
}

int main() {
  int N;
  ll x,y;
  map<pair<ll,ll>,pair<ll,ll>> iwa;
  ll worstiwa=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> x >> y;
    
    if(!x&&!y){
     worstiwa++;
     continue;
    }
    
    if(!x||!y){
     // cout << x << " " << y << endl;
     if(y==0){
       iwa[make_pair(0,1)].first+=1;
     }else{
       iwa[make_pair(0,1)].second+=1;
     }
     continue;
    }
    
    ll wa = gcd(x,y);
    x/=wa;
    y/=wa;
    if(x<0){
      x=-x;
      y=-y;
    }
    
    if(y>0){
     iwa[make_pair(x,y)].first+=1; 
    }else{
     iwa[make_pair(-y,x)].second+=1; 
    }
    
  }
 
  ll sum=1;
  
  for(pair<pair<ll,ll>,pair<ll,ll>> i:iwa){
    sum*=(kai(i.second.first)-1+kai(i.second.second)-1+1)%M;
    sum%=M;
  }
  sum=sum-1+worstiwa;
  if(sum<0)sum+=M;
  
  cout << (sum)%M << endl;
}

Measured memory_bytes: 19124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int answer = 0;
		int count = sc.nextInt();
		boolean endFlg = false;

		long[] nubmerList = new long[count];
		for(int i = 0; i < count; i++) {
			nubmerList[i] = sc.nextLong();
		}
		while(true) {
			for(int i = 0; i < count; i++) {
				if(nubmerList[i] % 2 == 1) {
					endFlg = true;
					break;
				}else {
					nubmerList[i] = nubmerList[i]/2;
				}
			}
			if(!endFlg) {
				answer++;
			}else {
				break;
			}
		}

		System.out.println(answer);
	}
}

Measured memory_bytes: 23764