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

vector<pair<pair<int, int>, int> > ans;
map<pair<int, int>, int> res;
int d[15][15];
int a, b;

int main()
{
	scanf("%d%d", &a, &b);
	for (int i = 1;i <= a;i++) for (int j = 1;j <= b;j++) scanf("%d", d[i]+j);
	for (int i = 1;i <= a;i++) for (int j = 1;j <= b;j++)
	{
		bool done = false;
		int nA = 0, nB = 0, c = 0;
		for (;nA*i <= d[i][j];nA++)
		{
			for (nB=0;nA*i+nB*j <= d[i][j];nB++)
			{
				c = d[i][j]-nA*i-nB*j;
				bool ok = true;
				for (int x = 1;x <= a;x++)
				{
					for (int y = 1;y <= b;y++) if (nA*x+nB*y+c < d[x][y])
					{
						ok = false;
						break;
					}
					if (!ok) break;
				}
				if (ok)
				{
					done = true;
					break;
				}
			}
			if (done) break;
		}
		if (!done)
		{
			printf("Impossible\n");
			return 0;
		}
		res[make_pair(nA, nB)] = c;
	}
	a = 0, b = 0;
	for (auto u: res) a = max(a, u.first.first), b = max(b, u.first.second);
	for (int i = 1;i <= a;i++) ans.emplace_back(make_pair(i-1, i), -1);
	for (int i = 0;i <= a;i++) for (int j = 1;j <= b;j++) ans.emplace_back(make_pair((j-1)*(a+1)+i, j*(a+1)+i), -2);
	for (auto u: res) ans.emplace_back(make_pair(u.first.second*(a+1)+u.first.first, 299), u.second);
	printf("Possible\n300 %ld\n", ans.size());
	for (auto u: ans)
	{
		printf("%d %d ", u.first.first+1, u.first.second+1);
		if (u.second >= 0) printf("%d\n", u.second);
		else if (u.second == -1) printf("X\n");
		else printf("Y\n");
	}
	printf("1 300\n");
	return 0;
}


Measured memory_bytes: 256
a,b,c=gets.chomp.split(" ").map(&:to_i)
k = $stdin.gets.chomp.to_i
until b > a
  k -= 1
  b = b * 2
end

until c > b
  k -= 1
  c = c *2
end

if 0 <= k
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14336
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define INF 0x7FFFFFFF
const double EPS = 1e-10;


int main(){
  string s;
  cin>>s;
  if(s.size()==2){
    cout<<s<<endl;
  }
  else{
    string ss;
    ss.push_back(s[2]);
    ss.push_back(s[1]);
    ss.push_back(s[0]);
    cout<<ss<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

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

    int ind = 0;
    int N = s.length();
    while(K > 0){
        if(ind == N-1){
            int p = s[N-1] - 'a';
            p += K;
            p = p % 26;
            s[N-1] = 'a' + p;
            K = 0;
        }
        else{
            if(s[ind] != 'a'){
                if(26 - (s[ind] - 'a') <= K){
                    K -= (26 - (s[ind] - 'a'));
                    s[ind] = 'a';
                    ind++;
                }
                else{
                    ind++;
                }
            }
            else{
                ind++;
            }
        }

    }

    printf("%s\n", s.c_str());

}

Measured memory_bytes: 3724
H, W = [int(x) for x in input().split()]
s_lst = [input() for i in range(H)]
can = True
for i in range(H):
    for j in range(W):
        if s_lst[i][j] == '#':
            f1 = 0
            f2 = 0
            f3 = 0
            f4 = 0
            if 0 < i and s_lst[i - 1][j] == '.':
                f1 = 1
            if i < H - 1 and s_lst[i + 1][j] == '.':
                f2 = 1
            if 0 < j and s_lst[i][j - 1] == '.':
                f3 = 1
            if j < W - 1 and s_lst[i][j + 1] == '.':
                f4 = 1
            if f1*f2*f3*f4 == 1:
                can = False
print('Yes') if can else print('No')


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	int n,m;//最初に入力される変数
	
	scanf("%d %d",&n,&m);//最初の入力
	
	int A[n][m];//行列の定義
	int b[m];	//ベクトルの定義
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			scanf("%d",&A[i][j]);//行列に要素を格納
		}
	}
	
	for(int i = 0;i < m;i++){
		scanf("%d",&b[i]);//ベクトルに要素を格納
	}
	
	int c;//列ベクトル
	for(int i = 0;i < n;i++){
		int c = 0;//列ベクトル初期化
		for(int j = 0;j < m;j++){//ciを導出
			c += A[i][j] * b[j];
		}
		printf("%d\n",c);//出力
	}
	return 0;
}



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

int main(){
	int sum, x, last;
	last = 10;
	sum = 0;
	for(int i=0; i<5; i++){
		cin >> x;
		if(x%10 != 0){
			last = min(last, x%10);
		}
		x = ((x+9)/10)*10;
		sum += x;
	}
	cout << sum-(10-last) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int H,W,X,Y;
    cin>>H>>W>>X>>Y;
    cout<<(H-X)*(W-Y)<<endl;
}

