akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)



Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		a[i] = x == y;
	}
	rep(i, n - 2) {
		if (a[i] && a[i + 1] && a[i + 2]) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define in(n, arr) for (int i = 0; i < n; ++i) cin >> arr[i]
#define out(n, arr) for (int i = 0; i < n; ++i) cout << arr[i] << " "
 
using namespace std;
long long int solve(long long int** dp, long long int* arr, long long int l, long long int r)
{
	if(l > r)
		return  0;
	if(l == r)
		return arr[l];
	if(dp[l][r]!=-1)
		return dp[l][r];
	long long int ans = arr[l] - solve(dp,arr,l+1,r);
	ans = max(ans,arr[r]-solve(dp,arr,l,r-1));
	dp[l][r] = ans;
	return ans;

}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
	#endif
	int t;
	cin >> t;
	long long int* arr = new long long int[t]();
	for(int  i =0; i<t; i++)
		cin >> arr[i];
	long long int** dp = new long long int*[t];
	for(int  i = 0; i<t; i++)
		dp[i] = new long long int[t];
	for(int i =0; i<t; i++)
	{
		for(int  j = 0; j<t; j++)
			dp[i][j] = -1;
	}
	cout << solve(dp, arr, 0, t-1) << endl;



return 0;
}

Measured memory_bytes: 74264
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;
const int MX = 1e5+5;
int dp[105][MX];
vector <int> v,w,valid;
int V,n,W;

int solve(int ind,int left){
    if(ind == n+1 && left == 0) return 0;
    if(ind == n+1) return 1e17;
    if(dp[ind][left] != -1) return dp[ind][left];
    long long ans = 1e17;
    ans = min(ans, solve(ind+1,max(0LL, left - v[ind]))+w[ind]);
    ans = min(ans, solve(ind+1,left));
    return dp[ind][left] = ans;
}

int32_t main()
{
    memset(dp,-1,sizeof dp);
    cin>>n>>W;
    v.resize(n+1);
    w.resize(n+1);
    for(int i=1 ; i<=n ; i++) cin>>w[i]>>v[i];
    for(int i=100000 ; i >= 0; i--){
        int ans = solve(1,i);
        if(ans <= W) return cout<<i, 0;
    }
    return 0;
}


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

int main() {
  int n,max = 0;
  cin >> n;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data.at(i);
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(abs(data.at(i)-data.at(j)) > max){
        max = abs(data.at(i)-data.at(j));
      }
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 256
def solve():
    maxCards, gates = map(int, input().split())
    gateRanges = [tuple(map(int, input().split())) for i in range(gates)]

    for i, permitRange in enumerate(gateRanges):
        if i == 0:
            activeBegin, activeEnd = permitRange
            continue
        begin, end = permitRange
        if not (begin <= activeEnd and end >= activeBegin):
            return print(0)
        else:
            activeBegin, activeEnd = max(activeBegin, begin), min(activeEnd, end)
    else:
        if (maxCards < activeBegin):
            return print(0)
        ans = min(activeEnd, maxCards) - activeBegin + 1
    print(ans)
solve()

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a[100000],b[100000],sum,cnt;
vector<int> v;

main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) v.pb(a[i]-b[i])
    sort(all(v));
    rep(i,v.size()) {
        if (v[i]<0) sum += v[i];
        else break;
        cnt++;
    }
    repm(i,v.size()) {
        if (sum>=0) {
            ct(cnt)
            return 0;
        }
        if (v[i]<=0) break;
        sum+=v[i];
        cnt++;
    }
    ct(-1)
}


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

int main() {
  int x, y;
  cin >> x >> y;
  int z = x*y;
  if (z % 2 == 0) {
    cout << "Even" << endl;
  }
    else {
      cout << "Odd" << endl;
    }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, W int
	fmt.Scan(&N, &W)
	w := make([]int, N)
	v := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&w[i], &v[i])
	}
	var dp [101][100010]int

	for i := 0; i < N; i++ {
		for j := 0; j <= W; j++ {
			if w[i] <= j {
				dp[i+1][j] = Max(dp[i][j], dp[i][j-w[i]]+v[i])
			} else {
				dp[i+1][j] = dp[i][j]
			}
		}
	}
	fmt.Println(dp[N][W])
}
func Max(a, b int) int {
	if b > a {
		return b
	}
	return a
}


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

