akhauriyash/Code-Regression huggingface dataset:
s = input()
if s[0] == ">":
    s="<"+s
if s[-1] == ">":
    s=s+"<"
elif s[-1] == "<":
    s=s+"><"

cc = 0
r = []
for b, c in zip(s, s[1:]):
    cc += 1
#    print(b, c)
    if b == "<" and c == ">":
        d = cc
        cc = 0
    if b == ">" and c == "<":
        r.append((d, cc))
        cc = 0
R = 0
for x, y in r:
#    print(x,y)
    R += (x-1)*x//2+(y-1)*y//2+max(x,y)
#    print((x-1)*x//2+(y-1)*y//2+max(x,y))
print(R)


Measured memory_bytes: 52096
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
A = LIST()
print(sum(A) if sum(A) < 10 else "error")

Measured memory_bytes: 5144
import Control.Applicative
import Data.List

--a<=b<=c
isRightTriangle a b c = if c*c == a*a + b*b then "YES" else "NO"

main = do
	n <- getLine
	l <- map sort . map (map (read::String->Int)) . map words . lines <$> getContents
	let l2 = [ isRightTriangle (t!!0) (t!!1) (t!!2) | t<-l ]
	mapM_ putStrLn $ l2

Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
	
	int N,K,count,tmp;
	cin>>N>>K;
	bool snuke[N]={false};
	
	for(int j=0;j<K;j++){
		cin>>count;
		for(int i=0;i<count;i++){
			cin>>tmp;
			snuke[tmp-1]=true;
		}
	}
	count=0;
	for(int i=0;i<N;i++){
		if(snuke[i]==false)
			count++;
	}
	cout<<count<<endl;
	
	return 0;
}

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


void solve(long long N, std::vector<long long> A){
    sort(A.begin(), A.end());
    cout << abs(A[0] - A[N-1]) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include "atcoder/fenwicktree.hpp"
using namespace std;
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

template<typename T>
class BIT{
public:
    int n;
    vector<T> bit; // 1-indexed

    BIT():n{0}{}
    BIT(int n_in):n{n_in}{
        bit.assign(n+1,0);
    }

    void init_u(){
        for(int i=1;i<n;i++)if(i+(i&-i)<=n) bit[i+(i&-i)]+=bit[i];
    }

    void add(int k,T w){
        if(k<=0) return;
        for(int i=k;i<=n;i+=i&-i) bit[i]+=w;
    }

    //(0,k]
    T sum(int k) const{
        T res=0;
        for(int i=k;i>0;i-=i&-i) res+=bit[i];
        return res;
    }

    //(l,r] 累積和区間と同じ
    T secsum(int l,int r) const{
        return sum(r)-sum(l);
    }

    //各要素は非負整数とする
    //w->w+1でupper_bound
    int lower_bound(T w) const{
        if(sum(n)<w) return n+1; //範囲外
        int idx=0,r=1;
        while(r<n) r<<=1;
        for(int len=r;len>0;len>>=1){
            if(idx+len<n && bit[idx+len]<w){
                w-=bit[idx+len];
                idx+=len;
            }
        }
        return idx+1;
    }
};

int main(){

    int n,q; cin>>n>>q;
    BIT<ll> bit{n};
    rep(i,n){
        int a; cin>>a;
        bit.bit[i+1]=a;
    }
  	bit.init_u();    
    rep(_,q){
        int t,l,r; cin>>t>>l>>r;
        if(t==0){
            bit.add(l+1,r);
        }
        else{
            printf("%lld\n",bit.secsum(l,r));
        }
    }
}


Measured memory_bytes: 8212
sa = input()
sb = input()
sc = input()

card = sa[0]
na = 1
nb = 0
nc = 0
flag = False

while True:
    if card == "a":
        if na >= len(sa):
            print("A")
            flag = True
        else:
            card = sa[na]
            na += 1
    elif card == "b":
        if nb >= len(sb):
            print("B")
            flag = True
        else:
            card = sb[nb]
            nb += 1
    else:
        if nc >= len(sc):
            print("C")
            flag = True
        else:
            card = sc[nc]
            nc += 1
    if flag:
        break

Measured memory_bytes: 3064
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());

