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

using VI = vector<int>;
using VVI = vector<VI>;

VI makev(string s) {
  VI v;
  for (char c: s) {
    if ('0' <= c && c <= '9') {
      for (int i = 0; i < c - '0'; i++) {
        v.push_back(0);
      }
    } else {
      v.push_back(1);
    }
  }
  return v;
}

VVI makeboard(string s) {
  VVI vv;
  string cur = "";
  for (char c: s) {
    if (c != '/') {
      cur += c;
    } else {
      vv.push_back(makev(cur));
      cur = "";
    }
  }
  vv.push_back(makev(cur));
  return vv;
}

string jfen(VI line) {
  int cnt = 0;
  string res = "";
  for (int i: line) {
    if (i == 1) {
      if (cnt != 0) {
        res += char('0' + cnt);
        cnt = 0;
      }
      res += "b";
    } else {
      cnt++;
    }
  }
  if (cnt != 0) {
    res += char('0' + cnt);
  }
  return res;
}

string jfen(VVI board) {
  string res = "";
  for (VI line: board) {
    res += "/";
    res += jfen(line);
  }
  return res.substr(1);
}

int main() {
  string s;
  while (1) {
    cin >> s;
    if (s == "#") return 0;
    VVI board = makeboard(s);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    assert(board[a][b] == 1);
    board[a][b] = 0;
    board[c][d] = 1;
    cout << jfen(board) << endl;
  }
}



Measured memory_bytes: 3224
N = int(input())
L1 = list(map(int, input().split()))
L2 = list(map(int, input().split()))

m = 0
for i in range(N):
    tmp = sum(L1[0:i+1])
    tmp = tmp + sum(L2[i:])
    m = max(m, tmp)
print(m)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    const int N = 3;
    vector<vector<int>> v(N,vector<int>(N));
    vector<int> a(N), b(N);
    REP(i,N) REP(j,N) cin >> v[i][j];
    REP(i,N) {
        a[i] = *min_element(ALL(v[i]));
        REP(j,N) v[i][j] -= a[i];
    }
    REP(i,N) {
        int m = 1000;
        REP(j,N) m = min(m,v[j][i]);
        b[i] = max(0,m);
        REP(j,N) v[j][i] -= b[i];
    }

    bool ans = true;
    REP(i,N) REP(j,N) if (v[i][j] != 0) {
        ans = false; break;
    }

    ATYN(ans);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 10000000005
