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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    while(1) {
        ll b;
        cin >> b;
        if(!b) break;

        ll first = b, len = 1;
        for(ll m=1; m*(m-1)/2<=b; ++m) {
            if((b - m*(m-1)/2) % m == 0) {
                first = (b-m*(m-1)/2) / m;
                len = m;
            }
        }
        if(first == 0) first++, len--;

        cout << first << " " << len << endl;
    }


    return 0;
}



Measured memory_bytes: 3204
import java.util.*;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long snack1 = sc.nextLong();
        long snack2 = sc.nextLong();
        long min = Math.min(snack1,snack2);
        long max = Math.max(snack1,snack2);
        
        long num = 1;
        
        long ans = 0;
        
        while(true){
            if((min * num)%max == 0){
                ans = min * num;
                break;
            } 
            num++;
        }
  System.out.println(ans);
    }
}

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

using namespace std;

int main()
{
    int N, T;
    int time, cost;
    int result = 10000;
    cin >> N >> T;
    for(int i = 0; i < N; ++i) {
        cin >> cost >> time;
        if(time <= T) result = min(result, cost);
    }
    if(result == 10000) cout << "TLE" << endl;
    else cout << result << endl;
}

Measured memory_bytes: 256
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


r, d , x = list(map(int, input().split()))
for i in range(10):
    x = r*x - d
    print(x)


Measured memory_bytes: 22728
import java.util.*;