int main(){
    string S;
    vector<char> Table(26, 0);
    cin >> S;

    for(int i=0; i<S.size(); i++){
        Table[S[i]-'a'] = 1;
    }
    for(int i=0; i<Table.size(); i++){
        if(Table[i]==0){
            printf("%c\n", 'a'+i);
            exit(0);
        }
    }
    cout << "None\n";
    return 0;
}

Measured memory_bytes: 3340
N, X, Y = map(int, input().split())

cost = [0 for _ in range(N - 1)]



for i in range(N-1):
    for j in range(i + 1,N):
        route_1 = j - i
        route_2 = abs(X-1 - i) + 1 + abs(Y-1 - j)
        route = min(route_1, route_2)
        #print(i, j, route)
        cost[route - 1]  += 1

for i in range(N-1):
    print(cost[i])

Measured memory_bytes: 3572
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    String[] title=new String[N];
    int[] time=new int[N];
    
    for(int i=0;i<N;i++){
      title[i]=sc.next();
      time[i]=sc.nextInt();
    }
    
    String target=sc.next();
    int Answer=0;
    
    for(int j=0;j<N;j++){
      if(title[j].equals(target)){
        for(int k=j+1;k<N;k++){
          Answer+=time[k];
        }
      }
    }
    
    System.out.println(Answer);
    
  }
}

Measured memory_bytes: 23124
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

list<long long int> Prime(long long int num) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= num; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	int num[100001] = {};
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		num[a]++;
		num[b]++;
	}
	for (int i = 0; i < N; i++) {
		if (num[i] % 2) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}



Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	char d, e, f;
	char str[4];
	int a, b;
	
	str[0] = '1';
	str[1] = '0';
	str[2] = '0';
	while (scanf("%c,%c", &d, &e) != EOF){
		if (d == 'A') {
			if (e == 'B') {
				f = str[0];
				str[0] = str[1];
				str[1] = f;
			}
			else if (e == 'C') {
				f = str[0];
				str[0] = str[2];
				str[2] = f;
			}
		}
		else if (d == 'B') {
			if (e == 'A') {
				f = str[1];
				str[1] = str[0];
				str[0] = f;
			}
			else if (e == 'C') {
				f = str[1];
				str[1] = str[2];
				str[2] = f;
			}
		}
		else if (d == 'C') {
			if (e == 'A') {
				f = str[2];
				str[2] = str[0];
				str[0] = f;
			}
			else if (e == 'B') {
				f = str[2];
				str[2] = str[1];
				str[1] = f;
			}
		}
	}
	for (a = 0; a < 3; a++) {
		if (str[a] == '1') {
			b = a;
		}
	}
	if (b == 0) {
		printf("A\n");
	}
	else if (b == 1) {
		printf("B\n");
	}
	else if (b == 2) {
		printf("C\n");
	}
	
	return (0);
}	

Measured memory_bytes: 524
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

using namespace std;

bool isSquare(ll n){
	return (ll)sqrt(n)*(ll)sqrt(n) == n;
}

