akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  double sum = 0;
  rep(i, n) {
    sum += (double)1 / a[i];
  }
  double ans = (double)1 / sum;

  cout << ans << endl;
}


Measured memory_bytes: 256
n, q = list(map(int, input().split()))

# pythonに甘えたサボり実装
from collections import deque
que = deque([])
for _ in range(n):
    que.append((int(x) if x.isdigit() else x for x in input().split()))

tottime = 0
while que:
    name, lefttime = que.popleft()
    if lefttime <= q:
        tottime += lefttime
        print(name, tottime)
    else:
        lefttime -= q
        tottime += q
        que.append((name, lefttime))


Measured memory_bytes: 46660
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
	string ta;
	
	bool win(char x){
	bool f=0;
	for(int i=0;i<9;i+=3){
	if(ta[i]==x&&ta[i+1]==x&&ta[i+2]==x)f=1;
	}
	for(int i=0;i<3;i++){
	if(ta[i]==x&&ta[i+3]==x&&ta[i+6]==x)f=1;
	}
	
	if(ta[2]==x&&ta[4]==x&&ta[6]==x)f=1;
	if(ta[0]==x&&ta[4]==x&&ta[8]==x)f=1;
	
	return f;
	}
int main(){
	while(cin>>ta){
	if(win('o'))cout<<'o'<<endl;
	else if(win('x'))cout<<'x'<<endl;
	else cout<<'d'<<endl;
	}
	return 0;
}

Measured memory_bytes: 1184
import numpy as np
import copy


def dist2(y, z):
    return np.sum((y - z)**2)


def main():
    N, D = map(int, input().split())
    Xs = []
    for _ in range(N):
        X = list(map(int, input().split()))
        Xs.append(X)
    Xs = np.array(Xs, dtype=np.int)
    assert Xs.shape == (N, D)

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            d = dist2(Xs[i, :], Xs[j, :])
            if d == int(np.sqrt(d))**2:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21468
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        if((100*r + 10*g + b) % 4 == 0) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <experimental/iterator>

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* debug */
auto debug = std::experimental::make_ostream_joiner(std::cout, " ");

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int s, w;
	cin >> s >> w;
	cout << (w < s ? "safe" : "unsafe") << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    double r = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        r += 1.0 / a;
    }

    printf("%.8f\n", 1 / r);

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int32_t main(){
    fastio;
    int n;
    cin >> n;
    int diff=0;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        if(x!=i+1) diff++;
    }
    if(diff > 2) cout << "NO" << endl;
    else cout << "YES\n";
}

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

int main() {
  int n,m,c,sum,ans;
  cin>>n>>m>>c;
  vector<int> b(m);
  for(int i=0; i<m; i++) cin>>b[i];
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      cin>>a[i][j];
    }
  }
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      sum += a[i][j]*b[j];
    }
    if(sum + c > 0) ans++;
    sum = 0;
  }
  cout<<ans;
}

Measured memory_bytes: 256
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let x = (readLine()!.characters.split(" ").map{Int(String($0))!}+[input[1]]).sort()
let d = (0..<input[0]).map{x[$0+1]-x[$0]}
var ans = 0
for i in d {
    var (a, b) = (i, ans)
    while b > 0 {
        (a, b) = (b, a%b)
    }
    ans = a
}
print(ans)

Measured memory_bytes: 6332
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	int time = 0;

	int makeCount = 1;
	while (n > x * makeCount)
	{
		makeCount++;
	}

	cout << makeCount * t << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << ele << endl
#define print10(ele) cout << fixed << setprecision(10) << ele << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n, r;
  cin >> n >> r;
  int ans;
  if (n >= 10)
    ans = r;
  else
    ans = r + (100 * (10 - n));
  print(ans);
  return 0;
}

Measured memory_bytes: 384
n = gets.chomp.to_i
ans = 0
n0 = n/3
ans = n

def f(n,base)
  return n.to_s(base).split("").inject(0){|result,item| result += item.to_i}
