akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define timer_start()                            \
    chrono::system_clock::time_point start, end; \
    start = chrono::system_clock::now();
#define timer_wrap()                                                       \
    end = chrono::system_clock::now();                                     \
    double time = static_cast<double>(                                     \
        chrono::duration_cast<chrono::microseconds>(end - start).count() / \
        1000.0);                                                           \
    printf("%lf[ms]\n", time);                                             \
    start = end;
#define optimize_cin() \
    cin.tie(0);        \
    ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
#define INF 1000000000    // 10^9
#define INFINF LLONG_MAX  // 2^63-1
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;
}
// ########## template end ##########

#ifdef DEBUG_ON
void test_all();
#endif

// const int N = pow(10, 6) + 10;
// vector<bool> is_prime(N, true);
// vector<bool> forans(N, false);
// vector<int> pr;

// void prime_table() {
//     is_prime.at(0) = false;
//     is_prime.at(1) = false;
//     for (int i = 0; i < N; i++) {
//         if (!is_prime.at(i)) {
//             continue;
//         }
//         for (int j = i + i; j < N; j += i) {
//             is_prime.at(j) = false;
//         }
//     }
// }
// bool isPrime(ll num) {
//     if (num < 2)
//         return false;
//     else if (num == 2)
//         return true;
//     else if (num % 2 == 0)
//         return false;  // 偶数はあらかじめ除く

//     double sqrtNum = sqrt(num);
//     for (int i = 3; i <= sqrtNum; i += 2) {
//         if (num % i == 0) {
//             // 素数ではない
//             return false;
//         }
//     }

