akhauriyash/Code-Regression huggingface dataset:
class UnionFind :
    def __init__(self, size) :
        self.rootList = list(range(size))
        self.height = [0] * size
        self.size = [1] * size

    def root(self, index) :
        if self.rootList[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.rootList[index])  # 葉の場合親の根を取得
        self.rootList[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :
            return

        if self.height[root1] < self.height[root2] :
            self.rootList[root1] = root2
            self.size[root2] += self.size[root1]
        else :
            self.rootList[root2] = root1
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

N , M = map(int,input().split())

tree = UnionFind(N)

edge = [0] * M

for i in range(M) :
    s , t = map(int,input().split())
    edge.append((s-1,t-1))

ans = [0] * (M + 1)
ans[-1] = (N * (N - 1)) // 2

for i in range(2,M+1) :
    s , t = edge[-i+1]

    if tree.root(s) == tree.root(t) :
        ans[-i] = ans[-i+1]
    else :
        count1 = tree.sizeOfSameRoot(s)
        count2 = tree.sizeOfSameRoot(t)
        ans[-i] = ans[-i+1] - count1 * count2

    tree.union(s,t)

ans.pop(0)

for a in ans :
    print(a)

Measured memory_bytes: 24864
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll a,v,b,w,t;
  cin >> a >> v >> b >> w >> t; 
  v *= t; v += a;
  w *= t; w += b;
  if(a > b){
    if(v - 2 * (v - a) <= w - 2 * (w - b)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }else if(a == b) cout << "YES" << endl;
  else{
    if(v >= w) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	int N;
	cin >> N;

	for (int v, i = 0; i < N; ++i) {
		cin >> v;
		if (~v & 1 && (v % 3 && v % 5)) return cout << "DENIED", 0;
	}

	cout << "APPROVED";

	return 0;
}

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

using namespace std;

bool cmp(long long int a, long long int b){
    return a>b;
}

long long int tab[200007];

int main()
{
    long long int n, i, w;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> tab[i];
    }
    sort(tab, tab+n, cmp);
    if(n==2){
        cout << tab[0] << '\n';
        return 0;
    }
    if(n==3){
        cout << tab[0]+tab[1] << '\n';
        return 0;
    }
    if(n==4){
        cout << tab[0]+2*tab[1] << '\n';
        return 0;
    }
    if(n==5){
        cout << tab[0]+2*tab[1]+tab[2] << '\n';
        return 0;
    }
    if(n==6){
        cout << tab[0]+2*tab[1]+2*tab[2] << '\n';
        return 0;
    }
    w=tab[0]+2*tab[1]+2*tab[2];
    for(i=6; i<n; i++){
        w+=tab[i/2];
    }
    cout << w << '\n';
    return 0;
}


Measured memory_bytes: 5204
#include "bits/stdc++.h"
#define ll long long
using namespace std;

string rot(string s) {
  ll e=s.size();
  string f=s;
  for(ll i=0;i<e;i++) {
    f.at(i)=s.at((i+e-1)%e);
  }
  return f;
}

int main() {
  string s,t;
  cin>>s>>t;
  int ans=0;
  for(int i=0;i<100;i++) {
    if(rot(s)==t) {
      cout<<"Yes"<<endl;
      ans++;
      break;
    }
    s=rot(s);
  }
  if(ans==0) {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fori(x,a,b) for (int x=a;x<=b;x++)
#define int long long
using namespace std;
int n,a[3010];
int f[3010][3010];
 main()
{
   cin>>n;
   fori(i,1,n) cin>>a[i];
   for (int l=n;l>=1;l--)
   {
       fori(r,l,n)
       {
           if (l==r) f[l][r] = a[l];
           else
           {
               f[l][r] = max(a[l] - f[l+1][r],a[r] - f[l][r-1]);
           }
       }
   }
   cout<<f[1][n];
}


Measured memory_bytes: 49720
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   //dpdpdpdpdpdpdpdpdpdpdp
           //10^7 ok
           ll n,a;
           cin>>n>>a;
           vll x(n);
           rep(i,0,n)cin>>x[i];
           ll ans=0;
           rep(num,1,n+1){
            ll sum=a*num;
             ll dp[n+1][2525][n+1];//dp[i][j][k]=i枚目までで和がjになる通り数 (k枚選ぶ）
             rep(i,0,n+1){
              rep(j,0,2525){
                rep(k,0,n+1){
               dp[i][j][k]=0;
                if(i==0&&j==0&&k==0)dp[i][j][k]=1;
               //選ぶ
               if(i-1>=0&&j-x[i-1]>=0&&k-1>=0)dp[i][j][k]+=dp[i-1][j-x[i-1]][k-1];
               //選ばない
               if(i-1>=0)dp[i][j][k]+=dp[i-1][j][k];
               }
              }
             }
             ans+=dp[n][sum][num];
           }
          cout<<ans<<endl;
}

Measured memory_bytes: 54904
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	string s;
	cin>>s;
	s.insert(4," ");
	cout<<s<<endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
def check(x,y):
    ans = True
    for i in range(m):
        for j in range(m):
            if b[i][j] != a[i+x][j+y]:
                ans = False
    return ans

for i in range(n-m+1):
  for j in range(n-m+1):
      if check(i,j):
          print("Yes")
          exit()
print("No")



Measured memory_bytes: 3316
void main()
{
    writeln(180 * (readln.chomp.to!int - 2));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
h, w = map(int,input().split())
hako = list()

for i in range(h):
    ww = ["." for _ in range(w)]
    st = list(str(input()))
    if st != ww:
        hako.append(list(st))


hako2 = []
for i in range(w):
    one = []
    for onelist in hako:
        one.append(onelist[i])
    hako2.append(one)
    
hako3 = []
for _ in hako2:
    check = ["." for pp in range(len(_))]
    if _ != check:
        hako3.append(_)
        
hako4 = []

for i in range(len(hako3[0])):
    one = []
    for onelist in hako3:
        one.append(onelist[i])
    hako4.append(one)
    
for _ in hako4:
    strs = ""
    for char in _:
        strs += char
    print(strs)
    
    

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

int main() {
  int a,b;
  cin >> a >> b;
  if (a<b) cout << "a < b" << endl;
  if (a==b) cout << "a == b" << endl;
  if (a>b) cout << "a > b" << endl;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int trainingTime = sc.nextInt();
		long power = 1;
		long amari = 0;
		for (int i = 0; i < trainingTime; i++) {
			power *= i + 1;
			power %= 1000000007;
		}
		amari = power % 1000000007;
		System.out.println(amari);
	}

}


Measured memory_bytes: 20820
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace AGC029
    {
        class Program
        {
            static void Main(string[] args)
            {
                string S = Console.ReadLine();
                long ans = 0;
                long count = 0;
                for (int i = 0; i < S.Length; i++)
                {
                    if (S[i] == 'W') { ans += i - count; count++; }
                }
                Console.WriteLine(ans);
            }
        }
    }

Measured memory_bytes: 11616
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c , x, ans=0;
    cin >> a >> b >> c >> x;
    for(int i=0; i<=a; i++){
	for(int j=0; j<=b; j++){
	    for(int k=0; k<=c; k++){
		if(500*i+100*j+50*k==x)
		    ans++;
	    }	
	}	
    }

    cout << ans << endl;    
}



Measured memory_bytes: 256
N = int(input())
S = input()

r= S.count("R")
g = S.count("G")
b= S.count("B")
ans=r*g*b

for j in range(N):
  for k in range(N):
    i=2*j-k
    if 0<=i<j<k<=N-1 and S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
      ans-=1
print(ans)

Measured memory_bytes: 67884
import java.util.Scanner;

/**
 * シカのAtCoDeerくんは二つの正整数a,bを見つけました。
 * aとbの積が偶数か奇数か判定してください。
 *
 * 1≤a,b≤10000 a,bは整数
 *
 * #input
 * 入力は以下の形式で標準入力から与えられる。
 * a b
 *
 * #output
 * 積が奇数なら Odd と、 偶数なら Even と出力せよ。
 */
public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();

        String result = (((a * b) % 2) == 0) ? "Even" : "Odd";
        System.out.print(result);
    }
}

