akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

        while(true) {
        	String str = sc.next();
        	int sum = 0;

        	if(str.equals("0")) {
        		break;
        	}

        	for(int i = 0; i < str.length(); i++) {
        		sum += Integer.parseInt(str.substring(i, i+1));
        	}

        	System.out.println(sum);
        }
    }
}


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

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

    if (s == "AAA" || s == "BBB") {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k - 1] += 32;
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();

        Map<Integer, Integer> counts = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int next = in.nextInt();
            counts.put(next, counts.getOrDefault(next, 0) + 1);
        }

        long sum = 0;
        for (Map.Entry<Integer, Integer> e : counts.entrySet()) {
            sum += e.getKey() * e.getValue();
        }

        int q = in.nextInt();
        for (int i = 0; i < q; i++) {
            int from = in.nextInt();
            int to = in.nextInt();

            int count = counts.getOrDefault(from, 0);
            counts.remove(from);
            counts.put(to, counts.getOrDefault(to, 0) + count);

            sum += count * (to - from);
            out.println(sum);
        }
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

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

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

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

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

map<ll, int> ma;
ll N, P;

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".INP", "r")){
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    cin >> N >> P;
    for (int i=2; 1ll*i*i<=P; ++i){
        while (P % i == 0){
            ma[i]++;
            P /= i;
        }
    }
    if (P != 1) ma[P]++;
    ll res = 1;
    for (auto it : ma){
        int cnt = it.se / N;
        while (cnt--){
            res *= it.fi;
        }
    }
    cout << res << '\n';
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
process.stdin.on('data', function (chunk) {
    var lines = chunk.toString().split('\n');
    var n = parseInt(lines[0]);
    var m = lines[1];
    var value = 0;
    var max = 0;
    
       for(i=0; i<n; i++){
        if(m.charAt(i) ==　"I"){
            value = ++value;
            if(value>max){
        max = value;
    }
    
        }else{
            value = --value;
                    }
    }
    
    
    console.log(max);
});

Measured memory_bytes: 7500
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<cstring>    //for memset
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define lli                      long long int
#define ull                      unsigned long long
#define ld                       long double
#define pi                       acos(-1)
#define pb                       push_back
#define pbk                      pop_back
#define ff                       first
#define ss                       second
#define pii                      pair<int,int>
#define pdd                      pair<double,double>
#define gcd(a,b)                 __gcd(a,b)
#define lcm(a,b)                (a/gcd(a,b))*b
#define all(v)                   v.begin(),v.end()
#define READ                     freopen("in.txt","r",stdin);
#define WRITE                    freopen("outer.txt","w",stdout);
#define mem(array,value)         memset(array,value,sizeof array)
#define TEST_CASE                int t;scanf("%d",&t);for(int z=1;z<=t;z++)
#define PRINT_CASE               printf("Case %d: ",z)
#define LINE_PRINT_CASE          printf("Case %d:\n",z)
#define ordered_set              tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sf                       scanf
#define pf                       printf
#define inf                      10000000000
#define mod                      1000000007
#define dist(ax,ay,bx,by)        sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
#define fastIO                   ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define watch(x)   	            cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define mx 2005

lli dp[mx][mx];
lli nCr(lli n,lli r)
{
    if(r==1)
    {
        return n;
    }
    if(n==r || r==0)
    {
        return 1;
    }
    if(dp[n][r]!=-1)
    {
        return dp[n][r];
    }
    else
    {
        dp[n][r]=((nCr(n-1,r)%mod)+(nCr(n-1,r-1)%mod)%mod);
        return dp[n][r];
    }

}


int main()
{
    mem(dp,-1);
    int n,k;//cout<<nCr(1,1)<<" "<<nCr(200,0)<<endl;
    cin>>n>>k;

    for(int i=1; i<=k; i++)
    {
          int p=n-k+1;
          if(p>=i && k>=i)
          cout<<((nCr(p,i)%mod)*(nCr(k-1,i-1)%mod))%mod<<endl;


          else cout<<"0"<<endl;


    }        return 0;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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

    vector<int> d(N);
    rep2(i, 0, N) cin >> d.at(i);

    int temp;
    rep2(i, 0, N){
        rep2(j, 0, N-1-i){
            if(d.at(j) < d.at(j+1)){
                temp = d.at(j);
                d.at(j) = d.at(j+1);
                d.at(j+1) = temp;
            }
        }
    }

    int X = 1;
    rep2(i, 1, N){
        if(d.at(i-1) != d.at(i)) X++;
    }

    cout << X << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
string s1,s2;
ll mem[3005][3005];
ll dp(int i,int j){
    if(i>=s1.size()||j>=s2.size())return 0;
    ll rta=0;
    if(mem[i][j]!=-1)return mem[i][j];
    if(s1[i]==s2[j]){
        mem[i][j]=1+dp(i+1,j+1);
    }else{
        mem[i][j]=max(dp(i+1,j),dp(i,j+1));
    }
    return mem[i][j];
}

int main() {
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>s1>>s2;
memset(mem,-1,sizeof(mem));
dp(0,0);
int i=0;
int j=0;
string ans="";
    while(i!=s1.size()&&j!=s2.size()){
        if(s1[i]==s2[j]){
            ans=ans+s1[i];
            ++i;++j;
        }else{
            if(mem[i+1][j]>mem[i][j+1]){
                i++;
            }else{
                j++;
            }
        }
}
  cout<<ans;
  return 0;
}


Measured memory_bytes: 71040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class team : IComparable {
        public string name;
        public int kati;
        public int make;
        public int index;
        
        public int CompareTo(object obj) {
            team eneT = (team)obj;
            if (eneT.kati != kati) {
                return kati - eneT.kati;
            }
            else if (eneT.make != make) { return eneT.make - make; }
            else { return eneT.index - index; }
        }

    }
    

    class ClassMain {



        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                team[] teams = new team[n];
                for (int i = 0; i < n; i++) {
                    string[] sprit = Console.ReadLine().Split(' ');
                    team t = new team();
                    t.name = sprit[0]; t.index = i;
                    for (int j = 1; j < n; j++) {
                        int rr = int.Parse(sprit[j]);
                        if (rr == 0) { t.kati++; }
                        if (rr == 1) { t.make++; }
                    }
                    teams[i] = t;
                }

                Array.Sort(teams);
                for (int i = 0; i < n; i++) {
                    Console.WriteLine(teams[n-1-i].name);
                }
            }
        }




    }

    
}

