akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(void) {
  char s[11];
  int i, n, num, count = 0, flag = 0;

  scanf("%s", s);

  n = strlen(s);

  if (s[0] != 65) {
    flag = 1;
  }

  for (i = 2; i < n-1; i++) {
    if (s[i] == 67) {
      count++;
      num = i;
    }
  }

  if (count != 1) {
    flag = 1;
  }

  for (i = 1; i < num; i++) {
    if (s[i] > 64 && s[i] < 91) {
      flag = 1;
    }
  }
  for (i = num+1; i < n; i++) {
    if (s[i] > 64 && s[i] < 91) {
      flag = 1;
    }
  }

  if (flag == 0) {
    printf("AC\n");
  }else {
    printf("WA\n");
  }

  return 0;
}

Measured memory_bytes: 128
def main():
    N = int(input())
    b = list(map(int, input().split()))
    i = 1

    for j in range(N):
        if b[j] == i:
            i += 1
    
    if i == 1:
        print(-1)
    else:
        print(N - i + 1)

if __name__ == '__main__':
    main()

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

bool has3(int x) {
    while(x) {
        if (x%10 == 3)  return true;
        x /= 10;
    }
return false;
}

void call(int n){
    for (int x = 1; x <= n; x++) {
        if (x % 3 == 0 || has3(x)) {
            cout << " " << x;
        }
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    call(n);
    return 0;
}


Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/
/******** User-defined Function *******/

/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<ll> a(n), b(n), c(n);

    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];

    sort(all(a));
    sort(all(c));

    ll ans = 0;

    rep(i,n){
        int val_b = b[i];

        int ng = -1;
        int ok = n;

        while(abs(ok - ng)>1){
            int mid = (ok+ng)/2;

            auto f = [&](int x){
                if(a[x]>=val_b) return true;
                else return false;
            };
            if(f(mid)) ok = mid;
            else ng = mid;
        }

        //cout << "a: ng " << ng << " ok " << ok << endl; 

        ll num_a = ng + 1;

        ng = -1;
        ok = n;

        while(abs(ok - ng)>1){
            int mid = (ok+ng)/2;

            auto g = [&](int x){
                if(c[x]>val_b) return true;
                else return false;
            };
            if(g(mid)) ok = mid;
            else ng = mid;
        }

        //cout << "c: ng " << ng << " ok " << ok << endl; 

        ll num_c = n - ok;

        ans += (num_a * num_c);
        //cout << "ans " << ans << endl;
    }

    cout << ans << endl;

}
/********  Main() Ends Here *************/


Measured memory_bytes: 5556
// Copyright 2017 wu_qing
#include <stdint.h>
#include <cstdio>
int64_t n, a, b;
int main() {
    scanf("%lld%lld%lld", &n, &a, &b);
    if ((n == 1 && a != b) || a > b)
        printf("0\n");
    else
        printf("%lld\n", (n - 2) * (b - a) + 1);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int a, b, d;

bool cmp(int ax, int ay, int bx, int by){
  if(ax+ay != bx+by) return ax+ay < bx+by;
  return a*ax+b*ay < a*bx+b*by;
}

int main(){
  while(scanf("%d%d%d", &a, &b, &d) && a+b+d){
    int resx = (INF)/2, resy = (INF)/2, r, l, y;
    rep(x, 100000){
      r = a*x + d;
      //      printf("%d\n", r);
      if(!(r%b)){
	y = r/b;
	if(cmp(x,y,resx,resy)) resx = x, resy = y;
      }
      l = a*x - d;
      if(l >= 0 && !(l%b)){
	y = l/b;
	if(cmp(x,y,resx,resy)) resx = x, resy = y;
      }
      l = d - a*x;
      if(l >= 0 && !(l%b)){
	y = l/b;
	if(cmp(x,y,resx,resy)) resx = x, resy = y;
      }
    }

    printf("%d %d\n", resx, resy);
  }
  return 0;
}

Measured memory_bytes: 1188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        static final long mod = 1000000007L;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            long k = Long.parseLong(in.next());
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            long ans = 0;
            for (int i = 0; i < n; i++) {
                long right = 0;
                long all = 0;
                for (int j = i; j < n; j++) {
                    if (a[i] > a[j]) right++;
                }
                for (int j = 0; j < n; j++) {
                    if (a[i] > a[j]) all++;
                }
                ans += right * k % mod;
                ans %= mod;
                ans += (k - 1) * k / 2 % mod * (all % mod);
                ans %= mod;

            }

            // 出力
            out.println(ans);

        }

    }
}



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

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

    long long int sum = 0;
    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }

    long long int div = n * (n+1) / 2;
    if(sum % div != 0){
        cout << "NO" << endl;
        return 0;
    }

    long long int times = sum / div;
    long long int count = 0;
    long long int memo = 0;

    for(int i=1; i<n; i++){
        long long int diff = (a[i-1] + times) - a[i];
        if(diff < 0 || diff % n != 0){
            cout << "NO" << endl;
            return 0;
        }
        count += diff / n;
        memo += (n+1 - i) * (diff / n);
    }
    if(count > times) cout << "NO" << endl;
    else if(memo + (times - count) != a[0]) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 4044
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args){
        
        int[][] A=new int[100][100];
        int[][] B=new int[100][100];
        long[][] C=new long[100][100];
        int[] a=new int[100];
        int[] b=new int[100];
        long c=0;
        
        Scanner scan=new Scanner(System.in);
        
        int n=scan.nextInt();
        int m=scan.nextInt();
        int l=scan.nextInt();
        
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                A[i][j]=scan.nextInt();
            }
        }        
        
        for(int i=0;i<m;i++){
            for(int j=0;j<l;j++){
                B[i][j]=scan.nextInt();
            }
        }
        
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                a[j]=A[i][j];
            }
            
            for(int j=0;j<l;j++){
                for(int k=0;k<m;k++){
                    b[k]=B[k][j];
                }
                c=0;
                for(int k=0;k<m;k++){
                    c+=a[k]*b[k];
                }
                C[i][j]=c;
            }
        }
        
        for(int i=0;i<n;i++){
            for(int j=0;j<l-1;j++){
                System.out.print(C[i][j]+" ");
            }
            System.out.print(C[i][l-1]+"\n");
        }
        
    }   
     
}

