akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;
ll mod(ll x){
    ll res=x%MOD;
    return res+(res<0?MOD:0);
}
ll inv(ll x){
    ll b=MOD,u=1,v=0;
    while(b){
        ll t=x/b;
        x-=t*b;swap(x,b);
        u-=t*v;swap(u,v);
    }
    return mod(u);
}
vector<ll> prods(int x){
    vector<ll> res(x+1);
    res[0]=1;
    for(int i=1; i<=x; i++)res[i]=mod(i*res[i-1]);
    return res;
}
vector<ll> pows(ll a,int x){
    vector<ll> res(x+1);
    res[0]=1;
    a=mod(a);
    for(ll i=1; i<=x; i++)res[i]=mod(a*res[i-1]);
    return res;
}
ll power(ll a, ll n){
    ll res=1;
    a=mod(a);
    for(;n>0;n>>=1){
        if(n&1)res=mod(res*a);
        a=mod(a*a);
    }
    return res;
}

vector<ll> p;//p=prods(MAX_n)
ll comb(ll a, ll b){
    if(b<0||b>a)return 0;
    return mod(mod(p[a]*inv(p[b]))*inv(p[a-b]));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<ll> c(n);rep(i,n)cin>>c[i];
    sort(c.begin(),c.end());
    ll ans = 0;
    for(int i=0; i<n; i++){
        ll sum = (((power(2,n-1)+(n-i-1)*power(2,n-2))%MOD)*c[i])%MOD;
        ans = (ans+sum)%MOD;
    }
    ans = (ans*power(2,n))%MOD;
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>

using namespace std;

int N, L;
int main() {
  cin >> N >> L;
  vector<string> vs;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    vs.push_back(move(s));
  }
  sort(vs.begin(), vs.end());
  for (const auto& i : vs) {
    cout << i;
  }
  cout << endl;
}


Measured memory_bytes: 256
n,m,*a=map(int,open(0).read().split())
d=[0]+[-1]*n*9
for i in range(n):
 for j,k in enumerate((0,2,5,5,4,5,6,3,7,6)):
  if d[i]>=0and j in a:d[i+k]=max(d[i+k],d[i]*10+j)
print(d[n])

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

using namespace std;

using int64 = long long;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int main()
{
  int N, M, A[100000];

  cin >> N >> M;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  UnionFind uf(N);
  for(int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    uf.unite(x, y);
  }

  int K = N - M;
  if(K == 1) {
    cout << 0 << endl;
    return (0);
  }
  if((K - 1) * 2 > N) {
    cout << "Impossible" << endl;
    return (0);
  }


  vector< int > items[100000];
  for(int i = 0; i < N; i++) {
    items[uf.find(i)].emplace_back(A[i]);
  }

  int64 ret = 0;
  vector< int > lis;
  for(int i = 0; i < N; i++) {
    if(uf.find(i) != i) continue;
    sort(begin(items[i]), end(items[i]));
    ret += items[i][0];
    for(int j = 1; j < items[i].size(); j++) {
      lis.emplace_back(items[i][j]);
    }
  }
  sort(begin(lis), end(lis));

  for(int i = 0; i < K - 2; i++) {
    ret += lis[i];
  }
  cout << ret << endl;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  
  int A = vec.at(0);
  int B = 0;
  int j;
  
  for (j = 0;j < N;j++) {
    B++;
    if (A == 2) {
      break;
    }
    A = vec.at(A - 1);
  }
  
  if (j == N) {
    cout << -1 << endl;
  } else {
    cout << B << endl;
  }
    
}


Measured memory_bytes: 640
N, Y = map(int, input().split())

n, m, l = -1, -1, -1
flag = False
for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j
        if Y == 10000 * i + 5000 * j + 1000 * k:
            n, m, l = i, j, k
            flag = True
            break
    if flag:
        break

