akhauriyash/Code-Regression huggingface dataset:
# cook your dish here
n, m = map(int, input().split(" "))
a = [list(map(int, input().split(" "))) for i in range(m)]
 
a_connects = [[] for i in range(n)]
for x, y in a:
	a_connects[x-1].append(y-1)
	a_connects[y-1].append(x-1)

jkl = []
for i in range(n):
    jkl.append(1)#if 1 ; mada

def ss(n): #jkl[n]
    jkl[n] = 0
    for x in a_connects[n]:
        if jkl[x] != 0:
            ss(x)
ass = 0            
for i in range(m):
    a_connects[a[i][0]-1].remove(a[i][1]-1)
    a_connects[a[i][1]-1].remove(a[i][0]-1)
    ss(0)
    if sum(jkl) != 0:
        ass += 1
    a_connects[a[i][0]-1].append(a[i][1]-1)
    a_connects[a[i][1]-1].append(a[i][0]-1)
    jkl = []
    for i in range(n):
        jkl.append(1)
print(ass)

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


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    unordered_map<string,int> mp;
    ll cnt = 0;
    for(int i =0; i< n; i++){
        string t;
        cin>>t;
        sort(t.begin(),t.end());
        
        if(mp.find(t) == mp.end()){
            mp.insert(make_pair(t,1));
         }else{
            cnt += mp[t]++;
        }
    }

    cout<< cnt <<endl;
    return 0;
}


Measured memory_bytes: 10660
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int N;
//v_iの部分和を格納している,初期値はすべてのv_iがゼロとする
//配列の数は要素数より大きいconstに
//bit[0]は使わない...
int bit[501][501]={};

//v_a=wとしたときにBITの値を更新する O(logN)
void add(int a, int b, int w) {
  for (int x = a; x <= N; x += x & -x){
    for (int y = b; y <= N; y += y & -y){
      bit[x][y] += w;
    }
  }
}

int sum(int a, int b) {
  int ret = 0;
  for (int x = a; x > 0; x -= x & -x){
    for (int y = b; y > 0; y -= y & -y){
      ret += bit[x][y];
    }
  }
  return ret;
}


int main(){
  int M, Q;
  cin >> N >> M >> Q;
  int L[M], R[M], p[Q], q[Q];
  REP(i, M){
    cin >> L[i] >> R[i];
  }
  REP(i, Q){
    cin >> p[i] >> q[i];
  }
  int memo[N+1][N+1] = {};
  REP(i, M){
    add(N-L[i]+1, R[i], 1);
  }

  REP(i, Q){
    cout << sum(N-p[i]+1, q[i]) << endl;
  }


  return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

#define ll long long

int main() {
    string s;
    int Q;
    char head[200010];
    char tail[200010];
    int hn = 0;
    int tn = 0;

    bool st = true;
    cin >> s >> Q;
    for (int i = 0; i < Q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            st = !st;
        } else {
            int f;
            char c;

            cin >> f >> c;
            if ((f == 1) == st) {
                head[hn] = c;
                hn++;
            } else {
                tail[tn] = c;
                tn++;
            }
        }
    }

    if (!st) {
        swap(head, tail);
        swap(hn, tn);
    }
    for (int i = 0; i < hn; ++i) {
        cout << head[hn - i - 1];
    }
    for (int i = 0; i < s.length(); ++i) {
        if (st) cout << s[i];
        if (!st) cout << s[s.length() - i - 1];
    }
    for (int i = 0; i < tn; ++i) {
        cout << tail[i];
    }
    cout << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

int main() {
    ll H, W;
    cin >> H >> W;
    ll sh, sw, gh, gw;
    cin >> sh >> sw;
    cin >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;

    // 道の一覧
    vector<vector<bool>> roads(H, vector<bool>(W, false));
    for (ll h = 0; h < H; h++) {
        for (ll w = 0; w < W; w++) {
            char c;
            cin >> c;
            while (c != '.' && c != '#') {
                cin >> c;
            }
            if (c == '.') {
                roads[h][w] = true;
            }
        }
    }

    vector<vector<bool>> done(H, vector<bool>(W, false));
    vector<stack<pair<ll, ll>>> diststack(256);
    ll d = 0;
    diststack[0].push(make_pair(sh, sw));
    while (true) {
        if (diststack[d].empty()) {
            if (diststack[d + 1].empty()) {
                break;
            }
            if (diststack.size() < d * 2) {
                diststack.resize(d * 2);
            }
            d++;
            continue;
        }
        auto src = diststack[d].top();
        diststack[d].pop();
        ll h = src.first;
        ll w = src.second;
        if (h == gh && w == gw) {
            cout << d << endl;
            return 0;
        }
        if (done[h][w]) {
            continue;
        }
        done[h][w] = true;
        for (ll y = h - 2; y <= h + 2; y++) {
            for (ll x = w - 2; x <= w + 2; x++) {
                if (y >= 0 && y < H && x >= 0 && x < W && roads[y][x] && !done[y][x]) {
                    if (abs(x - w) + abs(y - h) == 1) {
                        diststack[d].push(make_pair(y, x));
                    } else {
                        diststack[d + 1].push(make_pair(y, x));
                    }
                }
            }
        }
    }
    cout << -1 << endl;
}


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

typedef long long ll;

const int N = 2e5 + 5;
int n;
ll k;
ll A[N], F[N];

bool check(ll s) {
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (A[i] * F[i] > s) {
            ll nc = s / F[i]; // new coefficient
            cnt += A[i] - nc;
        }
    }
    return cnt <= k;
}

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

    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> F[i];
    }
    sort(A, A + n); // non-decreasing order
    sort(F, F + n, greater<int>());

    ll l = 0, r = 1e12;
    while (l < r) {
        ll m = (r - l) / 2 + l;
        if (check(m)) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    cout << l << endl;

    return 0;
}