Measured memory_bytes: 5612
import math

n,k = map(int,input().split())
a = list(map(int,input().split()))

def cal(lis,x):
    an = 0
    for i in range(len(lis)):
        an += (math.ceil(lis[i] / x) - 1)
        
    return an

left = 0
right = 10**9

for i in range(100):
    m = (left + right) / 2
    
    b = cal(a,m)
    
    if b > k:
        left = m
    else:
        right = m
        
print(math.ceil(m))

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin>>N;
    vec_int A(N);
    rep(i,N)cin>>A.at(i);
    int MOD = pow(10,9)+7;

    vec_int A_sum(N);
    A_sum.at(N-1) = A.at(N-1);
    for(int i=N-2;i>=0;i--){
        A_sum.at(i) = (A_sum.at(i+1) + A.at(i))%MOD;
    }

    int output = 0;

    for(int i=0;i<N-1;i++){
        output = (output + A.at(i) * A_sum.at(i+1))%MOD;
    }
    cout<<output%MOD<<endl;





    return 0;
}

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

/* --復習用-- */

//N,x[],y[] global

int N;
int x[10],y[10];

  //２点間の距離を返す
double dist(int i,int j){
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
   //べき乗を作る　
    return pow(dx*dx+dy*dy,0.5);
}

void solve(){
    cin>>N;
    for(int i=1;i<=N;i++) cin>>x[i]>>y[i];
    
   //2.225074 10-308 < double の絶対値 < 1.797693 10+308　（64bit)
    double sum=0.0;
    vector<int> V(N);
  
  	//順列を作るため、1からNまでの数が入った配列を作成
    for(int i=0;i<N;i++) V[i]=i+1;
    
  do{
    //順列上の隣接する２点間の距離を足し合わせる
    for(int i=0;i<N-1;i++) sum+=dist(V[i],V[i+1]);
	
    //next_permutationによって作られた順列を試しに表示する場合以下コメントアウトはずす
/*  for(int i=0;i<N;i++) cout<<V[i];
	cout<<endl;
*/
    
  }while(next_permutation(V.begin(),V.end()));	
  
	//階乗を作成
  	int factorial=1;
    for(int i=2;i<=N;i++) factorial*=i;
  
  	//fixed: 小数点で表示することを指示　setprecision: 桁数を指示（この場合小数点以下１０桁）
  	cout<<fixed<<setprecision(10)<<sum/factorial<<endl;
}


