akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define BIT(bit,a,n) for (int bit = a;bit < (1<<n);bit++) // {0, 1, ..., n-1} の部分集合の全探索 // n番目のフラグが立っている状態は (1<<n)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20

typedef long long ll;
using namespace std;

int n;
int ans = 1000;
int cnt;
int main() {
    scanf("%d",&n);
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    
    rep(i,0,n){
        cnt = 0;
        while(a[i]%2 == 0){
            a[i] /= 2;
            cnt++;
        }
        ans = min(ans,cnt);
    }
    pout(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define N 500043
#define mp(a,b) make_pair(a,b)
#define loop(a,b) for(int i=a;i<b;i++)
#define test int t; cin >> t; while(t--)
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    vector<int>vec(n);
    loop(0,n) cin >> vec[i];
    vector<bool>dp(k+1,false);
    for(int i=1;i<=k;i++){
        if(dp[i]==true) continue;
        bool ans=false;
        for(int j=0;j<n;j++){
            if(i-vec[j]>=0){
                if(dp[i-vec[j]]==false){
                    ans=true;
                }
            }
        }
        if(ans)
            dp[i]=true;
    }
    if(dp[k]) cout << "First";
    else cout <<"Second";
}

Measured memory_bytes: 3588
#include<stdio.h>
 
int main( ) {
    int input;
    int count = 0;
 
    while(1) {
        scanf("%d",&input);
        if( input == 0 ) {
            break;
        }
        count++;
        printf("Case %d: %d\n",count ,input);
    }
 
    return 0;
}

Measured memory_bytes: 1684
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=1e5+500;
ll a[maxn];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}	
	ll less=0;
	ll tedad=0;
	for(ll i=0;i<n;i++){
		ll v;
		cin>>v;
		a[i]-=v;
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++){
		if(a[i]<0){
			less+=(-a[i]);
			tedad++;
		}
	}
	for(ll i=n-1;i>=0;i--){
		if(less>0){
			less-=a[i];
			tedad++;
		}
	}
	if(less>0)cout<<-1;
	else cout<<tedad;


}




















Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  double l;
  cin >> l;
  cout << fixed << setprecision(15) << l * l * l / 27.0 << endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string a, b, c;
    cin >> a >> b >> c;
    cout << char('A') << b[0] << char('C') << endl;
    
    return 0;
}



Measured memory_bytes: 256
n  = int(input())

taro = 0
hanako = 0

for _ in range(n):
        words = input().split()

        w_t = words[0]
        w_h = words[1]
        flag = 0
        n = min(len(w_t),len(w_h))

        for i in range(n):
                if w_t[i] > w_h[i]:
                        taro += 3
                        flag = 1
                        break
                elif w_t[i] == w_h[i]:
                        pass
                
                else:
                        hanako += 3
                        flag = 1
                        break

        if flag == 0:
                if len(w_t) == len(w_h):
                        taro += 1
                        hanako += 1

                elif len(w_t) > len(w_h):
                        taro += 3
                else:
                        hanako += 3

        
        

print(taro,hanako)


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

int main()
{
  int n,k;
  cin>>n>>k;
  int arr[n],dp[n];
  for(int i=0;i<n;i++)
  {
      cin>>arr[i];
  }
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
  {
    int x=dp[i-1]+abs(arr[i]-arr[i-1]);
    for(int j=min(i,k);j>1;j--)
    {
        x=min(x,dp[i-j]+abs(arr[i]-arr[i-j]));
    }
    dp[i]=x;
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


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

typedef struct node{
  int id;
  struct node *parent;
  struct node *left;
  struct node *right;
}Node;

void print_tree(Node *x,int t) {
  if(x->left != NULL) print_tree(x->left,1);
  if(x->right != NULL) print_tree(x->right,1);
  if(t == 1)printf("%d ", x->id);
  if(t == 0)printf("%d\n", x->id);
}

Node *make_tree(int *pre, int * in, int i, int j, int n, Node *p) {
  if(i >= n) return NULL;
  Node *p1 = (Node*)malloc(sizeof(Node));
  p1->id = pre[i];
  p1->parent = p;
  p1->left = NULL;
  p1->right = NULL;
  if(pre[i] != in[j]) {
    p1->left = make_tree(pre,in,i+1,j,n,p1);
  }else{
    Node *tmp = p1;
    while(1) {
      if(p == NULL) {
	break;
      }
      if(p->id == in[j+1]) {
	j++;
	tmp = p;
      }
      p = p->parent;
    }
    tmp->right = make_tree(pre,in,i+1,j+1,n,tmp);
  }
  return p1;
}

int main()
{
  int i,n,*preorder,*inorder;
  scanf("%d",&n);
  preorder = (int*)malloc(sizeof(int) * n);
  inorder = (int*)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d",preorder+i);
  }
  for (i = 0; i < n; i++) {
    scanf("%d",inorder+i);
  }
  Node *root = make_tree(preorder,inorder,0,0,n,NULL);
  print_tree(root,0);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int x;
    cin >> x;
    if(x < 600) cout << 8 << '\n';
    else if(x < 800)    cout << 7 << '\n';
    else if(x < 1000)   cout << 6 << '\n';
    else if(x < 1200)   cout << 5 << '\n';
    else if(x < 1400)   cout << 4 << '\n';
    else if(x < 1600)   cout << 3 << '\n';
    else if(x < 1800)   cout << 2 << '\n';
    else    cout << 1 << '\n';
}

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

void bubbleSort(int n, pair<char, int> a[]) {
    rep(i, n) {
        for (int j = n - 1; j >= i + 1; j--) {
            if (a[j].second < a[j - 1].second) swap(a[j], a[j - 1]);
        }
    }
}

void selectionSort(int n, pair<char, int> a[]) {
    rep(i, n) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (a[j].second < a[minj].second) minj = j;
        }
        swap(a[i], a[minj]);
    }
}

