akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int a[200010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int m=read();
    int n=read(),mx=0;
    for(int i=1;i<=n;i++)
	{
		a[i]=read();
		if(i>1)mx=max(mx,a[i]-a[i-1]);
	}
    int ans=a[n]-a[1];
    pr2(min(ans,m-mx));
    return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
int main(){
  int n,i,ac=0,tle=0,wa=0,re=0;
  scanf("%d",&n);
  char s[n+1][4];
  for(i=0;i<n;i++){
    scanf("%*c%s",s[i]);
    if(s[i][0]=='A')
      ac++;
    else if(s[i][0]=='W')
      wa++;
    else if(s[i][0]=='T')
      tle++;
    else
      re++;
  }
  printf("AC x %d\n",ac);
  printf("WA x %d\n",wa);
  printf("TLE x %d\n",tle);
  printf("RE x %d\n",re);
  return 0;
}

Measured memory_bytes: 2120
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	int N;
	cin >> N;
	map<int, int> cnt;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		cnt[A]++;
	}
	int one = 0, two = 0;
	for (auto itr : cnt) {
		if (itr.second % 2 == 1) one++;
		else if (itr.second % 2 == 0) two++;
	}
	if (two % 2 == 0) cout << one + two << endl;
	else cout << one + two - 1 << endl;
}


Measured memory_bytes: 4992
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


if local:
    start=time.time()

N,M = ints()

connection = [dict() for i in range(N)]

for i in range(1, M+1):
    x,y,z = ints()

    connection[x-1][y-1] = True
    connection[y-1][x-1] = True

ans = 0
visited = set()

for i in range(N):
    if i in visited:
        continue

    ans+=1
    stck = [i]
    visited.add(i)

    while len(stck)>0:
        vertex = stck.pop(-1)

        for nextVertex in connection[vertex]:
            if nextVertex not in visited:
                visited.add(nextVertex)
                stck.append(nextVertex)

print(ans)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")


Measured memory_bytes: 98592
fn main() {
    proconio::input! {
        x: i64,
    }
    for a in -500..500 {
        for b in -500..500 {
            let a5 = a * a * a * a * a;
            let b5 = b * b * b * b * b;
            if a5 - b5 == x {
                println!("{} {}", a, b);
                return;
            }
        }
    }
}


Measured memory_bytes: 2092
K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    a = A[i]
    if nowm <= ((nowm+a-1)//a)*a and ((nowm+a-1)//a)*a <= nowM:
        nowm = ((nowm+a-1)//a)*a
        nowM = (nowM//a)*a + a - 1
    else:
        ans = -1
        break
    # if nowM < A[i]:
    #     ans = -1
    #     break
    # elif nowm <= A[i]:
    #     nowm = A[i]
    #     nowM = A[i]*2 - 1
    # else:
    #     M = nowM
    #     nowm = (nowm//A[i]+1)*A[i]
    #     if nowm > M:
    #         ans = -1
    #         break
    #     if (nowM//A[i]+1)*A[i] <= M:
    #         nowM = (nowM//A[i]+1)*A[i] - 1
    #         if nowM < nowm:
    #             nowM = nowm + A[i] - 1
    #     else:
    #         nowM = nowm + A[i] - 1
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))

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

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=a;i<=min(b,a+k-1);i++) cout<<i<<endl;
    for(int i=max(b-k+1,a+k);i<=b;i++) cout<<i<<endl;
}

Measured memory_bytes: 3596
#include<iostream>

using namespace std;

#define ll long long

