akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        static long MOD = (long) 1e9 + 7;

        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            char[][] S = new char[2][];
            S[0] = in.next().toCharArray();
            S[1] = in.next().toCharArray();

            long[] dp = new long[N];
            dp[0] = 3 * (S[0][0] == S[1][0] ? 1 : 2);
            for (int i = 1; i < N; i++) {
                if (S[0][i - 1] == S[0][i]) {
                    dp[i] = dp[i - 1];
                } else if (S[0][i - 1] == S[1][i - 1]) {
                    dp[i] = dp[i - 1] * 2 % MOD;
                } else {
                    if (S[0][i] == S[1][i]) {
                        dp[i] = dp[i - 1];
                    } else {
                        dp[i] = dp[i - 1] * 3 % MOD;
                    }
                }
            }
            out.println(dp[N - 1]);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}



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

typedef long long ll;
const int N = 1e5 + 100;

ll n, m, v, p, ans, a[N], ps[N];

bool ok(int dex) {
	vector<int> vec;
	for (int i = 0; i < n; i++)
		if (i != dex)
			vec.push_back(a[i]);
	ll x = a[dex] + m;
	int cnt = 0;
	for (int y: vec)
		if (y > x)
			cnt++;
	if (cnt >= p)
		return false;
	for (int i = 0; i < p - 1; i++)
		vec.pop_back();
	ll res = 0;
	for (int y: vec)
		res += min(m, x - y);
	return res >= m * (v - p);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m >> v >> p;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n; i++)
		ps[i + 1] = ps[i] + a[i];
	int l = -1, r = n - 1;
	while (r - l > 1) {
		int c = (l + r) >> 1;
		if (ok(c))
			r = c;
		else
			l = c;
	}
	cout << n - r;
}


Measured memory_bytes: 2796
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <queue>
#include <complex>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
using namespace std;

const long MOD = 1e9 + 7;
int main()
{
  long n;
  cin >> n;
  vector<long> c(n);
  vector<long> s(n);
  vector<long> f(n);

  for (int i = 0; i < n-1; ++i) {
    cin >> c[i] >> s[i] >> f[i];
  }

  for (int i = 0; i < n-1; ++i) { //開始時iにいるとき ciは時間　siは開始　fiはインターバル nは5*10^2
    long ti = 0;

    for (int j = i; j < n-1; ++j) { //開始0のときt = si +
      cerr <<f[j] <<" " <<s[j] << " "<<c[j] <<endl;
      if (ti < s[j])ti = s[j];

      if (ti % f[j] != 0) {
        ti += f[j] - ti % f[j];
      }

      ti = ti + c[j];
    }
    cout << ti << endl;
  }

  cout <<0 <<endl;





  return 0;
}

Measured memory_bytes: 256
from collections import deque
N , M =[int(hoge) for hoge in input().split()]
route = [[] for i in range(N)]
for i in range(M):
    A,B = [int(hoge)-1 for hoge in input().split()]
    route[A].append(B)
    route[B].append(A)
#全域部分木をほどよく作れるかどうか

#BFS
queue = deque()#append,popleft
went = [-1] * N
went[0] = True
queue.append(0)
while queue:
    cur = queue.popleft()
    for togo in route[cur]:
        if went[togo] == -1:
            went[togo] = cur
            queue.append(togo)

if any([x == -1 for x in went]):
    print("No")
else:
    print("Yes")
    for w in went[1:]:
        print(w+1)
    

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

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        cin>>B[i];
    }
    for(int i=0;i<N-1;i++){
        cin>>C[i];
    }
    int count=0;
    for(int i=0;i<N;i++){
        count+=B[i];
    }
    for(int i=0;i<N-1;i++){
        if(A[i]+1==A[i+1]) count+=C[A[i]-1];
    }
    cout<<count<<endl;
    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a>0){
    cout << "Positive" << endl;
  }
  else if(a<=0 && 0<=b){
    cout << "Zero" << endl;
  }
  else{
    int c=b-a+1;
    if(c%2==0){
      cout << "Positive" << endl;
    }
    else{
      cout << "Negative" << endl;
    }
  }
}
    


Measured memory_bytes: 3592
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

for i in range(1, n):
    if A[i - 1] + 1 == A[i]:
        ans += C[A[i - 1] - 1]
    else:
        pass

print(ans)

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

int f(int n){
  int a = 0;
  while(n%2==0){
  	n /= 2; a++;
  }
  return a;
}

int main(){
  int n; cin >> n;
  int ans = 0;
  for(int i = 0; i < n; i++){
  	int a; cin >> a;
  	ans += f(a);
  }
  
  cout << ans << endl;
}

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

