akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
const int mod = 1000000007;
int dp[2][100005];
int main(){
    string L;
    cin >> L;
    int n = L.length();
    dp[0][0]=1;
    for(int i = 0; i < n; i++){
        if(L[i]=='0'){
            dp[0][i+1] = dp[0][i] % mod;
            dp[1][i+1] = (dp[1][i] * 2 % mod + dp[1][i]) % mod;
        }else{
            dp[0][i+1] = (dp[0][i] * 2) % mod;
            dp[1][i+1] = ((dp[1][i] * 2 % mod + dp[1][i]) % mod + dp[0][i]) % mod;
        }
    }
    int ans = (dp[0][n] + dp[1][n]) % mod;
    cout << ans << endl;
    return 0;
}


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

Measured memory_bytes: 1156
import math
from functools import reduce
 
def gcd(nums):
    return reduce(math.gcd, nums)
 
K = int(input())
 
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd([i, j, k])
 
print(ans)

Measured memory_bytes: 69340
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N, M int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &N, &M)

	edges := make(map[int][]int)
	redges := make(map[int][]int)
	inCnt := make(map[int]int)
	for i := 0; i < N-1+M; i++ {
		var from, to int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &from, &to)
		edges[from] = append(edges[from], to)
		redges[to] = append(redges[to], from)
		inCnt[to]++
	}

	root := -1
	for i := 1; i <= N; i++ {
		if inCnt[i] == 0 {
			root = i
			break
		}
	}

	tpsorted := make([]int, 0)
	workList := make([]int, 0)
	left, right := 0, 0
	workList = append(workList, root)
	right++
	for left < right {
		// remove node
		node := workList[left]
		left++
		// add node
		tpsorted = append(tpsorted, node)
		for _, to := range edges[node] {
			inCnt[to]--
			if inCnt[to] == 0 {
				workList = append(workList, to)
				right++
			}
		}
	}

	node2order := make(map[int]int)
	for i, node := range tpsorted {
		node2order[node] = i
	}

	for i := 1; i <= N; i++ {
		if i == root {
			fmt.Println("0")
		} else if len(redges[i]) == 1 {
			fmt.Println(redges[i][0])
		} else {
			tmpOrder := -1
			tmpNode := -1
			for _, from := range redges[i] {
				order := node2order[from]
				if order > tmpOrder {
					tmpOrder = order
					tmpNode = from
				}
			}
			fmt.Println(tmpNode)
		}
	}

}


Measured memory_bytes: 37888
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define all(m) m.begin(), m.end()
#define uid uniform_int_distribution
#define init(m, x) memset(m, x, sizeof(m));
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    str t; cin>>t;
    for(int q=3; q>0; q--){
        str u = "R";
        for(; u.size()<q; ) u.pb('R');
        if(t.find(u)!=-1){
            cout<<q;
            return 0;
        }
    }
    cout<<0;
}

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

using namespace std;

int main() {
	int n;
	int a[200000];

	cin >> n;

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

	int maxv = -2147483647;
	int minv = a[0];
	for (int i = 1; i < n; i++) {
		maxv = max(maxv, a[i] - minv);
		minv = min(minv, a[i]);
	}

	cout << maxv << endl;

	return 0;
}


Measured memory_bytes: 3880
k,n = map(int,input().split())
A = list(map(int,input().split()))
result = 1000001
S = [0]
s = 0

for n,i in enumerate(A):
    if(n <= len(A)-2):
        s = A[n+1] - A[n]
        S.append(s)
S.append(k-A[len(A)-1]+A[0])
#print(S)
tmp = 0
for s in range(len(S)):
    tmp += S[s]
    S[s] = tmp
#print(S)


for i in range(len(S)):
    if(i == 0):
        ans = S[len(S)-2] - S[0]
        if(result>ans):
            #print(result,'1')
            result = ans
    else:
        ans = S[len(S)-1]- S[i] + S[i-1] - S[0]
        if(result>ans):
            #print(result,'2')
            result = ans
A.reverse()
S = [0]
for n,i in enumerate(A):
    if(n <= len(A)-2):
        s = k - A[n]
        S.append(s)
S.append(k)
#print(S)

for i in A:
    s += i
    S.append(s)
for i in range(len(S)):
    if(i == 0):
        S[len(S)-2] - S[0]
        if(result>ans):
            #print(result,'3')
            result = ans
    else:
        ans = S[len(S)-1]- S[i] + S[i-1] - S[0]
        if(result>ans):
            #print(result,'4')
            result = ans
print(result)

