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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int d = a[i] + a[j];
            int left = j; int right = n;
            while (right - left > 1) {
                int mid = (right + left) / 2;
                if (a[mid] < d) left = mid;
                else right = mid;
            }
            ans += left - j;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
    int N, * ai, count = 0;
    cin >> N;
    vector<int>I(N);
   
    for (int i = 0; i < N; ++i)
    {
        I.at(i)=i+1;
    }
    ai = new int[N];
    for (int j = 0; j < N; j++)
    {
        cin >> ai[j];
    }
    for (int k = 0; k < N; k++)
    {
        if (I[k] % 2 != 0 && ai[k] % 2 != 0)
        {
            count++;
        }
    }
    cout << count << endl;

    delete[]ai;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B, R = C + D;
  if (L < R){
    cout << "Right" << endl;
  }
  else if (L > R){
    cout << "Left" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

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

#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define track(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1000000007;
const ll inf=1e15;
const ll N=1e5+10;

ll n,m;
vector<int> s[20];
ll p[12];

bool chk(ll mask)
{
	for(ll i=0;i<m;i++)
	{
		ll count=0;
		for(auto j:s[i])
		{
			if(mask & (1ll<<j)) count++;
		}
		if(count%2 != p[i]) return 0; 
	}
	return 1;

}

int main()
{
	boost;
	cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
		ll k;
		cin>>k;
		while(k--)
		{
			ll x;
			cin>>x;
			x--;
			s[i].pb(x);
		}
	}
	for(ll i=0;i<m;i++)
	{
		cin>>p[i];
	}
	ll mask=0;
	ll bound=0;
	ll ans=0;
	for(ll i=0;i<n;i++) bound|=(1ll<<i);
	for(mask=0;mask<=bound;mask++)
	{
		if(chk(mask)) ans++;
	}	
	cout<<ans;
  	return 0;
}

