akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>


using namespace std;


int main()
{
	int n;
	int *data;
	double sum, avg, a2;

	while(1){
		cin >> n;
		if(!n)
			break;

		// データの準備・入力
		data = new int[n];
		sum = 0;
		for(int i = 0; i < n; i++){
			cin >> data[i];
			sum += data[i];
		}

		// 平均
		avg = sum / (double)n;

		// 分散
		sum = 0;
		for(int i = 0; i < n; i++)
			sum += pow(data[i] - avg, 2);
		a2 = sum / n;

		// 標準偏差
		cout << fixed;
		cout << sqrt(a2) << endl;

		delete []data;
	}

	return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }        /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }        /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; } /* a,b,c,d.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

char s[101][11];
int p[101];

int str_acs(const void *a, const void *b)
{
  int judge;
  judge = strcmp(s[*(int *)a], s[*(int *)b]); /* aaa,aab.. */
  if (judge == 0)
    return p[*(int *)b] - p[*(int *)a];
  else
    return judge;
}

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

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

  int rest_idx[101];
  for (i = 0; i < n; i++)
    rest_idx[i] = i;

  qsort(rest_idx, n, sizeof(int), str_acs);

  for (i = 0; i < n; i++)
    printf("%d\n", rest_idx[i] + 1);
  return 0;
}


Measured memory_bytes: 128
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::*,
    std::{cmp::*, collections::*, convert::*, iter::*, marker::*, mem::*, ops::*},
};
fn main() {
    input! {//
        k:usize,
        s:Chars,
    }
    if s.len() <= k {
        putChars(&s);
    } else {
        putChars(&s[0..k]);
        print!("...");
    }
    println!();
}
fn putChars(s: &[char]) {
    for &c in s.iter() {
        print!("{}", c);
    }
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a*b/2;
	return 0;
}

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

int main(){
    ll inf = 300000000000;
    ll N, M, L;
    cin >> N >> M >> L;
    vector<vector<ll>> dist(N+1, vector<ll>(N+1, inf));
    for (int i = 1; i <= N; i++) dist[i][i] = 0;
    for (int i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    for (int k = 1; k <= N; k++){
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    vector<vector<ll>> fill(N+1, vector<ll>(N+1, inf));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (dist[i][j] <= L) fill[i][j] = 0;
        }
    }
    
    for (int k = 1; k <= N; k++){
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                fill[i][j] = min(fill[i][j], fill[i][k] + fill[k][j] + 1);
            }
        }
    }
    
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int s, t;
        cin >> s >> t;
        if (fill[s][t] == inf) {
            cout << "-1\n";
            continue;
        }
        cout << fill[s][t] << endl;
        
    }
}

Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int  n;
long long k;
pair<long long,int> a[200005];

int BIT[200005];

void add(int i, int num){
  while( i<= n){
    BIT[i]+= num;
    i += (i & -i);
  }
}

int sum(int i){
  int ret = 0;
  while(i > 0){
    ret += BIT[i];
    i -= (i & -i);
  }
  return ret;
}