Measured memory_bytes: 96856
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val P = Array.fill(N, 2)(sc.nextInt())

    // 街を全て一回ずつ訪れるとき, 街を訪れる経路は全部でN!通りあります
    // 1番目に訪れる街, ,,,
    // N * N - 1 * N - 2 * ... * 1 通り
    // その経路の長さとします。これらのN!通りの経路の長さの平均値を計算してください
    val (sum, n) = (0 until N).permutations.foldLeft((0.0, 0))(
      (sum, permutation) => (permutation.sliding(2).foldLeft(sum._1)(
        (sum, path) => {
          val Seq(p1, p2) = path
          sum + Math.sqrt(Math.pow((P(p1)(0) - P(p2)(0)), 2) + Math.pow(P(p1)(1) - P(p2)(1), 2))
        }), sum._2 + 1))
    println(sum / n.toDouble)
  }

}


Measured memory_bytes: 62540
'use strict';
const main = input => {
  const n = parseInt(input[0], 10);
  let v = input[1].split(' ').map(val => parseInt(val, 10));
  v.sort((x,y) => x>y?1:-1);
  for(let i=0; i<n-1; i++) {
    let ave = (v[0]+v[1])/2;
    v.shift();
    v.shift();
    v = [ave, ...v];
    // console.log(v);
  }
  console.log(v[0]);
};
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 21192
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static int[][] map;
	public static int[][] dist;
	public static final int[] dx = {1, 0, -1, 0}; 
	public static final int[] dy = {0, 1, 0, -1}; 
	public static int w, h, n;
	public static void main(String[] args) throws IOException{
		Scanner in = new Scanner(System.in);
		while(true){
			w = in.nextInt();
			h = in.nextInt();
			if(w == 0) break;
			BitSet used = new BitSet(w*h);
			List<Pos> list = new ArrayList<Pos>();
			map = new int[h][w];
			int sx = 0;
			int sy = 0;
			n = 0;
			for(int i=0; i<h; i++){
				char[] s = in.next().toCharArray();
				for(int j=0; j<w; j++){
					switch(s[j]){
					case '.':
						map[i][j] = -1;
						break;
					case 'x':
						map[i][j] = -2;
						break;
					case '*':
						map[i][j] = n;
						list.add(new Pos(n++, i, j));
						break;
					case 'o':
						sx = j;
						sy = i;
						map[i][j] = -1;
						break;
					}
				}
			}
			dist = new int[n][n];
			int[] stod = new int[n];
			for(int i=0; i<n; i++){
				stod[i] = -1;
			}
			for(int i=0; i<n; i++){
				used.clear();
				Queue<Point> qu = new LinkedList<Point>();
				qu.add(list.get(i).p);
				while(!qu.isEmpty()){
					Point p = qu.poll();
					if(used.get(p.id)) continue;
					if(map[p.y][p.x] >= 0){
						dist[i][map[p.y][p.x]] = p.dist;
					}else if(p.y == sy && p.x == sx){
						stod[i] = p.dist;
					}
					used.set(p.id);
					for(int d=0; d<4; d++){
						int ny = p.y+dy[d];
						int nx = p.x+dx[d];
						if(out(ny, nx)) continue;
						if(map[ny][nx] == -2) continue;
						qu.add(new Point(ny, nx, p.dist+1));
					}
				}
			}
			res = 5000;
			for(int i=0; i<n; i++){
				if(stod[i] == -1){
					res = -1;
					break;
				}
				dfs(i, 1<<i, stod[i]);
			}
			System.out.println(res);
		}
	}
	
	public static int res;
	public static void dfs(int id, int state, int sum){
		if(Integer.bitCount(state) == n){
			res = Math.min(res, sum);
			return;
		}
		for(int i=0; i<n; i++){
			if((state&1<<i)>0) continue;
			dfs(i, state|1<<i, sum+dist[id][i]);
		}
	}
	
	public static boolean out(int y, int x){
		return y<0 || y>=h || x<0 || x>=w;
	}
}

class Point{
	int y, x;
	int id;
	int dist;
	public Point(int y, int x, int d){
		this.y = y;
		this.x = x;
		id = y*Main.w+x;
		dist = d;
	}
}

class Pos{
	int id;
	int y, x;
	Point p;
	public Pos(int id, int y, int x){
		this.id = id;
		this.y = y;
		this.x = x;
		this.p = new Point(y, x, 0);
	}
}

Measured memory_bytes: 63348
a, b = map(int, input().split())

if a > 0:
  print("Positive")
elif a == 0:
  print("Zero")
else:
  if b >= 0:
    print("Zero")
  else:
    if (b - a) % 2 == 0:
      print("Negative")
    else:
      print("Positive")

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

