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

int main(){
        string s;
        cin >>s;
        if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
        {
                cout << "Bad" << endl;
        }
        else
        {
                cout <<"Good" << endl;
        }
}


Measured memory_bytes: 3548
import bisect
from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
A = list(accumulate(A))
s = A[-1]
ans = float("inf")
for i in range(1, n-2):
  left = bisect.bisect(A, A[i]//2)
  right = bisect.bisect(A, (A[i]+s)//2)
  lm = float("inf")
  lM = 0
  rm = float("inf")
  rM = 0
  ld = float("inf")
  rd = float("inf")
  for j in range(-1, 2):
    if 0 <= left+j < i:
      a = A[left+j]
      b = A[i] - a
      if ld > abs(b-a):
        ld = abs(b-a)
        lm = min(a, b)
        lM = max(a, b)
    if i <= right+j < n-1:
      a = A[right+j] - A[i]
      b = s - A[right+j]
      if rd > abs(b-a):
        rd = abs(b-a)
        rm = min(a, b)
        rM = max(a, b)
  ans = min(ans, max(lM, rM) - min(lm, rm))
print(ans)

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

string s;
int k;

int main(){
  cin >> s >> k;
  char res;
  rep(i, k){
    if(s.at(i) != '1'){
      res = s.at(i);
      break;
    }
    if(i == k - 1){
      res = '1';
      break;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>

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

using namespace std;



int main() {
    char c;
    cin >> c;
    char d = c + 1;
    cout << d << endl;

    return 0;
}


Measured memory_bytes: 3544
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a, b; cin >> a >> b;
	if (a > 0) cout << "Positive\n";
	else if (b > 0)cout << "Zero\n";
	else{
		if ((b - a) % 2 == 1)cout << "Positive\n";
		else cout << "Negative\n";
	}
	char c; cin >> c;
}

Measured memory_bytes: 256
/* ex 7_1
   Sagzar1993 */

#include <stdio.h>

//頂点を表す構造体
typedef struct point{
    int x_elem;
    int y_elem;
} point;

//頂点を引数の分だけ移動した先の頂点を返す
point shift_point(point pnt, int x_move, int y_move){
    point pntMoved;
    pntMoved.x_elem = pnt.x_elem + x_move; //pntをx方向にx_moveだけ移動
    pntMoved.y_elem = pnt.y_elem + y_move; //pntをy方向にy_moveだけ移動
    return pntMoved;
}

int main(void){
    int delta_x, delta_y;
    point pnt1, pnt2, pnt3, pnt4; //正方形の各頂点
    //頂点１、頂点２の座標を入力
    scanf("%d %d %d %d", &pnt1.x_elem, &pnt1.y_elem, &pnt2.x_elem, &pnt2.y_elem);

    delta_x = pnt2.x_elem - pnt1.x_elem; //頂点２と頂点１のx座標の差
    delta_y = pnt2.y_elem - pnt1.y_elem; //頂点２と頂点１のy座標の差

    //頂点３は、頂点２からx方向に-delta_y, y方向にdelta_xだけ移動させた点
    pnt3 = shift_point(pnt2, -delta_y, delta_x);
    //頂点４は、頂点１からx方向に-delta_y, y方向にdelta_xだけ移動させた点
    pnt4 = shift_point(pnt1, -delta_y, delta_x);

    printf("%d %d %d %d\n", pnt3.x_elem, pnt3.y_elem, pnt4.x_elem, pnt4.y_elem); //出力

    return 0;
}

Measured memory_bytes: 1716
#include <iostream>

using namespace std;

int a, b;

int main(void)
{
	cin >> a >> b;
	
	if(b >= 0 && a <= 0){
		cout << "Zero" << endl;
		return 0;
	}
	
	if(a > 0){
		cout << "Positive" << endl;
		return 0;
	}
	
	if( (b-a+1) % 2 ) cout << "Negative" << endl;
	else cout << "Positive" << endl;
	
	return 0;
}

Measured memory_bytes: 256
// Problem : D - Xor Sum 2
// Contest : AtCoder Regular Contest 098
// URL : https://atcoder.jp/contests/arc098/tasks/arc098_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()

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

int n, a[N], x[N];
ll ans = 0, s[N];

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
		x[i] = x[i - 1] ^ a[i];
	}
	for (int i = 1; i <= n; i++) {
		int c = i;
		for (int j = log2(n - i); j >= 0; j--) {
			c += 1 << j;
			if (c > n || s[c] - s[i - 1] != (x[c] ^ x[i - 1])) {
				c -= 1 << j;
			}
		}
		ans += c - i + 1;
	}
	cout << ans;
}


Measured memory_bytes: 3328
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

p2 = [((e+1)*e / 2) / e for e in p]
res = sum(p2[:K])
ans = res
for i in range(K, N):
    res -= p2[i-K]
    res += p2[i]
    ans = max(ans, res)

print(ans)


Measured memory_bytes: 24804
#include <iostream>
#include <vector>
#include <cmath>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 998244353;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int n,m;
vector< vector<int> > a(300, vector<int>(300, 0));

int calc_rank(vector< vector<int> > a) {
    // int n = a.size(), m = a[0].size();

    int rank = 0;
    for(int j=0;j<m;++j) {
        int pivot = -1;
        for(int i=rank;i<n;++i) {
            if(a[i][j]) {
                pivot = i;
                break;
            }
        }
        if(pivot == -1) continue;
        if(pivot != rank) for(int j=0;j<m;++j)  swap(a[pivot][j], a[rank][j]);
        for(int i=rank+1;i<n;++i) {
            if(a[i][j]) for(int j=0;j<m;++j) a[i][j] ^= a[rank][j];
        }
        ++rank;
    }

    // for(int i=0;i<n;++i) {
    //     for(int j=0;j<m;++j) {
    //         cerr << a[i][j] << " ";
    //     }
    //     cerr << "\n";
    // }

    return rank;
}

ll modpow(ll a, ll t) {
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= MOD;
        }
        a *= a;
        a %= MOD;
        t >>= 1;
    }
    return ret;
}

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i=0;i<n;++i) for(int j=0;j<m;++j) cin >> a[i][j];
    int r = calc_rank(a);
    cout << (modpow(2LL, n+m-1) - modpow(2LL, n+m-r-1) + MOD) % MOD << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <stdio.h>

