akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	string s1, s2;
	cin >> s1 >> s2;
	vector<int> v;
	int cnt = 1;
	int now;
	for(int i = 0; i < n; i++){
		if(i == 0){
			if(s1[i] == s2[i]){
				now = 0;
			} else {
				now = 1;
				i++;
			}
		} else {
			if(s1[i] == s2[i]){
				if(now == 0){
					cnt++;
				} else {
					v.push_back(cnt);
					cnt = 1;
					now = 0;
				}
			} else {
				if(now == 1){
					cnt++;
				} else {
					v.push_back(cnt);
					cnt = 1;
					now = 1;
				}
				i++;
			}
		}
	}
	v.push_back(cnt);
	long long int ans;
	int start;
	if(s1[0] == s2[0]){
		ans = (3 * (long long int)pow(2, (v[0] - 1))) % mod;
		start = 0;
	} else {
		ans = (6 * (long long int)pow(3, (v[0] - 1))) % mod;
		start = 1;
	}
	// cout << v[0] << " " << ans << endl;
	for(int i = 1; i < v.size(); i++){
		if((start == 0 && i % 2 == 0) || (start == 1 && i % 2 == 1)){
			ans = (ans * (long long int)pow(2, (v[i] - 1))) % mod;
		} else {
			ans = (ans * 2 * (long long int)pow(3, (v[i] - 1))) % mod;
		}
		// cout << v[i] << " " << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int gcd(int x,int y){

  if(!y) return x;
  x%=y;
  return gcd(y,x);

}

int main(){

  int x,y;

  scanf("%d%d",&x,&y);
  printf("%d\n",gcd(x,y));

  return 0;

}



Measured memory_bytes: 2140
#include <iostream>
using namespace std;
int main(void){
    int W,H,x,y,r;
    cin >> W>>H>>x>>y>>r;
    
    if(x-r<0 || x+r>W) cout << "No"<<endl;
    else if (y-r<0 || y+r>H) cout << "No" <<endl;
    else cout <<"Yes"<<endl;
    
    
   
    
}


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


int main(){
	    int N;
        cin >> N;
        vector<int> X(N);
        rep(i, N){
            cin >> X[i];
        }
        int sum = 0;
        rep(i, N){
            sum += (X[i] - X[0]);
        }
        
        int g = round(sum / (double)N + X[0]);
        int ans = 0;
        rep(i, N){
            ans += (X[i] - g) * (X[i] - g);
        }
        cout << ans << endl;
}


Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  out(floor(nin()/3))
}
main()

Measured memory_bytes: 7372
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

typedef unsigned long long int ulint;
typedef long long int lint;

ulint H, W;

ulint INF = 10000000;

ulint enc(ulint h, ulint w) {
  return h * W + w;
}

// Solves the all-pairs shortest path problem using Floyd Warshall algorithm
int floydWarshall (vector<vector<ulint> > graph)
{
  int V = H * W;
    /* dist[][] will be the output matrix that will finally have the shortest 
      distances between every pair of vertices */
  vector<vector<int> > dist(V, vector<int>(V));
  int i, j, k;
 
    /* Initialize the solution matrix same as input graph matrix. Or 
       we can say the initial values of shortest distances are based
       on shortest paths considering no intermediate vertex. */
    for (i = 0; i < V; i++)
        for (j = 0; j < V; j++)
            dist[i][j] = graph[i][j];
 
    /* Add all vertices one by one to the set of intermediate vertices.
      ---> Before start of a iteration, we have shortest distances between all
      pairs of vertices such that the shortest distances consider only the
      vertices in set {0, 1, 2, .. k-1} as intermediate vertices.
      ----> After the end of a iteration, vertex no. k is added to the set of
      intermediate vertices and the set becomes {0, 1, 2, .. k} */
    for (k = 0; k < V; k++)
    {
        // Pick all vertices as source one by one
        for (i = 0; i < V; i++)
        {
            // Pick all vertices as destination for the
            // above picked source
            for (j = 0; j < V; j++)
            {
                // If vertex k is on the shortest path from
                // i to j, then update the value of dist[i][j]
                if (dist[i][k] + dist[k][j] < dist[i][j])
                    dist[i][j] = dist[i][k] + dist[k][j];
            }
        }
    }
 
    // Print the shortest distance matrix
    int ret = -1;
    for (i = 0; i < V; i++)
      for (j = 0; j < V; j++) {
        if (i == j) {
          continue;
        }
        if (dist[i][j] > ret && dist[i][j] < INF) {
          ret = dist[i][j];
        }
        // cout << dist[i][j] << " ";
      }
    // cout << endl;
    return ret;
}

