akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < n; ++i)
#define X first
#define Y second
#define MP(x,y) make_pair(x,y)
using namespace std;

int main(void){
  int n, d, w;
  while(cin >> n >> d >> w, n+d+w){
    queue<pair<int,int>> q;
    q.push(MP(d,w));
    rep(k,n){
      int p, s;
      cin >> p >> s;
      p--;
//      cout << "dbg " << endl;
      pair<int, int> t;
      rep(i,k+1){
        if(i == p){
          t = q.front();
//          cout <<"!" <<  q.front().X << " , " << q.front().Y << endl;
          q.pop();
        }else{
          q.push(q.front());
//          cout << q.front().X << " , " << q.front().Y << endl;
          q.pop();
        }
      }

      s %= (t.X + t.Y + t.X + t.Y);
      if(s-(t.X + t.Y) > 0){
        s-=(t.X + t.Y);
      }
      if( s <= t.X){
        if(t.X-s > s){
          q.push(MP(s,t.Y));
          q.push(MP(t.X-s, t.Y));
        }else{
          q.push(MP(t.X-s, t.Y));
          q.push(MP(s,t.Y));
        }

      }else if( s <= t.X + t.Y){
        s-=t.X;
        if(t.Y-s > s){
          q.push(MP(t.X, s));
          q.push(MP(t.X, t.Y-s));
        }else{
          q.push(MP(t.X, t.Y-s));
          q.push(MP(t.X, s));
        }
      }
    }
    vector<int> ans;
    while(!q.empty()){
      ans.push_back(q.front().X * q.front().Y);
      q.pop();
    }
    sort(ans.begin(), ans.end());
    rep(i,ans.size()){
      if(i != 0){
      cout << " ";
      }
      cout << ans[i];
    }
  cout << endl;
  }
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
ll ans = 0;
//親の頂点p,今見てるのはv
void dfs(vector<vector<ll>>& graph,ll v,vector<bool>& visited){
  visited[v] = true;
  for (auto next : graph[v]) {
    if (visited[next]) continue;
    dfs(graph, next, visited);
  }
}
void solve(){
    ll n,m;
    cin >> n >> m;
    vector<ll> x(m), y(m);
    for (ll i = 0; i < m;i++){
      cin >> x[i] >> y[i];
      x[i]--;
      y[i]--;
    }
    for (ll i = 0; i < m;i++){
        vector<vector<ll>> adj(n);
        for (ll j = 0; j < m; j++) {
          if (i == j) continue;
          adj[x[j]].push_back(y[j]);
          adj[y[j]].push_back(x[j]);
        }
    vector<bool> visited(n, false);
    dfs(adj, 0, visited);
    bool flag = false;
    
    for (ll i = 0; i < n; i++) {
      if (!visited[i]) flag = true;
    }
    if (flag) ans++;
    }

    cout << ans << endl;
}

int main() {
solve();

}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
  long long  int N = 0;
   int t = 1;
   cin >> N;
   for(long long int i = 1;i <= sqrt(N);i++){
       if(N % i == 0)
       t = i;
   }
   
    std::cout << (t - 2 + N / t) << std::endl;
}


Measured memory_bytes: 384
def init()
	$t = Array.new(17).map{Array.new(17, 0)}
	$t[1][1] = 1
	$vert = Array.new(17).map{Array.new(17, true)}
	$horiz = Array.new(17).map{Array.new(17, true)}
end

def input_matatabi()
	a = gets.chomp.split(" ").map{|str| str.to_i}
	if a[0] == a[2]
		$vert[a[0] + 1][[a[1], a[3]].min + 1] = false
	else
		$horiz[[a[0], a[2]].min + 1][a[1] + 1] = false
	end
end

def calc_t(x, y)
	for i in 1..x
		for j in 1..y
			if $vert[i][j - 1]
				$t[i][j] += $t[i][j - 1]
			end
			if $horiz[i - 1][j]
				$t[i][j] += $t[i - 1][j]
			end
		end
	end
end

n = gets.chomp.to_i

n.times do
	init()

	gx, gy = gets.chomp.split(" ").map{|str| str.to_i}
	num_matatabi = gets.chomp.to_i

	num_matatabi.times do
		input_matatabi
	end

	calc_t(gx + 1, gy + 1)

	if ($t[gx + 1][gy + 1] == 0)
		puts "Miserable Hokusai!"
	else
		puts $t[gx + 1][gy + 1]
	end
end

Measured memory_bytes: 8912
#include <stdio.h>

int main(void){

    int p, q, r;
    scanf("%d %d %d", &p, &q, &r);

    int min = p+q;
    if(min>(q+r)) min=q+r;
    if(min>(r+p)) min=r+p;
    
    printf("%d", min);

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.lang.Math;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int S=0;
        int W=0;
        int x;
        int res;
        
        for(int i=0; i<N; i++){
            x = Integer.parseInt(sc.next());
            S = S+x;
            W = W + (int) Math.pow(x,2);
        }

        int p = Math.round((float) S/N);
       
        res = N*((int) Math.pow(p,2))-2*p*S+W;
        System.out.println(res);   

        
    }
}


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

typedef long long ll;

using namespace std;

const int MAXN = 2e5 + 10;
int n, a[MAXN], B[MAXN];

