akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())

edges = [(0, i) for i in range(1, n)]
cnt = (n-1) * (n-2) // 2

if k == cnt:
    print(n-1)
    for u, v in edges:
        print(u+1, v+1)
    exit()

for i in range(1, n-1):
    for j in range(i+1, n):
        edges.append((i, j))
        cnt -= 1
        if cnt == k:
            print(len(edges))
            for u, v in edges:
                print(u+1, v+1)
            exit()

print(-1)


Measured memory_bytes: 3992
K, S = map(int, input().split())
count = 0
for x in range(K + 1):
    yz = S - x
    if yz < 0:
        break
    elif yz <= K:
        count += yz + 1
    elif yz <= 2*K:
        count += K - (yz-K) + 1
print(count)

Measured memory_bytes: 3060
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

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

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion


//ABC  115-C Chrismas Eve

int main(void) {
	int        i, n, k;
	int        h[100001];

	scanf("%d %d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &h[i]);

	qsort(h, n, sizeof(int), i_asort);

	//for (i = 0; i < n; i++)
	//	printf("%ld ", h[i]);
	//printf("\n");

	int min = 1000000001, tmp;
	for (i = 0; i <= n - k; i++) {
		tmp = h[i + k - 1] - h[i];
		min = _min(tmp, min);
	}

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


Measured memory_bytes: 2700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(row,h) rep(col,w){
        if(s[row][col] == '#') continue;
        int ans = 0;
        for(int i = -1; i <= 1; i++){
            for(int j = -1; j <= 1; j++){
                if(row + i < 0 || col + j < 0) continue;
                if(row + i >= h || col + j >= w) continue;
                if (s[row+i][col+j] == '#') ans++;
            }
        }
        s[row][col] = ans+'0';
    }
    rep(i,h) cout << s[i] << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define int      long long
# define all(vc)   vc.begin(),vc.end()
# define all2(vc)  vc.rbegin(),vc.rend()
# define pb        push_back
# define vec       vector
# define fi        first 
# pragma GCC optimize "-O3"
# define se        second
# define speed     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define time      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std; 
map <int, int> mp;
void solve(){
    int n = 0;
    string s;
    cin >> s;
    if( s == "ABC" ) cout << "ARC";
    else cout << "ABC";
}
int32_t main(){
    speed;
    int T = 1;
    //cin >> T;
    while( T-- ){
         solve();
         cout<<'\n';
    }
    time;
}
 

Measured memory_bytes: 3844
s=input()+'!'
l=len(s)
ans=1
pos=1
tmp=s[0]
flag=0
while pos<l:
  if s[pos]!=tmp:
    tmp=s[pos]
    ans+=1
    pos+=1
  else:
    if s[pos]==tmp:
      tmp=s[pos:pos+2]
      ans+=1
      pos+=2
ans-=1
print(ans)

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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){

  string s;   cin >> s;
  for(int i = 0 ; i < s.size() - 1 ; i++){
	if(s[i] == 'A' && s[i + 1] == 'C'){
		cout << "Yes" << endl;
      	return 0;
    }
  }
  
  cout << "No" << endl;
  return 0;
}


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

using namespace std;

using ll = long long;

int num(int n) {
  int ret = 0;
  while (n) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  int ans = 1e9;
  for (int i = 1; i < n; ++i) {
    int j = n - i;
    ans = min(ans, num(i) + num(j));
  }
  cout << ans << 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 all(x) (x).begin(), (x).end()

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

    // start
    int a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200 ? s : "red") << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

void solve()
{
    ll N;
    vll P;
    cin >> N;
    for1(i,N) {
        ll p;
        cin >> p;
        P.push_back(p);
    }
    ll ans = 0;
    for1(i,N-2) {
        if ((P[i] < P[i+1] && P[i+1] < P[i+2])
        ||  (P[i] > P[i+1] && P[i+1] > P[i+2])) {
            ++ans;
        }
    }

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 256
// @Author :- Gaurav Bharti
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int,int> 
#define mapll map<ll,ll>
#define all(a) a.begin(),a.end()
#define test int t; cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define ItsFUN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
const int MIN = INT_MIN;
const int MAX = INT_MAX;

bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b) {
	return (a.second < b.second) ;
}

ll binpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b&1) res = res * a;
		a = a*a;
		b = b >> 1;
	}

	return res;
}