Measured memory_bytes: 256
w, h, n = map(int, input().split())
W = [0, w]
H = [0, h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if W[0] < x:
            W[0] = x
    elif a == 2:
        if W[1] > x:
            W[1] = x
    elif a == 3:
        if H[0] < y:
            H[0] = y
    else:
        if H[1] > y:
            H[1] = y
if W[0] > W[1] or H[0] > H[1]:
    print(0)
else:
    print((W[1] - W[0]) * (H[1] - H[0]))

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long LL;
const int N = 305;
const LL MOD = 998244353;
LL dp[N][N * N], f[N][N * N];

int a[N];
int main() {
	int n;
	cin >> n;
	int sum = 0;
	for(int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	LL ans = 1;
	int m = sum;
	dp[0][0] = 1;
	f[0][0] = 1;
	for(int i = 1; i <= n; i ++) {
		ans = ans * 3 % MOD;
		for(int j = 0; j <= m; j ++) {
			if(j >= a[i]) 
				dp[i][j] = (dp[i - 1][j - a[i]] + dp[i - 1][j] * 2) % MOD;
			else dp[i][j] = dp[i - 1][j] * 2 % MOD, f[i][j] = f[i-1][j];
		}	
	}
	
	for(int j = 1; j <= m; j ++) 
		if(j * 2 >= m) ans = (ans - (3 * dp[n][j] % MOD) + MOD) % MOD;
	if(m % 2 == 0) {
		for(int i = 1; i <= n; i ++) {
			for(int j = 0; j <= m; j ++) 
				if(j >= a[i]) f[i][j] = (f[i - 1][j - a[i]] + f[i - 1][j]) % MOD;
				else f[i][j] = f[i - 1][j];
		}
		ans = (ans + 3 * f[n][m / 2] + MOD) % MOD;
	}
	cout << ans  << endl;
	
}


Measured memory_bytes: 439808
#from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"




def main():
    n = ii()
    donelist = []
    for i in range(n):
        tmp = li()
        donelist.append(tmp)

    anslist = [['.' for i in range(8)] for j in range(8)]


    for i in permutations(range(8)):
        lli = list(i)
        flag = False
        for tmp in donelist:
            if lli[tmp[0]] != tmp[1]:
                flag = True
        if flag:
            continue

        wa = []
        sa = []
        for e,tmp in enumerate(lli):
            if (tmp-e in sa) or (tmp+e in wa):
                flag = True
                break
            wa.append(tmp+e)
            sa.append(tmp-e)
        if not flag:
            for e,tmp in enumerate(lli):
                anslist[e][tmp] = 'Q'
                print(''.join(anslist[e]))
            exit()









main()




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


#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

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int h,w,n;cin>>h>>w>>n;	
	int x,y;cin>>x>>y;
	string s,t;cin>>s>>t;
	int lox = 1,hix = h,loy=1,hiy=w;
	repD(i,n-1,0){
		if(t[i]=='R'){
			loy = max(1,loy-1);
		}
		if(t[i]=='L'){
			hiy = min(w,hiy+1);
		}
		if(t[i]=='D'){
			lox = max(1,lox-1);
		}
		if(t[i]=='U'){
			hix = min(h,hix+1);
		}
		if(s[i]=='R'){
			hiy = hiy-1;
		}
		if(s[i]=='L'){
			loy++;
		}
		if(s[i]=='D') hix--;
		if(s[i]=='U') lox++;
		if(hix<lox||hiy<loy){
			cout<<"NO";return 0;
		}
	}
		if(hix<x||x<lox||hiy<y||y<loy){
			cout<<"NO";return 0;
		}
		else cout<<"YES";
	return 0;
}



Measured memory_bytes: 920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int a;
    cin >> a;
    cout << 3 * a * a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
typedef long long int llint;

int main(void){
  llint n, d, a;
  std::cin >> n >> d >> a;


  std::vector<std::array<llint, 2> > enemy(n);

  for(int i=0; i<n; i++){
    std::cin >> enemy[i][0] >> enemy[i][1];
    enemy[i][1] = std::ceil(enemy[i][1]/1.0/a);
  }
  std::sort(enemy.begin(), enemy.end());

  // shakutori
  llint st_idx = 0;
  llint ed_idx = 0;
  llint part_total = 0;


  std::vector<llint> tmp(n);
  llint cost = 0;
  while(st_idx < n){
    //std::cout << st_idx << " " << ed_idx << std::endl;
    //std::cout << cost << " " << part_total << std::endl;
    if(ed_idx < n && enemy[ed_idx][0]-enemy[st_idx][0] <= 2*d){
      //std::cout << "ADD" << std::endl;
      tmp[ed_idx] = std::max(0LL, enemy[ed_idx][1]-part_total);
      cost += tmp[ed_idx];
      part_total+= tmp[ed_idx];
      ed_idx++;
    }else{
      //std::cout << "SUB" << std::endl;
      part_total -= tmp[st_idx];
      st_idx++;
    }
  }

  std::cout << cost << std::endl;
  

  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

ll bpow(ll a , ll b){
  if (b == 0) return 1;
  ll ret;
  if (b%2 == 0){
    ll  t = bpow(a, b/2);
    ret = t*t;
  }else{
    ll t = bpow(a, (b-1)/2);
    ret = a*t*t;
  }
  return ret;
}

int main(){
  ll N; cin >> N;
  ll cnt = 1;
  REP(i,N){
    ll a; cin >> a;
    if(a%2==0) cnt *= 2; 
  }
  cout << bpow(3,N) - cnt << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
ll a[200001];
int ret[200001];


ll INF = 1ll << 60;
int calc_depth(int depth, int prev, int cur, vector<vector<int>> &edges)
{
    if(edges[cur].size() == 1)
    {
        return depth;
    }

    int ret = -1;
    for(auto next: edges[cur])
    {
        if(next == prev) continue;
        ret = max(ret, calc_depth(depth+1, cur, next, edges));
    }

    return ret;
}

void calc_lis(int prev, int cur, ll *dp, int max_depth, vector<vector<int>> &edges)
{
    int update_index = lower_bound(dp, dp+max_depth, a[cur]) - dp;
    ll back = dp[update_index];
    dp[update_index] = a[cur];
    ret[cur] = lower_bound(dp, dp+max_depth, INF) - dp;
    for(auto next: edges[cur])
    {
        if(next == prev) continue;
        calc_lis(cur, next, dp, max_depth, edges);
    }
    dp[update_index] = back;
}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> edges(n);
    for(int i=0;i<n;++i)
    {
        cin >> a[i];
    }
    for(int i=0;i<n-1;++i)
    {
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    // First path, check depth
    for(auto dst: edges[0])
    {
        int depth = calc_depth(1, 0, dst, edges) + 1;
        ll dp[depth] = {};
        for(int i=0;i<depth;++i) dp[i] = INF;
        dp[0] = a[0];
        calc_lis(0, dst, dp, depth, edges);
    }
    cout << 1 << endl;
    for(int i=1;i<n;++i)
    {
        cout << ret[i] << endl;
    }
}

Measured memory_bytes: 35024
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if ((a - 1) / d >= (c - 1) / b)cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;

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

    vector<ll> x(n);
    for(ll i = 0; i < n; i++){
        cin >> x[i];
    }

    ll ans = 0;
    for(ll i = 0; i < n - 1; i++){
        const ll d = x[i + 1] - x[i];
        ans += min(a * d, b);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include <algorithm>
using namespace std;
int h[100005];
int main() {
  int n,k;
  cin >> n >> k;
  
  for(int i = 0; i < n; i++) cin >> h[i];

  sort(h,h+n);
  // for(int i = 0; i < n; i++) cout << h[i] << endl;
  int ans = 1e9;
  for(int i = k-1; i < n; i++) {
    ans = min(ans,h[i] - h[i-k+1]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
s = input()
q = int(input())
p = 1
start = ""
end = ""
query =[]
for i in range(q):
    a = list(map(str,input().split()))
    query.append(a)

for i in range(q):
    if int(query[i][0]) == 1:
        p = p * (-1)
    else:
        if int(query[i][1]) == 1:
            if p ==1:
                start = query[i][2] + start
            else:
                end = query[i][2] + end
        else:
            if p == 1:
                end = query[i][2] + end
            else:
                start = query[i][2] + start
if p == 1:
    ans = start + s + end[::-1]
else:
    ans = end + s[::-1] + start[::-1]
print(ans)

Measured memory_bytes: 41408
#include <stdio.h>

int main(){
  int bingo[3][3][2];
  for(int i=0; i<3; i++)
    for(int j=0; j<3; j++){
      scanf("%d", &bingo[i][j][0]);
      bingo[i][j][1] = 0;
    }

  int n;  scanf("%d", &n);

  for(int j=0; j<n; j++){
    int t;  scanf("%d", &t);
    for(int i=0; i<9; i++)
      if(t == bingo[i/3][i%3][0])
	bingo[i/3][i%3][1] = 1;
  }

  int count;
  for(int mode=0; mode<2; mode++){
    for(int i=0; i<3; i++){
      count = 0;
      for(int j=0; j<3; j++){
	int t;
	if(mode)
	  t = bingo[i][j][1];
	else
	  t = bingo[j][i][1];
	if(t)
	  count++;
	if(count == 3){
	  printf("Yes\n");
	  return 0;
	}
      }
    }
  }
  count = 0;
  for(int i=0; i<3; i++)
    if(bingo[i][i][1])
      count++;
  if(count == 3){
    printf("Yes\n");
    return 0;
  }
  count = 0;
  for(int i=0; i<3; i++)
    if(bingo[i][2-i][1])
      count++;
  if(count == 3){
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}

  


Measured memory_bytes: 128
def main():
    H, W = map(int, input().split())
    S = ['.'*(W+2)]+['.'+input()+'.' for _ in range(H)]+['.'*(W+2)]

    for h in range(1, H+1):
        for w in range(1, W+1):
            if S[h][w] == '#':
                if S[h-1][w] == '.' and S[h+1][w] == '.' and S[h][w+1] == '.' and S[h][w-1] == '.':
                    return False
    return True


print('Yes' if main() else 'No')


Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(N: int, P: "List[int]"):
    ans=1
    mi=P[0]
    for i in range(1,N):
        if P[i]<=mi:
            ans+=1
            mi=P[i]
            
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25984
package main

import "fmt"

func main() {
	var x1, y1, x2, y2 int
	fmt.Scan(&x1, &y1, &x2, &y2)
	xd, yd := x2-x1, y2-y1
	x3, y3 := x2-yd, y2+xd
	x4, y4 := x3-xd, y3-yd
	fmt.Printf("%d %d %d %d\n", x3, y3, x4, y4)
}


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

int main() {
  int N;
  cin >> N;
  map<int, int> card;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    card[tmp]++;
  }
  int ans = N, discard = 0;
  for (auto p : card) {
    auto value = p.second;
    discard += value-1;
  }
  if (discard % 2 == 1) ans--;
  ans -= discard;
  cout << ans << endl;
}


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

int main()
{
  int n,d,m,a,sum[101];
  vector<vector<int> > V;

  while(1){
    cin>>n>>d;
    if(n+d==0)break;
    V.clear();
    V.resize(n);
    for(int i=0;i<n;i++){
      cin>>m;
      sum[i]=0;
      for(int j=0;j<m;j++){
	cin>>a;
	V[i].push_back(a);
	sum[i]+=a;
      }
    }/*
    for(int i=0;i<V.size();i++){
      for(int j=0;j<V[i].size();j++)cout<<V[i][j]<<" ";
      cout<<endl;
      }*/

    while(1){
      bool flag=true;
      for(int i=0;i<V.size();i++){
	if(!V[i].empty()){
	  int b=V[i].back();V[i].pop_back();
	  int ma=-1,mi=10000001;
	  sum[i]-=b;
	  for(int j=0;j<V.size();j++){
	    if(!V[j].empty()){
	      ma=max(ma,sum[j]);
	      mi=min(mi,sum[j]);
	    }
	  }
	  if((ma-mi)<=d){
	    break;
	  }
	  V[i].push_back(b);
	  sum[i]+=b;
	}
	if(i==V.size()-1)flag=false;
      }
      if(!flag){
	cout<<"No"<<endl;
	break;
      }
      int ans=0;
      for(int i=0;i<n;i++)ans+=sum[i];
      if(ans==0){
	cout<<"Yes"<<endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1268
#pragma warning(disable : 4996)
#include"bits/stdc++.h"
using namespace std;

#define ll long long
#define fo(i,n) for(ll i=0; i<(n); i++)
#define FO(i,a,b) for(auto i=a; i!=(b); i+=(b)>(a)?1:-1)
#define vll vector<ll>
#define vch vector<char>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sll set<ll>
#define all(c) c.begin(), c.end()
#define on(x) cout<<x<<"\n";
#define os(x) cout<<x<<' ';
#define nl cout<<"\n";

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll n, r, flag=0;
    cin>>n;
    while(n)
    {
        r=n%10;
        n/=10;
        if(r==7)
        {
            flag=1;
            break;
        }
    }
    if(flag) on("Yes")
    else on("No")
    return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int[][] list = new int[a + 1][b + 1];
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                list[i][j] = scanner.nextInt();
            }
        }
        for (int i = 0; i < a; i++) {
            int sum = 0;
            for (int j = 0; j < b; j++) {
                sum += list[i][j];
            }
            list[i][b] = sum;
        }
        for (int i = 0; i < b + 1; i++) {
            int sum = 0;
            for (int j = 0; j < a; j++) {
                sum += list[j][i];
            }
            list[a][i] = sum;
 
        }
 
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                if (j == 0)
                    System.out.print(list[i][j]);
                else
                    System.out.print(" " + list[i][j]);
 
            }
            System.out.println();
        }
    }
}


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

const int MAX_N=51;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p,stone;
    vector<int> have(MAX_N);
    while(cin >> n >> p,n,p){
        for (int i=0;i<MAX_N;++i) have[i]=0;
        stone=p;
        for (int i=0;;i=(i+1)%n){
            if (have[i]==p){
                cout << i << endl;
                break;
            }
            if (stone) ++have[i],--stone;
            else if (have[i]) stone+=have[i],have[i]=0;
        }
    }
}


Measured memory_bytes: 3012
#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)
#define yesno(flg) if(flg){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define vi vector<int>
#define MAX_N 200005
#define i197 1000000007

using namespace std;


typedef long long ll;
typedef pair<int,int> Pi;
typedef pair<ll,ll> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
P1 xy[MAX_N]={};


int main() {
	Pi hw[6];
	int h1,w1;

	rep(i,6){
		cin>>h1>>w1;
		if(h1>w1)swap(h1,w1);
		hw[i].first=h1;
		hw[i].second=w1;
	}
	sort(hw,hw+6);
	bool flg=true;
	if(hw[0]!=hw[1]||hw[2]!=hw[3])flg=false;
	if(hw[4]!=hw[5]||hw[0].first!=hw[2].first)flg=false;
	if(hw[0].second!=hw[4].first||hw[2].second!=hw[4].second)flg=false;


	if(flg){
		cout<<"yes"<<endl;
	}else{
		cout<<"no"<<endl;
	}


	return 0;
}



Measured memory_bytes: 6240
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 10000
#define N 300
#define M 30000

using namespace std;

int n, m, S, T;
int pri[N], cur[N];
int head[N], nex[M], to[M], cap[M], te = 1;

char gri[105][105];

inline void ade(int u, int v, int w) {
	nex[++te] = head[u], head[u] = te;
	to[te] = v, cap[te] = w;
}

bool bfs() {
	queue<int> que;
	memset(pri, 0, sizeof pri);
	pri[S] = 1;
	que.push(S);
	while(!que.empty()) {
		int u = que.front(); que.pop();
		for(int i = head[u]; i; i = nex[i]) {
			int v = to[i];
			if(cap[i] && !pri[v]) {
				pri[v] = pri[u] + 1;
				if(v == T) {
					return true;
				}
				que.push(v);
			}
		}
	}
	return false;
}
int dfs(int u, int rem) {
	if(!rem || u == T) return rem;
	int tmp, flow = 0;
	for(int &i = cur[u]; i; i = nex[i]) {
		int v = to[i];
		if(pri[v] != pri[u] + 1 ||
		   !( tmp = dfs(v, min(cap[i], rem)) ) ) continue;
		flow += tmp, cap[i] -= tmp, cap[i ^ 1] += tmp, rem -= tmp;
		if(!rem) break;
	}
	return flow;
}

void maxflow() {
	int flow = 0;
	while(bfs()) {
		memcpy(cur, head, sizeof cur);
		flow += dfs(S, inf);
	}
	if(flow >= inf) {
		puts("-1");
	} else {
		printf("%d\n", flow);
	}
	return;
}

int main() {
	scanf("%d%d", &n, &m);
	S = n + m + 1, T = n + m + 2;
	for(int i = 1; i <= n; ++i) {
		scanf("%s", gri[i] + 1);
		for(int j = 1; j <= m; ++j) {
			if(gri[i][j] == 'o') {
				ade(i, n + j, 1), ade(n + j, i, 1);
			} else if(gri[i][j] == 'S') {
				ade(S, i, inf), ade(i, S, 0);
				ade(S, n + j, inf), ade(n + j, S, 0);
			} else if(gri[i][j] == 'T') {
				ade(i, T, inf), ade(T, i, 0);
				ade(n + j, T, inf), ade(T, n + j, 0);
			}
		}
	}
	
	maxflow();
	return 0;
}

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

int main(){
  int n; cin>>n;
  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
    p[i]--;
  }
  int cnt=0;
  vector<int> d;
  rep(i,n){
    if(i==p[i]){
      cnt++;
    }else{
      if(cnt!=0) d.push_back(cnt);
      cnt=0;
    }
  }
  if(cnt!=0) d.push_back(cnt);
  int ans=0;
  for(auto x : d){
    ans+=(x+1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3832
// the biggest power of 2 that doesn't exceed X
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n;
  cin >> n;
  if(n == 1) {
    cout << 1;
    return 0;
  }
  // 0000000000001101 = 13
  // __builtin_ctzll(n);
  long long b = 1LL << (63 - __builtin_clzll(n));
  // while(2 * b <= n) b *= 2;
  cout << 2 * b - 1 << endl;
}

Measured memory_bytes: 256
S = list(input())
if int(''.join(S[0:2])) == 0 and int(''.join(S[2:4])) == 0:
    print('NA')
elif int(''.join(S[0:2])) == 0 and int(''.join(S[2:4])) > 12:
    print('NA')
elif int(''.join(S[0:2])) == 0 and int(''.join(S[2:4])) <= 12:
    print('YYMM')
elif int(''.join(S[2:4])) == 0 and int(''.join(S[0:2])) > 12:
    print('NA')
elif int(''.join(S[2:4])) == 0 and int(''.join(S[0:2])) <= 12:
    print('MMYY')
    
elif int(''.join(S[0:2])) > 12 and int(''.join(S[2:4])) > 12:
    print('NA')
elif int(''.join(S[0:2])) <= 12 and int(''.join(S[2:4])) > 12:
    print('MMYY')
elif int(''.join(S[0:2])) > 12 and int(''.join(S[2:4])) <= 12:
    print('YYMM')
else:
    print('AMBIGUOUS')



Measured memory_bytes: 3444
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007


void print_vec(vll a)
{
	cout << "start printing the vector\n";
	for (ll i = 0; i < a.size(); i++)
		cout << a[i] << " ";
	cout << "\n";
}
void print_mat(vector<vll> a)
{
	cout << "start printing the matrix\n";
	for (ll i = 0; i < a.size(); i++)
	{
		for (ll j = 0; j < a[i].size(); j++)
		{
			cout << a[i][j] << " ";
		}
		cout << "\n";
	}
}

/******************************************
* NUMBER THEORY ;) *
******************************************/



ll powermod(ll x, ll y)
{
	ll res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % mod;
		y = y >> 1;
		x = (x * x) % mod;
	}
	res %= mod;
	return res;
}
ll factmod(ll n)
{
	ll res = 1;
	while (n > 1)
	{
		res = (res * ((n / mod) % 2 ?  mod - 1 : 1)) % mod;
		for (ll i = 2; i <= n % mod; ++i)
			res = (res * i) % mod;
		n /= mod;
	}
	res %= mod;
	return res;
}



void solve()
{
	ll n, m;
	cin >> n >> m;
	cout << 1 + 2 + 3 - m - n << "\n";

}

int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 3644
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda a: a[0] + a[1], reverse=True)

ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += AB[i][0]
    else:
        ans -= AB[i][1]
print(ans)


Measured memory_bytes: 21300
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    string S;
    cin >> S;
    int i(0), sum(0), N = S.length(), N0 = N;
    for (i = 0; i < N - 1; i++)
    {
        while (S[i] != S[i + 1] && i < N - 1)
        {
            S.erase(i, 2);
            N -= 2;
        }
        while (S[i] != S[i - 1] && i < N && i > 0)
        {
            S.erase(i - 1, 2);
            i--;
            N -= 2;
        }
    }
    cout << N0 - N << endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(N: int):
    L = factorization(N)
    sm = 0
    for l in L:
        if l[0] == 1:
            continue
        n = l[1]
        ct = 1
        while (ct + 1) * ct / 2 <= n:
            ct += 1
        sm += ct - 1

    print(sm)
    return


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

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

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

    return arr

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Measured memory_bytes: 63472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  lint x;
  cin>>x;

  lint z=100;
  rep(i,1e8){
    if(z>=x) return i;
    z+=z/100;
  }
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  queue<int> q;
  for(int i=0; i<n; i++){
    int tmp;
    cin>>tmp;
    q.push(tmp);
  }
  int max=0;
  int count=0;
  for(int i=0; i<n; i++){
    if(max<=q.front()){
      count++;
      max=q.front();
    }
    q.pop();
  }
  
  cout<<count<<endl;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (pow(a, 2) == pow(b, 2) + pow(c, 2)) cout << b * c / 2 << endl;
	if (pow(b, 2) == pow(a, 2) + pow(c, 2)) cout << a * c / 2 << endl;
	if (pow(c, 2) == pow(a, 2) + pow(b, 2)) cout << a * b / 2 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N, X = map(int, input().split())
    *L, = map(int, input().split())

    D = [0]
    for i in range(0, N):
        D.append(D[i] + L[i])

    cnt = 0
    for i in range(len(D)):
        if D[i] <= X:
            cnt += 1
    print(cnt)


main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int w, h;
int c[51][51];
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

void dfs(int y, int x){
	c[y][x] = 0;
	for(int i = 0; i < 8; i++){
		int ny = y + dy[i], nx = x + dx[i];
		if(0<=ny and ny<h and 0<=nx and nx<w and c[ny][nx]==1){
			dfs(ny, nx);
		}
	}
}

int solve(){
	int res = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(c[i][j] == 1){
				dfs(i, j);
				res++;
			}
		}
	}

	return res;
}

int main(void){
	while(scanf("%d%d", &w, &h) != EOF){
		if(w == 0 and h == 0) break;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				scanf("%d", &(c[i][j]));
			}
		}
		printf("%d\n", solve());
	}

	return 0;
}