using namespace std;

#define SIZE 2000001
#define COUNT_SIZE 10001

int main(void)
{
  int *A, *B;
  int i, j, n, C[COUNT_SIZE];

  scanf("%d", &n);
  
  A = (int *)malloc(sizeof(int) * (n + 1));
  B = (int *)malloc(sizeof(int) * (n + 1));
 
  for(i = 0;i <= COUNT_SIZE;i++){
    C[i] = 0;
  }

  for(j = 1;j <= n;j++){
    scanf("%d",&A[j]);
    C[A[j]]++;
  } 

  for(i = 1;i <= COUNT_SIZE;i++){
    C[i] = C[i] + C[i - 1];
  }

  for(j = n;j >= 1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
    }

  for(i = 1;i < n;i++){
    printf("%d ", B[i]);
  }

  printf("%d\n", B[i]);
  
  return 0;
}



Measured memory_bytes: 18832
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    string S;
    cin >> S;
    int A = S[0]-'0';
    int B = S[1]-'0';
    int C = S[2]-'0';
    int D = S[3]-'0';
    if(A+B+C+D == 7) {
        cout << A << '+' << B << '+' << C << '+' << D << '=' << 7 << endl;
        return 0;
    }
    if(A+B+C-D == 7) {
        cout << A << '+' << B << '+' << C << '-' << D << '=' << 7 << endl;
        return 0;
    }
    if(A+B-C+D == 7) {
        cout << A << '+' << B << '-' << C << '+' << D << '=' << 7 << endl;
        return 0;
    }
    if(A-B+C+D == 7) {
        cout << A << '-' << B << '+' << C << '+' << D << '=' << 7 << endl;
        return 0;
    }
    if(A+B-C-D == 7) {
        cout << A << '+' << B << '-' << C << '-' << D << '=' << 7 << endl;
        return 0;
    }
    if(A-B-C+D == 7) {
        cout << A << '-' << B << '-' << C << '+' << D << '=' << 7 << endl;
        return 0;
    }
    if(A-B+C-D == 7) {
        cout << A << '-' << B << '+' << C << '-' << D << '=' << 7 << endl;
        return 0;
    }
    cout << A << '-' << B << '-' << C << '-' << D << '=' << 7 << endl;
}

Measured memory_bytes: 256
import numpy as np 

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

A = np.array(A,np.int64)##Ai<2^60

ans = 0
mod = int(1e9+7)

for i in range(60+1):
    bottom_bit = (A>>i)&1 ##i回シフトしたときの最下位bit
    ones = np.sum(bottom_bit[bottom_bit>0])
    ##ans += (N-ones)*ones*(2**i) ##0の個数*1の個数*2^i個
    tmp = ones*(N-ones)
    for j in range(i):
        tmp = (tmp * 2) % mod
    ans += tmp

print(ans%mod)

Measured memory_bytes: 48872
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define int long long int
using namespace std;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    b*=2;
    cout<<max((int)0,a-b);
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<cctype>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

  ll N,X,T;
  ll ans = 0;

  cin >> N >> X >> T;

  while(N > 0){
    N -= X;
    ans += T;
  }

  cout << ans << endl;

  return 0;

}   