int main(){
  cin >> H >> W;

  vector<vector<bool> > S(H, vector<bool>(W, false));
  
  for (int i = 0; i < H; ++i) {
    string p;
    cin >> p;
    for (int j = 0; j < W; ++j) {
      if (p[j] == '#') {
        S[i][j] = true;
      }
    }
  }


  // Reachable.

  vector<vector<ulint> > G(H * W, vector<ulint>(H * W, INF));

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j]) {
        continue;
      }
      // S[i][j] is a road
      if (0 < i && !S[i-1][j]) {
        G[enc(i, j)][enc(i-1, j)] = 1;
      }
      if (i < H - 1 && !S[i+1][j]) {
        G[enc(i, j)][enc(i+1, j)] = 1;
      }
      if (0 < j && !S[i][j-1]) {
        G[enc(i, j)][enc(i, j-1)] = 1;
      }
      if (j < W - 1 && !S[i][j+1]) {
        G[enc(i, j)][enc(i, j+1)] = 1;
      } 
    }
  }
  int m = floydWarshall(G);
  cout << m << endl;
}


Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<stdio.h>
#include<cmath>
using namespace std;

#define max(a,b) a > b ? a : b

int main() {

    int H, A;

    cin >> H >> A;

    if (H % A == 0)
    {
        cout << H / A << endl;
    }else
    {
        cout << H / A + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
t = gets().chop.to_i

t.times do
	n, k = gets().chop.split(" ").map{|num| num.to_i}
	x = gets().chop.split(" ").map{|num| num.to_i}
	a = Array.new(n - 1)
	for i in 0..n - 2
		a[i] = x[i + 1] - x[i]
	end
	a.sort!
	if 0 >= n - 1 - (k - 1)
		p 0
	else
		p a.take(n - 1 - (k - 1)).inject(:+)
	end
end

Measured memory_bytes: 22300
import sys
import queue
I=input()
K=int(I)
Q=queue.Queue()
for _ in range(1,10):
    Q.put(_)
x=0
for _ in range(K):
    x=Q.get()
    if x%10!=0:
        Q.put(10*x + x%10 -1)
    Q.put(10*x + x%10)
    if x%10!=9:
        Q.put(10*x + x%10 +1)
print(x)

Measured memory_bytes: 12452
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long valueA = 0;
		long countA = 0;
		long valueB = 0;
		long countB = 0;
		for (int i = 0; i < n; i++) {
			long a = sc.nextLong();
			valueA += a;
			valueB += a;
			if (i % 2 == 0) {
				if (valueA >= 0) {
					countA += valueA + 1;
					valueA = -1;
				}
				if (valueB <= 0) {
					countB += -valueB + 1;
					valueB = 1;
				}
			} else {
				if (valueA <= 0) {
					countA += -valueA + 1;
					valueA = 1;
				}
				if (valueB >= 0) {
					countB += valueB + 1;
					valueB = -1;
				}
			}
		}
		if (countA < countB) {
			System.out.println(countA);
		} else {
			System.out.println(countB);
		}
	}
}


Measured memory_bytes: 48452
#実験をすると順序によらず操作回数は一定そう
#...xy...でxとyに操作をすることを考える
#x+y<=9とx+y>=10で場合分けをすると、
#x+y<=9の時は、...xy... -> ...(x+y)... 1桁減る 総和は変わらない
#x+y>=10の時は、...xy... -> ...1(x+y-10)... 総和が9減る 桁数は変わらない
#最終的な状態は、1桁で、かつその数字が1~9になるので、
#桁数をn、総和をsとした時の答えはn-1+(s-1)/9になる
import sys
input = sys.stdin.readline

M = int(input())
s, n = 0, 0

for _ in range(M):
    d, c = map(int, input().split())
    s += d*c
    n += c
    
print(n-1+(s-1)//9)

Measured memory_bytes: 73592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  sort(ALL(a));
  cout << a.back()-a.front() << endl;
}


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

