akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<ll> A(N + 1);
  A[0] = 0;
  REP1(i, N)
  cin >> A[i];
  sort(ALL(A));
  vector<ll> sum(N + 1);
  sum[0] = 0;
  REP1(i, N)
  sum[i] = sum[i - 1] + A[i];
  int ng = 0;
  for (int i = N - 1; i >= 1; --i)
  {
    if (2 * sum[i] < A[i + 1])
    {
      ng = i;
      break;
    }
  }
  cout << N - ng << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int n;
    cin >> n;
    ll sum=0;
    ll ans = 9000000000;
    vector<ll> card(n);
    vector<ll> ruiseki(n+1);
    rep(i,n){
        cin >> card[i];
        sum += card[i];
    }
    for(int i=1; i<n+1; i++){
        ruiseki[i] = ruiseki[i-1] + card[i-1];
    }
    rep(i,n+1){
        if(i == 0 || i==n) continue;
        ll a,b;
        a =  ruiseki[i];
        b = sum - ruiseki[i];
        ll c = abs(a-b);
        if(c<ans) ans = c;
    }
    cout << ans << endl;
        
}

Measured memory_bytes: 6348
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
 
typedef long long ll;

// v[i] := テヲツ。ツ?ヲツ閉ーテ」ツ??i+1)テ」ツ?ョテ・ツ按療」ツ?ョテ・ツ青暗ィツィツ暗ヲツ鳴?・ツュツ療ヲツ閉ー.
vector<ll> v;

// 10^x テ」ツつ津ィツソツ氾」ツ??
ll pow10_(ll x){
	ll res = 1;
	for(ll i = 0 ; i < x ; i++ ) res *= 10;
	return res;
}

// long long => string テ」ツ?ョテ・ツ、ツ嘉ヲツ渉?
string i_to_s(ll n){
	string s;
	do{
		s.push_back( (n % 10) + '0' );
		n /= 10;
	}while( n != 0 );
	reverse(s.begin(), s.end());
	return s;
}

// k テ」ツつ津ィツカツ?」ツ?暗」ツ?ェテ」ツ??ヲツ慊?・ツ、ツァテ」ツ?ョ (d+1) * x テ」ツつ津ヲツアツづ」ツつ?」ツつ?
ll search(ll k, ll d, ll &x){
	ll low = 0, high = 1e+18;
	while( 1 < high - low ){
		ll mid = (low + high) / 2;
		ll n = (d + 1) * mid;
		
		if( n < k ){
			low = mid;
		}else{
			high = mid;
		}
	}
	
	ll a = (d + 1) * low, b = (d + 1) * high;
	if( b <= k ){
		x = high;
		return b;
	}
	x = low;
	return a;
}

// テ、ツスツ催ァツスツョ pos テ」ツ?ョテヲツ鳴?・ツュツ療」ツつ津ィツソツ氾」ツ??
char solve(ll pos){ 
	for(int i = 0 ; i < v.size() ; i++ ){
		if( 0 <= pos - v[i] ){ // テヲツャツ。テ」ツ?ョテヲツ。ツ?ヲツ閉ーテ」ツ?ォテ」ツ?凖」ツつ?
			pos -= v[i];
		}else{ // テヲツ。ツ?ヲツ閉ーテ」ツ??i+1)テ」ツ?ョテ」ツ?ゥテ」ツ?禿」ツ?凝」ツつ恥osテ」ツ?古ヲツ個?」ツ?療」ツ?ヲテ」ツ??」ツつ?
			ll x;
			pos -= search(pos, i, x);
			x = x + pow10_(i);
			string s = i_to_s(x);
			// s(i+1テヲツ。ツ?」ツ?ョテヲツ閉ーテ・ツュツ? テ」ツ?ョテ」ツ?ゥテ」ツ?禿」ツ?凝」ツつ?pos テ」ツ?古ヲツ個?」ツ?療」ツ?ヲテ」ツ??」ツつ?
			for(int j = 0 ; j < s.size() ; j++ ){
				if( pos == 0 ){
					return s[j];
				}
				pos--;
			}
		}
	}
	return 0;
}

