akhauriyash/Code-Regression huggingface dataset:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(N):
    C.append(A[i] - B[i])
C.sort()
if sum(-i for i in C if i < 0) > sum(i for i in C if i > 0):
    print(-1)
else:
    if min(C) >= 0:
        print(0)
    else:
        D = sorted([i for i in C if i > 0], reverse=True)
        r = [D[0]]
        for i in range(len(D)-1):
            r.append(r[i] + D[i+1])
        print(len([i for i in C if i < 0])+bisect.bisect_left(r, sum(-i for i in C if i < 0))+1)


Measured memory_bytes: 97484
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,t,a,x,p=1;
    double tmp,min;
    cin >> n >> t >> a;
    for(int i=1;i<=n;i++){
        cin >> x;
        if(i==1){
            min = abs(a-(t-x*0.006));
            p = i;
            continue;
        }
        tmp = abs(a-(t-x*0.006));
        if(min>tmp){
            min = tmp;
            p = i;
        }
    }
    cout << p << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define int long long int
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

int main(){

	int n,m;
	cin >> n >> m;

	int ca[200],rd[200];

	for(int i=0;i<2*n;i++){
		ca[i] = i+1;
	}

	for (int i=0;i<m;i++){
		int k;
		cin >> k;

		if(k == 0) {

			for(int j=0;j<n;j++){
				rd[2*j] = ca[j];
			}
			for(int j=0;j<n;j++){
				rd[2*j+1] = ca[j+n];
			}
		}

		else{

			for(int j=0;j<k;j++){
				rd[2*n-k+j] = ca[j];
			}
			for(int j=0;j<2*n-k;j++){
				rd[j] = ca[k+j];
			}

		}

		for(int j=0;j<2*n;j++){
			ca[j] = rd[j];
		}
	}

	for (int k=0;k<2*n;k++){
		cout << rd[k] << endl;
	}

	return 0;
}



Measured memory_bytes: 3100
n,m = map(int,input().split())

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

rank_hlist = sorted(hlist)
rank_dict = dict()
for i in range(n):
    rank_dict[rank_hlist[i]] = i

ab_list = []
for i in range(m):
    a, b = map(int,input().split())
    if rank_dict[hlist[a-1]] < rank_dict[hlist[b-1]]:
        a,b = b,a
    ab_list.append([a,b])

good_n = [1]*n

ab_list.sort(key=lambda x:x[0], reverse=True)

for i in range(m):
    ab = ab_list[i]
    if rank_dict[hlist[ab[0]-1]] > rank_dict[hlist[ab[1]-1]]:
        good_n[ab[1]-1] = 0
    elif rank_dict[hlist[ab[0]-1]] == rank_dict[hlist[ab[1]-1]]:
        good_n[ab[0]-1] = 0
        good_n[ab[1]-1] = 0
    
print(good_n.count(1))


Measured memory_bytes: 39380
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int K; cin >> K;
	int cnt = 7;
	cnt %= K;
	int ans = 1;
	while (cnt) {
		cnt *= 10;
		cnt += 7;
		cnt %= K;
		++ans;
		if (ans >= 100000000) {
			ans = -1;
			break;
		}
	}
	cout << ans << "\n";

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  int ev = 0, od = 1;
  REP(i,n){
    int a;
    cin>>a;
    int nev, nod;
    if(a%2==0){
      nev = ev * 3 + od * 1;
      nod = od * 2;
    }else{
      nev = ev * 3 + od * 2;
      nod = od * 1;
    }
    ev = nev;
    od = nod;
  }
  cout<<ev<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()
    T = input()
    cnt = 0
    N = len(S)
    for i in range(N):
        if S[i] == T[i]:
            continue
        cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9368
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int w, h, n;
    cin >> w >> h >> n;
    int l = 0, r = w, d = 0, u = h;
    rep(i, n) {
        int x, y, z;
        cin >> x >> y >> z;
        if (z == 1) {
            chmax(l, x);
        } else if (z == 2) {
            chmin(r, x);
        } else if (z == 3) {
            chmax(d, y);
        } else {
            chmin(u, y);
        }
    }
    if (l <= r && d <= u) cout << (r - l) * (u - d) << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		//int n=sc.I;
		int[] s=sc.Ia;
		long[] a=new long[11];
		a[0]=s[2];
		for(int i = 1;i<=10;i++) {
			a[i]=a[i-1]*s[0]-s[1];
			Console.WriteLine("{0}",a[i]);
		}
		//Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public string Sz{get{return Console.ReadLine();}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2(int b){return Array.ConvertAll((((b&1)!=0?"0 ":"")+Console.ReadLine()+((b&2)!=0?" 0":"")).Split(),int.Parse);}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public string[] Sa2{get{return ("# "+Console.ReadLine()).Split();}}
}


