akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll MOD = 998244353;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}
  mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}
  mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}
  mint operator+(const mint a) const {mint res(*this);return res+=a;}
  mint operator-(const mint a) const {mint res(*this);return res-=a;}
  mint operator*(const mint a) const {mint res(*this);return res*=a;}
  mint pow(ll b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // for prime MOD
  mint inv() const {return pow(MOD-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {mint res(*this);return res/=a;}
};
ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;}

int main2() {
  int N = nextLong();
  int K = nextLong();
  vector<pair<int,int>> rs(K);
  REP(i, K) {
    rs[i].first = nextLong();
    rs[i].second = nextLong();
  }

  vector<mint> dp(N+10);
  vector<mint> S(N+10);

  dp[1] = 1;
  S[1] = 1;
  for (int n = 2; n <= N; n++) {
    mint val = 0;
    REP(k, K) {
      int a = rs[k].first;
      int b = rs[k].second;
      val += (n-a >= 0 ? S[n-a] : 0) - (n-b-1 >= 0 ? S[n-b-1] : 0);
    }
    dp[n] = val;
    S[n] = S[n-1] + dp[n];
  }

  // if (N <= 5) {
  //   pv(ALL(dp));
  //   pv(ALL(S));
  // }

  mint ans = dp[N];
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 6352
import math
a,b = map(int,input().split())


def one_of(k,n):
    s=math.pow(2,k)
    matomari = ((n+1) // (s*2))*s

    amari = (n+1) % (s*2)
    if amari > s:
        amaribun=amari - s
    else:
        amaribun = 0

    return int(matomari + amaribun)


#
# for i in range(15):
#     print(one_of(2,i))

ans = 0
for i in range(40):
    pality=0
    one_of_A=0 #A-1まで何個でてますか
    one_of_B=0 #Bまで何個出てますか
    #one_of_A

    #one_of_B


    #palityを計算

    pality=(one_of(i,b)-one_of(i,a-1))%2
    if pality == 1:
        ans += int(math.pow(2,i))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	string a, b;
	cin >> n;
	cin >> a >> b;
	int cnt = 0;
	for (int k = 0; k < n; ++k){
		int i = k, j = 0, temp = 0;
		while (i < n && a[i] == b[j])
			++temp, ++i, ++j;
		cnt = max(cnt, temp);
	}
	int ans = 2 * n;
	cout << max(n, ans - cnt);
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
for i in range(N):
    if A[i]>B[i]:
        ans+=B[i]
    elif A[i]<=B[i]<A[i]+A[i+1]:
        ans+=B[i]
        A[i+1]-=B[i]-A[i]
    else:
        ans+=A[i]+A[i+1]
        A[i+1]=0
print(ans)

Measured memory_bytes: 24048
#include <bits/stdc++.h>
using ull = unsigned long long;
using ul = unsigned;
using ll = long long;
#define mod 10e+7+7
#define rep(i,a,b) for (int i =a;i<b;++i)
using namespace std;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin); 
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
#endif
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve(); 
	 cout<<"\n";
	}
	
	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;

}
int dp[3000][3000];
void solve()
{
	string s,t;
	cin>>s>>t;
	int n1=s.size();
	int n2=t.size();
	

	//cout<<s<<" "<<t;

	if(s[0]==t[0])
		dp[0][0]=1;
	else 
		dp[0][0]=0;
	for(int i=0;i<n1;i++)
	{
		for(int j=0;j<n2;j++)
		{ 
			//dp[i][j]=0;

			if(i>0)
			dp[i][j]=dp[i-1][j];

			if(j>0)
			{
				if(dp[i][j]<dp[i][j-1])	
				dp[i][j]=dp[i][j-1];
			}
			
			if(s[i]==t[j])
			{
				int	an=1;
				//dp[i][j]=0;
				if(i>0&&j>0)
				{
					an=1+dp[i-1][j-1];
					
				}
				
				if(an>dp[i][j])
				dp[i][j]=an;
					
			}

		}
	}
	/*for(int i=0;i<n1;i++)
	{
		for(int j=0;j<n2;j++)
		{
		cout<<dp[i][j]<<"\t"; 
		}
		cout<<"\n";
	}*/
	int k=dp[n1-1][n2-1];
	int i=n1-1,j=n2-1;
	string a="";
	while(k>0)
	{
		if(s[i]==t[j])
		{
			a=s[i]+a;
			i--;
			j--;
		}
		if(i>0&&dp[i][j]==dp[i-1][j])
		{
				i--;
		}
		if(i<0)
			break;
		else if(j>0&&dp[i][j]==dp[i][j-1])
		{
			j--;
		}
		if(j<0)
			break;
		k=dp[i][j];
	}
	//cout<<dp[n1-1][n2-1];
	cout<<a;
}

