akhauriyash/Code-Regression huggingface dataset:
while 1:
    list = [input().split()]
    n = int(list[0][0])
    x = int(list[0][1])
    i = 1
    j = 2
    k = 3
    cnt = 0
    if n == 0 and x == 0:
        break
    while 1 :
        for i in range(i,n-1):
            for j in range(i+1,n):
                for k in range(j+1,n+1):
                    if x == i + j + k:
                        cnt += 1
                k += 1
            j += 1
        i += 1
        if n-1 <= i:
            print(cnt)
            break

Measured memory_bytes: 7720
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=110;
const double pi=acos(-1.0);
int n;
double x[maxn],y[maxn],t,ans;
double a,b,A,B;
int main() {
	//freopen("1.txt","r",stdin);
	//freopen("1.out","w",stdout);
	read(n);
	for (int i=1;i<=n;i++) {
		read(x[i]),read(y[i]);
	}
	int T=100000; srand(time(0));
	while (T--) {
		t=rand()%100000; t=t/100000.0; t*=2*pi;
		A=0; B=0;
		for (int i=1;i<=n;i++) {
			a=cos(t)*x[i]-sin(t)*y[i];
			b=sin(t)*x[i]+cos(t)*y[i];
			if (a>=0) A+=a,B+=b;
		}
		//printf("%.4lf %.4lf\n",A,B);
		ans=max(ans,A*A+B*B);
	}
	printf("%.13lf\n",sqrt(ans));
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
for _ in range(n):
    x, y = map(int, input().split())
    a.append((x, y))
a.sort(key = lambda x:x[1])
time = 0
flag = 0
for x in a:
    if time + x[0] <= x[1]:
        time += x[0]
    else:
        flag = 1
if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 31836
from fractions import gcd
a,b,c,d = map(int,input().split())
e = (c * d) // gcd(c, d)
x = b//c - (a-1)//c
y = b//d - (a-1)//d
z = b//e- (a-1)//e
print(b-a+1-(x+y-z))



Measured memory_bytes: 5304
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

class Point{
public:
	ll x,y;
};

int main(){
	init();
	string s,t;cin>>s>>t;
	reverse(s.begin(),s.end());
	reverse(t.begin(),t.end());
	bool isOK=false;
	for(int i=0;i+(ll)t.size()<=s.size();i++){
		string subS=s.substr(i,t.size());
		//cout<<subS<<endl;
		isOK=true;
		for(int j=0;j<subS.size();j++){
			if(subS[j]=='?')continue;
			if(subS[j]!=t[j])isOK=false;
		}
		if(isOK){
			for(int j=0;j<subS.size();j++){
				s[i+j]=t[j];
			}
			break;
		}
	}
	if(!isOK){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();i++){
		if(s[i]=='?')cout<<(char)'a';
		else cout<<s[i];
	}
	cout<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int ans = 1;
    int place = 0;
    int n,x;
    scanf("%d %d", &n, &x);
    for(int i = 0; i < n; i++){
    	int a;
        scanf("%d", &a);
        place += a;
        if(place <= x){
        	ans++;
        }
    }
    printf("%d",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

int n, m;
int ans = 0;
bool visited[10];
vector<vector<int>> graph;

void dfs(int from = 0, int pre = 0){
    int cur = pre | (1 << from);
    if(cur == (1 << n) - 1){
        ++ans;
        return;
    }

    visited[from] = true;
    for(int to : graph[from]){
        if(visited[to]) continue;
        dfs(to, cur);
    }
    visited[from] = false;

    return;
}

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

    cin >> n >> m;
    graph.resize(n);
    for(int i = 0; i < m; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs();
    cout << ans << endl;
}

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

#pragma GCC diagnostic warning "-Wconversion"

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;

vector<int> succ[100007];

int dfs(int i, int from)
{
        int res = 0;
        forc(next, succ[i])
        {
                if (next == from)
                        continue;
                res ^= dfs(next, i) + 1;
        }
        return res;
}

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

        int n;
        cin >> n;
        fora(i, n - 1)
        {
                int a, b;
                cin >> a >> b;
                succ[a].pb(b);
                succ[b].pb(a);
        }

        int res = dfs(1, 0);
        if (res == 0)
                cout << "Bob" << endl;
        else cout << "Alice" << endl;
}


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

	static class Kitana implements Comparable<Kitana> {
		int d=0, i=0; // Damage, index
		boolean w = false;
		Kitana (int a, boolean t) {
			d=a; w=t;
		}
		public int compareTo (Kitana other) {
			return other.d-d;
		}
		public String toString() {
			return "Damage: "+d+" Wield: "+w;
		}
	}

	static void solve() {
		Scanner sc = new Scanner(System.in);
		List<Kitana> k = new ArrayList<Kitana>();
		int N = sc.nextInt(), H = sc.nextInt(), D = 0, t = 0, c = 0;
		while (N-->0) {
			k.add(new Kitana(sc.nextInt(), true));
			k.add(new Kitana(sc.nextInt(), false));
		}
		Collections.sort(k);
		for (Kitana o : k) {
			if (!o.w) { t+=o.d; c++; }
			if (t>=H) break;
			if (o.w) {
				while (t+D<H) { D+=o.d; c++; }
				break;
			}
		}
		System.out.println(c);
		sc.close();		
	}

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

}

Measured memory_bytes: 67532
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo2[10004] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	cin >> s;
	if (s<="2019/04/30")
	{
		cout << "Heisei" << endl;

	}
	else
	{
		cout << "TBD" << endl;

	}

	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

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

int main() {
  int n,m;
  int ans=-1;
  int c=0;

  cin >> n >> m;

  int a;

  for(int i=0;i<m;i++) {
    cin >> a;
    c+=a;
  }

  if(n>=c) ans=n-c;

  cout <<ans<< endl;

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

int const MAXN = 4005;
char s[MAXN];
int sum[3][MAXN];

signed main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n; cin >> n;
  cin >> (s + 1);
  for (RI i = 1; i <= n; ++i)
    if (s[i] == 'R') ++sum[0][i];
    else if (s[i] == 'G') ++sum[1][i];
    else ++sum[2][i];
  for (RI i = 1; i <= n; ++i) {
    sum[0][i] += sum[0][i - 1];
    sum[1][i] += sum[1][i - 1];
    sum[2][i] += sum[2][i - 1];
  }
  int ans = 0;
  for (RI i = 1; i <= n; ++i)
    for (RI j = i + 1; j <= n; ++j)
      if (s[i] != s[j]) {
        int tmp = 'R' + 'G' + 'B' - s[i] - s[j];
        if (tmp == 'R') {
          ans += sum[0][i - 1];
          int dis = j - i;
          if (i - dis > 0 && s[i - dis] == 'R') --ans;
        }
        if (tmp == 'G') {
          ans += sum[1][i - 1];
          int dis = j - i;
          if (i - dis > 0 && s[i - dis] == 'G') --ans;
        }
        if (tmp == 'B') {
          ans += sum[2][i - 1];
          int dis = j - i;
          if (i - dis > 0 && s[i - dis] == 'B') --ans;
        }
      }
  cout << ans;

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 3696
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long V = sc.nextLong();
        long B = sc.nextLong();
        long W = sc.nextLong();
        long T = sc.nextLong();
        sc.close();

        if(W*T -V*T + Math.abs(B -A) <= 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  string S;cin>>S;
  int N;N=S.size();
  int K;cin>>K;
  set<string> dict;
  // 0~N-1
  REP(i,N) {
    // 1~N-i
    FOR(j,1,min(6,N-i+1)) {
      dict.insert(S.substr(i,j));
    }
  }
  vector<string> vec(ALL(dict));
  OUT(vec[K-1]);

  return 0;
}

Measured memory_bytes: 1792
INT_MAX = 10**8
h, n = map(int, input().split())
e = tuple(tuple(map(int, input().split())) for _ in range(n))

dp = [INT_MAX] * (h+1)
dp[0] = 0
for i in range(1, h+1):
  for a, b in e:
    c = dp[max(0, i - a)] + b
    dp[i] = min(dp[i], c)

print(dp[h])

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

int main(){
  int k, a, b; cin>>k >>a >>b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  
  cout<<"NG"<<endl;
  return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;

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

Measured memory_bytes: 256
N=input()
left=1
right=10**9

while left <= right:
	center = (left + right)/2
	x=(1+center)*center/2
	#print left,center,right,x,N
	if x==N:
		print center
		break
	elif x<N and abs(N-x)<center+1:
		print center+1
		break
	elif x<N:
		left=center+1
	else:
		right=center-1
else:
	print center+1

Measured memory_bytes: 2568
from collections import deque
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  l,r,d = map(int, input().split())
  l,r = l-1,r-1
  E[l].append((r,d))
  E[r].append((l,-d)) 
  
#for e in E:
#  print(e)
  
# bfs
Q = deque()
visited = [False] * N
willSearch = [False] * N
INF = 10**16
A = [ INF ] * N

for i in range(N):
  if visited[i]:
    continue
  Q.append((i,-1,0))
  while Q:
    now, prev, num = Q.popleft()
    visited[now] = True
    if A[now] == INF:
      A[now] = num
    elif A[now] != num:
      # ある点において2通りのnum設定の仕方がある
      #print(now,prev,num,A[inxt])
      print("No")
      exit(0)
    for nxt, dis in E[now]:
      if nxt == prev:
        continue
      if A[nxt] < INF and A[nxt] != num + dis:
        # ある点において2通りのnum設定の仕方がある
        #print(now,prev,num, nxt,dis, A[nxt])
        print("No")
        exit(0)
      if visited[nxt] or willSearch[nxt]:
        continue
      Q.append((nxt, now, num + dis))
      willSearch[nxt] = True
    
print("Yes")

Measured memory_bytes: 76428
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << (double)w*h / 2 << " " << (x * 2 == w && y * 2 == h) ? 1 : 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        String s = sc.next();
        int m = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '1') m++;
        }

        int[] maArr = new int[n + 1];
        int[] mbArr = new int[n + 1];
        maArr[0] = 1;
        mbArr[0] = 1;
        // 2のi乗の累積和的な
        for (int i = 0; i < n; i++) {
            maArr[i + 1] = (maArr[i] * 2) % (m + 1);
            if (m == 0 || m == 1) continue;
            mbArr[i + 1] = (mbArr[i] * 2) % (m - 1);
        }

        // 初期段階のmodそれぞれ
        int maMod = 0;
        int mbMod = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '1') {
                maMod = (maMod + maArr[n - i - 1]) % (m + 1);
                if (m == 0 || m == 1) continue;
                mbMod = (mbMod + mbArr[n - i - 1]) % (m - 1);
            }
        }

        int[] modArr = new int[m + 1];

        for (int bit = 1; bit < m + 1; bit++) {
            int count = 0;
            for (int i = 0; i < 20; i++) {
                if ((bit & (1 << i)) != 0) {
                    count++;
                }
            }
//            debug(bit, count);
            int index = bit % count;
            modArr[bit] = modArr[index] + 1;
        }

