akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    string s;
    cin >> s;
    stack<char> st;
    int ans = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'S') {
            st.push(s[i]);
        }
        if(s[i] == 'T') {
            if(st.empty()) {
                ans++;
                continue;
            }
            if(st.top() == 'S') {
                st.pop();
            }
        }
    }
    cout << ans + st.size() << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[5],k;cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>k;
  if(a[4]-a[0]<=k)cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
}



Measured memory_bytes: 256
from collections import deque

def resolve():
    H,W,K = map(int,input().split())
    ys, xs, yg, xg = map(int,input().split())

    board = [['@']*(W+2)]
    for i in range(H):
        board.append(['@'] + list(input())+['@'])
    board.append(['@']*(W+2))
    board[ys][xs] = '#'

    queue = deque([(xs,ys,0)])
    while queue:
        x,y,dep = queue.popleft()
        l = []
        f1 = True
        f2 = True
        f3 = True
        f4 = True
        for i in range(1,K+1):
            if f1:
                if board[y][x+i] == '.':
                    l.append((x+i,y))
                elif board[y][x+i] == '@' or board[y][x+i] != dep+1:
                    f1 = False 
            if f2:
                if board[y][x-i] == '.':
                    l.append((x-i,y))
                elif board[y][x-i] == '@' or board[y][x-i] != dep+1:
                    f2 = False 
            if f3:
                if board[y+i][x] == '.':
                    l.append((x,y+i))
                elif board[y+i][x] == '@' or board[y+i][x] != dep+1:
                    f3 = False 
            if f4:
                if board[y-i][x] == '.':
                    l.append((x,y-i))
                elif board[y-i][x] == '@' or board[y-i][x] != dep+1:
                    f4 = False 
            if not(f1 or f2 or f3 or f4):
                break
        for nx,ny in l:
            if board[ny][nx] == '.':
                board[ny][nx] = dep + 1
                if (nx,ny) == (xg,yg):
                    print(dep+1)
                    return 
                else:
                    queue.append((nx,ny,dep+1))
    print(-1)
    return 
resolve()

Measured memory_bytes: 51080
mod = 1e9+7
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    A, B = [x for x in raw_input().split()]
    
    A_cnt, B_cnt = [int(x) for x in raw_input().split()]
    
    throw_away = raw_input()
    
    if throw_away == A:
        A_cnt -= 1
    else:
        B_cnt -= 1
    
    print(str(A_cnt) + " " + str(B_cnt))
    

main()

Measured memory_bytes: 85036
#include<cstdio>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<cstring>
#define eps 1e-8
#define pi acos(-1)
#define mp make_pair
#define PH push
#define pb push_back
#define PII pair<ll,ll>
#define VI vector<int>
#define fi first
#define se second
#define N(a,b) a=N(a,b)
#define Min(a,b) a=min(a,b)
#define sqr(x) ((x)*(x))
#define CL(a) memset(a,0,sizeof a)
#define fr(i,n) for(int i=1;i<=n;i++)
#define FR(i,S,n) for(int i=S;i<=n;i++)
#define dr(i,n) for(int i=n;i;i--)
#define DR(i,n,S) for(int i=n;i>=S;i--)
#define SZ(x) ((int)(x).size())
#define all(n) n.begin(),n.end()
#define rd(x) scanf("%d",&x)
#define pr(x) printf("%d",x)
#define prn(x) printf("%d\n",x)
typedef long long ll;
typedef unsigned long long ull;
ll expow(ll a,ll b,ll p) {ll v=1; for (; b; b>>=1,a=a*a%p)if (b&1)v=v*a%p; return v;}
ll inv(ll a,ll p) {return expow(a,p-2,p);}
using namespace std;
const int N=1000+10;
set<string>q;
int main(){
    string s;
    int k;
    cin>>s>>k;
    int n=s.size();
   for (int i=0;i<n;i++){
    	for (int j=1;j<=min(k,n-i);j++){
      	string t=s.substr(i,j);
        q.insert(t);
        }
    }
    auto pos=q.begin();
    for(int i=0;i<k-1;i++)pos++;
    cout<<*pos<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

    vector<pair<ll,ll>> p1(m),p2(m),P1(m);
    rep(i,m){
        ll P,y;
        cin >> P >> y;
        p1[i].first = P;
        p1[i].second = y;
        P1[i].first = P;
        P1[i].second = y;
    }
    sort(p1.begin(),p1.end());  

    map<ll,ll> mp; //mp.insert(make_pair(,));
    
    ll before = p1[0].first;
    int num = 1;
    for(int i = 0;i < m;i++){
        
        if(p1[i].first == before){
            mp.insert(make_pair(p1[i].second,num));
            num++;
            before = p1[i].first;
            continue;
        }else{
            num = 1;
            mp.insert(make_pair(p1[i].second,num));
            num++;
            before = p1[i].first;
            continue;
        }
    }

    rep(i,m){
        ll rank = mp.at(P1[i].second);
        string srank = to_string(rank);
        string shi = to_string(P1[i].first);
        ll dsrank = srank.size();
        ll dshi = shi.size();
        for(int i = 0;i < 6 - dshi;i++){
            cout << 0;
        }cout << shi;
        for(int i = 0;i<6 - dsrank;i++){
            cout << 0;
        }cout << rank << endl;
    }
}
    

    



    

Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
const int INF=1001001001;
int vimax(vector<int> &vec,int w){
  if(vec.at(vec.size()-1) <= w) return vec.size()-1;
  vec.pop_back();
  return vimax(vec,w);
}