Measured memory_bytes: 23764
string solve(int x){
	return (x<1200)? "ABC": "ARC";
}
void main(){
	int x = inelm();
	solve(x).writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2732
#include<iostream>

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


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

vector<vector<pair<int, int>>> graph;
vector<int> dist;
vector<tuple<int, int, int>> query;
const int INF = 2e9;

void dfs(int cv, int p, int cd){
    dist[cv] = cd;

    for(int i = 0; i < graph[cv].size(); i++){
        int nv, d;
        tie(nv, d) = graph[cv][i];
        if(nv == p) continue;
        if(dist[nv]!= -INF) continue;
        dfs(nv, cv, cd+d);
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;

    graph.resize(N);
    dist.assign(N, -INF);
    query.resize(M);

    for(int i = 0; i < M; i++){
        int l, r, d; cin >> l >> r >> d;
        l--; r--;
        graph[l].push_back(make_pair(r, d));
        graph[r].push_back(make_pair(l, -d));
        query[i] = make_tuple(l, r, d);
    }

    for(int i = 0; i < N; i++){
        if(dist[i] != -INF) continue;
        dfs(i, -1, 0);
    }

    bool ans = true;
    for(int i = 0; i < M; i++){
        int l, r, d; tie(l, r, d) = query[i];
        if(dist[r] - dist[l] != d)ans = false;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

template <typename T>
vector<T> compress(vector<T> &X){
  vector<T> vals = X;
  sort(ALL(vals));
  vals.erase(unique(ALL(vals)), vals.end());
  for(int i=0; i<(int)X.size(); i++){
    X[i] = lower_bound(ALL(vals), X[i]) - vals.begin();
  }
  return vals;
}

template<typename T>
struct BIT{
  private:
    vector<T> bit;
    int N;
 
  public:
    BIT(int size){
      N = size;
      bit.resize(N+1);
    }
 
    void add(int k, int w){
      for(int x=k; x<=N; x+=(x & -x)) bit[x] += w;
    }
  
    T sum(int k){
      T ret = 0;
      for(int x=k; x>0; x-=x&-x) ret += bit[x];
      return ret;
    }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k; cin >> n >> k;
  vector<ll> a(n);
  REP(i,n){
    cin >> a[i];
    a[i] -= k;
  }
  vector<ll> s(n+1, 0);
  REP(i,n) s[i+1] = s[i] + a[i];
  auto comp = compress(s);
  BIT<ll> bit(n+10);
  ll ans = 0;
  REP(i,n+1){
    ans += bit.sum(s[i]+1);
    bit.add(s[i]+1, 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9536
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    repeat(i, n) cin >> a[i];
    repeat(i, m) cin >> b[i];
    
    auto check = [](const vector<string> a, const vector<string> b) -> bool {
        assert(a.size() == b.size());
        bool ret = true;
        repeat(i, (int)a.size()) {
            if (a[i] != b[i]) {
                ret = false;
                break;
            }
        }
        return ret;
    };
    
    repeat(i, n-m+1) {
        repeat(j, n-m+1) {
            vector<string> c(m);
            repeat(k, m) {
                c[k] = a[j+k].substr(i, m);
            }
            if (check(c, b)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
            
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

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

const ll mx = 105;
const ll mod = 998244353;


vector<vector<int>> adj;


void solve(){
    
   ll n, m ,i ,j ,k;

   ll a, b;

   cin>>k>>a>>b;

   ll nm = b/k - (a-1)/k;

   if(nm > 0){
       cout<<"OK\n";
   }
   else{
       cout<<"NG\n";
   }
 
}


int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(0);

    ll t = 1;
    
   // cin>>t;

    while(t--){
        solve();
    }
   
}




Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(!(a % 3) || !(b % 3) || !((a + b) % 3)) {
        cout << "Possible" << "\n";
    }else{
        cout << "Impossible" << "\n";
    }


    return 0;
}


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

int main(void) {
    char S[20], T[20], U[20];
    int A, B, b, i;
    scanf("%s%s%d%d%s", S, T, &A, &B, U);
    b=0;
    for (i=0; i<strlen(S); i++) {
        if (S[i]!=U[i]) {
            b=1;
            break;
        }
    }
    if (b==0) A--;
    else B--;
    printf("%d %d", A, B);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string a,b;
  cin >> a >> b;
  
  if(a.length() > b.length()){
    cout << "GREATER" << endl;
    return 0;
  }
  else if(a.length() < b.length()){
    cout << "LESS" << endl;
    return 0;
  }
  else if(a == b){
    cout << "EQUAL" << endl;
    return 0;
  } 
  else{
    rep(i,a.length()){
      if((int)a[i] >(int)b[i]){
        cout << "GREATER" << endl;
        return 0;
      }else if ((int)a[i] < (int)b[i]){
        cout << "LESS" << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
n =input()

#最上位の桁をc,桁数をkとすると、
#c以外が9の場合(ex.49999)はc,9*(k-1)となる
#それ以外の場合、c,9*(k-2),8となる(ex.9995:9989)

c = int(n[0])
k = len(n)
if int(n)<10:
    print(n);exit()
if int(n[1:])==int('9'*(k-1)):
    ans = c+9*(k-1)
else:
    ans = c+9*(k-1)-1

print(ans)







Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

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

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dp[201010][2];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[10][10];
bool flag[10][10];
bool flag2[10][10];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n), b(n), c(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	rep(i, n) {
		cin >> c[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	ll ans = 0;
	rep(i, n) {
		auto res = lower_bound(a.begin(), a.end(), b[i]);
		auto res2 = upper_bound(c.begin(), c.end(), b[i]);
		ans += (res - a.begin()) * (c.end() - res2);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  long n,k;
  cin >> n >> k;
  vector<pair<long,long>> a(n,pair<long,long>());
  for(int i=0;i<n;i++) cin >> a[i].first >> a[i].second;
  sort(a.begin(),a.end());
  for(int i=0;true;i++) {
    if(k-a[i].second<=0) {
      cout << a[i].first << endl;
      break;
    } else {
      k-=a[i].second;
    }
  }
}

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

int main()
{
    int k;
    vector<int> n(3);
    vector<vector<long long> > v(3);
    for(int i=0; i<3; ++i)
        cin >> n[i];
    cin >> k;
    for(int i=0; i<3; ++i){
        v[i].resize(n[i]);
        for(int j=0; j<n[i]; ++j)
            cin >> v[i][j];
        sort(v[i].rbegin(), v[i].rend());
    }

    priority_queue<pair<long long, vector<int> > > pq;
    set<vector<int> > history;
    pq.push(make_pair(v[0][0] + v[1][0] + v[2][0], vector<int>(3, 0)));
    history.insert(vector<int>(3, 0));
    while(--k >= 0){
        long long sum;
        vector<int> index;
        tie(sum, index) = pq.top();
        pq.pop();
        cout << sum << endl;

        for(int i=0; i<3; ++i){
            if(index[i] < n[i] - 1){
                long long tmp = sum - v[i][index[i]];
                ++ index[i];
                tmp += v[i][index[i]];
                if(history.find(index) == history.end()){
                    pq.push(make_pair(tmp, index));
                    history.insert(index);
                }
                -- index[i];
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <numeric>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    ll N, K;
    input(N, K);

    vector<ll> p(N, 0);
    input(p);

    vector<double> e;
    rep(i, 0, N)
    {
        e.push_back((p[i] * (p[i] + 1) / 2) / (double)p[i]);
    }

    double m = accumulate(e.begin(), e.begin() + K, 0.0);
    double res = m;

    ll pos = K;
    while (pos < N)
    {
        m += e[pos] - e[pos - K];
        if (res < m)
        {
            res = m;
        }
        pos++;
    }

    printf("%.12f\n", res);

    return 0;
}

Measured memory_bytes: 3956
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

template <uint_fast64_t MOD> class ModInt {
    using u64 = uint_fast64_t;

  public:
    u64 a;

    ModInt(const u64 x = 0) : a(x % MOD) {}
    constexpr u64 &value() { return a; }
    constexpr ModInt operator-() { return a ? MOD - a : 0; }
    constexpr ModInt operator+(const ModInt rhs) {
        return ModInt(*this) += rhs;
    }
    constexpr ModInt operator-(const ModInt rhs) {
        return ModInt(*this) -= rhs;
    }
    constexpr ModInt operator*(const ModInt rhs) {
        return ModInt(*this) *= rhs;
    }
    constexpr ModInt operator/(const ModInt rhs) {
        return ModInt(*this) /= rhs;
    }
    constexpr ModInt &operator+=(const ModInt rhs) {
        a += rhs.a;
        if(a >= MOD) {
            a -= MOD;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) {
        if(a < rhs.a) {
            a += MOD;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) {
        a = a * rhs.a % MOD;
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt rhs) {
        *this *= rhs.inv();
        return *this;
    }

    constexpr bool operator==(const ModInt rhs) { return this->a == rhs.a; }
    constexpr bool operator!=(const ModInt rhs) { return this->a != rhs.a; }
    friend constexpr ostream &operator<<(ostream &os, const ModInt<MOD> &x) {
        return os << x.a;
    }
    friend constexpr istream &operator>>(istream &is, ModInt<MOD> &x) {
        return is >> x.a;
    }

    constexpr ModInt inv() {
        u64 x = a, y = MOD, u = 1, v = 0, t = 0;
        while(y > 0) {
            t = x / y;
            a -= t * y;
            swap(x, y);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    constexpr ModInt pow(int e) {
        u64 x = 1, p = a;
        while(e > 0) {
            if(e % 2 == 0) {
                p = (p * p) % MOD;
                e /= 2;
            } else {
                x = (x * p) % MOD;
                e--;
            }
        }
        return ModInt(x);
    }
};

using mint = ModInt<MOD>;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<mint> nums(N + 1);
    rep(i, N + 1) { nums[i] = i; }
    vector<mint> frontSums(N + 2);
    rep(i, N + 1) { frontSums[i + 1] = nums[i] + frontSums[i]; }
    mint res = 0;
    for(ll i = K; i <= N + 1; i++) {
        mint num = (mint(N * i) - frontSums[i]) - (frontSums[i] - mint(1));
        res += num;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6300
N = int(input())
A = [0] * N 
for i in range(N):
    A[i] = int(input())

B = sorted(A)
max1 = B[-1]
max2 = B[-2]
for x in A:
    if x == max1:
        print(max2)
    else:
        print(max1)

Measured memory_bytes: 19120
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>

using namespace std;

int main(void){

    int n, k, ans = 1000000007;
    cin >> n >> k;

    vector<int> h(n);

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

    sort(h.begin(), h.end());

    int tmp;
    for(int i = 0;i < n - k + 1;i++){
        tmp = h[i+k-1] - h[i];
        if(ans > tmp){
            ans = tmp;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a,b,c;
    string s,s1;
    cin >> s;
    if(s[0] == s[1]) {
        if(s[1]==s[2]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        if(s[1]==s[2]) {
            if (s[2]==s[3])
                cout << "Yes" << endl;
            else  cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
n=int(input())
cnt=0

a,b,c=0,0,0
for i in range(n):
    s=input()
    cnt +=s.count("AB")
    if s[0]=="B" and s[-1]=="A":c +=1
    elif s[0]=="B":b +=1
    elif s[-1]=="A": a +=1

if a==0 and b==0:print(cnt+max(0,c-1))
else:print(cnt+min(a,b)+c)


Measured memory_bytes: 44008
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_BeginnerContest_123
{
    class Program
    {

        static void Main(string[] args)
        {

            long cnt = long.Parse(Console.ReadLine());
            long min = 0;
            for (int i = 0; i < 5; i++)
            {
                long tmp = long.Parse(Console.ReadLine());
                if ((0 == i) || (tmp < min))
                {
                    min = tmp;
                }
            }

            long ret = 0;
            if (cnt == min)
            {
                ret = 5;
            }
            else
            {
                ret = cnt / min;
                if (1 == min)
                {
                    ret += 4;
                }
                else
                {
                    ret += 5;
                }
            }

            Console.WriteLine(ret);

        }

    }
}



Measured memory_bytes: 11092
# https://atcoder.jp/contests/abc152/submissions/9693323

import sys
read = sys.stdin.read

N, *A = map(int, read().split())
mod = 10 ** 9 + 7


def min_factor(n):
    sieve = list(range(n + 1))
    sieve[2::2] = [2] * (n // 2)
    for i in range(3, int(n ** 0.5) + 2, 2):
        if sieve[i] == i:
            sieve[i * i::2 * i] = [i] * ((n - i * i) // (2 * i) + 1)
    return sieve


def prime_factorize(n):
    a = {}
    while n != 1:
        b = table[n]
        if b in a:
            a[b] += 1
        else:
            a[b] = 1
        n //= b
    return a


table = min_factor(10**6)

dic = {}
for i in A:
    for key, value in prime_factorize(i).items():
        if key in dic:
            dic[key] = max(dic[key], value)
        else:
            dic[key] = value

lcm = 1
for i, j in dic.items():
    lcm *= pow(i, j, mod)
    lcm %= mod

answer = sum(lcm * pow(i, mod - 2, mod) for i in A) % mod
print(answer)


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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> v(N, K - Q);
  rep(i, Q) {
    int a;
    cin >> a;
    a--;
    v.at(a)++;
  }
  rep(i, N) {
    if (v.at(i) > 0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nmax=40,abmax=10,inf=1000000;

int a[nmax],b[nmax],c[nmax];
int price[nmax+1][nmax*abmax+1][nmax*abmax+1];
int main(){
  int n,ma,mb;
  cin>>n>>ma>>mb;
  int summax=nmax*abmax;
  for(int i=0;i<=n;++i){
    for(int j=0;j<=summax;++j){
      for(int k=0;k<=summax;++k){
        price[i][j][k]=inf;
      }
    }
  }
  for(int i=0;i<n;++i){
    cin>>a[i]>>b[i]>>c[i];
  }
  price[0][0][0]=0;
  for(int i=0;i<n;++i){
    for(int j=0;j<=summax;++j){
      for(int k=0;k<=summax;++k){
        if(price[i][j][k]==inf)continue;
        price[i+1][j][k]=min(price[i+1][j][k],price[i][j][k]);
        price[i+1][j+a[i]][k+b[i]]=min(price[i+1][j+a[i]][k+b[i]],price[i][j][k]+c[i]);
      }
    }
  }
  int ans=inf;
  
  for(int ca=1;ca<=nmax*abmax;++ca){
    for(int cb=1;cb<=nmax*abmax;++cb){
      if(ca*mb==cb*ma) ans=min(ans,price[n][ca][cb]);
    }
  }
  if(ans==inf)ans=-1;
  cout<<ans<<endl;
}

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n , k ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>k ;
	int ans = n-k ;
	if(k == 1)
		ans = 0 ;
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    bool found = false;
    int i = 1;
    for (; i <= 1500; ++i) {
        int tax8 = (int)(i * 0.08);
        int tax10 = (int)(i * 0.1);
        if (tax8 == A && tax10 == B) {
            found = true;
            break;
        }
    }

    cout << (found ? i : -1) << endl;
    return 0;
}


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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  int G=A+B-C;
  int F=A+G-C;
  int I=B+C-G;
  int go=A+C+I;
  int D=go-A-B;
  int E=go-C-F;
  int H=go-G-I;
  cout<<A<<" "<<B<<" "<<D<<endl;
  cout<<E<<" "<<C<<" "<<F<<endl;
  cout<<G<<" "<<H<<" "<<I<<endl;
}


Measured memory_bytes: 3600
(defvar *days*
  '("SUN" "MON" "TUE" "WED" "THU" "FRI" "SAT"))

(defun solve (s)
  (- 7 (position s *days* :test 'equal)))

#-swank
(let ((s (read-line)))
  (format t "~A~%" (solve s)))


Measured memory_bytes: 11492
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());
        int[] p = ReadIntArray();

        int err = 0;

        for (int i = 0; i < n; i++){
            if (p[i] != i + 1){ err++; }
        }

        if (err <= 2)
        {
            WriteLine("YES");
        }
        else
        {
            WriteLine("NO");
        }
    }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 100005;
const ll LLMAX = 200000000000000007;

ll solve(int n,vector<ll> a)
{
    vector<ll> dp(n+1,0);
    vector<ll> pref(n+1,0);
    pref[1] = a[0];
    for(int i=2; i<=n; i++)
        pref[i] = pref[i-2] + a[i-1];
    for(int i=2; i<=n; i++)
    {
        if(i%2)
            dp[i] = max(dp[i-2] + a[i-1], dp[i-1]);
        else
            dp[i] = max(dp[i-2] + a[i-1], pref[i-1]);
    }
    return dp[n];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int n;
    cin>>n;
    vector<ll> a;
    for(int i=0; i<n; i++)
    {
        ll ele;
        cin>>ele;
        a.push_back(ele);
    }
    cout<<solve(n,a);
	return 0;
}

Measured memory_bytes: 9432
x,y = map(int,input().split())
li1 = [1,3,5,7,8,10,12]
li2 = [4,6,9,11]
li3 = [2]
if li1.count(x)==1 and li1.count(y)==1 or li2.count(x)==1 and li2.count(y)==1 or x==y and y==2:
    print("Yes")
else:
    print("No")


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

int main(){
    int n, m;
    cin >> n >> m;
    int suki[m+1];
    for(int i = 1; i <= m; i++){
        suki[i] = 0;
    }
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            suki[a]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= m; i++){
        if(suki[i] == n){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
  int h,w,k;
  cin>>h>>w>>k;

  char pos[h][w];
  int ans=0;

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin>>pos[i][j];
    }
  }

  for(int bity=0; bity< (1<<h); ++bity){
    for(int bitx=0; bitx< (1<<w); ++bitx){
    //vector<vector<int>> Y(1000, vector<int>(1000));
      char cnt_pos[h][w];
      for(int n=0; n<h; n++){
        for(int l=0; l<w; l++){
          cnt_pos[n][l]=pos[n][l];
        }
      }

      for(int i=0; i<h; ++i){
        if(bity & (1<<i)){
          for(int x=0; x<w; x++){
            if(cnt_pos[i][x]=='#'){
              cnt_pos[i][x]='a';
            }
          } 
        }
      }
    
      for(int j=0; j<w; ++j){
        if(bitx & (1<<j)){
          for(int y=0; y<h; y++){
            if(cnt_pos[y][j]=='#'){
              cnt_pos[y][j]='b';
            }
          }
        }     
      }

      int cnt=0;
      for(int y=0; y<h; y++){
        for(int x=0; x<w; x++){
          if(cnt_pos[y][x]=='#'){
            cnt++;
          }
        }
      }
      
      if(cnt==k){
        ans++;
      }
    } 
  }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
from itertools import product
def main():
    N, M = map(int, input().split())
    CAKES = [tuple(map(int, input().split())) for _ in range(N)]
    m = 0
    for a, b, c in product([1, -1], repeat=3):
        C = [x * a + y * b + z * c for x, y, z in CAKES]
        C.sort(reverse=True)
        m = max(m, sum(C[:M]))
    return m

print(main())


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

const int N = 123456;

int p[2 * N + 1];
int main(){
	int n;
	p[0] = p[1] = 0;
	for(int i = 2;i <= 2 * N;++i){
		p[i] = 1;
	}
	for(int i = 2;i <= sqrt(2 * N);++i){
		if(p[i]){
			for(int j = i + i;j <= 2 * N;j += i){
				p[j] = 0;
			}
		}
	}
	for(int i = 3;i <= 2 * N;++i){
		p[i] += p[i - 1];
	}
	while(cin >> n, n){
		cout << p[2 * n] - p[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 2124
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include<cmath>
//#include <set>
//#include <fstream>

#define ll long long int
using namespace std;

void Solve()
{
    ll x;
    cin >> x;
    ll cnt = x / 500;
    cnt *= 1000;
    x %= 500;
    x /= 5;
    x *= 5;
    cnt += x;
    cout << cnt;
}

int main()
{
    ios_base::sync_with_stdio( false );
    cin.tie( nullptr );
    //freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
    //int t;
    //cin >> t;
    //while(t--)
    {
        Solve();
        cout << '\n';
    }
    return 0;
}



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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <uint MD> struct ModInt {
    using M = ModInt;
    uint v;
    ModInt() : v{0} {}
    ModInt(ll _v) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M(0) - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return (*this).pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};

using Mint = ModInt<TEN(9) + 7>;

const int MN = 44;
const int MD = 17;
const int S = (1 << MD) - 1;
int n, x, y, z;
Mint p10[MN];
Mint dp[S + 10], ndp[S + 10];

void first() {
    p10[0] = 1;
    for (int i = 1; i < MN; i++) {
        p10[i] = p10[i - 1] * Mint(10);
    }
}

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

    first();
    cin >> n >> x >> y >> z;
    int m = (1 << (x + y + z - 1)) + (1 << (y + z - 1)) + (1 << (z - 1));

    Mint ans = 0;
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        fill_n(ndp, S + 10, 0);
        for (int t = 0; t <= S; t++) {
            if (!dp[t]) continue;
            for (int d = 1; d <= 10; d++) {
                int nt = ((t << d) & S) | (1 << (d - 1));
                ndp[nt] += dp[t];
            }
        }
        copy_n(ndp, S + 10, dp);
        for (int t = 0; t <= S; t++) {
            if (m == (t & m)) {
                ans += dp[t] * p10[n - 1 - i];
                dp[t] = 0;
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
#define EPS 1e-9
#define PI acos(-1.0)
#define el        '\n'
#define ft       first
#define sd       second
#define sp(x)       fixed<<setprecision(x)
#define mp(x,y)    make_pair((x),(y))
#define pb(x)      push_back((x))
#define pf(x)      push_front((x))
#define all(v)    ((v).begin()),((v).end())
#define sz(x)      ((int) (x).size())
#define mem(a,b)  memset(a,b,sizeof(a))
#define fr(i, n)  for (ll i = 1; i < n-1; i+=2)
#define frn(i, n)  for (int i = 0; i <= n; ++i)
#define rf(i, n)  for (int i = n; i >= 0; --i)
#define fro(i, n)  for (ll i = 1; i <= n; ++i)
#define fora(a) for(auto &i : a)
#define Sum(a,n,i_s)       accumulate(a,a+n,i_s)
#define frt(v)     for (std::vector<int>::iterator i = v.begin(); i != v.end(); ++i)
const ll mod = 1e9 + 7;
const int  OO = INT_MAX, P = 3 * (1e5 + 5);
int xd[] = { 1,0,-1,0,-1,1,1,-1 };
int yd[] = { 0,-1,0,1,1,1,-1,-1 };
vector<ll>adj[P];
ll dp[P], vis[P], ans;
ll dfs(ll i)
{
	if (adj[i].empty())
	{
		return 0;
	}
	ll &ret = dp[i];
	if (~ret)
		return ret;
	for (ll j = 0; j < sz(adj[i]); j++)
	{
		ll nxt = adj[i][j];
		ret = max(ret, 1 + dfs(nxt));
	}
	return ret;
}

int main() {
	//freopen("Text.txt", "r", stdin);
	ll n, m, x, y;
	cin >> n >> m;
	mem(dp, -1);
	for (ll i = 0; i < m; i++)
	{
		cin >> x >> y;
		adj[x].pb(y);
	}
	ans = 0;
	for (ll i = 1; i <= n; i++)
	{
			ans = max(ans, dfs(i));
	}
	cout << ans << el;
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, T;
    cin >> N >> T;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    vector<vector<ll>> dp(N + 1, vector<ll>(T + 3001, 0));
    sort(items.begin(), items.end());
    rep(i, N) {
        P p = items[i];
        rep(t, T + 3000) {
            if (t - p.first >= 0 && t - p.first <= T - 1) {
                dp[i + 1][t] = max(dp[i + 1][t], dp[i][t - p.first] + p.second);
            }
            dp[i + 1][t] = max(dp[i + 1][t], dp[i][t]);
        }
    }
    ll ans = 0;
    rep(i, T + 3000) {
        ans = max(ans, dp[N][i]);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 141184
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.chrono.MinguoChronology;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.math.BigDecimal;

public class Main {

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

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int ansJ = 0;
		double ansB = 0;
		for (int count = 0; count < a ; count++) {
			double c = sc.nextDouble();
			String b = sc.next();
			
			if(b.equals("JPY")) {
				ansJ = ansJ + (int)c;
			} else {
				ansB = ansB + c;
			}
		}
		double ans = ansJ + ansB * 380000;
		BigDecimal aaa = BigDecimal.valueOf(ans);
		BigDecimal show = aaa.setScale(4, BigDecimal.ROUND_HALF_UP);
		System.out.println(show);
}
}

Measured memory_bytes: 23760
#include <iostream>

using namespace std;

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

    int k;
    cin >> k;

    cout << (k % 2 == 0 ? (k / 2) * (k / 2) : (k / 2) * (k/ 2 + 1)) << endl;
 
    return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main(){
  var a,b,c string
  fmt.Scan(&a, &b, &c)
  if a[len(a) - 1] == b[0] && b[len(b) - 1] == c[0] {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

template<typename T>
struct BIT {
	int n;
	vector<T>dat;
	BIT(int n = 0) {
		initialize(n);
	}
	void initialize(int temp) {
		n = temp;
		dat.resize(n);
		rep(i, 0, n)dat[i] = 0;
	}
	T sum(int i) {
		T s = 0;
		while (i >= 0) {
			s += dat[i];
			i = (i & (i + 1)) - 1;
		}
		return s;
	}
	T sum_between(int i, int j) {
		if (i > j)return 0;
		return sum(j) - sum(i - 1);
	}
	void plus(int i, T x) {
		while (i < n) {
			dat[i] += x;
			i |= i + 1;
		}
	}
	int lower_bound(T x) {
		if (sum(n - 1) < x)return -1;
		else if (sum(0) >= x)return 0;
		int ng = 0, ok = n - 1;
		while (ok - ng > 1) {
			int mid = (ok + ng) / 2;
			if (sum(mid) >= x)ok = mid;
			else ng = mid;
		}
		return ok;
	}
};

ll sum[202020];
int main() {
	int n, k;
	cin >> n >> k;
	vector<int>a(n);
	rep(i, 0, n) {
		cin >> a[i];
		sum[i + 1] = sum[i] + a[i];
	}
	rep(i, 0, n + 1)sum[i] = sum[i] - k * i;

	vector<ll>dic;
	rep(i, 0, n+1)dic.pb(sum[i]);
	sort(all(dic));
	dic.erase(unique(all(dic)),dic.end());
	int sz = dic.size();
	BIT<ll>bitnum(sz);

	rep(i, 0, n + 1) {
		int ind = lower_bound(all(dic),sum[i]) - dic.begin();
		bitnum.plus(ind,1);
	}

	ll ans = 0;
	rep(l, 0, n) {
		int ind = lower_bound(all(dic), sum[l]) - dic.begin();
		ans += bitnum.sum_between(ind,sz-1)-1;
		bitnum.plus(ind, -1);
	}
	puts(ans)

	return 0;
}


Measured memory_bytes: 5872
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int N;
	char S[100001];
	scanf("%d", &N);
	scanf("%s", S);

	int i, count[26] = {};
	long long total = 1;
	for (i = 0; S[i] != 0; i++) count[S[i] - 'a']++;
	for (i = 0; i < 26; i++) total = total * (count[i] + 1) % 1000000007;

	printf("%lld\n", (total + 1000000006) % 1000000007);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
S = input()

temp = S[1:].count('E')
ans = temp
for i in range(1, n):
    if S[i] == 'E':
        temp -= 1
    if S[i - 1] == 'W':
        temp += 1
    ans = min(ans, temp)
    
print(ans)

Measured memory_bytes: 3700