akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=1e9+7;
#define N 505
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,cnt[N],ans,fac[N],inv[N];
int dp[2][N][N]; // 区间长度到i，区间个数j，区间长度和 k。 
inline int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		inv[i]=1LL*inv[i+1]*(i+1)%mod;
	}
}
inline int C(int n,int m){
	return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;++i){
		++cnt[read()];
	}
	init(m);
	dp[(m+1)&1][0][0]=1;
	for(register int i=m;i>=1;--i){
		memset(dp[i&1],0,sizeof(dp[i&1]));
		for(int j=0;j<=m/i;++j){
			for(int k=0;k<=m;++k){
				if(!dp[(i+1)&1][j][k])continue;
				int lim=min((m-k)/i,m-j);
				for(int p=0;p<=lim;++p){
					dp[i&1][j+p][k+p*i]=(dp[i&1][j+p][k+p*i]+1LL*dp[(i+1)&1][j][k]*C(j+p,p))%mod;
				}
			}
		}
		for(int j=0;j<=m;++j){
			for(int k=j*(i-1);k<=m;++k){
				dp[i&1][j][k]=1LL*dp[i&1][j][k]*qpow(k-j*(i-1),cnt[i])%mod;
			}
		}
	}
	for(int j=0;j<=m;++j){
		for(int k=0;k<=m;++k){
			ans=(ans+1LL*dp[1][j][k]%mod*C(m-k+1,j)*((m-k)&1?-1:1))%mod;
		}
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}



Measured memory_bytes: 5748
import java.io.*;
import java.util.*;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		long[] A = new long[N];
		long[] F = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < N; ++i) {
			F[i] = sc.nextInt();
		}
		Arrays.sort(A);
		Arrays.sort(F);
		long ok = (long) 1e12 + 1;
		long ng = -1;
		while (ok - ng > 1) {
			long middle = (ok + ng) / 2;
			long s = 0;
			for (int i = 0; i < N; ++i) {
				long diff = middle - (long) A[i] * F[N - 1 - i];
				if (diff >= 0)
					continue;
				diff = Math.abs(diff);
				s += (diff + F[N - 1 - i] - 1) / F[N - 1 - i];
			}
			if (s <= K)
				ok = middle;
			else
				ng = middle;
		}
		System.out.println(ok);
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


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

int main(){

    int64_t K;
    int64_t i;
    int64_t a[1000002];
    cin >> K;
    
    a[1] = 7%K;

    for(i=2;i<=K;i++){
        a[i] = (a[i-1] *10 + 7)%K;
    }

    for(i=1;i<=K;i++){
        if(a[i]%K==0){
            cout << i << endl;
            return 0;
        }

    }

    cout << -1 << endl;

    
 
 }

