akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int binSearch(int S[], int n, int t) {
    int i;
    int left = 0;
    int right = n; 
    while(left < right) {
        i = (right + left) / 2;
        if (S[i] == t) return 1;
        else if (S[i] < t) left = i + 1;
        else right = i;
    }
    return 0;
}

int main() {
    int S[100000];
    int n, q, t, sum = 0;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> S[i];
    }
    cin >> q;
    for (int i=0;i<q;i++){
        cin >> t;
        sum += binSearch(S, n, t);
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 3472
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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



int main() {
int n;
cin>>n;
int l[n],r[n];
REP(i,n) cin>>l[i]>>r[i];
int ans=0;
REP(i,n) ans+=(r[i]-l[i])+1;

cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys


def solve(inp):
    (a, b) = inp.readline().strip().split(' ')

    ab = a * int(b)
    ba = b * int(a)

    return str(min(ab, ba))


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    rep(i, S.size()) {
        if (S[i] == '?') S[i] = 'D';
    }
    cout << S << "\n";
    return 0;
}


Measured memory_bytes: 3756
int main()
{
  int n;
  scanf("%d", &n);
  if (n <= 599)
    printf("8");
  else if (n <= 799)
    printf("7");
  else if (n <= 999)
    printf("6");
  else if (n <= 1199)
    printf("5");
  else if (n <= 1399)
    printf("4");
  else if (n <= 1599)
    printf("3");
  else if (n <= 1799)
    printf("2");
  else if (n <= 1999)
    printf("1");
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int x=1;
  
  for(int i=0; i<N; i++){
    
    if(x<K){
      x*=2;
    }
    
    else{
      x+=K;
    }
  }
  
  cout << x << endl;
}

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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  cin >> N;
  vector<ld> p(N);
  REP(i,N) cin >> p[i];

  vector<vector<ld>> dp(N + 1, vector<ld> (N + 1, 0));
  dp[0][0] = 1;
  REP(i,N)REP(j, N + 1){
    if(j + 1 <= N) dp[i + 1][j + 1] += dp[i][j] * p[i];
    dp[i + 1][j] += dp[i][j] * (1 - p[i]);
  }

  ld ret = 0;
  for(int j = (N + 1) / 2; j <= N; ++j) ret += dp[N][j];
  cout << fixed << setprecision(10) << ret << endl;
  return 0;
}



Measured memory_bytes: 141056
/*  -*- coding: utf-8 -*-
 *
 * 1386.cc: Starting a Scenic Railroad Service
 */

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

/* constant */

const int MAX_N = 200000;
const int MAX_M = 100000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N];
int csums[MAX_M + 1], asums[MAX_M + 1], bsums[MAX_M + 1];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int m = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", as + i, bs + i);
    csums[as[i]]++, csums[bs[i]]--;
    asums[as[i]]++;
    bsums[bs[i]]++;
    setmax(m, bs[i]);
  }

  for (int i = 0; i < m; i++) {
    csums[i + 1] += csums[i];
    asums[i + 1] += asums[i];
    bsums[i + 1] += bsums[i];
  }

  int maxp1 = 0;
  for (int i = 0; i < n; i++) setmax(maxp1, asums[bs[i] - 1] - bsums[as[i]]);

  int maxp2 = 0;
  for (int i = 1; i < m; i++) setmax(maxp2, csums[i]);

  printf("%d %d\n", maxp1, maxp2);
  //for (int i = 0; i <= m; i++) printf("%d ", csums[i]); putchar('\n');
  //for (int i = 0; i <= m; i++) printf("%d ", asums[i]); putchar('\n');
  //for (int i = 0; i <= m; i++) printf("%d ", bsums[i]); putchar('\n');
  return 0;
}



Measured memory_bytes: 5936
from collections import deque

h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]
mod = 10**9 +7

dp = [[0]*w for _ in range(h)]
dp[0][0] = 1
reach = [[False]*w for _ in range(h)]
que = deque(())

que.append((0,0))

while que:
    i,j = que.popleft()
    if i < h-1 and a[i+1][j] == '.':
        if dp[i+1][j] == 0:
            que.append((i+1,j))
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= mod
    if j < w-1 and a[i][j+1] == '.':
        if dp[i][j+1] == 0:
            que.append((i,j+1))
        dp[i][j+1] += dp[i][j]
        dp[i][j+1] %= mod
print(dp[h-1][w-1])