int main()
{
	int n,k,a[100005];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	   cin>>a[i];
	sort(a+1,a+n+1);
	int sum=0;
	for(int i=1;i<=k;i++)
	   sum+=a[i];
	cout<<sum;
	return 0;
}

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

#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
const int MOD =1e9+7;


int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie();
    //If you hack my code , You are gay;
    int k,n;
    cin>>k>>n;
    vector<int> mark(102);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mark[x]=1;
    }
    int L=k,R=k;
    while(L>=0 || R<=101){
        if(L>=0 && !mark[L]){
            cout<<L;
            return 0;
        }
        if(R<=101 && !mark[R]){
            cout<<R;
            return 0;
        }
        L--;
        R++;
    }
    return 0;
}

Measured memory_bytes: 3644
val = input()

if val == "SUN":
	print(7)
elif val == "MON":
	print(6)
elif val == "TUE":
	print(5)
elif val == "WED":
	print(4)
elif val == "THU":
	print(3)
elif val == "FRI":
	print(2)
else:
	print(1)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll solve(ll n){
    ll ans=1;
    for(int i=2;i<=n;i++)ans*=i;
    return ans;
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll A[n-1];
    for(int i=0;i<n-1;i++)cin>>A[i];
    ll ans=A[0]+A[n-2];
    for(int i=1;i<=n-2;i++)ans+=min(A[i],A[i-1]);
    cout<<ans;
    return 0;
}

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

using namespace std;

int card[500];

int main(){
	int n;
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		int ans1, ans2, num;
		ans1 = n;
		ans2 = n;
		for(int i = 1; i <= 2 * n; i++){
			card[i] = 2;
		}
		for(int i = 0; i < n; i++){
			cin >> num;
			card[num] = 1;
		}
		int next = 1;
		while(true){
			for(int i = 1; i <= 2 * n; i++){
				if(card[i] == next){
					card[i] = 0;
					if(next == 1){
						ans2--;
						next = 2;
					}else if(next == 2){
						ans1--;
						next = 1;
					}
				}
				if(ans1 == 0 || ans2 == 0){
					break;
				}
			}
			if(ans1 == 0 || ans2 == 0){
				break;
			}
			if(next == 1){
				next = 2;
			}else if(next == 2){
				next = 1;
			}
		}
		printf("%d\n%d\n", ans1, ans2);
	}
	return 0;
}

Measured memory_bytes: 1144
import java.util.*;
import java.math.BigInteger;

public class Main {
	
	void run(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			BigInteger[][] dv = new BigInteger[n][2];
			BigInteger m = BigInteger.ONE;
			for(int i=0;i<n;i++){
				dv[i][0] = new BigInteger(sc.next());
				dv[i][1] = new BigInteger(sc.next());
				m = m.multiply(dv[i][0]);
			}
			BigInteger GCD = BigInteger.ONE;
			for(int i=0;i<n;i++){
				dv[i][1] = dv[i][1].multiply(m).divide(dv[i][0]);
				if(i==0) GCD = GCD.multiply(dv[i][1]);
				else GCD = GCD.gcd(dv[i][1]);
			}
			for(int i=0;i<n;i++) System.out.println(dv[i][1].divide(GCD));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 39384
import java.io.*;
public class Main {
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a, b, c;
		int sum = 0;
		
		String[] str = br.readLine().split("\\s+");
		
		if (str.length == 3) {
			try {
				a = Integer.parseInt(str[0]);
				b = Integer.parseInt(str[1]);
				c = Integer.parseInt(str[2]);
				
				for (int i = a; i <= b; i++) {
					if (Math.floorMod(c, i) == 0) {
						sum++;
					}
				}
				
				System.out.println(sum);
				
			} catch(Exception NumberFormatException) {
			}
		}
	}
}

Measured memory_bytes: 24768
/*************************************
 * @contest:      ABC149.
 * @user_name:    hkxadpall.
 * @time:         2019-12-29.
 * @language:     C++.
 * @upload_place: AtCoder.
*************************************/ 

#include <bits/stdc++.h>
using namespace std;

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline Int read(char &c)       
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

long long A, B, K;

int main()
{
    cin >> A >> B >> K;
    if (K <= A) {
        cout << A - K << ' ' << B;
    } else if (K <= A + B) {
        cout << "0 " << A + B - K;
    } else cout << "0 0";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt[100001];
int main() {
    int N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    cnt[0] = 0;
    for (int i = 1; i < N; i++) {
        if (s[i-1] == 'A' && s[i] == 'C')
            cnt[i] = cnt[i - 1] + 1;
        else
            cnt[i] = cnt[i - 1];
    }
    for (int i = 0; i < Q; i++) {
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        cout << cnt[y] - cnt[x] << endl;
    }
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
  return 0;
}


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

using namespace std;

#define d(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
const int m = 1e9+7;
int main()
{
    int h, w;
    cin >> h >> w;
    string s[h];
    for(int i = 0; i < h; i++)
        cin >> s[i];
    int a[h][w];
    memset(a, 0, sizeof(a));
    a[0][0] = 1;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            int x = 0, y = 0;
            if(i-1 >= 0 and a[i-1][j] != 0)
                x = a[i-1][j];
            if(j-1 >= 0 and a[i][j-1] != 0)
                y = a[i][j-1];
            if(s[i][j] != '#')
                a[i][j] = max(a[i][j], (x+y) % m);
        }
    }
    cout << a[h-1][w-1] << endl;
    return 0;
}