int main(){
  solve();
  return 0;
  } 

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define MAX_N 50
#define MAX_M 50
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  int A[MAX_N];
  int B[MAX_N];
  for(int i = 0; i < N; i++) {
    scanf("%d %d", &A[i], &B[i]);
  }
  int C[MAX_M];
  int D[MAX_M];
  for(int i = 0; i < M; i++) {
    scanf("%d %d", &C[i], &D[i]);
  }

  int X[MAX_N];
  for(int i = 0; i < N; i++) {
    int MIN_J = 0;
    int MIN_M = INT_MAX;
    for(int j = 0; j < M; j++) {
      int M = ABSS(A[i], C[j]) + ABSS(B[i], D[j]);
      if(M < MIN_M) {
	MIN_M = M;
	MIN_J = j;
      }
    }
    X[i] = MIN_J + 1;
  }

  for(int i = 0; i < N; i++) {
    printf("%d\n", X[i]);
  }  
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
typedef long long ll;
ll k,a,b;
int main() {
    scanf("%lld%lld%lld",&k,&a,&b);k++;
    if(a+2>=b||k<=a+1) return !printf("%lld\n",k);
    ll ans=a;
    k-=a;b-=a;
    if(k&1) ans++;k>>=1;
    ans+=k*b;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  int even = 0, odd = 0;
  repz(i, 1, n + 1) {
    if (i % 2 == 0)
      even++;
    else
      odd++;
  }
  cout << fixed << setprecision(15) << (ld)odd / (ld)n << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int b[105],a[105];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>b[i];
	}
	b[n]=0x7f7f7f7f;
	b[0]=b[1];
	for(int i=n;i>=1;i--)
	{
		a[i]=min(b[i],b[i-1]);
	}
	int sum=0;
	for(int i=1;i<=n;i++) sum+=a[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]
s = set(w)
if len(s)!=len(w):
    print('No')
    exit()
prev = w[0][0]
for str in w:
    if prev != str[0]:
        print('No')
        exit()
    prev = str[-1]
print('Yes')


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