int main(){
	string a, b; cin >> a >> b;
	if (isSquare(atoi((a + b).c_str()))) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a,b,c;
  cin>>a>>b>>c;
  if(a[a.length()-1]==b[0] && b[b.length()-1]==c[0])
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 3552
# B-R()-P-R()-B

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

total = [1] + [0] * N
psum = [1] + [0] * N
for i in range(1, N + 1):
    total[i] = total[i - 1] * 2 + 3
    psum[i] = psum[i - 1] * 2 + 1

# layer k, rest x
def f(k, x):
    if x == 0:
        return 0
    if k == 0:
        assert x == 1
        return 1

    ret = 0

    # 一番左の B を食べる
    if x <= 1:
        return ret
    x -= 1

    # L-1 を食べる
    # 枚数は分かっている (total, psum) ので全部食べられるならそれを使って終わり
    # 切れ目が途中にある場合は再帰呼び出し
    if x <= total[k - 1]:
        return ret + f(k - 1, x)
    ret += psum[k - 1]
    x -= total[k - 1]

    # 真ん中の P を食べる
    if x < 1:
        return ret
    ret += 1
    x -= 1

    # 2回目の L-1 を食べる
    if x <= total[k - 1]:
        return ret + f(k - 1, x)
    ret += psum[k - 1]
    x -= total[k - 1]

    # 最後の B を食べる (残り 0 or 1 でないと何かがおかしい)
    assert x <= 1
    return ret

print(f(N, X))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 1e5 + 5;
const int MAXM = 5e5 + 5;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
int h[MAXN], b[MAXN];

int main(){
    int n;
    scanf("%d", &n);
    bool flag = true;
    for(int i = 0;i < n; ++i){
        scanf("%d", &h[i]);
        if(i==0) --h[i];
        else{
            if(h[i] >= h[i-1] + 1 ){
                --h[i];
            }else if(h[i]<h[i-1]){
                flag = false;
            }
        }
    }
//    if(b[1]<0){
//        printf("No\n");
//        return 0;
//    }
//    for(int i = 2; i < n; ++i){
//        if(b[i] > 0) --b[i];
//        if(b[i]==-1&&b[i-1]>0){
//            b[i] = 0;
//            b[i-1]-=1;
//        }else{
//            flag = false;
//            break;
//        }
//    }
    printf("%s\n",flag?"Yes":"No");
    return 0;
}
/*
a b
b - (a-1)
b - a + 1

(b-1) - a
b - a - 1

b[i] = a[i] - a[i-1]
[-1, ]

1 2 1 1 3
 1 -1 0 2
1 1 1 1 3

1 3 2 1
 2 -1 -1

1 2 3 4 5
1 1 1 1


*/

Measured memory_bytes: 640
# ABC 045 D
from collections import Counter
H, W, N = map(int, input().split())
L = []
for k in range(N):
    a, b = map(int, input().split())
    for k in range(3):
        for l in range(3):
            if 1 <= a-k <= H-2  and 1 <= b-l <= W-2:
                L.append((a-k,b-l))

M = Counter(L)
A = [0 for k in range(10)]
s = 0
for e in M:
    A[M[e]] += 1
    s += 1

A[0] = (H-2)*(W-2)-s
for a in A:
    print(a)

Measured memory_bytes: 155840
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;

    int cnt = 0, time = 0;
    while (cnt < n)
    {
        time += t;
        cnt += x;
    }
    cout << time;
}


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

using namespace std;

using ll = long long;

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

#define INF 1e9

ll h[100005], a, b, n;

bool nibutan(int k){
    ll i, x, c = 0;

    for(i = 0; i < n; i++){
        x = b * k;
        if(h[i] > x){
            c += (h[i] - x) / (a - b);
            if((h[i] - x) % (a - b) != 0)c++;
        }
    }
    if(c > k){
        return false;
    }
    else{
        return true;
    }
}

int main(void)
{
    ll i;

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

    ll left = 0, right = 1e9, center = (left + right) / 2;

    while(right - left > 1){
        if(nibutan(center)){
            right = center;
            center = (left + right) / 2;
        }
        else{
            left = center;
            center = (left + right) / 2;
        }
    }

    cout << right << endl;
}


Measured memory_bytes: 1024
/*
    Prodigia comploratus,
    silens, oro:
    "Regnet exitium."
*/
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 2e5 + 5, MOD = 1e9 + 7;
const ll inf = 1e15;
char len[100000000];
int n;
int main(){
    
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for(int i = 0; i * r <= n; i++)
        for(int j = 0; i * r + j * b <= n; j++)
            if((n - (i * r) - (j * b)) % g == 0)
                ans++;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
//




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


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define pf push_front
#define ppf pop_front()
#define ff first
#define ss second
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=j; i--)
#define pll pair<ll,ll>
#define plb pair<ll,bool>
#define psl pair<string,ll>
#define psb pair<string,bool>
#define srt(v) sort((v).begin(),(v).end())
#define ub(v,val) upper_bound((v).begin(),(v).end(),(val))-(v).begin()
#define lb(v,val) lower_bound((v).begin(),(v).end(),(val))-(v).begin()


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;
const ll mod = (ll) 1e9  +  7;




ll ncr(ll n,ll r) {
    ll val=1,i,j,p=2;
    rfr(i,n-r+1,n+1) {
        val*=i;
        while(val%p==0 && p<=r) {
            val/=p;
            p+=1;
        }
    }
    if(p<r) {
        fr(i,p,r+1) val/=i;
    }
    return val;
}



