akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    char num[4];
    for(int i=0;i<4;i++){
        cin>>num[i];
    }
    for(int bit=0;bit<(1<<3);bit++){
        int x=num[0]-'0';
        for(int i=0;i<3;i++){
            if(bit&(1<<i)){
                x+=num[i+1]-'0';
            }else{
                x-=num[i+1]-'0';
            }
        }
        if(x==7){
            cout<<num[0];
            if(bit&(1<<0))cout<<"+";
            else cout<<"-";
            cout<<num[1];
            if(bit&(1<<1))cout<<"+";
            else cout<<"-";
            cout<<num[2];
            if(bit&(1<<2))cout<<"+";
            else cout<<"-";
            cout<<num[3]<<"=7";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#we like agc
n=int(input())
import itertools
P=list(itertools.product('ACGT', repeat=3))
mod=10**9+7
use=[] 
for some in P:
    some=list(some)
    K="".join(some)
    use.append(K)
dp=[{some:0 for some in use}for k in range(n+1)]
for some in use:
    if some!="AGC" and some!="ACG" and some!="GAC":
        dp[3][some]=1

D=["A","C","G","T"]
for i in range(4,n+1):
    for some in use:
        #some=AAA,AAC,AAG,,,,,,,,TTT
        for j in range(4):
            S=list(some+D[j])
            if (S[0]=="A" and S[2]=="G" and S[3]=="C")  or (S[1]=="G" and S[2]=="A "and S[3]=="C") or (S[0]=="A" and S[1]=="G" and S[3]=="C"):
                pass
            else:
                if some!="AGC" and some!="ACG" and some!="GAC":
                    dp[i]["".join(S[1:])]+=dp[i-1][some]
                    dp[i]["".join(S[1:])]=dp[i]["".join(S[1:])]%mod
ans=0
for some in use:
    if some!="AGC" and some!="ACG" and some!="GAC":
        ans+=dp[n][some]
print(ans%mod)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;



int main(){
    string s;
    cin >> s;
    if(s[0] == 'S'){
        if(s[1] == 'U'){
            cout << "7";
            return 0;
        }else{
            cout << "1";
            return 0;
        }
    }
    if(s[0] == 'M'){
        cout << "6";
        return 0;
    }
    if(s[0] == 'T'){
        if(s[1] == 'U'){
            cout << "5";
            return 0;
        }else{
            cout << "3";
            return 0;
        }
    }
    if(s[0] == 'W'){
        cout << "4";
        return 0;
    }
    if(s[0] == 'F'){
        cout << "2";
        return 0;
    }


    return 0;
}

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

using namespace std;

int main()
{
    int n,arr[55];
    long long int sum = 0;
    cin>>n;
    for(int i = 0; i<n ;i++)
    {
        cin>>arr[i];
    }
    for(int i = 0; i<n ;i++)
    {
        for(int j = i+1 ; j<n; j++)
        {
            sum+=(arr[i]*arr[j]);
        }
    }
    cout<<sum<<endl;
    return 0;
}




Measured memory_bytes: 256
from math import factorial

n = int(input())
S = [input() for _ in range(n)]
d = dict()

for s in S:
    s = ''.join(sorted(s))
    if s not in d.keys():
        d[s] = 1
    else:
        d[s] += 1

d_comb = dict()
def fact(n):
    keys = d_comb.keys()
    if n not in keys:
        d_comb[n] = factorial(n)
    return d_comb[n]

def comb(n, r):
    if n < r:
        return 0
    f_n = fact(n)
    f_nr = fact(n - r)
    f_r = fact(r)
    return f_n // (f_nr * f_r)

ans = 0
for k in d.keys():
    ans += comb(d[k], 2)
print(ans)

Measured memory_bytes: 29072
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int n,X,v[MAXN];
int JCD;
int jcd(int x,int y){
	if(x==0)return y;
	return jcd(y%x,x);
}
int main(){
	scanf("%d%d",&n,&X);
	for(int i=1;i<=n;i++)
		scanf("%d",&v[i]);
	v[++n]=X;
	sort(v+1,v+n+1);
	JCD=v[2]-v[1];
	for(int i=3;i<=n;i++)
		JCD=jcd(JCD,v[i]-v[i-1]);
	printf("%d\n",JCD);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll gcd(ll a, ll b){
  if(b==0) return a;
  else gcd(b,a%b);
}
ll lcm(ll a, ll b){
  return a/gcd(a,b)*b;
}
int main(){
  ll n;
  cin >> n;
  vector<pair<ll,ll>>vec;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      vec.push_back(make_pair(i,n/i));
    }
  }
  ll ans=2e12;
  rep(i,vec.size()){
    ans=min(vec[i].first-1+vec[i].second-1,ans);
  }
  
  cout <<ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int n,m;
vector<P> g[105];
vector<P> cand;
int sz[105];
int dist[105];
int dist2[105];
void dijkstra(int s)
{
	for(int i=0;i<105;i++)dist[i]=INF;
	dist[s]=0;
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(0,s));
	while(!q.empty())
	{
		P a = q.top();
		q.pop();
		int v = a.sec;
		if(dist[v]<a.fi)continue;
		for(int i=0;i<g[v].size();i++)
		{
			int to = g[v][i].fi;
			int cost = g[v][i].sec;
			if(dist[to]>a.fi+cost)
			{
				dist[to]=a.fi+cost;
				q.push(P(dist[to],to));
			}
		}
	}
	return;
}
int main()
{
	while(1)
	{
		scanf("%d %d",&n,&m);
		if(n==0&&m==0)break;
		cand.clear();
		for(int i=0;i<105;i++)g[i].clear();
		for(int i=0;i<m;i++)
		{
			int a,b,c;
			scanf("%d %d %d",&a,&b,&c);
			a--;b--;
			g[a].pb(P(b,c));
			g[b].pb(P(a,c));
		}
		for(int i=0;i<105;i++)sz[i]=g[i].size();
		dijkstra(0);
		for(int i=0;i<105;i++)dist2[i]=dist[i];
		dijkstra(n-1);
		int ans = dist2[n-1];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<sz[i];j++)
			{
				for(int k=0;k<sz[g[i][j].fi];k++)
				{
					int to = g[g[i][j].fi][k].fi;
					if(i!=to)ans = min(ans,dist[i]+dist2[to]);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    ll a = n%k;
    ll ans = min(a,abs(a-k));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int v[200010], r[200010];

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    string s; cin >> s;

    int pcnt = 0;
    for (int i=0;i<n;i++) pcnt += s[i] == '1';

    for (int i=1;i<=n;i++) {
        r[i] = 1 + r[i%__builtin_popcount(i)];
    }

    int p = pcnt+1, val1 = 0;
    int q = pcnt-1, val2 = 0;
    for (int i=0;i<n;i++) {
        val1 = val1*2 + (s[i]=='1');
        val1 %= p;
        if (q>0) {
            val2 = val2*2 + (s[i]=='1');
            val2 %= q;
        }
    }

    int mul1 = 1, mul2 = 1;
    for (int i=n-1;i>=0;i--) {
        if (s[i]=='0') {
            int now = (val1+mul1)%p;
            v[i] = now%p;
        } else if (q>0) {
            int now = (val2+q-mul2%q)%q;
            v[i] = now%q;
        } else {
            v[i] = -1;
        }
        mul1 = mul1*2%p;
        if (q>0) mul2 = mul2*2%q;
    }

    for (int i=0;i<n;i++) {
        cout << (v[i]==-1? 0: 1+r[v[i]]) << endl;
    }
}


Measured memory_bytes: 5300
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int n,a,b;
		n = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
		
		if (n*a < b) {
			System.out.println(n*a);
		} else {
			System.out.println(b);
		}

	}

}

Measured memory_bytes: 23764
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc106_a.cpp
 * time   : Thu Apr 30 22:18:41 2020
 * quest  : A - Garden
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << (a * b) - (a + b - 1) << "\n";
  return 0;
}


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

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