void print(int n, pair<char, int> a[]) {
    rep(i, n) {
        cout << a[i].first << a[i].second;
        if (i != n - 1) cout << ' ';
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    pair<char, int> a[n], b[n];
    rep(i, n) cin >> a[i].first >> a[i].second;
    copy(a, a + n, b);

    bubbleSort(n, a);
    print(n, a);
    cout << "Stable" << endl;

    selectionSort(n, b);
    print(n, b);

    bool ok = true;
    rep(i, n) if (a[i] != b[i]) ok = false;
    if (ok)
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;

    return 0;
}



Measured memory_bytes: 3096
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
tail = 0
head = float('inf')
for i in range(N):
    tail = max(tail, sum(A[i]))
    head = min(head, sum(A[i]))
ans_1 = tail - head

tmp_h, tmp_t = 0, 0
tail = A[i]
head = A[i]
for i in range(N):
    tail = A[i] if tmp_t < A[i][0]-A[i][1] else tail
    head = A[i] if tmp_h < A[i][1]-A[i][0] else head
    tmp_t = A[i][0]-A[i][1] if tmp_t < A[i][0]-A[i][1] else tmp_t
    tmp_h = A[i][1]-A[i][0] if tmp_h < A[i][1]-A[i][0] else tmp_h

ans_2 = abs(tail[0]-head[0]) + abs(tail[1]-head[1])
ans = max(ans_1, ans_2)
print(ans)

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

char c[14][14];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int W,H;
int ice[14][14];
int num[10000];
int gx,gy;

int ans = 0;
void dfs(int x,int y,int C,int px,int py){
  if( c[y][x] == '#' || c[y][x] == '*') return;
  if( C + abs(x-gx) + abs(y-gy) >= ans ) return;
  if( c[y][x] == 'G'){ans = C; return; }

  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
   if(ty < 0 || tx < 0 || ty >= H || tx >= W)continue;
  
   if( px == tx && ty == py ) continue;
    if( c[ty][tx] == '*' ) return;
  }
  char cur = c[y][x];
  c[y][x] = '*';
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
   if(ty < 0 || tx < 0 || ty >= H || tx >= W)continue;
  
   if( c[ty][tx] == 'X' ){
      int b = ice[ty][tx];
      if( num[b] > 0 ){
	num[b]--;
	dfs(tx,ty,C+1,x,y);
	num[b]++;
      }
    }else{
      dfs(tx,ty,C+1,x,y);
    }
  }
  c[y][x] = cur;
  return;
}
void grouping(int x,int y,int k){
  ice[y][x] = k;
  num[k]++;
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if(ty < 0 || tx < 0 || ty >= H || tx >= W)continue;
    if( c[ty][tx] == 'X' && ice[ty][tx] < 0 )grouping(tx,ty,k);
  }
}

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

  while(cin >> W >> H && W){
    memset(ice,-1,sizeof(ice));
    rep(i,14)rep(j,14) 
      c[i][j] = '#';
    int sx , sy;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cin >> c[i][j];
	if(c[i][j] == 'S'){
	  c[i][j] = '.';
	  sx = j , sy = i;
	}else if(c[i][j] == 'G' ){
	  gx = j , gy = i;
	}
      }
    }
    int k = 0;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	if( c[i][j] == 'X' && ice[i][j] < 0){
	  num[k] = 0;
	  grouping(j,i,k);
	  num[k] /= 2;
	  k++;
	}
      }
    }
    ans = 1e7;
    dfs(sx,sy,0,-1,-1);
    cout << ans << endl;
    
  }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main() {
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (0 <= z && z <= k) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
'''
例えばスイッチが2つあった場合、on,offの組み合わせをビットで表すと
00
01
10
11
の4通りで、右からスイッチ1,2とすると
1を左に0ビットシフトしたものが01
1を左に1ビットシフトしたものが10
となり、それぞれスイッチ1がonの状態と
スイッチ2がonの状態を表すことができる
これを利用する
'''

n, m = map(int,input().split())
s = []
for _ in range(m):
    s.append([int(i) for i in input().split()])
p = [int(i) for i in input().split()]

ans = 0
for i in range(2**n):
    ok = True
    for j in range(m):
        cnt = 0
        for k in range(1,s[j][0]+1):
            if i & (1 << (s[j][k]-1)):
                cnt += 1
        if cnt % 2 != p[j]:
            ok = False
    if ok:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import numpy as np
X,N = map(int, input().split())


if N == 0:
  print(X)
else:
  ans_v = 102
  ans_idx = 0
  candidate = list(np.arange(0,102))
  p = list(map(int, input().split()))
  for i in range(N):
    candidate.remove(p[i])
  for i in range(len(candidate)):
    if ans_v > abs(X-candidate[i]):
      ans_v = abs(X-candidate[i])
      ans_idx = i
  print(candidate[ans_idx])


Measured memory_bytes: 26940
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int T = Integer.parseInt(sc.next());
		int[] t = new int[n];
		long sum = T;
		t[0] = Integer.parseInt(sc.next());
		for (int i = 1; i < n; i++) {
			t[i] = Integer.parseInt(sc.next());
			if (t[i] <= t[i - 1] + T) {
				sum += t[i] - t[i - 1];
			}
			else {
				sum += T;
			}
		}
		System.out.println(sum);
	}
}

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

