akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }.toIntArray().sorted()
    var ans = 0
    for (i in 0 until n - 2) {
        for (j in i + 1 until n - 1) {
            val sum = a[i] + a[j]
            for (k in j + 1 until n) {
                if (sum > a[k]) {
                    ans++
                } else {
                    break
                }
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 48588
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int ma = Integer.MIN_VALUE, mi = Integer.MAX_VALUE, n = sc.nextInt();
		while (n-->0) {
			int a = sc.nextInt();
			ma = Math.max(ma, a);
			mi = Math.min(mi, a);
		}
		System.out.println(ma-mi);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35716
#include<iostream>
using namespace std;
#define int long long
int dp[55][55][2600];//dp(i,j,k) i枚目にj枚使って和がk
int x[55];
signed main() {
	int n, a;
	cin >> n >> a;
	for (int i = 0; i<n; i++)cin >> x[i];

	dp[0][0][0] = 1;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < 2501; k++) {
					dp[i + 1][j][k] += dp[i][j][k];
					if (k >= x[i]) {
						dp[i + 1][j + 1][k] += dp[i][j][k - x[i]];
					}
			}
		}
		}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 2500; j++) {
			if (j == i*a) { ans += dp[n][i][j]; }
		}
	}
	cout << ans << endl;
	}

Measured memory_bytes: 56448
#include<stdio.h>
int main()
{
  int a,b,k,m,i,c=0,j ;
   scanf("%d",&k);
   scanf("%d",&a);
   scanf("%d",&b);
  for(i=a;i<=b;i++)
  {
    m=i/k;
    j=m*k;
    if(i==j)
      c++;
  }
  if(c!=0)
     printf("OK");
  else
    printf("NG");
}
    

Measured memory_bytes: 2168
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[M];
        int[] b = new int[M];
        for (int i = 0; i < M; ++i) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        System.out.println(solve(N, a, b));

        sc.close();
    }

    static int solve(int N, int[] a, int[] b) {
        int[] sortedIndices = IntStream.range(0, a.length).boxed().sorted((i1, i2) -> Integer.compare(b[i1], b[i2]))
                .mapToInt(x -> x).toArray();

        int result = 0;
        int prevEnd = -1;
        for (int index : sortedIndices) {
            if (a[index] >= prevEnd) {
                ++result;
                prevEnd = b[index];
            }
        }

        return result;
    }
}

Measured memory_bytes: 90560
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int ind[] = new int[n];
    for(int i=0;i<n;i++){
      a[i] = sc.nextInt();
    }

    for(int i=0;i<n;i++){
      //i番目にjが来たら、j番目はi+1
      ind[a[i]-1]=i+1;
      
    }
    for(int i=0;i<n;i++){
      System.out.print(ind[i]);
      System.out.print(" ");
    }
        
    
      
    
    
  }
  

  
}

Measured memory_bytes: 61344
from bisect import bisect_left
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

MOD = 998244353

n = int(input())
robot = []
pos = []

for i in range(n):
    x, d = map(int, input().split())
    robot.append([x, x+d])
    pos.append(x)

robot = sorted(robot, key=lambda y: y[0])
pos = sorted(pos)


def init(init_val):
    for i in range(n):
        MI[i+num-1] = init_val[i]
        MA[i+num-1] = init_val[i]
    for i in range(num-2, -1, -1):
        MI[i] = min(MI[2*i+1], MI[2*i+2])
        MA[i] = max(MA[2*i+1], MA[2*i+2])


def update(k, x):
    k += num-1
    MI[k] = x
    MA[k] = x
    while k+1:
        k = (k-1)//2
        MI[k] = min(MI[k*2+1], MI[k*2+2])
        MA[k] = max(MA[k*2+1], MA[k*2+2])