print(n, m, l)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    ll a[10101], b[10101];
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    ll cnt = 0;
    REP(i,n) {
        if(a[i] > b[i]){
            cnt -= a[i] - b[i]; // a to b
        } else {
            cnt += (b[i] - a[i]) / 2; // b to a 
        }
    }
    if(cnt >= 0) cout << "Yes";
    else cout << "No"; 
    cout << '\n';
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
int main(){
    fast_io

    int c[3][3];
    rep(i,3)rep(j,3) cin>>c[i][j];

    for(int i=0;i<3;i++){
        for(int j=i+1;j<3;j++){
            if(c[i][j]+c[j][i] == c[i][i]+c[j][j]){

            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B = get_ints

c = B - A
puts ( c * (c-1))/2 - A


Measured memory_bytes: 14404
#include<map>
#include<cctype>
#include<string>
#include<vector>
#include<iostream>

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

using namespace std;

void operator*=(vector<int> &a,const vector<int> &b){ rep(i,a.size()) a[i]+=b[i]; }
void operator/=(vector<int> &a,const vector<int> &b){ rep(i,a.size()) a[i]-=b[i]; }

map< string,vector<int> > f,g; // f : ツ組ツ猟ァツ療環づ個鳴シツ前 -> ツ甘ョツ本ツ療環づ個療ア, g : ツ陛渉青板づ個鳴シツ前 -> ツ甘ョツ本ツ療環づ個療ア
map< vector<int>,string > f_inv;

int idx;
string s;
bool error;

vector<int> expr();

vector<int> variable(){
	string a;
	while(idx<s.length() && isalpha(s[idx])) a+=s[idx++];
	return g[a];
}

vector<int> factor(){
	if(idx<s.length() && s[idx]=='('){
		idx++;
		vector<int> a=expr();
		idx++;
		return a;
	}
	else return variable();
}

vector<int> term(){
	vector<int> a=factor();
	while(idx<s.length() && (s[idx]=='*' || s[idx]=='/')){
		char op=s[idx++];
		vector<int> b=factor();
		if(op=='*') a*=b;
		else        a/=b;
	}
	return a;
}

vector<int> expr(){
	vector<int> a=term();
	while(idx<s.length() && (s[idx]=='+' || s[idx]=='-')){
		idx++;
		vector<int> b=term();
		if(a!=b){ error=true; break; }
	}
	return a;
}

string parse(string formula){
	idx=0;
	s=formula;
	error=false;

	vector<int> res=expr();
	if(error) return "error";
	if(f_inv.count(res)==0) return "undefined";
	return f_inv[res];
}

int main(){
	for(int n,m,p;cin>>n>>m>>p,n;){
		f.clear();
		g.clear();
		f_inv.clear();

		rep(i,m){
			string s; cin>>s;
			vector<int> a(n);
			rep(j,n) cin>>a[j];
			f[s]=a;
			f_inv[a]=s;
		}

		string formula; cin>>formula;
		rep(i,p){
			string s,t; cin>>s>>t;
			g[s]=f[t];
		}

		cout<<parse(formula)<<endl;
	}

	return 0;
}

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

using namespace std;

int main() {
  int h,w; cin >> h >> w;
  int a[30][30];
  for(int i=0;i<h;++i)
    for(int j=0;j<w;++j)
      cin >> a[i][j];

  int ans=1e9;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      int sum=0;
      for(int k=0;k<h;++k){
	for(int l=0;l<w;++l){
	  sum+=min(abs(k-i),abs(l-j))*a[k][l];
	}
      }
      ans=min(ans,sum);
    }
  }

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



Measured memory_bytes: 3112
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) * n != 0){
		int sum = 0;
		
		n /= 4;
		while (n-- > 0){
			int t;
			
			scanf("%d", &t);
			sum += t;
		}
		printf("%d\n", sum);
	}
	
	return 0;
}

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


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


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


MOD = 1000000007
N = read()
S1 = input()
S2 = input()

if S1[0] == S2[0]:
    ans = 3
    same = True
    n = 1
else:
    ans = 6
    same = False
    n = 2

