akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define     debug       printf("\n<<CameHere<<\n")
#define     mem(x,y)    memset(x, y, sizeof(x))
#define     all(qz)     qz.begin(),qz.end()
#define     rall(qz)    qz.rbegin(),qz.rend()
#define     inf         LLONG_MIN
#define     INF         LLONG_MAX
#define     mod         1000000007
#define     Sqr(x)      ((x)*(x))
#define     ll          long long
#define     mk          make_pair
#define     pb          push_back
#define     pi          acos(-1.0)
#define     cos(a)      cos(a*pi/180)
#define     sin(a)      sin(a*pi/180)
#define     tan(a)      tan(a*pi/180)

ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/
#define mx 10000009
ll ar[mx+100];

void fn(){
    for(ll i=2;i<=mx/2;i++){
        for(ll j=i*2;j<=mx;j+=i){
            ar[j]++;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);



    fn();
    ll n;
    cin>>n;
    ll cnt=1;
    for(ll i=2;i<=n;i++){
        cnt+=(i*(ar[i]+2));
    }
    cout<<cnt<<endl;
    return 0;
}



















Measured memory_bytes: 81768
n,k = map(int,input().split())
xi = [int(i) for i in input().split()]
ans = min(abs(xi[0])+abs(xi[0]-xi[k-1]),abs(xi[k-1])+abs(xi[k-1]-xi[0]))
for i in range(1,n-k+1):
  ans = min(ans,abs(xi[i])+abs(xi[i]-xi[k-1+i]),abs(xi[k-1+i])+abs(xi[k-1+i]-xi[i]))
print(ans)

Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, zero = 0;
	vector<int> a;
	map<int,int> mp;
	cin>>N;
	
	a.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
		if(!a[i]) zero++;
		mp[a[i]]++;
	}
	
	if(zero == N){
		cout<<"Yes"<<endl;
	} else if(N%3){
		cout<<"No"<<endl;
	} else if(mp.size() == 2){
		if(mp[0] == N/3) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	} else if(mp.size() == 3){
		int Xor = 0;
		for(pair<int,int> p : mp){
			Xor ^= p.first;
			if(p.second != N/3){
				cout<<"No"<<endl;
				return 0;
			}
		}
		if(Xor) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	} else {
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cerr << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
constexpr int mxN = 1e5;
int dp[mxN];
void solve(){
    int n;
    read(n);
    vi h(n);
    REP(i,n) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n ; i++){
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[n-1] << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



Measured memory_bytes: 3964
n,m = [int(i) for i in input().split()]
a = [0 for j in range(n)]
b = [0 for i in range(m)]
c = [0 for i in range(n)]
for i in range(n):
    a[i] = [int(i) for i in input().split()]
for i in range(m):
    b[i] = int(input())
for i in range(n):
    c[i] = sum([a[i][j]*b[j] for j in range(m)])
for i in range(n):
    print(c[i])


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

int main ()
{
    string  s ;
    cin >> s;
    reverse(s.begin(),s.end()) ; 
    map <int,int> c;
    int  ss=0,ans=0,cur=1;
    c[0] = 1 ; 
    for (int i=0;i<s.size();i++){
        ss = (ss+((s[i]-'0')*cur))%2019;
        ans += c[ss] ; 
        c[ss]++ ; 
        cur = (cur*10)%2019; 
    }
    cout << ans << endl ; 
    return 0;
}


Measured memory_bytes: 3612
S = str(input())
S = S[::-1]
moji = ["maerd", "esare", "remaerd", "resare"]
i = 0
while i < len(S):
    answer = False
    for j in range(4):
        if S[i:i+len(moji[j])] == moji[j]:
            i += len(moji[j])
            answer = True
    if not answer:
        print("NO")
        break
if answer:
    print("YES")


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(0, c-(a-b)) << endl;
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

int f(int x) {
    int ans = 0;
    if(x == 0) return 0;
    while(x > 0) {
        x %= __builtin_popcount(x);
        ans ++;
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int mod1 = 0, mod0 = 0;
    int bitset = 0;
    int p0[n + 1]{};
    int p1[n + 1]{};

    for(auto x: s) {
        bitset += (x == '1');
    }
    reverse(s.begin(), s.end());
    if(bitset != n) {
        int p2 = 1;
        int mod = bitset + 1;
        for(int i = 0; i < n; i++) {
            p1[i] = p2;
            mod1 += (p2 * (s[i] - '0')) % mod; 
            p2 *= 2;
            p2 %= mod;
            mod1 %= mod;
        }
    }

    if(bitset > 1) {
        int p2 = 1;
        int mod = bitset - 1;
        for(int i = 0; i < n; i++) {
            p0[i] = p2;
            mod0 += (p2 * (s[i] - '0')) % mod; 
            p2 *= 2;
            p2 %= mod;
            mod0 %= mod;
        }
    }
    
    for(int i = n - 1; i >= 0; i--) {
        if(s[i] == '0') {
            int ans = mod1;
            ans += (p1[i] % (bitset + 1));
            ans %= (bitset + 1);
            cout << 1 + f(ans) << endl;
        }
        else {
            int ans = mod0;
            int mod = bitset - 1;
            if(mod == 0) {
                ans = 0;
                cout << 0 << endl;
                continue;
            }
            ans -= (p0[i] % (bitset - 1));
            ans += (bitset - 1);
            ans %= (bitset - 1);
            cout << 1 + f(ans) << endl;
        }
    }

    return 0;
}



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

int main(){
    int k, n;
    cin >> k >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    int l = a[0] + k - a[n - 1];
    for(int i = 0; i < n - 1; i++){
        int tmp = a[i + 1] - a[i];
        l = max(l, tmp);
    }
    int ans = k - l;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
typedef vector<int> Tensu;
//---------------------------------------
double keisan(Tensu ten);
//---------------------------------------

int main(void)
{
	cout << fixed <<setprecision(4);  //???????°???°????¬¬4????????§??¨?????????(iomanip)
	
	while(true){
		
		int n; //???????????°
		cin >> n;
		
		if(n == 0){
			break;
		}
		else{
			Tensu  ten;
			for(int i = 0; i < n; i++){
				int tensu;
				cin >> tensu;
				ten.push_back(tensu);
			}
			
			cout << keisan(ten) << endl;
			//row.clear();
		}
	}
	
	return 0;
	
}

//---------------------------------------
double keisan(Tensu ten)
{
	double gokei = 0;
	//??????????±???????
	for(int i = 0; i < ten.size(); i++){
		gokei += ten[i];
	}
	double m = gokei / ten.size();  //m????????????
	
	double a = 0;  //a????¨??????????
	
	for(int i = 0; i < ten.size(); i++){
		a += pow(ten[i] - m, 2);
	}
	a /= ten.size();
	
	return sqrt(a);
}

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main()
{
	long A[3][3],N,b[10],i,j,k;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			cin >> A[i][j];
		}
	}
	cin >> N ;
	for(k=0;k<N;k++){
		cin >> b[k];
	}
	for(k=0;k<N;k++){
		for(i=0;i<3;i++){
			for(j=0;j<3;j++){
				if(b[k]==A[i][j]){
					A[i][j]=0;
				}
			}
		}
	}
	if(((A[0][0]==0)&&(A[0][1]==0)&&(A[0][2]==0))||((A[1][0]==0)&&(A[1][1]==0)&&(A[1][2]==0))||((A[2][0]==0)&&(A[2][1]==0)&&(A[2][2]==0))||((A[0][0]==0)&&(A[1][1]==0)&&(A[2][2]==0))||((A[0][0]==0)&&(A[1][0]==0)&&(A[2][0]==0))||((A[0][1]==0)&&(A[1][1]==0)&&(A[2][1]==0))||((A[0][2]==0)&&(A[1][2]==0)&&(A[2][2]==0))||((A[0][2]==0)&&(A[1][1]==0)&&(A[2][0]==0))){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}		

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl a(n);
    vl rui(n+1);
    rep(i, n) {
        cin >> a[i];
        rui[i+1] = rui[i] + a[i];
    }

    ll ans = 0;
    map<ll, ll> mp;
    rep(i, n+1) {
        ans += mp[rui[i]];
        mp[rui[i]]++;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 15872
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            if (S.Length > K)
                Console.WriteLine(S.Substring(0, K) + "...");
            else
                Console.WriteLine(S);
        }
    }
}

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();


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

void Main()
{
	ll N;
  	cin >> N;
	ll rN = floor(sqrt(N));
	ll temp, tempi, tempj;
  	ll tempmin = N;
  	rep3(i, rN+1, 1){
          if ( N%i == 0 ){
            	ll j = N/i;
			  	cout << i+j-2 << endl;
				return;
          }
    }
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
  	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
 
typedef signed long long ll;
const int MX = 1e6 + 5;

int main() {
	string S;
	int n, cnt = 0;
	cin >> n >> S;
	
	
	for(int i = 0; i < n; i++) {
		if((i + 2) < n) {
			string R;
			R.push_back(S[i]);
			R.push_back(S[i + 1]);
			R.push_back(S[i + 2]);
			if(R == "ABC") cnt++;
		}
	}
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[n,m,k]=i2()
s="No"


for i in range(m+1):
    for j in range(n+1):
      if i*n+j*m-i*j*2==k:
          s="Yes"
print(s)

Measured memory_bytes: 39280
#include<stdio.h>
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int k, a;
    int p[33] = {};
    int i, j;
    for (i = 0; i < n; i++)
    {
        scanf("%d", &k);
        for (j = 0; j < k; j++)
        {
            scanf("%d", &a);
            p[a]++;
        }
    }
    int ans = 0;
    for (i = 0; i <= m; i++)
        if (p[i] == n)
            ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e2 + 5;
const int K = 1e5 + 10;
const ll M = 1e9 + 7;
ll dp[N][K];
ll a[N];
ll power(ll x, ll y){
    x %= M;
    ll ans = 1;
    while(y){
        if(y & 1)
            ans = (ans * x) % M;
        y >>= 1LL;
        x = (x * x) % M;
    }
    return ans;
}
ll ad(ll a, ll b){
    return((a % M + b % M) % M);
}
ll sub(ll a, ll b){
    return((a % M - b % M + M) % M);
}
ll mul(ll a, ll b){
    return(((a % M) * (b % M)) % M);
}
ll divi(ll a, ll b){
    return(mul(a, power(b, M - 2)) % M);
}
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int j = 0; j <= a[1]; j++){
        dp[1][j] = 1;
    }
    for(int j = 1; j <= k; j++) dp[1][j] += dp[1][j - 1];

    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= k; j++){
            int left = max(0LL, j - a[i]);
            ll sum = sub(dp[i - 1][j], (!left ? 0 : dp[i - 1][left - 1]));
            dp[i][j] = ad(sum, dp[i][j - 1]);
        }
    }
    cout << sub(dp[n][k], dp[n][k - 1]);
