akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

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 U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

// 0 1 2 | 3 4 5

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vi D(N);
	REP(i, N)cin >> D[i];
	so(D);
	cout << D[N/2] - D[N/2-1] << endl;
	return 0;
}


Measured memory_bytes: 640
#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(){
  int n;
  cin >> n;
  bool f = false;
  rep(i, n){
    int in;
    cin >> in;
    if(in % 2 != 0) f = true;
  }
  if(f == true) cout << "first" << endl;
  else cout << "second" << endl;
  return 0;
}

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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 N;
    cin >> N;
    
    vector<ll> x(N),y(N);
    REP(i,N) cin >> x[i] >> y[i];
    
    vector<ll> p(N),m(N);
    REP(i,N){
        p[i] = x[i] + y[i];
        m[i] = x[i] - y[i];
    }
    
    sort(p.begin(),p.end());
    sort(m.begin(),m.end());
    
    ll ansp = abs(p[N-1] - p[0]);
    ll ansm = abs(m[N-1] - m[0]);
    
    ll ans = ansm;
    if ( ansp > ansm ) ans = ansp;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9524
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int     MOD = (int) 1E9 + 7;
    static final int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        int N = nint();
        int K = nint();
        int[] h = nints(N);
        
        int[] cost = new int[N];
        Arrays.fill(cost, INF);
        cost[0] = 0;
        
        for (int i = 0; i < N; i++) {
            for (int k = 1; k <= K && i + k < N; k++) {
                cost[i+k] = Math.min(cost[i] + Math.abs(h[i] - h[i+k]), cost[i+k]);
            }
        }
        
        System.out.println(cost[N-1]);
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

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

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 50028
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
string s;


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>s;
    ll g = 0;
    ll p = 0;
    rep(i,s.size()){
        if(s[i]=='g')g++;
        else p++;
    }
    print(s.size()/2 - p);
    return 0;
}

Measured memory_bytes: 512
def isAC(S):
    if S[0] != 'A':
        return False
    if S[2:-1].count('C') != 1:
        return False
    S = S[1:].replace('C', '')
    if not all('a' <= x <= 'z' for x in S):
        return False
    return True

print('AC' if isAC(input()) else 'WA')

Measured memory_bytes: 9104
n = int(input())
ans = n
dis = []

for i in range(n):
    a, b = map(int, input().split())
    dis.append((a-b, a+b))

dis = sorted(dis, key=lambda x: x[1])

right = dis[0][1]
for i in range(1, n):
    if dis[i][0] < right:
        ans -= 1
    else:
        right = dis[i][1]

print(ans)



Measured memory_bytes: 19028
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e3+5;
const int MOD=1e9+7;

int n, a, b, c, d;
int cache[N][N], cache2[N][N];
int fact[N], invfact[N], store[N][N];

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

int modinv(int k)
{
	return pow(k, MOD-2, MOD);
}

