akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    a /= g;
    return a*b;
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int h,n;
    ll cnt = 0;
    cin >> h >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        cnt += a[i];
    }
    if(cnt >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;
const int Maxn=200000;
typedef long long ll;
int n;
ll k;
int a[Maxn+5];
bool check_1(ll x){
	ll ans=0;
	int i,j=n;
	while(1ll*a[1]*a[j]<=x){
		j--;
	}
	j++;
	for(i=1;a[i]<0;i++){
		while(j<=n&&1ll*a[i]*a[j]>=x){
			j++;
		}
		ans+=(n-j+1);
	}
	return ans<k;
}
bool check_2(ll x){
	ll ans=0;
	int i,j;
	i=1;
	while(a[i]<=0){
		i++;
	}
	j=n;
	for(;i<j;i++){
		while(j>i&&1ll*a[i]*a[j]>=x){
			j--;
		}
		ans+=(j-i);
	}
	i=1;
	while(a[i]<0){
		i++;
	}
	i--;
	j=1;
	for(;i>j;i--){
		while(j<i&&1ll*a[i]*a[j]>=x){
			j++;
		}
		ans+=i-j;
	}
	return ans<k;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	int num_less=0,num_grea=0,num_zero=0;
	for(int i=1;i<=n;i++){
		if(a[i]<0){
			num_less++;
		}
		else if(a[i]==0){
			num_zero++;
		}
		else{
			num_grea++;
		}
	}
	ll left,right,mid;
	if(k<=1ll*num_less*num_grea){
		left=(-1000000000000000000ll),right=-1;
		while(left<right){
			mid=(left+right+1)/2;
			if(check_1(mid)){
				left=mid;
			}
			else{
				right=mid-1;
			}
		}
		printf("%lld\n",left);
	}
	else{
		k-=1ll*num_less*num_grea;
		if(k<=1ll*num_zero*(num_zero-1)/2+1ll*(n-num_zero)*num_zero){
			puts("0");
		}
		else{
			k-=1ll*num_zero*(num_zero-1)/2+1ll*(n-num_zero)*num_zero;
			left=1,right=(1000000000000000000ll);
			while(left<right){
				mid=(left+right+1)/2;
				if(check_2(mid)){
					left=mid;
				}
				else{
					right=mid-1;
				}
			}
			printf("%lld\n",left);
		}
	}
	return 0;
}


Measured memory_bytes: 896
//
//  main.cpp
//  cf
//
//  Created by Aviram Magen on 12/03/2019.
//  Copyright © 2019 Aviram Magen. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    vector<vector<int>> teams;
    if (n%2==1)
    {
        vector<int> tmp;
        tmp.push_back(n);
        teams.push_back(tmp);
        n--;
    }
    for(int i=1;i<=n/2;i++)
    {
        vector<int> tmp;
        tmp.push_back(i);
        tmp.push_back(n-i+1);
        teams.push_back(tmp);
    }
    vector<pair<int, int>> ans;
    for(int i=0;i<teams.size()-1;i++)
    {
        for(auto x: teams[i])
            for(auto y: teams[i+1])
                ans.push_back({x,y});
    }
    if(teams.size()>2)
    {
        for(auto x: teams[0])
            for(auto y: teams[teams.size()-1])
                ans.push_back({x,y});
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++)
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=input().split()
b=input().split()
c=input().split()
ans=0

for x in range(len(b)):
  ans+=int(b[x])
  if x+1<len(b):
    if int(a[x])+1==int(a[x+1]):
      ans+=int(c[int(a[x])-1])
print(ans)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long 
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
inline void in(ll &x){
	x=0; char c=getchar(), f=1;
	while ((c<'0' || c>'9') && c!='-') c=getchar();
	if (c=='-') f=-1, c=getchar();
	for (; c>='0' && c<='9'; c=getchar())
		x=x*10+c-'0';
	x*=f;
}
inline void out(ll n){
    if(n<0)
        putchar('-'),n=0-n;
    if(n>=10)
        out(n/10);
    putchar((n%10)+'0');
    return ;
}
int main(){
	ll n,m,ans=0;
	in(n);in(m);
	 if(2*n>=m) ans=m/2,m=0;
	 else ans=n,m-=n*2;
	if(m>0) ans+=m/4;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
from sys import stdin, exit

input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

a, b = mi()
if b / a % 1 == 0:
    print(a+b)
else:
    print(b-a)

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

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: String = read();
    for _ in 0..s.len() {
        print!("x");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int dp[100001][3];

int fun(int **a, int day, int ch, int n)
{
    if(day==n)
    {
        return 0;
    }
    if(dp[day][ch]!=-1)
    {
        return dp[day][ch];
    }
    int k1, k2;
    if(ch==0){k1=1;k2=2;}
    if(ch==1){k1=0;k2=2;}
    if(ch==2){k1=0;k2=1;}
    dp[day][ch]=a[day][ch]+max(fun(a, day+1, k1, n), fun(a, day+1, k2, n));
    return dp[day][ch];
}
int main()
{
    int n;
    cin>>n;
    memset(dp, -1, sizeof(dp));
    int **a=new int*[n];
    for(int i=0;i<n;i++)
    {a[i]=new int[3];
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    cout<<max(fun(a, 0, 0, n), max(fun(a, 0, 1, n), fun(a, 0, 2, n)))<<endl;
    return 0;

}



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

int H, W, N;

void drop(vector<vector<char> >& grid) {
    for (int i = H - 2; i >= 0; i--) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '.') continue;
            for (int k = i; k < H - 1; k++) {
                if (grid[k + 1][j] != '.') break;
                swap(grid[k][j], grid[k + 1][j]);
            }
        }
    }
}

bool is_ok(vector<vector<char> > grid) {
    bool is_empty = true;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] != '.') is_empty = false;
        }
    }
    if (is_empty) return true;
    vector<vector<bool> > is_deleted(H, vector<bool>(W, false));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W - N + 1; j++) {
            if (grid[i][j] == '.') continue;
            int cnt = 1;
            for (int k = j + 1; k < W; k++) {
                if (grid[i][j] == grid[i][k]) cnt++;
                else break;
            }
            if (cnt >= N) {
                is_deleted[i][j] = true;
                for (int k = j + 1; k < W; k++) {
                    if (grid[i][j] == grid[i][k]) is_deleted[i][k] = true;
                    else break;
                }
            }
        }
    }
    for (int i = 0; i < H - N + 1; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '.') continue;
            int cnt = 1;
            for (int k = i + 1; k < H; k++) {
                if (grid[i][j] == grid[k][j]) cnt++;
                else break;
            }
            if (cnt >= N) {
                is_deleted[i][j] = true;
                for (int k = i + 1; k < H; k++) {
                    if (grid[i][j] == grid[k][j]) is_deleted[k][j] = true;
                    else break;
                }
            }
        }
    }
    bool can_delete = false;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (is_deleted[i][j]) {
                grid[i][j] = '.';
                can_delete = true;
            }
        }
    }
    if (!can_delete) return false;
    drop(grid);
    return is_ok(grid);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> N;
    vector<vector<char> > grid(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) cin >> grid[i][j];
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W - 1; j++) {
            swap(grid[i][j], grid[i][j + 1]);
            vector<vector<char> > now_grid(grid);
            drop(now_grid);
            if (is_ok(now_grid)) {
                cout << "YES" << endl;
                return 0;
            }
            swap(grid[i][j], grid[i][j + 1]);
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  queue<int> num;
  int x = 1;
  int cnt = 0;
  bool ans = false;
  
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    num.push(a);
  }
  
  while(num.size()){
    int p = num.front(); num.pop();
    if(p == x){ 
      x ++;
      ans = true;
      continue;
    }
    cnt++;
  }
  
  if(ans) cout << cnt << endl;
  else cout << -1 << endl;
}
  
  


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