import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	public void run() {
		while(true){
			int n=sc.nextInt(),m=sc.nextInt();
			if(n==0 && m==0)
				break;

			int[] t=nextIntArray(n);
			int[] h=nextIntArray(m);
			Arrays.sort(t);
			Arrays.sort(h);
			int tsum=0,hsum=0;
			for(int val:t){
				tsum+=val;
			}
			for(int val:h){
				hsum+=val;
			}
			if((hsum+tsum)%2==1){
				ln(-1);continue;
			}
			int tval=-1,sval=-1,min=10000000;
			for(int i=0;i<n;i++){
				int send=t[i];
				int get=(hsum-tsum)/2+t[i];
				if(Arrays.binarySearch(h,get)>=0){
					if(send+get<min){
						min=send+get;
						tval=send;sval=get;
					}
				}
			}
			if(tval==-1)ln(-1);
			else ln(tval+" "+sval);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 21060
N = int(input())
if N % 2 ==1:
    print('No')
    exit
else:
    S = str(input())
    n = int(N / 2)
    former_S = S[:n]
    latter_S = S[n:]
    if former_S == latter_S:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
long double dist(long double center[],long double p[]){
    long double l = 0;
    rep(i,2) l+=((center[i]-p[i])*(center[i]-p[i]));
    return sqrt(l);
}
int main(){  
    int n;
    cin >> n;
    long double point[n][2];
    rep(i,n) cin >> point[i][0] >> point[i][1];
    long double move = 0.5;
    long double center[2] = {0.0,0.0};
    while(move>1e-8){
        rep(j,100){
            long double maxl = 0;
            int maxk = 0;
            rep(i,n){
                long double d = dist(center,point[i]);
                if(d>maxl){
                    maxk = i;
                    maxl = d;
                }
            }    
            rep(i,2) center[i]+=((point[maxk][i]-center[i])*move);        
        }
        move/=2;
    }
    long double ans = 0;
    rep(i,n) ans = max(ans,dist(center,point[i]));
    cout << setprecision(20) << ans << endl;
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int n;
int a, b;

constexpr int MOD = 1000000000 + 7;

// 普通に考えたときのN^P mod M
ll pow_mod(ll N, ll P, ll M) {
    ll ans = 1;
    for (ll i = 0; i < P; ++i) {
        ans *= N;
        ans %= M;
    }

    return ans;
}

// N^P mod M を求める
ll repeat_squaring(ll N, ll P, ll M) {
    if (P == 0) return 1; // 0乗は1
    if (P % 2 == 0) { // Pが偶数
        ll t = repeat_squaring(N, P/2, M);
        return t * t % M;
    } // Pが奇数
    return N * repeat_squaring(N, P-1, M) % M;
}

// n! / (n - r)!
ll modX(ll N, ll R, ll M) {
    ll ans = 1;
    ll ii = N;
    for (ll i = 0; i < R; ++i) {
        ans *= ii;
        ans %= M;
        ii--;
    }

    return ans;
}

vector<ll> fact_mods;

int main() {

    cin >> n >> a >> b;

    ll total = repeat_squaring(2, n, MOD) - 1;
    if (total < 0) total += MOD;

    ll acomb, bcomb;

    ll aX = modX(n, a, MOD);
    ll aY = repeat_squaring(modX(a, a, MOD), MOD - 2, MOD);
    acomb = aX * aY % MOD;

    ll bX = modX(n, b, MOD);
    ll bY = repeat_squaring(modX(b, b, MOD), MOD - 2, MOD);
    bcomb = bX * bY % MOD;

    ll ans = (total - acomb - bcomb) % MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int W = sc.nextInt();

        int[] wt = new int[N];
        int[] val = new int[N];

        for (int i = 0; i < N; i++) {
            wt[i] = sc.nextInt();
            val[i] = sc.nextInt();
        }

        System.out.println(knapsack(W,N,wt,val));
    }

    static long knapsack(int W, int N, int[] wt, int[] val) {

        long[][] dp = new long[N+1][W+1];

        for (int i = 0; i <= N; i++) {
            for (int w = 0; w <= W; w++) {
                if (i == 0 || w == 0) 
                    dp[i][w] = 0;
                else if (wt[i-1] <= w) {
                    long a = val[i-1] + dp[i-1][w-wt[i-1]];
                    long b = dp[i-1][w];
                    dp[i][w] = Math.max(a,b);
                } else
                    dp[i][w] = dp[i-1][w];
            }
        }

        return dp[N][W];
    }
}







Measured memory_bytes: 140828
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

s = input()

for i in range(1, len(s)):
    if s[i-1] == s[i]:
        print(i, i+1)
        exit()

for i in range(2, len(s)):
    if s[i-2] == s[i]:
        print(i-1, i+1)
        exit()

print(-1,-1)


Measured memory_bytes: 3924
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

int main()
{
#ifdef _MSC_VER
	freopen("a.in", "r", stdin);
#endif
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int c[32][32];
	memset(c, 0, sizeof(c));
	long long ret = 0;
	const int L = 18;
	for (int i = 0; i < n; i++) {
		double val;
		cin >> val;
		long long d = (long long)(val * 1e9 + 0.5);
		int c2 = 0;
		int c5 = 0;
		for (; d % 2 == 0; d /= 2) ++c2;
		for (; d % 5 == 0; d /= 5) ++c5;
		c2 = min(c2, L);
		c5 = min(c5, L);
		for (int x2 = 0; x2 <= L; x2++) {
			if (c2 + x2 >= L) {
				ret += c[x2][L - c5];
			}
		}
		for (int x5 = 0; x5 <= c5; ++x5) {
			++c[c2][x5];
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int r;
    cin>>r;
    cout<<r*r<<endl;
    return 0;
}

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

bool check(const string &str){
    int p=0;
    while((p=str.find("this", 0))!=string::npos){
        if((p==0||str[p-1]==' ') && (p+4>=str.length()||str[p+4]==' ')) return true;
    }
    p=0;
    while((p=str.find("that", 0))!=string::npos){
        if((p==0||str[p-1]==' ') && (p+4>=str.length()||str[p+4]==' ')) return true;
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, d;
    s.reserve(260);
    d.reserve(260);
    int n;
    cin>>n;
    getline(cin, s);
    for(int i=0; i<n; i++){
        getline(cin, s);
        for(int a=1; a<26; a+=2){
            if(a==13) continue;
            d=s;
            for(auto &c:d) if('a'<=c&&c<='z')c=((c-'a')*a)%26+'a';
            for(int b=0; b<26; b++){
                if(check(d)) {
                    cout<<d<<'\n';
                    goto ok;
                }
                for(auto &c:d){
                    if(c=='z') c='a';
                    else if('a'<=c&&c<'z') ++c;
                }
            }
        }
        ok:;
    }
    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n%2!=0){
    cout << "No" << endl;
    exit(0);
  }
  char c1[n/2], c2[n/2];
  for(int i = 0; i < n/2; i++)cin >> c1[i];
  for(int i = 0; i < n/2; i++)cin >> c2[i];
  int count = 0;
  for(int i = 0; i < n/2; i++){
    if(c1[i] == c2[i])count++;
  }
  if(count == n/2)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

class Main {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        StringBuilder s = new StringBuilder(sc.nextLine());
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '1') s.setCharAt(i, '9');
            else if (s.charAt(i) == '9') s.setCharAt(i, '1');
        }
        System.out.println(s.toString());
        sc.close();
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;

int main() {
  int N;
  cin >> N;
  
  cout << N/3 << endl;
}

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

ll f(ll n) {
  if (n % 2)
    return ((n + 1) / 2) % 2;
  else {
    return ((n / 2) % 2) ^ n;
  }
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (f(a - 1) ^ f(b)) << endl;
}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int i,j;
  cin>>i>>j;
  vector<string>vec(i);
  for(int l=0;l<i;l++){
    cin>>vec.at(l);
  }
  for(int n=0;n<j+2;n++){
    cout<<'#';
  }
  cout<<endl;
  for(int m=0;m<i;m++){
    cout<<'#'<<vec.at(m)<<'#'<<endl;
  }
  for(int n=0;n<j+2;n++){
    cout<<'#';
  }
  
}

Measured memory_bytes: 256
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.format;

byte cvt(char c) {
  if (c == 'R') return 0;
  if (c == 'G') return 1;
  return 2;
}

int[] ps (byte[] s, byte k) {
  auto res = new int[s.length+1];
  foreach (i; 0 .. s.length) {
    res[i+1] = res[i];
    if (s[i] == k) ++res[i+1];
  }
  return res;
}

void main() {
  auto s = readln;
  int n;
  formattedRead(s, " %d", &n);
  s = readln[0 .. n];
  auto a = new byte[n];
  foreach (i; 0 .. n) {
    a[i] = cvt (s[i]);
  }
  //s[i] != s[j]
  //s[i] != s[k]
  //s[j] != s[k]
  //j - i != k - j
  //i < j < k
  int[][] u = new int[][3];
  foreach (i; 0 .. 3) {
    u[i] = ps (a, i.to!byte);
  }
  long res;
  const xorsum = 0 ^ 1 ^ 2;
  foreach (j; 1 .. n - 1) {
    auto y = a[j];
    foreach (i; 0 .. j) {
      auto x = a[i];
      if (x != y) {
        auto z = xorsum ^ (x ^ y);
        int delta = j - i;
        res += u[z].back - u[z][j+1]; 
        int k = j + delta;
        if (k < n && a[k] == z) --res;
      }
    }
  }
  writeln(res);
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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; }

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int n,k;
  cin >> n >> k;

  vi l(n);
  rep(i,n) cin >> l[i];
  sort(l.rbegin(), l.rend());
  int ans = 0;
  rep(i,k) ans+=l[i];

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

Measured memory_bytes: 3604
function Main(input) {
  // 入力
  input = input.split(" ");
	//input = input.split("\n");
	//tmp = input[1].split(" ");
	var a = parseInt(input[0], 10);
	var op = input[1];
  var b = parseInt(input[2], 10);
  var ans;
  // 計算
  if (op === '+') {
    ans = a + b;
  } else {
    ans = a - b;
  }
  
	//出力
	console.log('%d', ans);
}

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

Measured memory_bytes: 22964
#include<bits/stdc++.h>
using namespace std;
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; }

int main(){
  int S;
  cin >>S;
  int ue = S/100;
  int shita = S%100;
  if((ue>=1 && ue<=12) && (shita>=1 && shita<=12)){
    cout<<"AMBIGUOUS"<<endl;
  }
  else if(ue>=1 && ue<=12){
    cout<<"MMYY"<<endl;
  }
  else if(shita>=1 && shita<=12){
    cout<<"YYMM"<<endl;
  }
  else{
    cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    total = sum(A)
    threshold = total / (4*M)
    count = sum([a>=threshold for a in A])
    if count >= M:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 9132
#include <iostream>
typedef long long ll;
#include <cmath>
#include <vector>
#include <algorithm>

void dump(int a[],int n)
{
  for (int codeTest = 0; codeTest < n; ++codeTest) {
    if (codeTest!=0)std::cout << " ";
    std::cout << a[codeTest];
  }
  std::cout << '\n';
}

int main() {
  int n,i,k,j,ans=0,tmp=0,l,cnt;
  std::vector<int> v;
  int a[262144],b[262144],c[262144];
  std::cin >> n;
  for (i = 0; i < std::pow(2,n); ++i) {
    std::cin >> tmp;
     v.push_back (tmp);
  }
  std::sort(v.begin(), v.end() ,std::greater<int>());
  j=0;
  a[0]=1;
  for (i = 1; i < std::pow(2,n); ++i) {
    if (v[i-1]==v[i]) {
      ++a[j];
    }else{
      ++j;
      a[j]=1;
    }
  }
  ++j;

  if (a[0]!=1){std::cout << "No" << '\n';}
  else{
    for (i = 0; i < j; ++i){b[j]=0;}
    b[0]=1;
    c[0]=1;
    for (i = 0; i < n; ++i) {
      for (int l = 1; l < j; ++l) {
        c[l]=c[l-1]+b[l];
      }

      cnt=0;
      for (int l = 1; l < j; ++l) {
        if (b[l]<a[l]&&c[l-1]>cnt) {
          tmp=std::min(a[l]-b[l],c[l-1]-cnt);
          b[l]+=tmp;
          cnt+=tmp;

        }
      }


      if (c[j-1]!=cnt){
        i=300000;
        l=j;
        std::cout << "No" << '\n';
      }
    }
    if (i!=300001){
      std::cout << "Yes" << '\n';
    }
  }

}


Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + 10;
const int maxm = 2e3 + 10;
const int inf = 1e9 + 9;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); //C++关同步
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if(abs(a - b) <= t * v - t * w)cout << "YES\n";
    else{
        cout << "NO\n";
    } 

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second
 
inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}
 
int n, m, r, g[201][201], a, b, c, ans;
long long d[201][201];
vector<int> p;
map<int, bool> mp;
 
int main() {
    init();
    cin >> n >> m >> r;
 
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i != j) d[i][j] = INF;
            else d[i][j] = 0;
        }
    }
 
    p.resize(r);
    for (int i = 0; i < r; ++i) {
        cin >> p[i];
        p[i]--;
        //mp[p[i]] = true;
    }
 
    for (int i = 0; i < m; ++i) {
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = d[b][a] = c;
    }
 
    rep(k,n) rep(i,n) rep(j,n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
 
    sort(p.begin(), p.end());
    ans = INF;
    do {
        int tmp = 0;
        for (int i = 0; i < r - 1; ++i) {
            tmp += d[p[i]][p[i + 1]];
        }
        ans = min(ans, tmp);
    } while (next_permutation(p.begin(), p.end()));
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 640
n=int(input())
ans=0
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        if i>1 and n//(i-1)==n%(i-1):
            ans+=i-1
        if n//i!=i:
            if n//(n//i-1)==n%(n//i-1):
                ans+=n//i-1
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class E
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int X = GetInt();
		int Y = GetInt();
		int A = GetInt();
		int B = GetInt();
		int C = GetInt();

		var list = new List<Tuple<long, int>>();
		for(int i = 0; i < A; i++)
			list.Add(Tuple.Create(GetLong(), 0));

		for(int i = 0; i < B; i++)
			list.Add(Tuple.Create(GetLong(), 1));

		for(int i = 0; i < C; i++)
			list.Add(Tuple.Create(GetLong(), 2));

		list.Sort((x, y) => (x.Item1 != y.Item1) ? y.Item1.CompareTo(x.Item1) : x.Item2 - y.Item2);

		long ans = 0;
		int cR = 0;
		int cG = 0;
		int cnt = 0;
		for(int i = 0; i < A + B + C; i++)
		{
			switch(list[i].Item2)
			{
				case 0:
					if(cR < X)
					{
						ans += list[i].Item1;
						cR++;
						cnt++;
					}
					break;

				case 1:
					if(cG < Y)
					{
						ans += list[i].Item1;
						cG++;
						cnt++;
					}
					break;

				case 2:
					ans += list[i].Item1;
					cnt++;
					break;
			}

			if(cnt == X + Y)
				break;
		}
		WriteLine(ans);	
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        string A, B, C; cin >> A >> B >> C;

        int s = 0;
        rep(i, N) {
            map<char, int> mp;
            mp[A[i]]++;
            mp[B[i]]++;
            mp[C[i]]++;
            int a = 3;
            for(auto p : mp) set_min(a, 3 - p.second);
            s += a;
        }
        cout << s << endl;

        return 0;
    }
};

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


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