Measured memory_bytes: 3328
s = input()
n = int(input())
for i in range(n):
 a = list(input().split())
 temp = s[int(a[1]):int(a[2])+1]
 if a[0] == 'replace':
  temp3 = a[3]
  s = list(s)
  seq = 0
  for i in range(int(a[1]), int(a[2])+1):
   s[i] = temp3[seq]
   seq += 1
  s = ''.join(s)
 elif a[0] == 'reverse':
  temp2 = temp[::-1]
  s = s.replace(temp, temp2, 1)
 elif a[0] == 'print':
  print(temp)
 
  

Measured memory_bytes: 7696
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int> a[100005];
int dp[100005],n,m;
int dfs(int i)
{
	if(dp[i]!=-1)
		return dp[i];
	int ans=0;
	for(int x:a[i])
		ans=max(ans,dfs(x)+1);
	return dp[i]=ans;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	while(m--)
	{
		int x,y;
		cin>>x>>y;
		a[x].push_back(y);	
	}
	int ans=0,i;
	for(i=1;i<=n;i++)	
		ans=max(ans,dfs(i));
	cout<<ans<<endl;	
}

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

int main() {
	ios::sync_with_stdio(false);
	int H, W;
	char ch;
	cin >> H >> W;
	int i, j;
	int cnt = 0;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> ch;
			if (ch == '#')cnt++;
		}
	}
	if (cnt == H + W - 1)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

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

int main() {
  int x, y;
  std::cin >> x >> y;
  int result;
  if (x >= 0) {
    if (y >= x) result = y - x;
    else if (y <= 0) result = std::abs(x + y) + 1;
    else result = abs(x - y) + 2;
  }
  else if (y < x) result = x - y + 2;
  else if (y > -x) result = 1 + x + y;
  else if (y <= 0) result = y - x;
  else result = -x - y + 1;
  std::cout << result << std::endl;
}


Measured memory_bytes: 384
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int A, B; cin >> A >> B;
    string s;
    if (A == 1 && B == 1) s = "Draw"; 
    else if (A==1) s="Alice";
    else if (B==1) s="Bob";
    else 
    {
        if (A > B) s="Alice";
        else if (A<B) s="Bob";
        else s = "Draw";
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 
const int MAX_N = 1 << 17;

int n, dat[2 * MAX_N -1];

void init(int n_){
	n=1;
	while(n < n_) n *= 2;

	for(int i=0; i<2*n-1; i++) dat[i]= IMAX;
}

void update(int k, int a){
	k += n - 1;
	dat[k] = a;
	while(k > 0){
		k = (k -1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}

int query(int a, int b, int k,int l,int r){
	if(r <= a || b <= l) return IMAX;
	if(a <= l && r <= b) return dat[k];
	else {
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2 , r);
		return min(vl, vr);
	}
}

int main(){
	int q;
	cin>>n>>q;
	int c,x,y;
	init(n);
	rep(i,q){
		cin>>c>>x>>y;
		if(c==0) update(x,y);
		else cout<<query(x,y+1,0,0,n)<<endl;
	}
}

Measured memory_bytes: 2184
def isDraw(s, H, W):
    for h in range(H):
        for w in range(W):
            if s[h][w] != "#":
                continue
            if h > 0 and s[h-1][w] == "#":
                continue
            if h < H-1 and s[h+1][w] == "#":
                continue
            if w > 0 and s[h][w-1] == "#":
                continue
            if w < W-1 and s[h][w+1] == "#":
                continue
            return "No"
    return "Yes"

H, W = map(int, input().split())
s = []

for i in range(H):
    s.append(input())

print(isDraw(s, H, W))

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

int main() {
  int n; cin >> n;
  vector<vector<int>> A(n);
  for(int i = 1; i < n; i++) {
    int a; cin >> a; a--;
    A[a].push_back(i);
  }
  for(int i = 0; i < n; i++) {
    cout << A[i].size() << endl;
  }
  return 0;
}


Measured memory_bytes: 14344
#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! get_chars {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect::<Vec<_>>()
        }
    };
    ($n:expr) => {
        {
            (0..$n)
                .map(|_| get_chars!())
                .collect::<Vec<_>>()
        }
    };
}