def rangemax(p, q):
    if q <= p:
        return -1
    p += num-1
    q += num-2
    res = -1
    while q-p > 1:
        if p & 1 == 0:
            res = max(res, MA[p])
        if q & 1 == 1:
            res = max(res, MA[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res, MA[p])
    else:
        res = max(max(res, MA[p]), MA[q])
    return res


# n:リスト長
num = 2**(n-1).bit_length()
MI = [1 << 100]*2*num
MA = [-1]*2*num

r = []
for x, d in robot:
    r.append(bisect_left(pos, d))

init(r)

s = [0]*n

for x in range(n-1, -1, -1):
    right_max = rangemax(x, r[x])
    s[x] = right_max
    update(x, right_max)

dp = [0]*(n+1)
dp[-1] = 1

for i in range(n-1, -1, -1):
    dp[i] = dp[i+1]+dp[s[i]]
    dp[i] %= MOD

print(dp[0])


Measured memory_bytes: 127540
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    vector<int> v(3);
    rep(i,3) cin >> v[i];
    sort(v.begin(),v.end());
    if(v[2] == v[0]+v[1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vvll g(n);
    ll a, b;
    vector<P> p(n - 1);
    REP(i, n - 1) {
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
        p[i] = {a, b};
    }
    ll cur = 0;
    queue<ll> que;
    que.push(cur);
    vll used(n);
    used[cur] = 1;
    map<P, ll> res;
    vll par(n); // par[i] : i と i の親の間の辺の色
    ll m = 0;
    while (!que.empty()) {
        cur = que.front();
        que.pop();
        ll col = 1;
        for (auto to : g[cur]) {
            if (used[to]) continue;
            if (col == par[cur]) col++;
            par[to] = col;
            res[{cur, to}] = res[{to, cur}] = col;
            m = max(m, col);
            col++;
            used[to] = 1;
            que.push(to);
        }
    }
    cout << m << endl;
    REP(i, n - 1) {
        cout << res[p[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 22144
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
  int i;
  for(;cin>>i,i;)
    {
      int count=32;
      int a[i];
      for(int j=0;j<i;j++)
	  cin>>a[j]; 
      for(int x=0;count!=0;x++)
	{
	  count-=(count-1)%5;
	  cout<<count<<endl;
	  count-=a[x%i];
	  if(count<0)
	    count=0;
	  cout<<count<<endl;
	}
    }
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N,M;
int A[110000];

signed main() {
    cin >> N >> M;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=1;i<N;i++){
        A[i]+=A[i-1];
    }
    for(int i=0;i<N;i++){
        A[i]%=M;
    }
    sort(A,A+N);
    int ans=0,cur=1;
    for(int i=0;i<N-1;i++){
        if(A[i]==A[i+1])cur++;
        else{ans+=cur*(cur-1)/2;cur=1;}
    }
    ans+=cur*(cur-1)/2;
    for(int i=0;i<N;i++)
        if(A[i]==0)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
    int a=sc.nextInt();
    String c=sc.next();
    char op=c.charAt(0);
    int b=sc.nextInt();
      if(op=='?') break;
      if(op=='+') System.out.println(a+b);
      else if(op=='-') System.out.println(a-b);
      else if(op=='*') System.out.println(a*b);
      else if(op=='/') System.out.println(a/b);
    }
     sc.close();
  }
}


Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, k, x, s, t;
  s = t = 0;
  in3(n, k, x);
  vector<ll> a(k);
  rep(i, k){
    in(a[i]);
    if(a[i] > x)
      s++;
    else
      t++;
  }
  s = min(s, t);
  out(s);
  memi;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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



/******************************************************************************************/


const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;



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

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

	auto ans = make_v<int>(55);

	string s;
	cin >> s;

	int cnt = 1;
	for (int i = 1; i < s.size(); i++)
	{
		if (s[i] == s[i - 1]) {
			
		}
		else
		{
			cnt++;
		}
	}

	cout << cnt - 1 << endl;


}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;
 /*temp*/

main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    cout << a[0] << ' '
         << a[1] << ' '
         << a[2] << '\n';
}

Measured memory_bytes: 3136
#[proconio::fastout]
fn main() {
    proconio::input! {
        n: usize,
        mut s: [String;n]
    }
    let mut s: Vec<String> = s;
    s.sort();
    let mut ans = 0;
    let mut prv = String::new();
    for v in s {
        if prv != v {
            ans += 1;
        }
        prv = v;
    }
    println!("{}", ans);
}


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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vi l(Q), r(Q);
    rep(i, Q) cin >> l[i] >> r[i];
    vector<int> cnt(N, 0);
    rep(i, N){
        if(i > 0) cnt[i] = cnt[i-1];
        if(i < N-1 && S[i] == 'A' && S[i+1] == 'C')
            cnt[i]++;
    }

    rep(i, Q){
        int ans = 0;
        ans = cnt[r[i]-1] - cnt[l[i]-1];
        if(S[l[i]-1] == 'A' && S[l[i]] == 'C') ans++;
        if(r[i] != N && S[r[i]-1] == 'A' && S[r[i]] == 'C') ans--;
        cout << ans << "\n";
    }

    //string ans = ( !flag ? "Yes":"No");
    //cout << ans << "\n";
    //printf("%.8lf", ans);
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s;
     cin>>s;

      int count=0;

       for(int i=0;i<s.size()/2;i++)
        {
            if(s[i]!=s[s.size()-i-1])
              count++;
        }
        cout<<count;
}


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