ll fun(ll h[],ll i,ll n,ll k,vector <ll> &dp) {
    if(i>=n-1) return 0;
    if(dp[i]!=-1) return dp[i];
    ll val=inf,j;
    fr(j,i+1,min(n,i+k+1)) {
        val=min(val,fun(h,j,n,k,dp)+abs(h[i]-h[j]));
    }
    return dp[i]=val;
}




void cazz() {
    ll t=1,i=0,j,n;
    //cin>>t;
    while(t--) {
        ll k;
        cin>>n>>k;
        ll h[n];
        fr(i,0,n) cin>>h[i];
        vector <ll> dp(n+1,-1);
        cout<<fun(h,0,n,k,dp)<<"\n";
    }
}




int main() {
    spdio;
	cazz();
	return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

vector<int> ks, khs;

void solve() {
  int n, k; scanf("%d%d", &n, &k);
  long long ans = 0;
  for (int i = k; i <= n; i += k) ++ans;
  ans *= ans*ans;
  if (k % 2 == 0) {
    long long extra = 0;
    for (int i = k-(k/2); i <= n; i += k) ++extra;
    extra *= extra*extra;
    ans += extra;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;k--;
  string s;cin>>s;s[k]=tolower(s[k]);
  print(s);
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;



int main(){
    ll h,w,n,X,Y;cin>>h>>w>>n>>X>>Y;
    string s,t;cin>>s>>t;

    for(int j=0;j<4;j++){
        ll x=X,y=Y;
        if(j==0){
            rep(i,0,n){if(s[i]=='U')x--;
            else if(s[i]=='L')y--;
            if(x<1||y<1){
                cout<<"NO"<<endl;
                return 0;
            }
            
            if(x+1<=h&&t[i]=='D')x++;
            if(y+1<=w&&t[i]=='R')y++;}
        }
        else if(j==1){
            rep(i,0,n){if(s[i]=='U')x--;
            else if(s[i]=='R')y++;
            if(x<1||y>w){
                cout<<"NO"<<endl;
                return 0;
            }
            
            if(x+1<=h&&t[i]=='D')x++;
            if(y-1>=1&&t[i]=='L')y--;}
        }
        else if(j==2){
            rep(i,0,n){if(s[i]=='D')x++;
            else if(s[i]=='L')y--;
            if(x>h||y<1){
                cout<<"NO"<<endl;
                return 0;
            }
            
            if(x-1>=1&&t[i]=='U')x--;
            if(y+1<=w&&t[i]=='R')y++;}
        }
        else if(j==3){
            rep(i,0,n){if(s[i]=='D')x++;
            else if(s[i]=='R')y++;
            if(x>h||y>w){
                cout<<"NO"<<endl;
                return 0;
            }
            
            if(x-1>=1&&t[i]=='U')x--;
            if(y-1>=1&&t[i]=='L')y--;}
        }
    }
    cout<<"YES"<<endl;
}

    









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

int main()
{
    int H, W;
    cin >> H >> W;

    vector<string> strlist(H);

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

    for (int i = 0; i < H; i++)
    {
        cout << strlist[i] << endl;
        cout << strlist[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
 
public class Main
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) 
	{
        //code by sushant kumar
        FastReader in=new FastReader();
        int n=in.nextInt();
        int arr[]=new int[n];
        int arr2[]=new int[100001];
        long sum=0;
        for(int i=0;i<n;i++)
        {
            arr[i]=in.nextInt();
            arr2[arr[i]]++;
            sum+=arr[i];

        }
        int q=in.nextInt();
        for(int i=1;i<=q;i++)
        {
            int b=in.nextInt();
            int c=in.nextInt();
            int val=arr2[b];
            if(b>c)
                sum-=(b-c)*val;
            else
                sum+=(c-b)*val;
            arr2[b]=0;
            arr2[c]+=val;
            System.out.println(sum);


        }
    }
}

Measured memory_bytes: 48788
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    long double L;
    scanf("%Lf", &L);
    long double x = L / 3.0;
    printf("%.8Lf\n", x * x * x);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
 
int main () {
	string N;
	cin >> N;
	if ((N[1]== N[2]) &&((N[0] == N[1]) || (N[2] == N[3]))) cout << "Yes";
	else cout << "No";
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
#include <set>

using namespace std;
using namespace chrono;
 
typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

//#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define loop(x,n) for(int x = 0; x < n; ++x)
#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 trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;

string get_str() {
    string temp;
    cin >> temp;
    return temp;
}
int get_int() {
    int temp;
    cin >> temp;
    return temp;
}

void solve() {

    int n; string s;
    cin >> n >> s;

    int r = 0;

    loop(i, n) {
        if(s[i] == 'R') {
            r++;
        }
    }   

    if(r == 0 || r == n) {
        cout << 0 << endl;
        return;
    }

    int p1 = 0, p2 = n-1, ans = 0;

    while(p1 < p2) {
        while(p1< p2 && s[p1] == 'R') {
            p1++;
        }
        while(p1 < p2 && s[p2] == 'W') {            
            p2--;
        }

        if(p1<p2) {
            ans++;
            p1++;
            p2--;
        }
    }
    cout << min(min(r, n-r), ans) << endl;

}

int main() {
    
    solve();

}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  int a, b;
  cin >> a >> b;
  int ans = 0;
  rep(i, 1, N + 1) {
    int x = i;
    int y = 0;
    while (x) {
      y += x % 10;
      x /= 10;
    }
    if(a <= y and y <= b)ans+=i;;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

const int N = 410;
long long dp[N][N], pr[N];
int a[N];

long long solve(int l, int r) {
  if (dp[l][r]) {
    return dp[l][r];
  }
  if (l == r) {
    return dp[l][r] = 0;
  }
  long long bst = 1e18;
  for (int i = l; i < r; ++i) {
    bst = min(bst, solve(l, i) + solve(i + 1, r));
  }
  return dp[l][r] = bst + pr[r] - pr[l - 1];
}

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

  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pr[i] = pr[i - 1] + a[i];
  }
  cout << solve(1, n);

  return 0;
}

Measured memory_bytes: 1536
import numpy as np
import sys

n = int(input())
p = np.array(list(map(int,input().split())))
p_sort = np.sort(p)

if (p==p_sort).all():
  print("YES")
  sys.exit()

if np.count_nonzero(p!=p_sort)==2:
  print("YES")
else:
  print("NO")

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

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
	llint n,a,b;
	cin >> n >> a >> b;
	vector<llint>x(n);
	for(int i=0;i<n;i++)cin >> x[i];
	llint ans=0;
	for(int i=1;i<n;i++){
		ans+=min((x[i]-x[i-1])*a,b);
	}
	cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

string S;

signed main()
{
	cin >> S;

	if (S.length() == 1) {
		cout << 0 << endl;
		return 0;
	}

	char color = S[0];
	int change = 0;
	for (int i=1; i<S.length(); i++) {
		if (S[i] != color) {
			change++;
			color = S[i];
		}
	}

	cout << change << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int ll

int M = (int)1e9 + 7;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
typedef complex<int> point;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>


#define cerr cout
#define watch(x) cerr << (#x) << " = " << (x)    << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
	return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
	return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
	return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " << get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
	out << "[";
	fori(i, a.size())
		out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
	return out;
}

void smain();

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);


	cout << setprecision(12) << fixed;
	smain();
}

#define N 400000
const int oo = (int)1e9;






void smain()
{
	vector <int> a(10);
	for (int i = 0; i < 4; i++)
	{
		int b;
		cin >> b;
		a[b]++;
	}

	if (a[1] && a[9] && a[7] && a[4])
		cout << "YES";
	else
		cout << "NO";
}

//m1.codeforces.com, m2.codeforces.com или m3.codeforces.com

Measured memory_bytes: 256
K, A, B = map(int, input().split())

if B <= A + 2:
    print(K+1)
else:
    if K <= A:
        print(K+1)
    else:
        t = K - A + 1
        s = t // 2
        if t % 2 == 0:
            print(A+((B-A)*s))
        else:
            print(A+((B-A)*s)+1)

Measured memory_bytes: 3060
read = input
N = int(read())
guidebook = {}
for i in range(1,N+1):
    n,s = read().split()
    s = int(s)
    if n not in guidebook:
        guidebook[n] = {}
    guidebook[n][s] = i
guidebook = list(guidebook.items())
guidebook.sort()
for n,d in guidebook:
    B = list(d.items())
    B.sort(reverse = True)
    for s,i in B:
        print(i)

Measured memory_bytes: 3064
N = int(input())
cardschar = input().split()
cards = []
for i in range(N):
    cards.append(int(cardschar[i]))

cards.sort()
cards.reverse()

Alice = 0
Bob = 0

for i in range(N):
    if (i%2 == 0):
        Alice = Alice + cards[i]
    else:
        Bob = Bob + cards[i]

print(Alice-Bob)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int r = kbd.nextInt();
        int d = kbd.nextInt();
        int x = kbd.nextInt();
        int temp = x;
        for(int i=0;i<10;i++){
            temp = r*temp - d;
            System.out.println(temp); 
        }
    }
}

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