Measured memory_bytes: 39080
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
map<char,string> mp;
int main(){
for (char c='a';c<='c';++c) cin>>mp[c];
char r='a';
for (;;){
  if (mp[r].empty()) return pc(r-32),0;  
  char now=mp[r][0];
  mp[r].erase(0,1);
  r=now;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int MOD = 1e9 + 7;

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}
// auto v = make_vec<int>(h, w);
// fill(v, 0);

signed main(){

  int n, x; cin >> n >> x;
  vector<int> s(n);
  for(int i = 0; i < n; i++) cin >> s[i];
  sort(s.begin(),s.end());

  auto dp = make_vec<int>(n+1, x+1);
  for(int i = 0; i <= x; i++){
    dp[0][i] = i;
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= x; j++){
      dp[i+1][j] += dp[i][j % s[i]]; dp[i+1][j] %= MOD;
      dp[i+1][j] += dp[i][j] * i; dp[i+1][j] %= MOD;
    }
  }
  cout << dp[n][x] << endl;

  return 0;
}


Measured memory_bytes: 158592
import sys
import math
from functools import reduce
from operator import mul
sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, sys.stdin.readline().split(' ')))
def In(): return int(sys.stdin.readline())
def InS(): return sys.stdin.readline()

L = In()
vol = L*L*L
print(vol/27)

Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int l[100000],r[100000] = {};
    for(int i=0;i<Q;i++){
        cin >> l[i] >> r[i];
    }
    int Count = 0;
    int Count2[100000] = {};
    
    for(int i=0;i<N;i++){
        if(S[i] == 'A' && S[i+1] == 'C'){
            Count++;
        }
        Count2[i+1] = Count;
    }
    
    int ans = 0;
    for(int i=0;i<Q;i++){
        ans = Count2[r[i]-1]-Count2[l[i]-1];
        cout <<  ans << endl;
    }
    return 0;
}



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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

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

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
ll ans = 1e12;
void calc(VLL &v) { chmin(ans, *max_element(all(v)) - *min_element(all(v))); }

void solve(int h, int w) {
  rep(i, h / 2) {
    ll left = (i + 1) * w;
    ll less = h - (i + 1);
    if(w % 2 == 0) {
      ll right = less * w / 2;
      chmin(ans, abs(left - right));
    } else {
      VLL v = {left, less * (w / 2), less * ((w + 1) / 2)};
      calc(v);
      VLL v2 = {left, ((less + 1) / 2) * w, (less / 2) * w};
      calc(v2);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;

  solve(h, w);
  solve(w, h);

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


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b&&b == c) {
		if(a%2==0)cout << -1 << endl;
		else cout << 0 << endl;
	}
	else {
		int cnt = 0;
		while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
			int A = c / 2 + b / 2, B = a / 2 + c / 2, C = a / 2 + b / 2;
			a = A; b = B; c = C;
			cnt++;
		}
		cout << cnt << endl;

	}


	return 0;
}


Measured memory_bytes: 256
i = 0
for i in range(3000):
    input_x, input_y =(int(x) for x in input().split())
    
    if input_x == 0 and input_y == 0:
        break
    if input_x < input_y:
        print(input_x, input_y)
    else:
        print(input_y,input_x)


Measured memory_bytes: 5620
# -*- coding: utf-8 -*-
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.append(A[0]+K)

distance_max = 0
for i in range(N):
    if distance_max < A[i+1] - A[i]:
        distance_max = A[i+1] - A[i]

print(K-distance_max)
        


Measured memory_bytes: 26444
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;
int main()
{
    long long m,n,xx1,xx;
    while(cin>>n>>m)
          {
            xx1=min(m/2,n);
            xx=m-xx1*2;
               cout<<xx1+xx/4<<"\n";

          }
    return 0;

}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


