akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
long long aa[2010],bb[2010];
int n;
long long k;
int a[2200];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]>a[j])
				aa[i]+=1LL;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i]>a[j])
				bb[i]+=1LL;
		}
	}
	long long res=0LL;
	for(int i=1;i<=n;i++){
		res+=aa[i]*k;
		res%=(1000000007LL);
		long long num1=((k-1)*k)/2LL;
		num1%=(1000000007LL);
		res+=bb[i]*num1;
		res%=(1000000007LL);
	}
	cout<<res<<endl;
	return 0;
}


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

int main() {
    int r,g;
    cin >> r >> g;
    cout << 2*g-r << endl;
}

Measured memory_bytes: 256
buf = input().split()
th = int(buf[0])
ts = int(buf[1])
ah = int(buf[2])
ass = int(buf[3])

while True:
  ah -= ts
  if ah <= 0:
    break
  th -= ass
  if th <= 0:
    break

if ah <= 0:
  print('Yes')
if th <= 0:
  print('No')


Measured memory_bytes: 9188
<?php
  fscanf(STDIN,"%d%d",$a,$b);
  $get = 0;
  for($i=0; $i<2; $i++){
      if($a >= $b){
          $get += $a;
          $a--;
      }else{
          $get += $b;
          $b--;
      }
  }
  echo $get;

