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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "YES";
const string NO = "NO";

const string t = "keyence";

int main(){
    string s;
    cin >> s;
    bool ans = false;
    for (int i=0; i+sz(t)<=sz(s); ++i) {
        if (s.substr(i, sz(t)) == t) ans = true;
    }
    if (!ans) {
        for (int i=0; i<=sz(t); ++i) {
            if (s.substr(0, i) + s.substr(sz(s)-(sz(t)-i), (sz(t)-i)) == t) ans = true;
        }
    }
    if (ans) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3616
// I've been expecting you <3
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
// vector<vector<ll>> v;
// ll memo[1000][100001]={-1};
// ll naive_recursive(int pointer,int capacity){
//     if(memo[pointer][capacity]!=-1)return memo[pointer][capacity];
//     if(pointer==-1||capacity==0){
//         return 0;
//     }
//     else if(v[pointer][0]>capacity){
//         memo[pointer-1][capacity]=naive_recursive(pointer-1,capacity);
//         return memo[pointer-1][capacity];
//     }
//     else{
//         memo[pointer][capacity]= max(naive_recursive(pointer-1,capacity),v[pointer][1]+naive_recursive(pointer-1,capacity-v[pointer][0]));
//         return memo[pointer][capacity];
//     }
// }
ll dp_iterative(int n,int capa,int val[], int wt[]){
    ll memo[n+1][capa+1];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=capa; j++){
            if(i==0||j==0){
                memo[i][j]=0;
            }
            else if(wt[i-1]>j){
                memo[i][j]=memo[i-1][j];
            }
            else{
                memo[i][j]=max(memo[i-1][j],val[i-1]+memo[i-1][j-wt[i-1]]);
            }
        }
    }
    return memo[n][capa];
}
int main(){
    // memset(memo,-1,sizeof(memo));
    int n,capacity;
    cin>>n>>capacity;
    int wt[n];
    int val[n];
    for(int i=0; i<n; i++){
        cin>>wt[i]>>val[i];
    }
    cout<<dp_iterative(n,capacity,val,wt);
}

Measured memory_bytes: 79104
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

vector<int> out;

void paint(int now,int before,bool cl, vector<vector<int> >& tree, vector<vector<int> >& d){
  int next,cln;
  for(int i=0;i<tree[now].size();i++){
      next=tree[now][i];

      if(out[next-1]!=3||next==before) continue;
      cln=cl^d[now][i];
      out[next-1]=cln;
      paint(next,now,cln,tree,d);
  }
}

int main(){
  int n,i,u,v,w;
  cin>>n;
  vector<vector<int> > tree(n+1);
  vector<vector<int> > d(n+1);
  
  for(i=0;i<n-1;i++){
    cin>>u>>v>>w;
    tree[u].push_back(v);
    tree[v].push_back(u);
    d[u].push_back(w%2);
    d[v].push_back(w%2);
  }


  for(i=0;i<n;i++) out.push_back(3);

  paint(1,0,0,tree,d);
	out[0]=0;
  for(i=0;i<n;i++){
    cout<<out[i]<<endl;
  }

  return 0;
}

Measured memory_bytes: 14968
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <string.h>
#include <cstdio>
using namespace std;
void deleteAllMark(string &s, const string &mark)
{
    size_t nSize = mark.size();
    while(1)
    {
        size_t pos=s.find(mark);
        if(pos==string::npos)
        {
            return;
        }
        s.erase(pos, nSize);
    }
}
int main(void)
{
    string input;
    cin >> input;
    //cout << input[input.length()-1] << endl;
    string screen="";
    for(int i=0;i<input.length();i++)
    {
        if(input[i]=='B')
        {
            deleteAllMark(screen," ");
            screen[screen.length()-1]=' ';
            deleteAllMark(screen," ");
            //cout << screen << endl;
        }
        else
        {
            screen+=input[i];
            //cout << screen << endl;
        }
    }
    cout << screen << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int a = sc.nextInt();
		String op = sc.next();
		int b = sc.nextInt();
		
		out.println(op.equals("+") ? a + b : a - b);
	}

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

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
     }

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

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

Measured memory_bytes: 20436
#include<iostream>
using namespace std;
int main()
{
	int l, r, d = 0;
	
	int count = 0;
	int i = 1;
	cin >> l >> r >> d;
	while (d*i <= r) 
	{
		int temp = d*i;
		if (temp >= l&&temp <= r)
		{
			count++;
		}
		i++;
	}
	cout << count << endl;
    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in= new Scanner(System.in);
		boolean f=false;
		while(in.hasNext())
		{
			int n=in.nextInt();
			if(n==0)
				return;
			if(f)
				System.out.println();
			f=true;
			String st[]=new String[n];
			int a[]= new int[n];
			int dex[]=new int[n];
			for(int i=0;i<n; i++)
			{
				st[i]=in.next();
				a[i]=in.nextInt()*3+in.nextInt()*0+in.nextInt();
				dex[i]=i;
			}
			for(int i=0;i<n;i++)
			{
				int m=i;
				for(int j=i;j<n; j++)
				{
					if(a[j]>a[m])
						m=j;
				}
				String tmp =st[i];
				st[i] = st[m];
				st[m] = tmp;
				int tmp2 =a[i];
				a[i]=a[m];
				a[m]=tmp2;
				int tmp6 = dex[i];
				dex[i]=dex[m];
				dex[m]=tmp6;
				for(int k=i+1;k<n; k++)
				{
					m=k;
					for(int l=k;l<n;l++)
					{
						if(dex[l]<dex[m])
							m=l;
					}
					int tmp3 = dex[k];
					dex[k]=dex[m];
					dex[m]=tmp3;
					String tmp4 =st[k];
					st[k] = st[m];
					st[m] = tmp4;
					int tmp5 =a[k];
					a[k]=a[m];
					a[m]=tmp5;
				}
			}
			for(int i=0;i<n;i++)
				System.out.println(st[i]+","+a[i]);
		}
	}
}