struct WeightedUnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;
    vector<int> diff_weight; 
 
    WeightedUnionFind (int n = 1 ) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n); siz.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; i++) par[i] = i, rank[i] = 0, siz[i] = 1, diff_weight[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
 
    bool same(int x, int y) {
        return root(x) == root(y);
    }
 
    void unite(int x, int y, int w) {
        w += weight(x);
        w -= weight(y);

        x = root(x);
        y = root(y);
        if (x == y) return;
 
        if (rank[x] < rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
            diff_weight[x] = -w;
        }
        else {
            par[y] = x;
            siz[x] += siz[y];
            if (rank[x] == rank[y]) rank[x]++;
            diff_weight[y] = w;
        }
    }
 
    int size(int x) {
        return siz[root(x)];
    }

    int weight(int x) {
        root(x);
        return diff_weight[x];
    }

    int diff (int x, int y) {
        return weight(y) - weight(x);
    }
};

//--------------------------- Solve ---------------------------//

void solve() {
    int N, M; cin >> N >> M;
    WeightedUnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int L, R, D; cin >> L >> R >> D;
        L--; R--;
        if (uf.same(L, R)) {
            if (uf.diff(L, R) != D) {
                cout << "No" << '\n';
                return;
            }
        }
        else uf.unite(L, R, D);
    }
    cout << "Yes" << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 4788
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import copy
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S, T):

    si = defaultdict(deque)
    for i, s in enumerate(S):
        si[s].append(i)

    for k in si:
        si[k].append(-1)

    wsi = si
    used = defaultdict(deque)
    ans = 0
    i = -1
    # from pprint import pprint
    # pprint(si)
    for t in T:
        if t not in wsi:
            return -1

        while wsi[t][0] != -1:
            j = wsi[t].popleft()
            used[t].append(j)
            if j > i:
                i = j
                break
        else:
            ans += len(S)
            for k, q in used.items():
                while q:
                    wsi[k].appendleft(q.pop())
            i = wsi[t].popleft()
            used = defaultdict(deque)
            used[t].append(i)
    return ans + i + 1