while n < N:
    if S1[n] == S2[n]:
        n += 1
        if same:
            ans = (ans * 2) % MOD
        else:
            same = True
    else:
        n += 2
        if same:
            ans = (ans * 2) % MOD
            same = False
        else:
            ans = (ans * 3) % MOD

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1e17
#define ninf -1e17
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
ll n;
ll a[405];
ll dp[405][405];
ll compute(int i, int j)
{
    if(i==j) return a[i];
    if(dp[i][j]!=-1) return dp[i][j];
    int k;
    ll ans = inf;
    ll ex = 0;
    FOR(k, i, j+1) ex += a[k];
    FOR(k, i, j)
    {
        ans = MIN2(ans, ex + compute(i, k) + compute(k+1, j));
    }
    return dp[i][j] = ans;
}
int main()
{
    she_told_me_dont_worry
    cin>>n;
    int i, j;
    FOR0(i, n+2)FOR0(j, n+2) dp[i][j] = -1;
    ll ans = 0;
    FOR0(i, n) 
    {
        cin>>a[i];
        ans -= a[i];
    }
    ans += compute(0, n-1);
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 1536
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define INF 1100000000
#define LLINF 1100000000000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;

int hist[9];
int main()
{
  int N; cin >> N;
  REP(i, N) {
    int a; cin >> a;
    if (a < 3200) hist[a / 400]++;
    else hist[8]++;
  }

  int cnt = 0;
  REP(i, 8) cnt += (hist[i] > 0);
  cout << max(1, cnt) << ' ' << (cnt + hist[8]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <map>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007

template <class T>
T getDigit(T num) {
    ll digits = 0;
    if (num == 0) return 1;
    while (num != 0) {
        digits++;
        num /= 10;
    }
    return digits;
}

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

    // input
    ll N;
    cin >> N;
    
    // calculation
    ll A, B, min_digit = getDigit(N), F_A_B;
    ll routeN = (ll)sqrt((double)N) + 1;
    // max計算量: 10^10 * 10(桁数を求める)
    for (int i = 1; i <= routeN; ++i) {
        A = i;
        if (N%A == 0) {
            B = N/A;
            F_A_B = max(getDigit(A), getDigit(B));
            min_digit = min(min_digit, F_A_B);
        }
    }
    
    cout << min_digit << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M;
vv<int> tree;
vv<ll> prol, pror;
vector<int> ans;

void dfs_pre(int v, int p) {
    for (int u : tree[v]) {
        if (u != p) dfs_pre(u, v);
    }

    prol[v].resize(tree[v].size() + 1);
    prol[v][0] = 1;
    for (int i = 0; i < (int)tree[v].size(); ++i) {
        if (tree[v][i] != p) prol[v][i + 1] = (prol[v][i] * (prol[tree[v][i]].back() + 1)) % M;
        else prol[v][i + 1] = prol[v][i];
    }
    pror[v].resize(tree[v].size() + 1);
    pror[v][tree[v].size()] = 1;
    for (int i = tree[v].size() - 1; i >= 0; --i) {
        if (tree[v][i] != p) pror[v][i] = (pror[v][i + 1] * (prol[tree[v][i]].back() + 1)) % M;
        else pror[v][i] = pror[v][i + 1];
    }
}

void dfs(int v, int p, ll subp) {
    ans[v] = prol[v].back() * (subp + 1) % M;

    for (int i = 0; i < (int)tree[v].size(); ++i) {
        if (tree[v][i] != p) dfs(tree[v][i], v, (subp + 1) * prol[v][i] % M * pror[v][i + 1] % M);
    }
}

int main() {
    cin >> N >> M;
    tree.resize(N);
    rep(i, N - 1) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }

    prol.resize(N);
    pror.resize(N);
    dfs_pre(0, -1);

    ans.resize(N);
    dfs(0, -1, 0);

    for (ll a : ans) write(a);
}

Measured memory_bytes: 23808
N,x = map(int,input().split())
alist = list(map(int,input().split()))
alist.sort()
counter = 0
for i in range(N):
    x -= alist[i]
    if x>=0:
        if i!=N-1:
            counter += 1
        else:
            if x==0:
                counter += 1
    else:
        break
print(counter)


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	vector<int> A=vecin(N);
	vector<ll> V(N,0);
	ll sum=1;
	REP(i,N){
		if(!A[i]){
			sum *= (3LL-V[A[i]]);
			sum %= atcoder_mod;
		}
		else{
			sum *= (V[A[i]-1]-V[A[i]]);
			sum %= atcoder_mod;
		}
		V[A[i]]++;
	}
	out(sum);
	return 0;
}


Measured memory_bytes: 1408
import java.math.BigDecimal;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int[][] arr = new int[n][2];

        Data[] data = new Data[n];
        for (int i=0; i<n; i++) {
//            arr[i][0] = sc.nextInt();
//            arr[i][1] = sc.nextInt();
            data[i] = new Data(arr[i][0], arr[i][1]);
        }

        int[] l = new int[n];
        int[] r = new int[n];
        for (int i=0; i<n; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        Arrays.sort(l);
        Arrays.sort(r);

//        System.out.println(data[0].b);

        if (n%2 == 1) {
            System.out.println(r[n/2]-l[n/2]+1);
            return;
        }

        int min = l[n/2-1] + l[n/2];


//        Data2[] data2s = new Data2[n];
//        for (int i=0; i<n; i++) {
//            data2s[i] = new Data2(arr[i][0], arr[i][1]);
//        }

//        Arrays.sort(data2s);
        int max = r[n/2-1] + r[n/2];

        System.out.println((max-min+1));
    }
    public static class Data implements Comparable<Data> {
        int a, b;
        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }
        public int compareTo(Data other) {
            if (this.a == other.a) {
                return this.b - other.b;
            } else {
                return this.a - other.a;
            }
        }
    }
    public static class Data2 implements Comparable<Data2> {
        int a, b;
        public Data2(int a, int b) {
            this.a = a;
            this.b = b;
        }
        public int compareTo(Data2 other) {
            if (this.b == other.b) {
                return this.a - other.a;
            } else {
                return this.b - other.b;
            }
        }
    }
}