Measured memory_bytes: 12000
n, m = map(int,input().split())
ran=[]
for i in range(m):
    ran.append(list(map(int,input().split())))

l = [ran[i][0] for i in range(m)]
r = [ran[i][1] for i in range(m)]
x = max(l)
y = min(r)

if x>y:
    print(0)
else:
    print(y-x+1)


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

int main() {
    int N, t_now, x_now, y_now;
    int t_old, x_old, y_old;
    cin >> N;

    t_old = x_old = y_old = 0;
    for (int i=0; i<N; i++) {
        cin >> t_now >> x_now >> y_now;

        int t_diff = t_now - t_old;
        int x_diff = abs(x_now - x_old);
        int y_diff = abs(y_now - y_old);
        int dist = x_diff + y_diff;

        if (dist > t_diff || dist % 2 != t_diff % 2) {
            cout << "No" << endl;
            return 0;
        }
        t_old = t_now;
        x_old = x_now;
        y_old = y_now;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	//#define LOCAL_INPUT_FILE
#else
	//#define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	
	int n, a, b, c, d; cin >> n >> a >> b >> c >> d; --a; --b; --c; --d;
	string s; cin >> s;
	n = s.size();
	
	auto isDouble = [&](int l, int r) {
		for (int i = l; i < r; ++i) {
			if (s[i] == '#' && s[i+1] == '#') {
				return true;
			}
		}
		return false;
	};
	
	auto isFree = [&](int l, int r) {
		for (int i = l; i <= r; ++i) {
			if (s[i] == '.' && (i == 0 || s[i-1] == '.') && (i == n-1 || s[i+1] == '.')) {
				return true;
			}
		}
		return false;
	};
	
	if (c < d) {
		cout << (isDouble(a, c) || isDouble(b, d) ? "No\n" : "Yes\n");
	} else {
		cout << (isFree(b, d) && !isDouble(a, c) ? "Yes\n" : "No\n");
	}
	
	return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int n,dp[2003][2003],a[6003],ans,tg,MX[2003],cur;
int A[100004],B[100004],C[100004],t;
void init(){t=0;}
void add(int x,int y,int z){A[t]=x,B[t]=y,C[t++]=z;}
void MAX(int &a,int b){
	if(a<b)a=b;
}
int main(){
	cin>>n;
	for(int i=1;i<=3*n;i++)cin>>a[i]; 
	memset(dp,-1,sizeof(dp));
	memset(MX,-1,sizeof(MX));
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=MX[a[1]]=MX[a[2]]=cur=0;
	for(int i=3;i<3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){tg++;continue;}
		init();
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i+1]>a[i+2])swap(a[i+1],a[i+2]);
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		for(int j=1;j<=n;j++){
		if(a[i]==a[i+1])if(dp[j][a[i]]>=0)add(j,a[i+2],dp[j][a[i]]+1);
		if(a[i+1]==a[i+2])if(dp[j][a[i+1]]>=0)add(j,a[i],dp[j][a[i+1]]+1);
		}
		if(dp[a[i]][a[i]]>=0)add(a[i+1],a[i+2],dp[a[i]][a[i]]+1);
		if(dp[a[i+1]][a[i+1]]>=0)add(a[i],a[i+2],dp[a[i+1]][a[i+1]]+1);
		if(dp[a[i+2]][a[i+2]]>=0)add(a[i],a[i+1],dp[a[i+2]][a[i+2]]+1);
		add(a[i],a[i+1],cur),add(a[i+1],a[i+2],cur),add(a[i],a[i+2],cur);
		for(int j=i;j<i+3;j++)for(int k=1;k<=n;k++)if(MX[k]>=0)add(a[j],k,MX[k]);
		for(int j=0;j<t;j++)if(dp[A[j]][B[j]]<C[j])
			dp[A[j]][B[j]]=dp[B[j]][A[j]]=C[j],MAX(MX[A[j]],C[j]),MAX(MX[B[j]],C[j]),MAX(cur,C[j]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)if(dp[i][j]>=0)ans=max(ans,dp[i][j]);
		if(dp[i][i]>=0)if(i==a[3*n])ans=max(ans,dp[i][i]+1);
	}
	printf("%d",ans+tg);
}

Measured memory_bytes: 19556
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const double pi = 2 * asin(1.0);

vector<int> Symmetry(vector<int> x) {
  for (int i = 0; i < x.size(); ++i) x[i] *= -1;
  return x;
}

const int inf = 1000 * 1000 * 1000;