Measured memory_bytes: 3232
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>8||b>8)ou(":(");
  else ou("Yay!");
}

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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n, m; cin >> n >> m;
  	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
  	return 0;
}


Measured memory_bytes: 3652
open Hashtbl
let n = Scanf.scanf " %d" (+) 0
let ss = Array.init n @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let m = Scanf.scanf " %d" (+) 0
let ts = Array.init m @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let h = create n
let f s n = if mem h s then replace h s @@ find h s + n else add h s 1
let _ = Array.iter (fun s -> f s 1) ss; Array.iter (fun t -> f t @@ -1) ts;
  fold (fun _ c m -> max m c) h 0 |> Printf.printf "%d\n"

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    int A[2][N];

    rep(i, 2) {
        rep(j, N) {
            cin >> A[i][j];
        }
    }

    int ans = 0;
    rep(i, N) {
        int cnt = A[0][0];
        repd(j, 1, i + 1) cnt += A[0][j];
        repd(j, i, N) cnt += A[1][j];
        ans = max(ans, cnt);
    }

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

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

using namespace std;

using int64 = long long;

int main() {
  string S;
  cin >> S;
  int w;
  cin >> w;
  for(int i = 0; i < S.size(); i += w) {
    cout << S[i];
  }
  cout << endl;
}