void precompute()
{
	fact[0]=fact[1]=1;
	for(int i=2;i<N;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
	invfact[N-1]=modinv(fact[N-1]);
	for(int i=N-2;i>=0;i--)
	{
		invfact[i]=invfact[i+1]*(i+1);
		invfact[i]%=MOD;
	}
	for(int i=1;i<N;i++)
	{
		int val=modinv(fact[i]);
		store[i][0]=1;
		for(int j=1;j<N;j++)
			store[i][j]=(store[i][j-1]*val)%MOD;
	}
}

int nCr(int x, int y)
{
	if(y>x)
		return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}

int dp2(int n, int r, int take)
{
	int ans=fact[n] * invfact[n-r*take];
	ans%=MOD;
	int den=store[r][take];
	ans*=den;
	ans%=MOD;
	return ans;
}

int dp(int remaining, int freq)
{
	if(remaining==0)
		return 1;
	if(freq==b+1)
		return 0;
	int &ans=cache[remaining][freq];
	if(ans!=-1)
		return ans;
	ans=dp(remaining, freq+1);
	for(int i=c;i<=d;i++)
	{
		int take=i*freq;
		if(take>remaining)
			break;
		int ways=dp2(remaining, freq, i);
		ways*=dp(remaining-take, freq+1);
		ways%=MOD;
		ways*=invfact[i];
		ways%=MOD;
		ans+=ways;
	}
	ans%=MOD;
	return ans;
}

int32_t main()
{
	IOS;
	precompute();
	memset(cache, -1, sizeof(cache));
	memset(cache2, -1, sizeof(cache2));
	cin>>n>>a>>b>>c>>d;
	int ans=dp(n, a);
	cout<<ans;
	cerr<<(double)clock()/CLOCKS_PER_SEC;
	return 0;
}


Measured memory_bytes: 24064
# 2020/01/18
# キーエンス プログラミング コンテスト 2020 - B

from operator import itemgetter

# Input
n = int(input())

in_list = list()

for i in range(n):
    wl = list()
    x, l = map(int, input().split())
    xl = x - l
    xr = x + l
    wl.append(x)
    wl.append(l)
    wl.append(xl)
    wl.append(xr)
    in_list.append(wl)

in_list.sort(key=itemgetter(3))

# Calc
wkx_a = in_list[0][0]
wkl_a = in_list[0][1]
wkxr_a = in_list[0][3]
ans = 1

for i in range(1, n):
    x = in_list[i][0]
    l = in_list[i][1]
    if wkxr_a <= in_list[i][2]:
        wkx_a = x
        wkl_a = l
        wkxr_a = in_list[i][3]
        ans = ans + 1

# Output
print(ans)

Measured memory_bytes: 29272
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const ll INF = 1e18 + 5;

void solve(){
    int n;
    cin>>n;
    vi v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    sort(all(v));
    cout<<v[v.size()/2]-v[v.size()/2-1];
}
int main(){
    int T=1;        //! COMMENT IF THERE IS NO TEST CASES
    //cin>>T;             
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(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 tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    const double pi = acos(-1);
    double r;
    cin >> r;
    double ans = r*2*pi;
    printf("%.6f",ans);
}


Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>
using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n+1);
    a[0] = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    int in=0;
    vector<int> ans(n+1,0);
    vector<int> res;
    for (int i = n; i > 0; --i) {
        int sum=0;
        for (int k = i+i; k <= n; k+=i) {
            sum += ans[k];
        }
        if (sum % 2 != a[i]) {
            ans[i]++;
            res.push_back(i);
        }
    }
    cout << res.size() << endl;
    for (auto c: res) {
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 3192
# vim: fileencoding=utf-8


def main():
    n = int(input())
    t, a = map(int, input().split())
    li = list(map(int, input().split()))
    ans_v = float("inf")
    ans_i = 0
    for i, x in enumerate(li):
        temperature = abs(a - (t - x * 0.006))
        if ans_v > temperature:
            ans_v = temperature
            ans_i = i + 1
    print(ans_i)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62612
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int L,R,D;
  cin >> L >> R >> D;
  int count = 0;
  for(int i = L;i<R+1;i++)
  {
    if(i%D==0)
    {
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

main(){
   int a,b,x;
   scanf("%d%d%d",&x,&a,&b);
   printf((MIN(abs(a-x),abs(b-x))==abs(a-x))?"A":"B");
}

Measured memory_bytes: 128
st [] = []
st [x] = show(x)
st (x:xs) = show(x) ++ " " ++ st xs

ms [x] = [x]
ms (x:xs)
  | x > y = y:x:ys
  | otherwise = x:y:ys
  where
    (y:ys) = ms xs

mss [] = []
mss xs = y : mss ys
  where
    (y:ys) = ms xs

main = do
  s <- getLine
  putStrLn $ st $ mss $ map (read :: String -> Int) $ words s

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

int main() {
  string s;
  cin >> s;
  if (s.front() == '>') s = '<' + s;
  if (s.back() == '<') s += '>';

  vector<ll> v;  // <の個数, >の個数, <の個数...
  int cnt = 0;
  bool ku = true;
  for (int i = 0; i < s.size(); i++) {
    if (ku) {
      if (s[i] == '<') {
        cnt++;
      } else {
        v.push_back(cnt);
        cnt = 1;
        ku = false;
      }
    } else {
      if (s[i] == '>') {
        cnt++;
      } else {
        v.push_back(cnt);
        cnt = 1;
        ku = true;
      }
    }
  }
  v.push_back(cnt);

  ll ans = 0;
  ku = true;
  ll mx = 0;
  for (auto w : v) {
    if (ku) {
      // < の個数から解析
      // 最後の < の左側まで確定 (0 < 1 < 2 < ? > >...)
      // それ以外は 0 から昇順
      ans += w * (w - 1) / 2;
      mx = w;
      ku = false;
    } else {
      // > の個数から解析
      // 最初の > の左側は、両側よりも大きい値 ( < 5 < 6 > 2 > 1 > 0 < 1 <...)
      // それ以外は 0 まで降順
      ans += w * (w - 1) / 2;
      ans += max(mx, w);
      ku = true;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3348
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top;

int isEmpty() {
	return ((top == 0)? 1:0);
}

void push(int *s, int x) {
	top++;
	s[top] = x;
}

int pop(int *s) {
	if (isEmpty()) {
		fprintf(stderr, "underflow\n");
	} else {
		top--;
	}

	return s[top + 1];
}

int main() {
	int x,tmp;
	int stack[101];
	char s[100];

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			tmp = pop(stack);
			x = pop(stack) + tmp;
			push(stack,x);
		} else if (s[0] == '-') {
			tmp = pop(stack);
			x = pop(stack) - tmp;
			push(stack,x);
		} else if (s[0] == '*') {
			tmp = pop(stack);
			x = pop(stack) * tmp;
			push(stack,x);
		} else {
			x = atoi(s);
			push(stack,x);
		}
	}
	printf("%d\n", stack[top]);

	return 0;
}

Measured memory_bytes: 548
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a


n = int(input())
a = list(map(int, input().strip().split()))

L = [0]
R = [0]
for i in range(n):
    L.append(gcd(L[i], a[i]))
    R.append(gcd(R[i], a[n-i-1]))

res = 0
for i in range(n):
    if res < gcd(L[i], R[n - i - 1]):
        res = gcd(L[i], R[n - i - 1])

print(res)


Measured memory_bytes: 20844
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N,x,y = map(int, readline().split())

    count = [0]*N
    for i in range(1,N):
        for j in range(i+1,N+1):
            k = min(j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
            count[k] += 1

    for k in range(1,N):
        print(count[k])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
import math

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

move= [A,B,C,D,E]
min_move =min(move) 
min_move_idx = move.index(min_move)
time = 4


time += math.ceil(N/min_move )

print(time)


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

using namespace std;

#define rep(i,m,n) for(int i=m;i<n;i++)


typedef long long ll;


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

 ll n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<ll> index;
  index.push_back(0);
  
  rep(i,1,n) if(s[i]!=s[i-1]) index.push_back(i);
  
    rep(i,0,2*k+2) index.push_back(n);
  
  ll res=0;
  rep(i,0,index.size()){
   if(index[i]==n) break;
    res=max(res,index[i+2*k+ll(s[index[i]]-'0')]-index[i]);
  }
  cout << res << endl;
  
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

long long sum(int i, string &s){
  int n = s.size()-1;
  vector<long long> part;
  part.push_back(s[0]-'0');
  
  for(int j=0; j<n; j++){
    if((i>>j)&1){
      part.push_back(s[j+1]-'0');
    }
    else{
      part.back() *= 10;
      part.back() += s[j+1]-'0';
    }
  }
  
  long long rtn = 0;
  for(int j=0; j<part.size(); j++){
    rtn += part[j];
  }
  //cout << rtn << endl;
  return rtn;
}

int main(){
  string s; cin >> s;
  int n = s.size()-1;
  long long ans = 0;
  
  rep(i, 1<<n){
    ans += sum(i, s);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	unsigned long long int a, b, n, ans;
	while(cin >> n >> a >> b) {
		if(!a && !b) ans = 0;
		else {
			ans = (n / (a + b)) * a;
			if(n % (a + b)) {
				ans += min(n % (a+b), a);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,s=0;
    cin>>t;
    int a,b;
    cin>>a>>b;
    while(t--){
        int n,c=0;
        cin>>n;
        for(int i=1; i<=a; i+=n)
            c++;
        s+=c;
    }
    cout<<s+b<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int ans=200;
    while(c){
        --ans;
        if(a%ans==0&&b%ans==0){
            --c;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i)

ans = 1
if n == 1 || as[0] == as[1]
  increased = 0
else
  increased = as[0] < as[1] ? 1 : -1
end

1.upto(n - 1) do |i|
  next if as[i - 1] == as[i]

  if increased == 0
    increased = as[i - 1] < as[i] ? 1 : -1
    next
  end

  if (increased == 1 && as[i - 1] > as[i]) || (increased == -1 && as[i - 1] < as[i])
    ans += 1
    increased = 0
  end
end

puts ans


Measured memory_bytes: 8460
#include <iostream>

using namespace std;

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

    int matrix[n+1][n+1];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> matrix[i][j];
        }
    }

    for (int i = 0; i < n+1; i++) {
        matrix[n][i] = 0;
        matrix[i][n] = 0;
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            matrix[i][n] += matrix[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            matrix[n][j] += matrix[i][j];
        }
    }

    matrix[n][n] = 0;
    for (int i = 0; i < n; i++) {
        matrix[n][n] += matrix[n][i];
    }
    
    for (int i = 0; i < n+1; i++) {
        for (int j = 0; j < n+1; j++) {
            cout.width(5);
            if (j == n) 
                cout << matrix[i][j];
            else 
                cout << matrix[i][j];
        }
        cout << endl;
    }
    }

    return 0;
}

            

Measured memory_bytes: 0
#include <iostream>


int main()
{
	int X;
	std::cin >> X;

	auto IsPrime = [](int X) {

		if (X == 2) {
			return true;
		}

		// 愚直に√Xまで割れるか判定する。
		for (int i = 2; i * i <= X; ++i) {
			if ((X % i) == 0) {
				return false;
			}
		}

		return true;
	};


	// 愚直にXからインクリメントして判定する。
	int Y = X;
	while (!IsPrime(Y)) {
		++Y;
	}

	std::cout << Y << std::endl;

	return 0;
}

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

char s[4], ss[4];
int ans = 0;

int main() {
	scanf("%s\n%s", s + 1, ss + 1);
	for(int i = 1; i <= 3; ++i) {
		if(s[i] == ss[i])	ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<n;i++)
using namespace std;

int main() {
  int N,ans;
  cin >> N;
  ans = 1000 - N%1000;
  if (ans==1000) cout << 0 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define ld long double
#define MAX 100007
#define pb push_back
#define MOD 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    ll t1=h1*60+m1;
    ll t2=h2*60+m2;
    ll ans=t2-t1-k;
    cout<<max(ans,0LL);
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int main()
{
    int x, y;
    cin>>x>>y;
    Yes(x * 2 <= y && y <= x * 4 && y % 2 == 0);

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol n,a,b,c,d;
  string s,w;
  int ans[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >>n;
  cout <<ans[n-1]<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=201234;

int n,nw,nw2,nx=1,nx2=1;
ll k,res,a[2][51][51],b[2][51][51];

void ksm(ll k)
{
    ll c;
    while(k)
    {
        if(k&1)
        {
            for(int i=1; i<=n; ++i)
            {
                for(int j=1; j<=n; ++j)
                {
                    c=0;
                    for(int k=1; k<=n; ++k)
                    {
                        c=(c+b[nw2][i][k]*a[nx][k][j]%MOD)%MOD;
                    }
                    b[nx2][i][j]=c;
                }
            }
            swap(nw2,nx2);
        }
        k>>=1;
        swap(nw,nx);
        for(int i=1; i<=n; ++i)
        {
            for(int j=1; j<=n; ++j)
            {
                c=0;
                for(int k=1; k<=n; ++k)
                {
                    c=(c+a[nw][i][k]*a[nw][k][j])%MOD;
                }
                a[nx][i][j]=c;
            }
        }
    }
}

int main()
{
    scanf("%d %lld",&n,&k);
    for(int i=1; i<=n; ++i)
    {
        for(int j=1; j<=n; ++j)
        {
            scanf("%lld",&a[nx][i][j]);
        }
        b[nw2][i][i]=1;
    }
    ksm(k);
    for(int i=1; i<=n; ++i)
    {
        for(int j=1; j<=n; ++j)
        {
            res=(res+b[nw2][i][j])%MOD;
        }
    }
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10 , OO = 0x3f3f3f3f ;
const int mod = 1e9 + 7;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int n;

int main()
{
   // startTime = (double)clock();
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    scanf("%d" , &n);
    printf("%d\n" , n + (n * n) + (n * n * n));



    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a, b, c; cin >> a >> b >> c;
	auto chk = [&](long long u, long long v, long long w){
		long long l = u / 2;
		return abs(l * v * w - (u - l) * v * w);
	};
	cout << min({chk(a, b, c), chk(b, a, c), chk(c, a, b)}) << endl;
	return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d%d", $n, $d);

for($i=0;$i<$n;$i++){
    $array[] = explode(" ",trim(fgets(STDIN)));
}

$ans = 0;
for($i=0;$i<($n-1);$i++){
    for($j=$i+1;$j<$n;$j++){

        $square_sum = 0;
        foreach($array[$i] as $index => $value){
            $square_sum += pow($value - $array[$j][$index],2);
        }

        $dist = pow($square_sum, 0.5);
        if(ceil($dist) == floor($dist)){
            $ans++;
        }


    }
}


echo $ans;

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

using namespace std;

int main()
{
    int N, S;
    while (cin >> N >> S, N) {
        vector<int> r(N);
        for (int i = 0; i < N; i++) {
            cin >> r[i];
        }
        
        sort(r.begin(), r.end());
        
        int res = 0;
        for (int i = 0; i < N; i++) {
            res += N - (upper_bound(r.begin() + i + 1, r.end(), S - r[i]) - r.begin());
        }        
        cout << res << endl;
    }
    return 0;
}

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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();

      Map<Character, Integer> freq = new HashMap<>();
      freq.put('M', 0);
      freq.put('A', 0);
      freq.put('R', 0);
      freq.put('C', 0);
      freq.put('H', 0);

      for(int i = 0; i < n; i++) {
        char c = sc.next().charAt(0);
        if(freq.containsKey(c))
          freq.put(c, freq.get(c) + 1);
      }

      long cnt = 0;
      List<Integer> vals = new ArrayList<>(freq.values());
      for(int i = 0; i < vals.size(); i++) {
        long a = vals.get(i);
        if(a == 0) continue;
        for(int j = i + 1; j < vals.size(); j++) {
          long b = vals.get(j);
          if(b == 0) continue;
          for(int k = j + 1; k < vals.size(); k++) {
            long c = vals.get(k);
            if(c == 0) continue;
            cnt += a * b * c;
          }
        }
      }
      

      System.out.println(cnt);
  }
}


Measured memory_bytes: 44228
MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  40 42 -1
  20 30 -1
  0 2 -1
  -1 -1 -1
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

m,f,r=[0,0,0]
n=0
while true
  m,f,r = line[n].split(" ").map(&:to_i)
  break if m+f+r == -3
  n += 1
  if m==-1 || f==-1
    puts "F"
  elsif m+f>=80
    puts "A"
  elsif 65<=m+f && m+f<80
    puts "B"
  elsif 50<=m+f && m+f<65
    puts "C"
  elsif 30<=m+f && m+f<50
    if r>=50
      puts "C"
    else
      puts "D"
    end
  else
    puts "F"
  end
end

Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

double dist(int x1, int y1, int x2, int y2){
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int fact(int n){
  if(n==0)return 1;
  return n*fact(n-1);
}

int main(){
  int n;
  cin >> n;
  vector<int>x(n), y(n), r(n);
  for(int i=0; i<n; i++){
    cin >> x[i] >> y[i];
    r[i]=i;
  }
  double ret=0;
  do{
    for(int i=0; i<n-1; i++){
      ret+=dist(x[r[i]], y[r[i]], x[r[i+1]], y[r[i+1]]);
    }
  }while(next_permutation(r.begin(), r.end()));
  ret/=fact(n);
  cout << setprecision(14) << ret;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

void solve()
{
    ll n;
    cin>>n;
    ll a[n+1];
    for(ll i=1; i < n+1; i++) cin >> a[i];
    ll ps[n+1]={0},dp[n+1]={0};
    dp[0] = 0;
	dp[1] = 0;
    ps[1] = a[1];
    for(ll i=3;i<=n;i+=2) 
	{
		ps[i] = ps[i-2] + a[i];
	//	cout << ps[i] << " ";
	}
    for(ll i = 2; i < n+1; i++)
	{
        if (i&1)
		{
            dp[i] = max(dp[i-1],a[i]+dp[i-2]);
        }
        else
		{
            dp[i] = max(dp[i-2] + a[i],ps[i-1]);
        }
	}
    cout << dp[n] << endl;
}
int main() 
{  
	fast;
	solve();
}

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

using namespace std;

#define int long long
#define mod 1000000007
#define maxn 200005
#define endl '\n'

int dp[maxn];

int inc(int l, int h, vector<int> &v, int m) {
    int i = l - 1;
    int mid;
    while (l <= h) {
        mid = (l + h) / 2;
        if (v[i] * v[mid] < m && v[i] * v[mid + 1] >= m)
            return mid - i;
        else if (v[i] * v[mid] < m && v[i] * v[mid + 1] < m)
            l = mid + 1;
        else h = mid - 1;
    }
}

int dec(int l, int h, vector<int> &v, int m) {
    int i = l - 1, mid;
    while (l <= h) {
        mid = (l + h) / 2;
        if(v[i] * v[mid] < m && v[i] * v[mid -1] >=m)
            return (int)v.size() - mid;
        else if(v[i] * v[mid] < m && v[i] * v[mid -1] < m)
            h = mid -1;
        else l = mid + 1;
    }
}

bool check(int m, int k, vector<int> &v, int n) {
    int c = 0;
    for (int i = 0; i < n - 1; i++) {
        if (v[i] < 0) {
            if (v[i] * v[n - 1] >= m) c += 0;
            else if (v[i] * v[i + 1] < m) {
                c += n - i - 1;
            } else {
               c +=  dec(i + 1 , n-1 , v , m);
            }
        } else {
            if (v[i] * v[i + 1] >= m) c += 0;
            else if (v[i] * v[n - 1] < m) {
                c += n - i - 1;
            } else {
                c += inc(i + 1 , n-1 , v , m);
            }
        }
    }
    return c < k;
}


void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    bool ve = false, _ve = false;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (v[i] >= 0) ve = true;
        else _ve = true;
    }
    sort(v.begin(), v.end());
    int l, h, m, ans = 0;
    if (ve && _ve) {
        l = v[0] * v[n - 1];
        h = max(v[0] * v[1], v[n - 1] * v[n - 2]);
    } else if (ve) {
        l = v[0] * v[1];
        h = v[n - 1] * v[n - 2];
    } else {
        l = v[n - 1] * v[n - 2];
        h = v[0] * v[1];
    }
    while (l <= h) {
        m = (l + h) / 2;
        if (check(m, k, v, n)) {
            ans = m;
            l = m +1;
        } else h = m - 1;
    }
    cout << ans << endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
//    cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 4788
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 2000000;
const int K = 60;
const int mod = 998244353;
int s[N], f[N], invf[N];
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int c(int n, int k){
    if (k > n) return 0;
    return f[n] * invf[k] % mod * invf[n - k] % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    f[0] = 1;
    invf[0] = 1;
    for (int i = 1; i < N; i++) f[i] = f[i - 1] * i % mod;
    for (int i = 1; i < N; i++) invf[i] = binpow(f[i], mod - 2);
    int n, m;
    cin >> n >> m;
    int ans = 0;
    int q = 0;
   // cout << ans << endl;
    s[0] = c(n - 2, 0);
    for (int i = 1; i <= m; i++) s[i] = (s[i - 1] + c(i + n - 2, i)) % mod;
   // for (int i = 0; i <= m; i++) cout << s[i] << " ";
   // cout << endl;
    for (int i = 0; i <= min(n, m); i++){
        if ((3 * m - i) % 2 == 1) continue;
        int t = c(n, i);
        int a = (3 * m - i) / 2;
        t = c(n + a - 1, a) % mod;
        int q = s[a - m - 1];
        if (a < m + 1) q = 0;
      //  cout << "t = " << t << endl;
        t = (t - q * (n - i) % mod + mod) % mod;
        q = s[a - m];
        if (a < m) q = 0;
        t = (t - q * i % mod + mod) % mod;
        ans = (ans + t * c(n, i)) % mod;
       // cout << i << " " << ans << endl;
    }
    cout << ans;
}


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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(u == s) {
        a--;
    } else {
        b--;
    }
    cout << a << " " << b;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n[5],i;
	for(i=0;i<5;i++)scanf("%d",&n[i]);
	for(i=n[0];i>0;i--){
		if(n[1]<=0 && n[2]<=0)break;
		n[1]-=n[3],n[2]-=n[4];
	}
	printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ll dist = 0;
    while(dist < x) {
        ans++;
        dist += ans;
    }
    cout << ans << endl;
}

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

int main() {
    int N, K;
    int S = 1;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        if(2*S >= S+K){
            S += K;
        }
    else{
        S *= 2;
    }

    }
    cout << S;
}
    


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(ABCD: str):
    l = list(str(ABCD))
    ope =('+', '-')

    import itertools
    for i in itertools.product(ope, repeat=3):
        t = int(l[0])
        tl = []
        tl.append(l[0])
        for j,x in enumerate(i):
            tl.append(x)
            tl.append(l[j+1])
            if(i[j] == '+'):
                t += int(l[j+1])
            else:
                t -= int(l[j+1])

        # print(tl)
        if(t == 7):
            tl.append('=7')
            # print(tl)
            print(''.join(map(str,tl)))
            sys.exit()

    l = list(map(int, l))
    print('%d+%d+%d+%d=7' % (l[0], l[1], l[2], l[3]))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = str(next(tokens))  # type: int
    solve(ABCD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		Eratosthenes e = new Eratosthenes(n);
		long ans = 0;
		for (int c = 1; c < n; c++) {
			Map<Integer, Integer> soinsu = e.bunkai(n - c);
			long val = 1;
			for (Integer key : soinsu.keySet()) {
				val *= soinsu.get(key) + 1;
			}
			ans += val;
		}
		System.out.println(ans);
	}

	static class Eratosthenes {
		int[] div;

		public Eratosthenes(int n) {
			if (n < 2) return;
			div = new int[n + 1];
			div[0] = -1;
			div[1] = -1;
			int end = (int) Math.sqrt(n) + 1;
			for (int i = 2; i <= end; i++) {
				if (div[i] == 0) {
					div[i] = i;
					for (int j = i * i; j <= n; j+=i) {
						if (div[j] == 0) div[j] = i;
					}
				}
			}
			for (int i = end + 1; i <= n; i++) {
				if (div[i] == 0) div[i] = i;
			}
		}

		public Map<Integer, Integer> bunkai(int x) {
			Map<Integer, Integer> soinsu = new HashMap<>();
			while (x > 1) {
				Integer d = div[x];
				soinsu.put(d, soinsu.getOrDefault(d, 0) + 1);
				x /= d;
			}
			return soinsu;
		}

		public boolean isSosuu(int x) {
			return div[x] == x;
		}
	}
}


Measured memory_bytes: 61360
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int x[1000100];
int y[1000100];

int main(){
	long i, j ,k;
	long n , m;
	cin >> n >> m;
	rep(i, m) cin >> x[i];
	sort(x,x+m);
	rep(i, m-1){
		y[i] = abs(x[i+1] - x[i]);
	}
	sort(y, y+m-1);
	rep(i, m-n){
		j += y[i];
	}
	cout << j << endl;
}

Measured memory_bytes: 4736
#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 <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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();}
long long a[200001];

void binary_dump(long long x)
{
    while(x > 1)
    {
        cout << (x % 2);
        x /= 2;
    }
    cout << x;
    cout << endl;
}

int main(){
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for(int i=0;i<n;++i)
    {
        cin >> a[i];
        // cout << i << (i < 10 ? " " : "") <<" : ";
        // binary_dump(a[i]);
    }

    long long xor_value = 0;
    long long sum = 0;
    long long continuous_length = 0;
    long long ans = 0;
    long long  l = 0;
    for(long long i=0;i<n;++i)
    {
        if((xor_value ^ a[i]) != (sum + a[i]))
        {
            // cout << "(" << l << ", " << (i - 1) << ")" << endl;
            // dump(continuous_length);
            //ans += (continuous_length + 1) * (continuous_length) / 2 - continuous_length;
            while((xor_value ^ a[i]) != (sum + a[i]))
            {
                xor_value = xor_value ^ a[l];
                sum -= a[l];
                ++l;
            }
            ans += (continuous_length + 1) * (continuous_length) / 2 - ((i - l) * (i - l - 1) / 2) - continuous_length;
            xor_value = xor_value ^ a[i];
            sum += a[i];
            continuous_length = i - l + 1;
            // dump(i);
            // dump(l);
        }
        else
        {
            // binary_dump(a[i]);
            continuous_length++;
            xor_value = xor_value ^ a[i];
            sum += a[i];
        }
    }

    ans += (continuous_length + 1) * (continuous_length) / 2 - continuous_length;

    cout << ans + n << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String t = sc.next();
		sc.close();

		int len = t.length();

		if(len==1) {
			if(t.equals("?")) {
				System.out.println("D");
			}else {
				System.out.println(t);
			}
			return;
		}

		String[] array = t.split("");
		int i = 0;
		if(array[i].equals("?")) {
			array[i] = "D";
		}

		for(i=1;i<len-1;i++) {
//			String str1 = array[i-1];
			if(array[i].equals("?")) {
				if(array[i-1].equals("P")) {
					array[i] = "D";
				}else {
					if(array[i+1].equals("P")) {
						array[i] = "D";
					}else {
						array[i] = "P";
					}
				}
			}
		}

		i = len - 1;
		if(array[i].equals("?")) {
			array[i] = "D";
		}
		System.out.println(String.join("",array));
	}
}


Measured memory_bytes: 55900
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stdio.h>
#include<cmath>
#include<string.h>

using namespace std;

int main(void)
{
	double a, b;
	cin >> a>> b;
	if (a < b)
	{
		cout <<"LESS" << endl;
	}
	else if (a > b)
	{
		cout << "GREATER" << endl;
	}
	else if (a == b)
	{
		cout << "EQUAL" << endl;
	}
		return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;


struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i, N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	string S, T; cin >> S >> T;
	
	VS ans(S.size() + T.size());
	REP(i, S.size())ans[i * 2] = S[i];
	REP(i, T.size())ans[i * 2+1] = T[i];
	REP(i, ans.size())cout << ans[i];
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

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

		int[] dp = new int[n];
		dp[0] = 0;
		for(int i=1;i<n;i++)
		{
			int min = Integer.MAX_VALUE;
			for(int j=i-1;j>=Math.max(0,i-k);j--)
			{
				min = Math.min(min,dp[j]+Math.abs(arr[j]-arr[i]));
			}

			dp[i] = min;
		}

		System.out.println(dp[n-1]);
	}
}

Measured memory_bytes: 59456
class UnionFind(): 
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n 
        
    def find(self, x): 
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
            
    def union(self, x, y): 
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x,y = y,x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def same(self, x, y): 
        return self.find(x) == self.find(y)

N, M = map(int, input().split())
P = list(map(int, input().split()))
uf = UnionFind(N+1)
graph = [[] for _ in range(N)]
can = [[] for _ in range(N)]
xy = list()
for i in range(M):
  x, y = map(int, input().split())
  uf.union(x, y)
ans = 0
for i in range(1, N+1):
  if uf.same(i, P[i-1]):
    ans += 1
print(ans)

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

int main(){
	int n, a;
	int ans[7];
	while( cin >> n , n ){
		for(int i=0 ; i<7 ; i++) ans[i] = 0;
		
		for(int i=0 ; i<n ; i++){
			cin >> a;
			if( a < 10 ) ans[0]++;
			else if( a < 20 ) ans[1]++;
			else if( a < 30 ) ans[2]++;
			else if( a < 40 ) ans[3]++;
			else if( a < 50 ) ans[4]++;
			else if( a < 60 ) ans[5]++;
			else ans[6]++;
		}
		for(int i=0 ; i<7 ; i++){
			cout << ans[i] << endl;
		}
	}
}

Measured memory_bytes: 868
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  char n[5];
  cin>>n;
  bool flag=false;
  for(int i=0;i<2;i++){
    if(n[i]==n[i+1]&&n[i+1]==n[i+2])flag=true;
  }
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256