akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  string S, T;
  cin >> S >> T;
  cout << T << S << endl;
  ios::sync_with_stdio(0);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

#define int long

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)

constexpr int evx[4] = { 1, 0, -1, 0 };
constexpr int evy[4] = { 0, 1, 0, -1 };

//----------------------------------
//----------------------------------

signed main()
{
    ios::sync_with_stdio(false);
        int n, x;
        vector<int> a;
        cin >> n >> x;
        for(int i = 0; i < n; i++)
        {
                int tmp;
                cin >> tmp;
                a.push_back(tmp);
        }
        int ans = 0;
        for(int i = 0; i < n-1; ++i)
        {
                if(a[i] + a[i+1] > x)
                {
                        int dif = a[i] + a[i+1] - x;
                        a[i+1] -= dif;
                        if(a[i+1] < 0)
                        {
                                a[i] += a[i+1];
                                a[i+1] = 0;
                        }
                        ans += dif;
                }
        }
        cout << ans << '\n';

}




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

typedef long long LL;
const int MAXN=1e5+5;
const int MAXM=1e5+5;
const int mod=1e9+7;

char x[20];
int n;

LL get(int l,int r){
	LL sum=0;
	for(int i=l;i<=r;i++){
		sum*=10;
		sum+=(x[i]-'0');
	}
	return sum;
}

LL ans;

int main(){
    scanf(" %s",x+1);
    n=strlen(x+1);
    ans=0;
    for(int i=1;i<=n;i++)
    	for(int j=i;j<=n;j++){
    		//cout<<i<<' '<<j<<' '<<get(i,j)<<'\n';
    		//cout<<(1<<max(0,i-2))<<' '<<(1<<max(0,n-j-1))<<endl;
    		ans+=get(i,j)*(1<<max(0,i-2))*(1<<max(0,n-j-1));
    	}
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
  int N;
  int K;
  cin >> N >> K;
  
  int halfsum = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (2 * x < K) {
      halfsum += x;
    }
    else {
      halfsum += K - x;
    }
  }
  
  cout << 2 * halfsum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,vi> g;
unordered_map<ll,ll> vis;

const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 2e5+10;
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
bool imp = false;
bool isPowerOfTwo (ll x)
{
    return x && (!(x&(x-1)));
}

void solve() {

    char c;cin>>c;
    if(c >='A' and c<='Z')
        cout<<'A';
    else
        cout<<'a';

}

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

    fio
    int t=1;
    if(imp) cin>>t;

    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }

}


Measured memory_bytes: 3648
import collections

usrCount = int(input())
usrStrList = []

mostStrList = []

for n in range(usrCount):
    usrStrList.append(input())

countObj = collections.Counter(usrStrList)
mostedList = countObj.most_common()

for n in range(len(mostedList)):
    if mostedList[0][1] == mostedList[n][1]:
        mostStrList.append(mostedList[n][0])

sortedList = sorted(mostStrList, reverse = False)

for m in range(len(sortedList)):
    print(sortedList[m])

Measured memory_bytes: 49204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int N,M;
        N=s.nextInt();
        M=s.nextInt();
        int [] arr =new int[N];
        int totalVotes=0;
        for(int i=0;i<N;i++){
            arr[i]=s.nextInt();
            totalVotes+=arr[i];
        }
        int cnt=0;
        for(int i=0;i<N;i++){
            if(arr[i]*(4*M)>=totalVotes)
                cnt++;
        }
        if(cnt>=M)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

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

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

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

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

}


Measured memory_bytes: 23252
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


N = I()
A = LMI()

for a in A:
    if a % 2 == 0:
        if a % 3 != 0 and a % 5 != 0:
            print('DENIED')
            exit(0)
