akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string txt;
	getline(cin, txt);
	for (int i = 0; i < txt.length(); i++)
	{
		char c = txt[i];
		if (c >= 65 && c <= 90)
		{
			c += 32;
		}
		else if (c >= 97 && c <= 122)
		{
			c -= 32;
		}
		cout << c;
	}
	cout << endl;
}


Measured memory_bytes: 3048
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		String[] S=sc.next().split("");

		int[] sumW=new int[N+1];
		int[] sumE=new int[N+1];

		sumW[0]=0;
		sumE[N]=0;

		for (int i = 0; i < N; i++) {

			if(S[i].equals("W")) {
				sumW[i+1]=sumW[i]+1;
			}else {
				sumW[i+1]=sumW[i];
			}

			if(S[N-(i+1)].equals("E")) {
				sumE[N-(i+1)]=sumE[N-i]+1;
			}else {
				sumE[N-(i+1)]=sumE[N-i];
			}

		}

		int ans=99999999;

		for (int i = 0; i < N; i++) {

			int buf=sumW[i]+sumE[i+1];

			ans=Math.min(ans,buf);

		}

		System.out.println(ans);
	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


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

using namespace std;
using ll = long long;

const ll MOD = int(1e9 + 7);
const int N = 22;
ll dp[1 << N];
int n;
int ar[N][N];

template<typename T>
T add(T &x, T y) { x += y; if(x >= MOD) x -= MOD; return x; }

ll rec(int i, int mask) {
  if(i == n) {
    return  __builtin_popcount(mask) == n;
  }
  if(dp[mask] != -1) return dp[mask];
  ll res = 0;
  for(int j = 0; j < n; ++j) {
    if(ar[i][j] && !(mask & (1 << j))) add(res, rec(i + 1, mask | (1 << j))); 
  }
  return dp[mask] = res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < n; ++j) {
      cin >> ar[i][j];
    }
  }
  memset(dp, -1, sizeof dp);
  cout << rec(0, 0) << '\n';
  return 0;
}