map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i*i <= n; i++){
		while(n%i == 0){
			res[i]++;
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	int ans = 0;
	for(auto p : prime_factor(n)){
		if(p.first == 1) continue;
		int cnt = 1;
		ll div = p.first;
		while(p.second >= cnt){
			//cout << n << " " << div << endl;
			n /= div;
			div *= p.first;
			p.second -= cnt;
			++cnt;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	int A[100010] = {0};
	for(int n=1; n<=N; ++n) cin >> A[n];
	int sum;	
	for(int i=1; i<=N+1; ++i){
		sum += abs(A[i]-A[i-1]);
	}
	for(int i=1; i<=N; ++i){
		int diff, add, tmpSum;
		tmpSum = sum;
		diff = abs(A[i] - A[i-1])+abs(A[i+1]-A[i]);
		add = abs(A[i+1]-A[i-1]);
		tmpSum -= diff;
		tmpSum += add;
		cout << tmpSum << endl;
	}
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
import math
import sys

n = int(sys.stdin.readline().rstrip())
ans = 0.0
for _ in range(n):
  x, u = list(map(str, sys.stdin.readline().rstrip().split()))
  if u == "JPY":
    ans += float(x)
  elif u == "BTC":
    ans += float(x) * 380000

print(ans)

Measured memory_bytes: 3060
fn main() {
    let i = input();
    let h = i / 60 / 60;
    let m = i / 60 % 60;
    let s = i % 60;

    println!("{}:{}:{}", h, m, s);
}

fn input() -> i32 {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().unwrap()
}



Measured memory_bytes: 5036
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl

#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define gap cout<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())



int main(){
	int n;
	cin>>n;
	if(n%2==0) cout<<n/2<<endl;
	else cout<<n/2+1<<endl;

	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
const int N = 105;
long long dp[N][100005];
int main() {
	long long n, W, v[N], w[N];
	cin >> n >> W;
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= W; j++) {
			if (j < w[i]) {
				dp[i][j] = dp[i - 1][j];
			}
			else {
				dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
			}
		}
	}
	cout << dp[n][W]<<endl;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
	int n = x.size();
	rep(i,n) {
		cout << x[i];
		if (i!=n-1) cout<<" ";
		else cout << endl;
	}
}

template<typename T>
void print(vector<vector<T>> &x) {
	int n = x.size();
	rep(i,n) {
		rep(j,x[i].size()) {
			cout << x[i][j] << " ";
		}
		cout << endl;
	}
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< MOD >;

constexpr int M = 114514;
modint dp[M][2];

int main(int argc, char const *argv[]) {
	string s; cin>>s;
	int n = s.length();
	rep(i,M) rep(j,2) dp[i][j] = 0;
	dp[0][0] = 1;

	rep(i,n) {
		if (s[i] == '1') {
			dp[i+1][1] += dp[i][1]*3;
			dp[i+1][0] += dp[i][0]*2;
			dp[i+1][1] += dp[i][0]*1;
		}
		else {
			dp[i+1][1] += dp[i][1]*3;
			dp[i+1][0] += dp[i][0]*1;
		}
	}

	cout << dp[n][0]+dp[n][1] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    lint N, A, B;
    cin >> N >> A >> B;
    if((B-A)%2 == 0) {
        cout << (B-A)/2 << endl;
    } else {
        lint t1 = (A-1) + (B-A+1) / 2;
        lint t2 = (N-B) + (B-A+1) / 2;
        cout << min(t1, t2) << endl;
    }
}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
W = [[] for _ in range(100005)]
for i in range(N):
    A, B = map(int, input().split())
    W[A].append(B)

hq = []

ans, ct, idx = 0, 0, 0
for A in range(1, M+1):
    for B in W[A]:
        heapq.heappush(hq, -B)
    if hq:
        B = heapq.heappop(hq)
        ans -= B
print(ans)


Measured memory_bytes: 72352
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
int N;
  cin>>N;
  string s,t;
  int a;
  cin>>s>>t;
  for(int i=0;i<=N;i++){
    if(i<N){
    int judge=0;
    for(int j=0;j<N-i;j++){
      if(s[i+j]!=t[j]) judge++;
    }
      if(judge==0){
       a=s.substr(0,i).size();
       a+=t.size();
        i+=10000;
      }
  }
    else{
      a=s.size();
      a+=t.size();
    }
  }
  cout<<a<<endl;
  
  return 0;
}

Measured memory_bytes: 256
import math

N = int(input())

primes = {}
i = 2
sqrt_N = math.floor(math.sqrt(N))
while i <= sqrt_N:
	if N % i == 0:
		if i in primes:
			primes[i] += 1
		else:
			primes[i] = 1
		N //= i
		sqrt_N = math.floor(math.sqrt(N))
	else:
		i += 1

if N != 1:
	if N in primes:
		primes[N] += 1
	else:
		primes[N] = 1

count = 0
for c in primes.values():
	i = 1
	while i <= c:
		count += 1
		c -= i
		i += 1
print(count)


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

#define int        long long
// #define mp      make_pair
#define eb         emplace_back
#define pb         push_back
#define ss         second
#define ff         first
#define IOS        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod        998244353
#define MOD        (1000*1000*1000+7)
#define MN         LLONG_MIN
#define MX         LLONG_MAX
#define v1d        vector<int>
#define v2d        vector<vector<int>>
#define vip        vector<pair<int,int> >
#define v1s        vector<string>
#define pa         pair<int,int>
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define print(v)   for(auto i:v)cout<<i<<" ";cout<<"\n";
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)     for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)     for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define endl       "\n"
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i+1];
#define Sort(v)    sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v)     v.begin(),v.end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s = bitset<64>(a).to_string();

