akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount


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


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int n, k, a[100005];
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = (n - 1  + k - 2) / (k - 1);
    cout << ans;
}

Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip()
tdlist = lambda i, j, value=0: [[value] * j for _ in range(i)]
MOD = 10**9+7

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

for i in range(h):
    for j, x in enumerate(input()):
        grid[i][j] = -1 if x == "#" else 0

for i in range(h):
    if grid[i][0] == -1: break
    grid[i][0] = 1

for j in range(w):
    if grid[0][j] == -1: break
    grid[0][j] = 1

for i in range(1, h):
    for j in range(1, w):
        if grid[i][j] == -1: continue
        a = 0 if grid[i-1][j] == -1 else grid[i-1][j]
        b = 0 if grid[i][j-1] == -1 else grid[i][j-1]
        grid[i][j] = (a + b) % MOD

print(grid[h-1][w-1] % MOD)


Measured memory_bytes: 42568
#include<iostream>
#include<vector>
#include<algorithm>
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
using namespace std;
int main()
{
    ios;
    ll x;
    cin >> x;
    int a = 0;
    int b = 0;
    for(ll i = -1000; i < 1000; i++)
        for(ll j = -1000; j < 1000; j++)
        {
            if((ll)(i * i * i * i * i) - (ll)(j * j * j * j * j) == x)
            {
                a = i;
                b = j;
                break;
            }
        }
    cout << a << " " << b << '\n';
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 0x3f3f3f3f3f3f3f3f
#define LL long long
#define MX 55
struct Node
{
    LL x, y;
    bool operator < (const Node &b)const{
        return x<b.x;
    }
}pt[MX];

int k, n;

int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++)
        scanf("%lld%lld",&pt[i].x, &pt[i].y);
    sort(pt+1,pt+1+n);
    LL area = INF;
    for (int i=1;i<=n;i++)
    {
        for (int j=i+1;j<=n;j++)
        {
            LL miny = min(pt[i].y, pt[j].y);
            LL maxy = max(pt[i].y, pt[j].y);
            for (int q=1;q<=n;q++)
            {
                if (pt[q].y>maxy||pt[q].y<miny) continue;
                int tot = 0;
                for (int z=q;z<=n;z++)
                {
                    if (pt[z].y>maxy||pt[z].y<miny) continue;
                    tot++;
                    if (tot>=k)
                        area = min(area, (maxy-miny)*(pt[z].x-pt[q].x));
                }
            }
        }
    }
    printf("%lld\n",area);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
// ------------------------
void solve() {
    string S; cin >> S;
    set<int> alph; rep(i, 26) alph.insert(i);

    rep(i, (int)S.size()){
        alph.erase((int)S[i] - (int)'a');
    }
    if(alph.empty()){
        cout << "None" << "\n";
    }else{
        cout << (char)('a' + *alph.begin()) << "\n";
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    string S;
    cin >> S;
    int a,b;
    a = b = -1;

    rep(i,S.size()-1) {
        if (S[i]==S[i+1]) {
            a = i+1;
            b = i+2;
            break;
        }
        else if (i+1<S.size()) {
            if (S[i]==S[i+2]) {
                a = i+1;
                b = i+3;
                break;
            }
        }
    }
    cout << a << " " << b << endl;
}


Measured memory_bytes: 3652
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String str = sc.nextLine();
        String[] str_split = str.split(" ",0);

        int[] nums = new int[str_split.length];
        int top = 0;

        for(int i = 0;i < str_split.length;i++){
            switch(str_split[i].charAt(0)){
                case '+':
                    top--;
                    nums[top - 1] = nums[top - 1] + nums[top];
                    break;
                case '-':
                    top--;
                    nums[top - 1] = nums[top - 1] - nums[top];
                    break;
                case '*':
                    top--;
                    nums[top - 1] = nums[top - 1] * nums[top];
                    break;
                default:
                    nums[top] = Integer.parseInt(str_split[i]);
                    top++;
                    break;
            }
        }
        System.out.println(nums[0]);
    }
}


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}