Measured memory_bytes: 3632
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 55;
const int MAX = 5050;

ll dp[MAX_N][MAX];
const int BASE = MAX/2;

int main(){
	int n, A;
	cin >> n >> A;
	vi x(n);
	rep(i, n) cin >> x[i], x[i]-=A;

	dp[0][BASE] = 1LL;
	rep(i, n) {
		rep(j, MAX) dp[i+1][j] += dp[i][j];
		rep(j, MAX) {
			int k = j + x[i];
			if(k >= 0 && k < MAX) {
				dp[i+1][k] += dp[i][j];
			}
		} 
	}

	cout << dp[n][BASE] -1LL<< endl;
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
#define SEG_LEN (1 << 18)
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
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); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  ll n,k;
  cin >> n >> k;
  ll ans = 0;
  REP(b,1,n + 1){
    ll tmp = b - k;
    if(tmp <= 0)continue;
    if(k != 0)ans += (tmp + 1) * (n / b) - (n / b) + max((ll)0,(n % b) - k + 1);
    else ans += n;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
	string S;
	cin>>S;
	if(S[2]==S[3]&&S[4]==S[5]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<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);
        while(true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) break;
            if(m == -1 || f == -1) { System.out.println('F'); continue; }
            if(m + f >= 80) { System.out.println('A'); continue; }
                if(m + f >= 65) { System.out.println('B'); continue; }
                if(m + f >= 50) { System.out.println('C'); continue; }
            if(m + f >= 30) {
                    if(r >= 50) System.out.println('C');
                else System.out.println('D');
                continue;
            }
            System.out.println('F');
             
        }
    }
}



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

ll k, n, mod=1e9+7;

bool cmp (ll a, ll b) {
	return (abs(a)<abs(b));
}

int main() {
	cin>>n>>k;
	ll a[n];
	for (int i=0; i<n; i++) {
		cin>>a[i];
	}
	sort(a, a+n, cmp);
	vector <ll> vpos, vneg;
	for (int i=n-1; i>=n-k; i--) {
		if (a[i]<0) vneg.push_back(a[i]);
		else vpos.push_back(a[i]);
	}
	if (vneg.size()%2==0) {
		ll ans=1;
		for (auto i: vneg) {
			ans*=(-i);
			ans%=mod;
		}
		for (auto i: vpos) {
			ans*=i;
			ans%=mod;
		}
		cout<<ans<<endl;
	}
	else {
		ll apos=-1, aneg=-1;
		for (int i=n-k-1; i>=0; i--) {
			if (a[i]>=0) {
				if (vpos.size()>0) apos=a[i]*vpos.back();
				else apos=a[i];
				break;
			}
		}
		for (int i=n-k-1; i>=0 && !vpos.empty(); i--) {
			if (a[i]<0) {
				aneg=a[i]*vneg.back();
				break;
			}
		}
		if (apos>aneg) {
			if (!vpos.empty())vpos.pop_back();
			vneg.pop_back();
			ll ans=apos%mod;
			for (auto i: vneg) {
				ans*=(-i);
				ans%=mod;
			}
			for (auto i: vpos) {
				ans*=i;
				ans%=mod;
			}
			cout<<ans<<endl;
		}
		else if (apos!=-1||aneg!=-1) {
			if (!vpos.empty()) vpos.pop_back();
			vneg.pop_back();
			ll ans=aneg%mod;
			for (auto i: vneg) {
				ans*=(-i);
				ans%=mod;
			}
			for (auto i: vpos) {
				ans*=i;
				ans%=mod;
			}
			cout<<ans<<endl;
		}
		else {
			ll ans=1;
			for (int i=0; i<k; i++) {
				if (a[i]<0) a[i]+=mod;
				ans*=a[i];
				ans%=mod;
			}
			cout<<ans<<endl;
		}
	}
}



Measured memory_bytes: 6816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'
#define fi first
#define se second