int main(){
  int n, w;
  cin >> n >> w;
  vector<int> vec(n*1000+1,INF);
  vec.at(0) = 0;
  for(int i=0; i<n; ++i){
    int wi, vi;
    cin >> wi >> vi;
    for(int j=n*1000; j-vi>=0; --j){
      vec.at(j)= min(vec.at(j), vec.at(j-vi)+wi);
    }
  }
  cout << vimax(vec,w) << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <bitset>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <random>
#include <cassert>
#include <iterator>
#include <utility>

using namespace std;

//#define FAST_ALLOCATOR_MEMORY 2e8
#undef LOCAL
//#include "optimization.h"

const int MX = 2e5 + 7;
vector<int> back[MX];

int main() {
	iostream::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	vector<int> a(n);
	int val = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] - i > val) {
			cout << -1;
			return 0;
		}
		val = min(val, a[i] - i);
	}
	vector<int> st(n);
	for (int i = 0; i < n; i++)
		back[a[i]].push_back(i);
	long long ans = 0;
	for (int i = MX - 1; i >= 0; i--) {
		for (int j : back[i]) {
			int pos = j - a[j];
			if (!st[pos]) {
				st[pos] = 1;
				ans += a[j];
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 12800
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 100000000
#define MOD 100000007
#define SIZE 100005
#define pi 	3.14159265358979323846


int main(){
    ld x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    printf("%llf",(ld)sqrt((ld)pow(x2-x1,2)+(ld)pow(y2-y1,2)));
}


Measured memory_bytes: 3276
/**
 *      purpose : ABC 79 D
 *      author  : kyomukyomupurin
 *      created : 2019-01-29 12:39:07
**/

// in, out
#include <iostream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias templates
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int h, w; cin >> h >> w;
    int c[10][10];
    rep(i, 10){
        rep(j, 10) cin >> c[i][j];
    }

    int a[h][w];

    rep(i, h){
        rep(j, w) cin >> a[i][j];
    }

    rep(k, 10){
        rep(i, 10){
            rep(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
        }
    }

    int64 ans = 0;

    rep(i, h){
        rep(j, w){
            if (a[i][j] == -1 || a[i][j] == 1) continue;
            else ans += c[a[i][j]][1];
        }
    }

    print(ans);
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>

#define rep(i,n) for(int i = 0;i < n;i++)
#define rep(i,m,M) for(int i = m;i < M;i++)
#define print(var) cout<<#var" = "<<var<<endl;

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;


int main()
{
	string S;
	int ans = 0;
	cin >> S;
	if (S == "SUN")
		ans = 7;
	if (S == "MON")
		ans = 6;
	if(S == "TUE")
		ans = 5;
	if (S == "WED")
		ans = 4;
	if (S == "THU")
		ans = 3;
	if (S == "FRI")
		ans = 2;
	if (S == "SAT")
		ans = 1;

	cout << ans;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();

		String[] strAry = str.split(" ");
		int[] intAry = new int[3];

		for(int i = 0; i < strAry.length; i++ ) {
			intAry[i] = Integer.parseInt(strAry[i]);
		}

		Arrays.sort(intAry);;
		System.out.println(intAry[0] + " " + intAry[1] + " " + intAry[2]);

	}
}

Measured memory_bytes: 24340
n,t = gets.split.map{|x| x.to_i}
mincost = 9999
for i in 0...n
  c,tt = gets.split.map{|x| x.to_i}
  if c < mincost && tt <= t
    mincost = c
  end
end

if mincost == 9999
  print "TLE"
else
  print mincost
end


Measured memory_bytes: 1788
import sys
def input(): return sys.stdin.readline().rstrip()

S = int(input())

dp = [1] * (S + 1)

if S >= 6:
    for n in range(3,S+1):
        for i in range(3,n-2):
            if n - i < 3:
                break
            else:
                dp[n] += dp[i]
    dp[n] = dp[n] % (10 ** 9 + 7)


if 1 <= S <= 2:
    print(0)
else:
    print(dp[S])

Measured memory_bytes: 9264
#include<iostream>
using namespace std;
typedef pair<int,int> P;
P t[100000];
int n,a,size=0,ans=0;
int main(){
  while(1){
    size=ans=0;
    cin>>n;
    if(n==0)break;
    cin>>a;
    t[size].first=a;
    t[size].second=1;
    for(int i=2;i<=n;i++){
      cin>>a;
      if(i%2==1){
	if(t[size].first==a)t[size].second++;
	else{
	  ++size;
	  t[size].first=a;
	  t[size].second=1;
	}
      }else{
	if(t[size].first==a)t[size].second++;
	else if(size==0){
	  t[size].first=a;
	  t[size].second++;
	}else{
	  size--;
	  t[size].second+=(t[size+1].second+1);
	}
      }
    }
    
    for(int i=0;i<=size;i++){
      if(t[i].first==0)ans+=t[i].second;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    ll X,Y;
    cin >> X >> Y;
    int ret = 0;
    while(X <= Y) {
        ret++;
        X *= 2;
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    if(n>=30)cout << "Yes" << ln;
    else cout << "No" << ln;
}
    


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

int main() {
	double x;
  	string u;
  	int n;
  	cin>>n;
  	double ans=0.0;
  	for(int i=0;i<n;i++){
    	cin>>x>>u;
      	if(u=="BTC"){
        	ans+=380000.0*x;
        }else{
        	ans+=x;
        }
    }
  	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
	char s[200010];
	scanf("%s",s);
	int length = strlen(s);
	int a,z,i;
	
	for(i=0;i<length;i++){
		if(s[i]=='A'){
			a=i;
			break;
		}
	}
	
	for(i=length-1;i>=0;i--){
		if(s[i]=='Z'){
			z=i;
			break;
		}
	}
	
	printf("%d\n",z-a+1);
	
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

typedef long long ll;
int main(void)
{
    int d;
    ll g;
    cin >> d >> g;

    ll p[d], c[d];
    REP(i, d)
    {
        cin >> p[i] >> c[i];
    }

    ll ans = 1001001001;

    for (int x = 0; x < (1 << d); x++)
    {
        vector<ll> prob;
        ll cnt;
        ll score;

        REP(i, d)
        {
            if (((x >> i) & 1) == 1)
            {
                prob.push_back(i);
            }
        }

        // 全部解く場合
        cnt = 0;
        score = 0;
        for (int i = 0; i < prob.size(); i++)
        {
            score += p[prob[i]] * (prob[i] + 1) * 100 + c[prob[i]];
            cnt += p[prob[i]];
        }
        if (score >= g)
            ans = min(ans, cnt);

        // 一つだけ全部解かない問題がある場合 i 全部は解かない問題
        for (int i = 0; i < prob.size(); i++)
        {
            score = 0;
            cnt = 0;

            // j すべて解く問題
            for (int j = 0; j < prob.size(); j++)
            {
                if (i == j)
                    continue;
                score += p[prob[j]] * (prob[j] + 1) * 100 + c[prob[j]];
                cnt += p[prob[j]];
            }

            ll diff = g - score;
            if (diff <= 0)
            {
                ans = min(ans, cnt);
            }
            else
            {
                ll singlescore = (prob[i] + 1) * 100;
                ll amari = (diff + singlescore - 1) / singlescore;
                if (amari < p[prob[i]])
                    ans = min(ans, cnt + amari);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>

using namespace std;


int main() {
	char s[200005];
	cin >> s;
	int len = strlen(s);

	int i;
	for (i = 0; i < len; i++) {
		if (s[i] == 'A')
			break;
	}


	int j;
	for (j = len - 1; j > i; j--) {
		if (s[j] == 'Z')
			break;
	}

	cout << j - i + 1<< endl;
}

Measured memory_bytes: 384
def solve():
  N = int(input())
  X = input()
  x = sum(map(int,list(X)))
  dp = [0]*N
  for i in range(1,N):
    dp[i] = dp[i%sum(map(int,list(bin(i)[2:])))]+1
  cnt1 = 0
  if x>1:
    for i in range(N):
      cnt1 += int(X[-i-1])*pow(2,i,x-1)
      cnt1 %= x-1
  cnt2 = 0
  for i in range(N):
    cnt2 += int(X[-i-1])*pow(2,i,x+1)
    cnt2 %= x+1
  
  ans = [0]*N
  for i in range(N):
    if X[i]=='1':
      if x==1:
        ans[i] = 0
      else:
        num = (cnt1-pow(2,N-i-1,x-1))%(x-1)
        ans[i] = dp[num]+1
    else:
      num = (cnt2+pow(2,N-i-1,x+1))%(x+1)
      ans[i] = dp[num]+1
  return ans
print(*solve(),sep='\n')

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int n; cin >> n;
    int v[n], c[n];
    int value = 0;
    int cost = 0;

    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]){
            value+=v[i];
            cost+=c[i];
        }
    }
    cout << value-cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<cstring> 
using namespace std;
int main()
{int a,b,ans=0;
 cin>>a>>b;
 if(a<b){
 cout<<a<<endl;
 }
 if(a>b){
 cout<<a-1<<endl;
 }
 if(a==b){
 cout<<a<<endl;
 }
 system("pause");
 return 0;
}

Measured memory_bytes: 504
CONST = 10**9+7
n = int(input())
s = input()

chars = {}
for c in s:
    if c in chars:
        chars[c] += 1
    else:
        chars[c] = 1

val = 1
for i in chars.values():
    val = (val * (i+1)) % CONST
print(val-1)


Measured memory_bytes: 9180
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int[][] students = new int[n][n];
			int[][] x = new int[n][n];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					students[i][j] = sc.nextInt();
				}
			}
			
			for(int i = 0; i < n; i++){
				int columnMax = -1;
				for(int j = 0; j < n; j++){
					if(columnMax < students[j][i]){
						columnMax = students[j][i];
                    }
				}
				for(int j = 0; j < n; j++){
					if(columnMax == students[j][i]){
						x[j][i] |= 2;
					}
				}
			}
			for(int i = 0; i < n; i++){
				int rowMin = Integer.MAX_VALUE;
				for(int j = 0; j < n; j++){
					if(rowMin > students[i][j]){
						rowMin = students[i][j];
                    }
				}
				for(int j = 0; j < n; j++){
					if(rowMin == students[i][j]){
						x[i][j] |= 1;
					}
				}
			}
			
			Set<Integer> both = new HashSet<Integer>();
            for(int i = 0;i < n;i++){
                for(int j = 0;j < n;j++){
                    if(x[i][j] == 3){
                        both.add(students[i][j]);
                    }
                }
            }
			
            if(both.size() == 1){
            	StringBuilder sb = new StringBuilder();
                for(int v : both){
                    sb.append(v + " ");
                }
                sb.deleteCharAt(sb.length() - 1);
                System.out.println(sb);
            }else{
            	System.out.println(0);
            }
/*			boolean noAns = true;
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					if(shortest[i][j] && tallest[i][j]){
						sb.append(students[i][j] + " ");
						noAns = false;
					}
				}
			}
			
			if(noAns){
				System.out.println(0);
			}else{
				sb.deleteCharAt(sb.length() - 1);
				System.out.print(sb);
			}
*/		}
		
	}
}

Measured memory_bytes: 17700
#include <bits/stdc++.h>
 
#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
 
const int N = (int) 1e6;
const int INF = (int) 1e9 + 7;
 
bool comp(ii a, ii b) {
	int x = max(a.fs, a.sc) - a.sc;
	int y = max(b.fs, b.sc) - b.sc;
	return x > y;
}
 
int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
 
	int n;
	sf("%d", &n);
	char s[N + 7];
	int l = 0, r = 0;
	vector<ii> a;
	vector<ii> b;
	for (int j = 0; j < n; ++j) {
		sf("%s", s);
		int x = 0;
		int y = 0;
		for (int i = 0; i < strlen(s); ++i) {
			if (s[i] == '(') {
				++x;
			}
			else {
				if (x < 1) {
					++y;
				}
				else {
					--x;
				}
			}
		}
 
		if (x > 0 && y > 0) {
			if (x > y) {
				a.pp(mp(y, x));
			}
			else {
				b.pp(mp(y, x));
			}
		}
		else {
			l += x;
			r += y;
		}
	}
 
	sort(a.begin(), a.end());
	for (int i = 0; i < a.size(); ++i) {
		if (l < a[i].fs) {
			puts("No");
			return 0;
		}
 
		l += a[i].sc - a[i].fs;
 
		if (l < 0) {
			puts("No");
			return 0;
		}
	}

	sort(b.begin(), b.end(), greater<ii>());
	for (int i = 0; i < b.size(); ++i) {
		if (l < b[i].fs) {
			puts("No");
			return 0;
		}

		l += b[i].sc - b[i].fs;
 
		if (l < 0) {
			puts("No");
			return 0;
		}
	}
 
	puts(l == r ? "Yes" : "No");
 
	return 0;
}


Measured memory_bytes: 5288
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    use std::cmp::min;
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: u8 = read(&mut stdin_lock, &mut buf, b' ');
    let b: u8 = read(&mut stdin_lock, &mut buf, b'\n');
    let s: String = (0..b).map(|_| ('0' as u8 + a) as char).collect();
    let t: String = (0..a).map(|_| ('0' as u8 + b) as char).collect();
    println!("{}", min(s, t));
}


Measured memory_bytes: 4476
#include <cstdio>
using namespace std;
int n, S[100001], q;
int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) scanf("%d", &S[i]);
  scanf("%d", &q);
  int ans = 0;
  for(int i = 0, T; i < q; ++i) {
    scanf("%d", &T);
    int l = -1, r = n;
    while(r-l > 1) {
      int m = (l+r)/2;
      if(S[m] >= T) r = m;
      else l = m;
    }
    if(S[r] == T) ++ans;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 2948
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(Math.abs(x - a) < Math.abs(x - b)){
            System.out.println("A");
            return;
        }
        System.out.println("B");
    }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    int n;
    cin>>n;
    double dp[n+1][n+1];
    memset(dp,0.0,sizeof(dp));
    double p[n+1];
    rep(i,n){
        cin>>p[i+1];
    }
    dp[0][0]=1.0;
    for (int i=1;i<n+1;i++){
        for (int j=0;j<i+1;j++){
            if (j==0){
                dp[i][j]=dp[i-1][j]*(1-p[i]);
            }
            else if (j==i){
                dp[i][j]=dp[i-1][j-1]*p[i];
            }
            else{
                dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
            }
        }
    }
    double ans=0.0;
    for (int i=n/2+1;i<n+1;i++){
        ans+=dp[n][i];
    }
    cout << fixed << setprecision(10);
    cout<<ans<<endl;


    return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> H(N), A(M), B(M);
    vector<int> good(N);

    for (int i = 0; i < N; i++)
    {
        cin >> H.at(i);
        good.at(i) = i + 1;
    }
    for (int i = 0; i < M; i++)
    {
        cin >> A.at(i) >> B.at(i);
    }

    for (int i = 0; i < M; i++)
    {
        if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1))
        {
            good.at(A.at(i) - 1) = -1;
        }
        else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1))
        {
            good.at(A.at(i) - 1) = -1;
            good.at(B.at(i) - 1) = -1;
        }
        else
        {
            good.at(B.at(i) - 1) = -1;
        }
    }

    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (good.at(i) > 0)
        {
            count++;
        }
    }
    cout << count << endl;
}

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

