akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n;
	cin >> n;
	if (n < 1200)
		cout << "ABC" << endl;
	else
		cout << "ARC" << endl;

	return 0;
}

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

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

    map<ll, ll> mp;
    sort(B.begin(), B.end());

    ll cnt = 1;
    for (int i = 1; i < N; i++) {
        if (B[i] == B[i - 1])
            cnt++;
        else {
            mp[B[i - 1]] = cnt;
            cnt = 1;
        }
    }
    mp[B[B.size() - 1]] = cnt;

    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        ans += itr->second * (itr->second - 1) / 2;
    }

    rep(i, N) {
        ll sa = mp[A[i]] - 1;
        cout << ans - sa << "\n";
    }

    return 0;
}

Measured memory_bytes: 11136
n, l = map(int, input().split())
tastes = [l+i-1 for i in range(1, n+1)]
mintaste = 1000000
index = 0
for i in range(n):
    if abs(tastes[i]) < mintaste:
        mintaste = abs(tastes[i])
        index = i
tastes[index] = 0
print(sum(tastes))

Measured memory_bytes: 3064
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse = True)
    ans = A[0]
    q, r = divmod(n - 2, 2)
    for a in A[1:1 + q]:
        ans += 2 * a
    if r == 1:
        ans += A[q + 1]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31348
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = [int(x) for x in input().split()]
    for i in range(n + 1):
        if not x - i in p:
            print(x - i)
            break
        elif not x + i in p:
            print(x + i)
            break
        else:
            continue


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

int main() {
  string c;
  cin >> c;
 
  if (c== "a"|| c == "e"||c == "i"||c == "o"||c == "u"){
      cout << "vowel" << endl;
    }
   else{
  cout << "consonant" << endl;
   }
}


Measured memory_bytes: 256
n = gets.to_i
ts = n.times.map { gets.to_i }
ans = ts.inject(1) do |lcm, t|
  x = lcm * t
  b, a = [lcm, t].minmax
  r = a % b
  while r != 0
    a = b
    b = r
    r = a % b
  end
  x / b
end

puts ans

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

int main(){
	int input1,input2;
	int tmp;
	while (1){
		cin >> input1 >> input2;
		if (input1 == 0 && input2 == 0)
			break;
		if (input1 > input2){
			tmp = input1;
			input1 = input2;
			input2 = tmp;
		}
		cout << input1 << " " << input2 << endl;
	}
}

