akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "unordered_set"
#include "stack"
#include "tuple"

#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<int,int>

typedef long long ll;
using namespace std;

int n, k, a[5000], l, r, p;
bool b[5000][5000];

int main() {
	cin >> n >> k;
	rep(n)
		cin >> a[i];
	sort(a, a + n);
	l = -1;
	r = n;
	rep(k)
		b[0][i] = false;
	b[0][0] = true;
	while (l + 1 != r) {
		p = 1;
		rep(n) {
			if (i != (l + r) / 2) {
				REP(k, j)
					b[p][j] = false;
				REP(k,j)
					if (b[p - 1][j]) {
						b[p][j] = true;
						if (j + a[i] < k)
							b[p][j + a[i]] = true;
					}
				++p;
			}
		}
		bool B = false;
		for (int i = max(k - a[(l + r) / 2],0); i < k; ++i) {
			if (b[n-1][i]) {
				B = true;
				break;
			}
		}
		if (B)
			r = (l + r) / 2;
		else
			l = (l + r) / 2;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 24832
#include<stdio.h>

int main(void){
	int N,i[10];
	char a[10]={'a','b','c','d','e','f','g','h','i','j'};
	scanf("%d",&N);
	for(i[0]=0;i[0]<1;i[0]++){
		if(N>1){
			for(i[1]=0;i[1]<i[0]+2;i[1]++){
				if(N>2){
					for(i[2]=0;i[2]<i[1]+2||i[2]<i[0]+2;i[2]++){
						if(N>3){
							for(i[3]=0;i[3]<i[2]+2||i[3]<i[1]+2||i[3]<i[0]+2;i[3]++){
								if(N>4){
									for(i[4]=0;i[4]<i[3]+2||i[4]<i[2]+2||i[4]<i[1]+2||i[4]<i[0]+2;i[4]++){
										if(N>5){
											for(i[5]=0;i[5]<i[4]+2||i[5]<i[3]+2||i[5]<i[2]+2||i[5]<i[1]+2||i[5]<i[0]+2;i[5]++){
												if(N>6){
													for(i[6]=0;i[6]<i[5]+2||i[6]<i[4]+2||i[6]<i[3]+2||i[6]<i[2]+2||i[6]<i[1]+2||i[6]<i[0]+2;i[6]++){
														if(N>7){
															for(i[7]=0;i[7]<i[6]+2||i[7]<i[5]+2||i[7]<i[4]+2||i[7]<i[3]+2||i[7]<i[2]+2||i[7]<i[1]+2||i[7]<i[0]+2;i[7]++){
																if(N>8){
																	for(i[8]=0;i[8]<i[7]+2||i[8]<i[6]+2||i[8]<i[5]+2||i[8]<i[4]+2||i[8]<i[3]+2||i[8]<i[2]+2||i[8]<i[1]+2||i[8]<i[0]+2;i[8]++){
																		if(N>9){
																			for(i[9]=0;i[9]<i[8]+2||i[9]<i[7]+2||i[9]<i[6]+2||i[9]<i[5]+2||i[9]<i[4]+2||i[9]<i[3]+2||i[9]<i[2]+2||i[9]<i[1]+2||i[9]<i[0]+2;i[9]++)printf("%c%c%c%c%c%c%c%c%c%c\n",a[i[0]],a[i[1]],a[i[2]],a[i[3]],a[i[4]],a[i[5]],a[i[6]],a[i[7]],a[i[8]],a[i[9]]);
																		}else printf("%c%c%c%c%c%c%c%c%c\n",a[i[0]],a[i[1]],a[i[2]],a[i[3]],a[i[4]],a[i[5]],a[i[6]],a[i[7]],a[i[8]]);
																	}
																}else printf("%c%c%c%c%c%c%c%c\n",a[i[0]],a[i[1]],a[i[2]],a[i[3]],a[i[4]],a[i[5]],a[i[6]],a[i[7]]);
															}
														}else printf("%c%c%c%c%c%c%c\n",a[i[0]],a[i[1]],a[i[2]],a[i[3]],a[i[4]],a[i[5]],a[i[6]]);
													}
												}else printf("%c%c%c%c%c%c\n",a[i[0]],a[i[1]],a[i[2]],a[i[3]],a[i[4]],a[i[5]]);
											}
										}else printf("%c%c%c%c%c\n",a[i[0]],a[i[1]],a[i[2]],a[i[3]],a[i[4]]);
									}
								}else printf("%c%c%c%c\n",a[i[0]],a[i[1]],a[i[2]],a[i[3]]);
							}
						}else printf("%c%c%c\n",a[i[0]],a[i[1]],a[i[2]]);
					}
				}else printf("%c%c\n",a[i[0]],a[i[1]]);
			}
		}else printf("%c\n",a[i[0]]);
	}
	return 0;
}

Measured memory_bytes: 1408
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, X, M = NMI()
    
    tmp = X%M
    
    ls = []
    ls.append(tmp)
    
    for n in range(N-1):
        tmp = (tmp ** 2)%M
        
        if tmp in ls:
            ls_before_loop = ls[:ls.index(tmp)]
            ls_in_loop = ls[ls.index(tmp):]
            break
        else:
            ls.append(tmp)


    
    if len(ls) == N:
        print(sum(ls))
    else:
        sum_before_loop = sum(ls_before_loop)
        sum_in_loop = ((N-len(ls_before_loop))//(len(ls_in_loop)))*sum(ls_in_loop)
        sum_after_loop = sum(ls_in_loop[:(N-((N-len(ls_before_loop))//(len(ls_in_loop)))*len(ls_in_loop))-len(ls_before_loop)])
        print(sum_before_loop+sum_in_loop+sum_after_loop)


if __name__ == '__main__':
    main()

Measured memory_bytes: 71576
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion
#define MAX 111111

struct edge{
  ll cost;
  pll node;
  edge(ll c, pll n) : cost(c), node(n) {}
  bool operator>(const edge &e) const {
	return cost > e.cost;
  }
};

priority_queue<edge, vector<edge>, greater<edge>> pq;

bool cmp(const pll& p1, const pll& p2) {
  if (p1.first != p2.first) {
	return p1.first < p2.first;
  }
  else {
	return p1.second < p2.second;
  }
}

vll hei, p;

void uset(ll n) {
  hei.resize(n, 0);
  p.resize(n, 0);
  FOR(i, 0, n) {
	p[i] = i;
	hei[i] = 0;
  }
}

ll find(ll x) {
  if (x != p[x]) {
	p[x] = find(p[x]);
  }
  return p[x];
}

void unite(ll a, ll b) {
  ll x = find(a);
  ll y = find(b);
  if (hei[x] > hei[y]) {
	p[y] = x;
  }
  else {
	p[x] = y;
	if (hei[x] == hei[y]) {
	  hei[y]++;
	}
  }
}

bool same(ll a, ll b) {
  return find(a) == find(b);
}

int main(void) {
  ll a, b;
  vector<pll> x, y;
  edge e = { 0,pll(0,0) };
  cin >> n;
  uset(n);
  FOR(i, 0, n) {
	cin >> a >> b;
	x.pb(pll(a, i));
	y.pb(pll(b, i));
  }
  sort(ALL(x), cmp);
  sort(ALL(y), cmp);

  FOR(i, 0, n - 1) {
	pq.push(edge(x[i + 1].F - x[i].F, pll(x[i].S, x[i + 1].S)));
	pq.push(edge(y[i + 1].F - y[i].F, pll(y[i].S, y[i + 1].S)));
  }

  FOR(i, 0, 2 * (n - 1)) {
	e = pq.top();
	pq.pop();
	if (!same(e.node.F, e.node.S)) {
	  unite(e.node.F, e.node.S);
	  ans += e.cost;
	}
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 14560
<?php
$c = str_split("abcdefghijklmnopqrstuvwxyz");
$s = str_split(trim(fgets(STDIN)));
$t = array_count_values($s);
$n = count($t);
if($n == 26){
echo "None";
}else{
$d = array_diff($c,$s);
sort($d);
echo $d[0];
}

Measured memory_bytes: 21900
function gcd(a, b) {
	if (a < b) return gcd(b, a);
	if (b == 0) return a;
	return gcd(b, a % b);
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
  var line = chunk.split(' ');
  var a = line[0];
  var b = line[1];
  console.log(gcd(a, b));
});

Measured memory_bytes: 7640
import scala.collection.mutable
object Main extends App {

  import scala.io.StdIn._

  solve
  def solve: Unit = {
    val state = readLine.trim
    if (state == "0") return
    val color = state.map{
      case 'r' ⇒ 0
      case 'b' ⇒ 1
      case 'g' ⇒ 2
    }
    val minStep = Array.tabulate(exponent(3, state.length)){_ ⇒ -1}
    minStep(color.foldLeft(0){(a, b) ⇒ a * 3 + b}) = 0
    val queue = mutable.Queue[IndexedSeq[Int]]().also{q ⇒ q.enqueue(color)}
    while(queue.nonEmpty){
      val top = queue.dequeue()
      val topI = top.foldLeft(0){(a, b) ⇒ a * 3 + b}
      for (i ← state.indices.tail if top(i) != top(i - 1)) {
        val next = top.updated(i - 1, (top(i) + top(i - 1)) * 2 % 3).updated(i, (top(i) + top(i - 1)) * 2 % 3)
        val index = next.foldLeft(0){(a, b) ⇒ a * 3 + b}
        if (minStep(index) == -1){
          minStep(index) = minStep(topI) + 1
          queue.enqueue(next)
        }
      }
    }
    val green = minStep(exponent(3, state.length) - 1)
    val blue = minStep((exponent(3, state.length) - 1) / 2)
    val red = minStep(0)
    List(green, blue, red).filterNot(_ == -1) match {
      case Nil ⇒ println("NA")
      case l ⇒ println(l.min)
    }
    solve
  }
  def exponent(base: Int, exp: Int): Int = {
    exp match {
      case 0 ⇒ 1
      case 1 ⇒ base
      case _ ⇒ exponent(base, exp / 2).let{i ⇒ i * i * exponent(base, exp % 2)}
    }
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}


Measured memory_bytes: 450868
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    String S = sc.next();

    String S1 = S.substring(0,1);
    String S2 = S.substring(1,2);
    String S3 = S.substring(2,3);

    int count = 0;

    if (S1.equals("o")) {
      count++;
    }

    if (S2.equals("o")) {
      count++;
    }

    if (S3.equals("o")) {
      count++;
    }

    System.out.println(700 + (100 * count));

  }
}

Measured memory_bytes: 21076
N = int(input())
A = list(map(int, input().split()))

cnt = 1
mode = 0

for i in range(1, N):
    if A[i-1] > A[i]:
        if mode == "+":
            cnt += 1
            mode = 0
        else:
            mode = "-"
    elif A[i-1] < A[i]:
        if mode == "-":
            cnt += 1
            mode = 0
        else:
            mode = "+"
            
print(cnt)

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

int main() {
	int n, x, m;
	int mini = 900000;
	cin >> n >> x;
	int cnt = 0;
	for (int i = 0;i < n;i++) {
		cin >> m;
		mini = min(mini, m);
		x -= m;
		cnt++;
	}
	cnt += x  / mini;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
// 重み付きUnion-Find で実装してみる

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

const ll INF = 1LL << 60;

template <typename T = int>
struct UnionFind {
  vector<int> par;	// 親ノード
  vector<int> rank;	// ランク（経路圧縮しなかった場合の木の高さ。rootノードでのみ有効な値が入っている）
  vector<T> dif_weight;	// ルートノードからの重み差分
  UnionFind( int n, T offset = 0) {
    init(n, offset);
  }
  void init( int n, T offset = 0 ) {
    par.resize(n);
    rank.resize(n);
    dif_weight.resize(n);
    for(int i=0; i<n; ++i )  par[i] = i;
    for(int i=0; i<n; ++i )  rank[i] = 0;
    for(int i=0; i<n; ++i )  dif_weight[i] = offset;
  }
  int root( int a ) {
    int pa = par[a];
    if ( pa == a ) return a;
    int r = root(pa);
    dif_weight[a] += dif_weight[par[a]];
//printf(" root( %d ) : %d\n",a,dif_weight[a]);
    return par[a] = r;
  }
  int weight( int a ) {
    root(a);
    return dif_weight[a];
  }
  int diff( int a, int b ) {
    return weight(b) - weight(a);
  }
  bool merge( int a, int b, T w ) {
    T bw = w;
    w += weight(a);
    w -= weight(b);
    int ra = root(a);
    int rb = root(b);
    if ( ra == rb ) return false;
    if ( rank[ra] < rank[rb] ) swap(ra,rb), w = -w;
    if ( rank[ra] == rank[rb] ) rank[ra]++;
    par[rb] = ra;
    dif_weight[rb] = w;
//printf(" merge( %d %d %d ) : %d\n",a,b,bw,w);
    return true;
  }
  bool isSame( int a, int b) {
    return (root(a) == root(b));
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind<int> uf(N);
  REP(i,M) {
    int l,r,d;
    cin >> l >> r >> d;
    l--; r--;
    if ( uf.isSame( l, r ) ) {
      if ( d != uf.diff(l,r) ) {
//printf("%d %d %d %d\n",l,r,d,uf.diff(l,r));
        cout << "No" << endl;
        return 0;
      }
    } else {
      uf.merge(l,r,d);
    }
  }
  cout << "Yes" << endl;
}



Measured memory_bytes: 1408
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0),cin.sync_with_stdio(0),cout.tie(0),cout.sync_with_stdio(0);
	int n, tmp, cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>tmp;
		if(tmp!=i)
			cnt++;
	}
	if(cnt==2||cnt==0) cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

x = ii()
l = [0]
i = 0
num = 0
while num < 10**11:
    i += 1
    num = i**5
    l.append(num)
#print(l[-1]-l[-2])
l = set(l)
for item in l:
    if item > x:
        if item - x in l:
            print(int(item**0.2),int((item-x)**0.2))
            exit()
    else:
        if x - item in l:
            print(int(item**0.2),int((x-item)**0.2)*(-1))
            exit()

'''
    if x - item in l:#Aがitemでx-itemは-B**5
        print(int(item**0.2),int(abs(item-x)**0.2)*(-1))
        exit()
    elif item - x in l:#Aがitemでx-itemはB**5
#        print(item,item-x)
        print(int(item**0.2),int(abs(item-x)**0.2)*(-1))
        exit()
'''

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

int main() {
    int d, t, s;
    cin >> d >> t >> s;

    int z = t * s;
    if (d <= z) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(void){
	int a,i,j,count=0,count2=0;
	scanf("%d",&a);
	for(i=1;i<=a;i+=2){
		for(j=1;j<=i;j++)
			if(i%j==0)count++;
		if(count==8)count2++;
		count=0;
	}
	printf("%d",count2);
	
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n,sum,sum1=0;
    cin>>k>>n;
    int a[k],t[k];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sum=a[n-1]-a[0];
    for(int i=1; i<n; i++)
    {
        sum=min(sum,k-a[i]+a[i-1]);
        //cout<<k-a[i]+a[i-1]


    }
    cout<<sum<<endl;
}


Measured memory_bytes: 2816
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush


def prime_factorization(n):
    res = []
    for i in range(2, int(pow(n, 0.5))+1):
        if n % i: continue
        ex = 0
        while n % i == 0:
            n = n // i
            ex += 1
        res.append((i, ex))
    if n != 1:
        res.append((n, 1))
    return res

def mcomb(n, k, mod):
    def mfac(l, r, mod):
        ans = l
        for i in reversed(range(r, l)):
            ans *= i
            ans %= mod
        return ans

    A = mfac(n,n-k+1,mod)
    B = mfac(k,1,mod)
    # B = mpow(B,mod-2,mod)
    B = pow(B, mod-2, mod)
    return A * B % mod

def solve():
    n, m = MI()
    fact = prime_factorization(m)
    if n == 1:
        print(1)
        return
    # print(fact)
    mod = 1000000007
    ans = 1
    for num, ex in fact:
        # print(ex, mcomb(ex+n-2, n-1, mod))
        ans *= mcomb(ex+n-1, n-1, mod) % mod
    print(ans % mod)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3380
use std::io;
use std::cmp;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    let v: Vec<u16> =
        line.split_whitespace().map(|n| n.parse().unwrap()).collect();
    let a = v[0];
    let b = v[1];
    let c = v[2];
    println!("{}", cmp::min(cmp::min(a+b, b+c), a+c));
}

Measured memory_bytes: 4352
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    k = f()[0]

    a = set()

    slen = len(s)
    for i in range(slen):
        for j in range(1,k+2):
            if i+j <= slen:
                a.add(s[i: i+j])
    
    a = sorted(a)
    print(a[k-1])


solve()


Measured memory_bytes: 4848
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<stack>
#include<string.h>
using namespace std;
int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a + b + c <= 21) printf("win"); else printf("bust");
	return 0;
}

Measured memory_bytes: 128
/************************************************
 * Au: Hany01
 * Prob: agc001b
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

template <typename T> inline T read() {
	static T _, __; static char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


LL f(LL x, LL N) {
	if (x > N) swap(x, N);
	if (N % x == 0) return 2ll * N - x;
	return 2ll * x * (N / x) + f(N % x, x);
}

int main()
{
#ifdef hany01
	freopen("agc001b.in", "r", stdin);
	freopen("agc001b.out", "w", stdout);
#endif

	LL N = read<LL>(), x = read<LL>();
	printf("%lld\n", N + f(x, N - x));

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MX 1005

char s[MX];

int main()
{
    scanf("%s",s);
    int len = strlen(s);
    for (int i=0;i<len;i++)
        if (i+8<len)
        printf("%c",s[i]);
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

struct Edge{
    ll dst;
    ll weight;
    Edge(ll dst, ll weight): dst(dst), weight(weight) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const ll INFLL = LLONG_MAX/3;
const ll MAX_V = 500;

ll dist[MAX_V][MAX_V];

void WarhshallFloyd(Graph &G){
	ll V = G.size();
	for(int i=0;i<V;i++){
		for(int j=0;j<V;j++){
			if(i==j) dist[i][j] = 0;
			if(i!=j) dist[i][j] = INFLL;
		}
	}
	for(int i=0;i<V;i++){
		for(int j=0;j<G[i].size();j++){
			Edge e = G[i][j];
			dist[i][e.dst] = e.weight;
		}
	}

	for(int k=0;k<V;k++){
		for(int i=0;i<V;i++){
			for(int j=0;j<V;j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	return;
}

int main(){
	ll V, E;
    cin >> V >> E;
    Graph G(V);
    ll s, t, w;
    for(int i=0;i<E;i++){
        cin >> s >> t >> w;
        Edge e(t, w);
        G[s].push_back(e);
    }

    for(int i=0;i<V;i++){
		for(int j=0;j<G[i].size();j++){
			Edge e = G[i][j];
		}
	}
    WarhshallFloyd(G);

    // detect negative cycle
    // there is a negative cycle iff for some i dist[i][i]<0
    bool negative_cycle = false;
    for(int i=0;i<V;i++){
    	if (dist[i][i]<0){
    		cout << "NEGATIVE CYCLE" << endl;
    		return 0;
    	}
    }
    for(int i=0;i<V;i++){
    	for(int j=0;j<V;j++){
    		if (dist[i][j]>INFLL/2) cout << "INF";
    		else cout << dist[i][j]; 
    		if(j<V-1) cout << " ";
    	}
    	cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((int)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

LL factorial(int x){
	if(x<=1)return 1;
	return x * factorial(x-1) % MOD;
}

bool flag = false;

void output(LL x){
	if(flag)cout << " ";
	cout << x;
	flag=true;
}

void outendl(){
	flag=false;
	cout << endl;
}

int countbit(int x){
	for(int i=10;;--i){
		if(BIT(i)&x)return i + 1;
	}
}

int main(){
	int N;
	cin >> N;
	vector<vector<int>> line(N);
	vector<vector<int>> ans(N, vector<int>(N, 0));
	REP(i, N){
		line[i].push_back(i);
	}
	int count = 1;
	while(line.size()>1){
		vector<vector<int>> ne;
		for(int i=0;i<line.size();i+=2){
			if(i+1==line.size()){
				ne.push_back(line[i]);
				continue;
			}
			foreach(j, line[i]){
				foreach(k, line[i+1]){
					ans[j][k]=count;
					ans[k][j]=count;
				}
			}
			line[i].insert(line[i].end(), ALL(line[i+1]));
			ne.push_back(line[i]);
		}
		++count;
		line = ne;
	}
	REP(i, N){
		for(int j=i+1;j<N;++j){
			output(ans[i][j]);
		}
		outendl();
	}
	return 0;
}


Measured memory_bytes: 1536
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])

    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i + j)

    print(ans)
main()

Measured memory_bytes: 47340
// #include <bits/stdc++.h>
// using namespace std;
// const double PI = acos(-1);
// const double e = 1e-7;
// double a, b, x;
// double f(double xx) {
// 	return a * a * b - a * a * a * cos(xx * PI / 180.0) / (sin(xx * PI / 180.0) * 2) - x;
// }
// int main () {
// 	cin >> a >> b >> x;
// 	// double ans = 2.0 * b / a - 2.0 * x / (a * a * a);
// 	// double ans = (a * a * b - x) * 2.0 / (a * a * a);
// 	// cout << ans << endl;
// 	// ans = 90.0 - atan(1.0 / ans) / PI * 180.0;
// 	// printf("%.10f\n", ans);
// 	double zuo = 0; double you = 90;
// 	// cout <<  f(45) << endl;
// 	while(1) {
// 		double temp = (zuo + you) / 2.0;
// 		if(fabs(f(temp) - 0.0) < 1e-7) {
// 			printf("%.10f\n", temp);
// 			return 0;
// 		}
// 		if(f(temp) > 0.0) {
// 			you = temp;
// 		}
// 		else if(f(temp) < 0.0) {
// 			zuo = temp;
// 		}
// 	}
// }

// #include <bits/stdc++.h>
// using n
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int main()
{
	double a, b, x;
	cin >> a >> b >> x;
	double v = a * a * b;
	double ans;
	if(x >= (v / 2))
		ans = atan(2.0 * (v - x) / (a * a) / a) * 180.0 / PI;
	else if(x < (v / 2))
		ans = atan(b / (2.0 * x / (a * b))) * 180 / PI;
	printf("%.10f\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    string S;
    int Q;
    cin >> S >> Q;
    bool flip = false;
    string head;
    string tail;
    for (int i = 0; i < Q; ++i) {
        int T;
        cin >> T;
        if (T == 1) flip = !flip;
        else {
            int F;
            cin >> F;
            if (F == 1) {
                char C;
                cin >> C;
                if (flip) tail += C;
                else head += C;
            }
            if (F == 2) {
                char C;
                cin >> C;
                if (flip) head += C;
                else tail += C;
            }
        }
    }
    if (flip) {
        reverse(tail.begin(), tail.end());
        reverse(S.begin(), S.end());
        cout << tail + S + head << endl;
    } else {
        reverse(head.begin(), head.end());
        cout << head + S + tail << endl;
    }
    return 0;
}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(3*n);
    REP(i,3*n) cin >> a[i];
    sort(a.rbegin(),a.rend());
    ll ans = 0;
    for(int i = 1; i < 2*n+1; i += 2) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;



int main() {
	int n;
	string s;
	cin >> n >> s;

	string abc = "abcdefghijklmnopqrstuvwxyz";
	ll ans = 1;
	rep(i, abc.size()) {
		ll cnt = 1;
		rep(j, s.size()) {
			if (abc[i] == s[j]) cnt++;
		}
		ans *= cnt;
		ans = ans % MOD;
	}
	ans--;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
from itertools import product
H,W=map(int,input().split())
S=[input() for i in range(H)]

isOK=True

for y,x in product(range(H),range(W)):
    if S[y][x]=='.':
        continue
    sum=0

    if 0<x:
        if S[y][x-1]=='#':sum+=1
    
    if x<W-1:
        if S[y][x+1]=='#':sum+=1
    
    if 0<y:
        if S[y-1][x]=='#':sum+=1
    
    if y<H-1:
        if S[y+1][x]=='#':sum+=1
    
    if sum==0:
        isOK=False

if isOK:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
using Set = multiset<long>;

bool is_prime (long n) {
  if (n == 1) return false;
  if (n == 2) return true;
  if (n == 3) return true;

  long sqrtn = sqrt(n);

  for (long i = 2; i < sqrtn + 1; i++) {
    if (n % i == 0) return false;
  }

  return true;
}

Set get_prime_factors (long n) {
  long sqrtn = sqrt(n);
  Set prime_factors;

  for (long i = 1; i < sqrtn + 1; i++) {
    if (n % i != 0) continue;

    long I = n / i;

    if (is_prime(i)) prime_factors.insert(i);
    if (is_prime(I)) prime_factors.insert(I);
  }

  return prime_factors;
}

int main () {
  long A, B;
  cin >> A >> B;

  Set p1 = get_prime_factors(A);
  Set p2 = get_prime_factors(B);
  Set S;

  set_intersection(
    p1.begin(), p1.end(),
    p2.begin(), p2.end(),
    inserter(S, S.end())
  );

  S.insert(1);

  cout << S.size() << endl;
}

/*
$A$と$B$の公約数の集合を$R$とおき，$A$と$B$の共通の素因数の集合と$\{1\}$との和集合を$S$とおく。
すなわち，たとえば$A = 12, B = 18$のときは，
\[
    R = \{1, 2, 3, 6\}, S = \{1, 2, 3\}
\]
である。

$R$の部分集合でその要素が対ごとに素であるような集合を「問題の集合」と呼ぶことにし，
「問題の集合」のうち要素の個数が最大のものを$R_0$とおくと，
$R_0$の要素の個数が求める値である。

$R, S$に対して次が成り立つ：
\begin{quote}
    性質 i) $S \subset R$ \\
    性質 ii) $R$に含まれる任意の合成数$c$について，$c$の素因数はすべて$S$に含まれる
\end{quote}

性質 i)について，$p \in S$ならば$p$は$A$も$B$も割り切るので$p \in R$，ゆえに$S \subset R$である。

性質 ii)について，$R$に含まれる任意の合成数$c$とその任意の素因数$p$をとると，
$p$が$c$を割り切ることと，$c$が$A$も$B$も割り切ることから，$p$は$A$も$B$も割り切る。
したがって$p$は$A$と$B$の共通の素因数なので，$p \in S$である。
よって性質 ii)が成り立つ。

ここで，$R_0$に合成数$c$が含まれると仮定すると，
$R_0$から$c$を除いて代わりに$c$の素因数を含めた集合を$R_0'$とおけば，
性質 ii)によって$R_0'$もまた「問題の集合」であるが，その要素の個数は$R_0$より多いので，
$R_0$の定義に矛盾する。よって$R_0$は合成数を含まない。

したがって，$R_0$は$R$に含まれる素因数の集合と$\{1\}$との和集合であり，
性質 i)によって$R_0 = S$である。
*/


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

int main(){

string a,b,s;
int n,cou;
int max = 0;

  cin >> n;
  cin >> s;

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

    a = s.substr(0,i);
    b = s.substr(i,n-i);


    set<char> sa(a.begin(), a.end());
    set<char> sb(b.begin(), b.end());
    vector<char> va(sa.begin(), sa.end());


    for(int j=0;j<va.size();j++){
      if(sb.count(va[j])>0){
        cou+=1;

      }
    }
    if(max<cou){
      max = cou;
    }
    cou = 0;

  }

cout << max << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(),x.end()
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define PI 3.1415926535897932384626
#define mod 1000000007
#define modd 998244353

void io() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	io();
	
	string s,t;
	cin>>s>>t;
	int n = s.size(), m = t.size(), ans = 0;
	for(int i=0;i+m-1<n;i++) {
		int cnt = 0;
		for(int j=0;j<m;j++) {
			if(t[j] == s[i+j]) cnt++;
		}
		ans = max(ans,cnt);
	}
	cout<<m-ans;
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    string s;
    while(cin >> s && !(s=="-")){
        int m;
        cin >> m;
        int h[m];
        F(i,0,m) cin >> h[i];
        F(i,0,m){
            string t;
            F(j,0,h[i]) t+=s[j];
            F(j,0,s.size()-h[i]) s[j]=s[j+h[i]];
            F(j,0,h[i]) s[s.size()-h[i]+j]=t[j];
        }
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3224
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[300];
int cha(int q,int p){
    int tq=max(a[q],-a[q]);
    int tp=max(a[p],-a[p]);
    if(tq>tp)
        return p;
    else
        return q;
}
int main(){
    int n,l;
    while(~scanf("%d%d",&n,&l)){
        for(int i=1;i<=n;i++)
            a[i]=l+i-1;
        int s=a[1],t=1;
   //     printf("%d\n",a[1]);
        for(int i=2;i<=n;i++){
     //           printf("%d\n",a[i]);
            s+=a[i];
            t=cha(i,t);
        }
        s-=a[t];
        printf("%d\n",s);
    }
}


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

using namespace std;

using pll = pair<long long, long long>;
bool cmp(pll a, pll b) {
  return a.second < b.second;
}

int main() {
  int n;
  vector<pll> v;

  cin >> n;

  v.resize(n);

  for (int i = 0; i < n; ++i) {
    cin >> v[i].first >> v[i].second;
  }

  sort(v.begin(), v.end(), cmp);

  bool enable = true;
  long long sum_time = 0;
  for (int i = 0; i < n; ++i) {
    sum_time += v[i].first;
    if (sum_time > v[i].second) {
      enable = false;
    }
  }
  if (enable) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main()
{
    string str;
    cin >> str;

    string stra = "A";
    string strz = "Z";
    int start, finish;
    for(int i=0;i<str.length();i++){
        if(str.compare(i,1,stra)==0){
            start = i;
            break;
        }
    }
    for(int i=str.length();i>=0;i--){
        if(str.compare(i,1,strz)==0){
            finish = i;
            break;
        }
    }

    cout << finish - start + 1 << endl;

    return 0;
}

Measured memory_bytes: 832
#include<stdio.h>
int main(void) {
    int a, b, c;
    int tmp;
    scanf("%d %d %d", &a, &b, &c);
    if(a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    if(b > c) {
        tmp = b;
        b = c;
        c = tmp;
    }
    if(a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    printf("%d %d %d\n", a, b, c);
    
    return 0;
}



Measured memory_bytes: 2056
#include <stdio.h>
#define swap(X, Y) {int Z; Z = Y; Y = X ; X = Z }
int main(){
	int a, i =1;
	
	while(true)
	{
		scanf("%d", &a);
		if(a ==0){
			break;
		}
		printf("Case %d: %d\n", i++,a);
	}
	return 0;
}



Measured memory_bytes: 2668
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
s, t = LI()
G = [[] for _ in range(n)]
for i in range(m):
    a, b, c = LI()
    G[a - 1] += [(b - 1, c)]
    G[b - 1] += [(a - 1, c)]


def dijkstra(graph, start=0):
    route_cnt = [start] * n
    route_cnt[start] = 1
    que = [(0, start)]
    dist = [INF] * n
    dist[start] = 0
    while que:
        min_dist, u = heappop(que)
        if min_dist > dist[u]:
            continue
        for v, c in graph[u]:
            if dist[u] + c < dist[v]:
                dist[v] = dist[u] + c
                route_cnt[v] = route_cnt[u]
                heappush(que, (dist[u] + c  , v))
            elif dist[u] + c == dist[v]:
                route_cnt[v] = (route_cnt[v] + route_cnt[u]) % mod
    return route_cnt, dist


route_cnt, dist = dijkstra(G, s - 1)
r_route_cnt, r_dist = dijkstra(G, t - 1)
total_dist = dist[t - 1]
ret = 0
for i in range(n):
    if dist[i] == r_dist[i]:
        ret = ret + (route_cnt[i] * r_route_cnt[i] % mod) ** 2 % mod


for u in range(n):
    for v, c in G[u]:
        if dist[u] < total_dist / 2 < dist[v] and dist[u] + c + r_dist[v] == total_dist:
            ret = (ret + route_cnt[u] ** 2 % mod * r_route_cnt[v] ** 2 % mod) % mod


print((route_cnt[t - 1] ** 2 - ret) % mod)

Measured memory_bytes: 120224
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define sz(x) (int) x.size()
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<str> vstr;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

//

int32_t main() {
  FAST_IO;
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (true) {
    c -= b;
    if (c <= 0) {
      cout << "Yes";
      rtn 0;
    }
    a -= d;
    if (a <= 0) {
      cout << "No";
      rtn 0;
    }
  }
  rtn 0;
}


Measured memory_bytes: 3576
#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
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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; }

/* 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(){
    int a, b ,t;
    cin >> a >> b >> t;
    cout << b * (t / a) << endl;
}



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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,t,a[3003],b[3003],dp[3003][3003][2];
int go(int pos,int tim,int f){
    if(pos==n+1) return 0;
    int &ans=dp[pos][tim][f];
    if(ans!=-1) return ans;
    ans=go(pos+1,tim,f);
    if(f==0) ans=max(ans,go(pos+1,tim,1)+b[pos]);
    if(a[pos]<=tim) ans=max(ans,go(pos+1,tim-a[pos],f)+b[pos]);
    return ans;
}
void solve(){
    cin>>n>>t;
    rep(i,1,n+1) cin>>a[i]>>b[i];
    memset(dp,-1,sizeof dp);
    cout<<max(go(1,t,1),go(1,t-1,0))<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 71420
#!/usr/bin/env python3

s = int(input().split()[0])
s_list = []
n = 1
a = s
i = 2
s_list.append(a)

while True:
    a = a // 2 if a % 2 == 0 else 3 * a + 1
    if a in s_list:
        break
    s_list.append(a)
    i += 1

ans = i
print(ans)


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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)

constexpr int mod = 1e9+7;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }
  int dp[3] = {0};
  ll ans = 1;
  REP(i, N){
    int cnt = 0;
    int id = 0;
    REP(j, 3){
      if(dp[j] == A[i]){
        cnt++;
        id = j;
      }
    }
    ans *= cnt;
    ans %= mod;
    dp[id]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import itertools
import numpy as np
n = int(input())
dic_ = {}
for i in range(n):
    m = int(input())
    for j in range(m):
        x, y = map(int, input().split())
        dic_[(i,x)] = y

ok = []
for i in itertools.product([0,1],repeat=n):
    for k in dic_.keys():
        if i[k[0]] == 0:
            continue
        if dic_[k] != i[k[1]-1]:
            break
    else:
        ok += [i]
mm = 0
for i in ok:
    mm = max(mm, sum(i))
print(mm)

Measured memory_bytes: 17888
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub fn shift_ascii_uppercase_char(ch: char, n: usize) -> char {
    assert!(ch.is_ascii_uppercase());
    let base = 0x41_u8;
    let m = 26;
    let offset = (ch as u8 - base + (n % m) as u8) % m as u8;
    char::from(base + offset)
}

fn solve() {
    input! {
        n: usize,
        s: Chars
    };

    let res = s
        .into_iter()
        .map(|ch| shift_ascii_uppercase_char(ch, n))
        .join("");
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

typedef long long ll;

ll n, a, b;

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

    if (n < 1){
        cout << 0 << endl;
    } else if (n == 1){
        if (a != b){
            cout << 0 << endl;
        } else {
            cout << 1 << endl;
        }
    } else {
        if (a > b){
            cout << 0 << endl;
        } else {
            // 分割数の話かと思ったけど、合計になりうる数のみをカウントすればよい
            cout << (b-a)*(n-2) + 1 << endl;
        }
    }
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")

#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int H, W;
int A, B;

int main() {
	cin >> H >> W >> A >> B;
	int a;
	REP(i, H) {
		if (i < B) {
			a = 0;
		}
		else {
			a = 1;
		}
		REP(j, W) {
			//とりあえずj < Aのとき0を出力
			//それ以外のとき 1を出力
			if (j < A) {
				cout << a;
			}
			else {
				cout << 1 - a;
			}
		}
		cout << endl;
	}
}

/*
4 3 1 2
*/

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

int main(void){
  int n, m=0;
  map<int,int> mode; //保存する変数の値,入力された回数
  vector<int> ans;

  for(int i=1; i<=100; i++){ //保存先の確保と初期化
    mode.insert( map<int,int>::value_type(i, 0));
  }

  while(cin >> n){ //入力回数をカウント
    mode[n] += 1;
  }

  for(int i=1; i<=100; i++){ //最も入力が多い数の回数
    m = max( mode[i], m );
  }

  for(int i=1; i<=100; i++){ //最頻値の取り出し
    if(m==mode[i]){
      ans.push_back(i);
    }
  }

  sort(ans.begin(), ans.end());

  for(int i=0; i<ans.size(); i++){
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
  long long n,sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    int count=0;
    long long data;
    cin>>data;
    while(true){
      if(data%2!=0) break;
      data=data/2;
      count++;
    }
    sum+=count;
  }
  cout<<sum<<endl;
  

}


Measured memory_bytes: 256
K = int(input())
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]

print(l[(K-1)])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int a,b;
    cin>>a;
    cin>>b;

    if ( a >= 2*b )
    {
        cout<<a-2*b<<endl;
    }
    else
    {
        cout<<"0"<<endl;
    }
    
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 256