int abs(int x) {
  if(x >= 0) {
    return x;
  }
  else {
    return -1 * x;
  }
}

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  int A = abs(a - x);
  int B = abs(b - x);
  if(A < B) {
    cout << "A" << endl;
  }
  else {
    cout << "B" << endl;
  }
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){
   
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}
 
Node treeSearch(Node u, int k){
   
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else  return treeSearch(u->right,k);
   
}
 
Node treeSuccessor(Node x){
  Node y = NIL;
   
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
   
  while(y != NIL && x == y->right){
    x =y;
    y = y->parent;
  }
  return y;
}
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
 
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
   
  if(y->left != NIL) x = y->left;
  else x = y->right;
   
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
   
  if(y != z) z->key = y->key;
   
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
   
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   
  while(x != NIL){
    y = x;
     
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
   
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}
 
void inorder(Node u){
   
  if(u ->left != NIL) {
    inorder(u->left);
    printf(" %d",u->key);
  }
   
  else printf(" %d",u->key);
   
  if(u->right != NIL) inorder(u->right);
}
 
void preorder(Node u){
  printf(" %d",u->key);
   
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

Measured memory_bytes: 24040
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	fmt.Println(NumToChar(N - 1))
}

func NumToChar(index int) string {
	ans := ""

	for ; index >= 0; index-- {
		add := 'a' + (index % 26)
		ans = string(byte(add)) + ans
		index /= 26

	}
	return ans
}