int main(){
  cin>>n;
  cin>>k;
  for(int i=0;i<n;i++){
    long long tmp;cin>>tmp;
    a[i] = make_pair(tmp-k,i);
  }

  for(int i=1;i<n;i++){
    a[i].first += a[i-1].first;
  }

  sort(a,a+n);

  //for(int i=0;i<n;i++)cout<<a[i].first<<" "<<a[i].second<<endl;
  //cout<<endl;

  long long ans = 0;


  for(int i=0;i<n;i++){
    //for(int j=0;j<=n;j++)cout<<bit[j]<<" ";cout<<endl;
    ans += (long long)sum(a[i].second);
    //cout<<i<<" "<<a[i].second<<" "<<ans<<endl;
    add(a[i].second+1, 1);
  }

  //cout<<ans<<endl;

  for(int i=0;i<n;i++){
    if(a[i].first >= 0) ans++;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 4096
# spent 4 hrs for this question why i am noob:(
def main():
	n , k = map(int , input().split())
	hd = input()
	grp=[]
	if hd[0]=='1':
		grp = [[0,0]]
	else:
		grp=[[0,0]]
	cnt =1
	for i in range(1, len(hd)):
		if hd[i]==hd[i-1]:
			cnt = cnt+1
		else:
			grp.append([cnt,i])
			cnt = 1
	grp .append([cnt , len(hd)-1])
	pre = [0 for i in range(0 , len(grp)+9)]
	pre[0]=grp[0][0]
	for i in range(1, len(grp)):
		pre[i]=pre[i-1]+grp[i][0]
	ans = 0
	for i in range(0 , len(grp)):
		if hd[grp[i][1]]=='0':
			rgt = min(i+2*k, len(grp)-1)
			ans = max(ans, pre[rgt]-pre[i])
		else:
			rgt = min(i+2*k+1, len(grp)-1)
			ans = max(ans, pre[rgt]-pre[i])
		if rgt==len(grp)-1:
			break
	print(ans)
if __name__=="__main__":
	main()

Measured memory_bytes: 88572
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	while(cin >> n && n){
		int g_max = -1;
		int g_min = 1000;
		for(int i = 0; i < n; i++){
			int grade = 0;
			for(int j = 0; j < 5; j++){
				int g;
				cin >> g;
				grade += g;
			}
			g_max = max(g_max, grade);
			g_min = min(g_min, grade);
		}
		cout << g_max << " " << g_min << endl;
	}
	return 0;
}

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



int main(){
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;

    if(m2==m1+1 && d2==1){
        cout<<1<<endl;

    }else
    cout<<0<<endl;



return 0;
}


Measured memory_bytes: 256
let input = require('fs').readFileSync('/dev/stdin', 'utf8');
input = Number(input);
const arr = [];
const isPrime = num => {
  let flag = 1;
  for(let i = 2; i <= Math.sqrt(num); i++){
    if(num % i === 0) {
      flag = 0;
      break;
    }
  }
  return flag;
};
const factorize = n => {
  if(isPrime(n)) {
    arr.push(n);
  } else {
    for(let i = 2; i <= Math.sqrt(n); i++) {
      if(isPrime(i) && n % i === 0) {
        arr.push(i);
        factorize(n / i);
        break;
      }
    }
  }
};
factorize(input);
console.log(input + ': ' + arr.join(' '));


Measured memory_bytes: 19224
from collections import Counter


def main():
    n = int(input())
    ss = Counter(input() for _ in range(n))
    m = int(input())
    ts = Counter(input() for _ in range(m))
    res = 0
    for k, v in ss.items():
        v -= ts[k]
        res = max(res, v)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
const double pi = 3.14159265358979323846;

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

	double r;
	cin >> r;
	printf("%.06f %.06f\n", pi * r * r, pi * 2 * r);
}


Measured memory_bytes: 3228
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	/*input*/
	int s;
	cin >> s;

	/*calc*/
    string ans{"\0"};
    int up2 = s/100;
    int under2 = s%100;

    if(up2>=1 && up2 <=12) {
    	if(under2 >= 1 && under2 <= 12 ) ans ="AMBIGUOUS";
    	else{ ans = "MMYY"; }
    }
    else{
    	if(under2 >= 1 && under2 <= 12 ) ans ="YYMM";
    	else{ ans = "NA"; }
    }
    /*output*/
	   	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    H, W, K = map(int, input().split())
    s = [None] * H
    for i in range(H):
        s[i] = input()

    preR = [1] * W
    start = 1
    flag = False
    ans = [None] * H
    for i in range(H):
        count = 0
        tmpR = [start] * W
        for j in range(W):
            if s[i][j] == '#':
                if count > 0:
                    tmpR[j] += count
                count += 1
            else:
                tmpR[j] += max(0,count-1)
        # print('count',count)
        if i == 0:
            if count == 0:
                flag = True
            else:
                ans[0] = tmpR
                start += count
                preR = tmpR
        else:
            if count == 0:
                if flag:
                    pass
                else:
                    ans[i] = preR
            else:
                ans[i] = tmpR
                if flag:
                    for k in range(i):
                        ans[k] = tmpR
                    flag = False
                start += count
                preR = tmpR
    [print(*ans[i]) for i in range(H)]

if __name__ == "__main__":
    main()


Measured memory_bytes: 7888
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100005;
int spf[MAXN];
ll fac1[MAXN],fac2[MAXN],inv[MAXN];
ll gcd(ll x, ll y){ return y?gcd(y,x%y):x; }