Measured memory_bytes: 3536
# 本当はBITやセグメントツリーを用いた解法を使いたいところ...(理解不足)

import bisect
from collections import defaultdict

N = int(input())
# 書き換える時に文字列だと不便なのでリスト化しておく
S = list(input())
Q = int(input())

# setは順序を保証しない、setで管理するとクエリ2で（リスト化した後に）ソートする必要がある
# 最初からlistで管理して、クエリ1ではソート済になるように挿入する
dict = defaultdict(list)
for i in range(N):
    dict[S[i]].append(i)

ans = []

for _ in range(Q):
    a, b, c = input().split()
    a = int(a)

    if a == 1:
        b = int(b) - 1
        # 書き換える必要がない場合
        if S[b] == c:
            continue
        else:
            # クエリ2が飛んできた時に毎回ソートしていては間に合わない
            # クエリ1の時点でソート済にしておく
            # 二分探索の際、同じ数字が既にあることはないので、leftでもrightでも良い
            dict[S[b]].remove(b)
            idx = bisect.bisect(dict[c], b)
            dict[c].insert(idx, b)
            # 文字列の書き換え
            S[b] = c

    elif a == 2:
        b = int(b) - 1
        c = int(c) - 1
        # 文字が何種類あるか
        char_cnt = 0
        for key, value in dict.items():
            # left,rightを指定する必要がある
            x1 = bisect.bisect_left(value, b)
            x2 = bisect.bisect_right(value, c)
            if x2 - x1 > 0:
                char_cnt += 1
        ans.append(char_cnt)

for i in ans:
    print(i)


Measured memory_bytes: 127188
import sys

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))

    solve(H)

def solve(H: int):
    count = 0
    while 0 < H:
        H = H // 2
        count = count + 1

    answer = 0
    for i in range(count):
        answer = answer + 2**i

    print(answer)

    return
 
if __name__ == "__main__":
    propare()

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

int main() {
  string N;
  cin >> N;
  
  if (N.at(0) == N.at(1) && N.at(0) == N.at(2)) {
    cout << "Yes" << endl;
  }
  else if (N.at(1) == N.at(2) && N.at(1) == N.at(3)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }    
}

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