int main() {
    ll N, M;
    cin >> N >> M;
    ll ans = 1;
    if(N==M) {
        for(int i=1; i<N+1; i++) {
            ans *= i;
            ans = ans%1000000007;
        }
        for(int i=1; i<M+1; i++) {
            ans *= i;
            ans = ans%1000000007;
        }
        ans *= 2;
    } else if((N+1==M)|(M+1==N)) {
        for(int i=1; i<N+1; i++) {
            ans *= i;
            ans = ans%1000000007;
        }
        for(int i=1; i<M+1; i++) {
            ans *= i;
            ans = ans%1000000007;
        }
    } else {
        ans = 0;
    }
    cout << ans%1000000007 << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<complex<double>> in(n);
  for (int i = 0; i < n; i++) {
    double x, y;
    cin >> x >> y;
    in[i].real(x);
    in[i].imag(y);
  }
  sort(in.begin(), in.end(), [] (complex<double> a, complex<double> b) {return arg(a) < arg(b);});
  double ans = 0;
  for (int i = 0; i < n; i++) {
    for (int len = 1; len <= n; len++) {
      double x = 0, y = 0;
      for (int j = 0; j < len; j++) {
        x += in[(i + j) % n].real();
        y += in[(i + j) % n].imag();
      }
      ans = max(ans, x * x + y * y);
    }
  }
  cout << setprecision(20) << fixed << sqrt(ans) << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  REP(i, n) cin >> s[i] >> t[i];
  string x; cin >> x;
  int idx = find(ALL(s), x) - s.begin();
  cout << accumulate(t.begin() + idx + 1, t.end(), 0) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int x,m,n,o,p,sum1,sum2;
    cin>>x;
    if(x==0)
        cout<<"0"<<endl;
    else
    {
    if(x>=500)
    {
        m=x%500;
        o=x/500;
        sum1=o*1000;
    }
    else if(x>=5)
    {
        m=x%5;
        o=x/5;
        sum1=o*5;
    }
    else if(x<5)
    {
        m=0;
        o=0;
        sum1=o*0;
    }
    if(m>=5)
    {
        n=m%5;
        p=m/5;
        sum2=p*5;
    }
    else
    {
        n=0;
        p=0;
        sum2=p*5;
    }
    cout<<sum1+sum2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>

int abfind(char *s, int len)
{
    int count = 0;
    for(int i=0; i<len-1; i++){
        if(s[i] =='A' && s[i+1] == 'B')
            count++;
    }
    return count;
}

int min(int a, int b)
{
    return a < b ? a: b;
}

int main()
{
    int N;
    scanf("%d", &N);
    char S[N][11];
    int a = 0; //末尾A
    int b = 0; //先頭B
    int c = 0; //両方
    int count = 0; //ABの数
    for(int i=0; i<N; i++){
        scanf(" %s", S[i]);
    }

    for(int i=0; i<N; i++){
        char *s = S[i];
        if(s[0] == 'B') b++;
        int len = 0;
        while(s[len] != '\0'){
            len++;
        }
        if(s[len-1] == 'A'){
            a++;
            if(s[0] == 'B') c++;
        }
        count += abfind(s, len);
    }

    if(c == 0){
        count += min(a, b);
        printf("%d\n", count);
        return 0;
    }
    a -= c;
    b -= c;

    count += c-1;
    if(a != 0){
        count++;
        a--;
    }
    if(b != 0){
        count++;
        b--;
    }

    //printf("%d %d %d %d\n", count, a, b, c);
    count += min(a, b);
    printf("%d\n", count);
}


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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, n;
  cin >> h >> n;
  int sum = 0;
  while (n--) {
    int a;
    cin >> a;
    sum += a;
  }
  if (sum >= h) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 3660
#!/usr/bin/env python3
import sys
import decimal
import math
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(a: int, b: int, c: int):
    decimal.getcontext().prec = 22
    if((c-a-b)**2>4*(a*b) and c>a+b):print(YES)
    else:print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)

if __name__ == '__main__':
    main()


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

int main(){
  int N,X,sum;
  cin >> N;
  
  
  for(int i = 0; i < N; i++){
    int A, B;
    cin >> A >> B;
    
    X = B - A + 1;
    sum += X;
  }
  
  cout << sum << endl;
}

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

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

#define FOR(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define REP(i,n) FOR(i,0,n)

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

using ll = long long;

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


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
int a[maxn], b[maxn], n, k;
ll dp[maxn], pa[maxn];
int l[maxn], r[maxn];
std::map<int,int> map;
typedef std::map<int, int>::iterator iter;
inline iter split(int r) { iter x = map.lower_bound(r); return x -> first == r ? x : map.emplace_hint(x, r, std::prev(x) -> second); }
inline void set(int l,int r,int c) { if(l <= r) { iter R = split(r + 1), L = split(l); map.erase(L, R), map[l] = c; } }
inline ll get(int x) { int c = split(x) -> second; return c ? dp[c] + (x + k - r[c]) % k : 0; }
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k, map[0] = map[k] = 0;
	rep(i, 1, n) {
		cin >> a[i] >> b[i];
		pa[i] = pa[i - 1] + a[i];
		if(b[i] == 1) {
			if(a[i] + a[i] > k) return cout << -1 << '\n', 0;
			l[i] = (ll) pa[i - 1] % k * (k - 2) % k, r[i] = (ll) pa[i - 0] % k * ll(k - 2) % k;
			dp[i] = get(r[i]);
			if(l[i] <= r[i]) set(r[i] + 1, k - 1, i), set(0, l[i] - 1, i);
			else set(r[i] + 1, l[i] - 1, i);
		}
	}
	ll ans = 1e18;
	rep(i, 1, n) ans = std::min(ans, get(l[i]));
	cout << ans + pa[n] + pa[n] << '\n';
}


Measured memory_bytes: 14976
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char

--import qualified Data.Heap as H  -- atcoder judge does not have this.
import Data.List

import qualified Data.Set as S

solver3 :: [(Int, Int)] -> String
solver3 ls =
  let ordered = reverse $ sortOn snd ls
   in let latest_dead = snd $ head ordered
       in eater latest_dead ordered
  where
    eater t [] =
      if t < 0
        then "No"
        else "Yes"
    eater t ((len, dead):rest) = (eater $! (t - len)) rest