//        debug(modArr);

        for (int i = 0; i < n; i++) {
            int index;
            if (s.charAt(i) == '0') {
                index = (maMod + maArr[n - i - 1]) % (m + 1);
            } else {
                if (m == 1) {
                    out.println(0);
                    continue;
                }
                index = (mbMod - mbArr[n - i - 1] + (m - 1)) % (m - 1);
            }
            out.println(modArr[index] + 1);
        }

        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 53536
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)

	var W = make([]float64, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&W[i])
	}

	ans := math.Inf(0)
	for i := 0; i < N; i++ {
		var S1, S2 float64
		for j := 0; j < i; j++ {
			S1 += W[j]
		}
		for k := i; k < N; k++ {
			S2 += W[k]
		}
		ans = math.Min(math.Abs(S1-S2), ans)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main {
    private static int[] calcPrimes(int n) {
        boolean[] table = new boolean[n + 1];
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (!table[i]) {
                for (int j = i + i; j <= n; j += i) {
                    table[j] = true;
                }
            }
        }
        int counter = 0;
        for (int i = 2; i <= n; i++) {
            if (!table[i]) {
                counter++;
            }
        }
        int[] result = new int[counter];
        int index = 0;
        for (int i = 2; i <= n; i++) {
            if (!table[i]) {
                result[index++] = i;
            }
        }
        return result;
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        int[] primes = calcPrimes(200000);
        while (true) {
            int n = scanner.nextInt();
            int result = 0;
            if (n == 0) {
                break;
            }
            for (int i = 0; i < n; i++) {
                result += primes[i];
            }
            System.out.println(result);
        }
    }

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

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace Template
{
    public static class Scan
    {
        public static string NextLine => Console.ReadLine();
        public static int NextInt => int.Parse(NextLine);
        public static long NextLong => long.Parse(NextLine);
        public static double NextDouble => double.Parse(NextLine);
 
        public static string[] StrAry(char separator = ' ') => Console.ReadLine().Split(separator);
        public static int[] IntAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), int.Parse);
        public static long[] LongAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), long.Parse);
        public static double[] DoubleAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), double.Parse);
    }
 
    internal class Template
    {
        public static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
        private static void Fill<T>(T[] src, T value, int len) { for (int i = 0; i < len; i++) { src[i] = value; } }
 
        static void Solve() 
        {            
            var str = Scan.StrAry();
            int A = int.Parse(str[0]), B = int.Parse(str[2]);
            if (str[1][0] == '+')
            {
                Console.WriteLine(A + B);
            }else
            {
                Console.WriteLine(A - B);
            }
        }
        private static void Main()
        {
            Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main()
{
    string s, t;
    cin >> s >> t;
    vector<int> imoss;
    vector<int> imost;
    imoss.push_back(0);
    imost.push_back(0);
    rep(i, t.length())
    {
        if (t[i] == 'A')
        {
            imost.push_back(imost[i] + 1);
        }
        else
        {
            imost.push_back(imost[i] + 2);
        }
    }
    rep(i, s.length())
    {
        if (s[i] == 'A')
        {
            imoss.push_back(imoss[i] + 1);
        }
        else
        {
            imoss.push_back(imoss[i] + 2);
        }
    }
    int q;
    cin >> q;
    rep(i, q)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if ((imoss[b] - imoss[a - 1]) % 3 == (imost[d] - imost[c - 1]) % 3)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 1788
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(n: i32) -> i64 {
    n as i64 * (n-1) as i64 / 2
}

fn main() {
    input!{
        n: i32,
    }

    println!("{:?}", solve(n));
}


Measured memory_bytes: 4352
h, w, k = map(int, input().split())
s = [[i for i in list(map(int, list(input())))] for i in range(h)]

def solve(l):
    choco = [0 for _ in range(len(l))]
    ans = 0
    for i in range(w):
        f = True
        tmp = [0 for _ in range(len(l))]
        for idx, vs in enumerate(l):
            for v in vs:
                if s[v][i]:
                    tmp[idx] += 1
        for j in range(len(l)):
            if choco[j] + tmp[j] > k:
                f = False
        if not f:
            ans += 1
            choco = [0 for _ in range(len(l))]
        for idx, vs in enumerate(l):
            for v in vs:
                if s[v][i]:
                    if choco[idx] + 1 > k:
                        return 10 ** 9
                    choco[idx] += 1
    return ans + len(l) - 1


ans = 10 ** 9
for i in range(2 ** (h-1)):
    div = []
    tmp = []
    for j in range(h):
        tmp.append(j)
        if ((i >> j) & 1):
            div.append(tmp)
            tmp = []
    div.append(tmp)
    res = solve(div)
    ans = min(ans, res)
print(ans)


Measured memory_bytes: 53228
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int N=0,L=0;
      Scanner scanner = new Scanner(System.in);
      N = scanner.nextInt();
      L = scanner.nextInt();
      scanner.close();

      // if (L < 1 && L+N-1 > 0) {
      //    int sum=0;
      //    for (int i=0; i<N; i++) {
      //       sum = sum+(L+i);
      //    }
      //    System.out.println(sum);
      // } else {
         int min = 1000;
         int flag = 0;
         for (int i=0; i<N; i++) {
            if (Math.abs(L+i)<min) {
               min = Math.abs(L+i);
               if (L+i<0) {
                  flag = 0;
               } else {
                  flag = 1;
               }
            }
         }
         int sum=0;
         for (int i=0; i<N; i++) {
            sum = sum+(L+i);
         }
         //System.out.println(min);
         if (flag == 0) {
            sum = sum + min;
         } else{
            sum = sum - min;
         }
         //sum = sum - min;
         System.out.println(sum);
      //}

   }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    set<int> st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    if(st.size()==2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 3e5 + 111;
        
using namespace std;          

int n, mx;
string s[maxn];
map <string, int> ma;

void solve(){
	cin >> n;

    for (int i = 1; i <= n; i++){
    	cin >> s[i];
    	ma[s[i]]++;
    	mx = max(ma[s[i]], mx);
    }      	

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

    for (int i = 1; i <= n; i++){
    	if (ma[s[i]] == mx){
    		cout << s[i] << endl;
    		ma[s[i]] = 0;
    	}
    }
}                              
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n, d, a;
    cin >> n >> d >> a;
    vector<pair<Int, Int>> v(n);
    for (Int i = 0; i < n; i++) {
        cin >> v[i].fi >> v[i].se;
        v[i].se = v[i].se / a + (v[i].se % a == 0 ? 0 : 1);
    }
    sort(all(v));
    // for (Int i = 0; i < n; i++) {
    //     cout << v[i].se << " ";
    // }
    // cout << endl;
    Int res = 0;
    Int cur = 0;
    queue<pair<Int, Int>> q;
    for (Int i = 0; i < n; i++) {
        if (cur < v[i].se) {
            Int add = v[i].se - cur;
            res += add;
            cur = v[i].se;
            q.push({v[i].fi + 2 * d, add});
        }
        if (i < n - 1) {
            while ((not q.empty()) and q.front().fi < v[i + 1].fi) {
                cur -= q.front().se;
                q.pop();
            }
        }
        //cout << v[i].fi << " " << cur << " " << q.front().fi << endl;
    }
    dump(res);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc093() {
	ll ans = 0;

	V v(3);

	cin >> v[0] >> v[1] >> v[2];

	sort(ALL(v));

	while (1) {
		if (v[2] > v[0] && v[2] > v[1]) {
			v[0]++;
			v[1]++;
			ans++;
		}
		else if (v[2] == v[1]) {
			if (v[2] == v[0]) {
				break;
			}
			else {
				if ((v[2] - v[0]) % 2 == 0) {
					ans += (v[2] - v[0]) / 2;
					break;
				}
				else {
					ans += (v[2] - v[0] + 1) / 2 + 1;
					break;
				}
			}
		}
	}

	cout << ans << "\n";
}

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

	solve_abc093();

	return 0;
}

Measured memory_bytes: 768
//https://atcoder.jp/contests/abc161
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int k = in.nextInt();
        Queue<Long>  queue = new LinkedList<>();
        for (long i = 1; i <= 9; i++) {
            queue.add(i);
        }
        for (int i = 0; i < k-1; i++) {
            Long x = queue.poll();
            long lastDigit = x % 10;
            if (lastDigit != 0) queue.add(10 * x + lastDigit -1);
            queue.add(10 * x + lastDigit);
            if (lastDigit != 9) queue.add(10*x + lastDigit + 1);
        }

        out.println(queue.poll());
        out.close();

    }
}


