akhauriyash/Code-Regression huggingface dataset:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
c = [rs() for _ in range(2)]
c2 = [i[::-1] for i in c[::-1]]
print('YES' if c == c2 else 'NO')

Measured memory_bytes: 63340
/*...Part - 01...*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
//#include <bits/stdc++.h>
using namespace std ;

/*...Part - 02...*/

typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef pair<ll,ll>             pll ;
typedef vector<int>             vi ;
typedef vector<ll>              vll ;
typedef vector<vector<int>>     vvi ;

int Int(){int x ; scanf("%d",&x) ; return x ;}
ll Long(){ll x ; scanf("%lld",&x) ; return x ;}

/*...Part - 03...*/
/*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

/*...Part - 04...*/
/*...Needed to change according to problem requirements...*/

const int N          = (int)2e5 + 5 ;
const int maxN       = (int)1e6 + 6 ;
const ll  Mod        = (ll)1e9 + 7 ;
const int inf        = (int)2e9 ;
const ll  Inf        = (ll)1e18 ;

/*..........................................................*/
/*...Part - 05...*/

#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e))  ; i += 1 - 2 * ((b) > (e)))
#define     Int         Int()
#define     Long        Long()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)

/*...Part - 06...*/
/*...... ! Code start from here ! ......*/

const int max_n = 100100 ;
int dp[max_n] ;

int main(){
    int test = 1 , tc = 0 ;
    while(test--){
        int n = Int, k = Int ;
        vi a(n + 1) ;
        for(int i = 1 ; i <= n ; ++i){
        	a[i] = Int ;
        	dp[a[i]] = 1 ;
        }
        dp[0] = 1 ;
        for(int i = 1 ; i <= k ; ++i){
        	if(dp[k])continue ;
        	for(int j = 1 ; j <= n ; ++j){
        		if(i >= a[j])
        		dp[i] |= (!dp[i - a[j]]) ;
        	}
        }
        if(dp[k]) puts("First") ;
        else puts("Second") ;
    }
    return 0 ;
}