fn main() {
    let k = get!(f64);
    let mut x = 100f64;
    let mut ans = 0;
    loop {
        ans += 1;
        x *= 1.01f64;
        x = x.floor();
        if x >= k {
            println!("{}", ans);
            break;
        }
    }
}


Measured memory_bytes: 2656
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

vi prime_number(int max_n) {
	vector<bool> vb(max_n + 1, true);
	vb[0] = vb[1] = false;
	vi ret;
	for(int i = 2; i <= max_n; i++) {
		if(!vb[i]) continue;
		for(int j = 2 * i; j <= max_n; j += i) {
			vb[j] = false;
		}
	}
	for(int i = 2; i <= max_n; i++) {
		if(vb[i]) ret.push_back(i);
	}
	return ret;
}

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	int tmp = n;
	vi p = prime_number(100000);
	vi ans;
	rep(i, p.size()) {
		if(n < p[i]) break;
		while(n % p[i] == 0) {
			n /= p[i];
			ans.push_back(p[i]);
		}
	}
	if(n != 1) ans.push_back(n);
	cout << tmp << ":";
	for(auto i: ans) cout << " " << i;
	cout << endl;
}



Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n;
  cin >> n;
  if(n % 2 == 1){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for(ll i = 10; i <= n; i *= 5){
    ll add = n/i;
    ans += add;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <fstream>
#include <queue>
#include <cstdio>
#include <deque>
#include <map>
#define fol(i,n) for(int i=0;i<n;i++)
#define db(a) cout << a<< endl;
using namespace std;

int main(){
    string s;
    int pc=-1,pf=-1;
    cin >>s;
    fol(i,s.size()){
        if (s[i]=='C') pc = i;
        if (s[i]=='F') pf = i;
    }
    if (pc<pf&&pc>-1&&pf>-1) cout << "Yes"<<endl;
    else cout << "No" <<endl;
    return 0;
}


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

using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n, k;
  cin >> n >> k;

  string s;
  cin >> s;

  -- k;
  s [k] = tolower (s [k]);

  cout << s << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    double a,b,c,d,e,f,bb,cc,ee,ff,x,y;
    for(;;){
        if(scanf("%lf",&a)==EOF){break;}
        scanf("%lf",&b);
        scanf("%lf",&c);
        scanf("%lf",&d);
        scanf("%lf",&e);
        scanf("%lf",&f);
        bb=b*d;
        cc=c*d;
        ee=e*a;
        ff=f*a;
        y=(cc-ff)/(bb-ee);
        x=(c-b*y)/a;
        printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

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

int main()
{
   int k;
   cin>>k;
   long long ans =0;
   for(int a=1; a<=k; a++)
   {
       for(int b=1; b<=k; b++)
      {

           for(int c=1; c<=k; c++)
               {
                    ans+= __gcd(a , __gcd(b,c));
                }
        }
   }

   cout<<ans;

}


Measured memory_bytes: 3560
// R I S E
/* Dedication has no limitation 
*/
// 17 MAY  2019
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
  cin >> a >> b >> c;
  int n = b/a;
  if(c<=n){
    cout << c << endl;
  }
  else{
    cout << n << endl;
  }
return 0;
}




 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    rep(i,n){
        cin >> a[i];
        b[i] = a[i];
    }

    sort(b,b+n);
    int ma = 0;
    int ma2 = 0;
    ma = b[n-1];
    ma2 = b[n-2];

    if(ma==ma2){
        rep(i,n){
            cout << ma << endl;
        }
    }else{
        rep(i,n){
            if(a[i]==ma){
                cout << ma2 << endl;
            }else{
                cout << ma << endl;
            }
        }
    }

    

    return 0;
}
 
 


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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

struct UFW { // union-find with weight
	vector<int> par,w; // w := weight between parent
	UFW(int size) : par(size, -1), w(size,0) { }
	bool unite(int x, int y, int d) {
		if (root(x) != root(y)) {
            w[root(y)] = d+weight(x)-weight(y);
			par[root(y)] = root(x);
            
		}
		return x != y;
	}
    void init(int size){
        for(int i=0;i<size;i++){
            par[i]=i;
            w[i]=0;
        }
    }
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
        if(par[x]!=x) return root(par[x]);
        return x;
	}
    int weight(int x){
        //cout<<x<<endl;
        if(root(x)==x) return 0;
        return w[x]+weight(par[x]);
    }
    /*
    void print(int size){
        for(int i=0;i<size;i++) cout<<" "<<i;
        cout<<endl;
        for(int i=0;i<size;i++) cout<<" "<<par[i];
        cout<<endl;
        for(int i=0;i<size;i++) cout<<" "<<w[i];
        cout<<endl;
    }*/
};