Measured memory_bytes: 4732
#include<iostream>
#include<set>
using namespace std;
#define f(x) (x % 2 == 0 ? x/2 : 3*x + 1)
int main()
{
    int a, i = 0;
    set<int> l;
    cin >> a;
    while(l.size() == i){
        l.insert(a);
        a = f(a);
        ++i;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  Int M = (1e5)+10;
  vector<vector<Int> > X(M+10), Y(M+10);
  for(Int i=0;i<N;i++){
    Int x, y;
    cin>>x>>y;
    X[x].push_back(y);
    Y[y].push_back(x);
  }

  vector<Int> usedX(M+10), usedY(M+10);
  using T = tuple<Int, Int, Int, Int>;
  function<T(Int, Int)>dfs =[&](Int x, Int y){
    Int a = 0, b = 0, c = 0, d = 0;
    if(x == -1){
      if(usedY[y]++) return T(0, 0, 0, 0);
      c += 1;
      for(Int to:Y[y]) {
        Int s, t, u, v; tie(s, t, u, v) = dfs(to, -1);
        a += s;
        b += t;
        c += u;
        d += v+1;
      }
    }
    if(y == -1){
      if(usedX[x]++) return T(0, 0, 0, 0);
      a += 1;
      for(Int to:X[x]){
        Int s, t, u, v; tie(s, t, u, v) = dfs(-1, to);
        a += s;
        b += t+1;
        c += u;
        d += v;
      }
    }
    return T(a, b, c, d);
  };


  Int ans = 0;
  for(Int i=0;i<M+10;i++){
    if(usedX[i]) continue;
    Int a, b, c, d; tie(a, b, c, d) = dfs(i, -1);
    pr(i, a, b, c, d);
    if(a < 2 || c < 2) continue;
    ans += a * c - (b + d)/2;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 20352
#include <cstdio>
#include <cstring>

const int MaxN = 50;
const int Mod = 1000000007;

int N;
long long K;

inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }
inline int sub(int x, int y) { return (x -= y) < 0 ? x + Mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % Mod; }

struct Matrix {
  int mat[MaxN][MaxN];

  Matrix() {
    memset(mat, 0, sizeof mat);
  }

  inline friend Matrix operator + (const Matrix &a, const Matrix &b) {
    Matrix c;
    for (int i = 0; i < N; ++i)
      for (int j = 0; j < N; ++j)
        c.mat[i][j] = add(a.mat[i][j], b.mat[i][j]);
    return c;
  }

  inline friend Matrix operator * (const Matrix &a, const Matrix &b) {
    Matrix c;
    for (int i = 0; i < N; ++i)
      for (int j = 0; j < N; ++j) {
        int x = 0;
        for (int k = 0; k < N; ++k)
          x = add(x, mul(a.mat[i][k], b.mat[k][j]));
        c.mat[i][j] = x;
      }
    return c;
  }

  inline friend Matrix operator ^ (Matrix low, long long high) {
    Matrix res;
    for (int i = 0; i < N; ++i) res.mat[i][i] = 1;
    while (high) {
      if (high & 1) res = res * low;
      high >>= 1;
      low = low * low;
    }
    return res;
  }
};
Matrix G;

void init() {
  scanf("%d %lld", &N, &K);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      scanf("%d", &G.mat[i][j]);
}

void solve() {
  G = G ^ K;
  int ans = 0;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      ans = add(ans, G.mat[i][j]);
  printf("%d\n", ans);
}

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

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath> 
typedef long long ll;
using namespace std;
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
inline int rd(){
	int res=0,sign=1;char ch;
	while((ch=getchar())<'0'||ch>'9')if(ch=='-')sign=-1;res=res*10+ch-48;
	while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;
	return res*sign;
}
int n,r;
int main(){
	cin>>n>>r;
	if(n<10)cout<<100*(10-n)+r<<endl;
	else cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks.Sources;

namespace TaskC
{
    class Program
    {
        static void Main(string[] args)
        {
            var numbers = Console.ReadLine()
                .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse)
                .ToArray();

            var n = numbers[0];
            var m = numbers[1];
            var x = numbers[2];

            var c = new int[n];
            var books = new int[n, m];

            for (var i = 0; i < n; i++)
            {
                numbers = Console.ReadLine()
                .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse)
                .ToArray();
                c[i] = numbers[0];
                for (var j = 0; j < m; j++)
                {
                    books[i, j] = numbers[j + 1];
                }
            }

            var selected = Enumerable.Repeat(0, n + 1).ToList();
            var bestPrice = int.MaxValue;

            while (selected[0] == 0)
            {
                var money = selected
                    .Skip(1)
                    .Select((val, index) => val * c[index])
                    .Sum();

                var score = Enumerable.Repeat(0, m).ToArray();
                selected
                    .Skip(1)
                    .Select((val, index) =>
                    {
                        if (val == 0) return 0;
                        for (var i = 0; i < m; i ++)
                        {
                            score[i] += books[index, i];
                        }
                        return 0;
                    })
                    .ToArray();

                if (money < bestPrice && score.All(v => v >= x))
                {
                    bestPrice = money;
                }

                for (var i = selected.Count - 1; i >=0; i--)
                {
                    if (selected[i] == 1)
                    {
                        selected[i] = 0;
                    }
                    else
                    {
                        selected[i] = 1;
                        break;
                    }
                }
            }

            Console.WriteLine(bestPrice == int.MaxValue ? -1 : bestPrice);
        }
    }
}


Measured memory_bytes: 31340
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{r:i32,g:i32};
    println!("{}", 2*g-r);
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
	int i,j,n,a,s,sum[4],aum[4],cum,bum,flg;
	while(1){
		scanf("%d",&n);
		flg=0;
		cum=0;
		if(n==0000){
			break;
		}
		else{
		while(!(n==6174)){
		bum=n;
		sum[0]=bum%10;
		bum=bum/10;
		sum[1]=bum%10;
		bum=bum/10;
		sum[2]=bum%10;
		bum=bum/10;
		sum[3]=bum;
		if(sum[0]==sum[1]&&sum[1]==sum[2]&&sum[2]==sum[3]){
			printf("NA\n");
			flg=1;
			break;
		}
		else{
			aum[0]=sum[0];
			aum[1]=sum[1];
			aum[2]=sum[2];
			aum[3]=sum[3];
			for(i=0;i<3;i++){
				for(j=i+1;j<4;j++){
					if(sum[i]<sum[j]){
						bum=sum[i];
						sum[i]=sum[j];
						sum[j]=bum;
					}
					if(aum[i]>aum[j]){
						bum=aum[i];
						aum[i]=aum[j];
						aum[j]=bum;
					}
				}
			}
			a=sum[0]*1000+sum[1]*100+sum[2]*10+sum[3];
			s=aum[0]*1000+aum[1]*100+aum[2]*10+aum[3];
			n=a-s;
			cum++;
		}
	}
	if(flg==0){
	printf("%d\n",cum);
	}
		}
	}
	return 0;
}


Measured memory_bytes: 2068
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll sum = 1;
    rep(i, N) {
        if (A[i] % 2 == 0) {
            sum *= 2;
        }
    }

    print((ll)pow(3, N) - sum);
    return 0;
}


Measured memory_bytes: 256
class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

import sys,random

input=sys.stdin.readline

H,W,M=map(int,input().split())
bomb=[[] for i in range(H)]
row=[0 for i in range(H)]
column=[0 for j in range(W)]