/*...Always look at the part - 04...*/
/*...............END................*/




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  int N;
  string S;
  cin>>N>>S;
  vector<int>B(N+1);
  vector<int>W(N+1);
  int BC=0,WC=0;
  for(int i=0;i<N;i++){
    if(S[i]=='#'){BC++;}
    if(S[i]=='.'){WC++;}
    B[i+1]=BC;
    W[i+1]=WC;
  }
  int ans=1e9;
  for(int i=0;i<=N;i++){
    int l=B[i],r=W[N]-W[i];
    ans=min(ans,l+r);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5248
import math
N = int(input())
P= list(map(int, input().split()))
Q = list(map(int, input().split()))
p=0
q=0
L=[0]*(N+1)
L[0]=1
for i in range(N):
    L[P[i]]=1 
    #print(L)
    
    num=0
    for y in range(1,P[i]+1):
        if L[y]==0:
            num+=1
    p+=num*math.factorial(N-i-1)
    #print(num,math.factorial(N-i-1))
        
L=[0]*(N+1)
L[0]=1           
for i in range(N):
    L[Q[i]]=1 
    #print(L)
    num=0
    for y in range(1,Q[i]+1):
        if L[y]==0:
            num+=1
    q+=num*math.factorial(N-i-1)
        

print(abs(q-p))

Measured memory_bytes: 9172
BLDG = 4
FLOOR = 3
ROOM = 10

cnt = Array.new(BLDG) do
    Array.new(FLOOR) do
        Array.new(ROOM, 0)
    end
end

data = gets.chomp.to_i
data.times do
    bldg, floor, room, people = gets.chomp.split.map(&:to_i)
    cnt[bldg - 1][floor - 1][room - 1] += people
end

BLDG.times do |i|
    puts "####################" if i != 0
    FLOOR.times do |j|
        ROOM.times do |k|
            print " " + cnt[i][j][k].to_s
        end
        puts ""
    end
end

Measured memory_bytes: 6112
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>
#include <iostream>
#define p 998244353
using namespace std;

string s;
map<string,int> dp;

int calc(string s)
{
	if(dp.find(s)!=dp.end())return dp[s];
	int n=s.size(),f[105],i,j,k,l;
	string subs,pres=s;
	s='0'+s;
	for(f[0]=i=1;i<=n;++i)
	{
		f[i]=f[i-1]*(s[i]-'0'+1)%p;
		for(j=1;j*2<=i;++j)
		{
			subs.clear();
			for(k=1;k<=j;++k)subs+=s[i-j+k];
			for(k=2;j*k<=i;++k)
			{
				for(l=1;l<=j;++l)if(s[i-j*k+l]=='0')subs[l-1]='0';
				f[i]=(f[i]+(long long)f[i-j*k]*calc(subs))%p;
			}
		}
	}
	dp[pres]=f[n];
	return f[n];
}

int main()
{
	cin >> s;
	dp["0"]=1;dp["1"]=2;
	printf("%d\n",calc(s));
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=I()
    
    N=10000
    
    #0~Nまで逆元などを事前計算

    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return (fact[n] * factinv[r] * factinv[n-r])%mod

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]

    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
        
    ans=0
    
    for i in range(1,N):#i此のグル-ぷに分ける
        if 3*i > S:
            break
        s2=S-i*3
        temp=cmb(s2+i-1,i-1,mod)
        ans=(ans+temp)%mod
        
    print(ans)
        
        
    

main()


Measured memory_bytes: 67768
/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Hemant Malviya

//It’s just pathetic to give up on something before you even give it a shot.
//Knowing you’re different is only the beginning. If you accept these differences 
you’ll be able to get past them and grow even closer.
//You can die anytime, but living takes true courage.
//Every journey begins with a single step. We just have to have patience.
//Life is not a game of luck. If you wanna win, work hard.
//It’s more important to master the cards you’re holding 
than to complain about the ones your opponent was dealt.
//If you just submit yourself to fate, then that’s the end of it.
//Whatever you do, enjoy it to the fullest. That is the secret of life.
//I too will obtain everything that I desire. Not because someone asked me to do it, 
//but because I know in my heart that I have something worth fighting for.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/   
#include<bits/stdc++.h>
 
#define lld long long int 
#define vint vector<int>
#define vlld vector<long long int>
#define vst vector<string>
#define ps push_back
#define pii pair<int,int>
#define mk make_pair
#define le length
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define sv()                  int t; scanf("%d",&t); while(t--)
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
 
int main()
{
   int n;
   cin>>n;
   set<string >st;

   while(n--){
    string str;
    cin>>str;
    st.insert(str);
   }
   cout<<st.size();
 return 0;   
}

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

int n, m, x, a, akhir=0, awal=0;

int main (){
	cin >>n>>m >> x;
	for(int i=1;i<=m;i++){
		cin >>a;
		if(a>x) akhir++;
		else awal++;
	}
	if(awal>akhir) cout <<akhir<< endl;
	else cout <<awal<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			//String tmp = sc.nextLine();
			System.out.print(sc.nextLine().substring(0,1));
			System.out.print(sc.nextLine().substring(1,2));
			System.out.print(sc.nextLine().substring(2,3));
    }
}


Measured memory_bytes: 20688
#include<bits/stdc++.h>
#define For(i,n) for(int i=0; i<n;i++)
#define whatis(x) cerr<<#x<<" is " << x<<endl
#define ll long long
using namespace std;

int main(){
    #ifdef magUNbos
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif // magUNbos
    ll n,l;
    cin>>n>>l;
    ll a[n];
    For(i,n){
        cin>>a[i];
    }
    int index=-1;
    For(i,n-1){
        if(a[i]+a[i+1]>=l){
            index = i;
            break;
        }
    }
    if(index==-1){
        cout<<"Impossible\n";
        return 0;
    }else{
        cout<<"Possible\n";
        For(i,index){
            cout<<i+1<<'\n';
        }
        for(int i=n-2;i>=index;i--){
            cout<<i+1<<'\n';
        }
    }


return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t H;
  cin>>H;
  int64_t x=0;
  while(H/2!=0){
    H /=2;
    x++;
  }
  int64_t y=2;
  for(int64_t i=0;i<x;i++){
    y*=2;
  }
  cout<< y-1 <<endl;
  

}

Measured memory_bytes: 256
from itertools import combinations_with_replacement

N, M, Q = map(int,input().split())
x = [_ for _ in range(1, M+1)]
y = list(combinations_with_replacement(x, N))
l = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
z = 0
for i in range(len(y)):
    for j in range(Q):
        if y[i][l[j][1]-1] - y[i][l[j][0]-1] == l[j][2]:
            z += l[j][3]
        ans = max(ans, z)
    z = 0
print(ans)

Measured memory_bytes: 84848
//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