Measured memory_bytes: 1832
package main

import "fmt"

func main() {
	var chara string
	fmt.Scan(&chara)
	boin := [5]string{"a", "i", "u", "e", "o"}
	for i := 0; i < 5; i++ {
		if boin[i] == chara {
			fmt.Println("vowel")
			return
		}
	}
	fmt.Println("consonant")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    set <string> s;
    for(int i=0;i<n;i++){
        string st;
        cin >> st;
        s.insert(st);
    }
    cout << s.size();
}

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

const ll MX = 1e18;
const long double PI = acos(-1);

int main()
{
    string s;
    cin >> s;
    pri(s.substr(0,3));
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
 
int main(int argc, char *argv[]){
  unsigned int N;
  std::cin >> N;
  std::vector<unsigned int>A(N);
  for(auto &a : A){
    std::cin >> a;
  }

  auto globalMaxIter = std::max_element(A.begin(),A.end());
  unsigned int globalMax = *globalMaxIter;
  A.erase(globalMaxIter);
  unsigned int secondMax = *std::max_element(A.begin(),A.end());
  A.insert(globalMaxIter,globalMax);
  for(auto &a : A){
    std::cout << (a == globalMax ? secondMax : globalMax) << std::endl;
  }
  return 0;
}

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

const int MAX = 2100000;
ll fac[MAX], finv[MAX], inv[MAX];

void cominit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i=2; i<MAX; i++) {
    fac[i] = fac[i-1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

ll com(ll n, ll k)
{
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main()
{
  ll n; cin >> n;
  ll k; cin >> k;
  cominit();
  ll ans = 0;
  ll z = min(n-1, k);
  for (int i=0; i<=z; i++) {
    ans = (ans + (com(n-1, i) * com(n, i) % mod)) % mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 49536
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  Vi v(3);
  VIN(v);
  RSORT(v);
  OUT(v[0]*10+v[1]+v[2]);
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
l, r = 0, 10 ** 9 + 10
while r - l > 1:
    res = 0
    m = (l + r) // 2
    for x in a:
        res += (x - 1) // m
    if res <= k:
        r = m
    else:
        l = m
print(r)


Measured memory_bytes: 94072
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
using ll = long long;
typedef long long lint;

int main() {
  int a,b;
  cin >> a >> b;
  string as = to_string(a);
  string bs = to_string(b);
  string s;
  if(a >= b){
    rep(i,a){
      s += bs;
    }
  }
  else{
    rep(i,b){
      s += as;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        String inputData;

        Scanner scanner = new Scanner(System.in);
        inputData = scanner.nextLine();
        scanner.close();
        char inputCharactor = inputData.charAt(0);

        inputCharactor++;

        System.out.println(inputCharactor);

    }
}

Measured memory_bytes: 21076
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s;
LL lft[100010],now,dp[100010][20];
vector <LL> v;

int main()
{
	cin>>s;
	lft[0]=1;
	repn(i,100005) lft[i]=lft[i-1]*10%13;
	for(int i=s.size()-1,j=0;i>=0;i--,j++)
	{
		if(s[i]=='?') v.pb(lft[j]);
		else now+=(s[i]-'0')*lft[j];
	}
	now%=13;
	dp[0][now]=1;
	rep(i,v.size())
	{
		rep(j,13)
		{
			if(dp[i][j]==0) continue;
			rep(k,10) dp[i+1][(j+k*v[i])%13]=(dp[i+1][(j+k*v[i])%13]+dp[i][j])%MOD;
		}
	}
	cout<<dp[v.size()][5]<<endl;
	return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;

void setIO(string name)
{
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //setIO("");
    double L;
    cin >> L;
    cout << setprecision(30) << L*L*L/27;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=200005;
#define M 1000000007
#define double long double
#define BINF 10000000000000000
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

multiset<int>s[N];\

#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);


    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x; 
        s[x].insert(i);
    }
    int ans = 0;
    if(s[1].size() == 0){
        cout << -1 << endl;
        return 0;
    }

    int ind = *s[1].begin();
    int x = 2;
    ans = 1;



    while(1){
        auto it = s[x].upper_bound(ind);
        if(it == s[x].end()) break;
        ans++;
        x++;
        ind = *it;
    }

    cout << n - ans << endl;





return 0;
}




Measured memory_bytes: 19072
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <string>
#include <stdio.h>
#include <iomanip>
using namespace std;
const double pi = 3.141592653;
int main (){

    int n = 0, x =0 , t =0;
    cin >> n >> x >> t;
    int r = 0;
    if(n%x == 0){
        r = n/x;
        cout << r *t;
    }else{
        r = n/x +1;
        cout << r*t;
    }
    return 0;

}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;
const char *YES = "Yes" , *NO = "No";

inline void failure(){puts(NO);exit(0);}

struct tla
{
#define lb(a) ((a)&(-(a)))
	int t[_];
	void cls(){memset(t,0,sizeof(t));}
	inline void add(int x,int d){while(x)t[x]+=d,x-=lb(x);}
	inline int sum(int x){int d=0;while(x<_)d+=t[x],x+=lb(x);return d;}
#undef lb
}t;

int n,val[_][3],tar[_],ic[2]={0},fc[2]={0};

int main()
{
	n=ty();
	for(int i=0;i<3;i++)for(int j=1;j<=n;j++)val[j][i]=ty();

	for(int i=1;i<=n;i++)
	{
		int loc=(val[i][0]-1)/3+1;
		if((loc-i)&1)failure();
		tar[loc]=i;
		int a=loc*3-2,b=a+1,c=b+1;
		if(val[i][0]==a && val[i][1]==b && val[i][2]==c)continue;
		if(val[i][0]==c && val[i][1]==b && val[i][2]==a)ic[i&1]^=1;
		else failure();
	}

	t.cls();
	for(int i=1,x;i<=n;i+=2)x=tar[i]+t.sum(tar[i])*2,fc[1]^=((x-i)/2)&1,t.add(tar[i],1);
	t.cls();
	for(int i=2,x;i<=n;i+=2)x=tar[i]+t.sum(tar[i])*2,fc[0]^=((x-i)/2)&1,t.add(tar[i],1);

	puts((ic[1]==fc[0] && ic[0]==fc[1])?YES:NO);

	return 0;
}


Measured memory_bytes: 2304
import Data.List
import Data.Maybe
import Debug.Trace

main = interact $ f.isSquare.(read::String->Int).concat .words

isSquare :: Int ->  Bool
isSquare a = (a==).fromJust .find (a<=) $ map (^2)[1..]

f :: Bool -> String
f x = if x then "Yes" else "No"

Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#define MAX 10000
#define INFTY 1<<30 // 2^30
#define N 8
using namespace std;
typedef long long llong;
static const int NIL = -1;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

static const int NOT_FREE = 0;
static const int FREE = 1;
static const int FIXED = 2;

bool X[N][N];
vector<pair<int, int> > ans;

void init()
{
  for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++)
      X[i][j] = false;
}

bool can_pos(int x, int y)
{
  for(int i = 0; i < ans.size(); i++)
  {
    int tx = ans[i].first;
    int ty = ans[i].second;
    if(x == tx) return false;
    if(y == ty) return false;
    if((x-tx)*(x-tx) == (y-ty)*(y-ty)) return false;
  }
  return true;
}

void printBoard()
{
  for(int i = 0; i < ans.size(); i++)
    X[ans[i].first][ans[i].second] = true;
  for(int i = 0; i < N; i++)
  {
    for(int j = 0; j < N; j++)
      cout << (X[i][j] ? "Q" : ".");
    cout << endl;
  }
}

bool recursive(int p)
{
  for(; p < N * N; p++)
  {
    int i = p%N;
    int j = p/N;
    if(!(can_pos(i,j))) continue;
    pair<int, int>tmp = make_pair(i, j);
    ans.push_back(tmp);
    if(!recursive((j+1)*N)) ans.pop_back();
  }
  if(ans.size() == N) return true;
  return false;
}

int main()
{
  init();
  int k, r, c; cin >> k;
  for(int i = 0; i < k; i++)
  {
    cin >> r >> c;
    pair<int, int> tmp = make_pair(r, c);
    ans.push_back(tmp);
  }
  if(recursive(0)) printBoard();
  return 0;
}

Measured memory_bytes: 1188
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 100002;
#define endl '\n'
#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()

int32_t main()
{ 
   IOS
 

  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i =  0;i<n;i++){
    cin>>a[i];
  }
  sort(all(a));
  if(a[n-1] == 0 and (k&1)){
    cout<<0<<endl;
    return 0;
  }
  if(a[n-1] <= 0 and (k&1)){
    int product = 1;
    for (int i = n - 1; i >= n - k; i--) 
            {product *= (mod + a[i]);product%=mod;} 
    cout<<product<<endl;
    return 0;
  }
   int product = 1;
   int i = 0; 
   int j = n - 1;  
    if (k & 1) { 
        product *= a[j]; 
        j--; 
        k--; 
    } 

      k >>= 1; 
    for (int itr = 0; itr < k; itr++) { 
        int left_product = a[i] * a[i + 1]; 
        int right_product = a[j] * a[j - 1]; 
        if (left_product > right_product) { 
            left_product = (left_product + mod*mod)%mod;
            product *= left_product;
            product%=mod; 
            i += 2; 
        } 
        else { 
            right_product = (right_product + mod*mod)%mod;
            product *= right_product;
            product%=mod; 
            j -= 2; 
        } 
    } 
  
    cout<<product<<endl;
    return 0;
  


  
}

Measured memory_bytes: 4756
N = int(input())
d = [int(input()) for i in range(N)]

maxv = -1 * (10 ** 9)
minv = d[0]

for i in range(N - 1):
    minv = min(d[i], minv)
    maxv = max(d[i + 1] - minv, maxv)

print(maxv)



Measured memory_bytes: 13592
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.LinkedList;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        String[] S=new String[N];
        int s[]=new int[4];
        int ans=0;
        for(int i=0;i<N;i++){
            S[i]=sc.next();
        }
        for(int i=0;i<N;i++){
            if(S[i].charAt(0)=='P')s[0]++;
            if(S[i].charAt(0)=='W')s[1]++;
            if(S[i].charAt(0)=='G')s[2]++;
            if(S[i].charAt(0)=='Y')s[3]++;
        }
        for(int i=0;i<4;i++){
            if(s[i]>0){
                ans++;
            }
        }
        if(ans==3){
            System.out.println("Three");
        }else{
            System.out.println("Four");
     }
    }
    }


Measured memory_bytes: 23764
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-5);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 1e5 + 5;
int n, q;
vector<pair<int, int> > Q[MAX_N];
#define INF 1e17

long long tree[4 * MAX_N], lazy[4 * MAX_N];

void pushDown(int p, int l, int r){
    if (lazy[p] != INF){
        tree[p] = min(tree[p], lazy[p]);
        if (l != r){
            lazy[2 * p] = min(lazy[2 * p], lazy[p]);
            lazy[2 * p + 1] = min(lazy[2 * p + 1], lazy[p]);
        }
        lazy[p] = INF;
    }
}

void updateSegment(int st, int en, long long v, int p = 1, int l = 0, int r = n - 1){
    if (l >= st && r <= en)
    {
        lazy[p] = min(lazy[p], v);
        pushDown(p, l, r);
        return;
    }
    pushDown(p, l, r);
    if (l > en || r < st)
        return;
    int mid = (l + r)/2;
    updateSegment(st, en, v, 2 * p, l, mid);
    updateSegment(st , en ,v,  2 * p + 1, mid + 1, r);
    tree[p] = min(tree[2 * p], tree[2 * p + 1]);
}

long long get(int st, int en, int p = 1, int l = 0, int r = n - 1){
    pushDown(p, l, r);
    if ( l >= st && r <= en)
        return tree[p];
    if (l > en || r < st)
        return INF;
    int mid = (l+r)/2;
    return min(get(st, en, 2 * p, l, mid), get(st, en, 2 * p + 1, mid + 1 ,r));
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> q;
    fill(tree, tree + 4 * MAX_N, INF);
    fill(lazy, lazy + 4 * MAX_N, INF);
    rep(i,0,q){
        int l, r, c;
        cin >> l >> r >> c;
        --l; --r;
        Q[l].push_back({r, c});
    }

    updateSegment(0, 0, 0);

    for (int i = 0; i < n; ++i){
        long long d = get(i, i);
//        cout << d << endl;
        for (auto p : Q[i]){
            int r = p.first, c = p.second;
            updateSegment(i, r, min((ll)INF, c + d));
        }
    }

    long long ans = get(n - 1, n - 1);

    if (ans >= INF){
        cout << -1;
    }
    else
        cout << ans;
    return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long a, b, c, ans;
    cin >> a >> b >> c;
    if(c - b <= 2){ ans = a + 1; }
    else{ ans = a + 1 + ((a - b + 1) / 2)*( c - b - 2); }
    cout << ans << endl;
}


Measured memory_bytes: 256
from itertools import groupby, accumulate, product, permutations, combinations
h,w,k = map(int, input().split()) 
l = [input() for i in range(h)]
ans = 0

for i in product([0,1],repeat=h):
    for j in product([0,1],repeat=w):
        Ans = 0
        for m in range(h):
            for n in range(w):
                if l[m][n] == '#' and i[m] == 1 and j[n] == 1:
                    Ans += 1
        if Ans == k:
            ans +=1

print(ans)

Measured memory_bytes: 9200