akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
    public class Main {
      public static void main(String...args) {
      	final Scanner sc = new Scanner(System.in);
        final int left = sc.nextInt() + sc.nextInt();
        final int right = sc.nextInt() + sc.nextInt();
        final int signum = (int)Math.signum(left - right);
        switch(signum) {
          case 0: System.out.println("Balanced"); break;
          case 1: System.out.println("Left"); break;
          case -1: System.out.println("Right"); break;
        }
      }
    }

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


bool dp[10000010];
int a[110];

int main(){
    int n, k;
    cin >> n >> k;
    rep(i, n) cin >> a[i];

    rep(i, k+1){
        rep(j, n){
            if (i >= a[j]) dp[i] |= !dp[i-a[j]];
        }
    }

    if (dp[k]) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#define endl codeforces
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t ...Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t ...Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

int main() {
    ll n;
    std::cin >> n;
    vec<ll> ans(n);
    for (ll i = 1; i < n; i++) {
        ll e;
        std::cin >> e;
        ans[--e]++;
    }
    for (ll e : ans) std::cout << e << '\n';
    return 0;
}


Measured memory_bytes: 4784
from sys import stdin

def main():
	N = int(stdin.readline().strip())
	array = [int(x) for x in stdin.readline().strip().split()]
	ans,i= 0,0
	while i+1 < N:
		if array[i] < array[i+1]:
			ans+=1
			while i+1 < N and array[i] <= array[i+1]:
				i+=1
			i+=1
		elif array[i] > array[i+1]:
			ans+=1
			while i+1 < N and array[i] >= array[i+1]:
				i+=1
			i+=1
		else:
			i+=1
	if i+1 == N or ans == 0:
		ans+=1
	print(ans)
main()

Measured memory_bytes: 14480
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,k;
   cin>>n>>k;
   int a[n+2];
   for(int i=0;i<n;i++)
        cin>>a[i];

   int sum=0;
   for(int i=0;i<k;i++)
    sum+=a[i];
    int maxx=sum,maxi=0;
   for(int i=1;i<=n-k;i++)
   {
       sum-=a[i-1];
       sum+=a[i+k-1];
       if(sum>maxx)
       {
           maxx=sum;
           maxi=i;
       }
   }
   double res=0;
   for(int i=maxi;i<maxi+k;i++)
   {
       double ans=0;
       ans=(1+a[i])*a[i]*1.0/2/a[i];
       res+=ans;
   }
   printf("%.10f",res);
}


Measured memory_bytes: 1024
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ansC = []

N, K = LI()
V = LI()
dp = [[[0]]*(K+1) for _ in range(K+1)]
right = [0]*N
left = [0]*N
#right[1] = V[-1]
#left[1] = V[0]

for i in range(min(N+1,K+1)):
    for j in range(min(N+1,K-i+1)):
        if i<N-j:
            dp[i][j] = [V[:i]+V[N-j:]+[0]]
        else:
            dp[i][j] = [V+[0]]
        dp[i][j][0].sort()

#print(dp)

for i in range(min(N+1,K+1)):
    for j in range(max(0,min(N+1,K-i+1))):
        if i+j!=0:
            t = max(K - (i + j),0)
            for l in range(t):
                if dp[i][j]!=[]:
                    m = dp[i][j][0][0]
#                    print(m)
                    if m < 0:
                        del dp[i][j][0][0]
#            print(i,j)
#            print(dp[i][j])
            if dp[i][j][0]:
#                print(dp[i][j][0])
                ansC.append(sum(dp[i][j][0][::]))

#print(ansC)
if ansC:
    print(max(ansC))
else:
    print("0")

Measured memory_bytes: 43884
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>
using namespace std;

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

void Erarosthenes(vector<int> num,int N){
    vector<bool> prime_number(1e8,false);
    FOR(i,2,1e8) prime_number[i] = true;
    FOR(i,2,1e4){
        if(prime_number[i]){
            for(int j = 2; i*j < 1e8;j++){
                prime_number[i*j] = false;
            }
        }
    }

    int ans = 0;

    FOR(i,0,N){
        if(prime_number[num[i]]) ans++;
    }

    put(ans);
}

int main(){
    int N; cin>>N;
    vector<int> num(N);
    FOR(i,0,N) cin>>num[i];
    Erarosthenes(num,N);
}


Measured memory_bytes: 15228
#include <cstdio>
#include <algorithm>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int main()
{
    int n;
    cin >> n;
    int a[101010];
    rep(i,n) cin >> a[i];

    sort(a, a+n);
    int e[3];
    int m = 0;
    for(int i=n-1; i>0 && m<2; i--){
        if(a[i]==a[i-1]){
            e[++m] = a[i],--i;
        }
    }
    if(m < 2) puts("0");
    else cout << (ll)e[1]*e[2] << endl;
    return 0;
}