void chmax(ll &a,const ll &b){
    if(a<b) a=b;
}
void chmin(ll &a,const ll &b){
    if(a>b) a=b;
}


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

    char a[H][W];
    ll dp[H][W];

    rep(i,H){
        rep(j,W){
            cin >> a[i][j];
            dp[i][j]=0;
        }
    }

    rep(i,H){
        rep(j,W){
            if(i!=0 && j!=0){
                if(a[i][j]=='.') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            }else if(i==0 && j!=0){
                if(a[i][j]=='.'){
                    if(dp[i][j-1]==1) dp[i][j]=1;
                }
            }else if(i!=0 && j==0){
                if(a[i][j]=='.'){
                    if(dp[i-1][j]==1) dp[i][j]=1;
                }                
            }else{
                dp[i][j]=1;
            }

        }
    }


    cout << dp[H-1][W-1] <<endl;


    return 0;


}

Measured memory_bytes: 9088
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
static void Main(string[] args){
var N = int.Parse(Console.ReadLine());
//var list=new List<string>();
int ans=0;
int a=0;
int b=0;
int ab=0;
for(int i=0;i<N;i++){
    var s=Console.ReadLine();
    ans+=s.CountOf("AB");
    if(s[s.Length-1]=='A') a+=1;
    if(s[0]=='B') b+=1;
    if(s[s.Length-1]=='A'&&s[0]=='B') ab+=1;
}
a=a-ab;
b=b-ab;
ans+=Math.Min(a,b);
if(ab!=0){
ans+=ab-1;
if(!(a==0&&b==0))ans+=1;
}

Console.WriteLine(ans);

}
}
public static partial class StringExtensions{

  /// <summary>
  /// 指定した文字列がいくつあるか
  /// </summary>
  public static int CountOf(this string self, params string[] strArray){
    int count = 0;

    foreach (string str in strArray) {
      int index = self.IndexOf (str, 0);
      while (index != -1) {
        count++;
        index = self.IndexOf (str, index + str.Length);
      }
    }

    return count;
  }

}  


Measured memory_bytes: 13404
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cout<<endl; 
	}
	eni(!=) cout << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int a, b, c, d;
		cin >> a >> b >> c >> d;
		ll int maxi = max({a * c, a * d, b * c, b * d});
		cout << maxi << endl;
	}
	return 0;
}

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

int main() {
	string st,tt;
	cin >> st;
	for(int i=0;i<st.size();i++)
	{
		if(st[i] == '0') tt+='0';
		else if( st[i] == '1') tt+='1';
		else if(tt.size()>0) tt.pop_back();
	}
	cout << tt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound

using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    if(K==1){
        cout << 0 << endl;
        return 0;
    }
    else{
        cout << N-K << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            solve(in);
        }
    }

    private static void solve(BufferedReader in) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        int N = Integer.parseInt(st.nextToken()), M = Integer.parseInt(st.nextToken());
        int[] l = new int[N + 1], r = new int[N + 1];
        for (int i = 1; i < N + 1; i++) {
            st = new StringTokenizer(in.readLine());
            l[i] = Integer.parseInt(st.nextToken());// 1 <= l <= r <= M
            r[i] = Integer.parseInt(st.nextToken());
        }

        @SuppressWarnings("unchecked")
        List<Integer>[] nByLen = new List[M + 1];
        for (int n = 1; n < N + 1; n++) {
            int len = r[n] - l[n] + 1;
            if (nByLen[len] == null) {
                nByLen[len] = new ArrayList<>();
            }
            nByLen[len].add(n);
        }

        int accum = N;

        fenwick = new int[M + 1];
        for (int d = 1; d < M + 1; d++) {
            int sum = accum;
            for (int e = d; e < M + 1; e += d) {
                sum += faccum(e);
            }
            System.out.println(sum);
            if (nByLen[d] != null) {
                accum -= nByLen[d].size();
                for (int i : nByLen[d]) {
                    fadd(l[i], 1);
                    fadd(r[i] + 1, -1);
                }
            }
        }
    }

    private static int[] fenwick;

    private static int faccum(int i) {
        int sum = 0;
        for (; i > 0; i -= i & -i) {
            sum += fenwick[i];
        }
        return sum;
    }

    private static void fadd(int i, int a) {
        for (; i < fenwick.length; i += i & -i) {
            fenwick[i] += a;
        }
    }
}