int main()
{
    double w,h,x,y;
    std::cin>>w>>h>>x>>y;
    std::cout<<std::setprecision(15)<<w*h/2.0<<" ";
    if(w==x+x&&h==y+y)std::cout<<1<<std::endl;
    else std::cout<<0<<std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[100000];
	int i;
	int flg;
	cin>>n;
	for(i=0;i<n;i++)	cin>>box[i];
	flg=0;
	if(n>1){
		for(i=n-1;i>=0;i--){
			if(box[i-1]>box[i]){
				box[i-1]--;
			}
		}
		for(i=0;i<n-1;i++){
			if(box[i]>box[i+1]){
				flg=1;
				break;
			}
		}
	}
	cout<<((flg)?"No":"Yes")<<endl;
	return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	ar := make([]int, 26)
	for _, v := range s {
		ar[v-'a']++
	}

	var ans int64 = 1
	for _, v := range ar {
		ans *= int64(v + 1)
		ans %= 1000000007
	}
	fmt.Println(ans - 1)
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

int main(){
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++){
        ll a; cin >> a;
        A[i] = --a;
    }

    

    ll dest = 0LL;
    vector<ll> v; v.push_back(0LL);
    set<ll> s; s.insert(0LL);
    ll cnt = 0;
    while (true){
        if (dest == A[dest]){
            cout << ++dest << endl;
            return 0;
        }
        dest = A[dest];
        cnt++;
        if (cnt == K){
            cout << ++dest << endl;
            return 0;
        }
        set<ll>::iterator it = s.find(dest);
        if(it == s.end()){
            s.insert(dest);
            v.push_back(dest);
        }
        else{
            break;
        }
    }
    ll index = 0;
    for (ll i = 0; i < (ll)v.size(); i++){
        if (v[i] == dest){
            index = i;
            break;
        }
    }

    //cout << dest << endl;
    //cout << index << endl;
    
    K -= index;    
    ll circle = s.size()-index;
    //cout << circle << endl;
    ll mod = K % circle;
    //cout << mod << endl;
    cout << v[index+mod]+1 << endl;
}

Measured memory_bytes: 13516
H, W = gets.split.map(&:to_i)
S = H.times.map { gets.chomp.chars }
count = Array.new(H+1) { Array.new(W+1, 0) }

S.each.with_index do |s, h|
  s.each.with_index do |c, w|
    next unless c == "#"
    ([h-1, 0].max..[H, h+1].min).each do |x|
      ([w-1, 0].max..[W, w+1].min).each do |y|
        count[x][y] += 1
      end
    end
  end
end

S.each.with_index do |s, h|
  s.each.with_index do |c, w|
    print case c
    when "." then count[h][w]
    when "#" then "#"
    end
  end
  puts
end


Measured memory_bytes: 3836
#include <stdio.h>

  int main(void)
  {

  int a,b,c,s;

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

  if(a > b){
    s = a;
    a = b;
    b = s;
    }
  if(b > c){
    s = b;
    b = c;
    c = s;
    }
  if(a > b){
    s = a;
    a = b;
    b = s;
    }

    printf("%d %d %d\n",a,b,c);

    return 0;

    }
     

Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
enum { };

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	ll n, m, ans = 0; cin >> n >> m;
	if (n >= m/2) {
		ans = m/2;
	} else {
		ans = n + (m - 2*n)/4;
	}
	cout << ans << endl;
	return 0;
}


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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    sort(a.begin(), a.end(), greater<long long>());

    long long ans = a[1];

    rep(i, n) {
        if (min(a[0] - a[i], a[i]) > min(a[0] - ans, ans)) {
            ans = a[i];
        }
    }

    cout << a[0] << " " << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007

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

using namespace std;
/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << (w * h)/ 2.0 << endl;
    if((w % 2 == 0) && (h % 2 == 0) && (w/2==x) &&(h/2==y)){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll a,b,x;
  cin>>a>>b>>x;
  double ans;
  if(x >= a*a*b/2.0){
    ans = atan(2 * (a*a*b - x) *1.0 / (a*a*a)) / acos(-1) * 180;
  }else{
    ans = 90.0 - atan(2.0 * x / (a*b*b)) / acos(-1) * 180;
  }
  cout<<setprecision(10)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b = 0, D, h, n, w, ans = 0, count = 0, res = 0, sum = 0, origin = 0;
  cin >> D;
  vlli c(26), r(26), f(26, 0), A, B;
  // vvli s(D, vlli(26));
  set<lli> g;

  rep(i, 0, 26)
  {
    cin >> c[i];
    origin += c[i];
  }
  rep(i, 0, D)
  {
    b++;
    w = 0;
    ans = 0;
    count = 0;
    vector<pair<lli, lli>> pr;
    repe(j, 1, 26)
    {
      cin >> a;
      // if (g.count(j))
      // {
      //   w = f[j - 1];
      //   count = c[j - 1] * (b - w);
      // }
      // else
      // {
      //   count = c[j - 1] * (b - 0);
      // }
      // a -= count;
      pr.eb(make_pair(-a, j));
    }
    SORT(pr);
    ans = pr[0].first;
    res += -ans;
    A.pb(res);
    sum = max(sum, res);
    for (auto x : pr)
    {
      if (x.first == ans)
      {
        cout << x.second << endl;
        g.insert(x.second);
        f[x.second - 1] = b;
        origin -= c[x.second - 1];
        B.pb(origin);
        break;
      }
    }
  }
  // lli t;
  // rep(i, 0, D)
  // {
  //   cin >> t;
  // }
  // rep(i, 0, A.size())
  // {
  //   cout << A[i] - B[i] << endl;
  // }
}

Measured memory_bytes: 3616
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
N, M = map(int, input().split())
#N = int(input())
#S = str(input())