return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<int> C(N);
    vector<int> S(N);
    vector<int> F(N);
    REP(i, N - 1) {
        cin >> C[i] >> S[i] >> F[i];
    }
    REP(i, N - 1) {
        int t = S[i];
        FOR(j, i, N - 1) {
            if(t <= S[j]) {
                t = S[j];
                t += C[j];
            }else{
                int x = S[j];
                for(;x < t;) {
                    x += F[j];
                }
                x = (t - S[j] + F[j] - 1)/F[j];
                t = S[j] + x*F[j];
                t += C[j];
            }
        }
        cout << t << endl;
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll H, W, h, w;

int main() {
	scanf("%lld %lld %lld %lld", &H, &W, &h, &w);
	ll tot = H * W;
	ll row = h * W;
	ll col = w * H;
	ll temp = row + col - (h * w);
	ll ans = tot - temp;
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
//qsort
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}
 
int main(void) {
 
  // 入力
  int n,d;
  int sum,result=0;
  double sumSqrt;
  scanf("%d",&n);
  scanf("%d",&d);
  int list[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      scanf("%d",&list[i][j]);
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
        sum=0;
        for(int k=0;k<d;k++){
          sum+=((list[i][k]-list[j][k])*(list[i][k]-list[j][k]));
        }      
        sumSqrt=sqrt(sum);
        if(sumSqrt-(int)sumSqrt==0)result+=1;      }
    }
  }
 
  printf("%d\n",result/2);
  
  return 0;
}

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

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	string s;

	cin >> s;

	if (s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc157/tasks/abc157_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, M;
  cin >> N >> M;

  VL digits(N, -1);

  rep(i, M) {
    ll s, c;
    cin >> s >> c;
    s--;

    if (s == 0 && c == 0 && N >= 2) drop(-1);
    if (digits[s] != -1 && digits[s] != c) drop(-1);

    digits[s] = c;
  }

  if (N == 1) {
    if (digits[0] == -1) drop(0);
    drop(digits[0]);
  }

  if (digits[0] == -1) digits[0] = 1;

  rep(i, N) {
    if (digits[i] == -1) {
      digits[i] = i == 0 ? 1 : 0;
    }
  }

  rep(i, N) cout << digits[i];

  cout << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

#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 INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  int N; cin>>N;
  if(N%10==7||(N/10)%10==7||(N/100)%10==7)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

void solve() {
	int n;
	cin >> n;
	vector<vector<multiset<int>>> vec(2, vector<multiset<int>>(n));
	long long res = 0;
	for(int i = 0; i < n; i++) {
		int k, l, r;
		cin >> k >> l >> r;
		--k;
		if(l >= r) {
			res += r;
			vec[0][k].insert(l - r);
		}
		else {
			res += l;
			if(k < n - 1)
				vec[1][n - 2 - k].insert(r - l);
		}
	}

	for(int t : {0, 1}) {
		multiset<int> chosen;
		for(int i = 0; i < n; i++) {
			if(vec[t][i].empty())
				continue;
			while(!vec[t][i].empty() && (int) chosen.size() < i + 1) {
				int val = *vec[t][i].rbegin();
				res += val;
				chosen.insert(*vec[t][i].rbegin());
				vec[t][i].erase(vec[t][i].find(val));
			}

			while(!vec[t][i].empty() && *vec[t][i].rbegin() > *chosen.begin()) {
				int val = *chosen.begin();
				res -= val;
				chosen.erase(chosen.begin());
				val = *vec[t][i].rbegin();
				vec[t][i].erase(vec[t][i].find(val));
				chosen.insert(val);
				res += val;
			}
		}
	}

	// chosen.clear();
	// swap(left, right);

	// for(int i = 0; i < n; i++) {
	// 	if(left[i].empty())
	// 		continue;
	// 	while(!left[i].empty() && (int) chosen.size() < i + 1) {
	// 		int val = *left[i].rbegin();
	// 		res += val;
	// 		chosen.insert(*left[i].rbegin());
	// 		left[i].erase(left[i].find(val));
	// 	}

	// 	while(!left[i].empty() && *left[i].rbegin() > *chosen.begin()) {
	// 		int val = *chosen.begin();
	// 		res -= val;
	// 		chosen.erase(chosen.begin());
	// 		val = *left[i].rbegin();
	// 		left[i].erase(left[i].find(val));
	// 		chosen.insert(val);
	// 		res += val;
	// 	}
	// }

	// for(int x : chosen)
	// 	cout << x << ' ';

	cout << res << '\n';
}

int main() {
	fast();
	int t;
	cin >> t;
	while(t--)
		solve();
}


Measured memory_bytes: 31416
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int n, m;
vector<int> G[100005];
queue<int> que;
int deg[100005];
int par[100005];

int main()
{
	scanf("%d%d", &n, &m);
	m += n - 1;
	rep(i, m) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		deg[v] ++;
	}
	rep1(i, n) if(deg[i] == 0) que.push(i);
	
	while(!que.empty()) {
		int v = que.front();
		que.pop();
		rep(i, G[v].size()) {
			int u = G[v][i];
			deg[u] --;
			if(deg[u] == 0) {
				que.push(u);
				par[u] = v;
			}
		}
	}
	rep1(i, n) printf("%d\n", par[i]);
	return 0;
}