Measured memory_bytes: 48728
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
#define N 300005
#define INF 0x3f3f3f3f
#define LL long long
int rd()
{
	LL x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48); c=getchar();}
	return f*x;
}
int n,rt;
int a[N],f[N]/*某个点可以向上延伸的路径数*/;
vector<int>G[N];
void dfs(int u,int fa)
{
	if(G[u].size()==1)//叶节点
	{
		f[u]=a[u];
		return ;
	}
	int mx=0 /*fv最大值*/,sum=0 /*fv之和*/;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(v==fa) continue;
		dfs(v,u);
		sum+=f[v],mx=max(mx,f[v]);
	}
	f[u]=2*a[u]-sum;
	/*
	如果有f[u]条向上 那么剩下(a[u]-f[u])条路径都是以u为lca的
	lca式路径一条可以解决子树里2个 满足 f[u]+2*(a[u]-f[u])=sum 
	解得 f[u]=2*a[u]-sum 
	*/
	if(f[u]<0||a[u]>sum||(mx-f[u]>min(sum-mx,sum/2)))
	{
		puts("NO");
		exit(0);
	}
	/*
	有一些无解的情况
	1.2*a[u]<sum(f[u]<0) 全部是lca式路径都不能满足子树内 u先空了
	2.a[u]>sum 路径全部向上没法把u的石头拿掉 那么u的石头永远也不会被拿掉
	3.mx-f[u]>min(sum-mx,sum/2)
	lca式路径最多有min(sum-mx,sum/2)
	这里是mx太大 让他全部向上贡献 lca式路径都还要单着 mx的无法石头无法全部拿掉 
	*/
} 
int main()
{
	n=rd();
	for(int i=1;i<=n;i++)
		a[i]=rd();
	if(n==2)
	{
		if(a[1]==a[2]) puts("YES");
		else puts("NO");
		return 0;
	} 
	for(int i=1;i<=n-1;i++)
	{
		int u=rd(),v=rd();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(G[i].size()>1)
			rt=i;//根节点的度数要大于1 不然他自己的石头没法拿掉 
	dfs(rt,-1);
	if(f[rt]) puts("NO");
	else puts("YES");
    return 0;
}


Measured memory_bytes: 21704
n = int(input())
s = [input().split() for i in range(n)]

dic = {}
for i in range(n):
    s[i][1] = int(s[i][1])
    s[i].append(i+1)
    restaurant = s[i][0]
    if restaurant not in dic:
        dic[restaurant] = [[s[i][1], s[i][2]]]
    else:
        dic[restaurant].append([s[i][1], s[i][2]])
#print(dic)
keys = sorted(dic.keys())
#print(keys)
for i in keys:
    for j in range(len(dic[i])):
        value = sorted(dic[i], key=lambda x: x[0], reverse=True)
        print(value[j][1])

Measured memory_bytes: 38384
#!python3.4
# -*- coding: utf-8 -*-
# hitachi2020/hitachi2020_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, B, M = i2nn()
    a = i2nn()
    b = i2nn()
    min_price = min(a) + min(b)
    for i in range(M):
        x, y, c = i2nn()
        min_price = min(min_price, a[x-1] + b[y-1] - c)
    print(min_price)
    return

main()


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

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b;
    string s, t;
    cin >> s >> t >> a >> b;
    string rem;
    cin >> rem;
    if (rem == s) --a;
    else --b;
    cout << a << ' ' << b << '\n';
}

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

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


def main():
    a,b,c,d = LI()
    if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d):
        return 'Yes'

    return 'No'



print(main())



Measured memory_bytes: 5460
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int m;
vs32 s, c;
bool ok(string& x)
{
    bool ret = true;
    rep (i, m)
    {
        if (x[s[i] - 1] != c[i] + '0') ret = false;
    }
    return ret;
}

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

    int n;
    cin >> n >> m;
    s.resize(m);
    c.resize(m);
    rep (i, m)
    {
        cin >> s[i] >> c[i];
    }

    string ans(n, '0');
    ans[0] = (n == 1 ? '0' : '1');
    int lim = 1;
    rep (i, n) lim *= 10;

    int temp = 0;
    while (!ok(ans))
    {
        temp = stoi(ans);
        ++temp;
        if (temp >= lim) break;
        for (int idx = n - 1; idx >= 0; --idx)
        {
            ans[idx] = '0' + temp % 10;
            temp /= 10;
        }
    }
    if (temp >= lim) ans = "-1";

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



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

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

  string a,b;
  cin >> a;
  string W[N];
  W[0] = a;

  bool result = true;
  for(int i=1;i<N;i++){
    cin >> b;
    W[i] = b;
    if(a[a.length()-1] != b[0]){
      result = false;
    };
    a = b;
  }

  REP(i,N){
    REP(j,N){
      if(i!=j && W[i] ==W[j]){
        result = false;
      }
    }
  }
  cout << (result ? "Yes" : "No") << endl;



  return 0;
}


