akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;string s;
  cin>>n>>s;
  int d[26]={};
  int a[11]={};
  for(int i=0;i<s.size();i++)d[s[i]-'a']++;
  for(int i=0;i<26;i++){
    if(d[i]){
  ans++;
  a[d[i]]++;
  }
  }
if(ans)ans--;
ans+=a[1];
for(int i=2;i<11;i++){
  ans+=min(a[i]+4,a[i]*3);
}
cout<<ans<<endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int n, q, a[100000];;
ll cnt[100001], b, c, tot;

int main()
{
    cin >> n;
    for(int i = 0; i<n; i++)
        cin >> a[i];
    for(int i = 0; i<n; i++)
        cnt[a[i]]++, tot+=a[i];
    cin >> q;
    for(int i = 0; i<q; i++)
    {
        cin >> b >> c;
        tot+=cnt[b]*(c-b);
        cnt[c]+=cnt[b], cnt[b] = 0;
        cout << tot << endl;
    }
}


Measured memory_bytes: 4680
program main
implicit none
integer :: i, j, n
real(8) :: nc_jpy, nc_btc
character(len=3) , allocatable :: cmoney(:)
real(8) , allocatable :: x(:)
real(8) :: y
real(8), parameter :: btc_jpy = 380000.

read(*,*) n
allocate(x(n))
allocate(cmoney(n))
nc_jpy = 0
nc_btc = 0
do i = 1, n
   read(*,*) x(i), cmoney(i)
   if (cmoney(i) == 'JPY') then
      nc_jpy = nc_jpy + x(i)
   else
      nc_btc = nc_btc + x(i)
   end if
end do

y = btc_jpy * nc_btc + nc_jpy
write(*,*) y

end program main


Measured memory_bytes: 256
(* O(√x log x) *)
let x = read_int ()
let rec f acc n = if acc * n > x then acc else f (acc * n) n
let b = ref 2
let ans = ref 1
let _ =
  if x > 1 then while !b * !b <= x do ans := max !ans @@ f !b !b; incr b done;
  Printf.printf "%d\n" !ans

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

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
typedef long long ll;
//////////////////////

int const N = 2e3 + 41;
int const MOD = 924844033;

int n, k, q;
int d[2][N][2][2];
int ans;

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

int mul(int a, int b){
	return (ll) a * b % MOD;
}

void clear(int id){
	memset(d[id], 0, sizeof(d[id]));
}

void solvechain(int m){
	fi(0, m){
		int p0 = (q&1);
		int p1 = (1 ^ p0);
		clear(p1);
		fj(0, N){
			for(int f0=0;f0<2;++f0){
				for(int f1=0;f1<2;++f1){
					int v = d[p0][j][f1][f0];
					if(v){
						//1
						add(d[p1][j][0][0], v);
						//2
						add(d[p1][j+1][1][1], v);
						//3
						if(j){
							int v1 = j - f0;
							add(d[p1][j][1][0], mul(v, v1));
						}
						//4
						if(j){
							int v1 = j - f1;
							add(d[p1][j][0][1], mul(v, v1));
						}
						//5
						if(j){
							int v1 = j - f0;
							int v2 = j - f1;
							add(d[p1][j-1][0][0], mul(v, mul(v1, v2)));
						}
					}
				}
			}
		}
		++q;
	}
	int pq = (q&1);
	fi(0, N){
		int s = 0;
		for(int f0=0;f0<2;++f0){
			for(int f1=0;f1<2;++f1){
				add(s, d[pq][i][f0][f1]);
				d[pq][i][f0][f1] = 0;
			}
		}
		d[pq][i][0][0] = s;
	}
}

void solve(){
	d[0][0][0][0] = 1;
	fi(0, k){
		solvechain((n - i + k - 1) / k);
	}
	ans = d[(q&1)][0][0][0];
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d %d",&n,&k);

	solve();

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] n = new int[10];
        for (int i = 0; i < n.length; i++) {
            n[i] = sc.nextInt();
        }
        Arrays.sort(n);
        for (int j =9; j > 6; j--) {
            System.out.println(n[j]);
        }
        
    }
}

Measured memory_bytes: 17236
#include <iostream>
#include <queue>
#include <string>
#include <set>
using namespace std;

const int MAX_H = 1005;
const int MAX_W = 1005;

string all[MAX_H];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int h, w;
int n;
int sx, sy;
typedef pair<int ,int> P;

int bfs(char target){
	set<P> s;
	queue<P> q1;
	queue<int> q2;
	q1.push(P(sy, sx));
	s.insert(P(sy, sx));
	q2.push(0);
	while (!q1.empty()){
		P p = q1.front(); q1.pop();
		int t = q2.front(); q2.pop();
		//cout << p.first << " " << p.second <<" "<<t<< endl;
		for (int i = 0; i < 4; ++i){
			int y = p.first + dy[i], x = p.second + dx[i];
			if (x >= 0 && x < w &&y >= 0 && y < h && all[y][x] != 'X'){
				if (s.count(P(y,x))){
					continue;
				}
				if (all[y][x] == target){
					all[y][x] = '.';
					sx = x, sy = y;
					return t + 1;
				}
				else{
					q1.push(P(y, x));
					q2.push(t + 1);
					s.insert(P(y, x));
				}
			}
		}
	}
}