Measured memory_bytes: 13268
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    
    let a : Vec<i64> = (0..n).map(|_|{
        iter.next().unwrap().parse().unwrap()
    }).collect();
    
    const N : usize = 200000;
    let mut buf = [0 ; N];
    
    let mut ball = 0;
    
    let half = n / 2;
    for i in half..n {
        if a[i] == 1 {
            buf[i] = 1;
            ball += 1;
        }
        else if a[i] == 0 {buf[i] = 0;}
        else {
            println!("-1");
            return;
        }
    }
    
    for i in (0..half).rev() {
        let mut sum = 0;
        let index = i + 1;
        
        let mut mul = 2;
        while(mul * index <= n){
            sum += buf[mul * index - 1];
            mul += 1;
        }
        
        if sum % 2 == a[i] {
            buf[i] = 0;
        }else{
            buf[i] = 1;
            ball += 1;
        }
    }
    
    println!("{}", ball);
    for i in 0..n {
        if buf[i] == 1 {
            print!("{} ", i + 1);
        }
    }
    println!(" ");
}

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

int main() {
  char s[4];
  fgets(s, 4, stdin);
  for (int i=0; i<3; i++) {
    if (s[i] == '1') s[i] = '9';
    else if (s[i] == '9') s[i] = '1';
  }
  int a = atoi(s);
  printf("%d\n", a);
  return 0;
}


Measured memory_bytes: 128
import sys
read = sys.stdin.read
n, k = map(int, read().split())


def count(digit, k):
    if k == 0:
        return 1
    elif k == 1:
        return digit
    elif k == 2:
        return digit * (digit - 1) // 2
    else:
        return digit * (digit - 1) * (digit - 2) // 6


def solve(n, k):
    if k == 0:
        return 1
    digit = len(str(n))
    res = 0
    if digit > k:
        res += count(digit - 1, k) * (9 ** k)
    pow10 = 10 ** (digit - 1)
    d, mod = n // pow10, n % pow10
    res += count(digit - 1, k - 1) * (9 ** (k - 1)) * (d - 1)
    res += solve(mod, k - 1)
    return res


print(solve(n, k))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n, c[1009], w[1009], sw[1009], cost[1009]; bool dp[1009][1009];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d%d", &c[i], &w[i]);
	for(int i = 0; i < n; i++) sw[i + 1] = sw[i] + w[i], dp[i][i + 1] = true;
	for(int i = 2; i <= n; i++) {
		for(int l = 0; l <= n - i; l++) {
			int r = l + i;
			if(dp[l][r - 1] && sw[r - 1] - sw[l] <= c[r - 1]) dp[l][r] = true;
			if(dp[l + 1][r] && sw[r] - sw[l + 1] <= c[l]) dp[l][r] = true;
		}
	}
	for(int i = 1; i <= n; i++) {
		cost[i] = 999999999;
		for(int j = 0; j < i; j++) {
			if(dp[j][i]) cost[i] = min(cost[i], cost[j] + 1);
		}
	}
	printf("%d\n", cost[n]);
	return 0;
}

Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;
  cin >> n;
  long long ans1=1,ans2=1,ans3=1;
  for(int i=0; i<n; i++) {
    ans1=(ans1*10)%1000000007;
    ans2=(ans2*9)%1000000007;
    ans3=(ans3*8)%1000000007;
  }
  //cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
  if(ans1+ans3-ans2*2<0) {
    cout << (ans1-ans2*2+ans3)%1000000007+1000000007 << endl;
    return 0;
  }
  cout << (ans1-ans2*2+ans3)%1000000007 << endl;
  return 0;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,ct=0; cin>>n;
	string s; cin>>s;
	for (int i=0; i<s.size(); i++)
		if (s.substr(i,3)=="ABC")
			ct++;
	cout<<ct<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	long long int a=1;
    int n;
    cin>>n;

	for(int i=1;i<=n;i++){
        a*=i;
	}
    cout<<a<<endl;

	return 0;
}

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

int main() {
    ll h, w;
    cin >> h >> w;
    if (w == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (h == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (w % 2 == 0) cout << h * (w/2) << endl;
    else cout << h * (w/2) + (h+1)/2 << endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int n = in();
    int s = in();
    if (n == 0 && s == 0) break;
    auto dp = vectors(n + 1, s + 1, 0LL);
    dp[0][0] = 1;
    for (int k = 0; k <= 100; k++) {
      for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j <= s; j++) {
          if (j + k <= s) dp[i + 1][j + k] += dp[i][j];
        }
      }
    }
    cout << dp[n][s] << endl;
  }
}