Measured memory_bytes: 256
submit = True


def solve_d(test=False, s="RL"):

    if not test:
        s = input()
    res_list = [0] * len(s)

    LR_list = [-1]
    RL_list = []

    for i in range(len(s) - 1):
        if s[i] == "R" and s[i + 1] == "L":
            RL_list.append(i)
        elif s[i] == "L" and s[i + 1] == "R":
            LR_list.append(i)
    LR_list.append(len(s) - 1)
    # print(LR_list)
    # print(RL_list)
    for j in range(len(RL_list)):
        r_cnt = RL_list[j] - LR_list[j]
        l_cnt = LR_list[j + 1] - RL_list[j]
        # print(r_cnt, l_cnt)
        res_list[RL_list[j]] += r_cnt - (r_cnt // 2)
        res_list[RL_list[j] + 1] += r_cnt // 2
        res_list[RL_list[j] + 1] += l_cnt - (l_cnt // 2)
        res_list[RL_list[j]] += l_cnt // 2

    print(" ".join([str(res_list[i]) for i in range(len(s))]))


if __name__ == "__main__":
    if submit:
        solve_d()
    else:
        solve_d(test=True, s="RRLRL")
        solve_d(test=True, s="RRLLLLRLRRLL")
        solve_d(test=True, s="RRRLLRLLRRRLLLLL")


Measured memory_bytes: 49264
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
	string S;
	cin >> S;
	if(S[2]==S[3]&&S[4]==S[5]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;

}

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

int main(void){
    int n, b[100010] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a--;
        b[a]++;
    }
    
    int k = 0, l = 0;
    for (int i = 0; i < 100000; i++) {
        if (b[i] > 0) b[i] = (b[i] + 1) % 2 + 1;
        if (b[i] == 1) k++;
        if (b[i] == 2) l++;
    }
    
    if (l % 2 == 0) cout << k + l << endl;
    else cout << k + l - 1 << endl;
    
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
using ll=long long;
const int M=100010;


int main(){
	int R,G,B,N;
	int dp[3300]={};

	cin>>R>>G>>B>>N;
	dp[0]=1;
	rep(i,0,N-R+2)dp[i+R]+=dp[i];
	rep(i,0,N-G+2)dp[i+G]+=dp[i];
	rep(i,0,N-B+2)dp[i+B]+=dp[i];
	
	cout<<dp[N]<<endl;
}

Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
r=[0]*n
for i in range(n-1):
    l[i+1]=gcd(l[i],a[i])
    r[i+1]=gcd(r[i],a[n-i-1])
#print(k)
#print(l)
ans=1
for i in range(n):
    ans=max(ans,gcd(l[i],r[n-i-1]))
    #iを除いたgcd
print(ans)


Measured memory_bytes: 63984
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B81 solver = new B81();
        solver.solve(1, in, out);
        out.close();
    }

    static class B81 {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            boolean flag = false;
            for (int i = 1; i <= 9; i++) {
                for (int j = 1; j <= 9; j++) {
                    if (i * j == n) flag = true;
                }
            }
            if (flag) out.println("Yes");
            else out.println("No");
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



Measured memory_bytes: 23764
import java.util.*;

public class Main {
  private static int getCost(int[] as, int v) {
    int sum = 0;
    for (int a : as) {
      sum += (a - v)*(a - v);
    }
    return sum;
  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int[] as = new int[n];
    for (int i = 0; i < n; i++) {
      as[i] = s.nextInt();
    }
    int minimumCost = Integer.MAX_VALUE;
    for (int v = -100; v <= 100; v++) {
      minimumCost = Math.min(minimumCost, getCost(as, v));
    }
    System.out.println(minimumCost);
  }
}


Measured memory_bytes: 9812
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> v;
    v.push_back(0);
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        v.push_back(x);
    }
    v.push_back(0);
    for(int i = 0; i < v.size() - 1; i++)
    {
        sum += abs(v[i] - v[i + 1]);
    }
    for(int i = 1; i <= n; i++)
    {
        int ans = sum + abs(v[i - 1] - v[i + 1]);
        ans -= abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1]);
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 1784
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type intHeap []int