Measured memory_bytes: 61888
s = input()
n = len(s)
r = [0]*n
l = [0]*n
for i in range(n-1):
    if s[i] == "R":
        r[i] += 1
        if s[i+1] == "R":
            r[i+2] += r[i]
            r[i] = 0
    if s[-i-1] == "L":
        l[-i-1] += 1
        if s[-i-2] == "L":
            l[-i-3] += l[-i-1]
            l[-i-1] = 0
ans = []
for i in range(n):
    ans.append(r[i]+l[i])
# print(r)
# print(l)
print(*ans)

Measured memory_bytes: 12412
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
    ll n,x;
    cin >> n >> x;

    ll g=gcd(n,x);

    cout << g*(n/g-1)*3 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
#include <numeric>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define REP(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define MSG(a) cout << #a << " "  << a << endl;
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

int snac[10000];
int dp[3][5105][2]; // dp[i][j][k] := i : |CgiôïÅg¢Üí·jj : [Ì k : ¼OÌrbg

const int INF = 0x7f7f;

int main()
{
	int n;
	cin >> n;
	{
		rep(i, 3) rep(j, n/2+2) rep(k, 2) dp[i][j][k] = INF;
		memset(snac, 0, sizeof(snac));

		rep(i, n-1)
			cin >> snac[i];

		dp[0][0][0] = 0;
		rep(i, n)
		{
			int m = min(i, n/2 + 2);
			rep(j, m+1)
			{
				dp[(i+1)&1][j+1][0] = min(dp[i&1][j][0], dp[i&1][j][1] + snac[i]);
				dp[(i+1)&1][j][1]   = min(dp[i&1][j][1], dp[i&1][j][0] + snac[i]);
			}
			memcpy(dp[i&1], dp[2], sizeof(dp[2]));
		}

		cout << dp[n%2][n/2][0] << endl;
	}
}

Measured memory_bytes: 988
#include<bits/stdc++.h>
int n,m;
std::map<std::string,int>cnt;
std::string s;
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n;
    std::cin >> s;
    std::vector<int>max_pos(10,-1);
    std::vector<int>min_pos(10,n + 1);
    for(int i = 0; i <= 9; ++i) min_pos[i] = n + 1,max_pos[i] = -1;
    for(int i = 0; i < n; ++i){
        int m = s[i] - '0';
        max_pos[m] = i;
        min_pos[m] = std::min(min_pos[m],i);
    }
    std::map<std::string,int>memo;
    for(int i = 0; i < n; ++i){
        int key = s[i] - '0';
        for(int l = 0; l <= 9; ++l){
            for(int r = 0; r <= 9; ++r){
                if(max_pos[r] == -1 or min_pos[l] == n + 1)
                    continue;
                if(min_pos[l] < i && i < max_pos[r])
                    memo[std::to_string(l) + std::to_string(key) + std::to_string(r)] += 1;
            }
        }
    }
    std::cout << memo.size() << '\n';
}




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

int main(){
    int a, b, d, r;
    double f;

    cin >> a >> b;

    d = a / b;
    r = a % b;
    f = static_cast<double>(a) / static_cast<double>(b);

    cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
    return 0;
}



Measured memory_bytes: 3284
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int a = cin.nextInt();
        int b = cin.nextInt();
        if (a <= b) {
            System.out.println(a);
        } else {
            System.out.println(a - 1);
        }
    }
}


Measured memory_bytes: 20816
n = gets.to_i
array =gets.chomp.split(" ").map(&:to_i);
sum = -1
a = true
while a

  array.each_with_index do |value, i|
     if value%2 == 0
      array[i] = value/2
    else
      a = false
      array[i] = value
    end
  end
  sum +=1
end
 puts sum


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 1; i <= n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
#define FI first
#define SE second
#define VI vector<int>
#define CLR(x) memset(x, 0, sizeof(x))
#define SZ(x) (x.size())
#ifdef QWERTIER
#define err(x) cerr<<x<<endl;
#else
#define err(x)
#endif