int main(){
  vector<int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << v.at(K-1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
    int data, i, b, f, r, v, rooms[4][3][10] = {};
    scanf("%d", &data);
    for (i = 0; i < data; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        rooms[b - 1][f - 1][r - 1] += v;
    }
    for (b = 0; b < 4; b++) {
        if (b != 0) {
            printf("####################\n");
        }
        for (f = 0; f < 3; f++) {
            for (r = 0; r < 10; r++) {
                printf(" %d", rooms[b][f][r]);
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 612
#include<stdio.h>

int dp[50];

int fib(int);
int main(){
  int n,i;
  scanf("%d",&n);
  for(i = 0;i < 50;i++){
    dp[i] = -1;
  }
  
  printf("%d\n",fib(n));
  
  return 0;
}
int fib(int n){
  if(n == 0) return 1;
  if(n == 1) return 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n-1)+fib(n-2);
}





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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	const int mod=998244353;
	auto add=[&](int a,int b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;return a;};
	auto sub=[&](int a,int b){a-=b;while(a>=mod)a-=mod;while(a<0)a+=mod;return a;};
	auto mul=[&](int a,int b){return 1LL*a*b%mod;};
	auto qpow=[&](ll t,ll p){
		ll ans=1;
		while(p){
			if(p&1)ans=ans*t%mod;
			t=t*t%mod;
			p>>=1;
		}
		return ans;
	};
	const int inv2=qpow(2,mod-2);
	
	int n;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	int MAXN=*max_element(a.begin(),a.end());
	vector<int>num(MAXN+5,0);
	for(int i=0;i<n;i++)num[a[i]]++;
	vector<int>prime,mu(MAXN+5);
	vector<bool>vis(MAXN+5);
	mu[1]=1;
	for(int i=2;i<=MAXN;i++){
		if(!vis[i])prime.push_back(i),mu[i]=-1;
		for(int j=0;j<prime.size();j++){
			if(1LL*i*prime[j]>MAXN)break;
			vis[i*prime[j]]=true;
			if(i%prime[j]==0){
				mu[i*prime[j]]=0;
				break;
			}
			mu[i*prime[j]]=-mu[i];
		}
	}
	vector<int>F(MAXN+5);
	for(int i=1;i<=MAXN;i++){
		int sum=0;
		for(int j=i;j<=MAXN;j+=i){
			F[i]=add(F[i],mul(mul(mul(mul(num[j],sub(num[j],1)),inv2),j),j));
			F[i]=add(F[i],mul(sum,mul(num[j],j)));
			sum=add(sum,mul(j,num[j]));
		}
	}
	int ans=0;
	for(int i=1;i<=MAXN;i++){
		int f=0;
		for(int j=i;j<=MAXN;j+=i){
			f=add(f,mul(mu[j/i],F[j]));
		}
		ans=add(ans,mul(f,qpow(i,mod-2)));
	}
	cout<<ans<<endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int P[51];

int ok() {
	int i;
	FOR(i,N) if(P[i]!=i+1) return 0;
	return 1;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>P[i];
	
	if(ok()) {
		cout<<"YES"<<endl;
		return;
	}
	FOR(y,N) FOR(x,y) {
		swap(P[x],P[y]);
		if(ok()) {
			cout<<"YES"<<endl;
			return;
		}
		swap(P[x],P[y]);
	}
	cout<<"NO"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
/*  Bismillahir Rahmanir Rahim
    Author  : Md. Sajjat Hosen
    Created : 06-July,2020  07:53:25 AM
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long               ll;
typedef long double             ld;
typedef unsigned long long      ull;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds_multiset;

inline int Int() { int x; scanf("%d", &x); return x; }
inline ll Long() { ll x; scanf("%lld", &x); return x; }

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

const int N       = (int) 2e5 + 5;
const int maxN    = (int) 1e6 + 6;
const int Mod     = (int) 1e9 + 7;

#define     debug(x)    cerr << #x << " = " << x << '\n';
#define     all(x)      x.begin(), x.end()
#define     szof(x)     (int) x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     mp          make_pair
#define     PI          acos(-1.0)
#define     TN          typename
#define     nl          '\n'
#define     Fast_IO     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

inline int add(int a, int b) { a += b; return a >= Mod ? a - Mod : a < 0 ? a + Mod : a; }
inline int mult(int a, int b) { return (ll) a * b % Mod; }

template <TN T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); }
template <TN T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }

int main() {
    //Fast_IO
    //clock_t tStart = clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int test = 1, tc = 0;
    while (test--) {
        int n = Int();
        string s;
        int AC = 0, WA = 0, TLE = 0, RE = 0;
        while (n--) {
            cin >> s;
            if (s == "AC") AC++;
            else if (s == "WA") WA++;
            else if (s == "TLE") TLE++;
            else RE++;
        }

        printf("AC x %d\n", AC);
        printf("WA x %d\n", WA);
        printf("TLE x %d\n", TLE);
        printf("RE x %d\n", RE);
    }
    //fprintf(stderr, "\nRuntime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 3736
#include<stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    if(a==b && a!=c && b!=c)
    {
        printf("Yes");
    }
    else if(a==c && a!=b && b!=c)
    {
        printf("Yes");
    }
    else if(b==c && a!=b && a!=c)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 128
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let k: usize = s.next().unwrap().parse().unwrap();
	let mut uf = UnionFind::new(n);
	let mut edges = vec![vec![]; n];
	for _ in 0..m {
		let a = s.next().unwrap().parse::<usize>().unwrap() - 1;
		let b = s.next().unwrap().parse::<usize>().unwrap() - 1;
		uf.unite(a, b);
		edges[a].push(b);
		edges[b].push(a);
	}
	let mut block = vec![0; n];
	for _ in 0..k {
		let a = s.next().unwrap().parse::<usize>().unwrap() - 1;
		let b = s.next().unwrap().parse::<usize>().unwrap() - 1;
		if uf.find(a) == uf.find(b) {
			block[a] += 1;
			block[b] += 1;
		}
	}
	let mut ans = String::new();
	for i in 0..n {
		let size = uf.size(i);
		ans.push_str(&format!("{} ", size - 1 - edges[i].len() - block[i]));
	}
	ans.pop();
	println!("{}", ans);
}

pub struct UnionFind {
	data: Vec<i32>,
}

impl UnionFind {
	pub fn new(n: usize) -> UnionFind {
		UnionFind { data: vec![-1; n] }
	}

	pub fn unite(&mut self, x: usize, y: usize) -> bool {
		let x = self.find(x);
		let y = self.find(y);
		if x == y {
			false
		} else {
			let (x, y) = if self.data[x] > self.data[y] { (y, x) } else { (x, y) };
			self.data[x] += self.data[y];
			self.data[y] = x as i32;
			true
		}
	}

	pub fn find(&mut self, i: usize) -> usize {
		if self.data[i] < 0 {
			i
		} else {
			let p = self.data[i] as usize;
			self.data[i] = self.find(p) as i32;
			self.data[i] as usize
		}
	}

	pub fn size(&mut self, i: usize) -> usize {
		let i = self.find(i);
		-self.data[i] as usize
	}
}


Measured memory_bytes: 19124
D, G = map(int, input().split())
PC = [list(map(int, input().split())) for _ in range(D)]

p, c = zip(*PC)

min_count = 10**18
for i in range(1<<D):
    h = -1
    point = 0
    count = 0
    for j in range(D):
        if (i>>j)%2:
            point += 100*(j+1)*p[j] + c[j]
            count += p[j]
        else:
            h = j
    if h > -1 and G > point:
        x = -(-(G-point)//(100*(h+1)))
        if x > p[h]:
            continue
        count += x
    min_count = min(min_count, count)

print(min_count)

Measured memory_bytes: 3188
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cstring>
#include <string>
#define rep(i,l,p) for(long long i=l;i<=p;i++)
#define drep(i,p,l) for(long long i=p;i>=l;i--)
using namespace std;
long long N;

int main(){
	//freopen("in.txt","r",stdin);
	scanf("%lld",&N);
	long long melo,deno,w;
	rep(h,1,3500){
		rep(n,1,3500){
			melo = N * h * n;
			deno = 4*h*n - N*n - N*h; 
			if ( deno > 0 && melo % deno == 0 )
			{
				w = melo / deno;
				printf("%lld %lld %lld\n", h,n,w);
				return 0;
			}
		}
	}
	 

	return 0;
}


Measured memory_bytes: 256
"use strict"

const main = arg => {
  arg = arg.trim().split("\n");
  const H = parseInt(arg[0].split(" ")[0]);
  const W = parseInt(arg[0].split(" ")[1]);
  
  const tiles = arg.slice(1, H + 1).map(n=>n.split(""));
  
  const nx = [1, 0, -1, 0];
  const ny = [0, 1, 0, -1];
  
  for(let i in tiles) {
      for(let j in tiles[i]) {
          let cnt = 0;
          
          for(let k=0; k<4; k++) {
              let dx = nx[k] + parseInt(j);
              let dy = ny[k] + parseInt(i);
              
              if(dy < 0 || dy > H - 1) continue;
              if(dx < 0 || dx > W - 1) continue;
             
              if(tiles[dy][dx] === ".") {
                  cnt++;
              }
          }
          
          if(tiles[i][j] === "#" && cnt === 4) {
              console.log("No");
              return;
          }
      }
   }
   
   console.log("Yes");
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include<iostream>
using namespace std;
int main(){
string s;
cin>>s;
int cnt1=0,cnt2=0,cnt3=0;
for(int i=0;i<3;i++){
if(s[i]=='a') cnt1++;
if(s[i]=='b') cnt2++;
if(s[i]=='c') cnt3++;
}
if(cnt1==1&&cnt2==1&&cnt3==1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;



}

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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main() {
  int k;
  cin >> k;

  int n;
  int ans=0;
  for (int a = 1; a <= k; a++) {
    for(int b = 1; b <= k; b++) {
      for(int c = 1; c <= k; c++) {
        n = gcd(a,b);
        n = gcd(n,c);
        ans+=n;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(void) {
	
 char s[100000];
 int i,j;
 scanf("%s",s);
 qsort(s,strlen(s), sizeof(char), cmpfunc);
 /*for(i=0;i<strlen(s);i++)
 {
     printf("%d ",s[i]);
 }*/
// printf("%s",s);
j=97;
for(i=0;i<strlen(s);i++)
{
    if(s[i]==j)
    {
    while(s[i]==j)
    {
        i++;
        if(s[i]!=j)
        j++;
    }
    }
    else
    break;
}
if(j==123)
printf("None");
else
printf("%c\n",j);
	return 0;
}



Measured memory_bytes: 380
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    long k=sc.nextLong();
    int count=0;
    while(count<s.length()&&s.charAt(count)=='1')count++;
    if(k>count)System.out.println(s.charAt(count));
    else System.out.println(1);
  }
}

Measured memory_bytes: 21844
fun main() {
    val mod = 1000000007L.toBigInteger()
    readLine()
    val x = readLine()!!.split(" ").map(String::toBigInteger)

    val s = x.toMutableList().apply {
        (1 until x.size).forEach { i -> this[i] += this[i - 1] }
    }

    x.indices.map { i -> (x[i] * (s.last() - s[i])) }
            .reduce { acc, i ->  (acc + i) }
            .let { println(it.rem(mod)) }
}


Measured memory_bytes: 113436
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 10000000000)

	s := nextInt()

	dp := make([]int, s+1)
	dp[0] = 1

	mod := 1000000000 + 7

	for i := 1; i <= s; i++ {
		for j := 0; j <= i-3; j++ {
			dp[i] += dp[j]
			dp[i] %= mod
		}
	}

	fmt.Println(dp[s])
}


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

