akhauriyash/Code-Regression huggingface dataset:
//author Eterna
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<numeric>
#include<unordered_map>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
#define pb(x) push_back(x)
#define lowbit(x) (x & -x)
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\in.txt", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\out.txt", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
inline int read_int() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
inline ll read_ll() {
	char c;
	ll ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
ll fsum(ll x) {
	ll a = 0;
	while (x) {
		a += (x % 10);
		x /= 10;
	}
	return a;
}
vector<ll>v;
int k;
int main()
{
	for (int i = 1; i < 10; i++) v.push_back(i);
	v.push_back(19);
	cin >> k;
	ll last = 19;
	while (v.size() < k) {
		ll p = fsum(last);
		ll add = 1;
		while ((last + add)*fsum(last + add * 2) > (last + 2 * add)*fsum(last + add)) add *= 10;
		last += add;
		v.push_back(last);
	}
	for (int i = 0; i < k; i++)cout << v[i] << endl;
	return 0;
}

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

using namespace std;

int main(){

	int card[14];
	int hand[5];
	char cm;
	while(1){
		fill(card,card+14,0);
		cin>>hand[0];
		card[hand[0]]++;
		if(cin.eof())
			break;
		for(int i = 1; i < 5; i++){
			cin>>cm>>hand[i];
			card[hand[i]]++;
		}

		int onepair=0;
		int threecard=0;
		int straight=0;

		int cont=0;
		bool f=false;

		if(card[1]==1&&card[10]==1&&card[11]==1&&card[12]==1&&card[13]==1){
			cout<<"straight"<<endl;
			continue;
		}

		for(int i = 1; i < 14; i++){
			if(card[i]==4){
				cout<<"four card"<<endl;
				f=true;
				break;
			}
			else if(card[i]==2){
				onepair++;
			}
			else if(card[i]==3){
				threecard++;
			}
			else if(card[i]==1){
				cont++;
				if(cont==5){
					straight++;
				}
			}
			else
				cont=0;
		}
		if(!f){
			if(onepair==2)
				cout<<"two pair"<<endl;
			else if(threecard==1){
				if(onepair==1)
					cout<<"full house"<<endl;
				else
					cout<<"three card"<<endl;
			}
			else if(straight){
				cout<<"straight"<<endl;
			}
			else if(onepair==1){
				cout<<"one pair"<<endl;
			}
			else
				cout<<"null"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
flag=0
for i in range(N):
  if x[i]>=Y:
    flag+=1
for i in range(M):
  if y[i]<=X:
    flag+=1
if X>Y:
  flag+=1
if flag>0:
  print("War")
else:
  if min(y)>max(x):
    print("No War")
  else:
    print("War")

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

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

using namespace std;

const int MAX = 1000;

int main(){
	int N;	
	while(cin >> N, N) {
		int ans=0, tmp=0;	
		
		for(int i = 1; i < N; ++i) {
			tmp = 0;	
			for(int j = i; j < N; ++j) {
				tmp += j;
				if(tmp == N) {
					++ans;
					break;
				}
				else if(tmp > N) break;
			}
		}

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

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

using namespace std;

using int64 = long long;

// Does coordinate compression.
// Arguments:
// - raw_xs: Values to compress.
// Returns:
// - xs: Compressed values.
// - to_raw: A mapping from a compressed value to a raw value.
// Verified: CF573Div1D
tuple<vector<int>, vector<int>> Compress(const vector<int>& raw_xs) {
  unordered_set<int> raw_x_set(raw_xs.begin(), raw_xs.end());
  vector<int> to_raw(raw_x_set.begin(), raw_x_set.end());
  sort(to_raw.begin(), to_raw.end());
  unordered_map<int, int> to_index;
  for (int i = 0; i < to_raw.size(); i++) {
    to_index[to_raw[i]] = i;
  }
  vector<int> xs;
  for (int raw_x : raw_xs) {
    xs.push_back(to_index[raw_x]);
  }
  return make_tuple(xs, to_raw);
}

class UFSet {
 private:
  vector<int> ranks;
  vector<int> prevs;

 public:
  UFSet(int n) : ranks(n), prevs(n) {
    for (int i = 0; i < n; i++) prevs[i] = i;
  }

  // Returns a root of a tree which x belongs to.
  int Find(int x) {
    if (x != prevs[x]) prevs[x] = Find(prevs[x]);
    return prevs[x];
  }

  // Merges a set which x blongs to and a set which y belongs to.
  void Union(int x, int y) {
    int x_root = Find(x);
    int y_root = Find(y);
    if (ranks[x_root] > ranks[y_root]) {
      prevs[y_root] = prevs[x_root];
    } else if (ranks[x_root] < ranks[y_root]) {
      prevs[x_root] = prevs[y_root];
    } else if (prevs[x_root] != prevs[y_root]) {
      prevs[y_root] = prevs[x_root];
      ranks[x_root]++;
    }
  }
};

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

  int n;
  cin >> n;
  vector<int> xs(n);
  vector<int> ys(n);
  for (int i = 0; i < n; i++) cin >> xs[i];
  for (int i = 0; i < n; i++) cin >> ys[i];
  int x_xor = 0;
  int y_xor = 0;
  for (int i = 0; i < n; i++) x_xor ^= xs[i];
  for (int i = 0; i < n; i++) y_xor ^= ys[i];

  vector<int> e_xs;
  e_xs.insert(e_xs.end(), xs.begin(), xs.end());
  e_xs.push_back(x_xor);
  vector<int> e_ys;
  e_ys.insert(e_ys.end(), ys.begin(), ys.end());
  e_ys.push_back(y_xor);
  sort(e_xs.begin(), e_xs.end());
  sort(e_ys.begin(), e_ys.end());
  for (int i = 0; i <= n; i++) {
    if (e_xs[i] != e_ys[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<int> raw_zs;
  for (int i = 0; i < n; i++) {
    if (xs[i] != ys[i]) {
      raw_zs.push_back(xs[i]);
      raw_zs.push_back(ys[i]);
    }
  }
  if (x_xor != y_xor) {
    raw_zs.push_back(x_xor);
    raw_zs.push_back(y_xor);
  }
  vector<int> zs;
  vector<int> to_raw_z;
  tie(zs, to_raw_z) = Compress(raw_zs);

  int m = to_raw_z.size();
  UFSet uf_set(m);
  for (int i = 0; i < zs.size() / 2; i++) {
    int z1 = zs[2 * i];
    int z2 = zs[2 * i + 1];
    uf_set.Union(z1, z2);
  }

  set<int> component_set;
  for (int i = 0; i < m; i++) {
    component_set.insert(uf_set.Find(i));
  }

  int ans = zs.size() / 2;
  ans += component_set.size();
  if (x_xor != y_xor) {
    ans -= 2;
  } else {
    bool valid = false;
    for (int raw_z : raw_zs) {
      if (raw_z == x_xor) {
        valid = true;
      }
    }
    if (valid) ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 13812
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;

Int dp[100010][5];

int main() {
    string s;
    cin >> s;
    string t = "ABC";
    dp[0][0] = 1;
    for (Int i = 0; i <= (Int)s.size(); i++) {
        for (Int j = 0; j <= (Int)t.size(); j++) {
            if (s[i] == '?') {
                dp[i + 1][j] += dp[i][j] * 3 % mod;
                dp[i + 1][j] %= mod;
                dp[i + 1][j + 1] += dp[i][j];
                dp[i + 1][j + 1] %= mod;
            }
            else {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= mod;
                if (s[i] == t[j]) {
                    dp[i + 1][j + 1] += dp[i][j];
                    dp[i + 1][j + 1] %= mod;
                }
            }
        }
    }
    /* cout << "    ";
    for (Int i = 0; i < 3; i++) cout << t[i] << " ";
    cout << endl;
    for (Int i = 0; i <= (Int)s.size(); i++) {
        if (i > 0) {
            cout << s[i - 1] << " ";
        }
        if (i == 0) cout << "  ";
        for (Int j = 0; j <= 3; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    } */
    dump(dp[(Int)s.size()][3]);
    return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;


int main()
{
	ll X;cin >>X;
	vector<ll> num;
	ll a;
	for (ll i=-1000;i<1001;i++)
	{
		a=i*i*i*i*i;
		num.push_back(a);
	}
	for (int i=0;i<num.size();i++)
	{
		auto itr=lower_bound(num.begin(),num.end(),X+num[i]);
		if (*itr==X+num[i])
		{
			cout << itr-num.begin()-1000 << " " << i-1000 << endl;
			break;
		}
	}
	return 0;

}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=2e5+5;



void solve()
{
    long double n,d,x,y,z;
    cin>>n>>d;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
      cin>>x>>y;
      z=sqrtl(x*x+y*y);
      if(z<=d)
        ans++;
    }
    cout<<ans;

}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t=1;
 for(int i=1;i<=t;i++)
 {
   solve();
 }


}

Measured memory_bytes: 3828
H,W = map(int, input().split())
N= int(input())
A = list(map(int, input().split()))


ans = [[0 for _ in range(W)] for _ in range(H)]


cnt = 0
c = 0
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            ans[i][j] = c+1
            A[c] -= 1
            if A[c] == 0:
                c += 1
    else:
        for j in reversed(range(W)):
            ans[i][j] = c+1
            A[c] -= 1
            if A[c] == 0:
                c += 1

for i in range(H):
    print(*ans[i])

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%3==0&&i%5==0){

		}else if(i%3==0 ){

		}else if(i%5==0){

		}else{
			sum+=i;
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[5005][5005],a,b;
int n,p[5005],pos[5005];

int main(){
	scanf("%d %lld %lld",&n,&a,&b);
	for(int i=1;i<=n;i++) scanf("%d",&p[i]),pos[p[i]]=i;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=1e18;
			if(j==pos[i]){dp[i][j]=min(dp[i][j],dp[i-1][j-1]);}
			dp[i][j]=min(dp[i][j],dp[i-1][j]+((j<pos[i])?b:a));
		}
		for(int j=1;j<=n;j++) dp[i][j]=min(dp[i][j],dp[i][j-1]);
	}
	printf("%lld\n",dp[n][n]); 

	return 0;
}

Measured memory_bytes: 195840
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;
vector<ll> A;

ll dp[2][100010];

void solve() {
  ll N, K;
  cin >> N >> K;
  rep (i, N) {
    ll tmp;
    cin >> tmp;
    A.push_back(tmp);
  }
  sort(A.begin(), A.end());

  for (ll i = 0; i <= K; i++)  {
    if (i < A[0]) {
      dp[0][i] = 1;
      dp[1][i] = 0;
      continue;
    }
    bool can_win = false;
    for (auto it: A) {
      if (i - it < 0) break;
      if (dp[1][i-it] == 0)  can_win = true;
    }
    dp[0][i] = can_win ? 0 : 1;
    dp[1][i] = can_win ? 1 : 0;
  }

  cout << (dp[0][K] == 0 ? "First" : "Second") << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ch;
    cin>>ch;
    if(ch=='A')
    {
        cout<<"T"<<endl;
    }
    if(ch=='T')
    {
        cout<<"A"<<endl;
    }
    if(ch=='C')
    {
        cout<<"G"<<endl;
    }
    if(ch=='G')
    {
        cout<<"C"<<endl;
    }
    return 0;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int cnt[3];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, ans=0;
	for(cin>>N;N;N--) {
		string s;
		cin>>s;
		for(int i=1;i<s.size();i++) ans+=(s[i-1]=='A' && s[i]=='B');
		if(s[0]=='B') {
			if(s.back()=='A') cnt[2]++;
			else cnt[0]++;
		}
		else if(s.back()=='A') cnt[1]++;
	}
	if(cnt[2]) {
		ans+=cnt[2]-1;
		if(cnt[0]) ans++, cnt[0]--;
		if(cnt[1]) ans++, cnt[1]--;
	}
	ans+=min(cnt[0],cnt[1]);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, a, b, c, d;

signed main()
{
    cin >> N >> a >> b >> c >> d;
    for(int i = 0; i < N; i++){
        int e = N - 1 - i;
        if(i * c - e * d <= b - a && b - a <= i * d - e * c){
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");

    return 0;
}
/*



*/


Measured memory_bytes: 256
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline


# S=(input())
# N=int(input())
# N,K=map(int,input().split())
# ListA=list(map(int,input().split()))
# ListA.sort()#reverse=True)



def resolve():
    N=int(input())
    if(N%1000==0):
        print(0)
    else:
        print(1000-N%1000)


resolve()




Measured memory_bytes: 9828
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	if(s.size() <= n){
		cout << s;
	}
	else{
		cout << s.substr(0,n) << "...";
	}

	return 0;
}



Measured memory_bytes: 3636
# @author 

import sys

class CHAndV:
    def solve(self, tc=0):
        h, w, k = [int(_) for _ in input().split()]
        g = []
        for i in range(h):
            g.append(list(input().strip()))

        ans = 0
        for mrow in range(1 << h):
            for mcol in range(1 << w):
                new_g = [line[:] for line in g]
                for i in range(h):
                    for j in range(w):
                        if (mrow >> i) & 1 or (mcol >> j) & 1:
                            new_g[i][j] = '0'

                cnt = 0
                for line in new_g:
                    cnt += line.count('#')

                if cnt == k:
                    ans += 1

        print(ans)




solver = CHAndV()
input = sys.stdin.readline

solver.solve()


Measured memory_bytes: 68568
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	static int j=0;
	static boolean conte=true;
	 static int[] field_make(String str){
		j=0;
		int[] field=new int[str.length()];
		Arrays.fill(field, -1);
		conte=true;
		 while(conte && j< str.length()){
			 if(str.indexOf('c',j) == -1){
				 conte=false; 
			 }else{
				 field[str.indexOf('c',j)]=0;
				 j=str.indexOf('c',j);
			 }
			 j++;
		 }
		 return field;
	}
	
	
	static void doit(){
		Scanner sc = new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int[][] field=new int[H][W];
		String[] str=new String[H];
		for(int i=0;i<H;i++){
			str[i]=sc.next();
			field[i]=field_make(str[i]);
		}
		
	sc.close();
	for(int i=0;i<H;i++){
		 for(int k=0;k<W-1;k++){
			 if(field[i][k]!=-1 && field[i][k+1]!=0){
				 field[i][k+1]=field[i][k]+1;
			 }
		 }
		 for (int k=0;k<W-1;k++){
				System.out.printf("%d ", field[i][k]);
			}
				System.out.printf("%d\n",field[i][W-1]);
	}
		
	}
	
	
	public static void main(String[] args) {
		new Main();
		doit();
	}

}

Measured memory_bytes: 44736
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;
  bool a_f = false, b_f = false;
  REP(i, 3) {
    if(s[i] == 'A') a_f = true;
    else b_f = true;
  }

  cout << (a_f && b_f ? "Yes" : "No") << endl;
}


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

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

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

    string s;
    cin >> s;
    ll a, t;
    a = t = 0;
    F0R(i,(int)s.size()-1)
    {
        if(s[i] == 'A')
            a++;
        else if (s[i] == 'B' && s[i+1] == 'C')
        {
            i++;
            t += a;
        }
        else
            a = 0;
    }
    cout << t;

    return 0;
}


Measured memory_bytes: 720
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int[] cnt = new int[n];
        for (int i = 0; i < n; i++) {
            if (a.charAt(i) == b.charAt(i)) {
                cnt[i]++;
            }
        }
        for (int i = 0; i < n; i++) {
            if (b.charAt(i) == c.charAt(i)) {
                cnt[i]++;
            }
        }
        for (int i = 0; i < n; i++) {
            if (c.charAt(i) == a.charAt(i)) {
                cnt[i]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (cnt[i] >= 3) {
                continue;
            }
            if (cnt[i] == 0) {
                ans += 2;
                continue;
            }
            ans++;
        }
        System.out.println(ans);
    }
}


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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
ll loc[NMAX] ;
ll pre_sum[NMAX];
int main(int argc, char const *argv[])
{
	ll n , ans = 0;
	ll x , m ,pos = 1;
	scanf("%lld%lld%lld",&n,&x,&m);
	loc[x] = 1;
	pre_sum[1] = x % m;
	for(register ll i = 2;i <= n && !loc[x*x%m];i++)
	{
		x = x*x%m;
		loc[x] = i;
		pre_sum[i] = pre_sum[i - 1] + x;
		pos = i;
	}
	if(pos == n)
		return 0*printf("%lld\n",pre_sum[n]);
	ans += pre_sum[loc[x*x%m] - 1];
	ll T = pos - loc[x*x%m] + 1;
	ans += (pre_sum[pos] - pre_sum[loc[x*x%m] - 1]) * ((n - loc[x*x%m] + 1)/T);
	ans += pre_sum[loc[x*x%m] - 1 + (n - loc[x*x%m] + 1)%T] - pre_sum[loc[x*x%m] - 1];
	printf("%lld\n",ans );
	return 0;
}

Measured memory_bytes: 4896
def div_ceil(x, y): return (x + y - 1) // y

N = int(input())
*A, = map(int, input().split())
cand_min, cand_max = 2, 2
for a in reversed(A):
    if div_ceil(cand_min, a) * a > cand_max: print(-1); break
    cand_min = div_ceil(cand_min, a) * a
    cand_max = (cand_max // a) * a + a - 1
else:
    print(cand_min, cand_max)

Measured memory_bytes: 14252
text = []
while(1):
    try:
        text.append(input())
    except EOFError:
        break
nums = []
not_nums = {}
for i in text:
    i = [j if j in ["0","1","2","3","4","5","6","7","8","9"] else " " for j in i]
    i = "".join(i)
    [nums.append(int(j)) for j in i.split()]
print(sum(nums))


Measured memory_bytes: 5600
N = input()
num = N.split(' ')
a = int(num[0])
b = int(num[1])
c = int(num[2])
d = int(num[3])

e = a * c
f = a * d
g = b * c
h = b * d
num_max = max([e, f, g, h])
print(num_max)

Measured memory_bytes: 9188
N = int(input())
numberlist = []
for i in range(2, N+1):
	numberlist.append(i)
prime = []
while numberlist != []:
	newnumberlist = []
	now = numberlist.pop(0)
	prime.append(now)
	while numberlist != []:
		x = numberlist.pop(0)
		if x%now != 0:
			newnumberlist.append(x)
	numberlist = newnumberlist
counter = []
for i in range(0, len(prime)):
	counter.append(1)
for i in range(1, N+1):
	m = i
	for j in range(0, len(prime)):
		if m == 1: break
		while m%prime[j] == 0:
			counter[j] += 1
			m = m // prime[j]
ans = 1
for i in range(0, len(counter)):
	ans = (ans*counter[i]) % 1000000007
print(ans)

Measured memory_bytes: 40048
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		int R = sc.nextInt();

		if(R<1200) {

			System.out.println("ABC");
		}else if(R<2800) {

			System.out.println("ARC");
		}else {

			System.out.println("AGC");
		}

	}

	//以下テンプレート
	int lowerbound(int[] a, int key) {

		int left = -1;
		int right = a.length;

		while (Math.abs(right - left) > 1) {

			int mid = (right + left) / 2;

			if (a[mid] >= key) {
				right = mid;
			} else {
				left = mid;
			}

		}

		return right;

	}

	int upperbound(int[] a, int key) {

		int left = -1;
		int right = a.length;

		while (Math.abs(right - left) > 1) {

			int mid = (right + left) / 2;

			if (a[mid] <= key) {
				left = mid;
			} else {
				right = mid;
			}

		}

		return left;

	}

	public static String numtoalpha(int i) {

		String alpha = "abcdefghijklmnopqrstuvwxyz";

		return alpha.substring(i, i + 1);

	}

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int,int> P;

int main() {
    int n,m;
    cin >> n >> m;

    set<int> e_out[n];
    set<int> e_in[n];

    for(int i=0; i<m; ++i) {
        int a,b;
        cin >> a >> b;
        e_out[a-1].insert(b-1);
        e_in[b-1].insert(a-1);
    }

    queue<int> q;
    vector<int> deg(n);
    for(int i=0; i<n; ++i) {
        deg[i]=(int)e_in[i].size();
        if(deg[i]==0) q.push(i);
    }

    bool flag=false;
    vector<int> ans;
    vector<bool> vis(n,false);

    while(!q.empty()) {
        if(q.size()!=1) flag=true;
        int p=q.front(); q.pop();
        if(vis[p]) continue;
        ans.push_back(p);
        vis[p]=true;
        for(auto x : e_out[p]) {
            --deg[x];
            if(deg[x]==0) q.push(x);
        }
    }

    for(int i=0; i<n; ++i) {
        cout << ans[i]+1 <<  endl;
    }

    cout << (flag?1:0) << endl;


    return 0;
}

Measured memory_bytes: 13072
def show (nums):
    for i in range(len(nums)):
        if i!=len(nums)-1:
            print(nums[i],end=' ')
        else :
            print(nums[i])

n = int(input())
A = list(map(int,input().split()))

flag = 1
counter = 0

while(flag):
    flag = 0
    for j in range(1,n)[::-1]:
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            counter += 1

show(A)
print(counter)


Measured memory_bytes: 5604
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int g,s;
	while(1)
	{
		cin>>g;
		if(g==0)
			break;
		for(int i=0;i<9;i++)
		{
			cin>>s;
			g-=s;
		}
		cout<<g<<endl;
	}
	return 0;
}


Measured memory_bytes: 3008
/*====================
author: fexuile
mail: fexuile@qq.com
QQ: 2165008534
====================*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#include<set>
#include<map>
using namespace std;
#define mp make_pair
#define ll long long
#define re register
typedef pair<int,int> pii;
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=210;
int n,L[N];
int main()
{
	n=gi();n<<=1;
	for(int i=1;i<=n;i++)L[i]=gi();
	sort(L+1,L+n+1);int ans=0;
	for(int i=n-1;i>0;i-=2)ans+=L[i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
D = 60

N, K = map(int, input().split())
to = [[None] * N for _ in range(D)]
to[0] = list(map(lambda x: int(x)-1, input().split()))

for i in range(D-1):
    for j in range(N):
        to[i+1][j] = to[i][to[i][j]]

v = 0
for i in range(D, -1, -1):
    hops = 1 << i
    if K >= hops:
        K -= hops
        v = to[i][v]

print(v+1)


Measured memory_bytes: 188440
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    char C;
    cin >> C;
    vector<char> abc={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int ans;
    for(int i=0;i<26;i++){
        if(C==abc.at(i)){
            ans=i+1;
            break;
        }
    }
    cout << abc.at(ans) << endl;
}


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

int main() {
  string s;
  cin>>s;
  int count=0;
  for(int i=1;i<s.size();i++){
    if(s[i]!=s[i-1])count++;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<cstring>
#define mod 998244353
#define ll long long
using namespace std;
map<string,ll>f,g;
ll dfs1(string);
ll dfs2(string);
ll dfs1(string s)
{
	if(f[s]) return f[s];
	int len=s.size();
	if(!len) return f[s]=1;
	ll ans=0;
	for(int i=1;i<=len;i++)
	ans=(ans+dfs2(s.substr(0,i))*dfs1(s.substr(i,len)))%mod;
	return f[s]=ans;
}
ll dfs2(string s)
{
	if(g[s]) return g[s];
	int len=s.size();
	ll res=0;
	if(len==1) return g[s]=1+(int)(s[0]=='1');
	for(int i=1;i<=len>>1;i++)
	if(len%i==0)
	{
		string t="";
		for(int j=1,r=1;j<=i;j++,t+=(char)(r+'0'),r=1)
			for(int k=j-1;k<=len-1;k+=i) r&=s[k]-'0';
		res=(res+dfs1(t))%mod;
	}
	return g[s]=res;
}
string s;
int main()
{
	cin>>s;
	printf("%lld\n",dfs1(s));
	return 0;
}


Measured memory_bytes: 12928
x,y = (int(i) for i in input().split())
if x == 1 or x == 3 or  x == 5 or  x == 7 or  x == 8 or  x == 10 or  x == 12:
  x = 1
elif x == 2:
  x = 2
else:
  x = 4
if y == 1 or y == 3 or  y== 5 or  y== 7 or  y== 8 or  y== 10 or  y == 12:
  y = 1
elif y == 2:
  y = 2
else:
  y = 4
  
if x == y:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<stdio.h>

main(){
  int week;
  int i;
  int res = 100000;
  int l;

  scanf("%d", &week);

  for(i = 0 ; i < week ; i++){
    res += res * 0.05;
    res += 999;
    l = res % 1000;
    res -= l;
  }

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

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<pair<string, pair<int, int>>> A(N);
    for(int i=0; i<N; i++){
        string s;
        int p;
        cin >> s >> p;
        A[i] = {s, {-p, i+1}};
    }
    sort(A.begin(), A.end());
    for(auto& p : A) cout << p.second.second << endl;
    return 0;
}


Measured memory_bytes: 256
// 相変わらず文章がぜんぜん頭にはいってこんな
// スイッチの状態を全探索る -> そのあとの判定が毎回混乱する
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	T := make([][]bool, M)
	for i := 0; i < M; i++ {
		var K int
		fmt.Scan(&K)
		T[i] = make([]bool, N)
		for j := 0; j < K; j++ {
			var V int
			fmt.Scan(&V)
			T[i][V-1] = true
		}
	}
	P := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&P[i])
	}
	ans := 0
	for bit := 0; bit < (1 << uint(N)); bit++ {
		tmp := []int{}
		for i := 0; i < N; i++ {
			if (bit>>uint(i))&1 == 1 {
				tmp = append(tmp, i)
			}
		}
		// スイッチの状態がtmp=onであったときそれぞれの電球がついてるかどうか これ
		flag := true
		for i := 0; i < M; i++ {
			yo := 0 // onになってるスイッチの数
			for _, t := range tmp {
				if T[i][t] {
					yo++
				}
			}
			// 判定
			if P[i] != yo%2 {
				flag = false
			}
		}
		if flag {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  int N;
  cin >> N;
  int ar[100];
  int sum = 0;
  REP(i,N) {
    int a;
    cin >> a;
    ar[i] = a * N;
    sum += a;
  }
  int min = 999999;
  int minby = -1;
  REP(i,N) {
    int abv = ar[i] - sum;
    if(abv < 0) abv = -abv;
    if(min > abv) {
      min = abv;
      minby = i;
    }
  }
  cout << minby << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i<b; i++)
#define dep(i,a,b) for(int i = a-1; i>=b; i--)
#define makeUnique(vec) sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin())
#define LOG_vec(vec, sep) for (int fl = 0; fl < vec.size(); fl++) { cout << vec[fl]<< sep; } cout << "\n";
#define LOG_ints(vec, sep) for (int fl = 0; fl < MAXSIZE; fl++) { cout << vec[fl]<< sep; } cout << "\n"
#define all(x) (x).begin(), (x).end()
#define LSB(i) ((i) & -(i))
#define MAXSIZE 300000
using namespace std;
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;

int main(){
	vi vs(400000);
	vi v;
	int N;
	cin >> N;
	ll maxi = 0;
	rep(i, 0, N) {
		int tmp;
		cin >> tmp;
		maxi += vs[tmp];
		vs[tmp]++;
		v.push_back(tmp);
	}
	rep(i, 0, N) {
		cout << maxi - vs[v[i]] + 1 << endl;
	}

}

Measured memory_bytes: 5108
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, b, n) for (int i = b; i < n; ++i)

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

void solve(long N, vector<long> A) {
  long ans = 1;
  enum {INC, DEC, FLAT};
  int state = FLAT;
  FOR(i, 1, N) {
    switch (state) {
    case FLAT:
      if (A[i] > A[i - 1])
	state = INC;
      else if (A[i] < A[i - 1])
	state = DEC;
      break;
    case INC:
      if (A[i] < A[i - 1]) {
	ans++;
	state = FLAT;
      }
      break;
    case DEC:
      if (A[i] > A[i - 1]) {
	ans++;
	state = FLAT;
      }
      break;
    }
  }
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  long N;
  cin >> N;
  vector<long> A(N);
  REP(i, N)
    cin >> A[i];

  solve(N, move(A));

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

//1:45   start
//1:56   compile

//#define DEBUG


char *day[]={
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday"};
int  num_of_day[]={
    31,29,31,30,31,30, //Leap Year
    31,31,30,31,30,31};
char month_day[12][31];

void calc(void)
{
    int cnt=3; //2004/1/1 is Thursday(3)
    int m,d;
    for(m=0;m<12;m++){
        for(d=0;d<num_of_day[m];d++){
           month_day[m][d]=cnt; 
           cnt=(cnt==7-1)?0:cnt+1;
        }
    }

}



int main(void)
{
    FILE* fp;
#ifdef DEBUG
    fp=fopen("input.txt","r");
#else
    fp=stdin;
#endif
    
    calc();

    while(1){
        int m,d;
        fscanf(fp,"%d %d\n",&m,&d);
        if(m==0){ break; }
        printf("%s\n",day[month_day[m-1][d-1]]); 
    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	int n; cin>>n;
	vector<int> a(n);
	for(auto &i:a) cin>>i;
	vector<int> b(n),c(n);
	b.at(0) = a.at(0);
	for(int i=1; i<n; i++){
		b.at(i) = __gcd(b.at(i-1),a.at(i));
	}
	c.at(n-1) = a.at(n-1); 
	for(int i=n-2; i>=0; i--){
		c.at(i) = __gcd(c.at(i+1),a.at(i));
	}
	int ans{1};
	for(int i=1; i<n-1; i++){
		ans = max(ans,__gcd( b.at(i-1),c.at(i+1) ));
	}
	ans = max(ans,b.at(n-2));
	ans = max(ans,c.at(1));
	cout << ans << endl;
	
}

Measured memory_bytes: 1408
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar
#define putchar putchar
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

int main(void){
	char c=getchar();
	putchar(c<='Z'?'A':'a');
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  ll n;
  
  cin >> n;

  string s;
  map<char,int> iCount;
  for(int i=0;i<n;i++){
    cin >>  s;
    iCount[s[0]]++;
  }
  
  string marchStr = "MARCH";
  for(int i=0;i<marchStr.length();i++){
    //cout << marchStr[i] << ":" << iCount[marchStr[i]] << endl;
  }
  // MARCH
  ll count = 0;
  for(int i=0;i<marchStr.length()-2;i++){
  	for(int j=i+1;j<marchStr.length()-1;j++){
  	  for(int k=j+1;k<marchStr.length();k++){
        //cout << marchStr[i] << marchStr[j] << marchStr[k] << ":" << iCount[marchStr[i]]*iCount[marchStr[j]]*iCount[marchStr[k]] << endl;;
        count += (ll)iCount[marchStr[i]]*(ll)iCount[marchStr[j]]*(ll)iCount[marchStr[k]];
      }
    }
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;

ll ans,mx,sum;
int main(){
	ll r,d,x;
	cin>>r>>d>>x;
	ans = x;
	for(int i=1; i<=10; i++){
		ans = (r*ans)-d;
		cout<<ans<<endl;
	}
}

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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int w, a, b; cin >> w >> a >> b;

  if (b >= a && b <= a + w) cout << 0 << endl;
  else if (a + w >= b && a + w <= b + w) cout << 0 << endl;
  else cout << min(abs(a + w - b), abs(a - b - w)) << endl;
  
  return (0);
}

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

typedef long long ll;

vector<ll> score(int D, vector<ll> c, vector<ll> t, vector<vector<ll>> s) {
    vector<vector<ll>> last(D + 1, vector<ll>(26, 0));
    vector<ll> ret(D);
    ll p = 0;
    rep(d, D) {
        p += s[d][t[d] - 1];
        rep(i, 26) last[d + 1][i] = last[d][i];
        last[d + 1][t[d] - 1] = d + 1;
        rep(i, 26) {
            p -= c[i] * (d + 1 - last[d + 1][i]);
        }
        ret[d] = p;
    }
    return ret;
}

int main() {
    int D;
    cin >> D;
    vector<ll> c(26), t(D);
    rep(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26)), last(D + 1, vector<ll>(26, 0));
    rep(i, D) rep(j, 26) cin >> s[i][j];
    ll p = 0;
    rep(d, D) {
        ll q, r = 0, maxq = -1e18;
        rep(j, 26) {
            q = s[d][j];
            rep(i, 26) last[d + 1][i] = last[d][i];
            last[d + 1][j] = d + 1;
            rep(i, 26) {
                q -= c[i] * (d + 1 - last[d + 1][i]);
            }
            if (q > maxq) {
                maxq = q;
                r = j;
            }
        }
        t[d] = r + 1;
        p += maxq;
        rep(i, 26) last[d + 1][i] = last[d][i];
        last[d + 1][r] = d + 1;
    }
    auto ans = score(D, c, t, s);
    ll maxs = ans.back();
    //cout << maxs << "\n";
    rep(j, min(D - 1, 40)) rep(i, D - 1 - j) {
        swap(t[i], t[i + 1 + j]);
        ans = score(D, c, t, s);
        if (ans.back() > maxs) {
            maxs = ans.back();
        } else {
            swap(t[i], t[i + 1 + j]);
        }
    }
    rep(i, D) cout << t[i] << "\n";
}

Measured memory_bytes: 4016
#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int iMax;
	cin >> iMax;
	for (int i = 0; i < iMax; ++i){
		vector<int> x;
		int t;
		for (int j = 0; j < 3; ++j){
			cin >> t;
			x.push_back(t);
		}
		sort(x.begin(), x.end());
		if (pow(x[0], 2)+pow(x[1], 2) == pow(x[2], 2)){
			cout << "YES" << endl;
		} else{
			cout << "NO" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
#define br "\n"
#define MAX  1000001
#define ff first
#define ss second

vector<vll> v;
ll dp[3001][3001][4];

void solve(){
    ll n,m,cunt;
    cin >> n >> m >> cunt;
    v.resize(n + 1,vll(m + 1,0));
    rep(i,0,n + 1){
        rep(j,0,m + 1){
            rep(k,0,4) dp[i][j][k] = 0;
        }
    }
    rep(i,0,cunt){
        ll a,b,val;
        cin >> a >> b >> val;
        v[a][b] = val;
    }
    // for(auto x:v){
    //     for(auto y:x) cout << y << " ";
    //     cout << br;
    // }

    rep(i,1,n + 1){
        rep(j,1,m + 1){
            ll mx=0;
            rep(k,1,4) mx = max(dp[i - 1][j][k],mx);
            rep(k,1,4) dp[i][j][k] = max(mx + v[i][j],max(dp[i][j - 1][k],dp[i][j - 1][k - 1] + v[i][j]));
            // cout << dp[i][j][1] << " ";
            
        }
        // cout << br; 
    }
    // for(auto x:sum){
    //     for(auto y:x) cout << y << " ";
    //     cout << br;
    // }
    ll ans = 0;
    rep(i,0,4) ans = max(ans,dp[n][m][i]);
    cout << ans << br;


}
	

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif  
        ll t = 1;
        // cin >> t;
        rep(i,0,t){
            solve();
        }
 
}	

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

constexpr int64_t MAX_LEN = 200000;
set<int64_t> up[MAX_LEN + 1], right_st[MAX_LEN + 1], down[MAX_LEN + 1], left_st[MAX_LEN + 1];
set<int64_t> downs[MAX_LEN * 2 + 1], lefts[MAX_LEN * 2 + 1];

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> X(N), Y(N), dir_num(N);
    vector<char> U(N);

    map<char, int64_t> dirChar2dirNum = {
            { 'U', 0 },
            { 'R', 1 },
            { 'D', 2 },
            { 'L', 3 }
    };

    for (int64_t i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> U[i];
        dir_num[i] = dirChar2dirNum[U[i]];
    }

    int64_t ans = LLONG_MAX;

    //まず正面衝突があるか調べる
    for (int64_t i = 0; i < N; i++) {
        if (U[i] == 'U') {
            up[X[i]].insert(Y[i]);
        } else if (U[i] == 'R') {
            right_st[Y[i]].insert(X[i]);
        } else if (U[i] == 'D') {
            down[X[i]].insert(Y[i]);
        } else if (U[i] == 'L') {
            left_st[Y[i]].insert(X[i]);
        }
    }

    //下向きの一番大きい位置と,上向きの一番小さい位置を比べて交差するかを検証
    for (int64_t x = 0; x <= MAX_LEN; x++) {
        if (down[x].empty() || up[x].empty()) {
            continue;
        }

        for (int64_t up_p : up[x]) {
            //これより大きいのがあれば一番近いやつを見る
            auto itr = down[x].lower_bound(up_p);
            if (itr != down[x].end()) {
                ans = min(ans, 5 * (*itr - up_p));
            }
        }
    }

    for (int64_t y = 0; y <= MAX_LEN; y++) {
        if (left_st[y].empty() || right_st[y].empty()) {
            continue;
        }

        for (int64_t right_p : right_st[y]) {
            auto itr = left_st[y].lower_bound(right_p);
            if (itr != left_st[y].end()) {
                ans = min(ans, 5 * (*itr - right_p));
            }
        }
    }
    
    //90度での衝突を調べる
    for (int64_t j = 0; j < 4; j++) {
        //downとleftの衝突だけを調べる
        //x + yが一致しているものがぶつかりそう
        for (int64_t xy = 0; xy <= MAX_LEN * 2; xy++) {
            downs[xy].clear();
            lefts[xy].clear();
        }

        for (int64_t i = 0; i < N; i++) {
            if (dir_num[i] == dirChar2dirNum['D']) {
                downs[X[i] + Y[i]].insert(Y[i]);
            } else if (dir_num[i] == dirChar2dirNum['L']) {
                lefts[X[i] + Y[i]].insert(Y[i]);
            }
        }

        //
        for (int64_t xy = 0; xy <= MAX_LEN * 2; xy++) {
            for (int64_t left_p : lefts[xy]) {
                auto itr = downs[xy].lower_bound(left_p);
                if (itr != downs[xy].end()) {
                    ans = min(ans, 10 * (*itr - left_p));
                }
            }
        }

        //90度回転
        for (uint64_t i = 0; i < X.size(); i++) {
            swap(X[i], Y[i]);
            Y[i] = MAX_LEN - Y[i];
            (++dir_num[i]) %= 4;
        }
    }

    if (ans == LLONG_MAX) {
        cout << "SAFE" << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 101596
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 x = sc.nextInt();
    	int y = sc.nextInt();

    	int sum1 = 0;
    	int sum2 = 0;
    	int sum3 = 0;

    	//aピザ　bピザ
    	sum1 = a * x + b * y;

    	//abピザも購入
    	if (x < y){
    		sum2 = x * c * 2 + (y - x) * b;
    		sum3 = y * c * 2;

    	} else {
    		sum2 = y * c * 2+ (x - y) * a;
    		sum3 = x * c * 2;
    	}


    	// 出力
    	//System.out.println(sum1);
    	//System.out.println(sum2);
    	System.out.println(Math.min(Math.min(sum1, sum2), sum3));
    }
}

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

int main() {
  int A , B;
  cin >> A >> B;
  if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
    cout << "Possible"  << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 256