void azmuth(int n=12){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
   
}
int lb = 10000000;

//____________________________________________________________________________________


int n;
vector<double> p;
vector<vector<double> > dp;

double fun(int idx,int head){
    if(idx > n){
        if(head >= (n+1)/2)return 1.0;
        else return 0;
    }
    if(dp[idx][head] != -1)return dp[idx][head];
    double a = p[idx]*fun(idx+1,head+1);
    double b = (1-p[idx])*fun(idx+1,head);
    return dp[idx][head] = a+b;

}

void solve(){
    cin>>n;
    dp.resize(n+1,vector<double> (n+1,-1));
    p.resize(n+1);
    for(int i=1;i<=n;i++)cin>>p[i];
    cout<<fixed<<fun(0,0);
}

int32_t main(){
    azmuth();
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    


    return 0;
}

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

namespace id_0297cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            foreach (var i in Enumerable.Range(0, n))
            {
                var vs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var k = vs[0];
                var p = vs[1];
                var result = k % p;
                if(result == 0)
                {
                    Console.WriteLine(p);
                }
                else
                {
                    Console.WriteLine(result);
                }
            }
        }
    }
}



Measured memory_bytes: 9536
#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
//#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-8
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define N 500005
//#define M 1000005
#define pi 3.14159265359
#define cpdd const pdd
#define hash Hash
using namespace std;
typedef long long LL;
using namespace std;
char c[200005];
int dp[200005][26];
int from[200005][26];
int main(){
	MEM(dp);
	vector<int> v[26];
	scanf("%s",c+1);
	int len=strlen(c+1);
	reverse(c+1,c+len+1);
	for(int i=1;c[i]!=0;i++){
		v[c[i]-'a'].pb(i);
	}
	for(int i=0;i<26;i++)
	v[i].pb(len+1);
	//printf("%d\n",len);
	for(int i=1;;i++){//,printf("\n")){
		for(int j=0;j<26;j++){
			for(int k=0;k<26;k++){
				int h=dp[i-1][k];
				int hi=*upper_bound(v[j].begin(),v[j].end(),h);
				if(dp[i][j]<hi){
					dp[i][j]=hi;
					from[i][j]=k;
				}
			}
			if(dp[i][j]==len+1){
				int now=i,k=j;
				while(now!=0){
					printf("%c",k+'a');
					k=from[now][k];
					now--;
				}
				return 0;
			}
			//printf("%d",dp[i][j]);
		}
	}
	
}
/*
14%20,15#17
20,14-18
1#5,11,4%10,14-18,20,21
11,21,20,14-18,4%10,1#5

*/


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