//byte単位で読む。
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

pub trait LexicalPermutation {
    /// Return `true` if the slice was permuted, `false` if it is already
    /// at the last ordered permutation.
    fn next_permutation(&mut self) -> bool;
}

impl<T> LexicalPermutation for [T]
where
    T: Ord,
{
    /// Original author in Rust: Thomas Backman <serenity@exscape.org>
    fn next_permutation(&mut self) -> bool {
        // These cases only have 1 permutation each, so we can't do anything.
        if self.len() < 2 {
            return false;
        }

        // Step 1: Identify the longest, rightmost weakly decreasing part of the vector
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] >= self[i] {
            i -= 1;
        }

        // If that is the entire vector, this is the last-ordered permutation.
        if i == 0 {
            return false;
        }

        // Step 2: Find the rightmost element larger than the pivot (i-1)
        let mut j = self.len() - 1;
        //while j >= i && self[j] <= self[i - 1] {
        while self[j] <= self[i - 1] {
            j -= 1;
        }

        // Step 3: Swap that element with the pivot
        self.swap(i -1 , j);

        // Step 4: Reverse the (previously) weakly decreasing part
        self[i..].reverse();

        true
    }
}

fn main() {
    let n = read();
    let p: Vec<u32> = (0..n).map(|_| read()).collect();
    let q: Vec<u32> = (0..n).map(|_| read()).collect();

    let mut data = vec![];

    for i in 0..n {
        data.push(i + 1);
    }

    let mut pn: i64 = 0;
    let mut qn: i64 = 0;
    let mut c: i64 = 0;

    loop{
        if p == data {
            pn = c;
        }
        if q == data {
            qn = c;
        }

        if !data.next_permutation() {
            break;
        }
        c += 1;
    }

    println!("{}", (pn - qn).abs());

}


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

