akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define MP make_pair

using namespace std;

typedef pair<int, int> P;

int base[5][20];
int rate[10];

int check(int num[5], int suit[5]){
	sort(num, num+5);
	bool fl = true;
	rep(i, 4) fl &= suit[i]==suit[4];
	bool st = true;
	rep(i, 4){
		if(num[i] == 1 && num[i+1] == 10) continue;
		st &= num[i+1]-num[i]==1;
	}

	int cards[5] = {};
	FOR(i, 1, 14){
		int cnt = 0;
		rep(j, 5) cnt += i==num[j];
		cards[cnt]++;
	}

	if(fl && st){
		if(num[0] == 1 && num[4] == 13) return 9;
		return 8;
	}
	if(cards[4]) return 7;
	if(cards[3] && cards[2]) return 6;
	if(fl) return 5;
	if(st) return 4;
	if(cards[3]) return 3;
	if(cards[2]>1) return 2;
	if(cards[2]) return 1;
	return 0;
}

int main(){
	map<char, int> dec;
	rep(i, 10){
		dec['0'+i] = i;
	}
	dec['T'] = 10;
	dec['J'] = 11;
	dec['Q'] = 12;
	dec['K'] = 13;
	dec['A'] = 1;

	dec['S'] = 0;
	dec['C'] = 1;
	dec['H'] = 2;
	dec['D'] = 3;

	int casenum = 0;
	int T;
	while(cin >> T){
		if(casenum++) cout << endl;
		rep(i, 4) FOR(j, 1, 14) cin >> base[i][j];
		FOR(i, 1, 10) cin >> rate[i];
		rep(i, T){
			int num[5], suit[5];
			int basepnt = 0;
			rep(j, 5){
				char a, b;
				cin >> a >> b;
				num[j] = dec[a];
				suit[j] = dec[b];
				basepnt += base[suit[j]][num[j]];
			}
			cout << basepnt*rate[check(num, suit)] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {

            char[] inputs = Console.ReadLine().ToArray();
            int hugCount = 0;
            int i = 0;
            int j = inputs.Length - 1;
            while(true)
            {
                if(inputs[i] != inputs[j])
                {
                    hugCount++;
                }
                if(j - i <= 1)
                {
                    break;
                }
                i++;
                j--;
            }

            Console.WriteLine(hugCount);
            Console.ReadKey();
        }

    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    long long cnt=0,ans=0;
    cin >> S;
    //bbw -> bwb -> wbb
    //あるwの左にあるbの数を数える。これを全てのw似たいし行う
    for(int i=0;i<S.size();i++){
        if(S.at(i)=='B') cnt++;
        if(S.at(i)=='W') ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <atcoder/math>
using namespace std;
using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N; cin >> N;
    if(N == 1){
        Out(1);
        return 0;
    }else if(N == 2){
        Out(3);
        return 0;
    }
    int ans = 2 * N;

    for(int k = 2; k * k <= 2 * N; k++) if((2 * N) % k == 0){
        int m0 = k, m1 = (2 * N) / k;
        auto res = crt(vec({0, m1 - 1}), vec({m0, m1}));
        if(res.fi > 0){
            chmin(ans, res.fi);
        }else{
            if(res.se > 0) chmin(ans, res.se);
        }
        res = crt(vec({m0 - 1, m1}), vec({m0, m1}));
        if(res.fi > 0){
            chmin(ans, res.fi);
        }else{
            if(res.se > 0) chmin(ans, res.se);
        }
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 3640
#define R(i,n)for(i=0;i<n;i++)
int N,i,j,k,f,n[9];char h;int main(){scanf("%d",&N);R(i,N){int c[3][12]={{0}};f=1;R(j,9){scanf("%d",&n[j]);}R(j,9){scanf(" %c",&h);c[h=='R'?0:h=='G'?1:2][n[j]-1]++;}R(j,3){R(k,12){f&=c[j][k]>=0;c[j][k]%=3;if(k<9){c[j][k+2]-=c[j][k];c[j][k+1]-=c[j][k];}}}printf("%d\n",f);}exit(0);}

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

int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] < 0) ++cnt;
		A[i] = abs(A[i]);
	}
	sort(A.begin(), A.end());
	ll res = accumulate(A.begin(), A.end(), 0LL);
	if (cnt & 1) res -= A[0] * 2;
	cout << res << endl;
	return 0;
}


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

#define I inline void 

using namespace std ; 

using ld = long double ; 
using ll = long long ; 

const int N = 1e6  + 7 , mod = 1e9 + 7 ; 

int n;   

ll masks[N][2] ; 

I maint(int ix , int v){
	if(v > masks[ix][0]){
		swap(masks[ix][1] , masks[ix][0]) ; 
		masks[ix][0] = v ; 
	}
	else if(v > masks[ix][1]){
		masks[ix][1] = v ; 
	}
}

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

	//freopen("in.in"  ,"r" , stdin) ; 

	cin >> n; 
	for(int i = 0 ;i <  (1 << n ) ; i++){
		cin >> masks[i][0] ; 
	}
	for(int j = 0 ;j < n ;j++){
		for(int i = 0 ;i < (1<< n ) ; i++){
			if(i&(1<<j)){
				int in = i ^ (1<<j) ; 
				maint(i , masks[in][0]) ; 
				maint(i , masks[in][1]) ; 
			}

		}
	}
	ll msk = 0 ; 
	for(int i =1 ; i< (1<<n) ;i++){
		msk = max(msk , masks[i][0] + masks[i][1]) ; 
		cout<< msk<<"\n" ; 
	}

	return 0 ; 
}

