akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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 main(){
  int N,K;
  cin >> N >> K;
  vector<bool> D(11,false);
  for(int i=0; i<K; i++){
    int d;
    cin >> d;
    D[d] = true;
  }
  int ans;
  for(int i=N; i<=1000000; i++){
    int t = i;
    bool can = true;
    while(t){
      if(D[t%10]){
        can = false;
      }
      t /= 10;
    }
    if(can){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int max=a;
    if(b>=a&&b>=c){
        max=b;
    }   
    if(c>=b&&c>=a){
        max=c;
    }
    cout<<a+b+c-max<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long n,a,b,m,c;
  scanf("%ld",&n);
  scanf("%ld",&a);
  scanf("%ld",&b);
  c=a+b;
  m=(n/c)*a;
  if(n%c<=a){
    printf("%ld",m+(n%c));
  }else{
    printf("%ld",m+a);
  }
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>

using namespace std;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    string s;
    cin >> s;
    int ans;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
        ans = 3;
    } else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) {
        ans = 2;
    } else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
        ans = 1;
    } else {
        ans = 0;
    }
    cout << ans << endl;
}


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

int main() {
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    vector<ll> tra = {a,b,c,d,e};
    ll mi = 20000000000000000;
    for(int i=0; i<5; i++){
        mi = min(mi,tra.at(i));
    }
    if(n%mi == 0) cout << n/mi + 4 << endl;
    else cout << n/mi + 5 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
using namespace std;
typedef long long unsigned int ll;

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

#define INF (1e9)
#define PI  (acos(-1))




int main()
{
	int N;
	cin >> N;
	int i, j ,a , max = 0;
	vector<int> num;

	rep(i, N) {
		cin >> a;
		num.push_back(a);
		if (max < a) max = a;
	}
	
	bool b = true;

	FOR(i, 1 ,max) {
		b = true;
		rep(j, N) {
			if (num.at(j) % i != 0) {
				b = false;
				break;
			}
		}
		if(b)
			cout << i << endl;
	}

	return 0;


}




Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1e5+5;
int pos[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,x,m;
	cin>>n>>x>>m;
	vector<ll> v;
	while(1)
	{
		v.pb(x);
		pos[x] = sz(v)-1;
		x = (x*x)%m;
		if(pos[x])
			break;
	}
	ll stc = pos[x];
	ll len = sz(v)-stc;
	ll res = 0;
	for(int i=0;i<stc;i++)
	{
		res += v[i];
		n--;
		if(n==0)
			break;
	}
	ll tot = 0;
	for(int i=stc;i<sz(v);i++)
		tot += v[i];	
	res += tot*(n/len);
	for(int i=0;i<n%len;i++)
		res += v[stc+i];
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 4272
n = int(input())
coins = [4, 7]
m = len(coins)
dp = [[False for j in range(n + 1)] for i in range(m + 1)]
dp[0][0] = True

for i in range(1, m + 1):
    for j in range(0, n + 1):
        dp[i][j] = dp[i - 1][j]
        if j - coins[i - 1] >= 0:
            dp[i][j] |= dp[i][j - coins[i - 1]]

print('Yes' if dp[m][n] else 'No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int M=1000000007;
int dp[100010][15];
string s;
int n,a[100010];
int main()
{
	cin>>s;
	int n=s.size();
	dp[0][0]=1;
	for(int i=0;i<n;++i) {
		a[i]=-1;
		if(s[i]>='0'&&s[i]<='9') a[i]=s[i]-'0';
	}
	for(int i=0;i<n;++i) {
		for(int j=0;j<13;++j) {
			if(a[i]>=0)
				dp[i+1][(j*10+a[i])%13]=(dp[i+1][(j*10+a[i])%13]+dp[i][j])%M;
			else {
				for(int k=0;k<=9;++k)
					dp[i+1][(j*10+k)%13]=(dp[i+1][(j*10+k)%13]+dp[i][j])%M;
			}
		}
	}
	printf("%d",dp[n][5]);
	return 0;
}

Measured memory_bytes: 6684
n,m,k = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = [0]*(n+1)
b = [0]*(m+1)
for i in range(n):
    a[i+1] = a[i] + A[i]
    
for i in range(m):
    b[i+1] = b[i] + B[i]

ans = 0
j = m
for i in range(n+1):
    if a[i] > k:
        break
    
    while b[j] > k-a[i]:
        j -= 1
    
    ans = max(ans,i+j)
    
print(ans)

Measured memory_bytes: 114508
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

vector<int> to[100];
bool used[100];

void addEdge(int a, int b) {
    to[a].push_back(b);
    to[b].push_back(a);
}

int dfs(int v) {
    int ret = 1;
    used[v] = true;
    for (int i=0; i<(int)to[v].size(); ++i) {
        if ( ! used[to[v][i]]) {
            ret = max(ret, 1 + dfs(to[v][i]));
        }
    }
    used[v] = false;
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        fill(to, to+100, vector<int>());
        int a, b;
        for (int i=0; i<n; ++i) {
            cin >> a >> b;
            --a, --b;
            addEdge(a, b);
        }
        int ret = 0;
        for (int i=0; i<100; ++i) {
            memset(used, false, sizeof used);
            ret = max(ret, dfs(i));
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
listA= list(input())
alphaL = [chr(i) for i in range(97, 97+26)]

index=0
while index < len(listA):
    if listA[index] in alphaL:
        alphaL.remove(listA[index])
    index+=1

if alphaL==[]:
    print("None")
else:
    print(alphaL[0])

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define all(a)                      a.begin(), a.end()
#define pb                          push_back
#define ll							long long
#define index(a)            		order_of_key(a)
#define value(a)					find_by_order(a)
#define count_1 					__builtin_popcount
#define mod(x, m)					((((x) % (m)) + (m)) % (m))
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	ll h[n+1],dp[n+1];
	for(int i=1;i<=n;i++){cin>>h[i];dp[i]=INT_MAX;}
	dp[1]=0;
	dp[0]=INT_MAX;
	
	for(int i=2;i<=n;i++){
		ll m=INT_MAX;
		for(int j=1;j<=k;j++){
			if(i-j>=0)
			m=min(m,dp[i-j]+abs(h[i]-h[i-j]));
		}
		dp[i]=m;
	}
//	for(int i=0;i<=n;i++)cout<<dp[i]<<" ";
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
http://abc068.contest.atcoder.jp/tasks/abc068_b
"""
from math import log

def solve(N):
    # N以下の2^n乗を求める
    flp2 = 2 ** int(log(N, 2))
    return flp2


def main():
    N = int(input())
    result = solve(N)
    print(result)


if __name__ == '__main__':
    main()
    

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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, l, r;	cin >> n >> l >> r;
	int ans = n;
	while (n--){
		int x;	cin >> x;
		if (l <= x && x < r)	ans--;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
use std::f64::consts::PI;
use proconio::input;

fn main() {
        input! {
                a: f64,
                b: f64,
                h: f64,
                m: f64,
        }

        let h_angle = 2.0 * PI * h / 12.0 + 2.0 * PI / 12.0 * m / 60.0;
        let m_angle = 2.0 * PI * m / 60.0;
        let angle   = (h_angle - m_angle).abs();
        let ans =  a * a + b * b - 2.0 * a * b * angle.cos();
        println!("{}", ans.sqrt());
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        string s,t;
        cin>>s>>t;
        int n,m;
        n = s.length();
        m = t.length();
        int ans = m;
        for(int i=0;i<n;i++)
        {
            string chk = s.substr(i,m);
            if(chk.length() < m)break;
            int now = 0;
            for(int j=0;j<m;j++)now += chk[j] != t[j];
            ans = min(ans,now);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 20 + 10;
int a[maxn];
int main(void)
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 2; i < n; ++i) {
		if (a[i] > a[i - 1] && a[i] < a[i + 1])
			ans++;
		if (a[i] < a[i - 1] && a[i] > a[i + 1])
			ans++;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, Q = LI()
s_list = []
t_list = []
for i in range(A):
  s_list.append(II())
for j in range(B):
  t_list.append(II())
x_list = []
for q in range(Q):
  x_list.append(II())
  
import bisect
for x in x_list:
  # x の左右で最も近い神社と寺をそれぞれ探しておく
  # bisectが0の場合は左はなく、len(x)の場合は
  tidx = bisect.bisect_left(t_list, x)
  if tidx == 0:
    tl = 9*10**11
  else:
    tl = t_list[tidx-1]
  if tidx == len(t_list):
    tr = 9*10**11
  else:
    tr = t_list[tidx]

  sidx = bisect.bisect_left(s_list, x)
  if sidx == 0:
    sl = 9*10**11
  else:
    sl = s_list[sidx-1]
  if sidx == len(s_list):
    sr = 9*10**11
  else:
    sr = s_list[sidx]

  dsl = abs(x-sl)
  dsr = abs(x-sr)
  dtl = abs(x-tl)
  dtr = abs(x-tr)

  print(min(max(dsl, dtl), max(dsr, dtr), dsl+dtr+min(dsl, dtr), dsr+dtl+min(dsr,dtl)))
  

Measured memory_bytes: 16164
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll TMOD = 2*MOD;
const int MAX_N = 100000;
ll fact[MAX_N + 1];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans;
    fact[0] = 0;
    fact[1] = 1;
    ll fs = 1;
    for (int i = 2; i < MAX_N + 1; i++){
        fs = (fs*i) % TMOD;
        fact[i] = (fact[i-1] + fs) % TMOD;
    }
    while (1){
        int N, R;
        cin >> N;
        if (N == 0) break;
        vector<int> word(N);
        for (int i = 0; i < N; i++) word[i] = i;
        word.push_back(0);
        ans = 0;
        cin >> R;
        vector<int> s(2*R+2, 0);
        s[2 * R + 1] = N;
        for (int i = 0; i < R; i++){
            cin >> s[i] >> s[i+R];
            s[i]--; s[i+R]--;
            s.push_back(s[i] + 1);
            s.push_back(s[i+R] + 1);
            swap(word[s[i]], word[s[i+R]]);
        }
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        for (int i = 0, R = s.size() - 1; i < R; i++){
            ans =(ans + word[s[i]] * (fact[N - s[i] - 1] - fact[N - s[i+1] - 1] + TMOD)) % TMOD;
            int dif = s[i+1] - s[i];
            for (int j = i + 1; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i]] ? dif : 0);
            }
        }
        cout << ans % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 2792
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
    	FastIO sc = new FastIO(System.in);
    	PrintWriter out = new PrintWriter(System.out);
    	long x = sc.nextLong();
    	long curr = 100;
    	int cnt = 0;
    	while(curr<x) {
    		curr+=curr/100;
    		cnt++;
    	}
    	System.out.println(cnt);
    	out.close();
    }
    static class FastIO {
		 
		// Is your Fast I/O being bad?
 
		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;
 
		public FastIO(String fileName) throws IOException {
			dis = new FileInputStream(fileName);
		}
 
		public FastIO(InputStream is) throws IOException {
			dis = is;
		}
 
		int nextInt() throws IOException {
			int ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
 
			return (negative) ? -ret : ret;
		}
 
		long nextLong() throws IOException {
			long ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
 
			return (negative) ? -ret : ret;
		}
 
		byte nextByte() throws IOException {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}
 
		String next() throws IOException {
			StringBuffer ret = new StringBuffer();
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}
 
			return ret.toString();
		}
 
	}
}

Measured memory_bytes: 32748
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N = lread();
    auto S = sread();
    long K = lread();
    char C = S[K - 1];
    foreach (c; S)
    {
        write(c == C ? C : '*');
    }
    writeln();
}


Measured memory_bytes: 256
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
int_list=[int(input()) for i in range(n)]

check = [0]*9
tmp = 0

for j in range(3):
    for i in range(n):
        if(int_list[i] == a1[j]):
                check[tmp] = 1
    tmp += 1

for j in range(3):
    for i in range(n):
        if(int_list[i] == a2[j]):
                check[tmp] = 1
    tmp += 1

for j in range(3):
    for i in range(n):
        if(int_list[i] == a3[j]):
                check[tmp] = 1
    tmp += 1

test = 0

if(check[0] == 1 and check[1] == 1 and check[2] == 1):
        test = 1
if(check[3] == 1 and check[4] == 1 and check[5] == 1):
        test = 1
if(check[6] == 1 and check[7] == 1 and check[8] == 1):
        test = 1
if(check[0] == 1 and check[3] == 1 and check[6] == 1):
        test = 1
if(check[1] == 1 and check[4] == 1 and check[7] == 1):
        test = 1
if(check[2] == 1 and check[5] == 1 and check[8] == 1):
        test = 1
if(check[0] == 1 and check[4] == 1 and check[8] == 1):
        test = 1
if(check[2] == 1 and check[4] == 1 and check[6] == 1):
        test = 1


if(test == 1):
    print("Yes")
else:
    print("No")


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())

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

const int MAXN = 1e5 + 5;

int sol;
int a[MAXN];

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

  int n; cin >> n;

  REP(i, n) cin >> a[i];
  sort(a, a + n);

  int mx = a[n - 1];
  sol = 0;

  REP(i, n) {
    if(abs(a[i] * 2 - mx) < abs(mx - sol * 2)) {
      sol = a[i];
    }
  }

  cout << mx _ sol << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int A, B, T;

  std::cin >> A >> B >> T;

  std::cout << (T / A) * B << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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 main(){
    ll n; cin>>n;
    vector<ll> col={-1};
    rep(i,n){
        ll a; cin>>a;
        ll len=col.size();
        if(col[0]<a){
            col[0]=a;
        }else{
            ll left=0, right=len;
            while(right-left>1){
                ll mid=(left+right)/2;
                if(col[mid]>=a) left=mid;
                else right=mid;
            }
          	if(right==len) col.push_back(a);
            else col[right]=a;
        }
        //rep(j, col.size()) cout<<col[j]<<' ';
    }
    cout<<col.size()<<endl;
    return 0;
}


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

int main(){
	int N,Y,i=0,j=0,k=0,w=0;

	cin >> N >> Y;

	for(i=0;i<=N;i++){
		for(j=0;j<=N-i;j++){
			for(k=0;k<=N-i-j;k++){
				if((10000*i+5000*j+1000*k==Y)&&(i+j+k==N)){
					cout << i << " " << j << " " << k;
					w++;
					break;
				}
			}
			if(w!=0) break;
		}
		if(w!=0) break;
	}
				
	if(w==0) cout << "-1 -1 -1";
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <iterator>
using namespace std;
int d[100100];
int main(){
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>d[i];
	}
	for(int i=1;i<=n;i++){
		int cn=d[i];
		if(d[cn]==i){
			ans++;
		}
	}
	cout<<ans/2<<endl;
	return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

int main(){
	string s;
	cin >> s;
	long long n = s.size();
	long long a[30]={};
	for(int i=0;i<n;i++){
		a[s[i]-'a']+=1;
	}
	long long ans=0;
	for(int i=0;i<30;i++){
		ans += a[i]*(n-a[i]);
	}
	cout << ans/2+1 << endl;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
S = [list(input()) for _ in range(2)]
prev = S[0][0] == S[1][0]
if prev:
    x = 3
    i = 1
else:
    x = 6
    i = 2
while i < N:
    nxt = S[0][i] == S[1][i]
    i += 1 if nxt else 2
    if prev and nxt:
        x *= 2
    elif prev:
        x *= 2
    elif nxt:
        x = x
    else:
        x *= 3
    prev = nxt
print(x % (10**9+7))

Measured memory_bytes: 9144
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include <cstdio>
#include<map>
#include<string>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ll long long
#define ld long double
#define rep(i,m)   for(int i=0;i<m;i++)
#define repp(s,i,m)   for(int i=s;i<m;i++)
#define mkp make_pair
using namespace std;
const int mod = 1000000007;
const int N = 1000005;
class cmp{
public:
	bool operator() (ll &A, ll &B){
		if (A > B) return true;
		return false;
	}
};
int main()
{
	Amr_Abdelazim
		ll n,k,ans=0;
	cin >> n;
	vector<ll>v(n+1),b(n);
	rep(i, n+1)cin >> v[i];
	rep(i, n)cin >> b[i];
	rep(i, n){
		ll mn = min(b[i], v[i]);
		ans += mn;
		v[i] -= mn;
		b[i] -= mn;
		if (v[i] == 0){
			mn = min(b[i], v[i+1]);
			ans += mn;
			v[i+1] -= mn;
			b[i] -= mn;
		}
	}
	cout << ans << "\n";
		return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
    tree_order_statistics_node_update> ost;

const int N=110000;
const int INFTY=2e9;
vpii adj[N];
int n, p[N], found=0;
ll ans, w[N];

void dfs1(int x, int u) {
    w[x]=1;
    p[x]=u;
    for(auto z:adj[x]) if(z.fs!=u) {
        int y=z.fs;
        dfs1(y, x);
        w[x]+=w[y];
        ans+=z.sc*2*min(w[y], n-w[y]);
        if(2*w[y]==n) ans-=z.sc, found=1;
    }
}

int dfs2(int x) {
    for(auto z:adj[x]) if(z.fs!=p[x]) {
        int y=z.fs;
        if(2*w[y]>n) return dfs2(y);
    }
    return x;
}

int main() {
    int i, u, v, t;
    scanf("%d", &n);
    for(i=0; i<n-1; i++) {
        scanf("%d%d%d", &u, &v, &t);
        adj[u].pb(pii(v, t));
        adj[v].pb(pii(u, t));
    }
    dfs1(1, 0);
    if(!found) {
        u=dfs2(1);
        t=INFTY;
        for(auto z:adj[u]) t=min(t, z.sc);
        ans-=t;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 13824
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define x first
#define y second
#define sz(a) ((int)(a.size()))
const int mod = 1812447359;
const int mod2 = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const int MAX = 200005;
const int ZSUV = 10 * 1000 * 1000;
int d[505][505];
int used[505][505];
int dx[4] = {1 , 0, -1 , 0};
int dy[4] = {0 , 1 , 0 , -1};
void dfs(int r, int c, int val)
{
	d[r][c] = val;
	for(int i = 0; i < 4; i++)
	{
		int newR = r + dx[i];
		int newC = c + dy[i];
		if(used[newR][newC] && d[newR][newC] > val + !used[r][c])
			dfs(newR, newC, val + !used[r][c]);
		if(!used[newR][newC] && d[newR][newC] > val + !used[r][c])
			dfs(newR, newC, val + !used[r][c]);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int ans = 0;
	vector<int> a(n * n);
	for(auto &x : a)
		cin >> x;
	//reverse(a.begin() , a.end());
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			d[i][j] = min({i - 1, n - i, j -1 , n - j});
	for(auto x : a)
	{
		x--;
		int r = x / n , c = x % n;
		r++;c++;
		used[r][c] = 1;
		dfs(r , c , d[r][c]);
		ans += d[r][c];
	}
	cout << ans;
}


Measured memory_bytes: 25444
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();
		int c = sc.nextInt();
		int d = sc.nextInt();
		boolean win = false;
		while (a > 0 || b > 0) {
			c -= b;
			if (c <= 0) {
				win = true;
				break;
			}
			a -= d;
			if (a <= 0) {
				break;
			}
		}
		if (win) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35772
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef double db;
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define SZ(x) (int)(x.size())
#define sci(x) scanf("%d",&(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define syn ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll modpow(ll x,ll n,ll mod){ll res=1;for(;n;n>>=1,x=x*x%mod)if(n&1)res=res*x%mod;return res;}
const db eps=1e-8,PI=acos(-1.0);
const int N=2e5+10,M=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;//998244353
int k,c;
ll v,x,y;
priority_queue<ll,vector<ll>,greater<ll> >q;
int main(){
	sci(k);
	rep(i,1,9)q.push(i);
	while(!q.empty()&&k){
		v=q.top();q.pop();
		c++;
		if(c==k){
			printf("%lld\n",v);
			break;
		}
		x=v*10;y=v%10;
		if((int)q.size()<k)q.push(x+y);
		if(y && (int)q.size()<k)q.push(x+y-1);
		if(y!=9 && (int)q.size()<k)q.push(x+y+1);
	}
    return 0;
}

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

int main() {
  int N, a, ans = 0;
  cin >> N;
  if (N % 2 == 0) {
    a = N / 2 - 1;
  }
  else {
    a = N / 2;
  }
  vector<int>b(N + 1);
  for (int i = 0; i <= a; i++) {
    for (int j = 1; j <= i * 2 + 1; j++) {
      if ((i * 2 + 1) % j == 0) {
        b.at(i * 2 + 1)++;
      }
    }
    if (b.at(i * 2 + 1) == 8) {
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)

	if n%2 != 0 {
		fmt.Println(0)
		return
	}

	ans := 0
	divisor := 5
	for divisor <= n/2 {
		ans += n / 2 / divisor
		divisor *= 5
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
    int a,b,c;
    cin >> a >>b >>c;
    if(a ==b && b != c){
        cout << "Yes" << endl;
    }else if(b == c && c != a){
         cout << "Yes" << endl;
    }else if(c == a && a !=b ){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B, C, X;
	std::cin >> A >> B >> C >> X;

	int result = 0;
	for (int a = 0; a <= A; ++a) {
		for (int b = 0; b <= B; ++b) {
			for (int c = 0; c <= C; ++c) {
				if (a*500 + b*100 + c*50 == X) {
					++result;
				}
			}
		}
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br
		= new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String buf;
			if((buf=br.readLine())==null)break;
			if(buf.length()==0)break;
			int d=Integer.parseInt(buf);
			int s=0;
			for(int i=0;i<(600/d);i++){
				s+=(d)*Math.pow((d*i),2);
			}
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 9368
/**
* Sources: various
*/

#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
template<typename T>
ostream& operator<< (ostream& out, const pair<T, T>& v) {
    out << "{" << v.first << ", " << v.second << "}";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    out << "[";
    size_t last = v.size() - 1;
    for(size_t i = 0; i < v.size(); ++i) {
        out << v[i];
        if (i != last) 
            out << ", ";
    }
    out << "]";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const set<T>& v) {
    out << "[";
    auto pen = v.end();
    pen--;
    for (auto it = v.begin(); it != v.end(); it++){
		out << *it;
		if (it != pen){
			out << ", ";
		}
	}
	out << "]";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const Tree<T>& v) {
    out << "[";
    auto pen = v.end();
    pen--;
    for (auto it = v.begin(); it != v.end(); it++){
		out << *it;
		if (it != pen){
			out << ", ";
		}
	}
	out << "]";
    return out;
}
vector<int> v;
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N; cin >> N;
	for (int i = 0; i < N; i++){
		int k; cin >> k; v.push_back(k);
	}
	sort(all(v));
	int top = v[N - 1];
	int bes = -1;
	for (int i = 0; i < N - 1; i++){
		if (abs(top - 2*v[i]) < abs(top - 2*bes)){
			bes = v[i];
		}
	}
	cout << top << ' ' << bes << endl;
}

// read!read!read!read!read!read!read!
// ll vs. int!


Measured memory_bytes: 892
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define pb push_back
using namespace std;
void solve(){
    int n,c=0;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.length()-2;i++)
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
    c++;
    cout<<c;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 3596
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;
const int N=1e5+5;

pair<int,int> tree[4*N];
int a[N],track[N];
vector<int> v[N];

pair<int,int> mrg(pair<int,int> a,pair<int,int> b)
{
    if(a.F>b.F)
        return a;

    if(a.F==b.F)
    {
        if(a.S<=b.S)
            return a;
    }

    return b;

}

void build(int node,int beg,int en)
{
    if(beg==en)
    {
        tree[node].F=a[beg];

        if(a[beg])
            tree[node].S=beg;
        else
            tree[node].S=0ll;
        return;
    }

    int mid=(beg+en)/2;
    build(2*node,beg,mid);
    build(2*node+1,mid+1,en);

    tree[node]=mrg(tree[2*node],tree[2*node+1]);
}

void update(int node,int start,int en,int idx)
{if(start==en)
 {
  if(track[idx]<v[idx].size())
  {
      a[idx]=tree[node].F=v[idx][track[idx]],++track[idx];
  }
  else
    a[idx]=tree[node].F=0ll,tree[node].S=0ll;
 }
 else
 {int mid=(start+en)/2;
  if(start<=idx and idx<=mid)
  update(2*node,start,mid,idx);
  else
  update(2*node+1,mid+1,en,idx);
  tree[node]=mrg(tree[2*node],tree[2*node+1]);
 }
}

pair<int,int> query(int node,int start,int en,int l,int r)
{if(r<start or en<l)
 return make_pair(0,0);
 if(l<=start and en<=r)
 return tree[node];
 int mid=(start+en)/2;
 pair<int,int> p1=query(2*node,start,mid,l,r);
 pair<int,int> p2=query(2*node+1,mid+1,en,l,r);
 return mrg(p1,p2);
}

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

    int x,y;
    for(int i=0;i<n;++i)
    {
        cin>>x>>y;
        v[x].pb(y);
    }

    mem(a,0);
    mem(track,0);
    for(int i=1;i<=m;++i)
    {
        sort(all(v[i]));
        reverse(all(v[i]));

        if(v[i].size())
        a[i]=v[i].front(),track[i]=1;
    }

    //for(int i=1;i<=m;++i)
    //    cout<<a[i]<<" ";
    //cout<<"\n";

    build(1,1,m);

    //cout<<"\n";
    //for(int j=1;j<=4*m;++j)
    //    cout<<tree[j].F<<" "<<tree[j].S<<"\n";

    int ans=0;
    pair<int,int> p;
    for(int i=1;i<=m;++i)
    {
        p=query(1,1,m,1,i);
        ans+=p.F;

        //cout<<p.F<<" "<<p.S<<"--\n";

        if(p.S)
        update(1,1,m,p.S);

        //cout<<"\n";
        //for(int j=1;j<=4*m;++j)
        //    cout<<tree[j].F<<" "<<tree[j].S<<"\n";
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}



Measured memory_bytes: 11520
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main(void){
    int minA = pow(10,9) + 1;
    int num = 0;
    
    int n,t,f = 0;
    cin >> n >> t;
    vector<int> A(n);
    
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    
    for(int i = 0; i < n; i++){
        if(minA > A[i]){
            minA = A[i];
        }else{
            
            if(f == A[i] - minA)num++;
            else if(f < A[i] - minA){
                num = 1;
                f = A[i] - minA;
            }
            
        }
    }
    
    cout << num << endl;
    
    
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	static int[] f=new int[112345];
	static long[] sz=new long[112345];
	static int[] lose=new int[112345];
	public static class edge implements Comparable<edge> {
		int u,v,w;
		@Override
		public int compareTo(edge o) {
			return w-o.w;
		}
	}
	public static int F(int x) {
		return x==f[x]?x:(f[x]=F(f[x]));
	}
	public static void U(int x,int y,int w) {
		int fx=F(x),fy=F(y);
		if (fx==fy) {
			//System.out.printf("1: %d %d %d\n",x,y,w);
			if (w>sz[fx]) ++lose[fx];
			return;
		}
		//System.out.printf("2: %d %d %d\n",x,y,w);
		sz[fx]+=sz[fy];
		f[fy]=fx;
		if (w<=sz[fx]) lose[fx]=0;
		else lose[fx]+=lose[fy]+1;
		return;
	}
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int m=in.nextInt();
		edge[] e=new edge[m];
		long tot=0;
		for (int i=1;i<=n;++i) {
			sz[i]=in.nextLong();
			f[i]=i;
			tot+=sz[i];
		}
		for (int i=0;i<m;++i) {
			e[i]=new edge();
			e[i].u=in.nextInt();
			e[i].v=in.nextInt();
			e[i].w=in.nextInt();
		}
		Arrays.sort(e,0,m);
		for (int i=0;i<m;++i) U(e[i].u,e[i].v,e[i].w);
		System.out.println(lose[F(1)]);
	}
}

Measured memory_bytes: 112040
# include <bits/stdc++.h>
# define int long long
# define endl "\n"
using namespace std;

void solve() {

	int n;
	cin >> n;
	string s;
	cin >> s;
	int i = 0, j = n - 1, count = 0;
	while (i < j) {
		if (s[i] == 'R') {
			i++;
		}
		else if (s[j] == 'W') {
			j--;
		}
		else {
			i++;
			j--;
			count++;
		}
	}
	cout << count << endl;
}
signed main() {

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

# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif

	// int t;
	// cin >> t;
	// while (t--)
	solve();

	return 0;
}

Measured memory_bytes: 3772
#include<iostream>
#include<math.h>
using namespace std;

int main(void) {
	int n;
	long a;
	bool flag_inc, flag_dec;
	flag_inc = flag_dec = false;
	cin >> n;
	
	int ans = 1;
	long pivot;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (i == 0) {
			pivot = a;
		}
		else {
			if (pivot > a) {
				if (flag_dec) {
					ans++;
					flag_dec = false;
				}
				else {
					flag_inc = true;

				}
			}
			else if (pivot < a) {
				if (flag_inc) {
					ans++;
					flag_inc = false;
				}
				else {
					flag_dec = true;
				}
			}
		}
		pivot = a;
	}

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

Measured memory_bytes: 256
class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 1 << ((self.n - 1).bit_length())
        self.op = op # operation
        self.e = e # identity element
        self.v = self._build(lst)
        
    def _build(self, lst):
        # construction of a tree
        # total 2 * self.N - 1 elements
        tree = [self.e] * (self.N - 1) + lst + [self.e] * (self.N - self.n)
        for i in range(self.N - 2, -1, -1):
            tree[i] = self.op(tree[2*i + 1], tree[2*i + 2])
        return tree
    
    def __getitem__(self, i):
        return self.v[i + self.N - 1]
    
    # update a_i to be x 
    def update(self, i, x):
        i += self.N - 1
        self.v[i] = x
        while i > 0:
            i -= 1; i >>= 1
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2])
    
    # returns answer for the query interval [l, r)
    def query(self, l, r):
        left = l + self.N - 1
        right = r + self.N - 1
        L = self.e; R = self.e
        while left < right:
            if left & 1 == 0: # self.v[left] is the right child
                L = self.op(L, self.v[left])
                left += 1
            if right & 1 == 0: # self.v[right-1] is the left child
                right -= 1
                R = self.op(self.v[right], R)
            left -= 1; left >>= 1
            right >>= 1
        return self.op(L, R)

def coord_compress(A):
    B = {a: i for i, a in enumerate(sorted(set(A)))}
    return [B[a] for a in A]
    
N = int(input())
*H, = map(int, input().split())
*A, = map(int, input().split())

H = coord_compress(H)
dp = SegmentTree([0] * len(H), max, 0)
for h, a in zip(H, A):
    dp.update(h, max(dp[h], dp.query(0, h) + a))
print(max(dp))

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

int main() {
    string s, t;
    cin >> s;
    cin >> t;
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s.at(i) != t.at(i)) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3840
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<=0&&b>=0) printf("Zero");
	else if(a>0) printf("Positive");
	else if(b<0)
	if((b-a+1)%2==0)  printf("Positive");
	else printf("Negative");
	return 0; 
} 

Measured memory_bytes: 128
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < N; i++) sum -= sc.nextInt() - sc.nextInt() - 1;
		System.out.println(sum);
	}
}

Measured memory_bytes: 25700
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back
ll n = 5*pow(10, 15);

int main() {
  string s;
  ll k;
  char ans = '1';
  cin >> s >> k;
  
  for(char c: s){
      if (c == '1') k--;// 1だと5000兆日たってもダメ
      else { 
        ans = c;
        break; 
      }

      if(k <= 0) break; 
    }
  
  cout << ans << endl;

}


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

int main() {
    long long l[86];
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i < 87; i++) {
        l[i] = l[i-1] + l[i-2];
    }

    int n;
    cin >> n;
    cout << l[n] << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>

int main(){
  	int N, sum = 0, S1 = 0, S2 = 0, min = 0, tmp = 0;
  	int w[100];
	scanf("%d\n",&N);
  	for(int i = 0; i < N; i++){
    	scanf("%d ",&w[i]);
      	sum += w[i];
    }
  	
  	min = sum - w[0];
  	if(min >= 0){
    
    }else{
    	min = -1*min;
    }
  	for(int i = 0; i < N; i++){
    	S1 += w[i];
      	S2 = sum - S1;
      	if(S1 >= S2){
        	tmp = S1 - S2;
        }else{
        	tmp = S2 - S1;
        }
      	
      	if(min >= tmp){
        	min = tmp;
        }
    }
  
  	printf("%d\n",min);
	return 0;
}

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


int main(){
  int n;
  int A[110];
  int total1 = 0;
  int total2 = 0;
  cin >> n;
    for(int i = 0;i<n;i++){
    cin >> A[i];
  }
  sort(A,A+n,greater<int>());
  

  
  for(int i = 0;i<n;i++){
  if(i % 2 == 0){
    total1 += A[i];
  }else{
    total2 += A[i];
  }
  }
  cout << total1 - total2 << endl;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int N = in();

	vi a(N);

	REP(i, N) {
		cin >> a[i];
	}

	sort(ALL(a));

	cout << (int)fabs(a.back() - a[0]) << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++) cin >> s.at(i);
  int M;
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < M; i++) cin >> t.at(i);
  
  int Money = 0;
  for(int i = 0; i < N; i++){
    int temp = 0;
    for(int j = 0; j < N; j++){
      if(s.at(i) == s.at(j)) temp += 1;
    }
    for(int j = 0; j < M; j++){
      if(s.at(i) == t.at(j)) temp -= 1;
    }
    if(temp > Money) Money = temp;
  }
  cout << Money << endl;
}

Measured memory_bytes: 256
s = list(input())
if s[0] == "0":
    s[0] = ''
if s[2] == "0":
    s[2] = ''
x = int(s[0]+s[1])
y = int(s[2]+s[3])

if (x <= 12 and x >= 1) and (y >=1 and y <=12):
    print("AMBIGUOUS")

elif(x >= 0 and (y >= 1 and y <= 12)):
    print("YYMM")

elif(y >= 0 and (x >= 1 and x <= 12)):
    print("MMYY")

else:
    print("NA")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <math.h>

using namespace std;
string s[2000];
int ans = 0,h,w;
int L[2000][2000] = {0};
int R[2000][2000] = {0};
int D[2000][2000] = {0};
int U[2000][2000] = {0};

int main(){
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    cin >> s[i];
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(i == 0) U[i][j] = ( 0 + 1 ) * (s[i][j] == '.');
      else U[i][j] = ( U [i-1] [j] + 1 ) * (s[i][j] == '.');
      if(j == 0) L[i][j] = ( 0 + 1 ) * (s[i][j] == '.');
      else L[i][j] = ( L[i][j-1] + 1) * (s[i][j] == '.');
    }
  }
  for(int i = h-1; i >= 0; i--){
    for(int j = w-1; j >=0; j--){
      if(i == h-1) D[i][j] = ( 0 + 1 ) * (s[i][j] == '.');
      else D[i][j] = ( D [i+1] [j] + 1 ) * (s[i][j] == '.');
      if(j == w-1) R[i][j] = ( 0 + 1 ) * (s[i][j] == '.');
      else R[i][j] = ( R[i][j+1] + 1) * (s[i][j] == '.');
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j]);
    }
  }
  // for(int i = 0; i < h; i++){
  //   for(int j = 0; j < w; j++){
  //       printf("%.2d ", L[i][j]);
  //   }
  //   cout << endl;
  // }
  cout << ans - 3;
  return 0;
}


Measured memory_bytes: 66816
use proconio::input;
use rand::Rng;
use std::collections::BTreeSet;

const N: i64 = 1000000;

fn main() {
   input! {
      dn: usize,
      c: [i64; 26],
      s: [[i64;26]; dn],
   }

   let mut t = vec![];
   let mut last = vec![BTreeSet::new(); 26];
   for i in 0..26 {
      last[i].insert(0);
      last[i].insert(dn + 1);
   }
   for d in 0..dn {
      let mut mx = std::i64::MIN;
      let mut tn = 0;
      for t in 0..26 {
         let mut score = 0i64;
         score += s[d][t];
         for j in 0..26 {
            if j != t {
               score -= c[j] * (d + 1 - last[j].range(..=d).rev().next().unwrap()) as i64;
            }
         }
         if score > mx {
            mx = score;
            tn = t;
         }
      }
      last[tn].insert(d + 1);
      t.push(tn);
   }

   let mut rng = rand::thread_rng();
   for i in 0..N {
      let d = rng.gen_range(0, dn);
      let q = rng.gen_range(0, 26);
      if t[d] == q {
         continue;
      }
      let p = t[d];
      let mut score = 0;
      score -= s[d][p];
      score += s[d][q];
      let f1 = last[p].range(..=d).rev().next().unwrap();
      let b1 = last[p].range(d + 2..).next().unwrap();
      let f2 = last[q].range(..=d).rev().next().unwrap();
      let b2 = last[q].range(d + 2..).next().unwrap();
      score -= c[p] * (d + 1 - f1) as i64 * (b1 - (d + 1)) as i64;
      score += c[q] * (d + 1 - f2) as i64 * (b2 - (d + 1)) as i64;
      if score > 0 || rng.gen_range(0.0, 1.00) < (score as f64 / ((N - i) as f64 / 100.0)).exp() {
         t[d] = q;
         last[p].remove(&(d + 1));
         last[q].insert(d + 1);
      }
   }
   for &t in t.iter() {
      println!("{}", t + 1);
   }
}


Measured memory_bytes: 3276