int main(){
	// テ・ツ青?ヲツ。ツ?ヲツ閉ー i テ」ツ?ォテ」ツ?、テ」ツ??」ツ?ヲテ・ツ青暗ィツィツ暗」ツ?ョテヲツ鳴?・ツュツ療ヲツ閉ーテ」ツつ津ヲツアツづ」ツつ?」ツ?ヲテ」ツ?甘」ツ??
	for(ll i = 1, n = 9; i <= 19 ; i++, n*= 10 ){
		v.push_back(n * i);
	}
	
	ll N, K;
	while( cin >> N >> K, N || K ){
		// テ、ツスツ催ァツスツョ (N-1) テ」ツ?凝」ツつ?K テヲツ鳴?・ツュツ療・ツ?コテ・ツ環崚」ツ?凖」ツつ?
		for(int i = N - 1 ; i < N + K - 1 ; i++ ){
			cout << solve(i);
		}
		cout << endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;

using ll = long long;
using ull = unsigned long long;

template <int mod>
struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    int getmod() { return mod; }
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.val;
    }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 1000000007;  // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1, -1);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i + 1);
    }
    vector<int> num;
    int red = 0;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int d = A[i + 1] - A[i] - 2;
        red += d;
        cnt++;
        // cout << red << " " << d << " " << cnt << endl;
        if (red < 0) {
            num.push_back(cnt);
            cnt = 0;
            red = 1;
        }
    }
    if (cnt != 0) num.push_back(cnt);

    modint ans = modint(1);
    int now = 0;
    for (auto i : num) {
        // cout << i << " " << now << " " << ans << endl;
        now += i;
        ans *= now;
        now--;
    }
    for (int i = now; i >= 1; i--) {
        ans *= i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    int W, a, b;
    cin >> W >> a >> b;
    if(a + W < b) {
        cout << b-(a+W) << endl;
    } else if(b+W < a) {
        cout << a - (b+W) << endl;
    } else {
        cout << 0 << endl;
    }
    /*
    char a, b;
    cin >> a >> b;
    if((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) {
        cout << 'H' << endl;
    } else {
        cout << 'D' << endl;
    }
    */
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    ans = [0] * n
    csf = []
    for _ in range(n - 1):
        c, s, f = map(int, input().split())
        csf.append([c, s, f])
    ps = 0
    pf = 1
    for i in range(n - 1):
        elapsed = csf[i][0] + csf[i][1]
        for j in range(i + 1, n - 1):
            c, s, f = csf[j]
            if elapsed <= s:
                elapsed = s
            else:
                elapsed += -elapsed % f
            elapsed += c
        ans[i] = elapsed
    print(*ans, sep="\n")

main()


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

int main() {
    string s;
    cin >> s;
    int leng = s.size();

    for (int i=0; i<leng; i++) {
        if (i == leng-1) {
            cout << 'x' << endl;
        } else {
            cout << 'x';
        }
    }
}

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

int main(void)
{
  int	n;
  int	d;
  int 	t;
  
  cin >> n >> d >> t;
  
  if (n <= d * t)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
  
}

Measured memory_bytes: 3632
from math import sqrt as r
from math import ceil as f
N = int(input())

dev2 = 0
N2 = N
while True:
    if N2 % 2 == 0:
        N2 /= 2
        dev2 += 1
    else:
        break

p = [2] * dev2

for c in range(3, f(r(N2)), 2):
    while True:
        if N2 % c == 0:
            N2 /= c
            p.append(int(c))
        else:
            break
if N2 != 1:
    p.append(int(N2))


pp = []
while True:
    if len(p) == 0:
        break
    pp.append(p.count(p[0]))
    del p[:pp[-1]]

#print(pp)
ans = 0

for c in pp:
    cou = 1
    while True:
        if cou + (cou + 1) > c:
            ans += cou
            break
        else:
            c -= cou
            cou += 1
print(ans)
        


Measured memory_bytes: 9240
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
string s;
int n,k;
int ans;
int main() {
	cin>>n>>k;
	cin>>s;
//	cout<<n<<" "<<k<<endl;
//	cout<<s<<endl;
	int l=0,r=0;
	while(r<n) {
		//cout<<r<<endl;
		if(s[r]=='0') {
			if(k==0) {
				while(s[l]=='1')++l;
				while(s[l]=='0')++l;
				++k;
			}
			while(r<n-1&&s[r]=='0')++r;
			--k;
		}
		ans=max(ans,r-l+1);
		++r;
	}
	printf("%d\n",ans);
	return 0;
}




Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

static const int N = 1000;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int n,a[N],m,dp[50010];
int dfs(int cost){
	int c = (1<<30);
	if(dp[cost] != (1<<30)){
		return dp[cost];
	}
	rep(i,n){
		if(cost-a[i] < 0)continue;
		c = min(c,dfs(cost-a[i]) + 1);
	}
	if(cost == 0)c=0;
	dp[cost] = c;
	return c;
}

int main(void){
	cin>>m>>n;
	rep(i,n)cin>>a[i];
	rep(i,50010)dp[i] = (1<<30);
	cout<<dfs(m)<<endl;;

}

Measured memory_bytes: 3704
#include<stdio.h>
#include<string.h>
const long long mod=1e9+7;
int main()
{
    char x;
    long long numa=0,numab=0,nums=1,numabc=0;
    while(scanf("%c",&x)!=EOF)
    {
        if(x=='A')
        {
            numa+=nums;
        }
        if(x=='B')
        {
            numab+=numa;
        }
        if(x=='C')
        {
            numabc+=numab;
        }
        if(x=='?')
        {
            numabc=3*numabc+numab;
            numab=3*numab+numa;
            numa=3*numa+nums;
            nums=nums*3;
        }
        nums=nums%mod;
        numa=numa%mod;
        numab=numab%mod;
        numabc=numabc%mod;
        //printf("%lld %lld %lld %lld\n",nums,numa,numab,numabc);
    }
    printf("%lld\n",numabc);
    return 0;
}

Measured memory_bytes: 128
import math
a,b = [int(x) for x in input().split()]
if a%2 == 0:
  amax = math.ceil((a+1)*12.5)
  amin = a*12.5
else:
  amax = (a+1)*12.5
  amin = math.ceil(a*12.5)
bmax = int((b+1)*10)
bmin = int(b*10)
hantei = bmin
if amax <= bmin:
  hantei = -1
elif bmax <= amin:
  hantei = -1
elif bmin < amin:
  hantei = amin
print(int(hantei))

Measured memory_bytes: 3064
#include <iostream>
int main(void){
  int n;
  std::cin >> n;
  int a = n/1.08;
  int b = a*1.08;
  int c = (a+1)*1.08;
  if(b == n)
  	std::cout << a << std::endl;
  else if (c == n)
  	std::cout << a+1 << std::endl;
  else
	  std::cout << ":(" <<std::endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        int max = Arrays.stream(l).max().getAsInt();
        int other = Arrays.stream(l).sum() - max;
        String result = max < other ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 26836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e6
typedef long long ll;
typedef vector<vector<int>> matrix;


int H, W, n;
vector<string> S;
matrix num, w;



void input() {
    cin >> H >> W;
    S = vector<string>(H);
    rep(i, H) cin >> S[i];
}


void warshall_floyd() {
    rep(k, n) rep(i, n) rep(j, n) {
        w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
    }
}


int main() {
    input();
    n = 0;
    matrix num(H, vector<int>(W));
    rep(i, H) rep(j, W) num[i][j] = n++;
    w = matrix(n, vector<int>(n, INF));
    rep(i, H) rep(j, W) {
        if (S[i][j] == '#') continue;
        int x = num[i][j];
        w[x][x] = 0;
        if ((i > 0) && (S[i-1][j] == '.')) w[x][num[i-1][j]] = 1;
        if ((i < H-1) && (S[i+1][j] == '.')) w[x][num[i+1][j]] = 1;
        if ((j > 0) && (S[i][j-1] == '.')) w[x][num[i][j-1]] = 1;
        if ((j < W-1) && (S[i][j+1] == '.')) w[x][num[i][j+1]] = 1;
    }
    warshall_floyd();
    int ans = 0;
    rep(i, n) rep(j, n) {
        if (w[i][j] == INF) continue;
        ans = max(ans, w[i][j]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 896
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
    int n = Integer.parseInt(sc.next());
    String s=sc.next();
    int x=0,max=0;
    for (int i = 0; i < n; i++) {
        if(s.charAt(i)=='I'){
            x++;
        }else{
            x--;
        }
        max=max(max,x);
    }
    out.println(max);
}}

Measured memory_bytes: 23508
#include<iostream>
#include<string>
using namespace std;
int main() {
    int h, w;
    cin >> h >> w;
    int i;
    for(i=0; i<h; i++){
        string s;
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int A, B;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {

    cin>>A>>B;

    cout<<max({A+B, A-B, A*B});
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;

	rep (i, s.length()){
		if (s[i] == ',') s[i] = ' ';
	} // end rep

	cout << s << endl;

	return 0;
}

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

int a, b, c, d;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> a >> b >> c >> d;
	a = a / d + (a % d > 0 ? 1 : 0);
	c = c / b + (c % b > 0 ? 1 : 0);
	if(a >= c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3664
// https://atcoder.jp/contests/abc128/tasks/abc128_b
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

struct Restaurant
{
    int index, score;
    string name;
};
bool myMethod(const struct Restaurant &first, const struct Restaurant &second)
{
    if (first.name == second.name)
    {
        return first.score > second.score;
    }
    else
    {
        return first.name < second.name;
    }
}
int main()
{
    int n;
    cin >> n;
    vector<Restaurant> restList(n);
    for (int i = 0; i < n; i++)
    {
        restList[i].index = i + 1;
        cin >> restList[i].name >> restList[i].score;
    }
    sort(all(restList), myMethod);
    for (int i = 0; i < n; i++)
        cout << restList[i].index << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define N 100005
int n;
struct edge{
    int to,next;
}e[N<<1];
int head[N],cnt;
void add(int u,int v){
    e[++cnt]=(edge){v,head[u]};
    head[u]=cnt;
}
int son[N];
int path[N],len;
bool dfs(int x,int fa){
    bool p=x==n;
    for(int i=head[x];i;i=e[i].next){
        int v=e[i].to;
        if(v==fa)continue;
        p|=dfs(v,x);
    }
    son[fa]+=son[x]+1;
    if(p){
        path[++len]=x;
        return true;
    }
    return false;
}
int main(){
    scanf("%d",&n);
    for(int i=1,u,v;i<n;++i){
        scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    dfs(1,0);
    int ans=0;
    for(int i=len;i>len/2;--i)
        ans+=son[path[i]]-son[path[i-1]];
    printf("%s\n",ans*2>n?"Fennec":"Snuke");
    return 0;
}


Measured memory_bytes: 7552
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
ll n;
ll a[1010];
ll sum[2];
vector<ll> vt[2];
int main()
{
	scanf("%lld", &n);
	ll ch = 1;
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		if (a[ch] < a[i])
			ch = i;
		if (a[i] > 0) {
			vt[i % 2].push_back(i);
			sum[i % 2] += a[i];
		}
	}
	if (a[ch] <= 0) {
		printf("%lld\n%d\n", a[ch],n-1);
		for (int i = n; i > ch; i--)
			printf("%d\n", i);
		for (int i = 1; i < ch; i++)
			puts("1");
		return 0;
	}
	int xx = 0;
	if (sum[0] < sum[1])
		xx = 1;
	printf("%lld\n", sum[xx]);
	vector<int> gap;
	int t = vt[xx].size();
	for (int i = n; i > vt[xx][t - 1];i--) {
		gap.push_back(i);
	}
	for (int i = 1; i < vt[xx][0]; i++)
		gap.push_back(1);
	for (int i = 0; i < vt[xx].size() - 1; i++) {
		int mm = vt[xx][i + 1] - vt[xx][i];
		for (int y = mm / 2 + 1; y >= 2; y--)
			gap.push_back(y);
	}
	printf("%d\n", gap.size());
	for (int i = 0; i < gap.size(); i++)
		printf("%d\n", gap[i]);
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using System.Threading.Tasks;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nda = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var monsters = Enumerable.Repeat(0, (int)nda[0]).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).OrderBy(x => x[0]).ToArray();
        SegmentTree<long> segtree = new SegmentTree<long>((int)nda[0], 0, (x, y) => x + y);
        for (int i = 0; i < nda[0]; i++)
            segtree.Operate(i, monsters[i][1]);
        var dist = 0L;
        int topInd = 0;
        long total = 0;
        for (int i = 0; i < nda[0]; i++)
        {
            while (topInd + 1 < monsters.Length)
            {
                var nextDist = dist + monsters[topInd + 1][0] - monsters[topInd][0];
                if (nda[1] * 2 < nextDist) break;
                dist = nextDist;
                topInd++;
            }
            if (0 <= segtree[i]) 
            {
                long count = (segtree[i] + nda[2] - 1) / nda[2];
                total += count; 
                segtree.Operate(i, topInd, -nda[2] * count);
            }
            if (i != nda[0] - 1) dist -= monsters[i + 1][0] - monsters[i][0];
        }
        Console.WriteLine(total);
    }
}

class SegmentTree<T>
{
    public readonly int Size;
    T[] Operators;
    Func<T, T, T> Merge;
    int LeafCount;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public SegmentTree(int size, T identity, Func<T, T, T> merge)
    {
        Size = size;
        Merge = merge;
        LeafCount = 1;
        while (LeafCount < size) LeafCount <<= 1;
        Operators = new T[LeafCount << 1];
        for (int i = 0; i < Operators.Length; i++)
            Operators[i] = identity;
    }
    public T this[int index]
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get { return Query(index); }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int i, T x) { i += LeafCount; Operators[i] = Merge(Operators[i], x); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int l, int r, T x)
    {
        for (l += LeafCount, r += LeafCount; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1)
        {
            if ((l & 1) == 1) Operators[l] = Merge(Operators[l], x);
            if ((r & 1) == 0) Operators[r] = Merge(Operators[r], x);
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Query(int i)
    {
        i += LeafCount;
        T res = Operators[i];
        while (0 < (i >>= 1)) res = Merge(res, Operators[i]);
        return res;
    }
}

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

int main()
{
	long long a,b,c,x,y,sum;
	cin>>a>>b>>c>>x>>y;
	
		
		sum=0;
		if ((c*2)>=(a+b))
		{
			sum=x*a+y*b;
		}
		else
		{
			if (x>y) 
			{
			   if (2*c<a)
			   {
			   	  sum=c*2*y+c*2*(x-y);
			   }
			   else
			   {
			      sum=c*2*y+a*(x-y) ; 
			    }
			}
			else 
			{
			   if (2*c<b)
			   {
			   	  sum=c*2*x+c*2*(y-x);
			   }
			   else
			   {
			   	  sum=c*2*x+b*(y-x);
			   }
			   
		    }
		
			
		}
		cout<<sum<<endl;
	
}

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b,c]=nrin(3)
  out(b-a==c-b?'YES':'NO')
}
main()

Measured memory_bytes: 7372
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>

using namespace std;

void selection_sort(deque<int> values, int n) {
  int cnt = 0;

  for (int i = 0; i < n; i++) {
    int minInd = i;

    for (int j = i; j < n; j++) {
      if (values[j] < values[minInd]) {
        minInd = j;
      }
    }

    if (minInd == i) continue;

    int tmp;

    tmp = values[i];
    values[i] = values[minInd];
    values[minInd] = tmp;

    cnt++;
  }

  // print
  for (int i = 0; i < n - 1; i++) {
    cout << values[i] << " ";
  }
  cout << values[n - 1] << endl;

  cout << cnt << endl;
}

int main() {
  int n;
  deque<int> values;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    values.push_back(tmp);
  }

  selection_sort(values, n);

  return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#define rep(i,rept) for(long long i = 0; i <(long long)rept;i++)
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0,x=0,y=0,z=0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami, mado[50];
	bool gg = true;
	int manji, nk[26] = { false };
	cin >> a>>b;
	x = 1001;
	for(int i=0;i<a;i++){
		cin >> d[i] >> e[i];
		if (e[i] <= b) {
			x = min(d[i],x );
			count++;
		}
	}
	if (count == 0) {
		cout << "TLE" << endl;
	}
	else { cout << x << endl; }
	return 0;
}


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

int main()
{
  ll k; cin >> k;
  ll ans = 0;
  for (int i=1; i<=k; i++) {
    for (int j=1; j<=k; j++) {
      for (int l=1; l<=k; l++) {
        ans += gcd(i, gcd(j, l));
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){
	int K, T;
	cin >> K >> T;
	int a[T];
	for(int i = 0; i < T; i++){
		cin >> a[i];
	}
	int max_a = 0, sum = 0;
	for(int i = 0; i < T; i++){
		sum -= a[i];
		if(max_a < a[i]){
			sum -= max_a * 2;
			max_a = a[i];
			sum += max_a * 2;
		}
	}
    int day = max(sum - 1, 0);
	printf("%d\n", day);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] formula = br.readLine().split(" ");
		
		Deque<String> deq = new ArrayDeque<String>();
		
		for(int i = 0; i < formula.length; i++){
			int tmp1; 
			int tmp2;
			
			switch(formula[i]){
			case "+":
				tmp1 = Integer.parseInt(deq.removeFirst());
				tmp2 = Integer.parseInt(deq.removeFirst());
				
				deq.addFirst(Integer.toString(tmp2 + tmp1));
				break;
				
			case "*":
				tmp1 = Integer.parseInt(deq.removeFirst());
				tmp2 = Integer.parseInt(deq.removeFirst());
				
				deq.addFirst(Integer.toString(tmp2 * tmp1));
				break;
				
			case "-":
				tmp1 = Integer.parseInt(deq.removeFirst());
				tmp2 = Integer.parseInt(deq.removeFirst());
				
				deq.addFirst(Integer.toString(tmp2 - tmp1));
				break;
				
			default:
				deq.addFirst(formula[i]);
				break;
			}
		}
		
		System.out.println(deq.removeLast());
	}

}

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

using namespace std;


int main() {
	string s;
	long long int n, k, c = 1;
	cin >> n >> k;
	while(1) {
		if((n / k) > 0) {
			c++;
			n /= k;
		}
		
		else {
			cout << c << endl;
			break;
		}  
	}

	return 0;
}






Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn],b[maxn];
int n;
int main()
{
	n=read();
	for(int i=1;i<=n+1;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	ll ans=0;
	for(int i=1;i<=n;i++)
		if(b[i]<a[i])ans+=b[i];
		else if(b[i]<a[i]+a[i+1])a[i+1]-=b[i]-a[i],ans+=b[i];
		else ans+=a[i]+a[i+1],a[i]=a[i+1]=0;
	writeln(ans);
	return 0;
}

Measured memory_bytes: 896
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

H, W = list(map(int, input().split()))
grid = []
for i in range(H):
    grid.append(input()[0:W])

num_yoko = [[0 for i in range(W)] for j in range(H)]
num_tate = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            if j == 0:
                num_yoko[i][j] = 1
            else:
                num_yoko[i][j] = num_yoko[i][j - 1] + 1
            if i == 0:
                num_tate[i][j] = 1
            else:
                num_tate[i][j] = num_tate[i - 1][j] + 1
for i in range(H - 1, -1, -1):
    for j in range(W - 1, -1, -1):
        if grid[i][j] == '.':
            if j != W - 1:
                if num_yoko[i][j + 1] != 0:
                    num_yoko[i][j] = num_yoko[i][j + 1]
            if i != H - 1:
                if num_tate[i + 1][j] != 0:
                    num_tate[i][j] = num_tate[i + 1][j]

num_max = 0
for i in range(H):
    for j in range(W):
        if num_yoko[i][j] + num_tate[i][j] > num_max:
            num_max = num_yoko[i][j] + num_tate[i][j]


print(max(0, num_max - 1))



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

int main() {
    int A,B;
    cin >> A >> B;
    int p = A + B;
    int m = A - B;
    int k = A * B;
    int ans;
    ans = max(p,m);
    ans = max(ans,k);
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    int n,a[105],x;
    scanf("%d%d",&n,&x);
    int minn=5000;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        minn=min(minn,a[i]);
        x-=a[i];
    }
    int sum=n;
    sum+=x/minn;
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
a,b,x = map(int,input().split())

import math
if 2*x > b * a**2:
  tan = 2*(b*a**2-x)/a**3
  t = math.atan(tan)
else:
  tan = (a * b**2)/x/2
  t = math.atan(tan)
  
print(math.degrees(t))

Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int sum = 0;
    
    if(N >= 1 && N < 10){
      sum += N;
    } else if (N >= 10){
      sum += 9;
    }
    
    if(N/100 >= 1 && N/100 < 10){
      sum += N - 99;
    } else if (N/100 >= 10){
      sum += 900;
    }
    
    if(N/10000 >= 1 && N/10000 < 10){
      sum += N - 9999;
    } else if (N/10000 == 10){
      sum += 90000;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	map<string,set<int>> mp;
	string s; int d;
	for(int i=0;i<n;i++){
		cin >> s >> d;
		mp[s].insert(d);
	}
	int m; cin >> m;
	int now=0;
	bool ok=1;
	while(m--){
		cin >> s;
		auto it=mp[s].upper_bound(now);
		if(it==mp[s].end())ok=0;
		else{
			now=*it;
		}
	}
	if(ok)printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 23548
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto a=new int[](n);
  foreach(i; 0..n) rd(a[i]);

  int[int] cnt;
  foreach(e; a){
    if(e in cnt) cnt.remove(e);
    else cnt[e]=1;
  }

  writeln(cnt.length);

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

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

int main(){
    int n, k, d, ans = 0;
    cin >> n >> k ;
    vector<int> vec(n, 0);

    for (int i = 0; i < k; i++){
        cin >> d;
        vector<int> sna(d, 0);
        for (int j = 0; j < d; j++) {
            cin >> sna.at(j);
            vec.at(sna.at(j)-1)++;
        }
    }
    for (int i = 0; i < n; i++){
        if (vec.at(i) == 0) ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define int  long long 

using namespace std;
int32_t  main(){
   int n;
   cin>>n;
   int a[100];
   for(int i=0;i<n;++i) cin>>a[i];
   int amt =1000;
    int q;
   for(int day =1 ;day<n;++day){
     if(a[day-1]<a[day]){
        q = amt/a[day-1];
        amt-= q*a[day-1];
        amt+=q*a[day];
     }

   }
   cout<<amt;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  string s;
  cin>>s;
  ll ans=0;
  
  for(int i=1;i<N;i++){
    ll count=0;
    
    for(char c='a';c<='z';c++){
      bool left=false,right=false;
      
      for(int j=0;j<i;j++){
        if(s[j]==c) left=true;
      }
      
      for(int j=i;j<N;j++){
        if(s[j]==c) right=true;
      }
      
      if(left&&right) count++;
    }
    ans=max(ans,count);
  }
  cout<<ans<<endl;
      
}

Measured memory_bytes: 3628
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[][] A = new int[2][N];
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < N; i++){
            A[0][i] = sc.nextInt();
            A[1][i] = sc.nextInt();
            map.put(A[0][i], A[1][i]);
        }
        sc.close();
        Arrays.sort(A[0]);

        System.out.println(A[0][N-1]-A[0][0]+1 + map.get(A[0][N-1])+A[0][0]-1);


   }
}

Measured memory_bytes: 98992
/*
    ALWAYS REMMEMBER:
        NEVER GIVE UP !
        DON'T MESS WITH ME !!!
        "" THE EXPERT IN ANYTHING WAS ONCE A BEGINNER ""
*/

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll n,a,b,d,r;
    cin >> n >> a >> b;

    // if(a==0)
    // {
    //     cout << 0 << endl;
    // }
    // else
    {
        d = n/(a+b);
        r = n%(a+b);

        cout << d*a + min(a,r) << endl;
    }    
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Class25
    {
        static void Main()
        {
            var NW = Console.ReadLine().Split();
            int N = int.Parse(NW[0]);
            int W = int.Parse(NW[1]);

            var DP = new long[W + 1];
            for (int i = 1; i <= W; i++) DP[i] = int.MinValue;
            DP[0] = 0;

            for(int i = 0; i < N; i++)
            {
                var read = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int w = read[0]; int v = read[1];

                for(int j = W-1; j >= 0; j--)
                {
                    if (DP[j] != int.MinValue)
                    {
                        if (j + w <= W)
                        {
                            DP[j + w] = Math.Max(DP[j + w], DP[j] + v);
                        }
                    }
                }
            }
            Console.WriteLine(DP.Max());
        }
    }
}


Measured memory_bytes: 13920
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#include<vector>


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

	int c[n],s,ct;
	if(n==1)c[0]=0;
	if(n>=2){c[0]=1;c[1]=0;}
	if(n>=3)c[2]=0;
	bool f=true;
	rep(i,m){
		cin >> s >> ct; 
		if(s==1){
			if(n==1&&(c[0]!=0&&c[0]!=ct))f=false;
			if(n>=2&&(c[0]!=1&c[0]!=ct))f=false;
                        if(n>=2&&ct==0)f=false;
			else c[0]=ct;
		}
		else{
			if(c[s-1]!=ct && c[s-1]!=0)f=false;
			else c[s-1]=ct;
		}

	}
	if(f)rep(i,n)cout << c[i];
	else cout << -1;


	return 0;
}

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

int main(){
    using namespace std;
    constexpr unsigned long C = 26;
    unsigned long D;
    cin >> D;
    /*vector<unsigned long> c(C);
    for(auto&& i : c)cin >> i;
    vector v(D, vector<unsigned long>(C));
    for(auto&& i : v)for(auto&& j : i)cin >> j;*/
    
    for(unsigned long i{0}; i < D; ++i)cout << 1 + i % C << endl;
    
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

int f[101][101];
int w, h;

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

bool checked[101][101];
bool isFill[101][101];

bool check(int y, int x) {
	checked[y][x] = true;
	if(x==0 || y==0 || x+1==w || y+1==h) return false;
	rep(i, 6) {
		int ny = y + dy[i], nx = x + (y%2 ? dx_odd[i] : dx_even[i]);
		if( !checked[ny][nx] && f[ny][nx] == 0 && !check(ny,nx) ) {
			return false;
		}
	}
	return true;
}

int main() {
	cin >> w >> h;
	rep(y, h) {
		rep(x, w) {
			cin >> f[y][x];
		}
	}
	rep(y, h) {
		rep(x, w) {
			if( !f[y][x] && !checked[y][x] ) {
				memset(checked, 0, sizeof(checked));
				if( check(y,x) ) {
					rep(y, h) {
						rep(x, w) {
							if( checked[y][x] )	isFill[y][x] = true;
						}
					}
				}
			}
		}
	}
	rep(y, h) {
		rep(x, w) {
			if( isFill[y][x] ) f[y][x] = 1;
		}
	}
	ll cnt = 0;
	rep(y, h) {
		rep(x, w) {
			rep(i,6) {
				int ny = y + dy[i];
				int nx = x + (y%2 ? dx_odd[i] : dx_even[i]);
				bool oor = (nx<0 || w<=nx || ny<0 || h<=ny);
				if(f[y][x] && (oor || (!oor && f[ny][nx]==0))) {
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1448
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class Test
{	
    public static void Main()
	{
	    double now = double.Parse(Console.ReadLine());
        double target = double.Parse(Console.ReadLine());
        double ans = target + (target - now);
        Console.WriteLine(ans);        
	}
}

Measured memory_bytes: 11220
'''ベスパリブ  takeg
（gcd(A, B)を素因数分解したときの素因数の個数）+1が答え。
入力例2。「420と660の正の公約数の中から、いくつか約数を選んで、
選んだやつの、どの異なる2つの整数も互いに素となる最大の約数の
個数は何か？」という問題。
420と660の正の公約数は、必ず最大公約数以下の値。
よって約数のとりうる範囲は1 ~ 最大公約数。
420と660 の最大公約数gcd(420, 660)は60。60の約数を列挙。
1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60
このうち、どの2つの整数も互いに素となる約数の個数が最大となる選び方は、
1, 2, 3, 5 の4つ。
60の約数	1	2	3	4	5	6	10	12	15	20	30	60
答え	     1	 2   3		 5							
たとえば15はなぜいけないのでしょうか？それは15を素因数分解すると
15=3^1∗5^1 なので、15を選ぶと3と5が選べなくなってしまいます。 
よって15を選ぶより3と5を選んだほうが多くを選べるということ。
12や20なんかも同様の理由で選べません。
4はどうでしょうか？これは素因数分解すると4=2^2になります。
つまり4を選ぶと2を選べなくなります。この2を選ばないパターンの
1 3 4 5は、どの2つの整数も互いに素となっているのでOKです。
よって2の代わりに4を選ぶのはありですが、選ぶメリットは特にない。
素数しか選ばないというルールのほうが問題を簡単化できます。
ということで入力例2の場合では、gcd(420, 660)で最大公約数を求めて、
その最大公約数を素因数分解したときの素因数を選べば、
どの2つの整数も互いに素となります。あとついでに1も約数なので
これも加えます。これが答えになります。
制約A,B≦10^12を考えます。Nがでかすぎるので、O(N)の解法はTLE。
この問題におけるNとは、AとBの最大公約数gcd(A, B)の値です。
1～gcd(A, B)の範囲で素因数を数えることになります。
gcd(A, B)の最大値は10^12なので、O(N)は無理です。
ですが実は、最大公約数Nが何かの整数pで割り切れるときは、
N=p∗q と書けますので、p≦√N(例：N=10^12 のとき、p=10^6、q=10^6)。
なのでNまで調べる必要はなく、O(√N)で解くことができます。
コーナーケース:最大公約数が1のとき、1を出力して終了
'''
import sys
from fractions import gcd
from collections import Counter

def prime_factorization(n):
    """nを素因数分解する
    Return d(dict):
        素因数をキー、素因数の指数部を値とするディクショナリを返す
    Example:
        n=140 -> d = {2: 2, 5: 1, 7: 1}
    """
    d = Counter()#インスタンス？実態は辞書。
    m = 2
    while m*m <= n:#上記に書いた上限
        while n%m == 0:#nがmで割り切れたら
            n //= m
            d[m] += 1#mで何回、割れたかを記録する
        m = m + 1 if m == 2 else m + 2  
        # m=3からは、m+=2する（偶数は明らかに素数ではないので）

    if n > 1:#sqrt(gcd(A, B)) より大きい素数が1つだけ存在しうる
        d[n] += 1
    return d

def solve():
    A, B = list(map(int, sys.stdin.readline().split()))
    cd = gcd(A, B)

    if cd == 1:  # コーナーケース
        print(1)
        return

    # (素因数分解の素因数の個数)+1が答え
    prime_d = prime_factorization(cd)
    print(len(prime_d)+1)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 5204
#include <iostream>
#include <vector>

using namespace std;

const int INFTY = (1 << 29);

class Edge
{
public:
    int s, t, w;
    Edge(int v = 0, int u = 0, int weight = 0) : s(v), t(u), w(weight) {}

    int get_weight() const { return w; }
};

bool operator<(const Edge &e1, const Edge &e2)
{
    return e1.get_weight() < e2.get_weight();
}

void Belman(vector<Edge> &edges, vector<long long> &cost, int N)
{
    for (int i = 0; i < N; i++)
    {
        for (Edge e : edges)
        {
            if(cost[e.s] == INFTY) continue;
            if (cost[e.t] > cost[e.s] + e.w)
            {
                cost[e.t] = cost[e.s] + e.w;
            }
        }
    }
}

int main()
{
    int N, M, r, s, t, w;
    cin >> N >> M >> r;
    vector<Edge> edges(M);
    vector<long long> cost(N);

    for (int i = 0; i < N; i++)
    {
        cost[i] = INFTY;
    }

    cost[r] = 0;

    for (int i = 0; i < M; i++)
    {
        cin >> s >> t >> w;
        edges[i] = Edge(s, t, w);
    }

    Belman(edges, cost, N);

    bool flag = true;
    for(Edge e : edges){
        if(cost[e.s] == INFTY) continue;
        if(cost[e.s] + e.w < cost[e.t]){
            flag = false;
        }
    }

    if (flag)
    {
        for (int i = 0; i < N; i++)
        {
            if (cost[i] == INFTY)
                cout << "INF";
            else
            {
                cout << cost[i];
            }
            cout << endl;
        }
    }
    else
    {
        cout << "NEGATIVE CYCLE" << endl;
    }
}


Measured memory_bytes: 3108
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

N,M=map(int, input().split())
H=list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(int(M))]

AB_unique=list(map(list, set(map(tuple, AB))))

AB_road=[[] for i in range(N)]
for AB in AB_unique:
    if H[AB[0]-1] > H[AB[1]-1]:
        AB_road[AB[1]-1].append(AB[0])
    elif H[AB[0]-1] < H[AB[1]-1]:
        AB_road[AB[0]-1].append(AB[1])
    else:
        AB_road[AB[1]-1].append(AB[0])
        AB_road[AB[0]-1].append(AB[1])

print(AB_road.count([]))

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

int main(){
    //freopen("2test.txt","r",stdin);
    char test;
    int flaga=0;
    int length=0;
    int ans;
    while(scanf("%c",&test)!=EOF){
        if(test=='A'){
            flaga=1;
            length++;
        }
        else if(test=='Z'&&flaga==1){
            length++;
            ans=length;
        }
        else if(flaga==1){
            length++;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
def D_joisino_travel(N, M, R, r, A):
    """
    N:国の中の町の数
    M:町を結ぶ道の総数
    R:訪れる町の数
    r:訪れる町の番号
    A:町の結び方とその間の距離
    """
    from itertools import permutations
    INF = float('inf')
    # 道の番号-1が要素の番号
    r = [x - 1 for x in r]
    dist = [[INF]*N for j in range(N)]
    for i in range(N):
        dist[i][i] = 0
    for m, n, c in A:
        m-=1
        n-=1
        dist[m][n] = c
        dist[n][m] = c

    # ワーシャルフロイド法(町A→Bの最短距離を求められる)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    permutation_route = permutations(r)
    min_dist = INF
    for i in permutation_route:
        cost = 0
        for j in range(R - 1):  # i(行く町の順列)の先頭から2つ要素を拾う
            cost += dist[i[j]][i[j + 1]]  # コストはワーシャルフロイド法で求めてある
        min_dist = min(min_dist, cost)
    return min_dist
  
N,M,R = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for i in range(M)]
print(D_joisino_travel(N, M, R, r, A))

Measured memory_bytes: 59736
n = int(input())
node = [[] for i in range(n)]

for i in range(n - 1):
    a, b = map(int,input().split())
    node[a-1].append(b-1)
    node[b-1].append(a-1)

def dfs(v):
    dis = [10 ** 10] * n
    dis[v] = 0
    q = []
    q.append(v)

    while q:
        u = q.pop()
        for i in node[u]:
            if dis[i] > dis[u] + 1:
                dis[i] = dis[u] + 1
                q.append(i)

    return dis

d1 = dfs(0)
d2 = dfs(n - 1)

c = 0
for i in range(1, n - 1):
    if d1[i] <= d2[i]:
        c += 1

if c > (n - 2) // 2:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 59680
#include <iostream>
using namespace std;
int main(void){
int n,a,b,c;

cin >> n;

a=n/100;
b=(n-a*100)/10;
c=n-a*100-b*10;
if (a==9) a=1;
else if (a==1) a=9;
if (b==9) b=1;
else if (b==1) b=9;
if (c==9) c=1;
else if (c==1) c=9;

cout << a << b << c <<endl;


}



Measured memory_bytes: 256