Measured memory_bytes: 108656
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define SORT(x) sort((x).begin(),(x).end())
int main(void){
    
    int N,T,A;
    cin >>N >>T >>A;
    
    int n; //出力する番号をつくるための変数
    int nr=10001000000; //最も理想的な気温を判定するための十分に大きい変数
    
    for(int i=0; i<N; i++){
        int H;
        cin >>H;
        
        if(abs((int)(((T-H*0.006)-A)*1000))<nr){
            nr=abs((int)(((T-H*0.006)-A)*1000));
            n=i+1;
        }
    }
    
    cout <<n <<endl;
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int n;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	n=read();
	printf("%d\n",n+n*n+n*n*n);
	return 0;
}

Measured memory_bytes: 3744
# input: H4 C9 S4 D2 C3
# return: [["H", 4], ["C", 9], ["S", 4], ["D", 2], ["C", 3]]
gets
a = gets.rstrip.split.map{|e| e.split('')}.map{|e| [e[0], e[1].to_i]}

def bubble_sort(a)
  is_reverse = true
  while is_reverse
    is_reverse = false
    0.upto(a.size - 2) do | i |
      if a[i][1] > a[i+1][1]
        a[i], a[i+1] = a[i+1], a[i]
        is_reverse = true
      end
    end
  end
  return a
end

def selection_sort(a)
  0.upto(a.size - 1) do | i |
    min_j = i
    i.upto(a.size - 1) do | j |
      if a[j][1] < a[min_j][1]
        min_j = j
      end
    end
    a[min_j], a[i] = a[i], a[min_j]
  end
  return a
end

def is_stable?(a, b)
  duplicate = []
  before = b[0][1]
  1.upto(b.size - 1) do | i |
    duplicate << before if before == b[i][1]
    before = b[i][1]
  end
  duplicate.uniq!

  duplicate.each do | d |
    dup_a, dup_b = [], []
    a.each do | ae |
      if ae[1] == d
        dup_a << ae
      end
    end
    b.each do | be |
      if be[1] == d
        dup_b << be
      end
    end
    return false if dup_a != dup_b
  end
  return true
end

bubbled =  bubble_sort(a.clone)
puts bubbled.map{|e|e.join('')}.join(' ')
puts is_stable?(a, bubbled) ? 'Stable' : 'Not stable'

selected = selection_sort(a.clone)
puts selected.map{|e|e.join('')}.join(' ')
puts is_stable?(a, selected) ? 'Stable' : 'Not stable'



Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL MOD=1e9+7;
vector<int>v;
priority_queue<LL>ma;
priority_queue<LL,vector<LL>,greater<LL> >mi;
int main(){
	int Q;
	cin>>Q;
	LL wa=0;
	LL aa=0;//小さい方
	LL bb=0;//大きい方
	int za=0;
	int zb=0;
	LL mid=0;
	REP(i,Q){
		int a;
		cin>>a;
		if(i==0){
			int b,c;
			cin>>b>>c;
			mid=b;
			wa+=c;
			continue;
		}
		if(a==1){
			LL b,c;
			cin>>b>>c;
			wa+=c;
			if(mid<b){
				zb++;
				mi.push(b);
				bb+=b;
			}else{
				za++;
				ma.push(b);
				aa+=b;
			}
			if(zb+1<za){
				mi.push(mid);
				bb+=mid;
				zb++;
				mid=ma.top();
				ma.pop();
				za--;
				aa-=mid;
			}
			if(za+1<zb){
				ma.push(mid);
				aa+=mid;
				za++;
				mid=mi.top();
				mi.pop();
				zb--;
				bb-=mid;
			}
			
		}else{
			LL ans=bb-aa+(za-zb)*mid;
			if(za>zb){
				LL aaa=ma.top();
				cout<<aaa<<" "<<(ans+wa)<<endl;
			}else{
				cout<<mid<<" "<<(ans+wa)<<endl;
			}
		}
	}
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll res = (n * (n - 1)) / 2;
  cout << res << endl;

}


Measured memory_bytes: 256
a, b , k = gets.chomp.split(" ").map(&:to_i)
ar = [*a..a+k-1]
ab = []
ar.each do |i|
    if i >= a && i <= b
        ab << i
    end
end
br = [*b-k+1..b]
ba = []
br.each do |j|
    if j >= a && j <= b
        ba << j
    end
end
arr = ab + ba
arr = arr.uniq
arr.each do |i|
    puts i
end

Measured memory_bytes: 14216
#include <iostream>
#include <algorithm>
#include <complex>
#define pb push_back
#define pll pair <ll, ll>
#define MOMI using namespace std;
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")
 
//#pragma GCC optimize("unroll-loops")
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 3e6;
 
ll n, m, k;