void sieve(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

void pre(){
    fac1[0]=fac2[0]=inv[1]=1;
    for(int i=1;i<MAXN;i++){
        fac1[i]=(fac1[i-1]*i)%mod;
        if(i>1) inv[i]=( mod - ((ll)(mod/i)*inv[mod%i])%mod ) %mod;
    }
    for(int i=1;i<MAXN;i++) fac2[i]=(fac2[i-1]*inv[i])%mod;
}
ll C(int n,int k){
    if(n<k) return 0;
    return ((fac1[n]*fac2[n-k]%mod)*fac2[k]%mod);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,t=1;
    // cin>>t;
    while(t--){
        string s;
        cin>>s;
        n=sz(s);
        if(s[n-1]=='s'){
            cout<<s+"es"<<nl;
        }
        else cout<<s+"s"<<nl;
        
    }
    return 0;
}

Measured memory_bytes: 3056
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



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

	int m = 0;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (m <= h[i]) {
			cnt++;
			m = h[i];
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3628
/*
 * main.cpp
 *
 *  Created on: 2020/05/13
 *      Author: yamashhi
 */
#include <iostream>

//動的配列<vector>の使用記述
#include <vector>


using namespace std;


int main(){

	int num;

	cin >> num ;
	vector<int> vec;
	vector<int> popvec;

	while(num){
		int innum;
		cin >> innum;

		switch (innum) {

		case 0:
			int pushnum;
			cin >> pushnum;

			/*
			 * push_back()
			 * 配列の末尾に要素を追加する
			 */
			vec.push_back(pushnum);
			break;

		case 1:
			int popnum;

			cin >> popnum;
			popnum =vec[popnum];
			popvec.push_back(popnum);
			break;

		case 2:
			/*
			 * pop_back()
			 * 配列の末尾の要素を削除する
			 */
			vec.pop_back();
			break;
		default:
			break;
		}
		num--;
	}

	int size ;
	size = popvec.size();
	int popnum = 0;

	while(size){
		cout << popvec[popnum] << endl;
		++popnum;
		size--;
	}


}





Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;

  if (c >= a && c <= b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3532
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {

    public static void main (String[] args) throws IOException{
	long start = System.currentTimeMillis();
	Scanner scan = new Scanner(System.in);
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	//int n = new Integer(br.readLine()).intValue();
	int n = scan.nextInt();
	int[] a = new int[n];
	int[] b = new int[n];
	int max = 0;
	//String[] inputArray = br.readLine().split(" ");
	for (int i = 0; i < n; i++) {
	    a[i] = scan.nextInt();
	    //a[i] = new Integer(inputArray[i]).intValue();
	    max = Math.max(max, a[i]);
	}
	//int[] b = new int[n];
	CountingSort(a, b, max);
	StringBuilder sb = new StringBuilder();
	//sb.append(b[0]);
	for (int i = 0; i < n; i++) {
	    sb.append(b[i]).append(' ');
	}
	//sb.append(b[n-1]);
	System.out.println(sb.toString().trim());
	long end = System.currentTimeMillis();
	//System.out.println((end-start) + "ms");
    }
    static void CountingSort (int[] a, int[] b, int k) {
	int n = a.length;
	int[] c = new int[k+1];
	for (int j = 0; j < n; j++) {
	    c[a[j]]++;
	}
	for (int i = 1; i <= k; i++) {
	    c[i] = c[i] +c[i-1];
	}
	for (int j = n - 1; j >= 0; j--) {
	    b[c[a[j]]-1] = a[j];
	    c[a[j]]--;
	}
    }
}

Measured memory_bytes: 536440
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    string s, t;
    cin >> s >> t;
    cout << t << s;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 10000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

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

    vector<ll> vec(x+y+c);
    vector<ll> v1(a), v2(b);
    for(auto& it : v1) cin>>it;
    for(auto& it : v2) cin>>it;
    for(int i = 0; i<c; ++i)
        cin>>vec[i];

    sort(all(v1), greater<ll>());
    sort(all(v2), greater<ll>());

    for(int i = 0; i<x; ++i) vec[i+c] = v1[i];
    for(int i = 0; i<y; ++i) vec[i+c+x] = v2[i];

    sort(all(vec), greater<ll>());

    ll ans = 0;
    for(int i = 0; i<x+y; ++i)
        ans += vec[i];

    cout<<ans<<endl;
} 

Measured memory_bytes: 3968
n, p = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0, 0] for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(2):
        dp[i+1][j] += dp[i][j]
        dp[i+1][(j+a[i])%2] += dp[i][j]
print(dp[n][p])

Measured memory_bytes: 3064
#include <stdio.h>
long long p = 1000000007;
long long n, k;
long long rui(long long a, long long b) {
	if (b == 0)return 1;
	if (b == 1)return a;
	if (b == 2)return a * a % p;
	if (b % 2)return(rui(rui(a, b / 2), 2) * a % p);
	return rui(rui(a, b / 2), 2);
}
long long inv(long long a) {
	return rui(a, p - 2);
}
long long kai[5000];
long long ans;
int main() {
	scanf("%lld%lld", &n, &k);
	kai[0] = 1;
	for (int i = 1; i < 5000; i++) {
		kai[i] = kai[i - 1] * i % p;
	}
	for (long long i = 1; i <= k; i++) {
		if (n - k - i + 1 < 0)ans = 0;
		else ans = 1;
		ans *= kai[k - 1]; ans %= p;
		ans *= inv(kai[k - i]); ans %= p;
		ans *= inv(kai[i - 1]); ans %= p;
		ans *= kai[n - k + 1]; ans %= p;
		if (ans)ans *= inv(kai[n - k + 1 - i]); ans %= p;
		ans *= inv(kai[i]); ans %= p;
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

vector<int> adj[200001];
int childs[200001];

ll res;
int n;

ll modpow(int a, int b)
{
  if(b == 1)
    return a;
  else if(b % 2 == 0)
  {
    ll temp = modpow(a, b/2);
    return temp * temp % mod;
  }
  else
    return modpow(a, b-1) * a % mod;
  
}

int inv(int a) {
  return modpow(a, mod-2); 
}



int dfs(int cur, int pre)
{
  vector<int> vcounts;
  childs[cur] = 1;
  
  for(int i = 0; i < adj[cur].size(); i++)
    if(adj[cur][i] != pre)
    {
      vcounts.push_back(dfs(adj[cur][i], cur));
      childs[cur] += vcounts.back();
    }
  
  if(childs[cur] < n)
    vcounts.push_back(n-childs[cur]);
  
  ll p[3] = {(mod+1)/2, 0, 0};
  
  for(int i = 0; i < vcounts.size(); i++)
  {
    ll q[3] = {};
    int w = modpow((mod+1)/2, vcounts[i]);
    int b = (mod+1 - w) % mod;
    
    q[0] = (p[0] * w) % mod;
    q[1] = ((p[0] * b) % mod + (p[1] * w) % mod) % mod;
    q[2] = (p[2] + p[1] * b) % mod;
    
    swap(p, q);
    
    /*if(cur == 2)
      printf("%llda\n", w);*/
  }
  //printf("%lld\n", p[2]);
  res += p[2];
  res %= mod;
  
  return childs[cur];
}

int main()
{
  scanf("%d", &n);
  
  for(int i = 0; i < n-1; i++)
  {
    int a, b;
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  
  dfs(1, -1);
  
  //printf("%lld\n", (((ll)mod+1)/2 * ((mod+1)/2))%mod);
  
  printf("%lld\n", res);
  
  return 0;
}


Measured memory_bytes: 34560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
#define int long long
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

signed main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep (i, 1, n + 1) {
        int k = i;
        for (int j = 2; j * j <= k; j++) {
            while (k % j == 0) {
                k /= j;
                mp[j]++;
            }
        }
        mp[k]++;
    }
    int ans = 1;
    const int mod = 1e9 + 7;
    for (auto p : mp) {
        // cout << p.first << " : " << p.second << "\n";
        if (p.first == 1) continue;
        ans = ans * (p.second + 1) % mod;
        // cout << ans << "\n";
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int main(){
    optimizar_io
    char a,b; cin>> a >> b;
    if(a<b)cout<<'<'<<endl;
    else if(b<a)cout<<'>'<<endl;
    else cout<<'='<<endl;
}



Measured memory_bytes: 256
import math

def f(h, a, b, t):
    y = 0
    for hi in h:
        if hi-b*t <= 0:
            break
        else:
            y += math.ceil((hi-b*t)/(a-b))
    if y <= t:
        return True
    else:
        return False

n, a, b = list(map(int, input().split()))
h = []
for _ in range(n):
    h.append(int(input()))
h.sort(reverse=True)

low = 0
high = math.ceil(h[0]/b)

while True:
    m = (low+high)//2
    if f(h,a,b,m):
        high = m
    else:
        low = m
    if low +1 == high:
        break

print(high)

Measured memory_bytes: 7480
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,Y = (int(_) for _ in input().split())
    # 10000
    for i in range(N+1):
        # 50000
        for j in range(N+1):
            cnt_of_1000 = N - i -j
            if cnt_of_1000 < 0:
                continue
            sum_of_yen = i* 10000 + j* 5000 + cnt_of_1000*1000
            if sum_of_yen == Y:
                print(i,j,cnt_of_1000)
                return
    print('-1 -1 -1')
if __name__ == '__main__':
    main()


Measured memory_bytes: 41324
def resolve():
    n, a, b = map(int, input().split())
    ss = input()
    b_count = 0
    total = 0
    for i, s in enumerate(ss):
        i += 1
        if s == "a":
            if total < a+b:
                total += 1
                print("Yes")
                continue
        elif s == "b":
            b_count += 1
            if total < a+b and b_count <= b:
                total += 1
                print("Yes")
                continue
        print("No")
resolve()

Measured memory_bytes: 9052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

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

bool comp(const string& a, const string& b)
{
	if(a.size() != b.size()) return a.size() > b.size();
	return a < b;
}

int main()
{
	int W, H;
	while(cin >> H >> W, (W||H)) {
		string field[10];
		for(int i=0; i<H; i++)
			cin >> field[i];

		string res;
		map<string, int> spells;
		for(int i=0; i<W; i++)
		for(int j=0; j<H; j++)
		for(int k=0; k<8; k++)
		{
			string s;
			int x = i, y = j;
			bool visit[10][20] = {0};
			while(1)
			{
				if(visit[y][x]) break;
				visit[y][x] = true;
				
				s += field[y][x];

				y = (y+dy[k]+H)%H;
				x = (x+dx[k]+W)%W;
				
				spells[s]++;
				if(spells[s] >=2 && comp(s,res)) res = s;
			}

		}

		if(res.size() <= 1) res = "0";
		cout << res << endl;
	}
}

Measured memory_bytes: 27000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL<<60;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,m,n) for(int i=m;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const double pi = 3.14159265358979323846;

int main(){
    int a;
    cin >>a;
    cout<<a*(1+a+a*a)<<endl;
}

Measured memory_bytes: 3544
x = int(input())
ans = 8
if x<600: ans=8
elif x<800: ans=7
elif x<1000: ans=6
elif x<1200: ans=5
elif x<1400: ans=4
elif x<1600: ans=3
elif x<1800: ans=2
else: ans=1
# elif x<2000: ans=1
print(ans)


Measured memory_bytes: 9028
#include <cstdio>
using namespace std;

int main ()
{
  int X, Y, Z;
  int r, s;

  scanf("%d", &X);
  scanf("%d", &Y);
  scanf("%d", &Z);

  s = X / (Y + Z);
  r = X % (Y + Z);
  if (r < Z) {
    printf("%d\n", s-1);
  } else {
    printf("%d\n", s);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

long double a, b, x;

void input() {
    cin >> a >> b >> x;
}

long double f(long double a, long double b, long double theta) {
    
    long double ret;
    if(a * tan(theta) <= b) {
        ret = a * a * b - a * a * a * tan(theta) / 2.0;
    } else {
        ret = b * b / tan(theta) * a / 2.0;
    }
    return ret;
}

void solve() {
    input();
    long double ok = PI / 2.0;
    long double ng = 0.0;
    for(int _ = 1; _ <= 100000; _++) {
        long double mid = (ok + ng) / 2.0;
        if(f(a, b, mid) < x) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(10) << ok / PI * 180 << endl;
    return;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
const int Maxn=1e5+10;
set<pair<int,int>>st[Maxn];
map<int,string>mp;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;cin>>n>>m;
    for(int i=1,x,y;i<=m;++i){
        cin>>x>>y;
        st[x].insert({y,i});
    }
    for(int i=1;i<=n;++i){
        int cnt=1;
        string s1=to_string(i);
        while(int(s1.size())<6)s1="0"+s1;
        for(auto x:st[i]){
            string s2=to_string(cnt);
            while(int(s2.size())<6)s2="0"+s2;
            mp[x.second]=s1+s2;
            ++cnt;
        }
    }
    for(auto x:mp)cout<<x.second<<"\n";
}

Measured memory_bytes: 20836
x, k, d = map(int, input().split())

from math import floor, ceil
def do(x, k, d):
    t1, t2 = floor(x/d), ceil(x/d)
    ogk = k
    ogx = x

    x -= t1*d
    k -= t1
    ans1 = 10**16
    if k%2 == 0:
        ans1 = abs(x)
    else:
        ans1 = min(abs(x + d), abs(x - d))

    x, k = ogx, ogk
    x -= t2*d
    k -= t2
    ans2 = 10**16
    if k%2 == 0:
        ans2 = abs(x)
    else:
        ans2 = min(abs(x + d), abs(x - d))
    
    print(min(ans1, ans2))


if x > 0:
    if x - k*d < 0:
        q = round(x/d)
        do(x, k, d)
    else:
        print(x - k * d)

elif x < 0:
    if x + k*d > 0:
        do(abs(x), k, d)
    else:
        print(abs(x + k*d))

else:
    # x == 0
    if k%2:
        print(d)
    else:
        print(0)


Measured memory_bytes: 62308
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 2e5+5;
int a[M],b[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++)
		cin>>a[i]>>b[i];
	set<pair<pair<int,int>,int>> st;
	multiset<int> res;
	for(int i=1;i<=w;i++)
	{
		st.insert({{i,i},i});
		res.insert(0);
	}
	for(int i=1;i<=h;i++)
	{
		while(1)
		{
			auto it = st.upper_bound({{a[i],-1},-1});
			if(it == st.end())
				break;
			if((it->ff).ff > b[i])
				break;
			auto P = *(it);
			// erase contribution from res
			res.erase(res.find(P.ff.ff-P.ss));
			if(it == st.begin())
			{
				st.erase(it);
				if(P.ff.ss > b[i])
				{
					P.ff.ff = b[i]+1;
					res.insert(P.ff.ff-P.ss);
					st.insert(P);
				}
			}
			else
			{
				auto Q = *(--it);
				st.erase(P);
				st.erase(Q);				
				if(P.ff.ss > b[i])
				{
					P.ff.ff = b[i]+1;
					res.insert(P.ff.ff-P.ss);
					st.insert(P);
					Q.ff.ss = b[i];
					st.insert(Q);
				}
				else
				{
					Q.ff.ss = P.ff.ss;
					st.insert(Q);
				}
			}
		}
		// cout<<"====="<<i<<"====="<<endl;
		// for(auto u:st)
		// 	cout<<u.ff.ff<<" "<<u.ff.ss<<" "<<u.ss<<endl;
		// cout<<"====="<<endl;
		if(sz(res))
			cout<<i + *(res.begin())<<"\n";
		else
			cout<<"-1\n";
	}
	return 0;
}

Measured memory_bytes: 26996
/*
[dp] J - Sushi
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 300;

int N;
int a[MAX_N];

double solve() {
    vector<vector<vector<double>>> dp(
        N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1)));
    int cnt[4];

    for (int j = 1; j <= 3; j++) {
        cnt[j] = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] >= j) {
                cnt[j]++;
            }
        }
    }

    dp[0][0][0] = 0;
    for (int i = 1; i <= cnt[1]; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i][j][k] = N;
                if (k > 0) {
                    dp[i][j][k] += dp[i][j][k - 1] * k;
                }
                if (j > k) {
                    dp[i][j][k] += dp[i][j - 1][k] * (j - k);
                }
                if (i > j) {
                    dp[i][j][k] += dp[i - 1][j][k] * (i - j);
                }
                dp[i][j][k] /= i;
            }
        }
    }

    return dp[cnt[1]][cnt[2]][cnt[3]];
}

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

    cout << setprecision(16) << solve() << endl;

    return 0;
}


Measured memory_bytes: 216832
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int M = scanner.nextInt();
        int N = scanner.nextInt();
        System.out.println(new Power().pow(M, N));
    }

}

class Power {
    private long MOD = 1_000_000_007;

    public long pow(long x, long n) {
        return pow(x, n, MOD);
    }

    public long pow(long x, long n, long mod) {
        long res = 1;
        while (n > 0) {
            if ((n & 1) > 0) {
                res = res * x % mod;
            }
            x = x * x % mod;
            n >>= 1;
        }
        return res;
    }
}



Measured memory_bytes: 26428
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

int ans1[300000];
int ans2[300000];

signed main(){
    int n,k,c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    int ndays = 0;
    REP(i,k){
        while(s[ndays]=='x'){
            ndays ++;
        }
        if(s[ndays] == 'o'){
            ans1[i] = ndays;
            ndays += c+1;
        }
        
    }
    ndays = n-1;
    REP(i,k){
        while(s[ndays]=='x'){
            ndays --;
        }
        if(s[ndays] == 'o'){
            ans2[k-1-i] = ndays;
            ndays -= c+1;
        }
    }
    REP(i,k){
        if(ans1[i] == ans2[i]){
            cout << ans1[i]+1 << endl;
        }
    }




    return 0;
}

Measured memory_bytes: 6716
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
    int ans = INF;
    FOR(i,1,1000001){
        if(N%i==0){
            int j = N/i;
            int tmp = i+j-2;
            ans = min(ans,tmp);
        }
    }
    Out(ans);
}

Measured memory_bytes: 256
#include<stdio.h>
typedef long long LL;
const int mod=1000000007;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	if(n>m){int t=n;n=m;m=t;}
	if(n+1<m) puts("0");
	else{
		int x=1,y=1;
		for(int i=1;i<=n;++i) x=(LL)x*i%mod;
		y=x; if(m==n+1) y=(LL)y*m%mod;
		if(n==m) x=(LL)x*2%mod*y%mod;
		else x=(LL)x*y%mod;
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n, u, v;
int dp[100007][2];
vector <int> edge[100007];
const int mod = 1e9 + 7;

void add(int &a, int b){
	a = (1LL * a * b) % mod;
}

void dfs(int u, int par){
	dp[u][0] = dp[u][1] = 1;
	for(int v : edge[u]){
		if(v == par) continue;
		dfs(v, u);
		add(dp[u][0], dp[v][0] + dp[v][1]);
		add(dp[u][1], dp[v][0]);
	}
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 1; i < n; i++){
		cin >> u >> v;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	dfs(1, 1);
	cout << (dp[1][1] + dp[1][0]) % mod;
}


Measured memory_bytes: 13440
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        int gcd(int a, int b) {
            if (b == 0) return a;
            return gcd(b, a % b);
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            int gcd = 0, max = 0;
            for (int i = 0; i < n; ++i) {
                int a = in.nextInt();
                gcd = gcd(gcd, a);
                max = Math.max(max, a);
            }

            if (k <= max && (max - k) % gcd == 0)
                out.println("POSSIBLE");
            else out.println("IMPOSSIBLE");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();

        }

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

    }
}



Measured memory_bytes: 35272
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
a,b  = ma()
x = lma()
ans = 10 **18
for i in range(a-b+1):
    a0 = x[i]
    ab = x[i+b-1]
    if ab< 0 :
        ans = min(ans,abs(a0))
    elif a0 <=0 and 0 <= ab:
        ans = min(ans, ab-2*a0, 2*ab-a0)
    else:
        ans = min(ans,ab)
print(ans)


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int N;
    while (cin >> N, N) {
        vs lines(N);
        REP(i, N) {
            cin >> lines[i];
            REP(j, SZ(lines[i])-1) {
                if (lines[i][j] == '.') {
                    if (lines[i][j+1] != '.') {
                        lines[i][j] = '+';
                        break;
                    } else {
                        lines[i][j] = ' ';
                    }
                }
            }
        }
        REP(i, N) {
            REP(j, SZ(lines[i])-1) {
                if (lines[i][j] == '+') {
                    int h = i+1, bh = i+1;
                    while (h < SZ(lines)) {
                        if (j >= SZ(lines[h])) break;
                        if (lines[h][j] == '+') {
                            FOR(k, bh, h) {
                                lines[k][j] = '|';
                            }
                            bh = h+1;
                        } else {
                            if (lines[h][j] != ' ') break;
                        }
                        h++;
                    }
                }
            }
        }

        REP(i, N) {
            cout << lines[i] << endl;
        }
    }
}

Measured memory_bytes: 3672
attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end

require 'pp'
N, M = attrs[0].map{|a| a.to_i}
res = 0
res += [*1..N].combination(2).to_a.length if N > 1
res += [*1..M].combination(2).to_a.length if M > 1
puts res

Measured memory_bytes: 2428
#include <vector>
#include <numeric>
#include <algorithm>

class unionfind {
private:
	int size_;
	std::vector<int> parent;
	std::vector<int> rank;
public:
	unionfind() : size_(0), parent(std::vector<int>()), rank(std::vector<int>()) {};
	unionfind(int size__) : size_(size__), parent(std::vector<int>(size_)), rank(std::vector<int>(size_, 0)) {
		std::iota(parent.begin(), parent.end(), 0);
	}
	int size() { return size_; }
	int root(int x) {
		if (parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	void unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) parent[x] = y;
		else if (rank[x] > rank[y]) parent[y] = x;
		else parent[y] = x, rank[x]++;
	}
};

#include <iostream>
using namespace std;
int n, m, x[109], y[109]; long long c[109]; bool used[109];
bool solve() {
	unionfind uf(n);
	for (int i = 0; i < m; i++) {
		if (used[i]) uf.unite(x[i], y[i]);
	}
	int s = uf.root(0);
	for (int i = 1; i < n; i++) {
		if (s != uf.root(i)) return true;
	}
	return false;
}
int main() {
	while (cin >> n >> m, n) {
		int sum = 0;
		for (int i = 0; i < m; i++) {
			cin >> x[i] >> y[i] >> c[i];
			if (c[i] > 0) used[i] = true;
			else used[i] = false, sum += c[i];
		}
		long long ret = 1LL << 60;
		if (solve()) ret = sum;
		for (int i = 0; i < m; i++) {
			if (!used[i]) continue;
			used[i] = false;
			if (solve()) ret = min(ret, sum + c[i]);
			used[i] = true;
		}
		for (int i = 0; i < m; i++) {
			if (!used[i]) continue;
			used[i] = false;
			for (int j = i + 1; j < m; j++) {
				if (!used[j]) continue;
				used[j] = false;
				if (solve()) ret = min(ret, sum + c[i] + c[j]);
				used[j] = true;
			}
			used[i] = true;
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 2932
import fractions 

N = int(input())
A = list(map(int, input().split()))
MODE = 10**9+7

def lcm(a, b):
    return a*b//fractions.gcd(a,b)

_lcm = 1
for a in A:
    _lcm = lcm(a, _lcm)

ret = 0
for a in A:
    ret += (_lcm // a)

print(ret%MODE)


Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int dp[1005][10005];

int main() {
    int h, n;
    cin >> h >> n;
    rep(i,n+1)rep(j,h+1) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n) {
        int a, b;
        cin >> a >> b;
        rep(j,h+1) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][min(j+a,h)], dp[i+1][j] + b);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

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

const int MOD = 1000000007;
using Data = pair<long long, vector<ll> >;

int main() {
  ll n;
  cin >> n;
  vector<ll>vec(n);
  rep(i,n) cin >> vec[i];
  rep(i,n-1){
    if(vec[i]<vec[i+1]) vec[i+1]--;
    else if(vec[i]==vec[i+1])continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes"<< endl;
  return 0;
 
}

Measured memory_bytes: 1024
N = int(input())
a = map(int, input().split())
e = 0
c = 0
cc = 0
for i, an in enumerate(a):
    if i + 1 == an:
        e = e + 1
        c = c + 1
    else:
        cc = cc + c // 2
        c = 0
cc = cc + c // 2
print(e-cc)

Measured memory_bytes: 10420
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int count;
int main() {
    string s;
    cin>>s;
    if(s[0]=='1') count++;
    if(s[1]=='1') count++;
    if(s[2]=='1') count++;
    cout<<count<<endl;
}


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

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

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

void solve(void){
    int a,b;

    cin >> a >> b;

    cout << a%b << endl;
}


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



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

long long x, b, c, d;

long long GCD(long long a1, long long a2) {
	if (a1 < a2) { swap(a1, a2); }
	if (a2 == 0) { return a1; }
	return GCD(a2, a1 % a2);
}

int main() {
	while (true) {
		cin >> x >> b >> c >> d;
		if (x == 0 && b == 0 && c == 0 && d == 0) { break; }
		long long v = x * 360 - x * 3 - 3;
		if (v % 3 == 0) { v /= 3; }
		long long w = 3600 * x;
		long long a = (b * 3600 + c * 60 + d)*v;
		long long H = 3600 * v;
		long long M = 60 * v;
		long long S = v;
		for (long long  h= 0; h <= v * x * 3600 * 2; h += w) {
			long long i = h % (v*x * 3600);
			long long HI = i;
			long long MI = (i%H) * 60;
			if (h >= a && HI != MI) {
				long long H1 = i / H;
				long long M1 = (i / M) % 60;
				long long S1 = i - (H1*H + M1*M);

				cout << H1 << ' ' << M1 << ' ' << S1 / GCD(S1, v) << ' ' << v / GCD(S1, v) << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1156