akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		char[] s = sc.next().toCharArray();

		int count = 0;

		int l = 0, r = s.length - 1;

		while (l < r) {
			if (s[l] == s[r]) {
				l++;
				r--;
			} else {
				if (s[l] == 'x') {
					count++;
					l++;
				} else if (s[r] == 'x') {
					count++;
					r--;
				} else {
					count = -1;
					break;
				}
			}
		}

		out.println(count);
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) return true;
		else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) return false;
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) return buffer[ptr++];
		return -1;
	}

	private boolean isPrintableChar(byte c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) throw new NoSuchElementException();
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}
}

Measured memory_bytes: 22868
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=tuple(map(int,input().split()))
    MAX=max(a)
    MIN=min(a)
    MAX_i=a.index(MAX)
    MIN_i=a.index(MIN)
    ans=[]
    if MAX>abs(MIN):
        for i in range(N):
            if i==MAX_i:
                continue
            ans.append((MAX_i,i))
        for i in range(N-1):
            ans.append((i,i+1))
    else:
        for i in range(N):
            if i==MIN_i:
                continue
            ans.append((MIN_i,i))
        for i in range(N-1,0,-1):
            ans.append((i,i-1))
    print(len(ans))
    for a in ans:
        print(a[0]+1,a[1]+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(a-1); i>=(b); i--)
#define qrep(i, q) for(auto i : q)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 100005;
const int logn = (log(maxn)/log(2))+5;
const int inf = 0x3f3f3f3f;
const ld eps = 1e-9;
const ll mod = 1e9+7;
char s[maxn];
ll dp[maxn][13];
void solve(int i){
	rep(j, 0, 13){
		int t = j*10+(s[i]-'0');
		dp[i][t%13] = (dp[i][t%13]+dp[i-1][j])%mod;
	}
}
int main()
{
	//std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
	scanf("%s", s+1);
	int n = strlen(s+1);
	dp[0][0] = 1;
	rep(i, 1, n+1){
		if(s[i] == '?'){
			rep(j, 0, 10){
				s[i] = (j+'0');
				solve(i);
			}
		}
		else{
			solve(i);
		}
	}
	cout << dp[n][5] << endl;
	return 0;
}


Measured memory_bytes: 10496
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans


template <typename T>
class BinaryIndexedTree {
    vector<T> data;
    int n;
    //
public:
    BinaryIndexedTree(int n_) : n(n_ + 2), data(n_ + 2, 0) {}
    T sum(int i) {
        T ret(0);
        for (int x = i + 1; x > 0; x -= x & -x)
            ret += data[x];
        return ret;
    }
    void add(int i, T a) {
        for (int x = i + 1; x <= n; x += x & -x) {
            data[x] += a;
        }
    }
};

int N, Q;


void solve() {
    BinaryIndexedTree<int> BIT(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        BIT.add(i, a);
    }
    while (Q--) {
        int a;
        cin >> a;
        if (a) {
            int l, r;
            cin >> l >> r;
            cout << BIT.sum(r - 1) - BIT.sum(l - 1) << endl;
        } else {
            int p, x;
            cin >> p >> x;
            BIT.add(p, x);
        }
    }
}

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

    cin >> N >> Q;

    solve();
    return 0;
}


Measured memory_bytes: 8232
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
T=[]
for a in A:
    T.append(a+1)
    T.append(a)
    T.append(a-1)
c=list(Counter(T).most_common())
c.sort(key=lambda x:x[1],reverse=True)
print(c[0][1])


Measured memory_bytes: 30932
# reply to https://atcoder.jp/contests/abc156/submissions/10292789
n, a, b = list(map(int, input().split()))

mod = 10**9 + 7