A = []
for _ in range(N) :
  A.append(str(input()))

B = ""
for _ in range(M) :
  B += str(input())

for x in range(N-M+1) :
  for y in range(N-M+1) :
    t = ""
    for k in range(M) :
      t += (A[y+k])[x:x+M]
    #print (t)
    if t == B :
      print ("Yes")
      exit()
      
print ("No")


Measured memory_bytes: 40556
#include <stdio.h>
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(((a-5)*(b-5)*(c-7))||((a-5)*(b-7)*(c-5))||((a-7)*(b-5)*(c-5))) puts("NO");
  else puts("YES");
}

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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll n, k;
    cin >> n >> k;
    ll t = n % k;
    cout << min(t, k - t) << endl;
    
    return 0;
}



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

int main(){
  int k;
  cin >> k;
  vector<long long> a;
  for(int i=1;i<=9;i++) a.push_back(i);
  while (1){
    if(k <= a.size()){
      cout << a[k-1] << endl;
      return 0;
    }
    k-= a.size();
    vector<long long> old;
    swap(old,a);
    for(long long x : old){
      for(int i=-1;i<=1;i++){
        int d = x%10+i;
        if(d<0 || d>9) continue;
        long long nx=x*10+d;
        a.push_back(nx);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1712
import sys

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
b = set(a)
li = [1] + [0 for _ in range(N)]

for i in range(1, N + 1):
    if i in b:
        #rint("pass!{}".format(i))
        continue
    else:
        li[i] = li[i - 1] + li[i - 2]

print(li[-1] % 1000000007)

Measured memory_bytes: 460040
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,x,t;
	int ans;
	scanf("%d %d %d",&n,&x,&t);
	if (x>=n) cout<<t<<endl;
	else {
		ans=n%x==0?t*n/x:t*(n/x+1);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3772
a = list(input().split('LR'))
for i in range(len(a) - 1):
    a[i] += 'L'
    a[i + 1] = 'R' + a[i + 1]

#print(a)

b = []
c = 0
d = []
for j in range(len(a)):
    b = [0 for i in range(len(a[j]))]
    c = a[j].find('L')
    #print(c)
    if c % 2 == 0:
        b[c - 1] = len(a[j]) // 2
        b[c] = len(a[j]) - len(a[j]) // 2
    else:
        b[c] = len(a[j]) // 2
        b[c - 1] = len(a[j]) - len(a[j]) // 2

    d.extend(b)

print(' '.join(map(str,d)))

Measured memory_bytes: 13976
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    a = LI()
    ans = 0
    for i in range(1, n+1):
        if i%2 and a[i-1]%2:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
import java.util.Scanner;

class Main {
	public static void main(String[] args){
        int n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
         
        for(int i = 3; i <= n; i ++){
            String str = String.valueOf(i);
            if(i % 3 == 0 || str.indexOf("3") != -1){
                System.out.print(" "+i);    
            }
        }
        System.out.println();
        sc.close();
    }
}


Measured memory_bytes: 29928
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL A,B;
int main() {
	cin >> A >> B;
	if (A==B) return puts("1"), 0;
	int w,k;
	for (w=61;((1LL<<w)&A) == ((1LL<<w)&B);w--);
	A &= (1LL<<(w+1)) - 1, B &= (1LL<<(w+1)) - 1;
	LL ans = (1LL<<(w+1)) - A;
	
	for(k = w-1;k >= 0 && (B & (1LL << k)) == 0;-- k);
    if(A > (1LL << (k+1))) ans -= A - (1LL << (k+1));
	cout << ans << endl;
	return 0;
}

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

struct SegmentTree {
  vector< int > seg, add;
  int sz;
  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz *= 2;
    seg.assign(sz * 2 + 1, 0), add.assign(sz * 2 + 1, 0);
  }
  void Add(int a, int b, int x, int k, int l, int r)
  {
    if(a >= r || b <= l) {
      return;
    } else if(a <= l && r <= b) {
      add[k] += x;
    } else {
      Add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      Add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      seg[k] = seg[2 * k + 1] + add[2 * k + 1] + seg[2 * k + 2] + add[2 * k + 2];
    }
  }
  int Query(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return(0);
    if(a <= l && r <= b) return(seg[k] + add[k]);
    return(Query(a, b, 2 * k + 1, l, (l + r) / 2) + Query(a, b, 2 * k + 2, (l + r) / 2, r) + add[k]);
  }
  void Add(int a, int b, int x)
  {
    Add(a, b, x, 0, 0, sz);
  }
  int Query(int a, int b)
  {
    return(Query(a, b, 0, 0, sz));
  }
};


int main()
{
  int N, M, P[100000];
  scanf("%d %d", &N, &M);
  SegmentTree segtree(N);
  for(int i = 0; i < M; i++) {
    scanf("%d", &P[i]);
    --P[i];
  }
  for(int i = 1; i < M; i++) {
    int u = min(P[i - 1], P[i]), v = max(P[i - 1], P[i]);
    segtree.Add(u, v, 1);
  }
  long long ret = 0;
  for(int i = 0; i < N - 1; i++) {
    long long used = segtree.Query(i, i + 1);
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    ret += min(used * A, C + used * B);
  }
  printf("%lld\n", ret);
}

Measured memory_bytes: 3376
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;


    ll N,K,L;
    ll ans;
    string A[200010];
    std::unordered_map<string,int> S;
struct UnionFind {
    vector< int > data;
    UnionFind(int sz){
        data.assign(sz, -1);
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) std::swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k){
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int k){
        return(-data[find(k)]);
    }
};
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N>>K>>L;
    UnionFind X(N+10),Y(N+10);
    REP(i,K){
        int a,b;
        cin>>a>>b;
        X.unite(a-1,b-1);
    }
    REP(i,L){
        int a,b;
        cin>>a>>b;
        Y.unite(a-1,b-1);
    }
    REP(i,N){
        A[i]=std::to_string(X.find(i))+"+"+std::to_string(Y.find(i));
        S[A[i]] += 1;
    }
    REP(i,N){
        cout<< S[A[i]];
        if(i!=N-1)cout<<" ";
    }
    //cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 26184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  vector<vector<int>> a=input(3,3);
  int n;
  cin >> n;
  vector<int> b=input(n);
  bool f[3][3];
  rep(i,3){
    rep(j,3){
      f[i][j]=false;
      rep(k,n){
        if(a[i][j]==b[k]){
          f[i][j]=true;
        }
      }
    }
  }
  for(int i=0;i<3;i++){
    if(f[i][0]&&f[i][1]&&f[i][2]){
      cout << "Yes" << endl;
      return 0;
    }
    if(f[0][i]&&f[1][i]&&f[2][i]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if(f[0][0]&&f[1][1]&&f[2][2]){
    cout << "Yes" << endl;
    return 0;
  }
  if(f[0][2]&&f[1][1]&&f[2][0]){
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
	int n = 0 , minj = 0, flag = 1, k = 0;
	char a[36][3], b[36][3], temp[3];

	cin >> n;

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

	for (int i = 0; i < n; i++)
		strcpy(b[i], a[i]);

	while (flag) {
		flag = 0;
		for (int j = n - 1; j > 0; j--) {
			if (b[j][1] < b[j - 1][1]) {
				strcpy(temp, b[j - 1]);
				strcpy(b[j - 1], b[j]);
				strcpy(b[j], temp);
				flag = 1;
			}
		}
	}

	for (int i = 0; i < n - 1; i++)
		cout << b[i] << " ";
	cout << b[n - 1] << endl;

	for (int i = 0; i < n - 1; i++) {
		if (b[i][1] == b[i + 1][1]) {

			int s = 0, t = 0;

			while (strcmp(a[s], b[i]))
				s++;

			while (strcmp(a[t], b[i + 1]))
				t++;

			if (s > t)
				k = 1;
		}
	}

	if (k == 0)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;

	for (int i = 0; i < n; i++)
		strcpy(b[i], a[i]);

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

		minj = i;

		for (int j = i + 1; j < n; j++) {
			if (b[j][1] < b[minj][1])
				minj = j;
		}

		if (minj > i) {
			strcpy(temp, b[i]);
			strcpy(b[i], b[minj]);
			strcpy(b[minj], temp);
		}
	}

	for (int i = 0; i < n - 1; i++)
		cout << b[i] << " ";
	cout << b[n - 1] << endl;

	k = 0;

	for (int i = 0; i < n - 1; i++) {
		if (b[i][1] == b[i + 1][1]) {

			int s = 0, t = 0;

			while (strcmp(a[s], b[i]))
				s++;

			while (strcmp(a[t], b[i + 1]))
				t++;

			if (s > t)
				k = 1;
		}
	}

	if (k == 0)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
		
	return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int add(int x, int y) {
	x += y;
	if (x >= mod) {
		return x - mod;
	}
	return x;
}
int mult(int x, int y) {
	return 1ll * x * y % mod;
}
int bin_pow(int x, int y) {
	if (y == 0) {
		return 1;
	}
	if (y % 2 == 0) {
		return bin_pow(mult(x, x), y / 2);
	}
	return mult(x, bin_pow(x, y - 1));
}
int inv(int x) {
	return bin_pow(x, mod - 2);
}
const int maxn = 2005;
vector<int> fact(maxn), inv_fact(maxn);
int C(int x, int y) {
	if (x < y) {
		return 0;
	}
	return mult(fact[x], mult(inv_fact[y], inv_fact[x - y]));
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i < maxn; ++i) {
		fact[i] = mult(fact[i - 1], i);
		inv_fact[i] = inv(fact[i]);
	}
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 1; i <= k; ++i) {
		int answer = mult(C(k - 1, i - 1), C(n - k + 1, i));
		cout << answer << '\n';
	}
	
 	return 0;
}


Measured memory_bytes: 256
def f(i):
    while True:
        a[i]=(a[i]+1)%10
        if a[i]==0: i+=1
        else: break

s=input()
a=[]
for i in range(len(s)-1,-1,-1):
    a.append(int(s[i]))
a.append(0)

ans=0
for i in range(len(a)-1):
    if a[i]<5: ans+=a[i]
    elif a[i]==5:
        if a[i+1]<5: ans+=5
        else:
            ans+=5
            f(i+1)

    else:
        ans+=10-a[i]
        f(i+1)

if a[-1]!=0: ans+=1

print(ans)

Measured memory_bytes: 121288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

vvi v;
int K;

ll perm(ll n,int k) {
  if(!k) return 1;
  return n*perm(n-1,k-1)%INF;
}

void dfs(int now,int par,ll &ans) {
  int num=v[now].size();
  if(par!=-1) ans*=perm(K-2,num-1);
  else ans*=perm(K,num+1);
  ans%=INF;
  for(int x:v[now]) {
    if(x==par) continue;
    dfs(x,now,ans);
  }
}

int main() {
  int N;
  cin >> N >> K;
  v=vvi(N);
  rep(i,N-1) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  
  ll ans=1;
  dfs(0,-1,ans);
  
  cout << ans << endl;
}

Measured memory_bytes: 12060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;

	return 0;
}

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

#define int long long

const int N=100005,K=10000005,M=1000000000,inf=0x7f7f7f7f7f7f7f7fll;

int lazy[K],t[K],L[K],R[K],cur;
int a[N],l[N],r[N],Q[2*N],f[N],cnt;

void pushdown(int o)
{
	if(lazy[o])
	{
	//	cout<<"D "<<o<<" "<<lazy[o]<<" "<<L[o]<<" "<<R[o]<<endl;
		//if(L[o])
	//	{
		if(!L[o]) L[o]=++cur;
		if(!R[o]) R[o]=++cur;
		t[L[o]]=lazy[o];
		lazy[L[o]]=lazy[o];
	//	}
	//	if(R[o])
	//	{
		t[R[o]]=lazy[o];
		lazy[R[o]]=lazy[o];
	//	}
		lazy[o]=0;
	}
	return ;
}

void update(int &o,int l,int r,int ql,int qr,int k)
{
//	cout<<"Q "<<l<<" "<<r<<" "<<ql<<" "<<qr<<endl;
	if(ql>qr) return ;
	if(ql<0||ql>M||qr<0||qr>M) return ;
	if(!o)
	{
		o=++cur;
		t[o]=inf;
	}
	if(l>=ql&&r<=qr)
	{
		t[o]=lazy[o]=k;
		return ;
	}
	pushdown(o);
	int mid=(l+r)/2;
	if(qr<=mid) update(L[o],l,mid,ql,qr,k);
	else
	{
		if(ql>mid) update(R[o],mid+1,r,ql,qr,k);
		else
		{
			update(L[o],l,mid,ql,qr,k);
			update(R[o],mid+1,r,ql,qr,k);
		}
	}
//	cout<<"M "<<l<<" "<<r<<" "<<t[L[o]]<<" "<<t[R[o]]<<endl;
	t[o]=min(t[L[o]],t[R[o]]);
	return ;
}

int query(int o,int l,int r,int k)
{
//	cout<<"C "<<l<<" "<<r<<" "<<t[o]<<" "<<lazy[o]<<endl;
	if(!o) return 0;
	if(l==r) return t[o];
	pushdown(o);
	int mid=(l+r)/2;
	if(k<=mid) return query(L[o],l,mid,k);
	return query(R[o],mid+1,r,k);
}

signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	int n,b,mod,ans=inf,o=0;
	t[0]=inf;
	cin>>n>>mod;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b;
		a[i]+=a[i-1];
		if(b==1)
		{
			if((a[i]-a[i-1])*2>mod)
			{
				cout<<-1;
				return 0;
			}
			l[i]=(-2*a[i-1]%mod+mod)%mod;
			r[i]=(-2*a[i]%mod+mod)%mod;
		}
		else
		{
			l[i]=0;
			r[i]=mod-1;
		}
		Q[++cnt]=l[i];
		Q[++cnt]=r[i];
	}
	/*for(int i=1;i<=n;i++)
	{
		cout<<l[i]<<" "<<r[i]<<endl;
	}
	cout<<endl;*/
	sort(Q+1,Q+cnt+1);
	cnt=unique(Q+1,Q+cnt+1)-Q-1;
	for(int i=n;i>=1;i--)
	{
		int p=query(o,0,M,l[i]);
		if(!p) f[i]=0;
		else f[i]=f[p]+(l[p]-l[i]+mod)%mod;
	//	cout<<"P "<<p<<" "<<f[i]<<" "<<f[p]<<endl;
		if(l[i]<=r[i]) 
		{
			update(o,0,M,0,l[i]-1,i);
			update(o,0,M,r[i]+1,M,i);
		}
		else update(o,0,M,r[i]+1,l[i]-1,i);
	}
	for(int i=1;i<=cnt;i++)
	{
		int p=query(o,0,M,Q[i]);
		if(!p)
		{
			cout<<2*a[n];
			return 0;
		}
	//	cout<<"Q "<<p<<" "<<f[p]+(l[p]-Q[i]+mod)%mod<<endl;
		ans=min(ans,f[p]+(l[p]-Q[i]+mod)%mod);
	}
	cout<<ans+2*a[n];
	return 0;
}