const long long INF = 1LL << 60;

int main() {
	int N, M; cin >> N >> M;
	vector<int> a(M), b(M);
	vector<long long> c(M);

	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> c[i];
		c[i] = -c[i];
		a[i]--, b[i]--;
	}
	
	vector<long long> dist(N, INF);
	dist[0] = 0;
	for (int iter = 0; iter < N-1; iter++) {
		for (int i = 0; i < M; i++) {
			if (dist[a[i]] == INF) continue;
			if (dist[b[i]] > dist[a[i]] + c[i]) {
				dist[b[i]] = dist[a[i]] + c[i];
			}
		}
	}
	long long ans = dist[N-1];

	vector<bool> neg(N, false);
	for (int iter = 0; iter < N; iter++) {
		for (int i = 0; i < M; i++) {
			if (dist[a[i]] == INF) continue;
			if (dist[b[i]] > dist[a[i]] + c[i]) {
				dist[b[i]] = dist[a[i]] + c[i];
				neg[b[i]] = true;
			}
			if (neg[a[i]]) neg[b[i]] = true;
		}
	}

	if (neg[N-1])
		cout << "inf" << endl;
	else
		cout << -ans << endl;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void answer1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void answer2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void answer3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void answer(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  //ll n;
  //cin >> n;
  ll n, m, x;
  cin >> n >> m >> x;
  //string s; cin >> s;
  ll result = 0;
  bool judge = true;
  
  vector<ll> a(m);
  for(i=0;i<m;i++)
    cin >> a[i];
  ll counta=0,countb=0;
  for(i=0;i<m;i++){
    a[i]<x?counta++:countb++;
  }
  cout<<min(counta,countb)<<endl;





  return 0;
}

Measured memory_bytes: 256
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  int n, m; cin >> n >> m;
  if(n == m) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A,B,C,X,houhou = 0;
	cin >> A >> B >> C >> X;

	for(int i=0;i<=C;++i){
		for(int j=0;j<=B;++j){
			for(int k=0;k<=A;++k){
				if(i*50 + j*100 + k*500 == X)++houhou;
			}
		}
	}

	cout << houhou << endl;
}

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

int main()
{    
    int n;
    cin >> n;
    vector<int> a(n);

    int first = -1;
    int cnt = 0;
    int second = -2;
    rep(i,n)
    {
        cin >> a[i];

        if(a[i]>first)
        {
            second = first;            
            first = a[i];
            cnt = 1;
        }
        else if(a[i]==first)
            cnt++;
        else if(a[i]>second)
            second = a[i];
    } 

    rep(i,n)
    {
        if(a[i]==first && cnt==1)
            cout << second << endl;
        else 
            cout << first << endl;
    }

    return 0;
}

Measured memory_bytes: 2432
#!/usr/bin/ruby

N = gets.chomp.to_i
A = gets.chomp.split(" ").map(&:to_i)

lcm = 1
A.each{|n|
 lcm = n.lcm(lcm)
}

#puts lcm

total = 0
A.each{|n|
 b = lcm/n
 total += b
}

puts total % (10**9 + 7)



Measured memory_bytes: 56864
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <bits/stdc++.h> 
 
using namespace std;
 
long long f(long int x,long int y){
    if (x<y) swap(x,y);
    if (y==0) return x;
    x=x%y;
    return f(x,y);
}
 
