akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h,w,k;
  int ans = 0;
  int x = 0;
  int x0;
  int i3,j3;
  bool flag = false;
  cin >> h >> w >> k;
  vector<vector<char>> a(h,vector<char>(w));
  vector<vector<char>> b(h,vector<char>(w));
  for(int i = 0;i<h;i++){
    for(int j = 0;j<w;j++){
      cin >> a.at(i).at(j);
      b.at(i).at(j) = a.at(i).at(j);
      if(a.at(i).at(j)=='#'){
        x = x + 1;
        x0 = x;
      }
    }
  }
  for(int i = 0;i<pow(2,h);i++){
    for(int j =0 ;j<pow(2,w);j++){
      i3 = i;
      j3 = j;
      x = x0;
      	for(int i0 = h-1;i0>=0;i0--){
            if(i3>=pow(2,i0)){
              for(int j1 = 0;j1<w;j1++){
                if(b.at(i0).at(j1) == '#'){
                  x = x - 1;
                  if(x < k){
                    flag = true;
                    break;
                  }
                }
                b.at(i0).at(j1) = 'n';
              }
              i3 = i3 - pow(2,i0);
            }
          if(flag == true){
            break;
          }
        }
        for(int j0 = w-1;j0>=0;j0--){
            if(j3>=pow(2,j0)){
              for(int i1 = 0;i1<h;i1++){
                if(b.at(i1).at(j0) == '#'){
                  x = x - 1;
                  if(x < k){
                    flag = true;
                    break;
                  }
                }
                b.at(i1).at(j0) = 'n';
              }
              j3 = j3 - pow(2,j0);
            }
          if(flag == true){
            break;
          }
        }
        if(x == k){
          ans = ans + 1;
        }
      flag = false;
      for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
          b.at(i).at(j) = a.at(i).at(j);
        }
      }
    }
  }
  cout << ans << endl;
}


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


