akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    if(s[0]!=t[0]){cout<<-1<<endl;return 0;}
    ll g=gcd(n,m);
    if(g==m*n){
        if(s[0]==t[0]&&s[n-1]==t[m-1]){
            cout<<n*m<<endl;return 0;
        }
    }
    ll l=(m/g)*n;
    ll ss=l/n,st=l/m;
    ll sn=0,tn=0;
    while(sn<n*(m/g)&&tn<n*(m/g)){
        if(sn<tn) sn+=ss;
        else if(sn>tn) tn+=st;
        if(sn==tn){
            if(s[sn/ss]!=t[tn/st]){
                cout<<-1<<endl;return 0;
            }
            sn+=ss;
            tn+=st;
        }
    }
    cout<<l<<endl;
    return 0;
}

Measured memory_bytes: 512
from itertools import permutations
import math

n = int(input())
P = [tuple(map(int, input().split())) for _ in  range(n)]

A = list(range(n))
ans = 0

for p in permutations(A):
    x, y = P[p[0]]
    for i in range(1, n):
        a, b = P[p[i]]
        ans += math.sqrt((x - a) * (x - a) + (y - b) * (y - b))
        x, y = a, b

p = 1
for i in range(2, n+1):
    p *= i

print(ans/p)

Measured memory_bytes: 3064
/* ex 7_1
   terakura */

#include <stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;


//頂点を移動させる関数
point shift_point(point point_p, int x_diff, int y_diff){
    point_p.x_elem -= y_diff;
    point_p.y_elem += x_diff;

    return point_p;
}


int main(void){
    int x_diff, y_diff;
    point point_a, point_b, point_c, point_d;
    scanf("%d %d %d %d", &point_a.x_elem, &point_a.y_elem, &point_b.x_elem, &point_b.y_elem);

    //x座標の差とy座標の差を計算
    x_diff = point_b.x_elem - point_a.x_elem;
    y_diff = point_b.y_elem - point_a.y_elem;

    point_c = shift_point(point_b, x_diff, y_diff);
    point_d = shift_point(point_a, x_diff, y_diff);

    printf("%d %d %d %d\n", point_c.x_elem, point_c.y_elem, point_d.x_elem, point_d.y_elem);

    return 0;

}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll t;
    t=1;
    while(t--) /// get diameter nothing else
    {
        ll n;
        cin>>n;
        ll ans=0;
        ans+=(n/500)*1000;
        n=n%500;
        ans+=(n/5)*5;
        cout<<ans;
    }
}


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

int main(void){
  int n, ans = 100000;
  cin >> n;
  for(int i = 0; i < n; i++){
    ans = ans * 1.05;
    if(ans % 1000 != 0)
      ans = ans - ans % 1000 + 1000;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			String s=sc.nextLine();
			int num=0;
			for(int i=0; i<4; i++) {
				if(s.charAt(i)=='+') {
					num++;
				}
				else {
					num--;
				}
			}
			System.out.println(num);
			
			
		}
	}
}



Measured memory_bytes: 23476
def partition(a, p, r)
  x = a[r]
  i = p - 1
  p.upto(r-1) do |j|
    if a[j] <= x
      i = i + 1
      a[i], a[j] = a[j], a[i]
    end
  end
  a[i+1], a[r] = a[r], a[i+1]
  return i + 1
end

n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
index = partition(a, 0, a.size-1)
a[index] = '[' + a[index].to_s + ']'
puts a.join(' ')

Measured memory_bytes: 17660
from collections import Counter

input()
lengths = tuple(map(int, input().split(' ')))
counter = Counter(lengths)

edges = []

for length in sorted(counter.keys(), reverse=True):
    if counter[length] >= 4:
        edges.append(length)
        edges.append(length)
    elif counter[length] >= 2:
        edges.append(length)

    if len(edges) >= 2:
        break

edges.append(0)
edges.append(0)

edges.sort(reverse=True)

print(edges[0] * edges[1])


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