Measured memory_bytes: 7724
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vec A(N); cin >> A;
    vec cnt(N, 0);
    REP(i, N){
        A[i]--;
        cnt[A[i]]++;
    }

    int ans0 = 0;
    REP(i, N) ans0 += cnt[i] * (cnt[i] - 1) / 2;

    vec ans(N);
    REP(i, N){
        ans[i] = ans0;
        int t = cnt[A[i]];
        ans[i] -= t * (t - 1) / 2;
        t--;
        ans[i] += t * (t - 1) / 2;
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 8832
#include<stdio.h>
#define MAX 1400
struct rect {
  int height;
  int pos;
};
int buffer[MAX][MAX], table[MAX][MAX];
int large_rectangle(int w, int *t);
int main(void)
{
  int i, j, h, w, max = 0;
  scanf("%d%d", &h, &w);
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      scanf("%d", &buffer[i][j]);
    }
  }
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (buffer[i][j]) table[i][j] = 0;
      else table[i][j] = (i > 0) ? table[i-1][j] + 1 : 1;
    }
  }
  for (i = 0; i < h; i++) {
    int temp = large_rectangle(w, table[i]);
    if (max < temp) max = temp;
  }
  printf("%d\n", max);
}
int large_rectangle(int w, int *t)
{
  int i, sp = 0, max = 0;
  struct rect stack[MAX];
  t[w] = 0;
  for (i = 0; i <= w; i++) {
    struct rect r;
    r.height = t[i];
    r.pos = i;
    if (!sp || stack[sp-1].height < r.height) stack[sp++] = r;
    else if (stack[sp-1].height > r.height){
      int target = i;
        while (sp && stack[sp-1].height >= r.height) {
        struct rect pre = stack[--sp];
          int area = pre.height * (i - pre.pos);
          if (max < area) max = area;
          target = pre.pos;
        }
        r.pos = target;
        stack[sp++] = r;
    }
  }
  return max;
}


Measured memory_bytes: 17032
object Main {
  trait Monoid[A]{
    def op(a1: A, a2: A): A
    def zero: A
  }

  class SegmentTree[A](val numOfNode: Int, val M: Monoid[A]){

    sealed trait Tree{ val value: A }
    case object Leaf extends Tree{ val value: A = M.zero }
    case class Node(value: A, left: Tree, right: Tree) extends Tree
    object Node {
        def apply(value: A) = new Node(value, Leaf, Leaf)
        def apply(l: Tree, r: Tree) = new Node(M.op(l.value,r.value),l,r)
    }

    private[this] val empty: Node = Node(M.zero,Leaf,Leaf)
    private[this] var root: Tree = empty

    private def updateRec(id: Int, x:A, l: Int = 0, r: Int = numOfNode, t: Tree = root): Tree = {
        def branch(now: Node): Node = {
            val m = (l + r)>>1
            if(r-l<=1)Node(x)
            else if(id < m)Node(updateRec(id,x,l,m, now.left), now.right)
            else Node(now.left,updateRec(id,x,m,r,now.right))
        }
        t match {
            case now: Node => branch(now)
            case _ => branch(empty)
        }
    }

    def update(id: Int, x: A): Unit = {
        root = updateRec(id, x)
    }

    def query(a: Int, b: Int, l: Int = 0, r: Int = numOfNode, t: Tree = root): A = {
      val m = (l + r)/2
      t match {
        case now: Node =>
          if(b<=l || r<=a)M.zero
          else if(a<=l && r<=b)now.value
          else M.op(query(a,b,l,m,now.left),query(a,b,m,r,now.right))
        case _ => M.zero
      }
    }
  }

  def main(args: Array[String]): Unit = {
    val line = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val n = line(0)
    val q = line(1)
    val m = new Monoid[Int]{
        def op(a1: Int, a2: Int): Int = a1 min a2
        def zero: Int = Int.MaxValue
    }

    val segtree = new SegmentTree[Int](n,m)

    for(i <- 1 to q){
        val input = scala.io.StdIn.readLine.split(" ").map(_.toInt)
        val x = input(1)
        val y = input(2)
        if(input(0)==0)segtree.update(x,y)
        else println(segtree.query(x,y+1))
    }
  }
}

Measured memory_bytes: 194424
#include <stdio.h>