void solve(){
	int ans = 0;
	char t = '1';
	for (int i = 0; i < n;++i){
		ans += bfs(t);
		++t;
	}
	cout << ans << endl;
}

int main(){
	cin >> h >> w >> n;
	for (int i = 0; i < h; ++i){
		cin >> all[i];
		for (int j = 0; j < w; ++j){
			if (all[i][j] == 'S'){
				sx = j, sy = i;
				all[i][j] = '.';
			}
		}
	}
	solve();
	return 0;
}

Measured memory_bytes: 24796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll n,p,odd = 0,even = 0,ans;
    cin >> n >> p;
    int a[n];
    rep(i, n){
        cin >> a[i];
        if (a[i] % 2 == 0) {
            ++even;
        }else{
            ++odd;
        }
    }
    if (odd == 0) {
        if (p == 0) {
            ans = pow(2, n);
        }
    }else{
        ans = pow(2, n - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
const LI MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      string s;cin>>s;
      LI n=s.length(),i;
      LI l[n],r[n];
      l[n-1]=n-1,r[0]=0;
      rfo(i,n-2,-1){
        if(s[i]=='L') l[i]=i;
        else l[i]=l[i+1];
      }
      fo(i,1,n){
        if(s[i]=='R') r[i]=i;
        else r[i]=r[i-1];
      }
      std::vector<LI> v(n,0);
      fo(i,0,n){
        if(s[i]=='R'){
          LI len=l[i]-i;
          if(len&1) v[i+len-1]++;
          else v[i+len]++;
        }
        else{
          LI len=i-r[i];
          if(len&1) v[i-len+1]++;
          else v[i-len]++;
        }
      }
      for(auto x:v) cout<<x<<sp;
    }
    return 0;
}

Measured memory_bytes: 5820
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int,input().split()))
    
    dp = [[-float("INF")]*(n+1) for i in range(n+1)]
    low = [-float("INF")]*(n+1)
    m = 0
    a,b = A[:2]
    dp[a][b] = 0
    dp[b][a] = 0
    low[a] = 0
    low[b] = 0
    base = 0

    for _ in range(1,n):
        a,b,c = A[3*_-1:3*_+2]
        q = []
        if a==b==c:
            base += 1
            continue
        m1 = max(m,max(dp[a][a],dp[b][b],dp[c][c])+1)
        for j in range(3):
            q.append((a,b,max(m,dp[c][c]+1)))
            for i in range(1,n+1):
                q.append((a,i,low[i]))
            if a==b:
                for i in range(1,n+1):
                    q.append((c,i,dp[a][i]+1))
                    m1 = max(m1,dp[a][i]+1)
            a,b,c = b,c,a
        for a,b,v in q:
            dp[a][b] = max(dp[a][b],v)
            dp[b][a] = max(dp[b][a],v)
            low[a] = max(low[a],v)  
            low[b] = max(low[b],v)      
        m = m1
    print(max(m,dp[A[-1]][A[-1]]+1)+base)

if __name__ == "__main__":
    main()

Measured memory_bytes: 226680
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;

//#define __DBG__

ll result=INF;

void solve(void){
  
  ll N;
  
  cin >> N;
  
  ll result=INF;
  
  for (ll a=1; a*a<=N; a++){
    if(N%a!=0){continue;}
    ll tmp = a+N/a-2;
    chmin(result, tmp);
  }
  
  cout << result << endl;
  
  return;
   
}


int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();
 
    return 0;
}


Measured memory_bytes: 256
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
A=list(map(int,input().split()))
c=0
lst=Counter([A[i]-(i+1) for i in range(N)])
for i in range(N):
    c+=lst[-(A[i]+i+1)]


print(c)


Measured memory_bytes: 130452
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    double W, H, x, y;
    cin >> W >> H >> x >> y;

    double S = W*H, ans;
    ans = S/2;
    printf("%.10lf", ans);
    
    if(x == W/2 && y == H/2)
        cout << ' ' << 1 << endl;
    else
        cout << ' ' << 0 << endl;

}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int a = 0, b = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if(x & 1) a++;
		if(x % 4 == 0) b++;
	}
	if(a + b == n) {
		puts(b + 1 >= a ? "Yes" : "No");
	} else {
		puts(b >= a ? "Yes" : "No");
	}
	return 0;	
}

Measured memory_bytes: 256
import sys