int LIS(const vector<int>& a) {
  int n = a.size();
  vector<int> d(n + 1);
  d[0] = -inf;
  for (int i = 1; i <= n; ++i) d[i] = inf; 
  
  for (int i = 0; i < n; ++i) {
    int j = int (upper_bound(d.begin(), d.end(), a[i]) - d.begin());
    if (d[j - 1] < a[i] && a[i] < d[j]) d[j] = a[i];
  }
  int j = n;
  while (d[j] == inf) --j;
  return j;
}

void Output(double x) {
  printf("%.10lf\n", x);
  exit(0);
}

int main()
{
  int x1, y1, x2, y2, n;
  cin >> x1 >> y1 >> x2 >> y2 >> n;
  double result = abs(x1 - x2) + abs(y1 - y2);
  result *= 100.0;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
  if (x1 > x2) {
    x1 *= -1;
    x2 *= -1;
    x = Symmetry(x);
  }
  if (y1 > y2) {
    y1 *= -1;
    y2 *= -1;
    y = Symmetry(y);
  }
  if (x2 - x1 > y2 - y1) {
    swap(x1, y1);
    swap(x2, y2);
    swap(x, y);
  }

  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; ++i) p[i] = make_pair(x[i], y[i]);
  sort(p.begin(), p.end());
  vector<int> a;
  for (auto q : p) if (x1 <= q.first && q.first <= x2 && y1 <= q.second && q.second <= y2) a.push_back(q.second);

  int len = LIS(a);
  cerr << "len = " << len << endl;
  double result1 = result + (5 * pi - 20) * (len - 1) + 10 * pi - 20;
  double result2 = result + (5 * pi - 20) * len;

  Output((len == x2 - x1 + 1) ? result1 : result2);

  return 0;
}


Measured memory_bytes: 5232
k,s = map (int ,input ().split ())
x = 0
y = 0
p = 0
while x <= k:
  while y <= k:
    if x+y > s:
      break
    z = s-(x+y)
    if 0 <= z <= k:
      p += 1
    y += 1
  x += 1
  y = 0
print (p)

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 50050;
using Bs = bitset<N>;
Bs bss[N];