Measured memory_bytes: 256
INF = 999999999999999999L
EPS = 1e-12

def read():
    return raw_input().strip()

def read_ints():
    return map(int,read().split())

n = int(read())
arr = read_ints()

ans = []

while len(arr) > 0:
    remove = -1 
    for i in range(len(arr)):
        if arr[i] == i+1:
            remove = i 
            
    if remove == -1:
        break 
        
    ans.append(arr[remove])
    del arr[remove]
    
if len(ans) == n:
    for x in reversed(ans):
        print x 
else:
    print -1 


Measured memory_bytes: 2568
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;
#define ll long long

int main(void) {
string str;
int box[50];
vector<int> v;
int buf;
cin>>str;
for(int i=0;i<str.size();i++){
  switch (str[i]) {
    case '1':box[i]=1;
    break;
    case '2':box[i]=2;
    break;
    case '3':box[i]=3;
    break;
    case '4':box[i]=4;
    break;
    case '5':box[i]=5;
    break;
    case '6':box[i]=6;
    break;
    case '7':box[i]=7;
    break;
    case '8':box[i]=8;
    break;
    case '9':box[i]=9;
    break;
  }

}


buf=abs(753-(100*box[0]+10*box[1]+box[2]));

for(int i=0;i<str.size()-2;i++){
  if(abs(buf)>abs(753-(100*box[i]+10*box[i+1]+box[i+2])))
  buf=abs(753-(100*box[i]+10*box[i+1]+box[i+2]));
}

printf("%d",buf);



	return 0;
}


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

