akhauriyash/Code-Regression huggingface dataset:
import Control.Monad

solver::[Int]->Bool
solver ls = []/=(filter (\i->mod i 2==1) ls)

main::IO()
main=do
  d<-getLine
  let n = read d
  c<-forM [1..n] (\_-> getLine)
  let dat  = map read c
  putStr (if solver dat then "first\n" else "second\n")


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

int main(){
    int n;
    cin >> n;
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    rep(i,n) {
        string s;
        cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "TLE") tle++;
        if(s == "RE") re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    int x[n];
    int y[n];
    int h[n];
    for (int i = 0; i < n; ++i) {
      cin >> x[i] >> y[i] >> h[i];
    }
    for (int cx = 0; cx <= 100; ++cx) {
      for (int cy = 0; cy <= 100; ++cy) {
        int H = 0;
        for (int i = 0; i < n; ++i) {
          if (h[i] == 0) continue;
          H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
          break;
        }
        if (H == 0) continue;
        bool f = true;
        for (int i = 0; i < n; ++i) {
          int z = max(H - abs(x[i] - cx) - abs(y[i] - cy), 0);
          f = f && (h[i] == z);
        }
        if (f) {
          cout << cx << ' ' << cy << ' ' << H << endl;
          cx = cy = 1000;
        }
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#define MAXN 100000
using namespace std;
typedef long long ll;

int N;
ll a[MAXN];
ll ans;
int minusCount;
ll smallest;

int main() {
	ans = 0;
	minusCount = 0;
	smallest = 1000000000;

	cin >> N;
	for (int i = 0; i<N; i++) {
		cin >> a[i];
		if (a[i] < 0) minusCount++;

		if (abs(a[i]) < smallest) {
			smallest = abs(a[i]);
		}

		ans += abs(a[i]);
	}

	if (minusCount % 2 == 0) {
		cout << ans << endl;
	}
	else {
		cout << ans - 2 * smallest << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
from copy import deepcopy, copy
class QueenMAP():
    __slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]
    def __init__(self):
        self.yoko = set()
        self.tate = set()
        self.naname1 = set()
        self.naname2 = set()
        self.MAP = [["."] * 8 for _ in range(8)]
    def add(self, y, x):
        self.MAP[y][x] = "Q"
        self.yoko.add(y)
        self.tate.add(x)
        self.naname1.add(y - x)
        self.naname2.add(x + y)
    def check(self, y, x):
        if y in self.yoko or x in self.tate or (y - x) in self.naname1 or (x + y) in self.naname2:
            return False
        return True
    def allcheck(self):
        for i in range(8):
            if not "Q" in self.MAP[i]:
                return False
        return True
def MAIN():
    f = lambda M: "\n".join("".join(m) for m in M)
    QM = QueenMAP()
    n = int(input())
    for _ in range(n):
        a, b = map(int, input().split())
        QM.add(a, b)
    dp = [(deepcopy(QM), n)]
    while dp:
        Q, cnt = dp.pop()
        if cnt == 8:
            if Q.allcheck():
                print(f(Q.MAP))
                break
            continue
        cnt += 1
        for i in range(8):
            for j in range(8):
                if Q.check(i, j):
                    CQ = deepcopy(Q)
                    CQ.add(i, j)
                    dp.append((CQ, cnt))
MAIN()



Measured memory_bytes: 6512
#include <iostream>
#include <climits>
#include <cstring>
using namespace std;

typedef long long ll;

int n;
ll t[4002], sum[4002], dp[4002][4002];
int pos[4002][4002];

void solve(){
  memset(dp, 0, sizeof(dp));
  memset(pos, 0, sizeof(pos));

  for(int i = 0; i < 4001; i++){
    pos[i][i] = i;
    pos[i][i + 1] = i;
  }

  for(int w = 2; w <= n; w++){
    for(int i = 0; i + w <= n; i++){
      int j = i + w;
      int cutK = -1;
      ll minSum = LONG_LONG_MAX;
      dp[i][j] = LONG_LONG_MAX / 4;

      for(int k = pos[i][j - 1]; k <= pos[i + 1][j]; k++){
        ll s = dp[i][k] + dp[k][j] + (sum[j] - sum[i]);

        if(minSum > s){
          minSum = s;
          cutK = k;
        }
      }

      dp[i][j] = minSum;
      pos[i][j] = cutK;
    }
  }

  cout << dp[0][n] << endl;
}

int main(){
  while(cin >> n){
    memset(sum, 0, sizeof(sum));

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

    solve();
  }
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    REP(i,3){
        if(s[i] == s[i+1]){
            ANS("Bad");
            return 0;
        }
    }
    ANS("Good");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll> > a(N);

  rep(i, N){
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(), a.end());

  ll ans = 0; // 金額
  ll cnt = 0; // 本数
  rep(i, N) {
    if(cnt+a[i].second <= M) {
      ans += a[i].first * a[i].second;
      cnt += a[i].second;
    } else {
      ans += a[i].first * (M - cnt);
      cnt = M;
    }

    if(cnt==M) break;
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int,int> P;

int main() {
    int N;cin >> N;
    vector<ll> L(N);
    for (int i = 0;i < N;i++){
        cin >> L[i];
    }
    sort(L.begin(),L.end());
    ll res = 0;
    for (int i = 0;i < N - 1; i++){
        for (int j = i + 1;j < N;j++){
            int X = L[i] + L[j];
            int key = lower_bound(L.begin(),L.end(),X) - L.begin();
            res += key - j - 1;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF=1001001001001001001;
// Combination Table
vector<ll> g[8];

ll ans=0;
int dfs(int t, vector<bool>vis){
//  cout<<t<<endl;
vis[t]=true;
  bool check=true;
  rep(i,vis.size()){
    if (vis[i]==false)check=false;
  }
  if (check==true){
    ans++;return 0;
  }
  for(int to:g[t]){
    if (vis[to]==true)continue;
  //
    dfs(to,vis);
  }
  return 0;
}

int main() {
  ll n,m;
  cin>>n>>m;
  rep(i,m){
    ll a1,b1;
    cin>>a1>>b1;
    a1--;b1--;
    g[a1].push_back(b1);
    g[b1].push_back(a1);
  }
  vector<bool> V(n);
//  V[0]=true;
  dfs(0,V);
  cout<<ans;

}


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

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  int ans = 0;
  rep(i, n) ans = max(ans, uf.size(i));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4044
import sys
sys.setrecursionlimit(500000)
def gcd(x , y):
    while y != 0:
        x , y = y , x % y
    return x
N = int(input())
A = list(map(int ,input().split()))
max_val = 0
if N == 2:
    print(max(A[1], A[0]))
    exit()
right = []
left = []
work_right = gcd(A[N - 2] , A[N - 1])
right.append(A[N - 1])
work_left = gcd(A[0] , A[1])
left.append(A[0])
for i in range(1 , N - 1):
    work_left = gcd(work_left , A[i])
    left.append(work_left)
    work_right = gcd(work_right , A[N - i - 1])
    right.append(work_right)
#print(right)
#print(left)
right.reverse()
max_val = 0
for i in range(N):
    if i == 0:
        max_val = right[0]
    elif i == N - 1:
        if max_val < left[-1]:
            max_val = left[-1]
    else:
        tmp = gcd(right[i] , left[i - 1])
        if tmp > max_val:
            max_val = tmp
print(max_val)
'''
for i in range(N):
    work = A[:i] + A[i + 1:]
    for j in range(1 , len(work)):
        if j == 1:
            tmp = gcd(work[0],work[1])
        else:
            tmp = gcd(tmp , work[j])
    if max_val < tmp:
        max_val = tmp
print(max_val)
'''

Measured memory_bytes: 14076
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <iomanip>
#include <stack>
#include <unordered_set>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e14, flag,cnt;


int main(){
	ll k;
	cin>>k;
	ans=7;
	if(ans%k==0){
		cout<<1<<endl;
		return 0;
	}
	for(ll i=2; i<=1000000; i++){
		if(ans==0) {
			cout<<i-1;
			return 0;
		}
		ans=((ans*10)+7)%k;
		
	}
	cout<<-1;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll ch[82];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	ll ans=1000;ll now=ch[0];
	ll s=now;ll e=now;
	for(ll i=1;i<n;i++){
		if(e<=ch[i]){
			e=ch[i];
		}
		else {
			ans+=ans/s*(e-s);
			s=ch[i];
			e=ch[i];
		}
//		cout <<ans<<endl;
		if(i==n-1){
			if(e>s){
			ans+=ans/s*(e-s);				
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3532
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0 ; i < n ; i++) s[i] = sc.next();
		int[] a = new int[26];
		char[] b = new char[26];
		for(char c = 'a' ; c <= 'z' ; c++) b[(int)(c - 'a')] = c;
		Arrays.fill(a, Integer.MAX_VALUE);
		for(int i = 0 ;  i < n ; i++) {
			int[] cnt = new int[26];
			for(int j = 0 ; j < s[i].length() ; j++) {
				for(char c = 'a' ; c <= 'z' ; c++) {
					if(s[i].charAt(j) == c) cnt[(int)(c - 'a')]++;
				}
			}
			for(int j = 0 ; j < 26 ; j++) {
				a[j] = Math.min(a[j], cnt[j]);
			}
		}
		for(int i = 0 ; i < 26 ; i++) {
			if(a[i] != Integer.MAX_VALUE && a[i] >= 1) {
				for(int j = 0 ; j < a[i] ; j++) {
					System.out.print(b[i]);
				}
			}
		}
		System.out.println();
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main() {
    int n;
    cin>>n;
    double xa,ya,ra,xb,yb,rb;
    
    while((cin>>xa>>ya>>ra>>xb>>yb>>rb)){
        double l = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
        if(l>ra+rb){
            cout<<0<<endl;
        }else if(l+rb<ra){
            cout<<2<<endl;
        }else if(l+ra<rb){
            cout<<-2<<endl;
        }else{
            cout<<1<<endl;
        }
    }
    return 0;
}

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

using namespace std;

const int N = 1e4 + 5;
const int mod = 1e9 + 7;

string k;
int n, d, f[N][2][2][105];

void add (int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> k >> d; n = k.length(); k = "#" + k;
    f[0][1][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int ok = 0; ok < 2; ok++) {
            for (int app = 0; app < 2; app++) {
                for (int rem = 0; rem < d; rem++) {
                    if (f[i][ok][app][rem]) {
                        for (int nxt = 0; nxt <= (ok ? k[i + 1] - '0' : 9); nxt++) {
                            int nok = ok && (nxt == k[i + 1] - '0');
                            int napp = app || (nxt > 0);
                            int nrem = (rem + nxt) % d;
                            add(f[i + 1][nok][napp][nrem], f[i][ok][app][rem]);
                        }
                    }
                }
            }
        }
    }
    
    cout << (f[n][0][1][0] + f[n][1][1][0]) % mod;
    return 0;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> dp(n+1, vector<int>(n+1, 0));
    for(int i=0; i<=n-1; i++){
        for(int j=0; j<=n-1; j++){
            if(i==0 or j==0){
                if(s[i]==s[j]){
                    dp[i+1][j+1] = 1;
                }
                else{
                    dp[i+1][j+1] = 0;
                }
            }
            else{
                if(s[i]==s[j]){
                    dp[i+1][j+1] = dp[i][j] + 1;
                }
                else{
                    dp[i+1][j+1] = 0;
                }
            }
        }
    }
    int ma=0;
    for(int i=0; i<n+1; i++){
        for(int j=0; j<n+1; j++){
            int now = dp[i][j];
            if(i+now <= j){
                chmax(ma, now);
            }
        }
    }
    cout << ma << endl;
    // ddump(dp)
    return 0;
}

Measured memory_bytes: 98176
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = sys.stdin.buffer.readline().decode().rstrip()
    T = sys.stdin.buffer.readline().decode().rstrip()

    print('Yes' if "".join(sorted(S)) < "".join(reversed(sorted(T))) else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  lint n, a, b;
  cin >> n >> a >> b;

  lint cnt = a*(n/(a+b));
  if(n%(a+b) < a) cnt += n%(a+b);
  else cnt += a;

  cout << cnt << "\n";
  return 0;
}


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

int main() {
  int X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  long long A[1000], B[1000], C[1000];
  for(int i=0;i<X;i++){
    cin>>A[i];
  }
  for(int i=0;i<Y;i++){
    cin>>B[i];
  }
  for(int i=0;i<Z;i++){
    cin>>C[i];
  }
  
  vector<long long> tmp;
  for(int i=0;i<Y;i++){
    for(int j=0;j<Z;j++){
      tmp.push_back(B[i]+C[j]);
    }
  }
  sort(tmp.begin(), tmp.end() );
  
  vector<long long> ans;
  //cout<<X<<endl;
  for(int i=0;i<X;i++){
    int u=0;
    if(tmp.size()>=K) u=tmp.size()-K;
    for(int j=tmp.size()-1 ;j>=u; j--){
      //cout<<"a"<<endl;
      ans.push_back(A[i]+tmp[j]);
    }
  }
  //cout<<tmp.size()<<' '<<ans.size()<<endl;
  sort(ans.begin(), ans.end() );
  for(int i=ans.size()-1;i>=ans.size()-K && i>=0;i--){
    cout<<ans[i]<<endl;
  }
 return 0; 
}

Measured memory_bytes: 43236
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int H, W;
vector<string> S;

void count_mine(int x, int y) {
  if (S[x][y] != '.') {
    cout << S[x][y];
    return;
  }

  int count = 0;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      if (i == 0 && j == 0)
        continue;
      int u = x + i;
      int v = y + j;
      if (0 <= u && u < H && 0 <= v && v < W && S[u][v] == '#')
        count++;
    }
  }
  cout << count;
}

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    S.push_back(s);
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count_mine(i, j);
    }
    cout << endl;
  }

  return 0;
}


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

using namespace std;

int main() {
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = 0;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += a[i];
    if (sum > x) {
      break;
    }
    ans++;
  }
  if (sum < x) {
    ans--;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
MOD=10**9+7
N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
ls=sorted(ls, key=lambda x: -abs(x))

#かける数をフラグで管理
flag=[0 for _ in range(N)]

sign=0
for i in range(K):
  flag[i]=1
  if ls[i]<0:
    sign=(sign+1)%2

if sign==1: #絶対値が大きい順にかけた数は負か？
  #フラグのない負の数を、フラグのある正の数と取り換え可能か？
  swap_neg_to_pos=[]
  for i in range(K,N):
    if ls[i]<0:
      for j in range(K):
        if ls[K-1-j]>0:
          swap_neg_to_pos=[i,K-1-j,ls[K-1-j],-ls[i]]
          break
      break
  #フラグのない正の数を、フラグのある負の数と取り換え可能か？
  swap_pos_to_neg=[]
  for i in range(K,N):
    if ls[i]>0:
      for j in range(K):
        if ls[K-1-j]<0:
          swap_pos_to_neg=[i,K-1-j,-ls[K-1-j],ls[i]]
          break
      break

  #フラグを修正        
  if swap_neg_to_pos!=[] and swap_pos_to_neg!=[]: #どちらも取り換え可能なとき
    #負の数にフラグを与えたほうがロスが少ないとき
    if swap_neg_to_pos[2]*swap_pos_to_neg[3]<swap_pos_to_neg[2]*swap_neg_to_pos[3]: 
      flag[swap_neg_to_pos[0]]=1
      flag[swap_neg_to_pos[1]]=0
    else: #正の数にフラグを与えたほうがロスが少ないとき
      flag[swap_pos_to_neg[0]]=1
      flag[swap_pos_to_neg[1]]=0
  elif swap_neg_to_pos==[] and swap_pos_to_neg==[]: #どちらも取り換え不可能なとき 
    flag.reverse()
  elif swap_pos_to_neg!=[]: #正の数にフラグを与えることのみ可能なとき
    flag[swap_pos_to_neg[0]]=1
    flag[swap_pos_to_neg[1]]=0
  else:                     #負の数にフラグを与えることのみ可能なとき
    flag[swap_neg_to_pos[0]]=1
    flag[swap_neg_to_pos[1]]=0

ans=1
for i in range(N):
  if flag[i]==1:
    ans=(ans*ls[i])%MOD
print(ans)


Measured memory_bytes: 31716
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let line: Vec<i16> = read_vec();
    let n = line[0];
    let t = line[1];
    let routes = (0 .. n)
        .map(|_n| { let vec: Vec<i16> = read_vec(); vec })
        .filter(|route| { route[1] <= t });
    match routes.map(|route| route[0]).min() {
        Some(cost) => println!("{}", cost),
        None       => println!("TLE"),
    };
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cstring>

typedef long long LL;
const int N = 1e5 + 10;
int n, m, L, a[N], ans[N];
LL sum, sum1;

bool ok(){
	if(sum < L)	return 0;

    for(int i=1; i<n; i++){
		if(a[i]+a[i+1] >= L){
            m = 0;
            for(int j=1; j<i; j++)	ans[++m] = j;
            for(int j=n; j>i+1; j--)	ans[++m] = j-1;
            ans[++m] = i;
            return 1;
		}
    }

    return 0;
}

int main(){
	while(~scanf("%d %d", &n, &L)){
		sum = 0;
		for(int i=1; i<=n; i++){
			scanf("%d", a+i);
			sum += a[i];
		}
		if(ok()){
			puts("Possible");
			for(int i=1; i<n; i++)	printf("%d\n", ans[i]);
		} else {
			puts("Impossible");
		}
	}
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define UB upper_bound
#define LB lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  string s,t;
  cin>>s>>t;
  if(s.size()<t.size()){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  vector<string> str;
  REP(i,s.size()-t.size()+1){
    string u=s.substr(i,t.size());
    bool k=true;
    REP(j,u.size()){
      if(u[j]=='?')continue;
      if(u[j]!=t[j]){
        k=false;
        break;
      }
    }
    if(k){
      string v=s;
      int p=0;
      for(int j=i;j<i+t.size();j++){
        v[j]=t[p];
        p++;
      }
      REP(j,v.size())if(v[j]=='?')v[j]='a';
      str.PB(v);
    }
  }
  sort(ALL(str));
  if(!str.empty())cout<<str[0]<<endl;
  else cout<<"UNRESTORABLE"<<endl;
  return 0;
}


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

a, p = [1], [1]

for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= a[n-1] + 1:
        return f(n - 1, x - 1)
    else:
        return p[n-1] + 1 + f(n-1, x-a[n-1]-2)

print(f(n, x))


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  ll x, y;
  cin >> x >> y;
  int ans = 1;
  while (x * 2ll <= y) {
    x *= 2ll;
    ans++;
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


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

int main() {
	long long n;
	cin >> n;
	vector<long long> arr;
	for(long long i=0;i<n;i++){
		long long a;
		cin>>a;
		arr.push_back(a);
	}long long ans=0;
	int i=0;
	while(i<n){
		if(arr[i]%2==0){
			ans++;
			arr[i]/=2;
		}else
			i++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3740
N = int(input())
arr = list(map(int, input().split()))
if len(set(arr)) == 1:
    print(N//2)
    exit()
A = []
B = []
for i in range(N):
    if i % 2 == 0:
        A.append(arr[i])
    else:
        B.append(arr[i])
from collections import Counter
A_counter = Counter(A)
B_counter = Counter(B)
if A_counter.most_common()[0][0] != B_counter.most_common()[0][0]:
    print(N-A_counter.most_common()[0][1]-B_counter.most_common()[0][1])
elif A_counter.most_common()[0][1] > B_counter.most_common()[0][1]:
    print(N-A_counter.most_common()[0][1]-B_counter.most_common()[1][1])
elif A_counter.most_common()[0][1] < B_counter.most_common()[0][1]:
    print(N-A_counter.most_common()[1][1]-B_counter.most_common()[0][1])
else:
    print(N-A_counter.most_common()[0][1]-max(A_counter.most_common()[1][1],B_counter.most_common()[1][1]))

Measured memory_bytes: 87172
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define ll long long
#define inf  1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
struct edge{int to;double cost;};
typedef pair<int,double>P;
vector<edge> G[100005];
double d[100005];
int n;
 
void dijkstra(long long k){
    priority_queue<P,vector<P>,greater<P> >que;
    fill(d,d+n,1e17);
    d[k]=0;
    que.push(P(0,k));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size(); i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
 
signed main()
{
    int sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy;
    cin>>n;
    int a[1145],b[1145],c[1141];
    for(int i=0; i<n; i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    a[n]=sx;b[n]=sy;c[n]=0;
    a[n+1]=gx;b[n+1]=gy;c[n+1]=0;
    n+=2;
    rep(i,0,n){
        rep(j,0,n){
            if(i==j)continue;
            double h=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]))-c[i]-c[j];
            if(h<0)h=0;
            G[i].push_back(edge{j,h});
        }
    }
    dijkstra(n-2);
    cout<<setprecision(15)<<d[n-1]<<endl;
    return 0;
}

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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define bits(n) __builtin_popcount(n)

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> ok(n, true);
    for(int i=0;i<n;i++) cin >> h[i];
    vector<int> ans(n);
    int cnt = 0;
    for(int i=0;i<m;i++)
    {
        int a, b;
        cin >> a >> b;
        if (h[a - 1] <= h[b - 1])
            ok[a - 1] = false;
        if (h[b - 1] <= h[a - 1])
            ok[b - 1] = false;
    }
    for(int i=0;i<n;i++)
    {
        if (ok[i])
            cnt++;
    }
    cout << cnt <<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

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

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1010, M = 20010;

int n, m;
int f[M];

int main()
{
	scanf("%d%d", &m, &n);
	memset(f, 0x3f, sizeof f);
	f[0] = 0;
	
	for (int i = 1; i <= n; i ++ )
	{
		int a, b;
		scanf("%d%d", &a, &b);
		
		for (int j = 0; j <= m; j ++ )
		{
			int t = min(m, j + a);
			f[t] = min(f[t], f[j] + b);
		}
	}
	
	int res = 0x3f3f3f3f;
	for (int i = m; i < M; i ++ ) res = min(res, f[i]);
	printf("%d\n", res);
	return 0;
}


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

//dpテーブルをローカルで宣言したらセグフォになった...

//dpの内部変えるのグローバルでやってたら
//expected unqualified-id
//って言うエラーがひたすら出てきた。

const ll INF=1e11;

int main(){

  ll N,k;
  cin >> N  >> k;
  ll x,ans=0;
  rep(i,N){
    cin >> x;
    if(x>=k-x)ans+=2*(k-x);
    else ans+=2*x;
  }
  cout << ans << endl;
}


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

int main()
{
        string s, m, h, a;
        int num, index, sz, i, cnt = 0, ci = 0;
        vector<char> answer;
        stringstream ss;

        while(getline(cin, s), s != "-") {
                a = "";
                int start_index = 0;
                sz = s.size();
                char shuffle[sz];

                getline(cin, m);
                ss << m;
//              num = stoi(m);
                ss >> num;
                ss.clear(stringstream::goodbit);
                for(int i = 0; i < num; i++) {
                        getline(cin, h);
//                      index = stoi(h);
                        ss << h;
                        ss >> index;
                        ss.clear(stringstream::goodbit);
                        ///// Calculation body ////////
                        start_index += index;
                        if(start_index >= sz) {
                                start_index -= sz;
                        }
                }
                for(int i = 0; i < sz; i++) {
                        a[i] = s[start_index++];
                        answer.push_back(a[i]);
                        if(start_index >= sz) start_index = 0;
                }
                answer.push_back('\n');
        }

        for(vector<char>::iterator ite = answer.begin(); ite != answer.end(); ++ite) {
                cout << *ite;
        }

        return 0;
}


Measured memory_bytes: 3160
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        for(int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        int sum = 0;
        int point = 0;
        for(int j = 0; j < n; j++) {
            sum += x[j];
        }
        double ave = (double)sum / n;
        if(ave % 1 >= 0.5){
        point = (int)ave + 1;
        }else{
            point = (int)ave;
        }
        long ans = 0;
        for(int i = 0; i < n; i++) {
            ans += ((point - x[i]) * (point - x[i])); 
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35796
x,y,a,b,c = map(int,input().split())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]

p.sort(reverse = True)
q.sort(reverse = True)

r.extend(p[:x])
r.extend(q[:y])

r.sort(reverse = True)
print(sum(r[:x+y]))


Measured memory_bytes: 108140
#include <stdio.h>
#include <iostream>
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;

int main(){
    int N;
    cin >> N;
    if(N / 100 == 7 || (N / 10) % 10 == 7 || N % 10 == 7){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

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

using namespace std;
typedef long long ll;

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

bool solve(ll mid, vector<ll> a, ll n, ll k){
    ll cnt = 0;
    REP(i, n){
        cnt += a[i] / mid;
        if(a[i] % mid != 0) cnt++;
    }
    if(cnt <= n+k) return true;
    else return false;
}

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    ll ng = 0, ok = 0;
    REP(i, n) ok = max(ok, a[i]);
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if(solve(mid, a, n, k)) ok = mid;
        else ng = mid;
    }
    cout << ok;
    return 0;
}

Measured memory_bytes: 6400
#include<iostream>

using namespace std;

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

  int h=0;
  int m=0;
  int s=0;

  h=S/3600;
  S=S%3600;

  m=S/60;
  S=S%60;

  s=S;

  cout<<h<<":"<<m<<":"<<s<<'\n';

  return 0;
}



Measured memory_bytes: 3096
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();

    let mut w_i = 0;
    let mut ans = 0;
    for (i,c) in s.iter().enumerate(){
        if *c == 'W' {
            ans += i-w_i;
            w_i += 1;
        }
    }

    println!("{}",ans);
}

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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


int main() {
  ll x;
  cin >> x;

  ll lb = 0, ub = x;
  while (ub-lb > 1) {
    ll mid = (lb+ub)/2;
    if (mid*(mid+1)/2 >= x) ub = mid;
    else lb = mid;
  }

  cout << ub << endl;
  return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

const int IINF = INT_MAX;

#define MAX 900
int N,T[50],dp[2][MAX][MAX];

void compute() {
  rep(j,MAX) rep(k,MAX) dp[0][j][k] = IINF;
  dp[0][0][0] = 0;
  
  rep(i,N) {
    int cur = i & 1;
    int next = ( i + 1 ) & 1;
    rep(j,MAX) rep(k,MAX) dp[next][j][k] = IINF;
    rep(j,MAX) {
      rep(k,MAX) {
        if( dp[cur][j][k] == IINF ) continue;
        if( j + T[i] < MAX ) {
          dp[next][j+T[i]][k] = min(dp[next][j+T[i]][k],dp[cur][j][k]);
        }
        if( k + T[i] < MAX ) {
          dp[next][j][k+T[i]] = min(dp[next][j][k+T[i]],dp[cur][j][k]);
        }
        dp[next][j][k] = min(dp[next][j][k],dp[cur][j][k]+T[i]);
      }
    }
  }
  int mini = IINF;
  rep(j,MAX) rep(k,MAX) {
    if( dp[N&1][j][k] == IINF ) continue;
    mini = min(mini,max(j,max(k,dp[N&1][j][k])));
  }
  cout << mini << endl;
}

int main() {
  cin >> N;
  rep(i,N) cin >> T[i];
  compute();
  return 0;
}

Measured memory_bytes: 9416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if(b-a==c-b)System.out.println("YES");
        else System.out.println("NO");
	}
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mt;
typedef vector<mt> cu;


ll n;
mt field;
mt ans;
const ll center = 100;

vl direction(ll front, ll top, ll x){
  if(front == x) return vl({0, 1, 0});
  if(top == x) return vl({0, 0, 1});
  if(front+x == 7) return vl({0, -1, 0});
  if(top+x == 7) return vl({0, 0, -1});
  vl cicle({front,top,7-front,7-top});
  for(ll i = 0;i < 4;i++){
    if(cicle[i] <= 3 && cicle[(i+1)%4] <= 3){
      if(((cicle[i]%3)-(cicle[(i+1)%4]%3)+3)%3 == 1){
        if(x <= 3) return vl({1, 0, 0});
        else return vl({-1, 0, 0});
      }else{
        if(x <= 3) return vl({-1, 0, 0});
        else return vl({1, 0, 0});
      }
    }
  }
  cerr << "error" << endl;
  return vl({0, 0, 0});
}

vl move(ll front, ll top, vl d){
  ll x = d[0];
  ll y = d[1];
  if(x == -1){
    for(ll i = 1;i <= 6;i++){
      if(direction(front, top, i)[0] == 1){
        return vl({front, i});
      }
    }
  }else if(x == 1){
    for(ll i = 1;i <= 6;i++){
      if(direction(front, top, i)[0] == -1){
        return vl({front, i});
      }
    }
  }else if(y == -1){
    return vl({7-top, front});
  }else if(y == 1){
    return vl({top, 7-front});
  }
  cerr << "error move" << endl;
  return vl({0, 0});
}




int main(){
  while(cin >> n){
    if(n == 0) return 0;
    field = mt(202,vl(202));
    ans = mt(202,vl(202));
    for(ll i = 0;i < n;i++){
      ll t,f;
      cin >> t >> f;
      field[center][center]++;
      bool flag = false;
      ll top = t;
      ll front = f;
      ll now_x = center;
      ll now_y = center;
      do{
        flag = false;
        for(ll men = 6;men >= 4;men--){
          vl d = direction(front, top, men);
          // cerr << men << " ";
          // for(ll dir : d) cerr << dir;
          // cerr << endl;
          ll dx = d[0];
          ll dy = d[1];
          if(dx == 0 && dy == 0) continue;
          if(field[now_x+dx][now_y+dy] < field[now_x][now_y]-1){
            flag = true;
            field[now_x][now_y]--;
            field[now_x+dx][now_y+dy]++;
            now_x += dx;
            now_y += dy;
            vl move_res = move(front, top, d);
            front = move_res[0];
            top = move_res[1];
            // cerr << now_x << " " << now_y << endl;
            break;
          }
        }
        // for(ll i = center-5;i <= center+5;i++){
        //   for(ll j = center-5;j <= center+5;j++){
        //     cerr << field[i][j] << " ";
        //   }
        //   cerr << endl;
        // }
        // cerr << endl;
        //
        // cerr << endl;
      }while(flag);
      ans[now_x][now_y] = top;
      // for(ll i = center-5;i <= center+5;i++){
      //   for(ll j = center-5;j <= center+5;j++){
      //     cerr << ans[i][j] << " ";
      //   }
      //   cerr << endl;
      // }
    }
    vl out_list = vl(7);
    for(auto x : ans){
      for(auto y : x){
        out_list[y]++;
      }
    }
    for(ll i = 1;i < 6;i++){
      cout << out_list[i] << " ";
    }
    cout << out_list[6] << endl;
  }

}



Measured memory_bytes: 3936
'use strict'

function main(input) {
  input = input.split(' ').map(v => ~~v)
  const n = input[0]
  const k = input[1]
  let rate = 0

  for (let i = 1; i <= n; i++) {
    // let xx = i * 2 * 2
    let tmp = i
    let cnt = 1
    while (k > tmp) {
      tmp = tmp * 2
      cnt++
    }
    // console.log(cnt - 1)
    rate += (1 / n) * Math.pow(0.5, cnt - 1)
  }

  console.log(rate)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 10060
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    rep(i,s.size()){
        if((int)s[i]+n>90){
            s[i]=(int)s[i]+n-26;
        }
        else    s[i]=(int)s[i]+n;
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<pair<ll,ll>> GG[100005];
ll dist[100005];

int N;
vector<int> G[100005];
int parent[64][100005];
int depth[100005];
void dfs(int v, int p, int d){
  parent[0][v] = p;
  depth[v] = d;
  for(int i=0; i<G[v].size(); i++){
    if(G[v][i] != p) dfs(G[v][i], v, d+1);
  }
}
void init(int root){
  dfs(root, -1, 0);
  for(int k=0; k+1<64; k++){
    for(int v=0; v<N+1; v++){
      if(parent[k][v] < 0) parent[k+1][v] = -1;
      else parent[k+1][v] = parent[k][parent[k][v]];
    }
  }
}
int lca(int u, int v){
  if(depth[u] > depth[v]) swap(u, v);
  for(int k=0; k<64; k++){
    if((depth[v] - depth[u]) >> k & 1){
      v = parent[k][v];
    }
  }
  if(u==v) return u;
  for(int k=64-1; k>=0; k--){
    if(parent[k][u] != parent[k][v]){
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}


void calc_dist(ll v, ll d){
  if(dist[v] != -1) return;
  dist[v] = d;
  rep(i,GG[v].size()){
    calc_dist(GG[v][i].first, d+GG[v][i].second);
  }
}

ll calc(int root, int x, int y){
  int z = lca(x, y);
  return abs(dist[z]-dist[x]) + abs(dist[z]-dist[y]);
}

int main(){
  cin >> N;
  rep(i,N-1){
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
    GG[a].emplace_back(b,c);
    GG[b].emplace_back(a,c);
  }

  rep(i,100005) dist[i] = -1;
  
  ll root = -1;
  rep(i,N){
    if(G[i].size() == 1) root = i;
  }
  init(root);
  calc_dist(root, 0);

  int Q, K;
  cin >> Q >> K;
  K--;
  rep(i,Q){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << calc(root, x, K) + calc(root, K, y) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 46720
def gcd(a, b):
  if a < b:
    a, b = b, a
  while a % b:
    a, b = b, a % b
  return b

n, k = map(int, input().split())
a = list(map(int, input().split()))
a_gcd = a[0]
for i in range(n):
  a_gcd = gcd(a_gcd, a[i])
a_max = max(a)
if k <= a_max and k % a_gcd == 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Measured memory_bytes: 14100
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, M = LI()
AB = LIR(N)

parts = [[] for i in range(M)]
for A, B in AB:
    if (A>M):
        continue
    parts[A-1].append(B)

ans = 0

h = []


for i in range(M):
    for part in parts[i]:
        heappush(h, -part)
    if not (h):
        continue
    ans += -heappop(h)

print(ans)

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

int main(){
  int day[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  string s[] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
  int m, d;

  while(cin >> m >> d, m || d){
    int sum = 2;
    for(int i = 1; i < m; i++){
      sum += day[i - 1];
    }
    sum += d;
    cout << s[sum % 7] << endl;
  }
}

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

int main(){
  string S, T, U;
  int A, B;
  cin >> S >> T ;
  cin >> A >> B ;
  cin >> U;
  if(S == U){
    cout << A-1 << " " << B;  
  } else{
    cout << A << " " << B-1;
  }   
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = sum(list(map(int, input().split())))
c = list(map(int, input().split()))
for i in range(n-1):
  if a[i+1] == a[i] + 1:
    b += c[a[i]-1]
print(b)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long
using namespace std;
 

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

map<int,map<int,int> >mm;
vector<vector<int> >adj;
int vis[705];
bool flag=true;
int sz[2];
int dp[705][1500];

void dfs(int ver,int x)
{
    sz[x]++;
    vis[ver]=x;
    for(auto i:adj[ver])
    {
        if(vis[i]==-1)
        {
            dfs(i,(x+1)%2);            
        }
        else if(vis[i]!=(x+1)%2)
        {
            flag=false;
            return ;
        }
    }
}

signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,m;
    cin>>n>>m;
    adj.resize(n+1);
    int x,y;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        mm[x][y]=1;
        mm[y][x]=1;
    }
    for(int i=1;i<=n;i++)
    {
        vis[i]=-1;
        for(int j=i+1;j<=n;j++)
        {
                if(!mm[i][j])
                {
                    adj[i].push_back(j);
                    adj[j].push_back(i);
                }
        }
    }

    vector<pair<int,int> >lol;

    for(int i=1;i<=n;i++)
    {
        if(vis[i]==-1)
        {
            sz[0]=0;
            sz[1]=0;
            dfs(i,0);
            lol.push_back({sz[0],sz[1]});
        }
    }
    if(!flag)
    {
        cout<<-1;
        return 0;
    }
    int lim=800;
    dp[0][lim]=1;
    int sz=lol.size();
    for(int i=0;i<sz;i++)
    {
        for(int j=0;j<1500;j++)
        {
            if(j-(lol[i].first-lol[i].second)>=0 && j-(lol[i].first-lol[i].second)<1500)
                dp[i+1][j]|=dp[i][j-(lol[i].first-lol[i].second)];
            if(j-(lol[i].second-lol[i].first)>=0 && j-(lol[i].second-lol[i].first)<1500)
                dp[i+1][j]|=dp[i][j-(lol[i].second-lol[i].first)];
        }
    }
    
    int mn=1e9;
    for(int j=0;j<1500;j++)
    {
        if(dp[sz][j])
            mn=min(mn,abs(j-lim));
    }
    if((mn+n)%2)
    {
        cout<<-1;
        return 0;
    }
    x=(mn+n)/2;
    y=n-x;
    int ans=(x*(x-1))/2+(y*(y-1))/2;
    cout<<ans;

}


Measured memory_bytes: 42328