void solve(int n, int m, vector<pair<int, int>> a) {
	for (int i = 0; i < n; ++i) {
		bss[i].flip(i);
	}
	vector<vector<int>> ed(n);
	vector<int> last(n);
	iota(all(last), 0);
	for (int i = 0; i < m; ++i) {
		int x, y;
		tie(x, y) = a[i];
		bss[x] |= bss[y];
		bss[y] = bss[x];

		int nx = (int)ed.size();
		int ny = (int)ed.size() + 1;
		ed.push_back({last[x], last[y]});
		ed.push_back({last[y], last[x]});
		last[x] = nx;
		last[y] = ny;
	}
	int idx = -1;
	for (int i = 0; i < n; ++i) {
		if ((int)bss[i].count() == n) {
			idx = i;
			break;
		}
	}
	if (idx == -1) {
		puts("-1");
		return;
	}
	idx = last[idx];

	vector<int> pr(ed.size(), -1);
	deque<int> q;
	q.push_back(idx);
	vector<int> dst(ed.size(), -1);
	dst[idx] = 0;
	while (!q.empty()) {
		int v = q.front();
		q.pop_front();
		if (ed[v].empty()) {
			continue;
		}
		for (int i = 0; i < 2; ++i) {
			int u = ed[v][i];
			if (dst[u] == -1) {
				dst[u] = dst[v] + i;
				pr[u] = v;
				if (i) {
					q.push_back(u);
				} else {
					q.push_front(u);
				}
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		assert(dst[i] > -1);
	}
	iota(all(last), 0);
	string res(m, 'v');
	for (int i = 0; i < m; ++i) {
		int v = n + 2 * i;
		if (pr[ed[v][1]] == v) {
			res[i] = '^';
		}
	}
	cout << res << "\n";
}

int main() {
	int n = nxt(), m = nxt(), t = nxt();
	vector<pair<int, int>> a(m);
	for (int i = 0; i < m; ++i) {
		a[i].first = nxt() - 1;
		a[i].second = nxt() - 1;
	}

	if (t == 1) {
		solve(n, m, a);
		return 0;
	}

	if (n == 2) {
		puts("-1");
		return 0;
	}
	vector<int> cnt(n, 1);
	vector<int> where(n);
	iota(all(where), 0);
	string res(m, '?');
	for (int i = m - 1; i >= 0; --i) {
		int x, y;
		tie(x, y) = a[i];
		if (where[x] == where[y]) {
			res[i] = 'v';
			continue;
		}
		if (cnt[where[x]] >= cnt[where[y]]) {
			--cnt[where[x]];
			++cnt[where[y]];
			res[i] = 'v';
			where[x] = where[y];
		} else {
			--cnt[where[y]];
			++cnt[where[x]];
			res[i] = '^';
			where[y] = where[x];
		}
	}
	cout << res << "\n";

	return 0;
}


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

int main(){
  string s; cin>>s;for(int i=0;i<4;i++)s[i]-='0';
  ll a=s[0]*10+s[1];
  ll b=s[2]*10+s[3];
  bool vl=(1<=a&&a<=12);
  bool vr=(1<=b&&b<=12);
  if(vl&vr)cout<<"AMBIGUOUS"<<endl;
  else if(vl)cout<<"MMYY"<<endl;
  else if(vr)cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
  return 0;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
 PROGRAM-ID. TEST01.
 
 ENVIRONMENT DIVISION.
 
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 
  01 INP.
    03 A      PIC 9(1).
    03 FILLER PIC X.
    03 B      PIC 9(1).
    03 FILLER PIC X.
    03 C      PIC 9(1).
  
  01 SW-KAWAISO PIC X(1).
 
 PROCEDURE DIVISION.
 
  ACCEPT INP.
  
  MOVE SPACE TO SW-KAWAISO.
  
  EVALUATE TRUE
   WHEN (A = B) AND (A NOT = C)
   WHEN (A = C) AND (A NOT = B)
   WHEN (B = C) AND (B NOT = A)
    MOVE '1' TO SW-KAWAISO  
   WHEN OTHER
    CONTINUE
  END-EVALUATE.
  
  IF SW-KAWAISO = '1'
    DISPLAY 'Yes'
  ELSE
    DISPLAY 'No'
  END-IF.
    
 STOP RUN.

Measured memory_bytes: 636
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i++)
int main(void){
	int pa[3];
	int ju[2];
	rep(i,3)cin>>pa[i];
	rep(i,2)cin>>ju[i];
	sort(pa,pa+3);
	sort(ju,ju+2);
	cout<<pa[0] + ju[0] - 50 <<endl;
	
}

Measured memory_bytes: 1176
#include <cstdio>
#include <algorithm>
#include <unordered_map>
using namespace std;

using ll = long long;
int const a[] { 2, 3, 5 };
int b[3], d;

ll f(ll n, unordered_map<ll, ll>& memo) {
    ll& ans = memo[n];
    if (n > 0 && ans == 0) {
        ans = 1e12;
        if (n < ans / d)
            ans = n * d;
        for (int i = 0; i < 3; i++) {
            int p = a[i], c = b[i];
            ll k = n / p, r = n % p;
            ans = min({ ans, f(k, memo) + r * d + c, r ? f(k + 1, memo) + (p - r) * d + c : ans });
        }
    }
    return ans;
}

int main() {
    int t;
    for (scanf("%d", &t); t--;) {
        ll n;
        scanf("%lld%d%d%d%d", &n, b, b + 1, b + 2, &d);
        unordered_map<ll, ll> memo{ {1, d} };
        printf("%lld\n", f(n, memo));
    }
}


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

int main()
{
    double h, m;
    int s_size, l_size;
    cin >> s_size >> l_size >> h >> m;
    long double l_ang = h / 6;
    l_ang += m / 360;
    long double s_ang = m / 30;
    long double ang = std::cos((s_ang - l_ang) * M_PI);
    long double ans = sqrt((long double)(pow(l_size, 2) + pow(s_size, 2)) - 2 * l_size * s_size * ang);

    cout << fixed << setprecision(17) << ans;
    return 0;
}


Measured memory_bytes: 4172
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

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 pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }

  ll x = 1;

  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

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

  ll n,m;
  std::cin>>n>>m;

  std::vector<std::vector<ll>> graph(n);

  ll front,back;

  std::deque<ll> path;

  std::set<ll> point;


  rep(i,0,m){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    front=a;back=b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  point.insert(front);point.insert(back);
  path.push_front(front);path.push_back(back);

  while(1){
    bool flag=true;
    ll temp;
    for(ll next:graph[front]){
      if(point.find(next)==point.end()){
        flag=false;
        temp=next;
        break;
      }
    }

    if(flag)break;

    point.insert(temp);path.push_front(temp);

    front=temp;
  }

  while(1){
    bool flag=true;
    ll temp;
    for(ll next:graph[back]){
      if(point.find(next)==point.end()){
        flag=false;
        temp=next;
        break;
      }
    }

    if(flag)break;

    point.insert(temp);path.push_back(temp);

    back=temp;
  }

  std::cout<<path.size()<<"\n";

  while(!path.empty()){
    std::cout<<path.front()+1<<" ";
    path.pop_front();
  }

  return 0;
}

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

int main()
{
  int w, h, n;
  cin >> w >> h >> n;
  int l = 0, r = w, d = 0, u = h;
  
  rep(i,n)
  {
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1)
    {
      l = max(l, x);
    }
    else if(a == 2)
    {
      r = min(r, x);
    }
    else if(a == 3)
    {
      d = max(d, y);
    }
    else if(a == 4)
    {
      u = min(u, y);
    }
  }
  
  cout << max(0, r-l)*max(0, u-d) << endl;
  
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    s[1]=(s[1]=='B' ? 'R' : 'B');
    cout<<s<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1e9+7
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

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

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}