Measured memory_bytes: 3032
#include<iostream>
using namespace std;
int main()
{
    int countt=0,countt2=0,countt3=0,countt4=0;
    char ch[4];
    cin>>ch;
    for(int i=0;i<=3;i++)
    {
        if(ch[0]==ch[i]) countt++;
        if(ch[1]==ch[i]) countt2++;
        if(ch[2]==ch[i]) countt3++;
        if(ch[3]==ch[i]) countt4++;
    }
    if(countt==2 && countt2==2 && countt3==2 && countt4==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

bool ok(const vecint& a, const int th, vecint& v) {
  ll n = a.size();
  v.assign(n*3, 0);
  int offset = n*1.5;
  ll cnt = 0;
  ll sum = 0;
  REP(i,n) {
    v[offset] += 1;
    if (a[i] >= th) {
      offset -= 1;
      sum -= v[offset];
    } else {
      sum += v[offset];
      offset += 1;
    }
    cnt += sum;
  }
  ll m = n * (n+1) / 2;
  ll mid = m/2 + 1;
  return cnt >= mid;
}

int main()
{
  int n;
  scanf("%d", &n);
  vecint a(n);
  string line;
  getline(cin, line);
  getline(cin, line);
  int i = 0;
  int num = 0;
  for (char c : line) {
    if (isdigit(c)) {
      num *= 10;
      num += c - '0';
    } else {
      a[i] = num;
      ++i;
      num = 0;
    }
  }
  a[i] = num;
  vecint b = a;
  b.push_back(0);
  b.push_back(1000000007);
  sort(ALL(b));
  b.erase(unique(ALL(b)), end(b));
  int hi = b.size() - 1;
  int lo = 0;
  vecint v(n*4);
  while ((hi - lo) > 1) {
    int mid = (hi + lo) / 2;
    if (ok(a, b[mid], v)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  printf("%d\n", b[lo]);
  return 0;
}


Measured memory_bytes: 4100
def paint(bd)
  pl = bd.map{|bl| bl.map{0}}

  max_y = bd.length - 1
  max_x = bd[0].length - 1
  num = 0

  for y in (0..max_y)
    for x in (0..max_x)
      next if ! bd[y][x] || pl[y][x] > 0

      num += 1
      pl[y][x] = num
      queue = [[x, y]]

      while queue.length > 0
        x0, y0 = queue.shift

        if x0 > 0 && bd[y0][x0 - 1] && pl[y0][x0 - 1] == 0
          pl[y0][x0 - 1] = num
          queue.push [x0 - 1, y0]
        end
        if x0 < max_x && bd[y0][x0 + 1] && pl[y0][x0 + 1] == 0
          pl[y0][x0 + 1] = num
          queue.push [x0 + 1, y0]
        end
        if y0 > 0 && bd[y0 - 1][x0] && pl[y0 - 1][x0] == 0
          pl[y0 - 1][x0] = num
          queue.push [x0, y0 - 1]
        end
        if y0 < max_y && bd[y0 + 1][x0] && pl[y0 + 1][x0] == 0
          pl[y0 + 1][x0] = num
          queue.push [x0, y0 + 1]
        end
      end
    end
  end

  return num
end

### main

cont = true

while cont
  bd = []

  while true
    line = gets
    if line.nil?
      cont = false
      break
    end

    line = line.chomp
    break if line == ""

    bd.push line.split("").map{|s| s == '1'}
  end

  puts paint(bd)
end

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

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

	int A,B;
	int i,j;
	int tmp;
	int answer;
	int counter=0;
	double ave;
	vector<int> given;

	cin >> A >> B;

	answer=A*B;
	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}

int main(void){
	int n,k,ans=0;
	scanf("%d%d",&n,&k);
	int l[n];
	for(int i=0;i<n;i++)scanf("%d",&l[i]);
	qsort(l,n, sizeof(int), compare_int);
	for(int i=0;i<k;i++)ans+=l[n-1-i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
from sys import stdin


def main():
    N, Q = map(int, input().split())
    S = input()
    LR = [int(x) - 1 for x in stdin.read().split()]
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()


Measured memory_bytes: 24800
import sys

input = sys.stdin.readline
n = int(input())
s_list = []
xa_num = 0
bx_num = 0
ba_num = 0
cnt = 0
for _ in range(n):
    s_in = input()[:-1]
    if s_in[0] == 'B':
        if s_in[-1] == 'A':
            ba_num += 1
        else:
            bx_num += 1
    elif s_in[-1] == 'A':
        xa_num += 1
    flag = 0
    for s in s_in:
        if s == 'A':
            flag = 1
        elif s == 'B':
            if flag == 1:
                cnt += 1
            flag = 0
        else:
            flag = 0

if ba_num == 0:
    print(cnt+min(xa_num, bx_num))
elif xa_num + bx_num == 0:
    print(cnt+ba_num-1)
else:
    print(cnt+ba_num+min(xa_num, bx_num))


Measured memory_bytes: 3064
#AGC031A
N=int(input())
S=input()
c={}
for s in S:
    c[s]=c.get(s,0)+1
ans=0
for s in S:
    c[s]-=1
    t=1
    for k in c.keys():
        if c[k]>0 and k!=s:
            t*=c[k]+1
    ans+=t
print(ans%(10**9+7))

Measured memory_bytes: 3188
n = gets.to_i
i = 0
re = 0
hash = {}
while i < n do 
  ss = gets.chomp.chars.sort.join
  if hash.key?(ss) 
    re += hash[ss]
    hash[ss] += 1
  else
    hash[ss] = 1
  end
  i += 1
end
p re

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

int n, m, x[2000], a[101];

int main(){
    cin >> n;
    for (int i = 0; i < n; i++)cin >> x[i];
    cin >> m;
    for (int i = 0; i < m; i++){
        cin >> a[i];
        a[i]--;
        if (a[i] + 1 == n)x[a[i]] = min(x[a[i]] + 1, 2019);
        else if (x[a[i]] + 1 < x[a[i] + 1])x[a[i]]++;
    }
    for (int i = 0; i < n; i++)cout << x[i] << endl;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int x1, y1;
    cin >> x1 >> y1;
    int x2, y2;
    cin >> x2 >> y2;
    int d1 = y2 - y1;
    int d2 = x2 - x1;
    int x3 = x2 - d1;
    int y3 = y2 + d2;
    int x4 = x3 - d2;
    int y4 = y3 - d1;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
long long int a[200005];
int main()
{
	long long int n,sum1=0,sum2=0,i,min=0,j,sum=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		min+=fabs(a[i]);
		sum+=a[i];			
	}	
	for(i=n-1;i>0;i--)
	{
		sum1+=a[i];
		if(fabs(2*sum1-sum)<min)
		{min=fabs(2*sum1-sum);}	
	}
	printf("%lld\n",min);
}

Measured memory_bytes: 1664
using System;
using System.Text;

namespace ITP1_6_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var suit = new string[] { "S", "H", "C", "D" };
            var memo = new bool[4, 14];

            var n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                var num = int.Parse(input[1]);
                switch (input[0])
                {
                    case "S":
                        memo[0, num] = true;
                        break;
                    case "H":
                        memo[1, num] = true;
                        break;
                    case "C":
                        memo[2, num] = true;
                        break;
                    case "D":
                        memo[3, num] = true;
                        break;
                }
            }

            var sb = new StringBuilder();
            for(int i = 0; i < 4; i++)
            {
                for(int j = 1; j < 14; j++)
                {
                    if (!memo[i, j])
                        sb.AppendLine(string.Format("{0} {1}", suit[i], j));
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9232
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LaL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  ll A,B,C,K;
  cin>>A>>B>>C>>K;
  
  if(A>=K) cout<<K<<endl;
  else if(A+B>=K) cout<<A<<endl;
  else cout<<A-(K-A-B)<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))//数组(结构体)清零 
#define ll long long
int A(int a,int b){if(a<b||a<1||b<0)return 0;int k=1;while(b--){k*=a--;}return k;}//数学中的Aab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
int C(int a,int b){if(a<b||a<1||b<0)return 0;b=min(a-b,b);int k=A(a,b),t=1;while(--b)k/=++t;return k;}//数学中的Cab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
int HW(char*HWa,int HWl,int HWr){if(HWr<HWl)swap(HWl,HWr);for(int i=0;i<(HWr-HWl)/2+1;i++)if(HWa[HWl+i]!=HWa[HWr-i])return 0;return 1;}//传递字符串名,判断区间l r,如果是回文字符串就返回1,否则返回0 
int SS(int a){if(a>4&&((a-1)%6)&&((a+1)%6))return 0;for(int i=2;i<=sqrt(a);i++)if(a%i==0)return 0;return 1;}//判断一个数是不是质数，是1 否0；请确保a>1; 
/*记得如果改int为long long,就把printf与scanf中相应的%d也改成%lld*/
int main()
{
	char c[10];
	cin>>c;
	if(c[2]==c[3]&&c[4]==c[5])cout<<"Yes";
	else cout<<"No" ;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll powerwithoutmod(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c);
    if (b&1) return (c*a);
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e5+5;
const int Q = 301;
const int logN = 18;

int a[] = {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};
void solve() {
    int k;
    cin>>k;
    cout<<a[k-1];
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

int f(int a, int d) {
    return Floor(a, d);
}

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

    int L, R, d;
    cin >> L >> R >> d;

    cout << f(R, d) - f(L - 1, d) << endl;

    return 0;
}

Measured memory_bytes: 3608
import sys
from io import StringIO
import unittest


def resolve():
    s = input()

    if s == 'ABC':
        print('ARC')
    else:
        print('ABC')

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """ABC"""
        output = """ARC"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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

int main() {
  int N;
  cin >> N;
  string op;
  bool ans = false;
  for (int i = 1; i <= N; i++) {
  cin >> op;   
  if (op == "Y") {
     ans = true;
  }  
}    
  if (ans) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

using Graph = vector<vector<int>>;
vector<int> color;

bool dfs(const Graph& G, int v, int cur = 0) {
	color[v] = cur;
	for (auto next_v : G[v]) {
		// 隣接頂点がすでに色確定していた場合
		if (color[next_v] != -1) {
			if (color[next_v] == cur) return false; // 同じ色が隣接したらダメ
			continue;
		}

		// 隣接頂点の色を変えて、再帰的に探索 (一回でも false が返ってきたら false)
		if (!dfs(G, next_v, 1 - cur)) return false;
	}
	return true;
}

signed main() {

	int N;
	cin >> N;
	vector<string> S(N);
	rep(i, N) cin >> S[i];

	Graph 	G(N);

	rep(i, N)rep(j, N) {
		if (S[i][j] == '1') {
			G[i].push_back(j);
			G[j].push_back(i);
		}
	}

	// 探索
	color.assign(N, -1);
	bool is_bipartite = true;
	for (int v = 0; v < N; ++v) {
		if (color[v] != -1) continue; // v が探索済みだったらスルー
		if (!dfs(G, v)) is_bipartite = false;
	}

	if (!is_bipartite) {
		// 二部グラフでない
		cout << -1 << endl;
	}
	else {
		// 二部グラフ
		// 直径を求める
		int d[210][210];	// INFで初期化しておく
		rep(i, N)rep(j, N) {
			d[i][j] = INF;
			if (S[i][j] == '1') d[i][j] = 1;
		}
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				if (d[i][k] == INF) continue;
				for (int j = 0; j < N; j++) {
					if (d[k][j] == INF) continue;
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		int longest = -1;
		rep(i, N) rep(j, N) {
			if (i == j) continue;
			longest = max(longest, d[i][j]);
		}
		cout << longest+1 << endl;
	}

	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}


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

    ll offset = 0;
    rep(i, n) offset = a[i] - offset;

    ll x = offset / 2;

    ll cur = x;
    rep(i, n) {
        cout << cur << " ";
        cur = a[i] - cur;
    }

    cout << endl;
}

Measured memory_bytes: 2048
#include <stdio.h>
#include <stdlib.h>

int main(){
  int x, a, b;
  scanf("%d%d%d", &x, &a, &b);
  if(abs(x - a) < abs(x - b)){
    printf("A\n");
  }else if(abs(x - a) > abs(x - b)){
    printf("B\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

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

    int ans = 0;

    rep(i, n - 1){
        string x = s.substr(0, i + 1);
        string y = s.substr(i + 1, n - i - 1);


        int c[2][26] = {};

        rep(j,x.size()){
            c[0][x[j] - 'a']++;
        }

        rep(j,y.size()){
            c[1][y[j] - 'a']++;
        }

        int tmpans = 0;

        rep(j, 26){
            if(c[0][j] > 0 && c[1][j] > 0) tmpans++;
        }

        ans = max(ans,tmpans);
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int k,l,i,r;
  scanf("%d",&k);

  if(k % 7 == 0){
    l = 9 * k / 7;
  }else{
    l = 9 * k;
  }

  if(l % 2 == 0 || l % 5 == 0){
    printf("-1\n");
  }else{
    r = 10 % l;
    for(i=1;;i++){
      if(r==1){
        printf("%d\n",i);
        break;
      }
      r = (10 * r) % l;
    }
  }

  return 0;
}

Measured memory_bytes: 1724
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

int32_t main()
{
    IOS
    
    
    
   
    string s1;
    cin>>s1;
    int n=s1.length();
    
    int fl[n+1];
    memset(fl,-1,sizeof(fl));
    for(int i=0;i<n;++i)
    {
        if(s1[i]=='R')
        {
            int temp=i;
            int index;
            for(int j=i+1;j<n;++j)
            {
                if(s1[j]=='L')
                {
                    index=j;
                    i=j;
                    break;
                }
            }
            for(int j=temp;j<i;++j)
                fl[j]=index;
        }

    }
    int fr[n+1];
    memset(fr,-1,sizeof(fr));
    for(int i=n-1;i>=0;--i)
    {
        if(s1[i]=='L')
        {
            int temp=i;
            int index;
            for(int j=i-1;j>=0;--j)
            {
                if(s1[j]=='R')
                {
                    i=j;
                    index=j;
                    break;
                }
            }
            for(int j=temp;j>i;--j)
                fr[j]=index;
        }
    }
    int ans[n+1];
    memset(ans,0,sizeof(ans));
    for(int i=0;i<n;++i)
    {
        if(s1[i]=='R')
        {
            int temp=fl[i]-i;
            if(temp%2==0)
            {
                ans[fl[i]]++;
            }
            else
                ans[fl[i]-1]++;

        }
        if(s1[i]=='L')
        {
            int temp=i-fr[i];
            if(temp%2==0)
                ans[fr[i]]++;
            else
            {
                ans[fr[i]+1]++;
            }
        }
    }
    for(int i=0;i<n;++i)
        cout<<ans[i]<<" ";
    // for(int i=0;i<n;++i)
    //     cout<<fl[i]<<" ";
    // cout<<endl;
    // for(int i=0;i<n;++i)
    //     cout<<fr[i]<<" ";
    




}



Measured memory_bytes: 3024
import java.util.*;
 
public class Main {
	
	public static final int A = 0;
	public static final int B = 1;
	
    public static void main( String args[] ) {
        Scanner scan = new Scanner( System.in );
		
		double a = scan.nextDouble();
		double b = scan.nextDouble();
		double C = scan.nextDouble();
		
		// S
		double S = a * b * Math.sin( Math.toRadians( C ) ) / 2;
		
		// L
		double L = a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos( Math.toRadians( C ) ) );
		
		// h
		double h = b * Math.sin( Math.toRadians( C ) );
		
		System.out.print(S + "\n" + L + "\n" + h + "\n");
		
	}
	
}

Measured memory_bytes: 18200
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let k = scan "%d" id
let s = scan "%s" id

let () =
  if String.length s <= k then Printf.printf "%s\n" s
  else Printf.printf "%s...\n" @@ String.sub s 0 k


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

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5])
        cout << "Yes";
    else
        cout << "No";
}


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

using namespace std;

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> house(n);
  for (int i=0; i<n; i++) {
    cin >> house.at(i);
  }
  
  int maxi = house.at(0) + k - house.at(n-1);
  for (int i=1; i<n; i++) {
    maxi = max(maxi, house.at(i) - house.at(i-1));
  }
  
  cout << k - maxi << endl;
  return 0;
}


Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
mod = 10**9+7

n, k = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
s = 0
t = 0
for a in A:
  if a < 0:
    B.append(-a)
    s += 1
  elif a > 0:
    C.append(a)
    t += 1
if s + t < k:
  print(0)
  exit()
if s + t == k:
  if k == n:
    ans = 1
    for a in A:
      ans *= a
      ans %= mod
    print(ans)
  else:
    if s%2:
      print(0)
    else:
      ans = 1
      for b in B:
        ans *= b
        ans %= mod
      for c in C:
        ans *= c
        ans %= mod
      print(ans)
  exit()
B.sort(reverse=True)
C.sort(reverse=True)
ans = 1
nb = 0
nc = 0
if t == 0:
  if k%2:
    if s == n:
      for b in B[-k:]:
        ans *= b
        ans %= mod
      ans *= -1
      ans %= mod
      print(ans)
    else:
      print(0)
  else:
    for b in B[:k]:
      ans *= b
      ans %= mod
    ans %= mod
    print(ans)
  exit()
for _ in range(k):
  if nb >= s:
    ans *= C[nc]
    ans %= mod
    nc += 1
  elif nc >= t:
    ans *= B[nb]
    ans %= mod
    nb += 1
  else:
    if B[nb] > C[nc]:
      ans *= B[nb]
      ans %= mod
      nb += 1
    else:
      ans *= C[nc]
      ans %= mod
      nc += 1
if nb%2:
  if nb == s:
    ans *= pow(B[-1], mod-2, mod)
    ans %= mod
    ans *= C[nc]
    ans %= mod
    print(ans)
  elif nc == t:
    ans *= B[nb]
    ans %= mod
    ans *= pow(C[-1], mod-2, mod)
    ans %= mod
    print(ans)
  else:
    if nc == 0:
      ans *= pow(B[nb-1], mod-2, mod)
      ans %= mod
      ans *= C[0]
      ans %= mod
      print(ans)
    else:
      if C[nc-1]*C[nc] >= B[nb-1]*B[nb]:
        ans *= pow(B[nb-1], mod-2, mod)
        ans %= mod
        ans *= C[nc]
        ans %= mod
        print(ans)
      else:
        ans *= pow(C[nc-1], mod-2, mod)
        ans %= mod
        ans *= B[nb]
        ans %= mod
        print(ans)
else:
  print(ans)

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

using ll = long long;

int main() {
    int q; cin >> q;
    while(q--) {
        ll a, b; cin >> a >> b;
        if(a > b) swap(a, b);
        if(a == b || a + 1 == b) {
            cout << 2 * a - 2 << endl;
        } else {
            ll c = sqrt(a * b);
            if(c * c == a * b) c--;
            if(c * (c + 1) >= a * b) {
                cout << 2 * c - 2 << endl;
            } else {
                cout << 2 * c - 1 << endl;
            }
        }
    }
}


Measured memory_bytes: 256
n,m=map(int,input().split())
pe=[-1 for i in range(n)]#ぺな
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=='WA' and pe[p-1] < 0:
        pe[p-1] -= 1
    elif s =='AC' and pe[p-1] < 0:
        pe[p-1] = abs(pe[p-1])
#print(pe)
print('{} {}'.format(len([i for i in pe if i > 0]),sum([i-1 for i in pe if i > 0])))

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

using namespace std;

pair<int, int> A[100000];
int ans[100001];

int main(){
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i].first;
		A[i].second = i + 1;
	}
	sort(A, A + N);
	for (int i = 0; i < N; i++) {
		cout << A[i].second << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1664
src = input()
length = len(src)
acgt = set("ACGT")
ans = 0
for i in range(length):
    n = length - i
    for ngram in [src[k:k+n] for k in range(length - n + 1)]:
        subtract = len(set(ngram) - acgt)
        if subtract == 0:
            ans = n
            break
    if ans != 0:
        break
print(ans)

Measured memory_bytes: 3060
/******
author :- Mahmoud Tarek.
*******/

#include<bits/stdc++.h>

using namespace std ;

#define rg register
#define dbg(v) cerr << #v << " " << v ;
typedef long long ll ;

int n;
struct doW{
int w[5] ;
};

vector<doW> a ;
int mem[100002][6] ;

int solve(int i, int ch){
if(i == n) return 0 ;
int & ret = mem[i][ch] ;
if(~ret) return ret ;
ret = 0 ;
for(int j = 2 ; j <= 4 ; j++){
    if(ch != j){
        ret = max(ret, a[i].w[j] + solve(i + 1, j)) ;
    }
}
return ret ;
}

int main() {
//  freopen("in.txt", "r", stdin) ;
    cin >> n ;
    a.resize(n) ;
    memset(mem, -1, sizeof mem) ;
    for(int i = 0 ; i < n ; i++){
        for(int j = 2 ; j <= 4 ; j++) cin >> a[i].w[j] ;
    }
    cout << solve(0, 1) ;

}

/*
  Empty set of troubles.
*/


Measured memory_bytes: 12288
#include<stdio.h>

int main(void)
{
  int num, i;
  int x[100];

  scanf("%d", &num);

  for(i=1;i<=num;i++)
    {
      scanf("%d", &x[i]);
    }

  for(i=num;i>1;i--)
    {
      printf("%d ", x[i]);
    }
  printf("%d\n", x[i]);

  return 0;
}

Measured memory_bytes: 596
import sys

for i in sys.stdin:
    i=int(i)
    count =0
    for a in range(9,-1,-1):
        k=i-a
        if(k==0):
            count+=1            
        if(k>0):
            for b in range(9,-1,-1):
                l=k-b
                if(l==0):
                    count+=1
                if(l>0):
                    for c in range(9,-1,-1):
                        m=l-c
                        if(m==0):
                            count+=1                            
                        if(m>0):
                            for d in range(9,-1,-1):
                                if(m-d==0):
                                    count+=1
                            
    print count

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

using namespace std;

int main(){
 	int A, B, C, D; cin >> A >> B >> C >> D;
  while(A>0&&C>0){
    C-=B;
    if(C<=0)
      break;
    A-=D;  
  }
  if(A<=0)
    cout << "No";
  else
    cout << "Yes";  
}

Measured memory_bytes: 3596
char buf[1800000],out[900000],f[5];
sz,osz;
rd(){
	int k,x=0;
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		x=x*10+k-'0';
	}
	return x;
}
N,M,L,Q;
D[301][301];
i,j,k;
a,b,c;
main()
{
	read(0,buf,1800000);
	N=rd();M=rd();L=rd();
	for(i=0;i<N;i++)for(j=0;j<N;j++)D[i][j]=1000000001;
	for(i=0;i<M;i++)
	{
		a=rd();b=rd();c=rd();
		--a;
		--b;
		D[a][b]=D[b][a]=c;
	}
	for(k=0;k<N;k++)for(i=0;i<N;i++)for(j=0;j<N;j++)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	for(i=0;i<N;i++)for(j=0;j<N;j++)D[i][j]=D[i][j]>L?1000000000:1;
	for(k=0;k<N;k++)for(i=0;i<N;i++)for(j=0;j<N;j++)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	Q=rd();
	for(i=0;i<Q;i++)
	{
		a=rd();b=rd();
		--a;
		--b;
		if(D[a][b]<1000000000)
		{
			c=D[a][b]-1;
			k=0;
			do{
				f[k++]=c%10+'0';
				c/=10;
			}while(c);
			for(;k--;)out[osz++]=f[k];
		}
		else out[osz++]='-',out[osz++]='1';
		out[osz++]='\n';
	}
	write(1,out,osz);
}

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

def num2alpha(n):
    if n <= 26:
        return chr(64 + n)
    elif n % 26 == 0:
        return num2alpha(n // 26 - 1) + chr(90)
    else:
        return num2alpha(n // 26) + chr(64 + n % 26)

def main():
    N = int(readline())
    print(num2alpha(N).lower())

if __name__ == '__main__':
    main()

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/


P dat[1000000];
int size_ = 1;
void init(int x) {
	while (size_ < x)size_ *= 2;
	rep(i, 2 * size_ - 1)dat[i] = { ((int)(1) << 31) - 1,inf };
}
void eval(int k, int l, int r) {
	if (dat[k].second != inf) {
		dat[k].first = dat[k].second;
		if (r - l > 1) {
			dat[k * 2 + 1].second = dat[k].second;
			dat[k * 2 + 2].second = dat[k].second;
		}
		dat[k].second = inf;
	}
}
void update(int a, int b, int k, int x, int l, int r) {
	eval(k, l, r);
	if (r <= a || b <= l)return;
	if (a <= l && r <= b) {
		dat[k].second = x;
		eval(k, l, r);
	}
	else {
		update(a, b, k * 2 + 1, x, l, (l + r) / 2);
		update(a, b, k * 2 + 2, x, (l + r) / 2, r);
		dat[k].first = min(dat[k * 2 + 1].first, dat[k * 2 + 2].first);
	}
}
int query(int a, int b, int k, int l, int r) {
	eval(k, l, r);
	if (r <= a || b <= l)return inf;
	if (a <= l && r <= b) {
		return dat[k].first;
	}
	int lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
	int rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
	return min(lv, rv);
}
signed main() {
	int n, q;
	cin >> n >> q;
	init(n);
	rep(i, q) {
		int a; cin >> a;
		if (!a) {
			int s, t, x; cin >> s >> t >> x;
			update(s, t + 1, 0, x, 0, size_);
		}
		else {
			int s, t; cin >> s >> t;
			cout << query(s, t + 1, 0, 0, size_) << endl;
		}
	}
}


Measured memory_bytes: 7220
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

template <typename T>
void warshall_floyd(vector<vector<T>>& d) {
	int n = d.size();
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {
	const Int INF = 1e18;
	int N, M; Int L;
	cin >> N >> M >> L;
	vector<vector<Int>> d(N, vector<Int>(N, INF));
	for (int i = 0; i < M; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		d[a][b] = c;
		d[b][a] = c;
	}
	int Q;
	cin >> Q;
	vector<int> s(Q), t(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> s[i] >> t[i];
	}

	for (int i = 0; i < N; ++i) { d[i][i] = 0; }
	warshall_floyd(d);

	vector<vector<Int>> d2(N, vector<Int>(N, INF));
	for (int i = 0; i < N; ++i) {
		d2[i][i] = 0;
		for (int j = 0; j < N; ++j) {
			if (d[i][j] <= L) { d2[i][j] = 1; }
		}
	}
	warshall_floyd(d2);

	for (int i = 0; i < Q; ++i) {
		Int tmp = d2[s[i] - 1][t[i] - 1];
		cout << (tmp == INF ? -1 : tmp - 1) << endl;
	}

	return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

int a[105];

int main() {
	int n;
  	cin >>n;
  	for (int i=0 ; i<n ; i++) {
    	cin >>a[i];  
    }
    int minn = 1e9;
    for (int i=-200 ; i<=200 ; i++) {
    	int br = 0;
    	for (int j=0 ; j<n ; j++) {
    		br += (a[j]-i)*(a[j]-i);
    	}
    	minn = min(minn, br);
    }
    cout <<minn<<endl;
	return 0;
}

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

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

    deque<int> ans;
    vector<bool> div;
    int m = 1;

    while (N) {
        if (N % 2) {
            div.push_back(1);
            N /= 2;
        } else {
            div.push_back(0);
            N--;
        }
    }

    for (int i = div.size() - 1; i >= 0; --i) {
        if (div[i])
            ans.push_back(m);
        else
            ans.push_front(m);
        m++;
    }

    rep(i, m - 1) ans.push_back(i + 1);

    cout << ans.size() << endl;
    rep(i, ans.size()) {
        if (i != 0)
            cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

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

int main() {
    long long n, ng = 0, ok;
    long long a, b, h[100000], c;
    cin >> n >> a >> b;
    c = a - b;
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    ok = 1e9+1;
    while(ng + 1 < ok){
        long long mid = (ng + ok) / 2, d = 0;
        for(int i=0;i<n;i++){
            long long r = h[i] - b * mid;
            if(r > 0){
                d += (r + c - 1)/c;
            }
        }
        if(d<=mid){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <complex>
#include <ctime>
#include <cassert>
#include <functional>
#include <list>
#include <bitset>
#include <cfenv>
#include <numeric>
#include <utility>
#include <cstdio>
#include <fstream>
#include <deque>
#include <limits>
#include <climits>
using namespace std;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(false);

    long long n;

    cin >> n;

    for(int i = n - 1; i > 1; i--) {
        n *= i;
    }

    cout << n << endl;

    return 0;
}

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

int main() {
  int a, s1, s2, s3;
  
  cin >> a;
  
  s1 = a / 100;
  s2 = (a - s1 * 100) / 10;
  s3 = a - s1 * 100 - s2 * 10;
  
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include <deque>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

int gcd(int a, int b)
{
	if (b == 0)return a;
	else return gcd(b, a%b);
}

int main()
{
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	int ans = a[0];
	for (int i = 0; i < n; i++)
		ans = gcd(ans, a[i]);
	cout << ans;
	
}	
		

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

int main()
{
  int K;
  cin >> K;
  
  if(K % 2 == 0)
    cout << pow((K / 2), 2.0) << endl;
  else
    cout << pow((K / 2), 2.0) + (K / 2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int mo=998244353;
map<string,int> mp;
int F(string s){
	int l=s.length();
	if (!l) return 1;
	if (l==1) return s[0]-'0'+1;
	if (mp.find(s)!=mp.end()) return mp[s];
	int ans=0;
	string su="",nx;
	Rep(i,l-1,1){
		For(j,1,i)
			if ((i+1)%j==0){
				nx="";
				For(k,0,j-1) nx=nx+"1";
				For(k,0,i) if (s[k]=='0') nx[k%j]='0';
				ans=(ans+1ll*F(su)*F(nx))%mo;
			}
		su=s[i]+su;
	}
	ans=(ans+1ll*(s[0]-'0'+1)*F(su))%mo;
	return mp[s]=ans;
}
int main(){
	string s;
	cin>>s;
	cout<<F(s)<<endl;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;

bool greater_pair(const pair<long long, long long>& r, const pair<long long, long long>& l) {
  return r.second > l.second;
}

int main()
{
  int N, M;
  cin >> N >> M;
  vector<long long> A(N,0);
  vector<pair<long long, long long>> B;
  for (int i=0;i<N;i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  for (int i=0;i<M;i++) {
    int b, c;
    cin >> b >> c;
    B.push_back(make_pair(b, c));
  }
  sort(B.begin(), B.end(), greater_pair);
  int index = 0;
  for (auto& p : B) {
    for (;index < A.size() && p.first > 0; index++) {
      if (A[index] < p.second) {
        A[index] = p.second;
      } else {
        break;
      }
      p.first--;
    }
  }
  long long ans = 0;
  for (auto& v : A) {
    ans += v;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3188
#include <stdio.h>
#include <bits/stdc++.h>
void swap(int *a, int *b) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b =tmp;
}

int check(int n, int m, int T[], int H[]) {
  int T_sum = 0;
  int H_sum = 0;

  for (int i = 0; i < n; i++) {
    T_sum += T[i];
  }
  for (int i = 0; i < m; i++) {
    H_sum += H[i];
  }
  if (H_sum == T_sum) {
    return 0;
  }
  else {
    return -1;
  }
}

int main(void) {
  while(1) {
    int flag;
    int n,m;
    int T[1000] = {0}, H[1000] = {0};
    int i, j;
    scanf("%d%d", &n, &m);
    if (n == m && n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      scanf("%d", &T[i]);
    }
    for (j = 0; j < m; j++) {
      scanf("%d", &H[j]);
    }
    
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        swap(&T[i], &H[j]);
        flag = check(n, m, T, H);
        if (flag == 0) {
          goto L1;
        }
        swap(&T[i], &H[j]);
      }
    }
  L1:
    if (flag == 0) {
      printf("%d %d\n",H[j], T[i]);
    }
    else {
      printf("-1\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s[s.size() - 1] != 's') {
    cout << s << 's' << endl;
  } else {
    cout << s << "es" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<utility>
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int gx[8] = {1,1,0,-1,-1,-1,0,1};
int gy[8] = {0,1,1,1,0,-1,-1,-1};
#define REP(i,n) for(int i=0;i<(n);i++)

using namespace std;

int nextInt(){int a;cin>>a;return a;}

int main(){
  int w,h,ct;
  
  queue<pair<int,int>> que;
  while(cin>>h>>w){
    if(!h&&!w)break;
    vector<vector<int>> d(w,vector<int>(h,-1));
    REP(i,w){
      REP(j,h){
	d[i][j] = nextInt();
      }
    }
    ct = 0;
    REP(i,w){
      REP(j,h){
	int def_i = i;
	int def_j = j;
	if(d[def_i][def_j] !=1)continue;
	else ct++;
	  que.push(make_pair(def_i,def_j));
	  while(que.size()){
	    pair<int,int> p = que.front();
	    que.pop();
	    REP(k,8){
	      def_i = gy[k] + p.first;def_j = gx[k] + p.second;
	      if(def_i>=0 && def_i<w && def_j>=0 && def_j<h){
		if(d[def_i][def_j] !=1)continue;
		else {
		  d[def_i][def_j] = -1;
		  que.push(make_pair(def_i,def_j));
		}
	      }
	    }
	  }
      }
    }
    cout << ct << endl;
    
  }
	
	return 0;
}

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

signed main(){
	string s;
	bool ans, f;
	
	cin>>s;
	
	
	f = (s[0] == s[s.size()-1]);
	
	ans = (s.size()+f)%2;
	
	
	cout<<(ans?"First":"Second")<<endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int A, B;

int main()
{
  scanf( "%d%d", &A, &B );

  printf( "%d\n", std::max({A+A-1,B+B-1,A+B}) );

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
  int n, m, l ;
  int i, j, k, x ;
  int mat_a[105][105] = {} ;
  int mat_b[105][105] = {} ;
  long int mat_c[105][105] = {} ;

  scanf("%d %d %d",&n,&m,&l) ;

  /*行列Aに代入*/
  for ( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < m ; j++ ){
      scanf("%d",&x) ;
      mat_a[i][j] = x ;
    }
  }

  /*行列Bに代入*/
  for ( j = 0 ; j < m ; j++ ){
    for( k = 0 ; k < l ; k++ ){
      scanf("%d",&x) ;
      mat_b[j][k] = x ;
    }
  }

  /*行列Cを計算*/
  for( i = 0 ; i < n ; i++ ){
    for( k = 0 ; k < l ; k++ ){
      for( j = 0 ; j < m ; j++ ){
        mat_c[i][k] += mat_a[i][j] * mat_b[j][k] ;
      }
    }
  }

  for( i = 0 ; i < n; i++ ){
    for( k = 0 ; k < l; k++ ){
      if( k < l-1 ){
        printf("%ld ", mat_c[i][k]) ;
      }else{
        printf("%ld", mat_c[i][k]) ;
      }
    }
    printf("\n") ;
  }

  return 0 ;
}


Measured memory_bytes: 2108