int main(){ 
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  int res = 1e9;
  for (int i = 0; i <= 100; i++) {
    int tmp = 0;
    for (int j = 0; j < n; j++) {
      tmp += (x[j] - i) * (x[j] - i);
    }
    res = min(res, tmp);
  }
  cout << res << endl;
  return 0;
} 

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

int main(int argc, char *argv[]){
  int n;
  while(cin >> n, n){
    int I[n], p[n], q[n], r[n], cnt = 0;
    for (int i = 0; i < n; i++) {
      cin >> I[i] >> p[i] >> q[i] >> r[i];
    }
    int P, Q, R, C;
    cin >> P >> Q >> R >> C;
    for (int i = 0; i < n; i++) {
      if(p[i]*4 + q[i]*9 + r[i]*4 <= C &&
         p[i] <= P && q[i] <= Q && r[i] <= R){
        std::cout << I[i] << std::endl;
        cnt++;
      }
    }
    if(cnt == 0){
      std::cout << "NA" << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1176
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
csf=(n-1).times.map{gsmi}
ans=[]

0.upto(n-2) do |i|
  sum=0
  (i).upto(n-2) do |j|
    ti,st,freq=csf[j]
    t1=st
    t2=(sum/freq.to_f).ceil*freq
    sum=max(t1,t2)+ti
  end
  ans<<sum
end

puts ans
puts 0

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

int main() {
  int a, b, c;
  cin >> a >> b;
  c = (a * b) % 2;
  if (c == 0) {
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[101];
	int n;
	int i;
	int max = 0;

	for (i = 0; i <= 100; i++){
		a[i] = 0;
	}

	while (scanf("%d", &n) != EOF){
		a[n]++;
		if (a[n] > max){
			max = a[n];
		}
	}

	for (i = 1; i <= 100; i++){
		if (max == a[i]){
			printf("%d\n", i);
		}
	}

	return (0);
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int s=1;
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]==s)
    {
      count++;
      s++;
    }
  }
  int br=n-count;
  if(br==n)
    cout<<-1;
  else 
    cout<<br;
}

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

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int n = s.length() + 1;
  char c = s[0];
  int p = 0;
  vector<long long> vec(n, -1);
  int co = 0;
  for(int x = 0; x<n-2; x++){
  	if(s[x] == '>' && s[x+1] == '<'){
  		co++;
  		vec[x+1] = 0;
  		int x1 = x;
  		while(x1 >= 1 && s[x1-1] == '>')vec[x1] = vec[x1+1] + 1, x1--;


  	}
  }
  if(co == 0){
  	if(s[0] == '<')
  		vec[0] = 0;
  	int x1 = 1;
  	for(auto a : s){
  		if(a == '<'){
  			vec[x1] = vec[x1-1] + 1;
  		}
  		else break;
  		x1++;
  	}
  	if(s[n-2] == '>')vec[n-1] = 0;
  	for(int x = n-2; x>=0; x--){
  		if(s[x] == '>')
  			vec[x] = vec[x+1] + 1;
  	}
  	cout << accumulate(vec.begin(), vec.end() , 0LL);
  	return 0;
  }
  // for(int f : vec)cout << f <<  " ";
  // 	cout << endl;
  if(s[0] == '<'){
  	vec[0] = 0;
  }





  for(int x =1; x<n; x++){
  	if(vec[x] == -1 && s[x-1] == '<')vec[x] = vec[x-1] + 1;
  }

  	if(s[0] == '<')
  		vec[0] = 0;
  	int x1 = 1;
  	for(auto a : s){
  		if(a == '<' && vec[x1] == -1){
  			vec[x1] = vec[x1-1] + 1;
  		}
  		else break;
  		x1++;
  	}
  	if(s[n-2] == '>')vec[n-1] = 0;
  	for(int x = n-2; x>=0; x--){
  		if(s[x] == '>' && vec[x] == -1)
  			vec[x] = vec[x+1] + 1;
  	}



  for(int x =0; x<n-1; x++){
  	if(s[x] == '>' && vec[x] <= vec[x+1])vec[x] =vec[x+1]+1;
  	if(s[x] == '<' && vec[x] >= vec[x+1])vec[x+1] = vec[x+1] + 1;
  }
  // cout << endl;
  //   for(int f : vec)cout << f <<  " ";

  long long ans = accumulate(vec.begin(), vec.end(), 0LL);
  cout << ans;


  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N,K; cin >> N >> K;
    vector<int> A(N);
    REP(i,N){     
        cin >> A[i];
    }
    sort(ALL(A));

    int ng = 0;
    int ok = A[N-1];
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        ll cnt = 0;
        REP(i,N){
            cnt += (A[i]-1)/mid;
        }
        if(cnt <= K){//ここに条件をかく
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
    

    return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
	string ans;
	int y, m, d;
	char s;
	cin >> y >> s >> m >> s >> d;
	if ((y > 2019) || (y == 2019 && m > 4)) {
		ans = "TBD";
	}
	else {
		ans = "Heisei";
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N,H,A[100000];
  cin>>H>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  for (int i(0);i<N;i++){
    H -= A[i];
  }
  if (H > 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}



Measured memory_bytes: 640
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    sums = []

    for i in range(n):
        if i == 0:
            sums.append(A[i])
            if A[i] == 0:
                sums[i] = 1
                res += 1
            elif A[i] < 0:
                res += 1 - A[i]
                sums[i] = 1
        else:
            sums.append(sums[i-1] + A[i])
            if sums[i] == 0:
                if sums[i-1] > 0:
                    sums[i] = -1
                    res += 1
                else:
                    sums[i] = 1
                    res += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res += 1 + sums[i]
                sums[i] = -1
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res += 1 - sums[i]
                sums[i] = 1
    
    sums = []
    res1 = 0

    for i in range(n):
        if i == 0:
            sums.append(A[i])
            if A[i] == 0:
                sums[i] = -1
                res1 += 1
            elif A[i] > 0:
                res1 += 1 + A[i]
                sums[i] = -1
        else:
            sums.append(sums[i-1] + A[i])
            if sums[i] == 0:
                if sums[i-1] > 0:
                    sums[i] = -1
                    res1 += 1
                else:
                    sums[i] = 1
                    res1 += 1
            elif (sums[i-1] > 0) and (sums[i] > 0):
                res1 += 1 + sums[i]
                sums[i] = -1
            elif (sums[i-1] < 0) and (sums[i] < 0):
                res1 += 1 - sums[i]
                sums[i] = 1
    
    print(min(res, res1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  int N,M;
  cin>>N>>M;
  Graph G(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }

  vector<int> sign(N,-1);
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int v=q.front();
    q.pop();
    for(auto nv:G.at(v)){
      if(sign.at(nv)==-1){
        sign.at(nv)=v;
        q.push(nv);
      }
    }
  }

  cout<<"Yes"<<endl;
  for(int i=1;i<N;i++){
    cout<<sign.at(i)+1<<endl;
  }
}


Measured memory_bytes: 10024
#include <bits/stdc++.h>
#include <unordered_map>
#define lli long long int
#define fl(i, a, b) for(int i = a; i < b; ++i)
#define fl2(i, a, b) for(int i = a; i <= b; ++i)
#define rfl(i, a, b) for(int i = a; i > b; --i)
#define rfl2(i, a, b) for(int i = a; i >= b; ++i)
#define all(v) ((v).begin(), (v).end())
#define all2(v) ((a) + 0, (a) + n);
#define sz(s) (s).size()
#define OO (lli)1e18
#define MIN INT_MIN
#define f first
#define s second		
#define mp make_pair
#define pb puch_back
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using namespace std;

lli power(lli x, lli y) {
	lli i, power = 1;
	if (y == 0)
		return 1;
	for (i = 1; i <= y; i++)
		power = power * x;
	return power;
}

int32_t main() {

	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	//freopen("overcode.in","r",stdin);
	//freopen("output.txt", "w", stdout);

	clock_t z = clock();

	int n, k;
	cin >> n >> k;
	fl2(i, k - n + 1, k) cout << i << " ";
	fl(i, k + 1, n + k) cout << i << " ";
	cout << '\n';
	debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007

int main(){
  ll h,w,a,b; cin>>h>>w>>a>>b;
  for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	  cout<<((i<b) xor (j<a));
      }
      cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

void input();
void calc();
void output();

int main(void)
{

	input();
	calc();
	output();
}


int n,m;
std::vector<int> line;

void set_line()
{
	for (int i = 0; i < n; i++)
	{
		line.push_back(i + 1);
	}
}

void input()
{
	cin >> n >> m;
	set_line();

}

void calc()
{
	int a, b;
	char c;
	for (int i = 0; i < m; i++)
	{
		cin >> a >> c  >> b;
		swap(line[a - 1], line[b - 1]);
	}

}

void output()
{
	for (int i = 0; i < n; i++)
	{
		cout << line[i] << endl;
	}
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std ; 
int main (){
        int n,k ;
        cin>>n>>k;
        int p[n];
        for(int  i=0;i<n;i++)cin>>p[i];
        sort(p,p+n);
        long long sum=0;
        for(int i =0;i<k;i++){
                sum+=p[i];
        }cout<<sum;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,u,v,tot,lev[N],dep[N],lg[N],fa[N][20],head[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
void dfs(int u,int p)
{
    dep[u]=dep[p]+1;fa[u][0]=p;
    for(int i=1;1<<i<=dep[p];i++)
        fa[u][i]=fa[fa[u][i-1]][i-1];
    lev[u]=true;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==p) continue;
        dfs(v,u);lev[u]=false;
    }
}
int LCA(int u,int v)
{
    if(dep[u]<dep[v]) swap(u,v);
    while(dep[u]>dep[v]) u=fa[u][lg[dep[u]-dep[v]]];
    if(u==v) return u;
    for(int i=lg[dep[u]];i>=0;i--)
        if(fa[u][i]!=fa[v][i])
        u=fa[u][i],v=fa[v][i];
    return fa[u][0];
}
int DIS(int u,int v)
{
    return dep[u]+dep[v]-2*dep[LCA(u,v)];
}
int main()
{
    for(int i=1;i<N;i++) lg[i]=lg[i-1]+(1<<lg[i-1]==i);
    for(int i=1;i<N;i++) lg[i]--;
    scanf("%d%d%d",&n,&u,&v);
    for(int i=1;i<n;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    dfs(1,0);
    int ans=0;
    for(int i=1;i<=n;i++)
        if(lev[i])
    {
        if(DIS(u,i)>DIS(v,i)) continue;
        int len=DIS(v,i)-1;
        ans=max(ans,len);
    }
    cout<<ans;
}


Measured memory_bytes: 15232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;

    if(k<=a)
        cout<<k<<endl;
    else if(k<=a+b)
        cout<<a<<endl;
    else
        cout<<a-(k-a-b)<<endl;
    exit(0);
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int x, s;
  s=0;
  for (int i=0; i<N; i++) {
    cin >> x;
    x = 2*x;
    if (x > K)
      x = 2*K - x;
    s += x;
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int A, B, K;
int main() {
	cin >> A >> B >> K;
	for (int i = 0; i < K; ++i) {
		if (i % 2 == 0) {
			A = A / 2 * 2;
			B += A / 2;
			A /= 2;
		}
		else {
			B = B / 2 * 2;
			A += B / 2;
			B /= 2;
		}
	}
	cout << A << ' ' << B << '\n';
	return 0;
}

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

int main() {
    int i, j;
    cin >> i >> j;
    if (i == j) {
        cout << "a == b" << endl;
    } else if (i < j) {
        cout << "a < b" << endl;
    } else {
        cout << "a > b" << endl;
    }
    return 0;
}

Measured memory_bytes: 1156