int findSumOfDigits(int n)
{
	int sum = 0;
	while (n > 0)
	{
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

int main()
{
	int N,res;
	res = 0;
	cin >>N;
	if (N % 10 == 0)
	{
		cout << 10 << endl;
	}
	else
	{
		res = findSumOfDigits(N);
		cout << res << endl;
	}
	
		//cout << res << endl;
	

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 5) --> {1,2,3,4}
// rep(i, 5, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, a;
    cin >> n >> a;
    cout << n*n-a;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
	int five = 0, seven = 0;
	int A, B, C;
	cin >> A >> B >> C;
	if (A == 5) {
		five++;
	}
	else {
		seven++;
	}
	if (B == 5) {
		five++;
	}
	else {
		seven++;
	}
	if (C == 5) {
		five++;
	}
	else {
		seven++;
	}
 
	if (five == 2 && seven == 1) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
 
	return 0;
}

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

prime_list = [2]
for i in range(2,5000):
    for j in range(len(prime_list)):
        if i % prime_list[j] == 0:
            break
        else:
            if j == len(prime_list)-1:
                prime_list.append(i)
cnt = 0
for i in range(len(prime_list)):
    if cnt == n:
        break
    elif prime_list[i] % 5 == 2:
        print(prime_list[i])
        cnt += 1


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#define N 100010

using namespace std;

typedef pair<int,int> par;

int n;
int fa[N];
map<par,int> M,A;
multiset<int> S[N];
queue<par> Q;

inline par makep(int x,int y){
    if(x>y) return par(y,x);
    return par(x,y);
}

int find(int x){
    return x==fa[x]?x:fa[x]=find(fa[x]);
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<=2*n-2;i++){
        int x,y; par z;
        scanf("%d%d",&x,&y);
        z=makep(x,y);
        S[x].insert(y); S[y].insert(x);
        if((++M[z])>1&&!A.count(z))
            A[z]=1,Q.push(z);
    }
    for(int k=1;k<n;k++){
        int x,y;
        while(1){
            if(Q.empty()) return puts("NO"),0;
            x=find(Q.front().first),y=find(Q.front().second); Q.pop();
            if(x!=y) break;
        }
        if(S[x].size()>S[y].size()) swap(x,y); fa[x]=y;
        for(set<int>::iterator i=S[x].begin();i!=S[x].end();i++){
            int v=find(*i);
            if(v==y) continue;
            S[y].insert(v); S[v].insert(y);
            if((++M[makep(y,v)])>1&&!A.count(makep(y,v)))
                Q.push(makep(y,v)),A[makep(y,v)]=1;
            S[v].erase(S[v].find(x));
        }
        S[y].erase(x);
        S[x].clear();
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 42496
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N, M, Q;
int L[200010], R[200010];
int acc[505][505];

signed main(){
    cin >> N >> M >> Q;
    REP(i, M){
        cin >> L[i] >> R[i];
        acc[L[i]][R[i]]++;
    }
    REP(i, N){
        REP(j, N){
            acc[i + 1][j + 1] += acc[i + 1][j] + acc[i][j + 1] - acc[i][j];
        }
    }
    int p, q;
    REP(i, Q){
        cin >> p >> q;
        PRINT(acc[q][q] - acc[p - 1][q] - acc[q][p - 1] + acc[p - 1][p - 1]);
    }
    return 0;
}

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

int main(){	
    int n;
    int i;
    int card[4][13] = { {} };
    cin >> n;
    char a;
    int b;
    for (i = 0; i < n; i++) {
        cin >> a >> b;
        switch (a) {
        case 'S':
            card[0][b - 1] = 1;
            break;
        case 'H':
            card[1][b - 1] = 1;
            break;
        case 'C':
            card[2][b - 1] = 1;
            break;
        case 'D':
            card[3][b - 1] = 1;
            break;
        }
    }
    for (i = 0; i < 52; i++) {
        switch (i / 13) {
        case 0:
            if (card[0][i % 13] == 0) cout << "S " << i + 1 << endl;
            break;
        case 1:
            if (card[1][i % 13] == 0) cout << "H " << i % 13 + 1 << endl;
            break;
        case 2:
            if (card[2][i % 13] == 0) cout << "C " << i % 13 + 1 << endl;
            break;
        case 3:
            if (card[3][i % 13] == 0) cout << "D " << i % 13 + 1 << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
 
int main(void) {
 
  int a, b;
  char op;

  scanf("%d %c %d", &a, &op, &b);

  while(op != '?') {
  if(op == '+') {
    printf("%d\n", a + b);
  } else if(op == '-') {
    printf("%d\n", a - b);
  } else if(op == '*') {
    printf("%d\n", a * b);
  } else if(op == '/') {
    printf("%d\n", a / b);
  }
  scanf("%d %c %d", &a, &op, &b);
  }

  return 0;
}

Measured memory_bytes: 1820
#include<iostream>
#include<string>
#include<set>

using namespace std;

int main() {
  set<string> d;
  int n, a;
  string o, b;
  cin >> n;
  for (a = 1; a <= n; a++) {
    cin >> o >> b;
    if (o == "insert") {
      d.insert(b);
    } else {
      decltype(d)::iterator it = d.find(b);
      if (it != d.end()) { // 見つかった
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}
return 0;
}




Measured memory_bytes: 32628
// 2_abc144_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if( i * j == n ){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}
ll n,m;
bool ok(ll a,ll b){
    return a>=0&&b>=0&&a<n&&b<m;
}
ll dx[8]={1,0,-1,0,1,-1,1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};

int main(){
    IOS;
    make2(ll,a,b);
    make(ll,c);
    for(ll i=0;i<b;i++){
        if((i*(a%b))%b==c){
            cout<<"YES \n";
            return 0;
        }
    }
    cout<<"NO \n";


    return 0;
}


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

int main() { /* ここに書く */
  
  int A,B,C;
  cin >> A >> B >> C ;
  
  if( A == B && A == C ){
    cout << "No" << endl;}
  
  else if( A != B && A != C  && B != C ){
    cout << "No" << endl;}
  
  else{
    cout << "Yes" << endl;}
 
  
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for B - Increment Decrement
	var N int
	var S string
	fmt.Scanf("%d\n%s", &N, &S)

	var x int = 0
	var max int = 0
	for i := 0; i < N; i++ {
		if S[i] == 'I' {
			x++
		} else {
			x--
		}

		if max < x {
			max = x
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 1836
#include<stdio.h>

int main(void){

	int S, h, m, s;

	scanf("%d", &S);

	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 3600 % 60;

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define scanf __builtin_scanf
using namespace std;

long s[100010], t[100010];
int main()
{
    int n, m, q; scanf("%d%d%d", &n, &m, &q);
    for(int i=0; i<n; ++i) scanf("%ld", s+i);
    for(int i=0; i<m; ++i) scanf("%ld", t+i);

    auto findLeft=[&](long* A, int N, long x) {
        if (A[0]>x) return -1L;
        int res=0;
        for(int a=1<<19; a>0; a>>=1) {
            int p=res^a;
            if (p<N and A[p]<x) res=p;
        }
        return A[res];
    };
    auto findRight=[&](long* A, int N, long x) {
        if (A[N-1]<x) return -1L;
        int res=(1<<20)-1;
        for(int a=1<<19; a>0; a>>=1) {
            int p=res^a;
            if (p>=N or A[p]>=x) res=p;
        }
        return A[res];
    };


    while (q--) {
        long x; scanf("%ld", &x);
        long res=1L<<62;
        long sL=findLeft(s, n, x);
        long sR=findRight(s, n, x);
        long tL=findLeft(t, m, x);
        long tR=findRight(t, m, x);
        if (sL>=0 and tL>=0) res=min(res, x-min(sL, tL));
        if (sR>=0 and tR>=0) res=min(res, max(sR, tR)-x);
        if (sL>=0 and tR>=0) res=min({res, x-sL+tR-sL, tR-x+tR-sL});
        if (sR>=0 and tL>=0) res=min({res, x-tL+sR-tL, sR-x+sR-tL});
        printf("%ld\n", res);
    }
}


Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
    
       
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) {
    cin >> v[i];
  }
  int ps;
  rep(i,n){
    if (i == 0) ps = v[i];
    else ps ^= v[i];
  }
  rep(i,n){
    v[i] ^= ps;
  }
  rep(i,n){
    cout << v[i] << " ";
  }

 
  
  return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll x; cin >> x;
if(x==0) cout << 1;
else cout << 0;
}

Measured memory_bytes: 3596
#ABC130B - Bounding
N, X = list(map(int,input().split()))
L = list(map(int,input().split()))
count = 1#D1で跳ねる
D = 0
for i in range(N):
    D = D + L[i]
    if D <= X:
        count += 1
print(count)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<vector <int>> v;
  
  if(N%2 ==0){//Nが偶数
    cout << (N*N - N*2)/2<<endl;
    for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++){
        if(j == i || j == N + 1 - i || j < i){
        }else{
          cout << i << " " << j << endl;
        }
      }
    }
  }else{
    cout << (N*N - (N*2-1))/2<<endl;
    for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++){
        if(j == i || j == N - i|| j < i){
        }else{
          cout << i << " " << j << endl;
        }
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int n;
    cin >> n;
    int N = 100010;
    vector<pii> A(N, {0, 0}), B(N, {0, 0});
    REP(i, 0, n) {
        int a;
        cin >> a;
        if (i % 2) {
            A[a].first++;
            A[a].second = a;
        } else {
            B[a].first++;
            B[a].second = a;
        }
    }
    sort(rbegin(A), rend(A));
    sort(rbegin(B), rend(B));
    int ans = N;
    REP(i, 0, 2) {
        REP(j, 0, 2) {
            if (A[i].second != B[j].second) {
                ans = min(ans, n - A[i].first - B[j].first);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

m = [a,b,c,d,e].min

puts((n + m - 1) / m + 4)

Measured memory_bytes: 1788
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000


N = int(input())
T = [int(i) for i in input().split()]
M = int(input()) # juice
PM = [[] for i in range(M)]
for i in range(M):
    PM[i] = [int(i) for i in input().split()]

solve_time = sum(T)
for i in range(M):
    p,m = PM[i]
    print(solve_time-T[p-1]+m)


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

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

constexpr ll MAX_N = 110;
constexpr ll MAX_V = 1000 * 100 + 10;

ll N, W;
ll table[MAX_N][MAX_V];

int main(int argc, char **argv)
{
	cin >> N >> W;

	vector<ll> w(N), v(N);
	for (int i = 0; i < N; ++i) cin >> w[i] >> v[i];

	for (int i = 0; i < MAX_N; ++i)
		for (int j = 0; j < MAX_V; ++j)
			table[i][j] = INF;

	table[0][0] = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int sum_v = 0; sum_v <= MAX_V; ++sum_v)
		{
			if (sum_v - v[i] >= 0)
				chmin(table[i+1][sum_v], table[i][sum_v-v[i]] + w[i]);
			chmin(table[i+1][sum_v], table[i][sum_v]);
		}
	}

	ll res{0};
	for (int i = 0; i < MAX_V; ++i)
	{
		if (table[N][i] <= W) res = i;
	}
	std::cout << res << std::endl;
}



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

/*高速化*/
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* define */
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define Rep(i,n) for(int i = 1;i <= (int)(n);++i)
#define REP(i,n,m) for(int i = (int)(n);i < (int)(m);++i)
#define Mod(n,m) n % m
#define Mod7(n) Mod(n,7)
#define Mod9(n) Mod(n,9)

/* 最大値と最小値に置き換える */
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}


/* 型定義 */
typedef vector<long long> vi;
typedef long long ll;
using Graph = vector<vi>;


/* 定数 */
const double PI = 3.141592;
const double e = 2.6;
const long long Inf = 1LL << 60;
const long long mInf = -Inf;

bool isAGCT(char c)
{
    if(c == 'A' or c == 'G' or c == 'C' or c == 'T')
        return true;
    return false;
}

void calc()
{
    string s;
    cin >> s;
    int res = 0;
    for(int i = 0;i < SZ(s);)
    {
        int j = i;
        while(j < SZ(s) and isAGCT(s[i]) == isAGCT(s[j]))j++;
        if(isAGCT(s[i])) chmax(res,j - i);
        i = j;
    }
    cout << res << '\n';
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    calc();
}


Measured memory_bytes: 256
import math

a, b, h, m = (int(each) for each in input().split())

h_angle = (60*h+m)/2
m_angle = 6*m
angle = abs(h_angle - m_angle)

# 余弦定理
result = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(angle)))
print(result)

Measured memory_bytes: 9568
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int m=1e9,w=0,b=0;
  for(int i=0;i<n;i++){
    if(s[i]=='.'){
      w++;
    }
  }
  for(int i=0;i<n;i++){
    if(s[i]=='.'){
      w--;
    }
    m=min(m,b+w);
    if(s[i]=='#'){
      b++;
    }
  }
  cout << m << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    long long n, a[10010], b[10010], cnt=0;
    cin>>n;
    for (int i=0; i<n; i++) cin>>a[i];
    for (int i=0; i<n; i++) cin>>b[i];
    for (int i=0; i<n; i++)
    {
        if (a[i]<b[i]) cnt+=(b[i]-a[i])/2;
        if (a[i]>b[i]) cnt-=(a[i]-b[i]);
    }
    if (cnt>=0) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;


int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	a *= 100;
	b *= 100;
	int to = a;
	int su = 0;
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			for (int k = 0; k <= 100; k++) {
				for (int t = 0; t <= 100; t++) {
					int wat = a * i + b * j;
					int sug = c * k + d * t;
					if ((wat + sug) <= f && sug * 100 <= wat * e) {
						if (su * (wat + sug) < sug * to) {
							to = wat + sug;
							su = sug;
						}
					}
				}
			}
		}
	}
	cout << to << " " << su << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
  string s, t, u;
  int a, b;
  
  cin >> s >> t >> a >> b >> u;
  
  if(s == u){
    a--;
  }else{
    b--;
  }
  
  cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find((v).begin(), (v).end(), i) != (v).end())
#define ERASE(v,i) (v).erase(remove((v).begin(),(v).end(),i),(v).end())
#define me (*this)

//repetition
//------------------------------------------
#define rep(i,s) for(int i=0; i<(int)(s); i++)

//constant
//--------------------------------------------
const int INF = 100000000;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLEAR(a) memset((a), 0 ,sizeof(a))

//debug
#define debug(x)  cerr << #x << " = " << (x) << endl

struct POS {
	int x, y;
};

POS vec[4] = {
	{1, 0}, // ツ右
	{0, -1}, // ツ湘」
	{-1, 0}, // ツ債カ
	{0, 1} // ツ可コ
};

vint nextAry(vint prev) {
	vint ret;
	rep(i,prev.size()) {
		ret.push_back(count(all(prev), prev[i]));
	}
	return ret;
}

int main() {
	while(1) {
		static int n;
		cin >> n;
		if(!n)
			break;
		vint ary(n);
		rep(i,n) {
			cin >> ary[i];
		}
		int ans = 0;
		bool f = true;
		while(f) {
			ans++;
			vint next = nextAry(ary);
			if(next == ary) {
				f = false;
			}
			ary = next;
		}
		cout << ans - 1 << endl;
		rep(i,ary.size()) {
			printf("%d", ary[i]);
			if(i < ary.size() - 1)
				printf(" ");
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
 
int main(void)
{
    int h, w, i;
 
    while (scanf("%d%d", &h, &w) && h != 0 && w != 0){
        while (h--){
            for (i = 0; i < w; i++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
 
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);

const int MAX = 405;
const int MOD = 1000000007;

int dp[MAX][MAX];
/* dp[i][j]: 1^j+2^j+...+i^j */
ll pow(int i, int j) {
    if (j == 0) { return 1; }
    ll a = ((ll)pow(i,j/2)*pow(i,j/2))%MOD;
    if (j%2) { a*=(ll)i; }
    return a%MOD;
}

int sum(int l, int r, int k) {
    /* l^k+...+r^k */
    return ((ll)dp[r][k] - dp[l-1][k] + MOD) % MOD;
}

int a[MAX];
int b[MAX];

int dp2[MAX][MAX];

int main() {
    FOR(i, 1, MAX) {
        F0R(j, MAX) {
            if (j == 0) { dp[i][j] = i; continue; }
            if (i == 1) { dp[i][j] = 1; continue; }
            dp[i][j] = ((ll)dp[i-1][j] + pow(i, j))%MOD;
        }
    }
    read2(n, c);
    F0R(i, n) { scanf("%d", &a[i]); }
    F0R(i, n) { scanf("%d", &b[i]); }
    for (int i=n-1; i>=0; i--) {
        for (int j=0; j<=c; j++) {
            if (i == n-1) { dp2[i][j] = sum(a[i], b[i], j); continue; }
            for (int k=0; k<=j; k++) {
                dp2[i][j] = ((ll)dp2[i][j] + ((ll)sum(a[i], b[i], k) * dp2[i+1][j-k])%MOD)%MOD;
            }
        }
    }
    println1(dp2[0][c]);
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

const long double pi = 3.141592653589793238462643383279l;

int main()
{
    int a, b, h, m;
    std::cin >> a >> b >> h >> m;

    long double angle = std::abs(h * 30 - m * 6 + m / 2.0);

    long double distance = std::sqrt(a * a + b * b - 2 * a * b * std::cos(angle * pi / 180.0l));

    std::cout << std::fixed << std::setprecision(21) << distance << "\n";

    return 0;
}

Measured memory_bytes: 3608
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define		vii 			vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
#define     test(i)        cout<<i<<endl
int dx[] = {-1 , 1 , 0 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 0 , 1 ,-1 ,-1 , 1 ,-1 , 1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
const int mxN=2e5+5,oo=0x3f3f3f3f,mod=1e9+7;
int n;
int arr[mxN],dp[mxN];
int go(int idx){
    if(idx==n)
        return 0;
    int &ret=dp[idx];
    if(~ret)
        return ret;
    if(idx+2<n)
        return ret=min(go(idx+2)+abs(arr[idx]-arr[idx+2]),go(idx+1)+abs(arr[idx]-arr[idx+1]));
    if(idx+1<n)
        return ret=go(idx+1)+abs(arr[idx]-arr[idx+1]);
    return 0;
}
void solve(){
    cin>>n;
    loop(n,i,0)
        cin>>arr[i];
    mem(dp,-1);
    cout<<go(0)<<endl;
}
int main() {
    fast();
    solve();
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

int solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = max(max(a * c, a * d), max(b * c, b * d));
    cout << ans << endl;
    return 0;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int a, b, c;
   cin >> a >> b >> c;
   if (b - a == c - b)
   {
      cout << "YES" << endl;
   }
   else
   {
      cout << "NO" << endl;
   }
   return 0;
}


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

int N;
vector<string>W(N);
vector<string>already(N);
bool cc(){
    already.push_back(W.at(0));
    for(int i=1;i<N;i++){
    
        rep(j,already.size()){
            if(already.at(j)==W.at(i))return false;
        }

        already.push_back(W.at(i));

        if(!(W[i][0]==W[i-1][W[i-1].size()-1])){
            return false;
        }
    }

    return true;
}

int main(){
    cin>>N;
    W.resize(N);
    already.resize(N);
    rep(i,N)cin>>W.at(i);

    if(cc())cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
a=int(input())
b=list(map(int, input().split()))
c=list(set(b))
t=0
d=[0 for i in range(len(c))]
if a==1:
  print("Yes")
else:
  if len(c)==1:
    if c[0]==0:
      print("Yes")
    else:
      print("No")
  elif len(c)==2:
    for i in range(len(c)):
      e=c[i]
      d[i]=b.count(e)
    if (c[0]==0 and d[0]*2==d[1])or (c[1]==0 and d[1]*2==d[0]):
      print("Yes")
    else:
      print("No")
  elif len(c)>3:
    print("No")
  else:  
    for i in range(len(c)):
      e=c[i]
      d[i]=b.count(e)
    if d[0]==d[1]and d[0]==d[2] and c[0]==c[1]^c[2]:
      print("Yes")
    else:
      print("No")

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

int main()
{
    string input;
    cin >> input;
    char c1, c2;
    int c1Num = 0, c2Num = 0, c3Num = 0;

    for (int i = 0; i < 4; ++i)
    {
        if (c1Num == 0)
        {
            c1 = input[i];
            c1Num = 1;
        }
        else if (input[i] == c1)
        {
            c1Num++;
        }
        else if (c2Num == 0)
        {
            c2 = input[i];
            c2Num = 1;
        }
        else if (input[i] == c2)
        {
            c2Num++;
        }
        else
        {
            c3Num = 1;
        }
    }

    if (c1Num == 2 && c2Num == 2 && c3Num == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}


vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main()
{
  ll N, M;
  cin >> N >> M;
  auto div = divisor(M);
  ll ans = 0;
  rep(i, div.size()) {
    if (div[i] <= M / (double)N) {
      ans = max(div[i], ans);
    }
  }
  print(ans);
  return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int x[n], y[n];
	for (int i = 0; i < n; i++) x[i] = ri(), y[i] = ri();
	int pos[n];
	std::iota(pos, pos + n, 0);
	double sum = 0;
	int num = 0;
	do {
		for (int i = 0; i + 1 < n; i++) {
			sum += sqrt((x[pos[i]] - x[pos[i + 1]]) * (x[pos[i]] - x[pos[i + 1]]) + (y[pos[i]] - y[pos[i + 1]]) * (y[pos[i]] - y[pos[i + 1]]));
		}
		num++;
	} while (std::next_permutation(pos, pos + n));
	printf("%.11f\n", sum / num);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9 +7;
signed main(){
    int n;
    cin>>n;
    int b[n],ans[n];
    for(int i=0;i<n;i++)cin>>b[i];
    int k,t=0;
    for(int i=0;i<n;i++){
        k=n-i;
        for(int j=n-1;j>=0;j--){
            if(b[j]==-1)continue;
            if(b[j]>k){
                t=1;
                break;
            }
            if(b[j]==k){
                ans[n-1-i]=k;
                b[j]=-1;
                break;
            }
            k--;
        }
        if(t==1)break;
    }
    if(t==1)cout<<-1;
    else {
        for(int i=0;i<n;i++){
            cout <<ans[i]<<endl;
        }
    }


    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str):
    week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
    print((-1-week.index(S)) % 7+1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


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

using namespace std;

#define sz(x) (int)(x.size())
#define fr(i, a, b) for(int i=a;i<b;++i)
#define fdr(i, a, b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
///////////////

string NO = "NO";
string YES = "YES";

int r, c;

bool onBoundary(int x, int y){
	bool ok = false;
	if(x == 0 || x == r) ok = true;
	if(y == 0 || y == c) ok = true;
	return ok;
}

vector<pii> a[4];

void push(int x, int y, int id){
	if(x == 0){
		a[3].pb(mp(y, id));
	}else if(x == r){
		a[1].pb(mp(y, id));
	}else if(y == 0){
		a[0].pb(mp(x, id));
	}else{
		a[2].pb(mp(x, id));
	}
}

vector<int> st;

void solve(){
	int n;
	cin >> r >> c >> n;
	bool no = false;
	fr(i, 0, n){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if(!onBoundary(x1, y1) || !onBoundary(x2, y2)) continue;
		push(x1, y1, i);
		push(x2, y2, i);
	}
	fr(i, 0, 4) sort(a[i].begin(), a[i].end());
	reverse(a[1].begin(), a[1].end());
	reverse(a[0].begin(), a[0].end());

	fdr(i, 0, 4){
		fr(j, 0, sz(a[i])){
			if(sz(st)){
				if(st.back() != a[i][j].second){
					st.pb(a[i][j].second);
				}else{
					st.pop_back();
				}
			}else{
				st.pb(a[i][j].second);
			}
		}
	}
	if(sz(st)) no = true;
	if(no) cout << "NO";
	else cout << "YES";
	cout << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

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

using namespace std;

int main()
{
	string s;

	cin >> s;

	if (s == "Sunny")
	{
		cout << "Cloudy" << endl;
	}
	else if(s == "Cloudy")
	{
		cout << "Rainy" << endl;
	}
	else
	{
		cout << "Sunny" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def sieve(n): # エラトステネスの篩
    num = [1]*n
    num[0]=num[1]= 0
    for i in range(int(n**0.5)+1):
        if num[i]:
            for j in range(i**2,n,i):
                num[j] = 0
    return num # list ### 1なら素数0なら合成数

primes = sieve(10**5)
like_2017 = [0]
for i in range(1,len(primes)):
    if i <= 2:
        like_2017.append(like_2017[i-1])
    elif primes[i] == 1 and primes[(i+1)//2] == 1:
        like_2017.append(like_2017[i-1]+1)
    else:
        like_2017.append(like_2017[i-1])
Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    print(like_2017[r]-like_2017[l-1])


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

 
int main(){
    int N;
    double M;
    cin >> N >> M;
    double sum = 0;
    int A[N] = {};
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }
    int res = 0;
    rep(i,N){
        if(A[i] >= sum / (4 * M)) res++;
    }
    cout << (res >= M ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 10e18, q, l;
  scanf("%lld%lld%lld", &n, &k, &q);
  ll a[n];
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }
  for(i = 0; i < n; ++i) {
    vector<ll> v;
    priority_queue<ll> que;
    for(j = 0; j < n; ++j) {
      if(a[j] >= a[i]) {
        que.push(a[j]);
      } else {
        for(l = 0; l < k - 1 && !que.empty(); ++l) que.pop();
        while(!que.empty()) {
          v.push_back(que.top());
          que.pop();
        }
      }
    }
    for(l = 0; l < k - 1 && !que.empty(); ++l) que.pop();
    while(!que.empty()) {
      v.push_back(que.top());
      que.pop();
    }
    sort(v.begin(), v.end());
    /*for(l = 0; l < v.size(); ++l) printf("%lld ", v[l]);
    printf("\n");*/
    if(v.size() >= q && ans > v[q - 1] - v[0]) ans = v[q - 1] - v[0];
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int a,b,c,n=0,i;
	
	scanf("%d%d%d",&a,&b,&c);
	i=a;

	while(i<=b){if(c%i==0)n++; i++;}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, a[100100];
map<int, int> m;
map<int, int>::reverse_iterator it;

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i]);
		m[a[i]]++;
	}
	int fir = -1, sec = -1;
	for(it = m.rbegin(); it != m.rend(); ++it){
		// cout << (*it).f << " " << (*it).s << "\n";
		if(fir == -1) {
			if((*it).s > 3){
				fir = sec = (*it).f;
				break;
			}else if((*it).s > 1){
				fir = (*it).f;
			}
		}else{
			if((*it).s > 1){
				sec = (*it).f;
				break;
			}
		}
	}
	if(fir != -1 && sec != -1){
		cout << 1ll * fir * 1ll * sec;
	}else{
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n,k;
    cin>>n>>k;
    vector<double> p(n);
    rep(i,n) cin>>p.at(i);
    vector<double> e(n);
    rep(i,n){
        e.at(i)=(p.at(i)+1)/2;
    }
    vector<double> s(n+1,0);
    rep(i,n) s.at(i+1)=s.at(i)+e.at(i);

    double emax=0.0;
    for(int i=0;i+k<=n;i++){
        double ans=s.at(i+k)-s.at(i);
        emax=max(emax,ans);
    }

    cout<<fixed<<setprecision(20)<<emax<<endl;
}

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

struct data{
	int x;
	int y;
	int a;
};

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

	int left=0,	right=w,
		up=h,	down=0;

	data d;
	for(int i=0;i<n;i++){
		cin>>d.x>>d.y>>d.a;

		switch(d.a){
			case 1:
				if(left<d.x)left=d.x;
				break;

			case 2:
				if(right>d.x)right=d.x;
				break;

			case 3:
				if(down<d.y)down=d.y;
				break;

			case 4:
				if(up>d.y)up=d.y;
				break;
		}

	}
//	cout<<"Left: "<<left<<endl;
//	cout<<"Right: "<<right<<endl;
//	cout<<"Up: "<<up<<endl;
//	cout<<"Down: "<<down<<endl;

	int x=right-left;	if(x<0)x=0;	
	int y=up-down;		if(y<0)y=0;
	
	cout<<x*y<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int mod_pow(int x,int y) {
    int res = 1;
    while(y > 0) {
        if(y%2) {
            res = res*x%mod;
        }
        x = x*x%mod;
        y/=2;
    }
    return res;
}
int fac[2500], finv[2500], inv[2500];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 2500; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
signed main() {
    int S;
    cin >> S;
    COMinit();
    int ans = 0;
    for(int i = 1; i <= S; i++) {
        if(i*3 > S) {
            break;
        }
        ans += COM(S-i*3+i-1,i-1);
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3696
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int a;
	cin>>a;
	cout<<a/100+a%100/10+a%10<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    for(;;) {
        if (x == 0 && y == 0) {
            return 0;
        }
        if (x > y) {
            printf("%d %d\n", y, x);
        } else {
            printf("%d %d\n", x, y);
        }
        scanf("%d %d", &x, &y);
    }
}


Measured memory_bytes: 2616