int n, a[200010];
int main() {
#ifdef QWERTIER
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  int cnt(0);
  FOR (i, n) {
    scanf("%d", &a[i]);
    if (a[i] % 2 == 1)
      cnt++;
  }
  printf("%s",cnt%2?"NO":"YES");
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>

int main() {
	int n = 0, x = 0, y = 0;
	int fx = 0, fy = 0, ft = 0;
	int time = 0;
	bool yn = true;
	std::cin >> n;
	std::cin >> ft >> fx >> fy;
	if (n != 1) {
		for (int i = 0; i < n - 1; i++) {
			std::cin >> time >> x >> y;
			if (std::abs(x - fx) == std::abs(y - fy)) {
				if ((time - ft) % 2 == 0) {
					continue;
				}
				else {
					std::cout << "No" << std::endl;
					return 0;
				}
			}else if (std::abs(x - fx) + std::abs(y - fy) > time - ft) { yn = false; }
			ft = time;
			fx = x;
			fy = y;
		}
	}
	else {
		if (fx + fy > ft) { yn = false; }
		else { yn = true; }
	}
	if (yn == true) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;
}

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

const i64 MOD = 1e9 + 7;

vector<i64> fac(1e6 + 1);
vector<i64> ifac(1e6 + 1);

i64 mpow(i64 x, i64 n)
{
  i64 ans = 1;
  while (n != 0)
  {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans;
}

i64 comb(i64 a, i64 b)
{
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0 || b < 0)
    return 0;
  i64 tmp = ifac[a - b] * ifac[b] % MOD;
  return tmp * fac[a] % MOD;
}

int main()
{
  i64 x, y;
  cin >> x >> y;
  i64 tx = 0, ty = 0;
  fac[0] = 1;
  ifac[0] = 1;
  for (i64 i = 0; i <= 1e6; i++)
  {
    fac[i + 1] = fac[i] * (i + 1) % MOD;
    ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
  }
  for (i64 i = 1; i <= 1e6; i++)
  {
    tx += 2;
    ty += 1;
    if (tx - x == y - ty)
    {
      cout << comb(i, tx - x) << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 15872
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long K = sc.nextLong();
    
    if(N>=K) {
      N %= K;
    }
    if(K-N<N) {
      N = K-N;
    }
    System.out.println(N);
  }
}

Measured memory_bytes: 35580
#include<stdio.h>
#define MAX 100001
#define max2(a,b) a<b?b:a
#define max3(a,b,c) max2((max2(a,b)),c)
#define max4(a,b,c,d) max3((max2(a,b)),c,d)

int main(){
	int i,j,k;
	long long int ans = 0;
	int min = 0;
	int tmp,t;
	int flag = 0;
	int a[MAX];
	int n;
	
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	
	for(i = 0;i < n;i++){
		//if(min+1 < a[i]){
			t = (a[i]-1)/(min+1);
			ans += t;
			if(t)flag = 1;
			tmp = (a[i]-1)%(min+1)+1;
			if(flag&&min < tmp){
				//min = tmp;
			}
			if(flag&&!i)min = 1;
			if(!flag&&min<a[i])min = a[i];
			flag = 0;
		//}
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
n, y = map(int, input().split())
y /= 1000 #10円札,5円札,1円札

for i in range(n+1): # i = 10円札の枚数
    for j in range(n-i+1): # j = 5円札の枚数
        k = n - i - j
        if 10*i + 5*j + k == y:
            print(i, j, k)
            exit()

print('-1 -1 -1')

Measured memory_bytes: 2940
m=-1e9
n=int(raw_input())
B=[[0]*(n+1) for _ in range(n+1)]
for _ in range(n):
  A=map(int,raw_input().split())
  for j in range(n):
    s=0
    for k in range(j,n):
      s+=A[k]
      B[j][k]=max(B[j][k],0)+s
      m=max(B[j][k],m)
print m

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

ll solve(ll x, ll y)
{
    ll prod=1;
    for(int i=1;i<=y;i++)
    {
        prod*=x;
        prod%=MOD;
    }
    return prod;
}
int main()
{
    ll n;
    cin>>n;
    ll ans1= solve(10,n)%MOD;
    ll ans2= solve(9,n)%MOD;
    ll ans3= solve(9,n)%MOD;
    ll ans4= solve(8,n)%MOD;
    ll ans= (ans1-ans2-ans3+ans4)%MOD;
    if(ans<0)
        ans+=MOD;
    cout<<ans<<endl;
    return 0;
}

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

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

    int n, m, c;
    cin >> n >> m >> c;
    long int b[m], a[n][m];
    rep(i, m) cin >> b[i];
    rep(i, n){
        rep(j, m) cin >> a[i][j];
    }
    
    int ans = 0;
    rep(i, n){
        long int test = 0;
        rep(j, m){
            test += a[i][j] * b[j];
        }
        if(test > -c) ans++;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a;
    string s;
    cin >> a >> s;
    if(a < 3200) cout << "red" << endl;
    else cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#include <queue>
#include <functional>
#include <sstream>
#include <climits>
#include <map>
using namespace std;

typedef long long LL;

const char *P;

LL aexpr();
LL xexpr();
LL oexpr();
LL expr();
LL term();
LL fact();

LL oexpr(){
	LL x = xexpr();
	while(*P == '|'){
		++P;
		x |= xexpr();
	}
	return x;
}

LL xexpr(){
	LL x = aexpr();
	while(*P == '^'){
		++P;
		x ^= aexpr();
	}
	return x;
}

LL aexpr(){
	LL x = expr();
	while(*P == '&'){
		++P;
		x &= expr();
	}
	return x;
}

LL expr(){
	LL x = term();
	while(1){
		if(*P == '+'){
			++P;
			x += term();
		}
		else if(*P == '-'){
			++P;
			x -= term();
		}
		else{
			break;
		}
	}
	return x;
}

LL term(){
	LL x = fact();
	while(*P == '*'){
		++P;
		x *= fact();
	}
	return x;
}

LL fact(){
	if(*P == '('){
		++P;
		LL x = oexpr();
		if(*P != ')'){
			throw 0;
		}
		++P;
		return x;
	}

	if(*P == '0' || !isdigit(*P)){
		throw "";
	}

	char *endp;
	LL x = strtoll(P, &endp, 10);
	P = endp;
	return x;
}


const string chs = "0123456789*+-&^|";

inline void update(LL &x, LL y, bool fst){
	if(fst){
		x = max(x, y);
	}
	else{
		x = min(x, y);
	}
}


LL solve(int n, const string &s, bool fst){
	LL ret;
	if(fst){
		ret = LLONG_MIN;
	}
	else{
		ret = LLONG_MAX;
	}

	try{
		P = s.c_str();
		LL t = oexpr();
		if(*P){ throw 0; }
		if(!n){
			return t;
		}
	}catch(...){
		if(fst){
			ret = LLONG_MAX;
		}
		else{
			ret = LLONG_MIN;
		}
		return ret;
	}

	for(int i = 0; i < s.size(); ++i){
		if(s[i] == '(' || s[i] == ')'){ continue; }
		string t = s;
		t.erase(t.begin() + i);
		LL x = solve(n - 1, t, !fst);
		update(ret, x, fst);
	}

	for(int i = 0; i <= s.size(); ++i){
		for(int j = 0; j < chs.size(); ++j){
			string t = s;
			t.insert(t.begin() + i, chs[j]);
			LL x = solve(n - 1, t, !fst);
			update(ret, x, fst);
		}
	}
	
	return ret;
}


int main(){
	int n;
	int cnt = 0;
	string s;
	while(cin >> n >> s, n){
		if(n % 2){ n = 1; }
		else{ n = 2; }
		cout << solve(n, s, true) << endl;
	}
}

Measured memory_bytes: 1296
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	if(c=='-')f=-1,c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll n,ans,k;
char c[1000010];
int main(){
	n=d;
	f(i,1,n){cin>>c[i];if(c[i]=='R')ans++,k++;}
	f(i,1,k)if(c[i]=='R')ans--;
	cout<<ans; 
	return 0;
}

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

string s;

int main(){
    cin>>s;
    int n=s.size();
    if(s[0]=='0'||s[n-1]=='1'){
        cout<<-1<<endl;
        return 0;
    }

    rep(i,n-2)if(s[i]!=s[n-2-i]){
        cout<<-1<<endl;
        return 0;
    }

    int par=n;
    for(int i=n-2;i>=0;i--){
        cout<<i+1<<" "<<par<<endl;
        if(s[i]=='1')par=i+1;
    }
}

Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
"""



"""
import sys


def solve(r, D, x):
    ans = []
    for i in range(10):
        x = r*x - D
        x = max(x, 0)
        ans.append(x)
    return ans


def main(args):
    r, D, x = map(int, input().split())
    ans = solve(r, D, x)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, a[100];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	double ans = 0;
	inc(i, n) { ans += 1.0 / a[i]; }
	
	printf("%.12f\n", 1.0 / ans);
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
    char t = a.charAt(0);
    char u = a.charAt(1);
    char v = a.charAt(2);
        char w = b.charAt(0);
        char x = b.charAt(1);
        char y = b.charAt(2);
        if(t == y &&u == x&&v==w){
        System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
}


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

int main(){
  int N;
  cin>>N;
  std::vector<string> s(N);
  for(int i=0;i<N;i++)cin>>s[i];
  int out=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(s[i]==s[j])out++;
    }
  }
  for(int i=0;i<N-1;i++){
    int a=s[i].size();
    if(s[i][a-1]!=s[i+1][0])out++;
  }
  if(out)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[200005],n,b[200005],i;
int P(int x){for(i=1;i<=n*2-1;i++)b[i]=(a[i]>=x);b[0]=b[1];
for(i=n;i<=n+n;i++){if(b[i]==b[i+1])return b[i];if(b[n+n-i]==b[n+n-i-1])return b[n+n-i];}}
int main(){
cin>>n;for(i=1;i<=n*2-1;i++)cin>>a[i];
int l=1,r=n*2,A=0,M;
while(l<=r){M=(l+r)/2;if(P(M))l=M+1,A=M;else r=M-1;}cout<<A;}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include<cstdio>
#include<iomanip>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>

int main()
{
    int l{};
    std::cin >> l;

    const auto result = std::pow(static_cast<double>(l) / 3, 3.0);
    std::cout << std::fixed << std::setprecision(10) << result << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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

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

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int b = 0;
		int c = 0;

		int su = Integer.parseInt(br.readLine());
		if((su > 0) && (86400 > su)){

			if(su >= 60){
				c = su / 60;
				su %= 60;
			}
			if(c >= 60){
				b = c / 60;
				c = c % 60;
			}
		}

		System.out.println(b+":"+c + ":" + su);
	}
}

Measured memory_bytes: 24408
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
vector<int>vt;
set<int>st;
map<int,int>mp;
unordered_map<string,int> umap; 
const long long MAX = 1e5;
const long long INF = 1e9;
const double pi = acos(-1);




int main() {
  int n,k;
  cin>>n>>k;
  for(int i=0;i<k;i++){
    int x,y;
    cin>>x;
    while(x--)
    {
      cin>>y;
      mp[y]++;
    }

  }
  int c=0;
  for(auto it:mp)
  {
    if(it.second)
    c++;
  }
  cout<<n-c<<endl;


}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  long long K;
  cin >> N >> M >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> B(M);
  for (int i = 0; i < M; i++){
    cin >> B[i];
  }
  vector<long long> SA(N + 1, 0);
  for (int i = 0; i < N; i++){
    SA[i + 1] = SA[i] + A[i];
  }
  vector<long long> SB(M + 1, 0);
  for (int i = 0; i < M; i++){
    SB[i + 1] = SB[i] + B[i];
  }
  int ans = 0;
  for (int i = 0; i <= N; i++){
    if (SA[i] <= K){
      auto itr = upper_bound(SB.begin(), SB.end(), K - SA[i]);
      ans = max(ans, (int)(i + itr - SB.begin() - 1));
    }
  }
  cout << ans << endl;
}

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

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        StringBuilder ans = new StringBuilder();

        for (int i = 0; i < str.length(); i += 2) {
            ans.append(str.charAt(i));
        }
        System.out.println(ans);
    }
}


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