Measured memory_bytes: 640
n,m=map(int,input().split())


if n==1 and m==1:
  print(1)
  exit()
if n==1:
  print(m-2)
  exit()
if m==1:
  print(n-2)
  exit()

if n==2 or m==2:
  print(0)
  exit()

print((n-2)*(m-2))


Measured memory_bytes: 38512
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
using namespace std;
const int maxn=100000;
///int a=atoi(s.c_str());
int main() {
    int n,k;
    while(cin>>n>>k,n||k) {
        set<int>M;
        map<int,int>N;
        stringstream ss;
        M.insert(n); N[n]=0;
        string x,y;
        int a=n,b=0,i=0;
        while(1){
            M.insert(a); N[a]=i;
            ss<<a;
            ss>>y; ss.clear();
            int len=y.size();
            y+=string(k-len,'0');
            sort(y.begin(),y.end());
            x=y;
            reverse(x.begin(),x.end());
            a=atoi(x.c_str());
            b=atoi(y.c_str());
            a-=b;
            if(M.count(a)){
                cout<<N[a]<<' '<<a<<' '<<++i-N[a]<<endl;
                break;
            }
            i++;
        }
    }
    return 0;
}

Measured memory_bytes: 1256
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct{
  int parent, left, right;
}Node;

Node Tree[MAX];
int degree[MAX];
int n;

void walkP(int);
void walkI(int);
void walkPo(int);

int main(void){
  int i;
  int vertex;
  int child[2];


  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    Tree[i].parent = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &vertex, &child[0], &child[1]);

    //子どもがいない場合はdegreeは0である。
    if(child[0] == NIL && child[1] == NIL)
      degree[vertex] = 0;

    //子どもがどちらかにいればdegreeは1である。
    else if(child[0] == NIL && child[1] != NIL){
      degree[vertex] = 1;
      Tree[child[1]].parent = vertex;
      Tree[vertex].right = child[1];
    }
    
    else if(child[0] != NIL && child[1] == NIL){
      degree[vertex] = 1;
      Tree[child[0]].parent = vertex;
      Tree[vertex].left = child[0];
    }


    //子どもが両方存在するという事はdegreeは2という事
    else{
      degree[vertex] = 2;
      Tree[child[0]].parent = vertex;
      Tree[child[1]].parent = vertex;
      
      Tree[vertex].left = child[0];
      Tree[vertex].right = child[1];
    }
  }

  printf("Preorder\n");
  for(i = 0; i < n; i++){
    if(Tree[i].parent == NIL)
      walkP(i);
  }
  printf("\n");


  printf("Inorder\n");
  for(i = 0; i < n; i++){
    if(Tree[i].parent == NIL)
      walkI(i);
  }
  printf("\n");

  printf("Postorder\n");
  for(i = 0; i < n; i++){
    if(Tree[i].parent == NIL)
      walkPo(i);
  }
  printf("\n");

  
  return 0;
}

void walkP(int v){
  int left = Tree[v].left;
  int right = Tree[v].right;
  
  printf(" %d",v);
  
  if(left != NIL )
    walkP(left);

  if(right != NIL)
  walkP(right);

}

void walkI(int v){
  int left = Tree[v].left;
  int right = Tree[v].right;
  
  if(left != NIL)
    walkI(left);
  
  printf(" %d",v);
  
  if(right != NIL)
    walkI(right);
}

void walkPo(int v){
  if(v != NIL)
    walkPo(Tree[v].left);

  if(v != NIL){
    walkPo(Tree[v].right);
    printf(" %d",v);
  }
}

Measured memory_bytes: 620
A, B, C = list(map(int, input().split()))
i = 1
d_set = set()
while(True):
    d = A*i % B
    if d == C:
        print('YES')
        break
    if d in d_set:
        print('NO')
        break
    d_set.add(d)
    i += 1

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;
#define MAX 500010
const int neutral = 0;
#define comp(a, b) ((a)+(b))
using vi = vector<int>;

class SegTree{
	vi a; //using vi = vector<int>
	int n;
	public:
	SegTree(){
		int sz = MAX;
		for(n = 1; n<sz; n<<=1 );
		a.assign(n<<1, neutral);
		for(int i=0; i<sz; ++i) a[i+n] = 0;
		for(int i=n+sz-1; i>1; --i)
			a[i>>1] = comp(a[i>>1], a[i]);
	}
	void update(int i, int x){
		a[i+=n] = x; 
		for( i>>=1; i ; i>>=1)
			a[i] = comp(a[i<<1], a[1+(i<<1)]);
	}
	int rsq(int l, int r){
		int ans = neutral;
		for(l+=n, r+=n+1; l<r; l>>=1, r>>=1){
			if(l&1) ans=comp(ans, a[l++]);
			if(r&1) ans=comp(ans, a[--r]);
		}
		return ans;
	}
};
SegTree bt[26];