Measured memory_bytes: 39380
import sys
input = sys.stdin.readline

N = [int(x) for x in input().rstrip()][::-1] + [0]
L = len(N)

dp = [[10 ** 18, 10 ** 18] for _ in range(L)]
dp[0] = [N[0], 10 - N[0]]

for i in range(1, L):
    n = N[i]
    dp[i][0] = min(dp[i - 1][0] + n, dp[i - 1][1] + (n + 1))
    dp[i][1] = min(dp[i - 1][0] + (10 - n), dp[i - 1][1] + (10 - (n + 1)))

print(dp[-1][0])

Measured memory_bytes: 140968
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define num(a) a-'0'
#define maxself(a,b) if(b>a)a=b
#define minself(a,b) if(b<a)a=b;
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define ln "\n"
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int h=1;
	rep(i,1,n){
		if(s[i]==s[i-1]){
		}
		else{
			h++;
		}
	}
	cout<<h<<ln;
}

int main(){
	boost_io;
	solve();
	return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	if(n==m){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,m,k,sum=0,a=0,b=0;
  long long mod = 1000000007;
  cin >> n;
  for (long long i=1;i<=n;i++){
    if(!(i%3 == 0 || i%5 == 0)) sum += i;
  }
  cout << sum << endl;
}



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

int main() {
  int n, s = 0;
  cin >> n;
  while ((n - s) % 4 != 0) {
    s += 7;
    if (s > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int h, a;

int main() { 

  cin >> h >> a;

  cout << (h + a - 1) / a << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    int N, M;
    cin>>N>>M;
    vector<pair<int, int> > ans(M);
    int tmp1, tmp2;
    map<int, int> amap;
    map<int, int> bmap;
    for(int i=0;i<M;++i){
        int yey1, yey2;
        yey1 = i+1;
        yey2 = N-i;
        tmp1 = yey2 - yey1 - 1;
        tmp2 = N - tmp1 - 2;
        while((amap[tmp1]>0) | (amap[tmp2]>0) | (bmap[yey1]>0) | (bmap[yey2]>0) | (tmp1==tmp2)){
            yey1++;
            yey1 %= N+1;
            tmp1 = N-i - yey1-1;
            tmp2 = N - tmp1 - 2;
        }
        ans[i] = make_pair(yey1, yey2);
        amap[tmp1]++;
        amap[tmp2]++;
    }
    for(int i=0;i<M;++i){
        cout<<ans[i].fi<<" "<<ans[i].se<<endl;
    }
}



Measured memory_bytes: 20556
#include<bits/stdc++.h>
using namespace std;
#define L long long
#define mx 100001
int main()
{
    L n,cs=1;
    while(scanf("%lld",&n)&&n){
        double x,y,x1,y1,x2,y2,area=0;
        scanf("%lf %lf",&x,&y);x1=x;y1=y;
        scanf("%lf %lf",&x2,&y2);
        area+=(((y1+y2)/2.0)*(x2-x1));x1=x2;y1=y2;
        for(L i=2;i<n;i++){
            scanf("%lf %lf",&x2,&y2);
            area+=(((y1+y2)/2.0)*(x2-x1));
            x1=x2;y1=y2;
        }
        x2=x;y2=y;
        area+=(((y1+y2)/2.0)*(x2-x1));
        printf("%lld %.1f\n",cs++,area);
    }


    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007
#define PI 3.1415926535

    int main(void)
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll cnt=0;

    int r=0,g=0,b=0,R[n], G[n], B[n];
    rep(i,n){
        if(s.at(i)=='R')
            r++;
        if (s.at(i) == 'G')
            g++;
        if (s.at(i) == 'B')
            b++;
        R[i] = r;
        G[i] = g;
        B[i] = b;
    }

    for (int i = 0; i < n - 2;i++){
        for (int j = i+1; j < n - 1;j++){
            if (s.at(i) == s.at(j))
                continue;
            int ji = j - i;

            if (s.at(i) == 'R' && s.at(j)=='G'){
                cnt += B[n - 1] - B[j];
                if (j + ji < n && s.at(j + ji) == 'B')
                    cnt -= 1;
            }
            if (s.at(i) == 'G' && s.at(j) == 'R'){
                cnt += B[n - 1] - B[j];
                if (j + ji < n && s.at(j + ji) == 'B' )
                    cnt -= 1;
            }
            if (s.at(i) == 'R' && s.at(j) == 'B'){
                cnt += G[n - 1] - G[j];
                if (j + ji < n && s.at(j + ji) == 'G' )
                    cnt -= 1;
            }
            if (s.at(i) == 'B' && s.at(j) == 'R'){
                cnt += G[n - 1] - G[j];
                if (j + ji < n && s.at(j + ji) == 'G' )
                    cnt -= 1;
            }
            if (s.at(i) == 'B' && s.at(j) == 'G'){
                cnt += R[n - 1] - R[j];
                if (j + ji < n && s.at(j + ji) == 'R' )
                    cnt -= 1;
            }
            if (s.at(i) == 'G' && s.at(j) == 'B'){
                cnt += R[n - 1] - R[j];
                if (j + ji < n && s.at(j + ji) == 'R' )
                    cnt -= 1;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define INF 100000000

int main()
{
    string S1,S2;
    int n,m;
    cin >> S1 >> S2;
    n=S1.size();m=S2.size();
    vector<vector<int>> dp(n+1,vector<int> (m+1,0));
    dp[0][0]=0;
    for (int i=1;i<n+1;i++) dp[i][0]=i;
    for (int i=1;i<m+1;i++) dp[0][i]=i;
    for (int i=1;i<n+1;i++)
    {
        for (int j=1;j<m+1;j++)
        {
            if (S1[i-1]==S2[j-1])
            {
                dp[i][j]=min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]});
            }
            else
            {
                dp[i][j]=min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+1});
            }            
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

const int N = 1010;
int n;
ll in[N][2];
vector<ll> segments;
vector<string> ans;
int main() {
  cin.tie(0); cin.exceptions(cin.failbit);
  scanf("%d", &n);
  rep(i, 0, n){
    scanf("%lld%lld", &in[i][0], &in[i][1]);
  }

  ll mod2 = abs((in[0][0] + in[0][1])%2);
  bool possible = true;

  // check that they all have same parity
  rep(i,1, n){
    if(abs((in[i][0] + in[i][1])%2) != mod2){
      possible = false;
      break;
    }
  }

  if(possible){
    if(mod2 == 0){
      segments.PB(1);
    }
    rep(i, 0, 31){
      segments.PB(1LL << i);
    }
    rep(i, 0, n){
      ll x = in[i][0], y = in[i][1];

      int num_segs = sz(segments);
      ll sum = (1LL << 31) - mod2;
      string s("");
      for(int j = num_segs-1; j >= 0; j--){
        sum -= segments[j];
        if(abs(x - segments[j]) + abs(y) <= sum) {
          s += 'R';
          x -= segments[j];
        } else if(abs(x + segments[j]) + abs(y) <= sum){
          s += 'L';
          x += segments[j];
        } else if(abs(x) + abs(y - segments[j]) <= sum){
          s += 'U';
          y -= segments[j];
        } else {
          s += 'D';
          y += segments[j];
        }
      }

      reverse(s.begin(), s.end());
      ans.PB(s);
    }

    printf("%d\n", sz(segments));
    trav(l, segments){
      printf("%lld ", l);
    }
    puts("");

    trav(s, ans){
      cout << s << endl;
    }

  } else{
    puts("-1");
  }
}


Measured memory_bytes: 512
#include <stdio.h>
#define N 500000
#define INFTY 999999999

void mergesort(int *,int,int);
void merge(int *,int,int,int);

int count = 0;
 
int main()
{
  int n,i,A[N];
 
  scanf("%d",&n);

  for( i = 0; i < n; i++)

    scanf("%d",&A[i]);
 
  mergesort(A,0,n);
 
  for(i = 0; i < n - 1; i++)
      printf("%d ",A[i]);

      printf("%d\n%d\n",A[n - 1],count);
   
  return 0;
}
 
void mergesort(int *A,int left,int right){
  int mid;
 
  if(left + 1 < right)
    {
      mid=(left+right)/2;
      mergesort(A,left,mid);
      mergesort(A,mid,right);
      merge(A,left,mid,right);
    }
}
 
void merge(int *A,int left,int mid,int right)
{
  int n1 = mid - left;
  int n2 = right - mid;
  int i,j,k;
  int L[N],R[N];
 
  for(i = 0; i < n1; i++)
    L[i] = A[left + i];

  for(i = 0; i < n2; i++)
    R[i] = A[mid + i];

  L[n1] = INFTY;
  R[n2] = INFTY;

  i=0;
  j=0;

  for(k = left; k < right;k++)
    {
      count++;

    if(L[i] <= R[j])
      {
	A[k] = L[i];
	i++;
      }

    else
      {
	A[k] = R[j];
	j++;
      }
    }
}

Measured memory_bytes: 5584
#include <cstdio>

typedef long long int ll;

int n, x, y, flagX, flagY, curX,  curY;
ll k, positive, negative;

int main() {
    scanf("%lld%d%d", &k , &x, &y);
    flagX = (x < 0) ? -1 : 1;
    flagY = (y < 0) ? -1 : 1;
    x *= flagX;
    y *= flagY;
    if (k % 2 ==0 && (x + y) & 1)
        printf("-1");
    else {
        if (k == x + y)
            n = 1;
        else {
            n = 2;
            while (n * k < x + y || (n * k - x - y) & 1) {
                ++n;
            }
        }
        positive = (n * k + x + y) >> 1;
        negative = (n * k - x - y) >> 1;
        printf("%d\n", n);
        while(n --) {
            if (negative) {
                if (negative >= k) {
                    if (x - curX <= y - curY)
                        curX -= k;
                    else
                        curY -= k;
                    negative -= k;
                }
                else {
                    if (x - curX <= y - curY) {
                        curX -= negative;
                        curY += (k - negative);
                    }
                    else {
                        curY -= negative;
                        curX += (k - negative);
                    }
                    negative = 0;
                }
            }
            else {
                if (curX < x) {
                    if (x - curX >= k)
                        curX += k;
                    else {
                        curY += (k - (x - curX));
                        curX = x;
                    }
                }
                else {
                    if (y - curY  >= k)
                        curY += k;
                    else
                        curY = y;
                }
            }
            printf("%d %d\n", curX * flagX, curY * flagY);
        }
    }
    return 0;
}

Measured memory_bytes: 2176
import sys
input = sys.stdin.readline

if __name__ == '__main__':
  n=int(input())
  D=[0]*n
  A=[]

  def h1(x):
    return x%n

  def h2(x):
    return 1+x%(n-1)

  def h(x,i):
    return h1(x)+i*h2(x)

  def insert(x):
    i=0
    k=0
    while True:
      k=h(x,i)%n
      if D[k]==0:
        D[k]=x
        return k
      elif D[k]==x:
        return k
      i+=1

  def find(x):
    i=0
    k=0
    while i<n:
      k=h(x,i)%n
      if D[k]==x:
        return True
      elif D[k]==0:
        return False
      i+=1
    return False


  def getKey(X):
    res=''
    for x in X:
      if x=='A':
        res+='1'
      elif x=='C':
        res+='2'
      elif x=='G':
        res+='3'
      elif x=='T':
        res+='4'
    return int(res)

  for _ in range(n):
    c,x=input().strip("\n").split()
    #x=x.replace('A','1').replace('C','2').replace('G','3').replace('T','4')
    #x=int(x)
    x=getKey(x)
    if c=='insert':
      insert(x)
    else:
      A.append(find(x))
  for ans in A:
    print('yes' if ans else 'no')



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

int main(){
    int r,g,b,n,temp,ans=0;
    cin>>r>>g>>b>>n;
    for(int i=0;i<=n/r;i++){
        for(int j=0;j<=n/g;j++){
            temp=n-i*r-j*g;
            if(temp<0){break;}
            if(temp%b==0){ans++;}
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;



int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    int n=0;
    int len = a>b?b:a;

    
        for(int i=len;i>0;i--){
            if(a%i==0 && b%i==0)++n;
            if(n==k){cout<<i;break;}
        }
    
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
Module Program
  Sub Main
    Dim s=GetInts()(0)
    Dim t=GetInts()(0)
    Dim ans=If(t<s Mod 500,"No","Yes")
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long

#ifdef sarthak
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#else
#define trace(...)
#endif

#ifndef sarthak
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fort(i,v) for(auto i:v)
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) rep(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) rep(i,sizeof(ar)/sizeof(ar[0])) rep(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%d %d",&x,&y)
#define slld2(x,y) scanf("%lld %lld",&x,&y)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pd2(x,y) printf("%d %d\n",x,y)
#define plld2(x,y) printf("%lld %lld\n",x,y)
#define all(ar) ar.begin(), ar.end()
#define endl '\n'
#define sz(x) (int)x.size()
#define len(x) (int)x.length()

typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

vector<string> v;
ll n;
string s = "";

void recur(ll in, ll now)
{
    if(in==n)
    {
        v.pb(s);
        return;
    }

    fr(i,0,now)
    {
        char c = 'a' + i;
        s.pb(c);
        recur(in+1,max(now,i+1));
        s.pop_back();
    }
}

void solve()
{
    cin >> n;
    recur(0,0);
    for(auto vv:v)
    {
        cout << vv << endl;
    }    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed;
    cout << setprecision(10);
    #ifdef sarthak
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }

    #ifdef sarthak
    cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    #endif
}


Measured memory_bytes: 9716
from collections import defaultdict

N = int(input())
S = [list(input()) for i in range(N)]

d = defaultdict(int)

for s in S:
    s.sort()
    s = "".join(s)
    d[s] += 1

ans = 0

for key in list(d):
    ans += d[key] * (d[key] - 1) // 2

print(ans)


Measured memory_bytes: 39428