int n;
map<string, int> mp;
void run(){
    int n; cin >> n;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;
    string s;
    while(n--){
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << '\n';
    cout << "WA x " << mp["WA"] << '\n';
    cout << "TLE x " << mp["TLE"] << '\n';
    cout << "RE x " << mp["RE"] << '\n';
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    run(); return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
#define INF 1e+8
int main(){
  int n, a;
  double t, h, dst = INF;
  int ans = -1;
  cin >> n >> t >> a;
  for(int i=1;i<=n;i++){
    cin >> h;
    if(dst > abs(a-(t-h*0.006))){
      ans = i;
      dst = abs(a-(t-h*0.006));
    }
  }
  cout << ans << endl;
}

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

vector<vector<bool>> grid;
int h,w;
vector<vector<vector<int>>> dpv;

int dp(int x, int y, bool inrect){
	if (dpv[x][y][inrect]!=-1){
		return dpv[x][y][inrect];
	}
	//cout<<x<<" "<<y<<" "<<inrect<<endl;
	if (x==w-1&&y==h-1){
		return 0;
	}
	int minuse = 1e9;
	if (!inrect){
		//white
		if (y+1<h){
			if (grid[x][y+1]){
				minuse=min(minuse,dp(x,y+1,false));
			} else {
				minuse=min(minuse,1+dp(x,y+1,true));
			}
		}
		if (x+1<w){
			if (grid[x+1][y]){
				minuse=min(minuse,dp(x+1,y,false));
			} else {
				minuse=min(minuse,1+dp(x+1,y,true));
			}
		}
	} else {
		//black
		if (y+1<h){
			if(!grid[x][y+1]){
				minuse=min(minuse,dp(x,y+1,true));
			} else {
				minuse=min(minuse,dp(x,y+1,false));
			}
		}
		if (x+1<w){
			if (!grid[x+1][y]){
				minuse=min(minuse,dp(x+1,y,true));
			} else {
				minuse=min(minuse,dp(x+1,y,false));
			}
		}
	}
	return dpv[x][y][inrect]=minuse;
}


int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>h>>w;
	grid.resize(w,vector<bool>(h));
	for (int y = 0; y<h; y++){
		for (int x = 0; x<w; x++){
			char c;
			cin>>c;
			if (c=='.'){
				grid[x][y]=1;
			} else {
				grid[x][y]=0;
			}
		}
	}
	dpv.resize(w,vector<vector<int>>(h,vector<int>(2,-1)));
	if (grid[0][0]){
		cout<<dp(0,0,false)<<endl;
	} else {
		cout<<1+dp(0,0,true)<<endl;
	}
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		java.util.Scanner scanner = new java.util.Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		int mincount = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int count = 0;
			while (a[i] % 2 == 0) {
				a[i] = a[i] / 2;
				count++;
			}
			mincount = Math.min(count, mincount);
		}
		System.out.println(mincount);
	}
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int X;
	cin >> X;

	if (X == 3 || X == 5 || X == 7)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct {
    int to;
    int from;
    int cost;
}edge;

int main() {
    int i, j, n, k, u, v, c, cnt = 0,flag=1;
    edge E[500000];
    int wei[10000];
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d%d", &u, &k);

        for (j = 0; j < k; j++) {
            E[cnt].from = u;
            scanf("%d%d", &v, &c);
            E[cnt].to = v;
            E[cnt].cost= c;
            cnt++;
        }
    }

    for (i = 0; i < n; i++) wei[i] = 1000000000;
       
    wei[0] = 0;

    while (flag!=0) {
        flag = 0;
        for (i = 0; i < cnt; i++) {
            if (E[i].cost + wei[E[i].from] < wei[E[i].to]) {
                wei[E[i].to] = E[i].cost + wei[E[i].from];
                flag = 1;
            }
        }
    }

    for (i = 0; i < n; i++) printf("%d %d\n", i, wei[i]);

    return 0;
}




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

using namespace std;

#define ll long long
#define mod 998244353

void solve(){
    char c;
    cin>>c;
    if(c >= 'A' && c <= 'Z'){
        cout<<'A';
    }else{
        cout<<'a';
    }
}

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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef pair<int, int> pint;

int H, W;
struct Edge { int num, to; Edge(int n, int t) : num(n), to(t) {}};
vector<vector<Edge>> edges;
bool bfs(int broken_edge, vector<int>& dist) {
    dist[(H - 1) * W + W - 1] = 0;
    queue<int> que; que.push((H - 1) * W + W - 1);
    while(!que.empty()) {
        int cur = que.front(); que.pop();
        for(const Edge& e : edges[cur]) {
            if(e.num == broken_edge || dist[e.to] != INF) continue;
            dist[e.to] = dist[cur] + 1;
            que.push(e.to);
        }
    }
    return dist[0] == INF;
}