class LowLinks:
    def __init__(self, edges, v, root=0):
        self.edges = edges
        self.root = root
        self.ord = [None] * v
        self.low = [None] * v
        self.cnt = 0
        self.bridges = []
        self.articulations = set()
        self.par = [None] * v

    def build(self):
        self.search(self.root)

    def search(self, x):
        self.ord[x] = self.cnt
        self.low[x] = self.cnt
        self.cnt += 1
        dim = 0
        for to in self.edges[x]:
            if to == self.par[x]:continue
            if self.ord[to] != None:
                self.low[x] = min(self.low[x], self.ord[to])
            else:
                self.par[to] = x
                self.search(to)
                dim += 1
                self.low[x] = min(self.low[x], self.low[to])

                if x != self.root and self.ord[x] <= self.low[to]:
                    self.articulations.add(x)

            if x == self.root and dim > 1:
                self.articulations.add(x)

            if self.ord[x] < self.low[to]:
                self.bridges.append((x, to))


sys.setrecursionlimit(1000000)
v, e = map(int, input().split())
edges = [[] for _ in range(v)]
for _ in range(e):
    s, t = map(int, input().split())
    edges[s].append(t)
    edges[t].append(s)

lowlinks = LowLinks(edges, v)
lowlinks.build()
if lowlinks.articulations: print(*sorted(lowlinks.articulations),sep="\n")


Measured memory_bytes: 19288
from sys import setrecursionlimit
from collections import Counter
from collections import defaultdict
from collections import deque
from heapq import heapify
from heapq import heappop
from heapq import heappush
from time import time
setrecursionlimit(10**9)
mod=10**9+7
inf=10**18

a,b,c,d=[int(x) for x in input().split()]

print(max(a*c,a*d,b*c,b*d))

Measured memory_bytes: 9460
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

map<string,int>s;
int main(){
    string S,T,U;
    cin>>S>>T;
    cin>>s[S]>>s[T];
    cin>>U;
    if(s[U]) s[U]--;
    cout<<s[S]<<' '<<s[T]<<endl;
    return 0;
}

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

struct UnionFind {
  vector<int> par, rank;

  UnionFind(int n = 1) : par(n), rank(n, 0) { iota(begin(par), end(par), 0); }

  int root(int x) {
    return (par[x] == x) ? x : par[x] = root(par[x]);
  }
  bool isSame(int x, int y) {
    return root(x) == root(y);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    rank[x] += rank[y];
    par[y] = x;
  }
};

vector<int> out;
vector<vector<int>> g;

struct Kruskal {
  struct Edge { int s, t; };
  int n;
  vector<Edge> es;

  Kruskal(int n = 0) : n(n) {}

  void addEdge(int u, int v) {
    n = max(n, max(u, v) + 1);
    es.push_back({u, v});
  }
  void build() {
    UnionFind uf(n);
    for (auto&& e : es) {
      int u = e.s;
      int v = e.t;
      if (!uf.isSame(u, v)) {
        uf.unite(u, v);
        g[u].push_back(v);
        g[v].push_back(u);
      } else {
        cout << u + 1 << ' ' << v + 1 << endl;
        out[u]++;
      }
    }
  }
};

Kruskal kr;

void dfs(int s, int p) {
  for (auto t : g[s]) {
    if (t == p) continue;
    dfs(t, s);
  }
  if (p == -1) return;
  int u = s;
  int v = p;
  if (out[u] % 2 == 0) swap(u, v);
  cout << u + 1 << ' ' << v + 1 << endl;
  out[u]++;
}

int main() {
  int n, m;
  cin >> n >> m;
  out.assign(n, 0);
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b, a--, b--;
    kr.addEdge(a, b);
  }
  if (m % 2 != 0) {
    cout << -1 << endl;
    return 0;
  }
  kr.build();
  dfs(0, -1);
}


Measured memory_bytes: 14068
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