int main ()
{
    int R;
    std::cin >> R;
    
    if (R < 1200)
    {
        std::cout << "ABC" << std::endl;
    }
    else if (R < 2800)
    {
        std::cout << "ARC" << std::endl;
    }
    else
    {
        std::cout << "AGC" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int num1 = sc.nextInt();
          int num2 = sc.nextInt();
          if(num1 == 1){
            num1 = 14;
          }
          if(num2 ==1){
            num2 = 14;
          }
            if(num1 > num2){
            System.out.println("Alice");
          } else if(num1 == num2){
            System.out.println("Draw");
          } else {
            System.out.println("Bob");
          }
        }
    
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    string s;
    cin>>s;
    int x=SZ(s),y;
    if(x%2==0)
    {
       y=x-2;
    }
    else
    {
        y=x-1;
    }
    while(1)
    {
        string ss,kk;
        for(int i=0;i<y/2;i++)
        {
            ss+=s[i];
        }
        for(int i=y/2;i<y;i++)
        {
            kk+=s[i];
        }
        if(ss==kk)
        {
            ss+=kk;
            cout<<SZ(ss)<<NL;
            return 0;
        }
        y-=2;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
int main() {
	int n, k;
	cin >> n >> k;
	if (n % k == 0)PRI(0);
	else PRI(1);
	return 0;
}

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

int main() {

    int n; cin >> n;
    
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int tmp; cin >> tmp;
        mp[tmp] = 1;
    }
    int cnt = 0;
    for (auto u : mp) {
        cnt++;
    }

    cout << cnt;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

int main(){
    ll x;
    cin >> x;
    for(int a=-300;a<=300;a++){
        for(int b=-300;b<=300;b++){
            if(pow(a,5)-pow(b,5)==x){
                cout << a <<' '<< b << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4024
#include <stdio.h>
using namespace std;

int main(){
  int n, a;
  int min = 1000000, max = -1000000;
  long long sum = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a);
    if(a < min){
      min = a;
    }
    if(max < a){
      max = a;
    }
    sum += a;
  }
  printf("%d %d %lld\n", min, max, sum);
}



Measured memory_bytes: 2752
#include<stdio.h>
int main()
{
	int w,h,x,y,r;
	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
	if ((x-r)>=0&&(x+r)<=w&&(y-r)>=0&&(y+r)<=h)
		printf("Yes\n");
	else
		printf("No\n");
		
	return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  string ans = a + b < c ? "No" : "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 256
#!python3.8
# -*- coding: utf-8 -*-
# tokiomarine2020/tokiomarine2020_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, V = i2nn()
    B, W = i2nn()
    T = i2n()
    if T * W  + abs(A - B) <= T * V:
        print('YES')
    else:
        print('NO')
    return

main()


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

int main()
{
    ll n, k;
    cin >> n >> k;

    set<int> children;
    for(int i = 0; i < k; i++)
    {
        int d;
        cin >> d;
        for(int j = 0; j < d; j++)
        {
            int c;
            cin >> c;

            children.insert(c);
        }
    }

    cout << n - children.size() << endl;

    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    ll x,y;cin>>x>>y;
    if(x%y==0) cout<<-1<<endl;
    else cout<<x<<endl;
}


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

int main()
{
    int n;
    while(cin>>n)
    {
        int i,flag=0,j;
           string s;
            cin>>s;
            int k=n/2;

            if(n%2!=0)
         cout<<"No"<<endl;
            else{
         for(i=0,j=k;i<k,j<n;i++,j++)
         {


                 if(s[i]!=s[j])
                 {
                     flag=1;
                     break;
                 }
             }
         if(flag==0)
            cout<<"Yes"<<endl;
         else
            cout<<"No"<<endl;
            }
    }
    return 0;
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>n;
    if(n==25) cout<<"Christmas";
    else if(n==24) cout<<"Christmas Eve";
    else if(n==23) cout<<"Christmas Eve Eve";
    else if(n==22) cout<<"Christmas Eve Eve Eve";


    

    return 0;
}


Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split(' ');
		int a = int.Parse(str[0]);
		int b = int.Parse(str[1]);
		Console.WriteLine(a*b+" "+(a+b)*2);
	}
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    char s[7]={};
    scanf("%s",s);
    if(s[2]==s[3] && s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc140/tasks/abc140_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] arrayA = makeArray(sc,N);
		int[] arrayB = makeArray(sc,N);
		int[] arrayC = makeArray(sc,N-1);
		sc.close();


		int ans = 0;
		for(int i:arrayA) {
			ans = ans + arrayB[i-1];
			if((i-1)>0&&arrayA[i-1]==arrayA[i-2]+1) {
				ans = ans + arrayC[arrayA[i-2]-1];
			}
		}

		System.out.println(ans);

	}

	public static int[] makeArray(Scanner sc,int N) {
		int[] array = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

}


Measured memory_bytes: 23636
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve=fst.foldl' f(0,0).tail
f(s,p)a=(s+b-a,b)where b=max p a

Measured memory_bytes: 9136
#include <iostream>

using namespace std;

int main(){
  int A,B,C,X,Y;

  cin >> A >> B >> C >> X >> Y;
  int priceAB=0,priceC=0;
  int goodprice = 0;
  if(X > 0 && Y > 0){
    priceAB = A+B;
    priceC = C*2;
    if(priceAB > priceC) goodprice = priceC;
    else goodprice = priceAB;
  }

  int total = 0;
  while(X > 0 && Y > 0){
    total+= goodprice;
    X--;
    Y--;
  }

  if(X > 0){
    priceAB =A;
    if(priceAB < priceC) goodprice = priceAB;
  }

  while(X > 0){
    total += goodprice;
    X--;
  }

  if(Y > 0){
    priceAB =B;
    if(priceAB < priceC) goodprice = priceAB;
  }

  while(Y > 0){
    total += goodprice;
    Y--;
  }

  cout << total << endl;

  return 0;
}


Measured memory_bytes: 256
use input::Input;

fn main() {
    let mut input = Input::default();

    let a: u32 = input.parse();
    let b: u32 = input.parse();
    let c: u32 = input.parse();
    let k: u32 = input.parse();

    if c > b && b > a {
        println!("Yes");
        return;
    }

    for i in 0..(1 << k) {
        let (red, mut green, mut blue) = (a, b, c);
        for j in 0..k {
            if i >> j & 1 == 1 {
                green *= 2;
            } else {
                blue *= 2;
            }
            if blue > green && green > red {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1 << 20

using namespace std;

int main()
{
	vector<string> s(100);
	int ans,h,w,sx,sy;
	int dx[4] = {1,0,-1,0};
	int dy[4] = {0,1,0,-1};
	int cost[100][100];
	
	while(cin >> w >> h)
	{
		if(w == 0 && h == 0) break;
		
		rep(i,h) rep(j,w) cost[i][j] = INF;
		ans = INF;

		rep(i,h)
		{
			cin >> s[i];
		}
		
		rep(i,h)
		{
			rep(j,w)
			{
				if(s[i][j] == '&')
				{
					sy = i;
					sx = j;
				}
			}
		}

		cost[sy][sx] = 0;

		queue<pair<int,int> > que;
		que.push(make_pair(sy,sx));

		while(!que.empty())
		{
			pair<int,int> p = que.front();
			int y = p.first;
			int x = p.second;
			que.pop();

			rep(i,4)
			{
				int ny = y + dy[i];
				int nx = x + dx[i];

				if(0 <= ny && ny < h && 0 <= nx && nx < w)
				{
					int temp = cost[y][x];
					if(s[y][x] != '#' && s[ny][nx] == '#')
					{
						temp++;
					}

					if(temp < cost[ny][nx])
					{
						cost[ny][nx] = temp;
						que.push(make_pair(ny,nx));
					}
				}
			}
		}

		rep(i,h)
		{
			rep(j,w)
			{
				if(i == 0 || i == h-1 || j == 0 || j == w-1)
				{
					ans = min(ans,cost[i][j]);
				}
			}
		}
	
		cout << ans << endl;
	}
}

Measured memory_bytes: 1296
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;
    if(a+b >= c){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int up(const void *a ,const void *b){
  return *(int *)b - *(int *)a;
}

int main(void){

  int n;
  scanf("%d",&n);
  int nx = n - 1;

  int a[n];
  for(int i =0;i < n;i ++){
    scanf("%d",&a[i]);
  }

  qsort(a,n,sizeof(int),up);

  int flag = 1;
  if(n%2 == 1){
    if(a[nx] != 0){
      flag = 0;
    }
  }

  if(flag == 1){
    int c = 0;
    for(int i = 0;i < nx/2;i ++){
      int t = i;
      if(a[2*t] == a[2*t +1]){
        if(a[2*t] != nx -2*t){
          flag = 0;
        }
      }
      else{
        flag = 0;
      }
    }
  }

  long long ans = 1;
  if(flag == 1){
    int temp = n/2;
    while(temp > 0){
      ans *= 2;
      if(ans > 1000000007){
        ans %= 1000000007;
      }
      temp --;
    }
  }

  else{
    ans = 0;
  }

  printf("%lld\n",ans);

  return 0;

}

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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    rep(i, n) {
        cin >> a.at(i);
    }
    for (int i = 1; i < n; i++) {
        if (a.at(i) < a.at(i - 1)) {
            ans += a.at(i - 1) - a.at(i);
            a.at(i) = a.at(i - 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4788
package main

import (
	"fmt"
	"sort"
)

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	c := make([]int, n)
	for i := range a {
		c[i] = a[i]-i
	}
	sort.Ints(c)

	b := 0
	if n % 2 == 0 {
		b = (c[n/2] + c[n/2-1]) / 2
	} else {
		b = c[n/2]
	}

	ans := 0
	for i := range a {
		ans += abs(a[i]-b-i)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6656
import java.util.*;

public class Main {

	private static Scanner scanner;

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		 scanner = new Scanner(System.in);
		int x = scanner.nextInt();
	        int y = scanner.nextInt();
	        int z = scanner.nextInt();
	         
	        if(x<y && y<z){
	            System.out.println("Yes");
	        }else{
	            System.out.println("No");
	        }

	}

}

Measured memory_bytes: 26132
#include<stdio.h>
int main(){
  int n,x;
  scanf("%d %d",&n,&x);
  int cnt = 1;
  int sum = 0;
  int t;
  for(int i=0;i < n;i++){
    scanf("%d",&t);
    sum+=t;
    if(sum <= x){
      cnt++;
    }
  }
  printf("%d",cnt);
}
          

Measured memory_bytes: 1736
MOD = int(1e9+7)
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
flag = 0
for a in A:
    if a>0:
        flag = 1
        break
if N==K:
    ans = 1
    for i in range(K):
        ans = (ans*A[i]) % MOD
    print(ans)

#すべてマイナスか0
elif flag == 0 and K%2==1:
    A.sort(reverse = True)
    ans = 1
    for i in range(K):
        ans = (ans*A[i]) % MOD
    print(ans)
#それ以外
else:
    A = sorted(A, key=abs, reverse = True)
    last_pos = -1
    last_neg = -1
    count_neg = 0
    is_zero = 0
    ans = 1
    for i in range(K):
        ans = (ans*A[i]) % MOD
        if A[i]>0:
            last_pos = i
        elif A[i]<0:
            last_neg = i
            count_neg += 1
        else:
            is_zero = 1
            break
    if is_zero == 1:
        print(0)
    elif count_neg%2 == 0:
        print(ans)
    else:
        flag_pos = 0
        flag_neg = 0
        new_pos = -1
        new_neg = -1
        for i in range(K,N):
            if A[i]>0 and flag_pos==0:
                flag_pos = 1
                new_pos = i
            elif A[i]<0 and flag_neg==0:
                flag_neg = 1
                new_neg = i
            if flag_pos == 1 and flag_neg == 1:
                break

        if last_pos > -1 and last_neg > -1 and new_pos > -1 and new_neg > -1:
            f1 = A[new_pos] * A[last_pos]
            f2 = A[new_neg] * A[last_neg]
            if f1>f2:
                ans = 1
                for i in range(K):
                    if i != last_neg:
                        ans = (ans*A[i]) % MOD
                ans = (ans*A[new_pos]) % MOD
            else:
                ans = 1
                for i in range(K):
                    if i != last_pos:
                        ans = (ans*A[i]) % MOD
                ans = (ans*A[new_neg]) % MOD
        elif last_pos > -1 and new_neg > -1:
            ans = 1
            for i in range(K):
                if i != last_pos:
                    ans = (ans*A[i]) % MOD
            ans = (ans*A[new_neg]) % MOD
        elif last_neg > -1 and new_pos > -1:
            ans = 1
            for i in range(K):
                if i != last_neg:
                    ans = (ans*A[i]) % MOD
            ans = (ans*A[new_pos]) % MOD
        else:
            ans = 0
            
        print(ans)

            
        

Measured memory_bytes: 31824
# D - Prediction and Restriction
def get_win_hand(com_hand):
    if com_hand == 'r':
        return 'p'
    elif com_hand == 's':
        return 'r'
    elif com_hand == 'p':
        return 's'

def get_score(my_hand, R, S, P):
    if my_hand == 'r':
        return R
    elif my_hand == 's':
        return S
    elif my_hand == 'p':
        return P
        
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = str(input())

score_list = [0] * K
for i in range(K):
    tmp_score = 0
    before_my_hand = '*'
    partialT = T[i::K]
    for com_hand in partialT:
        my_hand = get_win_hand(com_hand)
        if my_hand == before_my_hand:
            my_hand = '*'
        else:
            tmp_score += get_score(my_hand, R, S, P)
        before_my_hand = my_hand
    score_list[i] = tmp_score
    
print(sum(score_list))

Measured memory_bytes: 6644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  string S;
  cin >> S;
  for (int i = 0; i < 3; i++) {
    if (S[i]==S[i+1]) {
      cout << "Bad" << endl; return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main()
{
    int N;
    cin >> N;
    vector<pair<int,int>> pb;
    vector<pair<int,int>> pr;
    vector<bool> used(N,false);

    REP(i,N){
        int a,b;
        cin>>a>>b;
        pr.push_back(make_pair(a,b));
    }   
    REP(i,N){
        int a,b;
        cin>>a>>b;
        pb.push_back(make_pair(a,b));
    }

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

    int cnt=0;
    REP(i,N){
        int xb=pb[i].first;
        int yb=pb[i].second;
        //cout << xb<<" "<<yb << endl;

        int opt_i=-1;
        int max_y=-1;
        REP(j,N){
            if(used[j]) continue;
            int xr=pr[j].first;
            int yr=pr[j].second;
            //cout << xr<<" "<<yr << endl;
            if(xr<xb&&yr<yb){
                if(max_y<yr){
                  //printf("xr:%d yr:%d xb:%d yb:%d\n", xr, yr, xb, yb);
                    max_y=yr;
                    opt_i=j;
                }
            }
        }
        if(opt_i!=-1){
            used[opt_i] = true;
            cnt++;
        }

    }
    cout << cnt << endl;

    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int n, i;
    int a, b, c;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d", &a, &b, &c);
        if (a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 576
#include <stdio.h>
#define NIL -1
#define MAX 100001

int main(){
  int n,i,j,id,k,c,temp,depth,parent[MAX],left[MAX],right[MAX],degree[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++) parent[i]=left[i]=right[i]=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);
    degree[id]=k;
    for(j=0;j<k;j++){
      if(left[id]==NIL){
	scanf("%d",&c);
	left[id]=c;
	parent[c]=id;
	temp=left[id];
      }else{
	scanf("%d",&c);
	right[temp]=c;
	parent[c]=id;
	temp=c;
      }
    }
  }
  for(i=0;i<n;i++){
    printf("node %d: parent = %d,",i,parent[i]);
    depth=0;
    c=i;
    while(parent[c]!=NIL){
      c=parent[c];
      depth++;
    }
    printf(" depth = %d,",depth);
    if(parent[i]==NIL) printf(" root, [");
    else if(left[i]==NIL) printf(" leaf, [");
    else printf(" internal node, [");
    c=left[i];
    for(j=0;j<degree[i];j++){
      if(j) printf(", ");
      printf("%d",c);
      c=right[c];
      }
    printf("]\n");
  }
  return 0;
}
  



Measured memory_bytes: 3368
#include <bits/stdc++.h>
#include <cstdlib> // abs(x-y)
#include <iomanip> // 出力の桁数指定
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  rep (i, 0, n) 
    cin >> t.at(i);
  
  int m;
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  rep (i, 0, m) {
    cin >> p.at(i);
    cin >> x.at(i);
  }
  
  rep (i, 0, m) {
    vector<int> tp(n);
  rep (i, 0, n) 
    tp.at(i) = t.at(i);
    int sum = 0;
    tp.at(p.at(i) -1) = x.at(i);
    rep (j, 0, n)
      sum += tp.at(j);
    cout << sum << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	map<string, int> cnt;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		cnt[s]++;
	}
	int ma = 0;
	for (auto &p : cnt) {
		ma = max(ma, p.second);
	}
	for (auto &p : cnt) {
		if (ma == p.second) {
			cout << p.first << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int k;
    cin >> k;

    queue<string> q;
    for(char c = '1'; c <= '9'; ++c) q.push(string(1, c));

    while(true){
        string cur = q.front();
        q.pop();
        if(cur.back() != '0') q.push(cur + char(cur.back()-1));
        q.push(cur + cur.back());
        if(cur.back() != '9') q.push(cur + char(cur.back()+1));
        --k;
        if(!k){
            cout << cur << '\n';
            return;
        }
    }
    assert(false);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
// clang-format on

using VI = vector<int>;
using VVI = vector<VI>;

int main()
{
  IOS;
  int N, K;
  cin >> N >> K;
  VI A(N);
  forn(i, 0, N) cin >> A[i];
  VVI dp(K + 1, VI(2));
  dp[0][1] = 1;
  for (int k = 1; k <= K; k++)
  {
    int x = 0, y = 1;
    for (auto a : A)
    {
      if (k >= a)
      {
        x |= dp[k - a][1];
        y &= dp[k - a][0];
      }
      else
        break;
    }
    dp[k][0] = x;
    dp[k][1] = y;
  }

  cout << (dp[K][0] ? "First" : "Second") << endl;

  return 0;
}


Measured memory_bytes: 8704
#include<bits/stdc++.h>
#define LL  long long
#define INF 0x7FFFFFFF
#define mod 1000000007
using namespace std;
 
int row[2005][2005], col[2005][2005];
bool ch[2005][2005];
int main(){
	int n, m;
	char cmp;
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			cin >> cmp;
			if(cmp == '.'){
				ch[i][j] = 1;				
			}
			else{
				ch[i][j] = 0;
			}
		}
	}
	int b, e, now;
	for(int i = 0; i < n; ++i){
		b = 0; e = 0; now = 0;
		for(int j = 0; j < m; ++j){
			if(ch[i][j]){
				now++;
			}
			else{
				for(int k = b; k < e; ++k){
					row[i][k] = now;
				}
				now = 0;
				b = e;
			}
			e++;
		}	
		for(int k = b; k < e; ++k){
			row[i][k] = now;
		}
	}
	for(int i = 0; i < m; ++i){
		b = 0; e = 0; now = 0;
		for(int j = 0; j < n; ++j){
			if(ch[j][i]){
				now++;
			}
			else{
				for(int k = b; k < e; ++k){
					col[k][i] = now;
				}
				now = 0;
				b = e;
			}
			e++;
		}	
		for(int k = b; k < e; ++k){
			col[k][i] = now;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			ans = max(ans, row[i][j] + col[i][j]);
		}
	}
	cout << ans - 1 << endl;
	return 0;
}

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

int main() {
  ll N;
  ll M;
  cin >> N >> M;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  
  // M番目の Ax + Ay の値を求める
  ll low = 0;
  ll high = 1e10;
  while (high - low > 1) {
    ll mid = (low + high) / 2;
    ll num = 0;
    for (int i = 0; i < N; i++) {
      num += A.end() - lower_bound(A.begin(), A.end(), mid - A.at(i));
    }
    if (num >= M) {
      low = mid;
    } else {
      high = mid;
    }
  }
  
  // 累積和の計算
  vector<ll> s(N + 1, 0);
  for (int i = N - 1; i >= 0; i--) {
    s.at(i) = s.at(i + 1) + A.at(i);
  }
  
  ll ans = 0;
  ll cnt = 0;
  for (int i = 0; i < N; i++) {
    int x = upper_bound(A.begin(), A.end(), low - A.at(i)) - A.begin(); // 合計が low になるものは別で計算
    ans += (N - x) * A.at(i) + s.at(x);
    cnt += N - x;
  }
  ans += low * (M - cnt); // 合計が low になるものを加算
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<map>
#include<algorithm>
#include<functional>
#include<bitset>
#include<vector>
#include<set>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int  MOD = 1e9 + 7, OO = 1e9;
const int  N = 2e5 + 10;
int a[N];
int n;
int dp[4004][4004];
int solve(int i,int last) {
	if (last > 4000) {
		return -OO;
	}
	if (i == n + 1) {
		return 0;
	}

}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    while(1){
        string s;
        cin >> s;
        if(s.size() == 1 && s.at(0) == '0')break;
        int sum = 0;
        rep(i,s.size()) sum += (int) (s.at(i) -'0');
        cout << sum << endl;
    }
    
return 0;
}


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

int p[105];
bool isContained[505];

int main(){
    int X, N;
    scanf("%d%d", &X, &N);

    X += 200;

    memset(isContained, 0, sizeof(isContained));
    for(int i = 0; i < N; i ++){
        scanf("%d", &p[i]);
        p[i] += 200;
        isContained[p[i]] = 1;
    }

    int ans = 505;
    int bestAns = 0;
    for(int i = 0; i < 502; i ++){
        if(abs(i-X) < ans && !isContained[i]){
            ans = abs(i-X);
            bestAns = i;
        }
    }

    printf("%d\n", bestAns-200);
    return 0;
}


Measured memory_bytes: 3820
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()

	fmt.Printf("%d\n", ABC055B(N))
}

// ABC055B ...
func ABC055B(N int) int {
	res := 1
	for i := 1; i <= N; i++ {
		res = (res * i) % (1000000000 + 7)
	}
	return res
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n,k;

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>k;
  ll res=0;
  rep(i,n-1){
    res=(res/(k-1))+1+res;
  }
  cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3152
n = int(input())

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

Measured memory_bytes: 9180
#include<iostream>
using namespace std;
int main(){
  while(1){
    int n,c=0;
    cin>>n;
    if(n==0)break;
    string s,b;
    for(int i=0;i<n;i++){
      cin>>s;
      if(s[1]==b[1])c++;
      b=s;
    }
    cout<<c<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

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

  int n; cin >> n;

  int arr[n];
  memset(arr, 0, sizeof(arr));

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

  int m; cin >> m;
  for (int i = 0; i < m; ++i) {
    int p, x;
    cin >> p >> x;
    int res = s - arr[p - 1] + x;
    cout << res << "\n";
  }
}


Measured memory_bytes: 3592
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		sc.nextLine();

		PriorityQueue<Long> smallest = new PriorityQueue<>();
		PriorityQueue<Long> biggest = new PriorityQueue<>(Comparator.reverseOrder());
		long answer = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			String[] query = sc.nextLine().split(" ");
			if (query[0].charAt(0) == '1') {
				answer += Long.parseLong(query[2]);
				smallest.offer(Long.parseLong(query[1]));
				biggest.offer(Long.parseLong(query[1]));
				long s = smallest.peek();
				long b = biggest.peek();
				if (b > s) {
					smallest.poll();
					biggest.poll();
					smallest.offer(b);
					biggest.offer(s);
					answer += Math.abs(b - s);
				}
			} else {
				sb.append(biggest.peek()).append(" ")
						.append(answer).append("\n");
			}
		}
		System.out.print(sb.toString());
	}
}


Measured memory_bytes: 211344
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

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

int main() {
	LL n;
	cin >> n;
	vector<LL> a(n + 1);
	rep(i, 1, n + 1) cin >> a[i];
	vector<LL> l(n + 2), r(n + 2);
	l[0] = 0;
	rep(i, 0, n) l[i + 1] = gcd(l[i], a[i]);
	r[n + 1] = 0;
	for (int i = n; i > 0; i--) r[i] = gcd(r[i + 1], a[i]);
	LL ans = 0;
	rep(i, 0, n + 1) {
		LL m = gcd(l[i], r[i + 1]);
		ans = max(ans, m);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560