akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int n,m;
	List<List<Integer>> graph;
	static int[] memo;//graph.get(i)の有向パスの最大を記録
	static boolean f[];//memo[i]に記録されているならばtrue;

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

	private void solve() {
		n = nextInt();
		m = nextInt();
		graph = new ArrayList<List<Integer>>();
		for(int i=0;i<=n;i++)graph.add(new ArrayList<Integer>());
		for(int i=0;i<m;i++)graph.get(nextInt()).add(nextInt());

		f = new boolean [n+1];
		memo = new int [n+1];
		for(int i=1;i<=n;i++)if(!f[i])memo[i] = SearchVerticesPass(i);

		Arrays.sort(memo);
		System.out.println(memo[n]);
	}

	private int SearchVerticesPass(int vi) {
		if(f[vi])return memo[vi];
		List<Integer>V = graph.get(vi);
		int cntmax=0;
		for(int i=0;i<V.size();i++)cntmax=Math.max(SearchVerticesPass(V.get(i))+1, cntmax);
		f[vi]=true;
		return memo[vi] = cntmax;
	}

	private int nextInt() {
		return Integer.parseInt(sc.next());
	}
}

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

int h,w;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
char s[60][60];

int main(){
  cin >> h >> w;
  
  for (int i=0;i<h;i++) cin >> s[i];
  bool ans = true;
  
  for (int i=0;i<h;i++){
    for (int j=0;j<w;j++){
       if (s[i][j] == '#'){
          bool found = false; 
          for (int k=0;k<4;k++){
            int i2=i+dx[k];
            int j2=j+dy[k];
            if (i2>=0&&i2<h&&j2>=0&&j2<w&&s[i2][j2]=='#'){
              found = true;
          }
       }
      if (!found) ans = false;
    }
  }
}
cout << (ans ? "Yes" : "No") << endl;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
const int maxn = 1e6+100;
const int MOD = 1e9+7;
const double Pi = 3.141592654;
typedef long long ll;
typedef unsigned long long ull;

struct node
{
    ll x;
    ll y;
    int id;
} pos[maxn];

bool cmp1(node a, node b)
{
    if(a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}

bool cmp2(node a, node b)
{
    if(a.y == b.y)
        return a.x < b.x;
    return a.y < b.y;
}

struct edge
{
    int u;
    int v;
    ll w;
} g[maxn];

bool cmp(edge a, edge b)
{
    return a.w < b.w;
}

ll pre[maxn];

int Find(int x)
{
    if(pre[x] == x) return x;
    else return pre[x] = Find(pre[x]);
}

void unit(int x,int y)
{
    x = Find(x);
	y = Find(y);
    if(x != y)
    	pre[y] = x;
}

bool same(int x, int y)
{
    return Find(x) == Find(y);
}

int main()
{
    int n;
    cin >> n;
    for(int i=1 ; i<=n ; ++i)
    {
        cin >> pos[i].x >> pos[i].y;
        pos[i].id = i;
    }
    sort(pos+1, pos+1+n, cmp1);
    for(int i=1; i<=n ; ++i)
    {
        g[i].u = g[i+n].v = pos[i].id;
        g[i].v = g[i+n].u = pos[i+1].id;
        g[i].w = g[i+n].w = abs(pos[i].x - pos[i+1].x);
    }
    sort(pos+1, pos+1+n, cmp2);
    for(int i=1; i<=n ; ++i)
    {
        g[i+2*n].u = g[i+3*n].v = pos[i].id;
        g[i+2*n].v = g[i+3*n].u = pos[i+1].id;
        g[i+2*n].w = g[i+3*n].w = abs(pos[i].y-pos[i+1].y);
    }
    for(int i=0; i<=n; i++)
    {
        pre[i] = i;
    }
    sort(g+1, g+1+4*n, cmp);
    int sum = 0, cnt = 0;
    for(int i=1; i<=4*n; ++i)
    {
        if(cnt == n - 1)
            break;
        if(!same(g[i].u, g[i].v))
        {
            unit(g[i].u, g[i].v);
            sum += g[i].w;
            cnt ++;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 13312
using System;
using System.Linq;

namespace Sort_I
{
    class Shell_Sort
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var A = new int[n];
            for (int i = 0; i < A.Length; i++)
                A[i] = int.Parse(Console.ReadLine());

            var cnt = ShellSort(A);
            Console.WriteLine(cnt);

            for (int i = 0; i < A.Length; i++)
                Console.WriteLine(A[i]);
        }

        static public int InsertionSort(int[] A, int g)
        {
            var cnt = 0;
            for (int i = g; i < A.Length; i++)
            {
                var v = A[i];
                var j = i - g;
                while (j >= 0 && A[j] > v)
                {
                    A[j + g] = A[j];
                    j -= g;
                    cnt++;
                }
                A[j + g] = v;
            }
            return cnt;
        }

        static public int ShellSort(int[] A)
        {
            var cnt = 0;
            var n = A.Length;
            var m = 1;
            while ((n = n >> 1) != 0)
                m++;
            var G = Enumerable.Range(1, m).Select(i => (int)Math.Pow(2, m - i)).ToArray();

            Console.WriteLine(m);
            for (int i = 0; i < G.Length - 1; i++)
                Console.Write(G[i] + " ");
            Console.WriteLine(G.Last());

            for (int i = 0; i < m; i++)
                cnt += InsertionSort(A, G[i]);

            return cnt;
        }
    }
}

Measured memory_bytes: 17108
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  string a,b;
  cin >> a >> b;
  cout << b << a << endl;
  return 0;
}

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

int main(void) {
  int A, B, K;

  cin >> A >> B >> K;

  if (B - A + 1 >= 2 * K) {
    for (int i = 0; i < K; i++) {
      cout << A + i << endl;
    }
    for (int i = K - 1; i >= 0; i--) {
      cout << B - i << endl;
    }
  } else {
    for (int i = A; i <= B; i++) {
      cout << i << endl;
    }
  }

  return 0;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
int main( void ){
	// initialize();
	ll N, A, B;
	cin >> N >> A >> B;
	ll times = N / (( ll )A + B );
	if (times == 0){
		cout << min( A, N ) << endl;
	}
	else {
		cout << times * A + min( N - times * ( A + B ), A ) << endl;
	}
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 256
fun main(args:Array<String>){
  var N = readLine()!!.toInt()
  var V = readLine()!!.split(" ").map(String::toInt)
  var C = readLine()!!.split(" ").map(String::toInt)
  var total = 0
  for(i in 0..N-1){
    if(V[i] - C[i]>0){
      total += V[i] - C[i]
    }
  }
  println(total)
}

Measured memory_bytes: 37872
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;


int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if( (A % 2 == 0) && A == B && B == C){
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;

    while(! (A % 2 || B % 2 || C % 2)){
        int a = B / 2 + C / 2;
        int b = A / 2 + C / 2;
        int c = A / 2 + B / 2;
        A = a;
        B = b;
        C = c;
        ans ++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)


////////////////////////////////////////////////////////////

int main(){
	int n,m;
	cin >> n >> m;
	
	long ans = m*1900 + (n-m)*100;
	
	ans *= pow(2,m);
	P(ans);
	ret 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e6+5;
void solve(){
	int n,m,x; 
	cin>>n>>m>>x;
	if(n<m)swap(n,m);/// n is the biggest 
	bool can = false;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			int trt = i*j+(n-i)*(m-j);
			if(trt==x)can = true;
		}
	}
	if(can)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}
/// 11000
/// 11000
/// 00111


Measured memory_bytes: 3608
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7,MAXL=25;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
vector<int> v;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	pii mi={INF,0},ma={-INF,0};
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mi=min(mi,{a[i],i});
		ma=max(ma,{a[i],i});
	}
	if(abs(ma.F)>=abs(mi.F)&&ma.F>0){
		pii m=ma;
		cout<<2*n<<"\n";
		for(int i=1;i<=n;i++){
		//	bool t=1;
		//	if(a[i]<0)
		//		t=0;
			cout<<m.S<<" "<<i<<"\n";
			//a[i]+=m.F;
			//m=max(m,{a[i],i});
			cout<<m.S<<" "<<i<<"\n";
			//a[i]+=m.F;
			//m=max(m,{a[i],i});
		//	if(t)
				m.S=i;
		}
	}
	else{
		pii m=mi;
		cout<<2*n<<"\n";
		for(int i=n;i>0;i--){
		//	bool t=1;
	//		if(a[i]>0)
	//			t=0;
			cout<<m.S<<" "<<i<<"\n";
			//a[i]+=m.F;
			//m=min(m,{a[i],i});
			cout<<m.S<<" "<<i<<"\n";
			//a[i]+=m.F;
			//m=min(m,{a[i],i});
		//	if(t)
				m.S=i;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import time

def sum_A(A, n):
    dic = {}
    #A_ = A
    #n_ = n
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    #A = sorted(A)
    start = time.time()
    solve = sum_A(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"
    end = time.time()
    #print end - start

Measured memory_bytes: 12368
// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define debug(x) cerr << #x << " = " << x << '\n';
#define pll pair <ll, ll>
#define fir first
#define sec second

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

const int N = 200005;

ll a[N], n;
ll ans = 0;

int main() {
  scanf("%lld", &n);
  for (rint i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n, [&](ll a, ll b) {
    return a > b;
  });
  for (rint i = 1; i < n; i++) {
    ans += a[i / 2];
  }
  printf("%lld\n", ans);
  return 0;
}

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

int main() {
  vector<int> t(5);
  cin >> t[0] >> t[1] >> t[2] >> t[3] >> t[4];
  
  sort(t.begin(), t.end(), [](const int& x, const int& y) {return x%10 < y%10;});
  
  int T = 0;
  
  int i = 0;
  for(;i<5; i++){
    if(t[i]%10!=0)
      break;
    else
      T += t[i];
  }
  for(int j=4; j>=i; j--){
    T += t[j];
    if(j!=i)
	  T += (10-T%10);
//    cout << T << endl;
  }
  
  cout << T << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d.at(i);
    }
    int stage = N;
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            if(d.at(i) < d.at(j)){
                int t = d.at(i);
                d.at(i) = d.at(j);
                d.at(j) = t;
            }
        }
    }
    for(int i = 0; i < N - 1; i++){
        if(d.at(i) == d.at(i + 1)){
            stage--;
        }
    }
    cout << stage << endl;
}

Measured memory_bytes: 3564
N = int(input())
prefix = input()
suffix = input()


if len(prefix) + len(suffix) < N:
    d = N - len(prefix) + len(suffix)
    print(len(prefix + 'a' * d + suffix))
else:
    s = ""
    for i in range(1, N):
        # print(prefix[-i:], suffix[:i])
        if prefix[-i:] == suffix[:i]:
            s = prefix[:-i] + suffix
    if suffix == prefix:
        s = suffix
    if len(s) == 0:
        s = prefix + suffix
    print(len(s))



Measured memory_bytes: 3060
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

N = _I()
S = []
for i in range(N):
    S.append(input())

"""
a-zの文字数カウントする
[1,1,0,,,]
[1,1,0,,,]
[1,2,1,,,]

などのリストが得られる。
setしてカウント
"""

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#  ex = [chr(ord('a') + i) for i in range(26)]
#  s_counts = []
#  for s in S:
#      s_count = []
#      for a in ex:
#          s_count.append(s.count(a))
#      s_counts.append(s_count)

#  #  print(s_counts)

#  ans = 0
#  done_list = []
#  for s_count in s_counts:
#      if s_count in done_list:
#          continue
#      else:
#          done_list.append(s_count)
#          cnt = s_counts.count(s_count)
#          if cnt == 1:
#              continue
#          else:
#              ans += combinations_count(cnt, 2)
chars = []
for s in S:
    char_list = []
    for char in s:
        char_list.append(char)
    char_list.sort()
    char_list = ''.join(char_list)
    chars.append(char_list)
#  print(chars)
ans = 0
done_list = []
char_counts = {}
for char in chars:
    if char in char_counts.keys():
        char_counts[char] += 1
    else:
        char_counts[char] = 1
for char_count in char_counts.values():
    if char_count == 1: continue


    ans += combinations_count(char_count, 2)
print(ans)


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

typedef long long LL;

int main(void){
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5])cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define int long long
using namespace std;
typedef long long ll;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; ++ i) {
        cin >> a[i];
        sum += a[i];
    }
    int x = sum / n;
    function<int(int)> get = [&](int xx) -> int {
        int cur = 0;
        for (int i = 0; i < n; ++ i) {
            cur += (a[i] - xx) * (a[i] - xx);
        }
        return cur;
    };
    cout << min({get(x - 1), get(x), get(x + 1)});
    
}

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