Measured memory_bytes: 52292
N=int(input())
alist=[0]+list(map(int,input().split()))
xlist=list(range(1,N+1))
#print(alist,xlist)

# Ford-Fulkerson algorithm
class FordFulkerson:
  def __init__(self, vlist):
    self.G = {}
    for v in vlist:
      self.G[v] = []

  def add_edge(self, fr, to, cap):
    forward = [to, cap, None]
    forward[2] = backward = [fr, 0, forward]
    self.G[fr].append(forward)
    self.G[to].append(backward)

  def add_multi_edge(self, v1, v2, cap1, cap2):
    edge1 = [v2, cap1, None]
    edge1[2] = edge2 = [v1, cap2, edge1]
    self.G[v1].append(edge1)
    self.G[v2].append(edge2)

  def dfs(self, v, t, f):
    if v == t:
      return f
    used = self.used
    used[v] = True
    for e in self.G[v]:
      w, cap, rev = e
      if cap and not used[w]:
        d = self.dfs(w, t, min(f, cap))
        if d:
          e[1] -= d
          rev[1] += d
          return d
    return 0

  def flow(self, s, t):
    flow = 0
    f = INF = 10**9 + 7
    while f:
      self.used = {}
      for v in self.G:
        self.used[v]=False
      f = self.dfs(s, t, INF)
      flow += f
    return flow
  
asum_pos=0  
## 点数N、辺数M、始点s、終点t
ff = FordFulkerson(range(N+2))
for i in range(1,N+1):
  a=alist[i]
  if a<=0:
    ff.add_edge(0,i,-a)
  else:
    ff.add_edge(i,N+1,a)
    asum_pos+=a

for i in range(1,N+1):
  for j in range(2*i,N+1,i):
    ff.add_edge(i,j,float("inf"))

penalty=ff.flow(0,N+1)
print(asum_pos-penalty)

Measured memory_bytes: 3192
#include <stdio.h>
 
int main(){
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n], sum=0;
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
    sum+=a[i];
  }
  double t=(double) sum/(4*m);
  int count=0;
  for(int i=0; i<n; i++)
  if((double) a[i]>=t)count++;
  if(count>=m)printf("Yes\n");
  else printf("No\n");
}

Measured memory_bytes: 1664
<?php
    $line = trim(fgets(STDIN));
    $arr = explode(' ', $line);
    if($arr[0]+$arr[1]+$arr[2] >= 22){
        echo "bust\n";
    } elseif ($arr[0]+$arr[1]+$arr[2] <= 21){
        echo "win\n";
    }

