akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define int long long int
#define mp make_pair
using namespace std;

int32_t main() {
    int n;
    scanf("%lld", &n);
    vector<int> v(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
        sum += v[i];
    }
    vector<int> v1(n);
    int sum2 = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v1[i]);
        sum2 += v1[i];
    }
    vector<int> ans(n);

    int sum1 = 0;
    for (int i = 0; i < n; ++i) {
        if(v[i] < v1[i]){
            sum1 += v1[i];
            ans[i] = v1[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        if(ans[i] == 0){
            ans[i] = v[i];
            sum1 += v[i];
        }
    }
    if(sum1 > sum ){
        int adjust = sum1- sum;
        vector<pair <int, int> > ans1;
        for (int i = 0; i < n; ++i) {
            if(ans[i] != v1[i]){
                ans1.push_back(mp(abs(ans[i] - v1[i]) , i));
            }
        }
        sort(ans1.begin(), ans1.end() , greater <pair <int ,int> >());
        for (int i = 0; i < ans1.size(); ++i) {
            int index = ans1[i].second;
            int x1 = ans[index];
            ans[index] -= min(adjust , abs(x1 - v1[index]));
            adjust -= min(adjust , abs(x1 - v1[index]));
        }
        if(adjust != 0){
            printf("-1");
            return 0;
        }
    }
    else if(sum1 < sum){
        int adjust = sum - sum1;
        for (int i = 0; i < n; ++i) {
            if(ans[i] != v[i]){
                ans[i] += adjust;
                break;
            }
        }
    }
    int x = 0 ;
    for (int i = 0; i < n; ++i) {
        if(ans[i] != v[i]){
            x++;
        }
    }
    printf("%lld",x);
    return 0;
}

Measured memory_bytes: 3704
#include <iostream>
using namespace std;
int main(){
    int x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0)cout<<1;
    else if(x2==0)cout<<2;
    else if(x3==0)cout<<3;
    else if(x4==0)cout<<4;
    else if(x5==0)cout<<5;
    return 0;
}

Measured memory_bytes: 3620
import glob
import os

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        x = list(map(int, self.input_data().split()))
        for i in range(5):
            if x[i] == 0:
                print(str(i+1))
                break


solver = Solver(REL_PATH)
solver.exec_resolve()


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

using namespace std;

void shuffle(string &s,int num){
    int len=s.size();
    string temp=s;
    for (int i=num,j=0;j<len;i++,j++){
        temp[j]=s[i%len];
    }
    s=temp;
}

int main(){
    string s;
    vector<string> out;
    do{
        cin>>s;
        if (s!="-"){
            int m;
            cin>>m;
            for (int i=0;i<m;i++){
                int h;
                cin>>h;
                shuffle(s,h);
            }
            out.push_back(s);
        }
    }while (s!="-");
    for (int i=0;i<out.size();i++){
        cout<<out[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1212
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
        int[] x = new int[3];
        for(int i = 0; i < 3; i++){
            x[i] = scn.nextInt();
        }
        Arrays.sort(x);
        System.out.println(x[0]+" "+x[1]+" "+x[2]);
    }
}


Measured memory_bytes: 26252
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    if (n % 2 == 1L) {
        println(0)
        return
    }
    var ans = 0L
    var bunbo = 2L
    while (n > bunbo) {
        bunbo *= 5
        ans += n / bunbo
    }
    println(ans)
}