int main(void){
    long long int i, j, k, n, a, b, ans=0, po=0, x, y, popo=0;
    char name[30];
    scanf("%lld %lld", &x, &n);
    long long int p[n];
    if(n == 0){
        getchar();
        printf("%lld", x);
    }else{
    for(i=0; i<n; i++) scanf("%lld", &p[i]);
    for(i=0; 1; i++){
        po=0;
        popo=0;
        for(j=0; j<n; j++){
            if(x-i == p[j]) po++;
            if(x+i == p[j]) popo++;
        }
        if(po == 0){
            printf("%lld", x-i);
            break;
        }else if(popo == 0){
            printf("%lld", x+i);
            break;
        }
    }
    }
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)
 
#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;
 
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int arr[111];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, x;
  cin >> n >> m >> x;
  for (int i = 1; i <= m; ++i) {
    int xc;
    cin >> xc;
    arr[xc]++;
  }
  int ca = 0, cb = 0;
  for (int i = 1; i <= x; ++i) ca += arr[i];
  for (int i = x + 1; i <= n; ++i) cb += arr[i];
  cout << min(ca, cb) << endl;
}





Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    int ans=n*(n-1)/2+m*(m-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n, m = (int(i) for i in input().split()) 

ans_l = 1
ans_r = n

for i in range(m):
  l, r = (int(i) for i in input().split())
  if l > ans_l:
    ans_l = l
    
  if r < ans_r:
    ans_r = r

print(max(0, ans_r - ans_l + 1))

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int[] list = {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};
		System.out.println(list[scan.nextInt() - 1]);
	}
}