//     // 素数である
//     return true;
// }
void resolve() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> b(pow(10, 6) + 20, 0);
    // int minA = 1000000;
    // int maxA = 0;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        b.at(A.at(i)) += 1;
        // chmin(minA, A.at(i));
        // chmax(maxA, A.at(i));
    }
    for (int i = 0; i < N; i++) {
        if (b.at(A.at(i)) == 0) {
            continue;
        } else if (b.at(A.at(i)) > 1) {
            b.at(A.at(i)) = 0;
        }
        for (int j = A.at(i) * 2; j < pow(10, 6) + 20; j += A.at(i)) {
            b.at(j) = 0;
        }
    }
    int ans = 0;
    for (int i = 0; i < pow(10, 6) + 20; i++) {
        if (b.at(i) == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}

int main() {
#ifdef DEBUG_ON
    test_all();
#else
    resolve();
#endif
    return 0;
}


Measured memory_bytes: 7900
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof (c.begin()) i=c.begin(); i!=c.end(); i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;

const int mod=100000007;
int n,e[100],C[101][101];
double p[100],q[100];
bool v[100];

void _(vi &tmp,int c){
  v[c]=1; tmp.pb(c);
  if(!v[e[c]])_(tmp,e[c]);
}
double rec(int c,int s,bool start=1){
  if(start)return 1/p[c]+rec(e[c],s,0);
  return 1/q[c]+(e[c]!=s?rec(e[c],s,0):0);
}

int main(){
  rep(i,101)rep(j,i+1)C[i][j]=(i==0||j==i?1:C[i-1][j]+C[i-1][j-1])%mod;

  while(cin>>n,n){
    rep(i,n){
      int t; cin>>p[i]>>t>>q[i];
      e[t]=i; v[i]=0;
    }
    vector<vi> vs;
    
    rep(i,n)if(!v[i]){
      vi tmp;
      _(tmp,i);
      vs.pb(tmp);
    }
    
    ll comb=1; double ex=0;
    rep(i,vs.size()){
      double mn=1e9,tmp; int cnt=0;
      rep(j,vs[i].size()){
        tmp=rec(vs[i][j],vs[i][j]);
        if(tmp+1e-9<mn)mn=tmp, cnt=0;
        if(abs(tmp-mn)<1e-9)cnt++;
      }
      ex+=mn; (comb*=cnt*C[n][vs[i].size()])%=mod;
      n-=vs[i].size();
    }
    printf("%.9f %d\n",ex,(int)comb);
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int main(){
  char str[1001];
  int i;

  scanf("%s",str);
  for(i=0;i<strlen(str);i++){
    if((str[i]-3)<'A') str[i] += 26;
    str[i]-=3;
  }
  printf("%s\n",str);


  return 0;
}

Measured memory_bytes: 524
from heapq import heapify, heappop, heappush
N = int(input())
v = [int(i) for i in input().split()]

heapify(v)
while len(v) > 1:
    x, y = heappop(v), heappop(v)
    heappush(v, (x + y)/2)
print(v[0])

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>

int main(){
int a,b,c;
int x,y,z;
int temp;
scanf("%d%d%d",&a,&b,&c);
x=a+c;
y=a+b;
c=b+c;
temp=x;
if(temp>y){
	
	temp=y;
	
}
if(temp>c){
	
	temp=c;
	
	
}
printf("%d\n",temp);

	

	return 0;
}

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

int main(void){
    ll n;
    cin >> n;
    ll sum = 0;
    if(n != 1)rep1(y,sqrt(n)){
        if (n % y != 0) continue;
        ll x = (n/y)-1;
        if (n % x == y) {
            sum += x;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import product, permutations

expr_a = (
    "{}{}{}{}{}{}{}",
    "({}{}{}){}{}{}{}",
    "{}{}({}{}{}){}{}",
    "{}{}{}{}({}{}{})",
    "({}{}{}){}({}{}{})"
)

while True:
    a = list(map(int, input().split()))
    if a == [0, 0, 0, 0]:
        break
    flag = False
    for (op1, op2, op3), (n1, n2, n3, n4) in product(product("+-*", repeat=3), permutations(a)):
        inner = (n1, op1, n2, op2, n3, op3, n4)
        for expr in expr_a:
            if eval(expr.format(*inner)) == 10:
                print(expr.format(*inner))
                flag = True
                break
        if flag:
            break
    if not flag:
        print(0)


Measured memory_bytes: 5652
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    int n;
    cin>>n;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-1;i++)sum+=a[i];
    if(a[n-1]<sum)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int W, H, x, y, r;
	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	if (W>=(x+r)&&H>=(y+r)&&(y-r)>=0&&(x-r)>=0)
	printf("Yes\n");
	else printf("No\n");
	return 0;
} 


Measured memory_bytes: 2108
n,m = map(int,input().split())
a,b = [[] for i in range(n)],[[] for i in range(n)]
c,d = [[] for i in range(m)],[[] for i in range(m)]
for i in range(n):
    a[i],b[i] = map(int,input().split())
for i in range(m):
    c[i],d[i] = map(int,input().split())

check = [[] for i in range(m)]
for i in range(n):
    for j in range(m):
        check[j] = abs(a[i]-c[j])+abs(b[i]-d[j])
    print(check.index(min(check))+1)

Measured memory_bytes: 3188
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
//string S;
//int N, cnt;

int main() {
    string S;
    int N, cnt=0;
	cin >> N >> S;
	for (int i = 0; i < 1000; i++) {
		int c[3] = {i / 100, (i / 10) % 10, i % 10};
		int f = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == (c[f] + '0')) {
                f++;
            }
			if (f == 3) {
                break;
            }
		}
		if (f == 3) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main(){
    int K;
    cin >> K;
    ll sum = 0;
    for (int i = 1; i <= K;i++)
    {
        for (int j = 1; j <= K;j++)
        {
            for (int k = 1; k <= K;k++)
            {
                sum += __gcd(k, __gcd(i, j));
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if((e-a) >k)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
int main()
{
  string A;
  cin >> A;
  if(A[0] == A[1] || A[1] == A[2]|| A[2] == A[3]){
    cout << "Bad" << endl;
  }else {
    cout << "Good" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    long long a,b,n,an,m,i;
    cin>>a>>b>>n;
    //for(i=a;i<n;i++)
    //{
        m=min(b-1,n);
        an=floor(a*m/b)-(a*floor(m/b));
       // ma=max(ma,an);
    //}
   /* else
    {
        an=floor(a*(b-1)/b)-(a*floor(b-1/b));
    }*/
    cout<<an<<endl;
    return 0;
}

Measured memory_bytes: 3608
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 
  
const int MAX = 1000001; 
  
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(vector<int> arr, int n, vector<Query> queries, int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 
  
// driver code 
int main() 
{ 
    int n;
    cin >> n;

    int q;
    cin >> q;

    vector<int> a(n);

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

    vector<Query> queries(q);

    for(int i = 0; i < q; i++)
    {
        queries[i].idx = i;
        cin >> queries[i].l >> queries[i].r;
        queries[i].l--;
        queries[i].r--;
    }



    sort(queries.begin(), queries.end(), cmp); 
    answeringQueries(a, n, queries, q); 
    return 0; 
} 


Measured memory_bytes: 27236
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  string s; cin >> s;
  ll ans = 0;
  int n=s.size();
  for(int bit=0 ; bit<(1<<(n-1)) ; bit++){
    string st ="";
    st += s[0];
    for(int i=0 ; i<(n-1) ; i++){
      if(bit & (1<<i)){
        ll k;
        sscanf(st.c_str(), "%lld", &k);
        ans += k;
        st = s[i+1];
      }else{
        st += s[i+1];
      }
    }
    ll k;
    sscanf(st.c_str(), "%lld", &k);
    ans += k;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

g = []


def rec(i, s, N):
    # print(s)
    global g
    g.append(int(s))
    if len(s) > N:
        return

    if i - 1 >= 0:
        rec(i-1, s + str(i-1), N)
    rec(i, s + str(i), N)
    if i + 1 <= 9:
        rec(i+1, s + str(i+1), N)


def main():
    global g
    K = I()
    ans = []

    for i in range(1, 10):
        rec(i, str(i), 10)
    g = sorted(g)
    print(g[K-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 89428
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
int n;
ll ans;
bool cmp(int x,int y){return x>y;}
int main()
{
    scanf("%d",&n);
    vector<int> a(n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a.begin(),a.end(),cmp);
    ans=a[0];
    for(int i=0,j=1;i<a.size()-2;j+=(i&1),i++)
        ans+=a[j];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3996
import java.util.Scanner;
/**
 * @author saiyo
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		
		Seisu s = new Seisu(x, y);
		s.kouyaku();
		/*
		int con = scan.nextInt();
		int[] num = new int[con];
		for(int i = 0; i < con; i++){
			num[i] = scan.nextInt();
		}
		Sort s = new Sort(num);
		s.printSort();
		s.insertionSort();
		*/
	}

}

class Seisu{
	private int x, y;
	
	Seisu(int x, int y){
		if(x >= y){
			this.x = x;
			this.y = y;
		}else{
			this.x = y;
			this.y = x;
		}
		
	}
	
	public void kouyaku(){
		System.out.println(modSeisu(this.x, this.y));
	}
	
	
	public int modSeisu(int x, int y){
		if(x % y == 0){
			return y;
		}else{
			return modSeisu(y , x % y);
		}
	}
}

class Sort{
	private int[] sorted;
	
	Sort(int[] sorted){
		this.sorted = new int[sorted.length];
		for(int i = 0; i < sorted.length; i++){
			this.sorted[i] = sorted[i];
		}
	}
	
	public void insertionSort(){
		int v, j;
		for(int i = 1; i < this.sorted.length; i++){
			v = this.sorted[i];
			j = i - 1;
			while(j >= 0 && this.sorted[j] > v){
				this.sorted[j + 1] = this.sorted[j];
				j--;
			}
			this.sorted[j + 1] = v;
			printSort();
		}
	}
	
	public void printSort(){
		for(int i  = 0; i < this.sorted.length - 1; i++){
			System.out.print(this.sorted[i] + " ");
		}
		System.out.println(this.sorted[this.sorted.length - 1]);
	}
}



Measured memory_bytes: 26364
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [0] * N
for i in range(1, N):
    tmp = []
    for j in range(K):
        if (i - j - 1) < 0:
            break
        tmp.append(dp[i-j-1] + abs(H[i]-H[i-j-1]))
    dp[i] = min(tmp)
    # print("tmp", tmp)
    # print("dp ", dp)
print(dp[-1])

Measured memory_bytes: 84400
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		char[] s = sc.next().toCharArray();
		sc.close();
		for (i = 0; i < s.length; i++) {
			s[i] = (char)('A'+((s[i]-'A' + n)%26));
		}
		out.println(String.valueOf(s));
	}
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;
int main(){
  long long int a,b,x,ans=0;
  cin >> a >> b >> x;
  ans += (b-a)/x;
  b -= ((b-a)/x)*x;
  if(a%x == 0)ans++;
  else if(a%x > b%x)ans++;
  cout << ans << endl;
}


Measured memory_bytes: 384
n = int(input())
a = [int(i) for i in input().split(" ")]

a.sort()
a.append(a[-1] + 1)

c = 0
m = 0

for i in range(0, n):
    c += 1
    if a[i] != a[i + 1]:
        if c < a[i]:
            m += c
        else:
            m += c - a[i]
        c = 0

print(m)

Measured memory_bytes: 14028
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[3][n];
  
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<3;j++)
    cin>>a[j][i];
  }
  int dp[3][n];
  dp[0][0]=a[0][0];
  dp[1][0]=a[1][0];
  dp[2][0]=a[2][0];

  for(int i=1;i<n;i++)
  {for(int j=0;j<3;j++)
  {
    dp[j][i]=max(dp[(j+1)%3][i-1]+a[j][i],dp[(j+2)%3][i-1]+a[j][i]);
  }
  }
  int ans=dp[0][n-1];
  ans=max(ans,max(dp[1][n-1],dp[2][n-1]));
  cout<<ans;
}

Measured memory_bytes: 5920
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    cout << (n + 1) / 2 << endl;

    return 0;
}

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

int main(){
      string S;
     cin >> S;
    for(int i = 0; i < S.size() - 1; i++){
      if(S[i] == 'A' && S[i + 1] == 'C'){
            cout << "Yes" << endl;
            return 0;
         }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(n)]
C = [list(map(int, input().split())) for _ in range(m)]

for s in S:
    x, ans = 10**9, 0
    for i, c in enumerate(C):
        y = abs(s[0]-c[0]) + abs(s[1]-c[1])
        if y < x:
            x, ans = y, i+1
    print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#define N 101
#define INF 10000000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,mat[N][N];

void dijkstra(){
  int minv,i,v;
  int d[N],color[N];

  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INF;
    int u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && mat[u][v]!=INF){
        if(d[v]>d[u]+mat[u][v]){
          d[v]=d[u]+mat[u][v];
          color[v]=GRAY;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INF){
      d[i]=-1;
    printf("%d\n",d[i]);//d[i]=INF?-1:d[i];
  }
    else printf("%d\n",d[i]);
  }
}

int main(){
  int u,k,c,v;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      mat[i][j]=INF;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      mat[u][v]=c;
    }
  }

  dijkstra();
return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int dp[100010];
int main(void)
{
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=100000;++i)
    {
        dp[i]=i;
    }
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        dp[i]=min(dp[i],dp[i-1]+1);
        if(i>=6)
        {
            dp[i]=min(dp[i],dp[i-6]+1);
        }
        if(i>=36)
        {
            dp[i]=min(dp[i],dp[i-36]+1);
        }
        if(i>=216)
        {
            dp[i]=min(dp[i],dp[i-216]+1);
        }
        if(i>=1296)
        {
            dp[i]=min(dp[i],dp[i-1296]+1);
        }
        if(i>=7776)
        {
            dp[i]=min(dp[i],dp[i-7776]+1);
        }
        if(i>=46656)
        {
            dp[i]=min(dp[i],dp[i-46656]+1);
        }
        if(i>=9)
        {
            dp[i]=min(dp[i],dp[i-9]+1);
        }
        if(i>=81)
        {
            dp[i]=min(dp[i],dp[i-81]+1);
        }
        if(i>=729)
        {
            dp[i]=min(dp[i],dp[i-729]+1);
        }
        if(i>=6561)
        {
            dp[i]=min(dp[i],dp[i-6561]+1);
        }
        if(i>=59049)
        {
            dp[i]=min(dp[i],dp[i-59049]+1);
        }
    }
    cout <<dp[n]<<endl;
    return 0;
}


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

int main(){
    int bingo[3][3];
    rep(i,3){
        rep(j,3){
            cin >> bingo[i][j];
        }
    }
    int n;
    cin >> n;
    int b[n];
    rep(i,n){
        cin >> b[i];
    }
    rep(k,n){
        rep(i,3){
            rep(j,3){
             if(b[k]==bingo[i][j]) bingo[i][j]=-1;
             }
        }
    }
    rep(i,3){
        int cnt=0;
        rep(j,3){
            if(bingo[i][j]==-1) cnt++;
        }
        if(cnt==3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    rep(i,3){
        int cnt=0;
        rep(j,3){
            if(bingo[j][i]==-1) cnt++;
        }
        if(cnt==3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    rep(i,3){
        int cnt=0;
        rep(j,3){
            if(bingo[j][j]==-1) cnt++;
        }
        if(cnt==3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    int cnt=0;
    rep(i,3){
        if(bingo[i][2-i]==-1) cnt++;
    }
    if(cnt==3){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<deque>
using namespace std;

int main(){
    string s;
    cin >> s;

    string t;

    int q;
    cin >> q;

    int ti,fi;
    char ci;
    for(int i=0;i<q;i++){
        cin >> ti;
        if(ti==1){
            swap(t,s);
        }else{
            cin >> fi >> ci;
            if(fi==1){
                t += ci;
            }else{
                s += ci;
            }
        }
    }

    reverse(t.begin(),t.end());
    t += s;
    cout << t << endl;
}

Measured memory_bytes: 1128
import java.util.Scanner

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val n:Int = sc.nextInt()
    val button = IntArray(n+1)
    val map = IntArray(n+1)
    for(i in 1..n){
      button[i] = sc.nextInt()
      map[i] = 0
    }

    var i = 1
    var count = 0
    do{
      map[i] = 1
      count++
      i = button[i]
    }while(map[i]!=1&&i!=2)

    if(i==2) println(count)
    else println(-1)
}


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

int main() {
  string S;
  cin>>S;
  if(S=="ABC"){
    cout<<"ARC"<<endl;
  }  
  else{
    cout<<"ABC"<<endl;
  }
}



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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b)+min(c,d) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<set>

using namespace std;

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

	set<string> S;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		S.insert(s);
	}

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

}


Measured memory_bytes: 19100
#include<iostream>
#include<cstdio>
#include<set>
using namespace std;


set<int> ans;

int main(){
    int N;
    cin >> N;
    
    int ans_[] = {2, 5, 63, 20, 30};
    if(N <= 5){
        for(int i = 0; i < N; i++){
            if(i) cout << " ";
            cout << ans_[i];
        }
        cout << endl;
        return 0;
    }

    long long sum = 0;
    int breaked;
    for(int i = 1; i <= 30000; i++){
        if(i % 2 == 0 || i % 3 == 0){
            ans.insert(i);
            sum += i;
        }
        if(ans.size() >= N){
            breaked = i;
            break;
        }
    }
    if(sum % 6 == 2){
        ans.erase(8);
        ans.insert(breaked/6*6 + 6);
    }else if(sum % 6 == 3){
        ans.erase(9);
        ans.insert(breaked/6*6 + 6);
    }else if(sum % 6 == 5){
        ans.erase(9);
        ans.insert((breaked-4)/6*6 + 6 + 4);
    }

    for(auto it = ans.begin(); it != ans.end(); it++){
        if(it != ans.begin()) cout << " ";
        cout << *it;
    }
    cout << endl;
    
}

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

using namespace std;

int main() {
	long long n, s;
	scanf("%lld %lld", &n, &s);

	for (long long i = 2; i * i <= n; ++i) {
		long long b = i;
		long long sum = 0;
		long long t = n;

		while (t > 0) {
			sum += t % b;
			t /= b;
		}

		if (sum == s) {
			printf("%lld", i);

			return 0;
		}
	}
	for (long long i = min((long long)sqrt(n) + 1, s); i >= 1; --i) 
		if ((n - s) % i == 0) {
			long long p = i, q = s - p, b = (n - s) / i + 1;
			
			if (p < b && q < b) {
				printf("%lld", b);

				return 0;
			}
		}
	if (n == s)
		printf("%lld", n + 1);
	else
		printf("-1");

	return 0;

	return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]

    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    L = [[0] * w for _ in range(h)]

    b = True
    for i in range(h):
        for j in range(w):
            if b:
                U[i][j] = 1 if s[i][j] != "#" else 0
                D[-i - 1][j] = 1 if s[-i - 1][j] != "#" else 0
                R[i][-j - 1] = 1 if s[i][-j - 1] != "#" else 0
                L[i][j] = 1 if s[i][j] != "#" else 0
                b = False
            else:
                U[i][j] = 1 + U[i-1][j] if s[i][j] != "#" else 0
                D[-i-1][j] = 1 + D[-i][j] if s[-i-1][j] != "#" else 0
                R[i][-j-1] = 1 + R[i][-j] if s[i][-j-1] != "#" else 0
                L[i][j] = 1 + L[i][j-1] if s[i][j] != "#" else 0
    mt = 0
    for i in range(h):
        for j in range(w):
            mt = max(mt, U[i][j] + D[i][j] + R[i][j] + L[i][j] - 3)
    print(mt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 310408
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int i = 0;
		boolean[][] card = new boolean[4][13];

		while(true) {
			if(n == i) break;

			String mark = sc.next();
			int no = sc.nextInt();
			switch (mark) {
			case "S":
				card[0][no-1] = true;
				break;

			case "H":
				card[1][no-1] = true;
				break;

			case "C":
				card[2][no-1] = true;
				break;

			case "D":
				card[3][no-1] = true;
				break;
			}
			i++;
		}

		for(int j = 0; j < 4; j++) {
			for(int k = 0; k < 13; k++) {
				if(!card[j][k]) {
					if(j == 0) {
						System.out.println("S " + (k + 1));
					} else if(j == 1) {
						System.out.println("H " + (k + 1));
					} else if(j == 2) {
						System.out.println("C " + (k + 1));
					} else {
						System.out.println("D " + (k + 1));
					}
				}
			}
		}
	}

}


Measured memory_bytes: 26424
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<=(n); i++)
typedef long long ll;
using namespace std;
 
int main(){
    string S; cin >> S;
    bool bool1=0;
    bool bool2=0;
    int cnt=0;
    int cnt1=0;
    if (S[0]=='A'){ 
        bool1=1;
    }
    for (int i=2; i<=S.size()-2;i++){
        if(S[i]=='C'){
            bool2=1;
            cnt++;
        }
    }
    
    for (int i=0; i<S.size(); i++){
        if(isupper(S[i])){
            cnt1++;
        }
    }
    
    if(bool1==1&&bool2==1&&cnt==1&&cnt1==2){
        cout << "AC";
    }else{
        cout << "WA";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int n;
  scanf("%d", &n);

printf("%d\n",a[n-1]);
return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int ans = 0;
	int max = 0;
	for (int ii = 0; ii < N; ++ii){
		int h;
		cin >> h;
		if (max <= h){
			ans++;
			max = h;
		}
	}

	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int a = N%1000;
		if(a == 0) {
			System.out.println("0");
		}else {
			int b = 1000-a;
			System.out.println(b);
		}
	}

}


Measured memory_bytes: 35800
S = input()
for i in range(1 << 3):
    op = ['+'] * 3
    for j in range(3):
        if i >> j & 1:
            op[j] = '-'
    res = ''
    for s, p in zip(S, op):
        res += s + p
    res += S[-1]
    if eval(res) == 7:
        res += '=7'
        print(res)
        break



Measured memory_bytes: 9072
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int max = sc.nextInt();
        Map<String, Integer> map = new LinkedHashMap<>(max);
        for (int i = 0; i < max; i++) {
            map.put(sc.next(), sc.nextInt());
        }
        String music = sc.next();
        boolean hasSleep = false;
        int sum = 0;
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (hasSleep) {
                sum += entry.getValue();
            }
            if (entry.getKey().equals(music) && !hasSleep) {
                hasSleep = true;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23892
#include <stdio.h>

int main(void)
{
	int amida[30];
	int i;
	int tmp;
	int w, n;
	int a, b;
	for (i = 0; i < 30; i++) amida[i] = i + 1;
	
	scanf("%d", &w);
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);
		
		tmp = amida[a - 1];
		amida[a - 1] = amida[b - 1];
		amida[b - 1] = tmp;
	}
	
	for (i = 0; i < w; i++) printf("%d\n", amida[i]);
	
	return (0);
}

Measured memory_bytes: 1816
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

int main(void) {
	vector<int> v;
	string str;

	for (int i = 0; i < 10; i++) {
		getline(cin, str);
		v.push_back(atoi(str.c_str()));
	}

	sort(v.begin(), v.end());

	for (int j = v.size() - 1; j > v.size() - 4; j--) {
		cout << v[j] << endl;
	}

	return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)





int r1, r2;
//-----------------------------------------------------------------------------------
int main() {
	cin >> r1 >> r2;

	int d = abs(r2 - r1);
	double ans = (r1 + r2) / 2.0;
	if (180 < d) ans += 180;
	if (360 < ans) ans -= 360;
	printf("%.10f\n", ans);
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
const int MOD=1e9+7;
using namespace std;

char x;
int h, w, a[1005][1005], dp[1005][1005] = {0};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
        {
            cin >> x;
            if(x == '.')
                a[i][j] = 1;
            else
                a[i][j] = 0;
        }
    dp[0][0] = 1;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            if(a[i][j])
            {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= MOD;
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= MOD;
            }
    cout << dp[h - 1][w - 1] << "\n";
    return 0;
}

Measured memory_bytes: 8192
import sys
import numpy as np  # noqa

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


N = int(readline())

AC, WA, TLE, RE = 0, 0, 0, 0

for i in range(N):
    s = readline().rstrip().decode()
    if s == "AC":
        AC += 1
    elif s == "WA":
        WA += 1
    elif s == "TLE":
        TLE += 1
    elif s == "RE":
        RE += 1

print(f"AC x {AC}")
print(f"WA x {WA}")
print(f"TLE x {TLE}")
print(f"RE x {RE}")


Measured memory_bytes: 27056
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    a = sorted(nl(), reverse=True)
    print(sum(a[:n//2]) + sum(a[1:(n+1)//2]))
    return

solve()


Measured memory_bytes: 31416
#include <stdio.h>

void leapyear(int start, int end);

int main(void)
{
    int start, end;
    while (1){
        scanf("%d %d", &start, &end);
        if (start == 0 && end == 0){
            break;
        } else {
            // 2回目の出力からは前回の出力とのあいだに空行をおく
            static int first_output = 1; 
            if (first_output != 1){
                printf("\n");
            }
            first_output = 0;

            leapyear(start, end);
        }
    }

    return 0;
}

void leapyear(int start, int end)
{
    int cnt = 0;
    for (int year = start; year <= end; year++){
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)){
            printf("%d\n", year);
            cnt++;
        }
    }
    if (cnt == 0){
        printf("NA\n");
    }
}

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

void printElements(int elements[], int n){
	for(int i = 0; i < n; i++){
		cout << elements[i];
		if(i != n - 1){
			cout << " ";
		}
	}
	cout << endl;
}

void insertionSort(int elements[], int n){
	int tmp;
	int j;
	for(int i = 1; i < n; i++){
		tmp = elements[i];
		j = i - 1;
		while( j >= 0 && elements[j] > tmp){
			elements[j+1] = elements[j];
			j--;
		}
		elements[j+1] = tmp;
		printElements(elements, n);
	}
}

int main(){
	int n;
	int elements[100];

	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> elements[i];
	}
	printElements(elements, n);
	insertionSort(elements, n);
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int H, W;
vector<string> field;
vector<vector<vector<bool>>> visited;
int sh, sw, sd, gh, gw;

int dh[] = {-1, 0, 1, 0};
int dw[] = {0, 1, 0, -1};

class State{
public:
    int h, w, d;
    State(int h, int w, int d): h(h), w(w), d(d){};
};

inline bool in_field(int h, int w){
    return 0<=h&&h<H && 0<=w&&w<W;
}

int bfs(){
    queue<State> que;
    que.push({sh, sw, sd});
    
    while(!que.empty()){
        State cur = que.front(); que.pop();
        visited[cur.h][cur.w][cur.d] = true;
        
        if(cur.h==gh && cur.w==gw){
            int count = 0;
            for(int i=0; i<H; i++)
                for(int j=0; j<W; j++)
                    count += visited[i][j][0]||visited[i][j][1]||visited[i][j][2]||visited[i][j][3];
            return count;
        }
        
        int rh = cur.h + dh[(cur.d+1)%4];
        int rw = cur.w + dw[(cur.d+1)%4];
        
        if(in_field(rh, rw)&&field[rh][rw]!='#'){
            if(!visited[rh][rw][(cur.d+1)%4]){
                que.push({rh, rw, (cur.d+1)%4});
            }
        }else{
            if(!visited[cur.h][cur.w][(cur.d-1+4)%4]){
                que.push({cur.h, cur.w, (cur.d-1+4)%4});
            }
        }
    }
    
    return -1;
}

void solve(){
    visited = vector<vector<vector<bool>>>(H, vector<vector<bool>>(W, vector<bool>(4, false)));
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            char c = field[i][j];
            if(c == 'G')
                gh = i, gw = j;
            else if(c == '^')
                sh = i, sw = j, sd = 0;
            else if(c == '>')
                sh = i, sw = j, sd = 1;
            else if(c == 'v')
                sh = i, sw = j, sd = 2;
            else if(c == '<')
                sh = i, sw = j, sd = 3;
        }
    }
    
    cout << bfs() << endl;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    
    cin >> H >> W;
    field = vector<string>(H);
    for(auto &r: field) cin >> r;
    
    solve();
    
    return 0;
}

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

using namespace std;

typedef long long ll;

const int max_n = 22;
const int INF = INT_MAX / 2;
int h, w;
string grid[max_n];

int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};

int bfs(int r1, int c1, int r2, int c2){
	queue<int> qr;
	queue<int> qc;
	qr.push(r1);
	qc.push(c1);

	int dist[h][w];
	rep(i, h) rep(j, w) dist[i][j] = INF;
	dist[r1][c1] = 0;

	while(!qr.empty()){
		int r = qr.front(); qr.pop();
		int c = qc.front(); qc.pop();
		if(r == r2 && c == c2) return dist[r2][c2];
		rep(i, 4){
			int nr = r + dr[i];
			int nc = c + dc[i];
			if(0 <= nr && nr < h && 0 <= nc && nc < w && grid[nr][nc] != '#'){
				if(dist[nr][nc] != INF) continue;
				dist[nr][nc] = min(dist[nr][nc], dist[r][c] + 1);
				qr.push(nr);
				qc.push(nc);
			}
		}
	}

	return INF;
}

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

	cin >> h >> w;

	rep(i, h) cin >> grid[i];

	int ans = 0;
	rep(r1, h) rep(c1, w) rep(r2, h) rep(c2, w){
		if(r1 == r2 && c1 == c2) continue;
		if(grid[r1][c1] == '#') continue;
		if(grid[r2][c2] == '#') continue;
		int t = bfs(r1, c1, r2, c2);
		if(t == INF) continue;
		ans = max(ans, t);
	}

	cout << ans << endl;
}


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();
    int[] b = new int[n - 1];
    for(int i = 0; i < (n - 1); i++) {
      b[i] = sc.nextInt();
    }
    int ans = b[0] + b[n - 2];
    for(int i = 0; i < (n - 2); i++) {
      ans += Math.min(b[i], b[i + 1]);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35964
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+50;
const int inf=0x3f3f3f3f;
int n,k;
char s[10000];
int main()
{
    //freopen("/Users/zilongzhang/Desktop//l.txt","r",stdin);
    while(scanf("%d %s",&n,s)!=-1)
    {
        if(n>=3200)
            printf("%s\n",s);
        else
            printf("red\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[10024];string s;ll l;double d;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	double nextDouble(){scanf("%lf", &d);return d;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

string s;

bool isNum(char c){
	return c >= '0' && c<='9';
}

int calc(int l){
	//cout<<" "<<l<<" "<<s[l]<<endl;
	if(isNum(s[l])){
		int ret = 0;
		while(l < s.size() &&isNum(s[l])){
			ret *= 10;
			ret += s[l]-'0';
			l++;
		}
		return ret /2 + 1;
	}
	vector<int> v;
	int lv = 0;
	for(int i = l; i < s.size(); i++){
		if(s[i]=='[') {
			if(lv == 0) v.pb(calc(i + 1));
			lv++;
		}
		else if(s[i]==']') lv--;
		if(lv < 0) break;
	}
	sort(all(v));
	int ret = 0;
	assert(v.size()>0);
	for(int i = 0; i < v.size()/2 + 1; i++) ret += v[i];
	return ret;
}

int main(){
	int n = in.nextInt();
	rep(i, n){
		s = in.next();
		//cout<<s<<endl;
		cout<<calc(1)<<endl;
	}
}

Measured memory_bytes: 3268
import itertools
n = int(input())
target = ["7","5","3"]
c = 0
for i in range(1,len(str(n))+1):
  for p in list(itertools.product(target,repeat=i)):
    if int("".join(list(p))) <= n and len(set(p))==3: c += 1
print(c)
    

Measured memory_bytes: 6260
N = int(input())
HP = sorted([list(map(int,input().split())) for i in range(N)],key = lambda x: x[0]+x[1])
dp1 = [float('inf') for i in range(N+1)]
dp2 = [float('inf') for i in range(N+1)]
dp1[0] = 0
dp2[0] = 0
for i in range(1,N+1):
    for j in range(N+1):
        if dp1[j-1] <= HP[i-1][0]:
            dp2[j] = min(dp1[j],dp1[j-1]+HP[i-1][1])
        else:
            dp2[j] = dp1[j]
    dp1,dp2 =dp2,dp1
for i in range(N,-1,-1):
    if dp1[i] != float('inf'):
        print(i)
        break

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

int main() {
  string data;
  cin >> data;
  

  bool ans = false;  

  for (int i = 0; i < data.size()-1 ; i+=2) {
    if (data.at(i) == 'h' && data.at(i + 1)== 'i') {
      ans = true;
    }
     if (data.at(i) != 'h' || data.at(i + 1)!= 'i') {
      ans = false;
       break;
    }
  }
  if((data.size()%2) ==1){
    ans =false;
  }
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
pair<ll,ll> ar[2000+9];
ll dp[2009][2009],n;
ll rec(ll idx,ll i,ll j)
{
	if(idx==n+1)
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	return dp[i][j]=max(rec(idx+1,i+1,j)+((ar[idx].first)*abs(ar[idx].second-i)),rec(idx+1,i,j-1)+((ar[idx].first)*abs(ar[idx].second-j)));
}
int main()
{
	//freopen("/home/dhruv/Desktop/tests/input.txt","r",stdin);
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		ll x;
		cin>>x;
		ar[i].first=x;
		ar[i].second=i;
	}
	sort(ar+1,ar+1+n,greater< pair<ll,ll> >());
	memset(dp,-1,sizeof dp);
	cout<<rec(1,1,n)<<"\n";
}

Measured memory_bytes: 35288
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
 
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for(int i = 0; i < n; i++)
#define LL long long
const int mod = 1e9 + 7;
const int inf = 1e9;


char s[1000005];
int n;

int main() {
    //freopen("in", "r", stdin);

    int ans = 0;
    scanf("%s", s);
    n = strlen(s);

    int t = 0;
    for(int i = n - 1; i >= 0; i--) {
        int x = s[i] - '0' + t;

        if(x == 10) {
            t = 1;
        }
        else if(x == 5) {
            ans += 5;
            if(i > 0 && s[i - 1] >= '5') {
               t = 1; 
            }
            else {
               t = 0;
            }
        }
        else if(x < 5) {
            ans += x;
            t = 0;
        }
        else {
            ans += 10 - x;
            t = 1;
        }
    }
    printf("%d\n", ans + t);
    return 0;
}

Measured memory_bytes: 1280
/* ex 9_2
   Sagzar1993 */

#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    int cnt = 0; //除去可能なキューブの数
    char cube; //キューブの色を表す文字
    //最初のノードの指す先
    node *cubeFirst = NULL;
    
    //１文字ずつ入力してスタックを操作
    while(1){
        scanf("%c", &cube);
        //文字列の最後に来たら終了
        if(cube == '\n'){
            break;
        }
        if(cubeFirst == NULL){
            push(&cubeFirst, cube); //１文字目をスタックに追加
        }else if((cubeFirst->elem == '0' && cube == '1') || (cubeFirst->elem == '1' && cube == '0')){
            pop(&cubeFirst); //入力されたcubeをスタックの先頭と比較し、０と１の組ならば除去可能
            cnt += 2; //取り出したスタックの先頭および入力の２文字が除去可能なので、cntを＋２
        }else{
            push(&cubeFirst, cube); //０同士、１同士ならば除去不可なのでそのままスタックに追加
        }
    }
    
    printf("%d\n", cnt); //除去可能なキューブ数cntを出力
    return 0;
}

Measured memory_bytes: 4784
n, k = map(int,input().split())
per = 0
for i in range(1, n+1):
    # x = math.ceil(math.sqrt(k/i)) if k > i else 0
    x = 0
    t = i
    while t < k:
        t *= 2
        x += 1
    # per += float("{:.20g}".format(1/(2**x)))
    per += 2**-x

print(per/n)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long int
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define umpii unordered_map<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define mii map<int,int>
#define pqh priority_queue<int>
#define pql priority_queue<int,vi,greater<int>>
#define setbits(x) __builtin_popcountll(x);
#define zerobits(x)__builtin_ctzll(x);
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
#define mod 1000000007
int dp[1001][1001];
int  solve(int i, int j, int n, int m, string s[])
{
	if (i == n - 1 and j == m - 1 and s[i][j] == '.')
		return 1;
	if (i == n - 1 and j == m - 1 and s[i][j] == '#')
		return 0;
	if (i >= n or j >= m)
		return 0;
	if (s[i][j] == '#')
		return 0;
	if (dp[i][j] != -1)
		return dp[i][j];

	int cnt = 0;
	int right = solve(i, j + 1, n, m, s);
	int left = solve(i + 1, j, n, m, s);
	cnt = right + left;
	cnt %= mod;

	return dp[i][j] = cnt;


}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	string s[n];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	mem(dp, -1);
	cout << solve(0, 0, n, m, s);


	return 0;
}


Measured memory_bytes: 12660