#define llong long long 
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define rand __rand
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());  // or mt19937_64
template<class T = int> T rand(T range = numeric_limits<T>::max()) { return (T)(rng() % range); }

#define CONCAT_(x, y) x##y/*{{{*/
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef LOCAL_DEBUG   
int __db_level = 0;
bool __db_same_line = false;
#define clog cerr << string(!__db_same_line ? __db_level * 2 : 0, ' ')
struct debug_block {
    function<void()> fn;
    void print_name() { __db_same_line = true; fn(); clog << endl; __db_same_line = false;  }
    debug_block(function<void()> fn_): fn(fn_) { clog << "{ "; print_name(); ++__db_level; }
    ~debug_block() { --__db_level; clog << "} "; print_name(); }
};
#define DB(args...) debug_block CONCAT(dbbl, __LINE__)([=]{ clog << args; })
#define deb(...)  if (1) { (clog << "[" #__VA_ARGS__ "] = [" << __VA_ARGS__) << "]"; if (!__db_same_line) clog << endl; }
#else
#define clog if (0) cerr
#define DB(...)
#define deb(...)
#endif
template<class T>
ostream& operator,(ostream& out, const T& thing) { return out << ", " << thing; }
template<class U, class V>
ostream& operator<<(ostream& out, const pair<U, V>& p) { return (out << "(" << p.first, p.second) << ")"; }
template<class A, class B>
ostream& operator<<(ostream& out, const tuple<A, B>& t) { return (out << "(" << get<0>(t), get<1>(t)) << ")"; }
template<class A, class B, class C>
ostream& operator<<(ostream& out, const tuple<A, B, C>& t) { return (out << "(" << get<0>(t), get<1>(t), get<2>(t)) << ")"; }
template<class T> ostream& operator<<(ostream& out, const vector<T>& container) { 
    out << "{";
    if (len(container)) out << container[0];
    rep1(i, len(container) - 1) out, container[i];
    return out << "}";
}
template<class x> vector<typename x::value_type> $v(const x& a) { return vector<typename x::value_type>(a.begin(), a.end()); }
#define ptrtype(x) typename iterator_traits<x>::value_type
template<class u> vector<ptrtype(u)> $v(u a, u b) { return vector<ptrtype(u)>(a, b); }/*}}}*/
// ACTUAL SOLUTION BELOW ////////////////////////////////////////////////////////////

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    llong x; cin >> x;
    rep1(k, 360) {
        if (k * x % 360 == 0) {
            cout << k;
            break;
        }
    }

    return 0;
}