signed main()
{
    int n, k;
    cin >> n >> k;
    vector<int> pref(n+1), suf(n+1);
    for (int i = 1; i <= n; i++)
        pref[i] = suf[i] = i;
    for (int i = 1; i <= n; i++)
        pref[i] += pref[i-1];
    for (int i = n-1; i >= 0; i--)
        suf[i] += suf[i+1];

    int ans = 0;
    for (int i = k; i <= n+1; i++)
    {
        ans += suf[n+1-i] - pref[i-1] + 1;
        ans %= mod;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 200001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

//double rat;
L A[Mx+5],B[Mx+5];


void solve(){
    c=n-c;
    if(c>=0)printf("%lld\n",c);
    else printf("-1\n");
}
int main()
{
    c=0;
    scanf("%lld%lld",&n,&m);
    for(L i=0;i<m;i++){
        scanf("%lld",&d);
        c+=d;
    }
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(){
  int N;
  ll M=0,A=0,R=0,C=0,H=0;
  cin >> N;
  vector<char> S;
  string tmp;
  while(cin >> tmp){
   char f=tmp[0];
  if(f=='M'){M++;}
  else if(f=='A'){A++;}
  else if(f=='R'){R++;}
  else if(f=='C'){C++;}
  else if(f=='H'){H++;}   
  }
  ll ans=M*A*R +M*A*C +M*A*H +M*R*C +M*R*H+ M*C*H +A*R*C+ A*R*H +A*C*H +R*C*H;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int n,m;
    int i=0,j=0;
    int a[100][100],b[100],c[100]={0};
    
    scanf("%d %d",&n,&m);
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(j=0;j<=m;j++){
        scanf("%d",&b[j]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]+=a[i][j]*b[j];
        }
            printf("%d\n",c[i]);

    }
    return 0;
}


Measured memory_bytes: 2140
while true do
    h, w = gets.split.map(&:to_i)
    break if h == 0 && w == 0
    for x in 1..h do
        if (x % 2 != 0) then
            for i in 1..w do
                if (i % 2 == 0) then
                    print "."
                else
                    print "#"
                end
            end
        else
            for i in 1..w do
                if (i % 2 != 0) then
                    print "."
                else
                    print "#"
                end
            end
        end
            
        puts ""
    end
    puts ""
end

Measured memory_bytes: 8700
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


signed main(void){
    int a,b;
    string S,T;
    cin >> a >> b;
    REP(i,a){
        S.push_back('0'+b);
    }
    REP(i,b){
        T.push_back('0'+a);
    }
    if(S<T){
        cout << S << endl;
    }else{
        cout << T << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    int k=0;
    string s=to_string(n);
    for(int i=0;i<s.size();i++){
        k+=(s[i]-'0');
    }
    if(n%k==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m;
int a,b,ans[50];

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        ans[a-1]++; ans[b-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 256
# ABC073C - Write and Erase
def main():
    N, *A = map(int, open(0).read().split())
    store = set()
    for a in A:
        if a in store:
            store.remove(a)
        else:
            store.add(a)
    ans = len(store)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14308
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int memo[200][200];

int gcd(int x, int y) {
    if (memo[x-1][y-1]) {
        return memo[x-1][y-1];
    }
    if (x > y) {
        memo[x-1][y-1] = gcd(y, x);
    } else if (x == 1) {
        memo[x-1][y-1] = 1;
    } else if (x == y) {
        memo[x-1][y-1] = x;
    } else {
        memo[x-1][y-1] = gcd(y-x, x);
    }
    return memo[x-1][y-1];
}

int main()
{
    int k;
    long acc = 0;
    cin >> k;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            int x = gcd(a, b);
            for (int c = 1; c <= k; c++) {
                acc += gcd(x, c);
            }
        }
    }
    cout << acc << endl;
    return 0;
}

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

using namespace std;

inline int read()
{
	char ch;int num,f=0;
	while(!isdigit(ch=getchar())) f|=(ch=='-');
	num=ch-'0';
	while(isdigit(ch=getchar())) num=num*10+ch-'0';
	return f?-num:num;
}

typedef long long ll;
ll a,b,c,k,res;

int main()
{
	cin >> a >> b >> c >> k;
	
	if(k%2==1) res=b-a;
	else res=a-b;
	
	cout << res;
	return 0;
}

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

int main(){

  int x;
  cin>>x;

  int h = x / 3600;
  int m = (x / 60) % 60;
  int s = x % 60;
  cout<<h<<":"<<m<<":"<<s<<endl;

  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <random>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	static unordered_map<ll, ll> memo;

	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	if (memo.find(b) == memo.end()) {
		ll k = 1;
		FOR(i, 2, b + 1) {
			k *= i;
			k %= MOD;
		}
		memo[b] = pow(k, MOD - 2);
	}
	c *= memo[b];
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/

//--------------------------------------------------------

int main() {

	string s;
	cin >> s;

	ll count = 0;
	ll ans = 0;
	REP(i, s.size()) {
		if (s[i] == 'W') {
			ans += (i-count);
			++count;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
/**
 *    author:  tourist
 *    created: 19.12.2019 14:47:07       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  long long ans = 0;
  int cnt = 0;
  for (char c : s) {
    if (c == 'B') {
      ++cnt;
    } else {
      ans += cnt;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 720
void func1(int a,int b){

    int hh=a*a;
    int ww=b*b;
    int sqrt=ww+hh;

    //    int i=0,j=0;                                                                                                                                                            

    int max=150*150;
    int reh=0;
    int rew=0;
    int i=0;
    int j=0;


  for(i=2;i<150;i++){
      for(j=1;j<i;j++){

        int ii=i*i;
        int jj=j*j;
        int sub=ii+jj;
        if(sqrt<sub||(sqrt==sub&&a<j)){

          //      break lll;                                                                                                                                                      
          /*      int re[2];                                                                                                                                                      
          re[0]=i;                                                                                                                                                                
          re[1]=j;*/
          if(sub<max||(sub==max&&j<reh)){
            reh=j;
            rew=i;
            max=sub;
          }


        }


      }
    }
  printf("%d %d\n",reh,rew);
  return ;
}
int main(){

  int h=0,w=0;
  while(1){
    scanf("%d %d",&h,&w);
    if(h==0&&w==0)break;
    //    printf("%d %d",h,w);                                                                                                                                                    

    //    int result[2];                                                                                                                                                          
    func1(h,w);

  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
 int a[105];
 int dp[101][100002];
 int n,k;
signed main()
{


    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            dp[i][j]+=dp[i-1][j];
            dp[i][j]%=mod;
            if(j)
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
            if(j-a[i]-1>=0)
            {
                dp[i][j]+=mod;
            dp[i][j]-=dp[i-1][j-a[i]-1];
            dp[i][j]%=mod;
            }
        }
    }
    cout<<dp[n][k]<<endl;
	return 0;
}


Measured memory_bytes: 81648
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))

mul = 1
for a in As:
    mul *= a

s = 0
for a in As:
    s += mul // a

print("{:.15f}".format(mul / s))



Measured memory_bytes: 7120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N,K;
    cin >> N >> K;
    map<int,int> ma;
    REP(i,N){
        ll tmp;
        cin >> tmp;
        ma[tmp]++;
    }
    vector<ll> A(0);
    for(auto itr = ma.begin();itr != ma.end();itr++){
        A.eb(itr->S);
    }
    sort(ALL(A));
    ll ans = 0;
    if(A.size()>=K){
        REP(i,A.size() - K){
            ans += A[i];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 14548
#include <bits/stdc++.h>
using namespace std;
// rep macro
#define rep(i, n)        for (int i = 0; i < (int)(n); i++)
#define rev(i, n)        for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i, s, n)    for (int i = (s); i < (int)(n); i++)
#define rev2(i, s, n)    for (int i = (int)(n) - 1; i >= (int)(s); i--)
#define bitrep(i, n)     for (int i = 0; i < (1 << (int)(n)); i++)
#define bitrep2(i, s, n) for (int i = (s); i < (1 << (int)(n)); i++)
const int di[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dj[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// type macro
using ll = int64_t;
// vector macro
#define all(v) v.begin(), v.end()
using  vi = vector<int>;
using vvi = vector<vector<int>>;
using  vu = vector<size_t>;
using vvu = vector<vector<size_t>>;
using  vl = vector<ll>;
using vvl = vector<vector<ll>>;
using  vd = vector<double>;
using vvd = vector<vector<double>>;
using  vb = vector<bool>;
using vvb = vector<vector<bool>>;
using  vc = vector<char>;
using vvc = vector<vector<char>>;
using  vs = vector<string>;
using vvs = vector<vector<string>>;
// pair macro
#define fi first
#define sj second
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
// math macro
#define lcm(a, b) a / __gcd(a, b) * b
#define dist(a, b) sqrt(pow(a.fi - b.fi, 2) + pow(a.sj - b.sj, 2))
// print macro
#define println(x) cout << x << endl
#define Yes println("Yes")
#define No println("No")
#define YES println("YES")
#define NO println("NO")
// memo
// desc sort: sort(vec.begin(), vec.end(), greater<int>());#include "header.h"

int main()
{
    int n; cin >> n;
    vi a(n), b(n), c(n); 
    rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) cin >> c[i];
    sort(all(a));sort(all(b));sort(all(c));
    // max of sum : (10^5)^3 = 10^15
    ll sum = 0;
    auto ib = b.begin();
    // O(nlogn)
    while (ib != b.end())
    {
        auto ia = lower_bound(all(a), *ib);
        auto ic = upper_bound(all(c), *ib);
        sum += (ia - a.begin()) * (c.end() - ic);
        ib++;
    }
    cout << sum << endl;
}

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

int bubbleSort(vector<int>&, int);

int main(){
    vector<int> A(100);
    int n, sw;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A.at(i);

    sw = bubbleSort(A, n);

    for(int i = 0; i < n; i++){
        if (i) cout << " ";
        cout << A.at(i);
    }
    cout << endl;
    cout << sw << endl;
}

int bubbleSort(vector<int>& A, int n){
    int sw = 0;
    bool flag = 1;
    for(int i = 0; flag; i++){
        flag = 0;
        for(int j = n - 1; j >= i + 1; j--){
            if(A.at(j) < A.at(j-1)){
                swap(A.at(j), A.at(j-1));
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}


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

using namespace std;

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

    int max = ::max(a, b);
    vector<int> div;
    for (int i = 1; i <= max; i++)
    {
        if (a%i==0 && b%i==0)
        {
            div.push_back(i);
        }
    }

    cout << div.at(div.size()-k) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

print(*a)
for i in range(n-1):
    j = i
    while a[j]>a[j+1] and j>=0:
        a[j],a[j+1] = a[j+1],a[j]
        j -= 1
    print(*a)


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

int main()
{
	while (1)
	{
		ll n, k, m;
		cin >> n >> k >> m;
		if (n == 0) return 0;

		vi vec(n);
		rep(i, 0, n) vec[i] = i + 1;

		int now = m - 1;
		while (1 < n)
		{
			vec.erase(next(vec.begin(), now));
			n--;
			now = (now + k - 1) % n;
		}
		cout << vec[0] << endl;
	}
}

Measured memory_bytes: 3084
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    int m = nextInt();

    if(n==m){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

using namespace std;

const int N = 2018;

bitset<N * N> bs;
int n;

int main() {
  scanf("%d", &n);
  bs[0] = 1;
  int tot = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    tot += a;
    bs = bs | (bs << a);
  }
  int mid = tot/2;
  while (!bs[mid]) --mid;
  printf("%d\n", tot - mid);
  return 0;
}

Measured memory_bytes: 2176
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		while(true){
			int n = si(),cnt = 0;
			if(n==0) break;
			int[] ary = new int[n];
			for (int i = 0; i < n ; i++) {
				ary[i] = si();
			}
			for (int i = n-1; i > 0; i--) {
				for (int j = 0; j < i ; j++) {
					int tmp;
					if(ary[j+1]<ary[j]){
						tmp = ary[j+1];
						ary[j+1]=ary[j];
						ary[j] = tmp;
						cnt++;
					}
				}
			}
			out.println(cnt);
		}
		out.flush();
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 20580
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll root(ll x){
	ll l,r,m;
	l = 0ll;
	r = (1ll<<31);
	while((r-l)>1){
		m = (r+l)/2;
		if(m*m > x){
			r = m;
		}else{
			l = m;
		}
	}
	return ((r*r)>x)?l:r;
}

int main(void){
	int i,q;
	ll a,b,c;
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> a >> b;
		c = root(a*b);
		if(a*b == c*c && a!=b){
			cout << (2*c-3) << endl;
		}else if(c*(c+1)>=a*b){
			cout << (2*c-2) << endl;
		}else{
			cout << (2*c-1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
int H,W,i,j;
	while(1)
	{
	scanf("%d %d",&H,&W);
		if(H==0&&W==0)
		{
			break;
		}
	for(i=0;i<H;i++)
	{
		for(j=0;j<W;j++)
		{
			printf("#");
		}
		printf("\n");
	}
		printf("\n");
}
	return 0;
}


Measured memory_bytes: 2100
from collections import defaultdict
w,h,n = map(int,input().split())
board = defaultdict(lambda: 0)
for i in range(n):
    x,y = map(int,input().split())
    x -= 1; y -= 1
    if x > 1:
        if y > 1 :
            board[(x-2,y-2)] += 1
        if y < h-1 and y > 0:
            board[(x-2,y-1)] += 1
        if y < h-2:
            board[(x-2,y)] += 1
    if x < w-1 and x > 0:
        if y > 1 :
            board[(x-1,y-2)] += 1
        if y < h-1 and y > 0:
            board[(x-1,y-1)] += 1
        if y < h-2:
            board[(x-1,y)] += 1
    if x < w-2:
        if y > 1 :
            board[(x,y-2)] += 1
        if y < h-1 and y > 0:
            board[(x,y-1)] += 1
        if y < h-2:
            board[(x,y)] += 1

ans = [0]*10
for i in board.values():
    ans[i] += 1
ans[0] = (h-2)*(w-2)-sum(ans)
for i in ans: print(i)


Measured memory_bytes: 156728
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 998244353;


int main(){
    ll N, M; cin >> N >> M;
    dsu tree(N);
    for(int i = 0; i < M; i++){
        ll a, b; cin >> a >> b; a--; b--;
        tree.merge(a, b);
    }
    set<ll> ST;
    for(int i = 0; i < N; i++){
        ST.insert(tree.leader(i));
    }
    cout << ST.size()-1 << endl;
}


Measured memory_bytes: 7720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;cin>>n;
	set<ll> st;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			ll t=n;
			while(t%i==0) t/=i;
			if(t%i==1) st.insert(i);
		}
	}
	for(ll i=1;i*i<=n-1;i++){
		if((n-1)%i==0){
			st.insert(i);
			st.insert((n-1)/i);
		} 
	}
	st.erase(1);
	st.insert(n);
	cout<<st.size()<<"\n";
	return 0;
}

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

using namespace std;

int n,k;
int arr[305];
long long mem[305][305][305],mem1[305][305][305],mem2[305][305][305];

vector<int> cmp;

int get(int x)
{
	return lower_bound(cmp.begin(),cmp.end(),x)-cmp.begin();
}

int main()
{
	cin >> n >> k;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		cmp.push_back(arr[i]);
	}
	if(n==k)
	{
		cout << 0 << endl;
		return 0;
	}
	cmp.push_back(0); //cmp.push_back(1);

	sort(cmp.begin(),cmp.end());
	cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
	int cm=cmp.size()-1;
	for(int x=n-1;x>=0;x--)
	{
		for(int y=k;y>=0;y--)
		{
			for(int z=cm;z>=0;z--)
			{
				mem[x][y][z]=max(arr[x]-cmp[z],0)+mem[x+1][y][get(arr[x])];
				if(y==0)
					continue;
				if(x==n-1)
				{
					mem[x][y][z]=0;
					continue;
				}
				//cout << x << " " << y << " " << cmp[z] << " " << mem[x][y][z] << endl;
				mem[x][y][z]=min(mem[x][y][z],mem1[x+1][y-1][z]-cmp[z]);
				//cout << x << " " << y << " " << cmp[z] << " " << mem[x][y][z] << endl;
				mem[x][y][z]=min(mem[x][y][z],mem2[x+1][y-1][z]);
				//cout << x << " " << y << " " << cmp[z] << " " << mem[x][y][z] << endl;
			}
			mem1[x][y][cm]=mem[x][y][cm]+cmp[cm];
			for(int z=cm-1;z>=0;z--)
				mem1[x][y][z]=min(mem1[x][y][z+1],mem[x][y][z]+cmp[z]);
			mem2[x][y][0]=mem[x][y][0];
			for(int z=1;z<=cm;z++)
				mem2[x][y][z]=min(mem2[x][y][z-1],mem[x][y][z]);
		}
	}
	cout << mem[0][k][0] << endl;
}

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

long long gcd(long long A, long long B){
  long a=max(A,B),b=min(A,B),c=b;
  while(b!=0){
    b=a%b;
    a=c;
    c=b;
  }
  return a;
}

int main(){
  long long A,B,C,D,x,a,b,c;
  cin >> A >> B >> C >> D;
  x=C*D/gcd(C,D);
  
  if(A%C==0){
    a=B/C-A/C+1;
  }
  else{
    a=B/C-A/C;
  }
  if(A%D==0){
    b=B/D-A/D+1;
  }
  else{
    b=B/D-A/D;
  }
  if(A%x==0){
    c=B/x-A/x+1;
  }
  else{
    c=B/x-A/x;
  }
  
  cout << (B-A+1)-(a+b-c) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
import math
# 0 0 1 1

A = list(map(float, stdin.readline().split()))
x1, y1, x2, y2 = A[0], A[1], A[2], A[3]

distance = math.sqrt(math.pow(x2-x1, 2) + math.pow(y2-y1,2))
print(format(distance,'.8f'))



Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    double x = 1;
    printf("%.12f\n", x / 2);
  } else {
    printf("%.12f\n", double(double(n / 2) + 1) / n);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  long N,A,B;
  cin>>N>>A>>B; 

  vector<int>a(N);
  for (int i = 0; i < N; i++) {
    cin>>a.at(i);
  }
  vector<long>b(N);
  b.at(0)==0;
  for (int i = 1; i < N; i++) {
    b.at(i)=min(b.at(i-1)+A*(a.at(i)-a.at(i-1)),b.at(i-1)+B);
  }
   
  
      cout<<b.at(N-1)<<endl;
 
}

Measured memory_bytes: 1408
/*  ex7_1
    pptenshi  */

#include<stdio.h>

typedef struct{
    int x_elem;
    int y_elem;
}point;

point shift_point(point point_0, int dx, int dy);

int main(void) {
    point point_1, point_2, point_3, point_4;
    int dx_12,  // x_2 - x_1
        dy_12;  // y_2 - y_1                      

    // input
    scanf(
        "%d%d%d%d", 
        &point_1.x_elem, &point_1.y_elem, 
        &point_2.x_elem, &point_2.y_elem
    );

    
    // calculate
    dx_12 = point_2.x_elem - point_1.x_elem;
    dy_12 = point_2.y_elem - point_1.y_elem;
    
    // ベクトル (dx_12, dy_12) を90度回転させたものをpoint_2に足すとpoint_3
    // point_4も同様にして求められる
    // (x, y)を90度回転すると(-y, x)
    point_3 = shift_point(point_2, -dy_12, dx_12);
    point_4 = shift_point(point_3, -dx_12, -dy_12);


    // output
    printf("%d %d %d %d\n", 
        point_3.x_elem, point_3.y_elem,
        point_4.x_elem, point_4.y_elem
    );

    return 0;
}

// point_0 をx軸方向にdx, y軸方向にdy移動させたpointを返す
point shift_point(point point_0, int dx, int dy) {
    point shifted_point;

    shifted_point.x_elem = point_0.x_elem + dx;
    shifted_point.y_elem = point_0.y_elem + dy;
    
    return shifted_point;
}

Measured memory_bytes: 1724