Measured memory_bytes: 7040
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define INF 105
#define NMAX 105

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	std::fill( (T*)array, (T*)(array+N), val );
}

typedef pair<int ,int > P;
typedef long long ll;

int A,B,C,N,x_first = 0,x_second = INF,y_first = 0,y_second = INF,x[NMAX],y[NMAX],a[NMAX];
int ans;
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	x_second = A;
	y_second = B;
	for (int i = 0; i < N; ++i)
	{
		if(a[i] == 1){
			x_first = max(x_first,x[i]);
		}else if(a[i] == 2){
			x_second = min(x_second,x[i]);
		}else if(a[i] == 3){
			y_first = max(y_first,y[i]);
		}else{
			y_second = min(y_second,y[i]);
		}
	}
	if(x_second-x_first < 0 || y_second-y_first < 0){
		ans = 0;
	}else{
		ans = (x_second-x_first)*(y_second-y_first);
	}
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> A >> B >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> x[i] >> y[i] >> a[i];
	}
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> v;
    for (int i = 2; i <= 55555; ++i) {
        bool res = true;
        for (int j = 2; j * j <= i; ++j) {
            if (i % j == 0) {
                res = false;
                break;
            }
        }
        if (res) v.push_back(i);
    }

    vector<int> ans(N);
    int c = 0;
    rep(i, N) {
        for (; c < v.size(); ++c) {
            if (v[c] % 5 == 1) {
                ans[i] = v[c];
                c++;
                break;
            }
        }
    }

    for (int i : ans) cout << i << " ";
    cout << endl;
}