Measured memory_bytes: 5248
#include <iostream>
using namespace std;
int seihin[300];int test[1000][4];
int a,b,c,n;
bool henka;
 
void check(){
	for(int i=0;i<n;i++){
		int p=0;int k;
		if(test[i][3] == 0){
		for(int j =0;j<=2;j++){
			if(seihin[test[i][j]-1]!=1){
				k=test[i][j]-1;
				p++;}
		}
		if(p==1 and seihin[k]==2){
			henka=true;
			seihin[k]=0;
		}
		}
	}
}
 
int main() {
while(1){
	henka=true;
for(int i = 0;i<300;i++){
	seihin[i]=2;
}
cin>>a>>b>>c;
if(a==0 and b==0 and c==0){break;}
cin>>n;
int y=a+b+c;
for(int i=0;i<n;i++){
	cin>>test[i][0]>>test[i][1]>>test[i][2]>>test[i][3];
}
for(int i = 0;i<n;i++){
	if(test[i][3]==1){
		for(int j=0;j<=2;j++){
			seihin[test[i][j]-1]=1;
		}
	}
}
 
while(henka==true){
	henka=false;
	check();
}
for(int i=0;i<y;i++){
	cout<<seihin[i]<<endl;
}
}
	return 0;
}

Measured memory_bytes: 1176
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

// dp[i][j] - the number of ways to put numbers in prefix of size 'i'
// such that the last number is 'j'

const int nax = 3005;
char cmp[nax];
int dp[nax][nax], pref[nax][nax];

const int mod = 1e9 + 7;

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", cmp);
    dp[1][1] = 1;
    for(int len = 2; len <= n; ++len) {
        // let's compute prefix sums on dp[len-1]
        for(int i = 1; i <= len - 1; ++i) {
            pref[len-1][i] = (pref[len-1][i-1] + dp[len-1][i]) % mod;
        }
        for(int b = 1; b <= len; ++b) {
            int L, R;
            if(cmp[len-2] == '<') {
                L = 1, R = b - 1;
            }
            else {
                L = b, R = len - 1;
            }
            if(L <= R) {
                add_self(dp[len][b], (pref[len-1][R] - pref[len-1][L-1] + mod) % mod);
            }
            //~ for(int i = L; i <= R; ++i) {
                //~ add_self(dp[len][b], dp[len-1][i]);
            //~ }
            
            //~ for(int a = 1; a <= len - 1; ++a) {
                //~ int real_a = a;
                //~ if(a >= b) {
                    //~ ++real_a;
                //~ }
                //~ assert(real_a != b);
                //~ if((real_a < b) != (cmp[len-2] == '<')) {
                    //~ continue;
                //~ }
                //~ add_self(dp[len][b], dp[len-1][a]);
            //~ }
        }
    }
    int answer = 0;
    for(int b = 1; b <= n; ++b) {
        add_self(answer, dp[n][b]);
    }
    printf("%d\n", answer);
}


Measured memory_bytes: 69504
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

map<pair<long, long>, long> memo[2][2];

long dfs(bool ldzero, bool carry, long dig, long d){
  if(dig<=1){
    // dbg(ldzero, carry,dig,d);
    if(!ldzero) return 0;
    if(dig==1 && carry==false && d==0) return 10;
    if(dig==1 && carry==true && d==10) return 10;
    if(dig==0 && carry==true && d==1) return 1;
    if(dig==0 && carry==false && d==0) return 1;
    else return 0;
  }

  if(memo[ldzero][carry].count(mp(dig, d))==1){
    return memo[ldzero][carry][{dig, d}];
  }

  long ret = 0;
  rep(a,10)rep(b,10){
    if(!ldzero && b==0) continue;
    bool nflag = ldzero || b!=0;
    bool head_normal = carry*10 + a - b == d/dig;
    bool tail_normal = b - a == d%10;
    bool head_carry = carry*10 + a - 1 - b == d/dig;
    bool tail_carry = 10 + b - a == d%10;
    if(head_normal && tail_normal){
      ret += dfs(nflag, false, dig/100, (d%dig)/10);
    }
    if(head_normal && tail_carry){
      ret += dfs(nflag, false, dig/100, (d%dig)/10 + 1);
    }
    if(head_carry && tail_normal){
      ret += dfs(nflag, true, dig/100, (d%dig)/10);
    }
    if(head_carry && tail_carry){
      ret += dfs(nflag, true, dig/100, (d%dig)/10 + 1);
    }
  }

  return memo[ldzero][carry][{dig,d}] = ret;
}