int main(){
    long int N,M;
    cin>>N>>M;
    long int a[N];
    cin>>a[0];
    int n=0;
    while(a[0]%2==0){
        a[0]=a[0]/2;
        n++;
    }
    for (int i=1;i<N;i++){
        cin>>a[i];
        for (int j=0;j<n;j++){
            if (a[i]%2==0) a[i]=a[i]/2;
            else{
                cout<<0<<endl;
                return 0;    
            }
        }
        if (a[i]%2==0){
        	cout<<0<<endl;
            return 0;    
        }
    }
    M=M/pow(2,n-1);
    long long x=a[0];
    for (int i=1;i<N;i++){
        x=x*(a[i]/f(x,a[i]));
        if (x>M){
            cout<<0<<endl;
            return 0;
        }
    }
    M=M/x;
    cout<<(M+1)/2<<endl;
 
    return 0;
}

Measured memory_bytes: 4796
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };






signed main() {
	ll n, k;

	cin >> n >> k;

	//cout << min(n % k, n%(n%k)) << endl;
	cout << min({ n % k, n, k - (n%k)}) << endl;



	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class TestB
{
    public static void Main(){
        string line = Console.ReadLine();
        string line_2 = Console.ReadLine();
        string[] array = line.Split(' ');
        string[] array_2 = line_2.Split(' ');
        int N = int.Parse(array[0]);
        int M = int.Parse(array[1]);
        List<int> A = new List<int>();
        foreach(string temp in array_2)
        {
            A.Add(int.Parse(temp));
        }

        int rest = N;
        foreach(int temp in A)
        {
            rest = rest - temp;
        }

        if(rest < 0)
        {
            Console.WriteLine("-1");
        }
        else
        {
            Console.WriteLine(rest);
        }
    }
}

Measured memory_bytes: 28500
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
	int N;
	scanf("%d",&N);
	double X[N];
	for(int i=0;i<N;i++){
		scanf("%lf",&X[i]);
	}
	double answer=1000000000000000;
	for(double i=1;i<=100;i++){
		double sum=0;
		for(int j=0;j<N;j++){
			sum += pow( ( X[ j ] - i ) , 2.0 );
		}
		if(sum < answer){
			answer = sum;
		}
	}
	int ANSWER = answer;
	printf("%d ",ANSWER);
}

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

void factors(long int x) { 
	long int ans; 
	for (long int i = sqrt(x); i>=1; i--) { 
		if (x % i == 0 && i*(x / i) == x) {
			ans = i; 
			break;
		}
	} 
	cout << (ans + (x/ans) - 2);
} 


int main() { 
	long int x; 
	cin>>x;
	factors(x); 
	return 0; 
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int l,h,k=0;
  l=0;
  h=s.length()-1;
   while (h > l)
    {
        if (s[l++] != s[h--])
        {
          k+=1;
        }
   }
  cout<<k;
}


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

int main()
{
	   int a;
	   int b;
	   cin >> a;
	   cin >> b;
	   
	   if(a > b){
		   cout << "a > b" << endl;
		   }
	   else if(a == b){
		   cout << "a == b" << endl;
		   }
	   else {
		   cout << "a < b" << endl;
		   }
	  
	  
	}

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

int main()
{
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	
	int v=0;
	for(int i=min(a,x/500);i>=0;i--){
		for(int j=min(b,(x-i*500)/100);j>=0;j--){
			for(int k=min(c,(x-i*500-j*100)/50);k>=0;k--){
				if(x==i*500+j*100+k*50) v++;
			}
		}
	}
	
	cout<<v<<endl;
	
	return 0;
}


Measured memory_bytes: 256
//author:emre yazicioglu
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c);a++)
#define pb push_back
const int N = 2e5 + 7;
ll n,m,ans,ar[N];
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);

	ll a,b;
	cin >> a >> b;
	if((a+b)&1){
		cout << "IMPOSSIBLE";
	}
	else{
		cout << (a+b)/2;
	}
}

Measured memory_bytes: 256
!ref
!https://qiita.com/drken/items/dc53c683d6de8aeacf5a
      PROGRAM Frog2
      IMPLICIT NONE
      integer(16) :: n,k
      integer(16),allocatable :: h(:),dp(:)
      integer(16) :: i,j
      
      read*, n,k
      allocate( h(1:n) )
      read*, h(:)
      
      
      allocate( dp(1:n) )
      dp(:) = 10**9
      dp(1) = 0
      
      
      do i = 1,n
        do j = 1,k
          if( i+j>n ) cycle
          dp(i+j) = min( dp(i+j), dp(i)+abs( h(i+j)-h(i) ) )
        end do
      end do
      
      print*,dp(n)
      
      END PROGRAM

Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n; char s[10];
  vector<int> a(4, 0);
  while( scanf("%d,%s", &n, s) != EOF ){
    if( n == 0 ) break;
    if( s[0] == 'A' && s[1] == 'B' ) a[2]++;
    else if( s[0] == 'A' ) a[0]++;
    else if( s[0] == 'B' ) a[1]++;
    else if( s[0] == 'O' ) a[3]++;
  }
  for(int i=0; i<4; i++) cout << a[i] << endl;

  return 0;
}