int read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> x[N+5];
	for(int i=1;i<=M;i++){
		int a,b;
		cin >> a >> b;
		x[a].pb(b);
	}
	vector<int> y;
	for(int j=0;j<x[1].size();j++){
		y.pb(x[1][j]);
	}
	for(int i=0;i<y.size();i++){
		int r = y[i];
		for(int j=0;j<x[r].size();j++){
			int t = x[r][j];
			if(t == N){
				cout << "POSSIBLE\n";
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE\n";
}



Measured memory_bytes: 9208
#課題3-A 16D8102014J 井口和人　4/27
#python
a=input().split()

stack=[]

for i in a:
    if i=='+':
        a=stack.pop()
        b=stack.pop()
        stack.append(a+b)
    elif i=='-':
        a=stack.pop()
        b=stack.pop()
        stack.append(b-a)
    elif i=='*':
        a=stack.pop()
        b=stack.pop()
        stack.append(a*b)
    else:
        stack.append(int(i))

print(stack[0])



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

int main() {
	string s;
	cin>>s;
	long n,k=0,l=0,p=1,q;
	n=s.size();
	long a[n];
	for(int i=0;i<n;i++)a[i]=0;
	for(int i=0;i<n/2;i++){
		if(s.at(i)!=s.at(n-2-i)){
			k++;
			
		}
	}
	
	for(int i=0;i<n;i++){
		if(s.at(i)=='1'){
			a[l]=i-p-1;
			p=i;
			l++;
		}
	}
	long b[l+1];
	
	if(k!=0)cout<<-1<<endl;
	else if(n==2){
		if(s.at(0)=='1'&&s.at(1)=='0')cout<<1<<" "<<2<<endl;
		else{
			cout<<-1<<endl;
		}
	}
	else if(l==0)cout<<-1<<endl;
	else if(s.at(n-1)=='1')cout<<-1<<endl;
	else if(n==l)cout<<-1<<endl;
	else if(s.at(n-2)=='0')cout<<-1<<endl;
	else if(s.at(0)=='0')cout<<-1<<endl;
	else if(s.at(0)==1&&s.at(1)==0&&s.at(2)==1&&s.at(3)==0){
		cout<<1<<" "<<2<<endl;
		cout<<1<<" "<<3<<endl;
		cout<<1<<" "<<4<<endl;
	}
	else{
		b[0]=1;
		for(int i=0;i<l;i++){
			b[i+1]=b[i]+a[i+1]+1;
			
		}
		
		
			for(int i=0;i<l;i++){
				for(int j=b[i];j<b[i+1];j++){
					cout<<j<<" "<<b[i+1]<<endl;
				}
			}
		
		
	}
	
	return 0;
}

Measured memory_bytes: 3200
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get!(i32);
    let mut m = n;
    let mut h = 0;
    while m != 0 {
        h += m % 10;
        m /= 10;
    }
    println!("{}", if n % h == 0 { "Yes" } else { "No" });
}

Measured memory_bytes: 2076
/*Bismillahir Rahmanir Raheem*/

#include <bits/stdc++.h>
using namespace std;

//constant
#define PI acos(-1.0)

//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned un;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef map<int, int> mii;
typedef map<char, char> mcc;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<ll, ll> mll;

// defined for taking input
#define gl(x) getline(cin, x)
#define sf scanf
#define sfi(x) scanf("%d", &x)
#define sfc(x) scanf("%c", &x)
#define sfl(x) scanf("%lld", &x)
#define sflu(x) scanf("%llu", &x)
#define sfii(x, y) scanf("%d %d", &x, &y)
#define sfll(x, y) scanf("%lld %lld", &x, &y)
#define sfiii(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sflll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)

//defined for printing
#define pf printf
#define pfn pf("\n")
#define pfcas pf("Case %d: ", cas)
#define pfyes pf("Yes");
#define pfno pf("No");
#define pfi(x) pf("%d", x)
#define pfl(x) pf("%lld", x)

//defined for loop

//increament
#define loopi(i, j, k) for (int i = j; i < k; i++)
#define loopl(i, j, k) for (ll i = j; i < k; i++)
#define loopc(i, j, k) for (char i = j; i < k; i++)
#define looplu(i, j, k) for (ull i = j; i < k; i++)
//decreament
#define loopri(i, j, k) for (int i = j; i > k; i--)
#define looprl(i, j, k) for (ll i = j; i > k; i--)
#define looprlu(i, j, k) for (ull i = j; i > k; i--)
#define looprc(i, j, k) for (char i = j; i > k; i--)
#define wa(t) while (t--)

//testcases
#define testc(t) for (char cas = 1; cas <= t; cas++)
#define testi(t) for (int cas = 1; cas <= t; cas++)
#define testl(t) for (ll cas = 1; cas <= t; cas++)

//some cmd
#define pb push_back
#define ppb pop_back
#define mp make_pair

//code start

int main()
{
    // freopen("/root/Programming/input.txt", "r", stdin);
    // freopen("/root/Programming/output.txt", "w", stdout);
    string str;
    cin>>str;
    if(str[1]!=str[2] or str[1]!=str[0]){
        pfyes;
    }
    else
    {
        pfno;
    }
    pfn;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
ll cnt=1;
string c="0123456789";
set<string> v;
map<ll,ll> m;
void lunlun(ll t,ll l,string s)
{
    if(l==1)
    {

        string ss=s;
        ss.insert(ss.end(),1,c[t]);
        v.insert(ss);
    }
    else
    {
        string ss=s;
        ss.insert(ss.end(),1,c[t]);
        if(t>0) lunlun(t-1,l-1,ss);
        lunlun(t,l-1,ss);
        if(t<9) lunlun(t+1,l-1,ss);
    }
}
int main()
{
    ll k;
    string s="";
    rep(i,4) lunlun(i,10,s);
    for(int i=1;i<=9;i++)
    {
        s.insert(s.end(),1,'0');
        //cout<<s<<"\n";
        for(int j=2;j<=9;j++) lunlun(j,10-i,s);
    }
    cin>>k;
    bool x=1;
    rep(i,k)
    {
        //cout<<*v.begin()<<"\n";
        v.erase(v.begin());
    }
    string r=*v.begin();
    rep(i,r.size())
    {
        if(r[i]!='0'&&x) x=0;
        if(!x) cout<<r[i];
    }
}


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

int main() {
  int N,K;
  cin >> N >> K;
  int dist=0;

  for(int i =0; i < N; i++){
    int x;
    cin >> x;
    int A=0,B=0;    
    A=x*2;
    B=abs((x-K)*2);
    if(A>B){
      dist+=B;
    }else{
      dist+=A;
    }
  }
  cout << dist <<endl;
}


Measured memory_bytes: 256
S = input()
t = S[0]
skip = False
ans = 0
cnt = 0
for i in range(len(S)):
    if (skip):
        t = S[i]
        skip = False
        continue
    if (t == S[i]):
        cnt += 1
    else:
        if (cnt in [1, 2]):
            ans += cnt
            skip = (cnt == 2)
        # 文字が違ったときの処理
        else:
            ans += (cnt//3 * 2) + (cnt % 3)
            skip = (cnt % 3 == 2)
        t = S[i]
        cnt = 1
# 一番最後の文字列の処理
if (not skip):  
    if (cnt in [1, 2]):
        ans += 1
    # 文字が違ったときの処理
    elif (cnt % 3 == 0):
        ans += (cnt//3 * 2)
    elif (cnt % 3 == 1 or cnt% 3 == 2):
        ans += (cnt//3 * 2) + 1
print(ans)


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

int main() {
	int cnt = 0;
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if(s[i] == '1') cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int sort(const void *A,const void *B){return *(long long*)A>*(long long*)B?1:0;}
 
int main(void){
    int n;
    scanf("%d",&n);
    long long a[n],v[n],ans=0;
    for (int i=0; i<n; i++){
        scanf("%lld",&a[i]);
        v[i]=0;
    }
    qsort (a,n,sizeof(long long),sort);
    for (int i=31; i>=0; i--){
        long long count=0,back=n-1,sum=pow(2,i);
        while(count<back){
            if (v[count]==1){
                count++;
            } else if (v[back]==1){
                back--;
            } else if (a[count]+a[back]==sum){
                v[count]=1;
                v[back]=1;
                ans++;
                count++;
                back--;
            } else if (a[count]+a[back]<sum){
                count++;
            } else {
                back--;
            }
        }
    }
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 4860
import Control.Monad
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

simulate as table i' i l o h = do
  VUM.write table i (as ! i')
  let i''
        | o == True && i < h = i' - 2
        | o == True && i == h = i' + 1
        | o == True && i > h = i' + 2
        | o == False && i < h - 1 = i' - 2
        | o == False && i == h - 1 = i' - 1
        | o == False && i > h - 1 = i' + 2
  when (i /= l - 1) $ simulate as table i'' (i + 1) l o h

main = do
  n <- getInt
  as <- getIntList
  let l = length as
  let as' = listArray (1, l) as
  table <- VUM.replicate n 0 :: IO (VUM.IOVector Int)
  simulate as' table l 0 l (odd l) (l `div` 2)
  v <- VU.freeze table
  putStrLn $ unwords (map show (VU.toList v))


Measured memory_bytes: 33516
#include <cstdio>
#define MOD 1000000007
typedef long long ll; 
long long dp[2][100005], pw[205], ans; 
int x[205], y[205], one[100005], two[100005]; 
int main()
{
	// freopen("CF17-TR-I.in", "r", stdin); 
	pw[0] = 1; 
	for (int i = 1; i <= 200; i++)
		pw[i] = (pw[i - 1] + pw[i - 1]) % MOD; 
	int n, m; 
	scanf("%d%d", &n, &m); 
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", x + i, y + i);
		x[i]--;
		y[i]--; 
	}
	for (int i = 0; i < 1 << n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			one[i] += (i & (1 << x[j])) || (i & (1 << y[j]));
			two[i] += (i & (1 << x[j])) && (i & (1 << y[j])); 
		}
	}
	for (int i = 0; i <= 1; i++)
	{
		for (int j = 0; j < 1 << n; j++)
		{
			if (!(j & (1 << i)))
				continue; 
			dp[i][j] = pw[two[j]]; 
			for (int k = j; k; k = k - 1 & j)
				(dp[i][j] -= dp[i][j ^ k] * pw[two[k]]) %= MOD; 
		}
	}
	for (int i = 0; i < 1 << n; i++)
	{
		int rem = (1 << n) - 1 ^ i; 
		for (int j = rem; ; j = j - 1 & rem)
		{
			if (two[i] + two[j] == two[i | j])
				(ans += dp[0][i] * dp[1][j] % MOD * pw[m - one[i | j]]) %= MOD; 
			if (!j)
				break; 
		}
	}
	printf("%lld\n", (pw[m] - ans + MOD) % MOD);
	return 0; 
}


Measured memory_bytes: 896
import collections
import math

def comb(n, r):
  if n < r:
      return 0
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N=input()
A = list(map(int, input().split()))
c = collections.Counter(A)
#print(c.values())

ans = sum([comb(v, 2) for v in c.values()])
for ai in A:
    print(ans - c[ai] + 1)


Measured memory_bytes: 26780
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (5000L)
#define MAX_GSA (5000L)
#define NUM_ITEMS (4L)

using namespace std;

long dp1s[NUM_ITEMS + 1][MAX_N + 1], dp2s[NUM_ITEMS + 1][MAX_N * MAX_GSA + 1];
long w1s[NUM_ITEMS], v1s[NUM_ITEMS], w2s[NUM_ITEMS], v2s[NUM_ITEMS];

int main(int argc, char *argv[]) {
  // read inputs
  long N, ga, sa, ba, gb, sb, bb;
  scanf("%ld %ld %ld %ld %ld %ld %ld", &N, &ga, &sa, &ba, &gb, &sb, &bb);

  // solve knapsacs
  // first
  // set the problem
  w1s[0] = ga, v1s[0] = gb;
  w1s[1] = sa, v1s[1] = sb;
  w1s[2] = ba, v1s[2] = bb;
  w1s[3] = 1, v1s[3] = 1;
  // initialize
  for (long i = 0; i < NUM_ITEMS; i++) {
    dp1s[i + 1][0] = 0;
  }
  for (long j = 0; j <= N; j++) {
    dp1s[0][j] = 0;
  }
  // update
  for (long i = 0; i < NUM_ITEMS; i++) {
    const long w = w1s[i], v = v1s[i];
    for (long j = 1; j <= N; j++) {
      if (j < w) {
        dp1s[i + 1][j] = dp1s[i][j];
      } else {
        dp1s[i + 1][j] = max(dp1s[i][j], dp1s[i + 1][j - w] + v);
      }
    }
  }
  const long M = dp1s[NUM_ITEMS][N];
  // printf("M = %ld\n", M);

  // first
  // set the problem
  w2s[0] = gb, v2s[0] = ga;
  w2s[1] = sb, v2s[1] = sa;
  w2s[2] = bb, v2s[2] = ba;
  w2s[3] = 1, v2s[3] = 1;
  // initialize
  for (long i = 0; i < NUM_ITEMS; i++) {
    dp2s[i + 1][0] = 0;
  }
  for (long j = 0; j <= M; j++) {
    dp2s[0][j] = 0;
  }
  // update
  for (long i = 0; i < NUM_ITEMS; i++) {
    const long w = w2s[i], v = v2s[i];
    for (long j = 1; j <= M; j++) {
      if (j < w) {
        dp2s[i + 1][j] = dp2s[i][j];
      } else {
        dp2s[i + 1][j] = max(dp2s[i][j], dp2s[i + 1][j - w] + v);
      }
    }
  }
  printf("%ld\n", dp2s[NUM_ITEMS][M]);

  return 0;
}


Measured memory_bytes: 976896
//保持物品顺序不变（显然），那么，二分边界就可以了 
#include<iostream>
using namespace std;
const int N=2e5+10;
int n,Q;
char s[N],t[N],d[N];
int check(int x)
{
	for(int i=1;i<=Q;i++)
	{
		if(s[x]==t[i]) x+=(d[i]=='R')?1:-1;
		if(x>n) return -1;
		if(x<1) return 1;
	}
	return 0;
}
int main()
{
	cin>>n>>Q;
	scanf("%s",s+1);
	for(int i=1;i<=Q;i++) cin>>t[i]>>d[i];
	int l=1,r=n,la=0,ra=n+1;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid)==1) la=mid,l=mid+1;
		else r=mid-1;
	}
	l=1,r=n;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid)==-1) ra=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ra-la-1<<endl;
}

Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

// const abcd = "abcdefghijklmnopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e13
var mod = 1000000007

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	s := next.String()
	s = strings.Replace(s, ",", " ", -1)
	fmt.Println(s)
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a []int) int {
	r := 0
	for i := 0; i < len(a); i++ {
		r += a[i]
	}
	return r
}