int main(void) {
	char bun[100];
	int pin;
	int i,len;
	pin=0;
	while(1) {
		if(scanf("%s",bun)==-1)break;
		len=strlen(bun);
		for(i=0;i<len;i++) {
			if(bun[i]<'0' || bun[i]>'9')bun[i]=0;
		}
		for(i=0;i<len;i++) {
			if(bun[i]!=0) {
				pin+=atoi(&bun[i]);
				i+=strlen(&bun[i]);
			}
		}
	}
	printf("%d\n",pin);
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	int A=sc.nextInt();
    	int B=sc.nextInt();
    	int C=sc.nextInt();
    	int D=sc.nextInt();
    	
    	int s1=A*B;
    	int s2=C*D;
    	
    	if(s1>=s2) {
    		System.out.println(s1);
    	}else {
    		System.out.println(s2);
    	}
    }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a<b)
    cout << "a < b\n";
  else if(a>b)
    cout << "a > b\n";
  else if(a==b)
    cout << "a == b\n";
  return 0;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll max(ll a, ll b){
    return a > b? a: b;
}
int main() {
    string a, b;
    cin >> a >> b;
    int dp[a.size()+1][b.size()+1];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 0;
    for(int i = 1; i <= a.size(); i++) {
        for(int j = 1; j <= b.size(); j++) {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(a[i-1] == b[j-1]){
                dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
            }   
        }
    }
    string ans="";
    int i = a.size(), j = b.size();
    while(i >= 1 && j >= 1) {
        if(dp[i][j] == 1+dp[i-1][j-1] && a[i-1] == b[j-1]) {
            ans += a[i-1];
            i--;
            j--;
        }else if(dp[i][j] == dp[i-1][j])
            i--;
        else
            j--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 35456
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    int N, T; cin >> N >> T;
    int ans = 0;
    int t; cin >> t;
    rep(i, N - 1) {
        int u; cin >> u;
        if(u - t <= T) ans += (u - t);
        else ans += T;
        t = u;
    }
    cout << ans + T << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
all_dist = 0
for i in range(N + 1):
  all_dist += abs(A[i + 1] - A[i])

for i in range(1, N + 1):
  if (A[i - 1] <= A[i] and A[i] <= A[i + 1]) or (A[i - 1] >= A[i] and A[i] >= A[i + 1]):
    print(all_dist)
  else:
    print(all_dist - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]))

  



Measured memory_bytes: 14168
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string s;
    cin>>s;
    if(s.size()==1){
        cout<<1<<endl;
        return 0;
    }
    string pre = "$";
    int n=s.size();
    int ans = 0;
    rep(_,4){
        int cnt=0;
        rep(j,n){
            string t="";
            t+=s[j];
            while(t==pre&&j+1<n){
                ++j;t+=s[j];
            }
            if(pre!=t)++cnt;
            pre=t;
        }
        pre=s[0];
        ans= max(ans,cnt);
        if(_==1){
            reverse(s.begin(),s.end());
            pre="$";
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
from itertools import accumulate


def solve(string):
    n, *a = map(int, string.split())
    *a, = accumulate(a)
    l, r, e = 0, 2, a[-1]
    ans = e
    for c in a[1:-2]:
        while a[l] + a[l + 1] < c:
            l += 1
        while a[r] + a[r + 1] < c + e:
            r += 1
        tmp = sorted([a[l], c - a[l], a[r] - c, e - a[r]])
        ans = min(ans, tmp[-1] - tmp[0])
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 25588
import static java.lang.Math.*;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		System.out.println(0.0 + " " + 0.0);
		koch(n, 0.0, 0.0, 100.0, 0.0);
		System.out.println(100.0 + " " + 0.0);
	}

	static void koch(int n, double p1x, double p1y, double p2x, double p2y) {
		if (n == 0) return;

		double sx, sy;
		double ux, uy;
		double tx, ty;

		// sx = (p2x - p1x) * 1/3 + p1x = (p2x + 2*p1x) / 3
		// tx = (p2x - p1x) * 2/3 + p1x = (2*p2x + p1x) / 3
		sx = (p2x + 2*p1x) / 3;
		sy = (p2y + 2*p1y) / 3;

		tx = (2*p2x + p1x) / 3;
		ty = (2*p2y + p1y) / 3;

		double cos60 = cos( toRadians(60) );
		double sin60 = sin( toRadians(60) );

		ux = (tx-sx)*cos60 - (ty-sy)*sin60 + sx;
		uy = (tx-sx)*sin60 + (ty-sy)*cos60 + sy;

		koch(n-1, p1x, p1y, sx, sy);
		System.out.println(sx + " " + sy);

		koch(n-1, sx, sy, ux, uy);
		System.out.println(ux + " " + uy);

		koch(n-1, ux, uy, tx, ty);
		System.out.println(tx + " " + ty);

		koch(n-1, tx, ty, p2x, p2y);
	}
}

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

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

	set<int> s;
	bool ans = true;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;

		if (s.find(a) != s.end()) {
			ans = false;
			break;
		}

		s.insert(a);
	}

	if (ans) {
		cout << "YES";
	} else {
		cout << "NO";
	}
	
	return 0;
}
	

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int ones(int e) {
    int ans = 0;
    while (e) {
        e &= (e - 1);
        ans++;
    }

    return ans;
}