solver4 :: [(Int, Int)] -> String
solver4 ls =
  let idxed = [(dl, len, i) | ((len, dl), i) <- zip ls [1 ..]]
   in let set = S.fromList idxed
       in let (dl, _, _) = S.findMax set
           in eater dl set
  where
    eater t s =
      if s == S.empty
        then if t < 0
               then "No"
               else "Yes"
        else let Just ((_, len, _), rest) = S.maxView s
              in eater (t - len) rest

solver5 :: [(Int, Int)] -> String
solver5 ls =
  let ordered = reverse $ sortOn snd ls
   in let latest_dead = snd $ head ordered
       in eater latest_dead ordered
  where
    eater t [] = "Yes"
    eater t ((len, dead):rest) =
      if t - len < 0
        then "No"
        else (eater $! (t - len)) rest

solver6 :: [(Int, Int)] -> String
solver6 ls =
  let ordered = sortOn snd ls
   in eater 0 ordered
  where
    eater t [] = "Yes"
    eater t ((len, dead):rest) =
      if (t + len > dead)
        then "No"
        else eater (t + len) rest

main :: IO ()
main = do
  n <- read <$> getLine
  dat <-
    replicateM
      n
      ((\(a:b:_) -> (a, b)) . unfoldr (BS.readInt . BS.dropWhile isSpace) <$>
       BS.getLine)
  --dat <-
  --  replicateM n (\(a:b:_) -> (a, b)) . map (read . BS.unpack) . BS.words <$> BS.getLine
  mv <- newEmptyMVar
  --forkIO $ worker6 (reverse dat) mv
  forkIO $ worker6 dat mv
  --forkIO $ worker5 (reverse dat) mv
  --forkIO $ worker5 dat mv
  ans <- takeMVar mv
  putStrLn ans
  --putStrLn $ solver6 dat

worker6 :: [(Int, Int)] -> MVar String -> IO ()
worker6 dat mv =
  let ans = (solver6 dat)
   in seq ans (putMVar mv ans)

worker5 :: [(Int, Int)] -> MVar String -> IO ()
worker5 dat mv =
  let ans = (solver5 dat)
   in seq ans (putMVar mv ans)

Measured memory_bytes: 77180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
pair<pair<string, int>, int> p[110];
int n;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		pair<string, int> pt;
		cin >>pt.first>>pt.second;
		pt.second=-pt.second;
		p[i]=MP(pt,i);
	}
	sort(p,p+n);
	for (int i=0;i<n;i++) cout <<p[i].second+1<<"\n";
	return 0;
}

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

#define PI acos(-1.0)
#define INF 2e9
#define INFLL 9e18
#define EPS 1e-9
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int a[1000000],b[1000000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(2);
    cout << fixed;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);


    int t,a,b,c,n,m,i,j,k,mx,mn,res=0,cnt=0;
    cin >> n;
    if(n>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3580
def main():
    s = input()
    target = 0
    cost0 = 0
    cost1 = 0
    
    for c in s:
        if int(c) != target:
            cost0 += 1
        else:
            pass
        target = 0 if target == 1 else 1
    target = 1
    for c in s:
        if int(c) != target:
            cost1 += 1
        else:
            pass
        target = 0 if target == 1 else 1
    print(min(cost0, cost1))
if __name__ == "__main__":
    main()

Measured memory_bytes: 42588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public char[] S;
        public int K;
        public long MOD = 1000000007;

        public void Run()
        {
            S = Console.ReadLine().ToCharArray();
            K = Input.ReadInt();

            for (int i = 0; i < S.Length; i++)
            {
                char c = S[i];
                if (c == 'a') continue;
                if (K <= 'z' - c) continue;
                S[i] = 'a';
                K -= ('z' - c + 1);
            }

            K %= 26;
            for (int j = 0; j < K; j++)
            {
                if (S[S.Length - 1] == 'z')
                    S[S.Length - 1] = 'a';
                else
                {
                    S[S.Length - 1]++;
                }
            }

            Console.WriteLine(string.Join("", S));
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  for(int i=1;i<=5;i++){
    int x;
    cin >> x;
    if(x == 0)
      cout << i << endl;
  }

  return 0;
}

Measured memory_bytes: 3596
from collections import deque
h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
path = [[10**10]*w for i in range(h)]
maze = []
for _ in range(h):
  s = input()
  maze.append(s)

walk = [(0,1),(1,0),(-1,0),(0,-1)]
warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)]+walk]
Q = deque()
path[ch-1][cw-1]=0
Q.append((ch-1,cw-1,0))
while Q:
  hi,wi,c = Q.popleft()
  for i,j in walk:
    nh = i + hi
    nw = j + wi
    if 0<=nh<h and 0<=nw<w and maze[nh][nw]=='.' and path[nh][nw]>c:
      path[nh][nw] = c
      Q.appendleft((nh,nw,c))
  for i,j in warp:
    nh = i + hi
    nw = j + wi
    if 0<=nh<h and 0<=nw<w and maze[nh][nw]=='.' and path[nh][nw]>c+1:
      path[nh][nw] = c+1
      Q.append((nh,nw,c+1))
