akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
using ll = long long;

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

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

    int L, Q;
    cin >> L >> Q;

    int fore[20][N];
    int back[20][N];
    // fore[d][i] = 2^d日でx_iからどこまで進めるか
    // back[d][i] = 2^d日でx_iからどこまで戻れるか

    for (int i = 0; i < N; ++i) {
        int ok = i, ng = N;
        while (ng - ok > 1) {
            int mid = (ok + ng) / 2;
            if (x[mid] - x[i] <= L) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        fore[0][i] = ok;

        ok = i, ng = -1;
        while (ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if (x[i] - x[mid] <= L) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        back[0][i] = ok;
    }

    for (int d = 1; d < 20; ++d) {
        for (int i = 0; i < N; ++i) {
            fore[d][i] = fore[d - 1][fore[d - 1][i]];
            back[d][i] = back[d - 1][back[d - 1][i]];
        }
    }

    for (int q = 0; q < Q; ++q) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        int ans = 0;
        if (a <= b) {
            while (a < b) {
                if (fore[0][a] >= b) {
                    ++ans;
                    a = fore[0][a];
                    continue;
                }
                for (int d = 19; d >= 0; --d) {
                    if (fore[d][a] >= b) continue;
                    ans += (1 << d);
                    a = fore[d][a];
                    break;
                }
            }
        } else {
            while (a > b) {
                if (back[0][a] <= b) {
                    ++ans;
                    a = back[0][a];
                    continue;
                }
                for (int d = 19; d >= 0; --d) {
                    if (back[d][a] <= b) continue;
                    ans += (1 << d);
                    a = back[d][a];
                    break;
                }
            }
        }

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


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

int main(void) {
	  
     ios :: sync_with_stdio(false);
     cin.tie(0);
	 char  str[19] , a[5] , b[7] , c[5];
	  
	 int i=0,j=0,k=0;
	 
	 cin >> str;
	 
	 for(i=0;i<5;i++)
	 {
	     cout << str[i];
	 }
	 cout <<" ";
	 
	 for(i=6;i<13;i++)
	 {
	     cout << str[i];
	 }
	 cout <<" ";
	 
	 for(i=14;i<19;i++)
	 {
	     cout << str[i];
	 }
	 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LLI;

string smh(int & x, int & y)
{
	int group1[]={1,3,5,7,8,10,12}, group2[] = {4,6,9,11};
	int len1 = sizeof group1/ sizeof group1[0];
	int len2 = sizeof group2/ sizeof group2[0];
	char cx = 'x', cy = 'y';
	for(int i = 0; i < len1; i++){
		if( x == group1[i] )
			cx = '1';
		if( y == group1[i] )
			cy = '1';
	}
	for(int i = 0; i < len2; i++){
		if( x == group2[i] )
			cx = '2';
		if( y == group2[i] )
			cy = '2';
	}
	if( cx == cy )
		return "Yes";
	return "No";
}

int main()
{
	int x, y;
	cin >> x >> y;
	if( x == y )
		cout << "Yes";
	else
		cout << smh(x,y);
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    string s;
    cin>>s;
    cout<<s.substr(0,3)<<endl;
    
return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++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 SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint n;
    cin >> n;

    deque<lint> a(n);
    lint posi = 0, nega = 0;
    rep(i, n){
        cin >> a[i];
        if(a[i] < 0LL){
            ++nega;
        }else if(a[i] > 0LL){
            ++posi;
        }
    }
    SORT(a);

    vector< LLP > ans;
    rep(i, n - 1){
        lint l = a.front(), r = a.back();
        a.pop_front();
        a.pop_back();
        if(l < 0LL){
            --nega;
        }else if(l > 0LL){
            --posi;
        }
        if(r < 0LL){
            --nega;
        }else if(r > 0LL){
            --posi;
        }
        if(posi > nega){
            a.push_front(l - r);
            ans.emplace_back(l, r);
            ++nega;
        }else{
            a.push_back(r - l);
            ans.emplace_back(r, l);
            ++posi;
        }
    }

    cout << a[0] << endl;
    rep(i, ans.size()){
        cout << ans[i].first << " " << ans[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 4468
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;

int main(void) {
    ll N;
    cin >> N;
    vector<string> s(N);
    vector<ll> t(N);
    for (int i = 0; i < N; i++) {
        cin >> s[i] >> t[i];
    }
    string X;
    cin >> X;

    ll sum = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] != X) continue;
        for (int j = i+1; j < N; j++) {
            sum += t[j];
        }
        break;
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

int main() {
    int D, G;
    cin >> D >> G;
    int p[10], c[10];
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    int ans = -1;
    for (unsigned int bit = 0; bit < (1 << D); bit++) {
        int num = 0;
        lli point = 0;
        for (int i = 0; i < D; i++) {
            if (bit & (1 << i)) {
                num += p[i];
                point += p[i] * (i+1) * 100 + c[i];
            }
        }

        if (point < G) {
            for (int i = D-1; i >= 0; i--) {
                if (bit & (1 << i)) continue;
                int pp = (i+1) * 100;
                int need = (G - point + pp - 1) / pp;
                if (need >= p[i]) break;
                num += need;
                point += need * pp;
                break;
            }
        }

        if (point >= G) {
            if (ans > num || ans == -1) ans = num;
        }
    }

    cout << ans << endl;
}


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

int main(){
	int n,ta,ans=0;
	map<int,int> a;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>ta;
		a[ta]++;
	}
	for(auto itr=a.begin();itr!=a.end();itr++)
		if((itr)->second%2)ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+6;
int x[55];
int y[55];
vector<int>v[55];
bool vis[55];
void dfs(int x){
	vis[x] = true;
	for(int y:v[x]){
		if(vis[y])continue;
		dfs(y);
	}
}
void solve(){
	int n,m; 
	cin>>n>>m; 
	int ans = 0;
	for(int i=1;i<=m;i++)cin>>x[i]>>y[i];
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			v[j].clear();
			vis[j] = false;
		}
		for(int j=1;j<=m;j++){
			if(i==j)continue;
			v[x[j]].pb(y[j]);
			v[y[j]].pb(x[j]);
		}
		dfs(1);
		int cnt = 0;
		for(int j=1;j<=n;j++){
			if(!vis[j]){
				cnt = 1;
			}
		}
		ans+=cnt;
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3648
from fractions import gcd

A, B, C, D = map(int, input().split())
A -= 1

a = A // C + A // D - A // ((C * D) // gcd(C, D))
b = B // C + B // D - B // ((C * D) // gcd(C, D))

print(B - A - (b - a))


Measured memory_bytes: 5048
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//        int n = Integer.parseInt(sc.next());
        String n = sc.next();
        if ("0".equals(n)) {
            System.out.println("Yes");
            return;
        }
        long num = 0;
        for (int i = 0; i < n.length(); i++) {
            num += Character.getNumericValue(n.charAt(i));
        }
        if (num % 9 == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 40204
import numpy as np
from numba import njit

@njit
def solve(stdin):
    n, k = stdin[:2]
    A = stdin[2: 2 + n]
    A = np.sort(A)[::-1]
    F = np.sort(stdin[2 + n:])

    def is_ok(x):
        tmp = 0
        for a, f in zip(A, F):
            y = a * f
            if y > x:
                tmp += a - x // f
        return tmp <= k

    ok = 10 ** 16
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid

    return ok

print(solve(np.fromstring(open(0).read(), dtype=np.int64, sep=' ')))

Measured memory_bytes: 129968
N,M=map(int,input().split())
H=list(map(int,input().split()))
n=[0]*N
for i in range(M):
    A,B=map(int,input().split())
    if(H[A-1]<H[B-1]):
        n[A-1]+=1
    elif(H[A-1]>H[B-1]):
        n[B-1]+=1
    else:
        n[A-1]+=1
        n[B-1]+=1
print(n.count(0))

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;


void solve(long long X){
	long double a = 100;
	ll b;
	FOR(i,1,10000) {
		a *= 1.01;
		a = ll(a);
		if (a >= X ) {
			cout << i << endl;
			return;
		}	
	}
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}



Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N, M;
    cin >> N >> M;
    if(M < 2*N) cout << M/2 << endl;
    else cout << N + (M-2*N)/4 << endl;
}

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

int main() {
  string s;
  cin >> s;
  string ans;
  ans = "Yes";
  for(int i = 0; i < s.size(); ++i) {
    if (i % 2 != 0){
      if (s[i] == 'R') {
        ans = "No";
        break;
      } 
    } 
    else {
      if(s[i] == 'L') {
        ans = "No";
        break;
      } 
    } 
  } 
  cout << ans << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE

template<typename T,bool directed>
struct Fordfulkerson{
  struct edge{
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };

  vector<vector<edge> > G;
  vector<int> used;

  Fordfulkerson(){}
  Fordfulkerson(int n):G(n),used(n){}

  void add_edge(int from,int to,T cap){
    G[from].emplace_back(to,cap,G[to].size());
    G[to].emplace_back(from,directed?0:cap,G[from].size()-1);
  }

  T dfs(int v,int t,T f){
    if(v==t) return f;
    used[v]=true;
    for(int i=0;i<(int)G[v].size();i++){
      edge &e = G[v][i];
      if(!used[e.to]&&e.cap>0){
        T d=dfs(e.to,t,min(f,e.cap));
        if(d>0){
          e.cap-=d;
          G[e.to][e.rev].cap+=d;
          return d;
        }
      }
    }
    return 0;
  }

  int flow(int s,int t,T lim){
    T fl=0;
    while(1){
      fill(used.begin(),used.end(),0);
      T f=dfs(s,t,lim);
      if(f==0) break;
      fl+=f;
      lim-=f;
    }
    return fl;
  }

  int flow(int s,int t){
    return flow(s,t,numeric_limits<T>::max()/2);
  }

};
//END CUT HERE

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

  int V,E;
  cin>>V>>E;
  Fordfulkerson<int, true> G(V);
  for(int i=0;i<E;i++){
    int u,v,c;
    cin>>u>>v>>c;
    G.add_edge(u,v,c);
  }
  cout<<G.flow(0,V-1)<<endl;
  return 0;
}

/*
  verified on 2019/06/10
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A&lang=jp
*/



Measured memory_bytes: 3268
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>

using namespace std;

int top = 0;
int arr[200];

void push(int x){
  top++;
  arr[top] = x;
}

int pop(){
  top--;
  return arr[top + 1];
}

int main(){
  char x[10];
  int a, b;

  while(scanf("%s", x) != EOF){
    if(x[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }else if(x[0] == '-'){
      a = pop();
      b = pop();
      push(b - a);
    }else if(x[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }else{
      push(atoi(x));
    }
  }

  cout << pop() << endl;

  return 0;
}


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

using namespace std; 

#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define SZ(x) (int)x.size()

typedef  vector<string> vs;
typedef  vector<int> vi;	

int main(){
	
	int n;
	
	cin >> n;
	
	double x; 
	
	string y;
	
	double ans = 0.0;
	
	f(i,0,n){
		cin >> x >> y;
		
		if(y=="JPY"){
			ans+=x;
		}else{
			ans+=x * 380000.0;
		}
	}
	
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
f = 0
for i in range(1,n+1):
    if i%2:
        f += 1

print(f/n) 

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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define sort(vec) std::sort(all(vec))
#define rev(vec) std::reverse(all(vec))
#define cout std::cout

template<typename T>
using vec = std::vector<T>;

void input(){return;}
template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}

void inputVec(){return;}
template<typename First,typename... Rest> void inputVec(vec<First> &first,Rest&... rest){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i];
    }
    inputVec(rest...);
}

template<typename First,typename Second> void inputTwoVec(vec<First> &first,vec<Second>& second){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i] >> second[i];
    }
}

void calculate(){
    int n,k;
    input(n,k);
    vec<int> l(n);
    inputVec(l);
    sort(l);
    rev(l);
    int res = 0;
    rep(i,k){
        res += l[i];
    }
    cout << res << '\n';
}

int main(int,char**){
    calculate();    
}




Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string s;
	scan(s);
	if((s[0]==s[s.size()-1])^(s.size()%2)) prin("First");
	else prin("Second");
	return 0;
}


Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);
		int N = sc.nextInt();
		int[] a = nextIntArray(sc, N);
		sc.close();

		int c4 = 0, c2 = 0, other = 0;
		for (int x : a) {
			if (x % 4 == 0) {
				c4++;
			} else if (x % 2 == 0) {
				c2++;
			} else {
				other++;
			}
		}

		c2 %= 2;

		other += c2;

		if (other-1 <= c4) {
			out.println("Yes");
		} else {
			out.println("No");
		}

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 50656
#include<cstdio>
#include<algorithm>
int a[51];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	std::sort(a+1,a+1+n,cmp);
	int sum=0;
	for(int i=1;i<=k;i++){
		sum+=a[i];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	int f=0,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
#define MAXN 400000
#define INF 0x3f3f3f3f
char S[MAXN+5];
int main(){
	scanf("%s",S+1);
	int n=strlen(S+1);
	for(int i=1;i<=n;i++){
		if((i%2==1)&&!(S[i]=='R'||S[i]=='U'||S[i]=='D'))
			puts("No"),exit(0);
		else if((i%2==0)&&!(S[i]=='L'||S[i]=='U'||S[i]=='D'))
			puts("No"),exit(0);
	}
	puts("Yes");
	return 0;
}

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

using namespace std;

void dfs(int);
#define N 100
int t = 0;
int s[N], f[N], color[N];
int a[N][N];

int main(int argc, char const *argv[]) {
  int n;  cin >> n;
  for (int i = 0; i < n; ++i) {
    int u, k;  cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      int v;  cin >> v;
      a[u - 1][v - 1] = 1;
    }
  }
  for (int i = 0; i < n; ++i) {
    color[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    if (color[i] == 1) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << i + 1 << " " << s[i] << " " << f[i] << '\n';
  }

  return 0;
}

void dfs(int x) {
  color[x] = 2;
  s[x] = ++t;
  for (int i = 0; i < N; ++i) {
    if (a[x][i] == 0) {
      continue;
    }
    if (color[i] == 1) {
      dfs(i);
    }
  }
  color[x] = 3;
  f[x] = ++t;
}



Measured memory_bytes: 3132
#include<stdio.h>
void intstr(int n,char* s){
  int i,j=0;
  for(i=n;i  ;i/=10)s[++j]=0;
  for(i=n;j--;i/=10)s[j]=i%10+'0';
}
int f(int a){
  char s[10];
  int l=0,i;
  intstr(a,s);//printf("%s ",s);
  while(s[l++]);//printf("%d\n",l);
  for(i=0;2*i<l;i++){
    if(s[i]-s[l-i-2])return 1;
  }
  printf("%d\n",a);
  return 0;
}  
int main(){
  int i,n;
  scanf("%d",&n);
  for(i=0;f(n-i)&&f(n+i);i++);
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;


int main() {
    char ch;

    while(1) {
        scanf("%c", &ch);
        if (isalpha(ch)) {
            if (isupper(ch)) printf("%c", tolower(ch));
            else printf("%c", toupper(ch));
        }else printf("%c", tolower(ch));
        
        if (ch == '\n') break;
    }
    
    return 0;
}


Measured memory_bytes: 3132
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        public static void Main()
        {
          var input = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
          var bCount = Math.Ceiling(input[0] / (double)input[3]);
          var aCount = Math.Ceiling(input[2] / (double)input[1]);
          Console.WriteLine(aCount <= bCount ? "Yes" : "No");
        }
    }
}



Measured memory_bytes: 19104
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
 
ll power(ll a,ll b)
{
    if(a==0)
        return 0;
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
 
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solutions

int32_t main()
{
    IOS

    
    int n,p;
    cin>>n>>p;

    string s;

    cin>>s;
    int po[n+1];
    po[0]=1;
    mod=p;
    for(int i=1;i<=n;i++)
    {
        po[i]=po[i-1]*10;
        po[i]%=p;
    }

    
    int num=0;
    
    int ans=0;
    if(p==2 or p==5)
    {
        for(int i=0;i<s.length();i++)
        {
            if((s[i]-'0')%p==0)
                ans+=i+1;
        }
        cout<<ans;
        return 0;
    }
    map<int,int> m;
    m[0]++;
    for(int i=0;i<s.length();++i)
    {
        num=num*10+s[i]-'0';
        num%=p;
        int te=num*power(po[i],mod-2);
        te%=p;
        ans+=m[te];
        m[te]++;   
    }
    cout<<ans;
}       


Measured memory_bytes: 2580
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
vector<ll> data(100000000);
ll count(ll num){
    if(num==1) return 1;
    if(num<100000000){
        if(data[num]!=0){
        return data[num];
    }
    return data[num]=count(num/2)+count(num/2)+1;
    }else{
        return count(num/2)+count(num/2)+1;
    }
    
    
}

int main(){
    ll h;
    cin >> h;
    ll ans;
    ans = count(h);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 781568
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if (b<=c || d<=a)
        cout<<"0\n";
    else
        cout<<min(b,d)-max(a,c)<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
char str[21],c;
int i,length;
scanf("%s",str);
length=strlen(str);
if(length%2==0){
for(i=0;i<length/2;i++){
c=str[i];
str[i]=str[length-i-1];
str[length-i-1]=c;
}
}else{
for(i=0;i<(int)length/2;i++){
c=str[i];
str[i]=str[length-i-1];
str[length-i-1]=c;
}
}
printf("%s\n",str);
return 0;
}

Measured memory_bytes: 524
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int ans = 0;
    for (int i = 2; i <= 9; i++) {
      for (int j = 0; j <= 31; j++) {
        if (X >= (int) Math.pow(j, i)) {
          ans = Math.max(ans, (int) Math.pow(j, i));
        }
      }  
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
from sys import stdin
import numpy as np

lines = stdin.readlines()

n = int(lines[0].rstrip().split()[0])
a_s = [int(x) for x in lines[1].rstrip().split()]

a_size = len(a_s)
res = np.zeros((a_size))

for i in range(a_size):
    res[a_s[i]-1] += 1

for j in range(n-1):
    print(int(res[j]))
print(0)


Measured memory_bytes: 50136
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 10000000000007LL
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>
std::istream& operator>>(std::istream& in,pair<T1,T2> &a)
{
	in>>a.fr>>a.sc;
	return in;
}
template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a)
{
	out<<a.fr<<" "<<a.sc;
	return out;
}

int a[105];
int b[105];

int dp[105][100005];

void solve(){
	int n,w;
	cin>>n>>w;
	rep(i,0,n){
		cin>>a[i]>>b[i];
	}
	rep(i,0,100001){
		dp[0][i]=M;
	}
	dp[0][0]=0;
	dp[0][b[0]]=a[0];
	rep(i,1,n){
		rep(j,0,100001){
			dp[i][j]=dp[i-1][j];
		} 
		rep(j,b[i],100001){
			dp[i][j]=min(dp[i][j],a[i]+dp[i-1][j-b[i]]);
		}
	}
	int ans=0;
	rep(i,0,100001){
		// cout<<dp[n-1][i]<<" "
		if(dp[n-1][i]<=w)ans=i;
	}
	cout<<ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
struct point{
	int a,b;
	point *l,*r,*pa;
	point(){l=r=pa=NULL;}
	point(int aa,int bb):a(aa),b(bb){l=r=pa=NULL;};
};
point *root;
point *rightRotate(point *t){
	point *s=t->l;
	t->l=s->r;
	s->r=t;
	return s;
}
point *leftRotate(point *t){
	point *s=t->r;
	t->r=s->l;
	s->l=t;
	return s;
}
point* insert(point *p,int a,int b){
	if(p==NULL)return new point(a,b);
	if(a==p->a)return p;
	if(a<p->a){
		p->l=insert(p->l,a,b);
		if(p->b<p->l->b)
			p=rightRotate(p);
	}else{
		p->r=insert(p->r,a,b);
		if(p->b<p->r->b)
			p=leftRotate(p);
	}return p;
}
point *_del(point *p, int a);
point *del(point *p,int a){
	if(p==NULL)return NULL;
	if(a<p->a)p->l=del(p->l,a);
	else if(a>p->a)p->r=del(p->r,a);
	else return _del(p,a);
	return p;
}
point *_del(point *p, int a){
	if(p->l==NULL&&p->r==NULL)return NULL;
	else if(p->l==NULL)p=leftRotate(p);
	else if(p->r==NULL)p=rightRotate(p);
	else{
		if(p->l->b>p->r->b)p=rightRotate(p);
		else p=leftRotate(p);
	}return del(p,a);
}
bool find(int a){
	point *p=root;
	while(p){
		if(a==p->a)return 1;
		if(a>p->a)p=p->r;
		else p=p->l;
	}
	return 0;
}
void dfs1(point *p){
	if(!p)return;
	dfs1(p->l);
	printf(" %d",p->a);
	dfs1(p->r);
}
void dfs2(point *p){
	if(!p)return;
	printf(" %d",p->a);
	dfs2(p->l);
	dfs2(p->r);
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	int ta,tb;
	string s;
	while(cin>>s){
		if(s=="insert"){
			cin>>ta>>tb;
//			if(!root)root=new point(ta,tb);
//			else 
			root=insert(root,ta,tb);
		}else if(s=="find"){
			cin>>ta;
			if(find(ta))printf("yes\n");
			else printf("no\n");
		}else if(s=="print"){
			dfs1(root);
			printf("\n");
			dfs2(root);
			printf("\n");
		}else if(s=="delete"){
			cin>>ta;
			root=del(root,ta);
		}
	}
	return 0;
}


Measured memory_bytes: 12644
#include<queue>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

VI ME(const VI &a, const VI &b) {
    VI ret; ret.reserve(a.size() + b.size());
    int i = 0, j = 0;
    while (i < (int)a.size() && j < (int)b.size()) {
	if (a[i] < b[j]) ret.push_back(b[j++]);
	else ret.push_back(a[i++]);
    }
    ret.insert(ret.end(), a.begin()+i, a.end());
    ret.insert(ret.end(), b.begin()+j, b.end());
    return ret;
}

int N;
int A[2011];
VI G[2011];
bool use[2011];

VI F[2011];
VI R[200011];
VI P;

int D[200011], cnt;
VI rec(int s, int last) {
    if (A[s] == 1) {
	use[s] = true;
	return { 1 };
    }

    VI vs;
    cnt++;
    vs.push_back(s);
    for (int i=0; i<(int)vs.size(); i++) {
	int v = vs[i];
	EACH (e, F[v]) if (D[*e] != cnt) {
	    D[*e] = cnt;
	    EACH (f, R[*e]) if (!use[*f]) {
		vs.push_back(*f);
	    }
	}
    }

    int pick = -1;
    EACH (e, vs) if (__gcd(last, A[*e]) > 1) {
	if (pick == -1 || A[pick] > A[*e]) {
	    pick = *e;
	}
    }

    // pick;
    use[pick] = true;
    VI cur;
    EACH (e, G[pick]) if (!use[*e]) {
	VI tmp = rec(*e, A[pick]);
	cur = ME(cur, tmp);
    }
    
    cur.insert(cur.begin(), A[pick]);
    return cur;
}


void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    REP (i, N) {
	int m = A[i];
	for (int j=2; j*j<=m; j++) {
	    if (m % j == 0) {
		P.push_back(j);
		F[i].push_back(j);
		while (m % j == 0) m /= j;
	    }
	}
	if (m > 1) {
	    P.push_back(m);
	    F[i].push_back(m);
	}
    }

    sort(P.begin(), P.end());
    P.erase(unique(P.begin(), P.end()), P.end());
    REP (i, N) {
	EACH (e, F[i]) {
	    *e = lower_bound(P.begin(), P.end(), *e) - P.begin();
	    R[*e].push_back(i);
	}
    }

    REP (i, N) REP (j, N) if (i != j) {
	if (__gcd(A[i], A[j]) > 1) {
	    G[i].push_back(j);
	}
    }

    VI ans;

    REP (i, N) if (!use[i]) {
	VI tmp = rec(i, 0);
	ans = ME(ans, tmp);
    }
    rprintf("%d", ans.begin(), ans.end());
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 65152
import sys

x = int(sys.stdin.readline().rstrip())

def main():
    q, r = divmod(x, 11)
    if r == 0:
        return 2 * q
    elif r <= 6:
        return 2 * q + 1
    else:
        return 2 * (q + 1)

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main(){
  int n;
  cin >> n;
  double x,ans=0;
  string s;
  for(int i=0;i<n;i++){
    cin >> x >> s;
    if(s=="JPY")
      ans+=x;
    else
      ans+=x*380000;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3772
#include <iostream>

 

using namespace std;

 

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   s = i % 60;
   m = i / 60 - h*60;
   cout << h << ":" << m << ":" << s <<endl; 
   
   return 0;
}


Measured memory_bytes: 3088
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const int OO = (int)1e8;
const int dx[] = { 0, 1, -1, 0 };
const int dy[] = { 1, 0, 0, -1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }

//#pragma warning (disable : 4996)
void in_out_txt()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}
ll power(ll base, ll num)
{
	ll sum = 1;
	for (int i = 0; i < num / 2; i++)
		sum *= base;
	if (num % 2 == 0)
		return sum * sum;
	return sum * sum * base;
}
ll convertToDecimal(string str)
{
	ll sum = 0;
	int j = 0;
	for (int i = str.size() - 1; i >= 0; i--)
	{
		if (str[i] == '1')
			sum += power(2, j);
		j++;
	}
	return sum;
}
void convertToBinary(ll num)
{
	string str = "";
	while (num)
	{
		if (num % 2)
			str += '1';
		else
			str += '0';
		num /= 2;
	}
	reverse(all(str));
	cout << str << endl;
}
int main()
{
	IO;
	//in_out_txt();
	string str, st;
	cin >> str;
	for (int i = 0; i <= 9; i++)
	{
		st.resize(3, i + '0');
		if (str.find(st) != -1)
		{
			cout << "Yes" << endl;
			return 0;
		}
		st = "";
	}
	cout << "No" << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
N =int(input())
T,A= map(int,input().split())
H = [int(i) for i in input().split()]
m = 10 **10
ans = 0
for idx,h in enumerate(H):
    tmp = T - (0.006 * h)
    diff = abs(A -tmp)
    if diff < m:
        m=diff
        ans = idx+1
print(ans)

Measured memory_bytes: 3064
N = int(input())
p = list(map(int, input().split()))

a = range(1, N+1)

cnt = 0
for i in range(N):
  if a[i]!=p[i]:
    cnt += 1

if (cnt==2)or (cnt==0):
  print("YES")  
else:
  print("NO")  

Measured memory_bytes: 3060
s = input()
result = [0 for i in range(len(s))]

# 自位置がRで、右隣がLのセットについて
# Rがどれだけ続くか、Lがどれだけ続くか数える
rl = []
rs, ls = 0, 0
cycle = 'R'

for i in range(len(s)):
  ss = s[i]
  
  if cycle == 'R':
    if ss == 'R':
      rs += 1
    else:
      cycle = 'L'
      ls += 1
      position = i - 1
 
    continue
      
  if cycle == 'L':
    if ss == 'R':
      cycle = 'R'
      rl.append([position, rs, ls])
      rs, ls = 1, 0
    else:
      ls += 1

rl.append([position, rs, ls])

for i in range(len(rl)):
  q1, mod1 = divmod(rl[i][1], 2)
  q2, mod2 = divmod(rl[i][2], 2)
  
  result[rl[i][0]] = q1 + mod1 + q2
  result[rl[i][0]+1] = q1 + q2 + mod2

for i in result:
  print(i)


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, m; std::cin >> n >> m;
  map<int, int> conv;
  bool ok = true;
  rep(i, m) {
    int s, c; std::cin >> s >> c; s--;
    if (conv.count(s) && conv[s] != c) ok = false;
    conv[s] = c;
  }
  int ans = 0;
  rep(i, n) {
    if (conv.count(i)) ans = ans * 10 + conv[i];
    else if (i == 0 && n == 1) ans = 0;
    else if (i == 0) ans = 1;
    else ans *= 10;
  }
  if (n != 1 && conv.count(0) && conv[0] == 0) ok = false;
  if (!ok) ans = -1;
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >>y2;
    
    cout << fixed << setprecision(8);
    cout << sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) << endl;
    
    return 0;
}



Measured memory_bytes: 3292
#include <iostream>
#include <queue>
#include <vector>
 
#define mp(a,b) make_pair(a, b)
 
using namespace std;
 
typedef pair<int, int> xy;
 
int main() {
 
    const int SIZE = 200;
    const int OFFSET = 100;
    const int   mx[] = {0, 1, 1, 0, -1, -1},
                my[] = {1, 1, 0, -1, -1, 0};
 
    int t, n;
 
    while(cin >> t >> n,t||n) {
        vector< vector<bool> > f(SIZE, vector<bool>(SIZE, true));
        queue< pair< pair<int, int>, int> > open;
 
        while (n--) {
            int x, y;
            cin >>x >>y;
 
            f[y+OFFSET][x+OFFSET] = false;
        }
 
        int x, y, cnt = 0;
        cin >>x >>y;
        x += OFFSET; y += OFFSET;
        f[y][x] = false;
        open.push(mp(mp(x, y), 0) );
 
        while(!open.empty()) {
            pair<xy, int> tmp = open.front(); open.pop();
            xy tmp2 = tmp.first;
            int x = tmp2.first,
                y = tmp2.second,
                c = tmp.second;
 
            cnt++;
            if (c >= t) continue;
 
            for( int i = 0; i < 6; i++) {
                int nx = x + mx[i],
                    ny = y + my[i];
 
                if ( f[ny][nx] != true ) continue;
 
                f[ny][nx] = false;
                open.push( mp(mp(nx,ny), c+1));
            }
        }
        cout <<cnt <<endl;
    }
 
    return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

const int MAX = 1000010;
// const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N,K;cin>>N>>K;
    vector<ll> a(N,0);
    rep(i,N) cin>>a[i];
    sort(a.begin(),a.end());

    COMinit();

    ll ans = 0;
    rep(i,N-K+1) {
        ans = (ans + (COM(N-i-1,K-1)*a[N-i-1])%MOD) %MOD;
        ans = (ans + MOD - (COM(N-i-1,K-1)*a[i])%MOD) %MOD;
    }
    cout<<(ans+MOD)%MOD<<endl;
}

Measured memory_bytes: 27536
import sys
import itertools
import math

input = sys.stdin.readline

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

l = [i for i in range(1, N+1)]

p_list = list(itertools.permutations(l, N))

for i in range(N):
    p_list.sort(key = lambda x: x[N - i - 1])

a = p_list.index(P)
b = p_list.index(Q)

print(abs(a - b))

Measured memory_bytes: 8472
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] % 2 == 0)
        {
            if (a[i] % 3 == 0 || a[i] % 5 == 0)
            {
            }
            else
            {
                cout << "DENIED" << endl;
                exit(0);
            }
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : Dharmveer Jakhar *
* Handle : dvjakhar *
* INSTITUTION : IIT (BHU) Varanasi *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
#define lb(arr,n,x) lower_bound(arr,arr+n,x)-arr
#define ub(arr,n,x) upper_bound(arr,arr+n,x)-arr
#define endl "\n"
#define PI 3.14159265358979323846  /* pi */
#define sqr(x) (x)*(x)
#define all(v)  ((v).begin()),((v).end())
#define degreesToRadians(angleDegrees) (angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / PI) // Converts radians to degrees.

typedef long long ll;
typedef long double ld;
//Calculation of (x^y)%mm
ll mod_exp(ll x,ll y,ll mm)
{
    if(y==0)
        return(1);
    else if(y%2==0)
        return(mod_exp((x*x)%mm,y/2,mm));
    else
        return((x*mod_exp((x*x)%mm,(y-1)/2,mm))%mm);
}


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


int n;
cin>>n;
std::vector<int> v;
rep(i,n)
{
	int x;
	cin>>x;
	v.pb(x);
}
std::map<int, ll> map;
for(auto x:v)
	map[x]++;
ll ans=0;
	for(auto y:map)
	{
		ans+=(y.S)*((y.S)-1)/2;
	}
for(int i=0;i<n;i++)
{
		cout<<ans-(map[v[i]]-1)<<endl;

}

return 0;
}

