akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template <typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vi L(N);
    REP(i,N)cin >> L[i];
    so(L);
    int ans = 0;
    REP(i,N){
        FOR(j,i+1,N){
            ans += distance(L.begin() + j + 1,lower_bound(ALL(L),L[i] + L[j]));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define LIMIT 1000000000

bool check(long long key){
    if(key > LIMIT) return true;
    return false;
}

int main(){
    long long n,T,ans,total = 0;
    string str;
    bool flg = false;

    cin >> n >> T >> str;
    for(int i = 0 ; i < str.size() ; i++){
        if('0' <= str[i] && str[i] <= '9'){
            if(str[i] == '0') total++;
            else{
                ans = 1;
                for(int j = 0 ; j < str[i]-'0' ; j++){
                    ans *= n;
                    if(check(ans)){
                        flg = true;
                        goto end;
                    }
                }
                total += ans;
            }
        }
    }
    total *= T;
    if(total > LIMIT) flg = true;
    
    end:
    if(flg) cout << "TLE" << endl;
    else cout << total << endl;
    
    return 0;
}

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

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

  if (A <= C && C <= B) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" <<endl;
  }
  
return 0;
}

Measured memory_bytes: 3596
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, M;

    scanf("%jd%jd", &N, &M);

    if (N == M) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
import java.awt.image.BandedSampleModel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {


    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int cases = 5;
        int arr[] = new int[5];
        int ans=0;
        for(int i=0;i<cases;i++)
        {
            arr[i] = sc.nextInt();
            if(arr[i]==0)
            {ans=i+1;}
            //int arr[] = new int[n];
        }
        System.out.println(ans);



    }
}


Measured memory_bytes: 35732
#include <cstdio>
const int MAXN = 5e3 + 5;

int b[MAXN][205], n, m;
long long a[MAXN], sum[MAXN][MAXN];
int l[MAXN];
int stack[MAXN], top;


int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n - 1; i++) scanf("%lld", &a[i]);
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) scanf("%d", &b[i][j]);

	for(int j = 1; j <= m; j++) {
		top = 0;
		stack[top++] = 0;
		for(int i = 1; i <= n; i++) {
			while(top > 1 && b[stack[top - 1]][j] < b[i][j]) top--;
			l[i] = stack[top - 1];
			stack[top++] = i;
		}
		top = 0;
		stack[top++] = n + 1;
		for(int i = n; i >= 1; i--) {
			while(top > 1 && b[stack[top - 1]][j] <= b[i][j]) top--;
			int r = stack[top - 1];
			sum[l[i] + 1][i] += b[i][j];
			sum[l[i] + 1][r] -= b[i][j];
			sum[i + 1][i] -= b[i][j];
			sum[i + 1][r] += b[i][j];
			stack[top++] = i;
		}
	}
	for(int i = 2; i <= n - 1; i++) a[i] += a[i - 1];
	long long ans = 0;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
		sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		if(i <= j) {
			long long cur = a[j - 1] - a[i - 1];
			cur = sum[i][j] - cur;
			if(ans < cur) ans = cur;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;
VI g[MAX];
int C[MAX];
int cnt, all;
bool even;

void dfs(int v, int t)
{
	if (C[v] != -1)
	{
		if (t != C[v]) even = false;
		return;
	}

	C[v] = t;
	all++;
	if (t) cnt++;

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to, t ^ 1);
	}
}
int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].PB(b);
		g[b].PB(a);
	}

	FILL(C, -1);
	LL ans = 0;
	FOR(i, 0, n)
	{
		if(C[i] != -1) continue;

		cnt = all = 0;
		even = true;
		dfs(i, 0);

		if (even)
		{
			ans += cnt * (LL) (all - cnt);
			continue;
		}

		ans += all *(LL) (all -1) / 2;
	}

	ans -= m;
	cout << ans << endl;
	return 0;
}


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