int main(){
  long d;
  cin>>d;

  long dig = 1;
  long ans = 0;
  do {
    long tmp = dfs(false, false, dig, d);
    // dbg(dig, tmp);
    ans += tmp;
    // if(dig >= 1e+18) break;
    dig *= 10;
  } while(dig < LLONG_MAX/10);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define endl              "\n"
        #define int               long long
        #define rep(i,a,b)        for(long long i=a;i<b;i++)
        #define repp(i,a,b)        for(long long i=a;i<=b;i++)
        #define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
         
         
        void solve()
        {
            int i=0,j=0,k=0,n;
            string s;
            cin >> n;

            set<string>sl;

            rep(i,0,n){
            	cin>>s;
            	sl.insert(s);
            	
            }
            cout<<sl.size();




            cout<<endl;
           
        }
         
        signed main() {
            IOS;
        
            //sieve();
            int t = 1;
            //cin >> t;
            while (t--) solve();
            return 0;
        }

Measured memory_bytes: 19240
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  string s,t;

  cin>>s;
  cin>>t;

  for(int i = 0;i<s.size();i++){
    bool match = true;
    for(int j = 0;j<s.size();j++){
      if(s[(j+i)%s.size()] != t[j]){
	match = false;
	break;
      }
    }
    if(match){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL -1
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0){
      return 1;
    }
    else if(strlen(H[h])==0){
      return 0;
    }
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0){
      return 1;
    }
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for (i=0;i<M;i++) {
    H[i][0] = '\0';
  }
    
  scanf("%d", &n);
    
  for (i=0;i<n;i++){
    scanf("%s %s", com, str);
	
    if (com[0]=='i'){
      // printf("%s\n",com);
      insert(str);
    } else{
      if (find(str)){
	printf("yes\n");
      } else{
	printf("no\n");
      }
    }
  }

  return 0;
}

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