#define NIL -1
int main(){
    int n; cin >> n;
    int a[n];
    map<int, int> mp;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 1; i < n; i++){
        if(a[i-1] == a[i]){
            cnt++;
            a[i] += 101;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    s.append(input())

ans = [0]*4
for dat in s:
    if dat == 'AC':
        ans[0] += 1
    elif dat == 'WA':
        ans[1] += 1
    elif dat == 'TLE':
        ans[2] += 1
    elif dat == 'RE':
        ans[3] += 1

print (f'AC x {ans[0]}')
print (f'WA x {ans[1]}')
print (f'TLE x {ans[2]}')
print (f'RE x {ans[3]}')


Measured memory_bytes: 82856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> p(n),q(n);
    rep(i,n) cin>>p[i];
    rep(i,n) cin>>q[i];
    vector<int> t(n);
    rep(i,n) t[i] = i+1;
    int a1=0,b1=0;
    int cnt = 0;
    do {
        bool isp = true;
        bool isq = true;
        rep(i,n){
            if(p[i] != t[i]) isp = false;
            if(q[i] != t[i]) isq = false;
        }
        if(isp) a1 = cnt;
        if(isq) b1 = cnt;
        cnt++;
    } while(next_permutation(t.begin(), t.end()));
    cout<<abs(a1-b1)<<endl;
    return 0;

}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<char,int> PCI; 
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

vector<pair<char, int>> lanl(string s){
    int n = s.size();
    vector<pair<char, int>> res;
    res.push_back({s[0], 1});
    for(int i=1; i<n; i++){
        if(s[i] == res.back().first){
            ++res.back().second;
        }else{
            res.push_back({s[i], 1});
        }
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    int n = s.size();
    ll k; cin>>k;
    if(s == string(n, s[0])){
        cout<<n*k/2<<endl;
        return 0;
    }
    vector<PCI> t = lanl(s);
    ll p = 0;
    for(auto a : t){
        p += a.second/2;
    }
    ll ans = p*k;
    if(t.front().first == t.back().first){
        ll a = t.front().second;
        ll b = t.back().second;
        ans = ans - (a/2 + b/2 - (a+b)/2) * (k-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, i; string ans="APPROVED"; cin >> N; int A[N];
for(i=0; i<N; i++){
  cin >> A[i];
  if((A[i]%2==0)&&(A[i]%3)&&(A[i]%5)){ ans="DENIED"; break; }
}
cout << ans << "\n";
}

Measured memory_bytes: 256
a,b,c,d = map(int, input().split())

ans1 = a*c
ans2 = b*d
ans3 = a*d
ans4 = b*c

    
if d<0 and a>0:
    print(ans3)
elif c>0 and b<0:
    print(ans4)    
else:
    if ans1 > ans2:
        print(ans1)
    else:
        print(ans2)

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

int main() {
  int N,L;
  cin>>N>>L;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++){
    cout<<S.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 3544
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

int main() {
    long long ans=0;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) if(i%3&&i%5) ans+=i;
    printf("%lld\n",ans);
    return 0;
}


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

int main()
{
  int n,d,x;
  cin >> n >> d >> x;
  int ret = x;
  for(int i = 0; i < n; ++i){
    int a;
    cin >> a;
    ret += (d-1)/a + 1;
  }
	cout << ret << endl;  
  return 0;
}

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

long h, w;
long h2, w2;
long long ll, ss;
long long _min;
long long s[3] = {0,0,0};
long long a[3] = {0,0,0};

int main(){
    cin >> h >> w;
    if(h % 3 == 0 || w % 3 == 0){
        cout << 0 << endl;
        return 0;
    }else{
        if(h > w){
            _min = w;
        }else{
            _min = h;
        }
    }
    h2 = h / 2;
    w2 = w / 2;
    int debug[2] = {0,0};
    for(int i = 1; i <= h + 1; i++){
        s[0] = i * w;
        s[1] = (h - i) * w2;
        s[2] = (h - i) * (w - w2);
        if(s[0] < s[2]){
            ll = s[2];
            if(s[0] > s[1]){
                ss = s[1];
            }else{
                ss = s[0];
            }
        }else{
            ll = s[0];
            ss = s[1];
        }
        if(_min > ll - ss){
            _min = ll - ss;
            a[0] = s[0];
            a[1] = s[1];
            a[2] = s[2];
            debug[0] =h - i;
            debug[1] = (w - w2) ;//* (h - i);
        }
    }
    for(int i = 1; i <= w2 + 1; i++){
        s[0] = i * h;
        s[1] = (w - i) * h2;
        s[2] = (w - i) * (h - h2);
        if(s[0] < s[2]){
            ll = s[2];
            if(s[0] > s[1]){
                ss = s[1];
            }else{
                ss = s[0];
            }
        }else{
            ll = s[0];
            ss = s[1];
        }
        if(_min > ll - ss){
            _min = ll- ss;
            a[0] = ll;
            a[1] = ss;
        }
    }
    cout << _min << endl;
    //cout << a[0] << " " << a[1] << " " << a[2] << endl;
    //cout << debug[0] << " " << debug[1] << " " << a[2] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int t[100],h[100],f[200];
int n;
int i,j;
int c;
int ncard,turn;
bool used[2][100];

int search(int a[],int len,int b){
	for(int k=0;k<len;k++){
		if(a[k]>=b)return k;
	}
	return len;
}

int comp(const void* a,const void* b){
	int x,y;
	x=*(int*)a;
	y=*(int*)b;
	return x-y;
}

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
	for(i=0;i<n*2;i++)f[i]=0;
	for(i=0;i<n;i++){
		used[0][i]=false;
		used[1][i]=false;
	}
	c=0;
	ncard=0;
	turn=0;
	for(i=0;i<n;i++){
		scanf("%d",&t[i]);
		f[t[i]-1]=1;
	}
	for(i=0;i<n*2;i++)if(f[i]==0)h[c++]=i+1;
	qsort(t,n,sizeof(int),comp);
	qsort(h,n,sizeof(int),comp);
	while(1){
start:
		if(turn==0){
			j=search(t,n,ncard);
			while(j<n&&used[0][j])j++;
			if(j==n)ncard=0;
			else{
				ncard=t[j];
				used[0][j]=true;
			}
			turn=1;
		}
		else if(turn==1){
			j=search(h,n,ncard);
			while(j<n&&used[1][j])j++;
			if(j==n)ncard=0;
			else{
				ncard=h[j];
				used[1][j]=true;
			}
			turn=0;
		}
		bool fl[2]={false,false};
		for(j=0;j<n;j++)if(!used[0][j])fl[0]=true;
		for(j=0;j<n;j++)if(!used[1][j])fl[1]=true;
		if(!fl[0]||!fl[1])break;
	}
	int ans[2]={0,0};
	for(i=0;i<n;i++)if(!used[1][i])ans[0]++;
	for(i=0;i<n;i++)if(!used[0][i])ans[1]++;
	printf("%d\n%d\n",ans[0],ans[1]);
	}
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
#define rep(i,j,k) for(ll i=0;i<j;i+=k)
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	ll n;
	cin>>n;
	vector<ll> a(n);
	unordered_map<ll,ll> m;
	ll sum = 0;
	for(ll i=0;i<n;i++) {
		cin>>a[i];
		m[a[i]]++;
		sum = sum+a[i];
	}
	ll q;
	cin>>q;
	for(ll i=0;i<q;i++) {
		ll b,c;
		cin>>b>>c;
		sum = sum-m[b]*b;
		sum = sum+m[b]*c;
		m[c] += m[b];
		m[b] = 0;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 7808
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-07-16 23:00:42 +0900
# LastModified: 2020-07-16 23:23:14 +0900
#
from collections import deque


def main():
    s_a = input()
    s_b = input()
    s_c = input()
    s_a = [s for s in s_a if s != 'a']
    s_b = [s for s in s_b if s != 'b']
    s_c = [s for s in s_c if s != 'c']
    s_a = deque(s_a)
    s_b = deque(s_b)
    s_c = deque(s_c)
    if not s_a:
        print("A")
        return
    turn = s_a.popleft()
    ans = -1
    while 1:
        if turn == 'a' and s_a:
            turn = s_a.popleft()
        elif turn == 'b' and s_b:
            turn = s_b.popleft()
        elif turn == 'c' and s_c:
            turn = s_c.popleft()
        elif turn == 'a' and not s_a:
            ans = 0
            break
        elif turn == 'b' and not s_b:
            ans = 1
            break
        elif turn == 'c' and not s_c:
            ans = 2
            break
    if ans == 0:
        print("A")
    elif ans == 1:
        print("B")
    else:
        print("C")
    return




if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> x(n), y(n), h(n);
  for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];
  for(int cx = 0; cx <= 100; cx++){
  	for(int cy = 0; cy <= 100; cy++){
		set<int> canBe;
      	for(int i = 0; i < n; i++){
        	if(h[i]){
            	canBe.insert(h[i] + abs(x[i] - cx) + abs(y[i] - cy));
            }
        }
      	if(canBe.size() > 1) continue;
      	int rh = 1;
      	if(canBe.size() == 1) rh = *canBe.begin();
      	bool ok = true;
      	for(int i = 0; i < n; i++)
          if(h[i] != max(rh - abs(x[i] - cx) - abs(y[i] - cy), 0)) ok = false;
      	if(ok){
          cout << cx << " " << cy << " " << rh << endl;
          return 0;
        }
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  private static long solve(int n) {
    int[] factors = new int[n + 1];
    for (int i = 2; i <= n; i++) {
      int tempI = i;
      int p = 2;
      while (tempI > 1) {
        while (tempI % p == 0) {
          tempI /= p;
          factors[p]++;
        }
        p++;
      }
    }
    
    long answer = 1;
    for (int i = 2; i <= n; i++) {
      answer = (answer * (factors[i] + 1)) % 1_000_000_007L;
    }
    return answer;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    out.println(solve(n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int,int> > ans;
    if(n%2)
    {
        for(int l=1, r=n-1; l<r; l++, r--)
        {
            ans.emplace_back(l,r);
        }
    }
    else
    {
        bool flag = false;
        for(int l=1, r=n-1; l<r; l++, r--)
        {
            if(!flag && r-l <= n/2)
            {
                r--;
                flag = true;
            }
            ans.emplace_back(l,r);
        }
    }
    for(int i=0; i<m; i++)
    {
        printf("%d %d\n", ans[i].first, ans[i].second);
    }
    return 0;
}

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

int main(){
	string s, p;
	bool check;
	cin >> s >> p;
	for(int i = 0; i < s.size(); i++){
		check = true;
		for(int j = i, n = 0; n < p.size(); j++, n++){
			if(s[j%s.size()] != p[n]){
				check = false;
				break;
			}
		}
		if(check){
			cout << "Yes" << endl;
			break;
		}
	}
	if(!check){
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3224
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main(){
    nextLine()
    a := strings.Split(nextLine(), " ")
    tmp := 0
    colors := make([]int, 8)

    for _, val := range a {
        a_num, _ := strconv.Atoi(val)
        idx := a_num / 400
        if idx < 8 {
            colors[idx] = 1
        }else{
            tmp += 1
        }
    }

    min_result, max_result := 0, 0
    for _, val := range colors {
        min_result += val
        max_result += val
    }

    if min_result == 0 && tmp != 0 {
        min_result = 1
    }

    max_result += tmp
    fmt.Println(min_result, max_result)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    while (q--) {
        int type, x, y;
        cin >> type >> x >> y;
        if (type == 0) {
            uf.unite(x, y);
        } else {
            cout << (int)uf.same(x, y) << endl;
        }
    }

}



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

#define LIMIT 100001

int main(void)
{
    int vi, vj;
    int n;
    int i;
    char c;
    int *ctr_vi, *ctr_vj;
    int MAX_vi, MAX_vj;
    int MAX_vi2, MAX_vj2;
    int index_MAX_vi, index_MAX_vj;
    
    
    MAX_vi = MAX_vj = 0;
    MAX_vi2 = MAX_vj2 = 0;
    
    
    scanf("%d", &n);
    
    
    ctr_vi = (int*)malloc(sizeof(int)*LIMIT);
    ctr_vj = (int*)malloc(sizeof(int)*LIMIT);
    
    
    for(i=1; i<LIMIT; i++)
        ctr_vi[i] = ctr_vj[i] = 0;
    
    
    for(i=1; i<=n/2; i++)
    {
        scanf("%d%c", &vi, &c);
        scanf("%d%c", &vj, &c);
        
        ctr_vi[vi]++;
        ctr_vj[vj]++;
    }
    
    
    for(i=1; i<LIMIT; i++)
    {
        if(ctr_vi[i] >= MAX_vi)
        {
            MAX_vi2 = MAX_vi;
            MAX_vi = ctr_vi[i];
            index_MAX_vi = i;
        }
        else if(ctr_vi[i] > MAX_vi2)
        {
            MAX_vi2 = ctr_vi[i];
        }
        
        if(ctr_vj[i] >= MAX_vj)
        {
            MAX_vj2 = MAX_vj;
            MAX_vj = ctr_vj[i];
            index_MAX_vj = i;
        }
        else if(ctr_vj[i] > MAX_vj2)
        {
            MAX_vj2 = ctr_vj[i];
        }
    }
    
    
    if(index_MAX_vi != index_MAX_vj)
        printf("%d\n", n-MAX_vi-MAX_vj);
    else
    {
        if(MAX_vi > MAX_vj)
        {
            printf("%d\n", n-MAX_vi-MAX_vj2);
        }
        else if(MAX_vi < MAX_vj)
        {
            printf("%d\n", n-MAX_vj-MAX_vi2);
        }
        else
        {
            if(MAX_vi2 > MAX_vj2)
                printf("%d\n", n-MAX_vj-MAX_vi2);
            else
                printf("%d\n", n-MAX_vi-MAX_vj2);
        }
    }
    
    
    free(ctr_vi);
    free(ctr_vj);
    
    
    //system("pause");
    
    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>

#define max(a, b) ((a) > (b) ? (a) : (b))

int mp[256][256];
int test[256][256];
int X, Y;

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

typedef struct {
	int tx, ty;
	int time;
} State;

State q[100000];
int head, tail;

void enq(State a)
{
	q[head++] = a;
	tail %= 100000;
}

State deq(void)
{
	State r;
	
	r = q[tail++];
	tail %= 100000;
	return (r);
}

int bfs(int c[][256], int sx, int sy)
{
	int i;
	int ans;
	char v[256][256];
	State s;
	
	memset(v, 0, sizeof(v));
	
	v[sy][sx] = 1;
	c[sy][sx] = 0;
	head = tail = 0;
	s.tx = sx, s.ty = sy;
	s.time = 0;
	ans = 1;
	
	enq(s);
	while (head != tail){
		State t = deq();
		State n;
		
		for (i = 0; i < 6; i++){
			int mx, my;
			mx = t.tx + dx[t.ty % 2][i], my = t.ty + dy[t.ty % 2][i];
			
			if (0 <= mx && mx < X && 0 <= my && my < Y && !v[my][mx] && t.time + 1 < c[my][mx]){
				v[my][mx] = 1;
				c[my][mx] = t.time + 1;
				n = t;
				n.tx = mx, n.ty = my, n.time = t.time + 1;
				enq(n);
				ans++;
			}
		}
	}
	
	return (ans);
}

int main(void)
{
	int s, t;
	int i, j;
	int ans;
	
	while (scanf("%d", &X) && X){
		scanf("%d", &Y);
		
		scanf("%d", &s);
		
		for (i = 0; i < Y; i++){
			for (j = 0; j < X; j++){
				mp[i][j] = 99999;
			}
		}
		
		for (i = 0; i < s; i++){
			int xi, yi;
			scanf("%d %d", &xi, &yi);
			bfs(mp, --xi, --yi);
		}
		
		scanf("%d", &t);
		ans = 0;
		
		for (i = 0; i < t; i++){
			int pi, qi;
			int k;
			scanf("%d %d", &pi, &qi);
			memcpy(test, mp, sizeof(mp));
			k = bfs(test, --pi, --qi);
			ans = max(ans, k);
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 1032
from math import sqrt
def circle_center(x1, y1, x2, y2):
    xd = x2 - x1; yd = y2 - y1
    k = sqrt(1.0/(xd**2 + yd**2) - 0.25)
    xc = (x1 + x2) / 2.0; yc = (y1 + y2) / 2.0
    xd *= k; yd *= k
    return [[xc - yd, yc + xd], [xc + yd, yc - xd]]
while 1:
    n = int(raw_input())
    if n==0: break
    p = sorted(map(float, raw_input().split()) for i in xrange(n))
    prev = 0; pvx = p[0][0]
    ans = 1
    for i in xrange(n):
        bx, by = p[i]
        bxm2 = bx - 2.0; bxp2 = bx + 2.0
        bym2 = by - 2.0; byp2 = by + 2.0
        while bxm2 >= pvx:
            prev += 1; pvx = p[prev][0]
        for j in xrange(i+1, n):
            cx, cy = p[j]
            if cx >= bxp2: break
            if bym2 <= cy <= byp2 and (bx - cx)**2 + (by - cy)**2 <= 4.0:
                for ex, ey in circle_center(bx, by, cx, cy):
                    count = 2
                    exm1 = ex - 1.0; exp1 = ex + 1.0
                    eym1 = ey - 1.0; eyp1 = ey + 1.0
                    q = prev
                    while exm1 >= p[q][0]: q += 1
                    for k in xrange(q, n):
                        if k==i or k==j: continue
                        dx, dy = p[k]
                        if dx >= exp1: break
                        if eym1 <= dy <= eyp1 and (ex - dx)**2 + (ey - dy)**2 <= 1.0:
                            count += 1
                    ans = max(ans, count)
    print ans

Measured memory_bytes: 6492
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int c[10][1005];

int main() {
	int h, w, k;
	cin >> h >> w >> k;

	vs s(h);
	rep(i, h) cin >> s[i];
	int ans = inf;
	rep(div, 1 << (h - 1)) {
		int g = 0;
		vi id(h);
		rep(i, h) {
			id[i] = g;
			if (div >> i & 1) ++g;
		}
		++g;

		rep(i, g) rep(j, w) c[i][j] = 0;
		rep(i, h) rep(j, w) c[id[i]][j] += (s[i][j] - '0');

		int num = g - 1;
		vi now(g);
		auto add = [&](int j) {
			rep(i, g) now[i] += c[i][j];
			rep(i, g) if (now[i] > k) return false;
			return true;
		};

		rep(j, w) {
			if (!add(j)) {
				num++;
				now = vi(g);
				if (!add(j)) {
					num = inf;
					break;
				}
			}
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, m;
    cin >> n >> m;
    vi l(m), r(m);
    rep(i, m) cin >> l[i] >> r[i];

    int ll = 1, rl = n;
    rep(i, m) {
        if (ll < l[i]) ll = l[i];
        if (rl > r[i]) rl = r[i];
    }

    cout << max(0, rl - ll + 1) << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
namespace Sample{
class Sample
  {
    static void Main(string[] args)
    {
      int N=int.Parse(Console.ReadLine());
      string[] str=Console.ReadLine().Split(' ');
      int ans=0;
      for(int i=0;i<=N-1;i++){
        int di=(int.Parse(str[i]));
          for(int j=0;j<=N-1;j++){
            int hp=di*(int.Parse(str[j]));
      ans+=hp;
      }
        ans=ans-(di*di);
      }
      ans=(ans/2);
   
    Console.WriteLine(ans);
  }
 
}
}


Measured memory_bytes: 13140
#include <iostream>

using namespace std;

int main(){
  int N,M=0,i=1,k,S=0,l;
  cin >> N;
  if (N==3) {
    cout << 2 << " " << 5 << " " << 63;
    return 0;
  }
  while (N>2){
    if ((i%2)==0||(i%3)==0||(i%5)==0) {
      cout << i << " ";
      S+=i;
      N--;
    }
    i++;
  }
  if (S%2==0) {
    k=29998;
  } else {
    k=29997;
  }
  l=(S+2*k-1)/30 *30 -S-k;
  cout << k << " " << l;
  return 0;
}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var w,h,x,y float64
	fmt.Scan(&w,&h,&x,&y)

	c := 0
	if w/2.0 == x && h/2.0 == y{
		c = 1
	}
	fmt.Printf("%.10f %d\n", w*h/2.0, c)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
    int x ;
    cin >> x ;
    int a = x /100 ;
    int b = x % 100 ;
    if (a*5 < b)
    {
        cout << 0 << endl ;
    }else
    {
        cout << 1 << endl ;
    }
    
    
}

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

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int K, N; cin >> K >> N;
	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
	}
	
	ll dmax = A[0] + (K-A[N-1]);
	rep(i, N - 1) {
		dmax = max(dmax, (ll)(A[i + 1] - A[i]));
	}

	cout << K - dmax << endl;

	return 0;
}

Measured memory_bytes: 4028
A, B, C, X, Y = map(int, input().split())


if 2*C<A and 2*C<B:
	print(2*C*max([X,Y]))
elif 2*C<A:
	if X<Y:
		print(2*C*X+B*(Y-X))
	else:
		print(2*C*X)
elif 2*C<B:
	if Y<X:
		print(2*C*Y+A*(X-Y))
	else:
		print(2*C*Y)
elif 2*C<A+B:
	if Y<X:
		print(2*C*Y+A*(X-Y))
	else:
		print(2*C*X+B*(Y-X))

else:
	print(A*X+B*Y)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	int L, A, B, C, D;
	cin >> L >> A >> B >> C >> D;

	A = A%C == 0 ? A/C : A/C + 1;
	B = B%D == 0 ? B/D : B/D + 1;

	L = A>B ? L-A:L-B;

	cout << L << endl;
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
rank1 = 0
rank2 = 0
ax = []
for i in range(n) :
  a = int(input())
  if rank1 <= a : 
    rank2 = rank1 
    rank1 = a
  elif rank2 < a :
    rank2 = a
  ax.append(a)
    

for i in range(n) :
  if ax[i] == rank1 :
    print(rank2)
  else :
    print(rank1)

Measured memory_bytes: 12608
n = int(input())
a = list(map(int, input().split()))
mn = 10**9+1
minus = 0
zero = 0
ans = 0
for i in a:
    if abs(i) < mn:
        mn = abs(i)
    if i < 0:
        minus += 1
    if i == 0:
        zero += 1
    ans += abs(i)

tmp = mn if zero == 0 and minus % 2 else 0
print(ans - tmp * 2)


Measured memory_bytes: 14412
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define test            int t; cin>>t; while(t--)
#define io             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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


int32_t main(){
  io ;

  int n;
  cin >> n;
  int arr[n]; 
  for(int i = 0; i<n ; i++){
  cin>>arr[i] ; 
  }
  sort(arr, arr + n);
  int ans = 0; 
  for (int i = 0; i < n; i++){
      for (int j = 0 ; j < i ; j++){
          for (int k = 0; k < j; k++){
              if( arr[j]+arr[k]>arr[i]  and arr[i]!=arr[j] and arr[j]!=arr[k] and arr[i]!=arr[k]){
                  ans++; 
              }
          }
      }
  } 
  
  cout <<ans << "\n"; 
}

Measured memory_bytes: 3656
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let MOD: u64 = 1_000_000_007;
  let (n, m) = {
    let v: Vec<usize> = read_vec();
    (v[0], v[1])
  };

  let mut a: Vec<u64> = Vec::new();
  for _ in 0..m {
    let at = read();
    a.push(at);
  }
  let mut dp: Vec<u64> = vec![0; n+1];
  dp[0] = 1;
  dp[1] = 1;
  for i in 2..n+1 {
    let bn1 = match a.binary_search(&((i-1) as u64)) {
      Ok(i) => true,
      Err(err) => false,
    };

    let bn2 = match a.binary_search(&((i-2) as u64)) {
      Ok(i) => true,
      Err(err) => false,
    };
    if !bn1 && !bn2 {
      dp[i] = dp[i-1] + dp[i-2] % MOD;
    }
    else if bn1 && !bn2 {
      dp[i] = dp[i-2] % MOD;
    }
    else if !bn1 && bn2 {
      dp[i] = dp[i-1] % MOD;
    }

  }

  println!("{:?}", dp[n] % MOD);
}


Measured memory_bytes: 6396
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
L = []
for i, a in enumerate(A):
    L.append([i+1, a])
L = sorted(L,key=lambda x: x[1])

ans = []
for i in range(N):
    ans.append(L[i][0])
print(*ans)

    


Measured memory_bytes: 25624
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	char str[10001];
	int r[2], i;
	while (cin >> str)
	{
		if (cin.eof()) break;
		r[0] = r[1] = 0;
		for (i = 0; i < signed(strlen(str))-2;)
		{
			if (str[i] == 'I' || str[i] == 'J')
			{
				if (str[i+1] == 'O' && str[i+2] == 'I')
				{
					r['J'-str[i]]++;
					i+=2;
				}
				else
					i++;
			}
			else
				i++;
		}
		cout << r[0] << endl << r[1] << endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=20100;
int n,x,y;
int ans[maxn];
int main()
{
	
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<=n;++i)
	{
		for(int j=i+1;j<=n;++j)
		{
			int k=min(j-i,abs(x-i)+1+abs(j-y));
			k=min(k,abs(x-j)+1+abs(y-i));
			ans[k]++;
		}
	}
	for(int i=1;i<n;++i)
	{
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 3724
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll x,y;
cin >> x >> y;
ll ans = 0;
if(x == 1){
    ans += 300000;
}
if(y == 1){
    ans += 300000;
}
if(x == 2){
    ans += 200000;
}
if(y == 2){
    ans += 200000;
}
if(x == 3){
    ans += 100000;
}
if(y == 3){
    ans += 100000;
}
if(x == 1 && x == y){
    ans += 400000;
}
cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}



int main(){
  ll N,C; cin>>N>>C;
  ll x[N+2],v[N+2];
  x[0] = 0LL;
  v[0] = 0LL;
  x[N+1] = C;
  v[N+1] = 0LL;
  for(int i=1;i<=N;++i){
    cin >> x[i] >> v[i];
  }

  ll tokei_eiyo[N+2];
  tokei_eiyo[0] = 0LL;
  for(int i=0;i<=N;++i){
    tokei_eiyo[i+1] = tokei_eiyo[i] + v[i+1];
  }
  ll tokei_ofuku_max[N+2];
  tokei_ofuku_max[0] = 0LL;
  for(int i=0;i<=N;++i){
    tokei_ofuku_max[i+1] = max(tokei_ofuku_max[i],tokei_eiyo[i+1]-x[i+1]*2);
  }

  ll hanto_eiyo[N+2];
  hanto_eiyo[N+1] = 0LL;
  for(int i=N+1;i>0;--i){
    hanto_eiyo[i-1] = hanto_eiyo[i] + v[i-1];
  }
  ll hanto_ofuku_max[N+2];
  hanto_ofuku_max[N+1] = 0LL;
  for(int i=N+1;i>0;--i){
    hanto_ofuku_max[i-1] = max(hanto_ofuku_max[i],hanto_eiyo[i-1]-(C-x[i-1])*2);
  }

  ll ans = 0LL;
  for(int i=1;i<=N;++i){
    chmax(ans,tokei_ofuku_max[i-1]+hanto_eiyo[i]-(C-x[i]));
    chmax(ans,hanto_ofuku_max[i+1]+tokei_eiyo[i]-x[i]);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 8272
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
const long long mod = 1e9 + 7;
int p[1005];

int main()
{
    int n;
    int i,j,m,k;
    long long sum;

    while(scanf("%d",&n) != EOF)
    {
        memset(p,0,sizeof(int) * 1005);
        sum = 1;

        for(k = 2; k <= n; k++)
        {
            for(i = 2,m = k; i*i <= m; i++)
            {
                while(m % i == 0)
                {
                    p[i]++;
                    m /= i;
                }
            }
            if(m != 1) p[m]++;
        }
        for(i = 2;i < 1005;i++)
        {
            if(p[i] != 0)
            sum = (sum * (p[i]+1)) % mod;
        }
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 256
//2020.1.27
//s1270188 xxxmk2
//alds1_12a

#include<stdio.h>
#include<limits.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

//global
int data[N][N], num;

//function
int cnt(void){
  int color[N], d[N], p[N];
  int min, i, j, u;

  //reset
  for(i=0;i<num;i++){
    color[i]=WHITE;
    d[i]=INT_MAX;
    p[i]=-1;
  }
  d[0]=0;

  
  while(1){
    min=INT_MAX;
    
    for(i=0;i<num;i++){
      if(color[i]!=BLACK && d[i]<min){
	min=d[i];
	u=i;
      }
    }
    
    if(min==INT_MAX) break;

    color[u]=BLACK;

    for(j=0;j<num;j++){
      if(color[j]!=BLACK && data[u][j]!=INT_MAX ){
	if(data[u][j]<d[j]){
	  d[j]=data[u][j];
	  p[j]=u;
	  color[j]=GRAY;
	}
      }
    }
    
  }

  
  j=0;
  for(i=0;i<num;i++)
    if(p[i]!=-1) j+=data[i][p[i]];
  
  return j;
}



int main(){
  int i, j;

  //input
  scanf("%d",&num);
  for(i=0;i<num;i++){
    for(j=0;j<num;j++) {
      scanf("%d",&data[i][j]);
      if(data[i][j]<0) data[i][j]=INT_MAX;
    }
  }
  
  //output
  printf("%d\n",cnt());
  
  return 0;
}



Measured memory_bytes: 2112
#include <stdio.h>
#include <math.h>

int main(void){
	int N,K;
	int d[110];
	int A[110][110];
	scanf("%d %d\n",&N,&K);
	int i,j,k;
	int ans[110];
	int ans_s[110];
	for(i=0;i<K;i++){
	    scanf("%d\n",&d[i]);
    	for(j=0;j<d[i];j++){
	        scanf("%d ",&A[i][j]);
//	        printf("A%d%d=%d\n",i,j,A[i][j]);
    	}
	}
	for(i=0;i<K;i++){
	    for(j=0;j<d[i];j++){
	        ans[A[i][j]]++;
	    }
	}

	for(i=1;i<=N;i++){
//        printf("N%d=%d ",i,ans[i]);
//        ans[i]=ans_s[i];
        if(ans[i]==0){
            k++;
        }
	}
	printf("%d",k);

}


Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,X; cin >> n >> X;
    VI x(n); VIin(x);
    if(x.size() == 1) {
        OUT(abs(x[0] - X));
        return 0;
    }
    VI sa(n);
    rep(i,n) sa[i] = abs(x[i] - X);
    SORT(sa);
    int ans = INF, res;
    rep(i,n-1){
        res = gcd(sa[i],sa[i+1]);
        ans = min(ans,res);
    }
    ANS;

    return 0;
}



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

int main(){

    int n,l;
    cin>> n >> l;

    vector<int> a(n);
    int su=0;
    rep(i,n){
        a[i]=l+i;
        su+=a[i];
    }

    int ans=su-a[0];
    int mi=abs(su-(su-a[0]));
    rep(i,n){
        if(mi>abs(su-(su-a[i]))){
            ans=su-a[i];
            mi=abs(su-(su-a[i]));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200050
using namespace std;
typedef long long ll;
int a[N],b[N],n;
ll ans=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	if (a[1]) {printf("-1\n");return 0;}
	for (int i=2;i<=n;i++) if (a[i]-a[i-1]>=2) {printf("-1\n");return 0;};
	for (int i=1;i<=n;i++) b[i-a[i]]=a[i];
	for (int i=0;i<=n;i++) ans+=b[i];
	printf("%lld\n",ans);
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  char a, b;
  cin >> a >> b;
  if (a == 'D') {
    if (b == 'H') b = 'D';
    else b = 'H';
  }
  cout << b << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3604
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    for res in ['AC', 'WA', 'TLE', 'RE']:
        print(f"{res} x {S.count(res)}")
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16292
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define llint long long

using namespace std;

llint n, d;
llint x[100005], y[100005];
llint cnt[1005][1005], need[1005][1005];
llint type[1005][1005];
llint t1, t2;
llint sum1[2005][2005], sum2[2005][2005];
vector<llint> vec;

llint rect(llint sx, llint sy, llint tx, llint ty, llint sum[2005][2005])
{
	llint ret = sum[tx][ty];
	if(sx > 0) ret -= sum[sx-1][ty];
	if(sy > 0) ret -= sum[tx][sy-1];
	if(sx > 0 && sy > 0) ret += sum[sx-1][sy-1];
	return ret;
}

bool check(llint i, llint j, llint a)
{
	if(rect(i, j, i+a-1, j+a-1, sum2) < t2) return false;
	if(rect(i+a, j+a, i+d-1, j+d-1, sum1) > 0) return false;
	return true;
}

int main(void)
{
	cin >> n >> d;
	for(int i = 0; i*i <= 1e9+7; i++) vec.push_back(i*i);
	
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	for(int i = 1; i <= n; i++) cnt[x[i]%d][y[i]%d]++;
	for(int i = 0; i < d; i++){
		for(int j = 0; j < d; j++){
			if(cnt[i][j] == 0) continue;
			need[i][j] = lower_bound(vec.begin(), vec.end(), cnt[i][j]) - vec.begin();
		}
	}
	
	llint mx = 0, mn = 1e9;
	for(int i = 0; i < d; i++){
		for(int j = 0; j < d; j++){
			mx = max(mx, need[i][j]);
			mn = min(mn, need[i][j]);
		}
	}
	if(mx == mn){
		cout << d*mx-1 << endl;
		return 0;
	}
	
	for(int i = 0; i < d; i++){
		for(int j = 0; j < d; j++){
			if(cnt[i][j] <= (mx-1)*(mx-1)) type[i][j] = 0;
			else if(cnt[i][j] <= mx*(mx-1)) type[i][j] = 1, t1++;
			else type[i][j] = 2, t2++;
		}
	}
	//cout << mx << " " << t1 << " " << t2 << endl << endl;;
	
	for(int i = 0; i < 2*d; i++){
		for(int j = 0; j < 2*d; j++){
			if(type[i%d][j%d] == 1) sum1[i][j]++;
			if(type[i%d][j%d] == 2) sum2[i][j]++;
			if(i > 0) sum1[i][j] += sum1[i-1][j], sum2[i][j] += sum2[i-1][j];
			if(j > 0) sum1[i][j] += sum1[i][j-1], sum2[i][j] += sum2[i][j-1];
			if(i > 0 && j > 0) sum1[i][j] -= sum1[i-1][j-1], sum2[i][j] -= sum2[i-1][j-1];
		}
	}
	
	/*for(int i = 0; i < 2*d; i++){
		for(int j = 0; j < 2*d; j++){
			cout << sum2[i][j] << " ";
		}
		cout << endl;
	}*/
	
	llint ans = d;
	for(int i = 0; i < d; i++){
		for(int j = 0; j < d; j++){
			llint ub = d, lb = 0, mid;
			while(ub-lb>1){
				mid = (ub+lb)/2;
				if(check(i, j, mid)) ub = mid;
				else lb = mid;
			}
			//cout << i << " " << j << " " << ub << endl;
			ans = min(ans, ub);
		}
	}
	cout << (mx-1)*d + ans - 1 << endl;
	
	return 0;
}

Measured memory_bytes: 88572