int main() {
    int A, B, C, D;
    int L;
    int R;

    cin >> A >> B >> C >> D;

    L = A + B;
    R = C + D;

    if (L > R) {
        cout << "Left" << endl;
    }
    else if (L == R) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
}


Measured memory_bytes: 256
/**
 *   author: sahushivam
 *   created: 17 August 2019 (Saturday)  17:50:01
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    int c=0;
    set<char> se;
    string prev="",curr="";
    for(int i=0;i<n;i++)
    {
        if(prev!=curr && curr!="")
        {
            c++;
            prev=curr;
            curr="";

        }
        
            curr+=s[i];
    }
    if(prev!=curr && curr!="")
    {
            c++;
            prev=curr;
            curr="";

    }
    int cc=0;
    prev="",curr="";
    // for(int i=0;i<n;i++)
    // {
    //     if(prev!=curr && curr!="")
    //     {
    //         cc++;
    //         prev=curr;
    //         curr="";

    //     }
        
    //         curr+=s[i];
    // }
    // if(prev!=curr && curr!="")
    // {
    //         cc++;
    //         prev=curr;
    //         curr="";

    // }
    cout<<max(cc,c);
return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

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

const int inf = 1001001000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int h,w;
char c[50][50];
int cost[50][50];

int main(){
    cin >> h >> w;
    int count = 0;
    rep(i,0,h){
        rep(j,0,w){
            char t;
            cin >> t;
            c[i][j] = t;
            cost[i][j] = inf;
            if(t == '.')count++;
        }
    }

    queue<pair< pair<int,int>, int> > q;
    q.push(make_pair(make_pair(0,0),0));
    while(!q.empty()){
        pair<pair<int,int>, int> t = q.front();
        pair<int,int> p = t.first;
        int dist = t.second;
        q.pop();

        if(cost[p.first][p.second] == inf){
            cost[p.first][p.second] = dist;
            
            rep(i,0,4){
                int x = p.second + dx[i];
                int y = p.first + dy[i];
                
                if(-1 < x && x < w && -1 < y && y < h && c[y][x] == '.' && cost[y][x] == inf){
                    q.push(make_pair(make_pair(y,x),dist+1));
                }

            }
        }
    }
    if(cost[h-1][w-1] != inf){
        cout << count - cost[h-1][w-1] - 1 << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;

}




Measured memory_bytes: 256
use proconio::{fastout, input};
use std::cmp::min;
use std::cmp::Reverse;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
        t: usize,
    }
    for _ in 0..t {
        input! {
            n: u128, a: u128, b: u128, c: u128, d: u128,
        }
        let mut que = BinaryHeap::new();
        que.push(Reverse((0, n)));
        let mut used = BTreeSet::new();
        while let Some(Reverse((z, m))) = que.pop() {
            if used.contains(&m) {
                continue;
            }
            if m == 0 {
                println!("{}", z);
                break;
            }
            if m == 1 {
                println!("{}", z + d);
                break;
            }
            if m % 2 == 0 {
                que.push(Reverse((z + a, m / 2)));
            } else {
                que.push(Reverse((z + min(a + d, (m - m / 2 - 1) * d), m / 2 + 1)));
                que.push(Reverse((z + min(a + d, (m - m / 2) * d), m / 2)));
            }
            if m % 3 == 0 {
                que.push(Reverse((z + min(b, (m - m / 3) * d), m / 3)));
            } else {
                que.push(Reverse((
                    z + min(b + d * (3 - m % 3), (m - m / 3 - 1) * d),
                    m / 3 + 1,
                )));
                que.push(Reverse((z + min(b + d * (m % 3), (m - m / 3) * d), m / 3)));
            }
            if m % 5 == 0 {
                que.push(Reverse((z + min(c, (m - m / 5) * d), m / 5)));
            } else {
                que.push(Reverse((
                    z + min(c + d * (5 - m % 5), (m - m / 5 - 1) * d),
                    m / 5 + 1,
                )));
                que.push(Reverse((z + min(c + d * (m % 5), (m - m / 5) * d), m / 5)));
            }
            used.insert(m);
        }
    }
}


Measured memory_bytes: 2656
#include <iostream>
#include <string>

using namespace std;

int main() {
    int length_of_string, number_of_ABC;
    string input;

    cin >> length_of_string >> input;
    for(auto itr = input.begin(); itr != input.end(); itr++) {
        if(*itr == 'A') {
            if(*(itr+1) == 'B') {
                if(*(itr+2) == 'C') {
                    number_of_ABC++;
                }
            }
        }
    }
    cout << number_of_ABC << endl;

    return 0;
}

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

int main(){
long N;
  long sum=0;
  long max=0;
  cin>>N;
  vector <int>a(N); 
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
 
  for(int i=0;i<N;i++){
  if(a.at(i)>max){
  max=a.at(i);
  }
    else{
    sum+=max-a.at(i);
    }
  }
  cout<<sum<<endl;
  
}

Measured memory_bytes: 3948
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

a,b = map(int,input().split())

s1 = [1,3,5,7,8,10,12]
s2 = [2]
s3 = [4,6,9,11]

if (a in s1) and (b in s1):
    print("Yes")
elif (a in s2) and (b in s2):
    print("Yes")
elif (a in s3) and (b in s3):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string>) {}
template<typename T1,typename T2> ostream& operator<<(ostream& os, pair<T1,T2> buf) {
  return os << "(" << buf.first << ": " << buf.second << ")"; }
#define DefOut(Con) template<typename T>ostream&operator<<(ostream&os,Con<T>&A){ bool f = false; os << "{"; \
  for (const auto e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
#define DefOut2(Con) template<typename K,typename V>ostream&operator<<(ostream&os,Con<K,V>&A) \
{ bool f = false; os << "{"; for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
template<typename T>ostream &operator << (ostream &os,vector<vector<T>>& A) {
  for (auto &B: A) os << '\n' << B; return os; }
DefOut(vector) DefOut(set) DefOut(multiset) DefOut2(map) 
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1000000007;
long long const INF = 1e18;
#define PI 3.14159265358979323846
/***********************************************************************/