Measured memory_bytes: 11312
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    h, w = map(int, input().split())
    mat = [input() for _ in range(h)]

    hor = [[0] * (w + 1) for _ in range(h)]
    ver = [[0] * (h + 1) for _ in range(w)]

    for i, row in enumerate(mat):
        hi = hor[i]
        for j in range(w):
            if row[j] == '.':
                hi[j + 1] = hi[j] + 1
            else:
                hi[j + 1] = 0
        for j in reversed(range(w)):
            if hi[j]:
                hi[j] = max(hi[j], hi[j + 1])
        del hi[0]

    for i, col in enumerate(zip(*mat)):
        vi = ver[i]
        for j in range(h):
            if col[j] == '.':
                vi[j + 1] = vi[j] + 1
            else:
                vi[j + 1] = 0
        for j in reversed(range(h)):
            if vi[j]:
                vi[j] = max(vi[j], vi[j + 1])
        del vi[0]

    ver = list(zip(*ver))

    res = 0
    for i in range(h):
        hi = hor[i]
        vi = ver[i]
        for j in range(w):
            res = max(res, hi[j] + vi[j] - 1)

    print(res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 199352
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(21,0);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int ans = 0;
    for (int i = 1; i < n-1; i++) {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])) {
            ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int n,sum,i,j;
	char meirei[8];
	
	while(cin>>n,n){
		sum = 1;
		int map[3] = {1,2,3};
		while(n--){
			cin>>meirei;
			int tmp;
			if      ( !strcmp(meirei,"North") ){
				tmp = map[0];
				map[0] = map[1];
				map[1] = 7 - tmp;
				sum += map[0];
				
			}else if( !strcmp(meirei,"East") ){
				tmp = map[2];
				map[2] = map[0];
				map[0] = 7 - tmp;
				sum += map[0];
				
			}else if( !strcmp(meirei,"South") ){
				tmp = map[1];
				map[1] = map[0];
				map[0] = 7 - tmp;
				sum += map[0];
				
			}else if( !strcmp(meirei,"West") ){
				tmp = map[0];
				map[0] = map[2];
				map[2] = 7 - tmp;
				sum += map[0];
				
			}else if( !strcmp(meirei,"Right") ){
				tmp = map[1];
				map[1] = map[2];
				map[2] = 7 - tmp;
				sum += map[0];
				
			}else if( !strcmp(meirei,"Left") ){
				tmp = map[2];
				map[2] = map[1];
				map[1] = 7 - tmp;
				sum += map[0];
			}
			//printf("%d,%d,%d  sum_%d\n",map[0],map[1],map[2],sum);
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n){
        int t;
        cin >> t;
        if(t>=3200){
            mp[8]++;
        }else{
            mp[t/400]++;
        }
    }
    int ans = 0;
    rep(i, 8){
        if(mp[i]>0) ans++;
    }
    if(ans==0){
        cout << 1 << " " << mp[8] << endl;        
    }else{
        cout << ans << " " << ans+mp[8] << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 384
def insertionSort(A, N):
    for i in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    insertionSort(A, N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5980
program abc150b
      implicit none
      character(50)::s
      integer::i,n,ans
      
         read *, n
         read *, s
         
         ans=0
         do i=1,n-2
            if (s(i:i+2)=='ABC') ans=ans+1
         end do
         
         print *,ans
         
   end program abc150b


Measured memory_bytes: 768
#include<stdio.h>

int main(){
	
	int N,A,B,sum,ans=0,i,j;
	
	scanf("%d",&N);
	scanf("%d",&A);
	scanf("%d",&B);
	
	
	for(i=1;i<=N;i++){
	sum=0;
	j=i;
	while(j>0){
	sum+=j%10;
	j=j/10;
	}
	
	if(sum>=A&&sum<=B){
		ans+=i;
	}
	
	}
	
	
	printf("\n\n%d\n\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
N = int(input())
kotae = []
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            s = i
            t = j
            u = k
            x = 1
            while x != 0:
                v = t%s
                if v != 0:
                    t = s
                    s = v
                else:
                    t = s
                    x = u%t
                    if x != 0:
                        u = t
                        t = x
                    else:
                        kotae.append(t)
print(sum(kotae))

Measured memory_bytes: 218296
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Face = Tuple!(char, "dir", long, "num", bool, "edge");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, k, i, cnt;
    scan(n, k);
    auto s = sread();
    s ~= (s[n - 1] == 'R') ? 'L' : 'R';
    auto f = new Face[](0);
    while (++i < s.length)
    {
        if (s[i - 1] == s[i])
        {
            cnt++;
        }
        else
        {
            f ~= Face(s[i - 1], cnt + 1, false);
            cnt = 0;
        }
    }
    f[0].edge = true, f[$ - 1].edge = true;
    f = f.filter!(x => x.dir != s[0]).array();
    // f.each!(x => x.writeln());
    long happy = n - 1;
    f = f[min(k, f.length) .. $];
    happy -= f.length * 2;
    // f.writeln();
    if(!f.empty && f[$ - 1].edge)
        happy++;

    happy.writeln();
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 4220
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		log.Fatal(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}
func main() {
	sc.Split(bufio.ScanWords)

	x := getInt()

	for a := 1; a < 1000; a++ {
		for b := -1000; b < 1000; b++ {
			if a == b && x != 0 {
				continue
			}
			if x == 0 {
				out(0, 0)
				os.Exit(0)
			}
			if a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b == x/(a-b) {
				out(a, b)
				os.Exit(0)
			}
		}
	}
}


Measured memory_bytes: 1816
#include <cstdio>
#include <algorithm>

int main()
{
  int n;
  scanf("%d\n", &n);
  int l[2000];
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", l + i);
  }
  std::sort(l, l + n);
  long long ans = 0;
  for (int i = 0; i < n - 2; ++i)
  {
    for (int j = i + 1; j < n - 1; ++j)
    {
      ans += std::lower_bound(l + j + 1, l + n, l[i] + l[j]) - (l + j + 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

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


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <set>
#include <array>
#include <list>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

int main() {

	int n;
	int x;

	cin >> n >> x;

	vector<int> a(n);

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

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

	int sum = 0;
	int count = 0;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (sum <= x)
		{
			count++;
		}
		else
			break;
	}

	if (sum < x) count--;

	cout << count << endl;

	return 0;
}


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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int X, Y; cin >> X >> Y;
    cout << X + Y/2 << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;



int main() {
	int n, d, x[10][10];
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	int sum = 0;
	int count = 0;
	for (int i = 0; i < n-1; i++) {
		for (int j = i+1; j < n; j++) {
			sum = 0;
			for (int k = 0; k < d; k++) {
				int del = pow(x[i][k] - x[j][k], 2);
				sum += del;
			}
			for (int k = 1; k <= 200; k++) {
				if (sum == k * k) {
					count++;
					break;
				}
			}
		}
	}
	cout << count << endl;
	return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int times = B - A;
  
  int count = 0;
  for( int i = 0; i <= times; i++ ){
    int sen = ( A - ( ( A / 10000 ) * 10000 ) ) / 1000;
    int zyu = ( A / 10 ) % 10;
    if( A / 10000 == A % 10 && sen == zyu ){
      count++;
    }
    A++;
  }
  cout << count << endl;
}



Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

minlist = [0]*N
minlist[0] = 0
minlist[1] = abs(H[1] - H[0])
for i in range(2,N):
    minlist[i] = min(minlist[i-2] + abs(H[i-2] - H[i]), minlist[i-1] + abs(H[i-1] - H[i]))

print(minlist[N-1])

Measured memory_bytes: 20588
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const int MaxN = 1e5;

int n,s,ans;
int  a[MaxN + 5],b[MaxN + 5];

int gcd(int x,int y){
	if(y == 0)return x;
	return gcd(y,x%y);
}

int main(){
	cin >> n >> s;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for(int i = 1;i <= n;i++){
		b[i] = abs(s - a[i]);
	}
	ans = 1 << 30;
	for(int i = 1;i <= n;i++){
		ans = min(ans,gcd(b[i],b[1]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
a = [0] + a
b = [0] * -~n
for i in range(n, 0, -1):
    s = sum(b[j] for j in range(i, n + 1, i))
    if s % 2 != a[i]:
        b[i] = 1
print(sum(b))
print(*[i for i, b in enumerate(b) if b == 1])

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

int32_t main(){
	
  int n; cin>>n;
  int a[n+1];
  int dp[n+1][n+1];
  memset(dp,0,sizeof(dp));
  
  for(int i = 1; i<=n; i++)cin>>a[i];

  for(int len = 1; len<=n; len++){
  	for(int l = 1; l<=n-len+1; l++){
    	int r = l + len -1;
        if(len == 1)
          dp[l][r]=a[l];
        else
          dp[l][r] = max(a[l] -dp[l+1][r] , a[r] - dp[l][r-1]);
    }
  }
  	cout<<dp[1][n]<<endl;
	return 0;
}



Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

//vector<vector<ll>> G(N,vector<ll>(0));
void no_cost_graphmake(ll E,vector<vector<ll>> &G){
  rep(i,E){
    ll a,b;
    cin >> a >> b;
    G.at(a-1).push_back(b-1);
    G.at(b-1).push_back(a-1);//有向なら消す
  }
}

int main(){
  ll N,K,ans=1;
  cin >> N >> K;
  vector<vector<ll>> G(N,vector<ll>(0));
  no_cost_graphmake(N-1,G);
  queue<P> Q;
  Q.push(P(0,0));
  while(!Q.empty()){
    ll x=Q.front().first,y=Q.front().second;
    Q.pop();
    if(x==0){
      ans*=K;
      rep(i,G.at(x).size()){
        ans*=K-1-i;
        ans%=MOD;
        Q.push(P(G.at(x).at(i),x));
      }
    }else{
      rep(i,G.at(x).size()-1){
        ans*=K-2-i;
        ans%=MOD;
      }
      rep(i,G.at(x).size()){
        if(y==G.at(x).at(i)) continue;
        Q.push(P(G.at(x).at(i),x));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 11148
#include<iostream>
#include<algorithm>

using namespace std;
static const int MAX = 100;

void printArray(int array[],int N){
  for(int i = 0 ; i < N; i++){
    if(i > 0) cout << " ";
    cout << array[i];
  }
  cout << endl;
  return;
}

void insertionSort(int array[], int N){
  int i,j,tmp;
  for(i = 1 ; i < N ; i++){
    tmp = array[i];
    j = i - 1;
    while(j >= 0 && array[j] > tmp){
      array[j+1] = array[j];
      j--;
    }
    array[j+1] = tmp;
    printArray(array,N);
  }
  return;
}

int main(){
  int array[MAX],N;

  cin >> N;
  for(int i = 0 ; i < N ; i++) cin >> array[i];
  printArray(array,N);
  insertionSort(array,N);
}



Measured memory_bytes: 3092
from collections import deque

def main():
    n = int(input())
    adj = [[]for i in range(n+1)]
    ab = [list(map(int, input().split())) for i in range(n-1)]
    for a, b in ab:
        adj[a].append(b)
        adj[b].append(a)
    # dequeを使ったスタックによるDFS
    # 子をindexで、親ノードを要素で
    # 今回は彩色のためにどんな順番でpopされたかも保持しておく
    order  = []
    parent = [0] * (n+1)
    visited = [0] * (n+1)
    visited[1] = 1
    q = deque([1])
    while q:
        par = q.popleft()
        order.append(par)
        for chl in adj[par]:
            if visited[chl]:
                continue
            # 行ったことなかったら1へ
            visited[chl] = 1
            parent[chl] = par
            q.append(chl)
    # 彩色
    # 親と同じにならないように若い番号を割り当てて行く
    cl = [None] * (n+1)
    for par in order:
        # 親の色
        pc = cl[par]
        # 彩色は1以上k以下
        color = 1
        for chl in adj[par]:
            # 隣接リストの親は無視
            if chl == parent[par]:
                continue
            # 親の色と同じなら色を変える
            if pc == color:
                color += 1
            # カラーリストに子indexにcolorを入れる
            cl[chl] = color
            #　他の子は色を変える必要がある
            color += 1
    # 木グラフなので単純に次数最大で考えて問題ない
    g = max([len(i) for i in adj]) 
    print(g)   
    for a, b in ab:
        # 親子関係が逆転しない出力ならこれでいいがそうとも限らない 
        if parent[a] != b:
            print(cl[b])
        else:
            print(cl[a])
            
if __name__ == '__main__':
    main()

Measured memory_bytes: 41784
import java.util.*;
import java.io.*;

/**
 * C
 */
public class Main {

    void run() {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Set<String> dict = new HashSet<String>();

        for(int i=0; i<n; i++) {
            String doing = sc.next();
            String key = sc.next();
            if(doing.equals("insert")) {
                dict.add(key);
            } else {
                if(dict.contains(key)) {
                    System.out.println("yes");
                } else {
                    System.out.println("no");
                }
            }
        }

        sc.close();

    }

    public static void main(String[] args) {
        new Main().run();
    }

}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){

    string s, t;
    cin >> s >> t;
    cout << t + s << endl;

    return 0;
}

Measured memory_bytes: 256
program B083
    implicit none
    integer(8) :: N, A, B
    integer(8) :: i, j, k, l, sum

    read(5,*) N, A, B
    sum = 0
    do i = 1, N
        k = i
        l = 0
        do j = 1, 5
            l = l + mod(k,10**j) / 10**(j-1)
        end do
        if (A<=l .and. l<=B) then
            sum = sum + i
        end if
    end do

    write(6,*) sum



end program B083

Measured memory_bytes: 2920
N = int(input())
f = list(map(int, input().split()))
for i in range(N-1):
    f[i+1] += f[i]
l, r = 0, 2
ans = float('inf')
for m in range(1, N-2):
    while l+1 < m and abs(2*f[l+1]-f[m]) < abs(2*f[l]-f[m]):
        l += 1
    while r+1 < N and abs(2*f[r+1]-f[m]-f[N-1]) < abs(2*f[r]-f[m]-f[N-1]):
        r += 1
    tmp = max(f[l], f[m]-f[l], f[r]-f[m], f[N-1]-f[r]) - min(f[l], f[m]-f[l], f[r]-f[m], f[N-1]-f[r])
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 125560
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
const ll MOD=1e9+7;
ll mod(ll x)
{
   return (x%MOD+MOD)%MOD;
   // works for neg and pos values of x.
}

ll dp[2001];
ll get_ans(ll n)
{
    if(n<3) return 0;
    if(dp[n]!=-1) return dp[n];
    ll ans=1;
    fo(i,3,n-2)
    {
        //deb(n-i);
        ans+=get_ans(n-i);
        ans=mod(ans);
    }
    dp[n]=mod(ans);
    //deb(ans);
    return mod(ans);
}
void solve()
{
    ll n;
    cin>>n;
    fo(i,0,n+1) dp[i]=-1;
    cout<<get_ans(n);
}
int main()
{
//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

int main()
{
    long N;
    std::vector<long> H;
   std::cin >> N;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        H.push_back(temp);
    }
    H[0]=H[0]-1;
    int flag=0;
    for(long i=1; i<N;i++){
        if(H[i]>=H[i-1]){
            if(H[i]!=H[i-1]){
                H[i]=H[i]-1;
            }
        }else{
            flag=1;
            break;
        }
    }
    if(flag==0){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1400
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    K = int(input())
    q = deque()
    for i in range(9): q.append((i + 1, i + 1))
    lunlun = 1
    while lunlun < K:
        nowNum, lastNum = q.popleft()
        if lastNum > 0: q.append((nowNum * 10 + lastNum - 1, lastNum - 1))
        q.append((nowNum * 10 + lastNum, lastNum))
        if lastNum < 9: q.append((nowNum * 10 + lastNum + 1, lastNum + 1))
        lunlun += 1
    ans, lastNum = q.popleft()
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 24008
def examC():
    N = I()
    d = defaultdict(int)
    for i in range(N):
        curD = defaultdict(int)
        S = SI()
        for s in S:
            curD[s]+=1
        if i==0:
            d = curD
            continue
        for s in alphabet:
            d[s] = min(d[s],curD[s])
    d = sorted(d.items())
    ans = ""
    for key,i in d:
        ans +=key*i
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()


Measured memory_bytes: 3520
N = int(input())
ans = []

while N != 0:
    sup = N % 26
    if sup == 0:
        sup = 26
        ans.append(chr(96 + sup))
    else:
        ans.append(chr(96 + sup))
    N = int((N - sup) / 26)

ans = ''.join(reversed(ans))
print(ans)


Measured memory_bytes: 9156
_ = input()
s = input()

over = False


def process_slimes(s):
    res = ""
    curr = None
    over = True
    count = 0

    for c in s:
        if not curr:
            curr = c
            count += 1
        elif c != curr:
            res += curr
            curr = c
            count += 1
        else:
            over = False
    res += curr

    return res, count, over


while not over:
    s, count, over = process_slimes(s)

print(count)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x <<endl; 
#define De(...)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
using namespace std; 

int _; 

int n,a[200500],ans;

int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%lld",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		ans ^= a[i];
	}
	for(int i=0;i<n;i++)
		printf("%d ",ans^a[i]);
	return 0;
}


Measured memory_bytes: 4612
from math import gcd
a,b,c,d = map(int, input().split())

s = b - ((b//c)+(b//d)) + b//((c*d)//gcd(c,d))
t = (a-1) - (((a-1)//c)+((a-1)//d)) + (a-1)//((c*d)//gcd(c,d))
print(s-t)

Measured memory_bytes: 9052
#include <stdio.h>
#define N 200
int main()
{
    int i, a[N],b[N],dig[N];
    while(scanf("%d %d",&a[i], &b[i])!=EOF){
        int c[N];
        c[i]=a[i]+b[i];
        dig[i]=0;
        do{
            dig[i]++;
            c[i]/=10;
        }while(c[i]>=1);

        i++;
    }
    int sum=i;
    for(i=0;i<sum;i++){
        printf("%d\n",dig[i]);
    }
    //改行コード必要では？
    }



Measured memory_bytes: 2588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    ll ans = 0;
    for(int i = 1; i < n; i++)
    {
        ll d = x[i] - x[i-1];
        ans += min(a * d, b);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    cout << max(0LL, a - k) << " " << max(0LL, b - max(0LL, k - a)) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<queue>
#include<algorithm>
using namespace std;
#define N 5000
struct mzls
{
	int to;
	double cost;
}as;
struct mzls1
{
	int x,y,z;
}a1[N+5];
vector<mzls>g[N+5];
queue<int>q;
bool f[N+5],f1;
int n;
double dist[N+5];
inline void prepare()
{
	scanf("%d%d%d%d",&a1[1].x,&a1[1].y,&a1[2].x,&a1[2].y);
	a1[1].z=a1[2].z=0;
	dist[1]=dist[2]=1e18;
	scanf("%d",&n);
	n+=2;
	for(int i=3;i<=n;i++)
	{
		scanf("%d%d%d",&a1[i].x,&a1[i].y,&a1[i].z);
		dist[i]=1e18;
	}
	for(int i=2;i<=n;i++)
		for(int j=1;j<i;j++)
		{
			double ml=sqrt(1.0*(a1[i].x-a1[j].x)*(a1[i].x-a1[j].x)+1.0*(a1[i].y-a1[j].y)*(a1[i].y-a1[j].y));
			ml-=a1[i].z+a1[j].z;
			if(ml<0)
				ml=0;
			as.cost=ml;
			as.to=j;
			g[i].push_back(as);
			as.to=i;
			g[j].push_back(as);
		}
}
inline void SPFA(int s)
{
	dist[s]=0,f[s]=1;
	q.push(s);
	while(!q.empty())
	{
		int v=q.front();q.pop();
		f[v]=0;
		for(int i=0;i<g[v].size();i++)
		{
			mzls ml=g[v][i];
			if(dist[ml.to]>dist[v]+ml.cost)
			{
				dist[ml.to]=dist[v]+ml.cost;
				if(!f[ml.to])
				{
					q.push(ml.to);
					f[ml.to]=1;
				}
			}
		}
	}
}
int main()
{
	prepare();
	SPFA(1);
	printf("%.10lf\n",dist[2]);
	return 0;
}

Measured memory_bytes: 18560
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x =((x%MOD)+(y%MOD))%MOD;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return ((x%MOD)*(y%MOD))% MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {
        lld h,w,m;
        cin>>h>>w>>m;
        vector<lld>ar[h+1];
        vector<lld>br[w+1];
        set<pair<lld,lld>>s;
        for(i=0;i<m;i++)
        {
            lld a,b;
            cin>>a>>b;
            s.insert({a,b});
            ar[a].push_back(b);
            br[b].push_back(a);
        }
        vector<pair<lld,lld>>cr,dr;
        for(i=1;i<=h;i++)
        cr.push_back({ar[i].size(),i});
        for(i=1;i<=w;i++)
        dr.push_back({br[i].size(),i});
        sort(cr.rbegin(),cr.rend());
        sort(dr.rbegin(),dr.rend());
        lld ans=cr[0].first+dr[0].first;
        if(s.find({cr[0].second,dr[0].second})!=s.end())
           ans--;
        else
            {
                cout<<ans<<endl;
                return 0;
            }
        for(i=0;i<cr.size();i++)
        {
            if( i!=0 && cr[i].first!=cr[i-1].first)
            break;
            for(j=0;j<dr.size();j++)
            {   if(j!=0 && dr[j].first!=dr[j-1].first)
                break;
                if(i==0 && j==0)
                {
                ans=cr[0].first+dr[0].first;
                if(s.find({cr[0].second,dr[0].second})!=s.end())
                ans--;
                else
                {
                cout<<ans<<endl;
                return 0;
                }
                }
                lld curr=cr[i].first+dr[j].first;
                if(s.find({cr[i].second,dr[j].second})!=s.end())
                curr--;
                if(curr>ans)
                {
                    cout<<curr<<endl;
                    return 0;
                }
            }
        }
        cout<<ans<<endl;
    }
}





Measured memory_bytes: 71816
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define fr(i,n,m) for(ll i=n;i<m;i++)
int main()
{
    ll n,a,b=0,sum=0;
    scanf("%lli",&n);
    fr(i,1,n+1){
        scanf("%lli",&a);
        if(b>a){
            sum += b-a;
            continue;
        }
        b = a;
    }
    printf("%lli",sum);
    return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int r, D, x;
    cin >> r >> D >> x;
    rp(i, 0, 10) {
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 3568
from collections import deque

def search(h, w, pre_h, pre_w):
    can = []
    if h > 0:
        can.append((h-1, w))
    if h < H-1:
        can.append((h+1, w))
    if w > 0:
        can.append((h, w-1))
    if w < W-1:
        can.append((h, w+1))
    res = []
    for h, w in can:
        if S[h][w]=='.' and (h, w) != (pre_h, pre_w):
            res.append((h, w))
    return res

def bfs(h, w):
    d = [[float('inf') for _ in range(W)] for _ in range(H)]
    d[h][w] = 0
    pre_h, pre_w = h, w
    adj_list = search(h, w, pre_h, pre_w)
    open_list = deque([])
    closed_list = []
    closed_list = set(closed_list)
    for adj in adj_list:
        open_list.append((adj[0], adj[1], pre_h, pre_w))
    cnt = 0
    while True:
        cnt+=1
        if H==20 and W==20:
            if cnt > 10000:
                break
        if len(open_list) == 0:
            break
        h, w, pre_h, pre_w = open_list.popleft()
        closed_list.add((h, w, pre_h, pre_w))
        d[h][w] = min(d[h][w], d[pre_h][pre_w] + 1)
        adj_list = search(h, w, pre_h, pre_w)
        for adj in adj_list:
            if (adj[0], adj[1], h, w) in closed_list:
                continue
            open_list.append((adj[0], adj[1], h, w))

    res = 0
    for h in range(H):
        for w in range(W):
            if not d[h][w] == float('inf'):
                res = max(res, d[h][w])
    return res

def bounday():
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                return False
    return True

H, W = map(int, input().split())
S = []
for i in range(H): 
    S.append(list(input()))

if __name__ == "__main__":

    if bounday():
        print(H+W-2)
        exit(0)

    ans = 0
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                continue
            maxd = bfs(h, w)
            ans = max(maxd, ans)
    print(ans)

Measured memory_bytes: 3572
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    LLONG X, Y; cin >> X >> Y;
    int ans = 0;
    while (X <= Y)
    {
        ++ans;
        X *= 2;
    }
    cout << ans << endl;
}

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

int main()
{
  int N ;
  cin>>N ;
  vector<int64_t>A(N) ;
  for(int i=0;i<N;i++){
    cin>>A.at(i) ;
    A.at(i)-=(i+1)  ;
  }
  sort(A.begin(),A.end()) ;
  
  int64_t b ;
  if(N%2==0) b=(A.at(N/2-1)+A.at(N/2))/2 ;
  else b=A.at(N/2) ;
  
  int64_t sum=0 ;
  for(int i=0;i<N;i++){
    if(A.at(i)<b) sum+=b-A.at(i) ;
    else sum+=A.at(i)-b ;
  }
  cout<<sum<<endl ;
  
  return 0 ;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

vi fg[100005], bg[100005], s;
vi label(100005, -1);

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        fg[a].push_back(b);
        fg[b].push_back(a);
    }
    rep(i, k){
        int a, b;
        cin >> a >> b;
        a--; b--;
        bg[a].push_back(b);
        bg[b].push_back(a);
    }
    int num = 0;
    rep(i, n) {
        if (label[i] >= 0) continue;
        int p, size = 0;
        stack<int> st;
        label[i] = num;
        st.push(i); size++;
        while (st.size() > 0) {
            p = st.top();
            st.pop();
            for (int j : fg[p]) {
                if (label[j] < 0) {
                    label[j] = num;
                    st.push(j); size++;
                }
            }
        }
        s.push_back(size);
        num++;
    }
    rep(i, n) {
        int ans;
        ans = s[label[i]] - 1 - fg[i].size();
        for (int j : bg[i]) {
            if (label[j] == label[i]) ans--;
        }
        printf("%d%c", ans, i==n-1?'\n':' ');
    }
    return 0;
}



Measured memory_bytes: 12664
#include <iostream>

using namespace std;

typedef long long llong;

const llong mod = 1E9 + 7;

llong binary_pow(llong a, llong p)
{
    llong cur = a;
    llong ans = 1;

    while (p > 0)
    {
        if (p & 1)
            ans = (ans * cur) % mod;

        cur = (cur * cur) % mod;
        p /= 2;
    }

    return ans;
}

llong prod(llong a, llong b)
{
    llong ans = 1;

    while (a <= b)
    {
        ans = (ans * a) % mod;
        a++;
    }

    return ans;
}

llong comb(llong n, llong k)
{
    llong first = prod(n - k + 1, n);

    llong second = prod(1, k);
    second = binary_pow(second, mod - 2);

    return (first * second) % mod;
}

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

    llong n, a, b;
    cin >> n >> a >> b;

    llong total = binary_pow(2, n) - 1;
    total = total - comb(n, a) - comb(n, b);
    total = (total <= 0 ? total + mod * mod : total) % mod;

    cout << total << "\n";

    return 0;
}


Measured memory_bytes: 256
/*  
*  Sachin Mittal
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,j,n) for(int i=j;i<n;i++)
#define rrep(i, j, n) for(int i = j; i >= n; i--)
#define F first
#define S second
#define lb lower_bound
#define mem0(dp) memset(dp,0,sizeof(dp))
#define mem1(dp) memset(dp,-1,sizeof(dp))
#define pb push_back
#define sz(s) (int)(s.size())
#define debug(x) cout << #x << " = " << x << '\n';

int fast_power(int base,int power,int modulo)
{
  int result=1;
  while(power)
  {
    if(power%2)
    result=(result*base)%modulo;
    base=(base*base)%modulo;
    power/=2;
  }
  return result;
}

void solve(){
  int k;
  cin >> k;
  k *= 9;
  rep(i, 1, 1e6 + 5){
    int p = fast_power(10, i, k);
    p = (p - 1 + k) % k;
    p = (p * 7) % k;
    if(!p){
      cout << i << '\n';
      return;
    }
  }
  cout << -1 << '\n'; 
}

int32_t main(){
 
  ios_base::sync_with_stdio(false); 
  cin.tie(0); cout.tie(0);
  int tst = 1;
  // cin >> tst;
  while(tst--){
    solve();
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 ll n; cin>>n;
  string s; cin>>s;
  ll ans=1;
  char f; f=s[0];
  for(ll i=1;i<n;i++){
  ll t=s[i];
    if(t!=f){
    ans++; f=t;
    }
    
  }
  cout<<ans<<endl;
  
}

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

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

  ll H; cin >> H;
  ll W; cin >> W;
  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  int dr[] = {0, 1, 0, -1};
  int dc[] = {1, 0, -1, 0};
  vector<vector<ll>> cells(H, vector<ll>(W, 0));
  int cnt = 0, r = 0, c = 0, d = 0, n = 1;
  while (true) {
    if (cells[r][c] == 0) {
      cells[r][c] = n;
      cnt++;
      if (cnt == A[n - 1]) {
        cnt = 0;
        n++;
        if (n > N) break;
      }
    }
    for (ll i = 0; i < 4; i++) {
      ll nr = r + dr[d], nc = c + dc[d];
      if (nr >= 0 && nr < H && nc >= 0 && nc < W) {
        if (cells[nr][nc] == 0) {
          r = nr, c = nc;
          break;
        }
      } {
        d++; d %= 4;
      }
    }
  }

  for (int i = 0; i < cells.size(); i++) { cout << cells[i][0]; for (int j = 1; j < cells[i].size(); j++) { cout << ' ' << cells[i][j]; } cout << '\n'; }
  return 0;
}

Measured memory_bytes: 512
n = int(input())
number_of_monsters =  list(map(int,input().split()))
feasible_beat =  list(map(int,input().split()))

start = sum(number_of_monsters)
for i in range(n):
    if number_of_monsters[i] < feasible_beat[i]:
        number_of_monsters[i+1] -= (feasible_beat[i] - number_of_monsters[i])
        number_of_monsters[i] = 0
        if number_of_monsters[i+1] < 0:
            number_of_monsters[i+1] = 0
    else:
        number_of_monsters[i] -= feasible_beat[i]
print(start-sum(number_of_monsters))


Measured memory_bytes: 18476
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,A,B,C,D;
ll L,R;
void chk(){if(L<=B&&B<=R)puts("YES"),exit(0);}
int main()
{
	n=read();A=read();B=read()-A;C=read();D=read();
	for(int i=0;i<n;++i)
	{
		L=1ll*C*i-1ll*(n-1-i)*D;
		R=1ll*D*i-1ll*(n-1-i)*C;
		chk();
	}
	puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
  int n, m;
  cin >> n >> m;
  int l = 0, r = 100000;
  vector<int> throuth(n + 1, 0);
  for(int i = 0; i < m; i++){
    int left, right;
    cin >> left >> right;
    l = max(l, left);
    r = min(r, right);
  }
  if(l <= r) cout << r - l + 1 << endl;
  else cout << '0' << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int a[6];
    int c[4] = {};
    for(int i =0;i<6;i++){
        cin >> a[i];
        if(a[i] == 1) c[0]++;
        else if(a[i] == 2) c[1]++;
        else if(a[i] == 3) c[2]++;
        else if(a[i] == 4) c[3]++;
    }
    int max = 0;
    for(int i =0;i<4;i++)
        if(max < c[i]) max = c[i];
    if(max < 3) cout << "YES" << "\n";
    else cout << "NO" << "\n";
    return 0;
}


Measured memory_bytes: 256
n=int(input())
l = [list(map(int,input().split())) for _ in range(n)]
l.insert(0,[0,0,0])
can = True
for i in range(len(l)-1):
    dt = l[i+1][0] - l[i][0]
    dist = abs(l[i+1][1] - l[i][1]) + abs(l[i+1][2]-l[i][2])
    if dt < dist:
        can = False
        break
    if dist % 2 != dt % 2:
        can = False
        break
print('Yes') if can else print('No')

    



Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;
int main(){
 
int N,K; cin >> N >> K;
ll sum = pow(K-1,N-1);
sum *= K;
cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int H, W, N;
	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;//上からr番目、左からc番目
	string S, T;
	cin >> S >> T;
	//右に落としたい
	int nowr = sr, nowc = sc;
	for(int i = 0; i < N; i ++){
		if(S[i] == 'R')nowc ++;
		if(nowc > W){
			cout << "NO" << endl;
			return 0;
		}
		if(T[i] == 'L' && nowc > 1)nowc --;
	}
	//左に落としたい
	nowr = sr;
	nowc = sc;
	for(int i = 0; i < N; i ++){
		if(S[i] == 'L')nowc --;
		if(nowc < 1){
			cout << "NO" << endl;
			return 0;
		}
		if(T[i] == 'R' && nowc < W)nowc ++;
	}
	//上に落としたい
	nowr = sr;
	nowc = sc;
	for(int i = 0; i < N; i ++){
		if(S[i] == 'U')nowr --;
		if(nowr < 1){
			cout << "NO" << endl;
			return 0;
		}
		if(T[i] == 'D' && nowr < H)nowr ++;
	}
	//下に落としたい
	nowr = sr;
	nowc = sc;
	for(int i = 0; i < N; i ++){
		if(S[i] == 'D')nowr ++;
		if(nowr > H){
			cout << "NO" << endl;
			return 0;
		}
		if(T[i] == 'U' && nowr > 1)nowr --;
	}

	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i, k, N) for (decltype(N + k) i = k; i < N; i++)
#define rep(i, N) for (decltype(N) i = 0; i < N; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
template <class X>
void pr(X test) { cout << test << endl; }
template <class X>
void prr(X test)
{
    for (auto it : test)
    {
        cout << it << " ";
    }
    cout << endl;
}
template <class X>
void prrr(X test)
{
    int f = 0;
    for (auto it : test)
    {
        cout << (f++ != 0 ? " " : "") << it;
    }
    cout << endl;
}
template <typename X>
istream &operator>>(istream &i, vector<X> &v)
{
    for (X &x : v)
        i >> x;
    return i;
}

vector<string> split(string s, char sep)
{
    vector<string> ret = {""};
    for (auto it : s)
    {
        if (it == sep)
            ret.push_back("");
        else
            ret.back().push_back(it);
    }
    return ret;
}

void solve();
int main()
{
    ll n;
    cin >> n;
    ll sum = 0;
    fr(i, 1, n + 1)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            sum += i;
        }
    }
    pr(sum);
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using LL = long long;
const int INF = 1e9;

int main(void) {
    LL N, A, B;
    cin >> N >> A >> B;
    LL a = min(A, B);
    LL b = max(A, B);
    if (a%2==b%2) {
        cout << (b - a) / 2 << endl;
    } else {
        cout << min(min(b-1, N-a), min((a+b-1)/2, (2*N-a-b+1)/2)) << endl;
    }
}



Measured memory_bytes: 256