using namespace std;

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

	vector<vector<int>> v(N, vector<int>(26, 0));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < s[i].size(); ++j) {
			int key = s[i][j] - 'a';
			v[i][key] += 1;
		}
	}
	
	string res = "";
	for (int i = 0; i < 26; ++i) {
		int cnt = 1e5;
		for (int j = 0; j < N; ++j) {
			cnt = min(cnt, v[j][i]);
		}
		if (cnt > 0) {
			char c = 'a' + i;
			string tmp(cnt, c);
			res += tmp;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
<>=~/ (.*) /,$
$`{$1}=$$1{$`}=$' for 2..<>;@s=<>=~$"*$';map$d[$_]//=$d[$u]+$$u{$s[@s]=$_},keys%{$u=$_}for@s;//,print$d[$`]+$d[$'],$/for<>

Measured memory_bytes: 125056
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int H, W; cin>>H>>W;
  vector<bool> row(H, true), col(W, true);
  vector<string> a(H);
  REP(h, H) {
    cin>>a[h];
    REP(w, W) {
      if(a[h][w] == '#') {
	row[h] = false;
	break;
      }
    }
  }
  REP(w, W) {
    REP(h, H) {
      if(a[h][w] == '#') {
        col[w] = false;
	break;
      }
    }
  }
  REP(h, H) {
    if(row[h]) continue;
    REP(w, W) {
      if(col[w]) continue;
      cout << a[h][w];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
S = list(str(input()))

i = 0
ans = 'Yes'
for x in S:
    if i == 0:
        if x not in ['R','U','D']:
            ans = 'No'
            break
        i += 1
    else:
        if x not in ['L','U','D']:
            ans = 'No'
            break
        i -= 1

print(ans)


Measured memory_bytes: 38384
from typing import Union, List
import sys

sys.setrecursionlimit(100000)

# 木の根を返す
def find(x: int, S: List[int]) -> int:
    if S[x] == x:
        return x
    else:
        S[x] = find(S[x], S)
        return S[x]

# xとyが同じ集合に属すかの判定
def same(x: int, y: int, S: List[int]) -> bool:
    return find(x, S) == find(y, S)

# xとyの属する集合を結合
def unite(x: int, y: int, S: List[int]) -> None:
    rx = find(x, S)
    ry = find(y, S)
    if rx == ry:
        return None
    else:
        S[rx] = ry

if __name__ == '__main__':
    [n, q] = [int(i) for i in input().split()]

    S = [i for i in range(n)]

    for i in range(q):
        [com, x, y] = [int(i) for i in input().split()]
        if com == 0:
            unite(x, y, S)
        elif com == 1:
            if same(x, y, S):
                print('1')
            else:
                print('0')
        else:
            raise ValueError('value error')



Measured memory_bytes: 14628
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;

#define all(A) (A).begin(), (A).bumsoo()
#define II(A) int (A); scanf("%d",&(A));
#define DBG if(1)
#define NDBG if(0)

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

const int MN = 100000 + 1;

int N;
int A[MN];
int bumsoo[MN];

int val(int x,int y){
	if(x>=N) return true;
	if(y>=A[x])	return true;
	return bumsoo[x]^((A[x]-1-y)&1);
}

int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++) scanf("%d",&A[i]);
	sort(A, A+N, greater<int>());
	bumsoo[N-1] = 0;
	for(int i=N-2;i>=0;i--){
		if(A[i] == A[i+1]) bumsoo[i] = bumsoo[i+1]^1;
		else bumsoo[i] = 0;
	}
	int x=0,y=0;
	while(x<N-1 && y+1 < A[x+1]) x++, y++;
	if(!val(x,y+1) || !val(x+1,y)){
		puts("First");
	}
	else puts("Second");
	return 0;
} 


Measured memory_bytes: 896
#include<iostream>
#define INF 100000000000000
#define MAXN 1000+10
using namespace std;
long long dist[MAXN][MAXN];
int main(){
	int i,j,k,n,m,a,b;
	
	cin>>n>>m;
	for (i = 0;i < n;++i){
		for (j = 0;j < n;++j){
			if (i != j) {
				dist[i][j]=INF;
			}
		}
	}
	
	for (i = 0;i < m;++i){
		cin>>a>>b;
		cin>>dist[a][b];
	}
	
	for (k = 0;k < n;++k){
		for (i = 0;i < n;++i){
			for (j = 0;j < n;++j){
				if (dist[i][k] != INF && dist[k][j] != INF)dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	
	for (i = 0;i < n;++i){
		if (dist[i][i] < 0) {
			cout<<"NEGATIVE CYCLE"<<endl;
			return 0;
		}
	}
	
	for (i = 0;i < n;++i){
		for (j = 0;j < n;++j){
			if (j) cout<<" ";
			if (dist[i][j] == INF) cout<<"INF";
			else cout<<dist[i][j];
		}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3552
#include <stdio.h>
int main ()
{
	int A,B,y;
	scanf ("%d %d",&A,&B);
	if (A<6)
		y=0;
	else if (A>=6&&A<=12)
		y=B/2;
	else 
		y=B;
	printf ("%d\n",y);
	return 0;
}


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

const static long long int MOD = 1000000000 + 7;

map<llong, llong> M;

template<typename T> void factorization(T p) {
    llong i = 2;
    while (i * i <= p) {
        if (p % i == 0) {
            ++M[i];
            p /= i;
        } else {
            ++i;
        }
    }

    if (p != 1) ++M[p];
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    COMinit();
    factorization(m);
    llong ans = 1;
    for (auto itr = M.begin(); itr != M.end(); ++itr) {
        ans = (ans * COM(itr->second + n - 1, itr->second)) % MOD; 
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int c = 0;
    int o = 0;
    if(s[0] == 'A'){
        if(s.size() < 5){
            for(int i = s.size() - 3; i < 3; i++){
                if(s[i] == 'C'){
                    c++;
                }
            }
            if(c == 1){
                for(int i = 0; i < s.size(); i++){
                    if(s[i] >= 97){
                        o++;
                    }
                }
                if(o == 2){
                    cout << "AC" << endl;
                    return 0;
                } else {
                    cout << "WA" << endl;
                    return 0;
                }
            } else {
                cout << "WA" << endl;
                return 0;
            }
        } else {
            for(int i = 2; i < s.size() - 1; i++){
                if(s[i] == 'C'){
                    c++;
                }
            }
            if(c == 1){
                for(int i = 0; i < s.size(); i++){
                    if(s[i] < 97){
                        o++;
                    }
                }
                if(o == 2){
                    cout << "AC" << endl;
                    return 0;
                } else {
                    cout << "WA" << endl;
                    return 0;
                }
            } else {
                cout << "WA" << endl;
                return 0;
            }
        }
    } else {
        cout << "WA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
dp =[float("INF")]*(2**N)
dp[0] = 0
for i in range(1,M+1):
    a,b = map(int,input().split())
    tmp = 0
    for c in list(map(int,input().split())):
        tmp += 1 << (c-1)
    for j in range(2**N):
        target = j|tmp
        dp[target] = min(dp[j]+a,dp[target])
if dp[-1] == float("INF"):
    print(-1)
else:
    print(dp[-1])


Measured memory_bytes: 76604
#include <iostream>

using namespace std;

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

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

  double ans = 0;
  if (n % 2 == 0) {
    cout << ((n / 2) / (double)n) << endl;
  } 
  else {
    cout << (((n / 2) + 1) / (double)n) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    string s;
    cin >> s;

    int r = 0, b = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '0')
            r++;
        else
            b++;
    }

    if (b == 0 || r == 0) {
        cout << 0 << endl;
    }

    else if (b < r) {
        cout << b*2 << endl;
    }
    
    else {
        cout << r*2 << endl;
    }

    


    return 0;
}

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

typedef long long int ll;
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i < n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i) 
#define WATCH(x) cout << (#x) << " is " << (x) << endl

#define PB push_back
#define N 300101
#define SZ 3001
#define LB lower_bound
#define M 1000000007
#define UB upper_bound
#define MP make_pair
#define LD long double
#define F first
#define S second

typedef vector< long long int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i=c.begin() ; i != c.end() ; i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end()
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);

int main()
{   
    ll n;
  cin >> n;
  ll i;
  vi v(n);
  vi sum(n);
  vi sum_r(n);
  rep(i , n)
  {
    cin >> v[i];
    if(i==0)
    {
        sum[i] = v[i];
        continue;
    }
    sum[i] = sum[i-1]+v[i];
  }
  
  ll min =INT_MAX;
  
   for(i = n-1 ; i>0 ; i--)
   {
       if(i == n-1)
       {
           sum_r[n-1] = v[i];
           if(abs(sum[i-1] - sum_r[i]) < min)
           {
               min = abs(sum[i-1] - sum_r[i]);
           }
           continue;
       }
       else 
       {
           sum_r[i] = sum_r[i+1] + v[i];
           if(abs(sum[i-1] - sum_r[i]) < min)
           {
               min = abs(sum[i-1] - sum_r[i]);
           }
       }
   }
   
   cout << min << endl;
   
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())


count = 0
while (B <= A):
    B = B*2
    count = count + 1

while (C <= B):
    C = C*2
    count = count + 1

if (count <= K):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9120
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 2e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b,ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a,ll b){ if(a==0){return b;}else{ return gcd(b%a,a);}}

struct ed
{
	int to;
	int val;
	int next;
}edge[maxn*4];

int n,m,cnt;
int head[maxn],res[maxn],vis[maxn];
set<int>con[maxn];

void init()
{
	cnt=0;
	memset(edge,-1,sizeof(edge));
	memset(head,-1,sizeof(head));
}

void add(int u,int v,int c)
{
	cnt++;
	edge[cnt].to=v;
	edge[cnt].val=c;
	edge[cnt].next=head[u];

	head[u]=cnt;
}

void solve()
{
	scanf("%d%d",&n,&m);

	for(int i=0;i<m;i++)
	{
		int p,q,c;
		scanf("%d%d%d",&p,&q,&c);
		add(p,q,c);
		add(q,p,c);
	}
	for(int i=1;i<=n;i++)
	{
		res[i]=INF;
	}
	priority_queue< pair<int,int> >que;
	que.push(make_pair(0,1));

	int cnt=0;
	res[1]=0;
	while(!que.empty())
	{
		/*
		cnt++;
		if(cnt>100)
		{
			return;
		}
		*/
		int dis = -que.top().first;
		int x=que.top().second;
		//cout<<dis<<" "<<x<<endl;
		que.pop();
		if(dis>res[x])
		{
			//cout<<"continue"<<endl;
			continue;
		}
		for(int i=head[x];i!=-1;i=edge[i].next)
		{
			int to = edge[i].to;
			int c = edge[i].val;
			int d = dis + (!con[x].count(c));

			//cout<<x<<" "<<to<<" "<<c<<" "<<d<<endl;
			if(d<res[to])
			{
				res[to]=d;
				con[to].clear();
				con[to].insert(c);
				que.push(make_pair(-d,to));
			}
			else if(d==res[to])
			{
				con[to].insert(c);
			}
		}
		//cout<<endl<<endl;
	}
	if(res[n]==INF)
	{
		puts("-1");
	}
	else
	{
		printf("%d\n",res[n]);
	}
}

int main()
{
    init();
    solve();
	return 0;
}

Measured memory_bytes: 29944
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

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

  if (abs(x - a) > abs(x - b)) {
    cout << "B" << endl;
  } else {
    cout << "A" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    string s;
    in(s);

    int count = 0;

    if (s == "SSS")
    {
        count = 0;
    }
    else if (s == "SSR")
    {
        count = 1;
    }
    else if (s == "SRS")
    {
        count = 1;
    }
    else if (s == "SRR")
    {
        count = 2;
    }
    else if (s == "RSS")
    {
        count = 1;
    }
    else if (s == "RSR")
    {
        count = 1;
    }
    else if (s == "RRS")
    {
        count = 2;
    }
    else if (s == "RRR")
    {
        count = 3;
    }

    outl(count);

    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
  int a, b, c;
  cin>>a>>b>>c;
  cout<<((b*10+c)%4==0?"YES":"NO")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n;
  cin >> n;

  long long int ans = 0;
  
  for(int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    
    while(temp % 2 == 0){
      ans++;
      temp /= 2;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main(void)
{
    int N;
    int ans = -1;
    cin >> N;
    vector<vector<pair<int,int> > > clue(N, vector<pair<int,int> >());
    for (int i=0; i<N; ++i) {
        int a;
        cin >> a;
        for (int j=0; j<a; ++j) {
            pair<int,int> p;
            int x, y;
            cin >> x >> y;
            x--;
            p = make_pair(x, y);
            clue[i].push_back(p);
        }
    }

    for (int bit = 0; bit < (1 << N); ++bit) {
        int counter = 0;
        bool ok = true;
        for (int i=0; i<N; ++i) {
            if (bit & (1 << i)) {
                for (int j=0; j<clue[i].size(); ++j) {
                    if ((bit>>clue[i][j].first&1) != clue[i][j].second)
                        ok =false;
                }
                counter++;
            }
        }
        if (ok) ans = max(ans, counter);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
s=list(input())
if(len(s)==1):
    print(0)
else:
    a=s[:]
    fir,sec=0,0
    for i in range(len(s)-1):
        if(s[i]==s[i+1]):
            s[i+1] = str(1 - (ord(s[i])-48))
            fir+=1
    print(fir)
    
    


Measured memory_bytes: 7468
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int i = Integer.parseInt(as.next());
		int j = Integer.parseInt(as.next());
		String[] a;
		a = new String[i];
		for(int s=0;s<i;s++){
			a[s] = as.next();
		}
		boolean po = true;
		int t = j-1;
		for(int s=i-1;s>=0;s--){
			for(int k=j-1;k>t;k--){
				if(String.valueOf(a[s].charAt(k)).equals("#")){
					po = false;
					break;
				}
			}
			for(int l=t;l>=0;l--){
				if(String.valueOf(a[s].charAt(l)).equals(".")){
					t = l+1;
					for(int q=l-1;q>=0;q--){
						if(String.valueOf(a[s].charAt(q)).equals("#")){
							po = false;
						}
					}
					break;
				}
				if(s!=0&&l==0&&String.valueOf(a[s].charAt(l)).equals("#")){
					t = 0;
				}
			}
			if(!po){
				break;
			}
		}
		if(po){
			System.out.println("Possible");
		}else{
			System.out.println("Impossible");
		}
	}
}

Measured memory_bytes: 9680
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

struct Combination
{
    int maxn;
    vector<ll> fmemo;
    vector<ll> imemo;
    vector<ll> ifmemo;
    
    Combination(int maxn) : maxn(maxn){
        fmemo.resize(maxn + 1);
        imemo.resize(maxn + 1);
        ifmemo.resize(maxn + 1);
        for(ll i = 1; i <= maxn; i++){
            imemo[i] = modpow(i, MOD - 2);
        }
    }

    ll fact(ll n){
        if(n == 0) return 1;
        if(fmemo[n]) return fmemo[n];
        return fmemo[n] = n * fact(n - 1) % MOD;
    }

    ll ifact(ll n){
        if(n == 0) return 1;
        if(ifmemo[n]) return ifmemo[n];
        return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
    }

    ll com(ll n, ll k){
        if(k > n || k < 0) return 0;
        if(k == n || k == 0) return 1;
        return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
    }
};

ll dp[305][305][305];

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int d[305];
    int m = 0;
    int c = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '0'){
            d[m] = c;
            m++;
            c = 0;
        }
        else c++;
    }
    d[m] = c;
    m++;
    int b[305];
    b[m] = 0;
    for(int i = m - 1; i >= 0; i--) b[i] = b[i + 1] + d[i];
    int p;
    cin >> p;
    dp[m - 1][0][d[m - 1]] = 1;
    for(int i = m - 1; i > 0; i--){
        for(int j = 0; j <= min(p, b[i]); j++){
            for(int k = d[i - 1]; k <= b[i - 1]; k++){
                for(int l = max(d[i], k - d[i - 1]); l <= b[i - 1]; l++){
                    if(k - d[i - 1] < l - d[i]) dp[i - 1][j][k] = (dp[i - 1][j][k] + dp[i][j][l]) % MOD;
                    else dp[i - 1][j + (k - d[i - 1]) - (l - d[i])][k] = (dp[i - 1][j + (k - d[i - 1]) - (l - d[i])][k] + dp[i][j][l]) % MOD;
                }
            }
        }
    }
    ll ans = 0;
    for(int j = 0; j <= min(p, 300); j++){
        for(int k = 0; k <= 300; k++) ans = (ans + dp[0][j][k]) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 31500
using System;
using System.Linq;

namespace ITP1_7
{
    class Program
    {
        static void Main()
        {
            while(true)
            {
                string s = Console.ReadLine().Trim('\n');
                if(s == "0 0") break;
                int[] i = s.Split(' ').Select(e => int.Parse(e)).ToArray();            
                int c = 0;
                for(int j = 1; j <= i[0]; j++)
                    for(int k = j + 1; k <= i[0]; k++)
                        for(int l = k + 1; l <= i[0]; l++)
                           if(j + k + l == i[1])
                               c++;              
                Console.WriteLine("{0}", c);
            }
        }
    }
}

Measured memory_bytes: 9688
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define has_str(s, c)	((s).find(c) != string::npos)
typedef long long ll;
const int N = 1e5+9;
int a[N][4], dp[N][4];
int n;
int solve (int i, int w) {
    if(i > n)
        return 0;
    int &ret = dp[i][w];
    if(~ret)
        return ret;
    for(int j = 1; j <= 3; ++j) {
        if(j != w)
            ret = max(ret, a[i][j]+solve(i+1,j));
    }
    return ret;
}
int main() {
#ifdef LOCAL
    //freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i][1] >> a[i][2] >> a[i][3];
    }
    clr(dp, -1);
    cout << solve(1,0); 
    return 0;
}

Measured memory_bytes: 16144
n = int(input())
a = []
b = []
count = 0
for i in range(n):
    aa,bb = map(int, input().split())
    a.append(aa)
    b.append(bb)
for i in range(n):
    if a[i] == b[i]:
        count += 1
    else:
        count = 0
    if count == 3:
        print("Yes")
        break
else:
    print("No")


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

using namespace std;


int main() {
    ios::sync_with_stdio(false);
    int r,g,b;
    cin >> r >> g >> b;
    int sum = 100*r + 10*g+b;
    if(sum %4 ==0){
        cout << "YES"<< endl;
    }else
        cout << "NO"<< endl;

}


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

bool binsearch(int p, int ary[], int first, int last){
    int middle = (last+first)/2;
    if(first >= last){
        return (p == ary[last]) ? true:false;
    }
    if(p < ary[middle]){
        return binsearch(p, ary, first, middle-1);
    }else if(p > ary[middle]){
        return binsearch(p, ary, middle+1, last);
    }else{
        return true;
    }
}

int main(){
    int n, t;
    int N[100000], T[50000];
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &N[i]);
    }
    cin >> t;
    for(int i=0; i<t; i++){
        cin >> T[i];
    }

    int cnt = 0;
    for(int i=0; i<t; i++){
        int left = 0, right = n-1;
        int p = T[i];
        while(left <= right){
            int middle = (right + left)/2;
            if(p == N[middle]){
                cnt++;
                break;
            }else if(p < N[middle]){
                right = middle - 1;
            }else{
                left = middle + 1;
            }
        }
        //if(binsearch(T[i], N, 0, n-1)) cnt++;
    }
    cout << cnt;
    cout << endl;
}


Measured memory_bytes: 3740
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
  while(!feof(stdin)) {
    int n, tmp, data[5];
    for(int i=0;i<5;i++) scanf("%d", &data[i]);
    if(feof(stdin)) break;
    for(int i=4;i>0;i--) {
      for(int j=0;j<i;j++) {
	if(data[j]<data[j+1]) {
	  tmp=data[j+1]; data[j+1]=data[j]; data[j]=tmp;
	}
      }
    }
      printf("%d %d %d %d %d\n",data[0], data[1], data[2], data[3], data[4]);
  }
}

Measured memory_bytes: 1192
using System;
class main{
static void Main(string[] args)
        {
            const int N = 50;
            string[] I=new string[N];
            string[] I1;
            int a, b,G,L;
            for (int i = 0; i < N; i++)
            {
                I[i] = Console.ReadLine();
            }
                for (int i=0;i<N;i++)
            {
                if (string.IsNullOrEmpty(I[i])) break;
                I1 = I[i].Split();
                a = int.Parse(I1[0]);
                b = int.Parse(I1[1]);
                G = Gojo(a, b);
                L = a / G * b;
                Console.WriteLine(G+" "+L);
            }
        }

        public static int Gojo(int a, int b)
        {
            if (a == 0 || b == 0) return 0;
            int c = a;
            do
            {
                c = a % b;
                a = b; b = c;
            } while (b != 0);
            return a;
        }
}

Measured memory_bytes: 9068
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long x = scanner.nextLong();
			long y = scanner.nextLong();
			System.out.println(getDigits(y / x));
		}
	}

	/**
	 * @param l
	 * @return lの2進数の桁数
	 */
	private static int getDigits(long l) {
		int result = 0;
		while (l > 0) {
			l >>= 1;
			result++;
		}
		return result;
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

long long n, num;

int main(){
    cin >> n;
    map <int, int> mp;

    for(int i = 0; i < n; i++){
        cin >> num;
        if(mp[num]){
            mp.erase(num);
        }
        else mp[num] = 1;
    }
    cout << mp.size() << endl;
}

Measured memory_bytes: 8140
//tiが[A, B)に含まれるかを調べるだけ
#include <iostream>
using namespace std;

int n, a, b;
int t;

int main() {
	cin >> n >> a >> b;
	
	int ans = 0;
	while (n--) {
		cin >> t;
		if (a <= t && t < b) continue;
		ans++;
	}
	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 REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;


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

    ll n;cin>>n;
    vll a(n);
    ll mx =0;
    REP(i,n) {
        cin>>a[i];
        mx = max(mx,a[i]);
        if (mx - a[i]>1){
            cout<<"No";
            return 0;
        }
        
    }
    cout<<"Yes";
    return 0;
    
}



Measured memory_bytes: 1024
'use strict'
const rl = require("readline");

let lines=[];
const reader = rl.createInterface({
	input: process.stdin,
	output: process.stdout
});

const g=(function*(){
    const gets = () => reader.once("line", s => g.next(s));
    let str = yield gets();
    lines.push(str);
    str = yield gets();
    lines.push(str);
    str = yield gets();
    lines.push(str);
    lines[0] -= lines[1];
    lines[0] %= lines[2];
    console.log(lines[0]);

    process.exit();
})();
g.next();

Measured memory_bytes: 7500