Measured memory_bytes: 256
w, b = [int(i) for i in input().split()]

print("100 100")
a = []

for i in range(50):
    a.append(['#' for j in range(100)])

for i in range(50):
    a.append(['.' for j in range(100)])

for i in range(w - 1):
    x = (i % 50) * 2
    y = (i // 50) * 2 + 1
    a[y][x] = "."

for i in range(b - 1):
    x = (i % 50) * 2
    y = (i // 50) * 2 + 51
    a[y][x] = "#"

for y in range(100):
    print(''.join(a[y]))


Measured memory_bytes: 3188
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
      
      	long result = 1;
		final long D = 1000000007;

		// 壊れ段 スタート直前とゴール直後も登録しておく
		int[] a = new int[M + 2];
		a[0] = -1;
		a[M + 1] = N + 1;
		for ( int i = 1; i <= M; i++ ) {
			a[i] = in.nextInt();
			result = (result * getStepPatterns(a[i] - a[i - 1] - 1)) % D;
		}
		result = (result * getStepPatterns(a[M + 1] - a[M] - 1)) % D;

		System.out.println(result);
		in.close();
	}

	// n段のステップパターンを計算する（nにはスタートとゴールの段を含む）
	private static long getStepPatterns(int ｎ) {
		long D = 1000000007;
		long ptrn = 0;

		if ( ｎ <= 0 ) ptrn = 0;
		else if ( ｎ == 1 || ｎ == 2 ) ptrn = 1;
		else
		// (p+2)段目のパターン = (p+1)段目のパターン + p段目のパターン
		if ( 3 <= ｎ ) {
			long p0, p1, p2;
			p0 = p1 = p2 = 1;

			for ( int i = 2; i < ｎ; i++ ) {
				p2 = (p1 + p0) % D;
				p0 = p1;
				p1 = p2;
			}
			ptrn = p2;
		}
		return ptrn;
	}
}