using namespace std;
typedef long long ll;
const int MAX=1000050;
int f[MAX],zs[MAX];
int a[MAX],b[MAX],t=1,cnt=0;
void qzs(void)
{
    f[1]=f[2]=0;
    zs[0]=1;
    for(int i=2;i<MAX;i++){
        for(int j=2;!f[i]&&j*i<MAX;j++)
            f[j*i]=1;
        if(!f[i])
            zs[t++]=i;
    }
}
ll gcd(ll a,ll b)
{
    ll r=1;
    while(b)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int main()
{
    qzs();
  //  cout << zs[t-1] << endl;
    ll A,B;
    cin >> A >> B;
    ll aa=gcd(A,B),flag=0;
    int i=1;
    while(aa!=1&&i<t)
    {
        while(aa%zs[i]==0){
            aa/=zs[i];
            flag=1;
        }
        if(flag)
            cnt++;
        flag=0;
        i++;
    }
    if(aa!=1)
        cnt++;

    cout << cnt+1 << endl;
    return 0;
}


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

int main(){

while(1){   
    string str;
    int sum=0;
   /* cin>>str;*/
   getline(cin, str);
    if(str=="0"){
        break;
    }

    

for(int i=0;i<str.size();i++){
    sum+=str[i]-'0';
}
cout<<sum<<endl;
}
    return 0;
}


Measured memory_bytes: 3172
#include<iostream>

using namespace std;

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

	if(n<=111) 
	{
		cout<<111;
		return 0;
	}
	else if(n>111&&n<=222)
	{
		cout<<222;
		return 0;
	}
	else if(n>222&&n<=333)
	{
		cout<<333;
		return 0;
	}
	else if(n>333&&n<=444)
	{
		cout<<444;
		return 0;
	}
	else if(n>444&&n<=555)
	{
		cout<<555;
		return 0;
	}
	else if(n>555&&n<=666)
	{
		cout<<666;
		return 0;
	}
	else if(n>666&&n<=777)
	{
		cout<<777;
		return 0;
	}
	else if(n>777&&n<=888)
	{
		cout<<888;
		return 0;
	}
	else if(n>888&&n<=999)
	{
		cout<<999;
		return 0;
	}
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = in.nextIntArray(m);
        int sum = Arrays.stream(a).sum();

        out.println(n < sum ? -1 : n - sum);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

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


Measured memory_bytes: 35812
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first    
#define se second
#define mod 1000000007
void solve()
{
    string s,t;
    cin>>s>>t;
    ll ans=0;
    ans=(s[0]==t[0])+((s[1]==t[1]))+(s[2]==t[2]);
    cout<<ans;
}
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif  
    clock_t tStart = clock();
    ll t;
    // cin>>t;
    // while(t--)
       solve();
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}       

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

using namespace std;

#define ll long long
#define PI 3.14159265358979323846264338327950L

int a[101];
int n,k,d,t;

void solve(){

    cin >> n >> k;

    for (int i = 0; i < n; i++)
    {
        a[i] = 0;
    }
    

    for (int i = 0; i < k; i++)
    {
        cin >> d;

        for (int h = 0; h < d; h++)
        {
            cin >> t;
            t--;
            a[t] = 1;
        }
        
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if(a[i] ==0 ) ans++;
    }
    
    cout << ans << endl;
}





int main(){

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

    solve();

}

Measured memory_bytes: 3628
using System;
using System.Diagnostics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);
        Array.Sort(A);

        int ans = A[N / 2] - A[N / 2 - 1];
        Console.WriteLine(ans);

    }
    

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}




Measured memory_bytes: 24032
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid

    def pos(self, x, y):
        return y * (self.w + 2) + x + 1

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]

        ans = 0
        for i in range(1, self.h + 1):
            for j in range(1, self.w + 1):
                pass # ここから何か書いてね

def solve():
    n = getN()
    anums = getList()
    bnums = getList()
    cnums = getList()
    anums.sort()
    bnums.sort()
    cnums.sort()
    ka = [0]
    for bnum in bnums:
        ka.append(bisect_left(anums, bnum))


    for i in range(len(ka) - 1):
        ka[i+1] += ka[i]
    # print(ka)
    ans = 0
    for cnum in cnums:
        ans += ka[bisect_left(bnums, cnum)]

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 105228
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>