int32_t main(){
	ios::sync_with_stdio(0);
	int n;
	string st;
	cin >> n >> st;
	for(int i=0; i<n; ++i)
		bt[st[i]-'a'].update(i, 1);
	int q;
	cin >> q;
	while(q--){
		int op;
		cin >> op;
		if(op==1){
			int i; 
			char c;
			cin >> i >> c;
			--i;
			bt[st[i]-'a'].update(i, 0);
			bt[c-'a'].update(i, 1);
			st[i] = c;
		}
		else{
			int l, r;
			cin >> l >> r;
			--l; --r;
			int ans = 0;
			for(int j=0; j<26; ++j){
				if(bt[j].rsq(l, r)>0){ 
					++ans;
				}
			}
			cout << ans << '\n';
		}
	}
}



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

#define nax 100009
#define FOR(i,n,m) for(ll i =(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(v) int(v.size())
#define all(v) v.begin() , v.end()

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

int main(){
	string s,t; cin>>s>>t;
	int cont = 0;
	REP(i,3) cont +=(s[i]==t[i]);

	cout<<cont;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 標準入力の取得
N, K = list(map(int, input().split()))
d = []
A = []
for k in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

# 求解処理
persons = set()
for A_i in A:
    for A_ij in A_i:
        persons.add(A_ij)

result = N - len(persons)

# 結果出力
print(result)


Measured memory_bytes: 9184
i = gets.to_i
ary = gets.split(" ").map(&:to_i)
count = 0
sum = 0
(i-1).times do |n|
    if ary[n]>= ary[n+1]
        count +=1
    else
        count =0
    end
    if sum<count
        sum =count
    end
end
puts sum

Measured memory_bytes: 8580
k,n = gets.chomp.split(' ').map(&:to_i)
an = gets.chomp.split(' ').map(&:to_i)
ans = 1000000
def dif_forward(ary,num,distance)
    if num == 0
        dif = ary[-1] - ary[num]
    else
        dif = distance - (ary[num] - ary[num-1])
    end
    dif
end

def dif_backward(ary,num,distance)
    if num == (ary.size-1)
        dif = distance - (ary[0] + distance - ary[num])
    else
        dif = distance - (ary[num+1] - ary[num])
    end
    dif
end
an.size.times do |i|
    temp = [dif_forward(an,i,k),dif_backward(an,i,k)].min
    if ans > temp
        ans = temp
    end
end
puts ans

Measured memory_bytes: 28748
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#define MAX_N 110
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int cost[MAX_N][MAX_N];
int mincost[MAX_N];
bool used[MAX_N];
int n;
int prim()
{
    int res = 0;
    mincost[0] = 0;
    while(true)
    {
        int v = -1;
        for(int u = 0; u < n; u++)
        {
            if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
        }
        if(v == -1) break;
        used[v] = true;
        res += mincost[v];
        for(int u = 0; u < n; u++) mincost[u] = min(mincost[u], cost[v][u]);
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    memset(used, false, sizeof(used));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> cost[i][j];
            if(cost[i][j] == -1) cost[i][j] = INF;
        }
        mincost[i] = INF;
    }
    int ans = prim();
    cout << ans << endl;
    return 0;
}




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

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  rep(i, 0, N) cin >> a[i];
  ll sum = 0;
  ll ans = 0;
  rep(i, 0, N) {
    sum += a[i];
    ll dif = 0;
    if (i%2 == 0) {
      dif = sum - 1;
      if (sum < 1) {
        sum -= dif;
        ans += abs(dif);
      }
    } else {
      dif = sum + 1;
      if (sum > -1) {
        sum -= dif;
        ans += abs(dif);
      }
    }
  }
  sum = 0;
  ll ans2 = 0;
  rep(i, 0, N) {
    sum += a[i];
    ll dif = 0;
    if (i%2) {
      dif = sum - 1;
      if (sum < 1) {
        sum -= dif;
        ans2 += abs(dif);
      }
    } else {
      dif = sum + 1;
      if (sum > -1) {
        sum -= dif;
        ans2 += abs(dif);
      }
    }
  }
  cout << min(ans, ans2) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(T) (T).begin(), (T).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
ll intmax = (1LL<<32)-1;
const int INF = 1e9 + 5;


class fastio{
public:
	fastio(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	}
} __fastio;

template <typename T>
T abs(T x){
	if(x < 0) return -x;
	else return x;
}

template <typename T>
void swap(T &a, T &b){
	T temp;
	temp = a;
	a = b;
	b = temp;
}