for _ in range(M):
    h,w=map(int,input().split())
    #h,w=random.randint(1,H),random.randint(1,W)
    row[h-1]+=1
    column[w-1]+=1
    bomb[h-1].append(w-1)


for i in range(H):
    bomb[i].sort()

Seg=SegmentTree(column,segfunc=max,ide_ele=0)

ans=0
for i in range(H):
    for j in range(len(bomb[i])-1):
        L,R=bomb[i][j],bomb[i][j+1]
        tmp=row[i]+max(column[L],column[R])-1
        ans=max(ans,tmp)
        L+=1
        if L==R:
            continue
        tmp=row[i]+Seg.query(L,R)
        ans=max(ans,tmp)
    if bomb[i] and bomb[i][0]!=0:
        L,R=0,bomb[i][0]
        tmp=row[i]+Seg.query(L,R)
        ans=max(ans,tmp)
    if bomb[i] and bomb[i][-1]!=W-1:
        L,R=bomb[i][-1]+1,W
        tmp=row[i]+Seg.query(L,R)
        ans=max(ans,tmp)
    if not bomb[i]:
        tmp=row[i]+Seg.query(0,W)
        ans=max(ans,tmp)
    else:
        tmp=row[i]+column[bomb[i][0]]-1
        ans=max(ans,tmp)

print(ans)


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