Measured memory_bytes: 31684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String input = sc.nextLine();
		sc.close();

		int sa = (int)'A' - (int)'a';

		for(char moji : input.toCharArray()) {
			if('a' <= moji && moji <= 'z') {
				System.out.print( (char)((int)moji + sa) );
			} else if('A' <= moji && moji <= 'Z') {
				System.out.print( (char)((int)moji - sa) );
			} else {
				System.out.print(moji);
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 26632
A, B, C = map(int, input().split())
D = [A, B, C]
S = max(D)

ans = 0
l = 0
for i in range(3):
  if (D[i] == S) and (l == 0):
    ans += 10 * D[i]
    l = 1
  else:
    ans += D[i]
    
print(ans)




Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static final String WAR = "War";
    public static final String NO_WAR = "No War";

    public static String process(TestCase testCase) {
        final int X = testCase.X;
        final int Y = testCase.Y;
        final int M = testCase.M;
        final int N = testCase.N;
        final List<Integer> x = testCase.x;
        final List<Integer> y = testCase.y;

        return warOrNoWar(isXSmallerThanY(X, Y), areAllCitiesWithinCondition(X, Y, x, y));
    }

    private static String warOrNoWar(Boolean... conditions) {
        final boolean areAllConditionsSatisfied = Arrays.stream(conditions).allMatch(Boolean::booleanValue);
        return areAllConditionsSatisfied ? NO_WAR : WAR;
    }

    private static boolean isXSmallerThanY(int X, int Y) {
        return X < Y;
    }

    private static boolean areAllCitiesWithinCondition(int X, int Y, List<Integer> x, List<Integer> y) {
        final int xMax = x.stream().mapToInt(i -> i).max().orElseThrow(() -> new IllegalArgumentException("x is empty"));
        final int yMin = y.stream().mapToInt(i -> i).min().orElseThrow(() -> new IllegalArgumentException("y is empty"));

        return xMax < yMin && xMax < Y && X < yMin;
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        List<Integer> x = readList(sc, N);
        List<Integer> y = readList(sc, M);

        return new TestCase(N, M, X, Y, x, y);
    }

    private static List<Integer> readList(Scanner sc, int size) {
        return IntStream.range(0, size)
                .mapToObj(i -> sc.nextInt())
                .collect(Collectors.toList());
    }

    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int N;
        final int M;
        final int X;
        final int Y;
        final List<Integer> x;
        final List<Integer> y;

        public TestCase(int N, int M, int X, int Y, List<Integer> x, List<Integer> y) {
            this.N = N;
            this.M = M;
            this.X = X;
            this.Y = Y;
            this.x = x;
            this.y = y;
        }
    }
}


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