# x ** a をmodで割った余りを、O(log(a))時間で求める。
def power(x, a):
	if a == 0:
		return 1
	elif a == 1:
		return x
	elif a % 2 == 0:
		return power(x, a//2) **2 % mod
	else:
		return power(x, a//2) **2 * x % mod


# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
	return power(x, mod-2)

def binomial_coefficients2(n, k):
    ans = 1
    inv = 1
    for i in range(k):
        ans *= n-i
        inv = (inv * (i + 1)) % mod
        ans %= mod
    ans *= modinv(inv)
    return ans % mod

# (2 ** n - 1) - nCa - nCb
ans = power(2, n) - 1

ans -= (binomial_coefficients2(n, a) + binomial_coefficients2(n, b))
print(ans % mod)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x,t;
    cin>>n>>x>>t;
    int tot=0;
    int curr=0;
    while(1){
        if(curr>=n)
            break;
        curr=curr+x;
        tot+=t;
    }
    cout<<tot;
}

Measured memory_bytes: 3628
X, N = map(int, input().split())
p_s = list(map(int, input().split()))
 
p_s.sort()
ans = 0
tmp_diff = float('inf')
 
for num in range(-300,301):
    if(num not in p_s):
        diff = abs(X - num)
        if (diff < tmp_diff):
            ans = num
            tmp_diff = diff
            
print(ans)

Measured memory_bytes: 9100
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
    long[][] nums = new long[2*n][];//座標と種類
    long memo = 0;
    long multiplyMemo = 1;
    long answer = 1;
    long mod = 1000000007;
    for(long i = 0; i < n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = 0;
    }
    for(long i = n; i < 2*n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = 1;
    }
    Array.Sort(nums, (a, b) => a[0].CompareTo(b[0]));
    for(long i = 0; i < 2*n; i++)
    {
      if(nums[i][1] == 0)
      {
        memo++;
        if(memo > 1) answer *= Math.Abs(memo);
        answer %= mod;
      }
      else
      {
        memo--;
        if(memo < -1) answer *= Math.Abs(memo);
        answer %= mod;
      }
      //Console.WriteLine(answer);
    }
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)
  {
  long num = 2;
  long answer = 1;
  long check = a;
  long memo = x%p;
  
  while(check > 0)
    {
    if(check % num == num / 2)
      {
      check -= num / 2;
      answer *= memo;
      answer %= p;
      }
  memo *= memo;
  memo %= p;
  num *= 2;
    }
  return answer;
  }

static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数
  {
  long answer = DivideMod(x, p-2, p);
  return answer;
  }
  
}


Measured memory_bytes: 27472
#include <iostream>			//std::cout, std::cin
#include <string>			//std::string,std::to_string(C++11)
#include <vector>			//std::vector
#include <valarray>			//std::valarray
#include <algorithm>		//std::sort
#include <ctime>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs,std::pow,sqrt,sin,cos,round,floor,ceil
#include <fstream>			//std::ifstream,std::ofstream
#include <iomanip>			//std::setprecision,std::setw,std::setfill
#include <random>			//std::random(C++11)
#include <numeric>			//std::accumulate
#include <functional>		//std::greater
#include <chrono>			//std::chrono(C++11)
#include <bitset>			//std::bitset
#include <queue>			//std::queue

const static double	de_PI	= 3.14159265358979323846;
const static int	de_MOD	= 1000000007;
const static int	de_MAX	= 999999999;

