akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DColoringEdgesOnTree {
private:
    void dfs(int current, int previous, int previousColor, vector<unordered_map<int, int>>& edgeAndColors, int& maxColor) {
        int color = 1;
        for (auto& p : edgeAndColors[current]) {
            const auto next = p.first;
            if (next == previous) continue;
            if (color == previousColor) color++;
            edgeAndColors[current][next] = color;
            edgeAndColors[next][current] = color;
            maxColor = max(maxColor, color);
            dfs(next, current, color, edgeAndColors, maxColor);

            color++;
        }
    }

public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    in >> N;
	    vector<int> a(N), b(N);
	    REP(i,1,N) in >> a[i] >> b[i];

	    vector<unordered_map<int, int>> edgeAndColors(N+1);
	    REP(i,1,N) {
            edgeAndColors[a[i]][b[i]] = -1;
            edgeAndColors[b[i]][a[i]] = -1;
	    }
	    int maxColor = 0;
	    dfs(1, -1, -1, edgeAndColors, maxColor);
	    out << maxColor << "\n";
	    REP(i,1,N) {
	        out << edgeAndColors[a[i]][b[i]] << "\n";
	    }
	}
};


signed main() {
	DColoringEdgesOnTree solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 17152
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll a[5][5];
int main()
{
  ll n, b, flag = 0;
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      scanf("%lld", &a[i][j]);
    }
  }
  scanf("%lld", &n);

  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &b);
    for (int j = 0; j < 3; j++)
    {
      for (int k = 0; k < 3; k++)
      {
        if (a[j][k] == b)
        {
          a[j][k] = 0;
        }
      }
    }
  }

  for (int i = 0; i < 3; i++)
  {
    if ((a[i][0] == a[i][1] && a[i][0] == a[i][2]) || (a[0][i] == a[1][i] && a[0][i] == a[2][i]))
    {
      flag = 1;
    }
  }
  if ((a[0][0] == a[1][1] && a[0][0] == a[2][2]) || (a[0][2] == a[1][1] && a[0][2] == a[2][0]))
  {
    flag = 1;
  }
  puts(flag ? "Yes" : "No");
}

Measured memory_bytes: 128
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]

skip = []
for i in range(h):
  if a[i] == ["."] * w: skip.append(i)

a = list(zip(*a))
d = []
for i in range(w):
  if set(a[i]) == {"."}: d.append(i)
d.sort(reverse=True)
for i in d:
  a.pop(i)

a = list(zip(*a))
for i in range(h):
  if i in skip: continue
  else:
    print("".join(a[i]))

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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

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

     for(ll i=1;i<=n;i++){
        if((i*(i+1))/2 >= n){cout << i;return;}
     }
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k,ans;
signed main()
{
	cin>>n>>k;
	if(!k)
	{
		cout<<n*n;
		return 0;
	}
	for(int b=k+1;b<=n;++b)
	{
		ans+=max((n/b*b)/b,0ll)*(b-k);
		ans+=max(n%b-k+1,0ll);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N,M;
	char[][] a,b;

	public boolean check(){
		for(int i = 0;i < N;i++){

			for(int j = 0;j < N;j++){
				if(i + M - 1 >= N || j + M - 1>= N)continue;
				boolean flag = true;
				for(int x = 0;x < M;x++){

					for(int y = 0;y < M;y++){

						if(a[i+x][j+y] != b[x][y]){
							flag = false;
							x = y = M;
						}
					}
				}

				if(flag){
					return true;
				}
			}
		}
		return false;
	}

	public void solve() {
		N = nextInt();
		M = nextInt();

		a = new char[N][];
		b = new char[M][];

		for(int i = 0;i < N;i++){
			a[i] = next().toCharArray();
		}


		for(int i = 0;i < M;i++){
			b[i] = next().toCharArray();
		}


		if(check()){
			out.println("Yes");
		}else{
			out.println("No");
		}
	}

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

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8276
#include <stdio.h>
#include <algorithm>

int a[100003];
long long int b[100003];
int mb(int a)
{
    int x = 1;
    while(a)
    {
        a>>=1;
        x<<=1;
    }
    return x>>1;
}
int n,m;
long long getAns(int x)
{
    if(x < 0) return 0;
    long long int temp = 0;
    for(int i=0;i<n;i++)
    {
        if((x | a[i]) == x)
            temp += b[i];
    }
    return temp;
}
int main()
{

    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%d%lld",&a[i],&b[i]);
    }
    long long int ans = 0;
    ans = getAns(m);
    ans = std::max(ans, getAns(mb(m) - 1));
    for(int j=mb(m);j;j>>=1)
    {
        int x = m;
        if(j & x)
        {
            x -= j;
            x |= (j-1);
            ans = std::max(ans, getAns(x));
        }
    }
    printf("%lld\n", ans);
}

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

int main(){
    int N;
    cin >> N;
    int ans = 0;
    int count = 0;
    for(int a = 0; a <= N; a++){
        for(int b = 0; b <=N; b++){
            ans = 4*a + 7*b;
            if(ans == N) count++;
        }
    }
    if(count >= 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

   
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }

    val sum = a.reduceRight{ i,j ->
        i.xor(j)
    }

    a.forEach {
        print("${it.xor(sum)} ")
    }
}



Measured memory_bytes: 77564
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  /* std::cout<<std::fixed<<std::setprecision(6);*/
  long long W, H, x, y;
  cin >> W >> H >> x >> y ;

  double ans = (double)(W * H / 2.0);
  bool a = (W==x*2) && (H==y*2);
  
  printf("%lf",ans);
  cout << " " << a << endl;
}