int main(){
    long long ans = 0;
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    ans = max(a*c, b*d);
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    cout << ans;
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
int main() {
    int n,k;
    cin >> n >> k;
    VIN(int, a, n);
    SORT(a);
    int sum = 0;
    REP(i, k){
        sum += a[i];
    }
    COUT(sum);
}


Measured memory_bytes: 3596
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(long long i=a;i<=(b);++i)
#define dF(i,a,b) for(long long i=a;i>=(b);--i) 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 3e5+10;
const int N = 1e5+10;
const int E = 1e6+10;  
string s;
ll k;

int main(){
	cin>>k;
	cin>>s;
	if(s.size()<=k){
		cout<<s<<endl;
		return 0;
	}
	else{
		F(i,0,k-1){
			cout<<s[i];
		}
		cout<<"..."<<endl;
	}
}

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

typedef long long ll;

int main(){
    int N,M,X;
    cin>>N>>M>>X;
    int C[N];
    int A[20][20];

    for(int i=0; i<N; i++){
        cin>>C[i];
        for(int j=0; j<M; j++){
            cin>>A[i][j];
        }
    }

    bool flag = false;
    int ans = 100000000;

    for(int bit=0; bit<(1<<N); bit++){
        vector<int> alg(M,0);
        bool check = true;
        int cnt = 0;

        for(int i=0; i<N; i++){
            if(!(bit & (1<<i))) continue;
            cnt += C[i];
            for(int j=0; j<M; j++){
                alg[j] += A[i][j];
            }
        }

        for(int i=0; i<M; i++){
            if(alg[i] < X) check = false;
        }

        if(check){
            ans = min(ans,cnt);
            flag = true;
        }
    }   

    if(!flag) ans = -1;
    cout<<ans<<endl;

    return 0; 
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int N;
int numbers[3] = {3, 5, 7};
int ok = ((1 << 3) | (1 << 5) | (1 << 7));

int dfs(int num, int sz, int lim, int stat) {
    // cout << "# num : " << num << " sz : " << sz << " stat : " << stat << " N : " << N << endl;
    if (num > N) return 0;

    int count = 0;
    if (sz > 0 && num <= N && stat == ok) count++;
    if (sz == lim) return count;

    REP(i, 0, 3) {
        count += dfs(num * 10 + numbers[i], sz + 1, lim, stat | (1 << numbers[i]));
    }
    return count;
}

int main() {
    cin >> N;
    cout << dfs(0, 0, log10(N) + 1, 0) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#define ll long long
#include<vector>
 
using namespace std;
 
const ll mod = 998244353;
const ll N = 200000 + 10;
 
ll inv[N];
ll f[N];
 
ll ksm(ll a, ll b)
{
	ll rul = 1;
	while(b)
	{
		if(b & 1) rul = rul * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return rul;
}
 
ll c(ll a, ll b)
{
	return f[a] * inv[a-b] % mod * inv[b] % mod; 
}
 
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	
	int maxn = max(n,m);
	f[0] = 1;
	for(ll i = 1; i<=maxn; i++) f[i] = f[i-1] * i % mod;//求i! 
	inv[maxn] = ksm(f[maxn], mod-2);
	for(ll i = maxn-1; i>=0; i--) inv[i] = inv[i+1] * (i+1) % mod;//求逆元 
	
	ll ans = 0;//C(n-1,n-1-i)*m*(m-1)^(n-1-i) //n-1-i为隔板数 
	ll tem = ksm(m-1,n-1-k); 
	for(int i=n-1-k; i<=n-1; i++)
	{
		ans = ans + c(n-1, i) % mod * m % mod * tem % mod;
		ans = ans % mod;
		tem = tem * (m-1) % mod;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6700
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    char c; cin >> c;
    string s = "ACGT", t = "TGCA";
    rep(i,4) {
        if (s[i] == c) {
            cout << t[i] << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, lint> Pr;
const int N = 1 << 24;
const lint INF = 1ll << 56;

int n;
lint d;
lint x[30], y[30];

vector<Pr> v1, v2;

bool next_pat(int pat[])
{
	pat[0]++;
	for (int i = 0; i < 15; i++){
		if (pat[i] == 3){
			pat[i] = 0;
			pat[i + 1]++;
		}
		else return true;
	}
	return false;
}

void makeSeq(vector<Pr> &v, lint x[], lint y[])
{
	v.reserve(14348907);
	int pat[16] = {};
	do {
		Pr p(0, 0);
		for (int i = 0; i < 15; i++){
			if (pat[i] == 1){
				p.first += x[i];
				p.second += y[i];
			}
			else if (pat[i] == 2){
				p.first -= x[i];
				p.second -= y[i];
			}
		}
		v.push_back(p);
	} while (next_pat(pat));
	
	sort(v.begin(), v.end());
}

int main()
{
	cin >> n >> d;
	for (int i = 0; i < n; i++){
		cin >> x[i] >> y[i];
	}
	n = 30;
	
	makeSeq(v1, x, y);
	makeSeq(v2, x + 15, y + 15);
	reverse(v2.begin(), v2.end());
	
	lint res = 0;
	deque<int> dq;
	int l = 0, r = 0;
	for (int i = 0; i < v1.size(); i++){
		Pr pl(-v1[i].first + d, INF);
		Pr pr(-v1[i].first - d, -INF);
		
		while (r < v2.size() && v2[r] > pr){
			while (dq.size() && v2[dq.back()].second <= v2[r].second){
				dq.pop_back();
			}
			dq.push_back(r++);
		}
		
		while (l < v2.size() && v2[l] > pl){
			if (dq.size() && dq.front() == l){
				dq.pop_front();
			}
			l++;
		}
		
		if (dq.size()){
			res = max(res, v1[i].second + v2[dq.front()].second);
		}
	}
	
	for (int i = 0; i < v1.size(); i++){
		if (abs(v1[i].first) <= d) res = max(res, v1[i].second);
		if (abs(v2[i].first) <= d) res = max(res, v2[i].second);
	}
	
	cout << res << endl;
	
	return 0;
}

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

D={}
for i in range(1,N+1):
    I=str(i)
    if (I[-1],I[0]) not in D:
        D[(I[-1],I[0])]=1
    else:
        D[(I[-1],I[0])]+=1

ans=0
for j in range(1,N+1):
    J=str(j)
    if (J[0],J[-1]) in D:
        ans+=D[(J[0],J[-1])]
print(ans)

Measured memory_bytes: 3064
// 2012/03/02 Tazoe

#include <iostream>
using namespace std;

bool DFS(int A[10], int i, int B, int C){
	if(i==10)
		return true;

	if(A[i]>B&&DFS(A, i+1, A[i], C))
		return true;

	if(A[i]>C&&DFS(A, i+1, B, A[i]))
		return true;

	return false;
}

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

	for(int i=0; i<N; i++){
		int A[10];
		for(int j=0; j<10; j++){
			cin >> A[j];
		}

		if(DFS(A, 0, 0, 0)){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

a,b,c,d=mint()
print(max(a*c,a*d,b*c,b*d))

Measured memory_bytes: 67984
#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=300000+20;
int n,tot;
int a[maxn],b[maxn];
int main()
{
	int i,j,k;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		tot^=a[i];
	}
	for(i=0;i<n;i++)
	{
		b[i]=tot^a[i];
		cout<<b[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 4692
use std::cmp;

fn input_with_space_singleline() -> Vec<i64>{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).expect("!");
    s.trim().split(" ").map(|ref x|x.parse::<i64>().unwrap()).collect::<Vec<i64>>()
}

pub fn main(){
    let N = input_with_space_singleline()[0] as usize;
    let A = input_with_space_singleline();
    // 累積和
    let mut _accum = 0i64;
    let mut accum = Vec::<i64>::new();
    for a in &A {
        _accum += *a;
        accum.push(_accum);
    }
    //仕切り(範囲には仕切りも含む)
    let mut upper = 0usize;
    let mut bottom = 2usize;
    let mut result: i64 = 10i64.pow(18u32);
    for middle in 1usize..(N-2) as usize {
        //尺取り法（上部
        loop{
            if upper == middle - 1 {
                break;
            }
            let u = accum[upper ];
            let b = accum[middle ] - accum[upper ];
            if (u-b).abs() > ((u + A[(upper + 1) ]) - (b - A[(upper + 1) ])).abs() {
                upper += 1;
            }else{
                break;
            }
        }
        //尺取り法（下部）
        loop{
            if bottom == N - 2 {
                break;
            }
            let u = accum[bottom ] - accum[middle ];
            let b = accum[(N-1) ] - accum[bottom ];
            if (u-b).abs() > ((u+A[(bottom+1) ])- (b-A[(bottom+1) ])).abs() {
                bottom += 1;
            }else{
                break;
            }
        }
        //最小値を求める
        let t: Vec<i64> = vec![accum[N-1] - accum[bottom], accum[bottom] - accum[middle], accum[middle] - accum[upper], accum[upper]];
        result = cmp::min(result, (*t.iter().max().unwrap() - *t.iter().min().unwrap()) as i64);
    }
    println!("{}", result);
}

Measured memory_bytes: 10492
import scala.io.Source.stdin

object Main extends App {
  def calc(op:String,x:Double,y:Double):Double = {
    op match {
      case "+" => x+y
      case "-" => x-y
      case "/" => x/y
      case "*" => x*y
      case _ => throw new Exception("Unexpected")
    }
  }

  def revP(a:Array[String],i:Int,l:List[Double]):Double = {
    if(i==a.length) l.head
    else if(a(i) != "-" && a(i).forall(x=>x=='-' || x.isDigit)) revP(a,i+1,a(i).toDouble::l)
    else {
      l match {
        case hd1::hd2::tl => revP(a,i+1, calc(a(i),hd2,hd1)::tl)
        case _ => throw new Exception("Unexpected")
      }
    }
  }
  stdin.getLines.foreach { s=>
    printf("%.6f\n",revP(s.split(" "),0,Nil))
  }
}

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

using namespace std;

#define endl '\n'
#define Opy ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef long long ll;

int main()
{
    //Opy;

/*-------------------------------------------------
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
-------------------------------------------------*/
    string A;

    cin>> A;

    if(A[2] == A[3] && A[4] == A[5]) cout<< "Yes\n";

    else cout<< "No\n";

    return 0;
}


Measured memory_bytes: 3532
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n;
    string s;
    int ans = 0;
    cin >> n;
    if (n % 1000 == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << 1000 - (n % 1000) << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

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

int main() {
  int N, T[100], M, P[100], X[100];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> T[i];
  cin >> M;
  for (int i = 0; i < M; i++) cin >> P[i] >> X[i];

  for (int i = 0; i < M; i++) {
    int ans = 0;

    for (int j = 0; j < N; j++) {
      if (P[i] - 1 == j) ans += X[i];
      else ans += T[j];
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;



int main(){
    int m,n,k,s;
    cin>>n>>m;
    vector<bitset<10> > bulbs(m,0);
    vector<int> p(m);

    for(int i=0;i<m;i++){
        cin>>k;
        while(k--){
            cin>>s;
            bulbs[i].set(s-1);
        }
    }
    for(int i=0;i<m;i++){
        cin>>p[i];
    }
    int count = 0;
    for(int i=0;i<pow(2,n);i++){
        int light = 0;
        bitset<10> switches(i);
        for(int j=0;j<m;j++){
            if((bulbs[j] & switches).count() % 2 == p[j])
                light++;
        }
        if(light == m)
            count++;

    }
    cout<<count<<endl;


    return 0;

}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a==(b+c)||b==(a+c)||c==(a+b)){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FIO "agc31F"
#define ll long long

const int N=5e4+5,V=1e6+5;

int n,m,Q,MOD;
int u[N],v[N],w[N];
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
int vis[2][V],g,z;
int id[N][2][3],f[N*2*3],ptr;

inline int find(int x){
  while(x^f[x])x=f[x]=f[f[x]];
  return x;
}

inline void merge(int u,int v){
  if((u=find(u))==(v=find(v)))return;
  f[u]=v;
}

inline bool chk(int s,int t,int r){
  for(int x=0;x<2;x++)
    for(int y=0;y<3;y++)
      if(find(id[t][0][0])==find(id[s][x][y])
          //&&printf("x=%d y=%d vis[%d][%d]=%d\n",x,y,x,r+z-y*g,vis[x][((r+z-y*g)%MOD+MOD)%MOD])
          &&vis[x][((r+z-y*g)%MOD+MOD)%MOD])return 1;
  return 0;
}

int main(){
  scanf("%d%d%d%d",&n,&m,&Q,&MOD);
  for(int i=1;i<=m;i++){
    scanf("%d%d%d",&u[i],&v[i],&w[i]);
    g=gcd(g,abs(w[i]-w[1]));
  }
  for(int i=1;i<=n;i++){
    for(int j=0;j<2;j++)
      for(int k=0;k<3;k++)
      id[i][j][k]=++ptr,f[ptr]=ptr;
  }
  if(!g)g=MOD;
  z=w[1]%g;
  for(int i=1;i<=m;i++){
    for(int x=0;x<2;x++)
      for(int y=0;y<3;y++)
        //printf("merge(f[%d,%d,%d],f[%d,%d,%d])\n",u[i],x,y,v[i],!x,(y*2+w[i]/g)%3),
        merge(f[id[u[i]][x][y]],f[id[v[i]][!x][(y*2+w[i]/g)%3]]);
  }
  MOD=gcd(MOD,3*g);
  
  //!!! MOD=1 then MOD-1=0
  for(int i=z,t=0;t<=MOD-1;t++,i=(i<<1)%MOD)
    //printf("vis[%d][%d]=%d\n",t&1,i),
    vis[t&1][i]=1;

  while(Q--){
    int s,t,r;
    scanf("%d%d%d",&s,&t,&r);
    puts(chk(s,t,r)?"YES":"NO");
  }

  return 0;
}


Measured memory_bytes: 11136
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	string S;
	cin >> S;
	int N = S.length();
	int ans = 100;
	for (int i = 0; i < 26; i++){
		char tar = 'a' + i;
		int ans_tmp = 0;
		int c = 0;
		for (int j = 0; j < N; j++){
			if (S[j] != tar){
				c++;
			}
			else{
				c = 0;
			}
			ans_tmp = max(c, ans_tmp);
		}
		ans = min(ans, ans_tmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N, M;
  scanf("%d %d", &N, &M);

  int L = 1, R = N;

  int i, l, r;

  for(i = 0; i < M; i++){
    scanf("%d %d", &l ,&r);

    if(L < l) L = l;
    if(R > r) R = r;
  }

  if(R - L + 1 < 0){
    printf("0\n");
    return 0;
  }

  printf("%d\n", R - L + 1);

}


Measured memory_bytes: 128
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

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


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(false);

    int n, t;
    cin >> n >> t;
    pii ab[n];
    for (int i = 0; i < n; i++) {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab, ab+n);

    int dp[t];
    memset(dp, 0, sizeof(dp));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < t; j++) {
            ans = max(ans, dp[j] + ab[i].second);
        }
        for (int j = t - 1; j >= ab[i].first; j--) {
            dp[j] = max(dp[j], dp[j-ab[i].first] + ab[i].second);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c;
	char op;
	scanf("%d %c %d", &a,&op,&b);
	while(op != '?')
	{
		if(op == '+')
		{
			c=a+b;
		}
		else if(op == '-')

		{
			c=a-b;
		}
		else if(op == '*')
		{
			c=a*b;
		}
		else if(op == '/')
		{
			c=a/b;
		}
		printf("%d\n",c);
		scanf("%d %c %d", &a,&op,&b);
	}

	return 0;
}


Measured memory_bytes: 2088
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000000000000LL
#define MOD 998244353
#define F first
#define S second
#define exit dskosad
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,m,l[MAXN],r[MAXN],c[MAXN];
vector<P> enter[MAXN];
vector<ll> exit[MAXN];
multiset<ll> ms;
ll dp[MAXN];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&l[i],&r[i],&c[i]);
        enter[l[i]].push_back(P(r[i],c[i]));
    }
    dp[1]=0;
    for(int i=1;i<=n;i++)
    {
        if(i!=1)
        {
            if(ms.size()) dp[i]=*ms.begin();
            else dp[i]=INF;
        }
        for(auto p:enter[i])
        {
            ll res=dp[i]+p.S;
            ms.insert(res);
            exit[p.F].push_back(res);
        }
        for(auto x:exit[i]) ms.erase(ms.find(x));
    }
    if(dp[n]>=INF) puts("-1"); else printf("%lld\n",dp[n]);
    return 0;
}


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

class Main {

	void solve() {

		out.println(inint()+inint()>=inint()? "Yes" : "No");

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

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

	public int inint() {
		return in.nextInt();
	}

	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

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

typedef long long ll;
int N;
ll A[100010];
ll Agcd[100010][2];
ll gcd(ll a, ll b)
{
    if(a < b) return gcd(b, a);
    ll r;
    while (r = a % b) 
    {
        a = b;
        b = r;
    }
    return b;
}

int main ()
{
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    memset(Agcd, 0, sizeof(Agcd));
    Agcd[0][0] = A[0];
    Agcd[N - 1][1] = A[N - 1];
    for(int i = 0; i < N - 1; i++)
    {
        Agcd[i + 1][0] = gcd(Agcd[i][0], A[i + 1]);
        Agcd[N - 2 - i][1] = gcd(Agcd[N - 1 - i][1],A[N - 2 - i]);
    }
    
    ll gcdmax = 0;
    for(int i = 0; i < N; i++)
    {
        ll gcdtmp;
        if(i == 0) gcdtmp = Agcd[1][1];
        else if(i == N - 1) gcdtmp = Agcd[N - 2][0];
        else gcdtmp = gcd(Agcd[i - 1][0], Agcd[i + 1][1]); 
        gcdmax = max(gcdmax, gcdtmp);
    }

    cout << gcdmax << endl;
    
   return 0;
}

Measured memory_bytes: 2688
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 3*10**8+1
for i in range(n-k+1):
    tmp = min(abs(x[i])+abs(x[i+k-1]-x[i]), abs(x[i+k-1])+abs(x[i]-x[i+k-1]))
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 14252
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
long long n,ans;
char s[50];
map<pair<string,string>,long long>M;
void dfs1(string s1,string s2,long long x)
{
	if(x==n)
	{
		pair<string,string> o;
		o.first=s1;
		o.second=s2;
		M[o]++;
		return ;
	}
	dfs1(s1+s[x],s2,x+1);
	dfs1(s1,s2+s[x],x+1);
}
void dfs2(string s1,string s2,long long x)
{
	if(x==n-1)
	{
		pair<string,string> o;
		o.first=s1;
		o.second=s2;
		ans+=M[o];
		return ;
	}
	dfs2(s1+s[x],s2,x-1);
	dfs2(s1,s2+s[x],x-1);
}
int main()
{
	scanf("%lld",&n);
	scanf("%s",s);
	string s1,s2;
	dfs1(s1,s2,0);
	dfs2(s1,s2,2*n-1);
	printf("%lld\n",ans);
}

Measured memory_bytes: 87808
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<int, int> cnt;
    int n;
    cin>>n;

    for(int i=1; i<=n; i++)
    {
        int a;
        cin>>a;
        cnt[a]++;
    }
    int ans = 0;
    for( auto u : cnt)
    {
        if( u.second>=u.first ) ans+=( u.second - u.first );
        else ans += u.second;
    }
    cout<< ans <<endl;
}


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

using namespace std;

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

#ifdef DBG
#define log(item) cout << #item << " " << item << endl
#define loga(array, val) cout << #array << "[" << val << "] " << array [ val ] << endl
#else
#define log(item)
#define loga(array, val)
#endif

int gcd(int number1,int number2){
	int m = number1;
	int n = number2;

	if(number2 > number1){
		m = number2;
		n = number1;
	}

	while(m != n){
		int temp = n;
		n = m - n;
		m = temp;
	}

	return m;
}
int lcm(int number1,int number2){
	return number1 * number2 / gcd(number1,number2);	
}

//--------------------

map<string, int> mp;

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

    rep(i, N)
    {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }

    int ans = 0;

    for(auto m : mp)
    {
        auto y = m.second;
        ans += (y - 1) * y / 2;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

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

  vector<int> oddseq(101010), evenseq(101010);
  for (int i = 0; i < n; i++) {
    if (i % 2) {
      oddseq[v[i]]++;
    } else {
      evenseq[v[i]]++;
    }
  }
  pair<int, int> oddans1, evenans1;
  pair<int, int> oddans2, evenans2;
  for (int i = 0; i < 101010; i++) {
    if (oddans2.first < oddseq[i]) {
      oddans2.first = oddseq[i];
      oddans2.second = i;
      if (oddans1.first < oddans2.first) swap(oddans1, oddans2);
    }
    if (evenans2.first < evenseq[i]) {
      evenans2.first = evenseq[i];
      evenans2.second = i;
      if (evenans1.first < evenans2.first) swap(evenans1, evenans2);
    }
  }

  int ans = 0;
  if (oddans1.second == evenans1.second) {
    int ans1 = oddans1.first + evenans2.first;
    int ans2 = oddans2.first + evenans1.first;
    ans = max(ans1, ans2);
  } else {
    ans += oddans1.first + evenans1.first;
  }

  cout << n - ans << endl;

  return 0;
}


Measured memory_bytes: 1408
S=input()

#前までの連続するLの個数を-1,-2...,Rの個数を1,2....,と表す
before=1
after=-1
children=[0]*(len(S))

for i in range(1,len(S)):
  if S[i]=='L':
    if before>0:
      children[i]+=1
      before=-1
    elif before%2==0:
      children[i+before]+=1
      before-=1
    else:
      children[i+before-1]+=1
      before-=1
  else:
    #便宜上Rの個数をカウントするがしなくても良い
    if before>0:
      before+=1
    else:
      before=1
#逆から同様に
for i in range(len(S)-2,-1,-1):
  if S[i]=='R':
    if after<0:
      children[i]+=1
      after=1
    elif after%2==0:
      children[i+after]+=1
      after+=1
    else:
      children[i+after+1]+=1
      after+=1
  elif after<0:
    after-=1
  else:
    after=-1
print(*children)

Measured memory_bytes: 6512
#include <cmath>
#include <iostream>
#include <vector>

int main() {
  long long unsigned int H, W;
  std::cin >> H >> W;

  if (H == 1 || W == 1) {
    printf("1");
    return 0;
  }

  if (H % 2 == 0 || W % 2 == 0) {
    printf("%llu", (H * W) / 2);
  } else {
    printf("%llu", (H * W + 1) / 2);
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>
#include<random>



#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;

int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;


int N;
int num[101];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	int mx = 0, mn = 1000;
	REP(i, N) {
		int a; cin >> a;
		mx = max(mx, a);
		mn = min(mn, a);
		num[a]++;
	}
	bool ok = true;
	if (mx % 2 == 0) {
		if (mn != mx / 2) {
			ok = false;
		}
		if (num[mn] != 1)ok = 0;
		FOR(i, mn + 1, mx + 1) {
			if (num[i] < 2) {
				ok = 0;
			}
		}
	}
	else {
		if (mn != (mx + 1) / 2) {
			ok = 0;
		}
		if (num[mn] != 2)ok = false;
		FOR(i, mn+1, mx + 1) {
			if (num[i] < 2) {
				ok = false;
			}
		}
	}
	if (ok) {
		print("Possible");
	}
	else {
		print("Impossible");
	}
}

Measured memory_bytes: 256
n, m = map(int, input().split())
dicts = {key: [False,0] for key in range(1, n+1)}

for i in range(m):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        dicts[p][0] = True
        continue
    else:
        if dicts[p][0]==True:
            continue
        else:
            dicts[p][1] += 1
        
ans_list = [v[1] for k, v in dicts.items() if v[0]==True]
ans_n = len(ans_list)
penal = sum(ans_list)
print(ans_n, penal)

Measured memory_bytes: 23332
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;

	cout << 180 * (N-2) << endl;
}

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

#define db(s) cout << s << endl;

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

const int XX = 1000000007;

long f(long x) {
  long ans = 1;
  for (int i = 1; i <= x; i++) {
    ans = ((ans % XX) * (i % XX)) % XX;
  }
  return ans;
}

int main() {
  int N, M;
  cin >> N >> M;
  int d = abs(N - M);
  if (1 < d) cout << 0 << endl;
  else if (d == 1) cout << f(N) * f(M) % XX << endl;
  else cout << f(N) * f(M) * 2 % XX << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll T = 26;

ll D;
vector<ll> C;
vector< vector<ll> > S;
vector<ll> A, B;
ll AA, BB;

void input()
{
    cin >> D;

    C.assign(D, 0);
    rep (t, T) { cin >> C[t]; }

    S.assign(D, vector<ll>(T, 0));
    rep (d, D) { rep (t, T) { cin >> S[d][t]; } }

    A.assign(D, 0);
    B.assign(D, 0);
}

void output()
{
    rep (d, D) { cout << A[d] + 1 << endl; }
}

void solve()
{
    AA = 0;
    vector<ll> L(T, 0);

    rep (d, D)
    {
        ll xx = 0, tt = 0;

        rep (t, T)
        {
            const ll x = S[d][t] + (d + 1 - L[t]) * C[t];
            if (xx <= x) { xx = x; tt = t; }
        }

        A[d] = tt;
        L[tt] = d + 1;

        AA += S[d][tt];
        rep (t, T) { AA -= C[t] * (d + 1 - L[t]); }
    }
}

int main()
{
    input();

    solve();

    output();

    return 0;
}


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

// recursionを用いた深さ優先探索

string s;
vector<string> options = {"dream", "dreamer", "erase", "eraser"};

bool DFS (int n) {
  if (n == s.size()) return true;  // 最後まで来た = 綺麗に分割できた
  
  for (string c: options) {
    if (s.substr(n, c.size()) == c && ((n + c.size()) <= s.size())) {
      if (DFS(n + c.size())) return true;  // nからc.size分進める
    }
  }
  
  return false; // 分割できませんでした
}

int main() {
  cin >> s;
  cout << (DFS(0) ? "YES" : "NO") << endl;
}

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

typedef long long ll;

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0);

struct Problem {
  ll wa = 0, ac = 0 ;
};

Problem val[100005] ;

int main()
{
  ll n, m, pb, maxNum = 0, sol = 0, pen = 0 ;
  string s ;
  cin >> n >> m ;

  for(int i = 0; i < m; i++) {
    cin >> pb >> s ;
    if(s == "WA") {
      if(!val[pb].ac) val[pb].wa++ ;
    }
    else  val[pb].ac = 1 ;

    maxNum = max(maxNum, pb) ;
  }

  for(int i = 1; i <= maxNum; i++) {
    if(val[i].ac) {
      sol++ ;
      pen += val[i].wa ;
    }
  }

  cout << sol << " " << pen << endl ;
}


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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  int cur = 7 % k;
  int ans = 1;
  while (cur != 0) {
    cur = cur * 10 + 7;
    cur %= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int N, M;
vector<int> par;
vector<int> t_rank;

void init_union_find(void) {
	par.resize(N + 1, 0);
	t_rank.resize(N + 1, 0);
	for (int i = 1; i <= N; ++i)
		par[i] = i;
}

int find(int x) {
	if (par[x] == x)
		return x;
	else
		return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)
		return;
	if (t_rank[x] < t_rank[y])
		par[x] = y;
	else {
		par[y] = x;
		if (t_rank[x] == t_rank[y])
			t_rank[x]++;
	}
}

void input_init(void) {
	cin >> N >> M;
	init_union_find();
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		unite(a, b);
	}
}

int get_group_cnt(void) {
	int cnt = 0;
	for (int i = 1; i <= N; ++i) {
		if (par[i] == i)
			++cnt;
	}
	return cnt;
}

int main(void) {
	input_init();
	int g_cnt = get_group_cnt();
	int ans = g_cnt - 1;
	cout << ans << '\n';
	return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	rep(i,26){
		rep(j,16){
			if(i*4+j*7==n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))

iAs = [0] * (N + 1)
for i, A in enumerate(As):
    iAs[A] = i

ans = 0
iLs = list(range(N + 1))
iRs = list(range(N + 1))
for A in reversed(range(1, N + 1)):
    iA = iAs[A]
    iL, iR = iLs[iA], iRs[iA]
    ans += A * (iA - iL + 1) * (iR - iA + 1)
    iLs[iR + 1] = iL
    iRs[iL - 1] = iR

print(ans)


Measured memory_bytes: 37984
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

ll N, M;
bool E[10][10];
ll ans;
unsigned char endf;

void dfs(int n, unsigned char flag) {
  if (flag == endf) {
    ans++;
    return;
  }

  REP(i, N) if (E[n][i]) {
    if (flag & 0x01 << i)
      continue;
    unsigned char buf = flag + (0x01 << i);
    dfs(i, buf);
  }
}

void solve(long long NN, long long MM, vector<long long> a,
           vector<long long> b) {
  N = NN;
  M = MM;

  REP(i, N) { endf += 0x01 << i; }
  // cout << (int)end << endl;

  REP(i, M)
  E[a[i]][b[i]] = E[b[i]][a[i]] = true;

  dfs(0, 1);

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long M;
  long long N;
  cin >> N;
  cin >> M;
  vector<long long> a(M - 1 + 1);
  vector<long long> b(M - 1 + 1);
  for (int i = 0; i <= M - 1; i++) {
    cin >> a[i];
    a[i]--;
    cin >> b[i];
    b[i]--;
  }
  solve(N, M, a, b);
  return 0;
}


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

int n;
long long a[N];
long long pw2[N];
map<long long, int> num;

inline bool cmp(long long x, long long y) { return x > y;}

inline long long get(long long now) {
    long long x = pow(2, (int)log2(now));
    x *= 2; return x - now;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%lld", a + i), num[a[i]]++;
    pw2[0] = 1;
    for (int i = 1; i <= 50; ++i)
        pw2[i] = 1LL * pw2[i - 1] * 2;
    sort(a + 1, a + n + 1, cmp);
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        long long t = get(a[i]);
        if (a[i] == t && num[a[i]] < 2) continue;
        if (num[a[i]] > 0 && num[t] > 0) ans++, num[t]--, num[a[i]]--;
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,k,ans=0;
    cin>>n>>k;
    while (n>0)
    {
        n/=k;
        ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

ll n, a[405], dp[405][405];

ll rec(int i, int j){
    if(i+1==j)return 0;
    if(dp[i][j] < LLINF) return dp[i][j];
    ll res = LLINF;
    for(int k=i+1;k<j;k++){
        res = min(res, rec(i,k)+rec(k,j)+a[j]-a[i]);
    }
    dp[i][j] = res;
    return res;
}

int main() {
    cin >> n;
    REP(i,n) cin >> a[i+1];
    REP(i,n) a[i+1] += a[i];
    REP(i,n)fill(dp[i],dp[i]+n+1,LLINF);
    cout << rec(0,n) << endl;
    return 0;
}


Measured memory_bytes: 1536