void f() {
    int q;
    cin >> q;
    set<int> s;
    ll even = 0, odd = 0;
    int e;
    cin >> e;
    q--;
    int p = e;
    int on = ones(e);
    while (q--) {
        int e;
        cin >> e;


    }
}


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);



    int n, d;
    cin >> n >> d;
    int a[n][d];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> a[i][j];
        }
    }

    int ans = 0;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int dist = 0;
            for (int k = 0; k < d; k++) {
                dist += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
            }

            int sq = sqrt((double) dist);
            if (sq * sq == dist) {
                ans++;
            }
        }
    }

    cout << ans;



}



Measured memory_bytes: 256
package main

import(
  "fmt"
)

func main(){
  var S,T,R,Q string
  
  fmt.Scan(&S)
  fmt.Scan(&T)

  i := 0
  R=S
  
  for i<len(S){
    
    Q=R[len(R)-1:]
    R=R[:len(R)-1]
    R=Q+R
    
    if R==T{
      fmt.Println("Yes")
      break
    }else{
      if i==len(S)-1{
        fmt.Println("No")
        break
      }
    }
    i++
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int a[201][201];
		for(int i=1;i<201;i++){
			for(int j=i;j<201;j++){
				a[i][j]=__gcd(i,j);
				a[j][i]=a[i][j];
			}
		}
		int k;
		cin>>k;
		ll s=0;
		for(int i=1;i<=k;i++){
			for(int j=1;j<=k;j++){
				for(int h=1;h<=k;h++){
					s=s+a[a[i][j]][h];
				}
			}
		}
		cout<<s;
	}
	return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll n, q, s, t;

struct RSQ
{
	ll gt;
	ll a[N_SIZE];
	ll seg[N_SIZE * 2];
	void init(int n) {
		gt = 1;
		while (gt < n)gt *= 2;
		rep(i, n)a[i] = 0;
		rep(i, N_SIZE * 2)seg[i] = 0;
		rep(i, n)seg[i + gt] = a[i];
	}
	void update(int k, int x) {
		k += gt - 1;
		seg[k] += x;
		while (k) {
			k = (k - 1) / 2;//???????????????
			seg[k] += x;
		}
	}
	ll query(int a, int b) {
		return query(a, b, 0, 0, gt);
	}
	ll query(int a, int b, int k, int l, int r) {//[a,b)???????????????,k=0,l=0,r=gt
		if (r <= a || b <= l)return 0;

		if (a <= l&&r <= b)return seg[k];
		else return query(a, b, k * 2 + 1, l, (l + r) / 2)
			+ query(a, b, k * 2 + 2, (l + r) / 2, r);
	}
	void print() {
		rep(i, 2 * gt)cout << "!" << i << " " << seg[i] << endl;
	}
};

RSQ rsq;

int main() {
	cin >> n >> q;
	rsq.init(n + 1);
	rep(i, q) {
		int a, b, c;
		cin >> a >> b >> c;
		b--;
		if (a == 0) {
			rsq.update(b, c);
		}
		else {
			cout << rsq.query(b, c) << endl;
		}
	}
}

Measured memory_bytes: 20260
#include<iostream>
#include<bits/stdc++.h>
// iteration and input/output stream
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define printarr(x) rep(i,0,x.size()) cout<<x[i]<<" "; cout<<endl;

#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl prinf("\n")
#define tr(cont,it) \
for(decltype(cont.begin()) it = cont.begin(); it!= cont.end() ; it++)

#define tc() int tcase; cin >> tcase ; rep(tc,1,tcase+1)
//STL shortcuts
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair

// Error detection
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

typedef long long int ll; // 64 bit integer
typedef unsigned long long int  ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;

inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }

#define MOD 1000000007
#define inf 4000000000000000000LL
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define N 100000
ll gcd(ll a,ll b){ return ((b==0)? a:gcd(b,a%b) ); }