struct WeightedUnionFind{
    vector<int> par; // 親の番号
    vector<int> ws;  // 親との重みの差
    
    WeightedUnionFind(int n) : par(n,-1), ws(n,0){}
    
    int find(int x){
        if(par[x] < 0){
            return x;
        }else{
            int parent = find(par[x]);
            ws[x] += ws[par[x]];
            return par[x] = parent;
        }
    }
    
    int weight(int x){
        find(x); 
        return ws[x];
    }
    
    bool unite(int x, int y, int w){ // x <-(w)- y (x + w = y)
        w += weight(x); 
        w -= weight(y);
        x = find(x); y = find(y);
        
        if(x != y){
            if(par[y] < par[x]) {  // 多い方が根になるようにスワップする.
                int tmp = x; x = y; y = tmp; w = -w;
            }
            par[x] += par[y]; par[y] = x;
            ws[y] = w;
            return true;
        }else{
            return false;
        }
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
    
    void init(int size){
        for(int i=0;i<size;i++){
            par[i]=-1;
            ws[i]=0;
        }
    }
};

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

    int n,m;
    string s;
    int a,b;
    ll w;
    WeightedUnionFind ufw(111111);
    while(cin>>n>>m,n){
        ufw.init(n);
        for(int i=0;i<m;i++){
            cin>>s;
            if(s=="!"){
                cin>>a>>b>>w;
                a--;b--;
                ufw.unite(a,b,w);
            }
            else{
                cin>>a>>b;
                a--;b--;
                //uf.print(n);
                if(!ufw.same(a,b)) cout<<"UNKNOWN"<<endl;
                else{
                    cout<<ufw.weight(b)-ufw.weight(a)<<endl;
                    //cout<<uf.weight(b)<<" "<<uf.weight(a)<<endl;
                }
                
            }
        }
    }
}


Measured memory_bytes: 3468
def main():
    N = int(input())
    L = list(map(int, input().split(" ")))
    cnt = 0
    for i in range(N-2):
        for j in range(i + 1, N-1):
            for k in range(j + 1, N):
                l1 = L[i]
                l2 = L[j]
                l3 = L[k]
                l_max = max(l1, l2, l3)
                if l1 == l2 or l2 == l3 or l3 == l1:
                    continue
                if (l1+l2+l3) - l_max <= l_max:
                    continue
                cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9208
def main():
    X = list(map(int, input().split()))
    X.sort()
    if X[0] == X[1]:
        if X[1] != X[2]:
            return "Yes"
    if X[1] == X[2]:
        if X[0] != X[1]:
            return "Yes"
    return "No"


print(main())


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