Measured memory_bytes: 3224
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,t = map(int, input().split())
    a = list(map(int, input().split()))
    b = [0]*n
    b[-1] = a[-1]
    for i in range(n-2, 0, -1):
        if b[i+1] < a[i]:
            b[i] = a[i]
        else:
            b[i] = b[i+1]
    res = 0
    temp = 0
    for i in range(n-1):
        if temp < b[i+1]-a[i]:
            temp = b[i+1]-a[i]
            res = 1
        elif temp == b[i+1]-a[i]:
            res += 1
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14636
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String o = sc.next();
        String e = sc.next();

        char[] array = new char[o.length()+e.length()];

        boolean f = false;
        for(int i = 0; i<array.length; i++) {
            if(f) array[i] = e.charAt(i/2);
            else array[i] = o.charAt(i/2);
            f = !f;
        }
        for(char c: array) {
            System.out.print(c);
        }
        System.out.println();

    }
}

Measured memory_bytes: 20692
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <assert.h>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
//int exgcd(int a,int b,int &x,int &y) {
//	if(!b) { x=1,y=0; return a; }
//	int g=exgcd(b,a%b,y,x); y-=a/b*x; return g;
//}
//const int N=1010;
//int cnt[N],p[N],col[N];
//int A,B,W,H;
//void FAIL() { printf("-1"); exit(0); }
//bool cmp(int x,int y) { return cnt[x]>cnt[y]; }
//int main() {
//	rd(H),rd(W),rd(A),rd(B);
//	int a=2*A-W;
//	int b=H-2*B;
//	int c=A*H-B*W;
//	int x,y,g=exgcd(a,b,x,y);
//	if(c%g) FAIL();
//	int m=b/g; if(m<0) m=-m;
//	x=(x%m+m)%m;
//	if(x>H) FAIL();
//	y=(c-a*x)/b;
//	if(y<0||y>W) FAIL();
//	
//	
//	for(int j=1;j<=y;++j) cnt[j]=B;
//	for(int j=y+1;j<=W;++j) cnt[j]=H-B;
//	for(int j=1;j<=W;++j) p[j]=j;
//	for(int i=1;i<=x;++i) {
//		sort(p+1,p+W+1,cmp);
//		for(int j=1;j<=W;++j) col[j]=0;
//		for(int j=1;j<=A;++j) col[p[j]]=1;
//		for(int j=1;j<=W;++j) {
//			printf("%d",col[j]);
//			cnt[j]-=col[j];
//		}
//		puts("");
//	}
//	for(int i=x+1;i<=H;++i) {
//		sort(p+1,p+W+1,cmp);
//		for(int j=1;j<=W;++j) col[j]=0;
//		for(int j=1;j<=W-A;++j) col[p[j]]=1;
//		for(int j=1;j<=W;++j) {
//			printf("%d",col[j]);
//			cnt[j]-=col[j];
//		}
//		puts("");
//	}
//	return 0;
//}
int W,H,A,B;
int main() {
	rd(H),rd(W),rd(A),rd(B);
	for(int i=1;i<=H;++i,puts(""))
		for(int j=1;j<=W;++j)
			printf("%d",i<=B&&j<=A||i>B&&j>A);
	return 0;
}

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

typedef long long ll;

ll md = 1000000007;

vector<ll> a;
vector<ll> x;

int main(int, char**) 
{
	ll n;
	std::cin >> n;
	a.resize(100);
	for (int i = 0; i < 9; i++)
		for (int j = 0; j < 9; j++)
			a[i*10+j] = (i + 1) * (j + 1);
	bool isT = false;
	for (int i = 0; i < 99; i++){
		if (a[i] == n) {
			isT = true;
			break;
		}
	}
	if (isT)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}


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