// Remember:
// - Multitest? REFRESHING the data!!!
// - Constrains for each set of data may differs. Should NOT USE the same max constant (maxn)
//   for all of them.
// vim: foldmethod=marker



Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int a;
    string s;
    cin >> a >> s;
    if(a<3200) cout << "red";
    else cout << s;

}

Measured memory_bytes: 3488
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;

int main() {
	speed;
	int n, m;
	cin >> n >> m;
	vector<vector<int>>light(m);
	rep(i, m) {
		int k;
		cin >> k;
		light[i].resize(k);
		rep(j, k) {
			cin >> light[i][j];
			light[i][j]--;
		}
	}
	vector<int>p(m);
	rep(i, m)cin >> p[i];
	int ans = 0;
	rep(i, 1 << n) {
		bool flag = true;
		rep(j, m) {
			int c = 0;
			for (int id : light[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				flag = false;
			}
		}
		if (flag)ans++;
	}
	c(ans);
	ed;
	return 0; 
}



Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

//		int S = Integer.parseInt(sc.next());
		String S = sc.next();

		for(int i=0; i<S.length()-1; i++) {
			if(S.substring(i, i+1).equals(S.substring(i+1, i+2))) {
				System.out.println("Bad");
				return;
			}
		}
		System.out.println("Good");
	}
}


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

