akhauriyash/Code-Regression huggingface dataset:
def lcs(x,y):
    a, b = len(x), len(y)
    x1 = [0 for k in range(b+1)]
    for i in xrange(a):
        e = x[i]
        x2 = x1+[]
        for j in xrange(b):
            if e == y[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    print max(x1)
    return 0

def main():
    q = int(raw_input())
    for i in xrange(q):
        X = raw_input()
        Y = raw_input()
        lcs(X,Y)
    return 0

main()

Measured memory_bytes: 6516
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		for(int i = 1; i <= b; i++) {
		 if((a * i) % b == c) {
			 System.out.println("YES");
			 return;
		 }
		}
        System.out.println("NO");
		}	
}


Measured memory_bytes: 23764
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    long long A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    set<long long> waterS, sugarS;

    for (int i = 0; i <= 30; i++) {
        for (int j = 0; j <= 30; j++) {
            long long water = 100 * A * i + 100 * B * j;
            if (water <= F) waterS.insert(water);
        }
    }


    for (int i = 0; i <= 3000; i++) {
        for (int j = 0; j <= 3000; j++) {
            long long sugar = i * C + j * D;
            if (sugar <= F) sugarS.insert(sugar);
        }
    }

    double maxP = -1e20;
    long long ansS = 0;
    long long ansF = 0;

    for (auto water : waterS) {
        for (auto sugar : sugarS) {
            long long sum = water + sugar;
            if (sum > F) continue;
            double per = ((double) (100 * sugar)) / (double) (sum);
            if (per > maxP && (water / 100 * E) >= sugar) {
                ansS = sugar;
                ansF = sum;
                maxP = per;
            }
        }
    }

    cout << ansF <<  " " << ansS << endl;

    return 0;
}




















































































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

using namespace std;

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

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

    cout << A[A.size() - 1] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char s1[101],s2[101];
