akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int MAX = 2e5 + 10;
const ll mod = 1000000007;

int N;
ll a[MAX], b[MAX];
ll siz[MAX], rhs[MAX], col, vis[MAX];
ll f[MAX], num1, num2;
map<piii, int> mp[2];

piii calc(ll x, ll y) {
    x = abs(x), y = abs(y);
    ll gcd = __gcd(x % y, y);
    return piii{x / y, {x % y / gcd, y / gcd}};
}

int main() {
#ifdef ACM_LOCAL
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
    scanf("%d", &N);
    f[0] = 1;
    for (int i = 1; i <= N; i++) f[i] = 1ll * f[i - 1] * 2 % mod;
    for (int i = 0; i <= N; i++) f[i] = (f[i] - 1 + mod) % mod;
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        scanf("%lld%lld", a + i, b + i);
        if (a[i] == 0 && b[i] == 0) ans++;
        else if (a[i] == 0) num1++;
        else if (b[i] == 0) num2++;
        else {
            piii now = calc(a[i], b[i]), pre = calc(b[i], a[i]);
            int state = 0;
            if (1.0 * a[i] / b[i] > 0) state = 1;
            if (!mp[state].count(now)) {
                mp[state][now] = ++col;
                if (mp[state ^ 1].count(pre))
                    rhs[col] = mp[state ^ 1][pre], rhs[mp[state ^ 1][pre]] = col;
            }
            siz[mp[state][now]]++;
        }
    }
    ll t = (f[num1] + f[num2] + 1) % mod;
    for (int i = 1; i <= col; i++)
        if (!vis[i]) {
            vis[i] = 1;
            if (rhs[i]) {
                vis[rhs[i]] = 1;
                t = t * ((1ll + (f[siz[i]] + f[siz[rhs[i]]]) % mod) % mod) % mod;
            }
            else t = t * ((1ll + f[siz[i]]) % mod) % mod;
        }
    ans = (ans + t) % mod;
    printf("%lld\n", (ans - 1 + mod) % mod);

    return 0;
}


Measured memory_bytes: 23956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
const int M=2e5+10;
int head[N],ver[2*M],nex[2*M],tot=1;
inline void add(int x,int y) {
    ver[++tot]=y,nex[tot]=head[x],head[x]=tot;
}
struct Item{
    bool operator<(const Item &t)const{
        return pos<t.pos;
    }
    int pos,b;
};
Item x[N];
int a[N],pos[N],mp[2*M],vis[N],root;
vector<int> G[N],ans;
bool dfs(int x,int e){
    vis[x]=1;
    for(int i=head[x];i;i=nex[i]){
        int y=ver[i];
        if(!vis[y])dfs(y,i);
    }
    if(x==root)return a[root]==0;
    if(a[x]==1){
        ans.push_back(mp[e]);
        a[ver[e^1]]^=1;
    }
    return true;
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;++i)
        cin>>x[i].pos>>x[i].b;
    sort(x+1,x+1+n);
    for(int i=1;i<=n+1;++i){
        a[i]=x[i-1].b^x[i].b;
        pos[i]=x[i].pos;
    }
    for(int i=1;i<=m;++i){
        int l,r;
        scanf("%d%d",&l,&r);
        int x=lower_bound(pos+1,pos+n+1,l)-pos;
        int y=upper_bound(pos+1,pos+n+1,r)-pos;
        mp[tot+1]=mp[tot+2]=i;
        add(x,y);add(y,x);
    }
    bool f=true;
    for(int i=1;i<=n&&f;++i)
        if(!vis[i]){
            root=i;
            f=dfs(i,0);
        }
    if(f){
        sort(ans.begin(),ans.end());
        printf("%d\n",(int)ans.size());
        for(int x:ans)printf("%d ",x);
    }
    else puts("-1");
    return 0;
}

Measured memory_bytes: 13052
#include<bits/stdc++.h>
#define For(i, j, k) for(int i = j; i <= k; ++i)
#define Forr(i, j, k) for(int i = j; i >= k; --i)
using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') p = -1; c = getchar(); }
	while(isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return x *= p;
}

inline void File() {
	freopen("123.in", "r", stdin);
	freopen("123.out", "w", stdout);
}

const int N = 1e5 + 10, M = 30 + 10;
int n, A[N], tmp[N], m;