int main() {

    int n;
    cin >> n;

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

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

    int sum = 0;
    
    for (int i = 0; i < n-1; i++) {
        sum += p[i];
    }
    sum += p[n-1] / 2;

    cout << sum << endl;   

}

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

int main() {
	string S;
	cin >> S;
	if (S.size() < 26) {
		char C;
		for (int i = 97; i < 122; i++) {
			C = i;
			bool check = true;
			for (int j = 0; j < S.size(); j++) {
				if (S[j] == C) check = false;
			}
			if (check) break;
		}
		cout << S << C;
	}
	else {
		if (S == "zyxwvutsrqponmlkjihgfedcba") cout << -1;
		else {
			int X;
			char C = 'z';
			for (int i = 0; i < 26; i++) {
				bool check = true;
				for (int j = i + 1; j < 26; j++) {
					if (S[j - 1] < S[j]) check = false;
				}
				if (check) {
					X = i;
					break;
				}
			}
			for (int i = X; i < 26; i++) {
				if (S[i] > S[X - 1]) C = min(C, S[i]);
			}
			cout << S.substr(0, X - 1) << C;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				for (int l = 0; l < 2; l++) {
					string co = "";
					if (i == 1) {
						co += "A";
					}
					co += "KIH";
					if (j == 1) {
						co += "A";
					}
					co += "B";
					if (k == 1) {
						co += "A";
					}
					co += "R";
					if (l == 1) {
						co += "A";
					}
					if (co == s) {
						cout << "YES" << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}


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

int main(){
    char a,b;
    cin>>a>>b;
    if(a=='H'){
        if(b=='H') cout<<'H'<<endl;
        else cout<<'D'<<endl;
    }
    if(a=='D'){
        if(b=='H') cout<<'D'<<endl;
        else cout<<'H'<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> va(m);
  for (int i = 0; i < m; i++) {
    cin >> va[i];
  }

  int sum = 0;
  for (auto a : va) {
    sum += a;
  }

  if (sum > n) {
    cout << -1 << '\n';
  } else {
    cout << n - sum << '\n';
  }

  return 0;
}

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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define OK puts("OK")
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define int long long

using namespace std;

const int N = 2e5 + 5, mod = 1e9 + 7;

int fc[N], ifc[N];

int get (int n, int m)
{
    return fc[n + m - 2] * ifc[n - 1] % mod * ifc[m - 1] % mod;
}

int h, w, n, dp[N];

int binpow (int a, int b)
{
    if (b == 0)
        return 1;

    if (b & 1)
        return a * binpow(a, b - 1) % mod;

    int res = binpow(a, b >> 1);

    return res * res % mod;
}
pair <int, int> a[N];

main()
{
    fc[0] = 1, ifc [0] = 1;

    for (int i = 1; i < N; i++)
        fc[i] = fc[i - 1] * i % mod, ifc[i] = binpow(fc[i], mod - 2);

    cin >> h >> w >> n;

    for (int i = 1; i <= n; i++)
        scanf("%lld%lld", &a[i].fr, &a[i].sc);

    a[++n] = mk(h, w);

    sort(a + 1, a + n + 1);

    for (int i = 1; i <= n; i++)
    {
        dp[i] = get( a[i].fr, a[i].sc );

        for (int j = 1; j < i; j++)
        {
            if (a[j].fr <= a[i].fr && a[j].sc <= a[i].sc)
            {
                dp[i] -= dp[j] * get( a[i].fr - a[j].fr + 1, a[i].sc - a[j].sc + 1) % mod;
                dp[i] += mod;
                dp[i] %= mod;
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 6016
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
const int maxn = 0x3f3f3f3f;
const int mass = 105;
#define clr(arr,val) memset(arr,val,sizeof arr)
using namespace std;
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	if(n % m == 0)
		printf("0\n");
	else
		printf("1\n");
	return 0;
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long

template <class T>
T mymax(T a,T b){
    if(a>=b) return a;
    return b;
}
template <class T>
T mymin(T a,T b){
    if(a<=b) return a;
    return b;
}

ll gcd(ll a, ll b){
    if(a<b){
        swap(a,b);
    }
    while(b){
        ll r = a%b;
        a=b;
        b=r;
    }
    return a;
}

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

struct XX{
    long long x;
    long long jun;
    long long z;
    long long ix;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.x) == (riRight.x)){
            return riLeft.ix < riRight.ix;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.x) < (riRight.x);
    }
};

//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}


int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //cin >> x >> y;
    //テスト用
    //ifstream ifs( "1_06.txt" );
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N,Y;
    cin >> N >> Y;
    
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            if(N-i-j>=0 && 10000*i+5000*j+1000*(N-i-j)==Y){
                cout << i << " " << j << " " << N-i-j << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    
    //ここまで
    //cout << "debug" << endl;
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}



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

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    
    int x=0;
    for(int r=0; r <= N; r++) {
        if(N-r*R < 0) break;
        for(int g=0; g <= N; g++) {
            if(N-r*R-g*G < 0) break;
            if((N-r*R-g*G)%B == 0) x++;
        }
    }
    cout << x << endl;
}

Measured memory_bytes: 384
#include <vector>
#include <cstddef>

template<class T>
struct fenwick_tree {
	using value_type = T;
	using size_type = std::size_t;
private :
	std::vector<T> node;
public :
	fenwick_tree (size_type n) : node(n, 0) { }

	const size_type size () const noexcept {
		return node.size();
	}

	void add (size_type index, const T &value) noexcept {
		index++;
		while (index <= size()) {
			node[index - 1] += value;
			index += (index & -index);
		}
	}

	value_type sum (size_type last) const noexcept {
		value_type value = 0;
		while (last > 0) {
			value += node[last - 1];
			last -= (last & -last);
		}
		return value;
	}

	value_type sum (size_type first, size_type last) const noexcept {
		return (sum(last) - sum(first));
	}

};

#include <iostream>

using usize = std::size_t;

int main() {
	usize n, q;
	std::cin >> n >> q;
	fenwick_tree<long long> ft(n);
	for (usize i = 0; i < n; i++) {
		long long a;
		std::cin >> a;
		ft.add(i, a);
	}
	
	for (usize _ = 0; _ < q; _++) {
		usize type;
		std::cin >> type;
		if (type == 0) {
			usize index;
			long long x;
			std::cin >> index >> x;
			ft.add(index, x);
		} else {
			usize l, r;
			std::cin >> l >> r;
			std::cout << ft.sum(l, r) << '\n';
		}
	}
	
	return 0;
}

Measured memory_bytes: 8216
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>

/*
 *変数
 */
int a,b,arr[3];

/*
 *関数
 */
int ctoi(char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

/*
 *解 
 */
void solve(){
  arr[0]=a+a-1;
  arr[1]=a+b;
  arr[2]=b+b-1;
  std::sort(arr,arr+3);
  printf("%d",arr[2]);
}

/*
 *入力 
 */
int main(){
       std::cin.tie(0);
       std::ios::sync_with_stdio(false);
       std::cin>>a>>b;
       solve();
       return 0;
}

Measured memory_bytes: 256
n = int( raw_input( ) )
minv = int( raw_input( ) )
maxv = 0 - 1000000000
 
for j in range( n-1 ):
  num = int( raw_input( ) )  
  diff = num - minv
  if maxv < diff:
    maxv = diff
  if num < minv:
    minv = num
 
print maxv

Measured memory_bytes: 12636
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n,m,x;cin>>n>>m>>x;
    ll ans=inf*inf;
    vector<ll>c(n);
    vector<vector<ll> >a(n,vector<ll>(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            cin>>a[i][j];
        }
    }
    rep(k,1<<n){
        ll cnt=0;
        vector<ll>b(m);
        rep(j,n){
            if(k&(1<<j)){
                cnt+=c[j];
                rep(i,m){
                    b[i]+=a[j][i];
                }
            }
            bool f=1;
            rep(i,m){
                if(b[i]<x){
                    f=0;
                }
            }
            if(f)ans=min(ans,cnt);
        }
    }
    if(ans==inf*inf)cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 3632