print('APPROVED')


Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,C;
  cin >> N >> C;
  vvi D(C,vi(C));
  rep(i,C) {
    rep(j,C) {
      cin >> D[i][j];
    }
  }
  vvi c(N,vi(N));
  rep(i,N) {
    rep(j,N) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  vvi cnt(3,vi(C,0));
  rep(i,N) {
    rep(j,N) {
      cnt[(i+j)%3][c[i][j]]++;
    }
  }
  int ans = INF;
  rep(i,C) {
    srep(j,i+1,C) {
      srep(k,j+1,C) {
        vi rs = {i,j,k};
        do {
          int cost = 0;
          rep(l,C) {
            rep(r,3) {
              cost += cnt[r][l] * D[l][rs[r]];
            }
          }
          ans = min(ans,cost);
        } while(next_permutation(rng(rs)));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1280
import Data.Bits
import Data.Char
import Data.List

main = do
  li <- getLine
  let n = read li
  xs <- getLine
  mapM_ print $ compute n xs

compute :: Int -> String -> [Int]
compute n xs = [ f (x `xor` bit i) | i <- [n-1,n-2..0] ]
  where
    x :: Integer
    x = foldl' (\acc b -> acc+acc+b) 0 $ map (fromIntegral . digitToInt) xs

step :: Integer -> Integer
step x = x `mod` fromIntegral (popCount x)

f :: Integer -> Int
f x = length $ takeWhile (0 /=) $ iterate step x
{-
最大2万桁の2進数を扱うのは、Integerでやればできるかもしらんがどうかという。
最初のpopCountはたかだか2万なので、あまりもそれ未満。だから初回さえ乗り切ればあとは普通の整数で間に合う。
けどそれも面倒なので、IntegerのData.Bitsでゴリ押ししてみよう。
-}

Measured memory_bytes: 12236
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
bool cmp(P a, P b) {
    if (a.first == b.first) return a.second < b.second;
    else return a.first < b.first;
}
int main() {
    int T;
    cin >> T;
    vector<P> v;
    for (int i = 0; i < T; i++) {
        int a,b;
        cin >> a >> b;
        v.emplace_back(a,b);
    }
    sort(v.begin(), v.end(), cmp);
    for (auto & i : v) {
        cout << i.first << " " << i.second << endl;
    }
    return 0;
}


Measured memory_bytes: 3852
def gcd(m, n)
  return m if n == 0
  return gcd(n, m % n)
end
def lcm(m, n, g)
  return m * n / g
end
while gets do
  a, b = $_.chomp.split(/ /).map(&:to_i)
  g = gcd(a, b)
  l = lcm(a, b, g)
  puts "#{g} #{l}"
end

Measured memory_bytes: 6092
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
	typedef long long int lli;
	const int MaxN=200005;
	#define fst first
	#define snd second
	int mcd(int a,int b){	
		if(a==0)return b;
		return mcd(b%a,a);
	}	;
int main(){
	lli N,K,i,j,p,q;
	cin>>N;
	p=N/500;
	N=N%500;
	q=N/5;
	cout<<p*1000+q*5;
	
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 8
#define M 15

int putQueen(int);
int row[N],col[N],dpos[M],dneg[M];

int main(){
  int i,j,k,r,c;

  for(i=0;i<N;i++) row[i]=-1;

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    row[r]=c;
    col[c]=1;
    dpos[r+c]=1;
    dneg[r-c+N-1]=1;
    }

  putQueen(0);

  return 0;
}

int putQueen(int i){
  int j;
  
  if(i==N){
    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
	if(row[i]==j) printf("Q");
	else printf(".");
      }
      printf("\n");
    }
    return 0;
  }

  if(row[i]==-1){
    for(j=0;j<N;j++){
      if(col[j]==1||dpos[i+j]==1||dneg[i-j+N-1]==1) continue;
      
      row[i]=j;
      col[j]=dpos[i+j]=dneg[i-j+N-1]=1;
      if(putQueen(i+1)==0) return 0;
      col[j]=dpos[i+j]=dneg[i-j+N-1]=0;
      row[i]=-1;
    }
  }
  else{
    if(putQueen(i+1)==0) return 0;
  }
}

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

int main() {

  string s;
  getline(cin, s);

  string answer = "";

  for (int i = 0; i < s.size(); i++) {
    int v = (int) s[i];
    if (65 <= v && v <= 90) {
      answer += char(v + 32);
    } else if (97 <= v && v <= 122) {
      answer += char(v - 32);
    } else {
      answer += v;
    }
  }

  cout << answer << endl;

  return 0;

}


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

int main(void) {
  long N, sum, curmax;
  cin >> N;
  vector<long> A(N);
  sum = 0;

  for (size_t i = 0; i < A.size(); i++) cin >> A[i];
  curmax = A[0];
  for (size_t i = 1; i < A.size(); i++) {
    if (A[i] < curmax) sum += curmax - A[i];
    curmax = max(A[i], curmax);
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
float sum=0;
int main()
{
	
	int a;
	cin>>a;
	unsigned long long b[1005];
	for(int i=0;i<a;i++)
	{
		cin>>b[i];
	}
	sort(b,b+a);
	sum=(b[0]+b[1])/2.0;
	for(int i=2;i<a;i++)
	{
		sum=(sum+b[i])/2;
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int qs1[100001],qs2[100001];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    string A,B;cin >> A >> B;
    for(int i=0;i < A.size();i++) qs1[i+1]=qs1[i]+(A[i] == 'A' ? 1 : 2);
    for(int i=0;i < B.size();i++) qs2[i+1]=qs2[i]+(B[i] == 'A' ? 1 : 2);
    int Q;cin >> Q;
    while(Q--){
        int a,b,c,d;cin >> a >> b >> c >> d;
        int sum1=qs1[b]-qs1[a-1],sum2=qs2[d]-qs2[c-1];
        if(abs(sum1-sum2)%3 == 0) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 1744
use io::*;
use proconio::{fastout, input};
use std::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [i64; n]
    }
    a.sort();
    let mut s = collections::HashSet::new();
    let mut dups = collections::HashSet::new();
    for i in 0..a.len() {
        if s.contains(&a[i]) {
            dups.insert(&a[i]);
        } else {
            s.insert(&a[i]);
        }
    }
    let mut res = 0;
    for i in 0..n {
        let mut curr = a[i];
        let mut valid = false;
        if !s.contains(&curr) {
            continue;
        };
        while curr <= 1000000 && curr <= a[n - 1] {
            if s.contains(&curr) {
                s.remove(&curr);
            }
            curr += a[i];
        }
        if (!dups.contains(&a[i])) {
            res += 1;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 9568
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 55;

int main() {
  //freopen("in.cpp","r",stdin);

  int n;
  cin>>n;
  vector<int>c(26,maxn);
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    vector<int>tmp(26,0);
    for(int j=0;j<s.size();j++)tmp[s[j]-'a']++;
    for(int j=0;j<26;j++)c[j]=min(c[j],tmp[j]);
  }
  string ret;
  for(int i=0;i<26;i++){
    while(c[i]--)ret+=i+'a';
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;



int main() {
	vector<int> T(5);
	rep(i, 5) cin >> T[i];
	//vector<int> S(5);
	int sum = 0;
	int loss = 0;
	rep(i, 5) {
		int t = 10*dup(T[i],10);
		sum += t;
		if(loss<t-T[i]) loss = t-T[i];
	}

	cout << sum -loss << endl;
	
	return 0;
}

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

// templates -------------------------------------

#define ULL unsigned long long
#define LL long long
#define LLD long long double
#define REP(i, n) for(LL i = 0; i < n; i++)
#define INV_REP(i, n) for(LL i = n; 0 <= i; i--)

LL combination(LL n, LL m)
{
  LL nume = 1;
  REP(i, m) nume *= (n-i);
  LL demo = 1;
  for(int i = 1; i <= m; i++) demo *= i;
  return nume / demo;
}

template<class T>
class UnionFind
{
private:
  vector<T> par;
  vector<T> rank;
  vector<T> size;

public:
  UnionFind(T N) :
    par(N, T()), rank(N, T()), size(N, T())
  {
    REP(i, N)
    {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  inline T root(T x)
  {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  inline bool same(T x, T y)
  {
    return root(x) == root(y);
  }

  inline T getSize(T x)
  {
    return size[root(x)];
  }

  void unite(T x, T y)
  {
    T r1 = root(x);
    T r2 = root(y);
    if(r1 == r2) return;

    if(rank[r1] < rank[r2]) swap(r1, r2);
    if(rank[r1] == rank[r2]) rank[r1]++;
    par[r2] = r1;
    size[r1] += size[r2];
  }
};

template<class T> vector<T> cumulativeSum(const vector<T>& ordered)
{
  vector<T> res;
  T sum = 0;
  for(auto elem : ordered)
  {
    res.push_back(sum += elem);
  }
  return std::move(res);
}

vector<LL> divisor(LL n)
{
  vector<LL> res;
  for(LL i = 1; i*i <= n; i++)
  {
    if(n % i == 0)
    {
      res.push_back(i);
      if(i * i != n) res.push_back(n/i);
    }
  }
  sort(begin(res), end(res));
  return res;
}

LL gcd(LL m, LL n)
{
  return (n == 0) ? m : gcd(n, m%n);
}

LL gcd(const vector<LL>& n)
{
  LL allGCD = gcd(n[0], n[1]);
  for(LL i = 2; i < n.size(); i++)
  {
    allGCD = gcd(allGCD, n[i]);
  }
  return allGCD;
}

// --------------------------------------

int k, n;

void input()
{
  cin >> n >> k;
}

void solve()
{
  LL res = 0;
  for(int i = 0 ; i < n; i++)
  {
    
  }
  cout << n - (k-1);
}

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

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

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

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    ll N,A,B;
    cin >> N >> A >> B;

    if((B-A)%2==0){
        cout << (B-A)/2 << endl;
    }else{
        ll tmp = min(N-B,A-1); //片方が寄り切るまでの時間

        if(N-B<A-1){
            A += tmp;
            B = N; 
        }else{
            A = 1;
            B -= tmp;
        }
        cout << tmp+(B-A+1)/2 << endl;
    }


}



Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
for i in range(0, 10**n):
    if len(str(i)) == n and all(str(i)[s-1] == str(c) for s,c in sc):
        print(i)
        break
else:
    print(-1)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{s:String};
    let v:Vec<&str> = s.split(',').collect();
    //debug!(v);
    println!("{}", v.join(" "));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int X[3]={-1,-1,-1};
bool f=true;
int main()
{
  int N,M;
  cin>>N>>M;
  while(M--)
  {
    int A,B;
    cin>>A>>B;
    A--;
    if(!A&&!B&&N>1)
      f=false;
    if(X[A]!=-1&&X[A]!=B)
      f=false;
    X[A]=B;
  }
  for(int i=1;i<N;i++)
    if(X[i]==-1)
      X[i]=0;
  if(X[0]==-1&&N>1)
    X[0]=1;
  if(X[0]==-1&&N<=1)
    X[0]=0;
  if(f)
  {
    for(int i=0;i<N;i++)
      cout<<X[i];
  }
  else puts("-1");
  return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e18+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll H,W,D;
P A[90005];
map<P,ll> cost;
ll Q;

ll calc(ll a1,ll a2){
	ll x=A[a1].second;
	ll y=A[a1].first;
	ll i=A[a2].second;
	ll j=A[a2].first;
	return abs(x-i)+abs(y-j);
}

int main(){

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

cin>>H>>W>>D;

rep(h,H){
	rep(w,W){
		ll a;
		cin>>a;
		A[a].first=h+1;
		A[a].second=w+1;
	}
}

rep(i,D){
	ll to=i+1;
	while(1){
		if(to>D){
			P p1={i+1,to},p2{i+1,to-D};
			cost[p1]=cost[p2]+calc(to-D,to);
		}
		to+=D;
		if(to>H*W) break;
	}
}

cin>>Q;
rep(i,Q){
	ll L,R,d;
	cin>>L>>R;
	d=L%D;
	if(d==0) d=D;
	P p1={d,R},p2{d,L};
	cout<<cost[p1]-cost[p2]<<endl;
}


}
	


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[3][3], N;
    REP(i, 3)
    {
        REP(j, 3)
        cin >> A[i][j];
    }
    cin >> N;
    int B[N];
    REP(k, N)
    {
        cin >> B[k];
        REP(i, 3)
        {
            REP(j, 3)
            {
                if (B[k] == A[i][j])
                    A[i][j] = 0;
            }
        }
    }

    REP(i, 3)
    {
        if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    REP(j, 3)
    {
        if (A[0][j] == 0 && A[1][j] == 0 && A[2][j] == 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }

    if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

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


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	struct Point {
		public int x;
		public int y;
		public Point(int b, int c) {
			x = b;
			y = c;
		}
	}

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res="";
		//int res = 0; ;
		//int t = int.Parse(Console.ReadLine());
		//string str = Console.ReadLine();
		///int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = int.Parse(Console.ReadLine());

		//int num = vals[0];

		int[] vals = parseAry(Console.ReadLine().Split(cs));

		int[] chil = parseAry(Console.ReadLine().Split(cs));
		int res=0;

		Array.Sort(chil);
		for ( int i = 0; i < vals[0];i++ ){
			if ( vals[1] >= chil[i] ) { vals[1] -= chil[i]; res++; }
		}
		if (res==vals[0] && vals[1] > 0 ) { res--; }
		if ( res < 0 ) { res = 0; }
			Console.WriteLine(res);

		return;
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 11220
#define DAY 365
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    int c[4] = {0};
    for (int i = 0; i < n;i++){
        string s;
        cin >> s;
        if(s == "AC")
            c[0]++;
        else if(s == "WA")
            c[1]++;
        else if(s == "TLE"){
            c[2]++;
        }else{
            c[3]++;
        }
    }
    cout << "AC x " << c[0] << endl;
    ;
    cout << "WA x " << c[1] << endl;
    cout << "TLE x " << c[2] << endl;
    cout << "RE x " << c[3] << endl;
}

Measured memory_bytes: 3628
### subroutines

def dist(sp0, sp1)
  dx = sp1[0] - sp0[0]
  dy = sp1[1] - sp0[1]
  dz = sp1[2] - sp0[2]
  rr = sp1[3] + sp0[3]
  d = Math.sqrt(dx * dx + dy * dy + dz * dz) - rr
  (d < 0.0) ? 0.0 : d
end

def root(i)
  ri = i
  while ri != $uft[ri]
    ri = $uft[ri]
  end
  while ri != $uft[i]
    i0 = $uft[i]
    $uft[i] = ri
    i = i0
  end
  ri
end

def union(i, j)
  i = root(i)
  j = root(j)
  $uft[j] = i
end

### main

loop do
  n = gets.to_i
  break if n == 0

  sps = n.times.map{gets.split.map(&:to_f)}

  dists = []
  $uft = (0...n).to_a

  for i in (0...n)
    spi = sps[i]
    for j in ((i + 1)...n)
      spj = sps[j]
      d = dist(spi, spj)
      if d == 0.0
        union(i, j)
      else
        dists << [d, i, j]
      end
    end
  end

  dists.sort!
  #p $uft
  #p dists

  sumd = 0.0

  for dist in dists
    d, i, j = dist
    if root(i) != root(j)
      sumd += d
      union(i, j)
    end
  end

  puts "%.3f" % sumd
end

Measured memory_bytes: 6276
#include <iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<cmath>
#include<iomanip>
using namespace std;

const double PI  =3.141592653589793238463;
#define pb push_back
#define pf push_front
typedef unsigned long long ull;
typedef long long ll;

typedef vector<int> vi;
typedef pair<int,int> pi;
//2 7 3 4 9


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

int n;cin>>n;

int ans=n%1000;
if(ans==0){
    cout<<ans;
    return 0;
}
ans=1000-ans;
cout<<ans;
    return 0;
}


Measured memory_bytes: 3648
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Debug.Trace

main = do
  [x,y,z] <- map read . words <$> getLine :: IO [Int]
  putStr $ show z ++  " "
  putStr $ show x ++  " "
  putStrLn $ show y 


Measured memory_bytes: 508
import heapq
readints = lambda: map(int, raw_input().split())

def solve(N, M, A):
    pq = [-x for x in A]
    heapq.heapify(pq)
 
    for _ in xrange(M):
        x = -heapq.heappop(pq)
        x /= 2
        heapq.heappush(pq, -x)
    return -sum(pq)

N, M = readints()
print solve(N, M, readints())


Measured memory_bytes: 42996
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
const int mod = 998244353;

ll mpow(ll x, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n /= 2;
  }
  return res;
}

ll inv(ll x) {
  return mpow(x, mod - 2);
}

vl fac(1000000, 1);
vl invfac(fac.size(), 1);

ll bin(int a, int n) {
  return fac[n] * invfac[a] % mod * invfac[n-a] % mod;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  for (int i = 2; i < fac.size(); ++i) {
    fac[i] = fac[i-1] * i % mod;
    invfac[i] = inv(fac[i]);
  }
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll d = __gcd(a, b);
  if (k % d) {
    cout << 0 << endl;
    return 0;
  }
  k /= d;
  a /= d;
  b /= d;
  ll res = 0;
  for (ll x = 0; x <= n && x * a <= k; ++x) {
    ll rem = k - x * a;
    if (rem % b) continue;
    ll y = rem / b;
    if (y > n) continue;
    res = (res + bin(x, n) * bin(y, n)) % mod;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 15872
class Resolver 
  attr_reader :array
  
  def initialize(array)
    @array = array.sort
  end

  def execute
    calc_score_with_same_hash(array, extract_same_hash).to_s
  end

  private

  # 同一の値のハッシュを取り出す
  def extract_same_hash
    n = array.size
    i = 0
    same_hash = {}
    while( i < n )
      same_count = 1
      while( array[i] == array[i+1] )
        same_count += 1
        i += 1
      end
      same_hash.merge!({array[i] => same_count})
      i += 1
    end
    same_hash
  end

  # スコア計算する
  # 2連番の場合(n1, n2)、same_hash[n1] + same_hash[n2]
  # 1つ飛ばしの場合(n1, n3)、same_hash[n1] + same_hash[n2]
  # 3連番の場合(n1, n2, n3)、same_hash[n1] + same_hash[n2] same_hash[n3]
  def calc_score_with_same_hash(array, same_hash)
    # 同じ値の最大値でスコアを初期化する
    score = same_hash.reduce{|a, b| a[1] > b[1] ? a : b}[1]
    array.uniq!
    n = array.size
    i = 0
    while( i < n )
      # 2連番パターン
      if( array[i] + 1 == array[i+1] )
        tmp_score = same_hash[array[i]] + same_hash[array[i+1]]
        score = tmp_score if tmp_score > score
      end

      # 1つ飛ばしパターン
      if( array[i] + 2 == array[i+1] )
        tmp_score = same_hash[array[i]] + same_hash[array[i+1]]
        score = tmp_score if tmp_score > score
      end

      # 3連番パターン
      if( array[i] + 1 == array[i+1] && array[i] + 2 == array[i+2] )
        tmp_score = same_hash[array[i]] + same_hash[array[i+1]] + same_hash[array[i+2]]
        score = tmp_score if tmp_score > score
      end

      i += 1
    end

    score
  end

end

gets
array = gets.split(" ").map{|i| i.to_i}

print(Resolver.new(array).execute + "\n")

Measured memory_bytes: 27256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  for (int i = 0; i < 5; ++i)
  {
    int j;
    cin>>j;
    if(j==0) cout<<i+1;
  }
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(void) {
int S[100][2];
int n,i,cnt;
cnt=0;
    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d %d", &S[i][0], &S[i][1]);

    for(i=0; i<n; i++){
        if(S[i][0]==S[i][1]) cnt++; 
        else                 cnt=0;
        if(cnt==3)          break;
    }
    if(cnt==3) printf("Yes");
    else       printf("No");    
    return 0;
}

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

int main() {
  char s[1000];
  int w, i = 0;
  std::cin >> s;
  std::cin >> w;
  if(w == 1){
    std::cout << s << '\n';
    return 0;
  }

  char ans[1000];
  while (w*i <= strlen(s)) {
    ans[i] = s[w*i];
    i++;
  }
  printf("%s", ans);
  return 0;
}

Measured memory_bytes: 256
import numpy as np

N, M = map(int, input().split())
if M == 0:
  print(0,0)
  exit()

P = []
S = []
for _ in range(M):
  x, y = input().split()
  P.append(int(x))
  S.append(y)

AC = [0] * (N+1)
WA = [0] * (N+1)
block = [0] * (N+1)

for p, s in zip(P, S):
  if s == 'AC':
    AC[p] = 1
    block[p] = 1
  if s == 'WA':
    if block[p] == 0:
      WA[p] += 1

print(sum(AC), sum(np.array(WA) * np.array(AC)))


Measured memory_bytes: 27160
from math import ceil, floor
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = 10**9
m = (l+r)//2+1
for i in range(100):
    # print(l,m,r)
    cnt = 0
    for j in a:
        cnt += (ceil(j/m)-1)
    # print(cnt)
    # print(l,m,r,cnt)
    if cnt <= k:
        r = m
        m = ceil((l+r)/2)
    else:
        l = m
        m = ceil((l+r)/2)
print(m)


Measured memory_bytes: 93720
extern crate core;

use std::io::Read;
use core::cmp::min;

fn main() {
    let n: u32 = input();
    let a: u32 = input();
    let b: u32 = input();

    let ans = min(n * a, b);
    println!("{:?}", ans);
}

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  ll n,k;
  cin >> n >> k;
  ll ans = min(n,abs((n%k)-k));
  ans = min(ans,abs(n-k));
  if(n%k == 0) ans = 0;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

DP = [[0] * (S + 1) for i in range(N + 1)]
DP[0][0] = 1
for i in range(N):
  for j in range(S + 1):
    if j >= A[i]:
      DP[i + 1][j] = (DP[i][j] * 2 + DP[i][j - A[i]]) % MOD
    else:
      DP[i + 1][j] = (DP[i][j] * 2) % MOD

print(DP[-1][-1] % MOD)






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


int main() {
    string s;
    cin >> s;
    bool bad = false;
    if (s[0] == s[1]) bad = true;
    if (s[1] == s[2]) bad = true;
    if (s[2] == s[3]) bad = true;
    if (bad) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main(){

    int X,ans=0;
    cin >> X;

    while(X>=500){
        X-=500;
        ans+=1000;
    }

    while(X>=5){
        X-=5;
        ans+=5;
    }

    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int ok(int a, int b, int c) {
	return a == 5 && b == 7 && c == 5;
}

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

	scanf("%d%d%d", &a, &b, &c);
	printf("%s\n", ok(a, b, c) || ok(a, c, b) || ok(b, a, c) || ok(b, c, a) || ok(c, a, b) || ok(c, b, a) ? "YES" : "NO");
	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<ll> vec(n+2,0);
  for(int i=n-1;i>=0;--i) {
    if( s[i] == 'W' ) ++vec[i];
    vec[i] += vec[i+1];
  }
  ll ans = 0;
  rep(i,n) if( s[i] == 'B' ) ans += vec[i];
  cout << ans << endl;
  compute();
  return 0;
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
//using fixed so that output doesnt comes like 1e9 type
#define pr(x)  cout<<fixed<<setprecision(10)<<x<<endl;
using namespace std;

double n;
double dp[301][301][301];

double solve(int x,int y,int z){
   if(x<0 || y<0 || z<0)
   return 0;
   
   if(x==0 && y==0 && z==0)
   return 0;
   
   if(dp[x][y][z]> -0.9)
   return dp[x][y][z];
   
   double exp = n+ x*(solve(x-1,y,z)) + y*(solve(x+1,y-1,z)) + z*(solve(x,y+1,z-1));
   
   return dp[x][y][z]=exp/(x+y+z);	
}

int main(){
	cin>>n;
	int ones=0,two=0,three=0;
	for(int i=1;i<=n;i++){
		int m;
		cin>>m;
		if(m==1)
		ones++;
		else
		if(m==2)
		two++;
		else
		three++;
	}
	
	memset(dp,-1,sizeof(dp));
	pr(solve(ones,two,three));
}

Measured memory_bytes: 213376
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p,f,a;
  while(1){
    cin >> n >> p;
    a = p;
    if(n==0 && p==0) break;
    int set[50]={};
    int i=0;
    while(1){
      if(i==n) i = 0;
      if(p>0){
        set[i]++;
	p--;
      }
      else{
	if(set[i]!=0){
	p=p+set[i];
	set[i]=0;
	}
      }
      //for(int j=0; j<n; j++) cout << set[j] << " ";
      //cout << endl;
      //cout << p << endl;
      if(set[i]==a){
	f = i;
	break;
      }
      i++;
    }
    cout << f << endl;
  }
  return 0;
}


Measured memory_bytes: 3068
#include <iostream>
int main() {
    int h,w;
    while (scanf("%d %d", &h, &w)) {
        if (h == 0 && w == 0) break;
        for (int i = 0; i++ < h;) {
            for (int j = 0; j++ < w;) printf("%c", '#');
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <string> 
#define LEN 120
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K;
    int people[LEN] = {0};
    for(int i = 0; i < K; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            people[a - 1]++;
        }
    }
    
    int num = 0;
    for(int i = 0; i < N; i++){
        if(people[i] == 0){
            
            num++;
        }
    }
    cout << num << endl;
}


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

int main() {
  vector<vector<int>> bingo(3, vector<int>(3));
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> bingo[i][j];
    }
  }
  int n,m;
  cin >> n;
  for(int k = 0; k < n; k++){
    cin >> m;
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        if(m == bingo[i][j]){
          bingo[i][j] = 1000;
        }
      }
    }
  }
  int cnt;
  for(int i = 0; i < 3; i++){
    cnt = 0;
    for(int j = 0; j < 3; j++){
      if(bingo[i][j] == 1000){
        cnt++;
      }
    }
    if(cnt == 3){
      cout << "Yes";
      return 0;
    }
  }
  for(int i = 0; i < 3; i++){
    cnt = 0;
    for(int j = 0; j < 3; j++){
      if(bingo[j][i] == 1000){
        cnt++;
      }
    }
    if(cnt == 3){
      cout << "Yes";
      return 0;
    }
  }
  cnt = 0;
  for(int i = 0; i < 3; i++){
    if(bingo[i][i] == 1000){
      cnt++;
    }
  }
  if(cnt == 3){
    cout << "Yes" << endl;
    return 0;
  }
  cnt = 0;
  for(int i = 0; i < 3; i++){
    if(bingo[i][2-i] == 1000){
      cnt++;
    }
  }
  if(cnt == 3){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>?): Unit {
    while(true){
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        val weights = readLine()!!.trim().split(' ').map(String::toInt).toIntArray()
        println(solve(weights))
    }
}
fun solve(weights: IntArray): Int {
    val memo = Array(weights.size){i -> IntArray(weights.size - i){-1}}
    fun count(from: Int, until: Int): Int {
        if (until - from <= 1) return 0
        if (memo[from][until - from - 1] == -1) {
            memo[from][until - from - 1] = Math.max(count(from + 1, until), (from + 1 until until).filter{mid -> Math.abs(weights[from] - weights[mid]) <= 1 && count(from + 1, mid) == mid - from - 1}.map{mid -> mid - from + 1 + count(mid + 1, until)}.max() ?: 0)
        }
        return memo[from][until - from - 1]
    }
    return count(0, weights.size)
}


Measured memory_bytes: 435832
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define st first
#define nd second

using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#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__) << "] "
 
#define shandom_ruffle random_shuffle
 
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

const int kAlpha = 26;
const int kMaxSize = 2e6;

struct Node {
	int children[kAlpha];
	bool is_end;
};
int num_nodes = 1;

Node nodes[kMaxSize];
int cnt_alpha[kAlpha];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);

	int n;
	cin >> n;
	vector<string> ss(n);
	for (auto &x : ss) { cin >> x; }
	sort(ALL(ss), [&](const string &lhs, const string &rhs) {
		return SZ(lhs) < SZ(rhs);
	});

	ll ans = 0;

	for (string str : ss) {
		for (int i = 0; i < kAlpha; ++i) {
			cnt_alpha[i] = 0;
		}
		for (char ch : str) {
			++cnt_alpha[ch - 'a'];
		}

		const int len = SZ(str);
		int curv = 0;
		for (int i = len - 1; i >= 0; --i) {
			const char ch = str[i];
			const int chidx = ch - 'a';
			for (int other = 0; other < kAlpha; ++other) {
				if (!cnt_alpha[other]) { continue; }
				const int s = nodes[curv].children[other];
				if (s && nodes[s].is_end) {
					++ans;
				}
			}
			--cnt_alpha[chidx];
			
			if (!nodes[curv].children[chidx]) {
				break;
			} else {
				curv = nodes[curv].children[chidx];
			}
		}

		curv = 0;
		for (int i = len - 1; i >= 0; --i) {
			const char ch = str[i];
			const int chidx = ch - 'a';
			int &s = nodes[curv].children[chidx];
			if (!s) {
				s = num_nodes++;
			}
			curv = s;
		}
		nodes[curv].is_end = true;
	}

	cout << ans << "\n";
}


Measured memory_bytes: 109932
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<map>
#define N 200005
using namespace std;
///map<int,int>ma;
int ma[1<<26];
int i,j,k,l,s,n,m,f[N];
char c[N];
inline int work(int x) {
    if (!x) return 0;
    int s=l+1;
    if (ma[x]) s=f[ma[x]];
    for (int i=0;i<26;i++) if (ma[x^(1<<i)]) s=min(s,f[ma[x^(1<<i)]]);
    else if (x==(1<<i)) return 0;
    return s;
}
int main() {
    scanf("%s",c+1);
    l=strlen(c+1);
    s=0;
    for (i=1;i<=l;i++) {
        s^=(1<<(c[i]-97));
        f[i]=work(s)+1;
        if (!ma[s]&&s) ma[s]=i;
        else if (ma[s]&&f[ma[s]]>f[i]) ma[s]=i;
    }
    printf("%d\n",f[l]);
}


Measured memory_bytes: 262912
N = int(input())
S = input()

ans = N

d = [0] * N

d[0] = S[1:].count("E")

for i in range(1, N):
  d[i] = d[i-1]
  if S[i-1] == "W":
    d[i] += 1
  if S[i] == "E":
    d[i] -= 1

print(min(d))

Measured memory_bytes: 15436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main(){
  int n, k;
  cin >> n >> k;
  int h[n];
  int dp[n] = {};
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < n; i++) {
    dp[i] = INF;
  }
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k && i + j < n; j++) {
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1152