func pow(a []int) int {
	r := 1
	for i := 0; i < len(a); i++ {
		r *= a[i]
	}
	return r
}

func fill(a []int, n int) []int {
	for i := 0; i < len(a); i++ {
		a[i] = n
	}
	return a
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) String() string {
	return s.next()
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Ints(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = s.Int()
	}
	return r
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
// Aizu Vol-5 0593: Vote
// 2017.8.30 bal4u@uu

#include <stdio.h>

int a[1003], c[1003];

int main()
{
	int n, m, i, j, t;

	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++) scanf("%d", a+i);
	for (i = 1; i <= m; i++) {
		scanf("%d", &t);
		for (j = 1; j <= n; j++) {
			if (a[j] <= t) { c[j]++; break; }
		}
	}
	for (t = 0, i = 1; i <= n; i++) if (c[i] > t) t = c[i], j = i;
	printf("%d\n", j);
	return 0;
}

Measured memory_bytes: 604
#a,b=map(int,input().split())
n=int(input())
p=list(map(int,input().split()))
import copy
P=copy.deepcopy(p)
P.sort()
cnt=0
for i,j in zip(p,P):
        if i!=j:
                cnt+=1
print("YES") if cnt<=2 else print("NO")


Measured memory_bytes: 3444
/*
  -> Sayan Bose
  -> Do Good Die Great
*/
#include <bits/stdc++.h>
#define int long long int
#define pii pair<int, int>
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define MOD 1000000007
#define Hiraishin                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr);
#define tests \
    int t;    \
    cin >> t; \
    while (t--)