#define forn(a,n) for(int i=(a);i<(n);i++)
using namespace std;
const long long N=2000+3;
typedef long long ll;

int a[N];
int main()
{
//    ios::sync_with_stdio(false);
//    freopen("a.in","r",stdin);
//    freopen("a.out","w",stdout);

    int a,b,t;
    cin>>a>>b>>t;
    cout<<t/a*b;
return 0;
}


Measured memory_bytes: 256
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over= reduce(mul,range(n,n-r,-1))
    under = reduce(mul,range(1,r + 1))
    return over // under


N,P = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))

ae = [0,0]
ans = 0

for i in range(N):
    ae[A[i] % 2] += 1
for i in range(1,ae[1] + 1,2):
    ans += cmb(ae[1] ,i)
ans *= 2 ** ae[0]

if P == 1:
    print(ans)
else:
    print(2 ** N - ans)
    

Measured memory_bytes: 3700
N, M = map(int, input().split())
H = list(map(int, input().split()))

P = [[] for _ in range(N)]

for j in range(M):
    A, B = map(int, input().split())
    P[A-1].append(H[B-1])
    P[B-1].append(H[A-1])

good = 0
for n in range(N):
    if len(P[n]) == 0 or H[n] > max(P[n]):
        good += 1
print(good)

Measured memory_bytes: 22956
#include<stdio.h>
int main(){
	int i,k[31]={0},x;
	for(i=0;i<28;i++){
		scanf("%d",&x);
		k[x-1]=1;
	}
	for(i=0;i<30;i++)if(k[i]==0)printf("%d\n",i+1);
	return 0;
}



Measured memory_bytes: 2100
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int N, x;
  cin >> N >> x;
  cout << (N-x+1) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

namespace {

	int cnt;
	void InsertionSort(vector<int>& A, int g)
	{
		for (int i = g; i < A.size(); ++i)
		{
			int v = A[i];
			int j = i - g;

			while (j >= 0 && A[j] > v) {
				A[j + g] = A[j];
				j -= g;
				cnt++;
			}

			A[j + g] = v;
		}
	}

	void ShellSort(vector<int>& A)
	{
		cnt = 0;
		vector<int> G;
		G.push_back(1);
		for (int i = 1; i <= A.size(); ++i)
		{
			int g = pow(4, i) + 3 * pow(2, i - 1) + 1;
			if (g > A.size()) break;
			else G.push_back(g);
		}
		reverse(G.begin(), G.end());

		for (auto i : G)
			InsertionSort(A, i);

		cout << G.size() << endl;
		cout << G[0];
		for (auto it = G.begin() + 1; it != G.end(); ++it)
			cout << ' ' << *it;
		cout << endl;
		cout << cnt << endl;
		for (auto i : A)
			cout << i << endl;
	}
}

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

	int n;
	cin >> n;

	vector<int> A(n);
	for (auto& i : A) cin >> i;

	ShellSort(A);

	return 0;
}

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

template<typename T>
vector<T> cumulative_sum(vector<T> &v) {
    vector<T> sum(v.size() + 1);
    rep(i,v.size()){
        sum[i+1] = sum[i] + v[i];
    }
    return sum;
}

int main(void){
    int n;
    ll K;
    cin >> n >> K;
    vector<P> vp(n);
    rep(i,n) {
        ll t,d;
        cin >> t >> d;
        vp[i] = {d,t};
    }
    sort(all(vp),greater<P>());
    map<ll,bool> used;
    vector<ll> top, rem;
    rep(i,n) {
        ll t = vp[i].second;
        ll d = vp[i].first;
        if (used[t]) {
            rem.push_back(d);
        } else {
            used[t] = true;
            top.push_back(d);
        }
    }
    auto top_sum = cumulative_sum(top);
    auto rem_sum = cumulative_sum(rem);
    ll res = 0;
    for(ll x = 1; x <= K; x++){
        if (x >= (ll)top_sum.size()) continue;
        if (K < x) continue;
        if (K-x >= (ll)rem_sum.size()) continue;
        res = max(res, top_sum[x] + rem_sum[K-x] + x*x);
    }
    cout << res << endl;
    return 0;
}


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