print(path[dh-1][dw-1] if path[dh-1][dw-1]<10**10 else -1)

Measured memory_bytes: 94372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin >> n;
	ll a[n + 1];
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	ll mx = a[1], tot = 0;
	for(int i = 2;i <= n;i++)
	{
		if(a[i] < mx)
			tot += mx - a[i];
		mx = max(mx, a[i]);
	}
	cout << tot;
	return 0;
}

Measured memory_bytes: 5176
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 = a*b;
		// if文
		if( c % 2 == 0 ) 
          System.out.println("Even");
        else
          System.out.println("Odd");
	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 100005
#define INF 100000000000000000LL

using namespace std;
typedef long long int ll;
typedef pair <ll,int> P;

struct T
{
	ll sum;
	int sz;
	T *l,*r;
	P left,right;
	P p;
	T(ll sum=0,int sz=0,P p=P(0,0)):sum(sum),sz(sz),p(p),left(p),right(p){}
	void pass()
	{
		if(l!=NULL)
		{
			l->sum+=sum;
			l->p.first+=sum;
			l->left.first+=sum;
			l->right.first+=sum;
		}
		if(r!=NULL)
		{
			r->sum+=sum;
			r->p.first+=sum;
			r->left.first+=sum;
			r->right.first+=sum;
		}
		sum=0;
	}
	void update()
	{
		sz=1;
		sum=0;
		left=right=p;
		if(l!=NULL) sz+=l->sz;
		if(r!=NULL) sz+=r->sz;
		if(l!=NULL) left=l->left;
		if(r!=NULL) right=r->right;
	}
	void see()
	{
		printf("%lld %d : %lld %d\n",left.first,left.second,right.first,right.second);
		printf("%d\n",sz);
	}
};
typedef pair <T*,T*> PT;
T* merge(T *l,T *r)
{
	if(l==NULL) return r;
	if(r==NULL) return l;
	int t=rand()%(l->sz+r->sz);
	if(t<l->sz)
	{
		l->pass();
		l->r=merge(l->r,r);
		l->update();
		return l;
	}
	else
	{
		r->pass();
		r->l=merge(l,r->l);
		r->update();
		return r;
	}
}
PT split(T *v,P p)//leftがp未満と以上で切り分ける
{
	if(v==NULL) return PT(NULL,NULL);
	if(v->left>=p) return PT(NULL,v);
	if(v->right<p) return PT(v,NULL);
	if(v->p>=p)
	{
		v->pass();
		PT q=split(v->l,p);
		v->l=q.second;
		v->update();
		return PT(q.first,v);
	}
	else
	{
		v->pass();
		PT q=split(v->r,p);
		v->r=q.first;
		v->update();
		return PT(v,q.second);
	}
}
T* ins(T *v,P p)
{
	PT q=split(v,p);
	T *t=new T(0,1,p);
	return merge(q.first,merge(t,q.second));
}
T* add(T *v,P p,ll vl)//p以上のところにv足す
{
	PT q=split(v,p);
	if(q.second)
	{
		q.second->sum+=vl;
		q.second->p.first+=vl;
		q.second->left.first+=vl;
		q.second->right.first+=vl;
	}
	return merge(q.first,q.second);
}
P get(T *v,int k)//k番目取得
{
	T *at=v;
	while(1)
	{
		at->pass();
		//printf("%lld %d : %lld %d\n",at->left.first,at->left.second,at->right.first,at->right.second);
		if(at->sz==k+1) return at->right;
		if(k==0) return at->left;
		int left=at->l==NULL?0:at->l->sz;
		if(left<=k)
		{
			k-=left+1;
			if(k==-1) return at->p;
			at=at->r;
		}
		else at=at->l;
	}
	return P(-1,-1);
}
T *root;
void add_point(P p){root=ins(root,p);}
void add_value(P p,ll vl){root=add(root,p,vl);}
P get_kth(int k){return get(root,k);}