//#define FILE
#define int long long
//#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fst first
#define scd second
#define inv(x) ksm(x,mod - 2)
#define lowbit(x) (x & (-x))

const int MAXN = 2e5 + 10;
const int INF = 2e9;
const double PI = acos(-1);
//const double mul = 1e10;
//const int mod = 1e9 + 7;
//const int mod = 998244353;
//const int G = 3;

int n,a[MAXN],ans;
int two[MAXN],five[MAXN];
int p[110][110],sum[110][110];
char s[20];

template<typename T> inline void read(T &a) {
	a = 0; char c = getchar(); int f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') {a = a * 10 + (c ^ 48); c = getchar();}
	a *= f;
}

int calc(int x,int y) {
	x++,y++;
	x = max(x,1ll),y = max(y,1ll);
	return sum[100][100] - sum[x - 1][100] - sum[100][y - 1] + sum[x - 1][y - 1];
}

signed main () {
#ifdef FILE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	read(n);
	for(int i = 1;i <= n; ++i) {
		scanf("%s",s + 1);
		int lim = strlen(s + 1),flag = false,cnt = 10;
		for(int j = 1;j <= lim; ++j) {
			if(s[j] == '.') {flag = true; continue;}
			a[i] *= 10;
			a[i] += (s[j] - '0');
			if(flag) cnt--;
		}
		for(int j = 1;j <= cnt; ++j) a[i] *= 10;
		while(a[i] % 2 == 0) two[i]++,a[i] /= 2;
		while(a[i] % 5 == 0) five[i]++,a[i] /= 5;
		p[two[i] + 1][five[i] + 1]++;
	}
	for(int i = 1;i <= 100; ++i)
		for(int j = 1;j <= 100; ++j)
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + p[i][j];
	for(int i = 1;i <= n; ++i) {
		ans += calc(20 - two[i],20 - five[i]);
		if(20 - two[i] <= two[i] && 20 - five[i] <= five[i]) ans--;
	}
	printf("%lld\n",ans / 2);
	return 0;
}



Measured memory_bytes: 8548
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] ar = new int[n];
    int count =0;
    for(int i=0;i<n;i++){
      ar[i] = sc.nextInt();
    }
    for(int j=0;j<n;j++){
      if(ar[j] != j+1){
        count++;
      }
    }
    if(count == 2 || count == 0){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	ll n, a, b; cin >> n >> a >> b;
	ans = (n/(a+b))*a;
	n %= (a+b);
	ans += min(a, n);
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N,total = 0;
  cin >> N;
  vector<int> C(N),V(N);
  for(int i = 0;i < N;i++)
    cin >> V.at(i);
  for(int i = 0;i < N;i++)
    cin >> C.at(i);
  for(int i = 0;i < N;i++){
    if(V.at(i) > C.at(i)) total += V.at(i) - C.at(i);
  }
  cout << total <<endl;
}

Measured memory_bytes: 256
import heapq

# 「優先度付きキュー」の練習問題

n, m = map(int, input().split())
a = [int(_) for _ in input().split()]

# 各要素を-1倍する。最大値の取り出しができるように
a = list(map(lambda x: x*(-1), a))
# aの優先度付きキューに
heapq.heapify(a)

# 割引m回分ループ
for _ in range(m):
    popNum = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-popNum//2))

# 負で出力されているので戻す
print(-sum(a))

Measured memory_bytes: 14184
using static System.Console;
using System;