int main(){
    string s;
    cin>>s;
    int size=s.length();
    switch (s[s.size()-1])
    {
    case '2':
        cout<<"hon";
        break;
    case '4':
        cout<<"hon";
        break;
    case '5':
        cout<<"hon";
        break;
    case '7':
        cout<<"hon";
        break;
    case '9':
        cout<<"hon";
        break;
    case '0':
        cout<<"pon";
        break;
    case '1':
        cout<<"pon";
        break;
    case '6':
        cout<<"pon";
        break;
    case '8':
        cout<<"pon";
        break;
    case '3':
        cout<<"bon";
        break;
    default:
        break;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define endl '\n';

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    
    ll ans = n % 1000;
    
    if(ans == 0)
    {
        cout << 0;
    }
    else
    {
        cout << 1000 - ans;
    }
     
    
    
    return 0;
}

Measured memory_bytes: 3660
/*問題文
高橋君は青いカードを N枚，赤いカードを M枚持っています.
カードにはそれぞれ文字列が書かれており， i枚目の青いカードに書かれている
文字列は si， i枚目の赤いカードに書かれている文字列は tiです。高橋君は，文字列を 1つ言います。
そして，全てのカードを確認し， その文字列が書かれた青いカードを 1枚見つけるごとに 1円貰えます。
また，その文字列が書かれた赤いカードを 1枚見つけるごとに 1円失います。
なお，高橋君の言った文字列と，カードに書かれた文字列が完全に一致していた場合のみを考えます。 
高橋君は，最大で差し引き何円貰うことができるでしょうか？
ただし，違うカードに同じ文字列が書かれていることもあることに注意してください。*/
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,m_reward=0;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++)cin>>s.at(i);
  cin>>m;
  vector<string> t(m);
  for(int i=0;i<m;i++)cin>>t.at(i);
  for(int i=0;i<n;i++){
    int reward=0;
    for(int j=0;j<n;j++){
      if(s.at(i)==s.at(j))reward++;
    }
    for(int j=0;j<m;j++){
      if(s.at(i)==t.at(j))reward--;
    }
    if(m_reward<reward)m_reward=reward;
  }
  cout<<m_reward<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf (1LL<<60)
inline int read() {
    int x=0,f=1;
    char ch=getchar();
    while (!isdigit(ch)) {
        if (ch=='-') f=-1;
        ch=getchar();
    }
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x*f;
}
long long f[N][3];
int main() {
    int n=read();
    f[0][0]=0,f[0][1]=f[0][2]=-inf;
    for (int i=1;i<=n;i++) {
        int x=read();
        f[i][0]=max(f[i-1][0],f[i-1][1])+x;
        f[i][1]=max(f[i-1][1],f[i-1][2])-x;
        f[i][2]=f[i-1][2]+x;
        if (x<0) f[i][2]=max(f[i][2],f[i][1]),f[i][1]=max(f[i][1],f[i][0]);
    }
    cout<<max(f[n][0],max(f[n][1],f[n][2]))<<endl;
    return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dl = long double;
int main()
{
    ll x;
    cin>>x;
    ll amount = 100;
    ll t = 0;
    while(amount<x){
        t++;
        amount = amount+(amount/100);

    }

    cout<<t;

    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char s[301];
int left[301][26];
int right[301][26];
int dp[301][301][301];

int calc(int x, int y, int z) {
    int ans = 0, i;
    
    if (dp[x][y][z] >= 0) return dp[x][y][z];
    
    if (x > y) return dp[x][y][z] = 0;
    if (x == y) return dp[x][y][z] = 1;
    
    if (s[x] == s[y]) return dp[x][y][z] = calc(x + 1, y - 1, z) + 2;
    
    ans = calc(x + 1, y - 1, z);
    if (z > 0) ans = max(ans, calc(x + 1, y - 1, z - 1) + 2);
    
    if (left[y][s[x] - 'a'] > x) ans = max(ans, calc(x + 1, left[y][s[x] - 'a'] - 1, z) + 2);
    if (left[y][s[x] - 'a'] == x) ans = max(ans, 1);
    if (right[x][s[y] - 'a'] < y) ans = max(ans, calc(right[x][s[y] - 'a'] + 1, y - 1, z) + 2);
    if (right[x][s[y] - 'a'] == y) ans = max(ans, 1);
    
    return dp[x][y][z] = ans;
}

int main() {
    int n, k, i, j, l;
    
    scanf("%s", s);
    scanf("%d", &k);
    
    n = strlen(s);
    
    for (i = 0; i < 26; i++) left[0][i] = -1;
    for (i = 0; i < n; i++) {
        if (i > 0) {
            for (j = 0; j < 26; j++) left[i][j] = left[i - 1][j];
        }
        
        left[i][s[i] - 'a'] = i;
    }
    
    for (i = 0; i < 26; i++) right[n][i] = 1e9;
    for (i = n - 1; i >= 0; i--) {
        for (j = 0; j < 26; j++) right[i][j] = right[i + 1][j];
        
        right[i][s[i] - 'a'] = i;
    }
    
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            for (l = 0; l <= k; l++) {
                dp[i][j][l] = -1;
            }
        }
    }
    
    printf("%d\n", calc(0, n - 1, k));
    
    return 0;
}


Measured memory_bytes: 106752
#include <iostream>
#include <stdio.h>
#include <string>
#define llint long long
#define inf 1e18

using namespace std;

