akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

int x, y;
void solve(){
    cin >> x >> y;

    if(y%2==1 || y < 2*x || y > 4*x){
        cout << "No\n";
        return;
    }

    cout << "Yes\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3640
def modelAnswer(A:int,B:int,C:int,X:int,Y:int) -> int:
   ans = 10**9
   for i in range(10**5+1):
      total = i * 2 * C + max(0,X-i) * A + max(0,Y-i) * B
      ans = min(ans,total)
   return ans

def main():
   A,B,C,X,Y=map(int,input().split())
   print(modelAnswer(A,B,C,X,Y))
if __name__ == '__main__':
   main()

Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == 'g')
        {
            count++;
        }
    }
  if(s.size() % 2 == 1)
  {
    cout << count - s.size() / 2 - 1;
  }
  else
  {
    cout << count - s.size() / 2;
  }

    return 0;
}


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

int main(){
	string S;
	cin >> S;
	
	int ans = 0;
	
	rep(i,S.size()-1){
		if(S[i] == '0' && S[i+1] == '0'){
			S[i+1] = '1';
			ans++;
		}
		if(S[i] == '1' && S[i+1] == '1'){
			S[i+1] = '0';
			ans++;
		}
	}
	
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define mp make_pair

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef list<int> li;
typedef vector<li> vli;
typedef vector<vpi> vvpi;
typedef long long i64;

const int inf = 1e9 + 500500;

void solve_e() {
  int n,k,q;
  cin >> n >> k >> q;
  vi a(n);
  forn(i, n) cin >> a[i];
  int ans = inf;
  vi b(a); sort(all(b)); b.erase(unique(all(b)), b.end());
  vi t, z;
  for (int L: b) {
    t.clear(); z.clear();
    for (int x: a) {
      if (x < L) {
        if (t.size() >= k) {
          sort(all(t));
          z.insert(z.end(), t.begin(), t.begin() + t.size() - k + 1);
        }
        t.clear();
      } else t.pb(x);
    }
    if (t.size() >= k) {
      sort(all(t));
      z.insert(z.end(), t.begin(), t.begin() + t.size() - k + 1);
    }
    if (z.size() >= q) {
      sort(all(z));
      uin(ans, z[q - 1] - z[0]);
    } else break;
  }
  cout << ans << endl;
}

int main() {
#ifdef HOME
  freopen("../input.txt", "rt", stdin);
#endif
  solve_e();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

typedef struct edge{
    ll from, to, cost;
}edge;

int main() {
    cin>>N>>M;
    vector<edge> ed(M), rev(M);
    rep(i,M){
        cin>>A>>B>>L;
        --A; --B;
        ed[i].from = rev[i].to = A;
        ed[i].to = rev[i].from = B;
        ed[i].cost = rev[i].cost = L;
    }
    vector<bool> fromN(N,false), updated(N,false);
    vec score1(N,-INF);
    score1[0] = 0;
    rep(i,N){
        for(edge e : ed){
            if((score1[e.from] != -INF) && (score1[e.to] < score1[e.from] + e.cost)){
                score1[e.to] = score1[e.from] + e.cost;
                if(i == N - 1) updated[e.to] = true;
            }
        }
    }
    fromN[N-1] = true;
    rep(i,N){
        for(edge e : rev){
            if(fromN[e.from]) fromN[e.to] = true;
        }
    }
    rep(i,N) {
        if(updated[i] && fromN[i]){
            cout<<"inf"<<endl;
            return 0;
        }
    }
    cout<<score1[N-1]<<endl;
}

Measured memory_bytes: 384
s=list(input())

res=[0]*len(s)

ln=len(s)

pref=[0]*ln
suf=[0]*ln
cur=-1
for n in range(ln-1,-1,-1):
    if s[n]=='L':
        cur=n
    pref[n]=cur
cur=-1
for n in range(ln):
    if s[n]=='R':cur=n
    suf[n]=cur

for n in range(ln):
    if s[n]=='R':
        j=pref[n]-n-1
        if j%2:
            res[pref[n]]+=1
        else:
            res[pref[n]-1]+=1

    else:
        j= suf[n]-n-1

        if j%2:
            res[suf[n]]+=1
        else:
            res[suf[n]+1]+=1

print(*res)



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

int main() {
    int snucks, snacks;
    unordered_set<int> hasSnack;

    cin >> snucks >> snacks;

    while (snacks--) {
        int count, snuck;
        cin >> count;

        while (count--) {
            cin >> snuck;
            hasSnack.insert(snuck);
        }
    }

    int victims = 0;
    for (int i = 1; i <= snucks; ++i)
        if (!hasSnack.count(i))
            ++victims;

    cout << victims << "\n";

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if (S == "RRR"){
    cout << 3 << endl;
  } else if (S == "RRS" || S == "SRR"){
    cout << 2 << endl;
  } else if (S == "SSS"){
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3624
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Thu Jan  3 21:44:08 2019
//
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1e5+10)

func readLine() string {
	buf := make([]byte, 0, 1e5+10)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	s := readLine()

	minVal := len(s)
	for i := range s {
		if i+1 < len(s) && s[i] != s[i+1] {
			n := max(i+1, len(s)-i-1)
			if n < minVal {
				minVal = n
			}
		}
	}

	fmt.Println(minVal)
}


Measured memory_bytes: 896
#include <iostream>
#define INF 10e6
using namespace std;

int M,T,P,R;
int m,t,p,j;
bool flag[50];

bool check(){
	for(int i=0;i<T;i++)
		if(flag[i])
			return true;
	return false;
}

int main(void){
	int team[50][2];
	bool problem[50][10];
	int  time[50][10];
	while(cin >> M >> T >> P >> R,M){
		for(int i=0;i<T;i++)
			team[i][0]=team[i][1]=0,flag[i]=true;
		for(int i=0;i<T;i++)
			for(int j=0;j<P;j++)
				problem[i][j]=false,time[i][j]=0;

		for(int i=0;i<R;i++){
			cin >> m >> t >> p >> j;
			if(j)
				time[t-1][p-1]+=20;
			else
				problem[t-1][p-1]=true,time[t-1][p-1]+=m;
		}
			
		for(int i=0;i<T;i++){
			for(int j=0;j<P;j++){
				if(problem[i][j]){
					team[i][0]++;
					team[i][1]+=time[i][j];
				}
			}
		}
		
		int d=0;
		while(check()){
			cout <<( d ? "," :"") ;
			d++;
			int cor=0,less=INF,c=0;
			for(int i=T-1;i>=0;i--){
				if(flag[i]&&(team[i][0]>cor))
					cor=team[i][0],less=team[i][1];
				else if(flag[i]&&team[i][0]==cor&&team[i][1]<less)
					less=team[i][1];
			}
			for(int i=T-1;i>=0;i--)
				if(flag[i]&&team[i][0]==cor&&team[i][1]==less)
					flag[i]=false, cout<< (c? "=":"") << i+1,c++;
		
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	string s; cin >> s; int x, y; cin >> x >> y;
	vector<int> odd(0), even(0);
	int count = 0;
	int check = 1;
	rep(i,s.size()){
		if(s[i] == 'T'){
			if(check) even.push_back(count);
			else odd.push_back(count);
			count = 0;
			check = 1 - check;
		} else {
			count ++;
		}
	}
	if(check) even.push_back(count);
	else odd.push_back(count);

	vector<vector<bool>> dpx(even.size()+5, vector<bool>(20000));
	vector<vector<bool>> dpy(odd.size()+4, vector<bool>(20000));

	dpx[0][8000+even[0]] = 1;
	dpy[0][8000] = 1;
	For(i,1,even.size()){
		rep(j,17000){
			dpx[i][j] = dpx[i-1][j+even[i]];
			if(j-even[i]>=0)dpx[i][j] = dpx[i-1][j+even[i]] + dpx[i-1][j-even[i]]; 
		}
	}
	rep(i,odd.size()){
		rep(j,17000){
			dpy[i+1][j] = dpy[i][j+odd[i]];
			if(j-odd[i]>=0)dpy[i+1][j] = dpy[i][j+odd[i]]+dpy[i][j-odd[i]]; 
		}
	}
	if(dpx[even.size()-1][x+8000] && dpy[odd.size()][y+8000]){
		puts("Yes");
	} else {
		puts("No");
	}
}


Measured memory_bytes: 23060
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int power(int x, int n)
{
	int power = 1;
	for (int i = 0; i < n; i++) {
		power *= x;
	}
	return power;
}
int main()
{
	int X, j = 2, max = 0;
	scanf("%d", &X);
	for (int i = 1; i <= X; i++) {
		j = 2;
		while (power(i, j) <= X) {
			if (i == 1) {
				max = 1;
				break;
			}
			if (power(i, j) > max) {
				max = power(i, j);
			}
			j++;
		}
	}
	printf("%d", max);
	return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    string s; cin >> s;
    stack<char> t;
    int ans = 0;
    for (char c : s) {
        if (t.empty()) t.push(c);
        else {
            if (c == t.top()) t.push(c);
            else {
                t.pop();
                ans += 2;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int mod = 1000000007;
int n;
string s;
int dp[100001][13];

signed main() {
	cin >> s;
	n = s.length();
	
	int i, j, k;
	
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, 13) {
			rep(k, 10) {
				if (s[i] != '?' && (s[i] - '0') != k) continue;
				(dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= mod;
			}
		}
	}
	
	cout << dp[n][5] << endl;
	return 0;
}

Measured memory_bytes: 10624
N, M = map(int, input().split())
k = []
s = []
p = []
for i in range(M):
    tmpk, *tmps = map(int, input().split())
    k.append(tmpk)
    s.append(tmps)
    s[i] = [x-1 for x in s[i]]
*p, = map(int, input().split())
ans = 0
for pattern in range(2**N):
    flag = True
    for light in range(M):
        tmp = 0
        for i in s[light]:
            tmp += (pattern >> i)&1
        if tmp % 2 != p[light]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

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

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> A(M);
  
  for(int i=0; i<M; i++){
    cin >> A.at(i);
  }
  
  for(int i=0; i<M; i++){
    N-=A.at(i);
    if(N<0){
      N = -1;
      break;
    }
  }
  
  cout << N << endl;
}

Measured memory_bytes: 3632
n=int(input())
a = list(map(int,input().split()))

b=[]
m=0
for i in range(n):
    if m==a[i]:
        continue
    m=a[i]
    b.append(a[i])

c=[]
c.append(b[0])
vec=0
#1:up, 2:down
for i in range(1,len(b)):
    if b[i]>b[i-1]:
        if vec==1 or vec==0:
            vec=1
            continue
        else:
            vec=1
            c.append(b[i-1])
    elif b[i]<b[i-1]:
        if vec==2 or vec==0:
            vec=2
            continue
        else:
            vec=2
            c.append(b[i-1])
c.append(b[-1])

money=1000
for i in range(1,len(c)):
    if c[i]>c[i-1]:
        money=money+(money//c[i-1])*(c[i]-c[i-1])

print(money)
    

Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define lin puts("");
ll n,x,y,a[300000],b[300000],c=0,t=0,sum=0,z=0,i,j,f=0;
char ch[101],cr,ss[101];
string s;
int main()
{
    rep(i,0,2)
    cin>>a[i];	
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    rep(i,0,2)
    cout<<a[i]<<" ";
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;


int main()
{
	long long n;
	cin >> n;

	long long maxDivi = n+1;
	long long sqrtN = sqrt(n);
	for (long long i = 1; i <= sqrtN; i++)
	{
		if (n%i == 0)
		{
			long long j = n/i;
			maxDivi = min(maxDivi, i+j);
		}
	}
	
	cout << maxDivi-2;
	
	return 0;
}


Measured memory_bytes: 256
//
// Created by Naman Bhalla on 2019-04-08.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>

using namespace std;

int main(){
    int a, temp, last, k;

    cin >> a;

    for(int i{}; i < 3; ++i){
        cin >> temp;
    }

    cin >> last >> k;

    if(last - a <= k){
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] h = new int[N];
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
			if (h[i] >= K) {
				cnt++;
			}
		}
		sc.close();
		System.out.println(cnt);
	}
}


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

using namespace std;

int sum(int k){
	int s=0;
	while(k!=0){
		s += (k%10);
		k/=10;
	}
	return s;
}


int main(int argc, char* argv[]){
	long long int N;
	int min;
	cin >> N;
	min = N;
	for(int i=1;i<N/2;i++){
		if(min > (sum(i)+sum(N-i))) min = sum(i)+sum(N-i);
		else continue;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

long long gcd(long long N, long long M){
    while (true){
        if (min(N,M)==0){
            return max(N,M);
        }else if (N>M){
            N%=M;
        }else{
            M%=N;
        }
    }
}

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

    long long rest;
    cin >> rest;
    long long max_=rest;
    for(int i=1; i<N; i++){
        long long A;
        cin >> A;
        rest=gcd(rest, A);
        max_=max(max_, A);
    }
    if(max_<K){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    if(K%rest==0){
        cout << "POSSIBLE" << endl;
    }else{
        cout <<"IMPOSSIBLE" <<endl;
    }

}

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

using namespace std;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;
typedef vector<LL> V;
typedef vector<V> VV;
typedef __int128 INT;
template<typename T>
void chmin(T& a,T b){a=min(a,b);}
template<typename T>
void chmax(T& a,T b){a=max(a,b);}


#define PRO "YES"
#define SHUMI "NO"
#define fin "\n"

int main(){
    int N;
    cin>>N;
    LL a=1,b=1;
    for(int i=0;i<N;i++){
        LL T,A;
        cin>>T>>A;
        INT can=1e18,cannot=0;
        while(can-cannot>1){
            const INT mid=(can+cannot)/2;
            if(T*mid>=a&&A*mid>=b)can=mid;
            else cannot=mid;
        }
        a=T*can;b=A*can;
    }
    cout<<a+b<<endl;

}


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


int main(void) {
ll N;
cin >> N;
ll ans = INF;
for (ll i = 1;i <= sqrt(N);i++) {
string s,t;
if (N % i == 0) {
    ll cnt;
    s = std::to_string(i);
    t = std::to_string(N/i);
    cnt = max(s.size(),t.size());
    ans = min(ans,cnt);
}
}
cout << ans << endl;

return 0;
}





Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define int long long 
#define ll long long 
#define ld long double
using namespace std;
const int INF = 1e18;
const int MOD = 1e9 + 7;


vector<string> vec_splitter(string s) {
				s += ',';
				vector<string> res;
				while(!s.empty()) {
								res.push_back(s.substr(0, s.find(',')));
								s = s.substr(s.find(',') + 1);
				}
				return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
				if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
				stringstream ss; ss << H;
				cerr << args[idx] << " = " << ss.str();
				debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define deb(...) 42
#endif


int32_t main() {
		ios::sync_with_stdio(!cin.tie(NULL));

		int n;
		cin >> n;
		vector<pair<int, int>> edges;
		int u, v;
		for(int i = 0; i < n - 1; i++){
			cin >> u >> v;
			edges.push_back({u, v});

		}
		int res = 0;

		for(int i = 1; i <= n; i++) {
				res += (i * (n + 1 - i));
		}
		int tmp = (n * (n - 1)) / 2;
		for(auto x : edges){
				deb(res);
				u = min(x.first, x.second), v = max(x.first, x.second);
				res -= u * (n + 1 - v);
				deb(res, tmp, ((v - u + 1) * (v - u)) / 2);
		}
		cout << res << endl;
}



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

using namespace std;
#define PROBLEM "C"

int main(){

	#ifdef DBG
	freopen("problem" PROBLEM ".in", "r", stdin);
	freopen("problem" PROBLEM ".out", "w", stdout);
	#endif

	int n;
	while(cin >> n){

		int a[110];
		int b[110];

		for(int i = 0 ; i < n-1 ; i++){

			cin >> b[i];
		}

		a[0] = b[0];
		for(int i = 1 ; i < n ; i++){

			if(i == n-1){

				a[i] = b[i-1];
				break;
			}

			a[i] = min(b[i-1], b[i]);
			a[i+1] = b[i];
		}

		// for(int i = 0 ; i < n ; i++){

		// 	cout << a[i] << " ";
		// }
		// cout << endl;

		cout << accumulate(a, a+n, 0) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
my $n=get;
my ($t,$a)=get.words;
my @h=get.words;
my $f={$t-@h[$^i]*0.006};
my $x=0;
for 1..$n-1 -> $y {if ($f($x)-$a).abs>($f($y)-$a).abs {$x=$y;}}
say $x+1;

Measured memory_bytes: 89888
#include<iostream>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
ll h[100001],dp[100001];
ll frog(ll n, ll k)
{
    if(n == 0) return 0;
    if(n == 1) return abs(h[0] - h[1]);

    if(dp[n] != -1)
        return dp[n];

    ll cost = INT_MAX;
    for(int i=1;i<=k && i<=n;i++)
    {
        cost = min(cost, frog(n-i, k) + abs(h[n-i] - h[n]));
    }
    dp[n] = cost;
    return dp[n];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,k;
    cin >> n >> k;
    for(i=0;i<n;i++) cin >> h[i];
    memset(dp,-1,sizeof(dp));
    cout << frog(n-1, k) << endl;
    return 0;
}

Measured memory_bytes: 13028
#include<stdio.h>
#include<math.h>
#include<stdbool.h>
#include <string.h>


int main()
{
  int N;
  scanf("%d", &N);
  int A[200010];
  int B[200010];
  A[0]=0;
  B[0]=0;
  for(int i=1; i<N; i++){
      scanf("%d",&A[i]);
      B[i]=0;
  }

  for(int i=1; i<N+1; i++){
    B[A[i]-1]++;
  }

  for(int i=0; i<N; i++){
    printf("%d\n",B[i]);
  }
  return 0;
}


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

using namespace std;

using ll = long long;

int w, h;
vector< vector<int> > c, island;

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

void dfs(int x, int y, int id) {

    island[y][x] = id;

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

        int nx = x + dx[i];
        int ny = y + dy[i];

        if(nx < 0 || nx >= w || ny < 0 || ny >= h)
            continue;

        if(c[ny][nx] == 1 && island[ny][nx] != id)
            dfs(nx, ny, id);

    }

}

int main(){

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

    int ans;

    while(cin >> w >> h && w) {

        c.assign(h, vector<int>(w));
        island.assign(h, vector<int>(w, -1));
        ans = 0;

        for(int y = 0; y < h; y++)
            for(int x = 0; x < w; x++)
                cin >> c[y][x];

        for(int x = 0; x < w; x++)
            for(int y = 0; y < h; y++)
                if(c[y][x] == 1 && island[y][x] == -1) {
                    dfs(x, y, ans);
                    ans++;
                }

        cout << ans << endl;

    }
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
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;}
#define MOD 1000000007 //998244353


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

    // solution comes here

    ll N;
    cin >> N;
    vp X(N);// x<B, A>
    rep(i,N) cin >> X[i].S >> X[i].F;
    sortup(X);
    rep(i,N) {
        if(i) X[i].S += X[i-1].S;
        if(X[i].F<X[i].S) {
            cout << "No" << nl;
            return 0;
        }
    }

    cout << "Yes" << nl;
}

Measured memory_bytes: 3328
def resolve():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]
    d = defaultdict(int)
    sumA = 0
    for a in A:
        d[a] += 1
        sumA += a
    Q = int(input())
    BBCC = [list(map(int, input().split())) for _ in range(Q)]
    for b, c in BBCC:
        sumA = sumA + (d[b] * c - d[b] * b)
        tmp = d[b]
        d[c] += tmp
        d[b] = 0
        print(sumA)


resolve()


Measured memory_bytes: 39656
N = int(input())

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

c = 1
j = 0

if 0 in A:
  print(0)
  
else:
  for i in range(N):
    c = c * A[i]
    if c > 10**18:
      j = j
      break
    else:
      j += 1
  if j == N:
    print(c)
  else:
    print(-1)
  

Measured memory_bytes: 21708
//shan61916
#include <bits/stdc++.h>
    using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n" 
typedef long long ll;
typedef unsigned long long ull ;
typedef double dll ;
unordered_map<ll, ll> parent;
void make_set(ll v) {
    parent[v] = v;
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b)
        parent[b] = a;
}
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
   ll n, m;
   cin >> n >> m;
   for(ll i = 1; i <= n; i++) {
    make_set(i);
   }
   for(ll i = 0; i < m; i++) {
    ll x, y,z ;
    cin >> x >> y >> z; 
    union_sets(x, y);
   }
   set<ll> ss;
   for(ll i = 1; i <= n; i++) {
    ss.insert(find_set(i));
   }
   cout << (ll)ss.size() ;

  return 0;
} //good night.

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

#define lli long long int
#define REP(i,n) for(lli i=0;i<n;i++)

 
int main(){

	lli n;
	vector<lli> a;
	cin>>n;
	REP(i,n){
		lli tmp;
		cin>>tmp;
		a.push_back(tmp);
	}
	sort(a.begin(),a.end());
	lli ans[2]={0};
	lli cnt=0;

	for(lli i=a.size()-2;i>=0;i--){
		if(a.at(i) == a.at(i+1)){
			ans[cnt]=a.at(i);
			cnt++;
			i--;
		}
		if(cnt>=2)break;
	}

	cout<<ans[0]*ans[1]<<endl;

	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(b==0) return a;
  else gcd(b,a%b);
}



int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int num=a[0];
  for(int i=1;i<n;i++){
    num=gcd(num,a[i]);
  }
  cout<<num<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int i,j,n,x[30+1];
		for(j=1;j<=30;j++) {
			x[j]=0;
		}
		for(i=1;i<=28;i++) {
			scanf("%d",&n);
			for(j=1;j<=30;j++) {
				if(n==j) {
					x[j]=1;
				}
			}
		}
		for(j=1;j<=30;j++) {
			if(x[j]==0) {
				printf("%d\n",j);
			}
		}
	return 0;
}

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

int comb(int n,int r){
	if(n<r) return 0;
	int mul=1;
	int inv1=1,inv2=1;
	for(int i=1;i<=n;i++){
		mul*=i;
		if(i==r) inv1=mul;
		if(i==n-r) inv2=mul;
	}
	return mul/inv1/inv2;
}

int main(){
	int n;
	cin >> n;
	map<int,int> primes;
	for(int i=2;i<=n;i++){
		int k=i;
		for(int j=2;j*j<=i;j++){
			while(k%j==0){
				primes[j]++;
				k/=j;
			}
		}
		primes[k]++;
	}
	int three=0,five=0,fifteen=0,twentyfive=0,seventyfive=0;
	for(auto itr=primes.begin();itr!=primes.end();itr++){
		if(itr->first==1) continue;
		if(itr->second>=74) seventyfive++;
		if(itr->second>=24) twentyfive++;
		if(itr->second>=14) fifteen++;
		if(itr->second>=4) five++;
		if(itr->second>=2) three++;
	}
	cout << comb(seventyfive,1)+comb(twentyfive,1)*(three>1?three-1:0)+comb(fifteen,1)*(five>1?five-1:0)+comb(five,2)*(three>2?three-2:0) << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# abc144/abc144_b
import sys


def s2nn(s): return [int(c) for c in s.split(' ')]


def ss2nn(ss): return [int(s) for s in list(ss)]


def ss2nnn(ss): return [s2nn(s) for s in list(ss)]


def i2s(): return sys.stdin.readline().rstrip()


def i2n(): return int(i2s())


def i2nn(): return s2nn(i2s())


def ii2ss(n): return [i2s() for _ in range(n)]


def ii2nn(n): return ss2nn(ii2ss(n))


def ii2nnn(n): return ss2nnn(ii2ss(n))


def main():
    N = i2n()
    s = set(range(1, 10))
    for i in range(1, 10):
        if (N/i in s):
            print('Yes')
            return
    print('No')
    return


main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

void rot(string&s, int r, int p){
    s[p]=(s[p]-'0'+r+10)%10+'0';
}

int solve(string a, string& b, int d){
    if(d==a.size()) return 0;
    if(a[d]==b[d]) return solve(a,b,d+1);
    int need=10, r=b[d]-a[d];
    range(i,d,a.size()){
        rot(a,r,i);
        need=min(need,solve(a,b,d+1));
    }
    return need+1;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n;
	while(cin>>n,n){
		string a,b;
		cin>>a>>b;
		cout<<solve(a,b,0)<<endl;
	}
	return 0;
}



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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define endl '\n'

void solvetask(){
    long long n,k,d; cin >> n >> k >> d;
    
    if (n == 0){
        cout << (k & 1 ? d : 0) << endl;
        return;
    }
    if (n < 0) n = -n;
    long long need = n / d;
    if (need > k){
        cout << n - k*d << endl;
        return;
    }
    n -= need*d;
    k -= need;
    if (k & 1) cout << abs(n - d) << endl;
    else cout << n << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solvetask();
}

Measured memory_bytes: 3656
#include <iostream>
#include <numeric>
#include <vector>
#include<math.h>
//#include<cmath>
//#include <stdio.h> 
//#include <cstdint>
//#include <string>
//#include <cstdlib>
//#define pi 3.14159265359
using namespace std;

int main() {

	uint64_t a;
	cin >> a;
	vector<uint64_t> b(a);
	vector<uint64_t> c(a);
	for (uint64_t i = 0; i < a; i++) {
		cin >> b[i];
		c[b[i]] += 1;
	}
	
	uint64_t n = 1;
	uint64_t x = 1;

	if (c[0] != 1 || b[0]!=0) {
		n = 0;
	}

	else {
		for (uint64_t i = 0; i < a-1; i++) {
			if (c[i + 1] == 0 && i+2<a) {
				for (uint64_t j = i + 2; i < a; i++) {
					if (c[j] != 0) {
						n = 0;
						break;
					}
				}
				break;
			}

			if (n == 0) {
				break;
			}

			x = 1;
			for (uint64_t y = 0; y < c[i + 1]; y++) {
				x = x * c[i];
				if (x > 998244352) {
					x = x % 998244353;
				}
			}

			n = n * x;
			if (n > 998244352) {
				n = n % 998244353;
			}
		}
	}

	cout << n;

	return 0;

}

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

int main(){
    int n; cin >> n;
    str s; cin >> s;
    char moji;
    char max = 'Z';
    for(int i=0; i<s.length(); i++){
        moji = s[i];
        moji += n;
        if(moji > 'Z'){
            moji -= 26;
        }
        cout << moji;
    }
    cout << "\n" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		char s ;
		char t ;
		String str= "";

		for(int i=0;i<N;i++) {
			s = S.charAt(i);
			t = T.charAt(i);
			str += String.valueOf(s) + String.valueOf(t);

		}


		System.out.println(str);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define mod 1000000007
int x[2000005],sum[2000005],a[2000005],n,q;
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		x[i+1]--;
		x[max(1,i+1-sum[i])]++;
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		x[i]+=x[i-1];
		if(x[i] == 0) ans++;
	}
	for(int i=0;i<q;i++){
		int c,b; scanf("%d%d",&c,&b);
		if(a[c]+1-sum[a[c]]>=1){
			x[a[c]+1-sum[a[c]]]--;
			if(x[a[c]+1-sum[a[c]]]==0) ans++;
		}
		sum[a[c]]--;
		if(b-sum[b] >= 1){
			x[b-sum[b]]++;
			if(x[b-sum[b]]==1) ans--;
		}
		printf("%d\n",ans);sum[b]++; a[c] = b;
		//for(int i=1;i<=n;i++) cout << x[i] << " "; cout << endl;
	}
}

Measured memory_bytes: 10496
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}


long long int min(long long int a,long long int b){

    if(a>=b){return b;}
    return a;
}

int main(void){
char s[10];
scanf("%s",s);
if(s[0]=='7'||s[1]=='7'||s[2]=='7'){printf("Yes\n");}
else{printf("No");}
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

string s;

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

  cin >> s;
  REP(i, s.size() - 1) {
    if (s[i] == s[i + 1]) {
      printf("%d %d\n", i + 1 , i + 2);
      return 0;
    }
    if (i + 2 < s.size()) {
      if (s[i] == s[i + 2]) {
	printf("%d %d\n", i + 1, i + 3);
	return 0;
      }
    }
  }
  cout << "-1 -1" << endl;

  return 0;
}



Measured memory_bytes: 512
d,g=map(int,input().split())
T=[]
for _ in range(d):
  p,c=map(int,input().split())
  T.append([p,c])

ans=float('inf')
for i in range(1<<d):
  Q=[]
  cnt=0
  score=0
  for j in range(d):
    if (i>>j)&1:
      Q.append(j)
  for v in Q:
    score+=100*(v+1)*(T[v][0])+T[v][1]
    cnt+=T[v][0]
  if score>=g:
    ans=min(ans,cnt)
  else:
    for i in range(d-1,-1,-1):
      if i in Q:
        continue
      if score>=g:
        continue
      rest=T[i][0]
      while rest:
        if score>=g:
          break
        score+=100*(i+1)
        rest-=1
        cnt+=1
    ans=min(ans,cnt)
print(ans)      

Measured memory_bytes: 9244
N = int(input())
A = list(map(int, input().split()))

lst = [0] * (10**5 + 1)
for a in A:
  lst[a] += 1

Q =  int(input())

SUM = sum(A)
#print(lst[:10])

for i in range(Q):
  b, c = map(int, input().split())
  # b の個数
  cnt_b = lst[b]
  SUM += cnt_b * (c  - b)
  print(SUM)
  lst[c] += cnt_b
  lst[b] =  0

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

int count(int h[], int n) {
	if (n == 0) {
		return 0;
	}
	if (n == 1) {
		return h[0];
	}
	int min = 1000;
	int minn;
	for (int i = 0; i < n; i++) {
		if (h[i] < min) {
			min = h[i];
			minn = i;
		}
	}
	int a[100], b[100];
	for (int i = 0; i < minn; i++) {
		a[i] = h[i] - min;
	}
	for (int i = 0; i < n - minn - 1; i++) {
		b[i] = h[minn + 1 + i] - min;
	}
	return(count(a, minn) + count(b, n - minn - 1) + min);
}

int main()
{
	int n;
	cin >> n;
	int h[100];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	cout << count(h, n) << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++) {
        int x;
        scanf("%d", &x);
        n -= x;
    }
    printf("%d\n", max(-1, n));

    return 0;
}


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

int main() {
  int n;
  while(cin>>n, n) {
    int h=0,l=500;
    for(int i=0,k=0; i<n; ++i,k=0) {
      for(int j=0,t; j<5; ++j) {
        cin>>t;
        k += t;
      }
      h = max(h,k);
      l = min(l,k);
    }
    cout<<h<<" "<<l<<endl;
  }
}

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

int main()
{
    int n,x,z=0;
    cin>>n;
    x=n;
    while(x!=0)
    {
        z=(z*10)+x%10;
        x/=10;
    }
    if(z==n)
        cout<<"Yes";
    else
        cout<<"No";


}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1e9+7;
const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; 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;
  }
}

// 二項係数計算
ll 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;
}

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

int main()
{
  int n,m;
  cin >> n >> m;
  map<int, int> mp = prime_factor(m);
  COMinit();
  ll ans = 1;
  for(auto itr: mp){
    ans *= COM(itr.second+n-1, itr.second);
    ans %= MOD;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 12160
import numpy as np
from numba import njit

N, K = map(int, input().split())
A = np.array((list(map(int, input().split()))), dtype=np.int64)

@njit
def imos(A):
    B = np.zeros(N, dtype=np.int64)
    for i,x in enumerate(A):
        a = max(0, i-x)
        b = min(i+x, N-1)
        B[a] += 1
        if b+1 <= N-1:
            B[b+1] -= 1
    B = np.cumsum(B)
    return B

for i in range(K):
    if i >= 50:
        break
    A = imos(A)
print(*A)

Measured memory_bytes: 123528
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <algorithm>
#include <list>
#include <stdlib.h>
#include <stdio.h>
#include <queue>

using namespace std;
typedef long long ll;

static const int INF = (1<<21);
int d[100];

using Mat = vector<vector<int>>;
int N;

int dfs(int u,int N,Mat mat,bool visited[8]){
    
    bool all_visited = true;
    for(int i=0;i<N;i++){
        if(visited[i]==false){
            all_visited=false;
        }
    }
    if(all_visited){
        return 1;
    }
    int ret=0;
    visited[0]=true;
    for(int i=1;i<N;i++){
        if(mat[u][i]==0) continue;
        if(visited[i]) continue;

        visited[i]=true;
        ret+=dfs(i,N,mat,visited);
        visited[i]=false;
    }

    return ret;
}


int main() {
    int M;
    cin >> N >> M;
    Mat mat(N+10,vector<int>(N+10));
    vector<int> A(M+10),B(M+10);
    for(int i=0;i<M;i++){
        cin >> A[i] >> B[i];
        A[i]--,B[i]--;
        mat[A[i]][B[i]]=1;
        mat[B[i]][A[i]]=1;
    }
    bool visited[8];
    for(int i=0;i<N;i++){
        visited[i]=false;
    }
    int as = dfs(0,N,mat,visited);
    cout << as << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    final int m = stdin.nextInt();
	    if ( m == 0 ) {
		break;
	    }
	    int[] vals = new int[m + 1];
	    int[] nums = new int[m + 1];

	    for ( int i = 1; i <= m; i++ ) {
		vals[i] = stdin.nextInt();
		nums[i] = stdin.nextInt();
	    }

	    final int g = stdin.nextInt();
	    for ( int i = 0; i < g; i++ ) {
		final int n = stdin.nextInt();
		solve( n, vals, nums );
	    }
	}	
    }

    static void solve( final int n, final int[] vals, final int[] nums ) {
	final int m = vals.length - 1;
	
	final long[][] dp = new long[m + 1][n + 1];

	//init
	for ( int i = 0; i <= nums[1] && i * vals[1] <= n; i++ ) {
	    dp[1][i * vals[1]] = 1;
	}

	for ( int i = 2; i <= m; i++ ) {
	    for ( int j = 0; j <= n; j++ ) {
		int k = 0;
		while ( k <= nums[i] && j - k * vals[i] >= 0 ) {
		    dp[i][j] += dp[i - 1][j - k * vals[i]];
		    k++;
		}
	    }
	}
	System.out.println( dp[m][n] );
    }    
}

Measured memory_bytes: 24144
abc = input().split(" ")

a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

d = 0

if a == b:
    d = d + 1

if b == c:
    d = d + 1

if c == a:
    d = d + 1

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

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <bits/stdc++.h>

using namespace std;
int main()
{
	long long n;
	cin >> n;	
	if (n < 1200)
		cout << "ABC" << endl;
	else if (n >= 1200 && n < 2800)
		cout << "ARC" << endl;
	else 
		cout << "AGC" << endl;
}              


Measured memory_bytes: 256
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

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

// main function
int main()
{
	ll H = 0;
	ll W = 0;
	ll dx[4] = {0, 0, 1, -1};
	ll dy[4] = {1, -1, 0, 0};
	string ans = "Yes";

	cin >> H >> W;
	vector< string > floor(H);
	Rep(i, H) {
		cin >> floor[i];
	}

	Rep(y, H) {
		Rep(x, W) {
			if ('#' == floor[y][x]) {
				// check
				bool isOK = false;
				Rep(i, 4) {
					ll new_x = x + dx[i];
					ll new_y = y + dy[i];
					if (new_x >= 0 && new_x < W && new_y >= 0 && new_y < H) {
						if ('#' == floor[new_y][new_x]) isOK = true;
					}
				}

				if (!isOK) {
					ans = "No";
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 5e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, nulong long_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int r = 0, w = 0;
    for (auto i : s) {
        r += (i == 'R');
        w += (i == 'W');
    }
    int rns = 0, wns = 0;
    for (int i = 0; i < s.size() && i < r; i++) {
        if (s[i] != 'R') {
            rns++;
        }
    }
    for (int i = s.size() - 1, c = 0; i >= 0 && c < w; i--, c++) {
        if (s[i] != 'W') {
            wns++;
        }
    }
    cout << min(rns, wns) << '\n';
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    string s;
    cin >> s ;
    if(s[0] == s[1] or s[1] == s[2] or s[2] == s[3]){
        cout << "Bad\n" ;
        ro ;
    }
    else cout << "Good\n" ;
    ro ;
}































Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int ans = 0;
    cin >> s;
    rep(i,s.size()-1) {
        if (s[i] != s[i+1]) {
            ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	ll tmp,n,i,sum=0;
	cin>>n;
	tmp=n;
	while(n>0){
		sum+=n%10;
		n/=10;
	}
	if(tmp%sum==0)cout<<"Yes\n";
	else cout<<"No\n";

	return 0;
}

Measured memory_bytes: 256
var log = console.log;
if (typeof process != "undefined") {
	var input = "";
	process.stdin.resume();
	process.stdin.setEncoding('utf8');
	process.stdin.on('data', function (chunk) {
		input += chunk;
	});
	process.stdin.on('end', function () {
		var lines = input.split("\n");
		main(lines);
	});
}

//-----

function main(lines) {
	//??°????????????
	lines = lines.map(function (e) {
		if (e.split(" ").length >= 2) {
			return e.split(" ").map(function (f) {
				return Number(f);
			});
		} else {
			return Number(e);
		}
	});
	//????????????????????????
	while (lines.length > 0) {
		var top = lines.shift();
		var nums = top;
		var N = nums[0];
		var M = nums[1];
		//???????????£????????????????????¢
		if (N == 0 && M == 0) {
			return;
		} else {
			//N+M????????????
			var H = lines.splice(0, N);
			var W = lines.splice(0, M);
			dataset(H, W);
		}
	}
}

//???????????????????????????????????¢??°
function dataset(H, W) {
	//???????????????????????????????????¨????????????????????????????????´????????°??????????????°??????
	//??????????????¨?¨?????????????????????????????????????????????¨???????????????????????´????????°?????????????????????????????¨?????£?????????
	//???????¨??????????N^2??¬???????????§????°??????????
	var HE = listnum(H);
	var WE = listnum(W);
	var cross = crossobj(HE, WE);
	log(cross);
}

//???????????????????????????????????????????????????
function listnum(arr) {
	var len = arr.length;
	var result = {};
	for (var i = 0; i < len; i++) {
		var cur = 0;
		for (var j = i + 1; j <= len; j++) {
			cur += arr[j - 1];
			if (!result[cur]) {
				result[cur] = 1;
			} else {
				result[cur]++;
			}
		}
	}
	return result;
}

function crossobj(A, B) {
	var ret = 0;
	for (key in A) {
		if (!!B[key]) {
			ret += A[key] * B[key];
		}
	}
	return ret;
}

Measured memory_bytes: 64160