int main(){
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for(auto& h : H){
    cin >> h;
  }
  
  sort(H.begin(), H.end());
  int ans = 1000000000;
  for(int ii=0; ii<N-K+1; ii++){
    ans = min(ans, H[ii+K-1]-H[ii]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;
#define INF 100000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/

int main(){
    ll N,ans=200000000000000;
    cin>>N;
    for(ll i=1;i<=1000000;i++){
        if(N%i==0){
            ans=min(ans,N/i+i);
        }
    }
    ans-=2;
    if(ans<0) ans=0;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* 多次元デック */template<class T>deque<T> mdeq(size_t a){return deque<T>(a);}template<class T, class... Ts>auto mdeq(size_t a, Ts... ts){return deque<decltype(mdeq<T>(ts...))>(a, mdeq<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  fixsp(10);
  ll N, K;
  cin >> N >> K;
  ld ans{};
  rep(i, 1, N+1){
    ll d = i;
    ld g{1};
    while(d < K){
      g/=2;
      d*=2;
    }
    ans += g;
  }
  cout << ans/N << rt;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  
  cout<<max(0,a-2*b)<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<bits/stdc++.h>
using namespace std;

/*define*/
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
typedef pair<int, int> P;
static const int max_n = 10000, max_m = 10000;
static const int  INF = 1000000000;
int ci;
//vector<int> G[max_n];
//struct edge{int to, cost;};
//vector<edge> G[max_n];
//edge es[max_n];
int p[max_n], r[max_n];
class union_find{
    public:
    vector<int> parent;
    vector<int> sz;
    //初期化
    union_find(int n): parent(n), sz(n){
        for(int i=0;i<n;++i){
            parent[i] = i;
            sz[i] = 1;
        }
    }
    //親を探す
    int root(int i){
        //return parent[i]==i ? i:parent[i]=root(parent[i]);
        if(parent[i]==i) return i;
        else return parent[i]=root(parent[i]);
    }
    //i, jを結合
    void unite(int i, int j){
        i = root(i);
        j = root(j);
        if(i==j) return;
        if(sz[i] > sz[j]){
            parent[j] = i;
        }
        else{
            parent[i] = j;
            if(sz[i]==sz[j]){
                sz[j]++;
            }
        }
    }
    //iとjの親が同じか確認
    bool same(int i, int j){
        return root(i)==root(j);
    }
    //iのサイズを確認
    int size(int i){
        return sz[root(i)];
    }
};

int main(){
    int N;
    cin >> N;
    vector<ll> x(N), y(N);
    for (int i=0; i<N; ++i) cin >> x[i] >> y[i];
    vector<pair<ll, int>> vx(N), vy(N);
    for(int i=0; i<N; ++i){
        vx[i] = make_pair(x[i], i);
        vy[i] = make_pair(y[i], i);
    }
    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());
    vector<pair<ll, pair<int, int>>> E;
    for(int i=0; i<(int)vx.size()-1; ++i){
        E.push_back(make_pair(vx[i+1].first-vx[i].first, make_pair(vx[i+1].second, vx[i].second)));
    }
    for(int i=0; i<(int)vy.size()-1; ++i){
        E.push_back(make_pair(vy[i+1].first-vy[i].first, make_pair(vy[i+1].second, vy[i].second)));
    }
    sort(E.begin(), E.end());
    ll ans=0;
    union_find uf(N);
    for(int i=0; i<E.size(); ++i){
        int u = E[i].second.first;
        int v = E[i].second.second;
        if(!uf.same(u, v)){
            uf.unite(u, v);
            ans += E[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11248
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var a int64
	var b float64
	fmt.Scan(&a, &b)
	c := int64(b * 1000)
	x := big.NewInt(a)
	y := big.NewInt(c)
	z := new(big.Int).Mul(x, y)
	w := new(big.Int).Div(z, big.NewInt(1000))
	fmt.Println(w)
}


Measured memory_bytes: 1900
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll i,j;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k;
    cin>>n>>k;
    ll num=1;
    while(n--)
        num=min(num*2,num+k);
    cout<<num<<endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int r = scanner.nextInt();
        int g = scanner.nextInt();
        int b = scanner.nextInt();
        int n = scanner.nextInt();
        int ans = 0;
        for (int i = 0; r * i <= n; i++) {
            for (int j = 0; r * i + g * j <= n; j++) {
                if ((n - r * i - g * j) % b == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int X = scanner.nextInt();
        int Y = scanner.nextInt();

        for (int i = 0 ; i <= X ; i++) {
            int crane = i * 2;
            int turtle = (X - i) * 4;
            if (crane + turtle == Y) {
                System.out.println("Yes");
                return;
            }
        }

        System.out.println("No");
    }
}


Measured memory_bytes: 35796
using System;

namespace AtCoderBeginnerContest146
{
    class Program
    {
        static void Main(string[] args)
        {
            string week = Console.ReadLine();
            switch (week)
            {
                case "SUN":
                    Console.WriteLine("7");
                    break;
                case "MON":
                    Console.WriteLine("6");
                    break;
                case "TUE":
                    Console.WriteLine("5");
                    break;
                case "WED":
                    Console.WriteLine("4");
                    break;
                case "THU":
                    Console.WriteLine("3");
                    break;
                case "FRI":
                    Console.WriteLine("2");
                    break;
                case "SAT":
                    Console.WriteLine("1");
                    break;
            }
        }
    }
}


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

int main()
{
	std::vector<int> data;
	unsigned int ddata;
	int num;
	unsigned int maxvul;
	std::cin>>num;
	while(num){
		data.resize(num-1);
		maxvul=0;
		for(int i=0;i<num;i++){
			std::cin>>ddata;
			maxvul+=ddata;
		}
		ddata=maxvul;
		maxvul*=num;
		for(int i=0;i<num-1;i++){
			std::cin>>data[i];
		}
		std::sort(data.begin(),data.end(),std::greater<int>());
		
		for(int i=0;i<data.size();i++){
			ddata+=data[i];
			if(maxvul<ddata*(num-i-1)){
				maxvul=ddata*(num-i-1);
			}
		}
		std::cout<<maxvul<<std::endl;
		std::cin>>num;
	}
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
signed main() {
  int N; cin >> N;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  int minCost = (int)1e9;
  for(int y = -100; y <= 100; ++y) {
    int c = 0;
    REP(i,N) c += (A[i] - y) * (A[i] - y);
    minCost = min(minCost, c);
  }
  cout << minCost << endl;
}


Measured memory_bytes: 256
n=input()
w_s=list(input().split())
w=[int(s) for s in w_s]
a=sum(w)/2
i=0
aa=0
while aa < a:
    aa= aa + w[i]
    i=i+1

b=abs(sum(w[0:i])-sum(w[i:]))
c=abs(sum(w[0:i-1])-sum(w[i-1:]))
if b>c:
    print(c)
else:
    print(b)

Measured memory_bytes: 3064
/*  Begin at the beginning," the King said, very gravely, "and go on till you come to the end: then stop. */
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
uli abso(uli x){ return x<0?-x:x; }
int main(){
  uli a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  uli ans=-1;
  do{
    uli dif=a[0]*a[2]*((a[1]+1)/2-a[1]/2);
    if(ans==-1 || dif<ans)ans=dif;
  }while(next_permutation(a,a+3));
  cout<<ans<<endl;
  return 0;
}


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

vector<int> dig(10,1);
string cad, ans;

int funcion(int x){
	while(x > 0){
		int d = x % 10;
		x /= 10;
		if(dig[d] == 0)
		return 0;
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(NULL);
	int n,k,x,ans,i;
	cin>>n>>k;
	for(i=0; i<k; i++){
		cin>>x;
		dig[x] = 0;
	}
	for(i=n; i<99999; i++){
		if(funcion(i) == 1){
			ans = i;
			break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

void selectionSort(int *,int);

int main(){
  int i,N,A[100];

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  selectionSort(A,N);
  return 0;
}

void selectionSort(int *A,int N){
  int i,j,minj,x,count=0;
  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]) {
        minj=j;
      }
    }
    if(i!=minj){
      x=A[i];
      A[i]=A[minj];
      A[minj]=x;
      count++;
    }
  }
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i!=N-1) printf(" ");
  }
  printf("\n%d\n",count);
}


Measured memory_bytes: 2128
#include<cstdio>

int main(){
    int h1,m1,h2,m2,k;
    scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
    int t1 = h1*60+m1, t2 = h2*60+m2;
    int dt = t2-t1;
    if(dt<k) printf("0\n");
    else{
        int start = t2-k;
        printf("%d\n",start-t1);
    }
    return 0;
}


Measured memory_bytes: 1732
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

count = {}
for word in s:
    if not word in count:
        count[word] = 1
    else:
        count[word] += 1
for word in t:
    if not word in count:
        count[word] = -1
    else:
        count[word] -= 1

high_score = max(sorted(count.items(), key=lambda x: x[1], reverse=True)[0][1], 0)
print(high_score)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define MOD 1000000007

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

  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;

  return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int y, m, d;
  char s, t;
  cin >> y >> s >> m >> t >> d;

  if (m >= 5) {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
hs = list(map(int,input().split()))
pre1 = hs.pop(0)
pre1 -=1
for h in hs:
    if h>=pre1 +1:
        pre1 = h-1
    else:
        if h == pre1:
            pass
        else :
            print("No")
            break
else:
    print("Yes")


Measured memory_bytes: 14396
#include <stdio.h>
#include <math.h>

int main(){
	int N;
	int D;
	int X[10][10];
	scanf("%d %d",&N,&D);
	for(int i = 0;i < N;i++){
		for(int j= 0;j < D;j++){
			scanf("%d",&X[i][j]);
		}
	}
	int count = 0;
	float distance;
	for(int N1 = 0;N1 < N-1;N1++){
		for(int N2 = N1+1;N2 <N;N2++){
			distance = 0;
			for(int j= 0;j < D;j++){
				distance += (X[N1][j]-X[N2][j])*(X[N1][j]-X[N2][j]);
			}
			distance = sqrt(distance);
			if(ceil(distance) == floor(distance)){
				count++;
			}
		}
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
import bisect

s=input()
t=input()

sl=len(s)
tl=len(t)

r="abcdefghijklmnopqrstuvwxyz"
p=[[] for i in range(26)]

for i in range(sl):
  p[r.find(s[i])].append(i)

for i in range(26):
  if len(p[i])>0:
    p[i].append(p[i][0]+sl)

s=set()
for i in range(tl):
  s.add(t[i])
for c in s:
  if len(p[r.find(c)]) == 0:
     print(-1)
     exit()

ti, si = 0, -1
while ti < tl:
  si +=  p[r.find(t[ti])][bisect.bisect_right(p[r.find(t[ti])], si%sl)] - si%sl
  ti += 1

print(si+1)

Measured memory_bytes: 7564
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
int to_int(str& s)
{
    int res = 0, pw = 1;
    for (int i = sz(s) - 1; i >= 0; i--)
    {
        res += pw * (s[i] - '0');
        pw *= 10;
    }
    return res;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int k;
    cin >> k;
    set<str> cur;
    set<int> s;
    for (char i = '1'; i <= '9'; i++)
        cur.insert(str(1, i));
    for (int i = 0; i < 10; i++)
        s.insert(i);
    while (sz(s) < (int)(1E5 + 11))
    {
        set<str> nxt;
        for (str i : cur)
        {
            if (i.back() == '0')
            {
                nxt.insert(i + '1');
                nxt.insert(i + '0');
            }
            else if (i.back() == '9')
            {
                nxt.insert(i + '8');
                nxt.insert(i + '9');
            }
            else
            {
                nxt.insert(i + char(i.back() + 1));
                nxt.insert(i + i.back());
                nxt.insert(i + char(i.back() - 1));
            }
        }
        cur = nxt;
        for (str i : cur)
            s.insert(to_int(i));
    }
    vi v(all(s));
    cout << v[k] << endl;
    GAME_OVER;
}

Measured memory_bytes: 32512
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    x = inpl()
    for i in range(5):
        if x[i] != i+1:
            print(i+1)
            return
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 72932
<?php
$summar = explode(" ", trim(fgets(STDIN)));

$days = explode(" ", trim(fgets(STDIN)));
$count = 0;
for($i=0; $i<$summar[1]; $i++){
	$count += $days[$i];
}
if($summar[0]-$count > -1){
	echo $summar[0]-$count;
}else{
	echo -1;
}

Measured memory_bytes: 17048
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define sum(x) accumulate(all(x),0)
#define gll greater<ll>()


void solve(){
 string  s,t;
  cin >> s >> t;
  ll ans=0;
  rep(i,0,s.size()) if(s[i]!=t[i]) ans++;
  
  
  
  cout << ans << endl;
}

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

Measured memory_bytes: 3748
n =int(input())
first =[]
second =[]
for i  in range(n):
    d1 , d2 = map(int , input().split())
    first.append(d1)
    second.append(d2)

for i in range(n-2):
    count = 0
    for j in range(i ,i+3):
        if first[j]==second[j]:
            count +=1
        else:
            break
           
    if count ==3:
        print("Yes")
        break
else:
    print("No")


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
const int maxn=110;
const int drx[4]={1,-1,0,0};
const int dry[4]={0,0,-1,1};
int H,W,n;
struct node{
	int x,y;
}a[maxn];
long long val[maxn][maxn];
int dis[maxn][maxn];
long long ans;
long long Sum(long long x){
	return (x*(x+1)/2)%md;
}
int Abs(int x){
	return x<0?-x:x;
}
int getdis(const node &A,const node &B){
	return Abs(A.x-B.x)+Abs(A.y-B.y);
}
void get_ans(){
	for(int i=1;i<W;i++)
		ans=(ans+i*(long long)(W-i)%md*H%md*H)%md;
	for(int i=1;i<H;i++)
		ans=(ans+i*(long long)(H-i)%md*W%md*W)%md;
	for(int i=1;i<=n;i++){
		ans=(ans-Sum(H-a[i].x)*W%md+md-Sum(a[i].x-1)*W%md+md)%md;
		ans=(ans-Sum(W-a[i].y)*H%md+md-Sum(a[i].y-1)*H%md+md)%md;
	}
	ans=ans*2%md;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			ans=(ans+getdis(a[i],a[j]))%md;
}
int bx[maxn],by[maxn];
int vx[maxn],vy[maxn];
int mpx[1001000],mpy[1001000];
int cntx,cnty;
void build_val(){
	cntx=0,cnty=0;
	int numx,numy;

	for(int i=1;i<=n;i++)
		bx[i]=a[i].x;
	sort(bx+1,bx+n+1);
	numx=unique(bx+1,bx+n+1)-(bx+1);
	bx[0]=0,bx[numx+1]=H+1;
	for(int i=1;i<=numx+1;i++){
		if(bx[i]-bx[i-1]>1)
			vx[++cntx]=bx[i]-bx[i-1]-1;
		vx[++cntx]=1;
		mpx[bx[i]]=cntx;
	}
	cntx--;

	for(int i=1;i<=n;i++)
		by[i]=a[i].y;
	sort(by+1,by+n+1);
	numy=unique(by+1,by+n+1)-(by+1);
	by[0]=0,by[numy+1]=W+1;
	for(int i=1;i<=numy+1;i++){
		if(by[i]-by[i-1]>1)
			vy[++cnty]=by[i]-by[i-1]-1;
		vy[++cnty]=1;
		mpy[by[i]]=cnty;
	}
	cnty--;

	for(int i=1;i<=cntx;i++)
		for(int j=1;j<=cnty;j++)
			val[i][j]=vx[i]*(long long)vy[j]%md;
	for(int i=1;i<=n;i++)
		val[mpx[a[i].x]][mpy[a[i].y]]=-1;
}
queue<node> q;
bool out(int x,int y){
	if(x<1||x>cntx) return 1;
	if(y<1||y>cnty) return 1;
	return 0;
}
void BFS(node st){
	for(int i=1;i<=cntx;i++)
		for(int j=1;j<=cnty;j++)
			dis[i][j]=-1;
	dis[st.x][st.y]=0;
	q.push(st);
	int xx,yy;
	while(!q.empty()){
		st=q.front(),q.pop();
		for(int i=0;i<4;i++){
			xx=st.x+drx[i],yy=st.y+dry[i];
			if(out(xx,yy)) continue;
			if(val[xx][yy]==-1) continue;
			if(dis[xx][yy]!=-1) continue;
			dis[xx][yy]=dis[st.x][st.y]+1;
			q.push((node){xx,yy});
		}
	}
}
void updata(int x,int y){
	int dd;
	for(int i=1;i<=cntx;i++){
		for(int j=1;j<=cnty;j++){
			if(val[i][j]==-1) continue;
			dd=dis[i][j]-(Abs(x-i)+Abs(y-j));
			if(dd==0) continue;
			ans=(ans+val[x][y]*val[i][j]%md*dd)%md;
		}
	}
}
int main(){
//	freopen("I.in","r",stdin);
	scanf("%d%d%d",&H,&W,&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
		a[i].x++,a[i].y++;
	}
	get_ans();
	build_val();
	for(int i=1;i<=cntx;i++){
		for(int j=1;j<=cnty;j++){
			if(val[i][j]==-1) continue;
			BFS((node){i,j});
			updata(i,j);
		}
	}
	printf("%lld\n",(ans*((md+1)/2))%md);
	return 0;
}


Measured memory_bytes: 4608
#include <stdio.h>
int main(void){
	int t,h,s,tmp,at,ah,as;
	while(1){
		scanf("%d %d %d",&t,&h,&s);
		if(t<0)
			break;
		tmp=2*3600-(t*3600+h*60+s);
		at=tmp/3600;
		tmp%=3600;
		ah=tmp/60;
		as=tmp%60;
		printf("%02d:%02d:%02d\n",at,ah,as);
		tmp=(2*3600-(t*3600+h*60+s))*3;
		at=tmp/3600;
		tmp%=3600;
		ah=tmp/60;
		as=tmp%60;
		printf("%02d:%02d:%02d\n",at,ah,as);
	}
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  int X=(1ll<<N);
  map<int,int> M;
  rep(i,0,X){
    int Y; cin>>Y;
    M[Y]++;
  }
  vi A(1);
  auto p=*M.rbegin();
  A[0]=p.first;
  M[A[0]]--;
  if(M[A[0]]==0) M.erase(A[0]);
  rep(i,0,N){
    int P=A.size();
    rep(j,0,P){
      auto itr=M.lower_bound(A[j]);
      if(itr==M.begin()){
        cout<<"No"<<endl;
        return 0;
      }
      itr--;
      auto p=*itr;
      int Y=p.first;
      A.pb(Y);
      M[Y]--;
      if(M[Y]==0) M.erase(Y);
    }
  }
  cout<<"Yes"<<endl;
  }



Measured memory_bytes: 18808
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

// 最大公約数
uint64 gcd(uint64 a, uint64 b)
{
    uint64 tmp;
    if(b > a){ swap(a, b); }
    while(b > 0){ tmp = a % b; a = b; b = tmp; }
    return a;
}
// 最小公倍数
uint64 lcm(uint64 a, uint64 b)
{
    return (a/gcd(a,b)) * b;
}

void func(void)
{
//DEBUG_OUT("----\n");
    int N;
    cin >> N;

    uint64 ans = 1;
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        ans = lcm(ans, tmp);
    }

DEBUG_OUT("-----\n");
    cout << ans << endl;
    
    return;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int,int> P;

vector<P> G[100000];
int hour[100000];

int main(){
    int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].emplace_back(c,b);
    }
    for(int i=0;i<N;i++){
        sort(G[i].begin(),G[i].end());
    }
    priority_queue<P,vector<P>,greater<P>> que;
    fill(hour,hour+N,1000000001);
    que.emplace(0,0);
    hour[0]=0;
    hour[N-1]= -1;
    while(!que.empty()){
        P p = que.top(); que.pop();
        int t=p.first,v=p.second;
        if(t!=N-1&&hour[v]<t) continue;
        if(t==N-1&&hour[v]>t) continue;
        for(auto ite=lower_bound(G[v].begin(),G[v].end(),P(t,0));ite!=G[v].end();ite++){
            int t2=ite->first, to=ite->second;
            if(to==N-1){
                if(hour[to]<t2){
                    que.emplace(t2,to);
                    hour[to]=t2;
                }
            }else{
                if(hour[to]>t2){
                    que.emplace(t2,to);
                    hour[to]=t2;
                }
            }
        }
    }
    cout<<hour[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 9504
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
struct DSU {
    int N;
    vi dt;
    DSU(int n) : N(n), dt(n, -1) {}

    int root(int v){
        if (dt[v] < 0) return v;
        return dt[v] = root(dt[v]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x,y);
        dt[x] += dt[y];
        dt[y] = x;
        return true;
    }

    int size(int v) {return -dt[root(v)];}
};
#endif


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

    int N, K, L; cin >> N >> K >> L;
    vi P(K), Q(K);
    REP(i, K) {
        cin >> P[i] >> Q[i];
        P[i]--; Q[i]--;
    }
    vi R(L), S(L);
    REP(i,L) {
        cin >> R[i] >> S[i];
        R[i]--; S[i]--;
    }

    DSU ud(N);
    REP(i, K) {
        ud.unite(P[i], Q[i]);
    }

    DSU ul(N);
    REP(i, L) {
        ul.unite(R[i], S[i]);
    }

    map<pii, int> mp;
    REP(i,N) {
        mp[pii(ud.root(i), ul.root(i))]++;
    }

    vi ans(N);
    REP(i,N) {
        ans[i] = mp[pii(ud.root(i), ul.root(i))];
    }

    cout << ans[0];
    FOR(i, 1, N) cout << " " << ans[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 15872
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    long long X;
    long long year=0;
    long long money;
    scanf("%lld",&X);
    money=100;
    for( ;money<X;year++)
    {
        money *= 1.01;
    }
    printf("%lld",year);

    return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (auto &e : x)
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
//#define int long long
using namespace std;
using ii = pair<int, int>;

signed main() {
    FAST_IO;
    //setIO("input.txt", "output.txt");

    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No");
}


Measured memory_bytes: 3608
n = int(input())
p = [0]*n
p2 = []
for i in range(n):
    m = int(input())
    p[m-1] = i
    p2.append(m)

succ = [1] * n

for i in range(1,n):
    if p[i-1] < p[i]:
       succ[i] = succ[i-1] + 1

"""
print(p2)
print(p)
print(succ)
"""

print(n-max(succ))

Measured memory_bytes: 60960
import math

def cul(i,x):
    if tmp[i][x]==-1:
        tmp[i][x]=( cul(i+1,x)*(N-1-i) + cul(i+1,x%a[i]) )%MOD
    return tmp[i][x]

MOD=10**9+7
N,x=map(int,input().split())

a=list(map(int,input().split()))
a.sort(reverse=True)
tmp= [[-1 for j in range(x+1)] for i in range(N)] + [[j for j in range(x+1)]]

print(cul(0,x))

Measured memory_bytes: 192028
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		String s;
		int ac_count = 0;
		int wa_count = 0;
		int tle_count = 0;
		int re_count = 0;

		for(int i=0; i<n; i++) {
			s = sc.next();
			if(s.equals("AC")) {
				ac_count++;
			}else if(s.equals("WA")) {
				wa_count++;
			}else if(s.equals("TLE")) {
				tle_count++;
			}else if(s.equals("RE")) {
				re_count++;
			}
		}

		System.out.println("AC x " + ac_count);
		System.out.println("WA x " + wa_count);
		System.out.println("TLE x " + tle_count);
		System.out.println("RE x " + re_count);
	}

}


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if((A+B)>(C+D)){
  	cout << "Left" << endl;
  }else if((A+B)==(C+D)){
  	cout << "Balanced" << endl;
  }else{
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
def isa(s):
    if s == s[::-1]:
        return 1
    else:
        return 0

s = input()
n =int( (len(s)-1)/2)
list = list(s)
list1 = list[0:n]
list2 = list[n+1:2*n+1]

if list1 != list2:
    print('No')
elif isa(','.join(list1)) != 1:
    print('No')
else:
    print('Yes')



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define MAX 100005
using namespace std;
int a[MAX];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int ans;
    ans=max(0,a[n/2+1]-a[n/2]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
  
  int a,b,c,d,e,k;
  
  0<=a<b<c<d<e<=123;
  
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);
  scanf("%d",&k);
  
  if(e-a<=k){
    printf("Yay!");}
  else if(e-a>k){
    printf(":(");}
  
  
  
  
  
  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];

  int sum = accumulate(v.begin(), v.end(), 0);
  int max = *max_element(v.begin(), v.end());
  cout << sum - max / 2 << endl;
}


Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  string s;cin>>s;
  string ans="AC";
  if(s[0]!='A')ans="WA";
  int l=s.size();
  int cntc=0;
  int cnta=0;
  for(int i=1;i<l;++i){
    if(isupper(s[i])&&(i==1||i==l-1))
      ans="WA";
    if(i>1&&i<l-1&&s[i]=='C')
      cntc++;
    if(isupper(s[i]))
      cnta++;
  }
  if(cntc!=1||cnta!=1)
      ans="WA";
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string S;
    cin>>S;
    if(S=="Sunny")
    {cout<<"Cloudy";}
    else if(S=="Cloudy"){
            cout<<"Rainy";}
    else if (S=="Rainy"){
        cout<<"Sunny";
    }
    return 0;
}



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

#define REP(i,n) for(ll i=0;i<(n);i++)
#define REAP(i,a,n) for(ll i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

ll rd[101][101];

void solve(ll n){
    for(ll k=0;k<n;k++){
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                rd[i][j]=min(rd[i][j],rd[i][k]+rd[k][j]);
            }
        }
    }
}


void init(){
    REP(i,101){
        REP(j,101){
            rd[i][j]=1e9;
            if(i==j)rd[i][j]=0;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    ll n,m,s,g1,g2;
    while(cin>>n>>m>>s>>g1>>g2,n){
        s--;
        g1--;
        g2--;
        ll a,b,c;
        init();
        REP(k,m){
            cin >> a >> b >> c;
            a--;
            b--;
            rd[a][b]=c;
        }
        solve(n);

        ll res=INT_MAX;
        for(ll i=0;i<n;i++){
            res = min(res, rd[s][i]+rd[i][g1]+rd[i][g2]);
        }
        cout << res << endl;
    }
}



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

int main() {
  long n,k,ans=0,aaa=0;
  cin >> n >> k;
  map<long,long> x;
  map<long,long> y;
  vector<long> data(n);
  vector<long> a(n);
  for(long i=0;i<n;i++) cin >> a[i];

  for(long i=0;i<n;i++) {
    x[aaa]++;
    data[i]=aaa;
    if(i+1>=k) y[data[i-k+1]]++;
    aaa=(aaa+a[i]-1)%k;
    ans=ans+x[aaa]-y[aaa];
  }

  cout << ans << endl;
}

Measured memory_bytes: 28416
#include <cinttypes>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <limits>
using ui16 = std::uint_fast16_t;
using ui32 = std::uint_fast32_t;
using std::scanf;
using std::printf;
const ui32 N_MAX = 100000;
ui32 h[N_MAX], F[N_MAX];
int main()
{
	ui32 N;
	ui16 K;
	scanf("%" SCNuFAST32 "%" SCNuFAST16, &N, &K);
	for (ui32 i = 0; i < N; ++i)
	{
		scanf("%" SCNuFAST32, h + i);
		if (i)
		{
			F[i] = std::numeric_limits<ui32>::max();
			for (ui32 j = i > K ? i - K : 0; j < i; ++j)
				F[i] = std::min(F[i], F[j] + (h[i] > h[j] ? h[i] - h[j] : h[j] - h[i]));
		}
	}
	printf("%" PRIuFAST32 "\n", F[N - static_cast<ui32>(1)]);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> f(10000);
  for(int x = 1; x < 99;++x){
    for(int y = 1; y < 99 ; ++y){
      for(int z = 1;z < 99 ; ++ z){
        int a = x*x + y*y + z*z + x*y + y*z + z*x;
        if(a >= 1 && a <= 10000){
          f.at(a-1) ++;
        }
      }
    }
  }
  rep(i,N){
    cout << f.at(i) << endl;
  }
  return 0;
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


template <typename T = i64>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template <typename T = i64>
bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}


signed main(){

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

    int n;
    cin >> n;
    set<int> s;
    for(int i = 0; i < n; ++i){
        int k;
        cin >> k;
        s.emplace(k);
    }
    cout << s.size() << endl;
}




Measured memory_bytes: 7724
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    LL a;
    cin >> n >> a;
    n=n%500;
    if(a>=n){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std ;
 int main()
 {
    int n,q;
    cin>>n>>q;
    map<int ,vector<int>>  t;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        t[a].push_back(b); 
    }   int a[n+1];
    for(int i=0;i<n+1;i++)
        a[i]=0;
    while(q--)
        {
            int v,c;
            cin>>v>>c;
              a[v]=a[v]+c;
        }

        for(auto vertex:t)
        {
               for(int j=0;j<vertex.second.size();j++)
               {
                a[vertex.second[j]]=a[vertex.second[j]]+a[vertex.first];
               }
        }
        for(int i=1;i<n+1;i++)
        {
            cout<<a[i]<<' ';
        }

 }

Measured memory_bytes: 25088
#include"iostream"
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<list>
#include<map>
#include<string>
#include<algorithm> 
#include <queue> 
#include <sstream>
#include <fstream>
#include<cmath>
#define INF 100000000000
#define LL long long
using namespace std;
map<LL , LL> m;
long long N, M, K, ans,A,B;



int main() {
	cin >> N>>M;
	vector<pair<LL, LL>> v(N);
	for (int i = 0; i <N; i++) {
		cin >> A >> B;
		v[i] = make_pair(A, B);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < N; i++) {
		if (M == 0)break;
		if (v[i].second < M) {
			ans += v[i].first*v[i].second;
			M -= v[i].second;
		}
		else {
			ans += v[i].first*M;
			M = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii; 
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
  int a,b,c;
  cin>>a>>b>>c;
  cout<<min(a+b,min(a+c,b+c));
    return 0; 
}

Measured memory_bytes: 256
from itertools import permutations
n,m=map(int,input().split())
adj=[[] for i in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    adj[a].append(b)
    adj[b].append(a)
    
sum=0
for i in permutations(list(range(1,n))):
    i = [0]+list(i)
    c=1
    for j in range(n-1):
        if not(i[j+1] in adj[i[j]]):
            c*=0
    sum+=c
            
print(sum)

Measured memory_bytes: 40048
import java.math.BigInteger
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val x = sc.nextInt()
    println((1..n).map { Math.abs(x - sc.nextInt()) }.reduce { acc, i -> gcd(acc, i) })
}

fun gcd(acc: Int, i: Int): Int {
    return BigInteger(acc.toString()).gcd(BigInteger(i.toString())).toInt()
}


Measured memory_bytes: 71512
#include<iostream>

using namespace std;

int main(){
  
  int n;
  while(cin >> n && n>0){
  int a,b;
  int res_a=0,res_b=0;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    if(a>b) res_a+=(a+b);
    else if(a<b) res_b+=(a+b);
    else{res_a+=a;res_b+=b;}
  }
  cout << res_a << " " << res_b << endl;
}
}

  

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
int main(void){
    ll x,y;
    cin>>x>>y;
    bool ans=false;
    rep(0,i,x+1){
        ll j=x-i;
        if(2*i+4*j==y){
            ans=true;
        }
    }
    if(ans)cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	int T, K;
	scanf ("%d %d", &T, &K);
	
	for (int i = T; i <= K; i++){
		if (i % n == 0){
			puts("OK");
			return 0;
		}
		else continue;
	}
	puts("NG");
	return 0;
}

Measured memory_bytes: 1656
n=int(input())
ab = [[0, 0, 0] for i in range(n)]
for i in range(n):
    a, b = (int(x) for x in input().split())
    ab[i][0] = a+b
    ab[i][1] = a
    ab[i][2] = b

ab.sort(reverse=True)

ans = 0

for i in range(n):
    if i%2==0:
        ans += ab[i][1]
    else:
        ans -= ab[i][2]

print(ans)

Measured memory_bytes: 56880
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    vector<int> w, s;
    rep(i, 0, 31){
        rep(j, 0, 31){
            if(i == 0 && j == 0) continue;
            int now = (a * i + b * j) * 100;
            if(now > f) break;
            w.push_back(now);
        }
    }
    rep(i, 0, 3001){
        rep(j, 0, 3001){
            int now = c * i + d * j;
            if(now > f) break;
            s.push_back(now);
        }
    }
    double MAX = -1.0;
    int as = 0, aw = 0;
    rep(i, 0, w.size()){
        rep(j, 0, s.size()){
            if(w[i] + s[j] > f) continue;
            if(w[i] / 100 * e < s[j]) continue;
            double tmp = (double)s[j] / (double)(w[i] + s[j]);
            if(tmp > MAX){
                MAX = tmp;
                as = s[j];
                aw = w[i];
            }
        }
    }
    cout << as + aw << " " << as << endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define inf          0x3f3f3f3f
#define go(a,b,c)    for(int a=b;a<=c;a++)
#define gov(a,b)     for(int a=0;a<b.size();a++)
#define rgo(a,b,c)   for(int a=b;a>=c;a--)
#define sf(a)        scanf("%d",&a)
#define sff(a,b)     scanf("%d%d",&a,&b)
#define sfff(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define eps          1e-9
#define ft           first
#define sd           second
#define prt(a)       printf("%d\n",a)
#define prn(i,n,a)   printf("%d%c",a,i==n?'\n':' ')
#define pb           push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef double db;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int maxn=1e5+10;
const LL mod=1e9+7;
LL fsp(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans%mod;
}
int read()
{
	int f=0,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
//=======================================================
int n,a[maxn];
LL sm[maxn];
void work()
{
	go(i,1,n)sf(a[i]);
	LL tt=0;
	go(i,1,n)
	{
		sm[i]=sm[i-1]+a[i];
		if(i%2&&sm[i]<=0)
		{
			tt+=1-sm[i];
			sm[i]=1;
		}
		else if((i-1)%2&&sm[i]>=0)
		{
			tt+=sm[i]+1;
			sm[i]=-1;
		}
	}
	LL ans=0;
	go(i,1,n)
	{
		sm[i]=sm[i-1]+a[i];
		if(i%2&&sm[i]>=0)
		{
			ans+=sm[i]+1;
			sm[i]=-1;
		}
		else if((i-1)%2&&sm[i]<=0)
		{
			ans+=1-sm[i];
			sm[i]=1;
		}
	}
	cout<<min(ans,tt)<<endl;
}
int main()
{
	while(~sf(n))
	{
		work();
	}
	return 0;
}

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

int main(){
  int n,k;
  int s[100],b;

  while(cin >> n >> k){
    if(n==0 && k==0)break;
    for(int i=0;i<k;i++)cin >> s[i];

    for(int i=0;i<n;i++){
      for(int j=0;j<k;j++){
	cin >> b;
	s[j] -= b;
      }
    }
    
    bool ans = true;
    for(int i=0;i<k;i++){
      if(s[i] < 0)ans = false;
    }

    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1152
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double x = sc.nextDouble();
        sc.close();

        if (x / a >= (a * b) / 2) {
            System.out.println(Math.toDegrees(Math.atan((2 * b) / a - (2 * x) / Math.pow(a, 3))));
        } else {
            System.out.println(Math.toDegrees(Math.atan(a * Math.pow(b, 2) / (2 * x))));
        }
    }
}

Measured memory_bytes: 23124