int main() {
    string s, t; cin >> s >> t;
    vector<string> ss(2);
    for (int i = 0; i < (int)s.size(); i++) ss[i & 1] += s[i];
    auto check = [&](string &sub) {
        int p = 0, n = sub.size();
        for (char c: t) if (c == sub[p]) if (++p == n) return true;
        return p == n;
    };
    cout << (check(ss[0]) || check(ss[1]) ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 3216
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <istream>
#include <algorithm>

#ifdef _MSC_VER
#define scanf scanf_s
#define KEYWAIT getchar();getchar();
#else
#define KEYWAIT
#endif

int n,a[100][2];

int solve(int x, int y) {
    if (x == n-1 && y == 1)return a[x][y];
    int mx = 0;
    if (y == 0)
        mx = std::max(mx, solve(x, y + 1));
    if (x < n - 1)
        mx = std::max(mx, solve(x + 1, y));
    return mx+a[x][y];
}

int main()
{

    std::cin >> n;
    for(int j=0;j<2;j++)
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i][j]);
        }

    std::cout << solve(0,0) << std::endl;

    KEYWAIT

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N, T;
    cin >> N >> T;
    int maxi = 10000;
    for(int i = 0; i < N; i++){
        int c, t;
        cin >> c >> t;
        if(t > T)continue;
        if(maxi > c){
            maxi = c;
        }
    }
    if(maxi == 10000){
        cout << "TLE" << endl;
    }else{
        cout << maxi << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
#include <limits.h>
using namespace std;
typedef long long LL;
const int N=2e5;

int n,k,x[N];
vector<int> a,b;

int main() {
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++) {
		scanf("%d",&x[i]);
	}
	int p=n+1;
	for(int i=1;i<=n;i++) {
		if(x[i]>=0) {
			p=i;break;
		}
	}
	if(p<=n && x[p]==0) {
		k--;
	}
	for(int i=p;i<=n;i++) {
		if(x[i]>0) a.push_back(x[i]);
	}
	for(int i=p-1;i>0;i--) {
		b.push_back(-x[i]);
	}
	int ans=1e9;
	if(k==0) ans=0;
	else {
		if(a.size()>=k) {
			ans=min(ans,a[k-1]);
		}
		if(b.size()>=k) {
			ans=min(ans,b[k-1]);
		}
		for(int i=1;i<k;i++) {
			if(i>a.size() || k-i>b.size()) continue;
			ans=min(ans,a[i-1]*2+b[k-i-1]);
			ans=min(ans,a[i-1]+b[k-i-1]*2);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1404
import numpy as np

def solve():
    N = int(input())
    AB = np.array([list(map(int, input().split() )) for _ in range(N)], dtype=np.int64)
    A = AB[:,0]
    B = AB[:,1]
    Amed = np.median(A)
    Bmed = np.median(B)
    if N % 2 ==1:
        print(int(Bmed - Amed+1))
    else:
        print(int((Bmed - Amed )*2+1))


if __name__ == '__main__':
    solve()

Measured memory_bytes: 66556
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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


Measured memory_bytes: 3568
import numpy as np

N, M = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB = np.array(AB)
AB_sorted = AB[AB[:,0].argsort(),:]

cs = np.cumsum(AB_sorted[:,1])
n_full_store = (cs <= M).sum()
money_a = np.sum(AB_sorted[:n_full_store,0] * AB_sorted[:n_full_store,1])
if M - cs[n_full_store-1] > 0:
    money_b = (M - cs[n_full_store-1]) * AB_sorted[n_full_store,0]
elif M - cs[n_full_store-1] < 0:
               money_b = AB_sorted[0,0] * M
else:
    money_b = 0
print(money_a + money_b)

Measured memory_bytes: 37876
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 (a>b) { a=b; return 1; } return 0; }
    
int main(){
    string n;
    cin >> n;
    int l = n.size();
    int ans = 0;
    rep(i,l){
        int c = n[i] - '0';
        ans += c;
        ans %= 9;
    }
    if(ans) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    int n;
    cin>>n;
    double ans = 0.0;
    for(int i = 0;i < n;i++) {
        int x;
        cin>>x;
        ans += 1.0 / x;
    }
    ans = 1.0 / ans;
    printf("%.12lf\n", ans);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin >> k;
    int a = 7%k;
    rep(i,k){
        if (a == 0){
            cout << i+1 << "\n";
            return 0;
        }
        a = (a * 10 + 7)%k;
    }
    cout << -1 << "\n";
}

Measured memory_bytes: 3616
import java.io.*;
import java.util.*;
class Main {
	public static void main (String[] args) {
		//System.out.println("GfG!");
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n+1];
		a[0]=0;
		for(int i=1;i<=n;i++)
		a[i]=sc.nextInt();
	    int dp[]=new int[n+1];
	    dp[0]=0;
	    dp[1]=0;
	    dp[2]=Math.abs(a[2]-a[1]);
	    for(int i=3;i<=n;i++){
	        dp[i]=Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),
	        dp[i-2]+Math.abs(a[i]-a[i-2]));
	    }
	    System.out.println(dp[n]);
	}
}