Measured memory_bytes: 4604
#include<stdio.h>
int main(void){
  int a, b, c, d, i, count=0;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  for(i=0;i<=100;i++)
    if((a<=i && i<=b) && (c<=i && i<=d))
      count++;
  count = (count>0) ? count-1 : count; 
  printf("%d",count);
  return 0;
}


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

ll l;

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cnt, dist;
        bool operator>(const state s) const { return ((cnt > s.cnt) || (cnt==s.cnt && dist>s.dist)); }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<pair<ll,ll>> shortest_path(long long S) {
        vector<pair<ll,ll>> dp(E.size(), pair<ll,ll>(INF,INF));
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0,0 });
        while(!q.empty()) {
            long long v = q.top().v, cnt = q.top().cnt,dist = q.top().dist;
            q.pop();
            if(dp[v].first < cnt || (dp[v].first==cnt && dp[v].second <= dist)) continue;
            dp[v] = make_pair(cnt,dist);
            for(int i=0;i < E[v].size() ; i++) {
                long long nv = E[v][i].v, ncnt = cnt;
                ll nd = dist+E[v][i].dist;
                if(nd>l){
                    nd = E[v][i].dist;
                    ncnt++;
                }
                if(dp[nv].first > ncnt || (dp[nv].first==ncnt && dp[nv].second > nd)) q.push((state) { nv, ncnt, nd });
            }
        }
        return dp;
    }
};




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
   
    ll n,m;
    cin>>n>>m>>l;
    Dijkstra d(n);
    for(int i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        if(c>l) continue;
        d.add_undirected_edge(a,b,c);
    }
    vector<vector<pair<ll,ll>>> v(n);
    for(int i=0;i<n;i++){
        v[i] = d.shortest_path(i);
    }
    int q;
    cin>>q;
    while(q--){
        int s,t;
        cin>>s>>t;
        s--,t--;
        if(v[s][t].first>=n+1){
            cout << -1 << "\n";
            continue;
        }
        cout << v[s][t].first << "\n";

    }
}

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

using ll = long long;



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	
	vector<double> coins(n);
	for(double &i:coins)cin>>i;
	
	vector<double> dp(n+1);
	//dp[i] - the number of heads i
	dp[0]=1;
	
	for(double coin = 0; coin < n; ++coin){
		for(int i = coin + 1 ; i >= 0 ; --i ){
			dp[i]=  (i==0?0:dp[i-1]*coins[coin]) + dp[i]*(1-coins[coin]);
		}
	}
	double ans=0;
	for(int i = ceil(1.0*n/2) ; i <= n ; ++i ){
		ans+=dp[i];
	}
	cout<<fixed;
	cout<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 3892
#C
N, K = map(int, input().split())
A = list(map(int, input().split()))
p=[]
for i in range(N-K):
    if A[i+K]>A[i]:
        p.append(1)
    else:
        p.append(0)