//頂点vが葉の時，頂点vを削除
int dfs(vector<set<int> > &G, int v, vector<int> &deg, vector<bool> &del){
  if(deg[v] == 1) del[v] = true; //頂点vが葉
  else return 0; //頂点vが葉以外
  deg[v] = 0;

  //頂点vから辿れる頂点に移動
  int num = 1;
  for(const int& u : G[v]){
    G[u].erase(v);
    --deg[u];
    num += dfs(G, u, deg, del);
  }
  return num;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  vector<set<int> >G(N);
  vector<int> deg(N,0); //頂点の次数
  vector<bool> del(N,false);  //頂点が削除されたか
  //グラフの構築1
  rep(j,M){
    int x,y;cin >> x >> y;
    --x;--y;
    G[x].insert(y);
    G[y].insert(x);
  }

  //次数の確認
  rep(i,N) deg[i] = G[i].size();

  //橋の数カウント
  int num = 0;
  rep(i,N) num += dfs(G,i,deg,del);

  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
a, b = STDIN.gets.chomp.split(" ").map{|x| x.to_i}
sum = 0
if a > b
  sum += a
  a -= 1
else
  sum += b
  b -= 1
end
if a > b
  sum += a
  a -= 1
else
  sum += b
  b -= 1
end
puts sum

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
ll n, cnt = 1;
string s;
int main() { ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> s;
	for (int i=1; i< n;i++) {
		if (s[i] != s[i-1]) cnt++;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

typedef long long ll;

using namespace std;

bool used[30];
string str;
vector<string> cand;

void dfs(int i){
	if(i==str.size()) cand.push_back(str);
	else{
		if(str[i]=='a' || used[str[i]-'a']) dfs(i+1);
		if(!used[str[i]-'a'+1] && str[i]!='z'){
			str[i]++;
			used[str[i]-'a'] = 1;
			dfs(i+1);

			used[str[i]-'a'] = 0;
			str[i]--;
		}
	}
}


int main(void){
	while(1){
		cin >> str;
		if(str == "#") break;

		fill(used, used+30, false);
		cand.clear();
		dfs(0);

		cout << cand.size() << endl;
		if(cand.size() <= 10){
			for(int i=0; i<cand.size(); i++){
				cout << cand[i] << endl;
			}
		} else{
			for(int i=0; i<5; i++){
				cout << cand[i] << endl;
			}
			for(int i=cand.size()-5; i<cand.size(); i++){
				cout << cand[i] << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4120
# Contest No.: ABC171
# Problem No.: E
# Solver:      JEMINI
# Date:        20200621

import sys
import heapq

def main():
    n = int(input())
    nums = list(map(int, sys.stdin.readline().split()))

    refVal = nums[0]
    for i in range(1, n):
        refVal ^= nums[i]
    for i in nums:
        print(refVal ^ i, end = " ")
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 91536
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N = intinp()
a = list(mapint_inp())

mx = 0
for i in range(N):
    cnt = 0
    t = a[i]
    while t%2==0:
        cnt += 1
        t //= 2
    mx += cnt

print(mx)

Measured memory_bytes: 4148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<long double, null_type, less_equal<long double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 200 * 1000 + 23;
const double E = 1e-7;






int n, k;
ll ps[MAXN], ans;
double tav;

int main() {
    ordered_set os;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> ps[i], ps[i] -= k - ps[i - 1];
    os.insert(0);
    for (int i = 1; i <= n; i++) {
        ans += os.order_of_key(ps[i] + 1);
        tav += E;
        os.insert(ps[i] + tav);
    }
    cout << ans;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string s;
	cin >> s;

	int x,y;
	cin >> x >> y;

	int n = s.size();

	vector<int> v;
	vector<int> h;

	bool hori = true;
	int cnt = 0;
	rep(i,n){
		char c = s[i];
		if(c == 'F') cnt++;
		else{
			if(hori) h.push_back(cnt);
			else v.push_back(cnt);
			hori = !hori;
			cnt = 0;
		}
	}

	if(cnt != 0){
		if(hori) h.push_back(cnt);
			else v.push_back(cnt);
	}

	int hlen = h.size();
	bool dph[hlen+1][16000];
	rep(i,hlen+1) rep(j,16000) dph[i][j] = false;
	dph[0][8000] = true;

	if(s[0] == 'F'){
		dph[1][8000+h[0]] = true;
	}else{
		dph[1][8000+h[0]] = true;
		dph[1][8000-h[0]] = true;
	}

	FOR(i,1,hlen){
		rep(j,16000){
			dph[i+1][j] |= dph[i+1][j];
			if(j+h[i] < 16000) dph[i+1][j] |= dph[i][j+h[i]];
			if(0 <= j-h[i]) dph[i+1][j] |= dph[i][j-h[i]];

		}
	}


	int vlen = v.size();
	bool dpv[vlen+1][16000];
	rep(i,vlen+1) rep(j,16000) dpv[i][j] = false;
	dpv[0][8000] = true;

	rep(i,vlen){
		rep(j,16000){
			dpv[i+1][j] |= dpv[i+1][j];
			if(j+v[i] < 16000) dpv[i+1][j] |= dpv[i][j+v[i]];
			if(0 <= j-v[i]) dpv[i+1][j] |= dpv[i][j-v[i]];

		}
	}

	cout << (dph[hlen][x+8000] && dpv[vlen][y+8000] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 124288
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string word;
	char oki;
	int m,h,su;
	cin>>word;
	
	while(word!="-"){
		cin>>m;
		su=word.size();
		for(int i=1;i<=m;i++){
			cin>>h;
			
			for(int j=0;j<h;j++){
				oki=word[0];
				for(int k=0;word[k]!='\0';k++){
					word[k]=word[k+1];
				}
				word[su-1]=oki;
			}
		}
		cout<<word<<endl;
		cin>>word;
	}
	return 0;
}

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


int main(void){
  long x[6],s,mod,sum;
  int k,i;
  double temp,min;

  k=1;

  for(i=0;i<6;i++){
  if(scanf("%ld",&x[i])>1){
    exit(1);
  }
  }

  for(i=2;i<6;i++){
    if(x[k]>x[i]){
      k=i;
    }
  }
  s=x[0]/x[k];
  mod=x[0]%x[k];
  sum=sum+s+4;
  if(mod!=0){
    sum=sum+1;
  }

  printf("%ld",sum);
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, string> P;
typedef tuple<int, string, string> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s, t;

bool solve() {
    return s == t.substr(0, (int)s.size());
}

void input() {
    cin >> s >> t;
}

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

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


Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int N;
int main(){
	scanf("%d",&N);
	int n,h;
	for(n=1;n<=3500;n++){
		for(h=1;h<=3500;h++){
			LL u=4LL*(LL)n*(LL)h-(LL)N*(LL)n-(LL)N*(LL)h;
			long long d=(LL)n*(LL)h*(LL)N;
			if(u==0 || u<0) continue;
			if(d%u==0LL){
				cout<<h<<' '<<n<<' '<<d/u;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;

struct yes_no : numpunct<char> {
  string do_truename()  const { return "Yes"; }
  string do_falsename() const { return "No"; }
};

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha;
  cout.imbue(loc);

  int N, A, B;
  string s;
  cin >> N >> A >> B >> s;
  int na = 0, nb = 0;
  REP(i,N) {
    bool res = false;
    if (s[i] == 'a') {
      if (na + nb < A + B) { res = true; ++na; }
    }
    else if (s[i] == 'b') {
      if (na + nb < A + B && nb < B) { res = true; ++nb; }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 896
import sys

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


for line in sys.stdin:
    line = line.strip()
    if line == "":
        break

    X = int(line)
    ans = 360 // gcd(X, 360)
    print(ans)

Measured memory_bytes: 8944
s = input()
words = ["dreamer", "dream", "eraser", "erase"]
while len(s) > 0:
    match = [s.endswith(i) for i in words]
    if True in match:
        ans = words[match.index(True)]
        s = s[:-len(ans)]
        if len(s) == 0:
            print("YES")
            break
    
    else:
        print("NO")
        break

Measured memory_bytes: 9140
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <functional>
#define rep(i, a, b) for(int i=a;i<b;++i)
#define MOD 1000000007
#define RAND 1000
using namespace std;

void DQsort(int a[], int b[], int left, int right)
{
	if (left >= right) return;
	int center = a[(left + right) / 2], temp;
	int l = left, r = right;
	while (l <= r) {
		while (a[l] < center) { ++l; }
		while (a[r] > center) { --r; }
		if (l <= r) {
			temp = a[l];
			a[l] = a[r];
			a[r] = temp;
			temp = b[l];
			b[l] = b[r];
			b[r] = temp;
			++l;
			--r;
		}
	}
	DQsort(a, b, l, right);
	DQsort(a, b, left, r);
}

int main(void)
{
	int n, a[100000] = { 0 }, b[100000] = { 0 };
	long long int k;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
	}
	DQsort(a, b, 0, n - 1);
	for (int i = 0; i < n; ++i) {
		k -= b[i];
		if (k <= 0) {
			cout << a[i] << endl;
			break;
		}
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
int color[N];
vector < pair < int , int > > adj[N];

void dfs(int u , int dist , int p){
    if(dist & 1){
        color[u] = 0;
    } else {
        color[u] = 1;
    }
    for(auto v : adj[u]){
        if(v.first == p)
            continue;
        dfs(v.first , (dist + v.second) % 2 , u);
    }
}

int main(){
    scanf("%d" , &n);
    for(int i = 1; i < n; i++){
        int u , v , w;
        scanf("%d%d%d" , &u , &v , &w);
        adj[u].push_back({v , w});
        adj[v].push_back({u , w});
    }
    dfs(1 , 0 , -1);
    for(int i = 1; i <= n; i++){
        printf("%d\n" , color[i]);
    }
}


Measured memory_bytes: 10752
#include<stdio.h>

long int main(){

long int a,b,k;
double d;
scanf("%ld %ld",&a,&b);

if(a-b!=0){
d=(a*a)-(b*b);
d=d/(2*(a-b));
k=(int)d;
if(k==d){printf("%ld",k);}
else{
  printf("IMPOSSIBLE");
}
}
return 0;

}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;


//wierd debugging stuff
#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__) << "] "
//end of weird debugging stuff
using ll = long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define Test int T;cin>>T;while(T--)
#define REP(i,j,k) for(int i=(j);(i)<(k);(i)++)
#define Time()	cerr <<'\n' << clock() * 1000 / CLOCKS_PER_SEC << "ms\n"
#define SZ(x) (int)x.size();
#define all(x) x.begin,x.end()
// no change 

//const int MxN = 1e9+5;
const int N = 1e5+10;
int main() {
	int n,m;
	cin>>n>>m;
	vi v[n+1];
	vi x(n);
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;a--,b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int total=0;
	for(int i=0;i<n;i++){
		int a = x[i];
		bool q = true;
		debug()<<imie(v[i]);
		//if(v[i].size() == 0)continue;
		for(int j =0;j<(int)v[i].size();j++){
			if(a <=  x[v[i][j]])q = false;
			debug()<<imie(a)<<imie(x[v[i][j]]);
		}
		if(q) total++;
	}
	//debug()<<imie(v);
	debug()<<imie(x);
	cout<<total;
	
	
	
	
	
}


Measured memory_bytes: 8704
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	final static String EOF_STR = "END_OF_TEXT";
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    String findStr = br.readLine().toLowerCase();

	    int findCount = 0;
	    while (true) {
	    	String line = br.readLine();
	    	if (EOF_STR.equals(line)) break;

	    	line = line.toLowerCase();
	    	String[] words = line.split(" ");
	    	for (int i = 0; i < words.length; i++) {
	    		if (findStr.equals(words[i])) {
	    			findCount++;
	    		}
	    	}
	    }
        System.out.println(findCount);
	}
}

Measured memory_bytes: 24400
#include <stdio.h>
int main (){
	int lokasi, a, b, x, y;
	//lokasi rumah, toko a, toko b 
	scanf ("%d %d %d", &lokasi, &a , &b);
	
	x= a- lokasi; 
	y= b- lokasi; 
	if (x<0){
	x=-1*(x);
	}
	if (y<0){
	
	y=-1*(y);
	}
	if (x< y){
	printf ("A");
	}else{
	
	printf ("B");
}
	
	return 0; 
}

Measured memory_bytes: 1660
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

lli Gcd(lli x, lli y) {
  if (y == 0) return x;
  return Gcd(y, x % y);
}
int main(void) {
  lli a, b;
  scanf("%lld %lld", &a, &b);

  lli gcd = Gcd(a, b);
  lli ans = a * b / gcd;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>

int alph[26];
int p;

void Check(char _moji) {
    p = 0;
    if (isupper(_moji)) _moji = tolower(_moji);
    for (char ch = 'a'; ch <= 'z'; ch++) {
        if (ch == _moji) {
            alph[p] += 1;
            break;
        }
        p++;
    }
}
void Show() {
    p = 0;
    for (char ch = 'a'; ch <= 'z'; ch++) {
        printf("%c : %d\n", ch, alph[p]);
        p++;
    }
}
int main() {
    char moji;
    while(scanf("%c", &moji) != EOF) {
        Check(moji);
    }
    Show();
    return 0;
}

Measured memory_bytes: 3172
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;

int main() {
	while(true) {
		int n; scanf("%d", &n);
		if(n==0) break;
		int submax; scanf("%d", &submax);
		int maxval = submax;
		for(int i = 1; i < n; i++) {
			int a; scanf("%d", &a);
			submax = max(a, submax+a);
			maxval = max(maxval, submax);
		}
		printf("%d\n", maxval);
	}
	return 0;
}

Measured memory_bytes: 0
# frozen_string_literal: true

n = gets.to_i
xy = n.times.map { gets.split.map(&:to_i) }.sort

if n == 1
  puts 1
  exit
end

h = Hash.new(0)

xy.combination(2).each do |c|
  h[[c[0][0] - c[1][0], c[0][1] - c[1][1]]] += 1
end
puts n - h.max_by { |_k, v| v }[1]


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*num[i] = i番目の箱に何個ボールがあるか
　red[i] = i番目の箱に赤がありうるか
 num[xi] = 1かつred[xi] = 1のxi番目の箱から玉を取り出す時、
 red[xi] = 0となり、red[yi] = 1に、num[xi] -= 1,num[yi] += 1になる
 num[xi] >= 2かつred[xi] = 1のxi番目の箱から玉を取り出す時、
 red[xi] = 1のまま、red[yi] = 1,num[xi] -= 1,num[yi] += 1
 red[xi] = 0の時、num[xi] -= 1,num[yi] += 1
*/
int main() {
 int N,M;
 cin >> N >> M;
 vector<int> x(M);
 vector<int> y(M);
 rep(i,M){
     cin >> x[i];
     cin >> y[i];
 }
 vector<int> num(N,1);
 vector<int> red(N);
  red[0] = 1;
 for(int i = 0;i<M;i++){
     if(num[x[i]-1] == 1 && red[x[i]-1] == 1){
         red[x[i]-1] = 0;
         red[y[i]-1] = 1;
         num[x[i]-1] -= 1;
         num[y[i]-1] += 1;
     }
     else if(num[x[i]-1] >= 2 && red[x[i]-1] == 1){
         red[y[i]-1] = 1;
         num[x[i]-1] -= 1;
         num[y[i]-1] += 1;
     }
     else if(red[x[i]-1] == 0){
         num[x[i]-1] -= 1;
         num[y[i]-1] += 1;
     }
 }
 int c = 0;
 rep(i,N){
     if(red[i] == 1) c++;
 }
  cout << c << endl;
}

 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        rep(i,5){
            ll a;
            cin>>a;
            if(a==0){
                cout<<i+1<<endl;
                return 0;
            }
        }
    }

Measured memory_bytes: 3668
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            while(a % 2 == 0){
                a /= 2;
                ans++;
            }
        }
        System.out.println(ans);
    }
}


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

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n, k - q);
    rep(i, q)
    {
        int answerer;
        cin >> answerer;
        answerer--;
        a.at(answerer)++;
    }

    rep(i, n)
    {
        if (a.at(i) > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

ans = 0
l = []

for i in range(n):
  for j in range(m):
    l.append(a[i][j] * b[j]) 
  if sum(l) + c > 0:
      ans += 1
      l.clear()
  else:
      l.clear()

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define sgn(v) (abs((v))<eps?0:((v)<0?-1:1))
#define sqr(v) ((v)*(v))
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define debug 0
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double,int> PDI;
typedef pair<double,double> PDD;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<LL,LL> PLL;
typedef long double Double;
const Double eps=1e-8;
const Double pi=acos(-1);
using namespace std;
const int maxn=4e4+100;
Double x[maxn],y[maxn];
Double a[3][3],c[3][3],b[3];
Double replace(int ix)
{
    int i,j;
    double res=0;
    for(i=0;i<3;++i)
        for(j=0;j<3;++j)c[i][j]=a[i][j];
    for(j=0;j<3;++j)c[ix][j]=b[j];
    for(i=0;i<3;++i)
    {
        res+=c[0][i]*c[1][(i+1)%3]*c[2][(i+2)%3];
        res-=c[0][i]*c[1][(i+2)%3]*c[2][(i+1)%3];
    }
    return res;
}
int main()
{
    int n,i;
	//cout <<sizeof(double)<<" "<<sizeof(long double)<<" "<<sizeof(float)<<" "<<sizeof(int)<<endl;
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(i=0;i<n;++i)
    {
        scanf("%Lf%Lf",&x[i],&y[i]);
        b[0]+=(sqr(x[i])+sqr(y[i]))*x[i];
        b[1]+=(sqr(x[i])+sqr(y[i]))*y[i];
        b[2]+=(sqr(x[i])+sqr(y[i]));
        a[0][0]+=sqr(x[i]);a[0][1]+=x[i]*y[i];a[0][2]+=x[i];
        a[1][0]+=x[i]*y[i];a[1][1]+=sqr(y[i]);a[1][2]+=y[i];
        a[2][0]+=x[i];a[2][1]+=y[i];a[2][2]+=1;
    }
    for(i=0;i<3;++i)b[i]=-b[i];
    Double delta=0;
    for(i=0;i<3;++i)
    {
        delta+=a[0][i]*a[1][(i+1)%3]*a[2][(i+2)%3];
        delta-=a[0][i]*a[1][(i+2)%3]*a[2][(i+1)%3];
    }
    //cout <<delta<<endl;
    Double A=replace(0)/delta;
    Double B=replace(1)/delta;
    Double C=replace(2)/delta;
    printf("%.3Lf %.3Lf %.3Lf\n",A,B,C);
    //printf("%.9f %.9f %.9f\n",A,B,C);
    return 0;
}

Measured memory_bytes: 2508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;

#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
        cout << it << " ";        \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){\
cout << it.fi << " " << it.se << endl;}


#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
//#define endl "\n"
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n;
    vec ans(n,0);
    fo(i,n-1){
        int x;
        cin>>x;
        x--;
        ans[x]++;
    }
    fo(i, n)
            cout
        << ans[i] << endl;
        

}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  priority_queue<int> pq;
  int n, m;
  cin >> n >> m;

  vector<int> G[100001];
  int a, b;
  for(int i = 0; i < n; i++){ 
    cin >> a >> b;
    G[a].push_back(b); 
  }

  int ans = 0;
  for(int i = m; i >= 0; i--){
    for(int j = 0; j < G[m-i].size(); j++){
      pq.push(G[m-i][j]);
    }
    if(!pq.empty()){
      ans += pq.top(); pq.pop();
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5632
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








template <typename T>
class Bellmanford {
private:
    struct edge {
        int to;
        T cost;
    };
    int n;
    vector<vector<edge>> g;
    vector<T> dist;
    
public:
    Bellmanford(int n) : n(n), g(n){}
    
    void add_edge(int v1, int v2, T cost){
        g[v1].push_back({ v2, cost });
    }
    
    // 負の閉路があるときfalseを返す
    bool run(int s){
        dist = vector<T>(n, INF);
        dist[s] = 0;    //開始点の距離は0
        
        for (int i = 0; i < n; i++) {
            for (int v = 0; v < n; v++) {
                for (auto& e : g[v]) {
                    if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
                        dist[e.to] = dist[v] + e.cost;
                        if (i == n - 1) {
                            // return false;
                            dist[e.to] = -INF;
                        }
                    }
                }
            }
        }
        return true;
    }
    
    T get_distance(int v){
        return dist[v];
    }
};

int main(){
    ll n, m;
 
    cin >> n >> m;
 
	Bellmanford<ll> bell(n);
 
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
 
		bell.add_edge(a, b, -c);
	}
 
	bell.run(0);
 
	if (bell.get_distance(n - 1) > -INF) {
		cout << -bell.get_distance(n - 1) << endl;
	}
	else {
		cout << "inf" << endl;
	}

}

Measured memory_bytes: 384
using System;

namespace Dice
{
    class Program
    {
        private static bool Eql(string[]x, string[]y)
        {
            var g = true;
            for (int o = 0; o < x.Length; o++)
              if (x[o] != y[o]) g = false;
            return g;
        }

        private static string Check(string[]x, string[]y)
        {
            if (Eql(x, y)) return "Yes";
            for (int p = 0; p < 2; p++)
            {
                for(int q = 0; q < 4; q++)
                {
                    var a = x[0]; var b = x[1]; var c = x[2];
                    var d = x[3]; var e = x[4]; var f = x[5];
                    x = p == 0 ? new string[] { e, a, c, d, f, b } :
                                 new string[] { d, b, a, f, e, c };
                    if (Eql(x, y)) return "Yes";
                    var h = x;
                    for(int r = 0; r < 4; r++)
                    {
                        var i = h[0]; var j = h[1]; var k = h[2];
                        var l = h[3]; var m = h[4]; var n = h[5];
                        h = new string[] { i, k, m, j, l, n };
                        if (Eql(h, y)) return "Yes";
                    }
                }
            }
            return "No";
        }

        static void Main()
        {
            var s = Console.ReadLine().Split(' ');
            var t = Console.ReadLine().Split(' ');
            Console.WriteLine(Check(s, t));
        }
    }
}

Measured memory_bytes: 8940
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
		
		long n = a / x;
		long m = b / x;
		if (a % x == 0) {
			n--;
		}
		System.out.println(m - n);
	}
}


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

int bubbleSort(vector<int>& A, int N) {
    int sw = 0;
    bool flag = 1;
    for (int i = 0; flag; i++) {
        flag = 0;
        for (int j = N - 1; j >= i + 1; j--) {
            if (A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main() {
    int N, sw;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sw = bubbleSort(A, N);
    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
}


Measured memory_bytes: 3104
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>

using namespace std;

void solve(int N, int K, vector<long long> h) {
  long long ans = 1e9;
  vector<long long> hh(N + 1, 0);
  for (int i = 0; i <= N - K; i++) {
    ans = min(ans, h[i + K - 1] - h[i]);
  }
  printf("%lld\n", ans);
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  solve(N, K, h);
  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,k;cin>>n>>k;vector<int> ls(n);
	for(auto &x:ls)cin>>x;
	vector<int>dp(n,1e9);dp[0]=0;
	for(int u=0;u<n;u++){
		for(int v=u+1;v<n&&v-u<=k;v++){
			dp[v]=min(dp[v],dp[u]+abs(ls[u]-ls[v]));}}
	cout<<dp[n-1];
}
	
		

Measured memory_bytes: 4048
def war():
  print('War')
  exit()

def nowar():
  print('No War')
  exit()
  
N,M,X,Y= map(int, input().split())
if Y -X < 1: war()

xmax = max(list(map(int,input().split())))
ymin = min(list(map(int,input().split())))
for z in range(X+1,Y+1):
  if xmax < z and ymin >= z: nowar()

war()


Measured memory_bytes: 38512
#include <iostream>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b)
{
	ll x = a * b;
	if (a < b) {
		swap(a, b);
	}
	ll r = a % b;
	while (r) {
		a = b;
		b = r;
		r = a % b;
	}

	return x / b;
}

int main(int argc, char *argv[])
{
	ll A, B;

	cin >> A >> B;

	cout << gcd(A, B) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] a = new long[N];
    long count =0;
    for (int i =0; i<N; i++) {
      a[i] = sc.nextLong();
      while (a[i] % 2 == 0) {
        count++;
        a[i] /= 2;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 48936
#include<bits/stdc++.h>
using namespace std;
int H,W,K,a[1001][1001],dp[1001][1001];
int main(){
	while(true){
		cin>>H>>W>>K;if(H==0)break;
		for(int i=0;i<H;i++){for(int j=0;j<W;j++){scanf("%d",&a[i][j]);dp[i][j]=0;}}
		dp[0][0]=K-1;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(dp[i][j]%2==0){dp[i+1][j]+=dp[i][j]/2;dp[i][j+1]+=dp[i][j]/2;}
				else{
					if(a[i][j]==0){dp[i+1][j]+=dp[i][j]/2+1;dp[i][j+1]+=dp[i][j]/2;}
					if(a[i][j]==1){dp[i+1][j]+=dp[i][j]/2;dp[i][j+1]+=dp[i][j]/2+1;}
				}
			}
		}
		for(int i=0;i<H;i++){for(int j=0;j<W;j++){dp[i][j]%=2;a[i][j]^=dp[i][j];}}
		int cx=0,cy=0;
		while(cx<H && cy<W){if(a[cx][cy]==0)cx++;else cy++;}
		cout<<cx+1<<' '<<cy+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 10988