int solve(const vector<vector<int>>& wdist) {
    vector<int> dist(H * W, INF);
    priority_queue<pint, vector<pint>, greater<pint>> que;
    dist[(H - 1) * W + W - 1] = 0; que.emplace(0, (H - 1) * W + W - 1);
    auto upd = [](int& a, int b) { return a > b ? (a = b, true) : false;};
    while(!que.empty()) {
        int cos, node;
        tie(cos, node) = que.top(); que.pop();
        if(dist[node] < cos) continue;
        for(const Edge& e : edges[node]) {
            int ncos = max(cos + 1, wdist[e.num][e.to]);
            if(upd(dist[e.to], ncos)) que.emplace(ncos, e.to);
        }
    }
    return dist[0];
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    while(cin >> H >> W && H) {
        int t_, edgenum = 0;
        edges.assign(H * W, vector<Edge>());
        rep(i, H) {
            rep(j, W - 1) {
                cin >> t_;
                if(t_ == 0) {
                    edges[i * W + j].emplace_back(edgenum, i * W + j + 1);
                    edges[i * W + j + 1].emplace_back(edgenum, i * W + j);
                    ++edgenum;
                }
            }
            if(i == H - 1) continue;
            rep(j, W) {
                cin >> t_;
                if(t_ == 0) {
                    edges[i * W + j].emplace_back(edgenum, (i + 1) * W + j);
                    edges[(i + 1) * W + j].emplace_back(edgenum, i * W + j);
                    ++edgenum;
                }
            }
        }
        vector<vector<int>> wdist(edgenum, vector<int>(H * W, INF));
        rep(i, edgenum) if(bfs(i, wdist[i])) goto fail;
        cout << solve(wdist) << endl;
        continue;
      fail:
        cout << "-1" << endl;
    }
    return 0;
}

Measured memory_bytes: 9112
#include<bits/stdc++.h>
const int maxn=1e5+9;
using namespace std;
int main()
{
	int i,ac=0,wa=0,vis[maxn]={0},x,n,m,sum[maxn]={0};
	char s[10];
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%s",&x,s);
		if(vis[x])continue;
		if(s[0]=='A')vis[x]=1,ac++,wa+=sum[x];
		else sum[x]++;
	}
	printf("%d %d\n",ac,wa);
}

Measured memory_bytes: 1024
N,M=map(int,input().split())
A=list(map(int,input().split()))
d=0

for i in range(N):
  if A[i]>=sum(A)/(4*M):
    d+=1
    i+=1
  else:
    i+1
    
if d>=M:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

bool isPrime(ll n) {
    if (n < 2)return false;
    for (ll i = 2; i * i <= n; i++)if (!(n % i))return false;
    return true;
}
vector<bool> prime_table(int n) {
    vector<bool> prime(n + 1, true);
    if (n >= 0)prime[0] = false;
    if (n >= 1)prime[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (!prime[i])continue;
        for (int j = i + i; j <= n; j += i) {
            prime[j] = false;
        }
    }
    return prime;
}

ll POW(ll n, ll p) {
    ll ret = 1;
    for (; p > 0; p >>= 1, n = n * n % mod) {
        if (p & 1)ret = ret * n % mod;
    }
    return ret;
}
ll INV(ll n) { return POW(n, mod - 2); }

