akhauriyash/Code-Regression huggingface dataset:
N, X = [int(item) for item in input().split()]
L = [int(item) for item in input().split()][::-1]
D = 0
count = 0
while D <= X:
  if len(L)>0:
    l = L.pop()
    D += l
    count += 1
  else:
    count += 1
    break
  
print (count)

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

int main(){
    string S;
    cin >> S;
    int slen = S.size() / 2 - 1;
    while(1){
        if (S.substr(0, slen) == S.substr(slen, slen)){
            cout << slen * 2 << endl;
            break;
        }
        --slen;
    }
    return 0;
}

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

int main(){
	int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
	int dx = x2 - x1, dy = y2 - y1;
	cout<< x2-dy <<" "<<y2+dx<<" ";
	cout<< x1-dy <<" "<<y1+dx<<endl;
}


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

int main() {

  int n;
  cin >> n;
  int p = 0, w = 0, g = 0, y = 0;
  for (int i = 0; i < n; i++) {
      string A;
      cin >> A;
      if (A == "P" && p == 0) {
          p = 1;
      }
      if (A == "W" && w == 0) {
          w = 1;
      }
      if (A == "G" && g == 0) {
          g = 1;
      }
      if (A == "Y" && y == 0) {
          y = 1;
      }
      if (p == 1 && w == 1 && g == 1 && y == 1) {
          break;
      }
  }
  if(p == 1 && w == 1 && g == 1 && y == 0) {
      cout << "Three" << endl;
  }else{
      cout << "Four" << endl;
  }

}


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

const int MOD = (int) 1e9 + 7;

int A[1000006], X[10004];

void solve(int x)
{
    for(int i=2; i*i<=x; i++)
    {
        int f = 1;

        while(x % i == 0)
            x /= i, f *= i;
        
        A[i] = max(A[i], f);
    }

    if(x > 1)
        A[x] = max(A[x], x);
}

long long power(long long N, long long expo)
{
    long long ans = 1;

    while(expo)
    {
        if(expo % 2)
            ans = ans * N % MOD;
        
        N = N * N % MOD;
        expo /= 2;
    }

    return ans;
}

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

    int N;
    cin >> N;

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

    long long lcm = 1;

    for(int i=1; i<=1000000; i++)
        lcm = lcm * max(1, A[i]) % MOD;
    
    long long ans = 0;

    for(int i=1; i<=N; i++)
        ans += power(X[i], MOD-2);

    ans = ans % MOD * lcm % MOD;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> s(14), h(14), c(14), d(14);
    int n, m;
    char a;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a >> m;
        if(a == 'S') s.at(m) += 1;
        else if(a == 'H') h.at(m) += 1;
        else if(a == 'C') c.at(m) += 1;
        else if(a == 'D') d.at(m) += 1;
    }
    for(int i = 1; i <= 13; i++) if(s.at(i) == 0) cout << "S " << i << endl;
    for(int i = 1; i <= 13; i++) if(h.at(i) == 0) cout << "H " << i << endl;
    for(int i = 1; i <= 13; i++) if(c.at(i) == 0) cout << "C " << i << endl;
    for(int i = 1; i <= 13; i++) if(d.at(i) == 0) cout << "D " << i << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

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

using namespace std;

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

    int i;
    for( i = N; i != 0; i-- )
        if( (int)sqrt(i) * (int)sqrt(i) == i ) break;

    cout << i << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
$s = trim(fgets(STDIN));
$n = strlen($s);
$from0 = 0;
$from1 = 0;

$zero_flg = true;
for ($i=0; $i < $n; $i++) { 
	if ($zero_flg) {
		if ($s[$i] === '1') {
			++$from0;
		}
	}else{
		if ($s[$i] === '0') {
			++$from0;
		}
	}
	$zero_flg = !$zero_flg;
}

$zero_flg = false;
for ($i=0; $i < $n; $i++) { 
	if ($zero_flg) {
		if ($s[$i] === '1') {
			++$from1;
		}
	}else{
		if ($s[$i] === '0') {
			++$from1;
		}
	}
	$zero_flg = !$zero_flg;
}

echo min($from0, $from1);