int main()
{
	int i, n, m, a, b, diff;
	long long sum = 0, add[100001][2] = {};
	scanf("%d %d", &n, &m);
	scanf("%d", &a);
	a--;
	for (i = 2; i <= n; i++) {
		scanf("%d", &b);
		b--;
		diff = (b - a + m) % m;
		sum += diff;
		if (diff >= 2) {
			a = (a + 2) % m;
			b = (b + 1) % m;
			add[a][0]++;
			add[a][1]++;
			add[b][0]--;
			add[b][1] -= diff;
			if (b < a) {
				add[0][0]++;
				add[0][1] += m - a + 1;
			}
			a = (b + m - 1) % m;
		} else a = b;
	}
	
	long long tmp[2] = {}, max = 0;
	for (i = 0; i < m; i++) {
		tmp[0] += add[i][0];
		tmp[1] += add[i][1];
		if (tmp[1] > max) max = tmp[1];
		tmp[1] += tmp[0];
	}
	printf("%lld\n", sum - max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3264
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=min(a)+min(b)
for _ in range(m):
  x,y,c=map(int,input().split())
  ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)


Measured memory_bytes: 18612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<ll>>;
Graph G;
struct UnionFind{
  vector<ll> par,siz;
  
  UnionFind(ll N):par(N+1),siz(N+1,1){
    for(int i=0; i<=N; i++)
      par[i]=i;
  }
  
  void mkpar(ll n, ll pre){
    for(auto next_n: G[n]){
      if(next_n==pre) continue;
      par[next_n]=n;
      mkpar(next_n, n);
    }
  }
  
  ll root(ll x){
    if(par[x]==x)
      return x;
    return par[x]=root(par[x]);
  }
  
  void unite(ll x, ll y){
    ll rx=root(x), ry=root(y);
    if(rx==ry)
      return;
    par[ry]=rx;
    siz[rx]+=siz[ry];    
  }
  
  bool issame(ll x, ll y){
    return root(x)==root(y);
  }
  
  ll size(ll x){
    return siz[root(x)];
  }
};

vector<ll> CN;
void dfs(ll n, ll pre, ll num){
  num=1;
  for(auto next_n: G[n]){
    if(next_n==pre) continue;
    if(num==CN[n]) num++;
    CN[next_n]=num;
//    cout<<"nexn:"<<next_n<<" num:"<<num<<endl;
    dfs(next_n, n, num++);
  }
}
//出力順番みだれる。どうしよう。
//DFSじゃなくてBFSかな
//ううむ、DFSで深さ覚えとくか
//親の色だけ拾えればいいの
//1-2 1-3 2-4 だったら、2=1 3=2 をナンバリング 4=2 2が1なので
//UnionFindみたいなやつで親子関係つける
//mapで色付け管理か
//出発地点渡して、DFSで親子関係つくっていくのか
//mkpar作れた･･･ひとしお
//入力値の右側だけみりゃいいのか
int main(){
  ll N; cin>>N;
  G.assign(N+1,vector<ll>());
  vector<ll> H(N,0);
  CN.assign(N+1,0);
  for(int i=0; i<N-1; i++){
    ll a,b; cin>>a>>b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    H[i]=b;
  }
  UnionFind tree(N);
  tree.mkpar(1,1);
  dfs(1,1,1);
  ll mm=0;
  for(int i=0; i<N-1; i++) mm=max(mm,CN[H[i]]);
  cout<<mm<<endl;
  for(int i=0; i<N-1; i++) cout<<CN[H[i]]<<endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
ll mod=1e9+7,dp[103][100010];
int n,K,a[103];
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>K;
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<=a[0]; i++)
        dp[0][i]=1;
    for(int i=1; i<n; i++)
    {
        for(int j=0; j<=K; j++)
        {
            dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
            if(j-a[i]-1>=0)
                dp[i][j]-=dp[i-1][j-a[i]-1];
            dp[i][j]%=mod;
        }
        for(int j=1; j<=K; j++)
            dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
    }
    cout<<(dp[n-1][K]+mod)%mod;
    return 0;
}


Measured memory_bytes: 80128
a,b=map(int,input().split())
ans=0
while a<=b and a%2==1:
  ans^=a
  a+=1
while b>=a and b%2==0:
  ans^=b
  b-=1