int main() {
    init();

    int k; cin >> k;
    ll ans = 0;
    eFOR(a, 1, k)eFOR(b, 1, k){
        int g = gcd(a, b);
        if (g == 1)ans += k;
        else eFOR(c, 1, k) {
            ans += gcd(g, c);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
int p[110000];
int sh[110000];
pair<int,int> lat[110000];
int goal[110000];
int num[110000];
int rev[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int c;scanf("%d",&c);
	for(int i=0;i<c;i++){
		scanf("%d",p+i);
		p[i]--;
	}
	for(int i=0;i<b;i++)sh[i]=-1;
	
	for(int i=c-1;i>=0;i--){
		if(sh[p[i]]==-1){
			sh[p[i]]=i;
		}
	}
	for(int i=0;i<b;i++)lat[i]=make_pair(-sh[i],i);
	std::sort(lat,lat+b);
	for(int i=0;i<b;i++)goal[i]=lat[i].second;
	for(int i=0;i<b;i++)rev[goal[i]]=i;
	bool ok=true;
//	for(int i=0;i<b;i++)printf("%d\n",p[i]);
	for(int i=c-1;i>=0;i--){
		if(rev[p[i]]==0||num[rev[p[i]]]<num[rev[p[i]]-1]){
			num[rev[p[i]]]++;
		}
	}
	int fp=99999999;
	for(int i=0;i<b;i++){
		if(num[i]<a){
			fp=i;break;
		}
	}
	for(int i=fp;i<b-1;i++){
		if(goal[i]>goal[i+1])ok=false;
	}
	if(ok)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 2944
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int r; cin >> r;
    
    if(r<1200) cout << "ABC" << ln;
    else if(r<2800) cout << "ARC" << ln;
    else cout << "AGC" << ln;
    return 0;
}

Measured memory_bytes: 256
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
suma = [0]
sumb = [0]
for i in range(n):
    suma.append(suma[-1] + a[i])
for i in range(m):
    sumb.append(sumb[-1] + b[i])
ans = 0
for anum in range(n+1):
    remainder = k - suma[anum]
    if remainder < 0:
        break
    bnum = bisect.bisect_right(sumb, remainder)
    ans = max(ans, anum + bnum - 1)
print(ans)

Measured memory_bytes: 47556
#include <bits/stdc++.h>
using namespace std;
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; }

long long dp[330][330];
vector<long long> w(330, 0);
int n;

long long rec(int l, int r) {
    long long res = 0;
    if(dp[l][r] != -1) return dp[l][r];
    if(abs(l-r) <= 1) return 0;
    if(abs(w.at(l)-w.at(r-1)) <= 1 && rec(l+1, r-1) == r-l-2) {
        res = r-l;
    }
    for(int mid = l+1; mid <= r-1; ++mid) {
        chmax(res, rec(l, mid)+rec(mid, r));
    }
    return dp[l][r] = res;
}

int main() {
    while(1) {
        cin >> n;
        if(n == 0) break;
        for(int i = 0; i < n; ++i) cin >> w.at(i);
        for(int i = 0; i <= n; ++i) {
            for(int j = 0; j <= n; ++j) {
                dp[i][j] = -1;
            }
        }
        cout << rec(0, n) << endl;
    }    
}


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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    

    ll test=1;
    // cin>>test;
    while(test--)
    {
        map<ll,ll> mp;

        ll n;
        cin>>n;

        ll sum=0;

        for(ll i=0;i<n;i++)
        {
            ll x;
            cin>>x;

            mp[x]++;

            sum+=x;
        }

        ll q;
        cin>>q;

        while(q--)
        {
            ll from,to;
            cin>>from>>to;

            if(mp[from]!=0)
            {
                sum-=(from*(mp[from]));
                sum+=(to*(mp[from]));
                mp[to]+=mp[from];
                mp[from]=0;
            }

            cout<<sum<<endl;
        }
    }
}

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

static const int A = 80;
static const int B = 65;
static const int C = 50;
static const int D = 30;

int main(void) {
    int tmpResult, M, F, R;
    vector<char> results;

    while(true) {
        cin >> M >> F >> R;
        if(M == -1 && F == -1 && R == -1) break;
        if(M == -1 || F == -1) {results.push_back('F'); continue;}

        tmpResult = M + F;
        if(tmpResult >= A) {results.push_back('A'); continue;}
        if(tmpResult >= B) {results.push_back('B'); continue;}
        if(tmpResult >= C) {results.push_back('C'); continue;}
        if(tmpResult >= D && R >= C) {results.push_back('C'); continue;}
        if(tmpResult >= D) {results.push_back('D'); continue;}
        results.push_back('F');
    }

    for(auto result: results)
        cout << result << endl;

    return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=1e5+9;

int n,m,siz[N],red[N];

int main()
{
	n=read();
	m=read();
	for(int i=1;i<=n;i++)
		siz[i]=1;
	red[1]=1;
	for(int i=1,u,v;i<=m;i++)
	{
		u=read();v=read();
		if(red[u])
			red[v]=1;
		siz[v]++;
		if((--siz[u])==0)
			red[u]=0;
	}

	int ans=0;
	for(int i=1;i<=n;i++)
		if(red[i])
			ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}	
int a[114514],b[114514];
char c[114514];	
signed main(){
	ic(n) ic(k) sc(s)
	int sum=0;
	rep(0,i,n-1)if(s[i]!=s[i+1])sum++;
	c(n-1-max(0,sum-k*2))
}	

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

int main() {

  string S;
  cin >> S;

  string answer = "Yes";

  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      if(S[i] == 'L') {
        answer = "No";
        break;
      }
    } else {
      if(S[i] == 'R') {
        answer = "No";
        break;
      }
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second 
#define ll long long 
#define _for(i,j,k) for(int i=j;i<k;i++)
#define endl  '\n'
#define inf 1<<29
const int mod=1e9+7;
const int MAX=1e6+5;
// ll a[MAX]; 
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll x;
	cin>>x;
	cout<<x/500*1000+(x-x/500*500)/5*5;
	
	
}

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

int main() {
    int N;
    int A[110];
    int count = 0;
    int res = 0;

    cin >> N;

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

      while (true) {
        if ( (A[i]%2) == 0 ) {
          A[i] /= 2;
          count += 1;
        } else {
          A[i] = count;
          count = 0;
          break;
        }
      }
    }

    for (int i=1; i<N+1; ++i) {
      if (count <= A[i]) {
        count = A[i];
        res = i;
      }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    int N;
    cin >> N;
    char S[N];
    rep(i, N) cin >> S[i];

    int ans = 0;
    int temp = 0;
    for(int i = 1; i < N; ++i) {
        temp = 0;
        set<char> answer1, answer2;
        answer1 = {};
        answer2 = {};
        for(int j = 0; j < N; ++j) {
            if(j < i) answer1.insert(S[j]);
            else answer2.insert(S[j]);
        }
        for(char j = 'a'; j <= 'z'; ++j) {
            set<char>::iterator iti1 = answer1.find(j);
            set<char>::iterator iti2 = answer2.find(j);
            if(iti1 != answer1.end() && iti2 != answer2.end()) ++ temp;
        }

        ans = max(ans, temp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long;
int main() {
	// your code goes here
	int n,ans=0;
	cin>>n;
	string s[50];
	string X;
	int t[50];
	for(int i=0;i<n;i++){
		cin>>s[i]>>t[i];
	}
	cin>>X;
	for(int i=n-1;i>=0;i--){
		if(s[i]==X)
		break;
		ans+=t[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = 0
for i in range(1,n+1):
    cnt = 0
    if i % 2 == 0:
        continue
    for j in range(1,i+1):
        if i % j == 0:
            cnt += 1
    if cnt == 8:
        ans += 1
print(ans)

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

int main() {
    int n; cin >> n;
    vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    priority_queue<pair<long long, int>> pq;
    for (int i = 0; i < n; i++) {
        pq.push({b[i], i});
    }
    long long cnt = 0;
    while (!pq.empty()) {
        auto curr = pq.top(); pq.pop();
        int i = curr.second;
        long long y = curr.first;
        long long x = b[(n+i-1)%n];
        long long z = b[(n+i+1)%n];
        long long t = y - ((y-a[i]) / (x+z)) * (x+z);
        long long s = y - ((y - max(x,z) + (x+z-1)) / (x+z)) * (x+z);
        long long u = max(t, s);
        cnt += (y-u) / (x+z);
        b[i] = u;
        if (b[i] != a[i]) pq.push({b[i], i});
        if (b[i] != a[i] && y == u) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 9584
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int check(string c){
    char a[20] = {"23456789TJQKA"};
    int i;
    rep(i,14)if(a[i] == c[0])break;
    return i;
}

int main(void) {
    int i,j;
    string s;
    while(cin >> s, s != "#"){
        char card[4][13][5];
        rep(i,4)rep(j,13) cin >> card[i][j];
        int win[2] = {};
        int leader = 0;
        rep(i,13){
            int t = 0, ts = 0;//2:切り札,1:リーダー,0:その他
            rep(j,4){
                if(card[j][i][1] == s[0]){
                    if(ts != 2) t = j, ts = 2;
                    else if(check(card[j][i]) > check(card[t][i])) t = j, ts = 2;
                }else if(card[j][i][1] == card[leader][i][1]){
                    if(ts == 1 && check(card[j][i]) > check(card[t][i]))t = j, ts = 1;
                    if(ts == 0) t = j, ts = 1;
                }else{
                    if(ts == 0 && check(card[j][i]) > check(card[t][i]))t = j, ts = 0;
                }
            }
            win[t%2]++;
            leader = t;
        }
        if(win[0] < win[1]){
            cout << "EW " << win[1] - 6 << endl;
        }else{
            cout << "NS " << win[0] - 6 << endl;
        }
    }
}



Measured memory_bytes: 3140
#include <iostream>

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s)a--;
    if(u==t)b--;
    cout<<a<<' '<<b;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n,m; cin>>n>>m;
  vector<int> f(n,-1);
  queue<int> q={};
  vector<vector<int>> v(n);
  rep(i,0,m){
    int a,b; cin>>a>>b;
    pb(v[a-1],b-1);
    pb(v[b-1],a-1);
  }
  q.push(0); f[0]=1000000;
  while(!q.empty()){
    int x=q.front(); q.pop();
    rep(i,0,v[x].size()){
      if(f[v[x][i]]==-1){
        q.push(v[x][i]);
        f[v[x][i]]=x;
      }
    }
  }
  rep(i,0,n) if(f[i]==-1){co("No"); return 0;}
  co("Yes");
  rep(i,1,n){
    co(f[i]+1);
  }
  return 0;
}

Measured memory_bytes: 10164
from decimal import Decimal
import math
 
A = list(input().split())
 
for i in range(2):
    if i == 0:
        A[i] = int(A[i])
    elif i == 1:
        A[i] = Decimal(A[i])
 
ans = A[0] * A[1]
 
print(math.floor(ans))

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	llong ans = 0;
	llong l,r;

	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> l >> r;
		ans += r-l+1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
require 'pp'

h, w = gets.chomp!.split(" ").map(&:to_i)
routes = []

tails = []
h.times do |i|
    a_w = gets.chomp!.split(" ").map(&:to_i)

    count = 0
    while a_w.length != 1
        x = a_w.shift
        if x % 2 != 0
            routes << [i + 1, count + 1, i + 1, count + 2]
            a_w[0] += 1
        end


        count += 1
    end

    tails << a_w[0]
end

count = 0
while tails.length != 1
    x = tails.shift
    if x % 2 != 0
        routes << [count + 1, w, count + 2, w]
        tails[0] += 1
    end

    count += 1
end

puts routes.length
routes.each do |route|
    puts route.join(" ")
end


Measured memory_bytes: 27924
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string a;
  bool yellow = false;
  
  for (int i = 0; i < N; i++){
	cin >> a;
    if(a == "Y"){
	 yellow = true;
    }
  }
  if (yellow){
	cout << "Four";
  }else{
	cout << "Three";
  }
  
}

Measured memory_bytes: 256
import math

a, b, c = map(int,input().split())

s = a * b * 0.5 * math.sin(math.radians(c))
l = a + b + (a**2 + b**2 - 2 * a * b * math.cos(math.radians(c))) ** 0.5
h = b * math.sin(math.radians(c))

print(s)
print(l)
print(h)



Measured memory_bytes: 5716
import java.util.Scanner;
import java.util.*;
public class Main {
	static int[] ar;
	static int n;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (true) {
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			int c = stdIn.nextInt();
			if(a == 0 && b == 0 && c == 0) {
				break;
			}
			boolean[] ar = new boolean[a];
			boolean[] br = new boolean[b];
			boolean[] cr = new boolean[c];
			int n = stdIn.nextInt();
			int[] acr = new int[n];
			int[] bcr = new int[n];
			int[] ccr = new int[n];
			boolean[] tfr = new boolean[n];
			for (int i = 0; i < n; i++) {
				int tmpa = stdIn.nextInt();
				int tmpb = stdIn.nextInt();
				int tmpc = stdIn.nextInt();
				int tf = stdIn.nextInt();
				acr[i] = tmpa - 1;
				bcr[i] = tmpb - a - 1;
				ccr[i] = tmpc - a - b - 1;
				if (tf == 1) {
					ar[tmpa - 1] = true;
					br[tmpb - a - 1] = true;
					cr[tmpc - a - b - 1] = true;
				}
				tfr[i] = (tf == 1) ? true : false;
			}
			int[] aans = new int[a];
			for (int i = 0; i < a; i++) {
				aans[i] = 2;
			}
			int[] bans = new int[b];
			for (int i = 0; i < b; i++) {
				bans[i] = 2;
			}
			int[] cans = new int[c];
			for (int i = 0; i < c; i++) {
				cans[i] = 2;
			}
			for(int j = 0; j < 2; j++) {
			for (int i = 0; i < n; i++) {
				if (ar[acr[i]] && br[bcr[i]] && !cr[ccr[i]]) {
					aans[acr[i]] = 1;
					ar[acr[i]] = true;
					br[bcr[i]] = true;
					cr[ccr[i]] = false;
					bans[bcr[i]] = 1;
					cans[ccr[i]] = 0;
				}
				if (ar[acr[i]] && !br[bcr[i]] && cr[ccr[i]]) {
					aans[acr[i]] = 1;
					bans[bcr[i]] = 0;
					cans[ccr[i]] = 1;
					ar[acr[i]] = true;
					br[bcr[i]] = false;
					cr[ccr[i]] = true;
				}
				if (!ar[acr[i]] && br[bcr[i]] && cr[ccr[i]]) {
					aans[acr[i]] = 0;
					bans[bcr[i]] = 1;
					cans[ccr[i]] = 1;
					ar[acr[i]] = false;
					br[bcr[i]] = true;
					cr[ccr[i]] = true;
				}
				for(int k = 0; k < n; k++) {
					if (ar[acr[i]] && br[bcr[i]] && cr[ccr[i]]) {
						aans[acr[i]] = 1;
						bans[bcr[i]] = 1;
						cans[ccr[i]] = 1;
					}
				}

			}
			}
			for (int i = 0; i < a; i++) {
				System.out.println(aans[i]);
			}
			for (int i = 0; i < b; i++) {
				System.out.println(bans[i]);
			}
			for (int i = 0; i < c; i++) {
				System.out.println(cans[i]);
			}
		}
		
		
	}

	

}

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

#define o(output) cout << output << endl

using namespace std;

string s,t,u;
int a,b,c,d;
int l[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
char A,B,C;
priority_queue<int,vector<int>,greater<int> >small;

int main(){
  cin >>a>>b>>c;
  if(b-a==c-b)o("YES");
  else o("NO");
}

Measured memory_bytes: 256