Measured memory_bytes: 50840
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int main(){
    int n, d;
    cin >> d >> n;
    if(d == 0){
        if(n == 100){
            cout << 101 << endl;
        }else{
            cout << n;
        }
    }
    if(d == 1){
        if(n == 100){
            cout << 10100 << endl;
        }else{
            cout << n * 100;
        }
    }
    if(d == 2){
        if(n == 100){
            cout << 1010000 << endl;
        }else{
            cout << n * 10000;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF=1LL<<60;
int main(){
    string s;cin >> s;
    string t="",u="";
    bool f=true;
    int q;cin >> q;
    while(q--){
        int x;cin >> x;
        if(x==1){
            f=!f;
        }
        else{
            int y;cin >> y;
            char c;cin >> c;
            if(y==1){
                if(f){
                    t+=c;
                }
                else{
                    u+=c;
                }
            }
            else{
                if(f){
                    u+=c;
                }
                else{
                    t+=c;
                }
            }
        }
    }
    reverse(t.begin(),t.end());
    string ans=t+s+u;
    if(!f){
        reverse(ans.begin(),ans.end());
    }
    cout << ans << endl;
}

Measured memory_bytes: 1348
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> num = new HashMap<Integer, Integer>();
		while(N --> 0) {
			int a = sc.nextInt();
			if(num.containsKey(a)) {
				num.put(a, num.get(a) + 1);
			} else {
				num.put(a, 1);
			}
		}
		int cnt = 0;
		for(Entry<Integer, Integer> entry:num.entrySet()) {
			int n = entry.getKey();
			int x = entry.getValue();
			if(n > x) {
				cnt += x;
			} else {
				cnt += x-n;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 63884
N, X, M = map(int, input().split())
A = [0]*(M+1)
A[0] = X
ls, rs = 0, 0
m = [-1]*(M+1)
m[X] = 0
for i in range(1, M+1):
    A[i] = (A[i-1]*A[i-1]) % M
    if m[A[i]] >= 0:
        ls = m[A[i]]
        rs = i
        break
    m[A[i]] = i

if rs == 0:
    print(sum(A[:N]))
else:
    if ls > N:
        print(sum(A[:N]))
    else:
        ans = sum(A[:ls])
        N -= ls
        w = rs-ls
        ans += sum(A[ls:rs])*(N//w)
        ans += sum(A[ls:ls+N % w])
        print(ans)


Measured memory_bytes: 66552
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		// 計算
		String result = "No";
		if((a+d-1)/d >= (c+b-1)/b) result = "Yes";
		
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 27088
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] NW = br.readLine().split(" ");
        int N = Integer.parseInt(NW[0]);
        int W = Integer.parseInt(NW[1]);
        int[][] vw = new int[N+1][2];
        
        for (int i = 0; i < N; i++) {
            String[] s = br.readLine().split(" ");
            vw[i+1][0] = Integer.parseInt(s[0]);
            vw[i+1][1] = Integer.parseInt(s[1]);
        }
        
        int[][] dp = new int[N+1][W+1];
        
        for (int i = 0; i <= N; i++) {
            dp[i][0] = 0;
        }
        
        for (int i = 0; i <= W; i++) {
            dp[0][i] = 0;
        }
        
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= W; j++) {
                if (j-vw[i][1] >= 0) {
                    dp[i][j] = Math.max(dp[i-1][j-vw[i][1]]+vw[i][0], dp[i-1][j]);
                }
                else dp[i][j] = dp[i-1][j];
            }
        }
        
        /*for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= W; j++) {
                if (j+1 == W) System.out.println(dp[i][j]);
                else System.out.print(dp[i][j] + " ");
            }
        }*/
        
        
        System.out.println(dp[N][W]);
    }
}

class Box {
    int w;
    int h;
    public Box(int w, int h) {
        this.w = w;
        this.h = h;
    }
}

class BoxComparator1 implements Comparator<Box>{
	public int compare(Box b1, Box b2) {
		return b1.w - b2.w;
	}
}

class BoxComparator2 implements Comparator<Box> {
    public int compare(Box b1, Box b2) {
        return b1.h - b2.h;
    }
}



Measured memory_bytes: 29116
//////////////////////////////////////
////       ABHINASH GIRI          ////
/////////////////////////////////////
#include<bits/stdc++.h>
using namespace std;
#define pr 4294967296   // 2^32
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define high 1000000001
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             -1e18
#define pinf              1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define e               1000000000
#define w(x)            int t; cin>>t; while(t--)
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define co(x) cout<<(x)<<"\n"
#define endl "\n"
typedef unsigned long int  ul;
//typedef unsigned long long int ull;
typedef unsigned long long  int  li;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<long int> vl;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long int,long int>> vpl;
typedef vector<pair<long long int,long long int>> vpll;
typedef long long ll;
int main() {
    std::chrono::time_point<std::chrono::high_resolution_clock> start_timer, end_timer;
    start_timer = std::chrono::high_resolution_clock::now();
    bool show_time = false;  //  change it to true when needed;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif

    /* Cook your Code  */
    fast;
    string s,t;
    cin>>s>>t;
    t.pop_back();
    if(s==t)
    {
        cout<<"Yes\n";
    }
    else cout<<"No\n";
    end_timer = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_timer-start_timer).count();
    if(show_time)
    {cout << "\\nElapsed Time: " << elapsed_time << "ms\\n";}

    return 0;
}

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

