akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef long long ll;
 
#define pb push_back
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string a, b;;
	cin >> a >> b;
	int n = a.size(), m = b.size(), ans = 1e9;
	auto f = [&] (int i) {
		string sub = a.substr(i, m);
		int cnt = 0;
		for (int j = 0; j < m; j++)
			if (sub[j] != b[j])
				cnt++;
		return cnt;
	};
	for (int i = 0; i + m <= n; i++) 
		ans = min(ans, f(i));
	cout << ans;
   return 0;
}

Measured memory_bytes: 3604
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    vector<vector<int>> A(3, vector<int>(3));
    rep(i,3) rep(j,3) cin >> A[i][j];
    int N; cin >> N;
    vector<int> B(N);
    rep(i,N) cin >> B[i];

    vector<vector<bool>> C(3, vector<bool>(3));
    rep(i,N) {
        rep(j,3) {
            rep(k,3) if (A[j][k]==B[i]) C[j][k] = true; 
        }
    }

    bool ok = false;
    rep(i,3) if (C[i][0]&&C[i][1]&&C[i][2]) ok = true;
    rep(i,3) if (C[0][i]&&C[1][i]&&C[2][i]) ok = true;
    if (C[0][0]&&C[1][1]&&C[2][2]) ok = true;
    if (C[0][2]&&C[1][1]&&C[2][0]) ok = true;

    cout << (ok ? "Yes" : "No") << ln;
}

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

const int N = 505;

int n, k, sum = 0;
int a[N];

int check(int x)
{
	int reqd = 0;
	vector<int> v;
	for(int i = 1; i <= n; i++)
	{
		int cur = a[i] % x;
		v.push_back(cur);
	}
	sort(v.begin(), v.end());
	int l = 0, r = v.size() - 1;
	int add = 0;
	while(l <= r)
	{
		if(add >= 0)
		{
			add -= v[l];
			reqd += v[l];
			l++;
		}
		else
		{
			add += (x - v[r]);
			reqd += (x - v[r]);
			r--;
		}
	}
	if(add || reqd > 2 * k) return 0;
	return 1;
}

