akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200000

long long gcd(long long x, long long y) {
	if (x < 0)x = -x;
	if (y < 0)y = -y;
	if (x > y)swap(x, y);
	if (x == 0)return y;
	if (y%x == 0)return x;
	return gcd(y%x, x);
}


int main() {
	long long a, b;
	long long c, d, e;
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	x = gcd(c, d);
  e=(c*d);
  e=e/x;
	a--;
	x = b / c;
	y = b / d;
	z = b / e;
	ans = b + z - x - y;
	x = a / c;
	y = a / d;
	z = a / e;
	s = a + z - x - y;
	ans -= s;
	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 128
import typing


class FenwickTree:
    '''Reference: https://en.wikipedia.org/wiki/Fenwick_tree'''

    def __init__(self, n: int = 0) -> None:
        self._n = n
        self.data = [0] * n

    def add(self, p: int, x: typing.Any) -> None:
        assert 0 <= p < self._n

        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, left: int, right: int) -> typing.Any:
        assert 0 <= left <= right <= self._n

        return self._sum(right) - self._sum(left)

    def _sum(self, r: int) -> typing.Any:
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r

        return s


# https://atcoder.jp/contests/practice2/tasks/practice2_b
def main() -> None:
    import sys

    n, q = map(int, sys.stdin.readline().split())
    fenwick_tree = FenwickTree(n)

    a = map(int, sys.stdin.readline().split())
    for i, ai in enumerate(a):
        fenwick_tree.add(i, ai)

    for _ in range(q):
        t, x, y = map(int, sys.stdin.readline().split())
        if t == 0:
            fenwick_tree.add(x, y)
        if t == 1:
            print(fenwick_tree.sum(x, y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 68028
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second


typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;

priority_queue<P,vector<P>,greater<P> > q;
int par[100000];

void init(int n){
	rep(i,n) par[i]=i;
}

int find(int x){
	if(x==par[x]) return x;
	return par[x]= find(par[x]);
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	par[x]=y;
	return;
}

int N;
int x,y;
vector<P> xs;
vector<P> ys;
vector<P> es;


int main()
{
	cin>>N;
	init(N);
	rep(i,N){
		cin>>x>>y;
		xs.pb(P(x,i));
		ys.pb(P(y,i));
	}
	sort(xs.begin(),xs.end());
	sort(ys.begin(),ys.end());
	rep(i,xs.size()-1){
		es.pb(P(xs[i].sc,xs[i+1].sc));
		q.push( P( abs(xs[i+1].fr - xs[i].fr ) , es.size()-1 ) );
	}
	rep(i,ys.size()-1){
		es.pb(P(ys[i].sc,ys[i+1].sc));
		q.push( P( abs(ys[i+1].fr - ys[i].fr ) , es.size()-1 ) );
	}
	int ans = 0;
	while(!q.empty()){
		P e = q.top();
		q.pop();
		int a = es[e.sc].fr;
		int b = es[e.sc].sc;
		if(find(a)!=find(b)){
			ans+=e.fr;
			unite(find(a),find(b));
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 7052
#include <iostream>                                                       
#include <algorithm>                                                      
#define N 3                                                               
using namespace std;                                                      
                                                                          
void judgment(void);                                                      
                                                                          
int main (void) {                                                         
  judgment();                                                             
}                                                                         
                                                                          
void judgment(void) {                                                     
  int a[N];                                                               
  for (int i=0; i<N; i++) {                                               
    cin >> a[i];                                                          
  }                                                                       
  sort(a,a+N);                                                            
  for (int i=0; i<N-1; i++) {                                             
    cout << a[i] << " ";                                                  
  }                                                                       
  cout << a[N-1] << endl;                                                 
}                                                                         
                          

Measured memory_bytes: 3160
#include<stdio.h>
#define NIL -1
#define MAX 100000


struct Node{
  int p, l, r;
};
struct Node T[MAX];
int n,D[MAX];

int rec(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL)rec(T[u].r,p);
  if(T[u].l!=NIL)rec(T[u].l,p+1);

}

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int main(){
  int i,j,d,v,c,l,r;

  scanf("%d", &n);

  for (i=0;i<n;i++) {
    T[i].p = T[i].l = T[i].r = NIL;
  }

  for (i=0;i<n;i++){
    scanf("%d %d",&v,&d);
    for (j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0){
	T[v].l=c;
      }
      else{
	T[l].r=c;
      }
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }
  rec(r,0);
  
  for (i=0;i<n;i++)print(i);
  return 0;
}



Measured memory_bytes: 7268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string W, X;
  int L;
  cin >> W;
  L = W.size();
  
  for(int i = 0;i < L;i++) {
  X = X + "x";
  }
  
  cout << X << endl;
}

Measured memory_bytes: 256
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <string.h>
typedef long long ll;
const int MYINF = 1e9+7;
typedef int bool;
const bool true = 1;
const bool false = 0;

#define MAX_N 1024
int q;
char X[MAX_N], Y[MAX_N];

int dp[MAX_N][MAX_N];
int xlen, ylen;

int max(int a, int b) {
	return a > b ? a : b;
}

int rec(int x, int y) {
	if (dp[x][y] >= 0) return dp[x][y];
	if (x == xlen || y == ylen) return dp[x][y] = 0;
	int m = max(rec(x, y+1), rec(x+1, y));
	if (X[x] == Y[y]) {
		return dp[x][y] = max(1+rec(x+1, y+1), m);
	} else {
		return dp[x][y] = m;
	}
}

int solve() {
	xlen = strlen(X);
	ylen = strlen(Y);
	memset(dp, -1, sizeof(dp));
	return rec(0, 0);
}

/*
int solve_by_loop() {
	xlen = strlen(X);
	ylen = strlen(Y);
	memset(dp, 0, sizeof(dp));
	int x, y;
	for (x = xlen - 1; x >= 0; x--) {
		for (y = ylen - 1; y >= 0; y--) {
			int m = max(dp[x][y+1], dp[x+1][y]);
			if (X[x] == Y[y]) dp[x][y] = max(1+dp[x+1][y+1], m);
			else dp[x][y] = m;
		}
	}
	return dp[0][0];
}
*/

int main(int argc, char **argv)
{
	int i;
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%s %s", X, Y);
		printf("%d\n", solve());
	}

	return 0;
}

Measured memory_bytes: 4856
import java.util.Scanner;

class Main {
    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long fact = 1;
        for (long i = 1; i <= n; i++) {
            fact = i * fact;
        }
        System.out.println(fact);
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

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

  int set[3];
  set[0] = A;
  set[1] = B;
  set[2] = C;
  sort(set, set + 3);
  if(set[0] == 5 && set[1] == 5 && set[2] == 7){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = sorted([I() for _ in range(n)])
    if n % 2 == 0:
        k = n // 2
        b = a[:k-1]
        c = a[k+1:]
        t = [0] * n
        t[0] = a[k]
        t[-1] = a[k-1]
        for i in range(k-1):
            t[i*2+1] = b[i]
            t[i*2+2] = c[i]
        r = 0
        for i in range(n-1):
            r += abs(t[i]-t[i+1])

        return r

    k = n // 2 + 1
    b = a[:k-1]
    c = a[k+1:]
    t = [0] * n
    t[0] = a[k]
    t[-1] = a[k-1]
    t[-2] = b[-1]
    for i in range(k-2):
        t[i*2+1] = b[i]
        t[i*2+2] = c[i]
    r = 0
    for i in range(n-1):
        r += abs(t[i]-t[i+1])

    b = a[:k-2]
    c = a[k:]
    t = [0] * n
    t[0] = a[k-1]
    t[-1] = a[k-2]
    t[-2] = c[-1]
    for i in range(k-2):
        t[i*2+1] = c[i]
        t[i*2+2] = b[i]
    tr = 0
    for i in range(n-1):
        tr += abs(t[i]-t[i+1])

    if r < tr:
        r = tr

    return r


print(main())


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

long long N;
pair<long long, long long> parr[200005];
long long mini, maxi;

int main(){
	cin >> N;
	mini = 1000000000;
	maxi = 1;
	for(long long i = 0; i < N; i++){
		cin >> parr[i].first >> parr[i].second;
		if(parr[i].first > parr[i].second){
			swap(parr[i].first, parr[i].second);
		}
		mini = min(mini, parr[i].first);
		maxi = max(maxi, parr[i].second);
	}

	if(N == 1){
		return 1;
	}

	long long Xmax = maxi, Ymax = 1;
	long long Xmin = mini, Ymin = 1000000000;
	long long ans = 1e18;

	//Xmin == mini && Xmax == maxi
	/*
	long long mapos1 = -1, mapos2 = -1;
	long long mipos1 = -1, mipos2 = -1;

	for(long long i = 0; i < N; i++){
		if(parr[i].second == maxi){
			if(mapos1 < 0){
				mapos1 = i;
			}else{
				mapos2 = i;
			}
		}


		if(parr[i].first == mini){
			if(mipos1 < 0){
				mipos1 = i;
			}else{
				mipos2 = i;
			}
		}
	}
	*/

	//Which Y should choose?
	//if((mapos2 > 0 )|| (mipos2 > 0) || (mapos1 != mipos1)){
		//            val    ,   pos
		vector<pair<long long, long long> > pairvec;
		long long pastmin = 1000000000;

		for(long long i = 0; i < N; i++){
			pairvec.push_back(make_pair(parr[i].first, i));
		}
		sort(pairvec.begin(), pairvec.end());


		Ymin = pairvec[0].first;
		Ymax = pairvec[pairvec.size() - 1].first;
		ans = min(ans, Ymax - Ymin) * (Xmax - Xmin);

		for(int i = 0; i < pairvec.size(); i++){
			//swap does not update minimum val
			if(pairvec[i].first >= pastmin){
				break;
			}
			pastmin = min(pastmin, parr[pairvec[i].second].second);

			if(i == pairvec.size() - 1){
				Ymin = pastmin;
			}else{
				Ymin = min(pastmin, pairvec[i+1].first);
			}

			Ymax = max(Ymax, parr[pairvec[i].second].second);

			ans = min(ans, (Ymax - Ymin) * (Xmax - Xmin));
		}
	//}


	//Xmin == mini && Ymax == maxi
	Xmax = 1;
	Ymax = 1;
	Xmin = 1000000000;
	Ymin = 1000000000;
	
	for(long long i = 0; i < N; i++){
		Ymin = min(Ymin, parr[i].second);
		Xmax = max(Xmax, parr[i].first);
	}

	ans = min(ans, (maxi - Ymin) * (Xmax - mini));

	cout << ans << endl;

}



Measured memory_bytes: 9584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  string s;
  cin>>s;
  if(s.size()==1){
    cout<<1;
  }else if(s.size()==2){
    cout<<(s[0]==s[1]?1:2);
  }else{
    int c=0,i=0;string t="";
    while(i<s.size()){
      if(t!=s.substr(i,1)){
        t=s.substr(i,1);
        c++;
      }else if(i+1!=s.size()){
        t=s.substr(i,2);
        c++;i++;
      }
      i++;
    }
    cout<<c;
  }
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a >= 13 {
		fmt.Println(b)
	} else if a >= 6 {
		fmt.Println(b / 2)
	} else if a <= 5 {
		fmt.Println(0)
	}
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> w(n);
    REP(i, n) { cin >> w[i]; }
    lint ans=1000000;

    FOR(t,1,101){
        lint s1 = 0,s2=0;
        REP(i,n){
            if(i+1>t){
                s2 += w[i];
            }else{
                s1 += w[i];
            }
        }
        ans = min(ans, abs(s2 - s1));
    }

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int main() {
	int n, m,minlane=1; cin >> n >> m;
	vector<queue<int>>queue(n);
	vector<int>num(n);
	for (int i = 0; i < m; ++i) {
		int x, y,mincnt=10000000;
		cin >> x >> y;
		if (x == 0) {
			cout << queue[y - 1].front() << endl;
			queue[y-1].pop();
		}
		else queue[minlane - 1].push(y);
		for (int i = 0; i < n; ++i) {
			if (mincnt > queue[i].size()) {
				mincnt = queue[i].size();
				minlane = i + 1;
			}
		}
	}
	return 0;
}


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

using namespace std;
using ll = long long int;

int main()
{
	int a, b;
	cin >> a >> b;
	unordered_set<int> s = { 1, 2, 3 };
	s.erase(s.find(a));
	s.erase(s.find(b));

	for (auto &i : s)
	{
		cout << i << endl;
	}
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>

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


using namespace std;

const ll MOD = 1000000007;
 
ll fact_t[200010];
ll fact_inv[200010];
ll inv[200010];

void build_fact_table(ll n) {
	inv[1]=1;
	for(int i=2; i<=n; i++){
		inv[i]=MOD - (MOD/i)*inv[MOD%i]%MOD;
	}

	fact_t[0]=fact_inv[0] = 1;
	for (int i = 1; i <=n ; i++) {
		fact_t[i] = (fact_t[i - 1] * i) % MOD;
		fact_inv[i]=(fact_inv[i-1]*inv[i])%MOD;
	}
}



ll combi(ll n, ll r){
	if(r < 0 || n < r){
		return 0;
	}
	
	return (((fact_t[n] * fact_inv[r])%MOD)*fact_inv[n-r])%MOD;
}

int main(){
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	ll res=0;
	build_fact_table(200000);

	int i=0;
	while(h-a-1-i>=0 && w-b-1-i>=0){
		res +=( combi(h+b-a-1, h-a-1-i) * combi(w+a-b-1,a+i))%MOD;
		res %=MOD;
		i++;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 4992
<?php
  
  $a = explode(" ",fgets(STDIN));
  $b = explode(" ",fgets(STDIN));
  


  $int_ary = array_map(function($num){
    return (int)$num ;
}, $b);
  
  $ans = $a[0] - array_sum($int_ary);
  
  if($ans >= 0) {
  	echo $ans;
  } else {
    echo -1; 
  }



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

int main() {
    char s[100001];
    char ans;
    int n;
    int i;
    int flag;
    scanf("%s", s);
    n=strlen(s);
    for (ans=97;ans<123;ans++) {
        flag=1;
        for (i=0;i<n;i++) {
            if (ans==s[i]) {
                flag=0;
            }
        }
        if (flag) {
            break;
        }
    }
    if (ans==123) {
        printf("None\n");
    } else {
        printf("%c\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1820
#include <stdio.h>          // printf(), scanf()
#include <string.h>         // memset()

#define MAX_N 100
#define MAX_W 10000
#define max(a, b) ((a) > (b) ? (a) : (b))

int n, W;
int w[MAX_N];
int v[MAX_N];

int
solve()
{
	int dp[MAX_N + 1][MAX_W + 1];
	int i, j;

	memset(dp, 0, sizeof(dp));
	for (i = 0; i < n; ++i)
	{
		for (j = 0; j <= W; ++j)
		{
			if (j < w[i])
				dp[i + 1][j] = dp[i][j];
			else
				dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
		}
	}

	return dp[n][W];
}

int
main(int argc, char** argv)
{
	int i;

	scanf("%d %d", &n, &W);
	for (i = 0; i < n; ++i)
		scanf("%d %d", &v[i], &w[i]);


	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 4548
#include <bits/stdc++.h>
using namespace std;
const int N = 500+10;
int n;
int C[N], F[N], S[N];
int ans[N];

int main(){
cin>>n;
for(int i=1;i<n;++i) cin>>C[i]>>S[i]>>F[i];
for(int i=1;i<n;++i){
int t=0, j=i;
for(;j<n;){
t = max(t, S[j]);
while(t%F[j]) ++t;
 t += C[j]; ++j;
}
ans[i] = t;
}
for(int i=1;i<=n;++i) cout<<ans[i]<<endl;
return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
def calcAngle(h,m): 
        if (h < 0 or m < 0 or h > 12 or m > 60): 
            return 0
        if (h == 12): 
            h = 0
        if (m == 60): 
            m = 0
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m 
        angle = abs(hour_angle - minute_angle)
        angle = min(360 - angle, angle) 
        pi=22/7
        radian = angle*(math.pi/180)
        return radian 
def solve(A: int, B: int, H: int, M: int):
    C = calcAngle(H,M)
    ans = (A**2 + B**2 - 2*A*B*math.cos(C))**0.5
    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(A, B, H, M)

if __name__ == '__main__':
    main()

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

int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int ans=2e9;
  for(int i=0;i<=2*max(x,y);i+=2){
    ans=min(ans,i*c+max(0,(x-i/2))*a+max(0,(y-i/2))*b);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def main():
    N, K = map(int, sys.stdin.readline().strip().split())
    people = [False for _x in range(N)]
    for i in range(K):
        _ = sys.stdin.readline()
        for k in map(int, sys.stdin.readline().strip().split()):
            people[k-1] = True

    print(sum([1 for i in people if i is False]))


if __name__ == '__main__':
    main()


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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++) {
        if(floor(i * 1.08) == n) {
            cout << i << endl;
            break;
        }
        if(i == n) {
            cout << ":(" << endl;
        }
    }
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;

# define INF ((int)(1<<30))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12

template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int now, end;
		cin >> now >> end;
		vi ans;
		bool a = false;
		if (now > end&&now>5)
		{
			for (; now <= 9; now++)ans.push_back(now);
			now = 5; 
			for (; now >= 0; now--)
			{
				ans.push_back(now);
				if (now == end)break;
			}
			
			if (now != end) {
				now = 1;
				for (; now <= end; now++)
				{
					ans.push_back(now);
					if (now == end)break;
				}
			}
		}
		else if (now > end)
		{
			for (; now >= end; now--)ans.push_back(now);
		}
		else
		{
			for (; now <= end; now++)ans.push_back(now);
		}
		for (int i = 0; i < ans.size(); i++)
		{
			cout << (i ? " " : "") << ans[i];
		}
		cout << endl;

	}
}

Measured memory_bytes: 2900
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;


int main()
{
	int k,n,t=0;
	cin >> n >> k;
	n % 2 == 0 ? t = n / 2 : t = (n + 1) / 2;
	cout << (k <= t ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
from functools import lru_cache


a = int(input())
b = input()
X = b.count("1")
ans1 = []
ans2 = []

@lru_cache(maxsize=None)
def func1(c):
    x = X + 1
    n = 1
    nsum = 0
    for i in reversed(range(len(c))):
        ans1.append(n)
        nsum += n * int(c[i])
        n = n % x if n > x else n
        n *= 2
    return nsum
    
@lru_cache(maxsize=None)
def func2(c):
    x = X - 1
    if x == 0:
        return 0
    n = 1
    nsum = 0
    for i in reversed(range(len(c))):
        ans2.append(n)
        nsum += n * int(c[i])
        n = n % x if n > x else n
        n *= 2
    return nsum    

def func(c):
    x = c.count("1")
    if x == 0:
        return 0
    n = 1
    nsum = 0
    for i in reversed(range(len(c))):
        nsum += n * int(c[i])
        n = n % x if n > x else n
        if n == 0:
            break
        n *= 2
    nsum %= x
    cans = bin(nsum).count("1")
    if cans == 0:
        return 1
    else:
        return 1 + func(bin(nsum)[2:])
    
allans1 = func1(b)
allans2 = func2(b)
ans1 = ans1[::-1]
if allans2 == 0:
    ans2 = [0] * a
else:
    ans2 = ans2[::-1]

c = list(b)
for i in range(a):
    if c[i] == "0":
        ans = (allans1 + ans1[i]) % (X + 1)
        ans = func(bin(ans)[2:]) + 1
        print(str(ans))
    else:
        if allans2 - ans2[i] == 0 and X - 1 == 0:
            print("0")
        else:
            ans = (allans2 - ans2[i]) % (X - 1)
            ans = func(bin(ans)[2:]) + 1
            print(str(ans))


Measured memory_bytes: 108140
import sys
from collections import deque
import numpy as np

h, w = map(int, input().split())

grid = [list(map(str, input().rstrip())) for _ in range(h)]
init = np.where(np.array(grid).flatten() == "#")[0].shape[0]

moves = [[1, 0], [-1, 0], [0, 1], [0, -1]]

q = deque([[0, 0]])
grid[0][0] = 1

while q:
    curr = q.popleft()
    for m in moves:
        nx = curr[0] + m[0]
        ny = curr[1] + m[1]
        if 0 <= nx < h and 0 <= ny < w:
            if grid[nx][ny] == ".":
                grid[nx][ny] = grid[curr[0]][curr[1]] + 1
                q.append([nx, ny])
                if nx == h - 1 and ny == w - 1:
                    print(h * w - grid[nx][ny] - init)
                    sys.exit()
else:
    print(-1)

Measured memory_bytes: 27040
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007

using namespace std;
using P = pair<long, long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };

vector<edge>tree[100010];
int dist[2][100005];
vector<int> connect[100005];

int N;
long long a, B;
long long h[100000];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

bool isEnouph(long long value) {
	long long cost = 0;
	for (int i = 0; i < N;++i) {
		long long hp = h[i] - B * value;
		if (hp <= 0)continue;
		cost += ((hp + (a - 1)) / a);
	}
	return cost <= value;
}

int main() {

	cin >> N;
	cin >> a >> B;
	a -= B;

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

	long long bottom = 0;
	long long top = 1000000000;
	while (bottom + 1 != top) {
		long long middle = (bottom + top) / 2;
		if (isEnouph(middle))top = middle;
		else bottom = middle;
	}
	cout << top << endl;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

long long n, a, b, c, d;

int main() {
	cin >> n >> a >> b >> c >> d;
	a = abs(a - b);
	a <<= 1, c <<= 1, d <<= 1;
	for (int i = 1; i < n; ++i)
		if (a > 0) a -= (c + d) / 2;
		else a += (c + d) / 2;
	a = abs(a);
	if (a > (n - 1) * (d - c) / 2) cout << "NO";
	else cout << "YES";
	return 0;
}


Measured memory_bytes: 256
N=int(input())
T=[1]+list(map(int,input().split()))+[1]
V=[0]+list(map(int,input().split()))+[0]
T=list(map(lambda x:x*2,T))
V=list(map(lambda x:x*2,V))
X=[i for i in range(sum(T)+1)]
C=[0]
X[-1]=0
for i in range(len(T)):
  C.append(C[i]+T[i])
for i in range(N+2):
  for j in range(C[i+1]):
    if j>=C[i]:
      X[j]=min(X[j],V[i])
    else:
      X[j]=min(X[j],V[i]+C[i]-j-1)
for i in range(len(X)-1):
  X[i+1]=min(X[i+1],X[i]+1)
print(sum(X)/4)

Measured memory_bytes: 72220
#include <bits/stdc++.h>
#define ll long long
#define AwD 998244353
using namespace std;
ll mi(ll a, ll b) {
	ll ret = 1;
    for (; b; b >>= 1, a = a * a % AwD)
	if (b & 1) ret = ret * a % AwD;
    return ret;
}
ll x[250], y[250], ans;
map<ll, int> MAP;
int main() {
    ll n; cin >> n;
    for (int i = 1; i <= n; i ++) cin >> x[i] >> y[i];
	ans = mi(2, n) - n - 1;
	for (int i = 1; i <= n; i ++) {
		MAP.clear();
		for (int j = i + 1; j <= n; j ++) {
            ll k;
            if (x[j] == x[i]) k = -1;
			else k = ((y[j] - y[i]) * mi(x[j] - x[i], AwD - 2) % AwD + AwD)% AwD;
			MAP[k] ++;
		}
		for (auto it = MAP.begin(); it != MAP.end(); it ++) (ans -= mi(2, it -> second) - 1) %= AwD;
	}
	cout << ((ans) % AwD + AwD) % AwD << endl;
	return 0;
}


Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn remove_erase(v: &mut Vec<char>) -> bool {
    if v.len() < 5 {
        return false;
    }
    let e2 = v.pop().unwrap();
    let s = v.pop().unwrap();
    let a = v.pop().unwrap();
    let r = v.pop().unwrap();
    let e1 = v.pop().unwrap();
    if e1 != 'e' || e2 != 'e' || r != 'r' || a != 'a' || s != 's' {
        return false;
    }
    true
}

fn remove_eraser(v: &mut Vec<char>) -> bool {
    if v.len() < 6 {
        return false;
    }
    let r2 = v.pop().unwrap();
    let e2 = v.pop().unwrap();
    let s = v.pop().unwrap();
    let a = v.pop().unwrap();
    let r1 = v.pop().unwrap();
    let e1 = v.pop().unwrap();
    if e1 != 'e' || e2 != 'e' || r1 != 'r' || a != 'a' || s != 's' || r2 != 'r' {
        return false;
    }
    true
}

fn remove_dream(v: &mut Vec<char>) -> bool {
    if v.len() < 5 {
        return false;
    }
    let m = v.pop().unwrap();
    let a = v.pop().unwrap();
    let e = v.pop().unwrap();
    let r = v.pop().unwrap();
    let d = v.pop().unwrap();
    if d != 'd' || r != 'r' || e != 'e' || a != 'a' || m != 'm' {
        return false;
    }
    true
}
fn remove_dreamer(v: &mut Vec<char>) -> bool {
    if v.len() < 7 {
        return false;
    }
    let r2 = v.pop().unwrap();
    let e2 = v.pop().unwrap();
    let m = v.pop().unwrap();
    let a = v.pop().unwrap();
    let e1 = v.pop().unwrap();
    let r1 = v.pop().unwrap();
    let d = v.pop().unwrap();
    if d != 'd' || r1 != 'r' || e1 != 'e' || r2 != 'r' || e2 != 'e' || a != 'a' || m != 'm' {
        return false;
    }
    true
}

fn main() {
    let s: String = read();
    let mut svec: Vec<char> = s.chars().collect();

    while svec.len() > 4 {
        let l = svec.len();
        if svec[l - 1] == 'm' {
            if !remove_dream(&mut svec) {
                println!("NO");
                return;
            }
        } else if svec[l - 1] == 'e' {
            if !remove_erase(&mut svec) {
                println!("NO");
                return;
            }
        } else if svec[l - 1] == 'r' && svec[l - 3] == 'm' {
            if !remove_dreamer(&mut svec) {
                println!("NO");
                return;
            }
        } else if svec[l - 1] == 'r' && svec[l - 3] == 's' {
            if !remove_eraser(&mut svec) {
                println!("NO");
                return;
            }
        } else {
            println!("NO");
            return;
        }
    }

    if svec.is_empty() {
        println!("YES");
    } else {
        println!("NO");
    }
}


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

const int INF = 10000000;

struct yx{
    int y, x;
};

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

    string S[H];
    rep(i, H) cin >> S[i];

    int num_b = 0;
    rep(i, H) rep(j, W) if (S[i][j] == '#') num_b++;

    int D[H][W];
    rep(i, H) rep(j, W) D[i][j] = INF;

    int DX[4] = {1, -1, 0, 0};
    int DY[4] = {0, 0, 1, -1};

    D[0][0] = 1;
    queue<yx> que;
    que.push({0, 0});

    while (!que.empty()) {
        yx s = que.front();
        que.pop();

        rep(i, 4) {
            int nx = s.x + DX[i];
            int ny = s.y + DY[i];
            
            if (nx < 0 || nx >= W) continue;
            if (ny < 0 || ny >= H) continue;
            if (D[ny][nx] != INF) continue;
            if (S[ny][nx] == '#') continue;

            D[ny][nx] = D[s.y][s.x] + 1;
            que.push({ny, nx});
        }
    }

    int ans;
    if (D[H-1][W-1] == INF) ans = -1;
    else ans = H * W - num_b - D[H-1][W-1];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;;

const ll MOD = 1e9 + 7;
const ll MAX_NM = 2 * 1e5 + 2;

ll factorial[MAX_NM];

ll calc_pow(ll x, ll y) {
    ll z = 1;
    while (y > 0) {
        if (y & 1) {
            z = (z * x) % MOD;
        }
        x = (x * x) % MOD;
        y /= 2;
    }
    return z;
}

ll calc_comb(ll x, ll y) {
    ll div_num = (factorial[x - y] * factorial[y]) % MOD;
    return (factorial[x] * calc_pow(div_num, MOD - 2)) % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, K;
    cin >> N >> M >> K;
    factorial[0] = 1;
    for (ll i = 1; i <= N * M; i++) {
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    ll ans = 0;
    for (ll i = 1; i <= M; i++) {
        ll dist_sum = ((M - i) * (2 + (M - i - 1)) / 2) % MOD;
        ans = (ans + (((((N * N) % MOD) * calc_comb(N * M - 2, K - 2)) % MOD) * dist_sum) % MOD) % MOD;
    }
    for (ll i = 1; i <= N; i++) {
        ll dist_sum = ((N - i) * (2 + (N - i - 1)) / 2) % MOD;
        ans = (ans + (((((M * M) % MOD) * calc_comb(N * M - 2, K - 2)) % MOD) * dist_sum) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int X,Y,A,B,C; cin>>X>>Y>>A>>B>>C;
    vec p(A),q(B),r(C);
    rep(i,A) cin>>p[i];
    rep(j,B) cin>>q[j];
    rep(k,C) cin>>r[k];
    sort(all(p),greater<ll>());
    sort(all(q),greater<ll>());
    sort(all(r),greater<ll>());
    priority_queue<ll, vec, greater<ll>> pq;
    rep(i,X) pq.push(p[i]);
    rep(j,Y) pq.push(q[j]);
    rep(k,C){
        ll res=pq.top();
        if(r[k]>res){
            pq.pop();
            pq.push(r[k]);
        }
    }
    ll ans=0;
    while(!pq.empty()){
        ans+=pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4724
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n / 2];
        int b[] = new int[n / 2];
        for (int i = 0; i < n / 2; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        List<Integer> lista = new ArrayList<Integer>();
        List<Integer> listac = new ArrayList<Integer>();
        List<Integer> listb = new ArrayList<Integer>();
        List<Integer> listbc = new ArrayList<Integer>();

        lista.add(0);
        listac.add(0);
        listb.add(0);
        listbc.add(0);

        int count = 1;
        for (int i = 0; i < n / 2 - 1; i++) {
            if (a[i] != a[i + 1]) {
                lista.add(a[i]);
                listac.add(count);
                count = 1;
            } else {
                count++;
            }
        }
        lista.add(a[n / 2 - 1]);
        listac.add(count);

        count = 1;
        for (int i = 0; i < n / 2 - 1; i++) {
            if (b[i] != b[i + 1]) {
                listb.add(b[i]);
                listbc.add(count);
                count = 1;
            } else {
                count++;
            }
        }
        listb.add(b[n / 2 - 1]);
        listbc.add(count);

        int maxai = 0;
        int maxac = 0;
        for (int i = 0; i < listac.size(); i++) {
            if (listac.get(i) > maxac) {
                maxai = i;
                maxac = listac.get(i);
            }
        }
        int maxa = lista.get(maxai);
        lista.remove(maxai);
        listac.remove(maxai);
        int saxai = 0;
        int saxac = 0;
        for (int i = 0; i < listac.size(); i++) {
            if (listac.get(i) > saxac) {
                saxai = i;
                saxac = listac.get(i);
            }
        }
        int saxa = lista.get(saxai);

        int maxbi = 0;
        int maxbc = 0;
        for (int i = 0; i < listbc.size(); i++) {
            if (listbc.get(i) > maxbc) {
                maxbi = i;
                maxbc = listbc.get(i);
            }
        }
        int maxb = listb.get(maxbi);
        listb.remove(maxbi);
        listbc.remove(maxbi);
        int saxbi = 0;
        int saxbc = 0;
        for (int i = 0; i < listbc.size(); i++) {
            if (listbc.get(i) > saxbc) {
                saxbi = i;
                saxbc = listbc.get(i);
            }
        }
        int saxb = listb.get(saxbi);
        if (maxa != maxb) {
            System.out.println(n - maxac - maxbc);
        } else {
            System.out.println(Math.min(n - saxac - maxbc, n - maxac - saxbc));
        }
    }
}

Measured memory_bytes: 59848
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    string S[H];
    rep(i, H) cin >> S[i];
    rep(i, H){
        rep(j, W){
            if(S[i][j] == '#') cout << '#';
            else{
                int ans = 0;
                for(int dx=-1;dx<=1;dx++){
                    for(int dy=-1;dy<=1;dy++){
                        int nx = dx + i, ny = dy + j;
                        if (0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] == '#') ans++;
                    }
                }
                cout << ans;
            }
        }
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 256
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  n = int(input())
  a = list(map(int, input().split()))
  s = Counter(a)
  subete = 0
  herasu = [0]*(n+1)
  for key, value in s.items():
    if value>=2:
      subete += factorial(value)/(2*factorial(value-2))
      herasu[key] = value-1
  for i in a:
    print(int(subete-herasu[i]))
  

if __name__ == '__main__':
  main()

Measured memory_bytes: 27108
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, q int
	fmt.Fscan(reader, &n, &k, &q)
	s := make([]int, n+1)
	for i := 0; i < q; i++ {
		var a int
		fmt.Fscan(reader, &a)
		s[a]++
	}
	for i := 1; i <= n; i++ {
		if k-(q-s[i]) > 0 {
			fmt.Fprintln(writer, "Yes")
		} else {
			fmt.Fprintln(writer, "No")
		}
	}
}


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

int main(){
int N,M;
  cin>>N>>M;
  char A[N][N], B[M][M];
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
   cin>>A[i][j];}}
  for(int i=0; i<M; i++){
    for(int j=0; j<M; j++){
   cin>>B[i][j];}}
  
  bool ans=false;
  for(int ly=0; ly<N; ly++){
   for(int lx=0; lx<N; lx++){
     if(ly+M-1>=N || lx+M-1>=N){continue;}
       // ↑ B[i][j]の可動範囲はly,lx<=N-M+1より。この条件を満たしていればcontinue
     bool match=true;
     for(int i=0; i<M; i++){
      for(int j=0; j<M; j++){
        if(A[ly+i][lx+j]!=B[i][j]){match=false;}
      } // ↑ ly,lxを導入する事でB[i][j]が相対的に平行移動している形にできる
     }
   if(match){ans=true;} // Aの中にB[i][j]を全て含む場合はtrue
   }
  }
  
  if(ans){cout<<"Yes";}
  else{cout<<"No";}
  
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int N;
    int a[101];
    int i;
    int count =0;

    


    scanf("%d", &N);
    for (i=0; i<N; i++) {
        scanf("%d", &a[i+1]);
    }

    for (i=1; i<=N; i++) {
        if (i%2==1 && a[i]%2==1) {
            count = count + 1;
        }
    }


        printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;cin>>a>>b>>c>>d;
  int x=(c-1)/b+1,y=(a-1)/d+1;
  if(x<=y)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int B[n];
    int x = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> B[i];
        x ^= B[i];
    }
    for (int i = 0; i < n; i++)
        cout << (x ^ B[i]) << " ";
    
    return 0;
}

Measured memory_bytes: 4332
#include <cstdio>
using namespace std;
int n,m,a[100005],head[100005],cnt=0;
struct Edge{
  int to,nxt;
}e[200005];
void add_edge(int u,int v){
  e[++cnt].to=v;
  e[cnt].nxt=head[u];
  head[u]=cnt;
}
int main()
{
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;++i)
    scanf("%d",&a[i]);
  for(int i=1;i<=m;++i){
    int a,b;
    scanf("%d%d",&a,&b);
    add_edge(a,b);add_edge(b,a);
  }int ans=0;
  for(int i=1;i<=n;++i){
    bool flag=1;
    for(int j=head[i];j;j=e[j].nxt){
      if(a[e[j].to]>=a[i]){
        flag=0;break;
      }
    }
    ans+=flag;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 4040
#include<bits/stdc++.h>
#define int long long
#define re(i,n) for(i=0;i<n;i++)
#define bre(i,n) for(i=n;i>0;i--)
#define rep(i,l,r) for(i=l;i<r;i++)
#define brep(i,l,r) for(i=r;i>l;i--)
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
template<int H,int W>int wa(int x1,int y1,int x2,int y2,int(&p)[H][W]){
	return p[y2][x2]-p[y2][x1]-p[y1][x2]+p[y1][x1];
}
struct Node{
	vector<pair<int,int>> e;
} node[1];
int A,B,C,D,N,M,K,S,T,H,W;
int p[114514],q[114514],r[114514];
signed main(){
	int i,j,k;
	cin>>N;
	re(i,N)
		cin>>p[i];
	re(i,N)
		cin>>q[i];
	int u=0,v=0;
	re(i,N){
		u+=p[i];
		v+=q[i];
	}
	if(u>v){
		cout<<"No"<<endl;
		return 0;
	}
	int a=v-u,b=a;
	re(i,N){
		if(q[i]<p[i])
			b-=p[i]-q[i];
		else if((q[i]-p[i])%2)
			b--;
		if(b<0){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 384
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main() {
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 for(int t = 1; t <= T; t++) {
		 int64_t n;
		 cin >> n;
		 int64_t min_ans = n - 1;
		 int64_t sqrt_ = (int64_t) sqrt(n);
		 for(int64_t i = 1; i <= sqrt_; i++){
			 if(n % i == 0){
				 min_ans = min(min_ans,(i + n / i) - 2);
			 }
		 }
		 cout << min_ans;
	 }
}


Measured memory_bytes: 3696
import fractions
a, b, c, d = map(int, input().split())
div_c = b//c + (-a//c) + 1
div_d = b//d + (-a//d) + 1
div_cd = b//(c*d//fractions.gcd(c, d)) + (-a//(c*d//fractions.gcd(c,d))) + 1
print(b-a+1 - div_c - div_d + div_cd)


Measured memory_bytes: 63980
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[][] s = new int[k][2];
		for(int i = 0; i < k; i++){
		    s[i][0] = sc.nextInt();
		    s[i][1] = sc.nextInt();
		}
		
		// 計算
		long result = 0;
		int MOD = 998244353;
		int[] dp = new int[n+1];
		dp[1] = 1;
		int[] sum = new int[n+1];
		sum[1] = 1;
		for(int i = 2; i <= n; i++){
		    for(int j = 0; j < k; j++){
		        int l = i - s[j][1];
		        int r = i - s[j][0];
		        if(r < 1) continue;
		        l = max(1, l);
		        dp[i] += (sum[r] - sum[l-1] + MOD)%MOD;
		        dp[i] %= MOD;
		    }
		    sum[i] = (sum[i-1] + dp[i])%MOD;
		}
		//System.out.println(Arrays.toString(dp));
		result = dp[n];
		
		// 出力
		System.out.println(result);
		
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}

}


Measured memory_bytes: 27988
//B - Card Game for Three: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    string s1, s2, s3;
    int prox = 1, ans;

    cin >> s1 >> s2 >> s3;
    reverse(all(s1)); reverse(all(s2)); reverse(all(s3));
    while(true) {
        //cout << prox << '\n';
        //cout << s1.size() << " " << s2.size() << " " << s3.size() << "\n";
        if(prox == 1) {
            if(s1.size() == 0) {
                ans = 1;
                break;
            }
            prox = (s1[s1.size()-1] - 'a') + 1 ;
            s1.pop_back();
        } else if(prox == 2) {
            if(s2.size() == 0) {
                ans = 2;
                break;
            }
            prox = (s2[s2.size()-1]  - 'a') + 1;
            s2.pop_back();
        } else {
            if(s3.size() == 0) {
                ans = 3;
                break;
            }
            prox = (s3[s3.size()-1] - 'a') + 1;
            s3.pop_back();
        }
    }
    if(ans == 1) cout << "A\n";
    else if(ans == 2) cout << "B\n";
    else cout << "C\n";
}

Measured memory_bytes: 256