end

x0,y0 =0,0

(0..n/2).each{|i|
  (0..n/3).each{|j|
    if 2*i+3*j ==n0 then
      x0,y0 = i,j
      break
    end
  }
      break if (x0>0 or y0>0)
    }

x,y = 0,0
pair =[]
(0..n).each{|k|
    x,y = x0+3*k, y0-2*k
    break if y<0
    n1 = f(x,6)
    n2 = f(y,9)
    ans = n1+n2  if n1+n2 <ans
}

ans += n%3
ans = n if n <6
puts ans


Measured memory_bytes: 1916
//IIT Kanpur FacelessMen India
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

int a[26];
int main(){
  // freopen("product.in","r",stdin);
  // freopen("product.out","w",stdout);
  int n;
  cin>>n;
  REP(i,n){
    string s;
    cin>>s;
    REP(j,26){
      int x=0;
      REP(k,s.size()) x+=s[k]==('a'+j);
      if(i==0) a[j]=x;
      else a[j]=min(x,a[j]);
    }
  }
  string b;
  REP(i,26) {
    while(a[i]) a[i]--,b.pb('a'+i);
  }
  cout<<b<<endl;
  return 0;
}


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

typedef long long ll;

// index : 1 - n
struct BIT {
    typedef ll cont_type;
    vector<cont_type> ary;
    BIT(int n) { ary.assign(n, 0); }

    void update(int idx,cont_type val) {
        for(; idx < ary.size(); idx |= idx+1)
            ary[idx] = max(ary[idx], val);
    }

    cont_type get(int x) const {
        cont_type ret = 0;
        for(; x >= 0; x = (x & (x+1)) -1)
            ret = max(ary[x], ret);
        return ret;
    }
};

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

    BIT bit(n);
    ll ans = 0;
    for(int i=0; i<n; ++i) {
        ll p = bit.get(x[i]-1)+x[i];
        ans = max(ans, p);
        bit.update(x[i]-1, p);
    }

    ll ln = n;
    cout<<(ln*(ln+1))/2-ans<<endl;
}

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


