akhauriyash/Code-Regression huggingface dataset:
list_in = list(map(int, input().split()))

num = list_in[0]
length = list_in[1]

list_str = [None] * num
list_flags = [0] * num

for i in range(num):
    list_str[i] = input()

result = ""
str = "xxxx"
for i in range(num):
    idx = -1
    for j, flag in enumerate(list_flags):
        if flag != 0:
            continue
        elif idx < 0 and flag == 0:
            str = list_str[j]
            idx = j
        else:
            tmp_str = list_str[j]
            if str > tmp_str:
                str = tmp_str
                idx = j

    result = ''.join([result, str])
    list_flags[idx] = 1

print(result)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back

void setIO(string s) 
{
	//ios_base::sync_with_stdio(0); cin.tie(0); 

	//freopen((s+".in").c_str(),"r",stdin);
	//freopen((s+".out").c_str(),"w",stdout);
}

void solve()
{
    int x; scanf("%lld", &x);
    if (x >= 30) puts("Yes");
    else puts("No");
}
signed main(void)
{
    //setIO("exercise");
    int T = 1; //scanf("%lld", &T);
    while(T--) solve();
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353
#define MEM_SIZE 101010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template <typename T>
void DEBUG(T e)
{
  if (DEBUG_OUT == false)
    return;
  std::cout << e << " ";
}
template <typename T>
void DEBUG(const std::vector<T> &v)
{
  if (DEBUG_OUT == false)
    return;
  for (const auto &e : v)
  {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void DEBUG(const std::vector<std::vector<T>> &vv)
{
  if (DEBUG_OUT == false)
    return;
  for (const auto &v : vv)
  {
    DEBUG(v);
  }
}
template <class T, class... Ts>
void DEBUG(T d, Ts... e)
{
  if (DEBUG_OUT == false)
    return;
  DEBUG(d);
  DEBUG(e...);
}
template <class T>
void corner(bool flg, T hoge)
{
  if (flg)
  {
    cout << hoge << endl;
    abort();
  }
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//BELOW

void solve(void)
{
  int res = 0;
  int x = 1;
  int n;
  cin >> n;
  vector<int> vec(n, 0);
  for (int i = 0; i < n; i++)
  {
    cin >> vec[i];
  }
  res += vec[0] - 1;
  x = 2;
  for (int i = 1; i < n; i++)
  {
    if (vec[i] == x)
    {
      x++;
    }
    res += (vec[i] - 1) / x;
  }
  cout << res << endl;

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a>k){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>

int main(void)
{
	int x,y;
	int a,b;

	while(1)
	{
	scanf("%d %d",&x,&y);

	if((x == 0)&&(y == 0))
	{
		break;
	}
		for(a = 0; a < x; a++)
		{
			for(b = 0; b < y; b++)
			{

				printf("#");
			}
		
		    printf("\n");
		  
		}
		printf("\n");
	
    
	}
	return 0;
}

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

int A, B;

int main() {
  cin >> A >> B;
  int temp = B - A;
  int original = 0;
  REP(i, temp) original += i+1;
  printf("%d\n", original - B);
  return 0;
}


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

int main() {
    string s;
    int q;
    cin >> s >> q;
    
    bool r = false;
    rep(i, q) {
        int query;
        cin >> query;
        if (query == 1) r = !r;
        if (query == 2) {
            int f;
            string c;
            cin >> f >> c;
            if ((!r && f == 1) || (r && f == 2)) s = c + s;
            if ((r && f == 1) || (!r && f == 2)) s += c;
        }
    }

    if (r) reverse(s.begin(), s.end());

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 4680
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;
using vi = vector<int>;

vi pinv(const vi &p) {
	vi res(sz(p));
	rep(i,0,sz(p)) res[p[i]]=i;
	return res;
}

vi pcompose(const vi &p,const vi &q) {
	vi res(sz(p));
	rep(i,0,sz(p)) res[i]=p[q[i]];
	return res;
}

vi ppow(vi p,int n) {
	vi res(sz(p));
	rep(i,0,sz(p)) res[i]=i;
	while (n>0) {
		if (n%2) res=pcompose(res,p);
		p=pcompose(p,p);
		n/=2;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,K;
	cin>>N>>K;
	K--;
	
	vi p(N),q(N);
	rep(i,0,N) {
		cin>>p[i];
		p[i]--;
	}
	rep(i,0,N) {
		cin>>q[i];
		q[i]--;
	}
	
	vi P=pinv(p);
	vi Q=pinv(q);
	
	vi a=ppow(pcompose(q,pcompose(P,pcompose(Q,p))),K/6);
	vi b;
	switch (K%6) {
		case 0:
			b=p;
			break;
		case 1:
			b=q;
			break;
		case 2:
			b=pcompose(q,P);
			break;
		case 3:
			b=pcompose(q,pcompose(P,Q));
			break;
		case 4:
			b=pcompose(q,pcompose(P,pcompose(Q,pcompose(p,Q))));
			break;
		case 5:
			b=pcompose(q,pcompose(P,pcompose(Q,pcompose(p,pcompose(p,Q)))));
			break;
		default:
			assert(false);
	}
	
	vi res=pcompose(a,pcompose(b,pinv(a)));
	rep(i,0,N) cout<<res[i]+1<<" \n"[i+1==N];
}


Measured memory_bytes: 4312
#include<iostream>
using namespace std;
long long n,sum1,sum2,sum3,sum4,sum5,ans;
char a[100006][200];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i][0]=='M')sum1++;
		if(a[i][0]=='A')sum2++;
		if(a[i][0]=='R')sum3++;
		if(a[i][0]=='C')sum4++;
		if(a[i][0]=='H')sum5++;
	}
	ans+=sum1*sum2*sum3;
	ans+=sum1*sum2*sum4;
	ans+=sum1*sum2*sum5;
	ans+=sum1*sum3*sum4;
	ans+=sum1*sum3*sum5;
	ans+=sum1*sum4*sum5;
	ans+=sum2*sum3*sum4;
	ans+=sum2*sum3*sum5;
	ans+=sum2*sum4*sum5;
	ans+=sum3*sum4*sum5;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 23104
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MOD 1000000007
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;

lli GCD(lli a, lli b) {
    while(a%b) {
        lli temp = b;
        b = a;
        a = temp%b;
    }
    return b;
}

lli LCM(lli a, lli b) {
    return a*b/GCD(a,b);
}

int main()
{
    lli i, a, b, c, d;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    a -= 1;
    lli ans = b-a;
    ans -= b/c;
    ans -= b/d;
    ans += b/LCM(c,d);
    ans += a/c;
    ans += a/d;
    ans -= a/LCM(c,d);
    printf("%lld\n",ans);
    // printf("GCD=%lld",LCM(4,8));
    return 0;
}


Measured memory_bytes: 128
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

bool s_sort(pair<string, int> p1, pair<string, int> p2){
    if(p1.fst != p2.fst){
        return p1.fst < p2.fst;
    }
    else {
        return p1.snd > p2.snd;
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<string, int>> s(n);
    REP(i, n){
        cin >> s[i].fst >> s[i].snd;
    }
    auto t = s;
    sort(ALL(s), s_sort);
    //cout << endl;
    map<pair<string,int>, int> mapping;
    REP(i, n){
        mapping.insert(make_pair(make_pair(t[i].fst, t[i].snd), i+1));
    }
    REP(i, n){
        cout << mapping.at(make_pair(s[i].fst, s[i].snd)) << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L D(L a){L d;Z[a]=1;
for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,!Z[d]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L a,L i){for(a=M(i++G i);i<1e5;i+=i&-i)B[i]+=a;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=n;
for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    vll a(3);
    rep(i,3)cin >> a[i];
    sort(all(a));

    ll cnt = 0;
    rep(i,2)if(a[i] == a[i+1])cnt++;

    if(cnt == 0 || cnt > 1)cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  ll x=1,y=1;
  REP(i,n){
    int xx,yy;cin>>xx>>yy;
    ll m=max((xx+x-1)/xx, (yy+y-1)/yy);
    x=m*xx;
    y=m*yy;
  }
  P(x+y);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;int A,B,C,X,Y;priority_queue <int,vector<int>,greater<int> > q;int main(){cin >> A >> B >> C >> X >> Y;q.push(A*X+B*Y);q.push(2*C*max(X,Y));if(X>Y)q.push((X-Y)*A+2*C*Y);else q.push((Y-X)*B+2*C*X);cout << q.top() << endl;}

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

const int maxn = 1e5 + 10;

namespace bigraph {
  int n, col[maxn];
  vector<int> g[maxn];

  void init(int _n) {
    n = _n;
    for(int i = 1; i <= n; i++) {
      g[i].clear(); col[i] = 0;
    }
  }

  void link(int x, int y) {
    g[x].push_back(y);
    g[y].push_back(x);
  }

  void dfs(int x) {
    for(int v : g[x]) {
      if(!col[v]) {
	col[v] = -col[x];
	dfs(v);
      } else {
	assert(col[v] != col[x]);
      }
    }
  }
  
  void color(void) {
    for(int i = 1; i <= n; i++) {
      if(!col[i]) {
	col[i] = 1;
	dfs(i);
      }
    }
  }
}

int ans[maxn];

struct tree {
  int n, root;
  vector<int> g[maxn];

  void init(int _n) {
    n = _n;
    for(int i = 1, x; i <= n; i++) {
      scanf("%d", &x);
      if(!~x) {
	root = i;
      } else {
	g[x].push_back(i);
      }
    }
  }

  int dfs(int x) {
    vector<int> cur;
    for(int v : g[x]) {
      cur.push_back(dfs(v));
    }
    for(int i = 0; i + 1 < cur.size(); i += 2) {
      bigraph::link(cur[i], cur[i + 1]);
    }
    if(cur.size() & 1) {
      ans[x] = 1;
      return cur.back();
    } else {
      return x;
    }
  }

  void solve(void) {
    dfs(root);
  }
}T[2];

int n;

int main(void) {
  scanf("%d", &n);
  bigraph::init(n);
  for(int i = 0; i < 2; i++) {
    T[i].init(n);
  }
  for(int i = 1; i <= n; i++) {
    if((T[0].g[i].size() ^ T[1].g[i].size()) & 1) {
      return puts("IMPOSSIBLE"), 0;
    }
  }
  for(int i = 0; i < 2; i++) {
    T[i].solve();
  }
  bigraph::color();
  puts("POSSIBLE");
  for(int i = 1; i <= n; i++) {
    printf("%d%c", ans[i] ? 0 : bigraph::col[i], " \n"[i == n]);
  }
  return 0;
}


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

int main(void){
    char s[100000];
    int n,k,i;

    scanf("%d",&k);
    scanf("%s",s);

    n=strlen(s);

    if(n<=k){
        printf("%s\n",s);
    }

    if(n>k){
        for(i=0;i<k;i++){
            printf("%c",s[i]);
        }
        printf("...\n");
    }

    return 0;
}

Measured memory_bytes: 3176
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int n, x;

	public static void main(String args[]) {

		// 組み合わせ数を記録するリスト
		ArrayList<Integer> CombinationsCount = new ArrayList<Integer>();
		// 入力と終了判定
		while (inputNums()) {
			CombinationsCount.add(SearchCombinations());
		}

		// 出力
		CombinationsCount.forEach(count -> System.out.println(count));

	}

	// 入力処理
	static boolean inputNums() {
		n = sc.nextInt();
		x = sc.nextInt();
		if (n == 0 && x == 0) {
			return false;
		} else {
			return true;
		}
	}

	// 組み合わせを探す
	static int SearchCombinations() {
		int a, // 1つ目の数
				b = 2, // 2つ目の数(ループの初期判定のために2で初期化)
				c = 3, // 3つ目の数(ループの初期判定のために3で初期化)
				count = 0; // 組み合わせ数
		for (a = 1; a < b; a++) { // aは最小値から徐々に+1していく

			for (b = a + 1; b < c; b++) { // bはa+1からc-1まで+1していく

				for (c = n; c > b; c--) { // cは最大値から徐々に-1していく

					if (a + b + c == x) { // a,b,cの合計がxかどうか

						count++; // 組み合わせが見つかったためカウントアップ
					}
				}
				c = n;
			}
		}
		return count;
	}

}



Measured memory_bytes: 31588
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	ll N;
	std::cin >> N;
	vll A(N + 1);
	map<ll, ll> cnt_p, cnt_m;
	set<ll> num;

	repeq(i, 1, N) {
		std::cin >> A[i];
		cnt_p[i + A[i]]++;
		cnt_m[i - A[i]]++;
		num.insert(i + A[i]);
		num.insert(i - A[i]);
	}

	ll ans = 0;
	for (auto itr = num.begin(); itr != num.end(); itr++) {
		ans += cnt_p[*itr] * cnt_m[*itr];
	}

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


Measured memory_bytes: 67340
/*
    A - Iroha and Haiku (ABC Edition)
    https://atcoder.jp/contests/abc042/tasks/abc042_a
*/

#include <iostream>

using namespace std;

#define ll long long
#define forn(i, s, n) for (int i = s; i < n; i++)
#define whilen(val, n) while(n-- && cin >> val)

int main() {
    int p;
    int phs[8] = {0};
    forn(i, 0, 3) {
        cin >> p;
        phs[p] += 1;
    }
    if (phs[5] == 2 && phs[7] == 1) cout << "YES";
    else cout << "NO";
    return 0;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
prime = 10 ** 9 + 7

def fact(x):
    a = []
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            j = 0
            while x % i == 0:
                x //= i
                j += 1
            a.append((i, j))
    if x != 1:
        a.append((x,1))
    return a


f = fact(m)
def kai(x):
    a = 1
    for i in range(a, x + 1):
        a *= i
        a %= prime
    return a

def conv(a, b):
    c = kai(b)
    c *= pow(kai(a), prime - 2, prime)
    c %= prime
    c *= pow(kai(b - a), prime - 2, prime)
    return c % prime


ans = 1
for i in f:
    ans *= conv(n - 1, n + i[1] - 1)
    ans %= prime
print(ans)


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

typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define mp make_pair

unordered_map<string, int> MP;
char s[20];
int n, len;

int main(){
    scanf("%d", &n);
    LL ans = 0;
    for(int i=0; i<n; i++){
        scanf("%s", s);
        len = strlen(s);
        sort(s, s+len);
        ans = ans + (MP[s]++);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 10660
fun main(args : Array<String>) {
    val ss = readLine()!!

    var aCnt = 0
    var ans = 0L
    var found = false

    for (i in 0..ss.length-2) {
        if (found) {
            found = false
            continue
        }

        if (ss[i] == 'A') {
            aCnt++
            continue
        }

        if (aCnt > 0 && ss[i] == 'B' && ss[i+1] == 'C') {
            ans += aCnt
            found = true
            continue
        }

        aCnt = 0
    }

    println(ans)
}

Measured memory_bytes: 32664
//
// Created by Knight_F on 2019-08-18.
//

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
vector <int> loc[26];
int main(){
    ios::sync_with_stdio(false);
    string a,b; cin>>a>>b;
    a=" "+a; b=" "+b;
    for(int i=1;i<a.size();i++){
        loc[a[i]-'a'].push_back(i);
    }
    int last=0,k=0;
    for(int i=1;i<b.size();i++){
        int x=b[i]-'a';
        if(loc[x].size()==0){
            cout<<-1;
            return 0;
        }
        if(loc[x][loc[x].size()-1]>=last){
            int l=0,r=loc[x].size()-1;
            while(l<r){
                int mid=(l+r)>>1;
                if(loc[x][mid]>=last) r=mid;
                else l=mid+1;
            }
            last=loc[x][l]+1;
        }
        else {
            k++;
            last=loc[x][0]+1;
        }
    }
    cout<<(long long)k*(a.size()-1)+(long long)last-1;
    return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> a(n);
    for (auto &e: a) cin >> get<0>(e) >> get<1>(e);
    for (int i = 0; i < n; ++i) {
        get<1>(a[i]) *= -1;
        get<2>(a[i]) = i;
    }
    sort(a.begin(), a.end());

    for (int i = 0; i < n; ++i) {
        cout << get<2>(a[i])+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cctype>

#define MAX_LEN (1200)

using namespace std;

int main()
{
    char* str = new char[MAX_LEN + 1];
    int*  counter = new int[26];
    int   lest = MAX_LEN;

    for (int i = 0; i < 26; i++) {
         counter[i] = 0;
    }
    
    while (cin.getline(str, lest)) {
           for (int i = 0; str[i] != '\0'; i++) {
                if (str[i] >= 'A' && str[i] <= 'Z') {
                    str[i] = tolower(str[i]);
                }
           

                if (str[i] >= 'a' && str[i] <= 'z') {
                    int num = str[i] - 'a';
                    counter[num]++;
                }
           }

           lest -= strlen(str);
    }

    for (int i = 0; i < 26; i++) {
         cout << (char)('a' + i) << " : " << counter[i] << endl;
    }

    delete[] str;
    delete[] counter;

    return (0);
}

Measured memory_bytes: 1164
/*
ID: y1197771
PROG: test
LANG: C++
*/
#include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
void solve() {
    ll x;
    while(cin >> x) {
    ll t = floor(sqrt(x * 2));
    if(t * (t + 1) / 2 < x) t++;
    cout << t << endl;
    }
}
int main() {
   // freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


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

bool is_prime(int x);

int main(){
    int n;
    cin >> n;
    int number[10000];
    for(int i = 0; i < n; i++){
        cin >> number[i];
    }
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(is_prime(number[i])) cnt++;
    }
    cout << cnt << endl;
}

bool is_prime(int x){
    if (x == 2){
        return true;
    }
    else if(x < 2 || x % 2 == 0){
        return false;
    }
    int i = 3;
    while(i <= pow(x, 0.5)){
        if(x % i == 0){
            return false;
        }
        i += 2;
    }   
    return true;
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n; cin >> n;

	vector <int> d(n);


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


	sort(d.begin(), d.end());


	cout << d[n / 2] - d[(n - 1) / 2] << endl;





	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int n,a,q,b,c;
int A[100001];

int main()
{
	cin >> n;
	int long long sum = 0;

	for (int i = 0; i < n; i++)
	{
		cin >> a;
		sum += a;
		A[a]++;
	}
	
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> b >> c;
		int num = A[b];
		A[b] = 0;
		A[c] += num;
		sum += (c - b)*num;
		cout << sum << endl;
	}
	return 0;
}



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

int main (){
    int n;
    cin >> n;
    
    long long a[n]={};
    cin >> a[0];
    for(int i=1; i<n; i++) {
        int j;
        cin >> j;
        a[i] = a[i-1] + j;
    }
    
    long long b[n] ={};
    cin >> b[0];
    for(int i=1; i<n; i++){
        int j;
        cin >> j;
        b[i] = b[i-1] + j;
    }
    
    long long c[n] = {};
  c[0] = b[n-1];
    for(int i=1; i<n; i++) c[i] = b[n-1]-b[i-1];
    
    long long ans=0;
    for(int i=0; i<n; i++){
        ans = ans > a[i] + c[i] ? ans: a[i] + c[i];
    }
    
    cout << ans;
}

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

using namespace std;
typedef long long ll;

ll a[maxn];

int main()
{
	ll n;
	cin >> n;
	ll sum =0;
	for(ll i=1;i<n;i++)
	{
		sum += i; 
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
N = int(input())
Q = [input().split() for _ in range(N)]
start = ''
end = ''

# Sの向きを定義1:前から0:後ろから
direct = 0
for i in range(N):
  if Q[i][0] =='1':
    direct^=1
  else:
    if direct == int(Q[i][1])-1:
      start += Q[i][2]
    else:
      end += Q[i][2]
      
ans = start[::-1]+S+end
print(ans) if direct == 0 else print(ans[::-1])

Measured memory_bytes: 40692
N, M = map(int, input().split())
As = []
Bs = []
for _ in range(N):
    a, b = map(int, input().split())
    As.append(a)
    Bs.append(b)
Cs = []
Ds = []
for _ in range(M):
    c, d = map(int, input().split())
    Cs.append(c)
    Ds.append(d)

ans = []
for i in range(N):
    a = As[i]
    b = Bs[i]
    dist = 5 * 10**8
    tmp = 1
    for j in range(M):
        c = Cs[j]
        d = Ds[j]
        if abs(a - c) + abs(b - d) < dist:
            dist = abs(a - c) + abs(b - d)
            tmp = j + 1
    ans.append(tmp)
    
print('\n'.join(list(map(str, ans))))

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1000000007;
const double PI = 3.14159;

using namespace std;


int main() {

    int n;
    cin >> n;
    
    vector<int> d[n];
    vector<int> anss;
    int yy, mm, dd;
    int kn;
    rep(i, n) {
        ll ans = 0;
        cin >> yy >> mm >> dd;

        if (yy % 3 == 0) {
            ans += (200 - ((mm - 1)*20 + dd - 1));
        } else {
            kn = (mm) / 2;
            //if (mm == 1) kn = 0;
            int fd = 20 * kn + 19 * (mm - 1 - kn) + dd - 1;
            ans += (195 - fd);
        }
        
        yy += 1;

        int ud = (999 - yy) / 3 + 1;
        if (yy == 1000) ud = 0;
        ans += (20*10 * ud);
        ans += (( 1000 - yy - ud)*195);
        
        anss.push_back(ans);
        //AA(ans);

    }
    rep(i, anss.size())
        AA(anss[i]);
}


Measured memory_bytes: 3056
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 2018-9-8 20:58:13
# Powered by Visual Studio Code
#

a, b = gets.chomp.split(" ").map{|i| i.to_i}
if a % 2 == 0 || b % 2 == 0
  puts "No"
else
  puts "Yes"
end

Measured memory_bytes: 1788
// Problem : B - Digits
// Contest : AtCoder Beginner Contest 156
// URL : https://atcoder.jp/contests/abc156/tasks/abc156_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define pb emplace_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inf LLONG_MAX
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        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);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

 vi fact,inv;
void inverse(int n)
{inv.resize(n+1);inv[0]=1;
for(int i=1;i<=n;i++)inv[i]=Pow(fact[i],md-2);}
void factorial(int n)
{fact.resize(n+1);fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%md;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,k;cin>>n>>k;
int count=0;
while(n!=0)
{
	n/=k;
	count++;
}
cout<<count;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
    solve();
}
}


Measured memory_bytes: 256
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf
    .trim()
    .split_whitespace()
    .map(|x| x.parse().ok().unwrap())
    .collect()
}

fn main() {
  let v: Vec<usize> = read_vec();
  let (n, m) = (v[0], v[1]);
  let lights: Vec<Vec<usize>> = (0..m).map(|_| read_vec()).collect();
  let ps: Vec<usize> = read_vec();

  let mut ans = 0;
  for i in 0..(2_u32.pow(n as u32)) as usize {
    let bits: Vec<char> = format!("{:010b}", i).chars().rev().collect();
    let mut all = true;
    for (j, light) in lights.iter().enumerate() {
      let mut cnt = 0;
      for &s in &light[1..] {
        if bits[s - 1] == '1' {
          cnt += 1;
        }
      }
      if cnt % 2 != ps[j] {
        all = false;
        break;
      }
    }
    if all {
      ans += 1;
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 4352
n = 6;
a = [input() for i in range(n)];
 
k = a[-1];
ans = "Yay!";
 
for i in range(n-1):
  for j in reversed(range(n-1)):
    if k < a[i] - a[j]:
      ans = ":( ";
      break;
print ans;

Measured memory_bytes: 2568
N = input()


def dfs(s=""):
    if s != "":
        if int(s) > int(N):
            return 0
    if (len(s) == s.count("7") + s.count("5") + s.count("3")) and (s.count("7") >= 1 and s.count("5") >= 1 and s.count("3") >= 1):
        ret = 1
    else:
        ret = 0
    for l in ["3", "5", "7"]:
        ret += dfs(s+l)

    return ret


print(dfs(""))


Measured memory_bytes: 3060
N=int(input())
S=input()
ans=0
i=0
j=N-1
while i<j:
  while i<N:
    if S[i]=='W':
      break
    else:
      i+=1
  while j>0:
    if S[j]=='R':
      break
    else:
      j-=1
  if i<j:
    ans+=1
    i+=1
    j-=1
print(ans)

Measured memory_bytes: 9320
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    S = [list(SS()) for _ in range(H)]

    left = [[0] * W for _ in range(H)]
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][j] == '.':
                cnt += 1
                left[i][j] = cnt
            else:
                cnt = 0

    right = [[0] * W for _ in range(H)]
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][W-1-j] == '.':
                cnt += 1
                right[i][W-1-j] = cnt
            else:
                cnt = 0

    up = [[0] * W for _ in range(H)]
    for i in range(W):
        cnt = 0
        for j in range(H):
            if S[j][i] == '.':
                cnt += 1
                up[j][i] = cnt
            else:
                cnt = 0

    down = [[0] * W for _ in range(H)]
    for i in range(W):
        cnt = 0
        for j in range(H):
            if S[H-1-j][i] == '.':
                cnt += 1
                down[H-1-j][i] = cnt
            else:
                cnt = 0

    ans = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            ans[i][j] = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3

    print(max([max(i) for i in ans]))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 392208
#pragma GCC optimize("O3")

#include<bits/stdc++.h>
#define sp " "
#define endl "\n"
#define MAX 10e9
#define MAXN 100001
#define mod 1000000007
#define inf_int 2e9
#define inf_ll 2e18
#define e 1e-9
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpl vector<pair<ll,ll>>
#define vpc vector<pair<char,char>>
#define adj_list vector<vl>
#define umap unordered_map<ll, ll>
#define pll pair<ll,pair<ll, ll>>
#define clr(x) memset(x,0,sizeof(x))
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define google cout << "Case #" << ++it << ": " << ans << endl;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long int ll;

ll it = 0, ans = 0;

ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (auto i=2; i<MAXN; i++)
  		spf[i] = i;
  	for (auto i=4; i<MAXN; i+=2)
        spf[i] = 2;
    for (auto i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (auto j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
	return;
}

vl getFactorization(ll x)
{
    vl ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}


void check()
{
	ll n;
	cin >> n;
	ll dp[n+1];
	clr(dp);
	dp[0] = 1;
	for(int i=3;i<=n;i++) {
		for(int j=0;j<i-2;j++) {
			dp[i] = (dp[i]+dp[j])%mod;
		}
	}
	cout << dp[n]%mod;
    return ;
}

int32_t main()
{
    fastio
    ll t = 1;
    // cin >> t;
    while(t--)
        check();
    return 0;
}


Measured memory_bytes: 3568
from collections import deque
def bfs(sl, visited, sy, sx, gy, gx, h, w):
    q = deque([[sy,sx]])
    visited[sy][sx] = 0
    while q:
        y, x = q.popleft()
        if [y, x] == [gy, gx]:
            return visited[gy][gx]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = y+j, x+k
            if ny >= h or nx >= w or ny < 0 or nx < 0:
                continue
            if sl[ny][nx] == '.' and visited[ny][nx] == -1:
                visited[ny][nx] = visited[y][x] + 1
                q.append([ny,nx])
    return -1


def main():
    h,w = map(int, input().split())
    sl = []
    white = 0
    for _ in range(h):
        row = list(input())
        white += row.count('.')
        sl.append(row)

    visited = [ [-1]*w for i in range(h)]
    bfs(sl, visited, 0, 0, h-1, w-1, h, w)
    dist = visited[h-1][w-1]
    if dist == -1:
        print(-1)
    else:
        ans = white - dist - 1
        print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 73348
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    long n,W;
    cin>>n>>W;
    vector<pair<ll,ll> >item(n+1);
    for(int i=1;i<=n;i++)
        cin>>item[i].first>>item[i].second;
    //sort(item.begin(),item.end());
    ll dp[n+1][W+1],mx=LONG_MIN;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=W;j++)
        {
            if(j<item[i].first)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-item[i].first]+item[i].second);
            if(i==n)
            mx=max(mx,dp[i][j]);
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int hundexp(int n)
{
    int x = 1;
    for(int i = 0; i < n; i++)
    {
        x *= 100;
    }
    return x;
}
int main ()
{
    int D, N; cin >> D >> N;
    if(N == 100)
    {
        cout << 101*hundexp(D) << endl;
    }
    else
    {
        cout << N*hundexp(D) << endl;
    }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc150/tasks/abc150_c

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> s(n), p(n), q(n);
    for (int i = 0; i < n; i++)
        s[i] = i + 1; // [1,2,3,...,N]
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int i = 0; i < n; i++)
        cin >> q[i];

    long pi, qi;
    long i = 0;
    do
    {
        if (s == p)
        {
            pi = i;
        }
        if (s == q)
        {
            qi = i;
        }
        i++;
    } while (next_permutation(s.begin(), s.end()));
    cout << abs(pi - qi) << endl;

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int count[9]={0};
  for(int i=0;i<n;i++){
    int t=min(8,a[i]/400);
    count[t]++;
  }
  int ans=0;
  for(int i=0;i<8;i++){
    if(count[i]){
      ans++;
    }
  }
  cout << max(ans,1) << " " << ans+count[8] << endl;
}


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

int main() {
  int N, order;
  
  // input
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i = 0;i < N;i++) {
    cin >> A.at(i);
    B.at(A.at(i)-1) = i+1;
  }
  
  // output
  for(int i=0;i<N;i++) {
    cout << B.at(i) << " ";
  }
  cout << endl; 
}


Measured memory_bytes: 1664
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let N = readInt()!
let T = readIntSplit(by: " ")
let M = readInt()!
let drink = (0..<M).map{_ in readIntSplit(by: " ")}

for i in 0..<M {
    var tmp = T
    tmp[drink[i][0]-1] = drink[i][1]
    print(tmp.reduce(0){$0+$1})
}


Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, c[500], s[500], f[500];
    cin >> n;
    imfor(i, n - 1) {
        cin >> c[i] >> s[i] >> f[i];
    }
    imfor(i, n) {
        int t = 0;
        for (int j = i; j < n - 1; j++) {
            if (t < s[j]) {
                t = s[j];
            }
            else {
                if (t % f[j] == 0) {

                }
                else {
                    t += f[j] - (t % f[j]);
                }
            }
            t += c[j];
        }
        cout << t << endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n = I()
if n == 1:
    print('Hello World')
else:
    a = I()
    b = I()
    print(a + b)


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

using namespace std;

string s;

int main()
{
    cin>>s;
    for(int i = 0 ; i < s.size() ; i++ )
    {
        if(s[i] == ',') cout<<" ";
        else cout<<s[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let c: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();

    let mut t: Vec<usize> = (0..n)
        .map(|_| iterator.next().unwrap().parse().unwrap())
        .collect();
    t.sort();

    let mut ans: usize = 0;

    let mut i: usize = 0;
    while i < t.len() {
        let start: usize = t[i];
        let mut count: usize = 1;

        while i + 1 < t.len() && t[i + 1] <= start + k && count < c {
            i += 1;
            count += 1;
        }

        ans += 1;
        i += 1;
    }

    return ans.to_string();
}


Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>

#define Inf             987654321
using namespace std;

typedef long long int   ll;
typedef pair<ll, ll>    pii;
typedef vector<ll>      vi;
typedef vector<vi>      vii;
typedef vector <vector<char> > vvc;
typedef vector <char> vc;
/*************************************************/

ll N, K, R, S, P, ans;
string T;

ll func(const vc& subT) {
    char temp = subT[0];
    int nsize = subT.size();
    ll cnt(0), ret(0);
    for (int i = 0; i < nsize; i++) {
        if (subT[i] == 0)
            break;

        if (subT[i] == temp)
            cnt++;
        else {
            if (temp == 'r')
                ret += (cnt / 2 + cnt % 2) * P;
            else if (temp == 's')
                ret += (cnt / 2 + cnt % 2) * R;
            else if (temp == 'p')
                ret += (cnt / 2 + cnt % 2) * S;
            else;
            //cout << "got" << ret << endl;
            temp = subT[i];
            cnt = 1;
        }
    }

    if (temp == 'r')
        ret += (cnt / 2 + cnt % 2) * P;
    else if (temp == 's')
        ret += (cnt / 2 + cnt % 2) * R;
    else if (temp == 'p')
        ret += (cnt / 2 + cnt % 2) * S;
    else;

    return ret;
}

void sol() {
    //분할
    vvc subT(K, vc(N/K + 1, 0));
    for (ll i = 0; i < N; i++) {
        if (T[i] == 'r')
            subT[i % K][i / K] = 'r';
        else if (T[i] == 's')
            subT[i % K][i / K] = 's';
        else if (T[i] == 'p')
            subT[i % K][i / K] = 'p';
        else
            ;
    }

    /*for (ll i = 0; i <= N % K; i++) {
        for (int j = 0; j <= N / K; j++) {
            cout << subT[i][j] << " ";
        }
        cout << endl;
    }*/

    ans = 0;
    for (ll i = 0; i < K; i++) {
        ans += func(subT[i]);
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    sol();


    return 0;
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    for (int i = A; i <= A*B; i = i + A) {
        if (i % B == C) {cout << "YES" << endl; return 0;}
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256