Measured memory_bytes: 50304
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  if(x == 7 || x == 5 || x == 3) {
      cout << "YES" << '\n';
  } else {
      cout << "NO" << '\n';
  }
}

Measured memory_bytes: 256
def executor(v1, v2, v3)
	c = 0
	c += (v2 - v1).abs
	c += (v3 - v2).abs
	c
end

(a1, a2, a3) = gets.split.map(&:to_i)

min = [executor(a1, a2, a3), executor(a1, a3, a2), executor(a2, a1, a3), executor(a2, a3, a1), executor(a3, a1, a2), executor(a3, a2, a1)].min
p min




Measured memory_bytes: 1788
def main():
    import sys
    input = sys.stdin.readline
    from collections import deque
    N = int(input())
    A = deque()
    for i in range(N):
        s = input().split()
        if s[0] == 'insert':
            A.appendleft(s[1])
        elif s[0] == 'delete':
            try:
                A.remove(s[1])
            except ValueError:
                pass
        elif s[0] == 'deleteFirst':
            A.popleft()
        elif s[0] == 'deleteLast':
            A.pop()
    print(*A)

if __name__ == "__main__":
    main()


Measured memory_bytes: 69732
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  int ans = 0;
  vector<vector<int>> c(10, vector<int>(10));
  // ある点から1までの最短距離
  vector<int> z(10, -1);

  REP(i, 10) REP(j, 10) { cin >> c[i][j]; }
  vector<int> d(10, 1e9);
  vector<bool> used(10, false);
  d[1] = 0;
  while(true) {
    int v = -1;
    for(int u = 0; u < 10; u++) {
      if(!used[u] && (v == -1 || d[u] < d[v])) { v = u; }
    }

    if(v == -1) break;
    used[v] = true;

    for(int u = 0; u < 10; u++) {
      d[u] = min(d[u], d[v] + c[u][v]);
    }
  }
  REP(i, H * W) {
    int A;
    cin >> A;
    if(A == -1) continue;
    ans += d[A];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
while True:
  
  a, op, b = input().split()  
  a = int(a)                   
  b = int(b)   
  if op =='+':
    print(a + b)
  if op =='-':
    print(a - b)
  if op =='*':
    print(a * b)
  if op =='/':
    print(a // b)
  if op == '?':
    break


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long r[87];
    r[0]=2;
    r[1]=1;
    for(int i=2;i<87;++i)
        r[i]=r[i-1]+r[i-2];
    cout<<r[n]<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int i=0;
    int tmp1, tmp2, tmp, count;
    while(scanf("%d%d", &tmp1, &tmp2)!=EOF){
        tmp=tmp1+tmp2;
        count=0;
        while(tmp>0){
            count++;
            tmp=tmp/10;
        }
        printf("%d\n", count);
    }
    return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if( e - a >k){
    cout<<":("<<endl;
  }
  else{
  cout <<"Yay!"<< endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double c = sc.nextDouble();
		
		if(a/c<=b) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}

}


Measured memory_bytes: 37332
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

char c[4] = {'A', 'C', 'G', 'T'};

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;cin >> S;
    set<char> st;
    rep(i, 4) st.insert(c[i]);

    int ans = 0;
    rep(i, S.length()) {
        REP(j, i, S.length() - 1) {
            bool correct = true;
            REP(k, i, j) {
               
                rep(r, 4) {
                    if (st.find(S[k]) == st.end()) correct = false;
                }
            }
            if (correct) ans = max(ans, j - i + 1);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<set>
//headers packages!
//headers packages!
#include<stack>
#include<string>
#include<iterator>
#include<algorithm>

using namespace std;
using ll = long long;
int main()
{

   int n,c=0;
   ll d,x,y;
   cin>>n>>d;
   
   while(n--)
   {
      cin>>x>>y;
     if(x*x + y*y<=d*d)c++;
             
            }
   cout<<c<<endl;
    
 }

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
char s[500000], d;
int q, x, l, r, t;
int main() {
	cin>>s + 200000;
	l = 200000;
	r = 200000;
	while (s[r] != NULL)r++;
	r--;
	cin>>q;
	for (int i = 0; i < q; i++) {
		cin>>t;
		if (t == 1)x = 1 - x;
		if (t == 2) {
			cin>>t;
			cin>>d;
			if ((t + x) % 2) {
				l--;
				s[l] = d;
			}
			else {
				r++;
				s[r] = d;
			}
		}
	}
	if (x) {
		for (int i = r; i >= l; i--) {
		    cout<<s[i];
		}
	}
	else {
		for (int i = l; i <= r; i++) {
			cout<<s[i];
		}
	}
	cout<<'\n';
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int border[] = {599, 799, 999, 1199, 1399, 1599, 1799, 1999};

void solve(int cn) {
    int N,K; cin>>N>>K;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }

    for (int j = K; j < N; ++j) {
        if(a[j]>a[j-K]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

}


#define SINGLE
int main() {
#ifdef SINGLE
    solve(1);
#else
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        solve(i);
    }
#endif
    return 0;
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int gcd(int a,int b) {
    int maxi = -1;
    for (int i = 1;i <= min(a,b);i++) {
        if (a % i == 0 && b % i == 0) {
            maxi = i;
        }
    }
    return maxi;
}

int main() {
int K;
cin >> K;
int ans = 0;
for (int i = 1;i <= K;i++) {
    for (int j = 1;j <= K;j++) {
        for (int k = 1;k <= K;k++) {
            int c = gcd(i,j);
            ans += gcd(c,k);
        }
    }
}
cout << ans << endl;

return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <math.h>

using namespace std;

double distance(int x[], int y[], int d) {
    double distance = 0;
    for (int i=0; i<d; i++){
        distance += pow((x[i] - y[i]), 2);
    }
    return sqrt(distance);
}


int main() {
    int n, d;
    int x[20][20];
    double dis;
    int count = 0;
    cin >> n >> d;

    for (int i=0; i<n; i++){
        for (int j=0; j<d; j++){
            cin >> x[i][j];
        }
    }
    
    for (int i=0; i<n-1; i++){
        for (int j=i+1; j<n; j++){
            dis = distance(x[i], x[j], d);
            if (ceil(dis) == floor(dis)) count++;
        }
    }

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    string S;
    cin >> S;
    V<ll> ans(S.size() + 1, -1);
    V<ll> idx_v;
    for(ll i = 0; i <= S.size(); i++) {
        char pre = (i == 0 ? '>' : S[i - 1]);
        char pro = (i == S.size() ? '<' : S[i]);
        if(pre == '>' && pro == '<') {
            ans[i] = 0;
            idx_v.push_back(i);
        }
    }

    for(ll idx : idx_v) {
        {
            ll cur = 0;
            for(ll i = idx - 1; 0 <= i; i--) {
                if(S[i] == '>') {
                    cur++;
                    chmax(ans[i], cur);
                } else {
                    break;
                }
            }
        }
        {
            ll cur = 0;
            for(ll i = idx; i < S.size(); i++) {
                if(S[i] == '<') {
                    cur++;
                    chmax(ans[i + 1], cur);
                } else {
                    break;
                }
            }
        }
    }

    DEBUG(ans);
    cout << accumulate(ALL(ans), 0ll) << endl;
    return 0;
}


Measured memory_bytes: 6172
# -*- coding: utf-8 -*-

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    a, b = list(map(int, input().split()))

    if a >= 1:
        print('Positive')
    elif a * b <= 0:
        print('Zero')
    elif b <= -1:
        if (a - b + 1) % 2 == 0:
            print('Positive')
        else:
            print('Negative')


Measured memory_bytes: 2940
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

class Program
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		int A = int.Parse(s.Substring(0, 1));
		int B = int.Parse(s.Substring(1, 1));
		int C = int.Parse(s.Substring(2, 1));
		int D = int.Parse(s.Substring(3, 1));
		string op1 = "";
		string op2 = "";
		string op3 = "";
		string ans = "=7";

		for(int i = 0;i < 2; i++)
		{
            int sumAB = 0;
			check(i, B, A, out sumAB, out op1);

			for (int j = 0; j < 2; j++)
			{
                 int sumABC = 0;
				check(j, C, sumAB, out sumABC, out op2);
			
				for (int k = 0; k < 2; k++)
				{
                     int sumABCD = 0;
					check(k, D, sumABC, out sumABCD, out op3);
				
					if(sumABCD == 7)
					{
						Console.WriteLine(A+op1+B+op2+C+op3+D+ans);
						return;
					}
				}
			}
		}
	}

	static void check(int flg,int num ,int oldsum ,out int newsum,out string op)
	{
		if(flg == 0)
		{
			newsum = oldsum + num;
			op = "+";
		}
		else
		{
			newsum = oldsum - num;
			op = "-";
		}
	}
}

//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
//Boolean ok = false;

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();

//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];


Measured memory_bytes: 11092
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int calc(int x, int y){
  if(x == y) return 0;
  
  if(x < y){
    if((x < 0 && y <= 0) || (0 <= x && 0 <= y)){
      return y-x;
    }else{
      return abs(abs(y) - abs(x)) + 1;
    }
  }else{
    if(x > 0 && y > 0){
      return x-y+2;
    }else if(x < 0 && y < 0){
      return x-y+2;
    }else{
      return abs(abs(y) - abs(x)) + 1;
    }
  }

  assert(false);
  
  return -1;
}

int main(){
  int x,y;

  cin >> x >> y;


  cout << calc(x,y) << endl;
  
  return 0;
}


Measured memory_bytes: 764
using System;
using System.Linq;

namespace abc054_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (x[0] == 1) x[0] = 114514;
            if (x[1] == 1) x[1] = 114514;
            if (x[0] == x[1]) Console.WriteLine("Draw");
            else Console.WriteLine(x[0] > x[1] ? "Alice" : "Bob");
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,p[1000],ans;
int main(){
  while(1){
    ans=0;
    cin>>n>>m;
    if(n==0&&m==0) break;
    for(int i=0;i<n;i++)cin>>p[i];
    sort(p,p+n);
    for(int i=n-1;i>=0;i--)
      if((n-i)%m!=0)ans+=p[i];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n,int m){
	vl h(n+1),w(m+1);
	ll ans=0;
	map<ll,ll> hm,wm;
	rep(i,n){
		cin>>h[i+1];
		if(i!=0)h[i+1]+=h[i];
		rep(j,i+1)hm[h[i+1]-h[j]]++;
	}
	rep(i,m){
		cin>>w[i+1];
		if(i!=0)w[i+1]+=w[i];
		rep(j,i+1)wm[w[i+1]-w[j]]++;
	}
	for(auto x:hm)ans+=(x.sc)*(wm[x.fs]);
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n)solve(n,m);
}



Measured memory_bytes: 44828
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

S = list(rs())
X, Y = rl()

xy = [[], []]
dir = 0 # x軸方向を0とし、y軸方向を1とする
cur = 0
for s in S:
    if s == 'F':
        cur += 1
    else:
        xy[dir].append(cur)
        cur = 0
        dir = 1 - dir
xy[dir].append(cur)
# x軸方向が達成可能かどうか
xmax = sum(xy[0])
dif_x = xmax - X
ymax = sum(xy[1])
dif_y = ymax - Y
if dif_x&1 == 1 or dif_y&1 == 1:
    print('No')
    exit()
dif_x //= 2
dif_y //= 2
xset = set([0])
for x in xy[0][1:]:
    new_set = set()
    for z in xset:
        new_set.add(z+x)
    xset = xset.union(new_set)
yset = set([0])
for y in xy[1]:
    new_set = set()
    for z in yset:
        new_set.add(z+y)
    yset = yset.union(new_set)

if dif_x in xset and dif_y in yset:
    print('Yes')
else:
    print('No')
# 31

Measured memory_bytes: 4768
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = xpow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * xpow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll sum = 0;
	if (k - a >= 0)
	{
		//cout << "*" << endl;
		sum = (a);
		k -= a;
		if (k == 0)
		{
			cout << sum << endl;
			return 0;
		}
	}
	else if (k - a < 0)
	{
		sum += k;
		cout << sum << endl;
		return 0;
	}
	if (k - b >= 0)
	{
		k -= b;
		if (k == 0)
		{
			cout << sum << endl;
			return 0;
		}
	}
	else if (k - b < 0)
	{
		cout << sum << endl;
		return 0;
	}
	if (k - c >= 0)
	{
		sum += (c) * -1;
		k -= c;
		if (k == 0)
		{
			cout << sum << endl;
			return 0;
		}
	}
	else if (k - c < 0)
	{
		sum += k * -1;
		cout << sum << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 3648
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)

	if n % 2 != 0 {
		fmt.Printf("No")
		return
	}

	if s[0:n/2] == s[n/2:n] {
		fmt.Printf("Yes")
	} else {
		fmt.Printf("No")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
using namespace std;
#define ll long long

int main() {
	ll N, D, X, Y, dis, count = 0, i;
	cin >> N >> D;
	
	for(i=0; i<N; i++){
		cin >> X >> Y;
		
		dis = ceil(sqrt(pow(X, 2) + pow(Y, 2)));
		if(dis <= D)
			count++;
	}
	
	cout << count;
	
	return 0;
}

Measured memory_bytes: 3764
mod = 10 ** 9 + 7
n, k = map(int, input().split())

a = [1] * (k+1)
b = [ i for i in range(k+1) ]

for i in range(k//2,0,-1):
  cnt = pow( k // i , n, mod )
  for j in range(i*2,k+1,i):
    cnt = ( cnt - a[j] ) % mod
  a[i] = cnt
  b[i] = i * cnt % mod

ans = 0
for i in range(1,k+1):
  ans = (ans + b[i]) % mod

print(ans)

Measured memory_bytes: 74560