int main()
{
    int x, y;
    cin >> x >> y;

    if (y - 2 * x >= 0 && y % 2 == 0 && 2 * x - (int)(y/2) >= 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    int sum=1000000;
    for(int i=1;i<=100;i++){
        int tmp=0;
        for(int j=0;j<n;j++){
            tmp+=(x[j]-i)*(x[j]-i);
        }
        sum=min(sum,tmp);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3608
n = int(input())
Bs = list(map(int,input().split()))
a = []
a.append(Bs[0])
a.append(Bs[0])
for b in Bs[1:]:
  if a[-1] < b:
    a.append(b)
  else:
    a[-1] = b
    a.append(b)
print(sum(a))
    




Measured memory_bytes: 2940
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

import networkx as nx
n,x,y = inpm()
x -= 1
y -= 1
if x > y:
    x,y = y,x

d = np.zeros((n,n),int)
ans = np.zeros(n,int)
for i in range(n):
    for j in range(i+1,n):
        a = j - i
        b = abs(x - i) + abs(j - y) + 1
        ans[min(a,b)] += 1

for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 53732
import java.awt.*;
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        long cnt[]=new long[n+1];
        int a[]=new int[n];
        for (int i=0;i<n;i++){
            a[i]=sc.nextInt();
            cnt[a[i]]++;
        }
        long ways=0;
        for (int i=1;i<=n;i++){
            ways+=((long) cnt[i]*(cnt[i]-1)/2);
        }
        long ans[]=new long[n];
        for (int i=0;i<n;i++){
            ans[i]=ways-(cnt[a[i]]*(cnt[a[i]]-1)/2)+((cnt[a[i]]-2)*(cnt[a[i]]-1)/2);
        }
        StringBuilder sb=new StringBuilder();
        for (long x:ans){
            sb.append(x+"\n");
        }
        System.out.print(sb);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 70160
a = []
for i in range(3):
    ai = list(map(int, input().split()))
    a.append(ai)
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                a[j][k] = 0

ans = "No"
if sum(a[0]) == 0:
    ans = "Yes"
elif sum(a[1]) == 0:
    ans = "Yes"
elif sum(a[2]) == 0:
    ans = "Yes"
elif a[0][0] + a[1][0] + a[2][0] == 0:
    ans = "Yes"
elif a[0][1] + a[1][1] + a[2][1] == 0:
    ans = "Yes"
elif a[0][2] + a[1][2] + a[2][2] == 0:
    ans = "Yes"
elif a[0][0] + a[1][1] + a[2][2] == 0:
    ans = "Yes"
elif a[0][2] + a[1][1] + a[2][0] == 0:
    ans = "Yes"
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

int A, B;

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

void printvec(const std::vector<int>& vec) {
    for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << " "; } std::cout << std::endl;
}

int main(int argc, char **argv) {
    std::cin >> A >> B;
    
    std::cout << (A + B) % 24 << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/aising2019/tasks/aising2019_c
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int R,C;
int buf[412][412];
int vis[412][412];
int dr[]={0,1,0,-1};
int dc[]={1,0,-1,0};
void dfs(int r,int c,int& b,int& w){
    if(vis[r][c])return;
    if(buf[r][c]==-1)return;
    if(buf[r][c])b++;
    else w++;
    vis[r][c]=1;
    for(int d:range(4)){
        int nr=r+dr[d];
        int nc=c+dc[d];
        if(buf[r][c]!=buf[nr][nc])dfs(nr,nc,b,w);
    }
}
int main(){
    cin>>R>>C;
    for(int i:range(412))for(int j:range(412))buf[i][j]=-1;
    for(int i:range(R)){
        string s;
        cin>>s;
        for(int j:range(C)){
            buf[i+1][j+1]=(s[j]=='#');
        }
    }
    LL ret=0;
    for(int i:range(R))for(int j:range(C)){
        int b=0,w=0;
        dfs(i+1,j+1,b,w);
        ret+=b*1ll*w;
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string X;
	stack<char> s;
	int len;

	cin >> X;
	len = X.length();

	rep(i, len) {
		if (X[i] == 'T') {
			if (!s.empty() && s.top() == 'S') s.pop();
			else s.push(X[i]);
		}
		else s.push(X[i]);
	}

	cout << s.size() << endl;

	return 0;
}


Measured memory_bytes: 644
program sample
    implicit none
  
    integer(8) :: i,j,m,n,a,b,c
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) a,b,c
    do i=1,b
        if (mod(a*i,b)==c)then
            write(*,*)'YES'
            stop
        endif
    end do

    write(*,*) 'NO'
  
    stop
end program sample
  



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

int main() {
    int N; cin >> N;
    vector<vector<int>> edge(N);
    vector<P> nb_edge(N-1);
    // vector<vector<int>> edge_color(N, vector<int>(N, -1));
    map<P, int> I;
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
        nb_edge[i] = make_pair(a, b);

        // initialize color
        I[make_pair(a, b)] = I[make_pair(b, a)] = 0;
    }

    queue<int> node_que;
    node_que.push(0);
    vector<bool> reached(N, false);
    vector<int> color_par(N, 0); // その親とのcolor
    reached[0] = true;

    int color_max = 0;

    while(!node_que.empty()){
        int n = node_que.front();
        node_que.pop();
        // cout << "node now: " << node_now << endl; 
        color_max = max(color_max, int(edge[n].size()));
        // nodeの辺を見ていく
        int color = 1;
        // rep(i, edge[n].size()) {
        for (int u: edge[n]){
            // reachedじゃなければpush
            if (reached[u]) continue;
            // cout << "push: " << edge[node_now][i] << endl;
            node_que.push(u);
            reached[u] = true;
            // colorがnode_now iと同じならそのcolorは使えないので ++
            if (color_par[n] == color) color++;
            color_par[u] = I[make_pair(u, n)] = I[make_pair(n, u)] = color;
            color++;
        }
    }
    cout << color_max << endl;
    for(auto p: nb_edge) {
        // cout << nb_edge[i].first << " " << nb_edge[i].second << " color" << endl;
        cout << I[p] << endl;
    }
    return 0;
}

Measured memory_bytes: 19712
# -*- coding: utf-8 -*-

import sys


lineNumber = 0
#for line in [ "1", "6", "0", "8", "10", "0", "0", "0" ]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # except line
    if lineNumber == 1:
        cars = []
    
    # get data
    List = map(int, line.strip().split())

    n = List[0]
    if n == 0: print cars.pop()
    else     : cars.append(n)

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

int main(void){
    int n, res = 0;
    cin >> n;
    vector<string> s(n);
    int ra = 0, lb = 0; int ralb = 0;
    char start, end;

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

    for (int i = 0; i < n; i++) {
        start = s[i][0];
        end = s[i][s[i].length()-1];
        if (start != 'B' && end == 'A') ra++;
        else if (start == 'B' && end != 'A') lb++;
        else if (start == 'B' && end == 'A') ralb++;

        for (int j = 0; j < s[i].size() - 1; j++) {
            if (s[i][j] == 'A' && s[i][j+1] == 'B') res++;
        }
    }
    if (ralb == 0) {
        res += min(ra, lb);
    } else {
        if (ra + lb > 0) res += min(ra, lb) + ralb;
        else res += min(ra, lb) + ralb - 1;
    }
    cout << res << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
const int mod = 1e9+7;
const int maxn = 1e3+5;
const double EPS = 1e-6;
using namespace std;
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int road[maxn][maxn];
int v[maxn];
int R[25];
int main()
{
    int n,m,r;
    scanf("%d %d %d",&n,&m,&r);
    rep(i,0,n+1)
    {
        rep(j,0,n+1)
        {
            road[i][j]=inf;
        }
        road[i][i]=0;
    }
    rep(i,0,r)
    {
        scanf("%d",&R[i]);
    }
    sort(R,R+r);
    rep(i,0,m)
    {
        int a,b,v;
        scanf("%d %d %d",&a,&b,&v);
        if(road[a][b]>v) road[a][b]=v,road[b][a]=v;
    }
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                road[i][j]=min(road[i][j],road[i][k]+road[k][j]);
    int ans=inf;
    do{
        int sum=0;
        rep(i,0,r-1)
        {
            sum+=road[R[i]][R[i+1]];
        }
        ans=min(sum,ans);
    }while ( next_permutation(R,R+r));
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1024
# python template for atcoder1
import sys

N, A, B, C, D = map(int, input().split())
L = list([v for v in input()])

HOP = [1, 2]
dp_d = [0]*N
dp_d[B-1] = 1
for i in range(N):
    if L[i] == "#":
        continue
    for h in HOP:
        dst = i+h
        if dst < N and L[dst] == ".":
            dp_d[dst] = max(dp_d[dst], dp_d[i])
dp_c = [0]*N
dp_c[A-1] = 1
for i in range(N):
    if L[i] == "#":
        continue
    for h in HOP:
        dst = i+h
        if dst < N and L[dst] == ".":
            dp_c[dst] = max(dp_c[dst], dp_c[i])
reachable = False
if dp_c[C-1] == 1 and dp_d[D-1] == 1:
    reachable = True

if not reachable:
    print("No")
elif C < D:
    print("Yes")
else:
    if "..." in "".join(L[B-2:min(C, D)+1]):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 8180
# -*- coding: utf-8 -*-
# 標準入力を取得
S = input()
T = input()

# 求解処理
N = len(S)
ans = "No"
for i in range(N):
    if S[-i:] + S[:-i] == T:
        ans = "Yes"
        break

# 結果出力
print(ans)


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

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

	vector<int> num(N);

	for (size_t i = 0;i < N;++i) {
		cin >> num.at(i);
	}

	size_t i = 0,j=N-1;
	int left = num.at(i), right = num.at(j);
	while (i!=j) {
		if (left >= right) {
			j--;
			if (i == j) {
				break;
			}
			else {
				right += num.at(j);
			}
		}
		else if(left < right){
			i++;
			if (i == j) {
				break;
			}
			else {
				left += num.at(i);
			}
		}
		if (i == j) {
			break;
		}
	}
	cout << abs(right - left);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

int n, t[4444][4] = {};
char s[4444];

main(){
    scanf("%d", &n);
    scanf("%s", s);
    for(int i=n-1; i>=0; i--){
        for(int j=0;j<3;j++)t[i][j] = t[i+1][j];
        t[i][s[i]=='R'?0:s[i]=='G'?1:2]++;
    }
    ll nyan = 0;
    for(int i=0; i<n; i++){
        for(int j = i+1; j<n; j++){
            if(s[i] != s[j]){
                //r,g
                if(s[i]+s[j] == 'R'+'G'){
                    nyan += t[j+1][2] - ((2*j-i)<n && s[2*j-i]=='B');
                }
                //g,b
                if(s[i]+s[j] == 'G'+'B'){
                    nyan += t[j+1][0] - ((2*j-i)<n && s[2*j-i]=='R');
                }
                //b,r
                if(s[i]+s[j] == 'B'+'R'){
                    nyan += t[j+1][1] - ((2*j-i)<n && s[2*j-i]=='G');
                }
            }
        }
    }
    printf("%lld\n", nyan);
}

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

    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	while(true){
	int H = sc.nextInt();
	int W = sc.nextInt();
	if(H==0 && W==0){
	    break;
    }
for(int i =0; i<H; i++){
	    for(int j=0 ;j<W; j++){
	        if(i==0 || i==H-1){
                System.out.print("#");
            }
            else if(j==0 || j==W-1){
                System.out.print("#");
            }else{
                System.out.print(".");
            }
        }
    System.out.println("");
        }
        System.out.println("");
}
    }
}



Measured memory_bytes: 32664
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;

int main() {
  ll n,a,b; cin>>n>>a>>b;
  ll x[n]; for(int i=0;i<n;i++) cin>>x[i];
  ll an=0;
  for(int i=1;i<n;i++) {
    an+=min(a*(x[i]-x[i-1]), b);
  }
  cout<<an<<endl;
}
// Thank you for making problems and running the contest

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

ll H,W,a[26]={},l;
string S;
bool F=true;

int main(void){
	cin>>H>>W;
	rep(i,H){
		cin>>S;
		rep(j,W){
			a[S[j]-'a']++;
		}
	}
	if(H%2==1 && W%2==1){
		l=H+W-1;
	}else if(H%2==1){
		l=W;
	}else if(W%2==1){
		l=H;
	}else{
		l=0;
	}
	rep(i,26){
		a[i]%=4;
		if(a[i]%4!=0){
			if(a[i]%2==1){//奇数
				if(H%2==1 && W%2==1){//１回だけ助かる
					if(F){
						F=false;
					}else{
						printf("No\n");
						return 0;
					}
				}else{
					printf("No\n");
					return 0;
				}
			}else{//偶数
				if(a[i]<=l){
					l-=a[i];
				}else{
					printf("No\n");
					return 0;
				}
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int a[] = new int[N + 1];
		int b[] = new int[N + 1];

		int count = 0;
		for (int i = 1; i <= N; i++) {
			a[i] = sc.nextInt();
			if (N / 2 < i) {
				b[i] = a[i];
				if (b[i] == 1) {
					count++;
				}
			}
		}

		PrintWriter out = new PrintWriter(System.out);

		for (int i = N / 2; i > 0 ; i--) {
			int sum = 0;
			for (int j = i * 2; j <= N; j += i) {
				sum += b[j];
			}
			if (sum % 2 == a[i]) {
				b[i] = 0;
			} else if ((sum + 1) % 2 == a[i]) {
				b[i] = 1;
				count++;
			} else {
				out.println(-1);
				break;
			}
		}

		out.println(count);
		for (int i = 1; i <= N; i++) {
			if (b[i] == 1) {
				out.println(i);
			}
		}

		out.flush();
	}

	public static int gcd(int a, int b) {
	    if (b == 0) return Math.abs(a);
	    return gcd(b, a % b);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 34712
N = int(input())
*A, = list(map(int, input().split()))
cnt = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        cnt += 1
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
print(*A)
print(cnt)


Measured memory_bytes: 5600
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	cout << "ABC" + s << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
#define NIL -1

struct Node{
    int parent,right,left;
};

int getDepth(struct Node *,int);

int main(){
    int n,m;
    int id,c,tmp;
    int depth[MAX];

    struct Node TREE[MAX];

    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        TREE[i].parent = TREE[i].left = TREE[i].right = NIL;
    }

    for(int i = 0;i < n;i++){
        scanf("%d%d",&id,&m);
        for(int j = 0;j < m;j++){
            scanf("%d",&c);
            //j == 0の時は、子供ではなく親となるノードなので
            if(j == 0){
                //子供のid
                TREE[id].left = c;
                //子供たちの親
                TREE[c].parent = id;
                tmp = c;
            }
            else{
                //子供たちのidのノードを設定
                TREE[tmp].right = c;
                TREE[c].parent = id;
                tmp = c;
            }
        }
    }
    for(int i = 0;i < n;i++){
        depth[i] = getDepth(TREE,i);
    }

    for(int i = 0; i < n; i++){
        printf("node %d: parent = %d, depth = %d, ", i, TREE[i].parent, depth[i]);
        //親がいなかったら
        if(TREE[i].parent == NIL){
            printf("root");
        }
        // 子供がいなかったら
        else if(TREE[i].left == NIL){
            printf("leaf");
        }
        // どちらでもない時
        else{
            printf("internal node");
        }
        printf(", [");
        //子供がいなくなるまで
        if(TREE[i].left != NIL){
            printf("%d",TREE[i].left);
            tmp = TREE[i].left;
            while(1){
                if(TREE[tmp].right == NIL) break;
                printf(", %d", TREE[tmp].right);
                tmp = TREE[tmp].right;
            }
        }
        printf("]\n");
    }

    return 0;
}

int getDepth(struct Node *TREE,int i){
    if(TREE[i].parent == NIL)return 0;
    return getDepth(TREE,TREE[i].parent) + 1;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

string S;

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

  cin>>S;
  if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3])cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;

  return 0;
}


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

string s;

void agc005a() {
  int s_cnt = 0, t_cnt = 0, n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == 'S') {
      s_cnt++;
    }
    else {
      t_cnt++;
      if (s_cnt > 0) {
        s_cnt--;
        t_cnt--;
      }
    }
  }
  cout << s_cnt + t_cnt << '\n';
  return;
}

int main() {
  cin >> s;
  agc005a();
  return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int s = in.nextInt();
			int[] n = new int[1000000];
			n[1] = s;
			loop : for(int i = 2; i < n.length; i++) {
				if(n[i - 1] % 2 == 0) {
					n[i] = n[i - 1] / 2;
				}else {
					n[i] = n[i - 1] * 3 + 1;
				}
				for(int j = 0; j < i; j++) {
					if(n[i] == n[j]) {
						out.println(i);
						break loop;
					}
				}
			}
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

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

	}
}


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