func (h intHeap) Len() int           { return len(h) }
func (h intHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h intHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for D - Powerful Discount Tickets
	var N, M int
	fmt.Scan(&N, &M)

	sc.Split(bufio.ScanWords)
	A := make([]int, N)
	h := &intHeap{}
	heap.Init(h)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		heap.Push(h, A[i])
	}

	for i := 0; i < M; i++ {
		heap.Push(h, (heap.Pop(h).(int))/2)
	}

	var ans int
	for h.Len() > 0 {
		ans += heap.Pop(h).(int)
	}

	fmt.Println(ans)
}


Measured memory_bytes: 8056
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		// 標準入力の値を、半角スペースで分割
		String[] inputRowAndCol = (input.readLine()).split("\\s");
		int row = Integer.parseInt(inputRowAndCol[0]); // 行
		int col = Integer.parseInt(inputRowAndCol[1]); // 列

		// 表
		int[][] matrixA = new int[row +1][col +1];
		// 縦の合計用
		int[] colSum = new int[col +1];
		// 横の合計用
		int[] rowSum = new int[row +1];
		// 入力された、1行の数字を格納する用
		String[] number = null;

		// 表の行数だけ繰り返し
		for (int i = 0; i < matrixA.length; i++) {
			// 最終行以外は、入力された行の数字を処理
			if (i != matrixA.length -1) {
				number = (input.readLine()).split("\\s");
			}
			// 表の列数だけ繰り返し
			for (int j = 0; j < matrixA[i].length -1; j++) {
				// 最終行以外は、合計していく
				if (i != matrixA.length -1) {
				  rowSum[i] += Integer.parseInt(number[j]);
				  colSum[j] += Integer.parseInt(number[j]);
				}
				// 最終行の行の合計
				if (i == matrixA.length -1 && j == matrixA[i].length -2) {
					for (int m = 0; m < rowSum.length; m++) {
						matrixA[i][j +1] += rowSum[m];
					}
			    // 最終行以外の行の合計
				} else if (j == matrixA[i].length -2) {
					matrixA[i][j +1] = rowSum[i];

				}
				// 列の合計
				if (i == matrixA.length -1) {
					matrixA[i][j] = colSum[j];
				// 表に値を入れていく
				} else {
					matrixA[i][j] = Integer.parseInt(number[j]);
				}

			}
		}

		for (int k = 0; k < matrixA.length; k++) {
			for (int l = 0; l < matrixA[k].length; l++) {
				System.out.print(matrixA[k][l]);
				if (l != matrixA[k].length -1) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}


	}

}



Measured memory_bytes: 33656
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;