const int MX = 2001;

void solve() {
	
}

int main() {
	ll n,a,b;
	cin >> n >> a >> b;
	if(a == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll x = (n/(a+b)) * a;
	ll y = (n%(a+b));
	if(y > a) y = a;
	cout << x+y << endl;
}


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

auto clk=clock();
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define Mod 1000000007
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define all(x) x.begin(),x.end()

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k; cin>>n>>k;
    vector<ll>A(n),F(n);
    for(int i=0;i<n;i++) cin>>A[i];
    for(int i=0;i<n;i++) cin>>F[i];
    sort(all(A));
    sort(F.rbegin(),F.rend());
    ll low=0,high=1e12,ans=1e12;
    while(low<=high){
        ll mid=low+(high-low)/2;
        ll sum=0;
        for(int i=0;i<n;i++){
            sum+=max(0LL,A[i]-(mid/F[i]));
        }
        if(sum<=k){
            ans=mid;
            high=mid-1;
        }
        else{
            low=mid+1;
        }
    }
    cout<<ans<<"\n";
    cerr<<"\n"<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<"\n";
    return 0;
}


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

int main(){

	string s;
	int length,i;

	getline(cin,s);

	length = s.length();

	for(i=0;i<length;i++){
		if(s[i] >= 65 && s[i] <= 90){
			s[i] += 32;
		}
		else if(s[i] >= 97 && s[i] <= 122){
			s[i] -= 32;
		}
	}

	cout << s << endl;

	return 0;
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

// nのketa桁目の数値を取得する。ketaは1以上の整数である必要がある。
template <typename T>
int get_digit(T n, int keta) {
  for(int i = 1; i < keta; ++i) {
    n /= 10;
  }
  return n % 10;
}

// ABC157 C - Guess The Number
int main(){
  int n, m; // 1 <= N <= 3, 0 <= M <= 5
  cin >> n >> m;

  vector<int> ss(n, 0);
  vector<int> cc(n, 0);
  rep(i,m) {
    cin >> ss[i] >> cc[i];
  }
  int minI = 0;
  switch (n) {
    case 1:
      minI = 0;
      break;
    case 2:
      minI = 10;
      break;
    case 3:
      minI = 100;
      break;
  }
  for (int i = minI; i < 1000; ++i) {
    std::string ns = to_string(i);
    bool hit = true;
    rep(j,m) {
      const int rightDigit = n - ss[j] + 1;
      const int d = get_digit(i, rightDigit);
      if (cc[j] != d) {
        hit = false;
        break;
      }
    }
    if (hit) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

int main()
{
  int x,y,tmp;
  int i=1;
  while(1){
    cin >> x >> y;
    if(x == 0&&y==0){ break ;}
    if (x>y){
        tmp=x;
        x=y;
        y=tmp;
    };
    cout << x << " " << y << endl;
    i++;
  }
  
  return 0;
}


Measured memory_bytes: 3112
# ABC126B

s = int(input())
aa = s // 100
bb = s %  100
if 1 <= aa and aa <= 12:
    if 1 <= bb and bb <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= bb and bb <= 12:
        print('YYMM')
    else:
        print('NA')


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

int main()
{
    int a, b;
    cin >> a >> b;
    if ((a == 1 && b == 2) || (a == 2 && b == 1)) cout << "3" << endl;
    if ((a == 1 && b == 3) || (a == 3 && b == 1)) cout << "2" << endl;
    if ((a == 2 && b == 3) || (a == 3 && b == 2)) cout << "1" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;

int main()
{
    ft
    ll t,i,j,n,m,l,r,s=0;
    cin>>n;
    for(i=-200;i<=200;i++)
    {
        for(j=-200;j<=200;j++)
        {
            l=pow(i,5)-pow(j,5);
            if(l==n)
            {
                cout<<i<<" "<<j<<"\n";
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4112
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main (void){

    int N, M, tmp;
    long long result = 0;

    scanf("%d%d", &N, &M);
    priority_queue<int> q;

    for(int i = 0; i < N; i++){
        scanf("%d", &tmp);
        q.push(tmp);
    }

    for(int i = 0; i < M; i++){
        tmp = q.top() /  2;
        q.pop();
        q.push(tmp);
    }

    for(int i = 0; i < N; i++){
        result += q.top();
        q.pop();
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	string s,t;
	int i,j,k;
	int a,b;
	string c;
	string ss;
	cin>>s;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t;
		if(t=="print"){
			cin>>a>>b;
			for(j=a;j<=b;j++)	cout<<s[j];
			cout<<endl;
		}
		else if(t=="replace"){
			cin>>a>>b>>c;
			k=0;
			for(j=a;j<=b;j++){
				s[j]=c[k];
				k++;
			}
		}
		else{
			cin>>a>>b;
			ss="";
			for(j=b;j>=a;j--){
				ss+=s[j];
			}
			k=0;
			for(j=a;j<=b;j++){
				s[j]=ss[k];
				k++;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double a[3006], dp[3006][3006] = {};
int visit[3009][3009];
int n1;

long double solve(int n, int k)
{
    if(k > n || k < 0)
        return 0;
    if(n == 1)
    {
        if(k == 0)
            return 1 - a[1];
        else
            return a[1];
    }
    if(visit[n][k] == 1)
        return dp[n][k];
    visit[n][k] = 1;
    return dp[n][k] = a[n] * solve(n - 1, k - 1) + (1 - a[n]) * solve(n - 1, k);
}
main()
{
    cin>>n1;
    for(int i = 1; i <= n1; ++i)
    {
        cin>>a[i];
    }
    long double ans = 0;
    for(int i = (n1 + 2) / 2; i <= n1; ++i)
    {
        ans += solve(n1, i);
    }
    cout<<fixed<<setprecision(10);
    cout<<ans;


}


Measured memory_bytes: 175488
A = list(map(int, input().split()))
 
even = 0
odd = 0
for a in A:
  if(a%2==0):
    even += 1
 
for i in range(len(A)):
  if(A[i]%2==0 and even == 2):
    A[i] += 1
  elif(A[i]%2==1 and even == 1):
    A[i] += 1
 
if(even == 2 or even == 1):
  ans = 1
else:
  ans = 0
 
for a in A:
  ans += (max(A) - a) // 2
 
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
   string s;
   int i, ans=0, cnt=0;
   cin >> s;
   for(i=0;i<s.size();i++){
      for(int j=i;j<=s.size();j++){
         if(s[j]=='A' || s[j]=='C' || s[j]=='G' || s[j]=='T') cnt++;
         else break;
      }
      ans=max(ans, cnt);
      cnt=0;
   }
   cout << ans <<endl;
   return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

vector<int> node[n_max];
vector<int> depth(n_max,0);
vector<int> moved(n_max, 0);
vector<int> deg(n_max, 0);
vector<P> ans;

void dfs(int v, int pre = -1){
    for(auto to : node[v]){
        if(to != pre){
            if(moved[to] == 0){
                depth[to] = depth[v] + 1;
                moved[to] = 1;
                dfs(to,v);
            }
            else{
                if(depth[to] < depth[v]){
                    ans.pb(P(to,v));
                    deg[to]++;
                    // cout <<"to"  << ' ' <<  to  << ' ' << v << endl;
                }
            }
        }
    }

    if(pre != -1){
        if(deg[v] % 2){
            ans.pb(P(v,pre));
            deg[v]++;
        }
        else{
            ans.pb(P(pre,v));
            deg[pre]++;
        }
    }


}

int main(){
    int n,m; cin >> n >> m;
    // vi node[n];
    rep(i,m){
        int a,b; cin >> a >> b;
        a--;b--;
        node[a].pb(b);
        node[b].pb(a);
    }
    if(m%2){
        cout << -1 << endl;
        return 0;
    }
    moved[0]++;
    dfs(0);
    // cout << ans.size() << endl;
    for(auto p : ans) cout << p.first + 1  << ' ' << p.second + 1 << endl;
    return 0;

}

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

vector<vector<int>> g;
vector<bool> used;
 
void dfs(int s) {
  for (auto&& t : g[s]) {
    if (used[t]) continue;
    used[t] = true;
    dfs(t);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  g.resize(n);
  used.resize(n, false);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    used[i] = true;
    dfs(i);
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 8832
class UnionFindTree():
    def __init__(self, N):
        self.N = N
        self.__parent_of = [None] * N
        self.__rank_of = [0] * N
        self.__size = [1] * N

    def root(self, value):
        if self.__parent_of[value] is None:
            return value
        else:
            self.__parent_of[value] = self.root(self.__parent_of[value])
            return self.__parent_of[value]

    def unite(self, a, b):
        r1 = self.root(a)
        r2 = self.root(b)
        if r1 != r2:
            if self.__rank_of[r1] < self.__rank_of[r2]:
                self.__parent_of[r1] = r2
                self.__size[r2] += self.__size[r1]
            else:
                self.__parent_of[r2] = r1
                self.__size[r1] += self.__size[r2]
                if self.__rank_of[r1] == self.__rank_of[r2]:
                    self.__rank_of[r1] += 1

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def size(self, a):
        return self.__size[self.root(a)]

    def groups(self):
        groups = {}
        for k in range(self.N):
            r = self.root(k)
            if r not in groups:
                groups[r] = []
            groups[r].append(k)
        return [groups[x] for x in groups]


def main():
    N, M = map(int, input().split())
    uft = UnionFindTree(N)
    for _ in range(M):
        a, b = map(int, input().split())
        uft.unite(a-1, b-1)
    ans = 0
    for g in uft.groups():
        if 0 in g or 1 in g:
            x = len(g)
            y = N - x
            ans = max(ans, x * (x-1) // 2 + y * (y-1) // 2 - M)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 82776
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

while True:
    W, H = map(int, input().split())
    if W == 0 and H == 0:
        break
    adj = defaultdict(list)
    for i in range(H):
        if i == 0:
            vertical = list(map(int, input().split()))
            for j in range(1, W):
                if vertical[j - 1] == 1:
                    continue
                adj[(i, j - 1)].append((i, j))
                adj[(i, j)].append((i, j - 1))
        else:
            horizontal = list(map(int, input().split()))
            for j in range(W):
                if horizontal[j] == 1:
                    continue
                adj[(i - 1, j)].append((i, j))
                adj[(i, j)].append((i - 1, j))

            vertical = list(map(int, input().split()))
            for j in range(1, W):
                if vertical[j - 1] == 1:
                    continue
                adj[(i, j - 1)].append((i, j))
                adj[(i, j)].append((i, j - 1))

    start = (0, 0)
    goal = (H - 1, W - 1)


    from collections import deque
    dist = [[-1] * W for _ in range(H)]
    q = deque([])
    sy, sx = start
    dist[sy][sx] = 1
    q.append(start)
    while len(q) > 0:
        v = q.popleft()
        y, x = v
        if v == goal:
            print(dist[y][x])
            break
        for u in adj[v]:
            ny, nx = u
            if dist[ny][nx] != -1:
                continue
            dist[ny][nx] = dist[y][x] + 1
            q.append(u)
    else:
        print(0)


Measured memory_bytes: 6444
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int ta[1010],to[1000010],nt[1000010],co[1000010],F[1010];
int MF(int s,int t,int e,int min){
  if(s==t||min==0)return min;
  int i,r;
  F[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(F[to[i]])continue;
    r=MF(to[i],t,e,MIN(min,co[i]));
    co[i]-=r;
    co[(i+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
int maxf(int s,int t,int v,int e,int *a,int *b,int *c){
  int i,f,r,j;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];
    co[ta[b[i]]=i+e]=0;
  }
  for(f=0;r=MF(s,t,e,1000000000);f+=r){
    for(i=0;i<v;i++)F[i]=0;
  }
  return f;
}   
int main(){
  int v,e,a[1010],b[1010],c[1010],i;
  scanf("%d %d",&v,&e);
  for(i=0;i<e;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  printf("%d\n",maxf(0,v-1,v,e,a,b,c));
  return 0;
}

Measured memory_bytes: 4720
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
string s;
/**********************************************/

int main(){
    cin >> s;
    char current = 'a';
    while(current <= 'z'){
        if(s.find(current) == string::npos){
            cout << current << endl;
            return 0;
        }
        current += 1;
    }

    cout << "None" << endl;
}


Measured memory_bytes: 512
(defvar N (read))
(defvar R nil)
(defvar G nil)
(defvar B nil)

(defvar countR 0)
(defvar countG 0)
(defvar countB 0)

(defvar exceptR (make-array (1+ N)))
(defvar exceptG (make-array (1+ N)))
(defvar exceptB (make-array (1+ N)))

(defvar result 0)

(defun z (x y)
  (- (* 2 (max x y)) (min x y)))

(loop for x from 1 to N with c do
      (setf c (read-char))
      (cond 
        ((eq c #\R)
         (push x R)
         (incf countR)
         (loop for y in G do
               (or (< N (z x y))
                   (incf (aref exceptB (z x y)))))
         (loop for y in B do
               (or (< N (z x y))
                   (incf (aref exceptG (z x y)))))
         (incf result (- (* countG countB)
                         (aref exceptR x))))
        ((eq c #\G)
         (push x G)
         (incf countG)
         (loop for y in R do
               (or (< N (z x y))
                   (incf (aref exceptB (z x y)))))
         (loop for y in B do
               (or (< N (z x y))
                   (incf (aref exceptR (z x y)))))
         (incf result (- (* countR countB)
                         (aref exceptG x))))
        (t (push x B)
           (incf countB)
           (loop for y in R do
                 (or (< N (z x y))
                     (incf (aref exceptG (z x y)))))
           (loop for y in G do
                 (or (< N (z x y))
                     (incf (aref exceptR  (z x y)))))
           (incf result (- (* countR countG)
                           (aref exceptB x))))))

(princ result)

Measured memory_bytes: 24620
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << 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 debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

int main()
{
	FAST_IO;

 	string a;
 	cin >> a;
 	ll n = a.length();
 	for(int i=0;i<n;i++)
 	{
 		if(a[i] != a[n - 1 - i])
 		{
 			cout << "No" << endl;
 			return 0;
 		}
 	}   
 	for(int i=0;i<n/2;i++)
 	{
 		if(a[i] != a[n/2-1-i])
 		{
 			cout << "No" << endl;
 			return 0;
 		}
 	}
 	cout << "Yes" << endl;
    return 0;
}

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

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i=0; i<n; ++i) cin >> a[i];
    vector<int> dp(k+1, 0);
    for (int i=1; i<=k; ++i) {
        for (int j=0; j<n; ++j) {
            if (i >= a[j]) {
                dp[i] |= !dp[i - a[j]];
            }
        }
    }
    cout << (dp[k] ? "First" : "Second") << endl;
}

Measured memory_bytes: 640
#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() {
    ll n, a, b;
    cin >> n >> a >> b;


    ll size = a+b;
    ll res = (n/size*a) + min(n%size,a);
    cout << res << endl;
        




    return 0;
}



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

int isaki(char c) {
	if(c=='.' || c=='X')return 1; else return 0;
}

int main(void) {
	int width,height;
	char map[32][32];
	char p_map[32][32];
	char np_map[32][32];
	int x,y;
	int c_time;
	int people_exist;
	while(1) {
		scanf("%d%d",&width,&height);
		if(width==0 && height==0)break;
		memset(map,'#',sizeof(map));
		for(y=1;y<=height;y++) {
			scanf("%s",&map[y][1]);
			map[y][width+1]='#';
		}
		memset(p_map,0,sizeof(p_map));
		for(y=1;y<=height;y++) {
			for(x=1;x<=width;x++) {
				if(map[y][x]=='E' || map[y][x]=='N' ||
						map[y][x]=='W' || map[y][x]=='S') {
					p_map[y][x]=map[y][x];
					map[y][x]='.';
				}
			}
		}
		for(c_time=0;c_time<=180;c_time++) {
			people_exist=0;
			for(y=1;y<=height;y++) {
				for(x=1;x<=width;x++) {
					switch(p_map[y][x]) {
						case 'E':
							people_exist=1;
							if(isaki(map[y+1][x]) && p_map[y+1][x]==0) {
								p_map[y][x]='S';
							} else if(isaki(map[y][x+1]) && p_map[y][x+1]==0) {
								p_map[y][x]='E';
							} else if(isaki(map[y-1][x]) && p_map[y-1][x]==0) {
								p_map[y][x]='N';
							} else if(isaki(map[y][x-1]) && p_map[y][x-1]==0) {
								p_map[y][x]='W';
							}
							break;
						case 'N':
							people_exist=1;
							if(isaki(map[y][x+1]) && p_map[y][x+1]==0) {
								p_map[y][x]='E';
							} else if(isaki(map[y-1][x]) && p_map[y-1][x]==0) {
								p_map[y][x]='N';
							} else if(isaki(map[y][x-1]) && p_map[y][x-1]==0) {
								p_map[y][x]='W';
							} else if(isaki(map[y+1][x]) && p_map[y+1][x]==0) {
								p_map[y][x]='S';
							}
							break;
						case 'W':
							people_exist=1;
							if(isaki(map[y-1][x]) && p_map[y-1][x]==0) {
								p_map[y][x]='N';
							} else if(isaki(map[y][x-1]) && p_map[y][x-1]==0) {
								p_map[y][x]='W';
							} else if(isaki(map[y+1][x]) && p_map[y+1][x]==0) {
								p_map[y][x]='S';
							} else if(isaki(map[y][x+1]) && p_map[y][x+1]==0) {
								p_map[y][x]='E';
							}
							break;
						case 'S':
							people_exist=1;
							if(isaki(map[y][x-1]) && p_map[y][x-1]==0) {
								p_map[y][x]='W';
							} else if(isaki(map[y+1][x]) && p_map[y+1][x]==0) {
								p_map[y][x]='S';
							} else if(isaki(map[y][x+1]) && p_map[y][x+1]==0) {
								p_map[y][x]='E';
							} else if(isaki(map[y-1][x]) && p_map[y-1][x]==0) {
								p_map[y][x]='N';
							}
							break;
					}
				}
			}
			if(!people_exist)break;
			memcpy(np_map,p_map,sizeof(p_map));
			for(y=1;y<=height;y++) {
				for(x=1;x<=width;x++) {
					if(isaki(map[y][x]) && p_map[y][x]==0) {
						if(p_map[y][x+1]=='W') {
							np_map[y][x]='W';
							np_map[y][x+1]=0;
						} else if(p_map[y-1][x]=='S') {
							np_map[y][x]='S';
							np_map[y-1][x]=0;
						} else if(p_map[y][x-1]=='E') {
							np_map[y][x]='E';
							np_map[y][x-1]=0;
						} else if(p_map[y+1][x]=='N') {
							np_map[y][x]='N';
							np_map[y+1][x]=0;
						}
						if(map[y][x]=='X')np_map[y][x]=0;
					}
				}
			}
			memcpy(p_map,np_map,sizeof(np_map));
		}
		if(c_time>180)puts("NA"); else printf("%d\n",c_time);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define mod 1000000007
    #define f(i,n) for(int i=0;i<(int)n;i++)
    #define Fre(i,a,b) for(int i = a; i < b; i++)
    #define sf(n) scanf("%d", &n)
    #define sff(a,b) scanf("%d %d", &a, &b)
    #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
    #define pfn(n) printf("%d\n", n)
    #define pfs(n) printf("%d ", n)
    #define ff first
    #define ss second
    #define mem(a,b) memset(a,b,sizeof(a))
    #define READ freopen("in.txt", "r", stdin)
    #define WRITE freopen("out.txt", "w", stdout)
    #define sz size()
    #define number_of_digit(n) __builtin_ffs(n);
    #define ll long long
    #define T int
    #define ld long double
    #define endl "\n"

    bool sortbyf(const pair <int,int> a,const pair <int,int> b)
    {   
        if(a.ff==b.ff){
            return (a.ss<b.ss);
        }
        // return (a.ss< b.ss); 
        return (a.ff < b.ff);
    } 

    // int cnt;
    // bool sortbyabs(const pair <ll,ll> a, const pair <ll,ll> b){
    // // {   if(abs(a.ss)==abs(b.ss)){
    // //         return (abs(a.ff)<abs(b.ff));
    // //     }

    //     return (abs(abs(a.ss)-abs(a.ff)) > abs(abs(b.ss)-abs(b.ff))); 
    // } 


    
    
    int main(){   
        ios_base::sync_with_stdio(false); cin.tie(NULL);
        int n;
        cin>>n;
        int a[n][3];
        f(i,n){
            f(j,3)cin>>a[i][j];
        }
        for(int i=1;i<n;i++){
            a[i][0]+=max(a[i-1][1],a[i-1][2]);

            a[i][1]+=max(a[i-1][0],a[i-1][2]);

             a[i][2]+=max(a[i-1][0],a[i-1][1]);
        }

        cout<<*max_element(a[n-1], a[n-1]+3);
    } 

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define max_n 200200
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll t,n,a[max_n],sumn;
map<ll,ll> balls;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        balls[a[i]]++;
    }
    sumn=0;
    for(auto i=balls.begin();i!=balls.end();i++){
        sumn+=(i->second)*(i->second-1)/2;
    }
    for(int i=0;i<n;i++){
        cout<<sumn-balls[a[i]]+1<<endl;
    }
    return 0;
}


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

int main() {
  int N, Y, x, y, z;
  cin >> N >> Y;
  
  if (Y < 1000 * N || Y > 10000 * N) {
    x = -1;
    y = -1;
    z = -1;
  }
  
  else {
    for (int i = 0; i <= (Y / 1000 - N) / 4; i++) {
      y = i;
      x = (Y / 1000 - N - 4 * i)  / 9;
      z = N - x - y;
      if ((Y / 1000 - N - 4 * i)  % 9 == 0 && z >= 0) break;
     
      else if (i == (Y / 1000 - N) / 4) {
        x = -1;
        y = -1;
        z = -1;
      }
      else continue;
    }
  }
  cout << x << " " << y << " " << z << endl; 
}
    
  

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int[] A = new int[3];
		for(int i=0; i<3; i++) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		if(A[0] == 5 && A[1] == 5 && A[2] == 7) {
			System.out.println("YES");
		} else {
			print("NO");
		}
	}
	
	// print
	static void print(String s) {
		System.out.println(s);
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int a, b;
    cin >> a >> b;

    int ans = (a + b) / 2;
    int mod = (a + b) % 2;

    cout << ( mod ?  (ans + 1): ans ) << endl;
} 

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from,
                                      // to}}的に使う。
const ll LINF = 10010020030040056ll;
const int INF = 1001001001;
const double pi = acos(-1);

ll GCD(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }
    return GCD(b, a % b);
}

vector<pair<ll, ll>> prime_factor(ll N)
{
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

void solve()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        if (c == 'Y')
        {
            cout << "Four" << endl;
            return;
        }
    }
    cout << "Three" << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();
    return 0;
}


Measured memory_bytes: 3652