int main() {
	ll n,x[102],y[102],h[102],mx,my,mh,ansH;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i]>>h[i];
		if(h[i]>0){
			mx=x[i];my=y[i];mh=h[i];
		}
	}
	for(ll i=0;i<=100;i++){
		for(ll j=0;j<=100;j++){
			ansH=mh+abs(mx-i)+abs(my-j);
			bool ans=true;
			for(int k=0;k<n;k++){
				ll z=0;
				ll HH=max(ansH-abs(x[k]-i)-abs(y[k]-j),z);
				if(HH!=h[k]){
					ans=false;
					break;
				}
			}
			if(ans){
				cout << i << " "<<j<<" "<<ansH;
				return 0;
			}
		}
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl;
#define CNO cout<<"No"<<endl;

typedef long long LL;
typedef long double LD;

int main(){
  int r,g,b,n;
  cin >> r >> g >> b >> n;
  int ans=0;
  rep(i,n/r+1){
    rep(j,n/g+1){
      if(n-(i*r+j*g)>=0&&(n-(i*r+j*g))%b==0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,k,l,r;
    cin>>n>>k>>l>>r;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<vector<ll>> v(55),v2(55);

    for (long long bit = 0; bit < (1LL<<n/2); ++bit){
        ll sum=0;
        int cnt=0;
        for(int i=0;i<n/2;i++){
            if((bit>>i&1LL)) sum+=a[i],cnt++;
        }
        v[cnt].push_back(sum);
        
    }
    for(ll bit = 0; bit< (1LL<<(n-n/2));++bit){
        ll sum=0;
        int cnt=0;
        for(int i=0;i<n-n/2;i++){
            if((bit>>i&1LL)) sum+=a[n/2+i],cnt++;
        }
        v2[cnt].push_back(sum);
    }
    for(int i=0;i<22;i++){
        sort(v2[i].begin(),v2[i].end());
    }
    ll ans = 0;
    for(int i=0;i<=k;i++){
        for(auto j:v[i]){
            ans += (ll)(upper_bound(v2[k-i].begin(),v2[k-i].end(),r-j) - lower_bound(v2[k-i].begin(),v2[k-i].end(),l-j));
        }
    }

    cout<<ans<<endl;
}


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

int main() {
  int k;
  string s;
  cin>>k>>s;
  if(s.size()<=k){
    cout<<s<<endl;
  }
  else if(s.size()>k){
    for(int i=0;i<k;i++){
      cout<<s[i];
    }
  cout<<"..."<<endl;
}
}

Measured memory_bytes: 3596
//weighter LIS
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
typedef long long LL;
int main()
{
	int n;
	int h[maxn], a[maxn];
	scanf("%d",&n);
	for(int i=0; i<n; i++) scanf("%d",&h[i]);
	for(int i=0; i<n; i++) scanf("%d",&a[i]);
	map<int,LL> m;
	m[0] = 0;
	for(int i=0; i<n; i++)
	{
		map<int,LL>::iterator iter, iter_tmp;
		iter = m.lower_bound(h[i]);
		iter--;
		LL val = iter->second + a[i];
		iter++;
		while(iter!=m.end() && iter->second <= val)
		{
			iter_tmp = iter;
			iter_tmp++;
			m.erase(iter);
			iter = iter_tmp;
		}
		m[h[i]] = val;
	}
	printf("%lld\n",m.rbegin()->second);
	return 0;
}

Measured memory_bytes: 14336
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
 freopen("input","r",stdin);
 freopen("output","w",stdout);
*/

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }
    if (s.size() != 26) {
        int x[26];
        memset(x, 0, sizeof(x));
        for (int i = 0;i < s.size();i++) {
            x[s[i] - 'a']++;
        }
        cout << s;
        bool ok = 1;
        for (int i = 0;i < 26 && ok;i++) {
            if (x[i] == 0) {
                cout << char('a' + i);
                ok = 0;
            }
        }
        cout << endl;
        return 0;
    }
    // Next permutation
    vector<int> g;
    for (int i = 0;i < 26;i++) {
        g.push_back(s[i] - 'a');
    }
    next_permutation(g.begin(),g.end());
    string t;
    for (int i = 0;i < 26;i++) {
        t.push_back(char('a' + g[i]));
    }
    for (int i = 1;i <= 26;i++) {
        string ans = t.substr(0, i);
        if (ans > s) {
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  
  cout << n*n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll D, N;
    cin >> D >> N;
    if (N == 100) N += 1;
    ll ret_base = 1;
    for (size_t i = 0; i < D; i++){
        ret_base *= 100;
    }
    cout << N * ret_base << endl;

    return 0;
}

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

int main()
{
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if(a1 + a2 + a3 >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/



int main() {
    cin >> n;
    vi v(n);
    REP(i,n) {
        cin >> v[i];
        sum += v[i];
    }
    bitset<4000005> b;
    b.set(0);
    b[0] = 1;
    REP(i,n) {
        b |= b << v[i];
    }
    FOR(i,(sum+1)/2,4000005) {
        if(b[i]){
            cout << i << endl;
            return 0;
        }
    }
}

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

void solver(int n, int m) {

  vector<int> beet;
  bool memo[7368800] = {false};

  for (int i = m; ; ++i)  {
    if (memo[i]) continue;

    if (beet.size() == n) {
      cout << i << endl;
      return;
    }

    beet.push_back(i);
    for (int j = i; j < 7368800; j += i) {
      memo[j] = true;
    }  
  }
}

int main() {
  int n, m;

  while (cin >> m >> n, n) {
    solver(n, m);
  }
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int k;
    in>>k;
    ll s{};
    Fr(i,k) Fr(j,k) Fr(l,k) s+=gcd(gcd(i,j),l);
    cout<<s<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<numeric>
int main() {
	using usize = unsigned int;
	using i64 = long long int;
	usize n, q;
	std::cin >> n >> q;
	std::vector<i64> a(n), x(q), ans(q);
	std::vector<usize> index(q);
	i64 sum = 0;
	for (usize i = n;i--;) {
		std::cin >> a[i];
		if (i % 2 == 0) {
			sum += a[i];
		}
	}
	for (auto &e : x) {
		std::cin >> e;
	}
	std::iota(index.begin(), index.end(), 0);
	std::sort(index.begin(), index.end(),
		[&x](usize l, usize r) {return x[l] > x[r];});
	usize l = 0, r = 0;
	for (const auto i : index) {
		while (r < n&&std::abs(a[l] - x[i]) >= std::abs(a[r] - x[i])) {
			sum -= a[r + r % 2];
			sum += a[l];
			l += 1;
			r += 2;
		}
		ans[i] = sum;
	}
	for (const auto e : ans) {
		std::cout << e << std::endl;
	}
	return 0;
}


Measured memory_bytes: 4480
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
MOD = 10**9+7

ans = 0

C = [0]*61
for a in A:
    for idx in range(61):
        if (1<<idx) & a:
            C[idx] += 1

for i in range(61):
    ans = (ans + (1<<i)*C[i]*(N-C[i]))%MOD
print(ans)

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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> dp(n+1, 0);
  for ( int i = 0; i < m; i++ ) {
    int a;
    cin >> a;
    dp[a] = 1;
  }

  for ( int i = 1; i <= n; i++ ) {
    dp[i] += dp[i-1];
  }

  cout << min(dp[x], dp[n]-dp[x]) << endl;
  return 0;
}


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

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
void printhoge(set<int> v) {
	ALL(it, v) {
		cout << *it << " ";
	}
	cout << endl;

}
int main() {
	int n, k; cin >> n >> k;
	if (n % k >= 1)
		cout << 1 << endl;
	else
		cout << 0 << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
int main(){
ll n , a ,b ;
cin >> n >> a >>b;
if(n == 1 && a!=b) {cout<<0<<endl; return 0;}
else if(n==1 && a == b){cout <<1<<endl; return 0;}
else if(a>b) {cout <<0<<endl; return 0;}
else if(n == 2) {cout <<1<<endl ; return 0;}

ll low = (n-2) * a , high =(n-2) * b ;
cout<<high - low +1<<endl;
return 0;


}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            while (a % 2 == 0) {
                a /= 2;
                cnt++;
            }
        }

        System.out.println(cnt);
    }

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


Measured memory_bytes: 35816
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        n: usize,
        a: [usize;n-1],
    }

    let mut ans = vec![0; n];

    for i in 0..n - 1 {
        ans[a[i] - 1] += 1;
    }

    for i in 0..n {
        println!("{}", ans[i]);
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  bool c = false;
  bool b = true;
  for (int i=0; i<N; i++)
    cin >> A.at(i);
  
  sort(A.begin(), A.end());
  
  for (int i=0; i<N-1; i++){
    if (A.at(i)==A.at(i+1)){
      cout << "NO" <<endl;
      b=false;
      break;
    }
  }
  
  if (b)
    cout << "YES" <<endl;

        
}

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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

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

    int res=0;
    for(int i=n-1;i>=0;i--){
        bool flg=true;
        for(int j=0;j<i;j++){
            if(h[i]<h[j]) flg=false;
        }
        if(flg) res++;
    }
    p(res)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll<<60;
typedef pair<int,int> pii;

int W,H,N;
int X1[1001],Y1[1001],X2[1001],Y2[1001];
int fld[3000][3000];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int ans;
vector<int> xs;

int compress(int* x1,int* x2,int w){
    xs.clear();
    for(int i=0;i<N;++i){
        for(int d=-1;d<=1;++d){
            int tx1=x1[i]+d;
            int tx2=x2[i]+d;
            if(0<=tx1&&tx1<w)xs.PB(tx1);
            if(0<=tx2&&tx2<w)xs.PB(tx2);
        }
    }
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    for(int i=0;i<N;++i){
        x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
        x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
    }
    return xs.size();
}

void bfs(int sx,int sy){
    queue<pii> que;
    que.push(pii(sx,sy));
    while(!que.empty()){
        pii p=que.front();
        que.pop();
        int x=p.FI;
        int y=p.SE;
        for(int i=0;i<4;++i){
            int nx = x+dx[i];
            int ny = y+dy[i];
            if(nx<0||nx>=W||ny<0||ny>=H)continue;
            if(fld[ny][nx]==1)continue;
            fld[ny][nx]=1;
            que.push(pii(nx,ny));
        }
    }
}

signed main(){
    while(1){
        cin>>W>>H;
        if(W==0&&H==0)break;
        cin>>N;
        for(int i=0;i<N;++i){
            cin>>X1[i]>>Y1[i]>>X2[i]>>Y2[i];
        }
        W=compress(X1,X2,W);
        H=compress(Y1,Y2,H);
        for(int i=0;i<N;++i){
            for(int y=Y1[i];y<Y2[i];++y){
                for(int x=X1[i];x<X2[i];++x){
                    fld[y][x]=1;
                }
            }
        }
        for(int y=0;y<H;++y){
            for(int x=0;x<W;++x){
                if(fld[y][x]==1)continue;
                bfs(x,y);
                ans++;
            }
        }
        cout<<ans<<endl;
        memset(fld,0,sizeof(fld));
        ans=0;
    }
}

Measured memory_bytes: 38292
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long[] a = new long[5];
        long min = Long.MAX_VALUE;
        for (int i = 0; i < 5; i++) {
            long temp = Long.parseLong(sc.next());
            a[i] = temp;
            min = Math.min(min, temp);
        }
        long ans;
        if (n <= min) {
            ans = 5;
        } else {
            ans = (long)Math.ceil(n * 1.0 / min) + 4;
        }
        System.out.println(ans);
    }
}

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

using namespace std;
const long long INF = 1e18 + 10 ;
long long n , W ;
vector<long long> w , v ;
long long dp[110][100010] ;
long long dfs(long long x, long long cur){
    if ( cur > W ) return -INF ;
    if ( x == n ){
        return 0 ;
    }
    if ( dp[x][cur] != -1 ) return dp[x][cur] ;
    long long choice1 = dfs(x + 1, cur) ;
    long long choice2 = v[x] + dfs(x + 1, cur + w[x]);
    return dp[x][cur] = max(choice1, choice2) ;
}

int main(){
    memset(dp, -1, sizeof dp) ;
    cin >> n >> W ;
    w.resize(n) ;
    v.resize(n) ;
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i] ;
    }
    cout << dfs(0, 0) << endl;

    return 0 ;
}