double RoundOff(double a, const int n) {

	for (int i = 0; i < n - 1; i++) {	a *= 10;	}

	if (a > 0) {	a += 0.5;	}
	else {			a -= 0.5;	}

	a = static_cast<int>(a);

	for (int i = 0; i < n - 1; i++) {	a /= 10;	}

	return a;
}

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());
	//std::ofstream ofs("456.csv");
	//std::chrono::system_clock::time_point t_st = std::chrono::system_clock::now();

	double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
	std::vector<double> X, Y;

	while (std::cin >> a) {
		std::cin >> b >> c >> d >> e >> f;
		X.push_back(RoundOff((b*f - c*e) / (b*d - a*e), 4));
		Y.push_back(RoundOff((a*f - c*d) / (a*e - b*d), 4));
	}

	for (unsigned int i = 0; i < X.size(); i++) {
		std::cout << std::fixed << std::setprecision(3) << X[i] << " " << Y[i] << std::endl;
	}

	//std::chrono::system_clock::time_point t_ed = std::chrono::system_clock::now();
	//std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t_ed - t_st).count() << "ms" << std::endl;

}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define REP(i, d, n) for(int i=(d); i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    int n;
    cin >> n;

    vector<string> s(n);
    rep(i, n){
        cin >> s[i];
    }

    ll march[5] = {};
    rep(i, n){
        if(s[i][0] == 'M'){
            march[0]++;
        }
        else if(s[i][0] == 'A'){
            march[1]++;
        }
        else if(s[i][0] == 'R'){
            march[2]++;
        }
        else if(s[i][0] == 'C'){
            march[3]++;
        }
        else if(s[i][0] == 'H'){
            march[4]++;
        }
    }

    ll ans = 0;
    rep(i, 3){
        REP(j, i+1, 4){
            REP(k, j+1, 5){
                ans += march[i] * march[j] * march[k];
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x/500) *1000;
    ans += ((x%500) /5) *5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int K = Integer.parseInt(S[1]);
    
    int ans = 0;
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.next());
      if(n >= K){
        ans++;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 43992
N, M = [int(x) for x in input().split(" ")]
AB = [[int(x) for x in input().split(" ")] for _ in range(N) ]

AB = sorted(AB, key=lambda ab: ab[0])

costs = 0

for (a, b) in AB:
    if M < b:
        costs += a * M
        break
    else:
        costs += a * b
        M -= b

print(costs)


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

int main(){
  int N;
  bool P=false,W=false,G=false,Y=false;
  cin >> N;
  for(int i = 0;i<N;i++){
    string color;
    cin >> color;
    if(color == "P"){
      P = true;
    }else if(color == "W"){
      W = true;
    }else if(color == "G"){
      G = true;
    }else{
      Y = true;
    }
  }
  
  if(P && W && G && Y){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}

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

int main(void) {
    string S;
    ll total = 0;
    int i = 0;
    cin >> S;
    while(S[i])
    {
        total += S[i] - '0';
        i++;
    }
    
    if (total % 9 == 0)
        cout << "Yes";
    else
        cout << "No";
    
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
int dist[100005];
vector<int> edges[100005];

int dfs(int x){
    if(dist[x]>=0) return dist[x];

    int temp=0;
    for(auto j:edges[x]){
        temp=max(dfs(j)+1,temp);
    }
    dist[x]=abs(temp);
    return dist[x];
}
int main(){
    IOS
    int n,m;
    cin>>n>>m;
    fo(i,n+1) dist[i]=-1;
    int a,b;
    fo(i,m){
        cin>>a>>b;
        edges[a].pb(b);

    }
    FOR(i,1,n){
        if(dist[i]<0) dfs(i);
    }
    
    int ans=0;
    FOR(i,1,n) ans=max(ans,dist[i]);
    cout<<ans<<endl;



}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <string>
#include <cstdio>
#include <math.h>
using namespace std;

const long long int INF = 1000000007;

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

    long ans = 0;
    for (long a = 1; a < N; a++)
    {
        ans += N / a - ((N % a == 0)? 1 : 0);
    }

    cout << ans << endl;
}

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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)
#define MP(a, b) make_pair(a, b)

int main()
{
	long long a, b, ma, mi, res;
	cin >> a >> b;
	mi = min(a, b);
	ma = max(a, b);
	if (mi == 1) {
		if (ma == 1) res = 1;
		else res = ma - 2;
	} else {
		res = (mi-2) * (ma-2);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
A, B, N = map(int, input().split())

# def getmax(A,B,N):
#     x1 = max(B * (N//B) - 1, 0)
#     x2 = N

#     resx1 = int(A*x1/B) - A* int(x1/B)
#     resx2 = int(A*x2/B) - A* int(x2/B)

#     return max(resx1, resx2)

# print(getmax(A,B,N))

if N>=B:
    x = B-1
else:
    x = N
res = int(A*x/B) - A * int(x/B)

print(res)

Measured memory_bytes: 61744
#include <iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

struct point{
  int x,y;
};

bool cmp2(point p,point q){
  return p.x<q.x ;
}

bool cmp3(point p,point q){
  return p.y<q.y ;
}

point red[200],blue[200];
int chk[200],n;

int solve(){
  int ans=0;
  for(int i=0;i<n;i++){
    chk[i] = 0;
  }

  for(int i=n-1;i>=0;i--){
    for(int j=0;j<n;j++){
      if(blue[j].x>red[i].x&&blue[j].y>red[i].y&&!chk[j]){
        ans++;
        chk[j]=1;
        break;
      }
    }
  }
  return ans;
}

int main() {
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&red[i].x,&red[i].y);
  }
  for(int i=0;i<n;i++){
    scanf("%d%d",&blue[i].x,&blue[i].y);
  }
  int ans=0;
  sort(red,red+n,cmp3);
  sort(blue,blue+n,cmp2);
  ans = max(ans,solve());
  printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;



int main(void)
{
    int n;
    cin >> n;
    vector<int> x(n);

    rep(i, n) cin >> x[i];

    int ans = 1e9;

    rep(i, 100){
        int sum = 0;
        rep(j, n){
            sum += (i - x.at(j))*(i - x.at(j));
        }
        ans = min(ans, sum);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, C;
  cin >> N >> C;
  vec<vec<int>> T(N, vec<int>(3));
  REP(i, N) { cin >> T[i][1] >> T[i][0] >> T[i][2]; }
  sort(ALL(T));
  reverse(ALL(T));
  vec<vec<int>> lis;
  REP(i, N) {
    bool flg = false;
    int end = T[i][0];
    int begin = T[i][1];
    int channel = T[i][2];
    FORA(e, lis) {
      //  DEBUG(e[0]);
      if (e[1] == channel && end <= e[0]) {
        e[0] = begin;
        flg = true;
        break;
      } else if (e[1] != channel && end < e[0] - .5) {
        e[0] = begin;
        e[1] = channel;
        flg = true;
        break;
      }
    }
    if (!flg) {
      vec<int> tmp = {begin, channel};
      lis.pb(tmp);
    }
    //    DEBUG(i);
    //   DEBUG(begin);
    // DEBUG((int)lis.size());
  }
  print((int)lis.size());
}

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

const int INF = 1e9 + 1;

int N;
vector<int> a;
vector<vector<int>> neighbors;
vector<int> res;
vector<int> dp;

void dfs(int current, int parent = -1)
{
    vector<int>::iterator it = lower_bound(dp.begin(), dp.end(), a.at(current));
    int prev = *it;
    *it = a.at(current);

    res.at(current) = distance(dp.begin(), it) + 1;
    if (parent != -1)
    {
        res.at(current) = max(res.at(current), res.at(parent));
    }

    for (auto &&next : neighbors.at(current))
    {
        if (next == parent)
        {
            continue;
        }
        dfs(next, current);
    }

    *it = prev;
}

int main()
{
    cin >> N;
    a = vector<int>(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }
    neighbors = vector<vector<int>>(N, vector<int>());
    int ui, vi;
    for (int i = 0; i < N - 1; i++)
    {
        cin >> ui >> vi;
        ui--;
        vi--;
        neighbors.at(ui).push_back(vi);
        neighbors.at(vi).push_back(ui);
    }

    res = vector<int>(N);
    dp = vector<int>(N, INF);
    dfs(0);

    for (int i = 0; i < N; i++)
    {
        cout << res.at(i) << endl;
    }
}

Measured memory_bytes: 28012
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N):
    while N > 0:
        N -= 1000
    print(-N)


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    # As = [int(i) for i in input().split()]
    # Bs = [int(i) for i in input().split()]
    solve(N)


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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>
T _lcm_vector(vector<T> a) {
    T res = a[0];
    for (int i = 1; i < a.size(); i++) {
        res = _lcm(res, a[i]);
    }
    return res;
}

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

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

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    cout << _lcm_vector(a) << endl;
}

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

using namespace std;

struct node
{
	int u,v;
}b[20202];

int n,k,ret,ans,num;
vector <int> vec[20202];

void DFS(int x,int y,int deep)
{
	if(deep>k/2) ret++;
	for(int i=0;i<vec[x].size();i++)
	{
		int nxt=vec[x][i];
		if(nxt==y) continue;
		DFS(nxt,x,deep+1);
	}
}

int main()
{
	scanf("%d%d",&n,&k);ans=n;
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		b[i].u=x;b[i].v=y;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	if(!(k&1))
	{
		for(int i=1;i<=n;i++)
		{
			ret=0;DFS(i,-1,0);ans=min(ans,ret);
		}
	}
	else
	{
		for(int i=1;i<n;i++)
		{
			ret=0;
			DFS(b[i].u,b[i].v,0);
			DFS(b[i].v,b[i].u,0);
			ans=min(ans,ret);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 896
#define DEBUG(...)
/*                        Strip me down and go to town                        */
/*                          Lick me over upside down                          */
/*                     Pound and pound and pound and pound                    */
/*                        Baby make me make that sound                        */
/*                Aaah, aaah, aaah, aaah, aaaaaaaaaaaaaaaaaah!                */
#include<stdio.h>
#include<algorithm>
#include<utility>

using namespace std;

const int maxN = 200005;

pair<int,int> ar[maxN];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &ar[i].second, &ar[i].first);    
  }
  sort(ar, ar + n);
  int val = 1;
  for (int i = 0, tot = 0; i < n; i++) {
    tot += ar[i].second;
    if (tot > ar[i].first) {
      val = 0;
      break;
    }
  }
  printf("%s\n", val ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 1664
#include <set>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define sz(a) ((int) (a).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const int N = (int) 3e5 + 10;
int h, w, n, x, y;
vector<int> bad[N];

int main() {
	scanf("%d%d%d", &h, &w, &n);
	for (int i = 0; i < h; ++i) {
		bad[i].pb(0);
		bad[i].pb(w + 1);
	}
	for (int i = 1; i <= w; ++i) {
		bad[h + 1].pb(i);
	}
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &x, &y);
		bad[x].pb(y);
	}
	vector< pair<int, int> > good;
	good.pb(mp(1, 0));
	for (int x = 1; x <= h; ++x) {
		{
			for (int i = 0; i < sz(good); ++i) {
				good[i].sc = min(good[i].sc + 1, w);
			}
			vector< pair<int, int > > ngood;
			for (int i = 0; i < sz(good); ) {
				int j = i;
				while ((j + 1 < sz(good)) && (good[j + 1].fs == good[j].sc + 1)) {
					++j;
				}
				ngood.pb(mp(good[i].fs, good[j].sc));
				i = j + 1;
			}
			good = ngood;
		}
		{
			vector< pair<int, int> > ngood;
			sort(bad[x].begin(), bad[x].end());
			for (int i = 0, j = 0; i < sz(good); ++i) {
				int l = good[i].fs, r = good[i].sc;
				while (l <= r) {
					while ((j < sz(bad[x])) && (bad[x][j] < good[i].fs)) {
						++j;
					}
					if ((j < sz(bad[x])) && (bad[x][j] >= l) && (bad[x][j] <= r)) {
						if (l < bad[x][j]) {
							ngood.pb(mp(l, bad[x][j] - 1));
						}
						l = bad[x][j] + 1;
					} else {
						ngood.pb(mp(l, r));
						break;
					}
				}
			}
			good = ngood;
		}
		for (int i = 0; i < sz(bad[x + 1]); ++i) {
			int y = bad[x + 1][i];
			int it = (upper_bound(good.begin(), good.end(), mp(y, w)) - good.begin()) - 1;
			if ((it >= 0) && (good[it].fs <= y) && (y <= good[it].sc)) {
				printf("%d\n", x);
				return 0;
			}
		}
	}
	assert(false);
	return 0;
}


Measured memory_bytes: 14716
def bellman_ford(V, E, s, std):
  dist = [float('inf') for _ in range(V)]
  dist[s] = 0
  for i in range(V):
    for s, t, d in std:
      s -=1
      t -= 1
      d = -d
      if dist[t] > dist[s] + d:
        dist[t] = dist[s] + d 
        if i == V-1 and t+1 == V:
          return -1 
  return dist

def main():
  N, M = map(int, input().split())
  abc = [list(map(int, input().split())) for _ in range(M)]
  dist = bellman_ford(N, M, 0, abc)
  if dist == -1:
    print('inf')
    exit()
  else:
    print(-dist[N-1])

if __name__ == "__main__":
  main()

Measured memory_bytes: 3572
let n = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map(String.init).map { Int($0)! }

var acc = 0
var min = 0

for num in a {
  if min > num {
    acc = acc &+ (min - num)
  } else {
    min = num
  }
}

print(acc)


Measured memory_bytes: 21328
N=int(input())
A=list(map(int,input().split()))

b=0
X=0
K=0

for a in range(N):
    try:
        while X+A[b]==X^A[b]:
            X+=A[b]
            b+=1
    except:
        pass

    K+=b-a
    X-=A[a]

print(K)

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

int main() {
	int n;
	string s;
	cin >> n >> s;
	s += '#';
	int res = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] != s[i + 1])
			res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 512
a,b,c,x,y = map(int,input().split())

count = 0

ans1 = a*x + b*y
ans2 = 2*c*(min(x,y))
ans3 = 2*c*(max(x,y))

if x > y:
  ans2 += a*(x-y)
elif x < y:
  ans2 += b*(y-x)

print(min(ans1,ans2,ans3))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        200001
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--) 
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define MAXN		200001
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree1_order_statistics_node_update> 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll int n;
	cin >> n;
	ll int ans=(n)*(n-1)/2;
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int64 A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int64 ret;
  if (A + B < 2 * C) {
    ret = A * X + B * Y;
  } else {
    ret = 1LL << 60;
    for (int k = min(X, Y); k <= X || k <= Y; ++k) {
      int64 cur = k * C * 2 + max(0LL, X - k) * A + max(0LL, Y - k) * B;
      ret = min(ret, cur);
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

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

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll L[20];

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

  rep( i, N )
    std::cin >> L[i];

  std::sort( L, L+N );

  ll sum = 0;

  rep( i, N-1 )
    sum += L[i];

  std::cout << (L[N-1]<sum ? "Yes" : "No") << endl;

  return 0;
}

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

int main(){
    int N;cin>>N;
    int H[25];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=i;j++){
            if(H[i]<H[j]&&i!=j)break;
            else if(i==j){
                ans++;
                break;
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define DEBUG printf

int main() {
  long* box;
  box = (long*)calloc(100001, sizeof(long));
  long* duplicated_box = (long*)calloc(100000, sizeof(long));
  long duplicated_num = 0;
  long duplicated_sum = 0;
  long i,N, a;
  scanf("%ld%*c", &N);
  for (i = 0; i < N; i++) {
    scanf("%ld%*c", &a);
    box[a] += 1;
  }
  for (i = 1; i < 100001; i++) {
    if (box[i] > 1) {
      duplicated_box[duplicated_num++] = box[i] -1;
      duplicated_sum += box[i] -1;
    }
  }
  if (duplicated_sum % 2 == 0)
    printf("%ld\n", N - duplicated_sum);
  else
    printf("%ld\n", N - 1 - duplicated_sum);
  /* if (duplicated_num == 0) { */
  /*   printf("%ld\n", N); */
  /* } else if (duplicated_num == 1) { */
  /*   printf("%ld\n", N - duplicated_box[0] -1); */
  /* } else if (duplicated_num % 2 == 0) { */
  /*   for (i = 0; i < duplicated_num; i++) { */
  /*     N -= duplicated_box[i]; */
  /*   } */
  /*   printf("%ld\n", N); */
  /* } else { */
  /* } */
  free(box);
  free(duplicated_box);
  return 0;
}



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

int main() {
  string s;
  int n,a;
  cin>>a>>n;
  cin>>s;
  if(s[n-1]=='A') s[n-1]='a';
  if(s[n-1]=='B') s[n-1]='b';
  if(s[n-1]=='C') s[n-1]='c';
  cout<<s;
}


Measured memory_bytes: 256
from heapq import heappop, heappush

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

def dijkstra(graph, n, s):
    d = [float("inf")] * n
    d[s] = 0
    q = []
    heappush(q, (0, s))
    while q:
        dist, v = heappop(q)
        if d[v] < dist: continue
        for nv, cost in graph[v]:
            if d[nv] > d[v] + cost:
                d[nv] = d[v] + cost
                heappush(q, (d[nv], nv))
    return d

n = h*w+1
g = [list() for _ in range(n)]
for i in range(h):
    for j in range(w-1):
        cid = i*w + j
        g[cid].append((cid+1, int(s[i][j] == "." and s[i][j+1] == "#")))
for i in range(h-1):
    for j in range(w):
        cid = i*w + j
        g[cid].append((cid+w, int(s[i][j] == "." and s[i+1][j] == "#")))
g[n-1].append((0, int(s[0][0] == "#")))

print(dijkstra(g, n, n-1)[n-2])


Measured memory_bytes: 6260
#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 ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> 
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int long long
#define double long double
// mt19937 rnd(time(0));
// back to back like I'm Jordan 96 97
// const int MAXN = 1002;
const int INF = numeric_limits<int>::max() >> 2;
// const int MOD = (int)1e9 + 7;

signed main(){
  ios_base::sync_with_stdio(0); 
  cin.tie(0); 
  // freopen("FDT.txt","r",stdin);
  string s;
  cin >> s;
  for(char &c: s) if(c == '?') c = 'D';
  cout << s;
  return 0;
}


Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int ans=0;

		if(a>b)ans=0;
		else{
			if(b/a>=c)ans=c;
			else if(b/a<c)ans=b/a;
		}

		System.out.println(ans);
		sc.close();
	}
}



Measured memory_bytes: 22740
import sys
# from collections import deque
# import bisect
# import math
# import itertools
# from queue import deque
# from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)


N, M = inp_list()
X = inp_list()
X.sort()
# print(X)

if N >= M:
    print(0)
    exit()

d = [X[i + 1] - X[i] for i in range(M - 1)]
# for i in range(M - 1): d.append(X[i + 1] - X[i])
# print(d)
d.sort()
# ans = sum(d[: - (N - 1)])
ans = 0
for i in range(M - 1 -  (N - 1)):
    ans += d[i]
print(ans)


Measured memory_bytes: 13556
N,A,B = map(int,input().split())

def s(x):
  if x < 10:
    return x
  return x%10+s(x//10)

M = [0] * 37

for i in range(1,N+1):
  M[s(i)] += i
  
print(sum(M[A:B+1]))

Measured memory_bytes: 3064
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
char itoc(int i) { return i + '0'; };
int ctoi(char c) { return c - '0'; };
/*                    */

int main() {
  lint n;
  cin >> n;
  lint ans = 0;
  for (lint i = 1; i <= n; i++) {
    if ((i % 3 != 0) && (i % 5 != 0)) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main{
  public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int A=sc.nextInt();
int B=sc.nextInt();
if( A<=9 && B<=9){
  int c=A*B;
  System.out.println(c);
}else{
System.out.println("-1");
 }
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];

  vector<int> left(n+1), right(n+1);
  for(int i = 0; i < n; i++) left[i+1] = gcd(left[i], a[i]);
  for(int i = n-1; i >= 0; i--) right[i] = gcd(right[i+1], a[i]);

  int ans = 0;
  for(int i = 0; i < n; i++){
    int now = gcd(left[i], right[i+1]);
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
def use_fast_io():
    global input
    import io
    import sys
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline
use_fast_io()


from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = np.full((N, N), 10**10)
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1][t-1] = graph[t-1][s-1] = w
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0

Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(graph[s-1][t-1]) - 1)
print(*ans, sep='\n')


Measured memory_bytes: 18884
N = gets.chomp.to_i
restaurants = []
for i in 1..N do
    sp = gets.chomp.split(' ')
    sp[1] = sp[1].to_i
    sp          <<  i 
    restaurants << sp
end

restaurants.sort!{|a, b| (a[0] <=> b[0]).nonzero? || b[1] <=> a[1]}
restaurants.each do |sp|
    puts sp[2]
end





Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int N = GetInt();
		long[] csum = new long[N+1];
		for(int i = 1; i <= N; i++)
			csum[i] = GetLong();
		
		var num = new Dictionary<long, long>();
		num[0] = 1;
		for(int i = 1; i <= N; i++)
		{
			csum[i] += csum[i-1];
			long current = 0;
			num.TryGetValue(csum[i], out current);
			num[csum[i]] = current + 1;
		}

		long ans = 0;
		foreach(long key in num.Keys)
			ans += (num[key] * (num[key] - 1)) / 2;
		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 44000
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n,i,t;
	int w[100];
	scanf("%d", &n);

	for (i = 0; i < n; ++i)scanf("%d", &w[i]);

	int s1, s2, mini=1000000;

	for (t = 0; t < n - 1; t++) {
		s1 = s2 = 0;
		for (i = 0; i < n; ++i) {
			if (i <= t) {
				s1 += w[i];
			}
			else {
				s2 += w[i];
			}
		}
		if (mini > abs(s1 - s2)) {
			mini = abs(s1 - s2);
		}
	}

	printf("%d\n", mini);





}



Measured memory_bytes: 128
_ = gets
numbers = gets.chomp.split.map(&:to_i)

def halve_each(numbers)
  counter = 1
  if numbers.all? { |number| number % 2 == 0 }
    counter += halve_each(numbers.map { |number| number / 2 })
  end
  counter
end

puts halve_each(numbers) - 1


Measured memory_bytes: 3836
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAX 1000000

int main(){
	bool p[MAX+1];
	int num,answer;

	while ( scanf("%d" , &num) != EOF ){	
		p[0] = false;
		p[1] = false;
		for (int i=2 ; i<=MAX ; i++){
			p[i] = true;
		}
		answer = 0;

		for (int i=2 ; i<=sqrt(MAX)+1 ; i++){
			if (p[i]==1){
				for (int j=i*2; j<=MAX; j=j+i){
					p[j] = false;
				}
			}
		}

		for (int i=0; i<=num; i++){
			if (p[i]){
				answer++;
			}
		}
		printf("%d\n", answer);
	}
	return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/b.in", "r", stdin);
//  freopen("../IO/b.in", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int n,m,v,p;
  in >>n>>m>>v>>p;
  vector<int>a(n);
  for(int &i:a)in>>i;
  sort(a.rbegin(),a.rend());
  int lo = -1, hi = n;
  function<bool(int)> check=[&](int ind) {
    if (ind < p) return true;
    if (a[p - 1] > a[ind] + m) return false;
    int64_t cnt = (int64_t) m * (p - 1 + n - ind);
    for (int i = p - 1; i < ind; ++i) cnt += a[ind] + m - a[i];
    return cnt >= (int64_t) m * v;
  };
  while (hi - lo > 1) {
    int mid = lo+hi>>1;
    if (check(mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  out << lo + 1 << '\n';
}

Measured memory_bytes: 3696
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    from collections import deque

    s = input()
    s1 = deque([])
    s2 = deque([])
    sum_ = 0    # sumを変数名にすると、関数のsum()を使えなくなるので注意
    for i, ch in enumerate(s):
        if ch == '\\':   # \はエスケープ文字として機能してしまうので２連続で書く必要がある
            s1.append(i)
        elif ch == '/' and len(s1) > 0:
            j = s1.pop()
            sum_ += i - j
            a = i - j
            while len(s2) > 0 and s2[-1][0] > j:
                a += s2.pop()[1]
            s2.append([j,a])

    ans = []
    while len(s2) > 0:
        ans.append(s2.pop()[1])    # s2から水たまりの面積だけを取り出してansに入れる
    ans.reverse()                  # 順番反転
    print(sum(ans))
    ans.insert(0,len(ans))   # 先頭に水たまりの個数を挿入
    print(' '.join(map(str, ans)))



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

int main(){
 long long a,b,c,d;
cin>>a;
  c=0;
  d=0;
  for(int i=0;i<a;i++){
    cin>>b;
    if(b%2==0){
      c++;
    }
    else{
      d++;
    }
  }
 if(d%2==0){
   cout<<"YES"<<endl;
 }
  else{
    cout<<"NO"<<endl;
}
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 063 A / Link: http://abc063.contest.atcoder.jp/tasks/abc063_a  ----- */


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

	LL A, B; cin >> A >> B;
	if (A + B < 10)cout << A + B << endl;
	else cout << "error" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int l, r; cin >> l >> r;
  int d; cin >> d;
  int ans = 0;
  for (int x = l; x <= r; x++) {
    ans += (x % d == 0);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N;
    int a[1000];
    cin >> N;
    for(int i=0; i<N; i++)cin >> a[i];

    int flag = 1;
    for(int i=0; i<N; i++){
        if(a[i]%2==0){
            if(!(a[i]%3 == 0 || a[i]%5 == 0))flag = 0;  
        }
    }
    if(flag)cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,k,s;
vector<int>a;
main(){
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int b;cin>>b;a.push_back(b);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<k;i++)s+=a[n-i-1];
  cout<<s<<endl;
}

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

int main() {
#ifdef WIN32
	//freopen("input.txt", "rt", stdin);
#endif

	int x, y, z; cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z << endl;

	return 0;
}

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

using namespace std;


bool prime(int x){
    if(x == 1) return false;
    for (int i = 2; i*i<=x; i++)
    {
        if(x%i == 0) return false;

    }
     return true;
}
int main(){

    int x;

    cin>>x;

    int p = x;

    while (!prime(p)) p++;
    
        cout<<p<<"\n";
    return 0;
}

Measured memory_bytes: 256