int32_t main() {

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

  int n, k; cin >> n >> k;
  if (k == 1) kek(0);
  cout << (n - k) << '\n';
  
  return 0;
}


Measured memory_bytes: 256
def u(a,b):
  if b == 0:
    return a
  return u(b, a%b)

a,b,c,d = map(int,input().split())

e=int(c/u(c,d)*d)
a=a-1
ac = (a // c)
bc = (b // c)
ad = (a // d)
bd = (b // d)
ae = (a // e)
be = (b // e)

print(b - a - (bc - ac + bd - ad ) + (be - ae))

Measured memory_bytes: 3064
// A - Transfer 2019/8/17

#include<stdio.h>

int main(void){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    c=c-(a-b);
    if(c<=0){
        printf("0");
        return 0;
    }
    printf("%d",c);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int xa,ya,xb,yb,xc,yc,wx,wy,r;

int crosscheck(int tx,int ty,int sx,int sy,int wx,int wy,int rr){

	int abx=sx-tx,aby=sy-ty;
	int awx=wx-tx,awy=wy-ty;
	int bwx=wx-sx,bwy=wy-sy;

	int rr2=rr*rr;
	int aw2=awx*awx+awy*awy;
	int bw2=bwx*bwx+bwy*bwy;
	int ab2=abx*abx+aby*aby;

	int tim=abx*awy-aby*awx;
	int abw=abx*awx+aby*awy;

	if(aw2<rr2 && bw2<rr2)return 0;
	if(aw2<rr2 || bw2<rr2)return 1;
	if( tim*tim/ab2 >= (double)rr2)return 0;
	if(abw<0)return 0;
	if(abw>ab2)return 0;
	return 1;
}

int touchcheck(int tx,int ty,int sx,int sy,int wx,int wy,int rr){

	int abx=sx-tx,aby=sy-ty;
	int awx=wx-tx,awy=wy-ty;
	int bwx=wx-sx,bwy=wy-sy;

	int rr2=rr*rr;
	int aw2=awx*awx+awy*awy;
	int bw2=bwx*bwx+bwy*bwy;
	int ab2=abx*abx+aby*aby;

	int tim=abx*awy-aby*awx;
	int abw=abx*awx+aby*awy;

	if(aw2<rr2 && bw2<rr2)return 0;
	if(aw2<rr2 || bw2<rr2)return 1;
	if( tim*tim/ab2 != (double)rr2)return 0;
	if(abw<0)return 0;
	if(abw>ab2)return 0;
	return 1;
}

int main(){
	while(scanf("%d %d",&xa,&ya)*xa){
		scanf("%d %d %d %d %d %d %d",&xb,&yb,&xc,&yc,&wx,&wy,&r);

		int ttt=0;

		int d1=(xa-wx)*(xa-wx)+(ya-wy)*(ya-wy)-r*r;
		int d2=(xb-wx)*(xb-wx)+(yb-wy)*(yb-wy)-r*r;
		int d3=(xc-wx)*(xc-wx)+(yc-wy)*(yc-wy)-r*r;
		int tim1=(wx-xa)*(yb-ya)-(wy-ya)*(xb-xa);
		int tim2=(wx-xb)*(yc-yb)-(wy-yb)*(xc-xb);
		int tim3=(wx-xc)*(ya-yc)-(wy-yc)*(xa-xc);

		if (tim1*tim2>0 && tim2*tim3>0) ttt=1;

		if(d1<=0 && d2<=0 && d3<=0){printf("b\n");continue;}
		if(d1==0 || d2==0 || d3==0){printf("c\n");continue;}

		if(crosscheck(xa,ya,xb,yb,wx,wy,r)){printf("c\n");continue;}
		else if(crosscheck(xb,yb,xc,yc,wx,wy,r)){printf("c\n");continue;}
		else if(crosscheck(xc,yc,xa,ya,wx,wy,r)){printf("c\n");continue;}

		if(ttt==1){printf("a\n");continue;}

		if(touchcheck(xa,ya,xb,yb,wx,wy,r)){printf("c\n");continue;}
		else if(touchcheck(xb,yb,xc,yc,wx,wy,r)){printf("c\n");continue;}
		else if(touchcheck(xc,yc,xa,ya,wx,wy,r)){printf("c\n");continue;}
		
		printf("d\n");

	}
	return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
#include<vector>
using namespace std;

/*#### modular_arithmetic */
class modular_arithmetic{
public:
	int mod, range;
	vector<int> fac, ifac;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	void set_mod(int _mod){mod = _mod;}
	int add(int x,int y){return (x+y)%mod;}
	int sub(int x,int y){return (x-y+mod)%mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
	int pw(int x,int y){
		int r = 1;
		while(1){
			if(y&1)r=mul(r,x);
			if(y>>=1)x=mul(x,x);else
				break;
		}
		return r;
	}
	//mod must be a prime.
	int inv(int x){
		return pw(x, mod-2);
	}
	int div(int x,int y){
		return mul(x, inv(y));
	}
	void init(int _range, int _mod = 1000000007){
		range = min(_range, _mod);
		set_mod(_mod);
		fac.resize(range);
		ifac.resize(range);
		fac[0] = ifac[0] = 1;
		for(int i=1; i<range; i++){
			fac[i] = mul(fac[i-1], i);
			ifac[i] = pw(fac[i], mod-2);
		}
	}
	int comb(int x, int y){
		if(x<y)return 0;
		return mul(fac[x], mul(ifac[y],ifac[x-y]));
	}
};
/*####*/

modular_arithmetic ma;

void addto(int&x,int y){
	x=ma.add(x,y);
}

int res, N, K;
int dp[111][3333];

int main(){
	scanf("%d%d",&N,&K);

	dp[N][0] = 1;
	for(int i = N; i >= 1; i--){
		for(int j=0; j<3333; j++)if(dp[i][j])
			for(int k=0; k<=K; k++)if(k > i){
				addto(dp[i-1][j], dp[i][j]);
			}else{
				int cur = (k+j)/i;
				addto(res, ma.mul(dp[i][j],ma.mul(ma.pw(K+1, i-1), cur)));
				addto(dp[i-1][j+cur], dp[i][j]);
			}
	}

	int total = ma.mul((1+K) * K / 2 * N, ma.pw(K+1, N-1));
	printf("%d\n",ma.sub(total, res));
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{

string s;
set<ll>s1,s2;
cin>>s;
ll i;
for(i=0;i<s.size();i++)
{
    if(s[i]=='R')
        s1.insert(i);
    else
        s2.insert(i);
}
ll arr[s.size()]={0};
for(i=0;i<s.size();i++)
{
    if(s[i]=='R')
    {
        auto it=s2.lower_bound(i);
        //cout<<*it-i<<endl;
        if(((*it)-i)%2==0)
            arr[*it]++;
        else
            arr[(*it)-1]++;
    }
    else
    {
        auto it=s1.lower_bound(i);
        it--;
       // cout<<i-*it<<endl;
        if((i-(*it))%2==0)
            arr[*it]++;
         else
            arr[(*it)+1]++;
    }
}
for(i=0;i<s.size();i++)
    cout<<arr[i]<<" ";
cout<<endl;
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define fi first
#define se second
#define NAME "data"
using namespace std;
typedef long long LL;
typedef pair <LL, LL> pLL;
typedef pair <int, int> pii;
const int NMAX = 5e5+7;

int r, c, n;
vector <pii> a;
map <int, bool> mp;

int id(int x, int y) {
    if(y == 0) return x;
    if(x == r) return y+r;
    if(y == c) return (r-x)+r+c;
    return (c-y)+r*2+c;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(); cout.tie(0);
    //freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    cin >> r >> c >> n;
    for(int i = 1; i <= n; ++i) {
        int x, y, u, v;
        cin >> x >> y >> u >> v;
        int ok = 0;
        if(x == 0 || x == r || y == 0 || y == c) ok++;
        if(u == 0 || u == r || v == 0 || v == c) ok++;
        if(ok == 2) {
            a.push_back(pii(id(x, y), i));
            a.push_back(pii(id(u, v), i));
        }
    }
    sort(a.begin(), a.end());
    stack <int> st;
    for(int i = 0; i < a.size(); ++i) {
        int x = a[i].se;
        if(mp[x] == 0) {
            mp[x] = 1;
            st.push(x);
        } else {
            if(st.size() && st.top() != x) {
                cout << "NO";
                return 0;
            }
            st.pop();
            mp[x] = 0;
        }
    }
    cout << "YES";
}


Measured memory_bytes: 6512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int num = 105;
int p[num];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &p[i-1], &p[i]);
	}
	int m[num][num];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			m[i][j] = 2000000000;
		}
	}
	for (int i = 1; i <= n; i++) m[i][i] = 0;
	for (int l = 1; l < n; l++) {
		for (int i = 1; i < n - l + 1; i++) {
			int j = i + l;
			for (int k = i; k < j; k++)
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

ll dp[110][100010];
ll acc[110][100010];

int main() {

	int n,k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	memset(dp,0,sizeof(dp));
	memset(acc,0,sizeof(acc));
	dp[0][k] = 1;
	acc[0][k] = 1;
	for(int i=1; i<=n; i++) {
		int index = i-1;
		//cout << "i:" << i << " a[index]:" << a[index] << endl;
		for(int p=0; p<=k; p++) {
			//cout << "p:" << p << endl;
			dp[i][p] = acc[i-1][min((ll)k, p+a[index])];
			if(p != 0) dp[i][p] -= acc[i-1][p-1];
			if(dp[i][p] < 0) dp[i][p] += MOD;
			dp[i][p] %= MOD;
		}
		for(int j=0; j<=k; j++) {
			if(j == 0) acc[i][j] = dp[i][j];
			else acc[i][j] = acc[i][j-1] + dp[i][j];
			acc[i][j] %= MOD;
		}
	}
	/*rep(i,n+1) {
		rep(j,k+1) {cout << setw(3) << dp[i][j] << " ";}
		cout << endl;
	}*/

	cout << dp[n][0] << endl;
  return 0;
}


Measured memory_bytes: 172288
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for(int i = 0; i < n; i++){
        	count += i + 1;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35508
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define ld long double
#define fs(i,k,n,s) for (i=k;i<n;i+=s)
#define f(i,k,n) for (i=k;i<n;i++)
#define rf(i,n,k) for (i=n;i>=k;i--)
#define rfs(i,n,k,s) for (i=n;i>=k;i-=s)
#define fc(it,a) for (auto it=a.begin();it!=a.end();it++)
#define all(a) a.begin(),a.end()
#define mkp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define F first
#define S second
#define set(a,b) memset(a,b,sizeof(a))
#define M 1000000007
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define p(a,b) pair<a,b>
#define v(a) vector<a>
#define m(a,b) map<a,b>
#define um(a,b) unordered_map<a,b>
#define s(a) set<a>
#define ms(a) multiset<a>
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define test() int t;cin >> t;while(t--)
#define TakeInput freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
 
using namespace std;
 
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); }
ll lcm(ll a,ll b) {return (a*b)/gcd(a,b);}
ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}

int main()
{
	#ifndef ONLINE_JUDGE
	//TakeInput
	#endif
	fast;
	ll n;
	cin >> n;
	if (n%2==0)
		cout << n/2 << endl;
	else
		cout << n/2+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int inv_mod(int a, int m = MOD) {
  int b = m, x = 1, y = 0, t;
  while (b > 0) {
    t = a / b;
    swap(a -= t * b, b);
    swap(x -= t * y, y);
  }
  x %= m;
  if (x < 0) x += m;
  return x;
}

const int MAX_N = 100010;
int fac[MAX_N];
int ifac[MAX_N];
int inv[MAX_N];

void init(int n = MAX_N, int m = MOD) {
  fac[0] = 1;
  for (int i = 1; i < n; i++) fac[i] = fac[i - 1] * i % m;
  ifac[n - 1] = inv_mod(fac[n - 1]);
  for (int i = n - 2; i >= 0; i--) ifac[i] = ifac[i+1] * (i + 1) % m;
  for (int i = 1; i < n; i++) inv[i] = ifac[i] * fac[i - 1] % m;
}

int nPr(int n, int r, int m = MOD) {
  if (r < 0 || n < r) return 0;
  return fac[n] * ifac[n - r] % m;
}

int N,K;
int a[100010],b[100010];
vector<int> g[100010];
int dp[100010];

void dfs(int v, int pv) {
  int res = 1;
  int num = 0;
  for (int nv : g[v]) if (nv != pv) {
    dfs(nv,v);
    (res *= dp[nv]) %= MOD;
    num++;
  }
  (res *= nPr(K - 1 - (pv < 0 ? 0 : 1), num)) %= MOD;
  dp[v] = res;
}

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

  init();
  cin >> N >> K;
  REP(i,N-1) {
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  dfs(0,-1);
  cout << (dp[0]*K)%MOD << endl;

  return 0;
}

Measured memory_bytes: 16256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
using namespace std;
const int N=100005;
int n,k;
pll a[N];
ll As,Bs;
ll gcd(ll x,ll y){
	return y?gcd(y,x%y):x;
}
int main(){
	scanf("%d",&n);
	For(i,1,n){
		int x,y;
		scanf("%d%d",&x,&y);
		a[i]=pll(max(x,y),y);
		As+=x;
	}
	sort(a+1,a+n+1,greater<pll>());
	k=Bs=0;
	for (;k<=n;++k){
		Bs+=a[k].fi;
		if (Bs>=As) break;
	}
	//printf("%lld %lld\n",As,Bs);
	if (Bs<As)
		return puts("0 1\n"),0;
	ll fm=1,fz=1;
	For(i,1,n){
		ll val=As-Bs+a[min(i,k)].fi;
		if (val<=a[i].se)
			if (val*fm<fz*a[i].se)
				fm=a[i].se,fz=val;
	}
	//printf("%lld %lld\n",fm,fz);
	fz=(fm-fz)+(n-k)*fm; fm*=n;
	ll G=gcd(fz,fm); fz/=G; fm/=G;
	printf("%lld %lld\n",fz,fm);
}
/*
所有选的y越大越在后
x<y一定会选
剩下选若干
*/

Measured memory_bytes: 1792