/*
BHAI EFFORT DAAL
*/


int main(){
	ItsFUN;

	int n; cin >> n;
	vii a(n),b(n),c(n);

	for(int i = 0; i < n; ++i) {
		c[i] = i+1;
	}

	for(int &i : a) cin >> i;
	for(int &i : b) cin >> i;

	if(a==b) {
		cout << 0 << "\n";
		return 0;
	}

	int cnt = 0, l = 0, r = 0;
	do{
		if(c == a) {
			l = cnt; 
		}
		else if( c == b) {
			r = cnt;
		}
		++cnt;
	}while(next_permutation(c.begin(),c.end()));

	cout << abs(r-l) << "\n";

	return 0;
}

Measured memory_bytes: 3628
mat = [map(int ,raw_input().split()) for _ in range(3)]
def f(m):
	return (m[1] - m[0], m[2] - m[1])
b = True
s =set([])
for l in mat:
	s.add(f(l))
if len(s) >1:
	b = False
s = set([])
for j in range(3):
	c = [mat[i][j] for i in range(3)]
	s.add(f(c))
if len(s) >1:
	b = False
print 'Yes' if b else 'No'

Measured memory_bytes: 64396
#include <stdio.h>
#include <string.h>
char X[1001];
char Y[1001];
int c[1001][1001];
int n;

int lcs(){
  int m,n,i,j;
  m=strlen(X);
  n=strlen(Y);
  for(i=1;i<=m;i++){
    c[i][0]=0;
  }
  for(j=0;j<=n;j++){
    c[0][j]=0;
  }
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(X[i-1]==Y[j-1]){
	c[i][j]=c[i-1][j-1]+1;
      } else if(c[i-1][j]>=c[i][j-1]){
	c[i][j]=c[i-1][j];
      }else{
	c[i][j]=c[i][j-1];
      }
    }
  }
  return c[m][n];
}

int main(){
  scanf("%d",&n);
  int i;
  for(i=0;i<n;i++){
    scanf("%s",X);
    scanf("%s",Y);
    
    printf("%d\n",lcs());
  }


  return 0;
}

Measured memory_bytes: 4516
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  ll n,k; cin>>n>>k; ll a[n];
  rep(i,n){
    cin>>a[i];
    a[i]-=1;
  }
  ll b[n];
  b[0]=0;
  ll m,p;
  map<ll,ll> mp;
  mp[0]++;
  for(int i=1;i<n;i++){
    b[i]=a[b[i-1]];
    mp[b[i]]++;
    if(mp[b[i]]>=2){
      for(ll j=0;j<=i;j++){
        if(b[j]==b[i]){
          m=j;
          break;
        }
      }
      p=i-m;
      break;
    }  
  }
  if(k<=m){
    cout<<b[k]+1;
  }else{
    ll x=m+(k-m)%p;
    cout<<b[x]+1;
  }
}