int main(){
    vector<string> S(3) ;
    rep(i,3) cin >> S[i] ;
    cout << S[0][0] << S[1][1] << S[2][2] << endl ;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <utility>

using namespace std;

int main()
{
    int n;
    bool ok=false;
    cin>>n;
    for (int i=0; i<30; i++)
    {
        for (int j=0; j<30; j++)
        {
            if (4*i+7*j==n) ok=true;
        }
    }
    if (ok) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string N;
    cin >> N;
    ll M = N.size();
    ll ans = 0;
    bool down = false;
    rep(i, M) {
        if (i == 0) {
            ans += N[i] - '0';
        } else {
            if (N[i] == '9' || down) {
                ans += 9;
            }else {
                ans += 8;
                down = true;
            }
        }
    }
    cout << ans << '\n';
}

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


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

int main() {
    int x;
    cin >> x;
    cout << 32*x << endl;

    return 0;
}


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

double L;

int main() {
    cout << fixed << setprecision(10);
    cin >> L;
    cout << (L/3)*(L/3)*(L/3) << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
using namespace std;
int main() {
	int n;
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		int dp[10001] = {};
		for (int i = 0;i < n;++i) {
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			dp[a] = b + c;
		}
		int maxnow = 0;
		for (int i = 0;i < 10001;++i) {
			if (dp[maxnow] < dp[i]) {
				maxnow = i;
			}
		}
		printf("%d %d\n", maxnow, dp[maxnow]);
	}
}


Measured memory_bytes: 1232
#include <iostream>

using namespace std;

char divide(int m, int e, int j) {
    if (m == 100 || e == 100 || j == 100) return 'A';
    if ( (m+e)/2 >= 90 ) return 'A';
    if ( (m+e+j)/3 >= 80 ) return 'A';
    if ( (m+e+j)/3 >= 70 ) return 'B';
    if ( (m+e+j)/3 >= 50 && (m >= 80 || e >= 80) ) return 'B';
    return 'C';
}

int main() {
    int n;
    while (cin >> n, n) {
        while (n--) {
            int pm, pe, pj;
            cin >> pm >> pe >> pj;
            cout << divide(pm, pe, pj) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
n,h,*l=map(int,open(0).read().split())
a=max(l[::2])
c=0;f=1
for b in sorted(l[1::2])[::-1]:
	if b>a:
		h-=b
		c+=1
		if h<1:
			f=0
			break
print(c+(~-h//a+1)*f)

Measured memory_bytes: 25124
#include<bits/stdc++.h>
#define PB push_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=100005;
int n,s,x[N];
long long ans,p[N];
vector<int>v;
int main(){
	scanf("%d%d",&n,&s);
	rep(i,1,n)scanf("%d%lld",x+i,p+i);
	int l=1,r=n;
	while(l<r){
		if(x[l]>=s){
			l=r;
			break;
		}
		if(x[r]<=s)break;
		if(p[l]>=p[r])p[l]+=p[r],v.PB(r--);
		else p[r]+=p[l],v.PB(l++);
	}
	v.PB(l);
	while(v.size())ans+=abs(s-x[v.back()]),s=x[v.back()],v.pop_back();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
int main () {
  vector<long> data(100001), sub(100001), ans(100001);
  int flag;
  for(int i = 2; i < 100001; i++){
    flag = 1;
    for(int j = 2; j <= sqrt(i); j++){
      if(i % j == 0){
        flag = 0;
        break;
      }
    }
    if(flag == 1){
      data.at(i) = 1;
    }
  }
  for(int i = 3; i < 100001; i += 2){
    if(data.at(i) == 1 && data.at((i + 1) / 2) == 1){
      sub.at(i) = 1;
    }
  }
  for(int i = 1; i < 100001; i++){
    ans.at(i) = ans.at(i - 1) + sub.at(i);
  }
  int Q;
  cin >> Q;
  int l, r;
  for(int i = 0; i < Q; i++){
    cin >> l >> r;
    cout << ans.at(r) - ans.at(l - 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,m;

int main(){
  ll ans=0;
  cin >> n >> m;
  vi a(n);
  ll gk=0;
  REP(i,n){
    cin>>a[i];
    gk+=a[i];
  }


  REP(i,n){
    if ((a[i]*m*4)>=gk){
      ans++;
    }
  }

  if (ans>=m){
    cout<<"Yes"<<endl;
    return 0;
  }else{
    cout<<"No"<<endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

struct tenbo {
	ll h;
	bool ok;
};

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

	int n, m;
	cin >> n >> m;
	tenbo* tenbos = new tenbo[n];
	rep(i, n) {
		cin >> tenbos[i].h;
		tenbos[i].ok = true;
	}

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		if (tenbos[a - 1].h == tenbos[b - 1].h) {
			tenbos[a - 1].ok = false;
			tenbos[b - 1].ok = false;
		}
		else {
			if (tenbos[a - 1].h > tenbos[b - 1].h) {
				tenbos[b - 1].ok = false;
			}
			else {
				tenbos[a - 1].ok = false;
			}
		}
	}

	int ans = 0;
	rep(i, n) {
		if (tenbos[i].ok) ++ans;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 5172
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
  string s;
  cin >> s;
  int sl = (int)s.length();
  long c[2019];
  long cb[2019];
  long cnl[2019];
  for(int i =0 ;i<2019;++i){
    c[i] = 0;
    cb[i] = 0;
    cnl[i] = 0;
  }
  int l;
  for(int i =0 ;i<sl;++i){
    l = s[i] - '0';
    c[l] = cb[0]+1;
    for(int j =1 ;j<2019;++j){
      c[(j * 10 + l )%2019] = cb[j];
    }
    for(int j =0 ;j<2019;++j){
      cnl[j]+=c[j];
      cb[j] = c[j];
      c[j] = 0;
    }
  }
  cout << cnl[0] << endl;
}


Measured memory_bytes: 3732
/**
*   Russian Flag
**/

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

int n = 0;
int m = 0;
char flag[70][70] = {0};

int solve()
{
  int cnt = 0;
  int ans = 1001001001;
  for (int i = 0; i < n - 2; i++)
  {
    for (int j = i + 1; j < n - 1; j++)
    {
      cnt = 0;
      for (int l = 0; l < m; l++)
      {
        for (int w = 0; w <= i; w++)   if (flag[w][l] != 'W') cnt++;
        for (int b = i+1; b <= j; b++) if (flag[b][l] != 'B') cnt++;
        for (int r = j+1; r < n; r++)  if (flag[r][l] != 'R') cnt++;
      }
      //printf("[debug]{i: %d, j: %d, w: 0-%d, b: %d-%d, r: %d-%d, cnt: %d}\n", i, j, i, i+1, j, j+1, n-1, cnt);
      ans = min(ans, cnt);
      //printf("[debug]ans = %d\n", ans);
    }
  }
  return ans;
}

int main()
{
  cin >> n >> m;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      cin >> flag[i][j];
    }
  }
  printf("%d\n", solve());
  return 0;
}



Measured memory_bytes: 3204
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l.shift() * 1
P = l.shift() * 1

// 素因数分解
_primFactors = function(n) {
  var arr = []
  if (n == 1) {
      return [{n:1, r:1}]
  }
  s = n

  var i = 2
  r = 0
  if (n % i === 0) {
    do {
      r++
      n /= i
    } while(n%i===0)
    arr.push({n: i, r: r})
  }
  
  for (i = 3; i*i <= s; i+=2) {
    r = 0
    if (n % i === 0) {
       do {
           r++
           n /= i
       } while(n%i===0)
       arr.push({n: i, r: r})
    }
  }
  if (n > 1) {
      arr.push({n: n, r: 1})
  }
  return arr
}

arr = _primFactors(P)
ans = 1
for (i=0; i<arr.length;i++) {
    a = arr[i]
    r = a.r
    while (r>=N) {
        ans *= a.n
        r -= N
    }
}
console.log(ans)

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

int N;
int mod=1e9+7;
int main(){

    while(cin>>N){
            long long ans=1;
    for(int i=1;i<=N;i++){
        ans*=i;
        if(ans>mod){
            ans%=mod;
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=k;i<n;i++)
            cout<<((a[i]>a[i-k])?"Yes":"No")<<endl;
    }
    return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
const int MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1);
#define nl printf("\n");
#define _FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull; 

int x, a, b;

int main() {
  cin>>x>>a>>b;

  x-=a;
  x = x%b;

  cout<<x<<endl;

  return 0;
}




Measured memory_bytes: 768
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,b,c,d,e,f=10;cin>>a>>b>>c>>d>>e;
  if(a%10!=0){
    f=min(f,a%10);
    a=(a/10+1)*10;
  }
  if(b%10!=0){
    f=min(f,b%10);
    b=(b/10+1)*10;
  }if(c%10!=0){
    f=min(f,c%10);
    c=(c/10+1)*10;
  }if(d%10!=0){
    f=min(f,d%10);
    d=(d/10+1)*10;
  }if(e%10!=0){
    f=min(f,e%10);
    e=(e/10+1)*10;
  }cout<<a+b+c+d+e+f-10;
}



Measured memory_bytes: 27052
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>h(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  vector<P>data(m);
  for(int i=0;i<m;i++){
    cin>>data.at(i).first>>data.at(i).second;
  }
  vector<int>a(n,1);
  for(int i=0;i<m;i++){
    if(h.at(data.at(i).first-1)>=h.at(data.at(i).second-1)){
      a.at(data.at(i).second-1)*=0;
    }
    if(h.at(data.at(i).first-1)<=h.at(data.at(i).second-1)){
      a.at(data.at(i).first-1)*=0;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(a.at(i)!=0)ans++;
  }
  cout<<ans<<endl;
}
      
      
      

Measured memory_bytes: 4840
func readThreeInts(separator: String.Element = " ") -> (a: Int, b: Int, c: Int) {
    let ints = readLine()!.split(separator: separator).map { Int($0)! }
    return (a: ints[0], b: ints[1], c: ints[2])
}

func mainA() {
    let (D, T, S) = readThreeInts()

    print(D <= T * S ? "Yes" : "No")
}
mainA()

Measured memory_bytes: 8260
import math


if __name__ == '__main__':
    passed_time = 0
    is_traveling = True

    tourist_count = int(input())
    transports = []
    for i in range(5):
        transports.append(int(input()))

    bottle_neck = min(transports)
    print(math.ceil(tourist_count / bottle_neck) + 4)


Measured memory_bytes: 2940
#!/usr/bin/env python3
n = int(input())
ans = [0] * (n + 1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            w = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if w <= n:
                ans[w] += 1
for i in range(1, n + 1):
    print(ans[i])


Measured memory_bytes: 9108
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
k -= 1
ans = l[k]
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ll a;
    cin >> a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3584
def solve(s):
    x, y = s[:2], s[2:]
    mm = ["%02d" % i for i in range(1,13)]
    if (x in mm) and (y in mm):
        return "AMBIGUOUS"
    if x in mm:
        return "MMYY"
    if y in mm:
        return "YYMM"
    return "NA"

s = input()
print(solve(s))

Measured memory_bytes: 3060
#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(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    int temp = 0;
    int ans = 0;
    rep(i,n){
        if(temp!=d[i]) ans++;
        temp = d[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string S, T;
  cin >> S >> T;
  string temp = S;
  const int64_t L = static_cast<int64_t>(S.length());
  for (int64_t i = 0; i < L; ++i) {
    temp = temp.substr(L - 1, 1) + temp.substr(0, L - 1);
    if (temp == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

long long find_max(function<bool(long long)> solve, long long low, long long high) {
	long long ok = low, ng = high;
	while (ng - ok > 1) {
		long long mid = (ok + ng) / 2;
		if (solve(mid)) {
			ok = mid;
		} else {
			ng = mid;
		}
	}
	return ok;
}

int main() {
	long long n, m;
	cin >> n >> m;
	vector<long long> A(n), S(n+1, 0);
	for (int i = 0; i < n; i++) cin >> A[i];
	sort(A.begin(), A.end());
	for (int i = n-1; i >= 0; i--) {
		S[i] = S[i+1] + A[i];
	}

	function<long long(long long)> g = [&](long long x) {
		long long res = 0;
		int j = n;
		for (int i = 0; i < n; i++) {
			int z = x - A[i];
			while (j > 0 && A[j-1] >= z) j--;
			res += n - j;
		}
		return res;
	};
	function<bool(long long)> f = [&](long long x) {
		return g(x) >= m;
	};
	function<long long(long long)> sum = [&](long long x) {
		long long res = 0;
		int j = n;
		for (int i = 0; i < n; i++) {
			int z = x - A[i];
			while (j > 0 && A[j-1] >= z) j--;
			res += S[j] + A[i] * (n - j);
		}
		return res;
	};

	long long x = find_max(f, 0, A[n-1]+A[n-1]+1);
	long long ans = sum(x) - (g(x) - m) * x;
	cout << ans << endl;
	return 0;
}

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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int n,a,b,c;
int ans[N];
char s[N][3];

void dfs(int u,int a,int b,int c){
    if(u>n){
        puts("Yes");
        Rep(i,1,n)printf("%c\n",ans[i]+'A');
        exit(0);
    }
    if(s[u][0]=='A'&&s[u][1]=='B'){
        if(a)ans[u]=1,dfs(u+1,a-1,b+1,c);
        if(b)ans[u]=0,dfs(u+1,a+1,b-1,c);
    }
    if(s[u][0]=='A'&&s[u][1]=='C'){
        if(a)ans[u]=2,dfs(u+1,a-1,b,c+1);
        if(c)ans[u]=0,dfs(u+1,a+1,b,c-1);
    }
    if(s[u][0]=='B'&&s[u][1]=='C'){
        if(b)ans[u]=2,dfs(u+1,a,b-1,c+1);
        if(c)ans[u]=1,dfs(u+1,a,b+1,c-1);
    }
}

int main()
{
    read(n),read(a),read(b),read(c);
    Rep(i,1,n)scanf("%s",s[i]);
    dfs(1,a,b,c);
    puts("No");
    return 0;
}

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

int main(){
	int n;
	int A[21],B[21],C[20];
	int sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)	cin >> A[i];
	for (int i = 0; i < n; i++)	cin >> B[i];
	for (int i = 0; i < n-1; i++)	cin >> C[i];

	for (int i = 0; i < n; i++){
		sum += B[A[i]-1];
		if (A[i] - A[i-1] == 1&&i>0){
			sum += C[A[i]-2];
		}
	}

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

Measured memory_bytes: 888
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:46 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

"""

N = int(input())
dp = np.zeros((N+1, 4,4,4))
dp[0][3][3][3] = 1

mod = 10**9+7
for n in range(N):
    for i in range(4):
        for j in range(4):
            for k in range(4):
                if dp[n][i][j][k] == 0:
                    continue
                for now in range(4):
                    if now == 0 and i == 1 and j == 2:
                        continue
                    if now == 0 and i == 2 and j == 1:
                        continue
                    if now == 1 and i == 0 and j == 2:
                        continue
                    if now == 0 and j == 1 and k==2:
                        continue
                    if now == 0 and i == 1 and k==2:
                        continue
                    dp[n+1][now][i][j] += dp[n][i][j][k]
                    dp[n+1][now][i][j] %= mod

res = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            res += dp[N][i][j][k]
            res %= mod
   

print(int(res))

Measured memory_bytes: 15700
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 2e5;

ll N;
string S[300];

int main() {
  cin >> N;
  REP (i, N) cin >> S[i];

  int ans = 0;
  REP (a, N) {
    bool ok = true;
    REP (j, N) FOR (i, j+1, N) ok &= (S[(a+j)%N][i] == S[(a+i)%N][j]);
    if (ok) ans += N;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <vector>
//const int maxn = 1e5+5;
#define ll long long
#define MAX INT_MAX
#define FOR(i,a,b) for( int i = a;i <= b;++i)

using namespace std;
string s1,s2;
int main()
{
    int pos=0,ans=0;
    cin>>s1;
    while(s1.find("WB",pos)!=-1)
    {
        pos=s1.find("WB",pos)+1;
        ans++;
    }
    pos=0;
    while(s1.find("BW",pos)!=-1)
    {
        pos=s1.find("BW",pos)+1;
        ans++;
    }
     cout<<ans;

}


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

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

bool ok(const string& str) {
  char mx = 'a';
  for(char c:str) {
    if (c > mx+1) return false;
    mx = max(mx, c);
  }
  return true;
}

void solve(int n, int i, const string& str) {
  if (n == i) {
    if(ok(str)) cout<<str<<'\n';
    return;
  }
  for(int j = 0; j < i + 1; ++j) {
    string nx = str;
    nx += 'a' + j;
    solve(n,i+1,nx);
  }
}

int main() {
  int n;
  cin>>n;
  solve(n, 0, "");
  return 0;
}


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

const int N = 2005, M = 4000005, mo = 1e9 + 7;
int n, k; ll ans;
ll fac[M], ivf[M], inv[M], f[N][N];
void prep () {
	fac[0] = ivf[0] = 1;
	fac[1] = ivf[1] = inv[1] = 1;
	for (int i = 2; i < M; ++i) {
		fac[i] = fac[i - 1] * i % mo;
		inv[i] = mo - 1ll * mo / i * inv[mo % i] % mo;
		ivf[i] = ivf[i - 1] * inv[i] % mo;
	}
}
ll C (int n, int r) {
	if (r < 0 || n < r)
		return 0;
	return fac[n] * ivf[r] % mo * ivf[n - r] % mo;
}
ll get (int a, int b) {
	return C(a + b, a);
}
int main () {
	cin >> n >> k, prep();
	if (k == 1)
		return puts("1"), 0;
	f[n][n] = 1;
	for (int i = n; ~i; --i)
		for (int j = n; ~j; --j) {
			if (i)
				f[i - 1][j] += f[i][j], f[i - 1][j] %= mo;
			if (i <= j - 1 && j) {
				f[i][j - 1] += f[i][j] * get(k - 2, (k - 1) * (j - 1) + i);
				f[i][j - 1] %= mo;
			}
		}
	cout << f[0][0] * fac[n] % mo << endl;
	return 0;
}

Measured memory_bytes: 125440
# -*- coding: utf-8 -*-
s = input()

a_num = 0
ans = 0
i = 0
while i < len(s):
    if s[i] == 'A':
        a_num += 1
        i += 1
    elif s[i:i+2] == 'BC':
        ans += a_num
        i += 2
    else:
        a_num = 0
        i += 1

print(ans)


Measured memory_bytes: 3500
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    boolean ans = false;
        for(int i = 1; i <= 9; i++) {
            for(int j = 1; j <= 9; j++) {
                if(N == i*j) {
                    ans = true;
                    break;
                }
            }
        }
        if(ans) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
            
	}
}

Measured memory_bytes: 21844
package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	xy := stdin.Text()

	x_y := strings.Split(xy, " ")

	x, _ := strconv.Atoi(x_y[0])
	y, _ := strconv.Atoi(x_y[1])
	fmt.Println(x*y, 2*x + 2*y)
}



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

using namespace std;

int N, K;
int arr[505], brr[505];

long long solve(long long k){
    for(int i = 1; i<=N; i++){
        brr[i] = arr[i]%k;
    }
    sort(brr+1, brr+1+N);
    int tot = 0;
    for(int l = 1, r = N; l<=r;){
        int opt1 = brr[l], opt2 = k-brr[r];
        if(opt1 == opt2){
            tot += opt1;
            l++, r--;
        }
        else if(opt1 < opt2){
            tot += opt1;
            brr[r] += brr[l];
            l++;
        }
        else{
            tot += opt2;
            brr[l] -= k-brr[r];
            r--;
        }
    }
    return tot;
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;
    long long s = 0;
    for(int i = 1; i<=N; i++){
        cin >> arr[i];
        s += arr[i];
    }
    long long ans = 1;
    for(long long k = 1; k<=sqrt(s); k++){
        if(s%k == 0){
            if(solve(k) <= K){
                ans = max(ans, k);
            }
            if(solve(s/k) <= K){
                ans = max(ans, s/k);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
const int mxN=2e5+5,M=1e9+7;
//did u check when n=1?
//is mxN correct?
string s;
bool ok1,ok2;
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>s;
    for(int i=0;i<sz(s);i+=2)if(s[i]=='L')ok1=1;
    for(int i=1;i<sz(s);i+=2)if(s[i]=='R')ok2=1;
    cout<<(ok1+ok2==0?"Yes":"No");
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        String s = in.next();
        out.println(s.matches("(hi)+") ? "Yes" : "No");
    }

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

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

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

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

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

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

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private PrintWriter out = new PrintWriter(System.out);
    boolean autoFlush = false;

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(int[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int i : a) {
            joiner.add(Integer.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(long[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (long i : a) {
            joiner.add(Long.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 21460
#include<stdio.h>
#include<algorithm>
using namespace std;
int var[26][20];
int perm[26];
char in[2];
char str[1100];
int cur;
int n;
struct wolf{
	int p[20];
	wolf(){for(int i=0;i<20;i++)p[i]=i;}
};
wolf expr();
wolf term(){
	if(str[cur]=='('){
		cur++;
		wolf ret=expr();
		cur++;
		return ret;
	}
	if('A'<=str[cur]&&str[cur]<='Z'){
		char ch=str[cur];
		cur++;
		wolf ret;
		for(int i=0;i<n;i++)ret.p[i]=var[ch-'A'][i];
		return ret;
	}
	int ks=0;
	while('0'<=str[cur]&&str[cur]<='9'){
		ks*=10;
		ks+=str[cur]-'0';
		cur++;
	}
	wolf ret;
	wolf mat=term();
	wolf to;
//	for(int i=0;i<n;i++)mat.p[i]=var[str[cur]-'A'][i];
	while(ks){
		if(ks%2){
			for(int i=0;i<n;i++)to.p[i]=mat.p[ret.p[i]];
			for(int i=0;i<n;i++)ret.p[i]=to.p[i];
		}
		ks/=2;
		for(int i=0;i<n;i++)to.p[i]=mat.p[mat.p[i]];
		for(int i=0;i<n;i++)mat.p[i]=to.p[i];	
	}
	//cur++;
//	printf("[");
	//for(int i=0;i<n;i++)printf("%d ",ret.p[i]);
//	printf("]\n");
	return ret;
}
wolf expr(){
	wolf ret=term();
	while(str[cur]=='+'){
		cur++;
		wolf tmp=term();
		wolf to;
		for(int i=0;i<n;i++)to.p[i]=tmp.p[ret.p[i]];
		ret=to;
//	printf("(");
//	for(int i=0;i<n;i++)printf("%d ",ret.p[i]);
	//printf(")\n");
	}

	return ret;
}
int ans[20];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	n=a;
	for(int i=0;i<b;i++){
		int p,q;
		scanf("%s%d",in,&q);
		for(int j=0;j<a;j++)perm[j]=j;
		for(int j=0;j<q-1;j++){
			for(int k=0;k<a-1;k++){
				int r;scanf("%d",&r);
				if(r)swap(perm[k],perm[k+1]);
			}
		}
		for(int j=0;j<a;j++){
			var[in[0]-'A'][perm[j]]=j;
		}
	//	for(int j=0;j<a;j++)printf("%d ",var[in[0]-'A'][j]);
	//	printf("\n");
	}
	int c;
	scanf("%d",&c);
	while(c--){
		scanf("%s",str);
		cur=0;
		wolf ret=expr();
		for(int i=0;i<a;i++)ans[ret.p[i]]=i;
		for(int i=0;i<a;i++){
			if(i)printf(" ");
			printf("%d",ans[i]+1);
		}
		printf("\n");
	}
}

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

int main(void) {
    int A,B,C,D; cin >> A >> B >> C >> D;
    int flag = true;
    while(true) {
        if(flag) {
            C-=B;
            flag = false;
        }
        else {
            A-=D;
            flag = true;
        } 
        if(C<=0) {
            cout << "Yes" << endl;
            return 0;
        }
        if(A<=0) {
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3612
a = int(input())
num = input().split()
num2 = [int(i) for i in num]
count = 0
#print(num2)

while True:
    num2 = [i/2 for i in num2 if i%2 == 0]
    if len(num2) != a:
        break
    count += 1 

print(count)

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

using namespace std;
const int N = 1e5 + 4;

struct Node {
	int sum, cnt;
	Node *lf, *rt;
	Node(int sum = 0, int cnt = 0) : sum(sum), cnt(cnt), lf(this), rt(this) {}
	Node(int sum, int cnt, Node *lf, Node *rt) : sum(sum), cnt(cnt), lf(lf), rt(rt) {}
};

Node *empty = new Node;
Node *insert(int x, int v, Node *cur, int l = 0, int r = N) {
	if (x > r || x < l)
		return cur;
	if (l == r)
		return new Node(cur->sum + v, cur->cnt + 1);
	int mid = l + (r - l) / 2;
	Node *lf = insert(x, v, cur->lf, l, mid);
	Node *rt = insert(x, v, cur->rt, mid + 1, r);
	return new Node(lf->sum + rt->sum, lf->cnt + rt->cnt, lf, rt);
}

pair<int, int> query(int x, Node *curR, Node *curL, int l = 0, int r = N) {
//	cout << "{" << x << ", " << curR->sum << " " << curR->cnt << "}" << endl;
	if (x > r || x < l)
		return {0, 0};
	if (l == r)
		return {curR->cnt - curL->cnt, curR->sum - curL->sum};
	int mid = l + (r - l) / 2;
	auto qL = query(x, curR->rt, curL->rt, mid + 1, r);
	auto qR = query(x, curR->lf, curL->lf, l, mid);
	return {qL.first + qR.first, qL.second + qR.second};
}

Node *root[N];
struct Edge {
	int v, c, d;
};
vector<Edge> adj[N];
int dist[N], ST[N][20], lev[N];
void dfs(int node, int l, int par, int c, int parD, int totalD, Node *p) {
	root[node] = insert(c, parD, p);
	dist[node] = totalD;
	ST[node][0] = par;
	for (int i = 1; (1 << i) <= l; ++i)
		ST[node][i] = ST[ST[node][i - 1]][i - 1];
	lev[node] = l;
	for (auto e: adj[node])
		if (e.v != par)
			dfs(e.v, l + 1, node, e.c, e.d, totalD + e.d, root[node]);
}
int LCA(int x, int y) {
	if (lev[x] < lev[y])swap(x, y);
	int d = lev[x] - lev[y];
	for (int i = 0; d; i++) {
		if (d & 1)x = ST[x][i];
		d >>= 1;
	}
	if (x == y)return x;
	int l = log2(lev[x]);
	for (int i = l; i >= 0; i--) {
		if (ST[x][i] != ST[y][i])
			x = ST[x][i], y = ST[y][i];
	}
	return ST[x][0];
}

int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
#endif
	root[0] = empty;
	int n, q;
	scanf("%d %d", &n, &q);
	for (int i = 1; i < n; ++i) {
		int u, v, c, d;
		scanf("%d %d %d %d", &u, &v, &c, &d);
		adj[u].push_back({v, c, d});
		adj[v].push_back({u, c, d});
	}
	dfs(1, 1, 1, 0, 0, 0, root[0]);
	while (q--) {
		int x, y, u, v;
		scanf("%d %d %d %d", &x, &y, &u, &v);
		int lca = LCA(u, v);
		int res = dist[u] + dist[v] - dist[lca] * 2;
//		cout << dist[u] << " " << dist[v] << " " << lca << " " << dist[lca] << ", ";
		auto curU = query(x, root[u], root[lca]);
		auto curV = query(x, root[v], root[lca]);
		pair<int, int> cur = {curU.first + curV.first, curU.second + curV.second};
//		cout << "[" << cur.first << " " << cur.second << "]: ";
		res -= cur.second;
		res += cur.first * y;
		printf("%d\n", res);
	}
	return 0;
}



Measured memory_bytes: 78208
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(m):
    bb,cc=map(int,input().split())
    b.append([cc,bb])
a.sort()
b.sort(reverse=True)

i=0
j=0
while i<n:
    if j==m:
        break
    if b[j][1]>0:
        if a[i]<b[j][0]:
            a[i]=b[j][0]
            b[j][1]-=1
            i+=1
        elif a[i]>=b[j][0]:
            break
    else:
        j+=1
print(sum(a))

Measured memory_bytes: 23996
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;


ll N, M;
int main(void) {
    cin >> N >> M;

    ll ans = 0;
    if ( N == 1 && M == 1) {
        ans = 1;
    } else if (N == 1 && M > 1) {
        ans = M - 2;
    } else if (M == 1 && N > 1) {
        ans = N - 2;
    } else {
        // intだとoverflow
        ans = max(ll(0), (N - 2) * (M -2));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256