int main(){

    int n, k;
    cin >> n >> k;

    vector<vector<int>> hope(2*k, vector<int>(2*k, 0));
    int x, y;
    char c;
    for (int i = 0; i < n; i++){
        cin >> y >> x >> c;
        if (c == 'B') hope[x%(2*k)][y%(2*k)]++;
        else hope[(x+k)%(2*k)][y%(2*k)]++;
    }

    vector<vector<long long>> acc_hope(4*k + 1, vector<long long>(4*k + 1, 0));
    for (int i = 0; i < 4*k; i++){
        for (int j = 0; j < 4*k; j++){
            acc_hope[i+1][j+1] = acc_hope[i][j+1] + acc_hope[i+1][j] - acc_hope[i][j] + hope[i%(2*k)][j%(2*k)];
        }
    }

    long long ans = 0;
    long long tmp = 0;
    for (int i = 0; i < 2*k; i++){
        for (int j = 0; j < 2*k; j++){
            tmp = acc_hope[i+k][j+k] - acc_hope[i][j+k] - acc_hope[i+k][j] + acc_hope[i][j];
            tmp += acc_hope[i+2*k][j+2*k] - acc_hope[i+k][j+2*k] - acc_hope[i+2*k][j+k] + acc_hope[i+k][j+k];
            ans = max(ans, tmp);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 141184
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)

	ans := 0
	for i := 0; i < n; i++ {
		for a[i]&1 != 1 {
			ans++
			a[i] >>= 1
		}
	}

	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 896
# abc161_a.py
# https://atcoder.jp/contests/abc161/tasks/abc161_a

# A - ABC Swap /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 3つの箱 A,B,C があります。それぞれの箱には、整数が 1 つ入っています。
# 現在、箱 A,B,C に入っている整数はそれぞれ X,Y,Zです。
# これらの箱に対して以下の操作を順に行った後の、それぞれの箱に入っている整数を求めてください。
#     箱 Aと箱 Bの中身を入れ替える
#     箱 Aと箱 Cの中身を入れ替える

# 制約
#     1≤X,Y,Z≤100
#     入力はすべて整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# X Y Z

# 出力
# 箱 A,B,Cに入っている整数を、順番に空白区切りで出力せよ。

# 入力例 1
# 1 2 3

# 出力例 1
# 3 1 2

# 箱 Aと箱 B の中身を入れ替えた後、箱 A,B,C に入っている整数はそれぞれ 2,1,3 です。
# 箱 A と箱 C の中身を入れ替えた後、箱 A,B,C に入っている整数はそれぞれ 3,1,2です。

# 入力例 2
# 100 100 100

# 出力例 2
# 100 100 100

# 入力例 3
# 41 59 31

# 出力例 3
# 31 41 59


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    X, Y, Z = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = str(Z) + ' ' + str(X) + ' ' + str(Y)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['1 2 3']
        lines_export = ['3 1 2']
    if pattern == 2:
        lines_input = ['100 100 100']
        lines_export = ['100 100 100']
    if pattern == 3:
        lines_input = ['41 59 31']
        lines_export = ['31 41 59']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
# include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  string op;
  while(true){
    int ans;
    cin >> a >> op >> b;
    if(op == "+"){
      ans = a + b;
    }else if(op == "-"){
      ans = a - b;
    }else if(op == "*"){
      ans = a * b;
    }else if(op == "/"){
      ans = a / b;
    }else if(op == "?"){
      break;
    }
    cout << ans << endl;
  }
  
  return 0;
}


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

int main(void){
    int n;
    cin >> n;
    if(n % 10 == 7){
        cout << "Yes" << endl;
        return 0;
    }
    n /= 10;
    if(n % 10 == 7){
        cout << "Yes" << endl;
        return 0;
    }    
    n /= 10;
    if(n % 10 == 7){
        cout << "Yes" << endl;
        return 0;
    }    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

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

	scanf("%lld%lld%lld", &a, &b, &c);

	if(a* b* c% 2)
	{
		if(a>= b)
		{
			if(a>= c)
				printf("%lld\n", b* c);
			else// a< c
				printf("%lld\n", a* b);
		}
		else// a< b
		{
			if(b>= c)
				printf("%lld\n", a* c);
			else// b< c
				printf("%lld\n", a* b);
		}
	}
	else
		printf("0\n");

	return 0;
}

Measured memory_bytes: 128
class Dict(object):
    def __init__(self, size):
        self.dict = [None for _ in range(size)]
        self.size = size

    def h1(self, key):
        return key % self.size

    def h2(self, key):
        return 1 + (key % (self.size-1))

    def h(self, key, i):
        return (self.h1(key) + i * self.h2(key)) % self.size

    def insert(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.dict[j] == None:
                self.dict[j] = key
                break
            else:
                i += 1

    def find(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self.dict[j] == key:
                return 1
            elif self.dict[j] == None or i >= self.size:
                return 0
            else:
                i += 1


def get_key(table, word):
    return int(word.translate(table))


if __name__ == "__main__":
    import sys
    input = sys.stdin.readline # faster input

    table = str.maketrans({
        "A": "1",
        "C": "2",
        "G": "3",
        "T": "4"
    })

    m = 1046527
    d = Dict(m)

    n = int(input())

    for _ in range(n):
        command = input()
        if command[0] == 'i':
            d.insert(get_key(table, command[7:]))
        else:
            if d.find(get_key(table, command[5:])):
                print('yes')
            else:
                print('no')



Measured memory_bytes: 32188
n = int(input())
G = [[-1 for i in range(n)] for j in range(n)]
d = [999999 for i in range(n)]
  
for i in range(n):
    v = input().split()
    for j in range(int(v[1])):
        G[int(v[0])][int(v[2+2*j])] = int(v[3+2*j])

flag = [0] * n
tn = [0]
d[0] = 0
for k in range(n):
    for i in range(n):
        if i in tn:
            for j in range(n):
                if G[i][j] != -1:
                    if d[j] > d[i] + G[i][j]:
                        d[j] = d[i] + G[i][j]
                    if j not in tn:
                        tn.append(j)
  
for i in range(n):
    print(str(i) + " " + str(d[i]))

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

vector<pair<long long, long long>> divisor_pair(long long n) {
	vector<pair<long long, long long>> v;
	for (long long i = 1; i * i <= n; ++i) {
		if (n % i == 0) v.emplace_back(i, n/i);
	}
	return v;
}

vector<long long> divisor(long long n) {
	vector<pair<long long, long long>> div_pair = divisor_pair(n);
	vector<long long> v(div_pair.size()*2);
	if (div_pair.back().first == div_pair.back().second) v.pop_back();
	for (int i = 0, j = v.size()-1; i < div_pair.size(); i++, j--) {
		v[i] = div_pair[i].first;
		v[j] = div_pair[i].second;
	}
	return v;
}

int main() {
	long long n;
	cin >> n;
	long long ans = 0;
	ans += divisor(n-1).size() - 1;
	vector<long long> v = divisor(n);
	for (long long k : v) {
		if (k == 1) continue;
		long long nc = n;
		while (nc % k == 0) nc /= k;
		if (nc % k == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
n,m = map(int,input().split())
s = []
c = []
if m == 0:
  if n==1:
    print(0)
    exit()
  elif n==2:
    print(10)
    exit()
  else:
    print(100)
    exit()
 
 
for i in range(m):
  S,C =  map(int,input().split())
  s.append(S)
  c.append(C)
  
num = [1] + [0]*(n-1)
ans = ''
 
for i in range(m):
  if n != 1 and s[i] == 1 and c[i] == 0:
    print(-1)
    exit()
for i in range(m-1):
  for j in range(i+1,m):
    if s[i] == s[j] and c[i] != c[j]:
      print(-1)
      exit()
      
for i in range(m):
  num[s[i]-1] = c[i]
  
for i in range(n):
  ans += str(num[i])
  
print(ans)

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    int add = 'a' - 'A';

    printf("%c%c%c\n", a[0]-add, b[0]-add, c[0]-add);

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m



x,y = map(int, input().split())

# m = (2x-y)/3
# n = (2y-x)/3

if (2*x-y)%3!=0 or (2*y-x)%3!=0:
    print(0)
    exit()

m = (2*x-y)//3
n = (2*y-x)//3

if n<0 or m<0:
    print(0)
    exit()

MOD = 10**9 + 7
coeff = BiCoeff(10**6+10, MOD)

print(coeff.calc(n+m,n))


Measured memory_bytes: 62164
N=int(input())
S=[s for s in input()]
def res(i,a,b):
    if S[i]=="o":
        if a==b:
            return "S"
        else:
            return "W"
    else:
        if a==b:
            return "W"
        else:
            return "S"
def check(a,b):
    ans=[""]*N
    ans[0]=a
    ans[1]=b
    for i in range(2,N):
        ans[i]=res(i-1,ans[i-2],ans[i-1])
    if ans[0]==res(N-1,ans[N-2],ans[N-1]) and ans[1]==res(0,ans[N-1],ans[0]):
        return True,ans
    else:
        return False,ans
flag=False
for a,b in [("S","S"),("S","W"),("W","S"),("W","W")]:
    R,ans=check(a,b)
    if R:
        print("".join(ans))
        flag=True
        break
if not flag:
    print(-1)

Measured memory_bytes: 5532
L = list(map(int, input().split()))
if L[0]%2 == 1 or L[1]%2 == 1 or L[2]%2 == 1:
    print(0)
    exit()

if (L[0]//2)%2 == 1 and (L[1]//2)%2 == 1 and (L[2]//2)%2 == 1:
    print(-1)
    exit()

i = 0
while True:
    i += 1
    L = [L[1]//2+L[2]//2, L[0]//2+L[2]//2, L[0]//2+L[1]//2]
    if L[0]%2 == 1 or L[1]%2 == 1 or L[2]%2 == 1:
        print(i)
        exit()
    if i >= 10**6:
        print(-1)
        exit()


Measured memory_bytes: 9228
import sys

N = int(input())
A = list(map(int, input().split()))

if 0 in set(A):
  print("0")
  sys.exit()  

ans = 1
for i in A :
  ans *= i
  if ans > 1000000000000000000 :
    print("-1")
    sys.exit()

print(ans)


Measured memory_bytes: 21648
# coding: utf-8
# Your code here!
d,g = list(map(int,input().split()))	
g=g//100
p=[]
c=[]
for i in range(d):
    P,C=list(map(int,input().split()))
    p.append(P)
    c.append(C//100)


ans = 2000
for i in range(1<<d):
    score = 0
    problem = 0
    for j in range(d):
        jbit=((i>>j) & 1)
#        print(jbit)
        score += jbit*((j+1)*p[j] + c[j])
        problem += jbit*p[j]
#    print(score,problem,"TOTYUU")
    if score >= g:
        ans = min(ans,problem)
        continue
    else:
        nokori = g - score
#        print(nokori,problem,i)
        for j in range(d-1,-1,-1):
            jbit=((i>>j) & 1)
            if jbit == 1:
                continue
            else:
                mon = (nokori+j) // (j+1)
#                print(mon,j,"kezuri")
                if mon <= p[j]-1:
                    nokori=0
                    problem += mon
                    ans = min(ans,problem)
                else:
                    nokori -= (j+1)*(p[j]-1)
                    problem += p[j]-1

print(ans)







                






                










Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define re register
#define LL long long
const int maxn=2e5+5;
struct E{int v,nxt,w;}e[maxn<<1];
struct Edge{int a,b;LL c;}E[maxn*55];
int sum[maxn],vis[maxn],head[maxn],mx[maxn],a[maxn],fa[maxn],sz[maxn];
int n,num,m,dx,S,rt;LL dw,ans,pre[maxn];
void Add(int x, int y, int z)
{
    e[++num].v=y;e[num].nxt=head[x];head[x]=num;e[num].w=z;
}
void getroot(int x,int fa) {
    sum[x]=1,mx[x]=0;
    for(re int i=head[x];i;i=e[i].nxt) {
        if(vis[e[i].v]||e[i].v==fa) continue;
        getroot(e[i].v,x);sum[x]+=sum[e[i].v];
        mx[x]=max(mx[x],sum[e[i].v]);
    }
    mx[x]=max(mx[x],S-sum[x]);
    if(mx[x]<mx[rt]) rt=x;
}
void getdis(int x,int fa) {
    E[++m]=(Edge){dx,x,pre[x]+a[x]+dw};
    for(re int i=head[x];i;i=e[i].nxt) {
        if(vis[e[i].v]||e[i].v==fa) continue;
        getdis(e[i].v,x);
    }
}
void chk(int x,int fa) {
    if(pre[x]+a[x]<dw) dw=pre[x]+a[x],dx=x;
    for(re int i=head[x];i;i=e[i].nxt) {
        if(vis[e[i].v]||e[i].v==fa) continue;
        pre[e[i].v]=pre[x]+e[i].w;chk(e[i].v,x);
    }
}
void dfs(int x) {
    dx=x,dw=a[x];vis[x]=1;pre[x]=0,chk(x,0),getdis(x,0);
    for(re int i=head[x];i;i=e[i].nxt) {
        if(vis[e[i].v]) continue;
        S=sum[e[i].v],rt=0,getroot(e[i].v,0),dfs(rt);
    }
}
inline int cmp(Edge A,Edge B) {return A.c<B.c;}
inline int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}
inline int merge(int x,int y) {
    int xx=find(x),yy=find(y);
    if(xx==yy) return 0;
    if(sz[xx]<sz[yy]) fa[xx]=yy,sz[yy]+=sz[xx];
        else fa[yy]=xx,sz[xx]+=sz[yy];
    return 1;
}
int main()
{
	scanf("%d", &n);
	for(re int i=1;i<=n;i++)
		scanf("%d", &a[i]);
    for(re int x,y,z,i=1;i<n;i++) 
	{
		scanf("%d%d%d", &x, &y, &z);
		Add(x, y, z), Add(y, x, z); 
	}
	mx[0]=n+1,S=n,rt=0,getroot(1,0),dfs(rt);
    std::sort(E+1,E+m+1,cmp);
    for(re int i=1;i<=n;i++) sz[i]=1,fa[i]=i;
    for(re int i=1;i<=m;i++) if(merge(E[i].a,E[i].b)) ans+=E[i].c;
    std::cout<<ans;
}

Measured memory_bytes: 74496
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <bitset>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

const int P = 1e9 + 7;

int main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;

	vector<vector<int>> dp(n + 1, vector<int>(n + 1));

	vector<int> a(n);
	for (int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;
		--l;
		a[l] = max(r, a[l]);
	}

	dp[0][0] = 1;

	int rg = 0;

	for (int i = 0; i < n; ++i) {
		if (a[i] <= rg) {
			if (i < rg) {
				for (int j = 1; j <= n; ++j)
					dp[i + 1][j - 1] += dp[i][j];
				for (int j = 0; j <= n; ++j) {
					if (rg - i > j)
						dp[i + 1][j] += dp[i][j];
				}
			} else {
				dp[i + 1][0] = dp[i][0];
			}
		} else {
			int x = 0;
			for (int j = max(rg, i); j < a[i]; ++j) 
				x += s[j] - '0';

			rg = a[i];

			for (int j = n; j >= 0; --j) {
				if (j + x <= n && x != 0) {
					dp[i][j + x] = dp[i][j];
					dp[i][j] = 0;
				}
			}

			for (int j = 1; j <= n; ++j)
				dp[i + 1][j - 1] += dp[i][j];
			for (int j = 0; j <= n; ++j) {
				if (rg - i > j)
					dp[i + 1][j] += dp[i][j];
			}
		}

		for (int j = 0; j <= n; ++j)
			dp[i + 1][j] %= P;
	}

	cout << dp[n][0] << endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

string replace_str(string &str,string from,string to){
	const unsigned int pos=str.find(from);
	const int len=from.length();
	if(pos==string::npos || from.empty()) return str;
	return str.replace(pos,len,to);
}

int main()
{
	ll n;
	string s;
	cin >> n >> s;
	vll l(n+1),r(n+1);
	l[0]=0;
	r[n]=0;
	rep(i,n){
		if(s[i]=='#') l[i+1]++;
		l[i+1]+=l[i];
	}
	for(ll i=n-1;i>=0;i--){
		if(s[i]=='.') r[i]++;
		r[i]+=r[i+1];
	}
	ll ans=INF;
	rep(i,n){
		chmin(ans,l[i]+r[i+1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3716
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
const LL MOD = 1000000007LL;
const int inf = 1e9;
const LL INF = 1e18;
int main() {
	string S;
	cin >> S;
	int N = S.size();
	LL ans = 0;
	for (int bit = 0; bit < (1 << (N - 1)); bit++) {
		LL x = S[0] - '0';
		LL sum = 0;
		for (int i = 0; i < N - 1; i++) {
			if (bit&(1 << i)) {
				sum += x;
				x = S[i + 1] - '0';
			}
			else {
				x *= 10;
				x += S[i + 1] - '0';
			}
		}
		sum += x;
		ans += sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/13/20 21:03:09
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll a,v,b,w,t; cin>>a>>v>>b>>w>>t;
  bool ans = v > w;
  ans &= abs(a-b) <= (v-w)*t;
  cout << (ans ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> prices(n);

    for (int i = 0; i < n; ++i) {
        int a, b; cin >> a >> b;
        prices[i] = make_pair(a, b);
    }
    sort(prices.begin(), prices.end());

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ll numToBuy = min(m, prices[i].second);
        ans += numToBuy * prices[i].first;
        m -= numToBuy;
        if (m == 0) break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int inf = 1e9;

int main() {
  int n; cin >> n;
  int cnt = 0;
  int h = 0;
  for(int i=0; i<n; i++) {
    int a; cin >> a;
    if(a >= h) cnt++;
    h = max(a, h);
  }
  cout << cnt << endl;

  return 0;
}


//EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a, b;
    getline(cin, a);
    getline(cin, b);
    int count = 0;
    for (int i = 0; i < a.length(); i++)
    {
        if (a[i] != b[i])
            count++;
    }
    cout << count;

    return 0;
}

Measured memory_bytes: 3832
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define ull unsigned long long
#define si short int
#define ll long long
#define piii pair<pair<int, int>, int>
#define piiii pair<pair<int, int>, pair<int, int>>

/*-----------------------------------------------------MATH------------------------------------------------*/
inline ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

inline int pwm(ll xx, ll pow, int MD) {
    if (pow < 0) { pow = pow % (MD - 1) + MD - 1; }
    ll mlt = 1;
    while (pow) {
        if (pow & 1) {
            mlt *= xx;
            mlt %= MD;
        }
        xx *= xx;
        pow >>= 1;
        xx %= MD;
    }
    return (int) mlt;
}

inline ll gcdex(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll xx, yy;
    ll gc = gcdex(b, a % b, yy, xx);
    x = xx;
    y = yy - (a / b) * xx;
    return gc;
}

inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }

inline int64_t hilbertOrder(int x, int y, int pow, int rotate) {
    if (pow == 0) {
        return 0;
    }
    int hpow = 1 << (pow-1);
    int seg = (x < hpow) ? (
            (y < hpow) ? 0 : 3
    ) : (
                      (y < hpow) ? 1 : 2
              );
    seg = (seg + rotate) & 3;
    const int rotateDelta[4] = {3, 0, 0, 1};
    int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
    int nrot = (rotate + rotateDelta[seg]) & 3;
    int64_t subSquareSize = int64_t(1) << (2*pow - 2);
    int64_t ans = seg * subSquareSize;
    int64_t add = hilbertOrder(nx, ny, pow-1, nrot);
    ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
    return ans;
}
/*-----------------------------------------------------MATH------------------------------------------------*/
vector<pair<ll, ll>> arr;
void solve() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        ll x,l;
        cin>>x>>l;
        arr.push_back({x-l, x+l});
    }
    sort(arr.begin(), arr.end());
    int keep=1;
    ll x=arr[0].first;
    ll y=arr[0].second;
    for(int i=1;i<n;i++){
        if(arr[i].first>=y){
            keep++;
            x=arr[i].first;
            y=arr[i].second;
        }
        else if(arr[i].second<y){
            x=arr[i].first;
            y=arr[i].second;
        }
    }
    cout<<keep;
}

int main() {
    /*ios::sync_with_stdio(false);
    cin.tie(nullptr);*/
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);
    unsigned int beg_time = clock();

    int n = 1;
    for (int i = 0; i < n; i++) solve();


    unsigned int end_time = clock();
    //cout<<endl<<endl<<end_time-beg_time;

    return 0;
}

Measured memory_bytes: 2420
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    double x1, y1, x2, y2;
    double distance;
    x1 = Double.parseDouble(str2[0]);
    y1 = Double.parseDouble(str2[1]);
    x2 = Double.parseDouble(str2[2]);
    y2 = Double.parseDouble(str2[3]);
    distance = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    System.out.println(distance);
  }
}


Measured memory_bytes: 24456