Measured memory_bytes: 10356
#include <iostream>
#define N_MAX 100000
#define K_MAX 100000
#define W_MAX 10000
using namespace std;
int average(int *W, int n, int k) {
    int sum = 0;
    for (int i=0; i<n; i++) sum += W[i];
    return sum / k;
}
bool chkLoadable(int *W, int n, int k, int lim) {
    int truck[K_MAX] = {0};
    int wp = 0;
    for (int i=0; i<k; i++) {
        while ( truck[i] + W[wp] <= lim ) {
            truck[i] += W[wp];
            wp++;
        }
    }
    if (wp <= n-1) return false;
    return true;
}
int solve(int *W, int n, int k) {
    int ave = average(W, n, k);
    for (int i = ave; i < N_MAX * W_MAX; i++) {
        if ( chkLoadable(W, n, k, i) ) return i;
    }
    return -1;
}
int main() {
    int n, k;
    cin >> n >> k;
    int W[N_MAX];
    for (int i=0; i<n; i++) cin >> W[i];
    cout << solve(W, n, k) << endl;
}


Measured memory_bytes: 3864
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列
#define CO(a, b, c) ((a) ? (b) : (c))
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;

int main(void)
{

    string t;
    cin >> t;

    string res = "";
    for (auto &&i : t)
    {
        if (i == '?')
            res.push_back('D');
        else
            res.push_back(i);
    }

    cout << res;

    return 0;
}