def f(S, T):
    ans = -1
    ss = S * 1000
    for t in T:
        if t not in S:
            return -1
        for i in range(ans+1, len(ss)):
            if t == ss[i]:
                ans = i
                break
    return ans + 1





def main():
    S = read_str()
    T = read_str()
    print(slv(S, T))

    # S = ''.join(random.choices('ab', k=3))
    # T = ''.join(random.choices('ab', k=10))
    # print(S)
    # print(T)
    # print(slv(S, T))
    # print(f(S, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 107864
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  tmp = input[1].split(" ");
  //配列（ソートで比較する用の宣言）
  var Arrays = [];
  var min;
  var max;

  //文字列から10進数に変換するときはparseIntを使います
  var totalNum = parseInt(input[0], 10);
  for (i = 0; i <= totalNum - 1; i++) {
    Arrays[i] = parseInt(tmp[i], 10);
  }

  min = Math.min(...Arrays);
  max = Math.max(...Arrays);
	
  console.log(max - min);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30480
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  vi a(n);
  rep(i,n){
    cin >> a[i];
  }
  bool ans = true;
  rep(i, n){
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
        ans = false;
      }
    }
  }
  if(ans){
    print("APPROVED");
  }
  else{
    print("DENIED");
  }
}

Measured memory_bytes: 256
s = int(input())
def collatz(n):
    if n % 2 == 0:
        return n // 2
    return 3*n + 1

seen = set([s])
i = 2
while collatz(s) not in seen:
    s = collatz(s)
    seen.add(s)
    i += 1
print(i)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int N; cin >> N;
    deque<double> v;

    for (int i = 0; i < N; ++i) {
        double inp; cin >> inp;
        v.push_back(inp);
    }

    while (v.size() != 1) {
        sort(v.begin(), v.end());
        double f1num = v.front();
        v.pop_front();
        double f2num = v.front();
        v.pop_front();
        double anum = (f1num + f2num) / 2.0;
        v.push_back(anum);
    }
    cout << v[0] << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=15,INF=0x3f3f3f3f;
int d[N],a[N];
int n,k,c,lim,ans=INF;

void dfs(int dep,int cur)
{
	if(dep>=lim) ans=cur>=n?min(ans,cur):ans;
	else for(int i=1;i<=c;++i) dfs(dep+1,cur*10+a[i]);
}

int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1,x;i<=k;++i) scanf("%d",&x),d[x]=1;
	for(int i=0;i<10;++i) if(!d[i]) a[++c]=i;
	for(int t=n;t;t/=10,++lim);

	dfs(0,0);

	int t=a[1]==0?a[2]:a[1];
	for(int i=1;i<=lim;++i) t=t*10+a[1];
	ans=min(ans,t);

	printf("%d\n",ans);
	return 0;
}

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

struct Card
{
  char suit;
  int value;
};

int main()
{
  int N;
  cin >> N;
  vector<Card> C(N), D(N);
  for (int i = 0; i < N; i++)
  {
    string c;
    cin >> c;
    C.at(i).suit = c.at(0);
    C.at(i).value = c.at(1) - '0';
  }

  D = C;

  for (int i = 0; i < N; i++)
  {
    for (int j = N - 1; j >= i + 1; j--)
    {
      if (C.at(j).value < C.at(j - 1).value)
      {
        swap(C.at(j), C.at(j - 1));
      }
    }
  }

  for (int i = 0; i < N; i++)
  {
    int minj = i;
    for (int j = i; j < N; j++)
    {
      if (D.at(j).value < D.at(minj).value)
      {
        minj = j;
      }
    }
    swap(D.at(i), D.at(minj));
  }

  bool is_same = true;
  for (int i = 0; i < N; i++)
  {
    if (!(C.at(i).suit == D.at(i).suit && C.at(i).value == D.at(i).value))
    {
      is_same = false;
      break;
    }
  }

  for (int i = 0; i < N; i++)
  {
    if (i)
    {
      cout << " ";
    }
    cout << C.at(i).suit << C.at(i).value;
  }
  cout << endl;

  cout << "Stable" << endl;

  for (int i = 0; i < N; i++)
  {
    if (i)
    {
      cout << " ";
    }
    cout << D.at(i).suit << D.at(i).value;
  }
  cout << endl;

  if (is_same)
  {
    cout << "Stable" << endl;
  }
  else
  {
    cout << "Not stable" << endl;
  }
}


Measured memory_bytes: 3180
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
count = 0
cal = 0
for i in range(N):
    for k in range(M):
        cal += A[i][k]*B[k]
    if cal + C > 0:
        count += 1
        cal = 0
    else: 
    	cal =0
print(count)

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  string s;
  cin >> s;

  bool can_operate = false;
  FOR(i, 2, s.size()) {
    if (s[i] != s[i % 2]) {
      can_operate = true;
      break;
    }
  }

  if (!can_operate) {
    cout << "Second" << endl;
    return 0;
  }

  if ((s[0] == s[s.size() - 1]) ^ (s.size() % 2 == 1)) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }

  return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