Measured memory_bytes: 96512
#include <iostream>
using namespace std;
#define ll long long
ll min(ll a,ll b){return a<b?a:b;}
ll max(ll a,ll b){return a>b?a:b;}
 
ll sep(int a, int b){
    ll pre=1<<30,a1,a2;
    for(ll i=1;i<a;i++){
        a1=max(llabs(b*i-b*((a-i)/2)),llabs(b*i-b*(a-i-(a-i)/2)));
        a2=max(llabs(b*i-(a-i)*(b/2)),llabs(b*i-(a-i)*(b-b/2)));
        pre=min(pre,min(a1,a2));
    }
    return pre;
}
 
int main(void){
    ll h,w;
    cin>>h>>w;
    cout<<min(sep(h,w),sep(w,h));
}

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

string s , t;
int b[30];
set <int> ms[30];
ll full , stop = -1;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> s >> t;
    for (auto u: t) b[u-'a']=1;
    for (int i = 0; i < s.size(); i++){
        if (!b[s[i] - 'a'])continue;
        ms[s[i]-'a'].insert(i);
    }
    if (ms[t[0] - 'a'].empty()){
        cout << -1;
        return 0;
    }
    stop = *ms[t[0] - 'a'].begin();
    for (int i = 1; i < t.size(); i++){
        if (ms[t[i] - 'a'].empty()){
            cout << -1;
            return 0;
        }
        auto it = ms[t[i] - 'a'].upper_bound(stop);
        if (it == ms[t[i] - 'a'].end()) stop = -1 , full++ , it = ms[t[i] - 'a'].begin();
        stop = *it;
    }
    cout << full * s.size() + stop + 1;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
    ll h, w, m;
    cin >> h >> w >> m;
    vector<ll> H(m), W(m);
    for (ll i = 0; i < m; i++) cin >> H[i] >> W[i];
    map<pair<ll, ll>, ll> bomb;
    for (ll i = 0; i < m;i++){
        bomb[{H[i] - 1, W[i] - 1}]++;
    }
    vector<ll> mpx(h, 0), mpy(w, 0);
    for (ll i = 0; i < m; i++) mpx[H[i]-1]++;
    for (ll i = 0; i < m; i++) mpy[W[i]-1]++;
    ll xkey = 0;
    ll tmp = -INF;
    for (ll i = 0; i < h; i++) {
        if (chmax(tmp, mpx[i])) xkey = i;
    }
    tmp = -INF;
    ll ykey = 0;
    for (ll i = 0; i < w; i++) {
        if (chmax(tmp, mpy[i])) ykey = i;
    }
    vector<ll> xkouho, ykouho;
    for (ll i = 0; i < h;i++){
        if (mpx[i] == mpx[xkey]) xkouho.push_back(i);
    }
    for (ll i = 0; i < w;i++){
        if (mpy[i] == mpy[ykey]) ykouho.push_back(i);
    }
    ll ans = 0;
    for(auto i:xkouho){
        for(auto j:ykouho){
            ll tmp = mpx[i] + mpy[j];
            if (bomb[{i, j}]==0){
                ans = tmp;
                goto okok;
            }
        }
    }
    okok:
    if (ans == 0) ans = mpx[xkey] + mpy[ykey] - 1;
    cout << ans << endl;
}