for j in range(len(p)):
    if p[j]==1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 31352
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int a, b;
  cin >> a >> b;
  cout << (a <= b ? a : a - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func IsPalindromeNumber(n int) bool {
	i := n / 10000
	j := n % 10000 / 1000
	k := n % 100 / 10
	l := n % 10
	if i == l && j == k {
		return true
	}
	return false
}

func main() {
	a, err := strconv.Atoi(input())
	if err != nil {
		log.Fatalln(err)
	}

	b, err := strconv.Atoi(input())
	if err != nil {
		log.Fatalln(err)
	}

	count := 0
	for i := a; i <= b; i++ {
		if IsPalindromeNumber(i) {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Collections;
import java.util.ArrayList;

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

    static class StringsofImpurity {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String str = in.next();
            char[] s = str.toCharArray();
            char[] t = in.next().toCharArray();

            Map<Character, List<Integer>> map = new HashMap<>();
            for (int i = 0; i < s.length; i++) {
                List<Integer> list = map.getOrDefault(s[i], new ArrayList<>());
                list.add(i + 1);
                map.put(s[i], list);
            }

            for (char c : t) {
                if (!map.containsKey(c)) {
                    out.print(-1);
                    return;
                }
            }

            int pre = map.get(t[0]).get(0);
            long result = pre;

            for (int i = 1; i < t.length; i++) {
                List<Integer> pos = map.get(t[i]);
                int position = Collections.binarySearch(pos, pre + 1);
                if (position < 0) {
                    position = ~position;
                }
                int now;
                if (position == pos.size()) {
                    result += s.length;
                    now = pos.get(0);

                } else {
                    now = pos.get(position);
                }
                result += (now - pre);
                pre = now;
            }

            out.print(result);

        }

    }
}



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

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

int main(){
  int N;
  cin >> N;
  const long long INF = 1LL << 60;
  
  long long DP[100010];


  vector<int> h(N);
  for(int j=0;j<N;++j){
    cin >> h[j];
  }
  
  for(int i=0;i<100010;++i){
    DP[i] = INF;
  }
  DP[0] = 0;

  for(int k=0;k<N;++k){
    chmin(DP[k],DP[k-1] + abs(h[k]-h[k-1]));
    if(k > 1){
      chmin(DP[k],DP[k-2] + abs(h[k]-h[k-2]));
    }
  }
  cout << DP[N-1] << endl;
}

Measured memory_bytes: 1408
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt[28] = {};
    for(int i=0;i<4;++i)
    {
        cnt[s[i] - 'A']++;
    }

    bool ret = true;
    int twice = 0;
    for(int i=0;i<26;++i) {
        if (cnt[i] != 0 && cnt[i] != 2)
        {
            ret = false;
        } 
        else if(cnt[i] == 2)
        {
            twice++;
        }
    }

    if (twice == 2 && ret)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define ll long long
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(){cout << -1 << '\n';}
const ll INF = 1e18;

ll Roundup_div(ll x, ll y) {return (x+(y-1))/y;}

map<ll,ll> mp;
ll n, a, b, c, d;

ll dfs(ll now){
    if(mp[now] or !now) return mp[now];
    ll result = 0;
    ll res = (__builtin_mul_overflow(now,d, &result) ? INF : now * d);
    chmin(res, dfs(now/2) + now%2 * d + a );
    chmin(res, dfs(Roundup_div(now,2)) + now%2 * d + a);
    chmin(res, dfs(now/3) + now%3 * d + b);
    chmin(res, dfs(Roundup_div(now,3)) + (3 -now%3) * d + b);
    chmin(res, dfs(now/5) + now%5 * d + c);
    chmin(res, dfs(Roundup_div(now,5)) + (5 -now%5) * d + c);
    return mp[now] = res;
}

void solve(){
    cin >> n >> a >> b >> c >> d;
    mp.clear();
    mp[1] = d;
    cout << dfs(n) << '\n';
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t; cin >> t;
    while(t--) solve();
}

Measured memory_bytes: 4368
import itertools
N = int(input())
S = [3,5,7,11,13]

if N >= 189:
  ans = 2
elif N>= 135:
  ans = 1
else:
  ans = 0
A = list(itertools.combinations(S,3))
#print(A)
for x in A:
  a,b,c = x
  if a*b*c <= N:
    ans += 1
print(ans)

Measured memory_bytes: 61936
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  string s;
  string t = "";
  cin >> s;
  ll ans = 0, cnt = 0;
  rep(i, s.length() - 1) {
    if (s[i] == 'B' && s[i + 1] == 'C') {
      t += 'D';
      ++i;
    } else {
      t += s[i];
    }
  }
  rep(i, t.length()) {
    if (t[i] == 'A')
      cnt++;
    else if (t[i] == 'D')
      ans += cnt;
    else
      cnt = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 776
import math

n = int(input())


def cho(i):
    return (i * (i - 1)) // 2


d = {}
for i in range(n):
    s = "".join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 0

_ans = 0
for k, v in d.items():
    if v == 0: continue
    _ans += cho(v + 1)

print(_ans)


Measured memory_bytes: 17848
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = a
ans = 0
for i in range(n):
    x = 0
    y = 0
    for j in range(i):
        if a[i] > a[j]:
            x += 1
    for j in range(n):
        if a[i] > b[j]:
            y += 1
    ans += y * ((1 + k) * k // 2) - x * k
    ans %= ((10 ** 9) + 7)
print(ans)

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

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

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

int n,t,s;
int *a, *b;

int **memo;


//dp(u, x) = ??????u???????????§?¬?????????????a??§????????¨??????M????????§???
int dp(int u, int x){
	if(x==n) return 0;
	if(memo[u][x]>=0) return memo[u][x];

	int ans=dp(u, x+1);
	if(u<s){
		if(u+b[x]<=s){
			ans = max(ans, a[x]+dp(u+b[x], x+1));
		}else if(s + b[x]<=t){
			ans = max(ans, a[x]+dp(s+b[x], x+1));
		}
	}else{
		if(u+b[x]<=t){
			ans = max(ans, a[x]+dp(u+b[x], x+1));
		}
	}
	return memo[u][x]=ans;
}

int main(){
	n = read<int>();
	t = read<int>();
	s = read<int>();
	a = new int[n];
	b = new int[n];
	memo = new int*[t+1];
	rep(i, t+1) memo[i]=new int[n];
	rep(i, t+1) rep(j, n) memo[i][j]=-1;
	rep(i, n){
		a[i] = read<int>();
		b[i] = read<int>();
	}
	
	cout << dp(0, 0) << endl;
}

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

const long long int INF = 1e12;

int main() {
  int N, M, L;
  cin >> N >> M >> L;
  vector<vector<long long int>> edge(N, vector<long long int>(N, INF));
  for (int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    edge[A][B] = C;
    edge[B][A] = C;
  }
  for (int i = 0; i < N; i++) {
    edge[i][i] = 0;
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
      }
    }
  }

  vector<vector<long long int>> G(N, vector<long long int>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (edge[i][j] <= L) {
        G[i][j] = 1;
      } else {
        G[i][j] = INF;
      }
    }
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }

  int Q;
  cin >> Q;
  for (int iter = 0; iter < Q; iter++) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    if (G[s][t] < INF) {
      cout << G[s][t] - 1 << endl;
    } else {
      cout << -1 << endl;
    }
  }
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

#define mkf(n,mod)  int *fact=(int *)malloc((n+1)*sizeof(int)); mfac((n),fact,(mod)) //enables to let x!=fact[x]
#define mkfiv(n,mod)  int *finv=(int *)malloc((n+1)*sizeof(int)); mfiv((n),finv,fact[n],(mod)) // 1/x! = finv[x]

int mmul(int p,int q,int m){ //O(1)?
    ll lp=p,lq=q; return ((lp%m)*(lq%m))%m;}

int mpow(int x,int n,int m){ //O(logN)
    ll res=x,ans=1;
    while(n!=0){
        if(n%2==0){ res = mmul(res,res,m);n>>=1;
        }else{      ans = mmul(ans,res,m);--n;}}return ans;}

int mdiv(int p,int q,int m){ //O(logMOD)
    return mmul(p,mpow(q,m-2,m),m);}

void mfac(int x,int *f,int m){//O(n)
    *f=1; for(int i=1;i<=x;++i)f[i]=mmul(f[i-1],i,m);}

void mfiv(int x,int *f,int fx,int m){//O(n)
    f[x] = mdiv(1,fx,m); 
    for(int i=x;i>0;--i)f[i-1]=mmul(f[i],i,m);}

int mncr(int n,int r,int m,int* fac,int* fiv){//O(1)
    return mmul(fac[n],mmul(fiv[r],fiv[n-r],m),m);}


int main(){
    bool flag=false;
    ll ans=0,sum=0;

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

    mkf(n+1,MOD);
    mkfiv(n+1,MOD);

    int st=n-1;

    for (int i = st; i >= max(0,n-1-k); --i){
        int a = mncr(n-1,i,MOD,fact,finv);
        int b = mncr(n,i+1,MOD,fact,finv);
        ans = (ans+mmul(a,b,MOD))%MOD;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict
from collections import deque

N, M = map(int, input().split())

graph = defaultdict(list)
edges = []

# 無向グラフの表現
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    edges.append((a, b))

ans = 0
def dfs(graph, node_start, visited):
    global ans
    if sum(visited) == len(graph):
        ans += 1
        return
    for node_end in graph[node_start]:
        # 一回も訪れていない
        if not visited[node_end]:
            visited[node_end] = True
            dfs(graph, node_end, visited)
            visited[node_end] = False
    return

visited = [False] * N
visited[0] = True
dfs(graph, 0, visited)
print(ans)


Measured memory_bytes: 3316
N,M = map(int,input().split())
A = [[] for i in range(N+1)]

for i in range(M) :
    l,r,d = map(int,input().split())
    
    l -= 1
    r -= 1
    
    A[l].append([r,d])
    A[r].append([l,-d])

distance = ["#" for i in range(N)]

ans = "Yes"

flg = 0

for i in range(N) :
    if flg == 1 :
        break
    
    if distance[i] != "#" :
        continue
    
    distance[i] = 0
    stack = [i]
    
    while stack :
        v = stack.pop()
        
        for to,d in A[v] :
            if distance[to] == "#" :
                distance[to] = distance[v] + d
                stack.append(to)
            
            elif distance[to] != distance[v] + d :
                ans = "No"
                stack = []
                flg = 1
                break
                

print(ans)


Measured memory_bytes: 76932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

//#define DEBUG


int main(void)
{
  int N;
  cin >> N;
  vector<int> X(N);
  ll sumX=0; // 総和
  for(int i=0;i<N;i++)
  {
    cin >> X[i];
    sumX += X[i];
  }
  ll aveX; // 平均
  aveX = round((double)sumX/(double)N);
//  cout << aveX << endl;
   
  ll sum2jo=0;	// 差分の二乗の総和
  // 計算
  for(int i=0;i<N;i++)
  {
    sum2jo += pow( (X[i] - aveX), 2);
//    cout << i << "番目:" << sum2jo << endl;
  }
  cout << sum2jo;
  
  
  return 0;
} 

Measured memory_bytes: 256
void main()
{
    long r1, r2;
    rdVals(r1, r2);

    double r3 = (r1 * r2).to!double / (r1 + r2);

    writefln("%.15f", r3);
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

int main() {
    int w, h;
    std::cin >> w >> h;
    std::vector<int> cost(10, 0);
    std::vector<std::vector<int>> table(10, std::vector<int>(10, 0));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) std::cin >> table[i][j];
    }

    cost[1] = 0;
    for (int i = 0; i < 10; i++) {
        if (i == 1) continue;

        std::vector<bool> done(10, false);
        std::vector<int> g(10, 100100);
        g[i] = 0;

        while(true) {
            if (done[1]) break;

            int m = -1;
            for (int j = 0; j < 10; j++) {
                if (!done[j] && (m == -1 || g[j] < g[m])) m = j;
            }

            for (int j = 0; j < 10; j++) {
                if (!done[j]) g[j] = std::min(g[j], g[m] + table[m][j]);
            }

            done[m] = true;
        }

        cost[i] = g[1];
    }

    int tmp;
    long long ret = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> tmp;
            if (tmp == -1) continue;
            ret += cost[tmp];
        }
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int m,n,obj[200];
int dp[180000];
int p3[12];

int f(int mask){
	int& res = dp[mask];
	if(res!=-1)return res;
	res = INF;

	int d[12];
	rep(i,m)d[i] = mask/p3[i]%3;

	int hit = 0;
	rep(i,n){
		int ok = 1;
		rep(j,m)if(d[j]!=2 && d[j] != (obj[i]>>j&1)){
			ok = 0;
		}
		if(ok)hit++;
		if(hit>1)break;
	}

	if(hit <= 1)return res = 0;
	rep(i,m)if(d[i] == 2){
		res = min(res, 1 + max(f(mask - 2 * p3[i]), f(mask - 1 * p3[i])));
	}

	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	p3[0] = 1;
	rep(i,11)p3[i+1] = p3[i] * 3;
	while(cin>>m>>n && m){
		rep(i,n){
			string s;
			cin>>s;
			obj[i] = 0;
			rep(j,m)obj[i] |= (s[j] - '0')<<j;
		}
		memset(dp,-1,sizeof(dp));
		cout<<f(p3[m]-1)<<endl;
	}
}

Measured memory_bytes: 1924
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

int g=0, mx;

int gcd(int a, int b) {
	return b?gcd(b,a%b):a;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		mx = max(mx,a);
		g = gcd(g,a);

	}
	if(m%g == 0 && m <= mx) cout << "POSSIBLE\n";
	else cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int compare (const void *a, const void *b)
{
    if(*(intmax_t *)a - *(intmax_t *)b < 0)
        return 1;
    if(*(intmax_t *)a - *(intmax_t *)b > 0)
        return -1;
    return 0;
}

int main (void)
{
    intmax_t N, d[(int)1e5];
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &d[i]);
    }

    qsort(d, N, sizeof(intmax_t), compare);
    
    ans = d[N / 2 - 1] - d[N / 2];

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

    return 0;
}


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef vector<ll> Vl;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