Measured memory_bytes: 19008
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<long long, long long> P;
int main(){
    int N;
    cin >> N;
    vector<P> A(N);
    for(int i = 0; i < N; i++) {
        long long a, b;
        cin >> a >> b;
        A[i] = P(b, a);
    }
    sort(A.begin(), A.end());
    long long temp = 0;
    for(int i = 0; i < N; i++){
        temp += A[i].second;
        if(temp > A[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 6432
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
 <url:https://agc005.contest.atcoder.jp/tasks/agc005_a>
 問題文============================================================
 文字列 X が与えられます。X の長さは偶数であり、半分は S 、もう半分は T からなります。
 
 高橋君は ST という文字列が苦手です。なので以下の操作を 10^10000 回行うことにしました。
 
 X の(連続な)部分文字列で ST となるもののうち、最も左側にあるものを取り除く。存在しないならば何もしない。
 最終的に X は何文字になるかを求めてください。
 
 =================================================================
 
 解説=============================================================
 
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    string X; cin >> X;
    stack<string> st;
    for(int i = 0; i < (int)X.length(); i++){
        if(X[i] == 'S') st.push("S");
        else{
            if(!st.empty()){
                string c = st.top();
                if(c == "S") {
                    st.pop();
                    continue;
                }
            }
            st.push("T");
        }
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 11412
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;

#define A_MAX 25

typedef struct _tree {
    int parent;
    int left;
    int right;
} Tree;


void preorder(Tree *nodes, int n, int i) 
{
    printf(" %d", i);
    if (nodes[i].left != -1) {
        preorder(nodes, n, nodes[i].left);
    }
    if (nodes[i].right != -1) {
        preorder(nodes, n, nodes[i].right);
    }
    
    return;
}

void inorder(Tree *nodes, int n, int i) 
{
    if (nodes[i].left == -1) {
        printf(" %d", i);
    }
    else {
        inorder(nodes, n, nodes[i].left);
        printf(" %d", i);
    }
    if (nodes[i].right != -1) {
        inorder(nodes, n, nodes[i].right);
    }
    
    return;
}

void postorder(Tree *nodes, int n, int i) 
{
    if (nodes[i].left != -1) {
        postorder(nodes, n, nodes[i].left);
    }

    if (nodes[i].right != -1) {
        postorder(nodes, n, nodes[i].right);
    }
    
    printf(" %d", i);

    return;
}


int main() {
    int n;
    Tree nodes[A_MAX];

    cin >> n;

    for (int i = 0; i < n; i++) {
        nodes[i].parent = -1;
        nodes[i].left = -1;
        nodes[i].right = -1;
    }

    
    // input
    for (int i = 0; i < n; i++) {
        int id, left, right;
        cin >> id >> left >> right;
        nodes[id].left = left;
        nodes[id].right = right;
        if (left != -1) {
            nodes[left].parent = id;
        }
        if (right != -1) {
            nodes[right].parent = id;
        }
    }

    // search root
    int root;
    for (int i = 0; i < n; i++) {
        if (nodes[i].parent == -1)  {
            root = i;
            break;
        }
    }

    printf("Preorder\n");
    preorder(nodes, n, root);
    printf("\n");

    printf("Inorder\n");
    inorder(nodes, n, root);
    printf("\n");

    printf("Postorder\n");
    postorder(nodes, n, root);
    printf("\n");

    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
using namespace std;

int gcd(int a, int b){
	if (!a) return b;
	return gcd(b%a,a);
}
int main(){
    ll k, sum=0;
    cin >> k;
    for (int i=1; i<=k; i++){
    	for (int j=1; j<=k; j++){
    		for (int l=1; l<=k; l++){
    			sum+=gcd(i,gcd(j,l));
    		}
    	}
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << "\n";
    return 0;
}

Measured memory_bytes: 3688
package main

import (
	"fmt"
)

func main() {
	var a,b string
	fmt.Scan(&a,&b)

	if a == "H" {
		fmt.Println(b)
	} else if  b == "D" {
		fmt.Println("H")
	} else {
		fmt.Println("D")
	}
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

import sys
from itertools import combinations_with_replacement

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, Q = MAP()
ABCD = []
for i in range(Q):
    a, b, c, d = MAP()
    ABCD.append((a-1, b-1, c, d))

ans = 0
for comb in combinations_with_replacement(range(1, M+1), N):
    cnt = 0
    for a, b, c, d in ABCD:
        if comb[b] - comb[a] == c:
            cnt += d
    ans = max(ans, cnt)
print(ans)


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

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut scanner = Scanner::new(cin);
  scanner.new_line();
  let (r, c) = scan!(scanner; usize, usize);
  let mut sheet: Vec<Vec<i64>> = Vec::with_capacity(r + 1);
  for i in 0..r {
    sheet.push(Vec::with_capacity(c + 1));
    scanner.new_line();
    for _ in 0..c {
      let tmp = scanner.get();
      sheet[i].push(tmp);
    }
    let s = sheet[i].iter().sum();
    sheet[i].push(s);
  }
  sheet.push(Vec::with_capacity(c + 1));
  for j in 0..c + 1 {
    let mut s = 0;
    for i in 0..r {
      s += sheet[i][j];
    }
    sheet[r].push(s);
  }
  for i in 0..r + 1 {
    let col: Vec<String> = sheet[i].iter().clone().map(|v| v.to_string()).collect();
    println!("{}", col.join(" "));
  }
}



Measured memory_bytes: 5056
def main():
    cross_sections = input()
    s1 = []
    s2 = []
    total_surface = 0
    for i, cross_section in enumerate(cross_sections):
        if cross_section == '\\':
            s1.append(i)
        elif cross_section == '/' and s1:
            ip = s1.pop()
            # calc total surface
            sub_surface = i - ip
            total_surface += sub_surface
            # calc sub surface
            for s in reversed(s2):
                if s[0] > ip:
                    sub_surface += s2.pop()[1]
                else:
                    break
            s2.append((ip, sub_surface))

    print(total_surface)
    if s2:
        print(len(s2), ' '.join(map(lambda x: str(x[1]), s2)))
    else:
        print(len(s2))


if __name__ == "__main__":
    main()



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

int main() {
    int N;
    cin >> N;
    int S = 0;
    int i = 1;
    while (N/i > 0){
        S += N/i - (N/(i*10))*10;
        i *= 10;
    }
    if (N%S == 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b; i<e; i++)

int main(){
        int n, m, x;
        scanf("%d %d %d", &n, &m, &x);
        int s = 0, g = 0;
        REP(i, 0, m){
            int a;
            scanf("%d", &a);
            if(a>x) g++;
            else s++;
        }
        printf("%d\n", std::min(s, g));
        return 0;
}

Measured memory_bytes: 3820
import sys
from fractions import gcd


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    # i番目から左の全ての要素のGCD
    gcd_from_left = [None] * N
    gcd_from_left[0] = A[0]
    # i番目から右の全ての要素のGCD
    gcd_from_right = [None] * N
    gcd_from_right[-1] = A[-1]

    for i in range(1, N):
        gcd_from_left[i] = gcd(A[i], gcd_from_left[i - 1])

    for i in range(N - 2, -1, -1):
        gcd_from_right[i] = gcd(A[i], gcd_from_right[i + 1])

    gcd_from_right.sort()

    # 要素iを取り除いたときの最大公約数
    ans = max(gcd_from_left[-2], gcd_from_right[1])
    for i in range(1, N - 1):
        tmp = gcd(gcd_from_right[i + 1], gcd_from_left[i - 1])
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16144
#include<stdio.h>
int main(void){
    int n,i,age,a,b,c,d,e,f,g;
    for(;;){
        a=0,b=0,c=0,d=0,e=0,f=0,g=0;
        scanf("%d",&n);
        if(n==0)
            break;
        for(i=0;i<n;i++){
            scanf("%d",&age);
            /*while(age<10){
                a++;
            }*/
            if(age<10)
                a++;
            else if(10<=age&&age<20)
                b++;
            else if(20<=age&&age<30)
                c++;
            else if(30<=age&&age<40)
                d++;
            else if(40<=age&&age<50)
                e++;
            else if(50<=age&&age<60)
                f++;
            else
                g++;
        }
        printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",a,b,c,d,e,f,g);

    }
    return 0;
}

Measured memory_bytes: 596
n, m = map(int, input().split())
ship = {i:False for i in range(1, n+1)}
bl = []
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        ship[b] = True
    elif b == n:
        bl.append(a)

for i in bl:
    if ship[i] == True:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    bitset<8> bit;
    int count = 0;
    for(int i=0;i<n;i++){
        int a;cin >> a;
        if(a < 400){
            bit[0] = true;
        }else if(a < 800){
            bit[1] = true;
        }else if(a < 1200){
            bit[2] = true;
        }else if(a < 1600){
            bit[3] = true;
        }else if(a < 2000){
            bit[4] = true;
        }else if(a < 2400){
            bit[5] = true;
        }else if(a < 2800){
            bit[6] = true;
        }else if(a < 3200){
            bit[7] = true;
        }else{
            count++;
        }
    }

    cout << max(1, int(bit.count())) << " " << int(bit.count())+count << endl;

    return 0;
}


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//combination mod prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
ll n, m ;
cin >> n >> m;
mint now = 1;
combination c(n);
for(int i= m;i>m-n;i--) now *=i;
now *= now;
mint ans = now;

for(int k= 1; k<=n; k++){
    now = now /(m-k+1)/(m-k+1);
    now*=m-k+1;
    if(k%2==0)ans -= -c(n, k)*now;
     else ans -= c(n, k)*now;
}  
cout << ans<<endl;
 return 0;
}

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

int main()
{
    int n, rank;
    char suit;
    vector<char> suits{'S', 'H', 'C', 'D'};
    map<char, vector<bool>> cards;

    for (int i = 0; i < suits.size(); i++)
        cards[suits[i]] = vector<bool>(13, true);

    cin >> n;
    while (cin >> suit >> rank && n--)
        cards[suit][rank -1 ] = false;

    for (int i = 0; i < suits.size(); i++ )
        for (int j = 0; j < 13; j++)
            if (cards[suits[i]][j])
                cout << suits[i] << " " << j + 1 << endl;

    return 0;
}



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

int main(){
    int x, a, b;
    cin >> x >> a >> b;

    if(abs(x-a) > abs(x-b)){
        cout << "B" <<endl;
    }else{
        cout << "A" << endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    string s,t;
    cin >> s;
    cin >> t;
    int n = s.size();
    vi a(26,-1),b(26,-1);
    rep(i,n){
        int p = t[i] - 'a';
        int q = s[i] - 'a';
        if(a[p] != -1 || b[q] != -1){
            if(a[p] != q || b[q] != p){
                cout << "No" << endl;
                return 0;
            }
        }
        a[p] = q;
        b[q] = p;
    }
    cout << "Yes" << endl;
}


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


int main() {
    int N; cin >> N;
    string ans = "No";

    for (int i = 1; i <= 9; i++) for (int j = 1; j <= 9; j++) {
        if(i * j == N) ans = "Yes";
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstring>
#include<cstdlib>

using namespace std;

bool mem[1001];

bool FizzBuzz(int a,string str){
	if(str=="FizzBuzz"){
		if(a%15==0)return true;
		else return false;
	}
	else if(str=="Fizz"){
		if(a%3==0)return true;
		else return false;
	}
	else if(str=="Buzz"){
		if(a%5==0)return true;
		else return false;
	}
	else{
		const char* ss=str.c_str();
		int s=atoi(ss);
		if(s==a && a%3!=0 && a%5!=0)return true;
		else return false;
	}
}

int main(void){
	while(1){
		int a,b,m,n;
		vector<string> str;
		cin >> m >> n;
		if(m==0 && n==0)break;
		for(a=0;a<=1000;a++){
			mem[a]=true;
		}
		for(a=1;a<=n;a++){
			string s;
			cin >> s;
			str.push_back(s);
		}
		int j=1,jj;
		for(a=1;a<=n;a++){
			if(!FizzBuzz(a,str[a-1]))mem[j]=false;
			bool ch=true,cc=false;
			jj=j;
			j++;
			if(j>m)j=1;
			while(ch){
				if(j>m)j=1;
				if(mem[j]==false){
					j++;
				}else ch=false,cc=true;
				if(jj==j)ch=false;
			}
			if(cc==false)break;
		}
		bool nyu=false;
		for(a=1;a<=m;a++){
			if(mem[a]==true){
				if(nyu==true)printf(" %d",a);
				else printf("%d",a);
				nyu=true;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1248
package main

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

func main() {
	var (
		n, q, sum int
		s         string
		xs        []int
	)
	fmt.Scan(&n, &q, &s)
	xs = make([]int, n)
	for i := range s[:len(xs)-1] {
		if s[i] == 'A' && s[i+1] == 'C' {
			sum++
		}
		xs[i+1] = sum
	}

	var (
		sc   = bufio.NewScanner(os.Stdin)
		l, r int
	)
	sc.Split(bufio.ScanWords)
	for i := 0; i < q; i++ {
		sc.Scan()
		l, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		r, _ = strconv.Atoi(sc.Text())
		fmt.Println(xs[r-1] - xs[l-1])
	}
}


Measured memory_bytes: 5120
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

map<ll, int> dp;

int main() {
    int n;
    scanf("%d", &n);
    dp[0]++;
    ll s = 0;
    ll ret = 0;
    for(int i = 1; i <= n; i++) {
        ll t;
        scanf("%lld", &t);
        s += t;
        ret += dp[s]++;
    }
    printf("%lld\n", ret);
}


Measured memory_bytes: 12800
#include<stdio.h>
#include<string.h>
  
int main(){
  char t[1000],h[1000];
  int n,i,f;
  int tp=0,hp=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",t);
    scanf("%s",h);
    f=strcmp(t,h);
    if(f>0)
      tp+=3;
    else if(f<0)
      hp+=3;
    else{
      tp++;
      hp++;
    }
  }
  printf("%d %d\n",tp,hp);
  
  return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=2e5+5;
const int mod=1e9+7;

int n,sz[N],dep[N];
vector<int>adj[N];

int Power(int x,int n)
{
    if(n==0) return 1;
    if(n%2) return Power(x,n-1)*x%mod;
    int tmp=Power(x,n/2);
    return tmp*tmp%mod;
}

void dfs(int u,int p=0)
{
    sz[u]=1;
    for(auto&v:adj[u])
    {
        if(v==p) continue;
        dep[v]=dep[u]+1;
        dfs(v,u);
        sz[u]+=sz[v];
    }
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1);
    int res=0;
    for(int u=1;u<=n;u++)
    {
        for(auto&v:adj[u])
        {
            if(dep[u]>dep[v]) continue;
            int down=sz[v];
            int up=n-sz[v];
            int val_down=(1-Power(Power(2,down),mod-2)+mod)%mod;
            int val_up=(1-Power(Power(2,up),mod-2)+mod)%mod;
            int prob=val_down*val_up%mod;
            (res+=prob)%=mod;
        }
    }
    cout<<(res+1-(n*Power(2,mod-2)%mod)-Power(Power(2,n),mod-2)+mod*2)%mod;
}


Measured memory_bytes: 21376
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    const char *POSSIBLE = "POSSIBLE";
    const char *IMPOSSIBLE = "IMPOSSIBLE";

    int N, M;

    gc(N);
    gc(M);

    vector<bool> va(N, false);
    vector<bool> vb(N, false);

    int a;
    int b;
    for (int i = 0; i < M; i++)
    {
        gc(a);
        gc(b);

        if (a == 1) va[b - 1] = true;
        else if (b == N) vb[a - 1] = true;
    }

    bool flg = true;
    for (int i = 0; i < N; i++)
    {
        if (va[i] && vb[i])
        {
            printf("%s\n", POSSIBLE);
            flg = !flg;
            break;
        }
    }

    if (flg) printf("%s\n", IMPOSSIBLE);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

bool is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

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

    if (n % 2 == 1)
        n *= 2;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define vi vector<int>
#define si set<int>
#define vc vector<char>
#define vll vector<ll>
#define vd vector<double>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    char a ; cin >> a ;
    puts(isupper(a) ? "A" : "a") ;
}


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

int main() {
  int N;
  cin >> N;
  int c0=0;
  int c1=0;
  int c2=0;
  int c3=0;
  string str;
  for (int i=0; i<N; i++) {
    cin >> str;
    if (str[0]=='A') {
      c0++;
    } else if (str[0]=='W') {
      c1++;
    } else if (str[0]=='T') {
      c2++;
    } else if (str[0]=='R') {
      c3++;
    }
  }
  cout << "AC" << ' ' << 'x' << ' ' << c0 << endl;
  cout << "WA" << ' ' << 'x' << ' ' << c1 << endl;
  cout << "TLE" << ' ' << 'x' << ' ' << c2 << endl;
  cout << "RE" << ' ' << 'x' << ' ' << c3 << endl;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int sum = 0;
	vector<int> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sum += s[i];
	}
	int ans = sum, c = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] % 10 != 0) {
			ans = min(ans, s[i]);
			c++;
		}
	}
	if (c == 0)cout << 0 << endl;
	else if (sum % 10 != 0)cout << sum << endl;
	else cout << sum - ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{

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

        int a = scan.nextInt();

        int b = scan.nextInt();

        int c = scan.nextInt();

        int d;

        if (a > b) {
            // a(==X) , b(==Y)
            d = a;
            a = b;
            b = d;
        }
        if (b > c) {
            d = b;
            b = c;
            c = d;
        }
        if (a > b) {
            d = a;
            a = b;
            b = d;
            //
        }

        System.out.println(a + " " + b + " " + c);
    }
}



Measured memory_bytes: 25988
#include <stdio.h>

int main(void){
    int height, width;
    scanf("%d %d", &height, &width);

    char square[100][100];

    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            scanf(" %c", &square[i][j]);
        }
    }

    int row[100] = {0};
    int column[100] = {0};

    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            if(square[i][j] == '#'){
                row[i] = 1;
                break;
            }
        }
    }

    for(int j = 0; j < width; j++){
        for(int i = 0; i < height; i++){
            if(square[i][j] == '#'){
                column[j] = 1;
                break;
            }
        }
    }
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            if(row[i] == 1 && column[j] == 1){
                printf("%c", square[i][j]);
            }
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
double pi2 = acos(-1.0) * 2;
double f(double x){ return x*x; }

int main(void){
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double x2 = cos(pi2 * m/60) * b;
    double y2 = sin(pi2 * m/60) * b;
    m += h*60;
    double x1 = cos(pi2 * m/720) * a;
    double y1 = sin(pi2 * m/720) * a;
    cout << fixed << setprecision(12) << sqrt( f(x1-x2) + f(y1-y2) ) << endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int h,w; cin >> h >> w;
    char s[h][w];
    rep(i,h)rep(j,w)cin >> s[i][j];
    int num[h][w];
    rep(i,h)rep(j,w)num[i][j]=1001001;
    if(s[0][0]=='#'){
        num[0][0]=1;
        rep(i,h){
            if(i==0) continue;
            if(s[i][0]=='.') break;
            else num[i][0]=1;
        }
        rep(i,w){
            if(i==0) continue;
            if(s[0][i]=='.') break;
            else num[0][i]=1;
        }
    }else{
        num[0][0]=0;
        rep(i,h){
            if(i==0) continue;
            if(s[i][0]=='.') num[i][0]=0;
            else break;
        }
        rep(i,w){
            if(i==0) continue;
            if(s[0][i]!='.') break;
            else num[0][i]=0;
        }
    }
    rep(i,h){
        rep(j,w){
            if(i==0&&j==0) continue;
            if(s[i][j]=='.'){
                if(i==0) chmin(num[i][j],num[i][j-1]);
                else if(j==0) chmin(num[i][j],num[i-1][j]);
                else chmin(num[i][j],min(num[i-1][j],num[i][j-1]));
            }else{
                if(i==0) chmin(num[i][j],num[i][j-1]+1);
                else if(j==0) chmin(num[i][j],num[i-1][j]+1);
                else chmin(num[i][j],min(num[i-1][j],num[i][j-1])+1);
                
                for(int ii=i;ii<h;ii++){
                    if(s[ii][j]=='.') break;
                    for(int jj=j;jj<w;jj++){
                        if(s[ii][jj]=='.') break;
                        else chmin(num[ii][jj],num[i][j]);
                    }
                }
            }
        }
    }

    cout << num[h-1][w-1] << endl;
}


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

using namespace std;

int arr[2005], mn[2005][2005];
int main() {
    int n, x;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        mn[i][0] = arr[i];
    }
    /// mn[i][j] = min(arr[i], arr[i-1], arr[i-2], .., arr[i-j])
    for (int j = 1; j < n; j++) {
        for (int i = 0; i < n; i++) {
            mn[i][j] = min(mn[i][j - 1], arr[(i - j + n) % n]);
        }
    }
    long long res = 10000000000000;
    for (int k = 0; k < n; k++) {
        long long need = 0;
        for (int i = 0; i < n; i++) {
            need += mn[i][k];
        }
        res = min(res, need + 1LL * x * k);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define ll long long int 
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define P(x) printf("%d\n",(x))
#define Sl(x) scanf("%lld",&(x))
#define Pl(x) printf("%lld\n",(x))
#define pb push_back
#define f first
#define s second


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	double r ;
	cin >> r ;
	double pi = 3.1415926535 ;
	cout << setprecision(10) << 2*pi*r;
 	return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    LL a, b, c, n, i;
    string s;
    cin >> n >> i;
    cout << (n + 1) - i << endl;
    return 0;
}

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

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

int lcm(int a, int b){
   return a * b / gcd(a, b);
}

int main(void){
  ll a, b;
  cin >> a >> b;
  ll ans = lcm(a, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(void){
  int i, a, b;
  int check = 0, cross[101];

  for(i = 0; i < 101; i++){
    cross[i] = 0;
  }
  
  while(scanf("%d%d", &a, &b) != EOF){
    cross[a]++;
    cross[b]++;
    if(a == 0 && b == 0){
      for(i = 1; i < 101; i++){
	if((i > 2 && cross[i]%2 == 1) || (i <= 2 && cross[i]%2 == 0)){
	  check = 1;
	}
	cross[i] = 0;
      }
      if(check == 1){
	check = 0;
	printf("NG\n");
      }else{
	printf("OK\n");
      }
    }
  }  
  return 0;
}

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

using namespace std;

const int mod = 1e9+7;

int ways[100010];

int main()
{
    int n, k, a[100010];

    cin >> n >> k;

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

    ways[0] = 1;

    for (int child = 0; child < n; child++)
    {
        int prefix = 0;
        vector <int> v(k+1);

        for (int used = k; used >= 0; used--)
        {
            int tmp = ways[used];
            int l = used + 1;
            int r = used + min(a[child], k-used);

            if (l <= r)
            {
                v[l] += tmp;
                v[l] %= mod;

                if (r + 1 <= k)
                {
                    v[r+1] -= tmp;

                    if (v[r+1] < 0)
                        v[r+1] += mod;
                }
            }
        }

        for (int i = 0; i <= k; i++)
        {
            prefix += v[i];
            prefix %= mod;
            ways[i] += prefix;
            ways[i] %= mod;
        }
    }

    cout << ways[k] % mod << "\n";

    return 0;
}

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

int main() {
    int W, H;
    ll p[100005], q[100005];
    ll sum = 0ll;
    cin >> W >> H;

    for (int i = 0; i < W; i++) cin >> p[i];
    for (int i = 0; i < H; i++) cin >> q[i];
    
    sort(p, p + W); sort(q, q + H); 
    int i = 0, j = 0;
    while (i < W || j < H) {
        if (i < W && (j >= H || p[i] < q[j])) sum += p[i] * (H - j + 1), i++;
        else sum += q[j] * (W - i + 1), j++;
    }

    cout << sum << endl;
    return (0);
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int main()
{
	while(1) {
		int n, m;
		cin >> n >> m;
		if (!n && !m) break;
		map<int, int> a, b;
		int suma = 0, sumb = 0;
		rep(i,0,n) {
			int t; cin >> t;
			a[t]++;
			suma += t;
		}
		rep(i,0,m) {
			int t; cin >> t;
			b[t]++;
			sumb += t;
		}
		if ((suma + sumb)%2) {
			cout << -1 << endl;
			continue;
		} 
		int d = (sumb - suma) / 2;

		bool f = false;
		rep(i,0,101) {
			if (a[i]) {
				if (i+d >= 0 && i+d <= 100 && b[i+d]) {
					cout << i << " " << i+d << endl;
					f = true;
				}
			}
			if (f) break;
		}
		if (!f) cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S[] = new String[N];
		Map<String, Integer> map = new HashMap<String, Integer>();
		int max_cnt = 1;
		for(int i = 0; i < N; i++) {
			S[i] = sc.next();
			if(map.containsKey(S[i])) {
				map.put(S[i], map.get(S[i]) + 1);
				max_cnt = Math.max(max_cnt, map.get(S[i]));
			} else {
				map.put(S[i], 1);
			}
		}
		
		ArrayList<String> ary = new ArrayList<String>();
		for(String key : map.keySet()) {
			if(map.get(key) == max_cnt) {
				ary.add(key);
			}
		}
		Collections.sort(ary);
		for(int i = 0; i < ary.size(); i++) {
			System.out.println(ary.get(i));
		}
	}
}


Measured memory_bytes: 88688
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = int(lines[0])
    ws = [int(w) for w in lines[1].split(" ")]

    return (n, ws)


def solve(n, ws):

    result = None
    for i in range(1, n):
        a = sum(ws[:i])
        b = sum(ws[i:])
        diff = abs(a - b)
        if result:
            result = min(result, diff)
        else:
            result = diff

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

#    solve(*parse_input())

if __name__ == '__main__':

    main()


Measured memory_bytes: 3064