Measured memory_bytes: 3916
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		String S=stdIn.next();
		char b=' ',c=' ';
		int z=0,y=0,x=0;
		while(z<4){
			char a=S.charAt(z);
			if(b==' ')
				b=a;
			else
				if(a!=b&&c==' ')
					c=a;
			if(a==b)
				y++;
			if(a==c)
				x++;
			z++;
		}
		if(y==2&&x==2)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 21844
// https://atcoder.jp/contests/abc117/tasks/abc117_a

#include <algorithm>
#include <iomanip> //浮動小数点
#include <iostream>
#include <string>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int t, x;
    cin >> t >> x;

    cout << std::setprecision(10) << (double)t / x << endl;
    return 0;
}


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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int n,k;
    cin>>n>>k;
    vector<int>v(n+1);
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    vector<int>x;
    x.push_back(1);
    int t=1;
    if(k<(n-1)){
        for(int i=1;i<=k;i++){
        x.push_back(v[t]);
        t=v[t];
        }
        cout<<x[k]<<endl;
        return 0;
    }
    x.clear();
    x.push_back(1);
    t=1;
    int elem=0;
    vector<int>r;
     for(int i=1;i<n;i++){
        if(i==(n-1)){elem=v[t];}
        x.push_back(v[t]);
        t=v[t];
    }


    int f=0;bool ok=false;
    for(int i=0;i<(int)x.size();i++){
        if(x[i]==elem){
            ++f;
            ok=true;
            if(f<2)r.push_back(elem);
            else break;
        }
        else if(ok)r.push_back(x[i]);
    }
    int sz=r.size();
    int sz1=k%(n);
    cout<<r[(k-n+1)%sz]<<endl;
}


Measured memory_bytes: 8348
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int amari = (X - A) % B;
		System.out.println(amari);
	}
}


Measured memory_bytes: 21716