int main()
{
    SYNC

    int n;
    cin>>n;
    multiset<ll> v;
    rep(i,0,n)
    {
        ll x;
        cin>>x;
        v.insert(x);
    }

    multiset<ll>::iterator it = v.end();
    it--;
    int cnt =0;
    while(1)
    {
        ll cur = *it;
        //trace1(cur);
        int f=0;
        multiset<ll>::iterator x = it;

        for(ll i=35;i>=0;i--)
        {
            ll pw = pow(2,i);
            if(v.find(pw-cur) != v.end())
            {
                multiset<ll>::iterator tmp = v.find(pw-cur);
                if(tmp!= it)
                {
                    f=1;
                    cnt++;
                    v.erase(tmp);
                    if(x == v.begin())
                        break;
                    it--;
                    v.erase(x);
                    break;
                }

            }
        }
        if(!f)
            it--;

        if(it == v.begin())
            break;
    }
    cout<<cnt;



}


Measured memory_bytes: 9728
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
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;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	int t=0;
	int co=0;
	rep(i,n){
		if(i==n-1)cout<<-1<<endl;
		else{
			t=in[t]-1;
			if(t==1){
				cout<<i+1<<endl;
				return 0;
			}
		}
	}
}








Measured memory_bytes: 640
N=int(input())
A=[int(input()) for _ in range(N)]
mp=A[1]-A[0]
mn=A[0]
for i in range(1,N):
    if mp < (A[i]-mn):
        mp=A[i]-mn
        if 0>A[i]-mn:
            mn = A[i]
    if A[i]<mn:
        mn=A[i]
print(mp)

Measured memory_bytes: 13592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int n, m;
vector<int> ans, deg;
vector<vector<int> > g;

void rec(int i){
    //cout << "i" << i << endl;
    for(auto to : g[i]){
        deg[to]--;
    }
    vector<int> nx;
    for(auto to : g[i]){
        if(deg[to]==0){
            ans[to] = i+1;
            nx.push_back(to);
        }
    }
    for(auto to : nx){
        rec(to);
    }
    return;
}

int main() {
    cin >> n >> m;
    g.resize(n);
    deg.resize(n,0);
    ans.resize(n);
    REP(i,n+m-1){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        deg[b]++;
    }
    REP(i,n){
        if(deg[i]==0){
            ans[i]=0;
            rec(i);
            break;
        }
    }
    REP(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 19584
object Main extends App {
	val N = scala.io.StdIn.readInt
	val DX = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val a = new Array[Int](N)

	for(i<-0 until N){
		a(i) = scala.io.StdIn.readInt
	}

	var ans = DX(1) + N
	var i = 1

	var b = a

	while(b.size != 0){
		b = a.map(z => i*z + 1).filter(_ <= DX(0))
//		println(b.mkString(" "))
		ans += b.size
		i += 1
	}

	println(ans)
}

Measured memory_bytes: 27320
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();

		if (B % A == 0) {
			System.out.println(A + B);
		} else {
			System.out.println(B - A);
		}
	}
}


Measured memory_bytes: 23124
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	rdr := NewReader(200)
	rdr.ReadInt()
	a := rdr.ReadInts()

	ReverseSort(a)

	diff := 0
	for i, v := range a {
		if i%2 == 0 {
			diff += v
		} else {
			diff -= v
		}
	}

	fmt.Println(diff)
}

type Reader struct {
	rdr  *bufio.Reader
	size int
}

func NewReader(size int) Reader {
	return Reader{
		bufio.NewReaderSize(os.Stdin, size),
		size,
	}
}

func (r *Reader) ReadInt() (i int) {
	fmt.Scan(&i)
	return
}

func (r *Reader) ReadLine() string {
	buf := make([]byte, 0, r.size)
	for {
		line, isPrefix, err := r.rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func (r *Reader) ReadStrs() []string {
	s := r.ReadLine()
	return strings.Split(s, " ")
}

func (r *Reader) ReadInts() []int {
	a := r.ReadStrs()
	n := make([]int, 0)
	for _, v := range a {
		if i, e := strconv.Atoi(v); e == nil {
			n = append(n, i)
		}
	}
	return n
}

func ReverseSort(ints []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(ints)))
}


Measured memory_bytes: 640