using namespace std;

vector<int> divisors(10000005, 1);

void initialize(int n)
{
    for(int i = 2; i <= n; i++){
        int temp = i, cnt = 1;
        while(temp * cnt <= n){
            divisors[temp * cnt]++;
            cnt++;
        }
    }
}

void solve()
{
    int n;
    cin >> n;
    initialize(n);
    int res = 0;
    for(int i = 1; i <= n; i++)
        res += i * divisors[i];
    cout << res << '\n';
}

signed main()
{
    Hiraishin
        //tests
        solve();
    return 0;
}

Measured memory_bytes: 81216
import java.awt.Point;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.NoSuchElementException;

public class Main {
	
	static final int[] dx = { -1, 0, 0, 1 };
	static final int[] dy = { 0, -1, 1, 0 };
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		
		char[][] block = new char[h][w];
		Point[] point = new Point[n + 1];
		
		for (int y = 0; y < h; y++) {
			String s = sc.next();
			for (int x = 0; x < w; x++) {
				char c = s.charAt(x);
				if (c == 'S') {
					point[0] = new Point(x, y);
				} else if ('1' <= c && c <= '9') {
					point[c - '0'] = new Point(x, y);
				}
				block[y][x] = c;
			}
		}
		
		int total = 0;
		int[][] time = new int[h][w];
		Deque<Point> q = new ArrayDeque<>();
		