Measured memory_bytes: 39688
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<numeric>
#include<climits>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

int main(void) {
	long long r, d, x;
	cin >> r >> d >> x;
	for (int i = 1; i <= 10; i++)
	{
		x = r * x - d;
		cout << x << endl;
	}
}

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

int main() {
    int k,a,b,d;
    //cin>>k;
    cin>>a>>b;
    //d=a+min(abs(k-a%k),a%k);
    if(b%a==0)
    {
        cout<<a+b<<endl;
    }
    else
    {
        cout<<b-a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = []
count = 0
flag = 0
for i in range(N):
    L.append(list(map(int, input().split())))

L.sort(key = lambda x:x[1] )
for i in range(N):
    count += L[i][0]
    if L[i][1] < count:
        print("No")
        flag = 1
        break

if flag == 0:
    print("Yes")
#print(N)
#print(L)

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll A,B,M; cin >> A >> B >> M;
    ll a[100005],b[100005];
    ll mina = LLONG_MAX;
    ll minb = LLONG_MAX;

    for (int i = 0;i < A;i++){
        cin >> a[i];
        mina = min(a[i],mina);
    }
    for (int i = 0;i < B;i++){
        cin >> b[i];
        minb = min(b[i],mina);
    }

    ll ans = mina+minb;

    for (int i = 0;i < M;i++){
        ll x,y,c; cin >> x >> y >> c;
        ans = min(ans,a[x-1]+b[y-1]-c);
    }

    cout << ans << endl;

    return 0;

}

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

int main(){
  string s;
  bool frg = true;
  cin >> s;
  if(s[0] != char(65)){frg = false;}
  int cnt = 0;
  int point = -1;
  //bool check = true;
  for (int i=1;i<s.size(); ++i){
    if(s[i] == char(67)){cnt++;point = i;}
    else if((int)s[i] <= 90){frg = false;}
  }
  if(cnt != 1 || point <=1 || point >= s.size()-1){frg = false;}
  if(frg){
    cout << "AC" << endl;
  }else{
    cout << "WA" << endl;
  }
}


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

using namespace std;
typedef long long ll;

const ll mod=1000000007;
const int oo=1000000000;
int dx[8]={1,-1,0,0,1,-1,1,-1};
int dy[8]={0,0,1,-1,1,-1,-1,1};
const int N=100050;


int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2==1){
        cout<<b-a<<endl;
    }
    else{
        cout<<a-b<<endl;
    }

    return 0;
}


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