llint m, n;
llint a[100005];
llint dp[100005][2];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> m >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	if(m == 2){
		llint ans = 0;
		for(int i = 1; i <= n; i++){
			if(i%2 && a[i] == 1) ans++;
			if(i%2 == 0 && a[i] == 2) ans++;
		}
		llint tmp = 0;
		for(int i = 1; i <= n; i++){
			if(i%2 && a[i] == 2) tmp++;
			if(i%2 == 0 && a[i] == 1) tmp++;
		}
		ans = min(ans, tmp);
		cout << ans << endl;
		return 0;
	}
	
	llint ans = 0, cnt = 1;
	for(int i = 2; i <= n; i++){
		if(a[i-1] == a[i]) cnt++;
		else{
			ans += cnt/2;
			cnt = 1;
		}
	}
	ans += cnt/2;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))
 
using namespace std;
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using ll=long long;
const ll inf=1LL<<50;
 
// Problem Specific Parameter:
  
int main(void){
	ll n,a;
	cin >> n >> a;

	ll ans=n;
	for(ll idx=2LL;idx<=50LL;++idx){
		for(ll total=1LL;;++total){

			ll cur=1LL;
			vector<ll> ary(idx,total/idx);
			rep(i,total%idx) ary[i]++;
			rep(i,idx) cur*=ary[i];

			ll cost=a*(idx-1)+total;
			if(cur>=n) chmin(ans,cost);
			if(cur>4*n) break;
		}
	}
 
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 384
x, y = map(int, input().split())
ans = 0
minxy = min(abs(x), abs(y))
maxxy = max(abs(x), abs(y))
tmp = abs(maxxy - minxy)
if x == 0:
    if y < 0:
        ans = tmp + 1
    else:
        ans = tmp
elif y == 0:
    if x < 0:
        ans = tmp
    else:
        ans = tmp + 1

elif x >= 0 and y >= 0:
    if x < y:
        ans = tmp
    else:
        ans = tmp + 2
elif x <= 0 and y <= 0:
    if y < x:
        ans = tmp + 2
    else:
        ans = tmp
else:
    ans = tmp + 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

std::ostream &operator<<(std::ostream &out, const vector<ll> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << (abs(a - b) % 2 ? "Borys" : "Alice") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+7;
using namespace std;



int main(){
    string str;cin >> str;
    char a = 'a';
    int ans = 1e9;
    for(int index = 0;index < 26;index++){
        string ins = str;
        string nex;
        int _ans = 0;
        while(1){
            set<char> se;
            for(char c : ins)se.insert(c);
            if(se.size() == 1)break;
            _ans++;
            for(int i = 0;i < ins.size()-1;i++){
                if(ins.at(i) == a+index || ins.at(i+1) == a+index){
                    nex.push_back(a+index);
                }else{
                    nex.push_back(ins.at(i));
                }
            }
            ins = nex;
            nex.clear();
        }
        ans = min(ans,_ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b,c;
  cin >> a >> b >> c;
  cout << ((a==b && b==c)?1:(a!=b && b!=c && c!=a)?3:2) << endl;
  return 0;
}

Measured memory_bytes: 256
package main
import(
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc=bufio.NewScanner(os.Stdin)
func nextInt() int64{
  sc.Scan()
  i, e :=strconv.ParseInt(sc.Text(), 10, 64)
  if e!=nil{
    panic(e)
  }
  return i
}
func min (a *int64, b int64) bool{
  if *a>b{
    *a=b
    return true
  }
  return false
}
func abs(a int64) int64{
  if a<0{
    return a*-1
  }else{
    return a
  }
}
func main(){
  var i int64
  dp:=make([]int64, 100001)
  sc.Split(bufio.ScanWords)
  n:=nextInt()
  a:=make([]int64, n)
  for i=0;i<n;i++{
    a[i]=nextInt()
  }
  for i=0;i<100001;i++{
    dp[i]=1000000001
  }
  dp[0]=0
  for i=1;i<n;i++{
    min(&dp[i], dp[i-1]+abs(a[i]-a[i-1]))
    if i>1{
      min(&dp[i], dp[i-2]+abs(a[i]-a[i-2]))
    }
  }
  fmt.Println(dp[n-1])
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    int p[n];
    rep(i,0,n)cin>>p[i];
    int ans=0;
    rep(i,1,n-1){
        if((p[i+1]-p[i])*(p[i]-p[i-1])>0)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())

word = []
for i in range(N):
    word.append(input())

for i in range(N - 1):
    if word.count(word[i]) != 1:
        print('No')
        exit()

for i in range(1, N):
    if word[i][0] != word[i - 1][-1]:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 3060
def lscan; gets.split.map(&:to_i); end


S = gets.to_i
e9 = 1e9.to_i

if S < e9
  puts "0 0 0 #{S} 1 #{S}"
elsif S == e9*e9
  puts "0 0 0 #{e9} #{e9} 0"
else
  r = e9*e9 - S
  bd = r/e9+1
  a = e9-r%e9
  b = e9-bd
  c = e9
  d = b+1
  puts "0 #{a} #{b} 0 #{d} #{c}"
  
  #p b*c-a*b+a*d
end


Measured memory_bytes: 1788
#include <iostream>
#include<iomanip>

using namespace std;

int main()
{
    int a,b;
    cin >> a >>b;
    cout <<a/b<<endl;
    cout <<a%b<<endl;
    double s,t;
    s=a;
    t=b;
    cout<< fixed << setprecision(5) <<s/t<< endl;
    return 0;

}



Measured memory_bytes: 3284
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    hq = []
    for _ in range(n):
        a,b = map(int,ipt().split())
        hpq.heappush(hq,(a,b))
    while True:
        hqa,hqb = hpq.heappop(hq)
        if hqb < k:
            k -= hqb
        else:
            print(hqa)
            exit()
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 56408
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

const int mod = 1000000007;

struct Mod {
  int n;
  Mod () : n(0) {;}
  Mod (int m) : n(m) {
    if (n >= mod) n %= mod;
    else if (n < 0) n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};

bool operator==(Mod a, Mod b) { return a.n == b.n; }
Mod operator+=(Mod &a, Mod b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; }
Mod operator-=(Mod &a, Mod b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; }
Mod operator*=(Mod &a, Mod b) { a.n = ((long long)a.n * b.n) % mod; return a; }
Mod operator+(Mod a, Mod b) { return a += b; }
Mod operator-(Mod a, Mod b) { return a -= b; }
Mod operator*(Mod a, Mod b) { return a *= b; }
Mod operator^(Mod a, int n) {
  if (n == 0) return Mod(1);
  Mod res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}

ll inv(ll a, ll p) {
  return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
Mod operator/(Mod a, Mod b) { return a * Mod(inv(b, mod)); }

#define MAX_N 1024000

Mod fact[MAX_N], factinv[MAX_N];
void init() {
  fact[0] = Mod(1); factinv[0] = 1;
  REP(i,MAX_N-1) {
    fact[i+1] = fact[i] * Mod(i+1);
    factinv[i+1] = factinv[i] / Mod(i+1);
  }
}
Mod comb(int a, int b) {
  return fact[a] * factinv[b] * factinv[a-b];
}


int main()
{
  init();
  ll n,k;
  cin>>n>>k;
  vector<vector<Mod>> dp(2501, vector<Mod>(51));
  dp[0][0] = 1;
  REP(idx,n) {
    vector<vector<Mod>> tmp(2501, vector<Mod>(51));
    REP(i,k+1)REP(j,n+1) {
      if (i+2*j<=k) tmp[i+2*j][j] += dp[i][j];
      if (j&&i+2*j<=k) tmp[i+2*j][j] += dp[i][j] * Mod(j);
      if (j&&i+2*j-2<=k) tmp[i+2*j-2][j-1] += dp[i][j] * Mod(j*j);
      if (i+2*j+2<=k) tmp[i+2*j+2][j+1] += dp[i][j];
      if (j&&i+2*j<=k) tmp[i+2*j][j] += dp[i][j] * Mod(j);
    }
    swap(dp, tmp);
  }
  cout<<dp[k][0]<<endl;
  return 0;
}


Measured memory_bytes: 9596
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
a, b, c = gets_i_list.sort

puts a * b * (c -c/2) - a * b * (c/2)

Measured memory_bytes: 14420
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



//for (auto p : prime_factor(N)) {
//	cout << p.first << " " << p.second << endl;
//}

//auto primes=primefactor(n);


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

	LL ans = 0;

	LL q = 0;
	LL r = 0;

	for (LL i = 1; i*i <= n; i++) {
		if (n%i != 0)continue;

		q = n/i;
		r = q;

		if ((i - 1) > r && i!=1) {
			ans += i - 1;
		}
		r = i;
		if ((q - 1) > r && q != 1) {
			ans += q - 1;
		}

	}

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

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int h,w;
long long a,b;
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,1,0,-1,1,-1,1,-1};
int COS[]={1,1,1,1,2,2,2,2};
string s[1111];
long dis[1111][1111];
main()
{
	cin>>h>>w>>a>>b;
	int sx,sy;
	for(int i=0;i<h;i++)
	{
		cin>>s[i];
		for(int j=0;j<w;j++)if(s[i][j]=='s')
		{
			sx=i;
			sy=j;
		}
	}
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)dis[i][j]=9e18;
	priority_queue<pair<long,pair<int,int> > >P;
	P.push({0,{sx,sy}});
	dis[sx][sy]=0;
	while(!P.empty())
	{
		long cost=-P.top().first;
		int x=P.top().second.first,y=P.top().second.second;
		P.pop();
		if(dis[x][y]<cost)continue;
		if(s[x][y]=='g')
		{
			cout<<cost<<endl;
			return 0;
		}
		for(int r=0;r<4;r++)
		{
			int tx=x+dx[r],ty=y+dy[r];
			if(tx<0||ty<0||tx>=h||ty>=w||s[tx][ty]=='#'||dis[tx][ty]<=cost+a)continue;
			dis[tx][ty]=cost+a;
			P.push({-cost-a,{tx,ty}});
		}
		bool flag=1;
		for(int r=0;r<8;r++)
		{
			int tx=x+dx[r],ty=y+dy[r];
			flag&=tx<0||ty<0||tx>=h||ty>=w||s[tx][ty]!='*';
		}
		flag&=s[x][y]!='*';
		if(flag)
		{
			for(int r=0;r<8;r++)
			{
				int tx=x+dx[r],ty=y+dy[r];
				int nowcos=cost+b+COS[r]*a;
				if(tx<0||ty<0||tx>=h||ty>=w||dis[tx][ty]<=nowcos)continue;
				dis[tx][ty]=nowcos;
				P.push({-nowcos,{tx,ty}});
			}
		}
	}
	cout<<"INF"<<endl;
}



Measured memory_bytes: 12700
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


void solve(){
    ll n;
    cin>>n;
    cout<<10-n/200<<endl;

    


}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    
     

    solve(); 


    return 0;
}


Measured memory_bytes: 3644
while True:
  n = int(input())
  if not n:
    break
  mp = []
  for _ in range(n):
    lst = list(input())
    cum = []
    acc = 0
    for i in lst:
      if i == ".":
        acc += 1
      else:
        acc = 0
      cum.append(acc)
    mp.append(cum)
  mp.append([-1] * n)
  ans = 0
  
  for i in range(n):
    stack = []
    for j in range(n + 1):
      score = mp[j][i]
      if not stack:
        stack.append((score, j))
      else:
        last_score, last_ind = stack[-1][0], stack[-1][1]
        if score > last_score:
          stack.append((score, j))
        
        elif score == last_score:
          continue
        
        else:
          while stack != [] and stack[-1][0] >= score:
            last_score, last_ind = stack.pop()
            ans = max(ans, min(last_score, j - last_ind))
          stack.append((score, last_ind))
  
  print(ans)


Measured memory_bytes: 38016
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C(I) cout<<(I)<<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc;
vector<ll> va,vb,vc;

int main(){
    cin>>a>>b;
    if(a==1)a=14;
    if(b==1)b=14;
    
    if(a==b)C("Draw");
    else C(a>b ? "Alice":"Bob");
}

Measured memory_bytes: 256
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
   int ans=N;
     if(N%2==0){
      Console.WriteLine(N);
     }else{
       Console.WriteLine(2*N);
     }
}
  }

}


Measured memory_bytes: 27504
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;

int n;
vector<vector<p>> xy;

ll res = 0;

ll counter(vector<int> v){
  int count = 0;
  for(auto a : v) if(a == 1) count++;
  return count;
}

void dfs(int step, vector<int> beta){
  if(step == n){
    for (int i = 0; i < n; i++) {
      if(beta[i] == 0) continue;
      for (int j = 0; j < int(xy[i].size()); j++) {
        int target = xy[i][j].first;
        int is = xy[i][j].second;

        if(beta[target] != is) return;
      }
    }

    res = max(counter(beta), res);
    return;
  }

  dfs(step+1, beta);
  beta[step] = 0;
  dfs(step+1, beta);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<int> v(n);
  xy = vector<vector<p>> (n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    xy[i] = vector<p> (v[i]);
    for (int j = 0; j < v[i]; j++) {
      cin >> xy[i][j].first >> xy[i][j].second;
      xy[i][j].first--;
    }
  }

  dfs(0, vector<int> (n, 1));

  cout << res << endl;

}


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

int main()
{
	long long n, k;

	cin >> n >> k;

	long long sum = 0;

	if (k == 0)
	{
		sum = n * n;
	}
	else
	{
		for (int i = k + 1; i <= n; i++)
		{
			sum += (n / i)*(i - k);
			if ((n%i) - k + 1 > 0)
			{
				sum += (n%i) - k + 1;
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256