#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()
{
    int n,ans=0;
    cin>>n;
    vector<int> c(n),v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin>>c[i];
    }
    for (int i = 0; i < n; i++)
    {
        if(v[i]>c[i]) ans+=v[i]-c[i];
    }
    
    cout<<ans<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

int main() {
    int n, m, X, Y;
    scanf("%d %d %d %d", &n, &m, &X, &Y);
    for (int i = 0, x; i < n; i++) {
        scanf("%d", &x);
        X = std::max(x, X);
    }
    for (int i = 0, y; i < m; i++) {
        scanf("%d", &y);
        Y = std::min(y, Y);
    }
    if (X < Y) puts("No War");
    else puts("War");
    return 0;
}

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

#define all(p) p.begin(), p.end()
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define ll long long
#define llu unsigned long long
#define ld long double
#define vll vector<long long int>
#define vi vector<int>
#define pii pair <int, int>
#define pll pair <long long int, long long int>
#define vpii vector<pair<int,int> >
#define nl cout<<"\n"
#define sp cout<<" "
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)

const  int  INF = 0x7f7f7f7f;

int  main ()
{
	ios_base::sync_with_stdio(false);
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;

    int ans=0;
    rep(i,0,n-1)
    {
        if(s[i]==t[0])
        {
            int c=0;
            rep(j,i,n-1)
            {
                if(s[j]==t[c])
                    c++;
                else break;
            }
            if(c==(n-i)) ans=max(ans,c);
        }
    }
    cout<<2*n-ans;nl;
    return  0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	if(N==1) {
		cout<<"Hello World"<<endl;
	}
	else {
		cin>>A>>B;
		cout<<(A+B)<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main() {
    long long N,K;
    cin >> N>>K;
    vector<long long> A(N+1,0);
    for (long long i=0;i<N;i++){
        cin>>A.at(i+1);
    }
    vector<int> number(N+1,-1);
    number[1]=0;
    int idou=0;
    int now=1;
    for (long long i = 0;i<K;i++){
        if(number[A[now]]==-1){
            now=A[now];
            idou++;
            number[now]=idou;
        }else{
            idou++;
            int cheat=(K-number[A[now]])%(idou-number[A[now]]);
            rep(j,cheat+1){
                now=A[now];
            }
            break;
        }
    }
    cout << now <<endl;
}

Measured memory_bytes: 5640
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

k,a,b = readInts()

if a+1<=k and a+2<b:
	k-=a+1
	ans=k//2*(b-a)+k%2+b
else:
	ans = k+1

print(ans)

Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=2e5+10;
char s[MAXN];
int sum1[MAXN],sum2[MAXN];
int main()
{
	int n=read();
	scanf("%s",s+1);
	int ans=n+1;
	for(int i=1;i<=n;++i)
	{
		if(s[i]=='.')
			++sum1[i];//white
		else
			++sum2[i];
		sum1[i]+=sum1[i-1];
		sum2[i]+=sum2[i-1];
	}
	ans=sum2[n];
	for(int i=1;i<=n;++i)
	{
		ans=min(ans,i-sum1[i]+n-i-(sum2[n]-sum2[i-1]));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int W;
    int H;
    int x;
    int y;
    int r;
    cin>> W;
    cin>> H;
    cin>> x;
    cin>> y;
    cin>> r;
    if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0){
        cout<<"Yes"<<endl;
} else{
    cout<<"No"<<endl;
}
    
}

Measured memory_bytes: 1160
def main():
    n, k = map(int, input().split()) 
    al = list(map(int, input().split())) 
    city_l = [1]
    city_s = set([1])
    loop_city_l = []
    curr_city = 1
    cnt = 0
    for i in range(1,k+1):
        next_c = al[curr_city-1]
        if next_c in city_s:
            cnt = i
            first_city = city_l.index(next_c)
            loop_city_l = city_l[first_city:]
            break
        else:
            city_s.add(next_c)
            city_l.append(next_c)
        curr_city = next_c
    else:
        print(curr_city)
        return

    # print(loop_city_l)
    remained = k-cnt
    last_pos = remained%len(loop_city_l)
    print(loop_city_l[last_pos])

if __name__ == "__main__":
    main()

Measured memory_bytes: 123132
fun main(args: Array<String>) {
    val s = readLine()!!
    var (x, y) = readLine()!!.split(" ").map{it.toInt()}

    val ss = s.split("T").map{ it.length }
    x -= ss[0]
    val l = ss.drop(1)

    fun canCreate(a: Int, l: List<Int>): Boolean {
        var curr = BooleanArray(s.length * 2 + 1) { false }
        var next = BooleanArray(s.length * 2 + 1) { false }
        curr[s.length] = true

        for (b in l) {
            for (i in curr.indices) {
                if (i + b < next.size) {
                    next[i + b] = curr[i] || next[i + b]
                }
                if (i - b >= 0) {
                    next[i - b] = curr[i] || next[i - b]
                }
            }

            val tmp = next
            next = curr
            curr = tmp
            next.fill(false)
        }

        if (s.length + a < 0 || s.length + a >= curr.size) {
            return false
        } else {
            return curr[s.length + a]
        }
    }

    fun judge(a: Int, b: Int): Boolean {
        return canCreate(a, l.filterIndexed { index, c -> index % 2 == 0}) &&
                canCreate(b, l.filterIndexed { index, c -> index % 2 == 1})
    }

    if (judge(y, x)) {
        println("Yes")
    } else {
        println("No")
    }
}


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


int main()
{
	int N;
	cin>>N;
	map<int,int> m;
	rep(i,N-1)
	{
		int a;
		cin>>a;
		m[--a]++;
	}
	rep(i,N)
	{
		cout<<m[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 12968
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

bool f(int a, int b, int c){
    return (a == 0 && b == 1 && c == 2);
}

int dp[110][4][4][4] = {};
signed main(){
    
    int n; cin >> n;
    dp[0][3][3][3] = 1;
    for(int i = 0; i < n; i++){
        for(int a = 0; a < 4; a++){
            for(int b = 0; b < 4; b++){
                for(int c = 0; c < 4; c++){
                    for(int d = 0; d < 4; d++){
                        if(dp[i][a][b][c] == 0) continue;

                        if(f(a, b, c)) continue;
                        if(f(a, b, d)) continue;
                        if(f(a, c, d)) continue;
                        if(f(b, c, d)) continue;

                        if(f(b, a, c)) continue;
                        if(f(a, b, c)) continue;
                        if(f(c, b, d)) continue;
                        if(f(b, d, c)) continue;
                        dp[i + 1][b][c][d] += dp[i][a][b][c];
                        dp[i + 1][b][c][d] %= MOD;
                    }
                }
            }
        }
    }

    int ans = 0;
    for(int a = 0; a < 4; a++){
        for(int b = 0; b < 4; b++){
            for(int c = 0; c < 4; c++){
                ans += dp[n][a][b][c];
                ans %= MOD;
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int a,b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << endl;
}

Measured memory_bytes: 256
fn main() {
  let (n, m): (usize, usize) = read_tuple();
  let mut edges: Vec<(usize, usize)> = read_tuples(m);
  
  for i in 0..m {let (a,b) = edges[i]; edges[i] = (a-1,b-1)}
  let graph: Graph = Graph::new_nonlabeled(n, &edges[..]);
  
  let mut ans = 0;
  for (v, w) in edges {
    let mut g = graph.clone();
    g.cut(v,w);
    ans += if g.is_connected() {0} else {1};
  }
  
  println!("{:?}", ans);
}

struct Graph {
  adj: Vec<Vec<(usize,isize)>>
}

impl Clone for Graph {
  fn clone(&self) -> Graph {
    Graph {adj: self.adj.clone()}
  }
}

impl Graph {
  fn new_nonlabeled(n: usize, edges: &[(usize,usize)]) -> Graph {
    let mut g: Vec<Vec<(usize,isize)>> = vec![vec![]; n];
    for &(a, b) in edges {
      g[a].push((b,0));
      g[b].push((a,0));
    }
    Graph {adj: g}
  }
  
  fn cut(&mut self, v: usize, w: usize) {
    self.adj[v].retain(|&(t,_)| t != w);
    self.adj[w].retain(|&(t,_)| t != v);
  }
  
  fn is_connected(&self) -> bool {
    self.dfs(0).len() == self.adj.len()
  }
  
  fn dfs(&self, s: usize) -> Vec<(usize)> {
    fn go(g: &Graph, current: usize, mut path: &mut Vec<usize>, mut visited: &mut Vec<bool>) {
      for &(next, _) in &g.adj[current] {
        if visited[next] {
          continue
        } else {
          visited[next] = true;
          path.push(next);
          go(&g, next, &mut path, &mut visited)
        }
      }
    }
    let mut path = vec![s];
    let mut visited = vec![false; self.adj.len()];
    visited[s] = true;
    go(&self, s, &mut path, &mut visited);
    path
  }
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_tuples<T1: std::str::FromStr, T2: std::str::FromStr>(n: usize) -> Vec<(T1, T2)> {
  let mut vec: Vec<(T1, T2)> = vec![];
  for _ in 0 .. n {
    vec.push(read_tuple());
  }
  vec
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  if ((a * b) % 2 == 0)
  {
  	cout << "Even" << endl;
  }
  else
  {
  	cout << "Odd" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    //a=a%MOD;
    while(b>0){
        if(b&1)
		{res=(res*a);
		//res%=MOD;
		b--;}
        a=(a*a);
        //a%=MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int C(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>n;
	arrin(arr,n);
	
	for(i=0;i<n;i++)
	for(j=i+1;j<n;j++)
	for(k=j+1;k<n;k++)
	{
	    int yo[3];
	    yo[0]=arr[i];
	    yo[1]=arr[j];
	    yo[2]=arr[k];
	    sort(yo,yo+3);
	    if(yo[0]+yo[1]>yo[2] and yo[0]!=yo[1] and yo[1]!=yo[2])
	    sum++;
	    //debarr(yo,3);}
	}
	cout<<sum;
}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define pb push_back
#define eb emplace_back
const  int MAX=1000000;

int main()
{


      ll n;

      cin>>n;

      ll ara[n+2];


      for(ll i=0;i<n;i++)
      {
          cin>>ara[i];
      }
      sort(ara,ara+n);

      ll cnt=0;

      for(ll i=0;i<n;i++)
      {
          for(ll j=i+1;j<n;j++)
          {
              for(ll k=j+1;k<n;k++)
              {
                  ll a=ara[i];
                  ll b=ara[j];
                  ll c=ara[k];

                if(a==b || b==c || c==a)continue;

                  if(a+b>c)cnt++;



              }
          }
      }

      cout<<cnt<<endl;



    }











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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

long long arr[51], cur[51];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;

    long long diff, tot = 0;

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

    for(int i = 0; i < 1250; ++i){
        for(int j = 0; j < n; ++j){
            diff = (arr[j] + (tot - cur[j])) - (n - 1);
            diff = diff / n + (diff % n > 0);
            tot += diff;
            cur[j] += diff;
            arr[j] -= n * diff;
        }
    }

    cout << tot << "\n";

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	cin >> S;
	int N = S.size();
	if (N == 2 && S[0]==S[1]) {
		cout << 1 << " " << 2 << endl;
		return 0;
	}
	REP(i, N - 2) {
		if (S[i] == S[i + 1] || S[i] == S[i + 2] || S[i + 1] == S[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}



Measured memory_bytes: 512
n = gets.chomp.to_f
a = []
a = gets.chomp.split.map(&:to_f)
c = 0
for b in 0..n - 1
  c = c + a[b]
end
c = c / n
e = []
for d in 0..n - 1
  e << (a[d] - c).abs
end
puts e.index(e.min)


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


int main() {

    string s,t;
    cin >> s >> t;
    
    if(s == t.substr(0,s.size())) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

def soinsu(n):
    arr = []
    now = n
    for i in range(2, int(n**0.5)+1):
        if now%i==0:
            cnt=0
            while now%i==0:
                cnt+=1
                now //= i
            arr.append([i, cnt])

    if now!=1:
        arr.append([now, 1])

#     if arr==[]:
#         arr.append([n, 1])

    return arr

fac_a=soinsu(a)
fac_b=soinsu(b)

print( len(set(s[0] for s in fac_a) & set(s[0] for s in fac_b) )+1)

Measured memory_bytes: 38512
#include <iostream>
#include <set>
using namespace std;
set<int> G[200005];
int dist[200005];
int N,M;
int main()
{
    cin>>N>>M;
    for(int i=1;i<=M;i++)
    {
        int x,y;
        cin>>x>>y;
        G[x].insert(y);
        G[y].insert(x);
    }
    for(int i=1;i<=N;i++)
    {
        if(G[1].find(i)!=G[1].end()&&G[N].find(i)!=G[N].end())
        {
            cout<<"POSSIBLE";return 0;
        }
    }
    cout<<"IMPOSSIBLE";
    return 0;
}


Measured memory_bytes: 28416
#include <cstdio>
#include <utility>
#include <cmath>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int p, ps = 0, q, qs = 0, i = 0;
	while (scan(p)) {
		q = in();
		ps += p * q;
		qs += q;
		i++;
	}
	out(ps, '\n', (int) round((float) qs / i), '\n');
}


Measured memory_bytes: 2516
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, l; cin >> n >> l;
	int sum = l * n + (n - 1)*n / 2;
	int mn = 1000000;
	int ret = 0;
	rep(i, 0, n - 1)
	{
		mn = min(mn, abs(i + l));
		ret = mn;
		if (i + l < 0)ret = -ret;
	}
	cout << sum - ret << endl;
}

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

const int mod = 998244353;
vector<int> G[3][101010];
int s[3][101010];
int f[3][512];
int M[3];

int buffer[101010];

int _10[202020];

int main()
{
	_10[0] = 1;
	for(int i = 1; i <= 200000; i++)
		_10[i] = 1ll * _10[i-1] * (((long long)1e18) % mod) % mod;
	
	
	int N;
	scanf("%d", &N);
	
	for(int t = 0; t < 3; t++)
	{
		scanf("%d", &M[t]);
		for(int i = 1; i <= M[t]; i++)
		{
			int u, v;
			scanf("%d%d", &u, &v);
			if(u > v)
				swap(u, v);
			G[t][u].push_back(v);
		}
		for(int i = N; i >= 1; i--)
		{
			for(int x: G[t][i])
				buffer[s[t][x]] = 1;
			while(buffer[s[t][i]])
				s[t][i]++;
			for(int x: G[t][i])
				buffer[s[t][x]] = 0;
			f[t][s[t][i]] += _10[i];
			f[t][s[t][i]] %= mod; 
		}
	}
	int ans = 0;
	
	for(int i = 0; i < 512; i++)
	for(int j = 0; j < 512; j++)
	{
		ans += 1ll * f[0][i] * f[1][j] % mod * f[2][i^j] % mod;
		if(ans >= mod)
			ans -= mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 18232
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
bool flag[1001][1001][1001];
int main(){
  int n;
  cin >> n;
  int sum = 0;
  int a[3];
  rep(i,n){
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if(flag[a[0]][a[1]][a[2]]) sum++;
    flag[a[0]][a[1]][a[2]] = true;
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 7092
#include<bits/stdc++.h>
using namespace std;
long long int ans[100022],arr[100022];
int main()
{
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>arr[i];
	ans[0]=0;
	for(i=1;i<n;i++)
	{
		ans[i]= abs(arr[i]-arr[i-1])+ans[i-1];
		if(i>=2)
			ans[i]= min(ans[i],abs(arr[i]-arr[i-2])+ans[i-2]);
	}
	cout<<ans[n-1];
	return 0;
}

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

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	return a%mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}
//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}


signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    //cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n;
        cin>>n;
        if(n == 0) cout<<1<<endl;
        else cout<<0<<endl;
			
        
        
    }



return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    string s,t;cin >> s >>t;
    t.erase(t.size()-1);
    if(s==t)cout <<"Yes" <<endl;
    else cout <<"No" <<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"


int main() {
	#ifndef ONLINE_JUDGE
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k; cin >> n >> k;
	vector<ll> nums(n);
	for_(i, 0, n) cin >> nums[i];
	
	for_(i, k, n) {
		cout << (nums[i-k] >= nums[i] ? "No" : "Yes") << endl;
	}

	return 0;
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[60][5010];
int n, sum, p;
ll ans;
int a[110];
int main()
{
	scanf("%d%d", &n, &p);
	for(int i = 1; i <= n; ++i) 
	{
		scanf("%d", &a[i]); 
		sum += a[i];
	}
	dp[0][0] = 1ll;
	for(int i = 1; i <= n; ++i)
	{
		dp[i][0] = 1ll;
		for(int j = 1; j <= sum; ++j) if(j >= a[i])
			dp[i][j] = dp[i - 1][j] + dp[i - 1][j - a[i]];
		else 
			dp[i][j] = dp[i - 1][j];
	}
	for(int i = 0; i <= sum; ++i) if(i % 2 == p)	
		ans += dp[n][i];
	printf("%lld\n", ans);
	return 0;
} 

Measured memory_bytes: 1536
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 1'000'000'007;

int main() {

    llint N, K;
    cin >> N >> K;
    llint ans = 0;
    llint min_sum = 0, max_sum = 0;
    for(int i = 0; i < K - 1; i++) {
        min_sum += i;
        max_sum += N - i;
    }
    for(int i = K - 1; i <= N; i++) {
        min_sum += i;
        max_sum += N - i;
        ans += (max_sum - min_sum + 1);
        ans %= MOD;
    }
    cout << ans;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    if(c - a - b > 0){
        if(4 * a * b < (c - a - b) * (c - a - b)){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }else{
        cout << "No" << endl;
        return 0;
    }
}

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

int main(){
    int N;
    cin>>N;
    int x[365],y[365],b[365],p[365];
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i]>>b[i]>>p[i];
        if(b[i]>=5&&p[i]>=2) cout<<(x[i]*b[i]+y[i]*p[i])*4/5<<endl;
        else if(x[i]*b[i]+y[i]*p[i]>((x[i]*max(5,b[i])+y[i]*max(2,p[i]))*4/5)){
              cout<<(x[i]*max(5,b[i])+y[i]*max(2,p[i]))*4/5<<endl;  
        }else cout<<x[i]*b[i]+y[i]*p[i]<<endl;
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;
  vector<ll> A(N, 0);
  for (ll i = 0; i < N - 1; i++) {
    ll a; cin >> a;
    A[a - 1]++;
  }
  for (ll i = 0; i < N; i++) {
    cout << A[i] << '\n';
  }
  return 0;
}

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

const int n_max=1e3+10;
const int inf=INT_MAX/4;
vector<int> g[n_max];
vector<int> rg[n_max];


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

  int n,m;
  cin >> n >>m;

  rep(i,m){
    int a,b;
    cin >> a >> b;
    --a;--b;
    g[a].pb(b);
    rg[b].pb(a);      
  }
  int min_loop=inf;
  int min_ind=-1;
  {
  rep(i,n){
    vector<int> dp(n,inf);
    queue<int> qu;    
    dp[i]=0;
    qu.push(i);
    while(!qu.empty()){
      int v = qu.front();qu.pop();
      for(auto nv:g[v]){
	if(nv==i){
	  if(min_loop>dp[v]+1){
	    min_loop = dp[v]+1;
	    min_ind = i;
	    //	    cout << "minloop ind " << min_loop << " " << min_ind << endl;
	  }	  
	}
	if(dp[nv] > dp[v]+1){
	  dp[nv] = dp[v]+1;
	  qu.push(nv);
	}
      }
    }    
  }
  }
  if(min_ind==-1){
    cout << -1 << endl;
    return 0;
  }
  else{
    cout << min_loop << endl;
  }
  vector<int> dp(n,inf);
  queue<int> qu;
  dp[min_ind]=0;
  qu.push(min_ind);
  bool ok=true;
  while(!qu.empty()){
    int v = qu.front();qu.pop();
    for(auto nv:g[v]){
      if(nv==min_ind){
	dp[min_ind]=dp[v]+1;
	ok=false;
	break;
      }
      if(dp[nv] > dp[v]+1){
	dp[nv] = dp[v]+1;
	qu.push(nv);
      }
    }
    if(!ok) break;
  }
  //  cout << "ind dp " << min_ind << endl;
  //  cout << dp[min_ind] << endl;
  vector<int> ans;
  ans.pb(min_ind);
  while(ans.size()!=min_loop){
    for(auto i:rg[min_ind]){
      if(dp[i] == dp[min_ind]-1){
	//	cout << i << endl;
	ans.pb(i);
	min_ind = i;
	break;
      }
    }
  }
  rep(i,min_loop){
    cout << ans[i]+1 << endl;
  }

  return 0;
    

}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int n;
char s[10005];
int main(){
	while(~scanf("%d", &n)){
		scanf("%s", s + 1);
		int cnt1 = 0, tot1 = 0;
		for(int i = 1; i <= n; i++){
			if(s[i] == '(') cnt1++;
			if(s[i] == ')'){
				if(cnt1) cnt1--;
				else tot1++;
			}
		}
		int cnt2 = 0, tot2 = 0;
		for(int i = n; i >= 1; i--){
			if(s[i] == ')') cnt2++;
			if(s[i] == '('){
				if(cnt2) cnt2--;
				else tot2++;
			}
		}
		while(tot1--) printf("(");
		printf("%s", s + 1);
		while(tot2--) printf(")");
	}
	return 0;
}




Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
main()
{
	int i, l, x, j, f;
	char a[15], b[15];
	scanf("%s", a);
	l=strlen(a);
	for (i=0, j=0, f=0; i<l; i++)
	{
		if (a[i]!='B')
		{
			b[j]=a[i];
			j++;
			f=0;
		}
		else
		{
			if (j>0)
			{
				j--;
				f++;
			}
		}
	}
	x=strlen(b);
	x=x-f;
	for (i=0; i<j; i++)
	{
		printf("%c", b[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

bool compare_pair(pair<ll, ll> a, pair<ll, ll> b){
    if(a.first == b.first){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

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

    vector<pair<ll, ll>> arry(n);
    rep(i, n)cin >> arry[i].first >> arry[i].second;
    sort(ALL(arry), compare_pair);

    ll pos = 0;
    rep(i, n){
        pos += arry[i].second;
        if(pos >= k){
            cout << arry[i].first;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a,b,c,d,e,f;
	double ma = -1.0;
	int ma1,ma2;
	cin >> a >> b >> c >> d >> e >> f;
	for(int i = 0;i <= 30;i++){
		for(int j = 0;j <= 30;j++){
			int water = (a * i + b * j) * 100;
			if(!water) continue;
			for(int k = 0;k <= 3000;k++){
				if(water + k * c > f) continue;
				int matoke = water / 100 * e;
				if(matoke - k * c < 0) continue;
				int l = min((matoke - k * c) / d,(f - water - k * c) / d);
				if(ma < (double)(k * c + d * l) / (double)(water + k * c + d * l)){
					ma = (double)(k * c + d * l) / (double)(water + k * c + d * l);
					ma1 = water + k * c + d * l;
					ma2 = k * c + d * l;
				}
			}
		}
	}
	cout << ma1 << " " << ma2 << endl;
	return 0;
}

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

int main()
{
    int k, s;
    cin >> k >> s;
    vector<int> sum_ij;
    rep(i, k+1)
        rep(j, k+1)
            sum_ij.push_back(i+j);
    sort(all(sum_ij));
    long count = 0;
    rep(i, sum_ij.size())
    {
        if (0 <= s - sum_ij[i] && s - sum_ij[i] <= k) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 35044
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int n = s.length() + 1;

        int[] lt = new int[n];
        int[] gt = new int[n];

        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) == '<') {
                lt[i + 1] = lt[i] + 1;
            }
        }
        for (int i = n - 2; i >= 0; i--) {
            if (s.charAt(i) == '>') {
                gt[i] = gt[i + 1] + 1;
            }
        }
        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += Math.max(lt[i], gt[i]);
        }
        System.out.println(sum);
    }

}

Measured memory_bytes: 32904
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int, D: int):

    while True:
        C = C - B

        if C <= 0:
            print(YES)
            break

        A = A - D

        if A <= 0:
            print(NO)
            break

    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner(System.in);
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {

		int[] abc = { cin.nextInt(), cin.nextInt(), cin.nextInt() };
		Arrays.sort(abc);
		cout.println(abc[0] + abc[1]);
	}

	static class FastScanner {
		private final InputStream in;
		private final byte[] buf = new byte[1 << 14];
		private int bufs = 0;
		private final long[] num = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		private int ptr = 0;

		public FastScanner(InputStream in) {
			super();
			this.in = in;
		}

		boolean hasNext() {
			while (hasNextByte() && !isMeaningful(buf[ptr]))
				ptr++;
			return hasNextByte();
		}

		private boolean hasNextByte() {
			if (ptr < bufs)
				return true;
			ptr = 0;
			try {
				bufs = in.read(buf);
			} catch (IOException e) {
				throw new IllegalArgumentException(e);
			}
			if (bufs <= 0)
				return false;
			return true;
		}

		private static boolean isMeaningful(int b) {
			return 33 <= b && b <= 126;
			// return b != -1 && !Character.isWhitespace(b);
		}

		String next() {
			if (!hasNext())
				throw new IllegalArgumentException();
			StringBuilder sb = new StringBuilder();
			int b = read();
			while (isMeaningful(b)) {
				sb.appendCodePoint(b);
				b = read();
			}
			return sb.toString();
		}

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

		int nextInt() {
			long nl = nextLong();
			int ni = (int) nl;
			if (ni != nl)
				throw new IllegalArgumentException();
			return ni;
		}

		long nextLong() {
			if (!hasNext())
				throw new IllegalArgumentException();
			long n = 0;
			int plus = 1;
			int b = read();
			if (b == '-') {
				plus = -1;
				b = read();
			}
			if ('0' > b || b > '9')
				throw new java.lang.IllegalArgumentException();
			while (true) {
				if (!isMeaningful(b))
					return plus * n;
				n *= 10;
				n += num[b - '0'];
				b = read();
			}
		}

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

	}
}


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

int main()
{
  int N;
  cin >> N;
  double sum = 0;
  for (int i = 0; i < N; ++i) {
    double x;
    string u;
    cin >> x >> u;
    if (u == "BTC") x *= 380000;
    sum += x;
  }
  cout.precision(16);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
def dfs(i,sep,s,tot):
    n = len(s)
    i += 1

    # 最深部まで到達した時
    if i == n:
        ans = 0
        if len(sep)>1:
            for j in range(len(sep)-1):
                ans += int(s[sep[j]:sep[j+1]])
        ans += int(s[sep[-1]:])
        return ans

    # i番目に+を入れる時
    sep.append(i)
    tot += dfs(i,sep,s, 0)

    # i番目に+を入れない時
    sep.pop()
    tot += dfs(i,sep,s, 0)

    return tot

s = input()
print(dfs(0,[0],s,0))

Measured memory_bytes: 3064
N=int(input())
A_list = list(map(int,input().split()))

MAX = 10**18
ans = 1
isZero = False
isOverFlow = False
for a in A_list:
  if a == 0:
    isZero = True
    break
  if not isOverFlow:
    ans *= a
  if ans > MAX:
    isOverFlow = True

if isZero:
  print(0)
elif isOverFlow:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 84748