int32_t main()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	int ans = 1;
	for(int i = 1; i * i <= sum; i++)
	{
		if(sum % i == 0)
		{
			if(check(i))
				ans = max(ans, i);
			if(check(sum / i))
				ans = max(ans, sum / i);
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
def f(base,m,c):
	for i in range(16):
		for j in range(32):
			if not m:
				break
			base[2 * i][j * 2] = c
			m -= 1
		else:
			continue
		break
	return base

w,b=map(int,input().split())
print(64,64)
print("\n".join(map("".join,f([["#"]*64 for _ in range(32)],w-1,".")+[["."]*64]+f([["."]*64 for _ in range(31)],b-1,"#"))))

Measured memory_bytes: 3064
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    string s;
    cin >> s;
    bool C = false;
    for (char c : s) {
        if (c == 'C' && !C) C = true;
        if (c == 'F' && C) {
            cout << "Yes" << "\n";
            return;
        }
    }
    cout << "No" << "\n";
}

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

    solve();

    return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		double x[4],y[4];
		for(int j=0;j<4;j++)
			cin>>x[j]>>y[j];
		if(abs((x[3]-x[2])*(y[1]-y[0])-(x[1]-x[0])*(y[3]-y[2]))<1e-10)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N, M, X = map(int, input().split())
    CA = [list(map(int, input().split()))for _ in range(N)]

    result = []
    for i in range(2**N):
        bins = format(i, "b").zfill(N)
        tmp = [0] * (M + 1)

        for b, ca in zip(bins, CA):
            if b == "1":
                for j in range(M + 1):
                    tmp[j] += ca[j]
        if all([True if k >= X else False for k in tmp[1:]]):
            result.append(tmp)

    if result == []:
        print(-1)
    else:
        print(min([r[0]for r in result]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 11172
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val count = Array(n) {0}
    repeat(m) {
        val a = sc.nextInt() - 1
        val b = sc.nextInt() - 1
        count[a]++
        count[b]++
    }
    for (c in count) {
        println(c)
    }
}

Measured memory_bytes: 31268
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, K;
int A[212345];

int main() {

	cin >> N >> K;

	rep(i, K) cin >> A[i];

	rep(i, N - K) {
		cin >> A[K + i];
		if (A[i] < A[K + i]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main(){
  string s, s1, s2;
  cin >> s1 >> s2;
  s = s1 + s2;
  int num = stoi(s);
  
  for(int i=1; i<=sqrt(100100)+1; i++){
    if(num == i*i){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int prime[80000];
	int ptr=2;
	prime[0] = 2;
	prime[1] = 3;
	for(int num=5; num<1000000; num+=2){
		bool f = false;
		for(int i = 0; i<ptr; i++){
			if (prime[i]*prime[i] > num) break;
			if (num%prime[i]==0) {
				f = true;
				break;
			}
		}
		if(!f) prime[ptr++] = num;
	}
	prime[ptr]=1000001;
	int n;
	while(cin >> n){
		int k=0;
		for(;prime[k]<=n;k++);
		cout << k << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1052
#include <stdio.h>
int main(void)
{
	int a, i, max, min, n;
	long long int sum;
	max = -1000000;
	min = 1000000;
	sum = 0;

	scanf("%d", &n);

	for (i = 1; i <= n; i = i + 1)
	{
		scanf("%d", &a);
		if (min > a)
		{
			min = a;
		}
			
		if (max < a)
		{
			max = a;
		}
		sum = sum + a;
	}
	printf("%d %d %lld\n", min, max, sum);
	return 0;
}



Measured memory_bytes: 2108
#include <stdio.h>
int main(){
    int n,b,f,r,v,i,j,k,room[10][3][4];
    scanf("%d",&n);
    for(i=0; i<10; i++){
        for(j=0; j<3; j++){
            room[i][j][0] = 0;
            room[i][j][1] = 0;
            room[i][j][2] = 0;
            room[i][j][3] = 0;

        }
    }
    for(i=0; i<n; i++){
        scanf("%d %d %d %d",&b, &f, &r, &v);
        room[r-1][f-1][b-1] += v;
    }
    for(k=0; k<4; k++){
        for(i=0; i<3; i++){
            for(j=0; j<10; j++){
            //for(k=1; k<5; k++){
                printf(" %d",room[j][i][k]);

            }
            printf("\n");
        }
        if(k<3){
            printf("####################\n");
            //l++;
        }
    }
        //printf(" ");

    return 0;
}

Measured memory_bytes: 612
#include <iostream>
using namespace std;
 
int main() {
	string line;
    cin >> line;
    for (int i=0; i<5; i++){
    	cout << line[i];
    }
    cout << ' ';
    for (int i=6; i<13; i++){
    	cout << line[i];
    }
    cout << ' ';
    for (int i=14; i<line.length(); i++){
    	cout << line[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int ct[200009];
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  int n;
  cin>>n;
  repre(i,1,n-1)
  {
    int a;
    cin>>a;
    ct[a]++;
  }
  repre(i,1,n)cout<<ct[i]<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,m,p,a,b,c,ans,memo[2500];
bool is_ok[2500],visited[2500],inf;
vector<pair<int,int>> v[2500];
vector<int> vv[2500];

void kr(int k) {
    if (is_ok[k]) return;
    is_ok[k] = true;
    for(auto i : vv[k]) kr(i);
}
void masu(int k, int now) {
    if (!is_ok[k] || inf) return;
    if (visited[k] && memo[k] < now) {
        inf = true;
        return;
    }
    if (memo[k] >= now) return;
    memo[k] = now;
    if (k == n-1) ans = max(ans, memo[k]);
    visited[k] = true;
    for(auto i : v[k]) masu(i.fi,now+i.se);
    visited[k] = false;
}

signed main() {
    rep(i,2500) memo[i] = -INF;
    cin >> n >> m >> p;
    rep(i,m) {
        cin >> a >> b >> c;c-=p;
        a--,b--;
        v[a].pb(mp(b,c));
        vv[b].pb(a);
    }
    kr(n-1);
    masu(0,0);
    if (inf) cout << -1 << endl;
    else cout << max(0LL,ans) << endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<stdio.h>

using namespace std;

int main() {
   
   int a, b;
   cin >> a >> b;
  
   int k = b - a;

   int sum = 0;
   for (int i = 1; i <= k; i++) {
      sum += i;
   }
  
   cout << sum - b << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, k, a[114514], ma = 0;
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
		ma = max(ma, a[i]);
	}
	for (int i = 1; i < n; i++) {
		a[i] = gcd(a[i - 1], a[i]);
	}
	if (ma >= k && k % a[n - 1] == 0) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int y500, y100, y50, total;
  int count_ways = 0;
  cin >> y500 >> y100 >> y50 >> total;
  for (int i = 0; i <= y500; i++) {
    for (int j = 0; j <= y100; j++) {
      for (int k = 0; k <= y50; k++) {
        if (500 * i + 100 * j + 50 * k == total) {
          count_ways++;
        }
      }
    }
  }
  cout << count_ways << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var g = Enumerable.Range(1, N).Select(_ => Console.ReadLine())
                .GroupBy(_ => _).Select(_ => new { Count = _.Count(), _.Key })
                .OrderByDescending(_ => _.Count).ThenBy(_ => _.Key, StringComparer.OrdinalIgnoreCase)
                .ToArray();

            var max = g.Max(_ => _.Count);
            foreach (var item in g.Where(_ => _.Count == max))
            {
                Console.WriteLine(item.Key);
            }
        }
    }
}


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

int main(){
  int N, A;
  cin >> N;
  cin >> A;
  
  int B,C;
  B = N / 500;
  if (N - 500*B == 0){
  	cout << "Yes" << endl;
  } else if (A==0) {
    cout << "No" << endl;
  } else {
  	C = (N - 500*B) / A;
    if (C==0) {
      cout << "Yes" << endl;     
    } else {
      cout << "No" << endl;      
    }
  }
}


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

using namespace std;
int main()
{
	long N;
	cin >> N;

	long nAC = 0;
	long nWA = 0;
	long nTLE = 0;
	long nRE = 0;
	for (long i = 0; i < N; ++i)
	{
		string s;
		cin >> s;

		if (s == "AC")
		{
			nAC++;
		}
		else if (s == "WA")
		{
			nWA++;
		}
		else if (s == "TLE")
		{
			nTLE++;
		}
		else if (s == "RE")
		{
			nRE++;
		}
	}

	cout << "AC x " << nAC << endl;
	cout << "WA x " << nWA << endl;
	cout << "TLE x " << nTLE << endl;
	cout << "RE x " << nRE << endl;
}

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

struct edge {
  int a;
  int b;
  int weight;
};
int *ufp, *ufr;
struct edge *ed;

void qsort1(int, int);
int UF_find(int);
void UF_union(int, int);
int Kruskal(int, int);

int main(void)
{
  int i, j, v, e, s, t, w, cost;
  scanf("%d %d", &v, &e);
  ufp = (int*)malloc(sizeof(int) * v);
  ufr = (int*)malloc(sizeof(int) * v);
  ed = (struct edge*)malloc(sizeof(struct edge) * e);
  for (i = 0; i < v; i++) {
    ufp[i] = i;
    ufr[i] = 0;
  }
  for (i = 0; i < e; i++) {
    scanf("%d %d %d", &s, &t, &w);
    ed[i].weight = w;
    ed[i].a = s;
    ed[i].b = t;
  }
  cost = Kruskal(v, e);
  printf("%d\n", cost);
  free(ufp);
  free(ufr);
  free(ed);
}

void qsort1(int left, int right)
{
  int pivot = ed[(left + right) / 2].weight, i = left, j = right;
  if (i >= j) return;
  do {
    while (ed[i].weight < pivot) i++;
    while (ed[j].weight > pivot) j--;
    if (i <= j) {
      struct edge temp = ed[i];
      ed[i] = ed[j];
      ed[j] = temp;
      i++;
      j--;
    }
  } while (i <= j);
  qsort1(left, j);
  qsort1(i, right);
}

int UF_find(int a)
{
  if (ufp[a] == a) return a;
  else return UF_find(ufp[a]);
}

void UF_union(int a, int b)
{
  if (ufr[a] < ufr[b]) ufp[a] = b;
  else {
    ufp[b] = a;
    if (ufr[a] == ufr[b]) ufr[a]++;
  }
}

int Kruskal(int size, int esize)
{
  int i, cost = 0;
  qsort1(0, esize - 1);
  for (i = 0; i < esize; i++) {
    int ea = UF_find(ed[i].a), eb = UF_find(ed[i].b);
    if (ea != eb) {
      UF_union(ea, eb);
      cost += ed[i].weight;
    }

  }
  return cost;
}


Measured memory_bytes: 2984
// -*- coding:utf-8-unix -*-

use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
use std::convert::TryInto;
use std::io::*;
use std::str::FromStr;
use superslice::*;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//abc128-C

#[fastout]
fn main() {
    // input!
    //     input! {
    //         n: u8,
    //         m: u8,
    //         sk: [[u8]; n],
    //         ps: [u8; m]
    //     }

    //     println!(
    //         r#"
    // n: {},
    // m: {},
    // sk: {:?},
    // ps: {:?}
    //         "#,
    //         n, m, sk, ps
    //     );

    // read
    // let n: usize = read();
    // let m: usize = read();
    // let mut s: Vec<Vec<usize>> = vec![vec![]; m];
    // let mut p: Vec<usize> = vec![];

    // for i in 0..m {
    //     let k = read();
    //     for _ in 0..k {
    //         s[i].push(read());
    //     }
    // }

    // for _ in 0..m {
    //     p.push(read());
    // }
    // let mut ans = 0;

    input![s: String,];

    let mut ans = vec![0; s.len()];

    //rlを探す
    let mut rl_idx = Vec::new();
    let mut previous_s = 'A';
    for (idx, s) in s.chars().enumerate() {
        if previous_s == 'R' && s == 'L' {
            rl_idx.push(idx - 1);
        }

        previous_s = s;
    }

    // eprintln!("{:?}", rl_idx);

    //rlまでの距離をはかって、どちらかに足す
    for (idx, r_or_l) in s.chars().enumerate() {
        if idx == 0 {
            if &s[0..2] == "RL" {
                ans[0] += 1;
            } else {
                //Rまでの距離を図る
                let r_idx = rl_idx[rl_idx.upper_bound(&(idx))];
                // eprintln!("R:{}, {}", idx, r_idx);
                let len = r_idx - idx;

                if len % 2 == 0 {
                    ans[r_idx] += 1;
                } else {
                    ans[r_idx + 1] += 1;
                }
            }
            continue;
        }
        if r_or_l == 'R' {
            //Rまでの距離を図る
            let r_idx = rl_idx[rl_idx.upper_bound(&(idx - 1))];
            // eprintln!("R:{}, {}", idx, r_idx);
            let len = r_idx - idx;

            if len % 2 == 0 {
                ans[r_idx] += 1;
            } else {
                ans[r_idx + 1] += 1;
            }
        } else {
            //Lまでの距離を図る
            let l_idx = rl_idx[rl_idx.lower_bound(&idx) - 1];
            // eprintln!("L:{}, {}", idx, l_idx);
            let len = (idx + 1) - l_idx;

            if len % 2 == 0 {
                ans[l_idx + 1] += 1;
            } else {
                ans[l_idx] += 1;
            }
        }
    }

    print!("{} ", ans[0]);

    for ans in &ans[1..] {
        print!("{} ", ans);
    }
}


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

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

int main()
{
	int h, w;
	cin>>h>>w;
	string c[300];
	for(int i=0; i<h; i++){
		cin>>c[i];
	}
	ll ans=0;
	for(int k=0; k<w-1; k++){
		ll count[301][301];
		for(int d=0; d<=h; d++){
			count[d][0]=0;
			for(int i=1; i<=h-d; i++){
				count[d+i][i]=count[d+i-1][i-1];
				if(c[d-1+i][k]==c[i-1][k+1]) count[d+i][i]++;
			}
		}
		for(int d=1; d<=h; d++){
			count[0][d]=0;
			for(int i=1; i<=h-d; i++){
				count[i][d+i]=count[i-1][d+i-1];
				if(c[d-1+i][k+1]==c[i-1][k]) count[i][d+i]++;
			}
		}
		ll dp[301][301];
		for(int i=0; i<=h; i++){
			for(int j=0; j<=h; j++){
				dp[i][j]=1000000000000000ll;
			}
		}
		dp[0][0]=0;
		for(int i=0; i<=h; i++){
			for(int j=0; j<=h; j++){
				if(i>=1) dp[i][j]=min(dp[i][j], dp[i-1][j]+count[i][j]);
				if(j>=1) dp[i][j]=min(dp[i][j], dp[i][j-1]+count[i][j]);
			}
		}
		ans+=dp[h][h];
	}
	printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
#EDPC N

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = [0] + list(accumulate(a))
dp = [[inf]*(n) for _ in range(n)]
for i in range(n):
    dp[i][i] = 0
for l in range(n-1)[::-1]:
    for r in range(l+1,n):
        s = b[r+1] - b[l]
        for c in range(l,r):
            dp[l][r] = min(dp[l][r],s + dp[l][c] + dp[c+1][r])
print(dp[0][-1])

Measured memory_bytes: 46556
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] num = new long[k];
        for (int i = 1; i <= n; i++) {
            num[i % k]++;
        }
        long ans = 0;
        for (int a = 0; a < k; a++) {
            int b = (k - a) % k;
            int c = (k - a) % k;
            if ((b + c) % k != 0) {
                continue;
            }
            ans += num[a] * num[b] * num[c];
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 24916
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<< 29;
const double PI = 3.14159265358979323846;

        
struct edge{int to, cost;};

vector<edge> G[100000];
int d[100000];
bool f = true;

void dfs(int cur, int prev){
        //与えられた頂点から生えている変に向かってを調べる。
        for(auto e: G[cur]){
                //生えているへんはもちろん元々の頂点への道もあるからそれは調べる価値がない。
                if(e.to == prev) continue;
                //もしまだ訪れていない場所なら、そこに現在の位置のコストを代入して、さらにそこから生えている頂点について調べていく。
                if(d[e.to] == IMF){
                        d[e.to] = d[cur] + e.cost;
                        dfs(e.to, cur);
                }
                //最終的にすでに訪れた辺に戻ってくる辺がある。この辺が矛盾がないかどうかを調べて矛盾があるならfalseを代入する。
                if(d[e.to] != IMF && d[cur] + e.cost != d[e.to]) f= false;
        }
}

int main(){
        int v,e;
        cin >> v >> e;

        //頂点の数を調べる。
        set<int> vs;

        rep(i,e){
                int s,t,d;
                cin >> s >> t >> d;
                s--;
                t--;
                vs.insert(s);
                vs.insert(t);
                //グラフにそれぞれの辺から生える辺を生やす。
                //反対方向は-をつける。
                G[s].push_back(edge{t,d});
                G[t].push_back(edge{s,-d});
        }

        //初期化する。
        rep(i,100000){
                d[i] = IMF;
        }
        //それぞれの頂点を調べていく。
        for(auto elm: vs){
                //もしすでに調べた場所は調べる価値なし。
                if(d[elm] != IMF) continue;
                d[elm] = 0;
                dfs(elm, -1);
        }

        if(f) cout << "Yes" << endl;
        else cout << "No"<< endl;
}


Measured memory_bytes: 18688
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

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

    string ans = "";
    if (N == 0) {
        ans = "0";
    }
    else {
        while (N != 0) {
            if (abs(N) % 2 == 1) {
                ans = "1" + ans;
                N = (N - 1) / (-2);
            }
            else {
                ans = "0" + ans;
                N = N / (-2);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
K=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a = int(input())-1
print(K[a])

Measured memory_bytes: 3060
if ARGV[0]=="LOCAL_DEV"
  define_method("debug") do |var|
    p var
  end
else
  define_method("debug") do
  end
end

N,Z,W = STDIN.gets.strip.split.map(&:to_i)
a = STDIN.gets.strip.split.map(&:to_i)
puts [(W-a[N-1]).abs , (a[N-2]-a[N-1]).abs].max


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  for(ll i=0;i<n;i++) {
    cin >> b[i];
  }
  for(ll i=0;i<n;i++) {
    cin >> c[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  
  vector<ll> bsum(n);
  for(ll i=0;i<n;i++) {
    ll ok=-1,ng=n;
    ll temp=(ok+ng)/2;
    while(ng-ok>1) {
      if(b[i]>=c[temp]) {
        ok=temp;
      }
      else {
        ng=temp;
      }
      temp=(ok+ng)/2;
    }
    bsum[i]=n-(ok+1);
  }
  for(ll i=n-2;i>-1;i--) {
    bsum[i]+=bsum[i+1];
  }
  ll ans=0;
  for(ll i=0;i<n;i++) {
    ll ok=-1,ng=n;
    ll temp=(ok+ng)/2;
    while(ng-ok>1) {
      if(a[i]>=b[temp]) {
        ok=temp;
      }
      else {
        ng=temp;
      }
      temp=(ok+ng)/2;
    }
    if(ok==n-1) continue;
    ans+=bsum[(ok+1)];
  }
  cout << ans << endl;
}

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

vector<int> par;
vector<int> RA;

void Re(int a){
  par.resize(a);
  RA.resize(a);
  for(int i=0;i<a;i++){
    par[i]=i;
  }
}
int root(int a){
  if(a==par[a]){
    return a;
  }
  else{
    return par[a]=root(par[a]);
  }
}
void UN(int a,int b){
  a=root(a);
  b=root(b);
  if(a==b){
    return;
  }
  else if(RA[a]<RA[b]){
    par[a]=b;
  }
  else{
    par[b]=a;
  }
  if(RA[a]==RA[b]){
    RA[a]++;
  }
}
int same(int a,int b){
  if(root(a)==root(b)){
    return 1;
  }
  else{
    return 0;
  }
}

int main() {
  int N,Q;
  cin>>N>>Q;
  Re(N);
  for(int i=0;i<Q;i++){
    int a,b,c;
    cin>>a>>b>>c;
    if(a){
      cout<<same(b,c)<<endl;
    }
    else{
      UN(b,c);
    }
  }
}

Measured memory_bytes: 4572
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

long long x=0;

int main(){
	int n;
	cin >> n;
	for(int i=n;i>0;i--){
		if(i==64){
			cout << i << endl;
			return 0;
		}
		if(i==32){
			cout << i << endl;
			return 0;
		}
		if(i==16){
			cout << i << endl;
			return 0;
		}
		if(i==8){
			cout << i << endl;
			return 0;
		}
		if(i==4){
			cout << i << endl;
			return 0;
		}
		if(i==2){
			cout << i << endl;
			return 0;
		}
		if(i==1){
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var S,T string
	_,_ = fmt.Scan(&S ,&T)
	var ans = 0
	for i := 0; i < 3; i++{
		if S[i] == T[i]{
			ans++
		}
	}
	fmt.Println(ans)

}


Measured memory_bytes: 1768
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let N = parseInt(input[0][0], 10);
	let v_A = input[1].map(e => parseInt(e, 10));
	let i = 0;
	while (v_A[i] != null){
		if (v_A[i] === v_A[i + 1]) {
			v_A.splice(i + 1, 1);
		} else {
			i ++;
		}
	}
	let upDown = 0;
	let tmpKabu;
	let tmpMoney = 1000;
	// console.log(v_A);
	for (let j = 0; j < v_A.length - 1; j++){
		// console.log("ud", upDown);
		if (v_A[j] < v_A[j + 1]) {
			if (upDown === 0){
				//buy at j
				tmpKabu = Math.floor(tmpMoney / v_A[j]);
				tmpMoney %= v_A[j];
				// console.log(tmpMoney, tmpKabu);
			}
			upDown = 1;
		} else {
			if (upDown === 1){
				//sell at j
				tmpMoney += tmpKabu * v_A[j];
				tmpKabu = 0;
				// console.log(tmpMoney, tmpKabu);
			}
			upDown = 0;
		}			
	}
	if (upDown === 1) tmpMoney += tmpKabu * v_A[v_A.length - 1]; //sell

	console.log(tmpMoney);
}


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


Measured memory_bytes: 29584
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,x,a;cin>>n>>x;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>a;vec[i]=a;
    }
    sort(all(vec));
    int ans=0;
    for(int i=0;i<n;i++){
        if(x<vec[i]){
            x=0;break;
        }
        else if(x>=vec[i]){
            ans++;
            x-=vec[i];
        }
    }
    if(x>0)ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#define maxn 200005
#define D 26
#define LL long long
int n,cnt[D];
char s[maxn];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++) cnt[s[i]-'a']++;
	LL ans=1ll*n*(n-1)/2;
	for(int i=0;i<D;i++) ans-=1ll*cnt[i]*(cnt[i]-1)/2;
	printf("%lld\n",ans+1);
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
    int a,i,n,min=1000001,max=-1000001;
    long long sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        if(a<min) min=a;
        if(a>max) max=a;
        sum+=a;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 2756
import numpy as np

d=int(input())
c=np.array(list(map(int,input().split())))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))
#lastd=[[0]*26 for _ in range(d)]
lastd=np.zeros(26)

ans=[0]*d
for i in range(d):  
  a=np.argmax(c*([i]*26-lastd))
  lastd[a]=i
  #print(a,i,c,lastd)
  ans[i]=a+1

for i in range(d):
  print(ans[i])

Measured memory_bytes: 27476
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

vec chikan(vec X, vec M){
    vec ret(M.size());
    for(int i=0;i<M.size();i++) {
        ret.at(i)=M.at(X.at(i));
    }
    return ret;
}

vec bekic(vec X, ll n){
    vec ret(X.size());
    rep(i,X.size()) ret.at(i)=i;
    
    while(n>0){
        if(n%2) ret=chikan(ret,X);
        X=chikan(X,X);
        n/=2;
    }
    return ret;
}

int main(){
    ll N; cin>>N;
    vec x(N);
    rep(i,N) cin>>x.at(i);
    ll M,K; cin>>M>>K;
    vec a(M);
    rep(i,M) cin>>a.at(i);
    rep(i,M) a.at(i)--;

    vec d(N);
    REP(i,1,N) d.at(i)=x.at(i)-x.at(i-1);
    vec P(N);
    rep(i,N) P.at(i)=i;
    rep(i,M) swap(P.at(a.at(i)),P.at(a.at(i)+1));
    P=bekic(P,K);
    d=chikan(P,d);
    d.at(0)=x.at(0);
    rep(i,N-1) d.at(i+1)+=d.at(i);
    rep(i,N) cout<<d.at(i)<<endl;

}

Measured memory_bytes: 7344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

ll n, k;
ll a[100100];

int main() {
	cin >> n >> k;
	ll MAX = 0, MIN = INF;
	rep(i, n) {
		cin >> a[i];
		MAX = max(a[i], MAX);
		MIN = min(a[i], MIN);
	}
	if (k > MAX || MIN > k) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	sort(a, a + n);
	ll mod = a[0];
	rep(i, n - 1) {
		if (a[i + 1] - a[i] != 0)mod = min(mod, a[i + 1] - a[i]);
	}
	bool f = 0;
	rep(i, n) {
		a[i] %= mod;
		if (k%mod == a[i])f = 1;
	}
	if (f)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final String N;

    public Main() {
	N = scan.next();
	scan.close();
    }

    public final void answer() {
	System.out.println(N.charAt(0) == N.charAt(2) ? "Yes" : "No");
    }
}


Measured memory_bytes: 23892
N = int(input())
T = [0] + [int(i) for i in input().split()]
M = int(input())
D = [[int(i) for i in input().split()] for j in range(M)]

for p,x in D:
  tmp = T[p]
  T[p] = x
  print(sum(T))
  T[p] = tmp

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<string.h>
int max(int a,int b){
   if(a>b) return a;
   return b;
}
int min(int a,int b){
   if(a<b) return a;
   return b;
}
void sort(char *a,int l){
    for(int i=0;i<l;i++){
       for(int j=i+1;j<l;j++){
          char t;
         if(a[i]>a[j]) {
            t=a[i];
            a[i]=a[j];
            a[j]=t;
         }

       }
    }


}

int main(){
    char a[100],b[1000];
    scanf("%s",a);
    int l=strlen(a),cnt=0;
    if(a[0]!='A') {
       printf("WA");
       return 0;
    }
    for(int i=1;i<l;i++){
       if(a[i]<'a') {
          if(i==1|| i==l-1 || a[i]!='C'){
             printf("WA"); return 0;
          }
          cnt++;
       }
    }
   if(cnt==1) printf("AC");
   else printf("WA");
}
   
   
   
   
   
   

Measured memory_bytes: 128
n=int(input())
s=list(str(input()))
m=len(s)
t=''
l='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(m):
    c=l.find(str(s[i]))
    if c+n>=26:
        t+=l[c+n-26]
    else:
        t+=l[c+n]
print(t)

Measured memory_bytes: 42220
#include <stdio.h>
#include <string.h>

int main () {
	int k;
	char s[101];
	scanf ("%d", &k);
	scanf ("%s", &s);
	int pnjg = strlen(s);
	if (pnjg<=k) {
		printf ("%s", s);
	} else {
		s[k] = '\0';
		printf ("%s...", s);
		
	}
	return 0;
}

Measured memory_bytes: 1676
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

ans = 0
c = ['3', '5', '7']
N = 0

def check(l):
    return len(set(l)) == 4

def nummaker(k, n):
    global ans
    if k == 0:
        q = int(''.join(n))
        if q > N:
            print(ans)
            sys.exit(0)
        if check(n):
            ans += 1
        return
    for i in c:
        m = n[:]
        m.append(i)
        nummaker(k-1, m)

def rec(x):
    # print(x)
    ans = 0
    c = int(x)
    if c > N:
        return 0
    if check(x):
        ans += 1
    # if ans == 1:
    #     print(x)
    for s in '357':
        ans += rec(x + s)
    return ans

def main():
    global N
    N = int(input().strip())
    print(rec('0'))
    # for i in range(1, 11):
        # nummaker(i, [])

if __name__ == '__main__':
    main()


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

int findDigits(int num)
{
    int digit = 0;
    while(num > 0)
    {
        num /= 10;
        digit++;
    }
    return digit;
}


int main()
{
    long long N;
    scanf("%lld", &N);

    int num_test = sqrt(N);
    int ans = N;
    for (int i = 1; i < num_test + 1; i++)
    {
        if (N % i == 0)
        {
            ans = findDigits(N / i);
        }
    }

    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)

using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
    Ryuga;
    
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("op.txt","w",stdout);
    // #endif    

    ll n,m;
    cin>>n>>m;
    ll ans=(n*(n-1))/2;
    ans+=(m*(m-1))/2;
    cout<<ans;
    // }
    
}//Goodbye...

Measured memory_bytes: 256
#include<bits/stdc++.h>
namespace ZDY{
#define fir freopen("2.in","r",stdin)
#define ll long long
#define db double
#define Fur(i,x,y) for(int i=x;i<=y;i++)
#define fur(i,x,y) for(i=x;i<=y;i++)
#define Fdr(i,x,y) for(int i=x;i>=y;i--)
#define in2(x,y) in(x),in(y)
#define in3(x,y,z) in2(x,y),in(z)
#define in4(a,b,c,d) in2(a,b);in2(c,d)
#define clr(x,y) memset(x,y,sizeof(x))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define fl(i,x) for(ll i=head[x],to;to=e[i].to,i;i=e[i].next)
#define inf 2147483647
}
namespace FAST{
#define pob (fwrite(fob::b,sizeof(char),fob::f-fob::b,stdout),fob::f=fob::b,0)
#define pc(x) (*(fob::f++)=(x),(fob::f==fob::g)?pob:0)
#define gc ((*fib::f)?(*(fib ::f++)):(fgets(fib::b,sizeof(fib::b),stdin)?(fib::f=fib::b,*(fib::f++)):-1))
namespace fib{char b[300000]= {},*f=b;}namespace fob{char b[300000]= {},*f=b,*g=b+300000-2;}struct foce{~foce(){pob;fflush(stdout);}} _foce;namespace ib{char b[100];}template<class T>inline void in(T &x){x=0;char c;bool f=0;while((c=gc)>'9'||c<'0')if(c=='-')f=!f;x=c-48;while((c=gc)<='9'&&c>='0')x=x*10+c-48;if(f)x=-x;}template<class T>inline void out(T x){if(x==0){pc(48);return;}if(x<0){pc('-');x=-x;}char *s=ib::b;while(x) *(++s)=x%10,x/=10;while(s!=ib::b) pc((*(s--))+48);}template<class T>inline void outn(T x){out(x);pc('\n');}
inline char sc(){char c=gc;while(!(('A'<=c&&c<='Z')||('a'<=c&&c<='z')||('0'<=c&&c<='9')))c=gc;return c;}
template<class T>inline T ABS(T x){return x>0?x:-x;}
template<class T>inline T MAX(T x,T y){return x>y?x:y;}
template<class T>inline T MIN(T x,T y){return x<y?x:y;}
template<class T>inline T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<class T>inline void swap(T x,T y){T t=x;y=t;x=y;}
}using namespace FAST;using namespace ZDY;using namespace std;
#define N 10001
int a,b,c;
int main(){
	in2(a,b);
	outn(!!(a%b));
}

Measured memory_bytes: 256
class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

N = gets.to_i

ans = 0

N.divisor_list.each do |x|
  next if x == 1

  a = N / x
  b = N % (x - 1)

  if a == b
    ans += (x - 1)
  end
end

puts ans


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

int main() {
  int h1, m1, h2, m2, k;
  cin >>h1 >>m1 >>h2 >>m2 >>k;
  cout << ( (h2-h1)*60 + (m2-m1) - k ) << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
const int mod = 998244353;
using namespace std;
int sum(int a, int b){
    if (a+b<0) return a+b+mod;
    if (a+b >= mod) return a+b-mod;
    return a+b;
}
int mult(int a, int b){
    return ((ll) a * (ll) b) % (ll) mod;
}
int pw(int a, int b){
    if (b==0) return 1;
    if (b==1) return a;
    if (b % 2 != 0) return mult(a, pw(a, b-1));
    int R = pw(a, b/2);
    return mult(R, R);
}
int dv(int a, int b){
    return mult(a, pw(b, mod-2));
}
vector<int> solve(vector<int> a, vector<int> b){
    if (a.size() == 1){
        if (a[0] == 0) return {0};
        return {dv(b[0], a[0])};
    }
    vector<int> a1, b1;
    for (int i=0; i < a.size()/2; i++){
        a1.push_back(sum(a[2*i], a[2*i+1]));
        b1.push_back(sum(b[2*i], b[2*i+1]));
    }
    vector<int> F = solve(a1, b1);
    a1.clear(), b1.clear();
    for (int i=0; i < a.size()/2; i++){
        a1.push_back(sum(a[2*i], -a[2*i+1]));
        b1.push_back(sum(b[2*i], -b[2*i+1]));
    }
    vector<int> S = solve(a1, b1);
    vector<int> res;
    for (int i=0; i < a.size()/2;i++){
        res.push_back(dv(sum(F[i], S[i]), 2));
        res.push_back(sum(F[i], -res.back()));
    }
    return res;
}
signed main()
{
    int n;
    cin >> n;
    vector<int> v((1<<n));
    for (int i=0;i<(1<<n);i++) cin >> v[i];
    int S = 0;
    for (int i=0; i < (1<<n); i++) S += v[i];
    for (int i=0;i<(1<<n);i++) v[i] = dv(v[i], S);
    v[0] = sum(v[0], -1);
    vector<int> res = {sum(pw(2, n), -1)};
    for (int i=0; i < (1<<n)-1; i++) res.push_back(sum(0, -1));
    vector<int> ans = solve(v, res);
    for (int i=(1<<n)-1; i >= 0; i--){
        ans[i] = sum(ans[i], -ans[0]);
    }
    for (int i=0;i<(1<<n);i++) cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 9716
import sys
sys.setrecursionlimit(10 ** 6)


class Tree:
    WHITE = 0
    GRAY = -1
    BLACK = 1

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def init(self):
        self.__init__(self.adj)

    def dfs(self, u):
        if self.colors[u] == self.BLACK:
            return

        self.colors[u] = self.GRAY
        self.depths[u] = self.depth

        for v, w in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.depth += w
                self.dfs(v)
                self.depth -= w

        self.colors[u] = self.BLACK


n = int(input())
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(q)]

adj = [[] for _ in range(n)]
for a, b, c in abc:
	a -= 1
	b -= 1
	adj[a].append([b, c])
	adj[b].append([a, c])

tree = Tree(adj)
tree.dfs(k-1)

for x, y in xy:
	x -= 1
	y -= 1
	ans = tree.depths[x] + tree.depths[y]
	print(ans)


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

using std::cin;
using std::cout;
using std::endl;
using std::sort;
using std::vector;

struct data
{
  int i;
  int A;
};

bool cmp(const data &a, const data &b)
{
  return a.A < b.A;
}

int
main()
{
  int N;
  cin >> N;
  vector<data> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i].A;
    A[i].i = i;
  }
  std::sort(A.begin(), A.end(), cmp);
  for (int i = 0; i < N; i++)
  {
    if (i != 0)
    {
      cout << ' ';
    }
    cout << A[i].i + 1;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        var A = cin.scanint.OrderByDescending(i => i).ToArray();
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (i % 2 == 0)
            {
                ans += A[i];
            }
            else
            {
                ans -= A[i];
            }
        }
        WriteLine(ans);

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11348