Measured memory_bytes: 23892
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
import math
from decimal import *

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

c = abs(Decimal(b) - Decimal(a))
d = (Decimal(v)*Decimal(t) - Decimal(w)*Decimal(t))

if d >= c:
    print("YES")

else :
    print("NO")


Measured memory_bytes: 10004
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll n,m,q,a[55], b[55], c[55], d[55],buf[55],ans = -inf;
void dfs(int keta = 0, int range = 1) {
	if (keta == n+1) {
		ll now = 0;
		for (int i = 0; i < q; i++) {
			if (buf[b[i]] - buf[a[i]] == c[i]) {
				now += d[i];
			}
			ans = max(ans, now);
			
		}
		return;
	}
	for (int number = range; number < m + 1; number++) {
		buf[keta] = number;
		dfs(keta + 1, number);
	}
	
}
int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	dfs();
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if( Math.abs(x-a) < Math.abs(x-b) ) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}

Measured memory_bytes: 21844
M = 100
po = [26 ** i for i in range(M)]

N = int(input())

L = 0
for i in range(M):
    if N < po[i]:
        L = i
        break
    N -= po[i]

ans = ""
for i in range(L):
    ans += chr(ord('a') + N // po[L - (i + 1)])
    N %= po[L - (i + 1)]

print(ans)


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

int main() {
  string w;
  cin >> w;

  int temp[26] = {};
  for (int i = 0; i < w.size(); i++) {
    for (int j='a'; j < 'z'+1; j++) {
      if (w[i] == char(j)) {
        temp[j-97]++;
      }
    }
  }

  bool flag_No = false;
  for (int i = 0; i < 26; i++) {
    if (temp[i] % 2) {
      flag_No = true;
    }
  }

  cout << ( flag_No ? "No" : "Yes" ) << endl;
}


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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int c[3][3], a[3] = {}, b[3] = {};
	
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++)
			cin >> c[i][j];
	}
	
	for(int i=0; i<=100; i++){
		for(int j=0; j<=100; j++){
			for(int k=0; k<=100; k++){
				a[0] = i;
				a[1] = j;
				a[2] = k;
				b[0] = c[0][0] - a[0];
				b[1] = c[1][1] - a[1];
				b[2] = c[2][2] - a[2];
				if(c[0][1] == a[0]+b[1] && c[0][2] == a[0]+b[2] && c[1][0] == a[1]+b[0] && c[1][2] == a[1]+b[2] && c[2][0] == a[2]+b[0] && c[2][1] == a[2]+b[1]){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

template<int N, typename T, T M>
struct factorial_mod
{
	T mod[N + 1];
	T inv_mod[N + 1];

	constexpr factorial_mod() : mod(), inv_mod()
	{
		mod[0] = 1;
		for (int i = 0; i < N; ++i)
		{
			mod[i + 1] = (mod[i] * (i + 1)) % M;
		}
		inv_mod[N] = power(mod[N], M - 2);
		for (int i = N - 1; i >= 0; --i)
		{
			inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
		}
	}

	constexpr T power(T a, T b) const
	{
		T r = 1;
		while (b > 0)
		{
			if ((b & 1) != 0) r = (r * a) % M;
			a = (a * a) % M;
			b >>= 1;
		}
		return r;
	}

	constexpr T comb(T n, T r) const
	{
		if (r < 0 || r > n || n < 0) return 0;
		return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
	}

	constexpr T H(T n, T r) const
	{
		return comb(n + r - 1, r);
	}
};

template<typename T>
constexpr T pow_mod(T a, T b, T m)
{
	T r = 1;
	while (b > 0)
	{
		if ((b & 1) != 0) r = (r * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return r;
}

constexpr long long MOD = 1000000007;
factorial_mod<500000, long long, MOD> fmod;

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	long long ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		long long r = fmod.comb(n, i) * fmod.mod[m - i] % MOD * fmod.inv_mod[m - n] % MOD;
		ans = (ans + (i % 2 == 0 ? r : MOD - r)) % MOD;
	}
	ans = ans * fmod.mod[m] % MOD * fmod.inv_mod[m - n] % MOD;
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int m[101];
        int p[101][101];
        for(int i = 0; i <n; i++){
            cin >> m[i];
            for (int j = 0; j < m[i]; j++){
                cin >> p[i][j]; 
            }

        }

        int k;
        cin >> k;
        int l[101];
        for(int i = 0; i < k; i++){
            cin >> l[i];
        }

        int ans = 0;
        int count = 0;
        for(int i = 0; i < n; i++){
            int c = 0;
            int memo = 0;
            for(int j = 0; j < k; j++){
                for(int o = 0; o < m[i]; o++){
                    if(l[j] == p[i][o]){
                        c++;
                        memo = i+1;
                    }
                }
            }
            if(c == k){
                ans = memo; 
                count++;
            
            }
        }
        if(count == 1) cout << ans << endl;
        else cout << -1 << endl;

    }


}

Measured memory_bytes: 3140