VI e[SIZE];
bool u[SIZE];
int d[SIZE];
int v[2],ker;
bool dfs(int x,int s){
    u[x]=1;
    d[x]=s;
    v[s]++;
    ker++;
    bool tr=1;
    REP(i,SZ(e[x])){
        int y=e[x][i];
        if(u[y]){
            if(d[y]==d[x])tr=0;
        }
        else{
            if(!dfs(y,s^1))tr=0;
        }
    }
    return tr;
}
int main(){
    DRII(N,M);
    REP(i,M){
        DRII(x,y);
        e[x].PB(y);
        e[y].PB(x);
    }
    LL an=-M;
    REPP(i,1,N+1){
        if(!u[i]){
            ker=0;
            v[0]=v[1]=0;
            if(dfs(i,0)){
                an+=v[0]*(LL)v[1];
            }
            else{
                an+=ker*(ker-1LL)/2;
            }
        }
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 31616
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 100010
#define mod 1000000007
int n,a[N];
inline int qpow(int x,int y){
	int t=1;
	while(y){
		if(y&1) t=1ll*t*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return t;
}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=n;i>=1;i-=2){
		if((n&1) && (a[i]!=i-1 || a[i-1]!=i-1)){printf("0");return 0;}
		if(!(n&1) && (a[i]!=i-1 || a[i-1]!=i-1)){printf("0");return 0;}
	}
	if(n&1 && a[1]!=0){printf("0");return 0;}
	printf("%d\n",qpow(2,n/2));
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    string s,t;

    cin>>s>>t;
    int c=0;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]!=t[i])
            c++;
    }

    cout<<c<<endl;




    return 0;
}



Measured memory_bytes: 3780
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
const ll mod = 1e9 + 7;
 
 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll M = 10 + 10;
const ll N = 200 * 1000 + 10;

ll pw(ll a, ll b)
{
	if(b == 0)
		return 1;
	if(b & 1)
		return a * pw(a, b / 2) * pw(a, b / 2);
	return pw(a, b / 2) * pw(a, b / 2);
}