int main() {
    int H, W, ans = 0;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W + 1));
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            cin >> s[i][j];
            if(s[i][j] == '.')
                ++ans;
        }
    }

    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    dist[0][0] = 0;
    int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        for(int i = 0; i < 4; ++i) {
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(nx < 0 || ny < 0 || nx >= W || ny >= H)
                continue;
            if(dist[ny][nx] != -1)
                continue;
            if(s[ny][nx] == '#')
                continue;
            dist[ny][nx] = dist[p.first][p.second] + 1;
            que.push(make_pair(ny, nx));
        }
    }
    cout << (dist[H - 1][W - 1] == -1 ? -1 : ans - dist[H - 1][W - 1] - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
string agct = "AGCT";
vvll dp(101,vll(64,0));
bool agc(int x,int y,int z,int w){
    if((x==0&&y==1&&z==2)||(y==0&&z==1&&w==2)){
        return true;
    }else{
        return false;
    }
}
bool det(int x,int y,int z,int w){
    bool ret = agc(x,y,z,w);
    ret = ret || agc(y,x,z,w);
    ret = ret || agc(x,z,y,w);
    ret = ret || agc(x,y,w,z);
    return ret;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    REP(i,64){
        int x,y,z;
        x = i/16;
        y = (i/4)%4;
        z = i%4;
        if((x==0&&y==1&&z==2)||(x==0&&y==2&&z==1)||(x==1&&y==0&&z==2)){
            dp[3][i]=0;
        }else{
            dp[3][i]=1;
        }
    }
    for(int i=4;i<=n;i++){
        REP(j,64){
            REP(k,4){
                int x = j/16;
                int y = (j/4)%4;
                int z = j%4;
                int w = k;
                int next = y*16+z*4+w;
                if(!det(x,y,z,w)){
                    dp[i][next] += dp[i-1][j];
                    if(dp[i][next]>mod){
                        dp[i][next]-=mod;
                    }
                }
            }
        }
    }
    ll ans=0;
    REP(i,64){
        ans+=dp[n][i];
        if(ans>mod){
            ans-=mod;
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] junin = new int[n];
		for(int i =0;i < n;i++) {
			junin[i] = sc.nextInt();
		}
		int answerKoho = 0;
		int answer = 0;
		for(int i = 1;i <= 100;i++) {
			for(int j =0;j < n;j++) {
				answerKoho += (junin[j] -i) * (junin[j] -i);
			}
			if(answerKoho < answer) {
				answer = answerKoho;
			}
			if(i ==1) {
				answer = answerKoho;
			}
			answerKoho = 0;
		}
		System.out.println(answer);
	}
}

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

int main(){
  int N;
  cin >> N;
  vector <char> S(N);
  for(int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    if(S.at(i) == 'Y'){
      count++;
    }
  }
  if(count != 0){
    cout << "Four" << endl;
  }
  if(count == 0){
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
const int N=(int)1e5;
    vector<int> v[N];
    int was[N];
    int a[N];
    vector<int> d[N];
    int co[N];
    int gwas=0;
bool sss(int x,int y)
{
    if (a[x]!=a[y]) re a[x]<a[y];
    re x<y;
}
bool so(vector<int> &x,vector<int> &y)
{
    if (x.size()!=y.size()) re x.size()>y.size();
    re x[0]<y[0];
}
set<int,bool (*)(int,int)> s1(sss);
set<int,bool (*)(int,int)> s2(sss);
int f(int x)
{
    int i;
    was[x]=1;
    d[gwas].pb(x);
    fo(i,v[x].size())
    {
        if (!was[v[x][i]])
        {
            f(v[x][i]);
        }
    }
}
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    int n,m,c,t;
    cin>>n>>m;
    int i;
    fo(i,n)
    {
        scanf("%d",&a[i]);
    }
    fo(i,m)
    {
        scanf("%d%d",&c,&t);
        v[t].pb(c);
        v[c].pb(t);
    }
    int b;
    fo(i,n)
    {
        if (!was[i])
        {
            f(i);
            gwas++;
        }
    }
    sort(d,d+gwas,so);
    fo(i,d[0].size())
    {
        s1.in(d[0][i]);
        co[d[0][i]]=0;
    }
    int j;
    fr(i,1,gwas)
    {
        fo(j,d[i].size())
        {
            s2.in(d[i][j]);
            co[d[i][j]]=i;
        }
    }
    ll o=0;
    int r;
    fo(i,gwas-1)
    {
        if (s2.empty()||s1.empty())
        {
            cout<<"Impossible\n";
            re 0;
        }
        r=*s2.begin();
        o+=a[*s1.begin()];
        s1.er(s1.begin());
        o+=a[*s2.begin()];
        fo(j,d[co[r]].size())
        {
            s1.in(d[co[r]][j]);
            s2.er(d[co[r]][j]);
        }
        s1.er(r);
    }
    cout<<o<<endl;
    re 0;
}


Measured memory_bytes: 14464
import itertools
M,K=map(int,input().split())

if M==1 and K==1:
  print(-1)
elif K==0:
  ans_list=[]
  for i in range(2**M):
    ans_list.extend([i,i])
  print(*ans_list)
elif K<2**M:
  ans_list=[]
  for i in range(K+1):
    ans_list.append(i)
  for i in reversed(range(K)):
    ans_list.append(i)
  for i in reversed(range(K,2**M)):
    ans_list.append(i)
  for i in range(K+1,2**M):
    ans_list.append(i)
  print(*ans_list)
else:
  print(-1)

Measured memory_bytes: 19456
# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right

N,Q=map(int, sys.stdin.readline().split())

S=[]
event=[]	#x, s, t
for _ in range(N):
	s,t,x=map(int, sys.stdin.readline().split())
	heappush( event, (x, max(0,s-x) , max(0,t-1-x)) )


D=[ int(sys.stdin.readline().strip()) for _ in range(Q) ]
D.sort()
ans=[ float("inf") for _ in range(Q) ]

Next=[ i+1 for i in range(Q) ]	#Next


while event:
	x,s,t=heappop(event)
	start=bisect_left(D,s)
	end=bisect_right(D,t)

	i=start
	while i<end:
		ans[i]=min(ans[i],x)
		next=Next[i]
		Next[i]=end
		i=next

for x in ans:
	if x==float("inf"):
		print -1
	else:
		print x



Measured memory_bytes: 80924
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(usize);
    let mut a = get!(Vec<usize>);

    let mut ans = 0;
    for i in 1..N {
        if a[i] == a[i - 1] {
            ans += 1;
            a[i] = N + i;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include  <stdio.h>

int main(void)
{		
  int n,i,j,temp,x[100],count=0,mini;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
  }
  for (i=0;i<n;i++) {
    mini=i;
    for (j=i;j<n;j++) {
      if (x[j]<x[mini]) {
	mini=j;
      }
    }
    temp = x[i];        
    x[i] = x[mini];
    x[mini]= temp;
    if(x[i]!=x[mini])count++;
  }	
  for(i=0;i<n;i++){
    if(i==n-1)
      printf("%d\n",x[i]);
    else
      printf("%d ",x[i]);
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

#~ゴール
cnt_g = 0
for i in range(X+1, N):
    if i in A: cnt_g+= 1

#~スタート
cnt_s = 0
for i in range(X-1, 0, -1):
    if i in A: cnt_s += 1

print(min(cnt_g, cnt_s))

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    // multiset<int> s;
    map<int, int> m;
    rep(i, n) {
        int a;
        cin >> a;
        m[a]++;
    }

    int ans = 0;
    for (auto it = m.rbegin(); it != m.rend(); it++) {

        if (it->second <= 0) continue;

        int a = it->first;
        // while (it->second > 0) {
        for (int i = (1 << 30); i >= 1; i >>= 1) {
            if (i > a and 2 * a >= i and m[i - a] > 0) {
                if (2 * a == i) {
                    ans += it->second / 2;
                    it->second %= 2;
                } else {
                    int t = min(m[i - a], it->second);
                    m[i - a] -= t;
                    it->second -= t;
                    ans += t;
                }
            }
            if (it->second <= 0) break;
        }
        it->second = 0;
    }

    cout << ans << endl;

    return 0;
}


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

int main(){

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

string s;
cin>>s;

if(s.at(k-1)=='A')
s.at(k-1)='a';
else if(s.at(k-1)=='B')
s.at(k-1)='b';
else if(s.at(k-1)=='C')
s.at(k-1)='c';

cout<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
    int H, W;
    while(true) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for(int i = 0; i < H; i++) {
            for(int v = 0; v < W; v++) {
                if(i % 2 != 0) {
                    if (v % 2 != 0) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                } else {
                    if (v % 2 != 0) {
                        printf(".");
                    } else {
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3024
import heapq
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
q=[]
for i in range(N):
    heapq.heappush(q,-A[i])
for i in range(M):
    K=-heapq.heappop(q)
    L=K//2
    heapq.heappush(q,-L)
ans=0
for i in range(N):
    ans-=heapq.heappop(q)
print(ans)


Measured memory_bytes: 14180
n, a, b=map(int, input().split())
mod = 10 ** 9 + 7 
def cmb(n, r, mod):
    r = min(r, n -r)
    if r == 0: return 1
    over, under = 1, 1
    for i in range(1, r+1):
        over = over * (n-i+1) % mod
        under = under * i % mod
    
    inv=pow(under, mod-2, mod)
    
    return over*inv % mod
  
print((pow(2,n,mod)-1 - cmb(n, a,mod)-cmb(n,b,mod))%mod)

Measured memory_bytes: 38640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int max =0;
		int count =0;
		for (int i=0;i<N;i++) {
			int temp = sc.nextInt();
			if (max <=temp) {
				count ++;
				max= temp;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 35612
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <cmath>

int main(void){
    long long int n, x;
    std::cin >> n >> x;
    std::vector<long long int> a(n);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
    }


    long long int counter = 0;
    for(long long int i = 0; i < n-1; i++){
        if((a[i] + a[i+1]) > x){
            int box;
            box = ((a[i] + a[i+1]) - x);
            a[i+1] = a[i+1] - box;
            if(a[i+1] < 0){
                a[i+1] = 0;
            }
            counter += box;
        }
    }

    std::cout << counter;
    return 0;

}


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

// const long long int MOD = 1000000007;
const int MOD = 1000000007;


int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    for (int i = 0; i < N; i++) {
        cin >> Q[i];
        Q[i]--;
    }
    vector<int> nums(N);
    for (int i = 0; i < N; i++) {
        nums[i] = i;
    }
    int a=0,b=0,i=0;
    do {
        i++;
        if (nums == P) {
            a = i;
        }
        if (nums == Q) {
            b = i;
        }
        
    } while (next_permutation(nums.begin(), nums.end()));
    
    cout << abs(a-b) << endl;

}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
using namespace std;
const int N = 1e5 + 20;
int head[N], edge[N << 1], Next[N << 1], tot;
int dfn[N], low[N], n, m, num;
bool bridge[N << 1];
void add_edge(int a, int b)
{
    edge[++tot] = b;
    Next[tot] = head[a];
    head[a] = tot;
}
int ans = 0;
void tarjan(int x, int Edge)
{
    dfn[x] = low[x] = ++num;
    for (int i = head[x]; i; i = Next[i])
    {
        int y = edge[i];
        if (!dfn[y])
        {
            tarjan(y, i);
            low[x] = min(low[x], low[y]);
            if (low[y] > dfn[x])
                ans++;
        }
        else if (i != (Edge ^ 1))
            low[x] = min(low[x], dfn[y]);
    }
}
int main()
{
    scanf("%d%d", &n, &m);
    tot = 1;
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        add_edge(a, b);
        add_edge(b, a);
    }
    for (int i = 1; i <= n; i++)
        if (!dfn[i])
            tarjan(i, 0);

        cout << ans << endl;
    return 0;

}












Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/


int T,N;
int sx,sy;

void solve(){
    set<pair<int,int>> obs;
    for(int i=0;i<N;i++){
        int x,y;
        cin >> x >> y;
        obs.insert(make_pair(x,y));
    }
    cin >> sx >> sy;

    using Node = tuple<int,int,int>;
    using P = pair<int,int>;

    map<P,int> vis;
    queue<Node> que;
    vis[P(sx,sy)] = 0;
    que.push(Node(sx,sy,0));
    while(!que.empty()){
        int x,y,t;
        tie(x,y,t) = que.front();
        que.pop();
        if(t == T) continue;

        for(int dx=-1;dx<=1;dx++){
            for(int dy=-1;dy<=1;dy++){
                if(dx*dy==-1 or (dx==0 and dy==0)) continue;
                int nx = x + dx;
                int ny = y + dy;
                //if(abs(nx) > 30 or abs(ny) > 30) continue;
                if(obs.count(make_pair(nx,ny))) continue;

                if(vis.count(P(nx,ny)) and vis[P(nx,ny)] <= t+1) continue;
                vis[P(nx,ny)] = t+1;
                que.push(Node(nx,ny,t+1));
            }
        }
    }
    int cnt = 0;
    for(auto p : vis){
        cnt++;
        if(obs.count(p.first)){
            cout << "ERROR" << endl;
        }
    }
    cout << cnt << endl;
}

int main(){
    while(1){
        cin >> T >> N;
        if(T==0 and N==0) break;
        solve();
    }
}



Measured memory_bytes: 3248
N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B 
sumAB = A + B 


if diff % 2 == 0:
    print(diff // 2)
else:
    if N2B < A - 1:
        tmp = (N - (A + N2B))//2 + N2B
        if (N - (A + N2B))%2 == 1:
            tmp = tmp + 1
        if N2A < tmp:
            print(N2A)
        else:
            print(tmp)
    else:
        tmp = ((B + 1 - A) - 1)//2 + A - 1
        if ((B + 1 - A) - 1)%2 == 1:
            tmp = tmp + 1
        if B-1 < tmp: 
            print(B - 1)
        else:
            print(tmp)

Measured memory_bytes: 3064
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);


        int n=scan.nextInt();
        int k=scan.nextInt();
        int l[]=new int[n];
        for(int i=0;i<n;i++){
            l[i]=scan.nextInt();
        }

        Arrays.sort(l);
        int sum=0;
        for(int i=0;i<k;i++){
            sum+=l[n-i-1];
        }

        System.out.println(sum);

    }
}

Measured memory_bytes: 21588
def f_permutation_oddness(N, K, MOD=10**9 + 7):
    # 参考: https://atcoder.jp/contests/abc134/submissions/6487912
    from itertools import product

    # https://www.youtube.com/watch?v=-o4r74eJzV4 の 1:49:00 からの説明のように、
    # 左上→右下へ線を引いて水平線と交わる点の数と、
    # 左下→右上へ線を引いて水平線と交わる点の数は等しい。
    # よって奇妙さは必ず偶数であり、Kが奇数の場合はそれを満たすような置換がない。
    if K % 2 == 1:
        return 0

    # editorial と同じ定義と遷移
    dp = [[[0 for k in range(K + 1)]
           for j in range(N + 2)]
          for i in range(N + 1)]
    dp[0][0][0] = 1
    for i, j, k in product(range(1, N + 1), range(N + 1), range(K + 1)):
        k_previous = k - 2 * j
        if k_previous < 0:
            continue
        dp[i][j][k] += (2 * j + 1) * dp[i - 1][j][k_previous]
        dp[i][j][k] += (j + 1)**2 * dp[i - 1][j + 1][k_previous]
        if j > 0:
            dp[i][j][k] += dp[i - 1][j - 1][k_previous]
        dp[i][j][k] %= MOD
    return dp[N][0][K]

N, K = [int(i) for i in input().split()]
print(f_permutation_oddness(N, K))

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

int main() {
  int N, M, K, T, cnt=0;
  cin >> N >> M;
  vector<int> A(M,0);
  rep(i, N){
    cin >> K;
    rep(j, K){
      cin >> T;
      A.at(T-1)++;
    }
  }
  rep(i, M) if(A.at(i)==N) cnt++;
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
struct {string n; int w, l, d, p;} t[10], x;
int main()
{
	int n, i, j, b=0;
	while (cin >> n, n)
	{
		for (i = 0; i < n; i++)
		{
			cin >> t[i].n >> t[i].w >> t[i].l >> t[i].d;
			t[i].p = t[i].w * 3 + t[i].d;
		}
		if (b < 0) cout << endl;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (t[j].p < t[j+1].p)
				{
					x = t[j];
					t[j] = t[j+1];
					t[j+1] = x;
				}
			}
		}
		for (i = 0; i < n; i++)
			cout << t[i].n << "," << t[i].p << endl;
		b--;
	}
}

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

using namespace std;

int main()
{
    
    long long int L[100];
    
    L[0] = 2;
    L[1] = 1;
    
    for (int i=2;i<100;i++)
    {
        L[i] = L[i-1] + L[i-2];
    }
    
    int N;
    cin >> N;
    cout << L[N] << "\n";
    
}

Measured memory_bytes: 384
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

int n,a,b;

void run() {
	scanf("%d%d%d",&n,&a,&b);
	printf("%s\n",a%2==b%2?"Alice":"Borys");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mk make_pair
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl; 
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
// <=================================================================================================================================
// <=================================================================================================================================


void fun(){
    string s;cin>>s;
    int n=s.length();
    if(s[n-1]=='s')
        cout<<s<<"es"<<endl;
    else
    {
        cout<<s<<"s"<<endl;
    }
        
}

signed  main() {
    lets_go

    int t;
    t=1;
    //cin >> t;
    while (t--) {            
         fun();             
    }                        
                            
                            
    return 0;

}

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

int main(){
  int N;
  cin >> N;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
   cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());
  int x=vec.at(0); 
  reverse(vec.begin(), vec.end());
  int y=vec.at(0);

  cout << abs(x-y) << endl;
}  

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000000;
const long long MOD = 1000000007;

bool f(long long N){
  string s = to_string(N);
  long long slen = s.length();
  slen--;
  for (int i = 0; i < s.length(); i++)
  {
    if(s[i]!=s[slen-i])
      return false;
  }
  return true;
}

int main()
{
  long long N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N;i++)
    cin >> s[i];
  long long M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++)
    cin >> t[i];

  long long ans = 0;
  for (int i = 0; i < N; i++)
  {
    string now = s[i];
    long long nowans = 0;
    for (int j = 0; j < N;j++){
      if(s[j]==now)
        nowans++;
    }
    for (int j = 0; j < M; j++)
    {
      if (t[j] == now)
        nowans--;
    }
    ans = max(nowans, ans);
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll n, c[501] = {0}, s[501] = {0}, f[501] = {0};
  cin >> n;
  rep(i, n - 1) {
    cin >> c[i] >> s[i] >> f[i];
  }
  rep(i, n) {
    ll t = 0;
    FOR(j, i, n - 1) {
      if (t < s[j]) {
        t = s[j];
      } else if (t % f[j] != 0) {
        t += (f[j] - t % f[j]);
      }
      t += c[j];
    }
    cout << t << endl;
  }
}

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

int main() {
	string s,t;
    string result = "Yes";
    cin >> s >> t;
    for(int i=0;i<s.size();i++){
     if(s.at(i)!=t.at(i)){
     	result = "No";
        break;
     }
    }
    cout << result << endl;
}

Measured memory_bytes: 3576
import sys
from fractions import gcd

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print(*a, **dict(file=sys.stderr, **kw))

N = ini()


def solve():
    p = q = 1
    for i in range(N):
        x, y = inm()
        k = max((p + x - 1) // x, (q + y - 1) // y)
        p = x * k
        q = y * k
    return p + q


print(solve())


Measured memory_bytes: 10352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		String s = fs.next();
		if(s.equals("ABC")) {
			System.out.println("ARC");
		}else {
			System.out.println("ABC");
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32528
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        char name[] =in.next().toCharArray();;
        int count = 0;
        int n,m;
        for(int i=0;i<N;i++) {
        	m = 0;
        	char Signboard[]=in.next().toCharArray();
            for(int j=0;j<=Signboard.length-name.length;j++) {
                for(int k=1;k*(name.length-1)+1+j<=Signboard.length;k++) {
                	n = 0;
                    for(int l=0;l<name.length;l++) {
                        if(name[l] != Signboard[j+k*l]) n = 1;
                    }
                    if (n == 0) {
                        m = 1;
                        break;
                    }
                }
                if(m == 1) break;
            }
            if(m == 1) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 20544
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N, M = [int(x) for x in input().split()]
ls =[]
for _ in range(N):
    foodlist = [int(x) for x in input().split()]
    ls += foodlist[1:]

answer = 0
for M  in range(M):
    if ls.count(M +1) == N:
        answer += 1

print (answer)


Measured memory_bytes: 3060
n = int(input())
a_list = [int(x) for x in input().split()]
x = y = z = 0
for a in a_list:
    if a % 4 == 0:
        x += 1
    elif a % 2 == 0:
        y += 1
    else:
        z += 1
print("Yes" if (y == 0 and x >= z - 1) or (y > 0 and x >= z) else "No")

Measured memory_bytes: 19912
N,M = (int(i) for i in input().split())

if N == 1 and M == 1:
    print(1)
elif N == 1:
    print(M-2)
elif M == 1:
    print(N-2)
elif N == 2 or M == 2:
    print(0)
else:
    print((M-2)*(N-2))

Measured memory_bytes: 3060
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace __gnu_pbds;
using namespace std;

ll mod = 1e9+7;

ll add(ll a, ll b) { return (a % mod + b % mod) % mod; }
ll mul(ll a, ll b) { return (a % mod * b % mod) % mod; }
ll debug(vector<int> a) { for(int i: a) cout << i << " "; return puts("\n"), 0;}

ll power(ll base, ll exp) {
    ll res = 1;
    while(exp) {
        if(exp&1) res = mul(res, base);
        base = mul(base, base);
        exp >>= 1;
    }
    return res;
}
ll inv(ll p) {
    return power(p, mod-2);
}
ll fact[2000003] = {0};
int main() {
    fastio
    ll n, k; cin >> n >> k;
    ll a[n+1], x=0, pre=0, ans = 0;
    map<ll, ll> mp;
    mp[0] = 1; a[0] = 0;
    for(int i=1; i<=n; i++) {
        cin >> x; x -= 1;
        pre = (pre + x) % k;
        a[i] = pre;
        if(i >= k) {
            mp[a[i-k]]--;
        }
        if(mp[a[i]] > 0) {
            ans += mp[a[i]];
            mp[a[i]]++;
        }
        else {
            mp[a[i]] = 1;
        }
    }

    cout << ans << "\n";


}

Measured memory_bytes: 14336
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <vector>
#include <cstdio>
#include <cctype>

using namespace std;

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

const int INF=INT_MAX>>1;
const int N=200005;
const int Q=200005;

inline int min(int x,int y){return x<y?x:y;}

struct segment_tree
{
	int mi[N<<2],tag[N<<2];

	inline void update(int x){mi[x]=min(mi[x<<1],mi[x<<1|1]);}

	inline void change(int x,int y){mi[x]=min(mi[x],y),tag[x]=min(tag[x],y);}

	inline void clear(int x,int l,int r)
	{
		if (tag[x]!=INF)
		{
			if (l!=r) change(x<<1,tag[x]),change(x<<1|1,tag[x]);
			tag[x]=INF;
		}
	}

	void modify(int x,int st,int en,int l,int r,int edit)
	{
		clear(x,l,r);
		if (st==l&&en==r)
		{
			change(x,edit);
			return;
		}
		int mid=l+r>>1;
		if (en<=mid) modify(x<<1,st,en,l,mid,edit);
		else if (mid+1<=st) modify(x<<1|1,st,en,mid+1,r,edit);
		else modify(x<<1,st,mid,l,mid,edit),modify(x<<1|1,mid+1,en,mid+1,r,edit);
		update(x);
	}

	int query(int x,int y,int l,int r)
	{
		clear(x,l,r);
		if (l==r) return mi[x];
		int mid=l+r>>1;
		if (y<=mid) return query(x<<1,y,l,mid);
		else return query(x<<1|1,y,mid+1,r);
	}

	void build(int x,int l,int r)
	{
		mi[x]=tag[x]=INF;
		if (l==r) return;
		int mid=l+r>>1;
		build(x<<1,l,mid),build(x<<1|1,mid+1,r);
	}
}t;

vector<int> list[N];
int f[N],s[N];
bool a[N];
int n,q;

inline void update(int &x,int y){x=x<y?x:y;}

void dp()
{
	t.build(1,1,n),t.modify(1,1,1,1,n,0);
	for (int i=1;i<=n;++i)
	{
		f[i]=f[i-1]+a[i];
		sort(list[i].begin(),list[i].end());
		for (auto x:list[i])
		{
			int cur=t.query(1,x,1,n);
			update(f[i],cur+s[i]),t.modify(1,x,i,1,n,cur);
		}
		if (i<n) t.modify(1,i+1,i+1,1,n,f[i]-s[i]);
	}
}

int main()
{
	//freopen("dis.in","r",stdin),freopen("dis.out","w",stdout);
	n=read();
	for (int i=1;i<=n;++i) a[i]=read(),s[i]=s[i-1]+!a[i];
	q=read();
	for (int i=1,l,r;i<=q;++i) l=read(),r=read(),list[r].push_back(l);
	dp(),printf("%d\n",f[n]);
	//fclose(stdin),fclose(stdout);
	return 0;
}

Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main() {
	ios;
	string s;
	cin>>s;
	if(s[2]== s[3] && s[4]==s[5]) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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


def main():
    import sys
    input = sys.stdin.readline

    n, d = map(int, input().split())
    d2 = d ** 2
    ans = 0

    for i in range(n):
        xi, yi = map(int, input().split())

        if ((xi ** 2) + (yi ** 2)) <= d2:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
int main()

{

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n ;
	cin >> n;
	int res=0;
	int max =0;
	string s;
	cin >> s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='I')

		{
			res=res+1;
		}
        if(s[i]=='D')
		{
			res=res-1;
		}
		if(max<res)

		{
			max=res;
		}


	}
	cout<< max<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int MOD = 1000000007;

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

int add(int a, int b) {
	return (a + b) % MOD;
} 

int mul(int a, int b) {
	return (a * b) % MOD;
}

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

	int n;
	cin >> n;
	vector<int> pw(n + 1);
	pw[0] = 1;
	for (int i = 0; i < n; i++) {
		pw[i + 1] = mul(2, pw[i]);
	}
	map<pair<pair<int, int>, int>, int> cnt;
	int ans = 1;
	int kek = 0;
	while (n--) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0) {
			kek++;
			continue;
		}
		int g = gcd(abs(x), abs(y));
		x /= g;
		y /= g;
		int c = 0;
		for (int i = 0; i < 4; i++) {
			if (y >= 0 && x > 0) {
				// cerr << x << ' ' << y << ' ' << c % 2 << endl;
				cnt[{{x, y}, c % 2}]++;
				break;
			}
			int nx = -y;
			int ny = x;
			x = nx;
			y = ny;
			c++;
		}
	}
	for (auto [f, s] : cnt) {
		if (!cnt.count({f.first, f.second ^ 1})) {
			ans = mul(ans, pw[s]);
		} else {
			if (f.second == 1) continue;
			int cur = pw[cnt[{f.first, f.second ^ 1}]];
			cur = add(cur, pw[s]);
			cur = sub(cur, 1);
			ans = mul(ans, cur);
		}
	}
	ans = add(ans, kek);
	ans = sub(ans, 1);
	cout << ans << endl;
}

Measured memory_bytes: 19888
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>


class Dice{
    public : int diceNum[6];

    public : void set(int Num,int label){
        diceNum[label] = Num;
    };

    public : void roll(char label){
        switch (label)
        {
        case 'E':
            setAll(diceNum[3],diceNum[1],diceNum[0],diceNum[5],diceNum[4],diceNum[2]);
            break;
        case 'N':
            setAll(diceNum[1],diceNum[5],diceNum[2],diceNum[3],diceNum[0],diceNum[4]);
            break;
        case 'S':
            setAll(diceNum[4],diceNum[0],diceNum[2],diceNum[3],diceNum[5],diceNum[1]);
            break;
        case 'W':
            setAll(diceNum[2],diceNum[1],diceNum[5],diceNum[0],diceNum[4],diceNum[3]);
            break;
        }
    };
    public : int upNum(){
        return diceNum[0];
    }
    public : int frontNum(){
        return diceNum[1];
    }
    public : int rightNum(){
        return diceNum[2];
    }


    private : void setAll(int a1,int a2,int a3,int a4,int a5,int a6){
        set(a1,0);
        set(a2,1);
        set(a3,2);
        set(a4,3);
        set(a5,4);
        set(a6,5);
    };
};


int main(){
    

    Dice dice;

    for(int i = 0;i<6;i++){
        int diceNum;
        scanf("%d",&diceNum);
        dice.set(diceNum,i);
    }
    //printf("%d %d %d %d %d %d\n",dice.diceNum[0],dice.diceNum[1],dice.diceNum[2],dice.diceNum[3],dice.diceNum[4],dice.diceNum[5]);

    int orderNum;
    scanf("%d",&orderNum);


    for(int i = 0;i < orderNum;i++){
        int checkNum[2];
        scanf(" %d %d",&checkNum[0],&checkNum[1]);
        //printf("                                                                   %d %d\n",checkNum[0],checkNum[1]);
        for(int j = 0;j < 4;j++){
            if(dice.frontNum() == checkNum[1]){
                break;
            }
            dice.roll('S');
        }

        if(dice.frontNum() != checkNum[1]){
            dice.roll('W');
            dice.roll('S');
            //printf("                                                                   %d\n",dice.frontNum());
            if(dice.frontNum() != checkNum[1]){
                dice.roll('S');
                dice.roll('S');
            }
        }
        //printf("                                                                   %d\n",dice.frontNum());
        //printf("                                                                   %d\n",dice.frontNum());

        for(int j = 0;j < 3;j++){
            if(dice.upNum() == checkNum[0]){
                break;
            }
            dice.roll('W');
        }
        printf("%d\n",dice.rightNum());
    }



    return 0;
}



Measured memory_bytes: 2708