Measured memory_bytes: 256
# B - Easy Linear Programming
A,B,C,K = map(int,input().split())
while True:
    ans = 0
    ans += min(A,K)
    K -= min(A,K)
    if K<=0:
        break
    K -= B
    if K<=0:
        break
    ans -= K
    break
print(ans)

Measured memory_bytes: 9036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl;
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;

int main(){
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for(int i=0; i<=3000; i++){
        for(int j=0; j<=3000; j++){
            int tmp = n-i*r-j*g;
            if(tmp >= 0 && tmp%b == 0) ans++;
        }
    }
    OUT(ans);
}



Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
char fi[1005][1005];
P sg[10];
int d[1005][1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int n,k;
signed main(){
    string s,t;cin>>s>>t;
    int count=-1;
    rep(i,s.length()){
        bool k=true;
        rep(j,t.length()){
            if(s[i+j]!=t[j]&&s[i+j]!='?')k=false;
        }
        if(k)count=i;
    }
    if(count==-1){
       cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    for(int i=count;i<count+t.length();i++){
        s[i]=t[i-count];
    }
    rep(i,s.length()){
        if(s[i]=='?')cout<<'a';
        else cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
//jinhaonan
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	x=f?-x:x;
}
template<class T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
template<class T>inline bool chkmax(T &a,T const &b){
	return a<b?a=b,1:0;
}
template<class T>inline bool chkmin(T &a,T const &b){
	return a>b?a=b,1:0;
}
const int N=100000;
void Main(){
	static int v[2][N+5];
    int n;read(n);
    for(int i=1;i<=n;++i){
		int x;read(x);
		++v[i&1][x];
	}
	auto pos0=max_element(v[0]+1,v[0]+N+1);
	auto pos1=max_element(v[1]+1,v[1]+N+1);
	int ans=n;
	if(pos0-v[0]==pos1-v[1]){
		int tmp=*pos0;
		v[0][pos0-v[0]]=0;
		chkmin(ans,n-*pos1-*max_element(v[0]+1,v[0]+N+1));
		v[0][pos0-v[0]]=tmp;
		tmp=*pos1;
		v[1][pos1-v[1]]=0;
		chkmin(ans,n-*pos0-*max_element(v[1]+1,v[1]+N+1));
		v[1][pos1-v[1]]=tmp;
	}else{
		ans=n-*pos0-*pos1;
	}
	write(ans),putchar('\n');
}
int main(){
    // freopen("in.txt","r",stdin);
    // int test;read(test);
    // while(test--){
        Main();
    // }
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<vector>
#include<map>
#include<queue> 
#include<algorithm>
using namespace std;
#define maxn
#define ll long long
void read(int &x){
    x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    x*=f;
}
char s[50];
int main(){
	scanf("%s",s);
	for(int i=0;i<strlen(s)-8;i++) cout<<s[i];
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  stack<string>st;
  string s;
  while(cin>>s){
     if(s == "+" || s == "-" || s == "*"){
            int b = stoi(st.top()); st.pop();
            int a = stoi(st.top()); st.pop();
            int number;
            if(s == "+") number = a + b;
            if(s == "-") number = a - b;
            if(s == "*") number = a * b;
            st.push(to_string(number));
        }else{
            st.push(s);
        }
    }
    cout << st.top() << endl;
}


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

using namespace std;


int main(){

    string s;

    int left, right, sz;

    cin >> s;

    sz = s.size();
    //cout << sz << " sz\n";
    for(int i = 0;i < sz;i++)
        if(s[i] == 'A') {
            left = i;
            break;
        }

    for(int i = sz-1;i >= 0; i--)
        if(s[i] == 'Z') {
            right = i;
            break;
        }
    ///cout << left << " left\n" << right << " right \n";
    cout << abs(left - right) + 1 << endl;

    return 0;
}


Measured memory_bytes: 640
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    p = LI()
    ans = 0
    for i in range(1, n):
        if p[i-1] == i:
            temp = p[i-1]
            p[i-1] = p[i]
            p[i] = temp
            ans += 1
    if p[n-1] == n:
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 20768
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
int a[100010],b[200020];
P2 c[100010];

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>N;
    rep(i,0,N){
        cin>>a[i]>>b[i];
        c[i]=P2(a[i]+b[i],pint(a[i],b[i]));
    }
    sort(c,c+N);
    reverse(c,c+N);
    int ans=0;
    rrep(i,0,N){
        if(i%2)ans-=c[i].se.se;
        else ans+=c[i].se.fi;
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 4992
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bits (testBit)
import Data.List (transpose, mapAccumL)

main :: IO ()
main = do
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    fromIntToBools :: Int -> [Bool]
    fromIntToBools = flip map is . testBit
      where
        is = [39, 38..0] :: [Int]
    k' = fromIntToBools k :: [Bool]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    as' = transpose . map fromIntToBools $ as :: [[Bool]]
    maxF = snd . mapAccumL step (Just k') . map count $ as' :: [Int]
      where
        step :: Maybe [Bool] -> Int -> (Maybe [Bool], Int)
        step (Just (False : bs')) c             = (Just bs', c)
        step (Just (_ : bs'))     c | 2 * c < n = (Just bs', n - c)
                                    | otherwise = (Nothing, c)
        step Nothing              c             = (Nothing, max c (n - c))
  print . fromDigitsToInt $ maxF

fromDigitsToInt :: [Int] -> Int
fromDigitsToInt = foldl step 0
  where
    step :: Int -> Int -> Int
    step ds d = 2 * ds + d
{-# INLINE fromDigitsToInt #-}

count :: [Bool] -> Int
count = length . filter id
{-# INLINE count #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


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

int main() {
#ifdef LOCAL
	freopen("./input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<int> num(n, -1);
	int ok = 1;
	for (int i = 0; i < m; i++)
	{
		int s, c;
		cin >> s >> c;
		s--;
		if (num[s] == -1) num[s] = c;
		else if (num[s] != c) ok = 0;
	}

	if (num[0] == 0 && n!=1) ok = 0;

	if (!ok) {
		cout << -1 << endl;
	}
	else 
	{
		for (int i = 0; i < n; i++)
		{
			if (num[i] == -1) {
				if (i == 0 && n != 1)num[i] = 1;
				else num[i] = 0;
			}
			cout << num[i];
		}
		cout << endl;
	}



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*配列Aの中の数字とその個数のペア配列を作り、個数が奇数の
のものをカウント
*/
int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    A.push_back(-1);
    vector<pair<int,int>> p;
    int c = 1;

    for(int i = 0;i<N;i++){
        if(A[i] == A[i+1]){
            c++;
        }
        if(A[i] != A[i+1]){
            p.push_back(make_pair(A[i],c));
            c = 1;
        }
    }

    int ans = 0;
    for(int i = 0;i<p.size();i++){
       if(p[i].second%2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int N; cin >> N;
    string S, T; cin >> S >> T;
    string U = "";
    rep(i,N) {
        U += S[i];
        U += T[i];
    }
    cout <<  U << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;



int main()
{
	std::string s[51];
	int n;
	int d[51];
	std::string x;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> s[i] >> d[i];
	cin >> x;
	int c=0;
	for (int i = 0; i < n; i++) {
		if (s[i] == x) {
			c = 0;
		}
		else {
			c += d[i];
		}
	}
	cout << c;
}

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

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c) __typeof__((c).begin())
#define RITER(c) __typeof__((c).rbegin())
#define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)

int main(){
    string s;
    while(cin >> s){
        RFOREACH(it, s){
            cout << *it;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	int data[7];
	while(cin>>n&&n!=0){
		fill(data,data+7,0);
		for(int i = 0; i < n; i++){
			int num;
			cin>>num;
			if((num/10)>=6){
				data[6]++;
			}
			else{
				data[num/10]++;
			}
		}
		for(int i = 0; i < 7; i++)
			cout<<data[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 864
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");

		int p = Integer.parseInt(tmpArray[0]);
		int q = Integer.parseInt(tmpArray[1]);

		int g = gcd(p, q);

		q /= g;

		//qを構成する約数を調べる
		int result = 1;

		for(int i = 2; i <= q; i++){
			boolean divided = false;

			while(q % i == 0){
				divided = true;
				q /= i;
			}

			if(divided){
				result *= i;
			}
		}

		System.out.println(result);
	}

	static int gcd(int a, int b){
        int tmp;

        while (a % b != 0)
        {
            tmp = b;
            b = a % b;
            a = tmp;
        }
        return b;
    }
}



Measured memory_bytes: 25336
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
  int n, t, a;
  int ans;
  double temp, now;

  cin >> n >> t >> a;

  vector<double> h(n);
  for(int i = 0; i < n; ++i){
    cin >> h.at(i);
  }

  ans = 0;
  now = t - h.at(ans) * 0.006;
  for(int i = 0; i < n; i++){
    temp = t - h.at(i) * 0.006;

    if(fabs(a - now) > fabs(a - temp)){
      ans = i;
      now = temp;
    }
  }

  cout << ans + 1 << endl;


}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  double x1,x2,x3,x4,y1,y2,y3,y4;
  char d;

  while(cin>>x1>>d>>y1>>d>>x2>>d>>y2>>d>>x3>>d>>y3>>d>>x4>>d>>y4!='\0'){

    int a=0,b=0;
    int han=0;

    if(y2>(x2-x1)*(y3-y1)/(x3-x1)+y1)
      a=1;
    if(y4>(x4-x1)*(y3-y1)/(x3-x1)+y1)
      b=1;
    if(a==b)
      han=1;

    a=b=0;

    if(y1>(x1-x2)*(y4-y2)/(x4-x2)+y2)
      a=1;
    if(y3>(x3-x2)*(y4-y2)/(x4-x2)+y2)
      b=1;
    if(a==b)
      han=1;

    if(han==0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;

  }

}

Measured memory_bytes: 1212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A[] = new int[10];
		boolean b = false;
		for (int i=0;i<3;i++) {
			int temp = sc.nextInt();
			A[temp]++;
			if (A[temp]==2) {
				b = true;
			}
			if (A[temp]==3) {
				System.out.println("No");
				return ;
			}
		}
		if (!b) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 6006
typedef long long ll;
const int mod=998244353;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,x,ans,fac[N],ifac[N];
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		ifac[i]=1LL*ifac[i+1]*(i+1)%mod;
	}
}
inline int C(int n,int m){
	if(n<0||m<0||n-m<0)return 0;
	return 1LL*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int calc(int n){
	int tot=(x&1||2*n<x);
	for(int i=n;i<=(n<<1)-1;++i){
		if(i<x)tot=(tot+C(n,i-n))%mod;
		else if((x-i)&1){
			int p=(i-x+1)>>1;
			tot=(tot+C(n-(p<<1),(i-(p<<2))-(n-(p<<1))))%mod;
		}
	}
	return tot;
}	
int main(){
	n=read(),x=read();
	init(max(n,x));
	for(int k=0;k<=n;++k){
		ans=(ans+1LL*C(n,k)*calc(k))%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3724
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[]A = new int[M+1];
		for(var i=0;i<M;i++){
			A[i] = int.Parse(Console.ReadLine());
		}
		long[,]B = new long[N+1,2];
		long mod = 1000000007;
		int t = 0;
		B[0,0]=1;
		for(var i=1;i<=N;i++){
			if(t>=M || A[t]!=i){
				B[i,0] = (B[i-1,0]+B[i-1,1]) % mod;
				B[i,1] = B[i-1,0] % mod;
			} else {
				t++;
				B[i,1] = B[i-1,0] % mod;
			}
		}
		Console.WriteLine(B[N,0]);
	}
}

Measured memory_bytes: 14816
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

void call(int n){
	int i = 1, x;
	while (i <= n){
		x = i;
		if (x % 3 == 0)std::cout << " " << i;
		else while (x){
			if (x % 10 == 3){
				std::cout << " " << i;
				break;
			}
			x /= 10;
		}
		++i;
	}
	std::cout << std::endl;
}

int main(){
	int n;
	std::cin >> n;
	call(n);
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
ab = sorted(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
for c, d in cd:
    i = -1
    y = -1
    for j, (a, b) in enumerate(ab):
        if a < c and b < d and b > y:
            i = j
            y = b
    if i != -1:
        del ab[i]
print(n - len(ab))

Measured memory_bytes: 3064
import numpy as np
n, m, q = map(int, input().split())
train = np.zeros((n, n), dtype=int)
for _ in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    train[l][r] += 1

# 累積和
for i in range(n):
    np.add.accumulate(train[i], out=train[i])
np.add.accumulate(train, out=train)

ans = []
for _ in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    a = train[y][y]
    if x != 0:
        a -= train[x-1][y]
    ans.append(a)

print(*ans, sep="\n")


Measured memory_bytes: 20664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int t[111];
  cin>>n;
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>t[i];
    sum+=t[i];
  }
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int p,x;
    cin>>p>>x;
    cout<<sum-t[p-1]+x<<endl;
  }
  return 0;
}


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

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  vector<int> C;
  for(int i=A;i<B+1;i++){
    if(i<A+K){
      C.push_back(i);
    }
    else if(B-K<i){
      C.push_back(i);
    }
  }
  int D=C.size();
  for(int i=0;i<D;i++){
    cout << C.at(i) << endl;
  }
}


Measured memory_bytes: 3616
#include <stdio.h>
int main() {
//read in 10 integers
        int mountains[10];
        int i;
        for (i=0;i<10;i++) {
        scanf("%d",&mountains[i]);
        }


        int f, s, t;
        f=s=t=0;
        for (i=0;i<10;i++) {

                if (mountains[i] >= f) {
                        t = s;
                        s = f;
                        f = mountains[i];
                }
                if (mountains[i] >= s && mountains[i] < f) {
                        t = s;
                        s = mountains[i];
                }
                if (mountains[i] >= t && mountains[i] < s) {
                        t = mountains[i];
                }
        }

        printf("%d\n",f);
        printf("%d\n",s);
        printf("%d\n",t);


return 0;
}

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

const int INF = 2000000001;

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

  int N;
  cin >> N;

  int cur_min = INF;
  int cur_max = -INF;
  for (int i = 0; i < N; ++i) {
    int r;
    cin >> r;

    cur_max = max(cur_max, r - cur_min);
    cur_min = min(cur_min, r);
  }
  cout << cur_max << endl;
  return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int64_t ans; cin>>ans;
	auto gcd=[](auto p,auto q){
		while(p%q!=0){
			auto tmp=q;
			q=p%q;
			p=tmp;
		}
		return q;
	};
	auto lcm=[&](auto a,auto b){
		return a/gcd(a,b)*b;
	};
	for(int i=1;i<n;++i){
		int64_t t; cin>>t;
		ans=lcm(ans,t);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <string.h>
#include <vector>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <list>
using namespace std;
typedef long long ll;
/* prototype */
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
	int i,j;
	cin >> i >> j;
	if(i <= 8 && j <= 8)
		cout << "Yay!" << endl;
	else
		cout << ":(" << endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
/*FUNC*/
//エラトステネスのふるい(素数発見アルゴリズム)
vector<int> SOE(int min, int max)
{
    //0,1は含まれない
    if (min < 2) min = 2;
    //探索リスト作成
    vector<int> int_array;
    for (int i = min; i <= max; i++) int_array.push_back(i);
    //素数リスト
    vector<int> sosu;
    //√max
    double stop = sqrt(max);
    //計算
    while (true)
    {
        //素数リストに追加
        sosu.push_back(int_array.front());
        int_array.erase(int_array.begin());
        //停止
        if (stop < (double)(sosu.back())) break;
        //ふるい
        for (int i = 0; i < (int)int_array.size(); i++)
        {
            if (int_array[i] % sosu.back() == 0)
                int_array.erase(int_array.begin() + i);
        }
    }
    sosu.insert(sosu.end(), int_array.begin(), int_array.end());
    return sosu;
}

//最小公倍数
int MinCM(int a, int b)
{
    int c = a * b;
//入れ替え
    if (a < b)
        swap(a, b);
    int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return c / b;
}

//最大公約数
int MaxCD(int a, int b)
{
//入れ替え
    if (a < b)
        swap(a, b);
    int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
//iget cin int 2 vector
vector<int> igets(int N){
    vector<int> A;
    int temp;
    for (int i = 0; i < N; ++i) {
        cin >> temp;
        A.push_back(temp);
    }
    return A;
}

ll nPr(ll n,ll r) {
    ll ans=1;
    r=n-r;
    while(n!=r) {
        ans*=n;
        --n;
    }
    return ans;
}

ll nE(ll n) {
    return nPr(n,n);
}

ll nCr(ll n,ll r) {
    if(r==0)return -1;
    else{
        if(0!=n-r&&n-r<r)r=n-r;
        return nPr(n,r)/nE(r);
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (isOddMultipliedBy(a, b)) {
            System.out.println("Odd");
        } else {
            System.out.println("Even");
        }
    }

    private static boolean isOddMultipliedBy(int a, int b) {
        return a % 2 == 1 && b % 2 == 1;
    }
}


Measured memory_bytes: 21844
N, Q = gets.chomp.split.map(&:to_i)

$tree = Array.new(N+1).map{Array.new}

(N-1).times do |i|
  a, b = gets.chomp.split.map(&:to_i)
  # a < bなので片方だけ入れる→駄目だった　どっちが親かはいってないため
  $tree[a-1] << b-1
  $tree[b-1] << a-1
end

$visited = Hash.new(false)


# クエリに順番は関係ない
# 1つの頂点に対してのものはまとめて良い
$ans = Array.new(N, 0)

Q.times do |i|
  p, x = gets.chomp.split.map(&:to_i)
  $ans[p-1] += x
end

# stack level too deepのエラーが出る
# def dfs(vertex)
#   return if $tree[vertex].empty?
#
#   $tree[vertex].each do |v|
#     next if $visited[v] == true
#     $ans[v] = $ans[v] + $ans[vertex]
#     $visited[v] = true
#     dfs(v)
#   end
# end
#
# $visited[0] = true
# dfs(0)

queue = [0]
$visited[0] = true

until queue.empty?
  vertex = queue.shift

  $tree[vertex].each do |v|
    next if $visited[v] == true
    $ans[v] += $ans[vertex]
    $visited[v] = true
    queue.push(v)
  end
end

puts $ans.join(' ')



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

#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

const int M = 1000005;
const int N = 200005;
const int MOD = 998244353;

vi multiple[M];
int n, a[N];
vi divisor[M];
int calc[M];
int inv[M];
int w[M];


int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    for (int i = 1; i < M; i++) {
        for (int j = i; j < M; j += i) {
            divisor[j].pb(i);
        }
    }
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        for (auto u : divisor[a[i]]) {
            multiple[u].pb(a[i]);
        }
    }
    inv[1] = 1;
    for (int i = 2; i < M; i++) {
        inv[i] = 1LL * (MOD - MOD / i) * inv[MOD % i] % MOD;
    }
    for (int i = 1; i < M; i++) {
        int sum1 = 0;
        int sum2 = 0;
        for (auto e : multiple[i]) {
            sum1 = (sum1 + e) % MOD;
            sum2 = (sum2 + 1LL * e * e) % MOD;
        }
        calc[i] = (1LL * sum1 * sum1 - sum2 + MOD) % MOD;
        calc[i] = 1LL * calc[i] * inv[2] % MOD;
    }
    w[1] = 1;
    for (int i = 2; i < M; i++) {
        for (auto e : divisor[i]) {
            if (e == i) continue;
            w[i] = (w[i] - w[e] + MOD) % MOD;
        }
        w[i] = (w[i] + inv[i]) % MOD; 
    }
    int ans = 0;
    for (int i = 1; i < M; i++) {
        ans = (ans + 1LL * w[i] * calc[i]) % MOD;
    }
    cout << ans;
    return 0;
}

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

using namespace std;

const int N = 100005;

int f[N];
vector <int> g[N];

int dfs(int u) {
	if (f[u] > 0) {
		return f[u];
	}
	int ans = 0;
	for (int i = 0; i < (int)g[u].size(); i++) {
		int v = g[u][i];
		ans = max(ans, 1 + dfs(v));
	}
	return f[u] = ans;
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    g[x].push_back(y);
  }
  for (int i = 0; i < n; i++) {
    f[i] = -1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] < 0) {
    	ans = max(ans, dfs(i));	
    }
  }
  printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8832
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> pos(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x--;
    pos[x] = i;
  }
  int ans = 1, cnt = 1;
  for (int i = 0; i + 1 < n; i++) {
    if (pos[i] < pos[i + 1]) cnt++;
    else cnt = 1;
    ans = max(ans, cnt);
  }
  cout << n - ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,k;
int main()
{
	cin >>n>>m>>k;
	cout <<max(0,k-(n-m));
	return 0;
}

Measured memory_bytes: 256
T = input();
P = input();
t = list(T);
p = list(P);
k = 0;
if(P in T):
    for j in range(0,len(t)-len(p)+1):
        k = 0;
        for i in range(0,len(p)):
            if t[j+i] == p[i]:
                k += 1;
        if k == len(p):
            print(j);
        


Measured memory_bytes: 5568
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for(int i = 1; i <= n; i++){
        double a = 1;
        int num = i;
        while(num < k){
            a /= 2;
            num *= 2;
        }
        ans += a;
    }
    ans /= n;
    cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

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

int main() {
  string s; cin >> s;
  char c1[1000],c2[1000];bool can = true;
  REP(i,s.size()) {
 c1[i] = s.at(i); c2[i] = s.at(i);
  }
  reverse(c2,c2+s.size());
  REP(i,s.size()){
  if(c1[i] == c2[i]) ;
  else  {cout << "No" << endl;
  can = false; break;
  }
  }
  if(can)cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def main():
    reverse_count = 0
    s = raw_input()
    for i in range(len(s)-1):
        c, n_c = s[i], s[i+1]
        if c != n_c:
            reverse_count += 1
    print reverse_count

if __name__ == '__main__':
    main()


Measured memory_bytes: 5892
#include <iostream>
#include <stdio.h>

int main() {
	int m;
	int d;	
	scanf("2019/%d/%d", &m, &d);
	if (m > 4) {
		std::cout << "TBD";
	}
	else {
		std::cout << "Heisei";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct dualsegtree{
	using F=function<T(T,T)>;
	const F lazycalcfn,updatefn;
	int n;
	T lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	dualsegtree(int n_=0,T defvalue=0,
		const F lazycalcfn_=[](T a,T b){return a+b;},
		const F updatefn_=[](T a,T b){return a+b;},
		T lazydefvalue_=0
	):lazydefvalue(lazydefvalue_),
		lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(n,defvalue);
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i]=v[i];
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			if(k<n-1)
			{
				lazy[k]=lazycalcfn(lazy[k],x);
				lazyflag[k]=true;
			}
			else dat[k-n+1]=updatefn(dat[k-n+1],x);
		}
		else
		{
			if(lazyflag[k])
			{
				update(0,n,lazy[k],k*2+1,l,(l+r)/2);
				update(0,n,lazy[k],k*2+2,(l+r)/2,r);
				lazy[k]=lazydefvalue;
				lazyflag[k]=false;
			}
			update(a,b,x,k*2+1,l,(l+r)/2);
			update(a,b,x,k*2+2,(l+r)/2,r);
		}
	}
	T query(int i)
	{
		T ret=dat[i];
		i+=n-1;
		while(i>0)
		{
			i=(i-1)/2;
			if(lazyflag[i])ret=updatefn(ret,lazy[i]);
		}
		return ret;
	}
};
int H,W;
main()
{
	cin>>H>>W;
	dualsegtree<int>P(W,0,
	[](int a,int b){return b;},
	[](int a,int b){return b;});
	vector<int>init(W);
	priority_queue<pair<int,pair<int,int> > >Q;
	for(int i=0;i<W;i++)
	{
		init[i]=i;
		Q.push(make_pair(0,make_pair(i,i)));
	}
	P.copy(init);
	for(int i=0;i<H;i++)
	{
		int L,R;cin>>L>>R;
		L--;
		int li,ri;
		{
			int l=-1,r=W;
			while(r-l>1)
			{
				int mid=(l+r)/2;
				if(P.query(mid)<L)l=mid;
				else r=mid;
			}
			li=r;
		}
		{
			int l=-1,r=W;
			while(r-l>1)
			{
				int mid=(l+r)/2;
				if(P.query(mid)<=R)l=mid;
				else r=mid;
			}
			ri=r;
		}
		P.update(li,ri,R);
		if(li<ri&&R<W)
		{
			Q.push(make_pair(-(R-(ri-1)),make_pair(ri-1,R)));
		}
		while(!Q.empty()&&P.query(Q.top().second.first)!=Q.top().second.second)Q.pop();
		if(Q.empty())cout<<-1<<endl;
		else cout<<i-Q.top().first+1<<endl;
	}
}


Measured memory_bytes: 12448
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, W;
    std::cin >> N >> W;

    struct Bag {
        int64_t weight;
        int64_t value;
    };

    std::vector<Bag> B;
    int64_t W0;
    for (decltype(N) i = 0; i < N; ++i) {
        Bag t;
        std::cin >> t.weight >> t.value;
        if (i == 0) {
            W0 = t.weight -1;
        }
        B.push_back(t);
        B.back().weight -= W0;
    }

    #include <boost/multi_array.hpp>

    boost::multi_array<int64_t, 3> memo(boost::extents[101][101][5*100]);
// const auto Y = memo.shape()[0];
// const auto X = memo.shape()[1];

    std::fill(memo.data(), memo.data() + memo.num_elements(), -1);

    for (auto p = memo.data(); p < (memo.origin() + memo.num_elements()); ++p) {
        std::cin >> *p;
    }


    auto f = [&memo,W0, N, W, &B](auto F, int64_t i, int64_t s, int64_t w) -> int64_t {

        if (memo[i][s][w] != -1) {
            return memo[i][s][w];
        }
        if (i == N) {
            return 0;
        }

        if (w + B[i].weight <= W - (s+1)*W0) {
            memo[i][s][w] = std::max(F(F, i+1, s+1, w+B[i].weight) + B[i].value, F(F, i+1, s, w));
        }
        else {
            memo[i][s][w] = F(F, i+1, s, w);
        }
        return memo[i][s][w];
    };

    auto val = f(f, 0, 0, 0);

    std::cout << val << std::endl;

    return 0;
}


Measured memory_bytes: 40064
import collections
n = int(input())
s = []
for _ in range(n):
    s.append(input())
sc = collections.Counter(s).most_common()
ans = []
ans.append(sc[0][0])
mn = sc[0][1]
for n in range(1, len(sc)):
    if sc[n][1] == mn:
        ans.append(sc[n][0])
    else:
        break
for anss in sorted(ans):
    print(anss)

Measured memory_bytes: 120016
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		Scanner sc= new Scanner (System.in);
		int n=Integer.parseInt(sc.nextLine());
		int num;
		int ori=2000000001;
		int answer=-2000000000;
		for(int i=0;i<n;i++){
			num = Integer.parseInt(sc.nextLine());
			if(i>0 && answer<num-ori){
				answer=num-ori;
			}
			if(ori>num){
				ori=num;
			}
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 169208
#include <cstdio>

#define gc getchar
#define pc putchar
#define sp pc(' ')
#define ln pc('\n')

template <class t>
inline void read(t &num) {
    register char c = gc();
    register bool flag = 0;
    num = 0;
    while ((c < '0' || c > '9') && c != '-') c = gc();
    if (c == '-') flag = 1, c = gc();
    while (c >= '0' && c <= '9') num = (num << 1) + (num << 3) + c -'0', c = gc();
    flag && (num = ~(num - 1));
}
template <class t>
inline void print(t num) {
    if (num < 0) pc('-'), num = ~(num - 1);
    if (num >= 10) print(num / 10);
    pc(num % 10 + '0');
}

const int N = 200005;
int fir[N], to[N * 2], nxt[N * 2], ecnt;
void add_edge(int u, int v) {
    to[++ecnt] = v;
    nxt[ecnt] = fir[u];
    fir[u] = ecnt;
}

int add[N];
int ans[N];

void dfs(int node, int fa, int val) {
    ans[node] = add[node] + val;
    for (int e = fir[node]; e; e = nxt[e]) {
        if (to[e] == fa) continue;
        dfs(to[e], node, ans[node]);
    }
}

int main() {
    int n, q;
    read(n);
    read(q);
    for (int i = 1; i < n; i++) {
        int a, b;
        read(a);
        read(b);
        add_edge(a, b);
    }
    while (q--) {
        int p, x;
        read(p);
        read(x);
        add[p] += x;
    }
    dfs(1, 0, 0);
    for (int i = 1; i <= n; i++) print(ans[i]), sp;
    ln;
}

Measured memory_bytes: 16384
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<cmath>
using namespace std;

int main() {
	long long n,s;cin>>n>>s;
	if(s>n){
		cout<<-1<<endl;
		return 0;
	}
	if(s==n){
		cout<<s+1<<endl;
		return 0;
	}
	long long ans,def;
	def=1;
	for(int i=0;i<12;i++){
		def*=10;
	}
	ans=def;
	long long bm=n;
	if(n>10000){
		for(long long a=1;a<=sqrt(n);a++){
			if((n-s)%a==0){
				long long b=(n-s)/a+1;
				if((b>a)*(b>s-a)*(s>=a)){

					ans=b;
//					cout<<b<<' '<<a<<endl;
				}
			}
		}
		bm=sqrt(n);
	}
	for(long long b=bm;b>1;b--){
		long long sum=0;
		long long num=n;
		while(b<=num){
			sum+=num%b;
			num/=b;
			if(b==213){
//				cout<<sum<<' '<<num<<endl;
			}
		}
		sum+=num;
		if(sum==s){
			ans=b;
		}
	}

	if(ans<def){
		cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
	return 0;
}

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

int main() {
    int a;
    int b;
    int c;
    int d;
 
   cin >> a >> b >> c >>d;
  
   int left = a + b;
  
   int right = c + d;
  
   if (right > left){
     
      cout << "Right" << endl;
    
     
   }else if(right == left){
     
      cout << "Balanced" << endl;
     
   }else{
    
      cout << "Left" << endl;
   }
  
   
  
  return 0;
}

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

ll k, m = 0, n;
ll t[1 << 17], d[1 << 17];
vector<ll> u, v;

int main()
{
    cin >> n >> k;
    if (n % 2 == 0)
    {
        if (n / 2 >= k)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    else
    {
        if ((n + 1) / 2 >= k)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    String elem[] = scan.nextLine().split(" ");

    int nbCity = Integer.parseInt(elem[0]);
    int nbRoad = Integer.parseInt(elem[1]);

    int[] connexion = new int[nbCity];

    for (int i = 0; i < nbRoad; i++){
        String[] connect = scan.nextLine().split(" ");
        if (Integer.parseInt(connect[0]) <= connexion.length){
          connexion[Integer.parseInt(connect[0]) - 1]++;
        }
        if (Integer.parseInt(connect[1]) <= connexion.length){
          connexion[Integer.parseInt(connect[1]) - 1]++;
        }
    }

    for (int i = 0; i < nbCity; i++){
      System.out.println(connexion[i]);
    }

  }
}


Measured memory_bytes: 21972
def readInt():
    return list(map(int, input().split()))
    
h_1, m_1, h_2, m_2, k = readInt()
t_1 = h_1*60 + m_1
t_2 = h_2*60 + m_2
# print(t_1, t_2)
w_t = t_2 - t_1
print(w_t-k)

Measured memory_bytes: 61632
//#define LOCAL

#include <cstdio>

int a[110];

void trace(int n) {
	for(int i=0; i<n; ++i) {
		if(i > 0) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
}

int main()
{
	#ifdef LOCAL
		freopen("E:\\Temp\\input.txt", "r", stdin);
		freopen("E:\\Temp\\output.txt", "w", stdout);
	#endif 

	int i, j, n, v;
	scanf("%d", &n);
	for(i=0; i<n; ++i) scanf("%d", &a[i]);
		trace(n);

	for(i=1; i<n; ++i) {
		v = a[i];
		for(j=i-1; a[j] > v; --j)
			a[j+1] = a[j];
		a[j+1] = v;
		trace(n);
	}

	return 0;
}

Measured memory_bytes: 2756