tleft = 0
tright = 0
a = []
b=  []
for _ in range(N):
  s = input()
  left = 0
  lmin = 0
  for c in s:
    if c == "(":
      left += 1
    else: # ")"
      left -= 1
      lmin = min(lmin,left)
  #
  if left >= 0:
    if lmin == 0:
      tleft += left
    else:
      a.append([left,lmin])
  else:
    if left <= lmin:
      tright += left
    else:
      b.append([left,lmin])
#
a.sort(key=lambda x:-x[1])
b.sort(key=lambda x:x[1])

for left, lmin in a:
  if tleft + lmin < 0:
    print("No")
    exit(0)
  else:
    tleft += left
#
for left, lmin in b:
  if tleft + lmin < 0:
    print("No")
    exit(0)
  else:
    tleft += left
#
if tleft + tright == 0:
  print("Yes")
else:
  print("No")
#


Measured memory_bytes: 28340
x, y, z, k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=1)
B.sort(reverse=1)
C.sort(reverse=1)

D = []

for i in range(min(k, x)):
    for j in range(min(k, y)):
        for l in range(min(k, z)):
            if i*j*l <= k:
                D.append(A[i] + B[j] + C[l])
            else:
                break

D.sort(reverse=1)

for i in range(k):
    print(D[i])