Measured memory_bytes: 4728
// ?????¬???????????¬?????? (define int long long ?????????)

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

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

int H, W;
char board[110][110];
bool visited[110][110];

void dfs(int x, int y) {
    rep(k,0,4) {
        int nx = x + dx[k], ny = y + dy[k];
        if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
        if(board[nx][ny] != board[x][y]) continue;
        if(visited[nx][ny]) continue;

        visited[nx][ny] = true;
        dfs(nx, ny);
    }
}

int main() {
    while(cin >> H >> W, H || W) {
        memset(visited, false, sizeof(visited));
        rep(i,0,H) rep(j,0,W) cin >> board[i][j];

        int ans = 0;
        rep(i,0,H) rep(j,0,W) {
            if(visited[i][j]) continue;
            ans++;
            dfs(i, j);
        }
        cout << ans << endl;
    }
    return 0;
}

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


int main(){

    long N;
    cin >> N;

    long count = 0;

    for(long i=1;i<=N;i++){
        if(!(i%3==0 || i%5==0)){
            count += i;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 int N,K;
  int p[1000];

int main() {
  cin >> N >> K;
  for(int i=0;i<N;i++) cin >> p[i];
    sort(p, p + N);
  int ans =0;
   for(int i=0;i<K;i++) ans += p[i];
  cout << ans << endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
const int maxn = 100007;
int a[maxn+7];
int prime[maxn+7];
int p,n;
void prime1()
{
    memset(a,0,sizeof(a));
    a[0]=a[1]=1;
    for(int i=2;i<=maxn;i++)
    {
        if(a[i]==0)
        {
            for(int j=2*i;j<=maxn;j+=i)a[j]=1;
        }
    }
}
int main()
{
    cin>>n;
    prime1();
    p=1;
    prime[1]=prime[0]=1;
    for(int i=2;i<=100000;i++)
    {
        int k=(i+1)/2;
        if(i&1)
        {
            if(a[i]==0&&a[k]==0)
            {
                prime[i]=p+1;
                p++;
            }
            else prime[i]=p;
        }
        else prime[i]=p;
    }
    while(n--)
    {
        int c,b;
        cin>>b>>c;
        cout<<prime[c]-prime[b-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int n, M = 1e9 + 7;
    cin >> n;

    vector<int> h(n), dp(n);
    for (auto& i : h) cin >> i;
    for (int i = 1; i < n; ++i) {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        if (i > 1) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp.back() << '\n';

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int x; cin >> x;
    vector<bool> dp(x+110, false);
    dp[0] = true;

    vector<int> v{100, 101, 102, 103, 104, 105};

    rep(i, x+1) if(dp[i]) {
        rep(j, 6) dp[i+v[j]] = true;
    }

    cout << (dp[x]? 1:0) << endl;
    
    return 0;
}

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

using namespace std;

int main() {
	int N; cin >> N;
	int p[N];
	// cin >> p[0];
	
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	sort(p, p+N);
	p[N-1] = p[N-1] / 2;
	long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += p[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
using namespace std;
typedef long long ll;
int main() {
	int r;
	cin >> r;
	if (r < 1200) {
		cout << "ABC" << endl;
		return 0;
	}
	else if (r < 2800) {
		cout << "ARC" << endl;
		return 0;
	}
	else {
		cout << "AGC" << endl;
	}
	system("PAUSE");
	return 0;
}


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

int main() {
	bool ans = true;
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
	}
	int ls = h.at(0);
	if (ls > 0) {
		ls--;
	}
	for (int i = 1; i < n; i++) {
		if (h.at(i) < ls) {
			ans = false;
		}
		if (h.at(i) > ls) {
			ls = h.at(i) - 1;
		}
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

using namespace std;
#define rep(i,n) for(int i=1;i<n+1;i++)
#define ll long long int

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  vector<int> count;
  rep(i,max(A,B)){
    if(A%i==0&&B%i==0){
      count.push_back(i);
      //   cout<<i<<endl;
    }
      
  
  }
  cout<<count[count.size()-K]<<endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    [N, M] = list(map(int, input().split()))
    A = [0 for i in range(N)]
    B = [0 for i in range(M)]
    for i in range(N):
        A[i] = input()
    for i in range(M):
        B[i] = input()
    # print(A)
    # print(B)

    def cmp(i, j):
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                return False
        return True
        

    for i in range(N-M+1):
        for j in range(N-M+1):
            if cmp(i,j):
                print("Yes")
                return
    print("No")
    return

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

ll a[9][9];

int main(){
  int n;
  cin >> n;
  rep(i,n){
    int r=i+1;
    while(r>9){
      r/=10;
    }
    int l = (i+1)%10;
    //cout << r << ' ' << l << endl;
    if(l==0)continue;
    r--,l--;
    a[r][l]++;
  }
  ll ans = 0;
  rep(i,9)rep(j,9){
    //if(a[i][j]==1)continue;
    ans += a[i][j]*a[j][i];
  }
  //rep(i,9)ans += a[i][i]*a[i][i];
  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, V: "List[int]"):
    l = [0] * (K + 1)
    r = [0] * (K + 1)
    for i in range(1, K + 1):
        v = V[:i]
        v.sort(reverse=True)
        for j in range(0, i):
            if i + j <= K:
                l[i + j] = max(l[i + j], sum(v[:i - j]))

    V.reverse()
    for i in range(1, K + 1):
        v = V[:i]
        v.sort(reverse=True)
        for j in range(0, i):
            if i + j <= K:
                r[i + j] = max(r[i + j], sum(v[:i - j]))

    for i in range(1, K + 1):
        l[i] = max(l[i], l[i - 1])
        r[i] = max(r[i], r[i - 1])

    #print(l)
    #print(r)
    ret = 0
    for i in range(0, len(l)):
        ret = max(ret, l[i] + r[K - i])
        #print(l[i], r[K - i], ret)

    tmp = 0
    for v in V:
        if v > 0:
            tmp += v
    ret = min(ret, tmp)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;

int main(void){
	double x1,x2,y1,y2,r1,r2;
	int n;
	cin >> n;
	rep(i,0,n){
		cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2 ;
		x1 = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
		
		if(r1 > x1 + r2){
			cout << 2;
		}
		else if(r2 > x1 + r1){
			cout << -2;
		}
		else if(r1 + r2 < x1){
			cout << 0;
		}
		else{
			cout << 1;
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 1232
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
#include<iostream>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<vector>
#include<list>
using namespace std;
#define getint(n) scanf("%d",&n)
#define both(n,s) scanf("%d %s", &n, s)
#define getstring scanf("%s",s)
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
using namespace std;
#include<unordered_set>
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
# define INF 2147483647
#define _INF -2147483647
#define ss second
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define maxx 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define modd 1000000007;
int main()
{
	int n;
	cin >> n;
	pair<int, int>a[60];
	int ans = 0;
	forn(i, 0, n)cin >> a[i].ff;
	forn(i, 0, n)cin >> a[i].ss;
	forn(i, 0, n)if (a[i].ff - a[i].ss > 0)ans += a[i].ff - a[i].ss;
	cout << ans << 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 A = sc.nextInt();
    int B = sc.nextInt();
    String N = sc.next();
    Boolean bool = true;
    
    try {
      int a = Integer.parseInt(N.substring(0, A));
      int b = Integer.parseInt(N.substring(A+1));
      bool = true;
    } catch (NumberFormatException nfex) {
		bool = false;
	}

    if(N.length() == A+B+1 && N.substring(A, A+1).equals("-") && bool) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int main() {
  int N,i;
  cin >> N;
  for(i=1;i<10;i++) {
    if(N%i == 0 && N/i < 10) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

int main(void){
 	int A, B;
  	cin >> A >> B;
  	if(1<=A&&A<=9&&1<=B&&B<=9){
      	cout << A*B << endl;
    } else {
     	cout << -1 << endl; 
    }
  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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 f(int n)
{
	if(n < 2) return 0;
	if(n == 2) return 1;
	return n-1 + f(n-1);
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, m;
	cin >> n >> m;

	cout << f(n) + f(m) << endl;
	int ans = 0;
	return 0;
}

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

using namespace std;

int dx[] = {0, 0, 1, -1, 1,-1,1,-1};
int dy[] = {1, -1, 0, 0, 1,-1,-1,1};
int m,n;
bool isSafe(int x, int y){
    if(x<0||y<0||x>=n||y>=m)return false;
    return true;
}

int main()
{

    int n,m,k,ans=0;
    scanf("%d %d %d",&n,&m,&k);
    while((n-=k)>=(m+k))
    {
        n-=m;
        ans++;
    }
    printf("%d",ans);
/*
 scanf("%d %d",&n,&m);
 char c[n][m];
 int x[n][m];
 for(int i=0;i<n;i++)
    fill(x[i],x[i]+m,0);

 for(int i=0;i<n;i++)
    scanf("%s",&c[i]);

 for(int i=0;i<n;i++)
 {
     for(int j=0;j<m;j++)
     {
         if(c[i][j]=='.')
         {
             //cout<<" i = "<<i<<" // "<<" j = "<<j<<endl;
             for(int k=0;k<8;k++)
             {
                 if(isSafe(i+dx[k],j+dy[k])&&c[i+dx[k]][j+dy[k]]=='#')
                 {
                     x[i][j]++;
                     //cout<<"x = "<<x[i][j]<<" i = "<<i+dx[k]<<" j ="<<j+dy[k]<<endl;
                 }
             }
         }
     }
 }
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        if(c[i][j]=='.')
            printf("%d",x[i][j]);
        else
            printf("%c",c[i][j]);
    }
    printf("\n");
}
*/
    return 0;
}


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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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





int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin>>n;
    
    vector<int> a(n),buk(100001,0);
    rep(i,n){
        cin>>a[i];
        buk[a[i]]++;
    }

    rep1(i,1,100001){
        ans += (ll)buk[i]*i;
    }

    int q;
    cin>>q;

    rep(i,q){
        int b,c;
        cin>>b>>c;

        ans += (ll)(c-b)*buk[b];

        buk[c] +=buk[b];
        buk[b] = 0;

        cout<<ans<<endl;

    }


    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 4056
N, M, X = map(int, input().split())

C = []
A = []
for i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])

alist = []

for i in range(1 << N):
    mlist = []
    slist = []
    plist = [0] * M # 0要素の数M個のリスト

    for j in range(N):

        if (i >> j) & 1 == 1:
            mlist.append(C[j])
            slist.append(A[j])

    for j in range(len(slist)):
        if len(slist)==1:
            plist = slist[j]
        else:
            plist = [a + b for a, b in zip(plist, slist[j])]

    if all((x >= X for x in plist)) == True:
        alist.append(sum(mlist))

if len(alist) != 0:
    print(min(alist))
else:
    print(-1)


Measured memory_bytes: 9312
#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,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b-1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

static const ll mod  = 1e9 + 7;
static const ll inf  = 1e18;
static const int MAX = 10;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int n, m, ans = 0;
int k[MAX], p[MAX], sw[MAX];
vector<int> s[MAX];

void rec(int point){
    if(point >= n){
        bool flag = 1;
        REP(i, m){
            int sum = 0;
            REP(j, k[i]){
                sum += sw[s[i][j]];
            }
            sum %= 2;
            if(sum != p[i]) return;
        }
        ans++;
    }else{
        sw[point] = 0;
        rec(point+1);
        sw[point] = 1;
        rec(point+1);
    }
}
int main(){
    cin >> n >> m;
    int tmp;
    REP(i,m){
        cin >> k[i];
        REP(j, k[i]){
            cin >>tmp;
            s[i].push_back(tmp-1);
        }
    }
    REP(i,m) cin >> p[i];

    rec(0);
    
    p(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, Z, W;
vi A;
void input() {
  int x, y, z;
  cin >> N >> Z >> W;
  A.resize(N);
  rep(i, 0, N - 1) { cin >> A[i]; };
}
int dp[MX + 5][2];
void solve() {
  int ans = abs(W - A[N - 1]);
  if (N > 1) {
    ans = max(ans, (abs(A[N - 2] - A[N - 1])));
  }
  cout << ans << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    ll N;
    cin>>N;
    set<string> s;
    for(ll i=0;i<N;i++){
        string S;
        cin>>S;
        s.insert(S);
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 19228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N, M, K;
	cin >> N >> M >> K;
	vector<int> A(N), B(M);
	for (auto& x : A) cin >> x;
	for (auto& x : B) cin >> x;
	vector<ll> AA = {0};
	ll sA = 0;
	for (auto x : A) {
		sA += x;
		AA.push_back(sA);
	}
	AA.push_back(1LL<<62);
	vector<ll> BB = {0};
	ll sB = 0;
	for (auto x : B) {
		sB += x;
		BB.push_back(sB);
	}
	int r = 0;
	for (int i = 0; i <= M; ++ i) {
		if (K-BB[i] < 0) break;
		auto it = upper_bound(AA.begin(), AA.end(), K-BB[i]);
		int j = it - AA.begin();
		r = max(r, i+j-1);
	}
	cout << r << endl;
}


Measured memory_bytes: 9552
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std; 

int fun(int a,int b,int c){
    int f,l;
    f=a/2LL; l = a-f;
    return  (abs(f-l)*b*c);
}

inline void solve(){
    int  a,b,c; 
    cin >> a >> b >> c ; 
    int ans=a*b*c;
    if (a&1^1 or b&1^1 or c&1^1) ans=0;
    ans = min(ans,fun(a,b,c));
    ans = min(ans,fun(b,a,c));
    ans = min(ans,fun(c,a,b));
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846

void solve()
{
    ll a, b, k; cin >> a >> b >> k;
    a -= k;
    cout << max(0LL, a) << ' ';
    if(a < 0)
    {
        cout << max(b + a, 0LL);
        return;
    }
    cout << b;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    solve();
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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



 
 
int main(){
    long long a, b, c; std::cin >> a >> b >> c;
    bool okay(false);
    if((c-a-b >= 0) && (4*a*b < (c-a-b)*(c-a-b)))
        okay = true;
    std::cout << (okay ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
 
int main(void) {
    string s, t;
    cin >> s >> t;
    char toS[26];
    char toT[26];
    for (Int i = 0; i < 26; ++i) {
        toS[i] = '.';
        toT[i] = '.';
    }
    Int len = t.length();
    bool res = true;
    for (Int i = 0; i < len; ++i) {
        if (toT[(Int)(s[i] - 'a')] == '.') {
            toT[(Int)(s[i] - 'a')] = t[i];
        } else if (toT[s[i] - 'a'] != t[i]) {
            res = false;
        }
        if (toS[(Int)(t[i] - 'a')] == '.') {
            toS[(Int)(t[i] - 'a')] = s[i];
        } else if (toS[t[i] - 'a'] != s[i]) {
            res = false;
        }
    }
    if (res == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 100000007;
#define fr first
#define sc second
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
vl p, fac(2, 1), ifac(2, 1);

ll ad(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod) % mod;
}

ll ml(ll a, ll b, ll mod = md) {
    return ( (a%mod) * (b%mod) ) % mod;
}

ll pw(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = (n >> 1);
        x = (x*x)%mod;
    }
    return res;
}

int mu(ll n) {
	int c = 1, pn = p.size();
	for(int i = 0; i < pn && p[i] * p[i] <= n; i++) {
		if(n%p[i] == 0) c = -c, n /= p[i];
		if(n%p[i] == 0) return 0;
	}
	if(n > 1) return -c;
	return c;
}

void sieveMU(ll n, vl &mu) {
    vl factor(n+1, 0);
    for(int i = 2; i * i <= n; i++) {
        if(!factor[i]) {
            for(int j = i * i; j <= n; j += i) factor[j] = i;
        }
    }
    mu[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!factor[i]) {
            mu[i] = -1;
            continue;
        }
        if((i/factor[i])%factor[i] == 0) {
            mu[i] = 0;
        } else {
            mu[i] = (-1)*mu[i/factor[i]];
        }
    }
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

ll C(ll n, ll r) {
    if(n < r || r < 0) return 0;
    return ml(fac[n], ml(ifac[r], ifac[n-r]));
}

ll P(int n, int r) {
    if(n < r || r < 0) return 0;
    return ml(fac[n], ifac[n-r]);
}

void sieve(ll n) {
    vector<bool> prime(n+1, true);
    for(int i = 2; i*i <= n; i++) {
        if(prime[i]) {
            for(int j = i*i; j <= n; j += i) {
                prime[j] = false;
            }
        }
    }
    p.push_back(2);
    for(int i = 3; i <= n; i += 2) {
        if(prime[i]) p.push_back(i);
    }
}

ll PIE(ll n, ll k, ll f, ll mod = md) {
	if(f < 0 || k < 0 || n < 0) return 0;
	ll ans = 0, l = min(n, k/(f+1));
	for(int i = 0; i <= l; i++) {
		ans = ad(ans, (i&1 ? -1 : 1) * ml(C(n, i), C(n - 1 + k - (f+1) * i, k - (f+1) * i)));
	}
	return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vl a(n);
    for(int i = 0; i < n; i++) {
    	cin >> a[i];
    }
    ll h = 0;
    for(int i = 1; i < n; i++) {
    	if(a[i] < a[i-1]) {
    		ll cur = a[i-1] - a[i];
    		h += cur;
    		a[i] += cur;
    	}
    }
    cout << h << "\n";
    return 0;
}

Measured memory_bytes: 4780
w,h,n=map(int,input().split())
A=[[int(i) for i in input().split()] for l in range(n)]
o=[]
for y in range(h):
    p=[]
    for x in range(w):
        p.append(1)
    o.append(p)
for a in A:
    if a[2]==1:
        for y in range(h):
            for x in range(a[0]):
                o[y][x]=0
    if a[2]==2:
        for y in range(h):
            for x in range(a[0],w):
                o[y][x]=0
    if a[2]==3:
        for y in range(a[1]):
            for x in range(w):
                o[y][x]=0
    if a[2]==4:
        for y in range(a[1],h):
            for x in range(w):
                o[y][x]=0
print(sum(map(sum,o)))

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

int main(){
  	int n;
  	cin >> n;
  
  	cout << "Christmas";
  	n = 25 - n;
  
  	rep(i,0,n){
      cout << " Eve";
    }
  
  cout << 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 ll long long
int main(){
    int n,m;
    cin >> n;
    vector<string>s(n);
    rep(i,n) cin >> s[i];
    cin >> m;
    vector<string>t(m);
    rep(i,m) cin >> t[i];
    int ans=0;

    rep(i,n){
        string card;
        int cnt=0;
        card = s[i];
        rep(j,n){
            if(card == s[j]) cnt++;
        }
        rep(j,m){
            if(card == t[j]) cnt--;
        }
        ans = max(ans,cnt);
    }
    if(ans<0){
        cout << 0 << endl;
    }
    else cout << ans <<endl;
}
    


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

const int MAX_S = 8001;
bool dp_x[2][2*MAX_S];
bool dp_y[2][2*MAX_S];
int dx[MAX_S];
int dy[MAX_S];

int main() {
  string s;
  cin >> s;
  s.append(1, 'T');
  int x, y;
  cin >> x >> y;

  bool axis_change_flag = true;
  int lx = 0, ly = 0;
  for (unsigned long i = 0; i < s.length(); i++) {
    if (s[i] == 'F') {
      if (axis_change_flag) {
	dx[lx] += 1;
      }
      else {
	dy[ly] += 1;
      }
    }
    else {
      if (axis_change_flag) {
	lx++;
      }
      else {
	ly++;
      }
      axis_change_flag = !axis_change_flag;
    }
  }

  // cout << "x: ";
  // for (int i = 0; i < lx; i++) {
  //   cout << dx[i] << " ";
  // }
  // cout << endl;
  // cout << "y: ";
  // for (int i = 0; i < ly; i++) {
  //   cout << dy[i] << " ";
  // }
  // cout << endl;

  int rx = 0;
  dp_x[rx][MAX_S + dx[0]] = true;
  for (int i = 1; i < lx; i++) {
    int next_rx = (rx + 1) % 2;
    // cout << i << endl;
    for (int j = 0; j < 2*MAX_S; j++) {
      // cout << j << endl;
      int px = j - dx[i];
      int qx = j + dx[i];
      bool ux = (px >= 0 ? dp_x[rx][px] : false);
      bool vx = (qx < 2*MAX_S ? dp_x[rx][qx] : false);
      // if (ux || vx) {
      // 	cout << j << " ";
      // 	cout << qx << " " << ux << " ";
      // 	cout << px << " " << vx << endl;
      // }
      dp_x[next_rx][j] = ux || vx;
    }
    rx = next_rx;
  }

  int ry = 0;
  dp_y[ry][MAX_S + dy[0]] = true;
  dp_y[ry][MAX_S - dy[0]] = true;
  for (int i = 1; i < ly; i++) {
    int next_ry = (ry + 1) % 2;
    // cout << i << endl;
    for (int j = 0; j < 2*MAX_S; j++) {
      //cout << j << endl;
      int py = j - dy[i];
      int qy = j + dy[i];
      bool uy = (py >= 0 ? dp_y[ry][py] : false);
      bool vy = (qy < 2*MAX_S ? dp_y[ry][qy] : false);
      // if (uy || vy) {
      // 	cout << j << " ";
      // 	cout << qy << " " << uy << " ";
      // 	cout << py << " " << vy << endl;
      // }
      dp_y[next_ry][j] = uy || vy;
    }
    ry = next_ry;
  }

  cout << (dp_x[rx][x + MAX_S] && dp_y[ry][y + MAX_S]? "Yes" : "No") << endl;

}

Measured memory_bytes: 384
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(m):
  c,d=map(int,input().split())
  if c==1:
    a[d-1]=1
  if d==n:
    b[c-1]=1
success=0
for i in range(1,n):
  if a[i]*b[i]==1:
    success=1
if success==1:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

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

using lint = long long int;
using Graph = std::vector<std::vector<lint>>;

template<class T>
struct edge
{
	T dist;
	lint to;
	edge(){}
	edge(const T &a_dist,const lint &a_to) : dist(a_dist), to(a_to) {}
	~edge(){}
};

int main(int argc,char *argv[])
{
	int n;
	std::cin >> n;

	std::vector<char> a(n,0);
	for(int i = 0;i < n;++i) std::cin >> a[i];

	if(n%2 != 0)
	{
			std::cout << "No" << std::endl;
			return 0;
	}

	for(int i = 0;i < n/2;++i)
	{
		if(a[i] != a[i+n/2]) 
		{
			std::cout << "No" << std::endl;
			return 0;
		}
	}
	std::cout << "Yes" << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int n,x,p=1;
int a[450][450];

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=450&&!x;i++)
		if ((i+1)*i==(n<<1)) x=i;
	if (!x) return puts("No"),0;
	puts("Yes");
	printf("%d\n",x+1);
	for (int i=1;i<=x;i++)
		for (int j=1;j<=i;j++,p++)
			a[i][j]=p;
	for (int i=1;i<=x;i++)
	{
		printf("%d",x);
		int xx=i,yy=1;
		while (a[xx][yy]) printf(" %d",a[xx][yy++]);
		--yy;++xx;
		while (a[xx][yy]) printf(" %d",a[xx++][yy]);
		putchar('\n');
	}
	printf("%d",x);
	for (int i=1;i<=x;i++) printf(" %d",a[i][i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2048
N,Q = map(int,input().split())
A = list(map(int,input().split()))
X = [list(map(int,input().split())) for _ in range(Q)]
A.sort()
X.sort(key=lambda x:-x[1])
ans = sum(A)
left = 0
right = 0
for i in range(Q):
	if right > N:
		break
	else:
		right = left + X[i][0]
		for j in range(left,min(right,N)):
			if A[j] < X[i][1]:
				ans = ans-A[j]+X[i][1]
	left = right
print(ans)

Measured memory_bytes: 36168
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll n,k,q,ans;
ll a[Max];
ll score[Max];
void solve(){
	cin>>n;
	rep(i,0,n-1)cin>>score[i];
	ll ans=score[0]+score[n-2];
	rep(i,1,n-1){
		ans+=min(score[i],score[i-1]);
	}
	cout<<ans;
}
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

int N, M;
int ans;
unsigned edges[32];

inline int bsf(unsigned x) {
  __asm__("bsf %1, %0;" : "=r"(x) :"r"(x));
  return x;
}

inline int bsr(unsigned x) {
  __asm__("bsr %1, %0;" : "=r"(x) :"r"(x));
  return x;
}

void minimum_dominating_set(unsigned D) {
  if (__builtin_popcount(D) >= ans) { return; }
  bool ok = true;
  for (int x = ~D & ((1<<N)-1); x; x &= x-1) {
    if ((edges[bsf(x)] & D) == 0) { ok = false; break; } 
  }
  if (ok) {
    ans = __builtin_popcount(D);
  } else {
    FOR(i, D ? bsr(D)+1 : 0, N) {
      minimum_dominating_set(D | (1 << i));
    }
  }
}

int main() {
  while (scanf("%d%d", &N, &M), N|M) {
    REP(i, N) { edges[i] = 1 << i; }
    REP(i, M) {
      int s, t; scanf("%d%d", &s, &t);
      edges[s] |= 1 << t;
      edges[t] |= 1 << s;
    }
    ans = 1000;
    minimum_dominating_set(0);
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
int main(){
	int n;
        string s; 
       cin>>n>>s;
	map<char,int> count_;
	for(int i=0; i<n; i++)
                    count_[s[i]]++;
	ll res = (ll)count_['R'] * count_['G'] * count_['B'];
	for(int i=0; i<n-2; i++)
		for(int j=i+1,k=i+2; k<n;  k+=2,j++)
			if((s[i]^s[j]^s[k]) == ('R'^'G'^'B')) 
                                     res--;
	cout<< res <<endl;
}

Measured memory_bytes: 3648
#include "iostream"
#include "string"
#include "algorithm"
#include "cmath"
#define eps 10e-9
using namespace std;
typedef struct crop
{
	string name;
	double eff;

	static bool comp(const crop& l, const crop& r)
	{
		if(abs(l.eff-r.eff)>eps) return l.eff>r.eff;
		return l.name<r.name;
	}
}crop;


int main(void)
{
	int n;
	while (cin>>n,n) {
		crop in[n];
		for (int i = 0; i < n; i++) {
			cin>>in[i].name;
			int p,a,b,c,d,e,f,s,m;
			cin>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			int t=a+b+c+(d+e)*m;
			in[i].eff=(f*m*s-p)*1.0/t;
		}
		sort(in,in+n,crop::comp);
		for (int i = 0; i < n; i++) {
			cout<<in[i].name<<endl;
		}
		cout<<"#"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int N, M;
int ans=0;
vector<vector<int> > lp;
void dfs(int d,int parent,vector<int> visited){
    
    if(d==N){
        ans++;
    }else{
        for(int i=0;i<lp[parent].size();i++){
            if(!vector_finder(visited,lp[parent][i])){
           
                vector<int> l(visited);

                l.push_back(lp[parent][i]);
                dfs(d+1,lp[parent][i],l);
            }
        }
    }
}

int main()
{
    cin >> N >> M;
    lp.resize(N);
    REP(i,0,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        lp[a].push_back(b);
        lp[b].push_back(a);
    }
    vector<int> visited(1);
    visited[0]=0;

    dfs(1,0,visited);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int l, r;
    cin >> l >> r;
    if (r / 2019 - l / 2019 > 0) {
        cout << 0 << endl;
        return 0;
    }
    ll mn = 2018;
    for (ll i = l; i < r; ++i) {
        for (ll j = i+1; j <= r; ++j) {
            chmin(mn, (i * j) % 2019);
        }
    }
    cout << mn << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long int ll;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h, a;
    cin >> h >> a;
    ll ans = (h / a);
    if(h % a == 0)
    {
        cout << ans << endl;
    }
    else
    {
        cout << ans + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def solve(n, t, t_list):
    total = t
    prev = t_list[0]
    for i in t_list[1:]:
        if i - prev >= t:
            total += t
        else:
            total += i - prev
        prev = i
    return total

if __name__ == "__main__":
    n, t = [int(i) for i in input().split()]
    t_list = [int(i) for i in input().split()]
    print(solve(n, t, t_list))

Measured memory_bytes: 25200
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline lint nxi(){
		lint x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	lint x=nxi(),y=nxi();
	lint lim=std::min(x,y>>1);
	y-=lim*2;
	printf("%lld\n",lim+(y>>2));
}


Measured memory_bytes: 256