ll n, a[100005];
ll ans = 1;
bool j = true;

int main() {

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

	rep(i, n) {
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	rep(i, n) {
		if (a[i] <= 1000000000000000000 / ans) {
			ans *= a[i];
		}
		else {
			ans = -1;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define LP(i, a, n) for(int i = a; i < n; i++)
#define lpp(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
  char s[10];
  int a, b;
  vector<int> nums;
  while(scanf("%s", s) != EOF){
    if(s[0] == '*') {
      a = nums.back();
      nums.pop_back();    
      b = nums.back();
      nums.pop_back();
      nums.push_back(a*b);
    }
    else if(s[0] == '+') {
      a = nums.back();
      nums.pop_back();    
      b = nums.back();
      nums.pop_back();
      nums.push_back(a+b);
    }
    else if(s[0] == '-'){
      b = nums.back();
      nums.pop_back();    
      a = nums.back();
      nums.pop_back();
      nums.push_back(a-b);
    }
    else nums.push_back(atoi(s));
  }
  cout << nums[0] << endl;
  return 0;
}



Measured memory_bytes: 3256
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
	int n,q,num,v;
	cin >> n >> q;
	
	vector<int> wakasagi(n+1, 0);
	priority_queue<pair<int, int> > pq;
	for(int i=0;i<q;i++){
		 cin >> num >> v;
		 wakasagi[num] += v;
		 pq.push(make_pair(wakasagi[num],-num));
		  for(;;){
            int b = -pq.top().second;
            int w = pq.top().first;
            if(wakasagi[b] == w){
                cout << b << ' ' << w << endl;
                break;
            }
            pq.pop();
        }
		 
	}
	
}

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

int main() {
    int n;
    cin >> n;
    char c;
    bool flag=false;
    for(int i=0; i<n; i++) {
        cin >> c;
        if(c=='Y') flag=true;
    }
    if(flag) cout << "Four" << endl;
    else cout << "Three" << endl;
    return 0;
}

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

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7;
const double eps = 1e-9;

int main()
{
	int n;
	cin >> n;
	if (n == 1)
		cout << "Hello World";
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  while(1){
    int e,m,x,min=1000000000;
    cin>>e;
    if(e==0)break;

    for(int z=0;z*z*z<=e;z++)  
      for(int y=0;y*y<=e-z*z*z;y++){
	  x=e-z*z*z-y*y;
	  m=x+y+z;
	  if(m<min)min=m;
	}
      cout<<min<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define PI 3.14159265358979323846264338327950L
using namespace std;

int main()
{
	int A, B, H, M;
	cin >> A >> B >> H >> M;

	double x_h, y_h, x_m, y_m;
	double theta_h, theta_m;

	double ans;

	theta_m = (double)M * (360.0 / 60.0);		//deg
	theta_h = (double)(H + M/60.0) * (360.0 / 12.0);
	
	x_h = (double)A * sin(theta_h * PI / 180.0);
	x_m = (double)B * sin(theta_m * PI / 180.0);
	y_h = (double)A * cos(theta_h * PI / 180.0);
	y_m = (double)B * cos(theta_m * PI / 180.0);

	ans = sqrt((x_h - x_m) * (x_h - x_m) + (y_h - y_m) * (y_h - y_m));

	printf("%20.20f\n", ans);

	return 0;
}

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

#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define REP(i,k,N) for(int i=k;i<(int)(N);i++)

using namespace std;
int main(){
    int N,M;
    while(cin >> N >> M,N) {
        int t[1000], n[1000], m[1000], s[1000];
        int r, q, begin, end, id;
        cin >> r;
        rep(i, r) cin >> t[i] >> n[i] >> m[i] >> s[i];
        cin >> q;
        rep(i, q) {
            cin >> begin >> end >> id;
            //ここまで入力

            int ans = 0,  pc= 0, tmp;
            rep(j, r) {
                if (m[j] != id)continue;
                if (s[j] == 1) {
                    //ログイン
                    pc++;
                    if (pc == 1) tmp = t[j];
                }else{
                    //ログアウト
                    pc--;
                    if (pc == 0 && begin <= t[j] && tmp <= end) {
                        ans += (min(end, t[j]) - max(begin, tmp));
                    }
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}


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

int main() {
    
    long h,w;
    cin >> h >> w;
    
    unsigned long long ans ;
    ans = h*(w/2);
    if(w%2==1){
        ans+=(h+1)/2;
    }
    if(w==1||h==1){
        ans =1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC diagnostic ignored "-Wunused-result"

#include <cstdio>
#include <chrono>
#include <random>

using namespace std;
using namespace chrono;

constexpr int c_max = 26;
constexpr int D = 365;
constexpr int INF = 1e9;
constexpr int time_limit = 1987;

int c[c_max];
int s[D][c_max];
int best_score[D];
int last[c_max];
int schedule[D];

inline int calc_score(const int &day, const int &examining) {
  int ret;
  if (day == 0) ret = s[day][examining];
  else ret = best_score[day - 1] + s[day][examining];
  
  for (int i = 0; i < c_max; i++) {
    if (i == examining) continue;
    ret -= (day - last[i]) * c[i];
  }

  return ret;
}

inline int calc_score_diff(const int &day1, const int &day2) {
  int prev_interval_1 = 0;
  for (int i = day1 - 1; i >= 0; i--) {
    prev_interval_1++;
    if (schedule[i] == schedule[day1]) break;
  }

  int prev_interval_2 = 0;
  for (int i = day2 - 1; i >= 0; i--) {
    prev_interval_2++;
    if (schedule[i] == schedule[day2]) break;
  }

  int new_interval_1 = 0;
  for (int i = day2 - 1; i >= 0; i--) {
    new_interval_1++;
    if (schedule[i] == schedule[day1]) break;
  }

  int new_interval_2 = 0;
  for (int i = day1 - 1; i >= 0; i--) {
    new_interval_2++;
    if (schedule[i] == schedule[day2]) break;
  }

  int ret = s[day1][schedule[day2]] + s[day2][schedule[day1]]
          - s[day1][schedule[day1]] - s[day2][schedule[day2]];
  
  ret += c[schedule[day1]] * ((prev_interval_1 + 1) * prev_interval_1 - (new_interval_1 + 1) * new_interval_1) / 2;
  ret += c[schedule[day2]] * ((prev_interval_2 + 1) * prev_interval_2 - (new_interval_2 + 1) * new_interval_2) / 2;

  return ret;
}

int main() {
  system_clock::time_point start = system_clock::now(), now;

  random_device seed;
  mt19937 rnd(seed());

  /* input */
  scanf("%*d");

  for (int i = 0; i < c_max; i++) {
    scanf("%d", &c[i]);
  }

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < c_max; j++) {
      scanf("%d", &s[i][j]);
    }
  }

  /* calc initial solution */
  for (int d = 0; d < D; d++) {
    int best = -INF;
    int contest_to_hold = 0;
    for (int type = 0; type < c_max; type++) {
      int score = calc_score(d, type);
      if (best < score) {
        best = score;
        contest_to_hold = type;
      }
    }
    last[contest_to_hold] = d;
    schedule[d] = contest_to_hold;
  }

  /* try and error */
  int day1, day2, score_diff, tmp;
  while (1) {
    now = system_clock::now();
    if (duration_cast<milliseconds>(now - start).count() > time_limit) break;
    day1 = rnd() % D;
    day2 = rnd() % D;
    score_diff = calc_score_diff(day1, day2);
    if (score_diff < 0) {
      tmp = schedule[day1];
      schedule[day1] = schedule[day2];
      schedule[day2] = tmp;
    }
  }

  /* output */
  for (const int &x : schedule) {
    printf("%d\n", x+1);
  }

  return 0;
}

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

int main(){
    int q; cin >> q;
    map<string,int> m;
    rep(i ,q){
        int man; cin >> man;
        string key;
        int x;
        map<string,int>::iterator itr;
        decltype(m)::iterator itr1;
        decltype(m)::iterator itr2;
        switch (man)
        {
            case 0:
                cin >> key >> x;
                m[key] = x;
                break;
            case 1:
                cin >> key;
                itr = m.find(key);
                if(itr == m.end()) cout << 0 << endl;
                else cout << itr->second << endl;
                break;
            case 2:
                cin >> key;
                m.erase(key);
                break;
            case 3:
                string l , r;
                cin >> l >> r;
                itr1 = m.lower_bound(l);
                itr2 = m.upper_bound(r);
                itr = itr1;
                for(;itr!=itr2;++itr){
                    cout << itr->first << " " << itr->second << endl;
                }
                break;
        }
    }
}


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

int main() {
  int n,x,y;
  cin>>n>>x>>y;
  vector<int>a;
    for(int i=1;i<=n-1;i++){
      for(int j=i+1;j<=n;j++){
        int b=j-i;
        int c=abs(i-x)+abs(j-y)+1;
        a.push_back(min(b,c));
      }
    }
  int d=a.size();
  sort(a.begin(),a.end());
  int de=0;
  for(int k=1;k<n;k++){
    int ans=0;
    for(int i=de;i<d;i++){
      if(a[i]==k) ans++;
      else break;  
      de++;
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 10348
#include <stdio.h>
#include <stdlib.h>

int greater_int(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main(int argc, char *argv[]) {
    int n;
    int a[100];

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    qsort(a, n, sizeof(int), greater_int);

    int alice = 0;
    int bob = 0;

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }

    printf("%d\n", alice - bob);

    return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> v(m);

    priority_queue<int> pq;
    int sum = 0;
    for (int i = 0; i < m; i++)
        cin >> v[i];
    sort(v.begin(), v.end());
    for (int i = 0; i < m; i++) {
        if (i)
            pq.push(v[i] - v[i - 1]), sum += v[i] - v[i - 1];
    }
    for (int i = 0; i < n - 1 and !pq.empty(); i++)
        sum -= pq.top(), pq.pop();
    cout << sum << endl;
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 4928
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


int main(){
  int A, B;
  scanf("%d", &A);
  scanf("%d", &B);
  int min = std::min(A, B);
  int max = std::max(A, B);
  char ans[100][100];
  for (int i=0; i<100; i++){
    for (int j=0; j<100; j++){
      ans[i][j]='.';
    }
  }
  int counter=0;
  int i=0;
  int j=0;
  while(counter<min-1){
    //printf("counter=%d\n", counter);
    ans[i][j]='#';
    ans[i][j+1]='#';
    ans[i][j+2]='#';
    ans[i+1][j+2]='#';
    ans[i+2][j+2]='#';
    ans[i+2][j+1]='#';
    ans[i+2][j]='#';
    ans[i+1][j]='#';
    j+=4;
    if (j+2>=100){
      j=0;
      i+=4;
    }
    counter++;
  }
  // (#, .) = (min-1, min)
  i=99;
  j=0;
  while(counter<max){
    ans[i][j]='#';
    counter++;
    j+=2;
    if (j>=100){
      j=0;
      i-=2;
    }
  }
  
  if (A==max){
    for (int i=0; i<100; i++){
      for (int j=0; j<100; j++){
	ans[i][j]=(ans[i][j]=='.'?'#':'.');
      }
    }
  }
  
  printf("100 100\n");
  for (int i=0; i<100; i++){
    for (int j=0; j<100; j++){
      printf("%c", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}
 

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define foru(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
int t;
int n,d;
int main() {
//   freopen("input.txt","r",stdin);
   string s;
   cin>>s;
   stack<int> S;
   for(int i=0;i<s.size();++i){
      if(s[i]=='S')S.push(s[i]);
      else if(!S.empty()&&S.top()=='S')S.pop();
      else S.push(s[i]);
   }
   cout<<S.size();
   return 0;
}


Measured memory_bytes: 1284
S = input()

before, after = int(S[:2]), int(S[2:])

if 0 < before and before <= 12 and 0 < after and after <= 12:
	print('AMBIGUOUS')
elif (before > 12 or before == 0) and 0 < after and after <= 12:
	print('YYMM')
elif 0 < before and before <= 12 and (12 < after or after == 0):
	print('MMYY')
else:
	print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  cout << min(N*A,B) << endl;
}

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

using namespace std;

int n, a, b, ar[12345];

void init()
{
	scanf("%d", &n);
	scanf("%d", &a);
	scanf("%d", &b);
	for (int i = 0; i < n; ++i)
		{
			scanf("%d", &ar[i]);
		}	
	int cnt = 0;
	for (int i = 0; i < n; ++i)
	{
		if(ar[i] < a || ar[i] >= b) cnt++;
	}
	printf("%d\n", cnt);
}

int main()
{
/*
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
*/
	init();

	return 0;
}

Measured memory_bytes: 256
// ABC142 A

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

using namespace std;

int main() {
  
  int n; cin >> n;
  int odd = (n + 1) / 2;
  printf("%.10lf", 1.0 * odd / n);

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 256
/*
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104
?????????: Country Road
*/

#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;

int n;
int k;
int x[114514];



int difflist[114514];


signed main()
{
	int t;
	cin >> t;
	for(int i=0; i<t; i++){
		cin >> n >> k;
		for(int j=0; j<n; j++){
			cin >> x[j];
		}
		for(int l=0; l<n-1; l++) {
			difflist[l] = x[l+1] - x[l];
		} // ??¶??????????????¢???????????????
		sort(difflist, difflist+(n-1)); // ?°???????????????????????????????????????????n-2?????§?????????????????§???n-1
		if(n<=k) { //?????????????????£??????????????´???????????????
			cout << 0 << endl;
		} else {
			// ????????????1???????????¨??¨???????????????????????????????¢?????????????????????????????????????
			cout << accumulate(difflist, difflist+(n-k), 0) << endl;
		}
	}
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int a[105];
int main(){
    int n;
    scanf("%d", &n);   
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    int ans = 1e9;
    for(int j=-100;j<=100;j++){
        int res = 0;
        for(int i=1;i<=n;i++) res += abs(a[i]-j)*abs(a[i]-j);
        ans = min(ans, res);
    }
    printf("%d\n", ans);
}

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

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  int n;
  cin >> n;
  int n100 = n / 100;
  int n010 = (n % 100) / 10;
  int n001 = (n % 10);
  if (n100 == 1)
    n100 = 9;
  else if (n100 == 9)
    n100 = 1;
  if (n010 == 1)
    n010 = 9;
  else if (n010 == 9)
    n010 = 1;
  if (n001 == 1)
    n001 = 9;
  else if (n001 == 9)
    n001 = 1;
  int ans = 0;
  ans += (n100 * 100) + (n010 * 10) + n001;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;
public class Main{
    static int[][] grid;
    static int[][] memo;
    static int r;
    static int c;
    static int mod = (int) (1e9 + 7);
    public static void main(String[] args) throws IOException {
        scanner sc = new scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        r = sc.nextInt();
        c = sc.nextInt();

        grid = new int[r][c];

        for (int i = 0; i < r; i++) {
            String s = sc.next();
            for (int j = 0; j < c; j++) {
                if (s.charAt(j) == '.')
                    grid[i][j] = 0;
                else grid[i][j] = 1;
            }
        }

        memo = new int[r][c];
        for (int i = 0; i < r; i++)
            Arrays.fill(memo[i],-1);

        out.println(dp(0,0));
        out.flush();

    }

    static int dp(int i,int j){

        if (i == r-1 && j == c-1)
            return 1;

        if (memo[i][j] != -1) return  memo[i][j];

        int right = 0;
        int down = 0;

        if (valid(i+1,j))
            down = dp(i+1,j);

        if (valid(i,j+1))
            right = dp(i,j+1);

        return memo[i][j] = (right+down)%mod;

    }
    static boolean valid(int x,int y){
        if (x >= r || y >= c || grid[x][y] == 1)
            return false;
        return true;
    }
}
class scanner{
    StringTokenizer st;
    BufferedReader br;
    public scanner(InputStream s){
        br = new BufferedReader(new InputStreamReader(s));
    }
    public scanner (String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s));}

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
        return  Long.parseLong(next());
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public boolean ready() throws IOException {
        return br.ready();
    }
}

Measured memory_bytes: 36744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1e9 + 7;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> dis(n, -1);
    function<void(int, int)> dfs = [&](int v, int d) 
    {
        dis[v] = d;
        for(int nx : g[v])
        {
            if(dis[nx] >= 0) continue;
            dfs(nx, d + 1);
        }
    };
    dfs(0, 1);
    int ma = 0;
    int pos = 0;
    for(int i = 0; i < n; i++)
    {
        if(ma < dis[i])
        {
            ma = dis[i];
            pos = i;
        }
    }
    for(int i = 0; i < n; i++) dis[i] = -1;
    dfs(pos, 1);
    ma = 0;
    for(int i = 0; i < n; i++)
    {
        if(ma < dis[i])
        {
            ma = dis[i];
        }
    }
    if(ma % 3 == 2) cout << "Second" << endl;
    else cout << "First" << endl;
}


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

"""
参考：https://img.atcoder.jp/abc121/editorial.pdf
　　　https://www.youtube.com/watch?v=igfVeTsGeYw
・2周期じゃなくて4周期で分ける版
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,B=MAP()

def calc(n):
    # 4周期で場合分け
    if n%4==0:
        return n
    elif n%4==1:
        return 1
    elif n%4==2:
        return n+1
    else:
        return 0

# [A,B]の区間XOR
print(calc(B)^calc(A-1))


Measured memory_bytes: 5628
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class DBrickBreak {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        int a[200010];
        in >> n;
        rep(i, n){
            in >> a[i];
        }

        int now = 0;
        rep(i, n){
            if(a[i] == now+1){
                now++;
            }
        }

        if(now == 0) out << -1 << endl;
        else out << n-now << endl;
	}
};


int main() {
	DBrickBreak solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long
const int maxn = 100 + 100;
int n, m, ans;
int num[maxn][maxn];

int Sqrt(int x) {
    int xx = sqrt(x);
    return xx * xx == x;
}

int judge(int i, int j) {
    int sum = 0;
    for(int k = 0; k < m; ++k) {
        sum += (num[i][k] - num[j][k]) * (num[i][k] - num[j][k]);
    }
    return Sqrt(sum);
}

int main() {
    ios::sync_with_stdio(false);

    while(scanf("%d%d", &n, &m) != EOF) {
        ans = 0;
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                scanf("%d", &num[i][j]);
            }
        }
        for(int i = 0; i < n; ++i) {
            for(int j = i + 1; j < n; ++j) {
                ans += judge(i, j);
            }
        }
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    cout<<fixed<<setprecision(20)<<pow(in()/3.0,3)<<endl;
}


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

char maze[21][21];
int dist[21][21];

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

void reset_dist(){
    rep(i,21)rep(j,21) dist[i][j]=-1;
}

int main(){
    int h,w;
    cin >> h >> w;
    int ans=0;
    rep(i,21)rep(j,21)maze[i][j]='#';
    rep(i,h){
        string s;
        cin >> s;
        rep(j,s.size()) {
            dist[i][j]=-1;
            maze[i+1][j+1]=s[j];
            }
    }

    for(int i=1;i<21;++i){
        for(int j=1;j<21;++j){
            int sx,sy;
            sy = i; sx = j;
            reset_dist();
            if(maze[sy][sx]=='#') continue;
            dist[sy][sx]=0;

            //cout <<"s: " << sy << sx << endl;
            queue<P> Q;
            P p(0,0);
            p.first = sy; p.second = sx;
            Q.push(p);
            
            int current_max = 0;
            //cout << "ok" << endl;
            while(1){
                //cout << "ok2" << endl;
                P p(0,0);
                p = Q.front();
                Q.pop();
                int x,y;
                x = p.second; y = p.first;
                //int current_max = 0;
                rep(i,4){
                    if(((y+dy[i])>20) || ((x+dx[i])>20)) continue;
                    if(dist[y+dy[i]][x+dx[i]]==-1){
                        if(maze[y+dy[i]][x+dx[i]]=='#') continue;
                        dist[y+dy[i]][x+dx[i]]=dist[y][x]+1;
                        //cout << "dist" << dist[y+dy[i]][x+dx[i]] << endl;
                        current_max = max(current_max, dist[y+dy[i]][x+dx[i]]);
                        P p(0,0);
                        p.first = y+dy[i]; p.second = x+dx[i];
                        Q.push(p);
                    }
                //cout << "now: " << y+dy[i]<< ":" << x+dx[i] << endl;
                }
                if(Q.empty())break;
            }
            ans = max(ans,current_max);

        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int num[2001]={0};
int main(){
  int n;
  rep(i,1001)rep(j,1001)num[i+j]++;
  while(cin>>n){
    int ans=0;
    rep(i,2001){
      if(n-i<0)break;
      if(n-i>2000)continue;
      ans+=num[i]*num[n-i];
    }
    cout<<ans<<endl;
  }

}

Measured memory_bytes: 1168
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Fri Jan 11 02:25:48 2019
//
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)
	for i := 1; i < len(S); i++ {
		s := S[:len(S)-i]
		if s[:len(s)/2] == s[len(s)/2:] {
			fmt.Println(len(s))
			return
		}
	}
}


Measured memory_bytes: 512
/**
    And in the end, the love you take is equal to the love you make.

        I LOVE YOU LAURA.
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_DISABLE_PERFCRIT_LOCKS

#define findOrder find_by_order
#define orderKey order_of_key

#define isOn(mask, i) (mask & (1 << i))
#define turn(mask, i) (mask |= (1 << i))
#define switch(mask, i) (mask &= ~(1 << i))
#define change(mask, i) (mask ^= (1 << i))
#define lowbit(mask) (mask & (-mask))
#define turnAll(mask, n) (mask = (1 << n) - 1)
#define switchLastBit(mask) (mask & (mask - 1))
#define turnLastZero(mask) (mask | (mask + 1))
#define modulo(x, mod) ((x) & (mod - 1))
#define log2(x) (31 - __builtin_clz(x))

#define mkp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ins insert
#define rsz resize
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define debug(x) (cerr << x << " ")

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdb;
typedef pair<int, ii> tri;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vdb;
typedef vector<cd> vcd;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vll> matrix;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_tree;

const ll mod = 1e9+7;
const int maxn = 2e5+2;
const int pi = 2 * acos(0.0);
const db eps = 1e-9;

int n;
ll arr[17][17], dp[1 << 17], cost[1 << 17];

ll invert_mask (int n){
    int ans = n;
    for (int i = 0; i < log2(n); i++){
        change(ans, i);
    }
    return ans;
}

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

    int n; cin >> n;

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

    memset(dp, -1, sizeof dp);

    for (int i = 0; i < n; i++) dp[i] = 0;

    for (int mask = 0; mask < (1 << n); mask++){
        for (int i = 0; i < n; i++){
            for (int j = i + 1; j < n; j++){
                if ((mask & (1 << i)) && (mask & (1 << j))){
                    cost[mask] += arr[i][j];
                }
            }
        }
    }

    for (int mask = 0; mask < (1 << n); mask++){
        for (int submask = mask; submask; submask = (submask - 1) & mask){
            dp[mask] = max(dp[mask], dp[mask ^ submask] + cost[submask]);
        }
    }

    cout << dp[(1 << n) - 1] << "\n";


    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] g={0,1,3,1,2,1,2,1,1,2,1,2,1};
    String result=g[sc.nextInt()]==g[sc.nextInt()]?"Yes":"No";
   System.out.println(result); 
  }
}

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    mint ans = 0;
    ans += mint(2).pow(n);
    ans -= mint(1);
    mint c = 1;
    for (int i=0;i<a;i++){
        c *= mint(n-i);
        c /= mint(a-i);
    }
    ans -= c;
    c = 1;
    for (int i=0;i<b;i++){
        c *= mint(n-i);
        c /= mint(b-i);
    }
    ans -= c;
    cout << ans << "\n";
}

Measured memory_bytes: 256
import sys
#from collections import deque
#from functools import *
#from fractions import Fraction as f
from copy import *
from bisect import *	
#from heapq import *
#from math import ceil
#from itertools import permutations ,product
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def bo(i):
	return ord(i)-ord('A')	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())			
def gh():
	sys.stdout.flush()
def isvalid(i,j):
	return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)
mod=10**9+7
t=1
while t>0:
	t-=1
	n=fi()
	a=[]
	b=[]
	for i in range(n):
		x,y=mi()
		a.append(x+y)
		b.append(x-y)
	p=max(a)-min(a)
	q=max(b)-min(b)
	print(max(p,q))	
		



Measured memory_bytes: 93444
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, m; cin >> n >> m;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
    p[i]--;
  }

  vector<vector<int>> G(n);
  for(int i = 0; i < m; i++){
    int x, y; cin >> x >> y;
    x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  vector<int> group(n, -1);
  int color = 0;
  auto dfs = [&](auto&& dfs, int u, int par)->void{
    if(group[u] != -1) return;
    group[u] = color;
    for(int v : G[u]){
      if(v == par) continue;
      dfs(dfs, v, u);
    }
  };
  for(int i = 0; i < n; i++){
    if(group[i] == -1){
      dfs(dfs, i, -1);
      color++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 9088