int L[SIZE],R[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&L[i],&R[i]);
		if(i>0)
		{
			P p2=get_kth(i);
			//printf("%lld %d\n",p2.first,p2.second);
			add_value(p2,R[i]-L[i]);
			add_value(P(-INF,-1),-R[i]+L[i]);
			sum-=(ll) (R[i]-L[i])*(ll) i;
		}
		add_point(P(L[i],i*2));
		add_point(P(L[i],i*2+1));
		P p=get_kth(i+1);
		add_value(p,R[i]-L[i]);
		sum+=L[i];
		//printf("* %lld %d\n",p.first,p.second);
		//for(int j=0;j<2*i+2;j++) printf("%lld ",get_kth(j).first);puts("");
	}
	vector <P> vx;
	for(int i=0;i<2*n;i++) vx.push_back(get_kth(i));
	//for(int i=0;i<2*n;i++) printf("%lld\n",vx[i].first);
	//左端は-Nx+sum
	for(int i=0;i<n;i++) sum-=vx[i].first;
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 25972
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
int main() {
	int n;
	while (cin >> n, n) {
		vector<int> v[30];
		rep(i, n) {
			int f; cin >> f;
			rep(j, f) {
				int d; cin >> d; d--; v[d].push_back(i);
			}
		}
		int con[30][30];
		rep(i, 30) {
			rep(j, 30) {
				con[i][j] = 0;
			}
		}
		rep(i, 30) {
			Rep(j, i + 1, 30) {
				int len1 = v[i].size();
				int len2 = v[j].size();
				bool f = false;
				rep(k, len1) {
					rep(l, len2) {
						if (v[i][k] == v[j][l]) {
							f = true;
						}
					}
				}
				if (f) {
					con[i][j] = 1;
				}
			}
		}
		int canuse[30][30];
		rep(i, 30) {
			rep(j, 30) {
				canuse[i][j] = 0;
			}
		}
		rep(i, 30) {
			vector<int> u; u.push_back(i);
			per(j, i) {
				bool f = false;
				rep(k, (int)u.size()) {
					if (con[j][u[k]])f = true;
				}
				if (f) {
					canuse[j][i] = 1;
					u.push_back(j);
				}
			}
		}
		set<int> a[30];
		int chk = 1;
		rep(i, 30) {
			int len = v[i].size();
			rep(j, len) {
				a[i].insert(v[i][j]);
			}
			per(j, i) {
				if (canuse[j][i] == 0)continue;
				len = v[j].size();
				rep(k, len) {
					a[i].insert(v[j][k]);
				}
			}
			if (a[i].size() == n)break;
			chk++;
		}
		if (chk > 30) {
			cout << -1 << endl;
		}
		else {
			cout << chk << endl;
		}
	}
	return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;j<=(n);++i)
#define all(x) (x).begin(),(x).end()
//#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
signed main(){
    int a,b;
    cin >> a >> b;
    if(a % b == 0) cout << -1 << '\n';
    else cout << a << '\n';
    return 0;
}


Measured memory_bytes: 256
n,k,q = map(int,input().split())
start = [k for i in range(n)]
a = [0 for i in range(n)]
for i in range(q):
    a[int(input())-1] += 1


for i in range(n):
    t = start[i] - (q - a[i])
    if t <= 0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 85824
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9+7;

int main()
{   
    fastio
    int n;
    string str;
    cin>>n;
    cin>>str;
    int l =str.length();
    int countr = 0, countw = 0, swaps = 0;
    for (int i = 0; i < l; i++)
    {
        if(str[i]=='R')
            countr++;
        else 
            countw++;        
    }
    for (int i = 0; i < countr; i++)
    {
        if(str[i]=='W')swaps++;
    }
    cout<<min(min(countr, countw), swaps);
}

Measured memory_bytes: 3788
#!/usr/bin/env python3
from fractions import gcd
A, B, C, D = list(map(int, input().split()))