ll n, cnt = 10, ans;

int main() {

	cin >> n;

	if (n % 2 == 0) {
		while (cnt <= n) {
			ans += n / cnt;
			cnt *= 5;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
acs = [0]*n
was = [0]*n
ac = 0
wa = 0
for i in range(m):
  p, s = input().split()
  p = int(p) - 1
  if s == "AC" and acs[p]==0:
    acs[p] += 1
    ac += 1
    wa += was[p]
  elif s == "WA":
    was[p] += 1
print(ac, wa)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
	long long int ans=0,n,m,i;
    cin>>n>>m;
    for(i=m;i<=n+1;i++)
    {
    	ans+=i*n-(i*(i-1)-1);
    	ans=ans%1000000007;
    }
    cout<<ans;
}


Measured memory_bytes: 3624
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := getInt(), getInt()

	if a <= 0 && b >= 0 {
		out("Zero")
		return
	}
	if a > 0 {
		out("Positive")
		return
	}

	cnt := b - a + 1

	if cnt%2 == 0 {
		out("Positive")
	} else {
		out("Negative")
	}
}


Measured memory_bytes: 1772
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
long long int a,b,c,k;
int main(){
  cin >> a >> b >> c >> k;
  if(a<b) swap(a,b);
  if(a<c) swap(a,c);
  cout << a*pow(2,k)+b+c <<endl;
  return 0;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define gg return puts("No"),0
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll sum,sa,sb;int a[N],b[N],n;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	fp(i,1,n)scanf("%d",&b[i]);
	fp(i,1,n)sum+=b[i]-a[i];
	if(sum<0)gg;
	fp(i,1,n)if(a[i]!=b[i]){
		if(b[i]<a[i])sb+=a[i]-b[i];
		else if((b[i]-a[i])&1^1)sa+=(b[i]-a[i])>>1;
		else ++sb,sa+=(b[i]-a[i]+1)>>1;
	}
	if(sum<max(sa,sb))gg;
	sa=sum-sa,sb=sum-sb;
	puts(((sa<<1)==sb)?"Yes":"No");
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <string>

using namespace std;

char s[3] = ".#";
char c[4];

int main() {
    int n, i, j;
    string s1 = "", s2 = "";
    
    scanf("%d", &n);
    
    while (1) {
        int f = 0;
        
        for (i = 0; i < 2 && f == 0; i++) {
            for (j = 0; j < 2 && f == 0; j++) {
                string ss1 = s1 + s[i];
                string ss2 = s2 + s[j];
                
                printf("%s\n", ss1.c_str());
                printf("%s\n", ss2.c_str());
                fflush(stdout);
                
                scanf("%s", c);
                
                if (c[0] == 'e') {
                    return 0;
                } else if (c[0] == 'T') {
                    f = 1;
                    
                    s1 = ss1;
                    s2 = ss2;
                }
            }
        }
        
        if (f == 0) break;
    }
    
    while (1) {
        int f = 0;
        
        for (i = 0; i < 2 && f == 0; i++) {
            for (j = 0; j < 2 && f == 0; j++) {
                string ss1 = s[i] + s1;
                string ss2 = s[j] + s2;
                
                printf("%s\n", ss1.c_str());
                printf("%s\n", ss2.c_str());
                fflush(stdout);
                
                scanf("%s", c);
                
                if (c[0] == 'e') {
                    return 0;
                } else if (c[0] == 'T') {
                    f = 1;
                    
                    s1 = ss1;
                    s2 = ss2;
                }
            }
        }
        
        if (f == 0) break;
    }
    
    return 0;
}


Measured memory_bytes: 724
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

typedef long long ll;

struct Op {
	ll b;
	ll c;
	
	bool operator>(const Op& other) const {
		return c > other.c;
	}
};

int main (int argc, char* argv[]) {
	int n, m;
	cin >> n >> m;

	priority_queue<ll, vector<ll>, greater<ll>> q;
	for (int i = 0; i < n; i++) {
		ll n;
		cin >> n;
		q.push(n);
	}

	vector<Op> ops(m);
	for (int i = 0; i < m; i++) {
		cin >> ops[i].b >> ops[i].c;
	}
	sort(ops.begin(), ops.end(), greater<Op>());

	for (const auto& op : ops) {
		bool noop = true;
		for (int i = 0; i < op.b && q.top() < op.c; i++) {
			noop = false;
			q.pop();
			q.push(op.c);
		}
		if (noop) break;
	}

	ll res = 0;
	while (!q.empty()) {
		res += q.top();
		q.pop();
	}
	cout << res << endl;
}


Measured memory_bytes: 2676
//#define _GLIBCXX_DEBUG
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef map<int, int> mii;
    typedef map<char,int> mci;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef vector<ll> vll;
    typedef vector<pair<int,int>> vii;
    typedef vector<char> vc;
    typedef vector<vc> vcc;
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    #define in insert
    #define sz(v) v.size()
    #define mina(a,b) (a)=min((a),(b));
    #define maxa(a,b) (a)=max((a),(b));
    const int INF = 1e9 + 5;
    
    void solve(){
        int n; cin>>n;
        vi v(n);
        for(int i = 0; i < n; i++){
            cin>>v[i];   
        }
        int sum=0;
        for(int i = 0; i < n; i++){
            int t; cin>>t;
            v[i]-=t;
            if(v[i]>0)  sum+=v[i];
        }
        cout<<sum;

    }
    int main(){
        int T=1;
        //cin>>T;
        for(int i = 0; i < T; i++) solve(); 
    }

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

int N;
string S[111];
int main(){
  while(cin >> N && N ){
    int l,r;
    l = r = 0;
    for(int i=0;i<N;i++){
      cin >> S[i];
    }
    int cnt = 0;
    for(int i=0;i<N;i++){
      if( l == r && l == 0 ){
	if( i < N -1 ){
	  if( (S[i] == "lu" && S[i+1] == "ru") || 
	      (S[i] == "ru" && S[i+1] == "lu") ){
	    cnt ++;
	  }	  
	}
      }
      if( l == r && l == 1 ){
	if( i < N - 1){
	  if( (S[i] == "ld" && S[i+1] == "rd") || 
	      (S[i] == "rd" && S[i+1] == "ld") ){
	    cnt ++;
	  }
	}
      }
      if( S[i] == "ld" ){
	l = 0;
      } else if( S[i] == "rd" ){
	r = 0;
      } else if( S[i] == "lu" ){
	l = 1;
      } else {
	r = 1;
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define N 500010
 
//FenwickTree↓
int dat[N];
void init(){
    rep(i,N)dat[i]=0;
}
void add(int i,int x){
    for(;i<N;i+=i&-i)dat[i]+=x;
}
int sum(int i){
    int res=0;
    for(;i>0;i-=i&-i)res+=dat[i];
    return res;
}
int rangesum(int l,int r){//[l,r]
    return sum(r)-sum(l-1);
}
//FenwickTree↑
 
int a[N];
vector<int> ql[N],qid[N];
int ans[N];
 
int n,q,c[N];
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>c[i];
    rep(i,q){
        int l,r;
        cin>>l>>r;
        ql[r].push_back(l);
        qid[r].push_back(i);
    }
    init();
    for(int i=1;i<=n;i++)a[i]=0;
    for(int i=1;i<=n;i++){
        if(a[c[i]]>0)add(a[c[i]],-1);
        add(i,+1);
        a[c[i]]=i;
        rep(j,ql[i].size()){
            ans[qid[i][j]]=rangesum(ql[i][j],i);
        }
    }
    rep(i,q)cout<<ans[i]<<"\n";
}

Measured memory_bytes: 53000
#include <stdio.h>
#include <stdlib.h>

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


int main() {
  int N,M,X,Y;
  scanf("%d %d %d %d",&N,&M,&X,&Y);
  int x[N+1],y[M+1];
  for (int i = 0; i < N; i++) {
    scanf("%d",&x[i]);
  }
  for (int i = 0; i < M; i++) {
    scanf("%d",&y[i]);
  }
  x[N] = X;
  y[M] = Y;
  qsort(x,N+1,sizeof(int),compare_int);
  qsort(y,M+1,sizeof(int),compare_int);
  int Z = x[N]+1;
  for (;;) {
    if (Z <= X) {
      Z++;
    }
    else break;
  }
  if (Z <= y[0]) printf("No War\n");
  else printf("War\n");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
    int d, n;
    cin >> d >> n;
    if (n == 100) {
        if (d == 0) cout << "101" << endl;
        else if (d == 1) cout << "10100" << endl;
        else if (d == 2) cout << "1010000" << endl;
    } else if (d == 0) {
        cout << n << endl;
    } else if (d == 1) {
        cout << n * 100 << endl;
    } else if (d == 2) {
        cout << n * 10000 << endl;
    }
    return 0;
}


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

class D
{
	static void Main() => Console.WriteLine(string.Join("\n", GetNumbers().Reverse().Take(int.Parse(Console.ReadLine()))));

	static IEnumerable<long> GetNumbers()
	{
		var q = Enumerable.Range(0, 13).SelectMany(d => Enumerable.Range(0, 1000).Select(i => i + new string('9', d))).Select(long.Parse).Distinct().OrderBy(x => -x);
		double m = 1000000000000000, v;

		foreach (var x in q)
		{
			if ((v = (double)x / $"{x}".Sum(c => c - '0')) <= m)
			{
				m = v;
				yield return x;
			}
		}
	}
}


Measured memory_bytes: 16992
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll X,Y;
  cin >> X >> Y;
  int ans = 0;
  while (X <= Y) {
    X *= 2;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628