int main(){
	int n;
	int k;
	cin >> n >> k ;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int l = 0;
	int r = 1e9;
	while(r-l > 1){
		int x = (l+r)/2;
		auto f = [&](int x){
			ll now = 0;
			rep(i,n) now += (a[i]-1)/x;
				return now <= k;
		};
		if(f(x)) r = x;
		else l = x;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 3928
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut d: Vec<usize> = (0..n).map(|_| read()).collect();
    d.sort();
    println!("{}", d[n/2] - d[n/2-1]);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

typedef long long ll;
const int inf = 1e9;

string s;

int main(){
	cin>>s;
	if(s == "RRR")cout<<3<<endl;
	else if(s == "SRR" || s == "RRS")cout<<2<<endl;
	else if(s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR")cout<<1<<endl;
	else cout<<0<<endl;	
	return 0;
}


Measured memory_bytes: 3632
N, M = map(int, input().split())
A = list(map(int, input().split()))

cs = [0] * (N + 1)
for i in range(len(A)):
    cs[i + 1] = (cs[i] + A[i]) % M
d = {}
ans = 0
for i in range(len(cs)):
    if not cs[i] in d:
        d[cs[i]] = 1
    else:
        ans += d[cs[i]]
        d[cs[i]] += 1
print(ans)


Measured memory_bytes: 16268
import math

def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    for i in range(2, math.ceil(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def run():
    n = int(input())
    n_prime = 0
    for i in range(n):
        if is_prime(int(input())):
            n_prime += 1
    print(n_prime)

if __name__ == '__main__':
    run()


Measured memory_bytes: 5764
'use strict';
console.log(function(args){
  const tmp = args.trim().split('\n');
  const HW = tmp[0].split(' ').map(v=>v|0);
  const H = HW[0], W = HW[1];
  const map = [Array(W+2).fill(Infinity)]
  let s = 0;
  for ( let y = 1; y <= H; y++ ) {
    map.push([Infinity]);
    for ( let x = 0; x < W; x++ ) {
      if ( tmp[y][x] === '.' ) {
        s++; map[y].push( 0 );
      } else map[y].push( Infinity );
    }
    map[y].push(Infinity);
  }
  map.push(Array(W+2).fill(Infinity));
  const dir = [[-1,0],[0,-1],[1,0],[0,1]];
  const queue = [[1,1,2]];
  do {
    const q = queue.shift();
    for ( const d of dir ) {
      const x = q[0] + d[0], y = q[1] + d[1];
      if ( x === W && y === H ) return s - q[2];
      if ( map[y][x] === 0 ) {
        map[y][x] = q[2]+1;
        queue.push([x,y,q[2]+1]);
      }
    }
  } while ( queue[0] );
  return '-1';
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main() {
  int x,n;
  cin>>x>>n;
  map<int,int> mp;
  if(n==0){
    cout<<x<<endl;
    return 0;
  }
  rep(i,n){
    int p;
    cin>>p;
    mp[p]=1;
  }
  bool flag=0;
  int ans=x;
  if(mp[x]!=1){
    cout<<x<<endl;
    return 0;
  }
  for(int i=1; i<=130; i++){
    if(mp[x+i]!=1){
      ans=x+i;
      flag=1;
    }
    if(mp[x-i]!=1){
      ans=x-i;
      flag=1;
    }
    if(flag){
      break;
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

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

    int a = 0, b = 0;
    int h1 = 0, h2 = 0;

    cin >> h1;
    cin >> h2;
    b = abs(h2 - h1);

    vector<int> v(n);
    for (int i = 2; i < n; ++i) {
        int h;
        cin >> h;

        int cur = min(a + abs(h - h1), b + abs(h - h2));
        a = b;
        b = cur;
        h1 = h2;
        h2 = h;
    }
    cout << b;
}

Measured memory_bytes: 3760
# ABC106B - 105
n = int(input())
odd = []
odd_divs = []

for i in range(1, n + 1):
    if i % 2 == 1:
        odd.append(i)
        
for i in range(len(odd)):
    count = 0
    for j in range(1, odd[i] + 1):
        if odd[i] % j == 0:
            count += 1            
    odd_divs.append(count)
    
print(odd_divs.count(8))

Measured memory_bytes: 3060
def main():
    
    import itertools
    
    N = int(input())
    Ls = list(map(int, input().split()))

    ans = 0
    for L in list(itertools.combinations(Ls, 3)):

        if L[0] + L[1] > L[2] and  L[1] + L[2] > L[0] and  L[2] + L[0] > L[1] and len(L) == len(set(L)):
            ans += 1

    print(ans)
    
main()

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

int main(){
	
  int n , k;
  cin>>n>>k;
  int ans = 0;
  while(n--){
   	
    int x;
    cin>>x;
    if(x >=k)
      ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll pow_mod(ll a,ll b){
  ll res = 1;
  rep(i,b){
    res *= a;
    res %= 1000000007;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin>>a[i];
  if(n%2==1){
    vector<int> c(n/2+1,0);
    rep(i,n)c[a[i]/2]++;
    bool ok=1;
    if(c[0]!=1)ok=0;
    rep(i,n/2)if(c[i+1]!=2)ok=0;
    if(ok)cout << pow_mod(2,n/2) << endl;
    else cout << 0 << endl;
    return 0;
  }else{
    vector<int> c(n/2,0);
    rep(i,n)c[a[i]/2]++;
    bool ok=1;
    rep(i,n/2)if(c[i]!=2)ok=0;
    if(ok)cout << pow_mod(2,n/2) << endl;
    else cout << 0 << endl;
    return 0;
  }
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,d[200000];
int ans=0;
signed main(){
    cin>>n;
    rep(i,n)cin>>d[i];
    sort(d,d+n);
    rep(i,100000){
        int x=upper_bound(d,d+n,i)-d;
        if(x==n/2){
            ans++;
            
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1024
using System;
using System.Linq;

namespace AtCoderMake.ABC165
{
    class ABC165A
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray();
            int i = (s[0] - 1) / k;
            if (k*(i+1)<=s[1])
            {
                Console.WriteLine("OK");
            }
            else
            {
                Console.WriteLine("NG");
            }
        }
    }
}


Measured memory_bytes: 28292
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long dp[2222][2222];

int main(){
    int N;
    cin >> N;
    vector<pair<long long, long long>> A(N);
    REP(i, N){
        long long a;
        cin >> a;
        A[i] = make_pair(a, i);
    }
    sort(A.begin(), A.end(), greater<pair<long long, long long>>());

    vector<vector<long long>> dp(2222, vector<long long>(2222, -(1LL<<60)));
    dp[0][N] = 0;

    for(int i=0; i<N; i++){
        long long x = A[i].first;
        long long pos = A[i].second;
        for(int l=0; l<=i; l++){
            int r = l  + N - i;
            dp[l+1][r] = max(dp[l+1][r], dp[l][r] + x * abs(pos - l));
            dp[l][r-1] = max(dp[l][r-1], dp[l][r] + x * abs(pos - (r-1)));
        }
    }
    long long ans = 0;
    for(int i=0; i<N; i++)
        ans = max(ans, dp[i][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 42068
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin >>a>>b>>c;
  if(c<=b) cout <<"delicious\n";
  else{
    if(a+b>=c) cout <<"safe\n";
    else cout <<"dangerous\n";
  }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

#define N 100
#define V 100

int dp[N+1][N*V+1];

void run(){
    int n,W;
    cin>>n>>W;
    vi v(n),w(n);
    rep(i,n)cin>>v[i]>>w[i];
    fill(dp[0],dp[0]+N*V+1,inf);
    dp[0][0]=0;
    rep(i,n){
        rep(j,N*V+1){
            if(j<v[i])dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
        }
    }
    int ans=0;
    rep(i,N*V+1)if(dp[n][i]<=W)ans=i;
    cout<<ans<<endl;
}


Measured memory_bytes: 7128
#include<bits/stdc++.h>
const int MN=100000+5;
using namespace std;
typedef long long ll;
template<typename T>T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	in*=f;return in;
}
int n,k;
int nxt[MN*2],to[MN*2],h[MN],cnt;
int rt,a[MN],f[MN],L[MN],R[MN];
void add(int u,int v){to[cnt]=v,nxt[cnt]=h[u],h[u]=cnt++;}
int dfs1(int u,int fa){
	if(a[u]!=-1)L[u]=R[u]=a[u];
	else L[u]=INT_MIN+100,R[u]=INT_MAX-100;
	for(int e=h[u],v=to[e];~e;e=nxt[e],v=to[e])if(v^fa){
		f[v]=f[u]^1;
		if(!dfs1(v,u))return 0;
		L[u]=max(L[u],L[v]-1),R[u]=min(R[u],R[v]+1);
	}
	return L[u]<=R[u];
}
int dfs2(int u,int fa){
	for(int e=h[u],v=to[e];~e;e=nxt[e],v=to[e])if(v^fa){
		L[v]=max(L[v],L[u]-1),R[v]=min(R[v],R[u]+1);
		if(!dfs2(v,u))return 0;
	}
	return L[u]<=R[u];
}
void input(){
	IN(n);memset(h,-1,sizeof h);memset(a,-1,sizeof a);
	for(int i=1,u,v;i<n;++i)IN(u),IN(v),add(u,v),add(v,u);
	IN(k);
	for(int i=1,x,y;i<=k;++i)IN(x),IN(y),a[rt=x]=y;
	f[rt]=a[rt]&1;
	if(!dfs1(rt,0))return puts("No"),void();
	if(!dfs2(rt,0))return puts("No"),void();
	for(int i=1;i<=n;++i){
		if(L[i]==R[i]&&(L[i]&1)!=f[i])return puts("No"),void();
		if((L[i]&1)==f[i])a[i]=L[i];
		else a[i]=L[i]+1;
	}
	puts("Yes");
	for(int i=1;i<=n;++i)printf("%d\n",a[i]);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
int main(){
   ll n;
   cin>>n;
   ld A[n];
   loop(i,0,n){
      cin>>A[i];
   }
   ld prob[3000][3000];
   init(prob, 0);
   prob[0][0] = 1.0;
   loop(i,1,n+1){
      prob[i][0] = prob[i-1][0]*(1-A[i-1]);
   }
   loop(i,1,n+1){
      loop(j,1,n+1){
         if(j>i){
            break;
         }
         prob[i][j] = A[i-1]*prob[i-1][j-1] + (1-A[i-1])*prob[i-1][j];
      }
   }
   // loop(i,0,n+1){
   //    loop(j,0,n+1){
   //       cout<<prob[i][j]<<" ";
   //    }
   //    cout<<"\n";
   // }
   ld ans = 0;
   ll mid = n/2;
   loop(j,mid+1, n+1){
      ans+=prob[n][j];
   }
   cout<<fixed<<setprecision(10)<<ans<<endl;
   return 0;
}

Measured memory_bytes: 140928
#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

// https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396
using ll = long long;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main() {
	int H, W;
	cin >> H >> W;



	int w[H + 2][W + 2];

	ll count_dot[H * W];
	ll count_wall[H * W];

	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			 w[i][j] = -1;
		}
	}

	for (int i = 0; i < H * W; i++) {
		count_dot[i] = 0;
		count_wall[i] = 0;
	}



	for (int i = 0; i < H; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < W; j++) {
			if (s.at(j) == '.') {
				w[i + 1][j + 1] = 0;
			} else {
				w[i + 1][j + 1] = 1;
			}
		}
	}

	UnionFind uf(H * W);

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int x[] = {-1, 0, 1, 0};
			int y[] = {0,  1 , 0, -1};
			for (int k = 0; k < 4; k++) {
				int cur_x = j + 1;
				int cur_y = i + 1;
				int next_x  = cur_x + x[k];
				int next_y  = cur_y + y[k];
				int cur = w[cur_y][cur_x];
				int next = w[next_y][next_x];
 				if (next == -1) {
 					continue;
 				}
 				if (cur == next) {
 					continue;
 				}
 				uf.unite((next_y - 1) * W + next_x - 1, (cur_y - 1) * W + (cur_x - 1));
			}
		}
	}


	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int r = uf.root(i * W + j);
			if (w[i + 1][j + 1] == 0) {
				count_dot[r] ++;				
			} else {
				count_wall[r] ++;				
			}
		}
	}

	ll result = 0;


	for (int i = 0; i < H * W; i++) {
		result += count_dot[i] * count_wall[i];
	}
	cout << result << endl;


	return 0;
}


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

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e9 + 7;
const int N = 2e6 + 7;
const int M = 26;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve1()
{
    ll n,k;
    cin >> n >> k;
    ll ans = (n / k) * (n / k) * (n / k);
    if( k % 2 == 0 ){
        ll x = k / 2;
        ans += (n / x - n / k) * (n / x - n / k) * (n / x - n / k);
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 3680
#include <stdio.h>

int main(void)
{
	int a, b, c, i, N;
	scanf("%d", &N);
	for (i = 0; i < N; i++)
	{
		scanf("%d %d %d", &a, &b, &c);
		if(a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a)
			printf("YES");
		else
			printf("NO");
		putchar('\n');
	}
	return 0;
}

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

int main(){
	// sengen
	int n;
	LL money = 1000;
	LL keep;
	// nyuryoku
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
      
	}
	// keisan
	for(int i=0;i<n-1;i++){
		if(a[i] < a[i+1]){
			keep = money/a[i];
			money = money - a[i]*keep;
			money = money + a[i+1]*keep;
		}else{
			continue;
		}
	}
	// syutsuryoku
	cout << money << endl;
}

Measured memory_bytes: 3696
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int p[N];
  int ans=0;
  REP(i,N)cin>>p[i];
  REP(i,N){
    if(p[i]==i+1){
      ans++;
      i++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
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 mod 998244353
#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())
int n;
vector<ll>vec;
ll x;

struct xor_sum_lower_bound{
	vector<pair<int,ll> >t;
	//call init first!!!!!
	void init(vector<ll>a){
		t.clear();
		vector<ll>vec = a;
		int cur = 0;
		for(int mask=60;mask>=0;mask--){
			bool found = 0;
			for(int j=cur;j<vec.size();j++){
				if(((vec[j]>>mask)&1LL)){
					swap(vec[cur],vec[j]);
					found = 1;
					break;
				}
			}
			if(!found) continue;
			for(int j=cur+1;j<vec.size();j++){
				if(((vec[j]>>mask)&1LL)){
					vec[j] ^= vec[cur];
				}
			}
			cur++;
		}
		if(vec.size() > 100) vec.resize(100);
		while(vec.size() && vec[vec.size()-1] == 0) vec.pop_back();
		for(int i=0;i<vec.size();i++){
			int up = -1;
			for(int j=60;j>=0;j--){
				if(((vec[i]>>j)&1LL)){
					up = j;
					break;
				}
			}
			t.pb(mp(up,vec[i]));
		}
	}
	//num_1 ^ num_2 ^ ... ^ xr >= num?
	//if possible, return minimum num_1 ^ num_2 ^ ... ^ xr
	//if impossible, return -1
	ll calc(ll num,ll xr){
		if(num<0) num = 0;
		ll ret = -1;
		for(int mask=60;mask>=-1;mask--){
			if(mask >= 0 && ((num>>mask)&1)) continue;
			//(mask,INF)...same [mask,mask]...big
			int nxt = 0;
			ll num2 = num+(mask>=0?(1LL<<mask):0LL),sum = 0;
			bool bad = 0;
			for(int see=60;see>=(mask>=0?mask:0);see--){
				ll cur = (sum^xr);
				if( ((cur>>see)&1LL) == ((num2>>see)&1LL) ) continue;
				while(nxt != t.size() && t[nxt].fi > see) nxt++;
				if(nxt == t.size() || t[nxt].fi != see){
					bad = 1; break;
				}
				sum ^= t[nxt].sc;
			}
			if(bad) continue;
			for(int see=mask-1;see>=0;see--){
				ll cur = (sum^xr);
				if( ((cur>>see)&1LL) == 0 ) continue;
				while(nxt != t.size() && t[nxt].fi > see) nxt++;
				if(nxt == t.size() || t[nxt].fi != see){
					continue;
				}
				sum ^= t[nxt].sc;
			}
			ret = (sum^xr);
		}
     	if(ret != -1) assert(ret >= num);
		return ret;
	}
}kaede;

int main(){
    cin >> n;
    rep(i,n){ ll a; cin>>a; vec.pb(a); x^=a; }
    vector<int>pos;
    rep(i,60){
        if(!((x>>i)&1LL)) continue;
        rep(j,n){
            if((vec[j]&(1LL<<i)) > 0) vec[j] -= (1LL<<i);
        }
    }
    //cout << x << endl;
    //for(auto A:vec) cout << A << endl;
    kaede.init(vec);
    ll lb = 0, ub = (1LL<<61);
    while(ub-lb>1){
        ll mid = (lb+ub)/2;
        if(kaede.calc(mid,0) != -1 ) lb = mid; else ub = mid;
    }
    cout << lb*2LL+x << endl;
}


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

using namespace std;

vector<vector<pair<int, int>>> L;
vector<vector<pair<int, int>>> R;

bool DFS(int v, int position, unordered_map<int, int>& mem) {
  vector<pair<int, int>> vertices;
  if (mem.find(v) != mem.end()) {
    return mem[v] == position;
  } else {
    mem[v] = position;
  }

  for (auto p : L[v]) {
    if (!DFS(p.first, position + p.second, mem)) {
      return false;
    }
  }

  for (auto p : R[v]) {
    if (!DFS(p.first, position + p.second, mem)) {
      return false;
    }
  }

  return true;
}

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

  L.resize(N);
  R.resize(N);
  for (int i = 0; i < M; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    L[r].push_back(make_pair(l, -d));
    R[l].push_back(make_pair(r, +d));
  }

  vector<bool> used(N, false);
  for (int v = 0; v < N; v++) {
    if (used[v] or L[v].empty()) continue;

    unordered_map<int, int> mem;
    if (!DFS(v, 0, mem)) {
      printf("No\n");
      return 0;
    }

    vector<int> positions;
    for (const auto& p : mem) {
      positions.push_back(p.second);
      used[p.first] = true;
    }
    sort(positions.begin(), positions.end());

    if (positions.back() - positions.front() > 1e9) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}


Measured memory_bytes: 22180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int n, h, a[100010], b[100010];

    cin >> n >> h;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

    int ma = 0;
    for (int i = 0; i < n; i++) ma = max(ma, a[i]);

    sort(b, b + n);
    reverse(b, b + n);
    
    int sum = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] > ma) {
            sum += b[i];
            cnt++;
        }
        if (sum >= h) return cout << i + 1 << endl, 0;
    }

    cout << cnt + (h - sum + ma - 1) / ma << endl;

    return 0;
}


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

int main(void)
{
	double a[6], acopy, x , y;
	int i, ansx, ansy;
	
	while (scanf ("%lf %lf %lf %lf %lf %lf", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5])!= EOF){
		
		y = (a[3] * a[2] - a[0] * a[5]) / (a[3] * a[1] - a[0] * a[4]);
		x = (a[2] - a[1] * y) / a[0];
		printf("%.3f %.3f\n", x, y);
		/*acopy = a[1];
		for (i = 0; i < 3; i++)
		{
			a[i] *= a[4];
		}
		for (i = 3; i < 6; i++)
		{
			a[i] *= acopy;
		}
		a[0] -= a[3];
		if (a[0] == 0) x = 0;
		else {
			a[2] -= a[5];
			x = a[2] / a[0];
		}
		acopy = a[5] - (a[3] * x);
		y = acopy / a[4];
		if (x == -0) x = abs(x);
		if (y == -0) y = abs(y);
		
		ansx = 10000 * x;
		ansy = 10000 * y;
		if (ansx % 10 > 4) ansx += 10;
		if (ansy % 10 > 4) ansy += 10;
		
		printf("%.3f %.3f\n", (double)ansx / 10000, (double)ansy / 10000);*/
	}
	
	return (0);
}

Measured memory_bytes: 652
#include <stdio.h>

void bubble_sort(int[10]);

int main(){
	int i, height[10];
	for(i=0; i<10; ++i){
		scanf("%d", &height[i]);	
	}

	bubble_sort(height);

	for(i=9; i>6; --i){
		printf("%d\n", height[i]);
	}
	
	return 0;
}

void bubble_sort(int a[10]){
	int i, j, k;
	for(i=9; i>0; --i){
		for(j=0; j<i; ++j){
			if(a[j+1] < a[j]){
				k = a[j+1];
				a[j+1] = a[j];
				a[j] = k;
			}
		}
	}
}

Measured memory_bytes: 600
#include<iostream>
#include<map>

using namespace std;

int main() {
  int n, m;
  while(cin>>n>>m &&!(n==0 && m==0)) {
    map<int, int, greater<int> > myMap;
    for(int i=0; i<n; i++) {
      int d, p;
      cin>>d>>p;
      map<int, int>::iterator tmpItr;
      tmpItr = myMap.find(p);
      if(tmpItr == myMap.end()) {
        myMap.insert(make_pair(p, d)); // 期待値順にソート
      }
      else {
	myMap[tmpItr->first] += d;
      }
    }
    //cout<<myMap.size()<<endl;
    
    /*
    map<int, int>::iterator tmpItr = myMap.begin();
    for(; tmpItr!=myMap.end(); tmpItr++) {
      cout<<tmpItr->first<<" "<<tmpItr->second<<endl;
    }
    */
    
    for(int i=m; 0<i && !myMap.empty(); i--) {
      map<int, int>::iterator itr = myMap.begin();
      myMap[itr->first]--;
      if(myMap[itr->first] == 0) {
	myMap.erase(itr->first);
      }
    }
    
    int ans = 0;
    map<int, int>::iterator itr = myMap.begin();
    while(itr != myMap.end()) {
      ans += itr->first*itr->second;
      itr++;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1196
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

fn main() {
    let p: usize = read();
    let q: usize = read();
    let r: usize = read();

    println!("{}",min(p+q, min(q+r, r+p)));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
x,y,z,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
if k<x: a=a[:k]
if k<y: b=b[:k]
if k<z: c=c[:k]
d=[]
ans=[]
for i in a:
    for j in b:
        d.append(i+j)
d.sort(reverse=True)
if k<len(d): d=d[:k]
for i in c:
    for j in d:
        ans.append(i+j)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])


Measured memory_bytes: 134580
x, y, tx, ty = [int(i) for i in input().split()]
ans = []
for i in range(ty - y):
    ans.append('U')
for i in range(tx - x):
    ans.append('R')
for i in range(ty - y):
    ans.append('D')
for i in range(tx - x + 1):
    ans.append('L')
for i in range(ty - y + 1):
    ans.append('U')
for i in range(tx - x + 1):
    ans.append('R')
ans.append('DR')
for i in range(ty - y + 1):
    ans.append('D')
for i in range(tx - x + 1):
    ans.append('L')
ans.append('U')
ans = ''.join(ans)
print(ans)


Measured memory_bytes: 3188
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      int n = sc.nextInt();
      String s = sc.next();
      String t = sc.next();
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < n; i++) {
        sb.append(s.charAt(i));
        sb.append(t.charAt(i));
      }
      System.out.println(sb.toString());
    } finally {
      sc.close();
    }
  }
}

Measured memory_bytes: 35592
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}


int main(){
  int n,m; cin >>n >>m;
  vector<li> d(m-1),v(m);
  rep(i,m){
    cin >>v[i];
  }
  if(n>=m){
    print(0);
    return 0;
  }
  sort(v.begin(),v.end());
  rep(i,m-1) d[i]=v[i+1]-v[i];
  sort(d.begin(),d.end(),greater<li>());
  li s=0; rep(i,n-1) s+=d[i];
  print(v[m-1]-v[0]-s);
}


Measured memory_bytes: 4772
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0533?year=2009

#include <bits/stdc++.h>

using namespace std;

int main() {
    vector<int> a(10);
    for (int i = 0; i < 10; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<>());
    int ans1 = accumulate(a.begin(), a.begin() + 3, 0);

    vector<int> b(10);
    for (int i = 0; i < 10; ++i) {
        cin >> b[i];
    }
    sort(b.begin(), b.end(), greater<>());
    int ans2 = accumulate(b.begin(), b.begin() + 3, 0);

    cout << ans1 << " " << ans2 << endl;
    return 0;
}

/*
 *
 */


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main()
{int n,x,s=0;
 int a[50];
 cin>>n>>x;
 for(int i=0;i<n;i++)
    cin>>a[i];
 sort(a,a+n);
 for(int i=n-1;i>=n-x;i--)
    s+=a[i];
 cout<<s<<endl;
} 

Measured memory_bytes: 256