Measured memory_bytes: 33024
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> table,res,v[1000000],u[1000000];
int ch[1000000],ans,cnt,tmp,L;
string s,t,S;
map<int,int> mp;
vector<int> pre_kmp(string s){
    vector<int> v(s.size()+1);
    int k;
    v[0]=-1;
    for(int i=1;i<=s.size();i++){
        k=v[i-1];
        while(k>=0){
            if(s[k]==s[i-1])break;
            else k=v[k];
        }
        v[i]=k+1;
    }
    return v;
}
void match(string s, string t){
    int head = 0, j = 0, slen=s.size(),tlen=t.size();
    while(head < slen){
        if(t[j] == s[(head + j)%slen]){
            if(++j != tlen) continue;
            res.push_back(head);
            v[head].push_back((head+tlen)%slen);
            u[(head+tlen)%slen].push_back(head);
        }
        head += j - table[j], j = max(table[j], 0);
    }
}
int rdfs(int a,int b){
    for(auto x:u[a]){
        if(x==b)return -1;
        return rdfs(x,b);
    }
    return a;
}
int dfs(int a,int cnt){
    ch[a]=1;
    for(auto x:v[a]){
        return dfs(x,cnt+1);
    }
    return cnt;
}
int main(void){
    cin>>S>>t;
    s=S;
    while(s.size()<t.size()){
        s+=S;
    }
    //cout<<s<<" "<<t<<endl;
    table=pre_kmp(t);
    match(s,t);
    //for(auto x:res)cout<<x<<"res"<<endl;
    //cout<<rdfs(0,0)<<endl;
    for(int i=0;i<s.size();i++){
        if(ch[i]!=0||v[i].size()==0)continue;
        //cout<<ch[i]<<" "<<i<<endl;
        L=rdfs(i,i);
        if(L==-1){cout<<-1<<endl;return 0;}
        ans=max(ans,dfs(L,0));
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 120720
#abc084b
import sys

a,b=map(int,raw_input().split())
s=raw_input()
if s[a] != '-':
 print 'No'
 sys.exit()
for i in xrange(a):
 if s[i].isdigit()==False:
  print 'No'
  sys.exit()
for i in xrange(a+1,a+1+b):
 if s[i].isdigit()==False:
  print 'No'
  sys.exit()
print 'Yes'


Measured memory_bytes: 2568
R, G, B, N = map(int, input().split())

ans = 0
for i in range(N // R + 1):
    rem1 = N - i * R
    for j in range(rem1 // G + 1):
        rem2 = rem1 - j * G
        if rem2 % B == 0:
            ans += 1
print(ans)

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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



  //二分探索(最小値を出す問題は疑う)

// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < n; ++i){
// 		res += max(0ll, a[i]-x/f[i]);
//     }
//     return res <= k;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }



int main(){
  int N;
  cin >> N;
  vector<int>b(N);
  REP(i, N) {
    cin >> b.at(i);
    b.at(i)--;
  }
  vector<int>ans;
  
  REP(i, N){
    int pos = -1;
    for(int j = b.size() - 1; j >= 0; j--){
      if(b.at(j) == j) {
        pos = j;
        break;
      }       
    }
    if(pos == -1){
      print(-1);
      return 0;
    }
  ans.push_back(pos + 1);
  b.erase(b.begin() + pos);
  }
reverse(all(ans));
REP(i, N) print(ans.at(i));

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <deque>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <cstring>
using namespace std;

#define ll long long

map<ll, ll> mp;

int main() {
  int N;
  ll T;
  cin >> N >> T;
  for (int i = 0; i < N; ++i) {
    ll t;
    cin >> t;
    ++mp[t];
    --mp[t+T];
  }
  ll sum = 0, res = 0, start = -1;
  for (auto& p: mp) {
    sum += mp[p.first];
    if (sum > 0) {
      if (start == -1) start = p.first;
    } else {
      res += p.first - start;
      start = -1;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 25216
#include <stdio.h>

int main(){
  int a,b,i,max=-1111111111;
  scanf("%d %d",&a,&b);
  i = a+b;
  if(max <i) max=i;
  i = a-b;
  if(max <i) max=i;
  i = a*b;
  if(max <i) max=i;
  
  printf("%d",max);
  
  return 0;
}

Measured memory_bytes: 128
/*input
22 3051
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, r; cin >> n >> r;
    if(n < 10) cout << r + 100 * (10 - n);
    else cout << r;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k; 
int main(){
	scanf("%d%d",&n,&k);
	if(k>(n-1)*(n-2)/2){
		printf("-1\n");
	}
	else{
		int cnt=(n-1)*(n-2)/2-k;
		printf("%d\n",n-1+cnt);
		for(int i=2;i<=n;i++){
			printf("1 %d\n",i);
		}
		for(int i=2;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				if(cnt){
					printf("%d %d\n",i,j);
					cnt--;
				} 
				else{
					break;
				}
			}
			if(cnt==0) break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush


n = int(input())
H = list(map(int, input().split()))
dp = [INF]*n
dp[0] = 0

def main():
    for i in range(1, n):
        if i == 1:
            dp[i] = dp[i-1] + abs(H[i] - H[i-1])
        else:
            step_1 = dp[i-1] + abs(H[i] - H[i-1])
            step_2 = dp[i-2] + abs(H[i] - H[i-2])
            dp[i] = min(step_1, step_2)
    print(dp[n-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 84156
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		String t=sc.next();
		if(s.equals(t.substring(0,t.length()-1)) && s.length()+1==t.length()){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35664
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > t(n*2);
        for(int i=0; i<n; ++i){
            int m, a, b;
            cin >> m >> a >> b;
            t[i*2] = make_pair(a, m);
            t[i*2+1] = make_pair(b, -m);
        }
        sort(t.begin(), t.end());

        int w = 0;
        bool ret = true;
        for(int i=0; i<2*n; ++i){
            w += t[i].second;
            if(w > 150)
                ret = false;
        }
        if(ret)
            cout << "OK" << endl;
        else
            cout << "NG" << endl;
    }
}

Measured memory_bytes: 0
fun main(args: Array<String>) {
    readLine()!!
    val A = readLine()!!.split(" ").map{it.toLong()}.toTypedArray()

    if (A.last() != 2L) {
        println(-1)
        return
    }

    A.reverse()

    var l = 2L
    var u = 2L

    for (a in A) {
        l = (l + a - 1) / a * a
        u = (u / a) * a + (a - 1)

        if (l > u) {
            println(-1)
            return
        }
    }

    println("$l $u")
}


Measured memory_bytes: 59520
N, Blue, Red = map(int, input().split())

if(Blue >= N):
    print(N)
elif (Blue + Red) >= N or Blue == 0:
    print(Blue)
else:
    q = N // (Blue + Red)
    mod = N % (Blue + Red)
    if Blue < mod:
        print(q * Blue  + Blue)
    else:
        print(q * Blue + mod)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main() {
	ull N;
	ull K;
	cin >> N >> K;
	vector<ull> A(N);
	vector<ull> bits(64,0);
	for (ull i = 0; i < N; i++) {
		ull tmp;
		cin >> A[i];
		tmp = A[i];
		for (ull j = 0; j < 64; j++) {
			bits[j] += tmp&1;
			tmp = tmp >> 1;
		}	
	}
	ull ans = 0;
	for (ull i = 50; i+1 !=0; i--) {
		if (bits[i] > N/2) continue;
		ans += (1ULL << i);
		if (K < ans) ans -= (1ULL<<i);
	}
	ull sum = 0;
	for (ull i = 0; i < N; i++) {
		sum += ans^A[i];
	}
	cout << sum << endl;
	return 0;
}




Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int x,y,z;
	scanf("%d %d", &x, &y);
	
	if(x > y){
		z = x % y;
		  while(z!=0){
		  x = y;
		  y = z;
		  z = x % y;
		}
		printf("%d\n", y);
	}

	else if(x < y){
		z = y % x;
		  while(z!=0){
		  y = x;
		  x = z;
		  z = y % x;
		}
		printf("%d\n", x);
	}

	else printf("%d\n", x);
}

Measured memory_bytes: 1844
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline void rdi(int &x){
	int f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
const int M=1000005,MK=20005;
const long long P=1000000007;
long long fac[M],fac2[M],dp[M];
int n,m,K,x,y;
struct node{
	int x,y;
	inline bool operator <(const node &_)const{
		if(x!=_.x) return x<_.x;
		return y<_.y;
	}
}A[MK];
inline int C(int K,int m){return fac[K]*fac2[m]%P*fac2[K-m]%P;}
int main(){
	fac[0]=fac2[0]=fac2[1]=1;
	for(int i=1;i<M;++i) fac[i]=i*fac[i-1]%P;
	for(int i=2;i<M;++i) fac2[i]=-P/i*fac2[P%i]%P;
	for(int i=1;i<M;++i) fac2[i]=fac2[i]*fac2[i-1]%P;
	cin>>n>>m>>K;
	for(int i=0;i<K;++i) cin>>A[i].x>>A[i].y;
	sort(A,A+K);
	A[K]=(node){n,m};
	for(int i=0;i<=K;++i){
		dp[i]=C(A[i].x+A[i].y-2,A[i].x-1);
		for(int j=0;j<i;++j){
			int x=A[i].x-A[j].x,y=A[i].y-A[j].y;
			if(x>=0 and y>=0) dp[i]=(dp[i]-dp[j]*C(x+y,x))%P;
		}
	}
	cout<<(dp[K]+P)%P<<endl;
	return 0;
}


Measured memory_bytes: 18688
# ABC172b


def main():
    import sys
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    s = input()
    t = input()
    ans = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9420
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  string s,t,u;
  cin>>s>>t;
  cin>>a>>b;
  cin>>u;
  if(u==s)
     a-=1;
  else if(u==t)
    b-=1;
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int matubi(int n);
int sento(int n);

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

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

	long long ans = 0;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			ans += c[i][j] * c[j][i];
		}
	}
	cout << ans << endl;

	return 0;
}

int matubi(int n)
{
	return n % 10;
}

int sento(int n)
{
	int tmp = n;
	int d = 0;

	while (tmp != 0) {
		d++;
		tmp /= 10;
	}
	
	return n /= (int)pow(10, d - 1);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <list>
#include <math.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


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

  int now_max = 0;
  int count = 0;

  for(int i=0;i<s.size();i++){
    char b = s[i];
    if( b == 'A' || b == 'T' || b == 'C' || b == 'G'){
      count++;
    }else{
      count = 0;
    }
    now_max = max(now_max, count);
  }
  cout<< now_max <<endl;

}

Measured memory_bytes: 256
ans = [0,0,0,0]
for i in range(3):
    a,b = map(int,input().split())
    ans[a - 1] += 1
    ans[b - 1] += 1

if ans.count(1) == 2 and ans.count(2) == 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
a = list(sorted(map(int, input().split())))
if (a[2] - a[0]) % 2 == 0 and (a[2] - a[1]) % 2 == 0:
    print((a[2] - a[0]) // 2 + (a[2] - a[1]) // 2)
elif (a[2] - a[0]) % 2 == 1 and (a[2] - a[1]) % 2 == 1:
    print((a[2] - a[0]) // 2 + (a[2] - a[1]) // 2 + 1)
else:
    if (a[2] - a[0]) % 2 == 1:
        a[0] += 2
        a[1] += 1
        a[2] += 1
    else:
        a[0] += 1
        a[1] += 2
        a[2] += 1
    a = sorted(a)
    if (a[2] - a[0]) % 2 == 0 and (a[2] - a[1]) % 2 == 0:
        print((a[2] - a[0]) // 2 + (a[2] - a[1]) // 2 + 2)
    elif (a[2] - a[0]) % 2 == 1 and (a[2] - a[1]) % 2 == 1:
        print((a[2] - a[0]) // 2 + (a[2] - a[1]) // 2 + 1 + 2)
    else:
        raise


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n,l,q;
    vector<vector<int>> lb;
    vector<int> x;
    Problem(LL n):n(n),lb (n,vector<int>(18)),x(n){};

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

        cin >> l >> q;
        for(int i=0; i<n; ++i){
            lb[i][0]=upper_bound(x.begin(),x.end(),x[i]+l)-x.begin()-1;
        }
        for(int i=1; i<18; ++i){
            for(int j=0; j<n; ++j){
                lb[j][i]=lb[lb[j][i-1]][i-1];
            }
        }
        for(int i=0; i<q; ++i){
            int a,b;
            cin >> a >> b;
            --a;--b;
            if(a>b)swap(a,b);
            int lb = 0,ub = b-a;
            while(ub-lb>1){
                int mid = (ub+lb)/2;
                if(check(a,b,mid)){
                    ub= mid;
                }else{
                    lb = mid;
                }
            }
            cout << ub <<"\n";
        }
    }
    bool check(int a, int b, int x){
        int now = a;
        for(int i=0; i<18; ++i){
            if((x>>i)&1){
                now=lb[now][i];
            }
        }
        return now>=b;
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 11392
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define X real()
#define Y imag()
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

typedef vector<P> G;

enum { OUT, ON, IN };
int contains(const G &g, const P &p) {
  bool in = false;
  for (int i = 0; i < g.size(); ++i) {
    P a = curr(g,i) - p, b = next(g,i) - p;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) <= 0 && 0 < imag(b))
      if (cross(a, b) < 0) in = !in;
    if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}

int main() {
  int N, Q;
  cin >>N;
  G g(N);
  REP(i, N){
    int x, y; cin >>x >>y;
    g[i] = P(x, y);
  }
  cin >>Q;
  REP(q, Q){
    int x, y; cin >>x >>y;
    P p(x, y);
    cout <<contains(g, p) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
  
int main(){
 int n,i;
 long tmp;
 scanf("%d",&n);
 scanf("%ld",&tmp);
 long min=tmp,max=tmp,sum=tmp;
 for(i=1;i<n;i++){
  scanf("%ld",&tmp);
  if(min>tmp){
   min=tmp;
  }if(max<tmp){
   max=tmp;
  }
  sum=sum+tmp;
 }
 printf("%ld %ld %ld\n",min,max,sum);
 return 0;
}

Measured memory_bytes: 600
main :: IO()
main = do
  inputs <- getContents
  let specs = [ map (\x ->read x ::Int) $ words line | line <- lines inputs, length(line) > 0]
  mapM_ drawFrame specs

drawFrame :: [Int] -> IO()
drawFrame [h,w]
          | (h,w) == (0,0) = return()
          | otherwise = do envelope '#' (w-2) $ getRect '.' (h-2) (w-2)

getRect :: Char -> Int -> Int -> [String]
getRect x h w = replicate h $ (replicate w x)

envelope :: Char -> Int -> [String] -> IO()
envelope x w rect = do putStrLn $ concat $  map (\line -> [x] ++ line ++ [x, '\n']) $ [replicate w x]  ++ rect ++ [replicate w x]

Measured memory_bytes: 4236
n = int(input())
d, x = map(int, input().split())
cnt = 0
a = [int(input()) for i in range(n)]

for i in range(len(a)):
    t = d // a[i]
    for j in range(t+1):
        if d >= j*a[i]+1:
            cnt += 1
            
print(cnt+x)

Measured memory_bytes: 64012
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define f first
#define s second
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string a,b,c;
	cin>>a>>b>>c;
	char ch = a[0];
	a = a.substr(1,a.length()-1);
	for(int i =0; ;i++)
	{
		if(ch=='a')
		{
			if(a.length()==0)
			{
				cout<<"A"<<endl;
				break;
			}
			ch=a[0];
			a = a.substr(1,a.length()-1);
		}
		else if(ch=='b')
		{
			if(b.length()==0)
			{
				cout<<"B"<<endl;
				break;
			}
			ch=b[0];
			b = b.substr(1,b.length()-1);
		}
		else
		{
			if(c.length()==0)
			{
				cout<<"C"<<endl;
				break;
			}
			ch=c[0];
			c = c.substr(1,c.length()-1);
		}
	}
	return 0;
}	

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const LL MOD = 1000000007;

template<typename T>
void dump(T a, int n) { for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? '\n' : ' '); }

template<typename T>
void dump(T a) { dump<T>(a, a.size()); }

// base_year, range, name
typedef tuple<int, int, string> Era;

int main(void) {
	for (int N, Q; cin >> N >> Q, N;) {
		vector<Era> eras;
		for (int i = 0; i < N; i++) {
			int year, range;
			string name;
			cin >> name >> range >> year;
			eras.emplace_back(year - range, range, name);
		}

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

		for (int i = 0; i < Q; i++) {
			int qry;
			cin >> qry;

			auto it = upper_bound(eras.begin(), eras.end(), make_tuple(qry, 0, ""));

			if (it == eras.begin()) {
				cout << "Unknown" << endl;
				continue;
			}

			auto era = *(it - 1);
			
			int diff = qry - get<0>(era);
			if (diff <= get<1>(era)) {
				cout << get<2>(era) << " " << diff << endl;
			}else {
				cout << "Unknown" << endl;
			}
		}
	}

	return 0;
}

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

int main(void){
  string s;
  int cnt = 0;
  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    if (s[i]== '+') {
      cnt++;
    }else if (s[i]== '-') {
      cnt--;
    }
  }
  printf("%d", cnt);
  return 0;
}


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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  long a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << max({a * c, a * d, b * c, b * d}) << "\n";
}

Measured memory_bytes: 3656
from collections import defaultdict
def solve():
    N = int(input())
    d = defaultdict(int)

    for _ in range(N):
        d[input()] += 1
    
    print("AC x " + str(d["AC"]))
    print("WA x " + str(d["WA"]))
    print("TLE x " + str(d["TLE"]))
    print("RE x " + str(d["RE"]))
if __name__ == '__main__':
    solve()


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

typedef complex<double> P;

int main() {
  int n;
  cin >> n;
  while(n--) {
    double ra,rb;
    double x1,y1,x2,y2;
    cin >> x1>>y1>>ra>>x2>>y2>>rb;
    P a(x1,y1), b(x2,y2);
    double d = abs(a-b);
    if (d<ra-rb) cout << 2;
    else if (d<rb-ra) cout << -2;
    else if (d<=ra+rb) cout << 1;
    else cout << 0;
    cout << endl;
  }
}

Measured memory_bytes: 0
#include<stdio.h>
int main(){
  int a,b,i,j,d[10010]={};
  scanf("%d %d",&a,&b);
  while(b--){
    scanf("%d %d",&i,&j);
    d[i]++;
    d[j]++;
  }
  for(i=0;i<a;i++)printf("%d\n",d[i+1]);
  return 0;
}
	   


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> idx(n);
    rep(i, n) {
        cin >> idx[i];
        idx[i]--;
    }
    vector<ll> adp(n + 1, 0), bdp(n + 1, 0);
    rep(i, n) {
        ll cidx = idx[i];
        adp[cidx] += i;
        bdp[cidx + 1] -= i;
    }
    rep(i, n) {
        adp[i] += ((i > 0) ? adp[i - 1] : 0);
        bdp[i] += ((i > 0) ? bdp[i - 1] : 0);
    }
    vector<ll> a(n), b(n);
    rep(i, n) {
        a[i] = i + 1 + adp[i];
        b[i] = n - i + bdp[i] + abs(bdp[n - 1]);
    }
    rep(i, n) printf("%lld%s", a[i], (i == (n - 1)) ? "\n" : " ");
    rep(i, n) printf("%lld%s", b[i], (i == (n - 1)) ? "\n" : " ");
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#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++)
using namespace std;

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    map<string,int> mp;
    string s;
    rep(i,n) {
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    int ans = 0;
    for (auto p : mp){
        int k = p.second;
        ans += k*(k-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11264
while True:
    n = int(input())
    if n == 0:break
    A = B = 0
    for i in range(n):
        a,b = map(int,input().split())
        if a > b:A += a + b
        elif a < b:B += a + b
        else:
            A+=a
            B+=b
    print(A,B)

Measured memory_bytes: 7600
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1005;
const char END = '\n';

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

	ll Ans = 1;
	
	rep(i, 3)
		Ans *= N;

	cout << Ans << END;
	return 0;
}

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

int main() {
    int k; scanf("%d", &k);
    vector<vector<int>> dist(k, vector<int>(2, 1e9));
    dist[0][0] = 0;
    priority_queue<pair<int, pair<int, int>>> pq;
    pq.emplace(0, make_pair(0, 0));
    while (!pq.empty()) {
        int x = pq.top().second.first;
        int y = pq.top().second.second;
        pq.pop();
        for (int d = 0; d < 10; ++d) {
            if (dist[(x * 10 + d) % k][y || (d != 0)] > dist[x][y] + d) {
                dist[(x * 10 + d) % k][y || (d != 0)] = dist[x][y] + d;
                pq.emplace(-dist[(x * 10 + d) % k][y || (d != 0)], make_pair((x * 10 + d) % k, y || (d != 0)));
            }
        }
    }
    printf("%d\n", dist[0][1]);
}


Measured memory_bytes: 10228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		//変数//
		int W;		//右上頂点x座標
		int H;		//右上頂点y座標
		int N;		//長方形内の点の個数
		int minwx;	//白い部分のx座標始まり
		int maxwx;	//白い部分のx座標終わり
		int minwy;	//白い部分のy座標始まり
		int maxwy;	//白い部分のy座標終わり
		int warea;	//白い部分の面積
		
		int[] x;	//点のｘ座標
		int[] y;	//点のy座標
		int[] a;	//指定範囲ルールナンバー
		
		Scanner scan = new Scanner(System.in);
		
		//入力//
		W = scan.nextInt();
		H = scan.nextInt();
		N = scan.nextInt();
		
		x = new int[N];
		y = new int[N];
		a = new int[N];
		
		for(int i = 0; i < N; i++){
			x[i] = scan.nextInt();
			y[i] = scan.nextInt();
			a[i] = scan.nextInt();
		}
		
		scan.close();
		
		//処理//
		//初期処理
		minwx = 0;
		maxwx = W;
		minwy = 0;
		maxwy = H;
		
		//ルールナンバーごとに処理
		for(int j = 0; j < N; j++){
			if( a[j] == 1 && minwx < x[j] ){
				minwx = x[j];
			}else if( a[j] == 2 && maxwx > x[j] ){
				maxwx = x[j];
			}else if( a[j] == 3 && minwy < y[j] ){
				minwy = y[j];
			}else if( a[j] == 4 && maxwy > y[j] ){
				maxwy = y[j];
			}
		}
		
		//白い部分が残っているかどうか判定
		if( minwx >= maxwx || minwy >= maxwy ){
			warea = 0;
		}else{
			warea = (maxwx - minwx) * (maxwy - minwy);
		}
		
		//結果//
		System.out.println(warea);

	}

}


Measured memory_bytes: 10832
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
char s[105];
ll n,k;
int main(void){
    cin>>s>>k;
    n=strlen(s);
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            k--;
            if(k==0){
                cout<<1<<endl;
                return 0;
            }
        }else{
            cout<<s[i]<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
ll h[225816],dp[225816];
P segtree[816225];

ll f(int v, ll x){
	ll a, b;
	a = segtree[v].first;
	b = segtree[v].second;
	return a*x+b;
}

void update(ll a, ll b, int l=0, int r=n, int v=0){
	int m = ((l+r)>>1);
	ll o_l,o_m,o_r,n_l,n_m,n_r;
	o_l = f(v,h[l]); o_m = f(v,h[m]); o_r = f(v,h[r]);
	n_l = a*h[l]+b; n_m = a*h[m]+b; n_r = a*h[r]+b;
	if(r-l==1){
		segtree[v] = ((o_l>=n_l)?P(a,b):segtree[v]);
	}else if(o_r >= n_r && o_m >= n_m){
		segtree[v] = P(a,b);
		update(a,b,l,m,v*2+1);
	}else if(o_r < n_r && o_m < n_m){
		update(a,b,l,m,v*2+1);
	}else if(o_l >= n_l && o_m >= n_m){
		segtree[v] = P(a,b);
		update(a,b,m,r,v*2+2);
	}else if(o_l < n_l && o_m < n_m){
		update(a,b,m,r,v*2+2);
	}else if(o_l >= n_l && o_r >= n_r){
		segtree[v] = P(a,b);
	}
}

ll query(int k, int l=0, int r=n, int v=0){
	int m = ((l+r)>>1);
	ll ret = INFLL,vl=INFLL,vr=INFLL;
	if(l<=k && k<r){
		ret = f(v,h[k]);
		if(r-l>1){
			vl = query(k,l,m,v*2+1);
			vr = query(k,m,r,v*2+2);
		}
	}
	ret = min(ret,min(vl,vr));
	return ret;
}


int main(void){
	int i;
	ll c;
	fill(segtree,segtree+816225,P(0ll,INFLL));
	cin >> n >> c;
	h[n] = (ll)(2e6);
	for(i=0; i<n; ++i){
		cin >> h[i];
	}
	for(i=1; i<n; ++i){
		update(h[i-1]*(-2),dp[i-1]+h[i-1]*h[i-1]);
		dp[i] = query(i)+h[i]*h[i]+c;
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;


struct point{
    double x=0,y=0;
    constexpr point(double x=0,double y=0):x(x),y(y){}
    constexpr bool operator==(const point& r)const{return (x==r.x&&y==r.y);};
    constexpr point operator+(const point& r)const{return point(*this)+=r;}
    constexpr point operator+=(const point& r){
        x+=r.x;y+=r.y;
        return *this;
    }
    constexpr point operator-(const point& r)const{return point(*this)-=r;}
    constexpr point operator-=(const point& r){
        x-=r.x;y-=r.y;
        return *this;
    }
    constexpr point operator*(const double& r)const{return point(*this)*=r;}
    constexpr point operator*=(const double& r){
        x*=r;y*=r;
        return *this;
    }
    constexpr point operator/(const double& r)const{return point(*this)/=r;}
    constexpr point operator/=(const double& r){
        x/=r;y/=r;
        return *this;
    }
};

double norm(const point& a){return a.x*a.x+a.y*a.y;}
double abs(const point& a){return sqrt(a.x*a.x+a.y*a.y);}
double dot_product(const point& a,const point& b){return a.x*b.x+a.y*b.y;}
double cross_product(const point& a,const point& b){return a.x*b.y-a.y*b.x;}
point projection(const point& p,const point& b){return b*dot_product(p,b)/norm(b);}
double area(const point& a,const point& b,const point& c){return cross_product(b-a,c-a)/2.0;}

point PP[4];
double are[3];

int main(){
    while(1){
        rep(i,4) cin >> PP[i].x >> PP[i].y;
        if(!cin) break;
        rep(i,3) are[i] = area(PP[3],PP[i],PP[(i+1)%3]);
        if(are[0]>0&&are[1]>0&&are[2]>0||are[0]<0&&are[1]<0&&are[2]<0){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3040
import java.util.*;
public class Main {

    public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
        int Debt = sc.nextInt();
        double a =100;
        for (int i =0;i<Debt;i++){
            a = Math.ceil(a*1.05);
        }
        System.out.println((int)a*1000);
    }
}

Measured memory_bytes: 17300
# coding: utf-8
# Your code here!
import math
n,d = map(int,input().split())	

ans = 0
for i in range(n):
    a = (d+1) + i*(2*d+1)
    if n > a:
        ans += 1
    elif n >= a - d:
        ans += 1
        break
    else:
        break
print(ans)
        

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll; 
const ll MOD = 1000000007;

int main()  
{ 
    FAST_INP;
    int h,w;
    cin >> h >> w;
    char a[1005][1005];
    int dp[1005][1005], v[1005][1005];
    for(int i=0;i<h;i++){
    	cin >> a[i];
	}
	function<int(int,int)> solve = [&](int i, int j){
		// base cases
		if(i>=h||j>=w||a[i][j]=='#') return 0;
		if(v[i][j]) return dp[i][j];
		if(i==h-1&&j==w-1) return dp[i][j]=1;
		v[i][j]=1;
		return dp[i][j]=(solve(i+1,j)+solve(i,j+1))%MOD;
	};
	cout << solve(0,0) << endl;
	return 0;
} 

Measured memory_bytes: 12668
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 2345;
const int MOD = (int)1e9 + 7;
int A[MAXN], B[MAXN];
int dp[MAXN][MAXN];// 0 all, 1 use i, 2 = use j


int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
    for (int i = 1; i <= M; i++) scanf("%d", &B[i]);
    for (int i = 0; i <= N; i++) dp[i][0] = 1;
    for (int j = 0; j <= M; j++) dp[0][j] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
            dp[i][j] =(dp[i][j] - dp[i - 1][j - 1] + MOD) % MOD;
            if (A[i] == B[j]) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
        }
    }
    printf("%d\n", dp[N][M]);
    return 0;
}


Measured memory_bytes: 18816
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n;
	string s;
	cin>>n>>s;
	vector<ll> R(n);
	vector<ll> G(n);
	vector<ll> B(n);
	for(int i = n-1; i> 0; --i){
		R[i-1] = R[i] + (s[i] == 'R');
		G[i-1] = G[i] + (s[i] == 'G');
		B[i-1] = B[i] + (s[i] == 'B');
	}
	ll ans = 0LL;
	for(int i = 0; i<n-2; ++i){
		if(s[i] == 'R')ans += G[i]*B[i];
		if(s[i] == 'G')ans += R[i]*B[i];
		if(s[i] == 'B')ans += G[i]*R[i];
	}
	for(int d = 0; 2*d+3<=n; ++d){
		for(int h = 0; d*2+3+h<=n; ++h){
			if(s[h] != s[h+d+1] && s[h+d+1] != s[h+2*d+2] && s[h]!=s[h+2*d+2])ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define NODE_MAX 105

typedef vector<double> vd;

int main()
{
	while (1)
	{
		int n; cin >> n;
		if (n == 0) return 0;

		vd x(n), y(n), z(n), r(n);
		rep(i, 0, n)
		{
			cin >> x[i] >> y[i] >> z[i] >> r[i];
		}

		double adj[NODE_MAX][NODE_MAX];
		rep(a, 0, n) rep(b, 0, n)
		{
			adj[a][b] = sqrt(abs(x[a] - x[b])*abs(x[a] - x[b]) + abs(y[a] - y[b])*abs(y[a] - y[b]) + abs(z[a] - z[b])*abs(z[a] - z[b])) - r[a] - r[b];
			if (adj[a][b] < 0) adj[a][b] = 0;
		}

		double ans = 0;
		bool finished[NODE_MAX] = { false };
		finished[0] = true;
		rep(i, 0, n - 1)
		{
			int from = -1;
			int to = -1;
			double _min = 10000;
			rep(a, 0, n) rep(b, 0, n)
			{
				if (finished[a] == true && finished[b] == false)
				{
					if (adj[a][b] < _min)
					{
						from = a;
						to = b;
						_min = adj[a][b];
					}
				}
			}

			finished[to] = true;
			ans += _min;
		}

		printf("%.3f\n", ans);
	}
}

Measured memory_bytes: 3164
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  int tmp=0;
  cin>>a>>b>>c;
  for(int t=a;t<=b;t++){
    if(c%t==0){
      tmp++;
    }
  }
  cout<<tmp<<'\n';
  return 0;
}

Measured memory_bytes: 3088
def bubble_sort(A):
    flag = True
    swap = 0
    while flag:
        flag = False
        for j in range(len(A)-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
    return swap
 
if __name__=='__main__':
   N=int(input()) 
   A=list(map(int,input().split()))
   swap = bubble_sort(A)
   print(*A)
   print(swap)


Measured memory_bytes: 5608
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;



	int main(){
		int n, a[MAX];
		cin >> n;
		for (int i = 0; i < n; i++) cin >> a[i];
		int maxv = -2000000000;
		int minv = a[0];

		for (int i = 1; i < n; i++) {
			maxv = max(maxv, a[i] - minv);
			minv = min(minv, a[i]);
		}
		cout << maxv << endl;
		
		return 0;
	}



Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define MAX 100005
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define scan(a) scanf("%d", &a)
#define print(a) printf("%d\n", a);
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
    typedef string::iterator si;
    static void call(si it, si ed) {}
    template<typename T, typename ... aT>
    static void call(si it, si ed, T a, aT... rest) {
        string b;
        for(; *it!=','; ++it)
            if(*it!=' ')
                b+=*it;
        cout << b << "=" << a << " ";
        call(++it, ed, rest...);
    }
};

/* ----------------------------------------------------------------------------------- */


vi adj[MAX];
vi h(MAX);
vi connect(MAX);

void solve() {
    int n, m;
	scanf("%d %d", &n, &m);
    rep(i, 0, n) {
		scanf("%d", &h[i]);
	}
    rep(i, 0, m) {
		int a, b;
		scan(a);
		scan(b);
		a--;
		b--;
		adj[a].push_back(b);
		connect[a]++;
		connect[b]++;
	}

	int total = 0;
	vi ans(n);
    rep(i, 0, n) {
        rep(j, 0, adj[i].size()) {
            if(h[i] > h[adj[i][j]]) {
				// dbg(h[i], adj[i][j], h[adj[i][j]]);
				ans[i]++;
			} else if(h[i] < h[adj[i][j]]) {
                // dbg(h[i], adj[i][j], h[adj[i][j]]);
				ans[adj[i][j]]++;
			}
		}
    }

    rep(i, 0, n) {
        if(connect[i] == ans[i]) {
			total++;
		}
	}
	print(total);
}

int main() {
    solve();

    // __test {
    //     solve();
    // }
}

Measured memory_bytes: 8776
#include <iostream>
using namespace std;
int main(){
  int pas,ju,m =2001; 
  for(int i = 0 ; i < 3 ; i++){
      cin >> pas; 
      if(pas < m)m = pas;
  }
  int n = 2001;
  for(int i = 0 ; i < 2 ; i++){
    cin >> ju;
    if(ju < n)n = ju;
}

  cout << m+n-50 << endl;
  return 0;
}

Measured memory_bytes: 1160
from collections import deque,Counter

import numpy as np

N = int(input())
arrA = np.array(list(map(int,input().split())))
arrB = np.array(list(map(int,input().split())))

arrQ = arrA - arrB
arrQ.sort()
# num = arrQ.sum()
# if num < 0:
#     print(-1)
#     exit()

que = deque(sorted(arrQ))
tmp = 0
ans = 0
while len(que)>0:
    low = que.popleft()
    if low <0:
        tmp += low
        ans += 1
        while tmp < 0 and len(que)>0:
            tmp += que.pop()
            ans += 1
    else:
        break

if tmp < 0:
    print(-1)
    exit()

print(ans)

Measured memory_bytes: 24736
import math
s = input().split()
n=int(s[0])
m=int(s[1])
l=0
r=float('inf')
for i in range(m):
    s = list(map(int,input().split()))
    l=max(l,s[0])
    r=min(r,s[1])
a=r-l
if a>=0:
    print(a+1)
else:
    print(0)


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

int main() {
  uint64_t x = 100;
  uint64_t a;
  cin >> a;
  
  int cnt = 0;
  while (x < a) {
    x += x / 100;
    ++cnt;
  }
  cout << cnt << endl;
}

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

#define N 100000

int main(){
  int x, q, r, i, j, n, A[N], tmp;

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

  r = n - 1;
  x = A[r];

  i = -1;
  for(j = 0; j < r; j++){
    if (A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;
 
  q = i + 1;

  for(j = 0; j < n; j++){
    if(j > 0)
    printf(" ");

    if(j == q)
      printf("[");
    printf("%d", A[j]);
    if(j == q)
      printf("]");
  }

  printf("\n");

  return 0;
}



Measured memory_bytes: 2160
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = input()
    hon = [2,4,5,7,9]
    pon = [0,1,6,8]
    if int(N[-1]) in hon:
        print('hon')
    elif int(N[-1]) in pon:
        print('pon')
    else:
        print('bon')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
#include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    #include<algorithm>
    #include<map>
    #include<cmath>
    #include<cstdlib>
    using namespace std;
    const int M=100010;
char a[M],b[M];
long long int n,m,c,d,ll,kk,y;

int ping(int x)
{
    long long int gg;
    if(x==0)
        return 1;
    else
    {
        gg=1;
        for(int y=1;y<=x;y++)
            gg*=10;
        return gg;
    }
}
int bian(int xx)
{
    return xx-48;
}


int main()
{
  cin>>a;
  cin>>b;
  int i=0;
    while(b[i]!='\0')
    {
        i++;
    }
      int k=0;
    while(a[k]!='\0')
    {
        k++;
    }
    n=0;
    int j=i-1;
    for(int h=0;h<i;h++,j--)
    {
        ll=bian(b[j]);
        n+=ll*(ping(h));
    }
    m=0;
    int g=k-1;
    for(int h=i;h<k+i;h++,g--)
    {
        kk=bian(a[g]);
        m+=kk*(ping(h));
    }
    c=n+m;
    y=sqrt(c);
    d=y*y;
    if(d==c)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    double s = 0.0;
    REP(i,n){
        double x;
        cin >> x;
        s += 1.0 / x;
    }
    printf("%.15f\n", 1.0 / s);

    return 0;
}


Measured memory_bytes: 256