Measured memory_bytes: 135996
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int count = 0, ans = 0;
	rep(i, n){
		if(s[i] == 'I') count++;
		else count--;
		ans = max(ans, count);
	}
	cout << ans << endl;
	return 0;
}

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

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

  string ans = "";
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (N != 0) {
    if (N % 2 != 0) {
      N--;
      ans = "1" + ans;
    } else {
      ans = "0" + ans;
    }
    N /= -2;
  }

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

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

int main(){
    auto safeat = [](auto& t, auto i, auto j)->long{
        if(i < 0 || j < 0 || i >= t.size() || j >= t[0].size())return 0;
        else return t[i][j];
    };
    constexpr long m = 998244353;
    long N;
    string s;
    cin >> s;
    N = s.size();
    vector<pair<long, long>> S;
    for(auto i : s)S.emplace_back((i & 3), 2 - (i & 3));
    partial_sum(S.begin(), S.end(), S.begin(), [](auto a, auto b){return pair<long, long>(a.first + b.first, a.second + b.second);});
    vector<vector<long>> dp(S.rbegin()->first + 1, vector<long>(S.rbegin()->second + 1, 0));
    dp[0][0] = 1;
    for(int i = 1; i <= 2 * N; ++i){
        for(int j = 0; j <= i; ++j){
            if(j > S.rbegin()->first || i - j > S.rbegin()->second)continue;
            if(i <= N){
                if(j > S[i - 1].first)continue;
                if(i - j > S[i - 1].second)continue;
            }
            dp[j][i - j] = safeat(dp, j, i - j - 1) + safeat(dp, j - 1, i - j);
            dp[j][i - j] %= m;
        }
    }
    cout << *(dp.rbegin()->rbegin()) << endl;
    return 0;
}

Measured memory_bytes: 31616
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**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
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 pf(s): return print(s, flush=True)

N=_I()
S=[_I() for i in range(N)]
S.sort()
if all(i%10==0 for i in S):
	print(0)
	exit()

ans=sum(S)
idx=0
while ans%10==0 and idx < N:
	if S[idx]%10!=0:
		ans-=S[idx]
	idx += 1
print(ans)


Measured memory_bytes: 5464