Measured memory_bytes: 86144
from collections import deque
H,W,K = map(int, input().split())
D = [[0]*W for i in range(H)]
count = 1
memo = deque()
dx = [-1,1]

for y in range(H):
  r = input()
  if "#" in r:
    for x in range(W):
      if r[x] == "#":
        D[y][x] = count
        memo.append((y,x,count))
        count += 1
while memo:
  y,x,count = memo.popleft()
  for i in range(2):
    nx = x+dx[i]
    if 0<=nx<=W-1 and D[y][nx] == 0:
      D[y][nx] = count
      memo.appendleft((y,nx,count))
      """
      print(memo)
      for i in range(H):
        print(D[i])
      print()
      """

for y in range(1,H):
  if 0 in D[y]:
    for x in range(W):
      D[y][x] = D[y-1][x]
for y in range(H-2,-1,-1):
  if 0 in D[y]:
    for x in range(W):
      D[y][x] = D[y+1][x]

for i in range(H):
  print(" ".join(map(str,D[i])))

Measured memory_bytes: 14964
// JAI SHREE RAM
/*
	Author: gourav_raj
*/
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
void solve()
{
	int n;
	cin >> n;
	string s;
	int ac = 0, tle = 0, wa = 0, re = 0;
	while (n--)
	{
		cin >> s;
		if (s == "AC")
			ac++;
		else if (s == "TLE")
			tle++;
		else if (s == "WA")
			wa++;
		else
			re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;

}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
package main

import "fmt"

func main() {
  var A, B, m int
  fmt.Scan(&A, &B)
  for A%B != 0 {//ユークリッド
    m = A%B
    A = B
    B = m
  }
  ans := []int{1}
  n := 1
  for i := 2; i*i <= B; i++ {
	for B%i == 0 {
      B /= i
      if ans[n-1] != i {  
        n++
        ans = append(ans, i)
      }
	}
  }
  if B > 1 {
    ans = append(ans, B)
  }
  fmt.Println(len(ans))
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			int m,f,r;
			while(true){
				m = scan.nextInt();
				f = scan.nextInt();
				r = scan.nextInt();
				if((m == f) &&(f == r) &&(m == -1))break;
				int sum = m + f;
				if(m == -1 || f == -1){
					System.out.println("F");
				}else if(sum >= 80){
					System.out.println("A");
				}else if(sum >=65){
					System.out.println("B");
				}else if(sum >=50){
					System.out.println("C");
				}else if(sum >=30){
					if(r >=50){
						System.out.println("C");
					}else{
						System.out.println("D");
					}
				}else{
					System.out.println("F");
				}
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
}

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

using ll = long long;
using namespace std;



int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<double> dp(n+1);
    dp[0]=1; /// always have 0 head coin
    for(int i=0; i<n; ++i)
    {
        double x;
        cin >> x;
        for(int j=i+1; j>=0; --j)
        {
            dp[j]=dp[j-1]*x + dp[j]*(1-x); /// to have j head after i tossed, dp[j] = dp[j-1] *x; or dp[j]*(1-x);
        }
    }
    double ans=0;
    for(int i=1;i<=n;++i)
        if (n-i<i) ans +=dp[i];
    cout << setprecision(10) << fixed <<  ans;
    return 0;
}



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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

int n, m, ans;
int g[105][105];

void dfs(VI &v) {
  if(v.size() >= 2) {
    int tmp = 0;
    REP(i, v.size()) {
      int t = INF;
      REP(j, v.size()) if(i != j) {
        chmin(t, g[v[i]][v[j]]);
      }
      tmp += t;
    }
    chmax(ans, tmp);
  }

  int last = v.back();
  FOR(i, last+1, n) {
    bool ok = true;
    for(int j: v) {
      if(g[i][j] == 0) {
        ok = false;
        break;
      }
    }
    if(ok) {
      v.PB(i);
      dfs(v);
      v.pop_back();
    }
  }
}

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

  cin >> n >> m;
  REP(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--,  b--;
    g[a][b] = g[b][a] = c;
  }

  REP(i, n) {
    VI v({i});
    dfs(v);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3280
//Keep Working Hard
  // I__Like__Food  
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int mod = 1e9 + 7;
  const int N = 100005;
  const int INF = 1e16;
  const double PI = acos(-1);

int32_t main()
{


    int n;
    cin >> n;

    int ans = 0;

    for(int i = 1; i <= n; i++)
    {
      if(i%3 !=0 and i%5 !=0)ans+=i;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#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(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T, class U> vector<U> make_vec(size_t a, U val) {
    return vector<U>(a, val);
}
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int rec(int x, int y, vector<vector<int>> &dp) {
    if(dp[x][y] != -1)
        return dp[x][y];
    int ret = 0;
    for(int i = 1; 2 * i <= x; i++) {
        if(!rec(x - 2 * i, y + i, dp))
            ret = 1;
    }
    for(int i = 1; 2 * i <= y; i++) {
        if(!rec(x + i, y - 2 * i, dp))
            ret = 1;
    }
    return dp[x][y] = ret;
}

int main() {
    ll X, Y;
    cin >> X >> Y;
    // auto dp = make_vec<int>(200, 200, -1);
    // // dp:=Alice勝ちかどうか？
    // dp[0][0] = false;
    // dp[0][1] = false;
    // dp[1][0] = false;
    // for(int i = 0; i <= 100; i++) {
    //     for(int j = 0; j <= 100; j++) {
    //         rec(i, j, dp);
    //     }
    // }
    if(abs(X - Y) <= 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}

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

int main(){
    string red,blue;
    string get;
    int red1,blue1;
    cin>>red>>blue>>red1>>blue1;
    cin>>get;
    
    if(get==red){
        red1-=1;
    }
    else{
        blue1-=1;
    }
    cout<<red1<<" "<<blue1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int x[10000],y;
	
	for(y= 1; y<= 10000; y++){
		cin>>x[y];
		if(x[y]==0){
			break;
		}
				cout<<"Case"<<" "<<y<<": "<<x[y]<<endl;
		}
return 0;

}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
// #define vec(v) vector<int>(v)
// #define be(v) (v).begin(), (v).end()
// #define pb(q) push_back(q)
// #define mapci(mp) map<char*,int>(mp)
// #define mapcc(mp) map<char*,char*>(mp)
// typedef long long ll;
using namespace std;

int main(){

    int ans,i,n,d;
    cin>>n>>d;
    while(n>0){
        n-=2*d+1;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define input(x) x; cin >> x;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int maina(){
  int input(n);
  if(n == 1) return false;
  vector<int> a;
  FOR(i, 6, pow(n, 0.5) + 1){
    if(n%i == 0 && (i%7 == 1 || i%7 == 6)){
      a.push_back(i);
      a.push_back(n/i);
    }
  }

  vector<int> result;
  bool flg = true;
  cout << n << ":";
  for(int i: a){
    for(int j: a){
      if(i != j && i % j == 0){
        goto ELSE;
      }
    }
    for(auto k: result){
      if(k == i) goto ELSE;
    }
    result.push_back(i);
    flg = false;
ELSE:
    {}
  }
  sort(result.begin(), result.end());
  for(int i: result) printf(" %d", i);
  if(flg) cout << " " << n;
  cout << endl;
  return true;
}

int main(){
  while(maina());
}

Measured memory_bytes: 3336
import sys
input = sys.stdin.readline

def main():
    N, X = map(int, input().split())
    ans = N
    min_ = min(X, N-X)
    max_ = max(X, N-X)
    while min_ != 0:
        # print(max_, min_)
        ans += (max_ // min_) * 2 * min_
        tmp = max_ % min_
        max_ = min_
        min_ = tmp
    ans -= max_
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

#define PI 3.141592

int main(){
  int a,b;
  double v=.0,x=.0,y=.0;
  while(scanf("%d,%d",&a,&b)){
    if(a==0 && b==0)break;
    x+=sin(v*PI/180)*(double)a;
    y+=cos(v*PI/180)*(double)a;
    v+=b;
  }
  printf("%d\n%d\n",(int)x,(int)y);
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        //static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var S = ReadLine();
            var T = ReadLine();
            var spos = new List<long>[26];
            var tpos = new List<long>[26];
            for (var i = 0; i < spos.Length; ++i)
            {
                spos[i] = new List<long>();
                tpos[i] = new List<long>();
            }
            for (var i = 0; i < S.Length; ++i)
            {
                spos[S[i] - 'a'].Add(i);
                tpos[T[i] - 'a'].Add(i);
            }
            var cmp = new bool[26];
            for (var i = 0; i < S.Length; ++i)
            {
                var s = S[i] - 'a';
                if (cmp[s]) continue;
                var t = T[i] - 'a';
                if (spos[s].Count != tpos[t].Count)
                {
                    WriteLine("No");
                    return;
                }
                for (var j = 0; j < spos[s].Count; ++j)
                {
                    if (spos[s][j] != tpos[t][j])
                    {
                        WriteLine("No");
                        return;
                    }
                }
                cmp[s] = true;
            }
            WriteLine("Yes");
            //Out.Flush();
        }
    }
}


Measured memory_bytes: 22112
#include <iostream>
using namespace std;
int main()
{
	int h, w;
	cin >> h >> w;
	char c[100][100];
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			cin >> c[i][j];
		}
		for(int j = 0; j < w; j++)
		{
			cout << c[i][j];
		}
		cout << endl;
		for(int j = 0; j < w; j++)
		{
			cout << c[i][j];
		}
		cout << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include"stdio.h"
int main(){
int a,b,c,t;
scanf("%d%d%d",&a,&b,&c);
t=a;
a=b;
b=t;
t=a;
a=c;
c=t;
printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 2120
import sys
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]

stack = [(1, 0)]
while stack:
    root, curCount = stack.pop()
    
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        stack.append((neighbour, curCount))

print(*count[1:])


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

int main(){
    int n;
    cin>>n;
    vector<ll> c(n - 1), s(n - 1), f(n - 1);
    rep(i, n-1) cin >> c[i] >> s[i] >> f[i];

    rep(i,n-1){
        ll x = 0;
        forx(j,i,n-1){
            ll k = x / f[j];
            if(x%f[j])
                k++;
            k = max(k, (s[j] / f[j]));
            x = k * f[j] + c[j];
        }
        cout << x << endl;
    }
    cout << 0 << endl;
    return 0;
}


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

using namespace std;

int main(void) {
	int n, k;
	int total = 0;

	cin >> n >> k;
	vector<int> l(n);

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

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

	for (int i = 1; i <= k; i++) {
		total += l[n - i];
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for(int i = 0; i < M; i++) cin >> B[i];
    vector<vector<int>> A(N, vector<int>(M));
    int cnt = 0;
    for(int i = 0; i < N; i++){
        int temp = C;
        for(int j = 0; j < M; j++) {
            cin >> A[i][j];
            temp += A[i][j] * B[j];
        }
        if(temp > 0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdlib>
#include <climits>
using namespace std;

int test(int *h, int n, int k){
	int *dp = new int[n], temp;
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i = 2; i < n; i++){
		temp = INT_MAX;
		for(int j = i-1; j>=0 && j>=i-k; j--){
			temp = min(temp, abs(h[i]-h[j]) + dp[j]);
		}
		dp[i] = temp;
	}
	return dp[n-1];
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("/home/afzalrao/Desktop/Academics/2nd Year/3rd Sem/ESO207/CP/Text Files/input.txt", "r", stdin);
	freopen("/home/afzalrao/Desktop/Academics/2nd Year/3rd Sem/ESO207/CP/Text Files/output.txt", "w", stdout);
	#endif
	int n, k, *h;
	cin >> n >> k;
	h = new int[n];
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	cout << test(h, n, k);
	delete[] h;
	return 0;
}

Measured memory_bytes: 3996
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        S: String,
    }
    let mut ans = 0;
    let ref bs = S.as_bytes();
    for i in (0..bs.len()/2).rev(){
        if bs[0..i]==bs[i..i*2]{
            ans = i*2;
            break;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t K;
    char S[101];

    scanf("%jd", &K);
    scanf("%s", S);

    if (strlen(S) > K) {
        S[K] = '\0';
        printf("%s...\n", S);
    } else {
        puts(S);
    }

    return 0;
}


Measured memory_bytes: 2156
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() {
	int n, ans;
	int x[200000];
	int bufx[200000];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x[i]);
		bufx[i] = x[i];
	}
	qsort(x, n, sizeof(int), cmpint);
	for (int i = 0; i < n; i++) {
		if (bufx[i] <= x[n / 2 - 1])
			ans = x[n / 2];
		else
			ans = x[n / 2 - 1];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3692
D, N = map(int, input().split())
if D == 0:
    if N != 100:
        print(N)
    else:
        print(101)
elif D == 1:
    if N != 100:
        print(100*N)
    else:
        print(10100)
else:
    if N != 100:
        print(10000*N)
    else:
        print(1010000)

Measured memory_bytes: 3060