int main(){
	int ans = 700;
	for(int i = 0; i < 3; ++ i) {
		if(getchar() == 'o') ans += 100;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
map<string,int>s;
string tmp;
int max_val=-1;
rep(i,n){
    cin>>tmp;
    s[tmp]++;
    max_val=max(max_val,s[tmp]);
}

vector<string> ans;

for(auto m:s){
    if(m.second==max_val){
        ans.pb(m.first);
    }
}
sort(ans.begin(),ans.end());
for(auto m:ans){
    cout<<m<<endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 25584
#include<bits/stdc++.h>
using namespace std;
    int main(){
      while(1){
        int H,W;
        cin>>H>>W;
        if(H==0 && W==0) break;

        for(int i=0;i<H;i++){
          for(int i=0;i<W;i++){
            cout<<"#";
            }
          cout<<endl;
          }
        cout<<endl;
        }
     return 0;
}


Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 126476
n, m, x = map(int, input().split())
CA = [tuple(map(int, input().split())) for _ in range(n)]

minimum = float("inf")
for i in range(2**n):
    select = [0] * n
    a = [0] * m
    money = 0
    for j in range(n):
        if (i>>j)&1:
            select[n-1-j] = 1
    for i, v in enumerate(select):
        if v == 1:
            money += CA[i][0]
            for j, u in enumerate(CA[i][1:]):
                a[j] += u
    if all(l >= x for l in a):
        minimum = min(minimum, money)
print(-1 if minimum == float("inf") else minimum)

Measured memory_bytes: 69300
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, q, cnt[210000], sum;
int main() {
    cin >> n;
    vector<ll> s(n);
    REP(i,n){
        ll a;
        cin >> a;
        cnt[a]++;
        sum += a;
        s[i] = a;
    }
    cin >> q;
    REP(i, q){
        ll b, c;
        cin >> b >> c;
        sum -= cnt[b] * b;
        cnt[c] += cnt[b];
        sum += cnt[b] * c;
        cnt[b] = 0;
        cout<< sum <<endl;
    }
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
int main()
{
	int i,j;
	long long t,n;
	scanf("%lld",&t);
	for(i=1;i<=t;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+t+1);
	n=a[t];
	j=t-1;
	for(i=(t-2)/2;i>0;i--)
		n+=2*a[j--];
	if(t%2==1)
		n+=a[j];
	printf("%lld",n);
}

Measured memory_bytes: 5300
import java.util.Scanner;
public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long X=sc.nextLong();
		long ans=0;
		while(X>=500) {
			X-=500;
			ans+=1000;
		}
		while(X>=5) {
			X-=5;
			ans+=5;
		}
		System.out.println(ans);


	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,u=1;
  cin >> h >> w;
  string s[h][w];
  char t='A';
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> s[i][j];
      if(s[i][j]=="snuke"){
        cout << t << u << endl;
        return 0;
      }
      t++;
    }
    u++;
    t='A';
  }
}


Measured memory_bytes: 256
import math
def main():
  n = int(input())
  flg=0
  for i in range(0,int(n/7)+1):
    j=0
    while 4*j + 7*i <= n:
      if 4*j + 7*i ==n:
        flg=1
      j+=1
  if flg==1:
    print('Yes')
  else:
    print('No')
main()


Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
typedef pair<P,int> Pi;

const int MAX_N = 400;

map<ll, int> mp;
vi col[MAX_N];
ll num[MAX_N];

ll trans(vi& vec)
{
    ll r = (1LL << 60);
    rep(i,4){
        cmn(r, (vec[(i+3)%4]*1000000000LL+vec[(i+2)%4]*1000000LL+vec[(i+1)%4]*1000LL+vec[i]));
    }
    return r;
}

int cmp(ll arg)
{
    vector<int> vec(4);
    rep(i,4){
        vec[i] = arg%1000LL;
        arg /= 1000LL;
    }
    if(vec[0] == vec[2] && vec[1] == vec[3]){
        if(vec[0] == vec[1]){
            return 4;
        }else{
            return 2;
        }
    }else{
        return 1;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        col[i] = {a,b,c,d};
        num[i] = trans(col[i]);
        mp[num[i]]++;
    }
    ll ans = 0;
    rep(i,n){
        mp[num[i]]--;
        srep(j,i+1,n){
            mp[num[j]]--;
            rep(k,4){
                map<ll,int> mp2;
                rep(l,4){
                    vi hoge = {col[i][(l+1)%4],col[i][l],col[j][(k+5-l)%4],col[j][(k+4-l)%4]};
                    mp2[trans(hoge)]++;
                }
                ll res = 1;
                each(val,mp2){
                    int cnt = cmp(val.fi);
                    int kp = mp[val.fi];
                    rep(l,val.se){
                        res *= cnt*(kp-l);
                    }
                    if(!res) break;
                }
                ans += res;
            }
            mp[num[j]]++;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 20352
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

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

    int R;
    cin >> R;

    cout << 2 * R * M_PI << endl;

    return 0;
}



Measured memory_bytes: 3260
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=4e5+7;
const int mod=9901;
using namespace std;
int p[MX],k[MX];
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
/*/ /*/
map<string,int>mp;
int a[MX];
ll __C(ll n,ll m)
{
    if(n<m)return 0;
    if(m==1)return 9*n;
    else {
        return 9*9*n*(n-1)/2;
    }
}
int __get(int n,int m,int k)
{
    if(k==0)return m;
    return m*__C(n,k);
}
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  string s;
  int k;
  cin>>s>>k;
  int g=k;
  ll sum=0,res=0;
  int n=s.length();
  for(int i=0;i<n-1;i++)sum+=__get(i,9,k-1);
  for(int i=0;i<n;i++)
  {
     if(k)
    {
       if(s[i]-'0'>0)sum+=__get(n-i-1,s[i]-'0'-1,k-1);
          if(i>0&&s[i]-'0'>0)sum+=__get(n-i-1,1,k);
            if(s[i]-'0'>0)k--;
    }
    else break;
  }
  int ant=0;
  for(int i=0;i<n;i++)if(s[i]-'0'>0)ant++;
  if(ant>=g)sum++;
  cout<<sum<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
MOD = 10**9 + 7
ans = 0

for i in range(K, N + 2):
    p = 0 + i - 1
    q = N - i + 1
    P = p * (p + 1) // 2
    Q = P + (i * q)
    ans += Q - P + 1
    ans %= MOD
print(ans)




Measured memory_bytes: 63820
#include <stdio.h>

int main (void)
{
	int a , b , c;
	int max , min , total;
	scanf("%d %d %d" , &a , &b ,&c);
	if(a > b && a > c)
	{
		max = a;
	}
	else if(b > a && b > c)
	{
		max = b;
	}
	else if(c > a && c > b)
	{
		max = c;
	}
	if(a < b && a < c)
	{
		min = a;
	}
	else if(b < a && b < c)
	{
		min = b;
	}
	else if(c < a && c < b)
	{
		min = c;
	}
	total = a + b + c;
	printf("%d %d %d\n" , min , total - max - min , max);

	return 0;
}


Measured memory_bytes: 2144
N, C, K = map(int,input().split())
T = []
ans = 0 #バス内の人数
num = 1 #バスの台数
for i in range(N):
    ans = int(input())
    T.append(ans)
T = sorted(T)
ans = 0
S =  T[0] + K #バスの発車時刻
for i in T:
    if i <= S and ans < C:
        ans += 1
    else:
        num += 1
        S = i + K
        ans = 1
print(num)


Measured memory_bytes: 13960
#include <vector>
#include <set>
#include <algorithm>
#include <cstdio>
#define SENTINEL 99999999
using namespace std;
typedef pair<int,int> pii;
class union_find{
	vector<pii>parent;
	pii root(int a){
		if(parent[a].first==a)return parent[a];
		pii ret=root(parent[a].first);
		return parent[a]=make_pair(ret.first,ret.second+parent[a].second);
	}
public:
	union_find(int n): parent(n){for(int i=0;i<n;i++)parent[i]=make_pair(i,0);}
	int dist(int a,int b){
		pii x=root(a),y=root(b);
		if(x.first!=y.first)return SENTINEL;
		return x.second-y.second;
	}
	int unite(int a,int b,int w){
		pii x=root(a),y=root(b);
		if(x.first==y.first)return 0;
		parent[x.first]=make_pair(y.first,y.second-x.second+w);
		return 1;
	}
};
int main(){
	char s[2];
	int N,Q,a,b,w;
	for(;scanf("%d%d",&N,&Q),N;)for(union_find uf(N);Q--;){
		scanf("%s",s);if(*s=='!'){
			scanf("%d%d%d",&a,&b,&w),a--,b--;
			uf.unite(a,b,w);
		}else{
			scanf("%d%d",&a,&b),a--,b--;
			w=uf.dist(a,b);
			printf(w==SENTINEL?"UNKNOWN\n":"%d\n",w);
		}
	}
}

Measured memory_bytes: 2736
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long[] hi;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var KAB = Sarray();
            var K = KAB[0];
            var A = KAB[1];
            var B = KAB[2];
            //交換するより増やす方が良い
            if (B <= A + 2)
            {
                WriteLine(1 + K);
                return;
            }
            //A 枚まで増やせない
            if(K <= (A - 1))
            {
                WriteLine(K + 1);
                return;
            }
            var zan = K - (A - 1);
            //交換する。1円→B枚のセット
            if (zan == 1)//そのまま増やす
            {
                WriteLine(K + 1);
                return;
            }
            if (zan == 2)//A→1→B
            {
                WriteLine(B);
                return;
            }
            var ans = B + (zan - 2) / 2 * (B - A) + (zan - 2) % 2;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

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

int main(void){
    // Your code here!
    int A,B,C;cin>>A>>B>>C;
    int top=max(A,max(B,C));
    int bottom=min(A,min(B,C));
    int middle=A+B+C-top-bottom;
    int ans=top-middle;
    bottom+=top-middle;
    if((top-bottom)%2==0){
        ans+=(top-bottom)/2;
    }
    else{
        ans++;
        ans+=(top-bottom+1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <cassert>
#include <cstdio>
#include <deque>
#include <utility> //pair
using namespace std;

int main() {
  int N, L;
  scanf("%d %d", &N, &L);
  struct item {
    int val, idx;
  };
  deque<item> q;

  for (int i = 0, next; i < N; ++i) {
    scanf("%d", &next);
    while (!q.empty() && q.back().val > next)
      q.pop_back();
    q.emplace_back(item{next, i});
    if (q.front().idx <= i - L)
      q.pop_front();
    assert(q.front().idx > i - L);
    if (i >= L)
      printf(" ");
    if (i >= L - 1)
      printf("%d", q.front());
  }
  printf("\n");
}



Measured memory_bytes: 2884
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)
using namespace std;

class train{
	public:
		int v;
		double vRatio;
		double distance;
		int currentSta;

		train(int v = 0, double vRatio = 0.0, double distance = 0.0, int currentSta = 0):v(v), vRatio(vRatio), distance(distance), currentSta(currentSta){}
		
		void wantVRatio(int other){
			vRatio = (double)v / ((double)v + (double)other);
		}

		void wantDistance(int railsum){
			distance = (double)railsum * vRatio;
		}
	private:

	protected:

};


int main(){
	while(1){
		map<int, int> rail;
		int railsum = 0;
		train up, down(0,0.0,0.0,10);

		if(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &rail[0], &rail[1], &rail[2], &rail[3], &rail[4], &rail[5], &rail[6], &rail[7], &rail[8], &rail[9], &up.v, &down.v) == EOF){
			break;
		}

		PREP(i, 0, 10){
			railsum += rail[i];
		}

		up.wantVRatio(down.v);
		up.wantDistance(railsum);

		PREP(i, 0, 10){
			if(up.distance <= rail[i]) {
				up.currentSta = i;
				break;
			}
			up.distance -= rail[i];
		}

		//この2の内訳は、インデックスが0~9までに対して問題の区間番号が1~10定義になっているので+1と
		//仮に各電車の区間番号が5,7だった場合、すれ違うのは6なので5+1のための+1
		cout << up.currentSta + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        long[,]a=new long[n,n];
        for(int i=0;i<n;i++){
            int j=0;
            foreach(long x in Console.ReadLine().Split().Select(long.Parse)) {
                a[i,j++]=x;
            }
        }
        int N=1<<n;
        long[]b=new long[N];
        for(int bs=0;bs<N;bs++){
            for(int i=0;i<n;i++)if((bs>>i&1)==1){
                for(int j=i+1;j<n;j++)if((bs>>j&1)==1){
                    b[bs]+=a[i,j];
                }
            }
        }
        long[]dp=new long[N];
        for(int bs=1;bs<N;bs++){
            int max=0;
            for(int i=0;i<n;i++){
                if((bs>>i&1)==1)max=i;
            }
            dp[bs]=b[bs];
            for(int cs=bs;cs>0;cs--,cs&=bs){
                Chmax(ref dp[bs],dp[cs]+b[bs&~cs]);
            }
        }
        Console.WriteLine(dp[N-1]);
    }
    public static void Chmax(ref long x, long y){
        x=Math.Max(x,y);
    }
}


Measured memory_bytes: 13372
#include <stdio.h>

int main(void) {
	_Bool surface[8][8];
	int i, j;
	int a;
	while (1) {
		i = j = 0;
		while (1) {
			a = getchar();
			if( a == '\n') {
				i++;
				j = 0;
			}
			else {
				if( a == '0')
					surface[i][j] = 0;
				if( a == '1')
					surface[i][j] = 1;
				j++;
			}
			if( i == 8)
				break;
		}
		for (i = 0; i < 8; i++) {
			for (j = 0; j < 8; j++) {
				if( i + 1 < 8 && j + 1 < 8 && surface[i][j] && surface[i][j+1] && surface[i+1][j] && surface[i+1][j+1])
					printf("A\n");
				if( i + 3 < 8 && surface[i][j] && surface[i+1][j] && surface[i+2][j] && surface[i+3][j])
					printf("B\n");
				if( j + 3 < 8 && surface[i][j] && surface[i][j+1] && surface[i][j+2] && surface[i][j+3])
					printf("C\n");
				if( i + 2 < 8 && j + 1 < 8 && surface[i][j+1] && surface[i+1][j] && surface[i+1][j+1] && surface[i+2][j])
					printf("D\n");
				if( i + 1 < 8 && j + 2 < 8 && surface[i][j] && surface[i][j+1] && surface[i+1][j+1] && surface[i+1][j+2])
					printf("E\n");
				if( i + 2 < 8 && j + 1 < 8 && surface[i][j] && surface[i+1][j] && surface[i+1][j+1] && surface[i+2][j+1])
					printf("F\n");
				if( i + 1 < 8 && j + 2 < 8 && surface[i][j+1] && surface[i][j+2] && surface[i+1][j] && surface[i+1][j+1])
					printf("G\n");
			}
		}
		if( (a = getchar()) == EOF)
			break;
	}
	return 0;
}

Measured memory_bytes: 524