def nev(u, C, D):
  l = C*D//gcd(C, D)
  ret = (l-(l//C+l//D)+1)*(u//l)
  m = u % l
  ret += m-(m//C+m//D)
  return ret

a = nev(B, C, D)
a -= nev(A-1, C, D) if A>1 else 0
print(a)

Measured memory_bytes: 5564
using System;
using System.Collections.Generic;

class Program
{
    public static void Main (string[] args)
    {
        String _str;
        String[] str;
        while ((_str = Console.ReadLine()) != null
            && (str = _str.Split(' ')).Length == 2) {
            int digit = 1,
                left = int.Parse (str [0]),
                right = int.Parse (str [1]);
            for (uint tmp = (uint)(left + right); tmp / 10 > 0; tmp /= 10)
                ++digit;
            System.Console.WriteLine (digit);
         }
    }
}

Measured memory_bytes: 5640
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

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

  int32_t K;
  cin >> K;
  //vector<vector<vector<int64_t>>> runrun(10, vector<vector<int64_t>(vector<));
  vector<vector<int64_t>> runrun(10);
  int32_t cnt = 9;
  for (int i = 1; i <=9; i++) runrun[0].push_back(i);
  if (K <= 9) {
    cout << runrun[0][K-1] << endl;
    return 0;
  }

  for (int dig = 1; dig < 10; dig++) {
    for(auto prev : runrun[dig-1]) {
      int64_t lsd = prev % 10;
      if (lsd != 0) {
        runrun[dig].push_back(prev*10 + lsd - 1);
        cnt++;
        if (cnt == K) {
          cout << prev*10 + lsd - 1 << endl;
          return 0;
        }
      }
      runrun[dig].push_back(prev*10 + lsd);
      cnt++;
      if (cnt == K) {
        cout << prev*10 + lsd << endl;
        return 0;
      }
      if (lsd != 9) {
        runrun[dig].push_back(prev*10 + lsd + 1);
        cnt++;
        if (cnt == K) {
          cout << prev*10 + lsd + 1 << endl;
          return 0;
        }
      }
    }
  }
  cout << 3234566667 << endl;


  return 0;
}


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

int N;

void solve() {
    string s;
    bool plus = true;
    cin >> N;
    if (N == 0) {
        cout << 0 << endl;
        return;
    }
    while (N != 0) {
        int d;
        if (N % 2 != 0) {
            s.push_back('1');
            d = 1;
        } else {
            s.push_back('0');
            d = 0;
        }
        if (plus) {
            N -= d;
            N /= 2;
        } else {
            N += d;
            N /= 2;
        }
        plus = !plus;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}


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

int main()
{
    int a, b;
    while (1)
    {
        cin >> a >> b;
        if (a == 0 && b == 0)
            break;
        for (int j = 0; j < a; j++)
        {
            for (int i = 0; i < b; i++)
            {
                if(i == 0 || j == 0)cout << '#';
                else if(j == a-1 ||i == b-1)cout<< '#';
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin>>A.at(i);
    for (int i = 0; i < N;i++){
        int num = A.at(i);
        if(num%2==1)
            continue;
        if(num%3!=0&&num%5!=0){
            puts("DENIED");
            return 0;
        }
    }
    puts("APPROVED");
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

#define MOD 1000000007


int main(){
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    ll res = 1;
    bool pre;
    rep(i, n){
        if(s1[i] == s2[i]){
            if(i == 0)res*=3;
            else if(pre)res=(res*2)%MOD;
            pre = true;
        }
        else{
            if(i == 0)res*=6;
            else if(pre)res=(res*2)%MOD;
            else res=(res*3)%MOD;
            pre = false;
            i++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
import sys, cmath, math
t = complex(0)
a = math.pi/2
for line in sys.stdin:
    l = list(map(int, line.split(",")))
    if l == [0, 0]:
        break
    t += cmath.rect(l[0], a)
    a -= l[1]*math.pi/180
print(int(t.real))
print(int(t.imag))


Measured memory_bytes: 5776
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = m; i < (int)n; i++)
#define reps(i, n) for(int i = 1; i <= (int)n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n;
	cin >> n;
	ll a[100];
	a[0]=2;
	a[1]=1;
	repp(i, 2, 87) a[i]=a[i-1]+a[i-2];
	cout << a[n] << endl; 
	return 0;
}

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

const int N = 2000 * 2000 + 1;
bitset<N> mask;

int main() {
	int sum = 0;
	int n;
	scanf("%d", &n);
	mask.set(0);
	for (int i = 0, x; i < n; i++) {
		scanf("%d", &x);
		mask = (mask << x) | mask;
		sum += x;
	}
        sum++;
	sum /= 2;
	while (!mask.test(sum)) sum++;
	printf("%d\n", sum);
}

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

int main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=1250;i++){
      	int a_i,b_i;
      	a_i=i*0.08;
      	b_i=i*0.10;
		if(a==a_i && b==b_i){
      	cout<<i<<endl;
        return 0;
      }
    }
  	cout<<-1<<endl;
  	return 0;
}

Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int n = nxt(), m = nxt(), x = nxt();
    VI weight(n);
    int grid[n][m];
    for (int i = 0; i < n; i+=1){
        weight[i] = nxt();
        for (int j = 0; j < m; j+=1){
            grid[i][j] = nxt();
        }
    }
    int cost = INF;
    for (int t = 0; t < 1<<n; t+=1){
        VI knowledge(m);
        int temp = 0;
        for (int j = 0; j < n; j+=1){
            if(t & (1 << j)){
                for (int k = 0; k < m; k+=1){
                    knowledge[k] += grid[j][k];
                }
                temp += weight[j];
            }
        }
        bool done = true;
        for (int j = 0; j < m; j+=1){
            if(knowledge[j] < x) done = false;
        }
        if(done) cost = min(cost, temp);
    }
    if(cost == INF) printf("-1\n");
    else printf("%d\n", cost);
    return 0;
}



Measured memory_bytes: 3772
import sys
input = sys.stdin.readline
from fractions import gcd


def read():
    N, M = map(int, input().strip().split())
    A = []
    B = []
    for i in range(N):
        a = input().strip()
        A.append(a)
    for i in range(M):
        b = input().strip()
        B.append(b)
    return N, M, A, B


def solve(N, M, A, B):
    R = N - M
    C = len(A[0]) - len(B[0])
    if R < 0 or C < 0:
        return "No"
    L = len(B[0])
    for i in range(R+1):
        for j in range(C+1):
            is_match = True
            for k in range(M):
                if A[i+k][j:j+L] != B[k]:
                    is_match = False
                    break
            if is_match:
                return "Yes"
    return "No"


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 5076
import java.util.Scanner;

public class Main {
	
	static int n,m,R;
	static long [][]d;
	static int []r;
	static boolean []visit;
	static long ans;
	static int cnt;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		n = Integer.parseInt(sc.next());
		m = Integer.parseInt(sc.next());
		R = Integer.parseInt(sc.next());
		
		r = new int [R];
		
		for(int i = 0 ; i < R ;i++) {
			r[i] = Integer.parseInt(sc.next())-1;
		}
		
		d = new long [n][n];
		for(int i = 0 ; i < n ;i++) {
			for(int j = 0 ; j < n ;j++) {
				d[i][j] = 100000000000000000L;
			}
		}
		
		for(int i = 0 ; i < m ;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			int cost = Integer.parseInt(sc.next());
			d[a-1][b-1] = cost;
			d[b-1][a-1] = cost;
		}
		
		Floyd_Warshall();
		ans = 10000000000000000L;
	
		
		for(int i = 0 ; i < R ;i++) {
		cnt = 1;
		visit = new boolean [n];
		visit[r[i]] = true;
		dfs(r[i], 0L);
		}
		
		System.out.println(ans);
	}
		static void dfs(int now ,long dist) {
			
			if(cnt == R) {
				ans = Math.min(dist, ans);
				return;
			}
			
			for(int i = 0 ; i < R ;i++) {
				if(!visit[r[i]]) {
					visit[r[i]] = true;
					cnt++;
					dfs(r[i],dist + d[now][r[i]]);
					cnt--;
					visit[r[i]] = false;
				}
			}
			
		}
		static void  Floyd_Warshall() {
			
			for(int i = 0 ; i < n ;i++) {
				for(int j = 0 ; j < n ; j++) {
					for(int k = 0 ; k < n ;k++) {
						d[j][k] = Math.min(d[j][k], d[j][i] + d[i][k]);
					}
				}
			}
		}
	}


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

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

  int N, X; cin >> N >> X;
  int sum = 0, mom = 1000;
  for (int i = 0; i < N; i++) {
    int m; cin >> m;
    mom = min(mom, m);
    sum += m;
  }
  cout << N + (X - sum) / mom << "\n";
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 301
int n;

vector<int> w(MAXN);
int dp[MAXN][MAXN];

bool isin(int i, int j){
  return 0<=i && j<n;
}

bool bashable(int i, int j){
  return abs(w[i]-w[j])<=1;
}

int solve(){
  rep(i, n-1)dp[i][i+1] = bashable(i, i+1) ? 2 : 0;
  for(int len=4; len<=n; len++){
    rep(from, n-len+1){
      int to = from+len-1;

      int inner = from+1<to-1 ? dp[from+1][to-1] : 0;
      if(inner==len-2 && bashable(from, to))inner += 2;
      dp[from][to] = inner;

      for(int m=from; m<=to;m++){
        dp[from][to] = max(dp[from][to], dp[from][m]+dp[m+1][to]);
      }

      // rep(i, n){rep(j, n)cout<<dp[i][j]<<' ';cout<<endl;}cout<<endl;

    }
  }

  return dp[0][n-1];
}

int main(){
  while(cin>>n){
    if(!n) break;

    rep(i, MAXN)w[i]=0;
    rep(i, MAXN)rep(j, MAXN)dp[i][j]=0;
    rep(i, n)cin>>w[i];
    int result = solve();
    cout<<result<<endl;

// rep(i, n){rep(j, n)cout<<dp[i][j]<<' ';cout<<endl;}cout<<endl;

  }

  return 0;
}



Measured memory_bytes: 3468
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int n, a, i, min = 1000001, max = -1000001;
	long int sum = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a;
		if (a < min)min = a;
		if (a > max)max = a;
		sum += a;
	}
	cout << min << ' ' << max << ' ' << sum << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b;
    cin >> x >> a >> b;
    if(fabs(x - a) < fabs(x - b))
    {
        cout << "A";
    }
    else
    {
        cout << "B";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <stack>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

string str;

/* add your algorithm here */

int main() {
  cin >> str;

  stack<char> st;
  for (int i = 0; i < str.size(); ++i) {
    if (st.size() == 0) {
      st.push(str[i]);
      continue;
    }
    if (st.top() == 'S') {
      if (str[i] == 'T') {
        st.pop();
      } else {
        st.push(str[i]);
      }
    } else if (st.top() == 'T') {
      st.push(str[i]);
    }
  }

  cout << st.size() << endl;
}


Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  int cnt;

  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;
  int  cnt;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
  int K;
  
  get_N(&K);

  K--;

  printf("%lld", a[K]);
  return 0;
}



Measured memory_bytes: 128
import java.util.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    String[] str = (sc.next()).split(",");
	    int[] hand = new int[5];
	    for(int i = 0; i < 5; i++)
		hand[i] = Integer.parseInt(str[i]);
	    Arrays.sort(hand);
	    String res;

	    if(straight(hand)) res = "straight";
	    else res = func(hand);

	    System.out.println(res);
	}
    }

    String func(int[] hand){
	int[] num = new int[14];
	for(int i = 0; i < 14; i++) num[i] = 0;
	for(int i = 0; i < 5; i++) num[hand[i]]++;
	
	for(int i = 0; i < 14; i++){
	    if(num[i] == 4) return "four card";
	    else if(num[i] == 3){
		for(int j = i+1; j < 14; j++)
		    if(num[j] == 2) return "full house";

		return "three card";
	    } else if(num[i] == 2){
		for(int j = i+1; j < 14; j++){
		    if(num[j] == 3) return "full house";
		    else if(num[j] == 2) return "two pair";
		}

		return "one pair";
	    }
	}

	return "null";
    }

    boolean straight(int[] hand){
	boolean f;
	if(hand[0] == 1){
	    f = true;
	    for(int i = 1; i < 5 && f; i++)
		f = (hand[i] == 9+i);

	    if(f) return f;
	}
	f = true;
	for(int i = 1; i < 5 && f; i++)
	    f = (hand[i] == (hand[0]+i));

	return f;
    }

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

Measured memory_bytes: 12000
//Solution By SlavicG
#include <bits/stdc++.h>
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
#define mp                          make_pair
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	ll n;
	cin >> n;
	ll a[n];
	for(ll i= 0 ;i<n;i++)
	{
		cin >> a[i];
	}
	ll mx = 0;
	ll ret = 0;
	for(ll i= 0 ;i<n;i++)
	{
		ret += max(0LL, mx - a[i]);
		mx = max(mx,a[i]);
	}
	cout << ret << endl;
}