int main()
{
    int n, sum1 = 0, sum2 = 0;
    string s1, s2;
    cin >> n;
    for (int i = 0; i != n; ++i)
    {
        cin >> s1 >> s2;
        if (s1 == s2)
        {
            ++sum1;
            ++sum2;
        }
        else if (s1 > s2)
        {
            sum1 += 3;
        }
        else
        {
            sum2 += 3;
        }
    }
    cout << sum1 << " " << sum2 << endl;
    return 0;
}


Measured memory_bytes: 3156
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;
	final int MAX_N = 44;
	void run() {
		Scanner scan = new Scanner(System.in);
		int[] dp = new int[MAX_N + 1];
		dp[0] = dp[1] = 1;
		for (int i = 2; i <= MAX_N; i++)
			dp[i] = dp[i - 1] + dp[i - 2];
		int n = scan.nextInt();
		System.out.println(dp[n]);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 26124
#include <stdio.h>
#include <stdlib.h>

int partition(int *a,int p,int r){
  int i,j,x,alt;
  x=a[r];
  i=p-1;
  int k;
  for(j=p;j<r;j++){
    if(a[j]<=x){
      i=++i;
      alt=a[i];
      a[i]=a[j];
      a[j]=alt;
    }
  }
  alt=a[i+1];
  a[i+1]=a[r];
  a[r]=alt;
  return i+1;
}

int main(){
  int i,j,n;
  int *ar,*a;
  scanf("%d",&n);
  ar=(int *)malloc(n*sizeof(int)+1);
  a=ar;
  for(i=0;i<n;i++)scanf("%d",a+i);
  i=partition(a,0,n-1);
  for(j=0;j<i;j++)printf("%d ",*(a+j));
  printf("[%d]",*(a+j));
  for(j=i+1;j<n;j++)printf(" %d",*(a+j));
  printf("\n");  
  free(ar);
  return 0;
}

Measured memory_bytes: 888
#include <stdio.h>

int main(void)
{
	int a,b,l,s;
	scanf("%d %d",&a,&b);
	if(1<=a && b<=100){
		s=a*b;
		l=2*(a+b);
		printf("%d %d\n",s,l);
	}
	return 0;
}

Measured memory_bytes: 596
ans =["a"]
n =int(input())
for i in range(1,n):
  plus=[]
  for s in ans:
    nn=0
    for h in range(len(s)):
      nn=max(nn,ord(s[h]))
    num=nn-ord("a")+1
    for j in range(num+1):
      plus.append(s+chr(ord("a")+j))
  ans = plus
ans.sort()
for ss in ans:print(ss)


Measured memory_bytes: 12936
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int a,b,c,d;
  cin >> a;
  cout << (24-a)+24 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Here your code !
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if(a>=b){
        printf("delicious\n");
    }
    else if(b-a<=x){
            printf("safe\n");
    }
    else printf("dangerous");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main() {
    int n, m;
    while(1) {
        scanf("%d%d", &n, &m);
        if (!n) break;
        int a[1001] = {0};
        while(m--)
            for(int i=0; i<n; i++) {
                int tmp;
                scanf("%d", &tmp);
                a[i] += tmp;
            }
        for(int i=0; i<n; i++) if(a[i] > a[i+1]) a[i+1] = a[i];
        printf("%d\n", a[n]);
    }
}



Measured memory_bytes: 2064
#include<stdio.h>
int main()
{
    int max,i,j,k=0,l,a[10],b[10],n=5,sum=0,s,min=10;
    for(i=0; i<5; i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0; i<5; i++)
    {
        if(a[i]%10==0)
        {
            sum=sum+a[i];
            a[i]=0;
        }
    }
    for(i=0;i<5;i++)
    {
        s=a[i]%10;
        if(min>s&&s!=0)
        {
            min=s;
        }
    }
    for(i=0; i<5; i++)
    {
        max=0;
        for(j=0; j<5; j++)
        {
            s=a[j]%10;
            if(max<s)
            {
                max=s;
                k=j;
            }
        }
        l=10-(a[k]%10);
        if(a[k]!=0)
        {
            sum=sum+a[k]+l;
            a[k]=0;
        }
    }
    int t=10-min;
    printf("%d\n",sum-t);
    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b,c;
cin >> a >> b >> c;
string ans="No";
if(a+b==c||b+c==a||c+a==b) ans="Yes";
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_036
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long s = ReadLong();
            long x2 = (long)Sqrt(s);
            if (x2 * x2 < s) x2++;
            long y3 = x2;
            long delta = x2 * y3 - s;
            long x3 = 1;
            long y2 = delta;
            WriteLine("0 0 " + x2 + " " + y2+" " + x3 + " " + y3);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
D=int(input())
c=list(map(int,input().split()))
s= [list(map(int,input().split())) for _ in range(D)]
t = [int(input()) for _ in  range(D)]
last = [0 for _ in range(26)]

sati=0
for i in range(D):
    sati += s[i][t[i]-1]
    last[t[i]-1]=i+1
    for j in range(26):
        sati -= c[j]*(i+1-last[j])
    print(sati)

Measured memory_bytes: 9400
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

ll roc = 0;
string s;
ll i;
ll t;
bool found = false;
char ans = '#';

string genome() {
	string res = "";
	if(s[roc] == '(') {
		++roc;
		while(s[roc] != ')' && !found) {
			if(s[roc] >= 'A' && s[roc] <= 'Z') {
				res += s[roc];
				++t;
				if(t == i && ans == '#') {
					ans = s[roc];
					found = true;
					++roc;
					t = INF;
					break;
				}
				++roc;
			} else {
				ll roc_buf = roc;
				while(s[roc] >= '0' && s[roc] <= '9') ++roc;
				int roop = stoi(s.substr(roc_buf, roc - roc_buf));
				string rooped = genome();
				if(!found) {
					REP(j, roop - 1) {
						if(t + rooped.size() < i) {
							t += rooped.size();
							res += rooped;
						} else {
							if(ans == '#') {
								ans = rooped[(i - t) - 1];
								found = true;
								t = INF;
							}
							break;
						}
					}
					res += rooped;
				}
			}
		}
		++roc;
		return res;
	} else {
		res += s[roc];
		++t;
		if(t == i) {
			ans = s[roc];
			found = true;
		}
		++roc;
		return res;
	}
}

int main(void) {
	while(true) {
		cin>>s>>i;
		if(s == "0" && i == 0) break;
		roc = 0;
		t = -1;
		found = false;
		ans = '#';
		s = "(" + s;
		s += ")";
		genome();
		if(ans == '#') cout<<0<<endl;
		else cout<<ans<<endl;
	}
}

Measured memory_bytes: 5780
import java.util.Scanner;

/**
 * A - Coffee
 * ある長さ 6 の英小文字からなる文字列がcoffeeに似ているとは、3 文字目と 4 文字目が等しく、5 文字目と6 文字目も等しいことを言います。
 * 与えられる文字列 S がcoffeeに似ているか判定してください。
 * Sは長さ6文字からなる英小文字。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力された文字列
        String s = sc.next();
        // 文字列の3,4文字目が同一英字、5,6文字目が同一英字であるかを判定
        if( s.charAt( 2 ) == s.charAt( 3 ) && s.charAt( 4 ) == s.charAt( 5 ) ) {
            System.out.println( "Yes" );
        }
        else {
            System.out.println( "No" );
        }

        sc.close();
    }
}

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

int main()
{
  int g,k;
  cin >> g >> k;
  int t = g + k;
  int ans =  ((g * (g-1))+(k*(k-1)))/2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int h, w;
    cin >> h >> w;
    vvi a(h, vi(w));
    vvi b(h, vi(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> b[i][j];
        }
    }
    vvi c(h, vi(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            c[i][j] = abs(a[i][j] - b[i][j]);
        }
    }
    vector<vector<bitset<512001>>> dp(h, vector<bitset<512001>>(w, 0));
    dp[0][0][256000 + c[0][0]] = 1;
    dp[0][0][256000 - c[0][0]] = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            // for (int k = 0; k <= 512000; ++k) {
            if (i != 0) {
                dp[i][j] = dp[i][j] | dp[i - 1][j] << c[i][j];
                dp[i][j] = dp[i][j] | dp[i - 1][j] >> c[i][j];

                // if (k + c[i][j] <= 512000)
                //     if (dp[i - 1][j][k + c[i][j]] == 1)
                //         dp[i][j][k] = 1;
                // if (k - c[i][j] >= 0)
                //     if (dp[i - 1][j][k - c[i][j]] == 1)
                //         dp[i][j][k] = 1;
            }
            if (j != 0) {
                dp[i][j] = dp[i][j] | dp[i][j - 1] << c[i][j];
                dp[i][j] = dp[i][j] | dp[i][j - 1] >> c[i][j];
                // if (k + c[i][j] <= 512000)
                //     if (dp[i][j - 1][k + c[i][j]] == 1)
                //         dp[i][j][k] = 1;
                // if (k - c[i][j] >= 0)
                //     if (dp[i][j - 1][k - c[i][j]] == 1)
                //         dp[i][j][k] = 1;
            }
            // }
        }
    }
    int ret = 1000000000;
    for (int i = 0; i <= 512000; ++i) {
        if (dp[h - 1][w - 1][i] == 1) {
            chmin(ret, abs(i - 256000));
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 405760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string w;
  cin >> w;
  map<char,int> mp;
  
  for(int i=0;i<w.size();i++){
    mp[w.at(i)] += 1;
  }
  bool flag = true;
  for(auto itr = mp.begin();itr!=mp.end();itr++){
    if(itr->second%2==1){
      flag = false;
    }
  }
  cout << (flag ? "Yes" : "No") <<  endl;
}

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

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

ll lcd(ll x, ll y) {
    if(x < y)
        swap(x,y);
    
    ll tx=x, ty=y;
    
    while(x%y != 0) {
        ll t = x%y;
        x = y;
        y = t;
    }

    return tx/y*ty;
}

int main() {
    int N;
    ll T,r=1;
    cin >> N;

    rep(i,N) {
        cin >> T;
        r = lcd(r,T);
    }

    cout << r << endl;
}

Measured memory_bytes: 256