int main()
{
	gets(s1);
	gets(s2);
	int n=strlen(s1);
	int m=strlen(s2); 
	sort(s1,s1+n);
	sort(s2,s2+m);
	for(int i=0;i<fmax(n,m);i++)
	{
		if(s1[i]<s2[m-i-1])
		{
			printf("Yes\n");
			return 0;
		}
		if(s1[i]>s2[m-i-1])
			break;
	}
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

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

int main()
{
    ll n;
    cin >> n;
    string s;
    vector<ll> ruisekiw(n + 1), ruisekie(n + 1);
    cin >> s;
    for (int i = 0; i < n; i++)
    {
        ruisekie[i + 1] = ruisekie[i];
        ruisekiw[i + 1] = ruisekiw[i];
        if (s.at(i) == 'E')
        {
            ruisekie[i + 1]++;
        }
        else
        {
            ruisekiw[i + 1]++;
        }
    }
    ll ans = INFLL;
    for (int i = 0; i < n; i++)
    {
        chmin(ans, ruisekiw[i] + ruisekie[n] - ruisekie[i + 1]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 5508
/*
g++ -std=c++11 -o2 -Wall ABC111B.cpp -o .\out\ABC111B.out
.\out\ABC111B.out
*/

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

typedef long long ll;

int numbers [] = {111, 222, 333, 444, 555, 666, 777,888, 999};

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < 9; ++i) {
    if (numbers[i] >= n) {
      ans = numbers[i];
      break;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, r;
  cin >> n >> r;
  if(n >= 10) cout << r << endl;
  else{
    cout << r + (100 * (10 - n)) << endl;
  }
}


Measured memory_bytes: 256
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from heapq import heapify, heappop, heappush
from math import ceil, log, floor, sqrt
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, x, m = sp()
arr = [x]
s = set()
while True:
    x = (x * x) % m
    if x in s or x == 0 or x == 1:
        break
    s.add(x)
    arr.append(x)
answer = 0
m = n
if x == 0:
    for i in range(min(m, len(arr))):
        answer += arr[i]
    out(answer)
    exit()
if x == 1:
    for i in range(min(m, len(arr))):
        answer += arr[i]
    out(answer + max(0, m - len(arr)))
    exit()
find = arr.index(x)
if m <= len(arr):
    out(sum(arr[:m]))
    exit()
answer = sum(arr)
m -= len(arr)
arr = arr[find:]
for i in range(m % len(arr)):
    answer += arr[i]
s = sum(arr)
answer += s * (m // len(arr))
out(answer)


Measured memory_bytes: 78484
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
using namespace std;

int a[310][310],n,m;
multiset<int> st;
int ans;
int used[310];
bool vis[310];
bool check(int mid)
{
	if(mid==n)	return 1;
	st.clear();
	int i,j,mx,ps;memset(vis,0,sizeof(vis));
	for(i=1;i<=n;i++)	used[i]=1,st.insert(a[i][1]);
	for(i=1;i<=m;i++)
	{
		mx=0;ps=-1;	
		for(j=1;j<=m;j++)
		{
			if(st.count(j)>mx)
			{
				mx=st.count(j);
				ps=j;
			}
		}
		if(mx<=mid)	return true;
		if(i==m)	return false;
		vis[ps]=1;
		for(j=1;j<=n;j++)
		{
			if(a[j][used[j]]==ps)
			{
				st.erase(st.find(ps));
				while(vis[a[j][++used[j]]]){}
				if(used[j]>m)	return false;
				st.insert(a[j][used[j]]);
			}
		}
	}
	return false;
}

int main()
{
	int i,j,l,r,mid;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	l=0;r=n;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(check(mid))	ans=mid,r=mid-1;
		else	l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,x = li()
m = []
for _ in range(n):
    m.append(ni())
    
msum = sum(m)
mmin = min(m)

print(n + (x-msum)//mmin)

Measured memory_bytes: 3064
def Turn(sa, sb, sc, name):
    if name == 'a':
        card = sa.pop()
    elif name == 'b':
        card = Sb.pop()
    else:
        card = sc.pop()

    return card


def TurnLen(sa, sb, sc, name):
    if name == 'a':
        num = len(sa)
    elif name == 'b':
        num = len(sb)
    else:
        num = len(sc)

    return num


Sa = list(input())
Sb = list(input())
Sc = list(input())
Sa.reverse()
Sb.reverse()
Sc.reverse()

TName = "a"
TName = Turn(Sa, Sb, Sc, TName)

while TurnLen(Sa, Sb, Sc, TName) != 0:
    TName = Turn(Sa, Sb, Sc, TName)

print(TName.upper())



Measured memory_bytes: 3064
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    
    if (n >= 1000) {
      System.out.println("ABD");
    } else {
      System.out.println("ABC");
    }
  }
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> pii;
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const ll mod = 1000000007;
char s[maxn]; int n;
int k;
int ena;
ll dp[110][4][2];
ll dfs(int dep, int k) {
	if (n - dep + 1 < k)return 0;
	if (dep == n) {
		if (k == 0) {
			return 1;
		}
		else {
			if (ena)return 9;
			else return s[n] - '0';
		}
	}
	if (k == 0)return 1;
	if (dp[dep][k][ena] != -1)return dp[dep][k][ena];
	ll res = 0;
	if (ena) {
		res = 9*dfs(dep + 1, k - 1) % mod;
		res = (res + dfs(dep + 1, k)) % mod;
	}
	else {
		if (s[dep] - '0' > 0) {
			ena = 1;
			res = (s[dep] - '0' - 1)*dfs(dep + 1, k - 1) % mod;
			res = (res + dfs(dep + 1, k)) % mod;
			ena = 0;
			res = (res + dfs(dep + 1, k - 1)) % mod;
		}
		else {
			res = dfs(dep + 1, k) % mod;
		}
	}
	return dp[dep][k][ena] = res;
}
int main() {
	scanf("%s", s + 1);
	cin >> k;
	n = (int)strlen(s + 1);
	memset(dp, -1, sizeof(dp));
	ena = 0;
	cout << dfs(1, k) << endl;
	return 0;
};

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

int main(){
  int N;
  ll K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i,N){
    int a;
    cin >> a;
    A.at(i)=a-1;
  }
  vector<int> S; //i番目∈Kの居る地点
  vector<int> M(N, -1); //来たかの判定+何番目か

  int p=0;
  while(true){
    if(M.at(p)==-1){
      M.at(p)=S.size();
      S.push_back(p);
      p=A.at(p);
    }
    else break;
  }

  int f = S.size()-M.at(p); //周期

  if(K<M.at(p)) cout << S.at(K)+1 << endl; 
  else{
    int r = (K-M.at(p))%f; //f*x後から進む分
    cout << S.at(r+M.at(p))+1 << endl;
  }
}

Measured memory_bytes: 5880
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};


int N;
ll fact[110];

int main () {
  cin >> N;

  rep(i, N) {
    int tmp = i;

    for (int k=2;k<=100;++k) {
      while (tmp % k == 0) {
        //cout << k << "\n";
        fact[k]++;
        tmp /= k;
      }
    }

    if (tmp != 1) fact[tmp] = 1;
  }

  //rep(i, N) {
  //  cout << fact[i] << "\n";
  //}

  ll ans = 0;

  for (int i=0;i<=100;++i) {
    if (fact[i] >= 74) ans++;
  }

  //cout << ans << "\n";

  for (int i=0;i<=100;++i) {
    for (int j=i+1;j<=100;++j) {
      if (fact[i] >= 2 && fact[j] >= 24) {
        ans++;
      }
      if (fact[j] >= 2 && fact[i] >= 24) {
        ans++;
      }
    }
  }

  //cout << ans << "\n";

  for (int i=0;i<=100;++i) {
    for (int j=i+1;j<=100;++j) {
      if (fact[i] >= 4 && fact[j] >= 14) {
        ans++;
      }
      if (fact[i] >= 14 && fact[j] >= 4) {
        ans++;
      }
    }
  }  

  //cout << ans << "\n";

  for (int i=0;i<=100;++i) {
    for (int j=i+1;j<=100;++j) {
      for (int k=j+1;k<=100;++k) {
        if (fact[i] >= 2 && fact[j] >= 4 && fact[k] >= 4) {
          ans++;
        }
        if (fact[i] >= 4 && fact[j] >= 2 && fact[k] >= 4) {
          ans++;
        }
        if (fact[i] >= 4 && fact[j] >= 4 && fact[k] >= 2) {
          ans++;
        }
      }
    }
  }  

  cout << ans << "\n";
}

Measured memory_bytes: 256
//    ____       ____                 _           
//   |  _ \ _ __|  _ \  ___ _ __   __| |_ __ ___  
//   | | | | '__| | | |/ _ \ '_ \ / _` | '__/ _ \ 
//   | |_| | |_ | |_| |  __/ | | | (_| | | | (_) |
//   |____/|_(_)|____/ \___|_| |_|\__,_|_|  \___/ 
//                                                

 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;


#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define f first
#define s second
#define pb push_back
#define ll long long

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll LLOO = 1e18+7;
const ll OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 2e5+7;

int ans[N];

int main()
{
	
	int n;
	scanf("%d",&n);
	rep(i,n-1)
	{
		int x;
		scanf("%d",&x);
		ans[x-1]++;
	}
	rep(i,n)
	{
		printf("%d\n",ans[i]);
	}
    return 0;
}



Measured memory_bytes: 4500
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>
#include <cctype>
#include <algorithm>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const double PI=3.14159265358979323846;

int main(){
  string s, t;
  int ans = 0;
  cin >> s;
  transform(s.begin(),s.end(),s.begin(),::tolower);  
  while(93872984){
    cin >> t;
    if(t == "END_OF_TEXT") break;    
    transform(t.begin(),t.end(),t.begin(),::tolower);
    if(s == t) ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if(A + B > C + D){
        cout << "Left";
    }else if(A + B < C + D){
        cout << "Right";
    }else{
        cout << "Balanced";
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
N=int(input())

A=[[0,0] for i in range(N)]
B=[0]*(N*(N-1)//2)
for i in range(N):
    A[i][0],A[i][1]=map(int,input().split())
c=0
for i in range(N):
    for j in range(i+1,N):
        B[c]=((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)**0.5
        c+=1

D=(N)*(N-1)/2

print(sum(B)*(N-1)/(D))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////



int main() {
    
    ll n;cin>>n;
    ll a[n][3];rep(i,0,n-1)rep(j,0,2)cin>>a[i][j];
    if(a[0][2]==0){
        bool f=false;
        rep(i,1,n-1){
            if(a[i][2]!=0){
                rep(j,0,2){
                    swap(a[0][j],a[i][j]);
                }
                f=true;
                break;
            }
        }
        if(!f){
            bool x[105][105];memset(x,true,sizeof(x));
            rep(i,0,n-1){
                x[a[i][0]][a[i][1]]=false;
            }
            rep(ci,0,100)rep(cj,0,100){
                if(x[ci][cj]){
                    cout<<ci<<" "<<cj<<" "<<1<<endl;
                }
                return 0;
            }
        }
    }
    rep(ci,0,100){
        rep(cj,0,100){
            ll h=a[0][2]+abs(ci-a[0][0])+abs(cj-a[0][1]);
            bool flag=true;

            rep(i,1,n-1){
                if(a[i][2]==0){
                    if(a[i][2]+abs(ci-a[i][0])+abs(cj-a[i][1])<h){
                        flag=false;
                        break;
                    }
                }else if(h!=a[i][2]+abs(ci-a[i][0])+abs(cj-a[i][1])){
                    flag=false;
                    break;
                }
            }
            if(flag&&h>=1){
                cout<<ci<<" "<<cj<<" "<<h<<endl;
            }
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
S = input()
X = [-1]*N
k = 0
i = 1
c = 0
for s in S:
	if s == str(i):
		c += 1
	else:
		X[k] =c
		i = (i+1)%2
		c = 1
		k+= 1
X[k] = c
for n in range(N):
	if X[N-n-1] != -1:
		b = N-n
		break
X = X[:b]
M = len(X)
ko = M //2
if M == 2*ko:
	X.append(0)
#print(X)
if ko <= K:
	print(N) 
else:
	now = sum(X[0:2*K+1])
	#print(now)
	maxm = now
	for t in range(ko-K):
		a = X[2*t] +X[2*t+1]
		b = X[2*(K+t)+1]+X[2*(K+t)+2]
		now += b - a
		#print(now, a, b)
		maxm = max(maxm, now)
	print(maxm)

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int MAX_V = 1000;
int V; //????????°
vector<int> G[MAX_V]; //??°??????
int match[MAX_V]; // ??????????????°????????¢
bool used[MAX_V]; // dfs??§??¢???????????????

void add_edge(int u, int v){
    G[u].push_back(v); G[v].push_back(u);
}

// ?¢???????????????¢?´¢
bool bp_dfs(int v){
    used[v]=true;
    rep(i,G[v].size()){
        int u=G[v][i], w=match[u];
        if(w<0 || (!used[w]&&bp_dfs(w))){
            match[v]=u; match[u]=v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(){
    int ret=0;
    memset(match,-1,sizeof(match));
    rep(i,V){
        if(match[i]<0){
            memset(used,0,sizeof(used));
            if(bp_dfs(i)) ++ret;
        }
    }
    return ret;
}

vector<int> divisor(int n)
{
    vector<int> ret;
    for(int i=1; i*i<=n; ++i)
    {
        if(n%i==0)
        {
            ret.pb(i);
            if(i != n/i) ret.pb(n/i);
        }
    }
    sort(all(ret));
    return ret;
}

bool same_factor(const vector<int>& a, const vector<int>& b)
{
    int A=a.size(), B=b.size();
    int x=1, y=1;

    while(x<A && y<B)
    {
        if(a[x]>b[y]) ++y;
        else if(a[x]<b[y]) ++x;
        else return true;
    }

    return false;
}

int main()
{
    int m,n;
    while(scanf(" %d %d",&m,&n),m)
    {
        vector<int> b(m),r(n);
        rep(i,m) scanf(" %d", &b[i]);
        rep(i,n) scanf(" %d", &r[i]);

        vector<int> B[500],R[500];
        rep(i,m) B[i] = divisor(b[i]);
        rep(i,n) R[i] = divisor(r[i]);

        V = n+m;
        rep(i,MAX_V) G[i].clear();

        rep(i,m)rep(j,n)
        {
            if(same_factor(B[i],R[j])) add_edge(i,m+j);
        }

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

Measured memory_bytes: 5236
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let m: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut xv = vec![0i32; m];
    for i in 0..m - 1 {
        xv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    xv[m - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let ans = if n >= m {
        0
    } else {
        xv.sort();
        let mut lv = vec![0i32; m];
        for i in 1..m {
            lv[i] = (xv[i - 1] - xv[i]).abs();
        }
        lv.sort();
        let mut l = 0;
        for i in 0..m - n + 1 {
            l += lv[i];
        }
        l
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>

int main() {
    std::string S;
    std::cin >> S;

    std::vector<char> characters;
    for (int i = 0; i < S.size(); ++i) {
        characters.push_back(S[i]);
    }

    std::sort(characters.begin(), characters.end());
    characters.erase(std::unique(characters.begin(), characters.end()), characters.end());

    std::cout << (S.size() == characters.size() ? "yes" : "no") << std::endl;

    return 0;
}


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

int main(){
	string str;
	cin>>str;
	int date  = stoi(str);
	int xx = date%100;
	date/=100;
	int zz = date;
		
	if( xx > 0 && xx <= 12 ){
		ans = "MM";
	}
	else if( xx >= 0 ){
		ans = "YY";
	} 
	if( zz > 0 && zz <= 12 ){
		ans = "MM"+ans;
	} 
	else if( zz >= 0 ){
		ans = "YY"+ans;
	}
	
		if(ans == "MMMM") 
			cout<<"AMBIGUOUS"<<endl;
			
		else if(ans == "YYYY") 
			cout<<"NA"<<endl;
		else
			cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);

//SegmentTree 
template<class T>class SegmentTree{
	vector<T> seg;
	function<T(T, T)> func;
	/*func:ex)
	function<int(int,int)>down=[](int a,int b){return min(a,b);};
	*/
	private:
	T findquary(int left,int right,int index,int atStart,int atStop){
		if ((left <= atStart) and (atStop <= right)){//対象範囲に完全に囲まれる
			return seg[index];
		}if((atStop <= left) or ( right < atStart)){//対象範囲に全く関わらない
			return init;
		}if (index >= size){//範囲外・子がいない
			return seg[index];
		}
		//対象に一部が含まれる
		T aL=findquary(left, right, index * 2, atStart, atStart + (atStop - atStart) / 2);
		T aR= findquary(left, right, index * 2 +1,  atStart +(atStop - atStart) / 2, atStop);
		return func(aL,aR);
	}
	T upquary(int index){ //q1
		return func(seg[index],seg[index+1]);
	}
	public:
	int size; //size of segmenttree
	T init;//unit
	bool found=false;//find query done
	//constructor
	SegmentTree(int _legth, function<T(T, T)> _func, T _init = 0 )
	{
		size=1;
		func = _func;
		init=_init;
		while(size <=_legth){
			size<<=1;
		}
		seg.assign(size<<1,init);
	}
	T get(int index){
		return seg[size+index];
	}
	void show(){
		rep(i,size*2){
			clog<<seg[i]<<" ";
		}
	clog<<endl;
	}
	void clean(){
		found=true;
		for(int i=(size<<1)-2;i>=2;i-=2){
			seg[i/2]=upquary(i);
		}
	}
	//change value 
	void update(int index, T value){
		seg[size+index]=value;
		if (found==false){return ;}
		int ter=index+size;
		while(ter!=1){
			ter/=2;
			seg[ter]=upquary(ter*2);
		} //show();
	}
	//find value
	T find(int l, int r){ //q2
		if(found==false){
			clean();
		//	show();
		}
		T res = seg[size + l];
		res = findquary(l, r,1,0, size);
		return res;
	}
};
int main(){
	int n,q;
	cin >>n>>q;
	int id;
	ll x,y;
	function<ll(ll,ll)>down=[](ll a,ll b){return min(a,b);};
	SegmentTree<ll> seg(n, down, 2147483647);
	rep(i,q){
		cin>>id>>x>>y;
		if(id==0){
			seg.update(x,y);
		//	seg.show();
		}else{
			cout<<seg.find(x,y)<<endl;
		}
	}
	
}


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

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

  vector<int> wg;
  for(int i = 0;i < N;++i){
    int temp;
    cin>>temp;
    wg.push_back(temp);
  }

  vector<int> group;
  int j = 0;
  while(1){
    int mx = 0;
    int mn = 100000;
    int temp = 0;
    for(int i = 0;i < M;++i){
      if(j == N){
        j = 0;
      }
      temp = wg.at(j);
      mx = max(mx,temp);
      mn = min(mn,temp);
      ++j;
    }
    temp = mx - mn;
    group.push_back(temp);

    if(j == N){
      break;
    }
  }

  int ans = 0;
  for(int e : group){
    ans += e;
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3168
require 'prime'

MAX = 100_000

# E. Sieve
is_prime = {}
Prime.each(MAX) do |p|
  is_prime[p] = true
end

# 2017-like?
# cum sums
cs =
  Array
    .new(MAX) { |i| i.odd? && is_prime[i] && is_prime[(i + 1) / 2] ? 1 : 0 }
    .inject([0]) { |a, n| a << a.last + n }

# query
q = gets.to_i
q.times do
  l, r = gets.split.map(&:to_i)
  # [l,r) = l...r
  p cs[r + 1] - cs[l]
end


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

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX = 1e6 + 5, MOD = 1e9 + 7  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

int arr[MAX];
int main(){

    fastio;
    string s;
    cin>>s;
    if(s[2] == s[3] && s[4] == s[5]) cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    answer = [0 for i in range(N+1)]

    for i in range(0, N):
        for j in range(i+1, N):
            answer[min(abs(j-i), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X))] += 1

    for i in range(1, N):
        print(answer[i])


if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;
using ld = long double;

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(3));
    for (auto &e : a) cin >> e[0] >> e[1] >> e[2];

    vector<vector<int>> dp(n + 1, vector<int>(3, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (k != j) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i - 1][j]);
                }
            }
        }
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}


Measured memory_bytes: 11264
#include<iostream>
#include<cstring>
using namespace std;
const int mod = 1000000007;

int main(){
    int h, w, x;
    cin >> h >> w >> x;

    if(w == 1){
        cout << 1 << endl;
        return 0;
    }

    int dp[h+1][w];
    memset(dp, 0, sizeof(dp));

    dp[0][0] = 1;
    for(int i = 1; i <= h; i++){
        for(int j = 0; j < 1<<(w-1); j++){
            int raw[w-1];
            for(int k = 0; k < w-1; k++){
                raw[k] = 1&(j>>k);
            }

            bool judge = true;
            for(int k = 1; k < w-1; k++)  if(raw[k] + raw[k-1] == 2)  judge = false;
            if(!judge)  continue;

            for(int k = 0; k < w; k++){
                int nk = k;
                if(k > 0 && raw[k-1] == 1)  nk--;
                if(k < w-1 && raw[k] == 1)   nk++;
                dp[i][nk] = (dp[i][nk] + dp[i-1][k]) % mod;
            }
        }
    }

// for(int i = 0; i <= h; i++){
//     for(int j = 0; j < w; j++){
//         cout << dp[i][j] << " ";
//     }
//     cout << endl;
// }

    cout << dp[h][x-1] << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
naibu = 0
head = 0
tail = 0
both = 0

for _ in range(n):
    s = str(input())
    naibu += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        both += 1
    elif s[0] == 'B':
        head += 1
    elif s[-1] == 'A':
        tail += 1

ans = min(head, tail) + both + naibu
if head == 0 and tail == 0:
    ans = max(both-1, 0) + naibu
print(ans)

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

int main() {
    int n; cin >> n;
    vector<bool> p(n);
    for (int i = 1; i < n+1; i++) {
        int tmp;
        cin >>tmp;
        if (i == tmp)
            p[i-1] = true;
        else
            p[i-1] = false;
        
    }
    int ans = 0;
    rep(i, n) {
        if (p[i] == true) {
            ans++;
            if (i != n-1)
                p[i+1] = false;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define int long long
#define moder 1000000007
#define P std::pair<int,int>
using namespace std;

int n;
string s,t;
signed main(){
	cin>>n;
	int a=0,b=0;
	rep(i,n){
		cin>>s>>t;
		if(s==t){
			a++;
			b++;
		}
		if(s>t)a+=3;
		if(s<t)b+=3;
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  // string n;
  // int k;
  // cin >> n >> k;
  // vector<int> d(k);
  // rep(i,k) cin >> d[i];
  // set<int> st;
  // rep(i,k) st.insert(d[i]);

  // cout << (st.find(1)!=st.end()) << "\n";
  // int res = 0;
  // int m = n.size();
  // bool f = false;
  // rep(i,m){
  //   int x = n[i] - '0';
  //   if(f){
  //     rep(j,10){
  // 	if(st.find(j)==st.end()) {
  // 	  res = res*10+j;
  // 	  break;
  // 	}
  //     }
  //   }
  //   else{
  //     for(int j=x;j<=10;++j){
  // 	if(st.find(j)==st.end()) {
  // 	  res = res*10+j;
  // 	  if(j!=x) f = true;
  // 	  break;
  // 	}
  //     }
  //   }
  // }

  // cout << res << "\n";
    
  // return 0;

  int n,k;
  cin >> n >> k;
  vector<int> d(k);
  rep(i,k) cin >> d[i];
  set<int> st;
  rep(i,k) st.insert(d[i]);

  int j = 0;
  while(1){
    int x = n + j;
    bool f = true;
    while(x>0){
      if(st.find(x%10)!=st.end()){
	f = false;
	break;
      }
      x /= 10;
    }
    if(f){
      cout << n+j << "\n";
      break;
    }
    j++;
  }
  return 0;

}


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

int main()
{
    long long int a1,a2,b1,b2,c1,c2,d1,d2;
    cin>>a1>>a2>>b1>>b2;;
    c1=b1-b2+a2;
    c2=b2+b1-a1;
    d1=c1-c2+b2;
    d2=c2+c1-b1;
    cout<<c1<<' '<<c2<<' '<<d1<<' '<<d2<<endl;
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N,T; cin>>N>>T;
    vector<pair<int,int>> AB;
    rep(i,N){
        int a,b; cin>>a>>b;
        AB.push_back({a,b});
    }
    sort(AB.begin(),AB.end());
    vector<vector<int>> dp(N+1,vector<int> (T+1,0));
    for(int i = 0; i < N; i++){
        for(int t = 0; t < T; t++){
            int a = AB.at(i).first;
            int b = AB.at(i).second;
            if(a+t>T)dp.at(i+1).at(T) = max(dp.at(i+1).at(T),dp.at(i).at(t)+b);
            if(a>t)dp.at(i+1).at(t) = dp.at(i).at(t);
            else{
                dp.at(i+1).at(t) = max(dp.at(i).at(t),dp.at(i).at(t-a)+b);
            }
        }
    }
    int res = 0;
    rep(i,N+1)res = max({res,dp.at(i).at(T-1),dp.at(i).at(T)});
    cout<<res<<endl;
}


Measured memory_bytes: 35584
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n,k = LI()
p = LI()

p.sort()

sum = 0
for i in range(k):
    sum += p[i]

print(sum)

Measured memory_bytes: 62412
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
int h, w, map[1401][1401], upmost[1401][1401], ans;
struct rect{
    int h, pos;
    rect(){}
    rect(int h, int pos){
        this->h = h;
        this->pos = pos;
    }
};
stack<rect> dp;


int main(){
    //freopen("in.txt", "r", stdin);
    scanf("%d %d", &h, &w);
    memset(upmost, 0, sizeof(upmost));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            scanf("%d", &map[i][j]);
            upmost[i][j] = 1 - map[i][j];
        }
        upmost[i][w] = 0;
    }
    for(int i=1; i<h; i++)
    for(int j=0; j<w; j++)
        if(upmost[i][j]!=0)
            upmost[i][j] += upmost[i-1][j];

/*
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++)
            printf("%d ", upmost[i][j]);
        printf("\n");
    }
*/
    ans = 0; 
    for(int i=0; i<h; i++){
        while(!dp.empty()) dp.pop();
        for(int j=0; j<w+1; j++){
            if(dp.empty())
                dp.push(rect(upmost[i][j], j));
            else if(dp.top().h > upmost[i][j]){
                int left_most = j;
                while(!dp.empty() && dp.top().h > upmost[i][j]){
                    ans = max(ans, (j-dp.top().pos)*dp.top().h);
                    left_most = dp.top().pos;
                    dp.pop();
                }
                dp.push(rect(upmost[i][j], left_most));
            }else if(dp.top().h < upmost[i][j])
                dp.push(rect(upmost[i][j], j));
        }
    }    

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


Measured memory_bytes: 18048
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        Book[] book = new Book[n];
        for(int i = 0; i < n; i++){
            int c = sc.nextInt();
            int[] a = new int[m];
            for(int j = 0; j < m; j++){
                a[j] = sc.nextInt();
            }
            book[i] = new Book(c,a);
        }
        int ans = Integer.MAX_VALUE;
        int max = (int)Math.pow(2,n);
        for(int i = 0; i < max; i++){
            int[] tmp = new int[m];
            int cnt = 0;
            for(int j = 0; j < n; j++){
                if((i >> j) % 2 == 1){
                    cnt += book[j].y;
                    for(int k = 0; k < m; k++){
                        tmp[k] += book[j].a[k];
                    }
                }
            }
            boolean bool = true;
            for(int ch : tmp){
                if(ch < x){
                    bool = false;
                    break;
                }
            }
            if(bool){
                ans = Math.min(ans,cnt);
            }
        }
        if(ans == Integer.MAX_VALUE){
            System.out.println(-1);
        }else{
            System.out.println(ans);
        }
    }
}

class Book{
    int y;
    int[] a;
    public Book(int y,int[] a){
        this.y = y;
        this.a = a;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 26896
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int group(int x){
  if(x == 2)
    return 3;
  else if(x == 4 || x == 6 || x == 9 || x == 11)
    return 2;
  else
    return 1;
}

int main(){
  int x, y;
  cin >> x >> y;
  int gx = group(x), gy = group(y);
  if(gx == gy)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <cstdio>
using namespace std;

void insertionSort(int A[], const int n, const int g, int *cnt)
{
    for( int i = g; i < n; ++i ){
        int tmp = A[i];
        int j = i - g;
        while( -1 < j && tmp < A[j] ){
            //cout << A[j+g] << "<-->" << A[j] << endl;
            A[j+g] = A[j];
            j = j - g;
            ++*cnt;
        }
        A[j+g] = tmp;
    }
}

void shellSort(int A[], const int n)
{
    int cnt = 0;
    int m;
    int G[100];
    for( int i = 0; i < 100; ++i ){
        if( i == 0 ) G[i] = n / 2 + 1;
        else G[i] = G[i-1] / 2 - 1;
        if( G[i] < 0 ){
            G[i-1] = 1;
            G[i] = 0;
            m = i;
            break;
        }
    }

    for( int i = 0; i < m; ++i )
        insertionSort(A, n, G[i], &cnt);

    //出力
    printf("%d\n", m);
    for( int i = 0; i < m; ++i ){
        if( i ) printf(" ");
        printf("%d", G[i]);
    }
    printf("\n%d\n", cnt);
    for( int i = 0; i < n; ++i )
        printf("%d\n", A[i]);
}

int main()
{
    //入力
    int n;
    scanf("%d", &n);
    int A[n];
    for( int i = 0; i < n; ++i )
        scanf("%d", &A[i]);

    //シェルソート
    shellSort(A, n);

    return 0;
}


Measured memory_bytes: 7128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;

struct Node {
	int id;
	int depth;
	int height;
	int parent;
	int sibling;
	int deg;
	int left;
	int right;
	string type;
};

int solve(Node node[], int i, int depth) {
	int height = 0;
	int deg = 0;

	node[i].depth = depth;

	if (node[i].left == -1 && node[i].right == -1) {
		node[i].type = "leaf";
	}
	else {
		node[i].type = "internal node";
	}

	if (node[i].left != -1) {
		int left = node[node[i].left].id;
		node[left].parent = node[i].id;
		node[left].sibling = node[i].right;
		height = max(height, solve(node, left, depth + 1));
		deg++;
	}
	if (node[i].right != -1) {
		int right = node[node[i].right].id;
		node[right].parent = node[i].id;
		node[right].sibling = node[i].left;
		height = max(height, solve(node, right, depth + 1));
		deg++;
	}
	node[i].height = height;
	node[i].deg = deg;
	return height + 1;
}

int main() {
	int n;
	Node node[25];
	int root;
	bool table[25] = { false };

	cin >> n;
	for (int i = 0; i < n; i++) {
		int index;
		cin >> index;
		node[index].id = index;
		cin >> node[index].left;
		cin >> node[index].right;

		if(node[index].left != -1)table[node[index].left] = true;
		if(node[index].right != -1)table[node[index].right] = true;
	}
	
	for (int i = 0; i < n; i++) {
		if (table[i] == false) {
			root = i;
			break;
		}
	}

	solve(node, root, 0);
	node[root].type = "root";
	node[root].parent = -1;
	node[root].sibling = -1;

	for (int i = 0; i < n; i++) {
		cout << "node " << i << ": parent = " << node[i].parent << ", ";
		cout << "sibling = " << node[i].sibling << ", ";
		cout << "degree = " << node[i].deg << ", ";
		cout << "depth = " << node[i].depth << ", ";
		cout << "height = " << node[i].height << ", ";
		cout << node[i].type << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

struct UnionFind {
    vector<int> d;

    UnionFind(int n): d(n,-1) {}

    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) { return root(x) == root(y);}

    int size(int x) { return -d[root(x)];}
};


int main() {
    int n, m, k; cin >> n >> m >> k;
    int a[m], b[m];
    vector<int> deg(100010);
    UnionFind uf(n+1);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        uf.unite(a[i], b[i]);
        deg[a[i]]++;
        deg[b[i]]++;
    }

    int c[k], d[k];
    vector<vector<int>> block(100010, vector<int>());
    for (int i = 0; i < k; i++) {
        cin >> c[i] >> d[i];
        block[c[i]].push_back(d[i]);
        block[d[i]].push_back(c[i]);
    }


    for (int i = 1; i <= n; i++) {
        int res = uf.size(i) - 1 - deg[i];
        for (int u : block[i]) {
            if (uf.same(i, u)) res--;
        }
        printf("%d%c", res, i==n?'\n':' ');
    }
}


Measured memory_bytes: 8320
#include <stdio.h>

int gcd(int a, int b);

int main() {

	int a;
	int b;

	scanf("%d", &a);
	scanf("%d", &b);

	printf("%d\n", gcd(a, b));

	return 0;
}

int gcd(int a, int b) {

	int tmp;
	
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}


	while (a % b != 0) {
		tmp = a % b;
		a = b;
		b = tmp;
	}

	return b;

}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 1e6+3;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n), b(n);
    for (Int i = 0; i < n; i++) cin >> a[i] >> b[i];
    map<pair<Int, Int>, Int> mp;
    for (Int i = 0; i < n - 1; i++) {
        for (Int j = i + 1; j < n; j++) {
            mp[{a[j] - a[i], b[j] - b[i]}]++;
            mp[{a[i] - a[j], b[i] - b[j]}]++;
        }
    }
    Int ma = 0;
    for (auto v : mp) ma = max(ma, v.se);
    dump(n - ma);
    return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  string a,b;
  if (n%2 == 1){
    cout << "No" << endl;
  }
  else{
    for(int i=0; i<n/2; i++){
      a += s.at(i);
    }
    for(int i=n/2; i<n; i++){
      b += s.at(i);
    }
    if(a == b){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256