akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, k := nextInt(), nextInt()
	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = nextInt() - 1
	}
	c := nextInts(n)

	// マスfromからステップごとに得られるスコア
	calcPoint := func(from int) []int {
		point := make([]int, 0)
		sum := 0
		for i := from; ; i = p[i] {
			to := p[i]
			sum += c[to]
			point = append(point, sum)
			if to == from {
				break
			}
		}
		return point
	}

	ans := -10000000000
	for i := 0; i < n; i++ {
		// マスiから始めたときの最大スコアを求める
		point := calcPoint(i)
		size := len(point)
		var score int
		if k >= size && point[size-1] > 0 {
			// できるだけ多く周回
			// マスiから距離j+1の位置のマスを終着点としてスコア計算
			for j := range point {
				rap := (k - j - 1) / size
				score = max(score,
					point[j]+point[size-1]*rap)
			}
		} else {
			// 周回はしないorできない
			score = max(point[:min(size, k)]...)
		}
		ans = max(ans, score)
	}

	puts(ans)
}


Measured memory_bytes: 6592
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;


#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)


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

    int T=1;// cin>>T;
    while(T--){
        string s;
        cin>>s;
        bool f=true;
        for(int i=0; i<s.size()-1; i++){
            if(s[i]!=s[i+1]){
                f=false;
                break;
            }

        }
        if(f)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    }
    End;
}
/* pray for me
Do before die
*/





Measured memory_bytes: 256
H,W=list(map(int,input().split()))
N=int(input())
data=list(map(int,input().split()))
ans=[[0]*W for i in range(H)]
n_w,n_h=0,0
color=1
dire=1
for i in data:
   while i>0:
      if dire==1:
         i-=1
         ans[n_h][n_w]=color
         if n_w==W-1:
            dire=-1
            n_h+=1
         else:
            ans[n_h][n_w]=color
            n_w+=1
      else:
         i-=1
         ans[n_h][n_w]=color
         if n_w==0:
            dire=1
            n_h+=1
         else:
            ans[n_h][n_w]=color
            n_w-=1
   color+=1
for i in ans:
   print(" ".join(map(str,i)))

Measured memory_bytes: 9308
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = input()
f = int(s[:2])
b = int(s[2:])
flag1 = 0
flag2 = 0
if 0 <= f and f <= 99 and 1<= b and b<=12:
    flag1 = 1
if 0 <= b and b <= 99 and 1<= f and f<=12:
    flag2 = 1
if flag1 == 1 and flag2 == 1:
    print("AMBIGUOUS")
elif flag1 == 1:
    print("YYMM")
elif flag2 == 1:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3064
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,M = II()
L,R,C = Line(M,3)

from heapq import heappop, heappush
def dijkstra(E,s,n):
    inf=float('inf')
    d=[inf for _ in range(n)]
    d[s]=0
    q=[]
    heappush(q,(0,s))
    while q:
        du, u1 = heappop(q)
        if d[u1]<du: continue
        for v1,weight in E[u1].items():
            alt=du+weight
            if d[v1]>alt:
                d[v1]=alt
                heappush(q, (alt,v1))
    return d

A = []
for i in range(M):
    A.append((L[i]-1,R[i]-1,C[i]))
A.sort(key=lambda x:-x[2])

E = [dict() for _ in range(N)]
for i in range(M):
    E[A[i][0]][A[i][1]] = A[i][2]

for i in range(N-1):
    E[i+1][i] = 0

d = dijkstra(E,0,N)
if d[-1]==float('inf'):
    print(-1)
else:
    print(d[-1])