// EOF

Measured memory_bytes: 3148
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	
	
	if(N%2==0)
	{
		printf("%d", N/2);
	}	
	else if(N%2!=0)
	{
		printf("%d", N/2 + 1);
	}
	return 0;
}

Measured memory_bytes: 3224
def main():
    S = input()
    T = input()
    N = len(S)
    M = len(T)

    dp = [[0]*(M+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

    # 復元パート 昔のコピペ
    res = ""
    while N > 0 and M > 0:
        if dp[N][M] == dp[N-1][M]:
            N -= 1
        elif dp[N][M] == dp[N][M-1]:
            M -= 1
        else:
            res = S[N-1] + res
            N -= 1
            M -= 1
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 144568
def main():
    S = input()
    for i in range(len(S)):
        # 確認するべき文字は `R` と `L` のみ
        # 変数 i は０から始まることに留意
        if ((i+1) % 2) == 0:
            # 偶数文字目
            if S[i] == "R":
                print("No")  # RだったらNoが確定する
                return  # 処理終了
        else:
            # 奇数文字目
            if S[i] == "L":
                print("No")  # LだったらNoが確定する
                return  # 処理終了
    print("Yes")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
<?php

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

$ans = 0;
foreach($array as $v){
    if(sqrt($v[0]**2 + $v[1]**2) <= $d){
        $ans++;
    }
}
echo $ans;


Measured memory_bytes: 108744
/*
https://t.me/unstoppabIesoIvemachinechannel
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;











#define PI 3.14159265

signed main(){
    double a, b, x;
    cin >> a >> b >> x;
    if (a * a * b == x){
        cout << 0;
        return 0;
    }
    double get = (a * a * a) / (2 *(( a * a * b) - x));
    double f = PI / 2 - atan(get);
    if (a * a * b > x + x){
        get = (b * b * a) / (2 * x);
        f = atan(get);
    }
    //cout << get << endl;
    double fl = f * 180 / PI;
    cout << fixed << setprecision(15) << fl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Applicative


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

main = f 1

f n = do
    i <- readInt
    if i == 0
        then return ()
        else do
            putStrLn $ "Case " ++ show n ++ ": " ++ show i
            f (n+1)


Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define intt long long 
using namespace std;
int i , j;
int main ()
{
    int n;
    cin >> n;
    intt a[n], maxx = 0 , minn = 1e9;
    for ( i =1 ; i <= n ; i++ )
    {
        cin >> a[i];
        minn = min(minn,a[i]);
        maxx = max(maxx,a[i]);
    }
    cout << maxx - minn << endl;
}

Measured memory_bytes: 764
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,a,b,c,d=map(int,input().split())
    for k in range(n): # k 右に行った回数
        L=a+k*c-(n-k-1)*d
        R=a+k*d-(n-k-1)*c
        if(L<=b<=R):
            print("YES")
            return
    print("NO")
resolve()

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b, x;cin >> a >> b >> x;
    string ans = "NO";
    if(x >= a && x <= a+b) ans = "YES";
    cout << ans << endl;
    return 0;
}


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

p_list = list(map(float, input().split()))

dp = [[0.0] * (N+1) for i in range(N+1)]
dp[0][0] = 1.0

for i in range(N):
    for j in range(i+1):
        dp[i+1][j+1] += dp[i][j] * p_list[i]
        dp[i+1][j] += dp[i][j] * (1.0 - p_list[i])
    #print(dp[i])

ans = 0
for j in range(N//2+1, N+1):
    ans += dp[N][j]
#print(dp)
print(ans)

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

const int maxn = 1000000+7;

bool cut[maxn];
int arr[maxn];
int cnt[maxn];
set<int> st;

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

    for(int i = 0; i < n; i++){
        scanf("%d", &arr[i]);
        cnt[arr[i]]++;
        st.insert(arr[i]);
    }

    sort(arr, arr+n);
    int mn = arr[0];
    int mx = arr[n-1];

    for(int idx = 0; idx < n; idx++){
        bool isempty = false;
        for(int fact = 2; fact*arr[idx] <= mx; fact++){
            int val = fact * arr[idx];
            if(st.find(val) != st.end())
                st.erase(st.find(val));
            if(st.size() <= 1){
                isempty = true;
                break;
            }
        }
        if(isempty) break;
    }

    int ans = 0;
    for(set<int>::iterator it = st.begin(); it != st.end(); ++it){
        if(cnt[*it] == 1) ans++;
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef string str;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pair<ll, ll>> vpl;
typedef vector<vl> vvl;
typedef vector<vs> vvs;

#define f(i, start, end) for (i = start; i < end; i++)
#define trav(v) for (auto &x : v)
#define deb(x) cerr << #x << ":" << x << "\n"
#define nl cout << "\n"

int main()
{

    ios::sync_with_stdio(0);
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        ll n, i, j, k, a, b, m = 0;
        str d;
        cin >> d;
        k = -1;
        if (d == "MON")
        {
            k = 6;
        }
        else if (d == "TUE")
        {
            k = 5;
        }
        else if (d == "THU")
        {
            k = 3;
        }
        else if (d == "WED")
        {
            k = 4;
        }
        else if (d == "FRI")
        {
            k = 2;
        }
        else if (d == "SAT")
        {
            k = 1;
        }
        else
        {
            k = 7;
        }
        cout << k;
        nl;
    }
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  set<int> ans;
  REP(i, 1, 10) REP(j, 1, 10) REP(k, 1, 10) {
    if (i + j + k > 9) break;
    vector<int> a;
    rep(_, i) a.eb(3);
    rep(_, j) a.eb(5);
    rep(_, k) a.eb(7);
    do {
      int sum = 0;
      rep(_, a.size()) sum = 10 * sum + a[_];
      if (sum <= n) ans.insert(sum);
    } while (next_permutation(all(a)));
  }

  cout << ans.size() << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n;cin>>n;
	vl a(n+2);
	a[0]=0;a[n+1]=0;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	ll sum=0;
	rep(i,n+1)sum+=abs(a[i]-a[i+1]);
	for(int i=1;i<=n;++i)cout<<sum-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i+1]-a[i-1])<<endl;																																	
}

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


def solve(N: int, S: "List[str]", P: "List[int]"):
    isp = [(i+1,S[i],P[i]) for i in range(N)]
    isp.sort(key= lambda x: (x[1],-x[2]))
    for t in isp:
        print(t[0])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [str()] * (N)  # type: "List[str]"
    P = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)

if __name__ == '__main__':
    main()


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
#define pqasc priority_queue<long long, vector<long long>, greater<long long>>

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

class UnionFind{
private:
  vector<int> Parent; 
 public:
  UnionFind(int N){
    Parent = vector<int>(N, -1);
  }
  
  int root(int A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  int size(int A){
    return -Parent[root(A)]; 
  }
  
  bool connect(int A, int B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(int A, int B){
    return root(A) == root(B);
  }
};

long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

long long ngcd(vector<long long> a) {
  long long res = a[0];
  for(int i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}

long long nlcm(vector<long long> a){
  long long res = a[0];
  for(int i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}

bool is_prime(long long n) {
  if(n < 2) return false;
  for (long long i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}

int digsum(int n) {
  int res=0;
  while(n) res += n%10, n /= 10;
  return res;
}

int digcnt(int n){
  int res=0;
  while(n) res++, n /= 10;
  return res;
}

vector<int> divisor(int n) {
  vector<int> res;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int k; cin>>k;
  int l=k/2;
  k=k-l;
  cout<<k*l<<endl;
}

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

using namespace std;
int c(int x,int y){
    if(x>=2){
        return x*(x-1)/2;
    }else
    {
        return 0;
    }    
}

int main(){
    int n,m;
    cin>>n>>m;
    cout<<c(n,2)+c(m,2);
    return 0;
}

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

using namespace std;

int main(){
    long long int N,A,B,now=0,ans=0;
    cin >> N >> A >> B;
    vector<long long int> X(N);
    for(int i=0;i<N;i++){
        cin >> X[i];
    }

    now = X[0];

    for(int i=1;i<N;i++){
        if(B<A*(X[i]-now)){
            ans += B;
        }else{
            ans += A*(X[i]-now);
        }
        now = X[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
n=int(input())
s=list(map(int,input().split()))
u=sum(s)
min1=10000000
t=0
p=0
for i in range(n-1):
  
  t=sum(s[:i+1])
  p=sum(s[i+1:])
  min1=min(min1,abs(p-t))
        
print(min1)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		in := stdin.Text()
		out, _ := do(in)
		fmt.Println(out)
	}

}

func do(in string) (string, error) {
	s := strings.Split(in, " ")
	var A []int
	for i := range s {
		num, _ := strconv.Atoi(s[i])
		A = append(A, num)
	}
	if A[0] >= A[2] {
		return fmt.Sprintf("%d %d", A[0]-A[2], A[1]), nil
	}
	if A[0]+A[1] >= A[2] {
		return fmt.Sprintf("%d %d", 0, A[0]+A[1]-A[2]), nil
	}
	return "0 0", nil
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<pair<int,int>>a(n);
  for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
  
  vector<long long> s(n),d(n);
  for(int i=0;i<n;i++)
  {
    s[i]=a[i].first+a[i].second;
    d[i]=a[i].first-a[i].second;
  }
  sort(s.begin(),s.end());
  sort(d.begin(),d.end());
  long long ans=max((s[n-1]-s[0]),abs(d[n-1]-d[0]));
  cout<<ans<<endl;
  return 0;
}
  

Measured memory_bytes: 8000
a, b, k = map(int, input().split())

t = []

for i in range(k):
    if i+a <= b:
        t.append(i+a)

for i in range(k):
    if b-i >= a:
        t.append(b-i)

y = list(set(t))

for x in sorted(y):
    print(x)


Measured memory_bytes: 3060
kx=list(map(int,input().split()))
10**6
i=kx[0]
if kx[1]+i-1<10**6 and  kx[1]-i+1>-10**6:
    lst=list(range(kx[1]-i+1,kx[1]+i))
elif kx[1]+i-1>10**6:
    lst=list(range(kx[1]-i+1,10**6+1))
else:
    lst=list(range(-10**6,kx[1]+i))
print(' '.join(map(str, lst)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000, mod = 1000000007;
int n, q, a[maxn + 10], lst[maxn + 10][maxn + 10];
int x[maxn + 10], y[maxn + 10];
bool vis[maxn + 10][maxn + 10][4];
int f[maxn + 10][maxn + 10][4], ans;
int p2[maxn + 10];

int add(int x, int y) {
	x += y; return x < mod ? x : x - mod;
}
int mul(int x, int y) {
	return 1ll * x * y % mod;
}

int calc(int p, int l, int r) {
	int w = p2[min(lst[p][l], lst[p][r]) - p];
	p = min(lst[p][l], lst[p][r]);
	if (p == q + 1) return mul(w, l > r);
	int s, d;
	assert(l == x[p] || l == y[p] || r == x[p] || r == y[p]);
	if (l == x[p]) {
		d = 0; s = r;
	} else if (l == y[p]) {
		d = 1; s = r;
	} else if (r == x[p]) {
		d = 2; s = l;
	} else if (r == y[p]) {
		d = 3; s = l;
	}
	if (vis[p][s][d]) return mul(w, f[p][s][d]);
	if ((l == x[p] && r == y[p]) || (l == y[p] && r == x[p]))
		f[p][s][d] = add(calc(p + 1, l, r), calc(p + 1, r, l));
	else if (l == x[p]) f[p][s][d] = add(calc(p + 1, l, r), calc(p + 1, y[p], r));
	else if (l == y[p]) f[p][s][d] = add(calc(p + 1, l, r), calc(p + 1, x[p], r));
	else if (r == x[p]) f[p][s][d] = add(calc(p + 1, l, r), calc(p + 1, l, y[p]));
	else if (r == y[p]) f[p][s][d] = add(calc(p + 1, l, r), calc(p + 1, l, x[p]));
	vis[p][s][d] = 1;
	return mul(w, f[p][s][d]);
}

int main() {
	p2[0] = 1;
	for (int i = 1; i <= maxn; ++i) p2[i] = add(p2[i - 1], p2[i - 1]);
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= q; ++i) {
		scanf("%d%d", &x[i], &y[i]);
		lst[i][x[i]] = i; lst[i][y[i]] = i;
	}
	for (int i = 1; i <= n; ++i) lst[q + 1][i] = q + 1;
	for (int i = q; i >= 1; --i)
		for (int j = 1; j <= n; ++j)
			if (!lst[i][j]) lst[i][j] = lst[i + 1][j];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (a[i] < a[j]) ans = add(ans, calc(1, i, j));
	printf("%d", ans);
}


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

int main()
{
	char a,b;
	cin >> a >> b;
	if(a>b){
		cout << ">\n";
	}else if(a<b){
		cout << "<\n";
	}else{
		cout << "=\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
using ll = long long;
int main(void){
    int n,ans=1;
    cin>>n;
    vector <string> s(n);
    rep(i,n)cin>>s[i];
    sort(s.begin(),s.end());
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1])ans++;
    }
    // if(s[n-2]!=s[n-1])ans+=2;
    cout<<ans<<endl;
    // int n,size=0;
    // cin>>n;
    // string s,t[n];
    // rep(i,n){
    //     cin>>s;
    //     for(int j=0;j<=size;j++){
    //         if(j==size)t[size++]=s;
    //         if(s==t[j])break;
    //     }
    // }
    // cout<<size<<endl;
}


Measured memory_bytes: 9596
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> p_i;

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

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        while (a % 2 == 0)
        {
            a /= 2;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
MOD = 10**9 + 7
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, A, B = mi()

if N==1 and A!=B:
  print(0)
  exit()

if A>B:
  print(0)
  exit()

print((B*(N-1)+A) - (A*(N-1)+B) + 1)



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

int main(){
  int N=0,min=100000;
  int num=0;
  
  cin >> N;
  int i;
  rep(i,N){
    cin >> num;
    int count = 0;
    while(num%2 == 0){
      num /= 2;
      count ++;
    }
    if(min > count){
      min = count;
    }
  }
  
  cout << min;
}
  

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

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")
}

fn main() {
    let n: i64 = read();
    let k: i64 = read();
    let mut div: i64 = n / k;
    let mut keta: i64 = 1;
    while div != 0 {
        div = div / k;
        keta += 1;
    }

    println!("{}", keta);
}


Measured memory_bytes: 4352
// implement 23min
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct State {
    int cost;
    ll state;
    State() {;}
    State(const int c, const vector<int> &t) : cost(c) {
        state = 0;
        REP(i, 9) {
            state = (state << 4LL) + t[i];
        }
    }
    bool operator<(const State &rhs) const {
        return cost > rhs.cost;
    }
    vector<int> get() const {
        vector<int> ret(9);
        ll t = state;
        REP(i, 9) {
            ret[8 - i] = t & 15LL;
            t >>= 4LL;
        }
        return ret;
    }
};

State Read() {
    vector<int> t(9);
    REP(i, 9) {
        int v = scanf("%d", &t[i]);
        assert(v == 1);
    }
    return State(0, t);
}

int cx, cy;
unordered_map<ll, int> dist;
unordered_set<ll> visit;
State eState;

int main() {
    while (scanf("%d %d", &cx, &cy) > 0 && (cx || cy)) {
        dist.clear();
        visit.clear();
        priority_queue<State> que;
        {
            State start = Read();
            eState = Read();
            que.push(start);
        }
        while (!que.empty()) {
            State s = que.top();
            que.pop();
            if (s.state == eState.state) {
                printf("%d\n", s.cost);
                break;
            }
            if (visit.count(s.state)) { continue; }
            visit.insert(s.state);
            vector<int> tile = s.get();
            int pos = -1;
            REP(i, 9) { if (tile[i] == 0) { pos = i; } }
            int d[4] = { 1, 3, -1, -3 };
            int c[4] = { cx, cy, cx, cy };
            REP(dir, 4) {
                int ncost = s.cost + c[dir];
                int npos = (pos + d[dir] + 9) % 9;
                vector<int> ntile = tile;
                swap(ntile[pos], ntile[npos]);
                State ns(ncost, ntile);
                if (visit.count(ns.state) || (dist.count(ns.state) && dist[ns.state] <= ns.cost)) { continue; }
                dist[ns.state] = ns.cost;
                que.push(ns);
            }
        }
    }
}

Measured memory_bytes: 33768