Measured memory_bytes: 5152
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int x[50], y[50];

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) cin >> x[i] >> y[i];
	
	int ans = n;
	rep(i, n) {
		rep(j, n) {
			if (i == j) continue;
			int p = x[i] - x[j];
			int q = y[i] - y[j];
			if (p < 0 || (p == 0 && q < 0)) continue;
			
			int usedCnt = 0;
			bool used[50] = {false};
			int loopCnt = 0;
			while (usedCnt < n) {
				int id = -1;
				rep(k, n) {
					if (used[k]) continue;
					if (id == -1 || x[id] > x[k] || (x[id] == x[k] && y[id] > y[k])) {
						id = k;
					}
				}
				if (id == -1) { cout << "error" << endl; return 0; }
				
				used[id] = true; usedCnt++;
				while (true) {
					rep(k, n) {
						if (used[k]) continue;
						if (x[k] == x[id] + p && y[k] == y[id] + q) {
							break;
						}
					}
					if (k == n) break;
					used[k] = true; usedCnt++;
					id = k;
				}
				loopCnt++;
			}
			ans = min(ans, loopCnt);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define PI 		    acos(-1)
#define pb          push_back
#define ins         insert
#define INF        	1000000000000000007 //1e18+7
#define mk          make_pair
#define lb(v,x)     lower_bound(all(v),x)
#define ub(v,x)     upper_bound(all(v),x)
#define ff          first
#define ss          second
#define rev         reverse
#define umap        unordered_map
#define endl        "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a)       (ll)a.size()
#define double      long double
#define minpq       priority_queue <ll,vector<ll>,greater<ll> > 
#define fill(x,y)   memset(x,y,sizeof(x))
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define MOD         1000000007		//1e9+7
#define bp(n)       __builtin_popcountll(n)
#define mxt(a)      *(max_element(a.begin(),a.end()))
#define mnt(a)      *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i, a, mp) for(ll i = (a); i<= (mp); ++i)
#define trav(a, x) 	 for(auto &a : x)
#define re(i,n)      for(ll i = 0; i < n; ++i) 
const int N = 5e5 + 7;
typedef pair<ll,ll>   pii;
typedef vector<pii>   vpii;
typedef vector<ll>    vll;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int dx[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int dy[8]={+1, 0, -1, +1, -1, +1, 0, -1};
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
template<typename T> T gcd(T a,T mp){ if(a==0) return mp; return gcd(mp%a,a); }
template<typename T> T powm(T a,T mp, ll m){T cnt=1; while(mp>0){ if(mp%2==1) cnt=(cnt*a)%m; mp/=2; a=(a*a)%m; }return cnt%m;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll sqr(ll x) { return x * x;} 
void prec(){

}
void run(){
	ll n;cin>>n;
	ll a[n+1],b[n+1],c[n+1];
	rep(i,1,n) cin>>a[i]>>b[i]>>c[i];
	ll dp[n+1][4];
	fill(dp,0);
	dp[1][1]=a[1];
	dp[1][2]=b[1];
	dp[1][3]=c[1];
	rep(i,2,n){
		dp[i][1]=max(dp[i-1][2]+a[i],a[i]+dp[i-1][3]);
		dp[i][2]=max(dp[i-1][1]+b[i],b[i]+dp[i-1][3]);
		dp[i][3]=max(dp[i-1][2]+c[i],c[i]+dp[i-1][1]);
	}
	cout<<max3(dp[n][1],dp[n][2],dp[n][3]);
}
int main()
{
    cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
    int tc=1;
    //cin>>tc;
    prec();
    re(i,tc)
    	run();
    return 0; 
}

Measured memory_bytes: 5760
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    string a;
    cin >> a;
    if((a[0] == a[1] && a[1]== a[2]) || (a[1] == a[2] && a[2] == a[3])){
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    
    cout << endl;
}


Measured memory_bytes: 256