		for (int i = 0; i < n; i++) {
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					time[y][x] = 0;
				}
			}
			q.clear();
			q.offer(point[i]);
			while (!q.isEmpty()) {
				Point p = q.poll();
				if (p.equals(point[i + 1])) {
					total += time[p.y][p.x];
					break;
				}
				for (int j = 0; j < 4; j++) {
					int _x = p.x + dx[j];
					int _y = p.y + dy[j];
					if (((0 <= _y && _y < h) && (0 <= _x && _x < w)) && time[_y][_x] == 0 && block[_y][_x] != 'X') {
						time[_y][_x] = time[p.y][p.x] + 1;
						q.offer(new Point(_x, _y));
					}
				}
			}
		}
		
		System.out.println(total);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) return false;
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			System.out.println("poyo");
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	public int nextInt() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) { throw new NumberFormatException(); }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
}

Measured memory_bytes: 70932
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n+2];
	int b[n+2];
	for(int i=1;i<=n;i++){
		cin >> a[i];
		b[a[i]]=i;
	}
	for(int i=1;i<=n;i++)cout << b[i] << " ";
}

Measured memory_bytes: 1536
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); Integer [] a = new Integer[2 * n];
        for (int i = 0; i < 2 * n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());
        int ans = 0;
        for (int i = 1; i < 2 * n; i += 2) ans += a[i];
        System.out.println(ans);
    }


}

Measured memory_bytes: 35884
#include<iostream>
#include<queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];
void bfs(int s){
    queue<int> q;
    q.push(s);
    for ( int i = 0; i < n; i++ ) d[i] = INFTY;
    d[s] = 0;
    int u;
    while ( !q.empty() ){
        u = q.front(); q.pop();
        for ( int v = 0; v < n; v++ ){
            if ( M[u][v] == 0) continue;
            if ( d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
            
        }
    }
    for ( int i = 0; i < n; i++ ) {
        cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
    }
}
int main() {
    int u, k,v;
    
    cin >> n;
    for ( int i = 0; i < n; i++ ){
        cin >> u >> k;
        u--;
        for ( int j = 0; j < k; j++ ){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);
    
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
char s[10];
int main(){
	int now=0;scanf("%s",s);
	if(s[0] == 'S') {
		if(s[1] == 'U') now = 0;
		else now = 6;
	}
	if(s[0] == 'M') now = 1;
	if(s[0] == 'T') {
		if(s[1] == 'U') now = 2;
		else now = 4;
	}
	if(s[0] == 'W') now = 3;
	if(s[0] == 'F') now = 5;
	printf("%d\n", 7 - now);
	return 0;
} 

Measured memory_bytes: 256
A,B,C,D = map(int,input().split())
import fractions
lcm = int( C*D / ( fractions.gcd(C,D) ) )

first_c = ( A - 1) // C
first_d = ( A - 1) // D
first_cd = ( A - 1) // lcm 
first = ( A - 1 ) - ( first_c + first_d - first_cd )

end_c = B // C
end_d = B // D
end_cd = B // lcm 
end_ = B - ( end_c + end_d - end_cd )

print(end_ - first)


Measured memory_bytes: 5304
n,m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

xlen=0
ylen=0

for i in range(1,n):
    xlen+=i*(n-i)*(x[i]-x[i-1])

for i in range(1,m):
    ylen+=i*(m-i)*(y[i]-y[i-1])

print(xlen*ylen%(10**9+7))

Measured memory_bytes: 83044
#include<bits/stdc++.h>
#define ll long long
#define MOD = 1e9+7
#define rep(i,n) for(int i=0;i<(n);++i)
const double PI=3.14159265358979323846; 
const int INF = 1001001001;
using namespace std;

int main(){
  int n;
  cin >> n;
  if(n%1000==0){
    cout << 0 << endl;
    return 0;

  }
  cout << 1000 - (n%1000) << endl;
}

Measured memory_bytes: 3632