using namespace std;

const int N = 2000000 + 10;
const int MOD = 1000000007;

string s;
int p[N], pr[N];

int exp(int x, int n)
{
	int tmp;
	if (n == 0) return 1;
	tmp = exp(x, n / 2);
	tmp = 1LL * tmp * tmp % MOD;
	if (n % 2 == 1) tmp = 1LL * tmp * x % MOD;
	return tmp;
}

int cal(int n, int m)
{
	return 1LL * p[n] * pr[m] % MOD * pr[n-m] % MOD;
}

int main()
{
	int res, n, k, x, y, i;
	cin>>k;
	cin>>s;
	n = s.size();
	p[0] = 1;
	for (i=1; i<=k+n; i++) p[i] = 1LL * p[i-1] * i % MOD;
	pr[0] = 1;
	for (i=1; i<=k+n; i++) pr[i] = exp(p[i], MOD - 2);
	res = 0;
	for (i=0; i<=k; i++)
	{
		x = exp(26, i);
		y = exp(25, k - i);
		res = (res + 1LL * x * y % MOD * cal(k - i + n - 1, n - 1) % MOD) % MOD;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 19968
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int> vi;
const int mod = 1000000007;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    if(n==1 ){
        if(m>2){
            cout<<m-2<<endl;
        }
        else if(m==2){
            cout<<0<<endl;
        }
        else{
            cout<<1<<endl;
        }
        return 0;
    }
     if(m==1 ){
        if(n>2){
            cout<<n-2<<endl;
        }
        else if(n==2){
            cout<<0<<endl;
        }
        else{
            cout<<1<<endl;
        }
        return 0;
    }
    n = n-2;
    m = m-2;
    if(n<0){
        n=0;
    }
    if(m<0){
        m=0;
    }
    cout<<n*m<<endl;



}








Measured memory_bytes: 256
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

lists="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lists=list(lists)

max_len=len(lists)

N=one_int()
S=one_str()

N=N%max_len

output=[]
for s in list(S):
    index = lists.index(s)
    output.append(lists[(index+N)%max_len])
print("".join(output))

Measured memory_bytes: 39920
#include <bits/stdc++.h>
using namespace std;
#define int long long int
signed main(){
  int n;cin>>n;
  map<string,int> mp;
  for(int i=0;i<n;i++){string s;cin>>s;
       mp[s]++;
  }
  cout<<"AC x "<<mp["AC"]<<"\n";
  cout<<"WA x "<<mp["WA"]<<"\n";
  cout<<"TLE x "<<mp["TLE"]<<"\n";
  cout<<"RE x "<<mp["RE"]<<"\n";
  return 0;
}

Measured memory_bytes: 3644