if a<=b:
  dist=(b-a+1)/2
  if dist % 2 ==1:
    ans^=1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(void){
    int n; cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    int idx = 1,ans=0;
    for(int i=0;i<n;i++){
        if( a[i]==idx){
            idx++;
        }else{
            ans++;
        }
    }
    if(ans==n){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans = 700;
    for(int i = 0; i < 3; i++)
    {
        if (s[i] == 'o') {
            ans += 100;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
using ll = long long;

string s;
int x, y;
int l;

int dp(vector<int> v, int t) {
    int len = l + 2;
    if (t > len)
        return false;
    int dp[len];
    for (int i = 0; i < len; ++i) dp[i] = 0;
    dp[0] = 1;
    for (int vi : v) {
        for (int i = 0; i < len; ++i) {
            if ((i - vi >= 0 && dp[i - vi] == 1) || (i + vi < len && dp[i + vi] == 1)) {
                dp[i] = 2;
            }
        }
        for (int i = 0; i < len; ++i) {
            if (dp[i] == 1) dp[i] = 0;
            if (dp[i] == 2) dp[i] = 1;
        }
    }
    return dp[t] == 1;
}

int main(){
    cin >> s >> x >> y;

    l = s.size();

    int i;
    for (i = 0; i < s.size(); ++i) {
        if (s[i] == 'F')
            x--;
        else
            break;
    }

    x = abs(x);
    y = abs(y);

    vector<int> dx;
    vector<int> dy;

    dx.push_back(0);

    bool dirx = true;

    for (; i < s.size(); ++i) {
        if (s[i] == 'T') {
            dirx = !dirx;
            if (dirx) dx.push_back(0); else dy.push_back(0);
        } else {
            if (dirx)
                dx[dx.size() - 1]++;
            else
                dy[dy.size() - 1]++;
        }
    }

    //cout << endl;
    //for (int dxi : dx) {
    //    cout << dxi << " ";
    //}
    //cout << endl;

    cout << (dp(dx, x) && dp(dy, y) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = 0;
		int max = x;
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		for(char c : s) {
			if(c == 'I') x++;
			else x--;
			if(x > max) max = x;
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 20684
class BIT:
    def __init__(self, n):
        self.n = n
        self.tree = [0]*(n+1)

    def update(self, i, v):
        while i <= self.n:
            self.tree[i] += v
            i += i & (-i)

    def query(self, i):
        v = 0
        while i:
            v += self.tree[i]
            i -= i & (-i)
        return v


N, Q = map(int, input().split())
*c, = map(int, input().split())

q = [[] for _ in range(N+1)]
for i in range(Q):
    x, y = map(int, input().split())
    q[y-1].append([i, x-1])

bit = BIT(N)
finds = [-1]*(N+1)
ans = [0]*Q
for i in range(N):
    if finds[c[i]] != -1:
        bit.update(finds[c[i]]+1, -1)

    finds[c[i]] = i
    bit.update(finds[c[i]]+1, 1)

    for j, x in q[i]:
        ans[j] = bit.query(i+1) - bit.query(x)

for a in ans:
    print(a)


Measured memory_bytes: 223600
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++ )
#define INF (1 << 30)
typedef pair<int,int> P;
int n, abcd[4];
int mas[101][101];

int solve(int size){
  int x[4],y[4];
  for(int i = 0, j = 0, cnt = 0, all = 0 ; cnt < 4 ; all++, i++ ){
    if(i == size) i = 0, j++;
    rep(l,4) if(all == abcd[l]) cnt++, x[l] = i, y[l] = j;
  }
  return abs(x[0]-x[1]) + abs(y[0]-y[1]) + abs(x[2]-x[3]) + abs(y[2]-y[3]);
}
int main(){
  cin >> n;
  rep(i,4){
    cin >> abcd[i];
    abcd[i]--;
  }
  //全部のサイズのグリッド試せばいいじゃん(小並感)  オーダー気にしない
  int ret = INF;
  for(int i = 1 ; i <= n ; i++ ) ret = min(ret,solve(i));
  cout << ret << endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    ans += min(k, a);
    k -= min(k, a);
    if(k > 0){
        k -= min(k, b);
    }
    if(k > 0){
        ans -= min(k, c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<queue>
using namespace std;
const int N=2e5+5,LG=20;
int n,i,j,k,a[N],lg[N],mn[N][LG];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
void write(int x){if (x>9) write(x/10);putchar(x%10+48);}
int Min(int x,int y){return a[x]<a[y]?x:y;}
int ask(int l,int r){
	int v=lg[(r-l)/2+1];
	return Min(mn[l][v],mn[r-(1<<v)*2+2][v]);
}
struct heap{int l,r,x;};
bool operator < (heap A,heap B){return a[A.x]>a[B.x];}
priority_queue<heap> q;
void ins(int l,int r){
	if (l>r) return;
	q.push((heap){l,r,ask(l,r-1)});
}
int main(){
	for (n=read(),lg[0]=-1,i=1;i<=n;i++)
		a[i]=read(),mn[i][0]=i,lg[i]=lg[i>>1]+1;
	for (j=1,k=2;2*k-1<=n;j++,k<<=1)
		for (i=1;i+2*k-2<=n;i++)
			mn[i][j]=Min(mn[i][j-1],mn[i+k][j-1]);
	ins(1,n);
	while (!q.empty()){
		int l=q.top().l,r=q.top().r;
		int x=q.top().x,y=ask(x+1,r);q.pop();
		write(a[x]);putchar(' ');write(a[y]);putchar(' ');
		ins(l,x-1);ins(x+1,y-1);ins(y+1,r);
	}
}

Measured memory_bytes: 19320
#include<bits/stdc++.h>
using namespace std;
#define MAXN 201
#define INF 40000010

int N, M, R;
int r, a, b, c;

int lengths[MAXN][MAXN];
int fw[MAXN][MAXN];
bool visiting[MAXN];

int towns_to_visit[10];
vector<int> visits;
int ans = INF;

void floyd()
{
	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			fw[i][j] = lengths[i][j];
		}
	}
	
	for (int k = 1; k <= N; k++)
	{
		for(int i = 1; i <= N; i++)
		{
			for(int j = 1; j <= N; j++)
			{
				if(fw[i][k] + fw[k][j] < fw[i][j])
					fw[i][j] = fw[i][k] + fw[k][j];
			}
		}
	}
	
}

int check()
{
	int ret = 0, node1, node2;
	for (int i = 0; i < visits.size() - 1; i++)
	{
		node1 = visits[i];
		node2 = visits[i + 1];
		ret += fw[node1][node2];
	}
	return ret;
}

void search()
{
	if (visits.size() == R)
	{
		int checked = check();
		if (checked < ans)
		{
			ans = checked;
		}
	}
	else{
		for (int i = 0; i < R; i++)
		{
			int j = towns_to_visit[i];
			if (!visiting[j])
			{
				visits.push_back(j);
				visiting[j] = true;
				search();
				visits.pop_back();
				visiting[j] = false;
			}
		}
	}
}

int main()
{
	cin >> N >> M >> R;
	
	for (int i = 0; i < R; i++)
	{
		cin >> r;
		towns_to_visit[i] = r;
	}
	
	for (int i = 0; i < MAXN; i++)
	{
		for (int j = 0; j < MAXN; j++)
		{
			lengths[i][j] = INF;
		}
	}
	
	for(int i = 0; i < M; i++)
	{
		cin >> a >> b >> c;
		if (c < lengths[a][b])
		{
			lengths[a][b] = c;
			lengths[b][a] = c;
		}
	}
	floyd();
	search();

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

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> v(n, 0);
	REP(i, m)
	{
		int a, b;
		cin >> a >> b;
		v[a - 1]++;
		v[b - 1]++;
	}

	REPIT(v)
	{
		print(*it);
	}

	//map<int, int> mp;
	//REP(i, m)
	//{
	//	int a, b;
	//	cin >> a >> b;
	//	mp[a]++;
	//	mp[b]++;
	//}

	//REPIT(mp)
	//{
	//	print((*it).second);
	//}
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)

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


int main(){
    int n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    if(n==1){
        if(a[0]==0)cout<<1;else cout<<0;
        return 0;
    }
    ll b[n];b[0]=a[0];
    rep(i,1,n-1)b[i]=b[i-1]+a[i];
    sort(b,b+n);
    int pos=1;
    ll ans=upper_bound(b,b+n,0)-lower_bound(b,b+n,0);
    ll count=1;
    while(pos<=n-1){
        if(b[pos]==b[pos-1])count++;
        else{
            ans+=count*(count-1)/2;
            count=1;
        }
        pos++;
    }
    ans+=count*(count-1)/2;
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int n,a;
int num[51] = {};
long long memo[51][2501][51] = {};

long long dp(int now, int sum, int used){
	if(now == n){
		if(sum == a * used && used != 0){
			return 1;
		}else{
			return 0;
		}
	}
	if(memo[now][sum][used] != INFLL) return memo[now][sum][used];

	long long x,y;
	x = dp(now + 1, sum + num[now], used + 1);
	y = dp(now + 1, sum, used);

	return memo[now][sum][used] = x + y;
}

int main() {
	cin >> n >> a;
	for(int i = 0;i < n;i++){
		cin >> num[i];
	}

	for(int i = 0;i < 51;i++){
		for(int j = 0;j < 2501;j++){
			for(int k = 0;k < 51;k++){
				memo[i][j][k] = INFLL;
			}
		}
	}
	cout << dp(0,0,0) << endl;
	return 0;
}

Measured memory_bytes: 51072
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(){
    long long A,V;
    long long B, W;
    long long T;
    long long result;

    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    result = abs(A-B) - (T * (V - W));

    if(result <= 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

vector<P> G, _G;
bool used[100];
int N, M;

void dfs(int v){
    used[v] = true;

    for(const auto& p : _G){
        int a, b;
        tie(a, b) = p;

        if(a == v && !used[b]){
            dfs(b);
        }
        if(b == v && !used[a]){
            dfs(a);
        }
    }
}

bool can(){
    memset(used, 0, sizeof(used));

    dfs(1);

    for(int i=1;i<=N;++i){
        if(!used[i]){return false;}
    }

    return true;
}

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

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int a, b;
        std::cin >> a >> b;

        G.emplace_back(a, b);
    }

    int res = 0;
    for(int i=0;i<M;++i){
        _G.clear();

        for(int j=0;j<M;++j){
            if(j == i){continue;}

            _G.emplace_back(G[j]);
        }

        if(!can()){++res;}
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm_base(x, y):
	return (x * y) // gcd(x, y)

def lcm_list(numbers):
    ans = lcm_base(numbers[0], numbers[1])
    for x in numbers:
        ans = lcm_base(ans, x)
    return ans

n = int(input())
t = [int(input()) for i in range(n)]

result = lcm_list(t) if len(t) != 1 else t[0]
print(result)


Measured memory_bytes: 3060
from itertools import product
n, m = map(int,input().split())
li = []
for i in range(m):
    li_buf = list(map(int,input().split()))
    li.append(li_buf)
# print(li)
p = list(map(int,input().split()))
# print(p)

li_com = []
li_flag = [[True, False] for i in range(10)]
for a, b, c, d, e, f, g, h, i, j in product(li_flag[0], li_flag[1], li_flag[2], li_flag[3], li_flag[4], li_flag[5], li_flag[6], li_flag[7], li_flag[8], li_flag[9]):
    li_com.append([a, b, c, d, e, f, g, h, i, j])

for i in range(m):
    buf = []
    for j in range(len(li[i])):
        if j == 0:
            continue
        buf.append(li[i][j])
    li_com_2 = []
    for k in range(len(li_com)):
        buf_2 = []
        for l in range(len(buf)):
            buf_2.append(li_com[k][buf[l]-1])
        if buf_2.count(True) % 2 == p[i]:
            li_com_2.append(li_com[k])
    li_com = li_com_2
print(int(len(li_com)/ 2 ** (10 - n)))

Measured memory_bytes: 3188
#include<cstdio>
#include<iostream>
using namespace std;
string str;
int main()
{

	cin>>str;

	int curr = 0;
	int ans = 0;
	int len = str.length();
	for (int i = 0 ; i < len; i++)
	{
		if (str[i] != 'R') curr = 0;
		else
		if (str[i] == 'R')
		{
			if (i == 0) curr = 1;
			else		curr++;
		}

		ans = max(ans,curr);
	}
	cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,k;
  cin>>n;
  vector<long> vec(n+1);
  for(int i=0; i<n+1; i++){
    vec.at(i)=0;
  }
  for(int i=1; i<n; i++){
    cin>>k;
    vec.at(k)=vec.at(k)+1;
  }
  for(int i=1; i<n+1; i++){
    cout<<vec.at(i)<<endl;
  }
}
  

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

int main()
{
  list<int> ltiNumber;
  list<int>::iterator itlti;
  list<int>::iterator itltEND = ltiNumber.end();
  char acCommand[80];
  int iMaxCommand, iNumber;

  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin >> iMaxCommand;
  for (int i = 0; i < iMaxCommand; i++)
  {
    cin >> acCommand;
    if (acCommand[0] == 'i')
    {
      cin >> iNumber;
      ltiNumber.push_front(iNumber);
    }
    else if (acCommand[6] == 'F')
      ltiNumber.pop_front();
    else if (acCommand[6] == 'L')
      ltiNumber.pop_back();
    else if (acCommand[0] == 'd')
    {
      cin >> iNumber;
      for (itlti = ltiNumber.begin(); itlti != itltEND; ++itlti)
        if (*itlti == iNumber)
        {
          ltiNumber.erase(itlti);
          break;
        }
    }
  }

  int i = 0;
  for (itlti = ltiNumber.begin(); itlti != itltEND; ++itlti)
  {
    if (i++) cout << " ";
    cout << *itlti;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 32460
N,L=map(int,input().split())
if L >= 0:
  print(int((N-1)/2*(L + L + N)))
else:
  if L + N - 1 >= 0: 
    print(int(N / 2 * (L + L + N - 1)))
  else:
    print(int((N - 1)/ 2 * (L + L + N - 2)))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int N =1500;
int G[N][N];
int l[N];
int r[N];		
int H[N+5];
int main(){
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++)
			cin>>G[i][j];
	}
	int max1=0;
	for(int i=1;i<=h;i++){
		stack<int> S;
		for(int j=1;j<=w;j++){
			if(G[i][j])	H[j]=0;
			else H[j]++;
		}
		for(int j=1;j<=w;j++){
			if(S.empty()||H[S.top()]<=H[j]){
				if(S.empty()){
					S.push(j);
					l[j]=0; 
				} 
				else{
					l[j]=S.top();
					S.push(j);
				}
			}
			else{
				while(H[S.top()]>H[j]){
					r[S.top()]=j;
					S.pop();
					if(S.empty()) break;
				}
				if(S.empty()){
					S.push(j);
					l[j]=0; 
				} 
				else{
					l[j]=S.top();
					S.push(j);
				}
			}
		}
		while(!S.empty()){
			r[S.top()]=w+1;
			S.pop();
		}
		for(int j=1;j<=w;j++){
			max1=max(max1,(r[j]-l[j]-1)*H[j]);
		}
	}
	cout<<max1<<endl;
}


Measured memory_bytes: 11296
#include<bits/stdc++.h>
using namespace std;
 int main()
{
     long long int n,a,b;
     cin>>n;
     vector<pair<long long int,long long int> >v;
     for (long long int i=0;i<n;i++){
        cin>>a>>b;
        v.push_back(make_pair(b,a));
     }
     sort(v.begin(),v.end());
     int flag=0,s=0;
     for(long long int i=0;i<n;i++){
        s+=v[i].second;
        if(s>v[i].first){
            flag++;
        }
     }
     if(flag==0){
        cout<<"Yes"<<endl;
     }
     else{
        cout<<"No"<<endl;
     }
}


Measured memory_bytes: 6512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<vector<int>> GameId(n, vector<int>(n));
    int V = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < i; ++j){
            GameId[i][j] = V++;
            GameId[j][i] = GameId[i][j];
        }
    }
    vector<vector<int>> a(n, vector<int>(n - 1));
    vector<vector<int>> graph(V);
    for(int i = 0; i < n; ++i){
        vector<int> match;
        for(int j = 0; j < n - 1; ++j){
            cin >> a[i][j];
            --a[i][j];
            match.emplace_back(GameId[i][a[i][j]]);
        }
        for(int j = n - 2; j - 1 >= 0; --j){
            graph[match[j]].emplace_back(match[j - 1]);
        }
    }
    vector<int> dp(V, -1);
    vector<bool> visited(V, false);
    vector<bool> calculated(V, false);
    auto memo_rec = [&](auto&& self, int from) -> int {
        if(visited[from]){
            if(!calculated[from])   return -1;
            return dp[from];
        }
        visited[from] = true;
        dp[from] = 1;
        for(int to : graph[from]){
            int res = self(self, to);
            if(res == -1)   return -1;
            chmax(dp[from], res + 1);
        }
        calculated[from] = true;
        return dp[from];
    };
    int ans = 0;
    for(int i = 0; i < V; ++i){
        int res = memo_rec(memo_rec, i);
        if(res == -1){
            cout << -1 << endl;
            return 0;
        }
        chmax(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 37632
X,Y=gets.chomp.split(" ").map(&:to_i)
x=2*X-Y
y=2*Y-X
if x<0 || y<0 || x%3!=0 || y%3!=0
    puts 0
    exit
end
x/=3
y/=3
MOD=10**9+7
def ppow(x, n)
    return 1 if n == 0
    return ppow(x**2 % MOD, n / 2) if (n % 2) == 0
    return ppow(x**2 % MOD, n / 2) * x if (n % 2) == 1
end

def kaijou(a, b)
    (b..a).inject(1) {|i,j| i*j % MOD }
end

puts (kaijou(y+x,y+1) * ppow(kaijou(x,1),MOD-2)) % MOD


Measured memory_bytes: 14380
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  double sum = 0;
  double ave;
  double var = 0;
  vector<int> a(100);
  for(i=0;i<n;i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  ave = round (sum / n);
  for(i=0;i<n;i++){
    var += pow((a.at(i) - ave) , 2);
  }
  cout << var << "\n";
}

Measured memory_bytes: 512
io = STDIN
n=io.gets.to_i
$len={}
$ary=Array.new(n+1){[]}
(n-1).times do
  a,b,c=io.gets.split.map(&:to_i)
  $ary[a]<<[b,c]
  $ary[b]<<[a,c]
end
q,k=io.gets.split.map(&:to_i)

$dis={}
$dis[k]=0
def bfs(to)
  queue=[[to,-1]]  #to,from
  while(nn=queue.shift)
    to,from=nn
    $ary[to].each do |child,len|
      next if from == child
      $dis[child]=$dis[to]+len
      queue.unshift([child,to])
    end
  end
end
bfs(k)

q.times do
  x,y=io.gets.split.map(&:to_i)
  puts $dis[x]+$dis[y]
end


Measured memory_bytes: 35580
//i hate _____
#include<bits/stdc++.h>

#define ll long long int 
#define ld long double 
#define pb push_back
#define mk make_pair
#define ii pair<int , int>

using namespace std;
double pi = 2 * acos(0.0) ;

template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << " " << x;
        return os << '}'; 
}

void solve(){
    
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

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

    string s; cin>>s;
    int n = s.size();
    cout << s;
    if (s[n-1]=='s') cout << "es\n";
    else cout << "s\n";
    
    return 0;
}
/*
    problems are the sign of life
*/


Measured memory_bytes: 3656
#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 FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int n;
   cin >> n;
   vector<int> v(n);
   vector<int> c(n);
   rep(i,n)cin >> v[i];
   rep(i,n)cin >> c[i];
   vector<int> a(n);
   rep(i,n){
      a[i] = v[i] - c[i];
   }
   sort(All(a),greater<int>());
   int ans = 0;
   for(int i=0;i<n;i++){
      int tmp =a[i];
      if(tmp<=0){
         break;
      }else{
         ans+= tmp;
      }
   }
   cout << ans;
   return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

int main()
{
    int r;
    cin >> r;
    cout << 3 * r * r << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define min(a,b) a<b?a:b
using namespace std;
int main()
{
	int N,s=0;
	cin >>N;
	int a[N]={0},b[N]={0};
	for(int i=0;i<N-1;i++)
		cin >> b[i];
	b[N-1]=b[N-2];
	a[0]=b[0];
	s+=a[0];
	for(int i=1;i<N;i++)
	{
		a[i]=min(b[i-1],b[i]);
		s+=a[i];
	}
	cout << s << endl;
}

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

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

using namespace std;
using ll = int64_t;

constexpr int INF = (1 << 30);
constexpr ll INFL = (1LL << 62);
constexpr ll MOD = 1000000007;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};

int main() {
    cout << std::fixed << std::setprecision(10);
    int n;
    cin >> n;
    vector<int> ans(n+1, 0);
    rep(x, 300){
        if(x == 0) continue;
        rep(y, 300){
            if (y == 0) continue;
            rep(z, 300){
                if (z == 0) continue;
                int t = x*x + y*y + z*z + x*y + y*z + z*x;
                if(t <= n){
                    ans[t]++;
                }
            }
        }
    }
    rep(i, n){
        printf("%d\n", ans[i + 1]);
    }
    return 0;
}


Measured memory_bytes: 3660
N, Y = map(int, input().split())
for i in range(N + 1):
  for j in range(N - i + 1):
    if 10000*i + 5000*j + 1000*(N - i - j) == Y:
      print(i, j, N - i - j)
      exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K,X,Y;
int T;
vector<int> A,B;
//=============================
void input()
{
    cin>>K>>T;
    A.resize(T);
    rep(i,0,T-1){
        cin>>A[i];
    }
}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    priority_queue<int> q;
    for(auto x : A){
        q.push(x);
    }
    int m = q.top();

    cout<< max(m- (K-m+1) , 0LL)<<endl;

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
lst = []
for i in range(0, 5):
	lst.append(int(raw_input()))
k = int(raw_input())
ans = 'Yay!'
for i in range(0, 5):
	for j in range(i+1, 5):
		if lst[j]-lst[i] > k:
			ans = ':('
print ans

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,X,Y;
  cin >> N>> M>>X>>Y;
  int a=-100;
  int b=100;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    a=max(a,x);
  }
  for (int i = 0; i < M; i++) {
    int y;
    cin >> y;
    b=min(b,y);
  }
  if(a<Y&& b>X&&a<b){
    cout << "No War";
  }
  else{
    cout << "War";
  }
}
  



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

using namespace std;

#define ll long long

int main(){
	int n;
	cin >> n;
	vector<ll> v(n+1);
	v[0] = 0;
	for(int i = 1; i <= n; ++i){
		ll b;
		cin >> b;
		v[i] = v[i-1] + b;
	}
	ll sum = 0;
	ll inc1 = 0;
	bool neg = true;
	for(int i = 1; i <= n; ++i){
		if((neg && v[i] + sum >= 0)){
			inc1 += abs(v[i] + sum) + 1;
			sum -= abs(v[i] + sum) + 1;
		}
		else if(!neg && v[i] + sum <= 0){
			inc1 += abs(v[i] + sum) + 1;
			sum += abs(v[i] + sum) +1;
		}
		neg = !neg;
	}
	sum = 0;
	ll inc2 = 0;
	neg = false;
	for(int i = 1; i <= n; ++i){
		if((neg && v[i] + sum >= 0)){
			inc2 += abs(v[i] + sum) + 1;
			sum -= abs(v[i] + sum) + 1;
		}
		else if(!neg && v[i] + sum <= 0){
			inc2 += abs(v[i] + sum) + 1;
			sum += abs(v[i] + sum) +1;
		}
		neg = !neg;
	}

	cout << min(inc1, inc2);

	
	return 0;
}



Measured memory_bytes: 3960
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = [LIST() for _ in range(3)]
N = INT()
b = [INT() for _ in range(N)]

check = [[0]*3 for _ in range(3)]
for n in b:
	for i in range(3):
		for j in range(3):
			if A[i][j] == n:
				check[i][j] = 1

for i in range(3):
	if sum(check[i]) == 3:
		print("Yes")
		exit()
for i in range(3):
	if check[0][i] and check[1][i] and check[2][i]:
		print("Yes")
		exit()

if check[0][0] and check[1][1] and check[2][2]:
	print("Yes")
	exit()

if check[0][2] and check[1][1] and check[2][0]:
	print("Yes")
	exit()

print("No")


Measured memory_bytes: 5844
function main(arg) {
    let tmp = arg.trim().split("\n")[0]
    let N = Number(tmp.split(" ")[0])
    let K = Number(tmp.split(" ")[1])
    tmp = arg.trim().split("\n")
    tmp.shift()
    let data = []
    let snk = new Array(N).fill(0)
    for (let i = 0; i < tmp.length;i++) {
        if (i % 2 === 0) {
            continue
        }
        let row = tmp[i].split(" ").map(Number)
        for (let j = 0; j < row.length; j++) {
            let idx = row[j] - 1
            snk[idx] += 1
        }
    }
    let counter = 0
    // console.log(JSON.stringify(snk))
    for (let i = 0; i < snk.length; i++) {
        if (snk[i] === 0) {
            counter++
        }
    }
    console.log(counter)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29788