class Program {
    static void Main(string[] args) {
        var s = 700;
        var a = ReadLine();
        for (int i = 0; i < 3; i++) {
            if(a[i] == 'o') s += 100;
        }
        WriteLine(s);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
const int inf = 10e9 + 7;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
int a[300010];
signed main() {
	int n;
	cin >> n;
	rep(i, 3*n) {
		cin >> a[i];
	}
	sort(a, a + 3*n);
	reverse(a, a + 3 * n);
	int ans = 0;
	for (int i = 1; i < 2 * n; i += 2) {
		ans += a[i];
	}
	cout << ans << endl;
	endre;
}

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

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

int main(){
  ll n,d[10],v[10];
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      cin >> d[i] >> v[i];
      ll tmp = gcd(d[i],v[i]);
      d[i]/=tmp; v[i]/=tmp;
    }

    ll ans[10];
    ans[0] = 1;

    for(int i=1;i<n;i++){
      ll x = v[i-1]*d[i], y = v[i]*d[i-1], tmp = gcd(x,y);
      x/=tmp; y/=tmp;      
      tmp = x/gcd(ans[i-1],x);
      for(int j=0;j<i;j++)ans[j] *= tmp;
      ans[i] = ans[i-1]/x*y;
    }

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

Measured memory_bytes: 1156
#include <stdio.h>



int main(void){
  char N[4];
  scanf("%s", N);

  
  if(N[0]=='7'||N[1]=='7'||N[2]=='7'){
      printf("Yes\n");
        
      }
  else{
        printf("No\n");
  }

  return 0;
}





Measured memory_bytes: 1660
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
P = [int(sys.stdin.readline()) for _ in range(N)]

# dp[i]: i より前に何個連続してるか
dp = np.zeros(N + 1, dtype=int)
for i in range(N):
    p = P[i]
    dp[p] = dp[p - 1] + 1
print(N - dp.max())


Measured memory_bytes: 24084
# https://atcoder.jp/contests/abc159/tasks/abc159_e
import sys

ans = sys.maxsize
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

for h in range(1 << (H - 1)):
    g = 0
    ids = [-1 for _ in range(H)]
    for i in range(H):
        ids[i] = g
        if (h >> i) & 1:
            g += 1

    g += 1
    num = g - 1

    if num >= ans:
        continue

    c = [[0] * W for _ in range(g)]
    for i in range(H):
        for j in range(W):
            c[ids[i]][j] = c[ids[i]][j] + (s[i][j] == '1')

    now = [0 for _ in range(g)]


    def add(j):
        for i in range(g):
            now[i] += c[i][j]

        for i in range(g):
            if now[i] > K:
                return False

        return True


    for j in range(W):
        if not add(j):
            num += 1
            if num >= ans:
                continue
            now = [0 for _ in range(g)]
            if not add(j):
                num = sys.maxsize
                break

    ans = min(ans, num)

print(ans)


Measured memory_bytes: 3188
using System;
class Program
{
    public static void Main()
    {
        string[] imp = Console.ReadLine().Split(' ');
        int w, h, n;
        w = int.Parse(imp[0]);
        h = int.Parse(imp[1]);
        n = int.Parse(imp[2]);
        int[,] s = new int[w, h];
        int x, y, a;
        for (int i = 0; i < n; i++)
        {
            imp = Console.ReadLine().Split(' ');
            x = int.Parse(imp[0]);
            y = int.Parse(imp[1]);
            a = int.Parse(imp[2]);
            if (a == 1 && x != 0)
                for (int q = 0; q < h; q++)
                    for (int p = 0; p < x; p++)
                        s[p, q] = 1;
            if (a == 2 && x != w)
                for (int q = 0; q < h; q++)
                    for (int p = x; p < w; p++)
                        s[p, q] = 1;
            if (a == 3 && y != 0)
                for (int p = 0; p < w; p++)
                    for (int q = 0; q < y; q++)
                        s[p, q] = 1;
            if (a == 4 && y != h)
                for (int p = 0; p < w; p++)
                    for (int q = y; q < h; q++)
                        s[p, q] = 1;
        }
        int sum = 0;
        for (int p = 0; p < w; p++)
            for (int q = 0; q < h; q++)
                if (s[p, q] == 1)
                    sum++;
        Console.WriteLine(w * h - sum);
    }
}

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

int main() {

    int C[51] = {0};
    for (int a = 0; a < 10; ++a) {
        for (int b = 0; b < 10; ++b) {
            for (int c = 0; c < 10; ++c) {
                for (int d = 0; d < 10; ++d) {
                    C[a+b+c+d]++;
                }
            }
        }
    }

    int n;
    while (cin >> n) {
        cout << C[n] << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

int black[1001][1001];
int white[1001][1001];

int main(void){
    int n,k;
    cin>>n>>k;
    rep(i,n){
        int x,y;
        string c;
        cin>>x>>y>>c;
        bool isB = (c=="B")^((x/k + y/k)&1);
        x = x%k + 1;
        y = y%k + 1;
        if(isB){
            black[y][x]++;
        }else{
            white[y][x]++;
        }
    }


    rep1(y,k)rep1(x,k){
        white[y][x] += white[y-1][x] + white[y][x-1] - white[y-1][x-1];
        black[y][x] += black[y-1][x] + black[y][x-1] - black[y-1][x-1];
    }

    // rep1(y,k)rep1(x,k){
    //     cout<<black[k-y+1][x]<<(x==k ? "\n" : " ");
    // }
    // rep1(y,k)rep1(x,k){
    //     cout<<white[k-y+1][x]<<(x==k ? "\n" : " ");
    // }
    int res = 0;
    rep1(y,k)rep1(x,k){
        int cnt1 = black[k][k] - black[y][k] - black[k][x] + 2*black[y][x];
        int cnt2 = white[y][k] + white[k][x] - 2*white[y][x];
        res = max(res, cnt1+cnt2);

        cnt1 = white[k][k] - white[y][k] - white[k][x] + 2*white[y][x];
        cnt2 = black[y][k] + black[k][x] - 2*black[y][x];
        res = max(res, cnt1+cnt2);
    }
    cout<<res<<endl;
    

    return 0;
}


Measured memory_bytes: 8064
import math
l=[]
f=0
for i in range(5):
    z=int(input())
    l.append(z)
k=int(input())
for i in range(4):
    for j in range(1,5):
        if math.fabs(l[i]-l[j])>k:
            f=1
            break
if f==1:
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 3060
char r[99],g[99],d[99];main(){
	int c,i,j,k;
	for(;scanf("%s%s%s",r,g,d)>2;puts("")){
		for(i=j=k=0,c=g[j++];i+j<=strlen(r)+strlen(g);){
		//if(c==r[i]){
			if(c==d[k]){//push_down
				k++;
				c=r[i++];
			}else{ //push_right
				putchar(c);
				c=g[j++];
			}
		}
	}
exit(0);}

Measured memory_bytes: 524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var list = new List<int>();

            for (int i = 0; i < n - 1; i++)
            {
                var x = new List<char>();
                var y = new List<char>();

                x.AddRange(s.Substring(0, i + 1));
                y.AddRange(s.Substring(i + 1));

                x = x.Distinct().ToList();
                y = y.Distinct().ToList();

                list.Add(x.Intersect(y).Count());
            }

            Console.WriteLine(list.Max());
        }
    }
}

Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var al = Console.ReadLine().Split(' ')
        .Select(x => int.Parse(x))
        .ToArray();
        var ans = 0;
        for (var i = 0; n > i; i++) {
            if ((i + 1) % 2 == 0) continue;
            if (al[i] % 2 != 0) ans++;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 28160
#include<cstdio>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
long long n,h,d,p,y,x,z;
deque<pair<long long,long long> > w;

int main(){
  scanf("%lld%lld", &n, &p);
  y = p;
  for(int i = 0;i < n - 1;i++){
    scanf("%lld%lld", &d, &h);
    while(!w.empty() && w.back().first < h){
      w.pop_back();
    }
    w.push_back(make_pair(h, x));
    x += d;
    while(p <= x){
      long long int tmpp = p ;
      while(!w.empty() && tmpp + w.front().first - w.front().second > y){
	p = max(p, w.front().second + y);
	w.pop_front();
      }
      if(!w.empty()){
	p = max(p, tmpp + w.front().first);
	int tmp = max(0ll, min((x - p) / w.front().first, (w.front().second + y - p) / w.front().first));
	z += tmp;
	p += tmp * w.front().first;
      }
      z++;
    }
  }
  printf("%lld\n", z);
  return 0;
}

Measured memory_bytes: 1052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N; ll K;
    cin >> N >> K;
    ll A[N], F[N];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    sort(A, A+N, greater<ll>());
    sort(F, F+N);
    //(l,r]
    ll l = -1, r = INF;
    while(r-l > 1){
        ll n = (l+r)/2;
        ll cnt = 0;
        rep(i, N){
            if(n/F[i] >= A[i]) continue;
            else cnt += A[i]-n/F[i];
        }
        if(cnt > K) l = n;
        else r = n;
    }
    cout << r << endl;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod>
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w, bool f = 0) { if (!f) this->w = w; else *this = fix(w); }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	inline modulo& operator += (const modulo &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline modulo& operator -= (const modulo &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline modulo& operator *= (const modulo &b) { w = (num) w * b.w % mod; return *this; }
	inline modulo& operator /= (const modulo &b) { w = (num) w * b.inv() % mod; return *this; }
	inline modulo  operator +  (const modulo &b) { modulo r = *this; r += b; return r; }
	inline modulo  operator -  (const modulo &b) { modulo r = *this; r -= b; return r; }
	inline modulo  operator *  (const modulo &b) { modulo r = *this; r *= b; return r; }
	inline modulo  operator /  (const modulo &b) { modulo r = *this; r /= b; return r; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
const int mod = int(1e9 + 7);
typedef modulo<mod> rem;

const int nsz = int(5e3);
int n, k, a[nsz + 5];
rem dp[nsz + 5], ans;
vector<int> r;

struct union_find {
	int pr[nsz + 5], siz[nsz + 5];
	
	union_find() {
		cont (u, nsz) pr[u] = u, siz[u] = 1;
	}
	
	int inline operator [] (int id) { return qry(id); }
	
	int qry(int u) { return pr[u] == u ? u : pr[u] = qry(pr[u]); }
	
	bool inline link(int u, int v) {
		int pu = qry(u), pv = qry(v);
		if (pu == pv) return 0;
		pr[pv] = pu;
		siz[pu] += siz[pv];
		return 1;
	}
};
union_find uf;

int main() {
	scanf("%d", &n);
	cont (i, n) {
		scanf("%d", &a[i]);
		if (a[i] != -1) uf.link(a[i], i);
		if (a[i] == -1) r.push_back(i);
	}
	k = int(r.size());
	
	cont (u, n) {
		if (uf[u] != u || a[u] == -1) continue;
		ans += rem(n - 1).pow(k);
	}
	
	dp[0] = 1;
	loop (i, k) {
		int sz = uf.siz[r[i]];
		for (int j = i; j >= 0; --j) {
			dp[j + 1] += dp[j] * (j ? rem(j) : rem(1)) * rem(sz);
		}
	}
	
	cont (j, k) {
		ans += dp[j] * rem(n - 1).pow(k - j);
	}
	cont (u, n) {
		if (uf[u] != u || a[u] != -1) continue;
		ans -= rem(n - 1).pow(k - 1);
	}
	
	ans = rem(n) * rem(n - 1).pow(k) - ans;
	printf("%d\n", ans);
}

Measured memory_bytes: 3928
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    if(b/a >= c){
        cout << c << endl;
    }else{
        cout << b/a << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ll n,k;cin>>n>>k;
    ll a[n];
    set<ll> st[200001];
    rep(i,0,n){
        cin>>a[i];
        st[a[i]].insert(i);
    }
    ll now=0;
    ll cnt=0;
    for(;;){
        if(now==n){
            cnt++;
            break;
        }
        ll num=a[now];
        auto y=st[num].upper_bound(now);
        if(y==st[num].end()){
            cnt++;
            now=*st[num].begin()+1;
        }
        else{
            now=*y+1;
        }
    }
    //cout<<cnt;return 0;
    ll t=k%cnt;
    if(t==0){
        cout<<endl;
        return 0;
    }
    vector<ll> ans;
    now=0;
    cnt=0;
    for(;;){
        if(now==n){
            if(cnt==t-1)break;
            now=0;
        }
        //cout<<now<<endl;
        ll num=a[now];
        auto y=st[num].upper_bound(now);
        if(y==st[num].end()){
            if(cnt==t-1){
                ans.push_back(a[now]);
                now++;
                if(now==n)break;
                continue;
            }
            cnt++;
            now=*st[num].begin()+1;
        }
        else{
            now=*y+1;
        }
    }
    rep(i,0,ans.size())cout<<ans[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 23540
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long int ll;

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

	vector<int> X(N);
    vector<int> Xs(N);
 	for(int i=0; i<N; i++) {
		int x;
		cin >> x;
		X[i] = x;
        Xs[i] = x;
	}

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

    ll l_median = Xs[N/2-1];
    ll r_median = Xs[N/2];

	for(ll i=0; i<N; i++) {
        if(X[i] <= l_median) {
            cout << r_median << endl;
        } else {
            cout << l_median << endl;
        }
	}
}


Measured memory_bytes: 3712
#include<iostream>
#include<cstring>  
#include<algorithm>
using namespace std; 
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n )  
{  
    int L[m + 1][n + 1];  
    int i, j;  
      
    /* Following steps build L[m+1][n+1] in  
       bottom up fashion. Note that L[i][j]  
       contains length of LCS of X[0..i-1] 
       and Y[0..j-1] */
    for (i = 0; i <= m; i++)  
    {  
        for (j = 0; j <= n; j++)  
        {  
        if (i == 0 || j == 0)  
            L[i][j] = 0;  
      
        else if (X[i - 1] == Y[j - 1])  
            L[i][j] = L[i - 1][j - 1] + 1;  
      
        else
            L[i][j] = max(L[i - 1][j], L[i][j - 1]);  
        }  
    }  
          
    i=m;
	j=n;
	int index=L[m][n];
	char lcs[index];
	lcs[index]='\0';
	
	while(i>0 && j>0)
	{
		//cout<<"hai";
		if(L[i][j]!=max(L[i-1][j],L[i][j-1]))
		{
			//cout<<max(L[i-1][j],L[i][j-1]);
			lcs[index-1]=X[i-1];
			i-=1;
			j-=1;
			index-=1;
		}
		else
		if(L[i-1][j]<L[i][j-1])
		j-=1;
		else
		i-=1;
	}
    /* L[m][n] contains length of LCS  
    for X[0..n-1] and Y[0..m-1] */
    //return L[m][n];  
    
    cout<<lcs;
    //cout<<"\n"<<strlen(lcs)<<lcs[1]<<L[m][n];
}  
  
/* Utility function to get max of 2 integers */
  
// Driver Code 
int main()  
{  
    //char X[] = "AGGTAB";  
    //char Y[] = "GXTXAYB"; 
	
	string X,Y;
	cin>>X>>Y; 
      
    int m = X.length();  
    int n = Y.length();  
      
    lcs(X,Y,m,n);  
      
    return 0;  
}  


Measured memory_bytes: 38780
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define Would
#define you
#define please

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

	int N;
	cin >> N;
	co(N / 3);

	Would you please return 0;
}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

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

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

main(){
	int n,m,r,ans=MOD;
	cin>>n>>m>>r;
	int q[r];rep(i,r)cin>>q[i];
	sort(q,q+r);
	int v=n+1;
	int d[v][v];
	rep(i,v)rep(j,v){
		d[i][j]=MOD;
	}
	rep(i,m){
		int x,y,c;cin>>x>>y>>c;
		d[x][y]=c;
		d[y][x]=c;
	}
	rep(k,v)rep(i,v)rep(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	do{
		int t=0;
		rep(i,r-1)t+=d[q[i]][q[i+1]];
		ans=min(ans,t);
	}while(next_permutation(q,q+r));
	dans;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 3) {
        if(s[i] == '1') ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {
		VI a(n); rep(i, n)cin >> a[i];
		VI r(n + 1); r[0] = 0;
		FOR(i, 1, n + 1)r[i] = r[i - 1] + a[i - 1];

		int ans = -inf;
		rep(i, n + 1) {
			FOR(j, i + 1, n + 1) {
				ans = max(ans, r[j] - r[i]);
			}
		}
		Cout(ans);
	}
}


Measured memory_bytes: 3084
#include <iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main()
{
  int R[MAX],n;

  cin>> n;
  for(int i=0;i<n;i++)
  {
    cin>>R[i];
  }
  int maxv=-2000000000;
  int minv=R[0];
  for(int i=1;i<n;i++)
  {
    maxv=max(maxv,R[i]-minv);
    minv=min(minv,R[i]);
  }
  cout<<maxv<<endl;
  return 0;
}


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

int main() {
	int N , K;
  	cin >> N >> K;
    int x;
  	int sum = 0;
	for(int i = 0; i < N; i++){
        cin >> x;
    	if( 2 * x > 2 * (K - x)){
        	sum += 2 * (K - x);
        }else{
        	sum += 2 * x;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

bool checkCanMerge(string &dist, string &src, int offset) {
	if ((int)dist.size() < offset || (int)src.size() < offset) return false;

	for (int i = 0; i < offset; i++) {
		if (dist[dist.size() - offset + i] != src[i]) {
			return false;
		}
	}

	return true;
}

string merge(string dist, string src) {
	if (dist.find(src) != string::npos) return dist;
	if (src.find(dist) != string::npos) return src;

	for (int offset = min(dist.size(), src.size()); offset >= 0; offset--) {
		if (checkCanMerge(dist, src, offset)) {
			return dist + src.substr(offset, src.size() - offset);
		}
	}

	return dist + src;
}

int main(void) {
	int N;

	while (cin >> N, N) {
		vector<string> ws(N);
		for (auto &w : ws) {
			cin >> w;
		}

		vector< vector<string> > dp(1 << N, vector<string>(N));
		for (int i = 0; i< N; i++) {
			dp[1 << i][i] = ws[i];
		}

		for (int i = 1; i < 1 << N; i++) { // done bit
			for (int j = 0; j < N; j++) {  // before word
				if (!(i & 1 << j)) continue;

				string dist = dp[i][j];
				if (dist == "") continue;
				
				for (int k = 0; k < N; k++) { // now word
					int next = 1 << k | i;
					if (next == i) continue;

					string src = ws[k];
					string merged = merge(dist, src);
					auto &target = dp[next][k];
//					printf("%d %d %s %s %s %s\n", i, next, dist.c_str(), src.c_str(), merged.c_str(), target.c_str());

					if (target == "" || target.size() > merged.size()) {
						target = merged;
					} else if (target.size() == merged.size() && target > merged) {
						target = merged;
					}
				}
			}
		}

		string ans = dp.back().back();
		for (auto w : dp.back()) {
			if (ans.size() > w.size()) {
				ans = w;
			} else if (ans.size() == w.size() && ans > w) {
				ans = w;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e6+7;

string s,s1;
int k,n1,n2;

int cal(string s) {
    int num = 0;
    rep(i,1,s.size()-1) {
        if (s[i] == s[i-1]) num ++,s[i]='0';
    }
    return num;
}

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

    cin >> s >> k;
    if (k < 10) {
        s1 = "";
        rep(i,1,k) s1 += s;
        cout << cal(s1) << endl;
    }else {
        ll ans = 0;
        if (k%2==0) {
            s1 = "";
            rep(i,1,8) s1 += s;
            n1 = cal(s1);

            s1 = "";
            rep(i,1,10) s1 += s;
            n2 = cal(s1);
            ll cha = n2-n1;
            ans = cha*(k-10)/2+n2;
        }else {
            s1 = "";
            rep(i,1,7) s1 += s;
            n1 = cal(s1);

            s1 = "";
            rep(i,1,9) s1 += s;
            n2 = cal(s1);
            ll cha = n2-n1;
            ans = cha*(k-9)/2+n2;
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-05-26
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    unordered_set<int> seen;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (seen.count(x)) {
            cout << "NO" << '\n';
            return 0;
        }
        seen.insert(x);
    }
    cout << "YES" << '\n';
    return 0;
}

Measured memory_bytes: 8520
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a,b) memset(a, b, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int a[maxn];
int dp[maxn];

int main(){
        _ios;
        int n,k; cin >> n >> k;
        for(int i = 0; i<n; i++){
            cin >> a[i];
        }
        for(int i = 0;i<=n; i++){
            dp[i] = mod;
        }
        dp[0] = 0;

        for(int i = 0; i<n; i++){
            for(int j = 1; j<=k; j++){
                if(i+j<n)dp[i+j] = min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));
            }
        }
        cout<<dp[n-1]<<endl;


return 0;
}



Measured memory_bytes: 4736
import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

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

mod = 10**9 + 7
fac = [1]*(n+5)
inv = [1]*(n+5)
for i in range(1,n+1):
  fac[i] = (fac[i-1]*i) % mod  
inv[n] = pow(fac[n], mod-2, mod)
for i in range(n, 0, -1):
  inv[i-1] = (inv[i]*i) % mod
    
def cmb(n, r):
  if r < 0 or r > n: return 0

  return (((fac[n] * inv[r])%mod) * inv[n-r]) % mod

ans=0
a.sort()
for h in range(2):
  for i in range(n):
    now = cmb(i,k-1)%mod
    if h == 1:now = -now
    ans += now*a[i]%mod

  a.sort(reverse=True)

print(ans%mod)


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

	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int a[][]=new int[n][m];
		for(int i=0;i<n;i++)
		{
				String st=sc.next();
          for(int j=0;j<m;j++)
          {
              //System.out.println(ch);
            char ch=st.charAt(j);
				if(ch=='.')
					a[i][j]=1;
				else 
					a[i][j]=-1;
          }
		}
		long dp[][]=new long[n][m];
		dp[0][0]=1;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(a[i][j]==-1)
					dp[i][j]=0;
				else
				{
					if(i-1>=0)
						dp[i][j]+=dp[i-1][j];
					if(j-1>=0)
						dp[i][j]+=dp[i][j-1];
                  dp[i][j]%=1000000007;
				}
			}
		}
		System.out.println(dp[n-1][m-1]);
	}
}



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


int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans=0;
    rep(i,a+1){
        rep(j,b+1){
            rep(k,c+1){
                if(500*i + 100*j + 50*k == x){
                    ans ++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P       = pair<int, int>;

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

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    string b;
    cin >> b;
    string ans;
    if (b == "A")
        ans = "T";
    else if (b == "C")
        ans = "G";
    else if (b == "G")
        ans = "C";
    else
        ans = "A";
    cout << ans << endl;
}


Measured memory_bytes: 888