ll abs(ll x){
  return (x < 0 ? -1LL*x : 1LL*x);
}

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

  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]), B[i] = a[i] - i;

  sort(B + 1, B + n + 1);

  ll ans = 0;
  int b = (n % 2 ? B[n/2+1] : (B[n/2]+B[n/2+1])/2);
  for(int i = 1; i <= n; i++)
    ans += abs(a[i] - (b+i));
  
  printf("%lld\n", ans);
}

Measured memory_bytes: 1792
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
Edges=[[] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    a-=1; b-=1
    Edges[a].append(b)
    Edges[b].append(a)
Colors=[0]*n

def dfs(v,color):
    Colors[v]=color
    for to in Edges[v]:
        if Colors[to]==color:
            return False
        if Colors[to]==0 and not dfs(to,-color):
            return False
    return True

def isbipartite():
    return dfs(0,1)

if isbipartite():
    black=(sum(Colors)+n)//2
    white=n-black
    print(black*white-m)
else:
    print(n*(n-1)//2-m)

Measured memory_bytes: 209500
l, r = map(int, input().split())
r = l + 2019 if r - l >= 2019 else r
ans = 2018
for i in range(l, r):
    for j in range(i + 1, r + 1):
        tmp = (i * j) % 2019
        ans = min(tmp, ans)
print(ans)

Measured memory_bytes: 3060
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXY 128
#define MAXX 128
typedef long long ll;
const int dx[] = {1, 1, 0, -1, -1, 0};
const int dy[] = {0, 1, 1, 0, -1, -1};

//bool done[MAXY][MAXX];
int d[MAXY][MAXX];

int main(void) {
    int t, n;
    while (1) {
        cin >> t >> n;
        if (t == 0 && n == 0) break;
        for (int i = 0; i < MAXY; i++) {
            for (int j = 0; j < MAXX; j++) {
                //done[i][j] = false;
                d[i][j] = -1;
            }
        }
        for (int i = 0; i < n; i++) {
            int x, y;
            cin >> x >> y;
            d[y+64][x+64] = -2;
        }
        int sx, sy;
        cin >> sx >> sy;
        sx += 64; sy += 64;
        queue<int> X;
        queue<int> Y;
        X.push(sx); Y.push(sy);
        d[sy][sx] = 0;
        while (!X.empty()) {
            int x = X.front(); X.pop();
            int y = Y.front(); Y.pop();
            if (d[y][x] >= t) continue;
            for (int i = 0; i < 6; i++) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (d[ny][nx] == -1) {
                    d[ny][nx] = d[y][x] + 1;
                    X.push(nx); Y.push(ny);
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < MAXY; i++) {
            for (int j = 0; j < MAXX; j++) {
                if (d[i][j] >= 0) ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

	int n;
	cin >> n;

	int ap[n]['z'-'a'+1] = {0};
	REP(i,n)
	{
		string t; cin >> t;
		REP(j, len(t))
		{
			// dbg(t[j]-'a');
			ap[i][t[j]-'a']++;
		}
	}

	
	REP(i,'z'-'a'+1)
	{
		int m = INF;
		REP(j, n)
		{
			if(ap[j][i] > 0)
			{
				m = min(m, ap[j][i]);
			}
			else
			{
				m = INF;
				break;
			}
		}
		if (m != INF)
		{
			REP(k,m)
			{
				cout << (char)((int)'a' + i);
			}
		}
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
def DrawRectangle(lst):
    drawn=["a"]*lst[0]
    tmp=""
    for i in range(lst[0]):
        for j in range(lst[1]):
            if (i+j)%2==0:
                tmp+="#"
            else:
                tmp+="."
            if j==(lst[1]-1):
                drawn[i]=tmp
                tmp=""
    for i in drawn:
        print(i)
    print("")

a=[]
while True:
    a.append(list(map(int,input().split(" "))))
    if a[-1]==[0,0]:
        a=a[:-1]
        break
    
for i in a:
    DrawRectangle(i)


Measured memory_bytes: 5628
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph=vector<vector<int>>;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main(){
    ll a,b,c,k;cin>>a>>b>>c>>k;
    if(a>=k) cout<<k<<endl;
    else if(a+b>=k) cout<<a<<endl;
    else cout<<a-(k-a-b)<<endl;
}

Measured memory_bytes: 3624
n = int(input())

n_str=str(n)

set1 = set(['2', '4', '5', '7', '9'])

if n_str[len(n_str)-1] == '3':
    print('bon')
elif n_str[len(n_str)-1] in set1:
    print('hon')
else:
    print('pon')

Measured memory_bytes: 9180
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	f = 0
	for i in 1:n
		if a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0
			f = 1
		end
	end
	println(f==0?"APPROVED":"DENIED")
end

main()

Measured memory_bytes: 166404
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
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); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
ll modpow(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2, M);
        return t*t % M;
    }
    return N * modpow(N, P-1, M) % M;
}
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>ans(k + 1);
  for(int i = k; i > 0; i--){
    if(k / i == 1)ans[i] = 1;
    else{
      ans[i] = modpow(k / i,n,INF);
      ans[i] %= INF;
      for(ll j = 2; i * j <= k; j++){
        if(ans[i] - ans[i * j] >= 0)ans [i] -= ans[i * j] % INF;
        else ans[i] = ans[i] - ans[i * j] + INF;
        ans[i] %= INF;
      }
    }
  }
  ll sum = 0;
  REP(i,1,k + 1){
    sum += ((ans[i] % INF) * i) % INF;;
    sum %= INF;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3996
import java.util.*;

public class Main {

	public static void main(String args[]) {

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int arr[] = new int[n+1];
		for (int i = 1; i <=n; i++) {
			arr[i] = scn.nextInt();

		}
		
		System.out.println(frog(arr, k,n));

	}

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

		}
		return dp[n];

	}
}

Measured memory_bytes: 59736
n=int(input())
s=input()
l=[[] for i in range(10)]
for i in range(n):
    j=int(s[i])
    l[j].append(i)
ans=0
for i in range(1000):
    i=str(i).rjust(3,"0")
    a,b,c=[int(j) for j in i]
    if l[a] and l[b] and l[c]:
        p,q=l[a][0],l[c][-1]
        if p<q:
            for j in l[b]:
                if p<j<q:
                    ans+=1
                    break
print(ans)


Measured memory_bytes: 4364
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  string s; cin >>s;
  int n = s.size();
  bool ok = true;
  string t = s;
  rep(i, n) t[i] = s[n-1-i];
  if (s != t) ok = false; // 回文かどうか
  int n2 = (n-1)/2;
  string s2 = ""; rep(i, n2) s2.push_back(s[i]);
  string t2 = s2; rep(i, n2) t2[i] = s2[n2-1-i];
  if (s2 != t2) ok = false; // 2つ目の条件
  int n3 = (n+3)/2;
  string s3 = ""; for (int i=n3-1; i<n; i++) s3.push_back(s[i]);
  string t3 = s3; rep(i, s3.size()) t3[i] = s3[s3.size()-1-i];
  if (s3 != t3) ok = false;
  cout <<(ok ? "Yes" : "No") <<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

using namespace std;
typedef unsigned long long ll;
typedef pair<int,int>P;

int main()
{
	int N,K;
	vector<int>X;
	vector<int>PO,NE;
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		int n;
		cin>>n;
		X.push_back(n);
		if(n==0)K--;
		else if(n<0)NE.push_back(abs(n));
		else PO.push_back(n);
	}
	sort(NE.begin(),NE.end());
	sort(PO.begin(),PO.end());
	ll res=10e14;
	for(int p=0;p<=min(K,(int)PO.size());p++)
	{
		if(K-p>NE.size())continue;

		ll pp=p==0?0:PO[p-1];
		ll np=p==K?0:NE[K-p-1];
		ll x=min(pp,np)*2+max(pp,np);
		res=min(res,x);
	}
	cout<<res<<endl;
}


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

int main(){
  int N;
  cin >> N;
  stack<int> s;
  queue<int> q;
  
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    if (N % 2 == 0){
    // 偶数なら、偶数が前、奇数が後ろ
      if(i % 2 != 0){
        s.push(tmp);
      } else {
        q.push(tmp);
      }
    } else { 
      if(i % 2 == 0){
        q.push(tmp);
      } else { 
        s.push(tmp);
      }
    }
  }
  
  vector<int> v;
  while(!s.empty()){
    int x;
    x = s.top();
    s.pop();
    v.push_back(x);
  }
  while(!q.empty()){
    int x;
    x = q.front();
    q.pop();
    v.push_back(x);
  }
  if( N % 2 == 1){
    reverse(v.begin(), v.end());
  }
  
  for(int i = 0; i < v.size(); i++){
    cout << v[i];
    if( i != v.size() -1){
      cout << " " ;
    } else { 
      cout << endl;
    }
  }
}

Measured memory_bytes: 3960
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

const int MAX_V = 10010;
const int MAX_E = 100010;
const int INF = 100000000;
struct edge {
    int to, next;
    double cost;
};
edge es[MAX_E];
int head[MAX_V];


double d[MAX_V];
int cnt, V, E, s;
typedef pair<double,int> P;
bool visited[MAX_V];

double x[MAX_V];
double y[MAX_V];

void init() {
    cnt = 0;
    fill(head, head + MAX_V, -1);
    fill(visited, visited + MAX_V, false);
    fill(d, d + MAX_V, INF);
}

void add(int from, int to, double cost) {
    es[cnt].to = to;
    es[cnt].cost = cost;
    es[cnt].next = head[from];
    head[from] = cnt++;
}

double prim() {
    double ans = 0;
    for(int i = 1; i <= V; i++) {
        if(visited[i]) continue;
        priority_queue<P, vector<P>, greater<P> > que;
        d[i] = 0;
        que.push(P(0,i));

        while(!que.empty()) {
            P p = que.top(); que.pop();
            int from = p.second;
            if(visited[from]) continue;
            ans += p.first;
            visited[from] = true;
            for(int i = head[from]; ~i; i = es[i].next) {
                if (es[i].cost < d[es[i].to]) {
                    d[es[i].to] = es[i].cost;
                    que.push(P(d[es[i].to], es[i].to));
                }
            }
        }
    }
    return ans;
}

int main() {
    init();
    scanf("%d%d", &V, &E);
    for(int i = 0; i < V; i++) {
        scanf("%lf%lf", &x[i+1], &y[i+1]);
    }
    int u, v;
    double cost, sum = 0;
    for(int i = 0; i < E; i++) {
        scanf("%d%d", &u, &v);
        cost = sqrt((x[u] - x[v]) * (x[u] - x[v]) + (y[u] - y[v]) * (y[u] - y[v]));
        sum += cost;
        add(u, v, -cost);
        add(v, u, -cost);
    }
    double ans = sum + prim();
    printf("%.3f\n", ans);
    return 0;
}


Measured memory_bytes: 4536
#include <iostream>
using namespace std;
 
int main() {
    int c[3];
    while (cin >> c[0] >> c[1] >> c[2]) {
        int under20 = 0;
        int sum = c[0] + c[1];
        for (int i = 1; i <= 10; i++) {
            if (i != c[0] && i != c[1] && i != c[2] && sum + i <= 20) {
                under20++;
            }
        }
        if (under20 > 3.5) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

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

using namespace std;
using ll = long long;

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

const int INF = 1001001001;

ll gcd(ll a, ll b) {
  if (a == INF) return b;
  if (b == INF) return a;
  if (a % b == 0) return b;
  return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];

  ll l[n + 1], r[n + 1];
  l[0] = r[0] = INF;
  rep(i, n) {
    l[i + 1] = gcd(l[i], a[i]);
    r[i + 1] = gcd(r[i], a[n - 1 - i]);
  }

  ll ans = 1;
  rep(i, n) ans = max(ans, gcd(l[i], r[n - i - 1]));
  cout << ans;

  return 0;
}


Measured memory_bytes: 5856
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
# import numpy as np

# sys.setrecursionlimit(10000001)
INF = 10 ** 16
# MOD = 10 ** 9 + 7
MOD = 998244353


def ni(): return int(sys.stdin.readline())
def ns(): return map(int, sys.stdin.readline().split())
def na(): return list(map(int, sys.stdin.readline().split()))


# ===CODE===

class ModCombination:
    # https://atcoder.jp/contests/abc167/submissions/13058694
    # https://ikatakos.com/pot/programming_algorithm/number_theory/mod_combination

    def __init__(self, maxN, MOD):
        self._maxN = maxN
        self._MOD = MOD
        self.facts = [1]
        self.invs = [1]*(self._maxN+1)

        fact = 1
        for i in range(1, self._maxN+1):
            fact *= i
            fact %= self._MOD
            self.facts.append(fact)

        inv = pow(fact, self._MOD-2, self._MOD)
        self.invs[self._maxN] = inv
        for i in range(self._maxN, 1, -1):
            inv *= i
            inv %= self._MOD
            self.invs[i-1] = inv

    def nCr(self, n, r):
        return self.facts[n]*self.invs[r]*self.invs[n-r] % self._MOD


def main():

    n, m, k = ns()

    mc = ModCombination(n, MOD)

    result = 0

    for ki in range(k + 1):
        ans = 1
        ans *= m % MOD
        ans *= pow(m - 1, n - 1 - ki, MOD)
        ans %= MOD
        ans *= mc.nCr(n-1, ki)
        ans %= MOD
        result += ans
        result %= MOD

    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88180
eval"N,K,*A,D=#{`tr ' 
' ,`}(0..255).map{[0]*101}"
D[0][0]=1
A.map{|a|N.times{|j|256.times{D[_1^a][i=N-j]+=D[_1][i-1]*i}}}
p D[K].sum.%10**9+7
##########

Measured memory_bytes: 20080
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int add(int a, int b) {
	a += b;
	if (a >= mod) {
		return a - mod;
	}
	return a;
}
void add_self(int& a, int b) {
	a = add(a, b);
}
int mult(int a, int b) {
	return 1ll * a * b % mod;
}
int bin_pow(int a, int b) {
	if (b == 0) {
		return 1;
	}
	if (b % 2 == 0) {
		return bin_pow(mult(a, a), b / 2);
	}
	return mult(a, bin_pow(a, b - 1));
}
int inv(int a) {
	return bin_pow(a, mod - 2);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	vector<int> a(5);
	int k;
	for (int i = 0; i < 5; ++i) {
		cin >> a[i];
	}
	cin >> k;
	sort(a.begin(), a.end());
	if (a[4] - a[0] <= k) {
		cout << "Yay!\n";
	} else {
		cout << ":(\n";
	}
	return 0;
}


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

int main() {
  int N,K,M;
  cin>>N>>K;
  vector<int> high(N);
  for(int i=0;i<N;i++){
    cin>>high.at(i);
  }
  
  vector<int> cost(N);
  cost.at(0)=0;
  cost.at(1)=abs(high.at(1)-high.at(0));
    for(int i=2;i<N;i++){
      M=2000000000;
      for(int j=1;j<=min(i,K);j++){
        M=min(M,cost.at(i-j)+abs(high.at(i)-high.at(i-j)));
      }
      cost.at(i)=M;
    }
  
  cout<<cost.at(N-1);
    
}


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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)
const ll N = 123456;

vector < int > a[N];

const ll mod = 1e9 + 7;

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

    string s;
    cin >> s;

    map < char , int > a;

    for(auto j : s) a[j]++;

    if(a.size() == 2) {
        for(auto j : a) {
            if(j.second != 2) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;

ll n, k, a[maxn], ans = 0;
bool cmp(const ll &a, const ll &b) { return abs(a) > abs(b); }
void slove() {
    scanf("%lld%lld", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a, a + n, cmp);
    vector<ll> a1, a2;
    for (int i = 0; i < n; i++) {
        if (a[i] > 0)
            a1.push_back(a[i]);
        else if (a[i] < 0)
            a2.push_back(a[i]);
    }

    if (a1.size() + a2.size() < k) {
        ans = 0;
        return;
    }
    int flag0 = 0;
    if (a1.size() + a2.size() < n) flag0 = 1;
    if (a1.size() + a2.size() == k) {
        if (flag0 == 1 && (a2.size() % 2 == 1)) {
            ans = 0;
            return;
        }
        ans = 1;
        for (int i = 0; i < a1.size(); i++) {
            ans = ans * a1[i];
            ans %= mod;
        }
        for (int i = 0; i < a2.size(); i++) {
            ans = ans * a2[i];
            ans %= mod;
        }
        return;
    }
    if (a1.size() == 0) {
        if (k % 2 == 1) {
            if (flag0 == 1) {
                ans = 0;
                return;
            }
            ans = 1;
            for (int i = a2.size() - 1; i >= a2.size() - k; i--) {
                ans = ans * a2[i];
                ans %= mod;
            }
            return;
        }
        ans = 1;
        for (int i = 0; i < k; i++) {
            ans = ans * a2[i];
            ans %= mod;
        }
        return;
    }
    int c1 = 0, c2 = 0;
    for (int i = 0; i < k; i++) {
        if (a[i] > 0) c1++;
        if (a[i] < 0) c2++;
    }
    if (c2 % 2 == 0) {
    } else {
        ll t1, t2;
        // printf("%lld %lld %lld %lld\n", a1[c1 - 1], a1[c1], a2[c2 - 1],
        // a2[c2]);
        if (c1 == a1.size() || c2 == 0) {
            c1--, c2++;
        } else if (c2 == a2.size() || c1 == 0) {
            c1++, c2--;
        } else {
            t1 = a1[c1 - 1] * a1[c1], t2 = a2[c2 - 1] * a2[c2];
            if (t1 > t2) {
                c1++, c2--;
            } else {
                c1--, c2++;
            }
        }
    }
    // printf("%d %d\n", c1, c2);
    ans = 1;
    for (int i = 0; i < c1; i++) {
        ans = ans * a1[i];
        ans %= mod;
    }
    for (int i = 0; i < c2; i++) {
        ans = ans * a2[i];
        ans %= mod;
    }
}
int main() {
    slove();
    // if (ans < 0) ans += mod;
    ans = ((ans % mod) + mod) % mod;
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 6944
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n=3;
	vvi in(n,vi(n));
	rep(i,n)rep(j,n)cin>>in[i][j];
	bool h=false;
	rep(i,101)rep(j,101)rep(k,101){
		bool H=true;
		rep(q,3)if(in[0][q]-i>=0&&in[0][q]-i==in[1][q]-j&&in[0][q]-i==in[2][q]-k);
		else H=false;
		if(H)h=true;
	}
	if(h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;}








Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int LCS(char*,char*);
int max(int,int);
int main(){

  int i;
  int q;
  char X[1000],Y[1000];

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s%s",X,Y);
    printf("%d\n",LCS(X,Y));
  }
  return 0;
}
int LCS(char *X,char *Y){

  int i,j;
  int N[strlen(X)+1][strlen(Y)+1];
  
  for(i=0;i<strlen(X)+1;i++){
    for(j=0;j<strlen(Y)+1;j++){
      if(i==0 || j==0){
	N[i][j]=0;
      }
      else if(X[i-1]==Y[j-1]){
	N[i][j]=N[i-1][j-1]+1;
      }
      else{
	N[i][j]=max(N[i][j-1],N[i-1][j]);
      }
    }
  }
  return N[strlen(X)][strlen(Y)];
}
int max(int a,int b){
  if(a>b) return a;
  return b;
}



Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second


using namespace std;

vector<int> color(1e5 + 1);

int get_color(int x){
    //cout << x << endl;
    if(x == color[x]){
        return x;
    }
    return color[x] =  get_color(color[x]);
}

void update(int x, int y){
    if(get_color(x) != get_color(y)){
        //cout << x << ' ' << y << endl;
        color[get_color(x)] = get_color(y);
    }
}

bool comp(vector<int> x, vector<int> y){
    return min(x[0], x[1]) < min(y[0], y[1]);
}

void check(vector<int> sv, vector<vector<int> > og){
    int n = sv.size();
    int mi = 0, ma = 0;
    if(og.size() == 0){
        return;
    }
    map<int, int> c;
    for(int i = 0; i < n; i++){
        c[sv[i]] =i;
    }
    vector<int> used(n,  0), x(n, 0);
    used[0] = 1;
    vector<vector<vector<int> > > dop(n);
    for(auto it : og){
        dop[c[it[0]]].push_back(it);
        dop[c[it[1]]].push_back(it);
    }
    queue<vector<int> > d;
    for(auto it : dop[0]){
        d.push(it);
    }
    while(!d.empty()){
        auto it = d.front();
        d.pop();
        int t = c[it[0]], t1 = c[it[1]];
        if(used[t] == 0){
            swap(t, t1);
            it[2] = -it[2];
        }
        if(used[t1] == 0){
            for(auto it1 : dop[t1]){
                if(it1 != it)
                d.push(it1);
            }
        }
        if(used[t1] == 1 && x[t1] != x[t] + it[2]){
            cout << "No";
            exit(0);
        }
        if(used[t] == 0){
            exit(-1);
        }
        used[t1] = 1;
        x[t1] = x[t] + it[2];
    }
    for(auto it : x){
        mi = min(it, mi);
        ma = max(it, ma);
    }
    if(ma - mi > 1e9){
        cout << "No";
        exit(0);
    }
}

void solve(){
    int n, q;
    cin >> n >> q;
    vector<vector<int> > e(q);
    for(int i = 0; i < n; i++){
        color[i] = i;
    }
    for(int i = 0 ; i < q; i++){
        int l, r, d;
        cin >> l >> r >> d;
        e[i] = {--l, --r, d};
        update(l, r);
        //cout << color[0] << ' ' << color[1] <<' ' << color[2] << endl;
    }
    vector<vector<int> > sv(n);
    for(int i = 0; i < n; i++){
        sv[get_color(i)].push_back(i);
    }
   vector<vector<vector<int> > > og(n);
   for(auto it : e){
        og[get_color(it[0])].push_back(it);
   }
   for(int i = 0; i < n; i++){
    sort(og[i].begin(), og[i].end(), comp);
    //out << "rhgingk" <<  endl;
    check(sv[i], og[i]);
   }
   cout << "Yes";
}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int test = 1;
    //freopen("output.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //
    //cin >> test;
    while(test--){
        solve();
    }
}


Measured memory_bytes: 87404
#include<cstdio>
#define LL long long
int n,k;
LL ans;
int main()
{
	scanf("%d%d",&n,&k);
	int x=n/k;
	ans=1ll*x*x*x;
	if(k%2==0)
	{
		if(x*k+k/2<=n) ans+=1ll*(x+1)*(x+1)*(x+1);
		else ans+=1ll*x*x*x;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
n=int(input())

p = list(map(int, input().split()))

ans=0
for i in range(0,n-2):
  if (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i+2] < p[i+1] and p[i+1] < p[i]):
    ans+=1

print(ans)

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


int main(){
	int a,b,c,d;cin>>a>>b>>c>>d;
	if(abs(a-c) <= d) cout<<"Yes"<<endl;
	else if(abs(a-b) <= d && abs(b-c) <= d) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}
	

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    int N,M; cin >> N >> M;
    pair<int,int> ans[100000];
    vector<pair<int,int> > yd[100001];
    for(int i=0;i<M;i++){
        int p,y;
        cin >> p >> y;
        yd[p-1].push_back(make_pair(y,i));

    }
    
    for(int i=0;i<N;i++){
        sort(yd[i].begin(),yd[i].end());
        for(int j=0;j<yd[i].size();j++){
            ans[yd[i][j].second] = make_pair(i,j+1);
        }
    }
    for(int i=0;i<M;i++){
        printf("%06d%06d\n",ans[i].first+1,ans[i].second);//,yd[P[i]]);
    }
    return 0;
}


Measured memory_bytes: 7808
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
void put_ull(long long n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[20];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
long long merge_sort(int *first, int *last) {
    const int N = (int)(last - first);
    if(N < 2) return 0;
    int *mid = first + N / 2;
    const int N1 = (int)(mid - first);
    const int N2 = (int)(last - mid);
    int *left = malloc(sizeof(int) * (N1 + 1));
    int *right = malloc(sizeof(int) * (N2 + 1));
    memcpy(left, first, sizeof(int) * (N1 + 1));
    memcpy(right, mid, sizeof(int) * (N2 + 1));
    // sufficiently large value
    left[N1] = right[N2] = 1 << 30;

    long long cnt = 0;
    cnt += merge_sort(left, left + N1);
    cnt += merge_sort(right, right + N2);

    for(int *it = first, i = 0, j = 0; it != last; ++it) {
        if(left[i] <= right[j]) *it = left[i++];
        // swap ? cnt += moved num
        else *it = right[j++], cnt += N1 - i;
    }
    free(left);
    free(right);
    return cnt;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int a[200001];
    for(int i = 0; i < n; ++i) a[i] = get_uint();
    put_ull(merge_sort(a, a + n));
    putchar_unlocked('\n');
    return 0;
}



Measured memory_bytes: 3928
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(){
	int N, P;
	int t=0;
	int number[2];
	int odd=0, even=0;
	int i, j;
	double answer=1;
	scanf("%d%d", &N, &P);
	for(i=1;i<=N;i++){
		scanf("%d", &t);
		if(t%2==1) odd++;
		if(t%2==0) even++;
	}
	if(odd==0&&P==1){
		printf("0");
		return 0;
	} 
	if(odd!=0) N--;
	for(i=1;i<=N;i++){
		answer*=2;
	}
	printf("%.0lf", answer);
	return 0;
}

Measured memory_bytes: 128
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let d: i32 = read();
    let x: i32 = read();
    let a: Vec<i32> = (0..n).map(|_| read()).collect();

    let mut ans = 0;
    for a_i in a {
        let mut count = 0;
        let mut day = 1;
        while day <= d {
            day += a_i;
            count += 1;
        }
        ans += count;
    }
    println!("{}", ans + x);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

struct tree_element {
    int to;
    int cost;
};

vector<int> ans(100001, -1);
vector<vector<tree_element>> tree(100001);

int dfs(int id)
{
    for(auto itr = tree[id].begin(); itr != tree[id].end(); itr++) {
        if(ans[itr->to] < 0) {
            IFD cout << id << ": " << itr->to << endl;
            ans[itr->to] = ans[id] ^ itr->cost;
            dfs(itr->to);
        }
    }
}

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

    for(int i = 1; i <= N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        tree[u].push_back((tree_element){v, w % 2});
        tree[v].push_back((tree_element){u, w % 2});
    }
    ans[1] = 0; // 1 は必ず白に決める
    dfs(1);

    for(int i = 1; i <= N; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 7680
// Problem : A - Fairness
// Contest : AtCoder - AtCoder Grand Contest 024
// URL : https://atcoder.jp/contests/agc024/tasks/agc024_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	ll a,b,c,k,ca,cb,cc;
	cin>>a>>b>>c>>k;
	if(k%2)
	cout<<b-a;
	else
	cout<<a-b;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3660
#include<stdio.h>
int main(void){
  int i,j,n,len,c,count=0;
  int A[100];
  scanf("%d",&len);
  for(i=0;i<len;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<len;i++){
    for(j=len-1;j>i;j--){
      if(A[j]<A[j-1]){
	c=A[j];
	A[j]=A[j-1];
	A[j-1]=c;
	count++;
      }
    }
  }
  for(i=0;i<len;i++){
    if(i!=0){
      printf(" ");
    }
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int q;
    cin >> q;
    int a, x;
    string key;
    map<string, int> m;
    while(q--){
        cin >> a >> key;
        if(a==0){
            cin >> x;
            m[key]=x;
        }else{
            cout << m[key] << "\n";
        }
    }
    
    return 0;
}


Measured memory_bytes: 27692
#include <bits/stdc++.h>
using namespace std;
int main(){
  string A,B,C;
  cin>>A>>B>>C;

  if(A.at(A.size()-1)==B.at(0)&&B.at(B.size()-1)==C.at(0)){
    cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}
  
  return 0;}

Measured memory_bytes: 256
'use strict';
(function(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  const N=input[0];
  const K=input[1];
  var k=K-1;
  var e=[Infinity,K-1];
  while(k>0){
    k=Math.floor(k/2);
    e.push(k);
  }
  var p=new Array(N+1).fill(1/N);
  p[0]=0;
  var ans=0;
  p.forEach(function(x,i){
    for(let j=0;j<e.length;j++){
      if(e[j+1]<i&&i<=e[j]){
        ans+=x/Math.pow(2,j);
      }
    }
  });
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 15052
#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();
	
	int H, W, D; cin >> H >> W >> D;
	map<int, pair<int, int>>yx;
	rep(i, 0, H) {
		rep(j, 0, W) {
			int a; cin >> a;
			yx[a] = { i + 1,j + 1 };
		}
	}
	int Q; cin >> Q;
	map<int, ll>cnt;
	rep(i, 1, H* W + 1) {
		if (!cnt.count(i)) {
			cnt[i] = 0;
			ll ans = 0;
			pair<int, int>now = yx[i];
			int j = i;
			while (j <= H * W) {
				j += D;
				ans += (abs(now.first - yx[j].first) + abs(now.second - yx[j].second));
				cnt[j] = ans;
				now = yx[j];
			}
		}
	}

	rep(i, 0, Q) {
		int L, R; cin >> L >> R;
		ll ans = cnt[R] - cnt[L];
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 24960
#include <bits/stdc++.h>
#define rep(i,n)for(unsigned long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 510000;

int main() {
  int a,b;
  cin >> a >> b;
  string s(b,'0'+a);
  string t(a,'0'+b);
  cout << min(s,t)<< endl;
}

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

lib = {}

for _ in range(n):
    l = input().split()

    if not l[0] in lib.keys():
        lib[l[0]] = []

    lib[l[0]].append([l[1], _])


lib = sorted(lib.items())
for v in lib:
    for i in sorted(v[1], key=lambda x: -int(x[0])):
        print(i[1]+1)

Measured memory_bytes: 3064
#include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int c;
int a[100][100];
int times = 0;
vector<pair<int,int> > v;

vector<int> search(int node)
{
    vector<int> r;
    for(int i = 0;i<c;i++)
    {
        if(a[node][i] == 1)
            r.push_back(i);
    }
    return r;
}

int deep(int node)
{
    if(v[node].first == 0)
    {
        v[node].first = ++times;
        vector<int> r = search(node);
        for(int i = 0;i<r.size();i++)
        {
            deep(r[i]);
            
        }
        v[node].second = ++times;
    }
    else
        return -1;

    return 1;
}

int main() {

    cin >> c;
    for(int i= 0;i<c;i++)
        for(int j = 0;j<c;j++)
            a[i][j] = 0;
    v = vector<pair<int,int> >(c,{0,0});
    for(int i = 0; i<c;i++)
    {
        int rem[2];
        cin >> rem[0] >> rem[1];
        for(int j = 0;j<rem[1];j++)
        {
            int rem11;
            cin >> rem11;
            a[i][rem11-1] = 1;
        }
    }//cin fin
    for(int i = 0;i<c;i++)
    {
        if(v[i].first == 0)
            deep(i);
    }
    
    for(int i = 0; i<c;i++)
    {
        cout << i+1 << " " << v[i].first << " " << v[i].second << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>
int sort(int A[],int N){
	int i,j,t,sw = 0,minj;
	for(i = 0; i < N-1; i++){
		minj = i;
		for(j = i; j < N; j++){
			if(A[j] < A[minj]) minj = j;
		}
		t = A[minj]; A[minj] = A[i]; A[i] = t;
		if(i != minj) sw++;
	}
	return sw;
}
int main(void){
	int r,R[100],i,sw;
	scanf("%d",&r);
	for(i = 0; i < r; i++) scanf("%d",&R[i]);
	sw = sort(R,r);
	for(i = 0; i < r; i++) {
	    if(i > 0) printf(" ");
	    printf("%d",R[i]);
	}
	printf("\n%d\n",sw);
	return 0;
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
long long mypow(long long px, long long py){
	if(py == 0) return 1;
	if(py % 2 == 0) return mypow((px * px), py / 2);
	else return (px * mypow(px, py - 1));
}
int main() {
    // your code goes here
    int n,i,j,k,a[20],x[20][20],y[20][20],m,ans=0;
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> a[i];
        for(j=1;j<=a[i];j++){
            cin >> x[i][j] >> y[i][j];
        }
    }
    for(i=0;i<mypow(2,n);i++){
        m=i;
        int db[20]={0},os=0;
        bool ok=true;
        j=1;
        while(m>0){
            db[j]=m%2;
            if(db[j]==1) os++;
            m=(m-m%2)/2;
            j++;
        }
        for(j=1;j<=n;j++){
            if(db[j]==1){
                for(k=1;k<=a[j];k++){
                    if(y[j][k]!=db[x[j][k]]) ok=false;
                }
            }
        }
        if(ok) ans=max(ans,os);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		Map<Integer,List<Integer>> map = new HashMap<>();
		for(int i=0;i<m;i++) {
			int u = in.nextInt();
			int v = in.nextInt();
			if(map.containsKey(u)) map.get(u).add(v);
			else {
				List<Integer> list = new ArrayList<>();
				list.add(v);
				map.put(u, list);
			}
		}
		int s = in.nextInt();
		int t = in.nextInt();
		int[][] dist = new int[n+1][3];
		for(int i=0;i<n+1;i++) {
			for(int j=0;j<3;j++) {
				dist[i][j] = 100000000;
			}
		}
		dist[s][0] = 0;
		boolean[][] used = new boolean[n+1][3];
		used[s][0] = true;
		Queue<int[]> deq = new ArrayDeque<>();
		int[] start = {s,0};
		deq.add(start);
		while(!deq.isEmpty()) {
			int[] tmp = deq.poll();
			if(!map.containsKey(tmp[0])) continue;
			for(int next : map.get(tmp[0])) {
				dist[next][(tmp[1]+1)%3] = Math.min(dist[tmp[0]][tmp[1]]+1, dist[next][(tmp[1]+1)%3]);
				if(!used[next][(tmp[1]+1)%3]) {
					int[] tmp2 = {next,(tmp[1]+1)%3};
					deq.add(tmp2);
					used[next][(tmp[1]+1)%3] = true;
				}
			}
		}
		if(dist[t][0]==100000000) System.out.println(-1);
		else System.out.println(dist[t][0]/3);
		
		in.close();

	}

}


Measured memory_bytes: 106776
#include <stdio.h>
#include <stdlib.h>

#define MAXN 5000

unsigned long t, n, j;
long a[MAXN], cur_min, max, s;
unsigned int count_min, count;

int main() {
        while (1) {
                scanf("%lu", &n);
                if (n == 0) break;
                for (j = 0; j < n; ++j) scanf("%ld", &a[j]);
                cur_min = s = max = a[0]; count_min = count = 1;
                for (j = 1; j < n; ++j) {
                        s += a[j];
                        if (s > max) {
                                max = s;
                                count = 1;
                        } else if (s == max)
                                count++;
                        if (s - cur_min > max) {
                                max = s - cur_min;
                                count = 1;
                        } else if (s - cur_min == max)
                                count += count_min;
                        if (s < cur_min) {
                                cur_min = s;
                                count_min = 1;
                                continue;
                        }
                        if (s == cur_min) count_min++;
                }
                printf("%ld\r\n", max);
        }
        return 0;
}

Measured memory_bytes: 628
#include<stdio.h>

int main(void){
  char a[4];
  char b[4];

  scanf("%s",a);
  scanf("%s",b);

  
  if((a[0]==b[2])&&(a[1]==b[1])&&(a[2]==b[0])){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128