int main() {
    ll q, w, e, a, b, c;
    cin >> a >> b;
    cout << max((ll)0, a - 2 * b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#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 pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll mod=1000000007; // 998244353 = (119<<23)+1
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// head
const int nax=1e5+7;
int n,q;
string s;
int fen[nax];
void add(int p,int x) {
	for(int i=p;i<=n;i+=i&-i) fen[i]+=x;
}
int sum(int p) {
	int ans=0;
	for(int i=p;i;i-=i&-i) ans+=fen[i];
	return ans;
}
int main() {
	  ios::sync_with_stdio(false);
  	cin.tie(0);
		cin>>n>>q>>s;
		rep(i,1,n) if(s[i]=='C'&&s[i-1]=='A') add(i+1,1);
		rep(i,0,q) {
			int a,b;
			cin>>a>>b;
			int ans=sum(b)-sum(a-1);
//			cout<<ans<<' ';
			if(s[a-1]=='C'&&s[a-2]=='A') ans--;
			cout<<ans<<'\n';
		}
		return 0;
}

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
bool isPrime[MAXN];
vector<int> pr;
vector<int> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {

            ans.push_back(i);
        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int main()
{
    FAST
    string h[4]={"AC", "WA", "TLE","RE"};
    int n;
    cin>>n;
    map<string,int> m;
    for(int i=0;i<n;i++)
    {
        string a;
        cin>>a;
        m[a]++;
    }
    for(int i=0;i<4;i++)
    {
        cout<<h[i]<<" x "<<m[h[i]]<<endl;
    }
    return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (auto&& e : s) {
    int i = e - 'A';
    i += n;
    i %= 26;
    e = 'A' + i;
  }
  cout << s << '\n';
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto ps = readln.split.to!(int[]);
    auto qs = new bool[](N+1);
    int r, last = 1;
    foreach_reverse (p; ps) {
        qs[p] = true;
        if (p == last) ++r;
        while (last <= N && qs[last]) ++last;
    }
    writeln(r);
}

Measured memory_bytes: 11664
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
typedef long long Int;


Int n;
string s;
Int sum[324000];
Int xr[324000];

bool ok(int x ,int y){
		return sum[y] - sum[x-1] == (xr[y] ^ xr[x-1]);
}

int main(){
	cin >> n;
	for(Int i = 1;i <= n;i++){
		cin >> sum[i];
		xr[i] = sum[i];
		sum[i] += sum[i-1];
		xr[i] ^= xr[i-1];
	}

	Int r = 1;
	Int res = 0;
	for(Int i = 1;i <= n;i++){
		r = max(r, i);
		while(r < n && ok(i,r+1))r++;
		res += r - i + 1;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3840
#include<iostream>
using namespace std;
int main()
{
    string name;
    cin>>name;
    if(name=="SUN"){
            cout<<"7"<<endl;

    }else if(name=="MON"){
        cout<<"6"<<endl;

    }else if(name=="TUE"){
        cout<<"5"<<endl;

    }else if(name=="WED"){
        cout<<"4"<<endl;

    }else if(name=="THU"){
        cout<<"3"<<endl;

    }else if(name=="FRI"){
        cout<<"2"<<endl;

    }else if(name=="SAT"){
        cout<<"1"<<endl;

    }
    return 0;


}


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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        ll n;
        cin>>n;
        cout<<fixed<<setprecision(12)<<2*PI*n;
        



        cout<<'\n';
    return 0;
}

Measured memory_bytes: 3780
S = input()

if S[0] == 'A':
    if S[2:-1].count('C') == 1:
        S = S.replace('A', '')
        S = S.replace('C', '')
        if S.islower():
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")


Measured memory_bytes: 2940
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let s: Vec<char> = s.trim().chars().collect();

    let mut cum_cnt: usize = 0;
    let mut res: usize = 0;
    for s_i in s {
        if s_i == 'B' {
            cum_cnt += 1;
        } else if s_i == 'W' {
            res += cum_cnt;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
enumDivisor x b
  | b<=1 = [1]
  | otherwise = f (min b (x`div`2)) where
      f 1 = [1]
      f n
        | x`mod`n==0 = n : f (n-1)
        | otherwise = f (n-1)

solv 1 m = m
solv n m = head $ enumDivisor m (m`div`n)

main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  print $ solv n m


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

int main(){
  int n;
  string p,q,r;
  cin >> n >> p >> q >> r;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if((p[i] == q[i] && p[i] != r[i]) || (p[i] == r[i] && p[i] != q[i]) || (q[i] == r[i] && p[i] != q[i])) ans++;
    else if(p[i] != q[i] && q[i] != r[i] && p[i] != r[i]) ans += 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

function isPrime($x) {
    if ($x < 2) return false;
    else if ($x === 2) return true;
    else if ($x % 2 === 0) return false;
    else {
        for ($i = 3; $i ** 2 <= $x; $i++) {
            if ($x % $i === 0) return false;
        }
        return true;
    }
}

$count = 0;
$n = (int)input();
for ($i = 0; $i < $n; $i++) {
    $x = (int)input();
    if (isPrime($x)) $count++;
}
echo "{$count}\n";


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

public class Main{

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String k = br.readLine();

		String ans;
		if(n >= k.length()) {

			ans = k;
		}else {

			ans = k.substring(0, n ) + "...";
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 36284
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll a,b,c,k; cin >> a >> b >> c >> k;
    if(k % 2 == 0) cout << a-b << endl;
    else{
        ll tmp,tmp2;
        tmp = c;
        tmp2 = b;
        c = a + b;
        b = a + tmp;
        a = tmp2 + tmp;
        cout << a-b << endl;
    }
}


Measured memory_bytes: 256
import math
N,M = map(int,input().split())

sq = math.sqrt(M)
sq = math.floor(sq)


ans = 1
for i in range(1,sq+2):
  if M % i == 0:
    if i * N <= M:
      ans = max(i,ans)
    if M / i * N <= M:
      ans = max(M // i,ans)
if N == 1:
  print(int(M))
else:
  print(int(ans))


Measured memory_bytes: 3060
n, m = map(int, input().split())
p, s = [], []
for i in range(m):
    pi, si = input().split()
    p.append(int(pi))
    s.append(si)

lst_ac = [0 for i in range(n+1)]
for i in range(m):
    if s[i] == 'AC':
        lst_ac[p[i]] = 1
ans_ac = sum(lst_ac)

out = 0
for i in range(m):
    if s[i] == 'WA' and lst_ac[p[i]] == 1:
        out += 1
    if s[i] == 'AC' and lst_ac[p[i]] == 1:
        lst_ac[p[i]] = 2

print(ans_ac, out)

Measured memory_bytes: 14552
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int t=sc.nextInt();
    int c=Integer.MAX_VALUE;
    for(int i=0;i<n;i++){
      int cc=sc.nextInt();
      if(sc.nextInt()<=t){
        c=Math.min(c,cc);
      }
    }
    System.out.println(c==Integer.MAX_VALUE?"TLE":c);
  }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    double D;
    cin >> N >> D;

    ll ans = 0;
    double x, y;
    rep(i, N){
        cin >> x >> y;
        if(sqrt(x * x + y * y) <= D){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3816
n = gets.to_i
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i

#    s  a  b  c  d  e <- 各場所の人数
s = [n, 0, 0, 0, 0, 0]
x = [a, b, c, d, e]

min = x.min
if min > n
  p 5
else
  #bottle_neck = n.div(min) + 1
  bottle_neck = n.fdiv(min).ceil
  p bottle_neck+4
end


Measured memory_bytes: 1788
#include <stdio.h>

int search(int A[], int n, int key){
	int i = 0;
	A[n] = key;
	while(A[i] != key){
	i++;
	}
	if(i != n)return 1;
	return 0;

}

int main(void){
	int i,n;
	int A[10001];
	int m, k;
	int sum = 0;
	
	scanf("%d",&n);
	for(i = 0; i < n;i++)
	{
		scanf("%d", &A[i]);
	}
	
	scanf("%d",&m);
	for(i = 0; i < m;i++)
	{
		scanf("%d", &k);
		if(search(A,n,k) == 1)sum++;
	}
	printf("%d\n",sum);
	return 0;
}


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

const int MX = 105;
int f[MX];

int main() {
	int a, b, c, tot = 0;
	cin >> a >> b >> c;
	tot++;
	f[a] = 1;
	if(f[b] == 0) tot++;
	f[b] = 1;
	if(f[c] == 0) tot++;
	
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 256
A, B, C, D = list(input())

op = ['+', '-']

for i in range(7):
    formula = A + op[(i >> 0) & 1] + B + op[(i >> 1) & 1] + C + op[(i >> 2) & 1] + D
    if eval(formula) == 7:
        print(formula + '=7')
        break

Measured memory_bytes: 3060
'use strict'
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var A=input.shift();
  var B=input.shift();
  var T=input.shift();
  var ans=Math.floor(T/A)*B;
  console.log(ans);
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    th = 10**18
    if 0 in A:
        print(0)
        return
    for a in A:
        ans *= a
        if ans > th:
            print(-1)
            return 
    print(ans if ans <= th else -1)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 21644
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define f(i,a,b) for(int i=(a); i<(b);++i)
const unsigned int M = 1000003;
int main()
{
    int s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3640
import sys
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7
N,K = map(int,input().split())
A = np.array([input().split() for _ in range(N)],dtype=np.int64)

def mult1(A,B):
    C = np.zeros_like(A)
    for i in range(N):
        for j in range(N):
            C[i,j] = (A[i,:] * B[:,j] % MOD).sum() % MOD
    return C

def mult(A,B):
    # 桁あふれ回避のため
    M = 1 << 16
    A1,A2 = A//M,A%M
    B1,B2 = B//M,B%M
    X,Y,Z = (np.dot(P,Q) % MOD for P,Q in ((A1,B1),(A1-A2,B1-B2),(A2,B2)))
    return ((X << 32) + (X+Z-Y << 16) + Z) % MOD

def power(A,k):
    if k == 1:
        return A
    X = power(A,k//2)
    X = mult(X,X)
    return mult(A,X) if k&1 else X

answer = power(A,K).sum() % MOD
print(answer)

Measured memory_bytes: 13148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    REP(i,n) cin >> c[i];
    ll ans = 0;
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    REP(i,n){
        ll u = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll d = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += u * d;
    }
    cout << ans << endl;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    string s; cin >> s;
    if (s == "RSR"){
        cout << 1 << endl;
    } else {
        ll cnt = 0;
        for(auto c: s){
            cnt += (c == 'R');
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int x, y, z, ans;
	cin >> x >> y >> z;
	ans = (x - z) / (y + z);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    h  = list(map(int, input().split()))
    h = h[::-1]
    
    if n == 1:
        print('Yes')
    else:
        for i in range(n-1):
            if h[i+1] - h[i] == 1:
                h[i+1] -= 1

            elif h[i+1] <= h[i]:
                pass

            elif h[i+1] > h[i]:
                print('No')
                break 

            if i == n-2:
                print('Yes')
                break

    
    
if __name__ == '__main__':
    main()



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

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};
//mint
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
//BIT
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
};
//combination
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
//gcd and lcm
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
//prime

int main() {
  int n;cin >>n;
  vector<int> a(n);
  rep(i,n){
  cin>>a[i];
  }
  sort(a.begin(),a.end());
  double ans=mod;
  double sum=mod;
  rep(i,100){
    sum=0;
    rep(j,n){
  sum+=min(ans,pow(a[j]-i,2));
    }
    ans=min(ans,sum);
  }
  cout <<ans<<endl;
  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL A, B, C; cin >> A >> B >> C;
		if (A == B && B == C) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int main() {
	ll N, W;
	cin >> N >> W;

	vector<vector<ll>> v(4);
	ll w0, v0;

	cin >> w0 >> v0;
	v[0].pb(v0);

	for (int i = 1; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		v[a-w0].pb(b);
	}

	for (int i = 0; i < 4; i++) sort(RALL(v[i]));

	vector<vector<ll>> sum(4);
	for (int i = 0; i < 4; i++) sum[i].pb(0);

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < (int)v[i].size(); j++) {
			sum[i].pb(sum[i][j] + v[i][j]);
		}
	}

	ll ans = 0;
	for (int i = 0; i <= (int)v[0].size(); i++) {
		for (int j = 0; j <= (int)v[1].size(); j++) {
			for (int k = 0; k <= (int)v[2].size(); k++) {
				for (int l = 0; l <= (int)v[3].size(); l++) {
					ll tmp_w = w0*i + (w0+1)*j + (w0+2)*k + (w0+3)*l;
					if (tmp_w <= W) ans = max(ans, sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l]);
				}
			}
		}
	}

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


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

int main(){
    string A,B,C;
    cin>>A>>B>>C;
    if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0])    cout<<"YES"<<endl;
    else                                            cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,m,c=0;
int fl[1010]={1};
int f(int a,int b){
  if(a<b){
    if(a)return f(b%a,a);
    return b;
  }
  if(b)return f(a%b,b);
  return a;
}
int g(int s,int t,char d[1010][1010]){
  int i,r;
  if(s==t)return 1;//{printf("%d\n",++c);return 1;}
  for(i=1;i<=n+m+1;i++){//printf("%d ",i);
    if(d[s][i]==0||fl[i])continue;
    fl[i]=1;//printf("%d ",i);
    if(g(i,t,d)){
      d[s][i]--;
      d[i][s]++;
      return 1;
    }//printf("up\n");
  }
  return 0;
}
int main(){
  int i,j,a[510],b,s;
  while(scanf("%d %d",&n,&m),n||m){
    char d[1010][1010]={0};
    for(i=1;i<=n;i++){
      scanf("%d",&a[i]);
      d[0][i]=1;
    }
    for(s=0;i<=n+m;i++){
      d[i][n+m+1]=1;
      scanf("%d",&b);
      for(j=1;j<=n;j++){
	if(f(a[j],b)-1)d[j][i]=1;
      }
    }
    /*for(i=s=0;i<=n+m+1;i++){
      for(j=0;j<=n+m+1;j++){
	if(d[i][j]){
	  printf("%d %d 1\n",i,j);
	  s++;
	}
      }//*/
    //}
    while(1){
      for(i=1;i<=n+m+1;i++)fl[i]=0;
      if(g(0,n+m+1,d)==0)break;
      s++;
    }
    printf("%d\n",s);
  }
  return 0;
}
  
	

Measured memory_bytes: 1660
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
const int MAX_N = 100010;

int par[MAX_N];
int Rank[MAX_N];
int sizeed;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
    sizeed = n;
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    sizeed--;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}
bool same(int x, int y) {
    return find(x) == find(y);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    init(N);
    rep(i, M) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        X--; Y--;
        unite(X, Y);
    }
    cout << sizeed << endl;

    return 0;
}


Measured memory_bytes: 4432
#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long ll;
const int N = 49;
const int M = (1 << 17) + 9;
const ll mod = 1e9 + 7;

int n, x, y, z;
ll f[N][M];

int main() {
    scanf("%d %d %d %d", &n, &x, &y, &z);
    int st = (1 << (x + y + z - 1)) | (1 << (y + z - 1)) | (1 << (z - 1));
    int m = x + y + z;
    f[0][0] = 1;
    for (int i = 1; i <= n; ++i)
        for (int s = 0; s < (1 << m); ++s) if (f[i - 1][s] && ((s & st) != st))
            for (int j = 1; j <= 10; ++j)
                f[i][((s << j) | (1 << (j - 1))) & ((1 << m) - 1)]
                 = (f[i][((s << j) | (1 << (j - 1))) & ((1 << m) - 1)] + f[i - 1][s]) % mod;
    ll ans = 0, num = 1;
    for (int s = 0; s < (1 << m); ++s) 
        if ((s & st) != st) ans = (ans + f[n][s]) % mod;
    for (int i = 1; i <= n; ++i) num = num * 10 % mod;
    printf("%lld\n", (num - ans + mod) % mod);
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    cout << ceil(N/2.0) << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
K = int(input())
s_list = []
for i in range(len(S)):
	for j in range(i + 1, i + K + 1):
		s_list.append(S[i:j])
sub_set = set(s_list)
substring = list(sub_set)
substring.sort()
print(substring[K-1])

Measured memory_bytes: 5068
#include <iostream>

using namespace std;

int main(){

	int H = 0;
	int W = 0;

	cin >> H >> W;

	while (H != 0 && W != 0) {

		for (int i = 0; i < H; i++) {

			for (int u = 0; u < W; u++) {

				if (i == 0 || i == H - 1) {

					cout << "#";

				}
				else if (u == 0 || u == W - 1) {

					cout << "#";

				}
				else {

					cout << ".";

				}

			}

			cout << endl;

		}

		cout << endl;

		cin >> H >> W;

	}

	return 0;

}



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

struct SegmentTree {
   int n;  // 最下段のノード数
   vector<int> node;
   int SIJK;  // 最弱なやつ(INFとか-1とか)
 
  public:
   SegmentTree(vector<int> v) {
     SIJK = 0;  // INFは最弱なので
 
     int sz = v.size();
     n = 1;
     while (n < sz) n *= 2;  // n…最下段の横幅
     node.resize(2 * n - 1, SIJK);
 
     // 最下段に突っ込む
     for (int i = 0; i < sz; i++) node[(n - 1) + i] = v[i];
 
     // 最下段以外を更新していく
     for (int i = n - 2; i >= 0; i--) {
       node[i] = compare(node[i * 2 + 1], node[i * 2 + 2]);
     }
   }
 
   // 結合法則を満たすやつならなんでもいいよー。aとbを足す。
   int compare(int a, int b) {
     return a+b;
   }
 
   // i番目の要素をvalに変更する
   void update(int i, int val) {
     // まず最下段(2n-1)を変更する
     i += n - 1;
     node[i] = val;
 
     // 上に行きながら更新していく
     while (i > 0) {
       i = (i - 1) / 2;  // 親へ
       node[i] = compare(node[2 * i + 1], node[2 * i + 2]);
     }
   }
 
   // [a,b) 中の結果を返す。[l,r)は対称区間の左端と右端。
   int find(int a, int b, int now = 0, int l = 0, int r = -1) {
     // 初期化
     if (r < 0) r = n;
 
     // 俺は関係ないとき -> 答えの邪魔にならない値を返す
     if (r <= a || b <= l) return SIJK;
 
     // 要求区間の中にノードがすっぽり入ってる → 計算候補として返す
     if (a <= l && r <= b) return node[now];
 
     // ノードの一部分だけ要求区間に入ってる → 子を再帰的に探索する
     int vl = find(a, b, 2 * now + 1, l, (l + r) / 2);  // 子(左)
     int vr = find(a, b, 2 * now + 2, (l + r) / 2, r);  // 子(右)
     return compare(vl, vr);
   }
 };
 

int main(){
    int N;cin>>N;
    string str;cin>>str;
    vector<vector<int>> base(26,vector<int>(N,0));
    vector<SegmentTree> segs;
    for(int i = 0;i < N;i++){
        base[str[i] - 'a'][i]++;
    }
    for(int i = 0;i < 26;i++){
        segs.push_back(SegmentTree(base[i]));
    }
    int Q;cin>>Q;
    // cout<<'d'-'a'<<endl;
    vector<int> results;
    for(int _ = 0;_< Q;_++){
        int type;cin>>type;
        if(type == 1){
            int i;char c;
            cin>>i>>c;
            i--;
            segs[str[i]-'a'].update(i, 0);
            segs[c-'a'].update(i,1);
            str[i] = c;
        }else{
            int l,r;cin>>l>>r;l--;r--;
            int result = 0;
            for(int i = 0;i < 26;i++){
                if(segs[i].find(l,r+1) > 0){
                    result++;
                }
            }
            results.push_back(result);
        }
    }
    if(results.size()==0)return 0;
    for(int i = 0;i < results.size();i++){
        cout<<results[i]<<endl;
    }
}

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

using namespace std;
const double PI=3.14159265358979323846;

double bisection(double from, double to, double ans){
    double ans_tmp = (from + to)/2.0;
    if(fabs(ans - tan(ans_tmp)) < 0.00000001) return ans_tmp;
    else if(ans - tan(ans_tmp) > 0){
        return bisection(ans_tmp, to, ans);
    }else{
        return bisection(from, ans_tmp, ans);
    }
}

int main(){
    double a, b, x, ans, radi, deg;
    cin >> a >> b >> x;
    double s = x/a;
    if(s == a*b) deg = 0.0;
    else{
        if(s < a*b/2.0){
            double ap = (2.0 * s)/b;
            radi = atan(b/ap);
            deg = radi*(180.0/PI);
        }else{
            double bp = ((2.0*s)/a) - b;
            double bpp = b - bp;
            radi = atan(bpp/a);
            deg = radi * (180.0/PI);
        }
    }
    cout << fixed << deg << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        vector<int> X(100);
        int N,P = 0,Q=1;

        cin >> N ;

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

        int min = *std::min_element(X.begin(), X.end());
        int max = *std::max_element(X.begin(), X.end());
        for(int i=min; i<=max; i++){
            for(int j=0; j<N; j++){
                P=P + (X[j]-i)*(X[j]-i);
            }
            if(P<Q || i== min)Q=P;
            P=0; 
        }

        cout << Q << endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int main() {
	ll A1, B1, A2, B2, T1, T2;
	cin >> T1 >> T2;
	cin >> A1 >> A2;
	cin >> B1 >> B2;

	if (A1 > B1 && A2 > B2) {
		cout << 0 << endl;
		return 0;
	}
	if (A1 < B1 && A2 < B2) {
		cout << 0 << endl;
		return 0;
	}

	if (A1 > B1) {
		swap(A1, B1);
		swap(A2, B2);
	}

	ll adv1 = 0, adv2 = T1 * B1 - T1 * A1;
	ll saf1 = -adv2, saf2 = T2 * B2 - T2 * A2;
	ll da = (T1 * B1 + T2 * B2 - T1 * A1 - T2 * A2);
	if (da == 0) {
		cout << "infinity" << endl;
		return 0;
	}
	ll ans = max(0LL, (saf1 + 1) / da) + max(0LL, saf2 / da);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<limits.h>
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e3+10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    if(a>=b){
        while(a--)
            cout<<b;
    }
    else{
        while(b--)
            cout<<a;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
const int MAX_V = 50;
const int MAX_S = MAX_V*50+5;
const ll INF = 1e18;
struct Edge {
    int to, a, b;
    Edge(int to, int a, int b): to(to), a(a), b(b) {}
};

struct Data {
    int v, s;
    ll x;
    Data(int v, int s, ll x): v(v), s(s), x(x) {}
    bool operator<(const Data& a) const {
        return x > a.x;
    }
};
vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S+5];
typedef pair<ll, ll> P;
int main(){
    int n, m, s;
    cin >> n >> m >> s;
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u; --v;
        g[u].emplace_back(v, a, b);
        g[v].emplace_back(u, a, b);
    }
    vector<int> c(n), d(n);
    rep(i, n) cin >> c[i] >> d[i];
    rep(i, n)rep(j, MAX_S+5) dp[i][j] = INF;
    s = min(s, MAX_S);

    priority_queue<Data> q;
    auto push = [&](int v, int s, ll x) {
        if (s < 0) return;
        if (dp[v][s] <= x) return;
        dp[v][s] = x;
        q.emplace(v, s, x);
    };
    push(0, s, 0);
    while(!q.empty()) {
        Data hoge = q.top(); q.pop();
        int v = hoge.v, s = hoge.s;
        ll x = hoge.x;
        if (dp[v][s] != x) continue;
        {
            int ns = min(s+c[v], MAX_S);
            push(v, ns, x+d[v]);
        }
        for (Edge e : g[v]) {
            push(e.to, s-e.a, x+e.b);
        }
    }
    for(int i = 1; i < n; ++i) {
        ll ans = INF;
        rep(j, MAX_S+5) {
            ans = min(ans, dp[i][j]);
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 6212
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ln(a) cout << (a) << endl
#define debug(a, n) rep(hoge, n) printf("%lld%c", a[hoge], hoge == (n) - 1? '\n' : ' ');
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define int ll

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

int inv(int x) {
    int n = MOD - 2;
    int res = 1;
    int tmp = x;
    while(n) {
        if(n & 1) {
            res *= tmp;
            res %= MOD;
        }
        tmp *= tmp;
        tmp %= MOD;
        n >>= 1;
    }
    return res;
}

signed main() {
    int n;
    cin >> n;
    int* x = new int[n];
    rep(i, n) cin >> x[i];
    
    int prob = 0;
    int ans = 0;
    rep(i, n - 1) {
        prob += inv(i + 1);
        prob %= MOD;
        ans += (x[i + 1] - x[i]) * prob % MOD;
    }
    rep(i, n - 1) {
        ans *= i + 1;
        ans %= MOD;
    }

    ln(ans);
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(ll i = 0;i<(ll)n;i++)
using namespace std;
typedef long long ll;
static const int MAX = 50;
static const long long INFTY = (1 << 31);
ll mod = 1000000007;
pair<ll, ll> p[MAX];

int main()
{
	int N, K;
	cin >> N >> K;

	rep(i, N) {
		ll x, y;
		cin >> x >> y;
		p[i] = make_pair(x, y);
	}

	ll rectangle = 9000000000000000000;
	rep(x1, N) {
		rep(x2, N) {
			if (p[x1].first == p[x2].first)
			{
				continue;
			}
			rep(y1, N) {
				rep(y2, N) {
					if (p[y1].second == p[y2].second) {
						continue;
					}
					int count = 0;
					ll X1 = min(p[x1].first, p[x2].first);
					ll X2 = max(p[x1].first, p[x2].first);
					ll Y1 = min(p[y1].second, p[y2].second);
					ll Y2 = max(p[y1].second, p[y2].second);
					rep(i, N) {
						if (X1 <= p[i].first && p[i].first <= X2 &&
							Y1 <= p[i].second && p[i].second <= Y2) {
							count++;
						}
					}
					if (K <= count) {
						rectangle = min(rectangle, abs(X1 - X2)* abs(Y1 - Y2));
					}
				}
			}
		}
	}
	cout << rectangle << endl;

	return 0;
}

Measured memory_bytes: 384
def digitSum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

def main():
    n = int(input())
    n_sum = digitSum(n)
    if n_sum%9==0:
        print('Yes')
    else:
        print('No')
if __name__ == "__main__":
    main()

Measured memory_bytes: 11064
#include <bits/stdc++.h>
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int m = ri();
	std::map<int, int> all;
	for (int i = 0; i < n; i++) all[ri()]++;
	for (int i = 0; i < m; i++) {
		int b = ri();
		int c = ri();
		int cnt = 0;
		while (all.size() && all.begin()->first < c && cnt < b) {
			int update_num = std::min(b - cnt, all.begin()->second);
			all.begin()->second -= update_num;
			if (all.begin()->second == 0) all.erase(all.begin());
			cnt += update_num;
		}
		all[c] += cnt;
	}
	int64_t res = 0;
	for (auto i : all) res += (int64_t) i.first * i.second;
	std::cout << res << std::endl;
	return 0;
}



Measured memory_bytes: 4992