akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
 
struct Node 
{
    int key;
    Node *prev, *next;
};
 
Node *nil;
 
Node* listSearch(int key)
{
    Node *cur = nil->next;
    while(cur != nil && cur->key != key)
    {
        cur = cur->next;
    }
    return cur;
}
 
void init()
{
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}
 
void insert(int key)
{
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}
 
void printList()
{
    Node *cur = nil->next;
    int isf = 0;
    while(1)
    {
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}
 
void deleteNode(Node *t)
{
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}
 
void deleteFirst()
{
    deleteNode(nil->next);
}
 
void deleteLast()
{
    deleteNode(nil->prev);
}
 
void deleteKey(int key)
{
    deleteNode(listSearch(key));
}
 
 
int main()
{
    int key,n,i;
    int size = 0;
    char com[20];
    int np = 0,nd = 0;
    scanf("%d",&n);
    init();
    for(i = 0; i < n; i++)
    {
        scanf("%s%d",com,&key);
        if(com[0] == 'i')
        {
            insert(key);
            np++;
            size++;
        }
        else if(com[0] == 'd')
        {
            if(strlen(com) > 6)
            {
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }
     
    printList();
    return 0;
}

Measured memory_bytes: 33852
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
    int N, K, i, l[51], ans=0;

    cin >> N >> K;

    for(i=1; i<=N; i++){
        cin >> l[i];
    }

    sort(l+1, l+N+1);

    for(i=N-K+1; i<=N; i++){
        ans += l[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a1 = [[1,i] for i in a]
bc = [list(map(int, input().split())) for _ in range(m)]
abc = a1+bc
abc.sort(key=lambda x:x[1])
abc.reverse()

ans = 0
n1 = n+0
for x,y in abc:
    if n1 >x:
        ans += x*y
        n1 -= x
    else:
        ans += n1*y
        break

print(ans)

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

int main() {
    int n, x, m;
    cin >> n;
    m = n;
    x = 0;
    while(true) {
        x += m % 10;
        m /= 10;
        if(m == 0) {
            break;
        }  
    }

    if(n % x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <deque>
#include <iostream>
using namespace std;
int main() {
    int H, W; cin >> H >> W;
    string s[H]; for (int i = 0; i < H; i++) cin >> s[i];
    int dist[2][H][W];
    int INF = 1<<30;
    for (int b = 0; b < 2; b++)
        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++) dist[b][i][j] = INF;
    struct pt { int b, x, y; };
    deque<pt> deq;
    if (s[0][0] == '.') {
        dist[0][0][0] = 0;
        deq.push_front({0, 0, 0});
    } else {
        dist[1][0][0] = 1;
        deq.push_front({1, 0, 0});
    }
    const int dx[] = {1, 0}, dy[] = {0, 1};
    while (!deq.empty()) {
        pt p = deq.front();
        deq.pop_front();
        int b = p.b, x = p.x, y = p.y;
        for (int i = 0; i < 2; i++) {
            int x1 = x + dx[i], y1 = y + dy[i];
            if (0 <= x1 && x1 < H && 0 <= y1 && y1 < W)
                if ((s[x1][y1] == '.') == (b == 0) && dist[b][x1][y1] == INF) {
                    dist[b][x1][y1] = dist[b][x][y];
                    deq.push_front({b, x1, y1});
                }
        }
        if (dist[1-b][x][y] == INF) {
            if (b == 1) {
                dist[0][x][y] = dist[1][x][y];
                deq.push_front({0, x, y});
            } else {
                dist[1][x][y] = 1 + dist[0][x][y];
                deq.push_back({1, x, y});
            }
        }
    }
    // for (int b = 0; b < 2; b++) {
    //     for (int i = 0; i < H; i++) {
    //         for (int j = 0; j < W; j++) cerr << dist[b][i][j] << ' ';
    //         cerr << endl;
    //     }
    //     cerr << endl;
    // }
    
    cout << dist[0][H-1][W-1] << endl;
}


Measured memory_bytes: 384
n = int(input())
x = list(map(int, input().split()))
ave = sum(x) / n
ave_int = int(ave)
if (ave - ave_int) < (ave_int+1-ave):
  p = ave_int
else:
  p = ave_int+1

r = sum([ abs(i-p)**2 for i in x ])
print(r)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;

void solve()
{
 ll i,j=1,k,n,m=0,f,s1=0,x,c=1,t,y=0;
 cin>>n;
 vector < ll > v(n+1),vv(n);
 rep(i,0,n)
 {
     cin>>m;
     vv[i]=m;
     v[m]++;
 }
 rep(i,1,n+1)
 {
     k=v[i];
     y+=max(0LL,((k*(k-1))/2));
 }
 rep(i,0,n)
 {
    f=vv[i];
    k=v[f];
    cout<<(y-max(0LL,(k*(k-1))/2)+max(0LL,((k-1)*(k-2)))/2)<<endl;
 }

}


 //}

    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
         //cin>>t;
        while(t--)
        solve();
    }


Measured memory_bytes: 5760
a,b,c = map(int,input().split())

if a%2 or b%2 or c%2:
  print(0)
  exit()
elif a==b==c:
  print(-1)
  exit()
  
ans =0
while 1:
  if all((a%2==0, b%2==0, c%2==0)):
    ans += 1
  else:
    print(ans)
    exit()
  a, b, c = (b+c)//2, (a+c)//2, (b+a)//2



Measured memory_bytes: 3064
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

    g = A[0]
    for a in A[1:]:
        g = gcd(g, a)
    print(g)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62704
x,y = input().split()
q,w = input().split()
a =int(x)
b=int(y)
c= int(q)
d =int(w)
e =int(input())

if c-a >0:
  if c-a <=e*(b-d):
    print('YES')
   
  else:
    print('NO')
    
else:
  if a-c<=e*(b-d):
    print('YES')
   
  else:
    print('NO')

Measured memory_bytes: 9200
#include<iostream>
#include<algorithm>
#define rep(i,k,n) for(int i=(int)(k);i<(int)(n);i++)
using namespace std;
static const int MAX=1000;
static const int VMAX=10000;

int n,A[MAX],s;
int B[MAX],T[VMAX+1];

int solve(){
    int ans=0;

    bool V[MAX];
    rep(i,0,n){
        B[i]=A[i];
        V[i]=false;
    }
    sort(B,B+n);
    rep(i,0,n) T[B[i]]=i;
    rep(i,0,n){
        if(V[i]) continue;
        int cur=i;
        int S=0;
        int m=VMAX;
        int an=0;
        while(1){
            V[cur]=true;
            an++;
            int v=A[cur];
            m=min(m,v);
            S+=v;
            cur=T[v];
            if(V[cur]) break;
        }
        ans+=min(S+(an-2)*m,m+S+(an+1)*s);
    }
    return ans;
}

int main(){
    cin>>n;
    s=VMAX;
    rep(i,0,n){
        cin>>A[i];
        s=min(s,A[i]);
    }
    int ans=solve();
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3184
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

const char_list: [char; 26] = ['a', 'b', 'c', 'd', 'e', 
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 
'q', 'r', 's', 't', 'u','v', 'w', 'x', 'y', 'z'];
use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        n: usize,
        s: [chars; n],
    }
    let mut char_counts = vec![[0; 26]; n];

    for (s, cs) in s.iter().zip(char_counts.iter_mut()) {
        for &c in s.iter() {
            cs[c as usize - 'a' as usize] += 1;
        }
    }
    
    for &c in char_list.iter() {
        let mut min = std::usize::MAX;
        for cs in char_counts.iter() {
            min = cmp::min(min, cs[c as usize - 'a' as usize]);
        }

        for _ in 0..min {
            print!("{}", c);
        }
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
 
using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,a,b;
  cin>>n>>a>>b;
  ll diff=abs(a-b);
  if((diff%2) == 0) {
    cout<<diff/2<<endl;
    return 0;
  }
  ll sum=(a-1)+(b-1);
  ll sum2=(n-a)+(n-b);
  ll dmin=min(sum,sum2);
  cout<<(dmin+1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
def main ():
    N = int(input())
    A = list(map(int,input(). split ()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main ()


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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    char c;
    cin >> c;
    char l = tolower(c);
    if (l == c) {
        cout << "a" << '\n';
    } else {
        cout << "A" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3636
//ios::sync_with_stdio(false);
#include<bits/stdc++.h>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
#define ckmax(a,b) (a)=max(a,b)
#define ckmin(a,b) (a)=min(a,b)
#define pb push_back
using namespace std;
LL R(){
    LL ans=0,f=1;char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) ans=ans*10+c-'0';
    return ans*f;
}
const int N=200010;
int n,a[N],p[N],z[N],tp;
bool ck(int k){
	tp=0;p[0]=0;z[0]=-N;
	F(i,2,n)
		if(a[i]<=a[i-1]){
			if(k==1)return 0; 
			while(p[tp]>a[i])--tp;
			if(p[tp]!=a[i]){
				++tp;
				p[tp]=a[i];
				z[tp]=1;
			}
			else{
				++z[tp];
			}
			while(z[tp]==k){
					if(p[tp-1]==p[tp]-1){
						--tp;
						++z[tp];
					}
					else{
						--p[tp];
						z[tp]=1;
					}
				}
		}
	return z[0]==-N;
}
int main(){
	//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	n=R();
	F(i,1,n)a[i]=R();
	int ll=1,rr=n+1,mid,ans;
	while(ll<=rr){
		mid=(ll+rr)/2;
		if(ck(mid))ans=mid,rr=mid-1;
		else ll=mid+1;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
S=input()
ans='Yes'
if S.count('N')>=1 and S.count('S')==0:
    ans='No'
elif S.count('S')>=1 and S.count('N')==0:
    ans='No'
elif S.count('E')>=1 and S.count('W')==0:
    ans='No'
elif S.count('W')>=1 and S.count('E')==0:
    ans='No'
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <numeric>
#include <time.h>
#include <bitset>
#include <string.h>
#include <stack>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <complex>
#include <functional>
#include <limits.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef unsigned long long ull ;
#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define pi (acos(-1.0))
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lson (o<<1),l,mid
#define rson (o<<1|1),mid+1,r
#define MP make_pair
#define sqr(x) ((x)*(x))
#define ALL(v) (v).begin(),(v).end()
#define showtime fprintf(stderr,"time = %.15f\n",clock() / (double)CLOCKS_PER_SEC)
const double eps = 1e-9 ;
const int MOD=(int)1e9+7,BAS=233;
inline int sign(double x){return x<-eps?-1:x>eps;}
inline int clz(int x){return __builtin_clz(x);}
inline int clz(ll x){return __builtin_clzll(x);}
inline int lg2(int x){return !x ? -1 : 31-clz(x);}
inline int lg2(ll x){return !x ? -1 : 63-clz(x);}
int AP (char *s) {
	unsigned hash=0;
	for(int i=0; s[i]; i++){
		if (i & 1) hash ^= (~((hash<<11)^s[i]^(hash>>5)));
		else hash ^= ((hash<<7)^s[i]^(hash>>3));
   } return hash & 0x7FFFFFFF;
}

int main () {
	int a, b;
	scanf ("%d%d", &a,&b);
	if (a==1) a+=13;
	if (b==1) b+=13;
	if (a>b) puts("Alice");
	else if (a==b) puts("Draw");
	else puts ("Bob");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	double d;
	cin >> d;
	cout << fixed << setprecision(9) << max(floor(d) + 1,sqrt(2) * d) << endl;
  return 0;
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> snuke(n+1);
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      int a;
      cin >> a;
      snuke[a] ++;
    }//j
  }//i
  int ans = 0;
  rep1(i,n) if(snuke[i] == 0) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3624
import Prelude hiding (log)
import Control.Monad
-- import Control.Arrow ((&&&))
import Data.Array
import qualified Data.Set as S
-- import Data.List (nub, sort, group)
-- import Data.Maybe (fromMaybe)
-- import qualified Data.IntMap as M
type Lights = Array Int Int
type Log = S.Set Int

main :: IO ()
main = do
    n <- readLn
    as <- conv n <$> replicateM n readLn
    print $ solve (as, 0, S.empty) 1

-- |
--
-- >>> solve (conv 3 [3,1,2],0, S.empty) 1
-- 2
--
-- >>> solve (conv 4 [3,4,1,2],0, S.empty) 1
-- -1
--
-- >>> solve (conv 5 [3,3,4,2,4],0, S.empty) 1
-- 3
solve :: (Lights, Int, Log) -> Int -> Int
solve (as, cnt, log) x
  | y == 2       = cnt + 1
  | y `S.member` log = -1
  | otherwise    = solve (as, cnt + 1, x `S.insert` log) y
  where y = as ! x

conv :: Int -> [Int] -> Lights
conv n as = array (1, n) (zip [1 .. n] as)


Measured memory_bytes: 44540
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int H = s.nextInt();
        int W = s.nextInt();
        int K = s.nextInt();
        int count = 0;

        char[][] c = new char[H][W];

        for (int i = 0; i < H; i++) {
            c[i] = s.next().toCharArray();
        }

        int x = (int) Math.pow(2, H + W);
        boolean[] bool = new boolean[H + W];

        for (int i = 0; i < x; i++) {
            int temp = i;
            for (int j = 0; j < H + W; j++) {
                bool[j] = temp % 2 != 0;
                temp /= 2;
            }

            int blackCount = 0;

            for (int k = 0; k < H; k++) {
                for (int l = 0; l < W; l++) {
                    if(bool[k] && bool[l + H]){
                        if(c[k][l] == '#') blackCount++;
                    }
                }
            }

            if(K == blackCount) count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 36436
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    A, B = InputToInt()
    if (A-B)%2 == 1:
        print('IMPOSSIBLE')
    else:
        print(abs(int((A+B)/2)))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main()
{
int n;
cin >> n;
vector<int> vec(n);
for(int i=0;i<n;i++) cin >> vec[i];
sort(vec.begin(),vec.end());
int ans = 0;

for(int i = 0;i<n;i++){
	for(int j = 0;j<i;j++){
		for(int k = 0;k<j;k++){
			if(vec[k] != vec[j] and vec[i] != vec[j]
			and vec[k] + vec[j] > vec[i]){
				ans++;
			}
		}
	}
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a < b)
        if (b < c)
            printf("%d %d %d\n",a,b,c);
        else if (c < a)
            printf("%d %d %d\n",c,a,b);
        else
            printf("%d %d %d\n",a,c,b);
    else 
    if (a<c)
        printf("%d %d %d\n",b,a,c);
    else if (c<b)
        printf("%d %d %d\n",c,b,a);
    else
        printf("%d %d %d\n",b,c,a);
     
    return 0;
}

Measured memory_bytes: 2684
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i;
        String line=sc.nextLine();
        String answer="";
        int length=line.length();
        for(i=0;i<length;i++){
            char ch =line.charAt(i);
            if(Character.isLowerCase(ch)==true){
                answer+=Character.toUpperCase(ch);
            }else{
                answer+=Character.toLowerCase(ch);
            }
        }
        System.out.println(answer);
    }
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
char tmp[20000];
int cnt=0;
int mminus(int num){
  if(num==1)return 1;
  else if(num==2)return 0;
  else return 2;
}
int dfs(){
  if(tmp[cnt]=='('){
    cnt++;
    int le=dfs();
    cnt++;
    if(tmp[cnt]=='*'){
      cnt++;
      int ri=dfs();
      cnt++;
      //cout<<le<<" "<<ri<<endl;
      if(le==2&&ri==2){
	return 2;
      }else if(le!=0&&ri!=0){
	return 1;
      }else
	return 0;
    }else if(tmp[cnt]=='+'){
      cnt++;
      int ri=dfs();
      cnt++;
      if(le==0&&ri==0)return 0;
      else if(le==2||ri==2)return 2;
      else return 1;
    }
  }else if(tmp[cnt]=='-'){
    cnt++;
    return mminus(dfs());
  }else{
    return (int)(tmp[cnt]-'0');
  }
}
int main(){
  string s;
  while(cin>>s,s!="."){
    for(int i=0;i<20000;i++)
      tmp[i]='\0';
    int ans=0;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
	for(int k=0;k<3;k++){
	  for(int l=0;l<s.size();l++){
	    if(s[l]=='P'){
	      tmp[l]=(char)(i+'0');
	    }else if(s[l]=='Q'){
	      tmp[l]=(char)(j+'0');
	    }else if(s[l]=='R'){
	      tmp[l]=(char)(k+'0');
	    }else{
	      tmp[l]=s[l];
	    }
	  }
	  cnt=0;
	  if(dfs()==2)ans++;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



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

int main() {
    int s, h, m;
    cin >> h;
    s = h % 60;
    h -= s;
    m = h % 3600;
    h -= m;
    cout << h/3600 << ":" << m/60 << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3136
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 1024;
const long long INF = 1000000000000000001LL;

int n;
int a[MAX][3];

long long eval(int cx, int cy) {
    long long left = 1, right = INF;
    while (left <= right) {
        long long mid = (left + right) / 2;
        bool smaller = false, larger = false;
        for (int i = 0; i < n; i++) {
            long long h = max(mid - abs(a[i][0] - cx) - abs(a[i][1] - cy), 0LL);
            if (h > a[i][2]) {
                larger = true;
                break;
            }
            if (h < a[i][2]) {
                smaller = true;
                break;
            }
        }
        if (larger) {
            right = mid - 1;
        } else if (smaller) {
            left = mid + 1;
        } else return mid;
    }
    return -1;
}

/*
long long eval(int cx, int cy) {
    long long h = -1;
    for (int i = 0; i < n; i++) {
        if (h != -1) {
            long long exp = h - abs(a[i][0] - cx) - abs(a[i][1] - cy);
            if (a[i][2] != max(exp, 0LL))
                return -1;
        }
        if (a[i][2] == 0)
            continue;
        if (h == -1) {
            h = (long long)a[i][2] + (long long)abs(a[i][0] - cx) + (long long)abs(a[i][1] - cy);
        }
    }
    return h;
}
*/

int main(void) {
	// in = fopen("C.in", "rt");
	
	fscanf(in, "%d", &n);
	for (int i = 0; i < n; i++)
	    fscanf(in, "%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
	
	for (int ansX = 0; ansX <= 100; ansX++) {
	    for (int ansY = 0; ansY <= 100; ansY++) {
	        long long h = eval(ansX, ansY);
	        if (h >= 1) {
	            fprintf(out, "%d %d %lld\n", ansX, ansY, h);
	            return 0;
            }
        }
    }
	
	return 0;
}

Measured memory_bytes: 128
import java.lang.Math.*

fun main(args: Array<String>){
    val (n, w) = readLine()!!.split(" ").map { it.toInt() }
    val weight = IntArray(n)
    val value = IntArray(n)
    for (i in 0 until n) {
        val tmp = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
        weight[i] = tmp[0]
        value[i] = tmp[1]
    }
    val vSum = value.sum()

    val dp = Array(n + 1) { LongArray(vSum + 1) { pow(10.0, 10.0).toLong() } }
    dp[0][0] = 0L

    for (i in 0 until n) {
        for (j in 0 until vSum + 1) {
            if (j - value[i] >= 0) {
                dp[i + 1][j] = min(dp[i][j - value[i]] + weight[i], dp[i][j])
            } else {
                dp[i + 1][j] = dp[i][j]
            }
        }
    }

    var min = 0
    for (i in dp[n].indices){
        if (dp[n][i] <= w) min = i
    }
    println(min)
}

Measured memory_bytes: 152080
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

class APoor {
public:
	void solve(std::istream& in, std::ostream& out) {
        vi a(3);
        f(i,0,3) s(a[i]);
        sort(range(a));
        if((a[0] == a[1] && a[1]!=a[2]) || (a[2] == a[1] && a[1]!=a[0])) out<<"Yes"<<endl;
        else out<<"No"<<endl;
	}
};


integer main() {
	APoor solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100000

int binarySearch(int[],int[],int,int);

int main(){
    
    int i,n,q;
    
    scanf("%d",&n);
    
   if(n<=N){
        
        int s[N];
        
        for(i=0 ; i<n ; i++){
            scanf("%d",&s[i]);
        }

        scanf("%d",&q);
        
       if(q<=N){
            
            int t[N];
            
            for(i=0 ; i<q ; i++){
                scanf("%d",&t[i]);
            }
            
            printf("%d\n",binarySearch(s,t,n,q));

        }
    }
    return 0;
}


int  binarySearch(int s[N],int t[N],int n,int q){
    int count=0,key,i,mid,left=0,right = n;
    for(i=0;i<q;i++){
        key = t[i];
        left = 0;
        right = n;
        while(left<right){
            mid = (left+right)/2;
            if(s[mid] == key){
                count++;
                break;
            }
            else if(key<s[mid]) right = mid;
            else left = mid + 1;
        }
    }
    return count;
}



Measured memory_bytes: 2332
import math

n, d = map(int, input().split())
a = []
for i in range(n):
  a.append(list(map(int, input().split())))
  
def dist(x, y):
  ret = 0
  for i in range(len(x)):
    ret += (x[i]-y[i]) * (x[i]-y[i])
  return ret
    
ans = 0
for i in range(n):
  for j in range(i+1, n):
    d = math.sqrt(dist(a[i], a[j]))
    if d == int(d):
      ans += 1
      
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 2000000
int H,A[MAX+1];
void swap(int *a, int *b) {
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}
void maxHeapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
  if(l<=H && A[l]>A[i])largest =l;
  else largest =i;
  if(r<=H && A[r]>A[largest])largest = r;
  if(largest != i){
    swap(&A[i],&A[largest]);
    maxHeapify(largest);
  }
}

int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);
  for(i=H/2;i>=1;i--)maxHeapify(i);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3736
#include <stdio.h>

int main(void)
{
    int N,H,W;
    
    if(scanf("%d %d %d",&N, &H, &W) == 1){};
    
    int A[N];
    int B[N];
    
    int i;
    int num=0;
    
    for(i=0; i<N; i++){
        if(scanf("%d", &A[i]) == 1){};
        if(scanf("%d", &B[i]) == 1){};
    }
    
    for(i=0; i<N; i++){
        if(A[i] >= H && B[i] >= W){
            num++;
        }
    }
    
    printf("%d\n", num);
    return 0;
    
}




Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    if(N <= 5){
        cout<<N<<endl;
        return 0;
    }
    ll rest = N % 3;
    N -= rest;
    ll ans = 1e+9;
    vec bit6(6,6), bit9(5,9);
    reps(i,1,6) bit6[i] = bit6[i-1] * 6;
    reps(i,1,5) bit9[i] = bit9[i-1] * 9;
    for(ll for6 = 0; for6 <= N; for6 += 6){
        ll temp = 0;
        M = for6; L = N - for6;
        for(ll i = 5; i >= 0; --i){
            temp += M / bit6[i];
            M %= bit6[i];
        }
        for(ll i = 4; i >= 0; --i){
            temp += L / bit9[i];
            L %= bit9[i];
        }
        if(L == 0) ans = min(ans, temp);
    }
    cout<<ans + rest<<endl;
}


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

#define Abigail inline void
typedef long long LL;

const int N=100000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,a[N+9],g[2][N+9],mx; 

Abigail into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i)
    scanf("%d",&a[i]); 
}

Abigail work(){
  g[0][1]=a[1];
  for (int i=2;i<=n;++i)
    g[0][i]=gcd(g[0][i-1],a[i]);
  g[1][n]=a[n];
  for (int i=n-1;i>=1;--i)
    g[1][i]=gcd(g[1][i+1],a[i]);
  mx=max(g[0][n-1],g[1][2]);
  for (int i=2;i<n;++i)
    mx=max(mx,gcd(g[0][i-1],g[1][i+1]));
}

Abigail outo(){
  printf("%d\n",mx);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>
#define MAX 1000000
int main(void) {
    int a,d,n,i,j,sieve[MAX+1]={0};
    sieve[1]=1;
    for (i=2; i<=sqrt(MAX); i++) {
        if (sieve[i]==0) {
            for (j=2*i; j<=MAX; j+=i) sieve[j]=1;
        }
    }
    while (scanf("%d %d %d",&a,&d,&n)!=EOF&&(a!=0||d!=0||n!=0)) {
        i=0;
        while (n!=0) {
            if (sieve[a+i*d]==0) {
                n--;
            }
            i++;
        }
        printf("%d\n",a+(i-1)*d);
    }
    return 0;
}

Measured memory_bytes: 4512
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
char s[2001];
vector <int> v[2000];

pair<int, pair<int, int>> dfs(int x, int y) {
    int c1 = 0, c2 = 0, c3 = 0, m = 0, sum = 0, i;
    
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) continue;
        
        pair<int, pair<int, int>> p = dfs(v[x][i], x);
        
        c1 += p.first;
        c2 += p.second.first + p.first;
        c3 += p.second.second;
        m = max(m, p.second.first + p.first - p.second.second * 2);
        sum += p.second.first + p.first - p.second.second * 2;
    }
    
    c3 += min(sum - m, sum / 2);
    
    if (s[x] == '1') c1++;
    
    return make_pair(c1, make_pair(c2, c3));
}

int calc(int x) {
    int sum = 0, m1 = 0, m2 = 0, i;
    
    for (i = 0; i < v[x].size(); i++) {
        pair<int, pair<int, int>> p = dfs(v[x][i], x);
        p.second.first += p.first;
        
        if (p.first > 0) {
            sum += p.second.first;
            if (p.second.first > m1) {
                m1 = p.second.first;
                m2 = p.second.second;
            }
        }
    }
    
    if (sum % 2 == 0 && m1 - m2 * 2 <= sum - m1) {
        return sum / 2;
    } else {
        return 1e9;
    }
}

int main() {
    int ans = 1e9, i;
    
    scanf("%d", &n);
    scanf("%s", s);
    
    for (i = 0; i < n - 1; i++) {
        int a, b;
        
        scanf("%d %d", &a, &b);
        a--;
        b--;
        
        v[a].push_back(b);
        v[b].push_back(a);
    }
    
    for (i = 0; i < n; i++) {
        /*
        pair<int, pair<int, int>> p = dfs(i, -1);
        if (p.second.first % 2 == 0 && p.second.second == p.second.first / 2) ans = min(ans, p.second.second);
        */
        ans = min(ans, calc(i));
    }
    
    if (ans == 1e9) ans = -1;
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  vi data(3);
  rep(i,3) cin >> data[i];
  sort(data.begin(), data.end());
  int sum = 0;
  int a = data[1] - data[0];
  a = max(a,-a);
  int b = data[2] - data[1];
  b = max(b,-b);
  sum += a + b;
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

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

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

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    if(k == 0){
        pf(n * n);
        return 0;
    }
    rep1(b, n){
        if(b <= k)continue;
        ans += n / b * (b - k) + max(ll(n % b - k + 1),0ll);
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    /*ll n, m; cin >> n >> m;
    vector<pair<ll,ll>> p(m);
    rep(i, m) cin >> p[i].first >> p[i].second;
    vector<pair<ll,ll>> q(m);
    rep(i, m) cin >> p[i].first >> p[i].second;*/
    ll n, a, b; cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    ll ans = 0;
    _rep(i, 1, n){
        ans += min(a * (x[i] - x[i - 1]), b);
    }
    cout << ans << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int x = 0;

  for (int i = A; i < B+1; i++){
    if ((i%10==i/10000) && ( (i/10)%10==(i/1000)%10)){
      x ++;
    }
  }
  cout << x << endl;
}
      
  

Measured memory_bytes: 256
using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;

class Program
{
    static void Main()
    {
        string[] arr = Console.ReadLine().Split();
        int A, B;
        A = int.Parse(arr[0]);
        B = int.Parse(arr[1]);
        Console.WriteLine(2 * B < A ? A - 2 * B : 0);
        return;
    }
}

Measured memory_bytes: 27380
#include <iostream>
using namespace std;
int main(){
 
  int n,m,l,i,j,k;
  long am[100][100],bm[100][100],cm[100][100]={};
 
  cin>>n>>m>>l;
  for(i=0; i<n; i++)for(j=0; j<m; j++)cin>>am[i][j];
  for(j=0; j<m; j++)for(k=0; k<l; k++)cin>>bm[j][k];
  for(i=0; i<n; i++)for(k=0; k<l; k++)for(j=0; j<m; j++)cm[i][k]+=am[i][j]*bm[j\
][k];
 
  for(i=0; i<n; i++){
    for(k=0; k<l; k++){
            if(k==l-1){
        cout<<cm[i][k]<<"\n";
        break;
      }
 
      cout<<cm[i][k]<<" ";
    }
  }
}


Measured memory_bytes: 3320
import java.util.*;

//https://beta.atcoder.jp/contests/arc102/submissions/3118322

class Edge{
	int a,b,c;
	public Edge(int a,int b,int c){
		super();
		this.a=a;
		this.b=b;
		this.c=c;
	}
	@Override
	public String toString(){
		return a+" "+b+" "+c;
	}
}

class Main{
	static int nextBit(StringBuilder str,int idx){
		int v=str.indexOf("1",idx+1);
		return v==-1?str.length()-1:v;
	}

	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int L=s.nextInt()-1;
		if(L==1){
			System.out.println("2 2\n1 2 0\n1 2 1");
			return;
		}

		boolean f=false;
		StringBuilder sb=new StringBuilder();
		Map<Integer,Integer> m=new HashMap<>();
		
		for(int i=20;i>=0;i--){
			boolean b=(L&(1<<i))==0;
			if(!f&&b)
				continue;
			f=true;
			m.put(sb.length(),1<<i);
			sb.append(b?0:1);
		}

		List<Edge> ret=new ArrayList<>();

		for(int i=1;i<sb.length();++i){
			ret.add(new Edge(i,i+1,0));
			ret.add(new Edge(i,i+1,m.get(i)));
		}

		int num=0;
		for(int i=0;i<sb.length();++i){
			if(sb.charAt(i)=='0')
				continue;
			num+=m.get(i);
			ret.add(new Edge(1,nextBit(sb,i)+1,num));
		}

		System.out.println(sb.length()+" "+ret.size());
		ret.forEach(System.out::println);
	}
}


Measured memory_bytes: 26580
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
//template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a,c=0;
  cin>>a;
  vector<int> b(a-1);
  fo(i,a)
    cin>>b[i];
  c+=b[0];
  for(int i=0;i<a-2;i++){
    c+=min<int>(b[i],b[i+1]);
  }
  cout<<c+b[a-2]<<endl;
}

Measured memory_bytes: 256
A = [4,6,9,11]
x,y = map(int,input().split())
if x in A:
  x = 4
elif x != 2:
  x = 3
if y in A:
  y = 4
elif y != 2:
  y = 3
if x == y:
  print('Yes')
else:
  print('No')


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

int main() {
    int m = 0;
    int l = 0;
    string n;
    cin >> n;
    n += 'p';
    for(int i = 0; i < n.size(); i++){
        if(n.at(i) == 'A' || n.at(i) == 'C' || n.at(i) == 'G' || n.at(i) == 'T'){
            m = 0;
            for(int j = 0; j + i < n.size(); j++ ){
                if(n.at(i + j) == 'A' || n.at(i + j) == 'C' || n.at(i + j) == 'G' || n.at(i + j) == 'T'){
                    m++;
                }else{
                    if(m > l){
                        l = m;
                    }
                    break;
                }
            }
        }
    }cout << l << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)

int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  map<string, int> a;
  vector<int> s;

  rep(i, n) {
    string temp;
    cin >> temp;
    a[temp] += 1;
  }
  int maxv = 0;
  for (auto x : a) {
    int v = x.second;
    if (v > maxv) maxv = v;
  }
  for (auto i : a) {
    if (i.second == maxv) {
      cout << i.first << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a,b;
int main() {
	string s;
	cin >> s;
	for (int i=0;i<s.length();i++) {
		if (s[i] == 'S') a++;
		else if (a > 0) a--;
		else b++;
	}
	cout << b*2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char b; 
  cin >>b;
  if(b=='A')cout <<"T";
  else if(b=='T')cout <<"A";
  else if(b=='G')cout <<"C";
  else if(b=='C')cout <<"G";
}
  


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

const bool DEBUG = false;

long long N, A, B;

void input() { cin >> N >> A >> B; }

int main(int argc, char const *argv[]) {
  input();

  long long result = N / (A + B) * A + min(N % (A + B), A);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i=0; i<n; i++) a[i] = sc.nextLong();
        sc.close();

        long ans = 0;
        for(int i=0; i<n; i++){
            long min = Math.max(n, Arrays.stream(a).min().getAsLong());
            // min += Math.max(0, (a[i]-min)/n);
            // if(i==0) min = n;
            // long rem = Math.max(0, a[i] - min);
            // long div = rem / n;
            long div = (a[i] - min) / (n+1);
            ans += div;
            a[i] -= div * n;
            for(int j=0; j<n; j++){
                if(i==j) continue;
                a[j] += div;
            }
        }
        
        long min = Arrays.stream(a).min().getAsLong();
        if(min >= n){
            ans += (min - n + 1) * n;
            for(int i=0; i<n; i++){
                a[i] -= (min - n + 1);
            }
        }

        while(true){
            int maxpos = 0;
            long max = Long.MIN_VALUE;
            for(int i=0; i<n; i++){
                if(a[i] > max){
                    max = a[i];
                    maxpos = i;
                }
            }
            if(max < n) break;
            ans++;
            a[maxpos] -= n;
            for(int i=0; i<n; i++){
                if(i == maxpos) continue;
                a[i]++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 29012
N = int(input())
D, X = map(int, input().split(" "))

result = X
for i in range(N):
    A = int(input())
    if A == 1:
        result += D
        continue
    if A < D:
        result += 1 + (D - 1) // A
        continue
    result += 1

print(result)


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> As(N);
    for (auto & a : As) cin >> a;
    sort(As.begin(), As.end());
    long long a1 = 0;
    long long a2 = 0;
    for (int i = 1; i < N; ++i){
        if (As[i] == As[i - 1]){
            a1 = a2;
            a2 = As[i];
            ++i;
        }
    }
    cout << a1 * a2 << endl;
    return 0;
}

Measured memory_bytes: 640
//The Number of Even Pairs

#include<iostream>
using namespace std;

int main (){
    int n, m, ans;
    cin >> n >> m;
    if (n==1&&m==1){
        ans = 0;
    }else{
        ans=n*(n-1)/2+m*(m-1)/2;
    }
    cout << ans << endl;
    return 0;
}

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

int main () {
int A, B, C; cin >> A >> B >> C;
int K; cin >> K;

// A < B < C
for (int i = 0; i < K; i++){
	if (!(A < B)) {
  	B *= 2;
	} else if(!(B < C)) {
  	C *= 2;
	} else {
		C *= 2;
	}
}
if (A < B && B < C)
	cout << "Yes" << endl;
else
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3560
N, M, C = map(int,input().split())
b = list(map(int,input().split()))
x=0
a=[[0]*20]*20
for i in range(N):
	a[i]=list(map(int,input().split()))
for i in range(N):
	work=0
	for h in range(M):
		work += a[i][h] * b[h]
	x += (1 if work + C > 0 else 0)
print(x)

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<vector<int>> P(N, vector<int>(3));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> P[i][j];
        }
    }

    vector<vector<int>> dp(N + 1, vector<int>(3));
    dp[1][0] = P[0][0];
    dp[1][1] = P[0][1];
    dp[1][2] = P[0][2];
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + P[i][k]);
            }
        }
    }
    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
stack <char> s;
int main()
{
        char a[100005];
        int sum=0;
        cin>>a;
        for(int i=0;i<=strlen(a)-1;i++)
        {
                if(s.empty()||s.top()==a[i])
                        s.push(a[i]);
                else
                {
                        s.pop();
                        sum+=2;
                }
        }
        printf("%d\n",sum);
        return 0;
}

Measured memory_bytes: 1016