int main()
{
	faster();
	ll n, p;
	cin >> n >> p;
	vector <pii> v;
	for (ll i = 2; i * i <= p; i++)
	{
		if(p % i == 0)
		{
			int k = 0;
			while(p % i == 0)
				p /= i, k++;
			v.push_back({k, i});
		}
	}
	if(p > 1)
		v.push_back({1, p});
	ll maxi = 1;
	for (int i = 0; i < v.size(); i++)
	{
		int t = v[i].first;
		if(t >= n)
		{
			t /= n;
			maxi *= pw((ll) v[i].second, t);
		}
	}
	cout << maxi << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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

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

bool dp[8010][16010];

int main() {
    string s; int x,y;
    cin>>s>>x>>y;

    vector<int> xmove,ymove;
    bool even=true;
    int cnt=0;
    for (int i = 0; i < s.length(); ++i) {
        if(s[i]=='F') ++cnt;
        else{
            if(even) xmove.push_back(cnt);
            else ymove.push_back(cnt);
            cnt=0;
            even^=true;
        }
    }
    if(cnt>0){
        if(even) xmove.push_back(cnt);
        else ymove.push_back(cnt);
    }

    memset(dp,0, sizeof(dp));
    dp[0][8000]=true;
    for (int i = 0; i < xmove.size(); ++i) {
        for (int j = 0; j < 16010; ++j) {
            if(dp[i][j]){
                if(i>=1)dp[i+1][j-xmove[i]]=true;
                dp[i+1][j+xmove[i]]=true;
            }
        }
    }

    if(!dp[xmove.size()][8000+x]){
        cout<<"No"<<endl;
        return 0;
    }

    memset(dp,0, sizeof(dp));
    dp[0][8000]=true;
    for (int i = 0; i < ymove.size(); ++i) {
        for (int j = 0; j < 16010; ++j) {
            if(dp[i][j]){
                dp[i+1][j-ymove[i]]=true;
                dp[i+1][j+ymove[i]]=true;
            }
        }
    }

    if(!dp[ymove.size()][8000+y]){
        cout<<"No"<<endl;
        return 0;
    }

    cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 125568
def main():
    buf = input()
    N = int(buf)
    s = []
    for i in range(N):
        buf = input()
        s.append(buf)
    ab_count = 0
    for i in range(N):
        for j in range(len(s[i])-1):
            if s[i][j] == 'A' and s[i][j+1] == 'B':
                ab_count += 1
    A_count = 0
    B_count = 0
    BA_count = 0
    for i in range(N):
        if s[i][-1] == 'A' and s[i][0] == 'B':
            BA_count += 1
        elif s[i][-1] == 'A':
            A_count += 1
        elif s[i][0] == 'B':
            B_count += 1
    # BA-BA
    ab_count += max(0, BA_count - 1)
    # A-BA-B
    if BA_count > 0 and A_count > 0:
        A_count -= 1
        ab_count += 1
    if BA_count > 0 and B_count > 0:
        B_count -= 1
        ab_count += 1
    # A-B
    ab_count += min(B_count, A_count)
    print(ab_count)


if __name__ == '__main__':
    main()


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

string s;
int k[100010];

int main()
{
	memset(k, 0, sizeof(k));
  ios::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
	cin >> s;
	for (int i = 0; i < s.length() - 1; i++)
	{
		int l = 0, r = 0;
		int pos = 0;
		if (s[i] == 'R' && s[i + 1] == 'L')
		{
			for (int j = i - 1; j >= 0; j--)
			{
				if (s[j] == 'R') l ++;
				else break;
			}
			for (pos = i + 2; pos < s.length(); pos ++)
			{
				if (s[pos] == 'L') r ++;
				else break;
			}
			k[i] = l / 2 + r - r / 2 + 1;
			k[i + 1] =  l - l / 2 + r / 2 + 1;
			i = pos - 1;
		}
	}
	for (int i = 0; i < s.length(); i ++)
		printf("%d ", k[i]);
	printf("\n");
}


Measured memory_bytes: 1104
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#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,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[3];
    rep(i, 3) cin >> A[i];
    sort(A, A + 3);
    cout << A[2] * 10 + A[1] + A[0] << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#AGC010A
import sys
import collections

n= int(input())
tmp = input().split()
a = list(map(lambda a: int(a), tmp))

count=0
for i in range(0,n):
	if(a[i]%2==1):
		count+=1
if(count%2==0):
	print("YES")
else:
	print("NO")

Measured memory_bytes: 14360
// 6/26 解き直し → 6/30
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> B(N, 0);  // ボールを入れるかどうか。0/1。

    // 後ろから貪欲に決めていく。
    for (int i = N-1; i >= 0; i--) {
        int now = 0;
        for (int j = 2*i+1; j < N; j += (i+1)) now += B[j];
        B[i] = (A[i] - now) % 2;
    }

    // cout << "here?" << endl;

    // int res = 0;
    // for (auto b : B) res += b;
    // cout << res << endl;
    // if (res > 0) rep(i, N) if (B[i] == 1) cout << i + 1 << endl;
    vector<int> ans;
    rep(i, N) if (B[i]) ans.push_back(i);
    cout << ans.size() << endl;
    rep(i, ans.size()) {
        if (i != 0) cout << " ";
        cout << ans[i] + 1 << endl;
    }
}

Measured memory_bytes: 5248
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005
int n;
vector<int> arr;
long long dp[200005][3][2][2];
long long solve(int pos, int state, bool flag, bool even) {
	if(pos >= n) {
		if(even == false && flag == false) {
			return minf;
		}
		return 0;
	}
	if(dp[pos][state][flag][even] != -1) {
		return dp[pos][state][flag][even];
	}
	long long ans = solve(pos + 2, state, flag, even) + arr[pos];
	if(state > 0 && (pos + 1) < n) {
		ans = max(ans, solve(pos + 3, state - 1, 1, even) + arr[pos + 1]);
	}
	if(state > 1 && (pos + 2) < n) {
		ans = max(ans, solve(pos + 4, 0, 1, even) + arr[pos + 2]);
	}
	dp[pos][state][flag][even] = ans;
	return ans;
}
int main()
{
    fastread;
    memset(dp, -1, sizeof(dp));
    cin>>n;
    arr.resize(n);
    for(int i = 0; i < n; i++) {
    	cin>>arr[i];
    }
    if(n % 2) {
    	cout<<solve(0, 2, 0, 0)<<endl;
    }
    else {
    	cout<<solve(0, 1, 0, 1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 32236
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll maxi = (ll)pow(10, 5);

int main(){
  ll Q;
  cin >> Q;
  vvl lr(Q, vl(2));
  rep(i, Q) cin >> lr[i][0] >> lr[i][1];

  vl prime(maxi + 1, 1);
  ll sq = (ll)sqrt(maxi) + 1;
  prime[0] = prime[1] = 0;
  rep2(i, 2, sq){
    if(prime[i] == 1){
      ll j = 2*i;
      while(j <= maxi){
        prime[j] = 0;
        j += i;
      }
    }
  }

  vl like(maxi + 1, 0);
  rep(i, maxi + 1){
    if((prime[i] == 1) && (prime[(i + 1) / 2] == 1)) like[i] = 1;
  }

  vl cumul(maxi + 1, 0);
  rep2(i, 1, maxi + 1) cumul[i] += cumul[i - 1] + like[i];

  rep(i, Q){
    cout << cumul[lr[i][1]] - cumul[lr[i][0] - 1] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 8448
# deque で高速に文字を先頭でもたせる

#初期入力
from collections import deque
import sys
input = sys.stdin.readline
S = input().strip()
Q = int(input())
FQ_dic={}
for i in range(Q):
    FQ_dic[i] =input().split()

rev =0 #反転Flag
dq =deque(S)
for i in range(Q):
    if FQ_dic[i][0] =="1":
        rev +=1
    else:
        a,b,c =FQ_dic[i]
        if rev %2 ==0 and b =="1"  :
            dq.appendleft(c)
        elif rev %2 ==0 and b =="2":
            dq.append(c)
        elif rev %2 ==1 and b =="1":
            dq.append(c)
        elif rev %2 ==1 and b =="2":
            dq.appendleft(c)
if rev %2 ==1:
    dq.reverse()
ans ="".join(dq)
print(ans)

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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
    int h,a;
    cin>>h>>a;
    if(h%a==0)
     cout<<(h/a)<<"\n";
     else
      cout<<((h/a)+1);
      return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <iomanip>
#include <assert.h>

using namespace std;

const int MAXN = 200005;

struct Edge
{
	int to;
	int next;
}edge[MAXN << 1];

int n,id,ans;
int a[MAXN];
int first[MAXN];

bool mark[MAXN];

vector<pair<int,int> > v;

void addE(int u,int v)
{
	edge[++id] = (Edge){v,first[u]};
	first[u] = id;
}

void dfs(int now)
{
	mark[now] = true;
	for (int i = first[now];i;i = edge[i].next)
		if (!mark[edge[i].to])
		{
			dfs(edge[i].to);
			int val = min(v[edge[i].to].second,v[now].second);
			v[edge[i].to].second -= val;
			v[now].second -= val;
			ans += val;
		}
}

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	sort(a + 1,a + n + 1);
	v.push_back(make_pair(0,0));
	for (int i = 1;i <= n;i++)
	{
		if (v.size() == 0 || v.back().first != a[i])
			v.push_back(make_pair(a[i],1));
		else
			v.back().second++;
	}
	n = v.size() - 1;
	for (int k = 1;k <= 30;k++)
	{
		int sum = (1 << k);
		for (int i = 1,j = n;i <= j;i++)
		{
			while (i <= j && v[i].first + v[j].first > sum)
				j--;
			if (i >= j)
				break;
			if (v[i].first + v[j].first == sum)
			{
				addE(i,j);
				addE(j,i);
			}
		}
	}
	for (int i = 1;i <= n;i++)
		if (!mark[i])
			dfs(i);
	for (int k = 1;k <= 30;k++)
		for (int i = 1;i <= n;i++)
			if (v[i].first + v[i].first == (1 << k))
				ans += (v[i].second >> 1);
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 6000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	BufferedReader input;
	int field[][];
	final int N=3;
	final int dir[][]={{1, 0}, {1, 1}, {0, 1}, {-1, 1}};
	
	int search(int i, int j, int d, char c){
		if(i<0||i>=N||j<0||j>=N||field[i][j]!=c) return 0;
		else return 1+search(i+dir[d][0], j+dir[d][1], d, c);
	}
	
	int length(char c){
		int max=0;
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				for(int d=0;d<4;++d){
					int k=search(i, j, d, c);
					max=max>k?max:k;
				}
			}
		}
		return max;
	}
	
	
	char solve(){
		if(length('o')==3) return 'o';
		else if(length('x')==3) return 'x';
		else return 'd';
	}
	
	void makeField(String s){
		field=new int[3][3];
		for(int i=0;i<9;++i){
			field[i/3][i%3]=s.charAt(i);
		}
	}
	
	void io(){
		input=new BufferedReader(new InputStreamReader(System.in));
		String s;
		try {
			while((s=input.readLine())!=null){
				makeField(s);
				System.out.println(solve());
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}

}

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

const int N = 200005;
int n, a[N];

int main() {
    int red = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        char ch; cin >> ch;
        a[i] = ch == 'W' ? 0 : 1;
        red += a[i];
    }
    int x = 0, y = 0, c = 0;
    for (int i = 1; i <= red; i++) c += a[i];
    for (int i = 1; i <= n && a[i] == 0; i++) x++;
    for (int i = 1; i <= n && a[i] == 1; i++) y++;
    int ans = min(max(red - c, 0), x + red);
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

int h, w;
int n;

int a[100005], b[100005];
long long c[10];
#define x first
#define y second
signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> h >> w >> n;
    memset(c, 0ll, sizeof c);
    set< pair<int, int> > av;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        av.insert({a[i], b[i]});
    }
    set< pair<int, int> > canxet;
    for (int i = 1; i <= n; i++) {
        for (int j = -2; j <= 2; j++) {
            for (int k = -2; k <= 2; k++) {
                if (a[i] + j >= 1 && a[i]+j <= h-2 && b[i] + k >= 1 && b[i] + k <= w-2) {
                    canxet.insert({a[i]+j, b[i]+k});
                }
            }
        }
    }
    for (set< pair<int, int> >::iterator i = canxet.begin(); i != canxet.end(); i++) {
        int cnt = 0;
        for (int j = 0; j <= 2; j++) {
            for (int k = 0; k <= 2; k++) {
                if (av.find({(*i).x + j, (*i).y + k}) != av.end()) cnt++;
            }
        }
        c[cnt]++;
    }
    c[0] = 1ll*(w-2)*(h-2);
    for (int i = 1; i < 10; i++) {
        c[0] -= c[i];
    }
    for (int i = 0; i < 10; i++) {
        cout << c[i] << endl;
    }
}


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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    int i = A;
    while(i < B+1){
        if(i%K == 0){
            cout << "OK" << endl;
            return 0;
        }else{
            i++;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9+7;

int main(){
    string s;
    cin>>s;
    ll sl = s.length();
    ll dp[sl][13];
    memset(dp,0,sizeof(dp));
    //dp[sl-1][0]=1;
    if(s[0]=='?'){
        for(int i=0;i<10;i++)dp[0][i]=1;
    }else{
        dp[0][s[0]-'0']=1;
    }
    for(ll i=1;i<sl;i++){
        int c=0;
        if(s[i]!='?'){
            c = s[i]-'0';
            for(int j=0;j<13;j++){
                dp[i][(j*10+c)%13] = (dp[i-1][j] + dp[i][(j*10+c)%13])%mod;
                //dp[i][(c*10+j)%13] %=mod;
            }
        }else{
            c = -1;
            for(int j=0;j<10;j++){
                for(int k=0;k<13;k++){
                    dp[i][(10*k+j)%13] = (dp[i][(10*k+j)%13]+dp[i-1][k])%mod;
                    //dp[i][(c*10+j)%13] %=mod;
                }
            }
        }
    }
    // for(int i=0;i<sl;i++){
    //     cout<<"i:"<<i<<" dp:"<<dp[i][5]<<endl;
    // }
    cout<<dp[sl-1][5]<<endl;
}

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

int main() {
  string S;
  cin >> S;
  char s=S.at(0);
  int ans=0;
  for(int i=1; i<S.size(); i++){
    if(s!=S.at(i)){
      s=S.at(i);
      ans++;
    }
  }
  cout << ans << endl;
    
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));

  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
    //}
  //}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <utility>
#include <cmath>
using namespace std;
typedef long long int lli;

//Floating Point Numbers
struct fpn{
	lli sgn;
	lli exp;
	fpn(lli s, lli e):sgn(s),exp(e){}
	fpn(bitset<64> f){
		sgn = (f.to_ullong() & ((1ULL<<52)-1)) | (1ULL << 52);
		exp = f.to_ullong() >> 52;
	}
	fpn add(fpn a){
		fpn b = *this;
		if(a.exp > b.exp) swap(a, b);
		a.sgn >>= (b.exp -a.exp);
		sgn = a.sgn +b.sgn;
		exp = b.exp;
		if(sgn>>53 & 1){
			sgn >>= 1;
			exp++;
		}
		return *this;
	}
	fpn times(lli n){
		fpn a = *this;
		fpn ret = fpn(0, 0);
		for(int i=0; i<64; i++){
			if(n>>i & 1) ret.add(a);
			a.exp++;
		}
		*this = ret;
		return *this;
	}
	lli rem_addition(fpn a){
		a.sgn >>= (exp -a.exp);
		if(a.sgn == 0) return -1;
		return ((1LL<<53) -sgn) /a.sgn;
	}
	bitset<64> to_bitset(){
		return bitset<64>(exp<<52 | (sgn^1LL<<52));	
	}
	double to_double(){
		return (double)sgn*pow(2, exp-52);
	}
};

int main(){
	while(1){
		lli n;
		cin >> n;
		if(n==0) break;

		bitset<64> bit;
		cin >> bit;
		fpn a(bit);
		fpn s = a;
		while(n>0){
			lli rem = s.rem_addition(a);
			if(rem == -1) break;
			if(rem > n) rem = n;
			if(rem == 0) rem = 1;
			fpn tmp = a;
			tmp.sgn &= ~((1LL<<(s.exp -tmp.exp))-1);
			tmp.times(rem);
			s.add(tmp);
			n -= rem;
		}
		cout << s.to_bitset() << endl;
	}
    return 0;
}


Measured memory_bytes: 3152
s = input()
s = s.split('BC')
count = [0]
count_all = 0
Icount = 0

for i in range(0,len(s)-1):
    Icount = 0
    j = 1
    while(j<=len(s[i]) and s[i][-j]=='A'):
        Icount = Icount + 1
        j = j + 1
        
    if (s[i]=='' or s[i]=='A'*len(s[i])):
        Icount = Icount + count[-1]
   
    count.append(Icount)
  
        
count_all = sum(count)  
print(count_all)

Measured memory_bytes: 7328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int n, m;
  cin >> n >> m;
  vi k(m);
  vector<vi> s(m);
  for (int i = 0; i < m; i++) {
    cin >> k.at(i);
    for (int j = 0; j < k.at(i); j++) {
      int x;
      cin >> x;
      s.at(i).push_back(x);
    }
  }
  vi p(m);
  for (int i = 0; i < m; i++) cin >> p.at(i);
  string bits;
  for (int i = 0; i < n; i++) bits.push_back('0');
  ll cnt = 0;
  for (int i = 0; i < pow(2, n); i++) {
    for (int j = 0; j < m; j++) {
      int sum = 0;
      for (int l = 0; l < k.at(j); l++)
        if (bits.at(s.at(j).at(l) - 1) == '1') sum++;
      if (sum % 2 != p.at(j)) break;
      if (j == m - 1) cnt++;
    }
    if (i == pow(2, n) - 1) break;
    int x = 0;
    while (bits.at(n - 1 - x) == '1') {
      bits.at(n - 1 - x) = '0';
      x++;
    }
    bits.at(n - 1 - x) = '1';
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> a(6);
  for(int i=0;i<6;i++){
    cin >>a.at(i);
  }
  int s=0;
  for(int i=0;i<6;i++){
    for(int j=0;j<i;j++){
      if(a.at(i)==a.at(j))s++;
    }
  }
  if(s==3)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val sorted = A.sorted()
    var left = 0
    var right = N
    val x = 1L * N * (N + 1) / 4
    while (left + 1 < right) {
        val mid = (left + right) / 2
        val am = sorted[mid]
        val s = IntArray(N + 1)
        for (n in 0 until N) {
            s[n + 1] = s[n] + if (A[n] >= am) 1 else -1
        }
        val bit = BIT(2 * N + 1)
        var sum = 0L
        for (n in 0 until N + 1) {
            sum += bit.sum(s[n] + N)
            bit.add(s[n] + N, 1)
        }
        if (x <= sum) {
            left = mid
        } else {
            right = mid
        }
    }
    println(sorted[left])
}

class BIT(size: Int) {
    private val bit: LongArray
    init { bit = LongArray(size) }
    fun sum(n: Int): Long {
        var k = n
        var s = 0L
        while (k > 0) {
            s += bit[k]
            k -= k and -k
        }
        return s
    }
    fun add(n: Int, x: Long) {
        var k = n
        while (k < bit.size) {
            bit[k] += x
            k += k and -k
        }
    }
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


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

int main() {
  int a_hp, a_attack, b_hp, b_attack;
  cin >> a_hp >> a_attack >> b_hp >> b_attack;
  while (true) {
    // 高橋くんの攻撃
    b_hp -= a_attack;
    if (b_hp <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    a_hp -= b_attack;
    if (a_hp <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3624
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}


class DLine {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, X, Y; in >> N >> X >> Y;
	    vector<int> ans(N+1);
	    for (int i = 1; i <= N; ++i) {
	        for (int j = i+1; j <= N; ++j) {
	            int xy = abs(X - i) + 1 + abs(Y - j);
	            int yx = abs(Y - i) + 1 + abs(X - j);
	            int dist = min(abs(i - j), min(xy, yx));
	            ans[dist]++;
	        }
	    }
	    for (int k = 1; k <= N-1; ++k) {
	        out << ans[k] << '\n';
	    }
	}
};


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

	DLine solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

int group[13];

int main() {
  group[1] = 1;
  group[2] = 3;
  group[3] = 1;
  group[4] = 2;
  group[5] = 1;
  group[6] = 2;
  group[7] = 1;
  group[8] = 1;
  group[9] = 2;
  group[10] = 1;
  group[11] = 2;
  group[12] = 1;

  int x, y;
  cin >> x >> y;
  if (group[x] == group[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  ll ans = 0;
  rep(i, 0, n) cin >> d[i];
  rep(i, 0, n - 1) rep(j, i + 1, n) ans += d[i] * d[j];
  cout << ans << endl;
  return 0;
}

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

using namespace std;
const int N=3e5+5;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,k,q;
    cin>>n>>k>>q;
    for(int i=0;i<q;i++)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(k-q+a[i]>0) cout<<"Yes"<<'\n';
        else cout<<"No"<<'\n';
    }
    return 0;
}


Measured memory_bytes: 1024
m=10**9+7;f=max;r=range
for _ in r(int(input())):
	x,y=sorted(map(int,input().split()));s=-1;i=j=1
	while j<=x and i+j<=y:i,j,s=j,i+j,s+1
	if x<2 or y<3:print(1,x*y%m);continue
	a=f(0,(y-j)//i+1)+f(0,(x-j)//i+1);i=j=1
	for c in r(s):
		k,l=j,i+j*2
		for _ in r(s-c):k,l=l,k+l
		if x>=k:a+=f(0,(y-l)//k+1)
		if y>=k:a+=f(0,(x-l)//k+1)
		i,j=j,i+j
	print(s+1,a%m)

Measured memory_bytes: 81052
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)
	arr := []int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
	fmt.Println(arr[k-1])
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main() {
    int a;
    int b;
    cin >> a >> b;

    if((a%2==0 && b%2==1) || (a%2==1 && b%2==0)){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (a+b)/2 << endl;
    }
	
}

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

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
    int r;
    cin>>r;
    printf("%.10f\n",2*3.14159*r);
    return 0;
}

Measured memory_bytes: 3760