int main() {
	n = read();
	For(i, 1, n) {
		int x = read();
		while(x % 2 == 0) x /= 2, ++ A[i];
	}
	sort(A + 1, A + 1 + n);

	int cnt = 0;
	For(i, 1, n + 1 >> 1) {
		tmp[++cnt] = A[i], tmp[++cnt] = A[n + 1 - i];
		if(i == n + 1 - i) -- cnt;
	}

	int flag = 1;
	For(i, 1, n - 1) if(tmp[i] + tmp[i + 1] < 2) flag = 0;
	printf("%s\n", flag ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 1024
fn main() {
    let (x, y): (usize, usize) = (read::<usize>(), read::<usize>());
    let (a, b, c): (usize, usize, usize) = (read(), read(), read());
    let mut ah: BinaryHeap<MinInt> = BinaryHeap::new();
    let mut bh: BinaryHeap<MinInt> = BinaryHeap::new();
    for _ in 0..a {
        let v = read();
        if ah.len() == x {
            if ah.peek().expect("something wrong").v > v {
                continue;
            } else {
                ah.pop();
            }
        }
        ah.push(MinInt { v: v });
    }
    for _ in 0..b {
        let v = read();
        if bh.len() == y {
            if bh.peek().expect("something wrong").v > v {
                continue;
            } else {
                bh.pop();
            }
        }
        bh.push(MinInt { v: v });
    }
    for _ in 0..c {
        let v: usize = read();
        if let (Some(&MinInt { v: va }), Some(&MinInt { v: vb })) = (ah.peek(), bh.peek()) {
            if va < vb && va < v {
                ah.pop();
                ah.push(MinInt { v: v });
            } else if vb < v {
                bh.pop();
                bh.push(MinInt { v: v });
            }
        }
    }

    let mut ans = 0;
    for _ in 0..x {
        ans += ah.pop().expect("wrong").v;
    }
    for _ in 0..y {
        ans += bh.pop().expect("wrong").v;
    }
    println!("{}", ans);
}

#[derive(Debug, PartialEq, Eq)]
struct MinInt {
    v: usize,
}
impl std::cmp::PartialOrd for MinInt {
    fn partial_cmp(&self, other: &MinInt) -> Option<std::cmp::Ordering> {
        other.v.partial_cmp(&self.v)
    }
}
impl std::cmp::Ord for MinInt {
    fn cmp(&self, other: &MinInt) -> std::cmp::Ordering {
        other.v.cmp(&self.v)
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 6396
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()

    total = 0
    now = 0
    for i in a:
        total += abs(now-i)
        now = i
    total += abs(i)
    a.insert(0,0)
    a.append(0)

    ans = []

    for i,k in enumerate(a[1:-1], start=1):
        # print(i,k)

        if a[i-1] <= k and k <= a[i+1] or a[i-1] >= k and  k >= a[i+1]:
            ans.append(total)
        else:
            ans.append(total - abs(k-a[i-1]) - abs(k-a[i+1]) + abs(a[i-1]-a[i+1]))

    for i in ans:
        print(i)




if __name__=="__main__":
    main()


Measured memory_bytes: 21096
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    int k,z,i;
    char s[101];
    cin>>k;
    cin>>s;
    z=strlen(s);

   if(z>k)
    {
        for(i=0;i<k;i++)
        {
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    else
    {
        cout<<s<<endl;
    }
}


Measured memory_bytes: 3672
n = int(input())
grad = []
for i in range(n):
    grad.append(int(input()))
# sorting
grad.sort()


s = sum(grad)
while s % 10 == 0:
    if s == 0:
        break
    if min(grad)% 10 == 0:
        
        for i in grad:
            if i % 10 != 0 :#and i != max(grad):
                
                grad.remove(i)
                
                s = sum(grad)
                break
            else:
                s = 0
    else:
        s = s - min(grad)
        
print(s)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = n / 100;
		int c = n % 100 % 10;
		if (a == c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35620
#include <stdio.h>

typedef struct _node{
    int parent;
    int depth;
    int height;
    int l,r;
}NODE;

void getDepth(NODE node[],int id,int d){
    node[id].depth=d;
    
    if(node[id].l!=-1)getDepth(node,node[id].l,d+1);
    if(node[id].r!=-1)getDepth(node,node[id].r,d+1);
    return;
}
void getHeight(NODE node[],int id,int h){
    if(node[id].height<h)node[id].height=h;
    
    if(node[id].parent!=-1)getHeight(node,node[id].parent,h+1);
    return;
}
int getSibling(NODE node[],int id){
    int p=node[id].parent;
    if(p==-1)return -1;
    
    int l=node[p].l;
    int r=node[p].r;
    
    if(l==id&&r!=-1)return r;
    else if(r==id&&l!=-1)return l;
    else return -1;
}
int getDegree(NODE node[],int id){
    int l=node[id].l;
    int r=node[id].r;
    
    if(l!=-1&&r!=-1)return 2;
    else if(l!=-1||r!=-1)return 1;
    else return 0;
}
void printNode(NODE node[],int n){
    int i;
    for(i=0;i<n;i++){
        printf("node %d: parent = %d,",i,node[i].parent);
        printf(" sibling = %d, degree = %d,",getSibling(node,i),getDegree(node,i));
        printf(" depth = %d, height = %d, ",node[i].depth,node[i].height);
        if(node[i].parent==-1)printf("root\n");
        else if(node[i].height==0)printf("leaf\n");
        else printf("internal node\n");
    }
    return;
}
int main(void){
    int i;
    
    int n;
    scanf("%d\n",&n);
    
    NODE node[n];
    for(i=0;i<n;i++){
        node[i].parent=-1;
        node[i].depth=-1;
        node[i].height=-1;
        node[i].l=-1;
        node[i].r=-1;
    }
    
    int id,l,r;
    for(i=0;i<n;i++){
        scanf("%d %d %d\n",&id,&l,&r);
        node[id].l=l;
        node[id].r=r;
        if(l!=-1)node[l].parent=id;
        if(r!=-1)node[r].parent=id;
    }
    
    int root;
    for(root=0;root<n;root++)if(node[root].parent==-1)break;
    node[root].depth=0;
    
    getDepth(node,root,0);
    
    for(i=0;i<n;i++){
        if(node[i].l==-1&&node[i].r==-1)getHeight(node,i,0);
    }
    
    printNode(node,n);
    
    return 0;
}


Measured memory_bytes: 2104
#include<math.h>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<stdio.h>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include <iostream>
#include <limits.h>
using namespace std;

#define ull unsigned long long
#define pp pair<ull,ull>
const ull MAXN = 4233;
#define vecu vector<ull>
#define vevi vector<int>
#define vecp vector<pp >
const ull HASH_P1 = 4003;
const ull HASH_P2 = 4007;
const ull HASH_MOD1 = 1000247;
const ull HASH_MOD2 = 1000000037;
#define hash1(x,b) (((ull)x * HASH_P1 + b)%HASH_MOD1)
#define hash2(x,b) (((ull)x * HASH_P2 + b)%HASH_MOD2)
#define next_hash(tmp,b) (make_pair(hash1(tmp.first,b),hash2(tmp.second,b)))
#define add_hash(tmp,b) (make_pair((tmp.first + hash_hex[idx(b)].first) % HASH_MOD1,(tmp.second + hash_hex[idx(b)].second) % HASH_MOD2))
#define sub_hash(tmpa,tmpb) (make_pair((tmpa.first + HASH_MOD1 - tmpb.first) % HASH_MOD1 , (tmpa.second + HASH_MOD2 - tmpb.second)%HASH_MOD2 ) )
#define idx(x) (x-'a')


char str1[MAXN];
char str2[MAXN];
int str1_len,str2_len;
pp hash_hex[MAXN];
pp str1_hash[MAXN];
pp str2_hash[MAXN];

vecu hash_table[HASH_MOD1];
inline bool find_key(ull idx,ull key){
    int len = hash_table[idx].size();
    for(int i=0;i<len;++i){
        if(hash_table[idx][i] == key)return true;
    }return false;
}
inline void hash_insert(ull idx,ull key){
    hash_table[idx].push_back(key);
}
inline void hash_clear(ull idx){
    hash_table[idx].clear();
}

inline bool check(int length){
    hash_insert(str1_hash[length-1].first,str1_hash[length-1].second);
    for(int i=length;i<str1_len;++i){
        pp tmp = sub_hash(str1_hash[i],str1_hash[i-length]);
        hash_insert(tmp.first,tmp.second);
    }
    if(find_key(str2_hash[length-1].first,str2_hash[length-1].second))return true;
    for(int i=length;i<str2_len;++i){
        pp tmp = sub_hash(str2_hash[i],str2_hash[i-length]);
        // hash_insert(tmp.first,tmp.second);
        if(find_key(tmp.first,tmp.second))return true;
    }

    hash_clear(str1_hash[length-1].first);
    for(int i=length;i<str1_len;++i){
        pp tmp = sub_hash(str1_hash[i],str1_hash[i-length]);
        hash_clear(tmp.first);
    }

    return false;
}

void init(){

    str1_len = strlen(str1);
    str2_len = strlen(str2);
    str1_hash[0] = hash_hex[idx(str1[0])];
    str2_hash[0] = hash_hex[idx(str2[0])];

    for(int i=1;i<str1_len;++i)str1_hash[i] = add_hash(str1_hash[i-1],str1[i]);
    for(int i=1;i<str2_len;++i)str2_hash[i] = add_hash(str2_hash[i-1],str2[i]);

    int limit = min(str1_len,str2_len);
    int ans = 0;
    for(int i=limit;i;i--){
        if(check(i)){
            ans = i;
            break;
        }
    }
    cout<<ans<<"\n";
}

int main(){
    
    hash_hex[0] = make_pair(1,1);
    for(int i=1;i<233;++i) hash_hex[i] = next_hash(hash_hex[i-1],0);
    // while(gets(str1)&&gets(str2))init();
    while(~scanf("%s %s",str1,str2))init();
    return 0;
}


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

int main()
{
    long long X,Y;
    cin >> X >> Y;

    if (abs(X - Y) <= 1){
        cout << "Brown" << endl;
    }else{
        cout << "Alice" << endl;
    }

    return 0;
}


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

int main()
{
    int n, m, sum;
    cin >> n >> m;
    sum = 0;
    vector<int> vec(n);
    rep(i, n)
    {
        cin >> vec.at(i);
        sum += vec.at(i);
    }

    sort(vec.begin(), vec.end(), greater<int>());

    int a = vec.at(m-1) ;
    if(4*m*a<sum)
    {
        cout << "No" << endl ;
    }
    else
    {
        cout << "Yes" << endl ;
    }
    
}

Measured memory_bytes: 3616
#include<map>
#include<queue>
#include<cstdio>
#include<vector>

#define	mp			make_pair
#define	pb			push_back
#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

typedef	vector<int>		vi;
typedef	vector<vi>		vvi;
typedef	pair<int,int>	pii;

const int INF=1<<29;

int main(){
	for(int n,T=0;scanf("%d",&n),n;T++){
		vvi adj(n),revadj(n);
		int s,g,m;	scanf("%d%d%d",&s,&g,&m);
		s--,g--;
		map<pii,int> road;
		rep(i,m){
			int a,b;	scanf("%d%d",&a,&b);
			a--,b--;
			if(a==b || road.count(mp(a,b))>0)	continue;
			adj[a].pb(b);
			revadj[b].pb(a);
			road[mp(a,b)]=i+1;
		}

		int ans,ians;
		vvi dmin(n,vi(2,INF));	dmin[s][0]=0;
		vvi rmin(n,vi(2,INF));	rmin[s][0]=0;
		priority_queue< pair<pii,int>,vector< pair<pii,int> >,greater< pair<pii,int> > > pq;
		pq.push(mp(mp(0,0),s));
		while(!pq.empty()){
			pair<pii,int> a=pq.top();	pq.pop();
			int dis=a.first.first,roadid=a.first.second,u=a.second;
			bool rev=(bool)roadid;
			if(u==g){ ans=dis,ians=roadid; break; }
			if(mp(dmin[u][rev],rmin[u][rev])<mp(dis,roadid))	continue;

			rep(i,adj[u].size()){
				int v=adj[u][i];
				if(mp(dis+1,roadid)<mp(dmin[v][(bool)roadid],rmin[v][rev])){
					dmin[v][rev]=dis+1;
					rmin[v][rev]=roadid;
					pq.push(mp(mp(dis+1,roadid),v));
				}
			}
			if(!rev){
				rep(i,revadj[u].size()){
					int v=revadj[u][i],nextroadid=road[mp(v,u)];
					if(mp(dis+1,nextroadid)<mp(dmin[v][1],rmin[v][1])){
						dmin[v][1]=dis+1;
						rmin[v][1]=nextroadid;
						pq.push(mp(mp(dis+1,nextroadid),v));
					}
				}
			}
		}

		printf("%d %d\n",ans,ians);
	}

	return 0;
}

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

const int N = 1e2 + 5;
const int V = 1e5 + 5;
const int INF = 1e9;

int w[N], v[N];
ll dp[N][V];
int n, wt;

ll solve(int i, int cv) {
  if (cv <= 0)
    return 0;
  if (i == n)
    return INF;
  if (dp[i][cv] != -1)
    return dp[i][cv];
  dp[i][cv] = min(solve(i+1, cv), w[i] + solve(i+1, cv - v[i]));
  return dp[i][cv];
}

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  for (int i = 0; i < N; i++)
    for (int j = 0; j < V; j++)
      dp[i][j] = -1;
  cin >> n >> wt;
  int mxv = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
    mxv += v[i];
  }
  int ans = -INF;
  for (int i = mxv; i >= 0; i--) {
    if (solve(0, i) <= wt) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 82304
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    //final List<Integer> list = new ArrayList<>();
    //final List<Integer> list2 = new ArrayList<>();
    //final List<Long> list3 = new ArrayList<>();

    String s = sc.next();
    int count1 = 0;
    int count2 = 0;

    for(int i = 0; i < s.length(); i++){
        if(s.charAt(i) == '0'){
            count1++;
        }else{
            count2++;
        }
    }

    System.out.println(Math.min(count1, count2)*2);
    

    




    







}
}

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

long long p;
long long a[3000], s[3000], t[3000], b[3000];

int main()
{
	cin >> p;

	for (long long i = 0; i < p; i++)
		cin >> a[i];

	for (long long i = 0; i < p; i++)
		b[i] = 0;

	s[0] = 1;
	t[0] = 1;

	for (long long i = 1; i < p; i++) {
		s[i] = s[i - 1] * i % p;

		long long j = s[i], k = 1;

		while (k < (p - 2) / 2) {
			j = j * j % p;
			k *= 2;
		}

		while (k < p - 2) {
			j = j * s[i] % p;
			k++;
		}

		t[i] = j;
	}

	for (long long i = 0; i < p; i++) {
		if (a[i] == 1) {
			b[p - 1] = (b[p - 1] - 1 + p) % p;

			if (i == 0)
				b[0] = (b[0] + 1) % p;
			else {
				long long u = i, v = 1;

				while (v < (p - 2) / 2) {
					u = u * u % p;
					v *= 2;
				}

				while (v < p - 2) {
					u = u * i % p;
					v++;
				}

				long long w = u;

				for (long long j = 1; j < p - 1; j++) {
					if (j % 2 == 0)
						b[j] = (b[j] - s[p - 1] * t[j] % p * t[p - 1 - j] % p * w + p) % p;
					else
						b[j] = (b[j] + s[p - 1] * t[j] % p * t[p - 1 - j] % p * w) % p;

					w = w * u % p;
				}
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 512
while True:

    n,x = [int(r) for r in input().split()]

    if n == x ==0:
      break

    count =0
    for s in range(1,n-1):
        for m in range(s+1,n):
            for e in range(m+1,n+1):
                if x ==sum([s,m,e]):
                    count+= 1

    print(count)

Measured memory_bytes: 7720
N, M = map(int, input().split())

# if N is odd
if M & 1:
    odd_head = 1
    odd_tail = M + 1
    even_head = M + 2
    even_tail = M + 2 + M - 1
    while odd_tail - odd_head > 0:
        print(odd_head, odd_tail)
        odd_head += 1
        odd_tail -= 1

    while even_tail - even_head > 0:
        print(even_head, even_tail)
        even_head += 1
        even_tail -= 1

else:
    odd_head = 1
    odd_tail = 1 + (M - 1)
    even_head = M + 1
    even_tail = M + 1 + M
    while odd_tail - odd_head > 0:
        print(odd_head, odd_tail)
        odd_head += 1
        odd_tail -= 1

    while even_tail - even_head > 0:
        print(even_head, even_tail)
        even_head += 1
        even_tail -= 1

Measured memory_bytes: 9172
# Problem - サイコロⅢ

t, s, e, w, n, b = map(int, input().split())
t_2, s_2, e_2, w_2, n_2, b_2 = map(int, input().split())

# initialization
dice_dic = {}
dice_dic[t] = {s:e, e:n, n:w, w:s}
dice_dic[b] = {n:e, w:n, s:w, e:s}
dice_dic[s] = {e:t, t:w, w:b, b:e}
dice_dic[n] = {t:e, e:b, b:w, w:t}
dice_dic[e] = {s:b, b:n, n:t, t:s}
dice_dic[w] = {s:t, t:n, n:b, b:s}

dice_dic_2 = {}
dice_dic_2[t_2] = {s_2:e_2, e_2:n_2, n_2:w_2, w_2:s_2}
dice_dic_2[b_2] = {n_2:e_2, w_2:n_2, s_2:w_2, e_2:s_2}
dice_dic_2[s_2] = {e_2:t_2, t_2:w_2, w_2:b_2, b_2:e_2}
dice_dic_2[n_2] = {t_2:e_2, e_2:b_2, b_2:w_2, w_2:t_2}
dice_dic_2[e_2] = {s_2:b_2, b_2:n_2, n_2:t_2, t_2:s_2}
dice_dic_2[w_2] = {s_2:t_2, t_2:n_2, n_2:b_2, b_2:s_2}

is_ok = True

for k in dice_dic:
    for k_2 in dice_dic[k]:
        if k_2 in dice_dic_2[k]:
            if not dice_dic[k][k_2]==dice_dic_2[k][k_2]:
                is_ok = False
                break
        else:
            is_ok = False
            break

# output
if is_ok:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5620
def solve():
    N, A = map(int, input().split())
    x = [int(i) for i in input().split()]
     
    lim = sum(x)
    dp = [[0]*(lim + 1) for i in range(N + 1)]
     
    dp[0][0] = 1
     
    for i in range(N):
        for k in range(i + 1, 0, -1):
            for v in range(lim, x[i] - 1, -1):
                dp[k][v] += dp[k - 1][v - x[i]]
     
    ans = 0
     
    for k in range(1, N + 1):
        if k*A > lim:
            break
        ans += dp[k][k*A]
     
    print(ans)
 
if __name__ == '__main__':
    solve()

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

int main()
{
    int n, k, q, a;
    cin >> n >> k >> q;
    vector<int> N(n, 0);
    for (size_t i = 0; i < q; i++)
    {
        cin >> a;
        N[a - 1]++;
        /* code */
    }
    for (size_t i = 0; i < n; i++)
    {
        if (k - q + N[i] <= 0)
        {
            cout << "No" << endl;
        }
        else
        {
            cout << "Yes" << endl;
        }
    }

    return 0;
}

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

int main(){
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if (a == 0)
  {
    cout << 1 << endl;
  }

  if (b == 0)
  {
    cout << 2 << endl;
  }
  
    if (c == 0)
  {
    cout << 3 << endl;
  }
  
  if (d == 0)
  {
    cout << 4 << endl;
  }
  if (e == 0)
  {
    cout << 5 << endl;
  }
  
}

Measured memory_bytes: 3628
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): 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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class Sieve:
    def __init__(self, n):
        self.plist = [2]  # n以下の素数のリスト
        min_prime_factor = [2, 0] * (n // 2 + 5)
        for x in range(3, n + 1, 2):
            if min_prime_factor[x] == 0:
                min_prime_factor[x] = x
                self.plist.append(x)
                if x ** 2 > n: continue
                for y in range(x ** 2, n + 5, 2 * x):
                    if min_prime_factor[y] == 0:
                        min_prime_factor[y] = x
        self.min_prime_factor = min_prime_factor

    def isprime(self, x):
        return self.min_prime_factor[x] == x

    # これが素因数分解(prime factorization)
    def pfct(self, x):
        pp, ee = [], []
        while x > 1:
            mpf = self.min_prime_factor[x]
            if pp and mpf == pp[-1]:
                ee[-1] += 1
            else:
                pp.append(mpf)
                ee.append(1)
            x //= mpf
        return pp

mx=10**6+5
n=II()
aa=LI()
sv=Sieve(mx)
use=[0]*mx
ispair=True
for a in aa:
    pp=sv.pfct(a)
    for p in pp:
        if use[p]:ispair=False
        use[p]+=1
if ispair:print("pairwise coprime")
elif max(use)<n:print("setwise coprime")
else:print("not coprime")


Measured memory_bytes: 210076
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <set>
using ll = long long;
using namespace std;
#define INF 999999999

int main()
{
    int N;
    cin >> N;
    int tmp;
    int m = 0;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        sum += tmp;
        m = max(m, tmp);
    }
    if (sum > 2 * m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;


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

	long long a, b, c, aa, bb;
	cin >> a >> b >> c;
	aa = 4 * a * b;
	bb = (c - a - b) * (c - a - b);

	if ((aa < bb) && (c - a - b > 0)) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass

n,r = i2()
print(r if n >= 10 else r+100*(10-n))



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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head


int dp(int n, vector<int>& memo, vector<int>& heights) {

    if (n == 2)
        return abs(heights[2] - heights[1]);
    else if (n == 1)
        return 0;
    else if (memo[n] == INT_MIN)
        return memo[n] = min(abs(heights[n] - heights[n-1]) + dp(n-1,memo,heights), abs(heights[n] - heights[n-2]) + dp(n-2,memo,heights));
    
    return memo[n];
}


int main()
{
    int n = 0;
    cin >> n;

    vector<int> heights(n+1);
    vector<int> memo(n+1,INT_MIN);

    for (long unsigned int i = 0; i < n; i++) {
        int num = 0;
        cin >> num;
        heights[i+1] = num;
    }

    cout << dp(n,memo,heights);

    return 0;
}


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

typedef vector<pair<int,int>> vpii;

int main(){
  int N;
  vpii AB(200010);

  cin >> N;
  for(int i=0; i<N; i++) cin >> AB[i].second >> AB[i].first;

  sort(AB.begin(), AB.begin()+N);

  int cur = 0;
  for(int i=0; i<N; i++){
    cur += AB[i].second;
    if(cur > AB[i].first){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
from collections import deque

n, m = map(int, input().split())
rooms = [[] for i in range(n + 1)]

for i in range(m):
    a, b = map(int, input().split())
    rooms[a].append(b)
    rooms[b].append(a)

q = deque()
q.append(1)
sign = [-1]*(n + 1)
sign[1] = 0

while q:
    rnum = q.popleft()
    for i in rooms[rnum]:
        if sign[i] == -1:
            sign[i] = rnum
            q.append(i)

print("Yes")

for i in sign[2:]:
    print(i)

Measured memory_bytes: 34936
def solve():
    dp = [0] * (N+1)
    dp[0] = 1
    for i in range(N):
        for j in range(i+1, min(N,i+2)+1):
            if broken[j]:
                dp[j] += dp[i]
                dp[j] %=  1000000007
    print(dp[-1])

if __name__ == "__main__":
    N,M = list(map(int, input().split()))
    broken = [True] * (N+1)
    for i in range(M):
        a = int(input())
        broken[a] = False
    solve()  


Measured memory_bytes: 13408
#include<iostream>
using namespace std;
int main (void){
	string S,S2="AKIHABARA";
	cin>>S;
	int p1,p2;
	p1=p2=0;
	if (S.size()>S2.size()){
		cout<<"NO"<<endl;
		return 0;
	}
	while (p1!=S.size()&&p2!=S2.size()){
		while (p1!=S.size()&&p2!=S2.size()&&S[p1]==S2[p2]) ++p1,++p2;
		while (p2!=S2.size()&&S2[p2]=='A') ++p2;
		if (p1==S.size()&&p2==S2.size()){
			cout<<"YES"<<endl;
			return 0;
		}
		if (S[p1]!=S2[p2]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

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

using namespace std;

int main()
{
	vector<string> input;
	while (true)
	{
		string s;
		cin >> s;
		if (s == "-")
		{
			break;
		}
		else
		{
			input.push_back(s);

			int n;
			cin >> n;
			for (int i = 0; i < n; i++)
			{
				int r;
				cin >> r;
				input.back() = input.back() + input.back();
				string temp;
				for (int j = 0; j != input.back().size(); j++)
				{
					if (r <= j&&j < (input.back().size() / 2 + r))
					{
						temp += input.back()[j];
					}
				}
				input.back() = temp;
			}
		}
	}

	for (auto& s : input)
	{
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3184
# -*- coding: utf-8 -*-

import Queue

def output_frame(w):
    f = ""
    for i in range(w+2):
        f += "#"
    return f

H,W = map(int, raw_input().split())
q_str = Queue.Queue()
for i in range(H):
    q_str.put(raw_input())

print output_frame(W)
while not q_str.empty():
    print "#" + q_str.get() + "#"
print output_frame(W)


Measured memory_bytes: 3052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????


//InputStreamReader isr = new InputStreamReader(System.i//n);
	int ave,sum=0;
	Scanner sc = new Scanner(System.in);
	int[] data=new int[10];
	for(int i=0;i<5;i++){
		 data[i]=sc.nextInt();
		if(data[i]<40)data[i]=40;
	}
	for(int i=0;i<5;i++){
		sum+=data[i];
	}


	System.out.printf("%d\n", sum/5);



	}

}

Measured memory_bytes: 26100
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
 
ll mymod(ll a, ll b)
{
	return (a%b + b)%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
struct edge
{
	ll src;
	ll to;
	ll val;
	ll index;
};
struct node
{
	vll adj;
	ll parent;
	ll time;
	ll ex_time;
	ll indegree;
};

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;
	return 0;
}




Measured memory_bytes: 256
#include<stdio.h> 
#include<memory.h>
int pa[55],ran[55],sum[55];
struct edge
{
	int a,b;
}x[2505];
int find(int a)
{
	if(pa[a]!=a) pa[a]=find(pa[a]);
	return pa[a];
}
void bing(int a,int b)
{
	a=find(a);
	b=find(b);
	if(a==b) return ;
	if(ran[a]>ran[b]) {
	pa[b]=a;
	sum[a]+=sum[b];}
	else 
	{
		pa[a]=b;
		sum[b]+=sum[a];
		if(ran[a]==ran[b]) ran[b]++;
	}
}
int main()
{
	int n,m,i,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&x[i].a,&x[i].b);
	}
	int cnt=0;
	for(i=1;i<=m;i++)
	{
		memset(ran,0,sizeof(ran));
		ran[1]=0x3f;
		for(j=1;j<=n;j++)
		{
			pa[j]=j;
			sum[j]=1;
		}
		for(int k=1;k<=m;k++)
		{
			if(k==i) continue;
			int a=find(x[k].a);
			int b=find(x[k].b);
			if(a==b) continue;
			else bing(a,b);
		}
		if(sum[1]!=n) cnt++;
	}
	printf("%d\n",cnt);
} 

Measured memory_bytes: 128
//こんなプログラムを組んではいけない(戒め
//マージの仕様が複雑だし、空白マスを引く処理忘れやすいし、ひどいコードだ。
#include<iostream>
#include<queue>
using namespace std;

const int h = 12;
const int w = 12;
const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};

char data[h][w+2];

//データ構造をマージする一般的なテクなし。
class UnionFind {
public:
	int oya[2521], size;
	void ini(int size) { this->size = size; for( int i = 0;i < size; i++ ) oya[i] = i; }
	int root(int x) { if( oya[x] == x ) return x; return (oya[x] = root(oya[x]) ); }
	void marge(int x, int y) { x = root(x); y = root(y); if ( x != y ) { size--; oya[x] = y; } }
}uf;

void bfs(int sy, int sx) {
	queue<int> que;
	que.push(sy*w + sx);
	
	while( !que.empty() ) {
		int now = que.front();
		que.pop();
		
		if ( data[now/w][now%w] == '0' )
			continue;
		if ( uf.root(now) != now ) 	//すでに調べている(マージされている)ならcontinue
			continue;
		
		uf.marge(sy*w + sx, now);	//nowをsy*w + sxにくっつける(の逆をしてみた。無限ループするかも)
		
		for(int i = 0; i < 4; i++ ) {
			int ny = now/w + dy[i];
			int nx = now%w + dx[i];
			if ( 0 <= ny && ny < h && 0 <= nx && nx < w )
				que.push(ny * w + nx);
		}
	}
}

int main() {
	int i, j;
	while( cin >> data[0] ) {
		for( i = 1; i < h; i++ )
			cin >> data[i];
		
		uf.ini(h*w);
		
		int minus = 0;
		for( i = 0; i < h; i++ ) {
			for( j = 0; j < w; j++ ) {
				minus += (data[i][j] == '0');
				bfs(i, j);
			}
		}
		cout << uf.size - minus << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>

#define NMAX 10000

int linearSearch(int[], int, int);

int main(){
  
  int S[NMAX], n, i, q, key;
  int sum = 0;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]); 

  scanf("%d", &q);
  
  for(i = 0; i < q; i++){
    scanf("%d", &key);
    
    if (linearSearch(S, n, key))
      sum++;
  }
  
  printf("%d\n", sum);
  
  return 0;
}

int linearSearch(int S[], int n, int key){
  
  int i = 0;
  S[n] = key;
  
  while(S[i] != key)
    i++;
  
  if(i == n)
    return 0;
  
  else return 1;
}




Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[110000];
main(){
    ll n,m,k,ans=0;
    cin>>n>>m;
    if(n==m)cout<<"Yes";
    else cout<<"No";
    //rep(i,0,n)cin>>a[i];
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int h, w;
  cin >> h >> w;
  char x[h][w];
  char ans[h][w];

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

  int count;
  string s;
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){

      count = 0;
      if (x[i][j] == '#'){
        ans[i][j] = '#';
      }
      else {

        for (int ti = i - 1; ti <= i + 1; ti++){
          for (int tj = j - 1; tj <= j + 1; tj++){

            if ((ti < 0) || (tj < 0) || (h <= ti) || (w <= tj)){
              continue;
            }
            else if (x[ti][tj] == '#'){
              count++;
            }
            else {
              continue;
            }

          }
        }

        s = to_string(count);
        ans[i][j] = s[0];

      }

    }
  }

  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
        cout << ans[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll>Q;


int main(void){
    int a,b;
    cin>>a>>b;
    int x = a*b;
    if(x%2==0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
n= gets.to_i
array_p = gets.split(" ").map(&:to_i)
array_q = gets.split(" ").map(&:to_i)

array = (1..n).to_a

p = array.permutation(n).to_a
a = p.index(array_p)
b = p.index(array_q)

puts (a - b).abs


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

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

int ans=0 ;
for(int i=0 ;i<n ;i++){
    ans += A[i] ;
}
if(A[n-m]*4*m >= ans)
cout<< "Yes" << endl;
else

cout <<"No" <<endl;
}

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

int main() {
  int N,l,r;
  cin >> N;
  int sum = 0;
  for(int i = 0;i < N;i++){
    cin >> l >> r;
    sum = sum + (r - l + 1);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;
#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif


namespace Solver{
using namespace std;

struct Problem{
    int n;
    vector<int> x,y,t;
    Problem(LL n):n(n),x(n+1),y(n+1),t(n+1){};
    void solve(){
        for(int i=1; i<=n; ++i){
            cin >> t[i] >> x[i] >> y[i];
        }
        bool ans =true;
        for(int i=1; i<=n; ++i){
            int dist = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
            int tt = t[i]-t[i-1];
            if(!(tt>=dist and(tt-dist)%2==0))ans =false;
        }
        if(ans)cout << "Yes" <<"\n";
        else cout << "No" << "\n";
    }
};
}

int main(){
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    long long n=0;
    std::cin >> n;
    Solver::Problem p(n);
    p.solve();
    return 0;
}



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

int main()
{
    double l;
    cin >> l;

    // arithmetic-geometric mean 
    // (a*b*c)^(3/1) <= (abc)/3

    printf("%.12f\n",(double) l*l*l/27);
    
    return 0;
}

Measured memory_bytes: 3756
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N,P;
	string S;
	cin>>N>>P>>S;

	int ans=0;
	if(P==2||P==5)
	{
		rep(i,0,SZ(S))
		{
			if((S[i]-'0')%P==0)ans+=i+1;
		}
	}
	else
	{
		int sum=0;
		int b=1;
		map<int,int> vmap;
		vmap[0]++;
		rrep(i,0,SZ(S))
		{
			sum+=(b*(S[i]-'0'));
			sum%=P;
			b*=10;
			b%=P;
			vmap[sum]++;
		}

		for(auto p:vmap)
		{
			ans+=p.second*(p.second-1)/2;
		}
	}

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

Measured memory_bytes: 1044
ans_list = []

while True:
    n,p = map(int,input().split())
    if (n,p) == (0,0):
        break
    table = p
    a = [0]*n
    turn = 0
    while True:
        if table != 0:
            a[turn] += 1
            table -= 1
        else:
            table += a[turn]
            a[turn] = 0
        if a[turn] == p:
            ans = turn
            break
        turn += 1
        turn %= n
    ans_list.append(ans)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 5600
#include <stdio.h>

int main(int argc, char **argv)
{
	int a, b, t;

	scanf("%d%d", &a, &b);
	
	t = a - 2 * b;
	
	if (t > 0)
		printf("%d\n", t);
	else
		printf("0\n");

	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		sc.close();

		int ans = 0;
		int num = 1;
		while(num < B) {
			ans++;
			num = A * ans - (ans - 1);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  map<ll,ll>mp;
  rep(i,0,n){
    cin>>a[i];
    res+=a[i];
    mp[a[i]]++;
  }
  ll q;cin>>q;
  while(q--){
    ll b,c;cin>>b>>c;
    ll cnt=mp[b];
    res-=b*cnt;
    res+=c*cnt;
    mp.erase(b);
    mp[c]+=cnt;
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 7952
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので

# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）
for _ in range(q):
    before, after = map(int, input().split())

    # 合計を変更します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]

    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0

    print(sum_res)

Measured memory_bytes: 24076
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;
const int mod = 1000000007;

struct mint{
  ll x;
  mint(ll x = 0):x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& stream, const mint& n){
  stream << n.x;
  return stream;
};

struct comb{
  vector<mint> fact, ifact;
  comb(int n): fact(n+1), ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k) const noexcept{
    if(k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
};

mint dp[100001][4];

int main(void){
  string s;
  cin >> s;
  ll n = s.size();
  dp[0][0] = 1;
  REP(i, n){
    REP(j, 4){
      dp[i+1][j] += dp[i][j] * ((s[i] == '?') ? 3 : 1);
    }
    if(s[i] == 'A' || s[i] == '?') dp[i+1][1] += dp[i][0];
    if(s[i] == 'B' || s[i] == '?') dp[i+1][2] += dp[i][1];
    if(s[i] == 'C' || s[i] == '?') dp[i+1][3] += dp[i][2];
  }
  cout << dp[n][3] << endl;
  return 0;
}

Measured memory_bytes: 3584