Measured memory_bytes: 121820
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define N 1000005
using namespace std;
typedef long long LL;
inline int read()
{
	char c=getchar(); int num=0,f=1;
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c<='9'&&c>='0') { num=num*10+c-'0'; c=getchar(); }
	return num*f;
}
inline LL readl()
{
	char c=getchar(); LL num=0,f=1;
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c<='9'&&c>='0') { num=num*10+c-'0'; c=getchar(); }
	return num*f;
}
int n,cnt=0,a[N],b[N],w[N],fa[N];
struct data{
	LL w; int s,x;
	data(LL _w=0,int _s=0,int _x=0) { w=_w; s=_s; x=_x; }
	bool operator < (const data o) const { return w*o.s<o.w*s||w*o.s==o.w*s&&x<o.x; }
}p[N];
LL ans;
set<data> Q;
int find(int x) { return b[x]==x?x:b[x]=find(b[x]); }
int main()
{
	cnt=n=read(); for (int i=2;i<=n;i++) fa[i]=read();
	for (int i=1;i<=n;i++)
	{
		w[i]=readl(); b[i]=i;
		p[i]=data(w[i],1,i);
		Q.insert(p[i]);
	}
	while (!Q.empty())
	{
		data t=*Q.begin(),e=t; Q.erase(t);
		int y=find(fa[t.x]); if (y==0) continue;
		ans+=(t.s-t.w)*p[y].w;
		Q.erase(p[y]);
		e.w+=p[y].w; e.s+=p[y].s; e.x=++cnt;
		b[cnt]=cnt; b[y]=cnt; b[find(t.x)]=cnt;
		fa[cnt]=fa[y]; fa[t.x]=cnt; 
		p[cnt]=e; Q.insert(e);
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 37376
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

# a = cmb(n,r,mod)

ans = 0
n,k = map(int,input().split())

if n <= k:
    k = n-1
# print(k)

while k >=0:
    if k == 0:
        ans += 1
        ans %= mod
    else:
        base = cmb(n,k,mod)
        # print(base)
        base *= cmb(n-1,n-k-1,mod)
        base %= mod
        ans += base
        ans %= mod
    # print(ans,k)
    k-=1

print(ans)

Measured memory_bytes: 27092
n = int(input())

res = [0,0,0,0]
for _ in range(n):
    tmp = input()
    if tmp == "AC":
        res[0] +=1
    elif tmp == "WA":
        res[1] +=1
    elif tmp == "TLE":
        res[2] +=1
    elif tmp == "RE":
        res[3] +=1

print("AC x ", res[0])
print("WA x ", res[1])
print("TLE x ", res[2])
print("RE x ", res[3])

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  --k;

  if(s[k] == 'A') s[k] = 'a';
  if(s[k] == 'B') s[k] = 'b';
  if(s[k] == 'C') s[k] = 'c';

  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3616
MOD = 10**9 + 7
S = int(input())
dpt = [[0 for i in range(S+1)] for i in range(S//3+1)]

for i in range(3, S+1):
    dpt[1][i] = 1

for i in range(2, S//3+1):
    s = 0
    for j in range(3*i, S+1):
        s += dpt[i-1][j-3]
        dpt[i][j] = s % MOD
print(sum([dpt[i][S] for i in range(S//3+1)])%MOD)

Measured memory_bytes: 40376
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;
enum long MOD = 10L^^9+7;

void main() {
  long N, K;
  scanln(N, K);
  long[] hs = readln.split.to!(long[]).sort!"a>b".array;
  long ans = 0;
  foreach(h; hs) {
    if (K > 0) {
      K--;
    } else {
      ans += h;
    }
  }
  ans.writeln;
}

// ----------------------------------------------


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
  static if (__VERSION__ >= 2071) {
    readf!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "readf(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


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

int main() {
  string s, t;

  cin >> s >> t;

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

  if (s < t) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 998244353

using namespace std;
using ll = long long;

int main() {
	double a, b,  h, m;
	cin >> a >> b >> h >> m;
	h = 30 * h + m / 2;
	m = m * 6;
	double rad = max(h, m) - min(h, m);
	if (rad > 180) rad = 360 - rad;
	rad = acos(-1) * rad / 180;
	double ans = a*a  + b*b - 2*a*b*cos(rad);
	ans = sqrt(ans);
	printf("%.10f\n", ans);
	return 0;
}


Measured memory_bytes: 4196
import math

def main():

    N = int(input())

    pts = []
    for _ in range(N):
        x, y = map(int, input().split())
        pts.append((x, y))

    total = 0
    for i in range(N):
        x1, y1 = pts[i]
        for j in range(i + 1, N):
            x2, y2 = pts[j]

            dx = x2 - x1
            dy = y2 - y1
            distSq = dx * dx + dy * dy

            total += math.sqrt(distSq)

    print(total * 2 / N)


main()


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for (int a, b, n; cin >> a >> b >> n;) {
		int s = 0;
		while (n--)
			s += ((a %= b) *= 10) / b;
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MOD = 1000 * 1000 * 1000 + 7;

//const int MAX = 1000007;


LL ans = 0;
LL a[200007], b[200007];
int n;

int main()
{
    //freopen("in.txt", "r", stdin);
    //ios::sync_with_stdio(false); cin.tie(0);
    //freopen("/Users/Taras/Downloads/big_top.txt", "r", stdin);
    //freopen("/Users/Taras/Downloads/mout.txt", "w", stdout);
    
    cin >> n;
    FOR (i,0,n) cin >> a[i] >> b[i];
    RFOR (i,n,0)
    {
        a[i] += ans;
        LL x = (a[i]+b[i]-1)/b[i]*b[i]-a[i];
        ans += x;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
n,m = map(int,input().split())
d = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)

ans = [-1]*n
ans[0] = 0
from collections import deque
q = deque([0])
while q:
    u = q.popleft()
    for v in d[u]:
        if ans[v]==-1:
            ans[v] = u
            q.append(v)
print('Yes')
for i in ans[1:]:
    print(i+1)

Measured memory_bytes: 34856
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	costs := ScanFloats(n)
	dp := make([]float64, n)
	dp[1] = math.Abs(costs[0] - costs[1])
	for i := 2; i < n; i++ {
		abs1 := math.Abs(costs[i-1] - costs[i])
		abs2 := math.Abs(costs[i-2] - costs[i])
		if dp[i-1]+abs1 < dp[i-2]+abs2 {
			dp[i] = dp[i-1] + abs1
		} else {
			dp[i] = dp[i-2] + abs2
		}
	}
	fmt.Println(int(dp[n-1]))
}

func ScanFloats(len int) (nums []float64) {
	var num float64
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 5504
#include <cstdio>
int ans[505][505];
int main()
{
 int k;
 scanf("%d",&k);
 if(k==1)
 {
  puts("1");
  puts("1");
  return 0;
 }
 int n=(k+1)/2;
 if(n%2)n++;
 printf("%d\n",n);
 for(int i=0;i<n;i++)
  for(int j=0;j<n;j++)
   ans[i][j]=n*(i%2)+(i+j)%n+1;
 for(int c=2*n;c>k;c--)
  for(int i=1;i<n;i+=2)
   for(int j=0;j<n;j++)
    if(ans[i][j]==c)ans[i][j]-=n;
 for(int i=0;i<n;i++)
 {
  for(int j=0;j<n;j++)
   printf("%d ",ans[i][j]);
  puts("");
 }
 return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int num[3];
    cin >> num[0] >> num[1] >> num[2];
    sort(num, num + 3);
    cout << num[0] << ' ' << num[1] << ' ' << num[2] << endl;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
#define chmax(x, y) { x = max(x, y); }
#define chmin(x, y) { x = min(x, y); }

int main(){
    int n,i=1;
    cin>>n;

    while(true){
        if(n-1000*i<=0){
            cout<<-(n-1000*i)<<endl;
            return 0;
        }
        i++;
    }
}

Measured memory_bytes: 3632
n,q = map(int,input().split())

#print(n,q)
edge=[]
for i in range(n-1):
    a = list(map(int,input().split()))
    edge.append(a)

add_list = []
for i in range(q):
    p = list(map(int,input().split()))
    add_list.append(p)

#print(edge,add_list)

ans = [0] * n
edge_list = [-1] * n

for e in edge:
    edge_list[e[1]-1] = e[0]-1

add_value = [0]*n
for v in add_list:
    add_value[v[0]-1] += v[1]

#print(edge_list)
#print(add_value)


dp = [-1] * n
def get_value(i):
    if(dp[i]!=-1):
        return dp[i]
    tmp = add_value[i]
    if edge_list[i] != -1:
        tmp += get_value(edge_list[i])
    dp[i] = tmp
    return dp[i]

for i in range(n):
    ans[i] = get_value(i)
    #print(i,ans)

print(' '.join(map(str,ans)))

Measured memory_bytes: 141864
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 100000
int n,x;
int A,G;
int gcd(int m,int n)
{
    while(m>0)
    {int c=n%m;n=m,m=c;}
    return n;
}
int main()
{
    scanf("%d%d",&n,&x);
    scanf("%d",&A);
    G=abs(x-A);
    for(int i=2;i<=n;i++){scanf("%d",&A);G=gcd(G,abs(x-A));}
    printf("%d",G);
}


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

class co{
	public:
	int x,y,r;
	co(){};
	co(int x,int y,int r){
		this->x=x;
		this->y=y;
		this->r=r;
	};
	bool operator < (const co& c) const {
		if(this->x-this->r != c.x-c.r)
			return this->x-this->r < c.x-c.r;
		else
			return this->y-this->r < c.y-c.r;
	}
};

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

	int x,y,r;
	co c[1<<18];

	int i=0;
	while(i<N){
		cin>>x>>y>>r;
		c[i]=co(x,y,r);
		i++;
	}

	//sort(&c[0],&c[N-1]);
	sort(&c[0],&c[N]);

	/*
	for(i=0;i<N;i++){
		cout<<"c{"<<c[i].x<<","<<c[i].y<<","<<c[i].r<<"}"<<endl;
	}
	*/

	bool all,exit;
	int sn;

	all=true;
	exit=false;
	sn=0;
	for(int w=0;w<=W;w++){
		if(sn==N){
			all=false;
			break;
		}
		for(int n=sn;n<N;n++){
			sn=n;
			//cout<<"n="<<n<<", w="<<w<<endl;
			if( w<(c[n].x-c[n].r) ){
				//cout<<"c{"<<c[n].x<<","<<c[n].r<<"} (w<)"<<endl;
				all=false;
				break;
			}else if( ((c[n].x-c[n].r)<=w)&&
			          (w<=(c[n].x+c[n].r)) )
			{
				//cout<<"c{"<<c[n].x<<","<<c[n].r<<"} (<=w<=)"<<endl;
				w=c[n].x+c[n].r-1;
				sn++;
				if(w+1==W) exit=true;
				break;
			}else{
				//cout<<"c{"<<c[n].x<<","<<c[n].r<<"} (<w)"<<endl;
				if(n==N-1){
					all=false;
				}
			}
		}
		//cout<<"sn="<<sn<<", w="<<w<<endl;
		if(exit) break;
	}

	//cout<<"all="<<all<<endl;

	if(!all){
		all=true;
		exit=false;
		sn=0;
		for(int h=0;h<H;h++){
			if(sn==N){
				all=false;
				break;
			}
			for(int n=sn;n<N;n++){
				sn=n;
				//cout<<"n="<<n<<", h="<<h<<endl;
				if( h<(c[n].y-c[n].r) ){
					//cout<<"h<"<<endl;
					all=false;
					break;
				}else if( ((c[n].y-c[n].r)<=h)&&
				          (h<=(c[n].y+c[n].r)) )
				{
					//cout<<"<=h<="<<endl;
					h=c[n].y+c[n].r-1;
					sn++;
					if(h+1==H) exit=true;
					break;
				}else{
					//cout<<"<h"<<endl;
					if(n==N-1){
						all=false;
					}
				}
			}
			//cout<<"sn="<<sn<<", h="<<h<<endl;
			if(exit) break;
		}
	}

	if(all)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

}

Measured memory_bytes: 4196
#include <vector>
#include <string>
#include <iostream>
using namespace std;
bool NeedSwp(string& a, string& b,int l){
	for (int i = 0; i < l; ++i){
		if (b[i] < a[i]){ return true; }
		if (b[i] > a[i]){ return false; }
	}
	return false;
}
void swp(string& a, string& b){
	string t = a;
	a = b;
	b = t;
}
int main()
{
	vector<string> nStr;
	int N, L;
	cin >> N >> L;
	for (int i = 0; i < N; ++i){
		string s;
		cin >> s;
		nStr.push_back(s);
	}

	for (int t = 0; t < N; ++t){
		bool flag = false;
		for (int i = 0; i < N - 1; ++i){
			if (NeedSwp(nStr[i], nStr[i + 1],L)){
				swp(nStr[i], nStr[i + 1]);
				flag = true;
			}
		}
		if (!flag){ break; }
	}
	string ans;
	for (auto& elem : nStr){
		ans += elem;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, ans=0;
  cin >> N >> M;
  vector<int> B(M);
  
  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A;
      cin >> A;
      B.at(A-1)++;
    }
  }
  for (int i = 0; i < M; i++) {
    if (B.at(i) == N) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void we_r_done(){cout<<"NO"; exit(0);}

void debug(string mssg){cout<<mssg; exit(0);}

using minHeap = priority_queue< int, vector< int >, greater< int > >;

vector<int>g[100005];
int ans = 0;
bool vis[100005];
int dp[100005];

void dfs(int x){

    vis[x] = true;

    for(int u : g[x]){

        if(vis[u]){
            dp[x] = max(dp[x] , 1+dp[u]);
            continue;
        }
        dfs(u);

        dp[x] = max(dp[x] , 1+dp[u]);
    }
}

int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    int n,m;
    scn2(n,m);

    for(int i=0; i<m; i++){
        int x,y;
        scn2(x,y);
        g[x].pb(y);
    }

    for(int i=1; i<=n; i++){
        if(vis[i]==false)dfs(i);
    }

    for(int i=1; i<=n; i++) ans = max(ans , dp[i]);

    cout<<ans;
    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 8192
import sys

n = int(input())

d1d2 = [map(int, input().split()) for _ in range(n)]
d1, d2 = [list(i) for i in zip(*d1d2)]

cnt = 0
for i in range(n):
    if d1[i] == d2[i]:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        print("Yes")
        sys.exit()

print("No")


Measured memory_bytes: 9184
#include <stdio.h>
#include <math.h>


int n,i,j,sqrtn,sum,flag;
char number[1000000];

int hantei(int x){
	if (number[x]==1){
		return 0;
	}
	sqrtn=(int)sqrt(x);
	flag=0;
	for(j=1;j*6-1<sqrtn;j++){
		if(x%(j*6+1)==0 || x%(j*6-1)==0){
			flag=1;
			break;
		}
	}
	if(flag==0){		/*ツ素ツ青板つカツづ。ツづ按つ「ツづ個づ可フツδ可グツづーツ猟ァツづづつュツづヲ*/
		sum++;
		for(j=3*x;j<n;j+=x+x){
			number[j]=1;
		}
	}
	return 0;

}

int main(){
	while(scanf("%d",&n)!=EOF){
		/*for(i=0;i<n;i++){
			number[i]=0;
		}*/
		if (n>=3){
			sum=2;
		}else if (n==2){
			sum=1;
		}else{
			sum=0;
		}
		for(i=6;i-1<=n;i+=6){
			hantei(i-1);
			if(i+1<=n)hantei(i+1);
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

Measured memory_bytes: 1380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N; cin >> N;
  if(N==1 || N==0){
    cout << 0 << endl;
    return 0;
  }
  if(N%2==1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  rep(i,60){
    ans += N/5/2;
    N /= 5;
  }

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


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

int main() {
  int N;cin>>N;
  vector<char> S(N);
  for(int i=0;i<N;i++)cin>>S.at(i);
  vector<int> R(N),L(N);
  int cnt=0;
  for(int i=0;i<N-1;i++){
    if(S.at(i)=='W'){
      cnt++;
    }
    R.at(i+1)=cnt;
  }
  cnt=0;
  for(int i=N-1;i>0;i--){
    if(S.at(i)=='E'){
      cnt++;
    }
    L.at(i-1)=cnt;
  }  
  R.at(0)=0;
  L.at(N-1)=0;
  int mini=10000000;
  for(int i=0;i<N;i++){
    R.at(i)+=L.at(i);
    mini=min(mini,R.at(i));
  }
  cout<<mini<<endl;
}


Measured memory_bytes: 2944
/* ***********************************************
Author        :yang12138
Created Time  :2017年04月19日 星期三 19时30分51秒
File Name     :D.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=2e5+10;
const int INF=1e9+5;
const int mod=1e9+7;

vector<pii>g[N];
vector<int>gg[N],p;
int c[N],w[N];
bool vis[N];

int fa[N],cnt[N];
ll fact[N],inv[N];

ll quick_pow(ll base,ll n){
	ll ans=1;
	while(n){
		if(n&1) (ans*=base)%=mod;
		(base*=base)%=mod;
		n>>=1;
	}
	return ans;
}

void init(){
	fact[0]=1,inv[0]=1;
	for(int i=1;i<N;i++){
		fa[i]=i;
		fact[i]=fact[i-1]*i%mod;
		inv[i]=quick_pow(fact[i],mod-2);
	}
}

int find_fa(int u){
	return fa[u]==u?u:fa[u]=find_fa(fa[u]);
}

bool Union(int u,int v){
	u=find_fa(u);
	v=find_fa(v);
	fa[u]=v;
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	init();
   	int n,x,y; 
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<=n;i++){
		scanf("%d%d",c+i,w+i);
		g[c[i]].push_back(pii(w[i],i));
	}

	int Min=INF,id1,id2;

	for(int i=1;i<=n;i++){
		if(g[i].size()>0){
			sort(g[i].begin(),g[i].end());
			if(Min>g[i][0].first) Min=g[i][0].first,id1=i,id2=g[i][0].second;

			for(int j=1;j<g[i].size();j++){
				if(g[i][0].first+g[i][j].first<=x)
					Union(g[i][0].second,g[i][j].second);
				else break;
			}
		}
	}

	for(int i=1;i<=n;i++){
		if(g[i].size()){
			if(i==id1) continue;
			for(int j=0;j<g[i].size();j++){
				if(g[i][j].first+Min<=y)
					Union(g[i][j].second,id2);
			}
		}
	}

	Min=INF;
	for(int i=1;i<=n;i++){
		if(g[i].size()){
			if(i==id1) continue;

			if(Min>g[i][0].first) Min=g[i][0].first,id2=g[i][0].second;
		}
	}

	for(int j=0;j<g[id1].size();j++){
		if(g[id1][j].first+Min<=y)
			Union(g[id1][j].second,id2);
	}

	for(int i=1;i<=n;i++){
		find_fa(i);
		gg[fa[i]].push_back(i);
	}

	ll ans=1;
	for(int i=1;i<=n;i++){
		if(gg[i].size()){
			ll tmp=fact[(int)gg[i].size()];
			for(int j=0;j<gg[i].size();j++){
				cnt[c[gg[i][j]]]++;
				if(!vis[c[gg[i][j]]]) p.push_back(c[gg[i][j]]),vis[c[gg[i][j]]]=1;
			}
			for(int j=0;j<p.size();j++){
				tmp*=inv[cnt[p[j]]];
				tmp%=mod;
				cnt[p[j]]=0,vis[p[j]]=0;
			}
			p.clear();
			ans=ans*tmp%mod;
		}
	}

	printf("%lld\n",ans);


    return 0;
}


Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,m,v,p;cin>>n>>m>>v>>p;
  V<ll> a(n);
  rep(i,0,n)cin>>a[i];
  sort(all(a));
  reverse(all(a));

  ll ok=0,ng=n,mid;
  while(abs(ok-ng)>1){
    mid=(ok+ng)/2;
    
    if(a[mid]+m<a[p-1]){
      ng=mid;
      continue;
    }

    ll sum=0;
    sum+=(p-1)*m;
    sum+=(n-mid)*m;
    rep(j,p-1,mid){
      sum+=a[mid]+m-a[j];
    }
    if(m*v<=sum)ok=mid;
    else ng=mid;
  }
  cout<<ok+1<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

int main() {
  	ll n;
  	cin>>n;
  
  	ll a[n],b[n];
  	ll all=0;
  
  	rep(i,n+1){
      cin>>a[i];

    }
  
	ll ans =0;
               
  	rep(i,n)cin>>b[i];
  
  for(int i=0;i<n;i++){
    if(a[i]<=b[i]){
        ans +=a[i];
    	b[i]-=a[i];
 
    }
    else{
    	ans +=b[i];
        b[i]=0;
    }
        
    if(a[i+1]<=b[i]){
    	ans +=a[i+1];
      	a[i+1] =0;
      	
    }
    
    else{
    	ans +=b[i];
      	a[i+1]-=b[i];

    }

  }
  
	cout<<ans<<endl;

}

Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pii pair<ll,ll>
#define sc(x) scanf("%lld",&x)
 
int main(){
	io;
	ll n,k;
	cin>>n>>k;
	vector<ll>v(k);
	for(ll i=0;i<k;i++){
		cin>>v[i];
	}
	
	ll ans=v[k-1]-v[0];
	
	for(ll i=1;i<k;i++){
		ans=min(ans,n-v[i]+v[i-1]);
	}
	cout<<ans;
	return 0;
}


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

using namespace std;

string solve(int a, int b, int c) {
    int count = 0;
    if (a == b)
        ++count;
    if (b == c)
        ++count;
    if (a == c)
        ++count;
    if (count == 1)
        return "Yes";
    else
        return "No";
}

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << solve(a,b,c);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W; cin>>H>>W;
  vector<vector<char>>A(H+2,vector<char>(W+2,'.'));
  for(int i=1;i<=H;i++){
    string S; cin>>S;
    for(int j=1;j<=W;j++){
      A[i][j]=S.at(j-1);
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(A[i][j]=='.')continue;
      if(A[i+1][j]=='#')continue;
      if(A[i-1][j]=='#')continue;
      if(A[i][j+1]=='#')continue;
      if(A[i][j-1]=='#')continue;
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MOD 1000000007
#define MAX 17
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;
}
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
int bin[MAX],jc[1<<MAX],inv[1<<MAX],jv[1<<MAX];
int C(int n,int m){if(n<m)return 0;return 1ll*jc[n]*jv[m]%MOD*jv[n-m]%MOD;}
int a[MAX],n,m,ans,f[MAX+1][1<<MAX],cnt[1<<MAX];
int main()
{
	n=read();m=read();cnt[0]=jc[0]=bin[0]=jv[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=n;++i)bin[i]=bin[i-1]<<1;
	for(int i=1;i<=bin[n];++i)jc[i]=1ll*jc[i-1]*i%MOD;
	for(int i=2;i<=bin[n];++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
	for(int i=1;i<=bin[n];++i)jv[i]=1ll*jv[i-1]*inv[i]%MOD;
	for(int i=1;i<=bin[n];++i)cnt[i]=(i&1)?MOD-cnt[i>>1]:cnt[i>>1];
	for(int i=1;i<=m;++i)a[i]=read();sort(&a[1],&a[m+1]);
	f[m+1][0]=1;
	for(int i=m;i;--i)
		for(int t=0;t<bin[n];++t)
			if(f[i+1][t])
			{
				add(f[i][t],f[i+1][t]);
				int p=bin[n]-1-t;
				for(int j=0;j<n;++j)
					if(!(t&(1<<j)))
						add(f[i][t|(1<<j)],1ll*C(p-a[i]+1,(1<<j)-1)*f[i+1][t]%MOD*jc[1<<j]%MOD);
			}
	for(int i=0;i<bin[n];++i)
		add(ans,1ll*f[1][i]*jc[bin[n]-1-i]%MOD*cnt[i]%MOD);
	ans=1ll*ans*bin[n]%MOD;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
  if(a>b){swap(a,b);}
  if(a==0){return b;}
  else{return gcd(b%a,a);}
}
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  ll ans=1,a;
  for(int i=0;i<n;i++){
    cin>>a;
    ans=a/gcd(ans,a)*ans;
  }
  cout<<ans;
}

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

using namespace std;

const int N = 100005;

vector<int> g[N];
int dep[N], pre[N], sum[N];

void dfs(int u, int fa, int d) {
  dep[u] = d;
  pre[u] = fa;
  sum[u] = 1;
  for (auto v : g[u]) {
    if (v != fa) {
      dfs(v, u, d + 1);
      sum[u] += sum[v];
    }
  }
}

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1, 0);
  int u = n;
  for (int i = 0; i < (dep[n] - 1) / 2; i++) {
    u = pre[u];
  }
  cout << (sum[u] * 2 >= n ? "Snuke" : "Fennec") << endl;
  return 0;
}


Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
int main()
{
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>x;
		ans+=x%2;
		ans%=2;
	}
	if (ans%2)
		cout<<"NO"<<endl;
	else
		cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 100000

int main(){
  int n, q, time[N], head = 0, tail = 0, t_sum = 0, i;
  char name[N][11];
  
  scanf("%d%d" ,&n ,&q);
  for(i = 0; i < n; i++){
    scanf("%s%d", name[i], &time[i]);
    tail += 1;
  }
  
  if(tail == 1){
    printf("%s %d\n", name[head], time[head]);
    return 0;
  }

  while(head != tail){
    if(time[head] > q){
      t_sum += q;
      time[head] -= q;
      strcpy(name[tail], name[head]);
      time[tail] = time[head];
      tail += 1;
      if(tail >= N) tail = 0;
    }
    else{
      t_sum += time[head];
      printf("%s %d\n", name[head], t_sum);
    }
    head += 1;
    if(head >= N) head = 0;
  }
  return 0;
}

Measured memory_bytes: 2076
function Main(input) {
	input = input.split("\n");
	var a = input[0].split(" ").map(Number);
	var flag = true;
	input.shift();
	var arr = new Array(a[0]).fill("#");
	for(var i=0;i<input.length;i++){
      
		var mem = input[i].split(" ").map(Number);
   //   console.log(mem,arr)
    if(mem[0]==1&&mem[1]==0&&a[0]!=1) flag = false;
		if(arr[mem[0]-1]=="#"){
			arr[mem[0]-1] = mem[1];
		}else if(arr[mem[0]-1]!=mem[1]){
			flag = false;
			break;
		}
	}
	if(arr[0]=="#"&&a[0]!=1){arr[0] = 1;
                            }else if(arr[0]=="#"){
                            arr = [0];
                            }
	for(i=0;i<arr.length;i++){
		if(arr[i]=="#") arr[i] = 0;
	}
	if(flag){
		console.log(arr.join(""))
	}else{
		console.log(-1)
	}
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){
  long long int N, A, B;
  scanf("%lld%lld%lld", &N, &A, &B);

  long long int ans = (N/(A+B))*A + std::min(N%(A+B), A);

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    long long int ans=0;
    for(int i=1;i<=N;i++){
        if(i%3!=0 && i%5!=0){
            ans += i;
        }
    }

    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<string> blue(N); 
  for(int i = 0;i < N;i++){ //blueに入力
    cin >> blue.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> red(M);
  for(int i = 0;i < M;i++){ //redに入力
    cin >> red.at(i);
  }
  
  
  int profit = 0;
  for(int i = 0;i < N + M;i++){
    string testcode;
    if(i < N){testcode = blue.at(i);}
    else{testcode = red.at(i - N);}
    int p = 0;          
    for(int j = 0;j < N;j++){if(testcode == blue.at(j)){p++;}}
    for(int k = 0;k < M;k++){if(testcode == red.at(k)){p--;}}
    if(profit < p){profit = p;}
    }
  cout << profit << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int AliceP = 0;
	int BobP = 0;
	int n; cin >> n;
	std::vector<int> a(n);

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

	sort(a.rbegin(), a.rend());

	for (int i = 0; i < n; ++i)
	{
		if(i%2==0) AliceP += a[i];
		else BobP += a[i]; 
	}

	cout << AliceP - BobP << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (317);

int n;
string s;
int k;

void read()
{
	cin >> s >> k;
	n = s.size();
}

int dp[MAXN][MAXN][MAXN];

int rec(int l, int r, int o)
{
	if(r < l) return 0;
	if(l == r) return 1;

	int &memo = dp[l][r][o];
	if(memo != -1) return memo;
	
	memo = 0;
	if(s[l] == s[r]) chkmax(memo, 2 + rec(l + 1, r - 1, o));
	chkmax(memo, rec(l + 1, r, o));
	chkmax(memo, rec(l, r - 1, o));
	if(o) chkmax(memo, 2 + rec(l + 1, r - 1, o - 1));
	return memo;
}

void solve()
{
	memset(dp, -1, sizeof(dp));
	cout << rec(0, n - 1, k) << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 124800
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <string>
#define int long long
#define P pair<int,int>
#define V vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define vsort(vec) sort(vec.begin(),vec.end())
using namespace std;
signed main() {
	int n, memo[100000];
	V h;
	cin >> n;
	rep(i, n) {
		int in;
		cin >> in;
		h.push_back(in);
	}
	memo[n - 1] = 0;
	memo[n - 2] = abs(h[n - 1] - h[n - 2]);
	for (int i = n - 3; i >= 0; i--) {
		memo[i] = min(memo[i + 1] + abs(h[i] - h[i + 1]), memo[i + 2] + abs(h[i] - h[i + 2]));
	}
	cout << memo[0] << endl;
	system("PAUSE");
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> button(N);
  rep(i, N){
  	cin >> button.at(i);
  }
    int X = 0;
  rep(j, 10 * 10 * 10 * 10 * 10){
    X = button.at(X) - 1;
  	if(X == 1){
    	cout << j + 1 << endl;
    	return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

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



int main() {
    string S;
    cin >>S;
    rep(i,S.size()){
        cout << "x";
    }
    
    cout << endl;

    return 0;
    

}

Measured memory_bytes: 3628
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll dp[100005][3];
ll ans,n;
ll a[100005][3];
int main()
{
	ll i,j,k,x,y,t;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i][0]>>a[i][1]>>a[i][2];
	for(i=1;i<=n;i++)
	{
		for(j=0;j<3;j++)
		{
			for(k=0;k<3;k++)
			{
				if(k!=j)
				dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);	
			}	
		}
	}
	for(i=0;i<3;i++)
	{
		ans=max(ans,dp[n][i]);
	}
	//ans=ans[n][0]
	cout<<ans;
	return 0;
}


Measured memory_bytes: 8200
n , y = map(int,input().split())

a = y // 10000

for i in range(n+1):
    for j in range(n+1-i):
        if y == 10000*i + 5000*j + 1000*(n-i-j):
            print(str(i) + " " + str(j) + " " + str(n-i-j))
            exit()

print("-1 -1 -1")

Measured memory_bytes: 40684
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main()
{
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k-a-b<=0)
        if(k>a)
            cout << a << endl;
        else
            cout << k << endl;
    else
        cout << a-(k-a-b) << endl;
    return 0;
}

Measured memory_bytes: 3624
import itertools
A = list(itertools.chain.from_iterable([input().split() for _ in range(3)]))
N = int(input())
B = [input() for _ in range(N)]

for i in range(9):
    if A[i] in B:
        A[i] = "Bingo"

if A[0] == A[1] == A[2]:
    print("Yes")
elif A[3] == A[4] == A[5]:
    print("Yes")
elif A[6] == A[7] == A[8]:
    print("Yes")
elif A[0] == A[3] == A[6]:
    print("Yes")
elif A[1] == A[4] == A[7]:
    print("Yes")
elif A[2] == A[5] == A[8]:
    print("Yes")
elif A[0] == A[4] == A[8]:
    print("Yes")
elif A[2] == A[4] == A[6]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<string>
#include<cctype>
#include<cmath>
#include<queue> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
  queue <int> q1;
  int n,i,j;
  cin >> n;
  int d[n][n];
  int m[n];
  int v[n];
  rep(i,n){
    m[i]=10000;
    v[i]=0;
    rep(j,n){
      if(i==j){
        d[i][j]=0;
      }else{
        d[i][j]=10000;
      }
    }
  }
  m[0]=0;

  rep(i,n){
    int u,k;
    cin >> u >> k;
    if(k>0){
      rep(j,k){
        int v;
        cin >> v;
          d[u-1][v-1]=1;
      }
    }
  }   

  q1.push(0);
  while(!q1.empty()){
    int u = q1.front(); q1.pop();
      rep(j,n){
        if(d[u][j]==1 && v[j]==0){
          q1.push(j);
          m[j] = min(m[j],m[u]+1);
        }
      }
    v[u]=1;
  }

  rep(i,n){
    cout << i+1 << ' ';
    if(m[i]==10000){
      cout << -1 << endl;
    }else{
      cout << m[i] << endl;
    }
  }

  return 0;
}
 

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
struct P
{
    int x,y,z;
    bool operator<(const P &a)const{
        //if(y!=a.y) return y>a.y;
        return max(x,-x)>max(a.x,-a.x);

    }

};
vector<int> v[1];
//bitset<4001000> b;
int i,n,d,m,k,a,b,c,e;
int o[11];
int l[1];
int j[1];

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s,s1;

//priority_queue<int> q;
queue<int> q;
string r;
//char r[1];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());
/*struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> p;//safe_map;
*/
bool as(P a,P b)
{
    //if(a.y!=b.y)
    //return a.y>b.y;
    return a.x<b.x;
}


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();

int main()
{
    scanf("%d",&a);
    cin>>r;
    for(int t=0;t<r.size();t++)
        if(r[t]=='R') n++;
        else m++;
    if(n>m) puts("Yes");
    else puts("No");

}


Measured memory_bytes: 256
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

k=I()
s=SI()

if len(s)<=k:
    print(s)
else:
    print(s[0:k],end="")
    print("...")

Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define __m int mid=(l+r)>>1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

template<class T>
inline bool rd(T &num) {
    char in;
    bool IsN = false;
    while(in = getchar(), in != '-' && (in < '0' || in > '9'))if(in == EOF)return false;
    in == '-' ? (IsN = true, num = 0) : num = in - '0';
    while(in = getchar(), in >= '0' && in <= '9')num = num * 10 + in - '0';
    return IsN ? num = -num : num, true;
}

#define rep(i,a,b) for(register int i = (a); i< (b); i++)
#define per(i,a,b) for(register int i = (a); i> (b); i--)
#define clr(a) memset(a,0,sizeof(a));
#define inf(a) memset(a,0x3f,sizeof(a));
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rd2(a,b) rd(a)&&rd(b)
#define rd3(a,b,c) rd(a)&&rd(b)&&rd(c)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

string nico;
#ifdef LOCAL
#define bug(x) cout<<#x<<" : "<<x<<endl
#define infile(x) freopen(x,"r",stdin)
#define outfile(x) freopen(x,"w",stdout)
#else
#define bug(x)
#define infile(x)
#define outfile(x)
#endif

const int maxn = 1e5 + 7;
const int inf  = 0x3f3f3f3f;
const LL linf  = (LL)inf << 32 | inf;
const int mod  = 1e9 + 7;

int main() {
    IO;
    int n;
    cin>>n;
    char num[maxn];
    sprintf(num,"%d",n);
    int k=0;
    for(int i=0;i<strlen(num);i++)
        k+=num[i]-'0';
    if(n%k==0)
        cout<<"Yes"<<endl;
    else 
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    string S;
    cin >> S;
    bool isSeq = false;
    for (ll i = 0; i < 3; i++)
    {
        if (S[i] == S[i + 1])
        {
            isSeq = true;
            break;
        }
    }

    cout << (isSeq ? "Bad" : "Good") << endl;
}

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


Measured memory_bytes: 256