akhauriyash/Code-Regression huggingface dataset:
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let (a, b): (usize, usize) = {
        let mut split = buf.split_whitespace();
        (split.next().unwrap().parse().unwrap(), split.next().unwrap().parse().unwrap())
    };
    let mut upper_grid = vec![vec![false; 100]; 50];
    let mut lower_grid = vec![vec![true; 100]; 50];
    let mut count_a = 0;
    for x in 0..24 {
        for y in 0..24 {
            if count_a + 1 == a { break; }
            count_a += 1;
            upper_grid[y * 2 + 1][x * 2 + 1] ^= true;
        }
    }
    let mut count_b = 0;
    for x in 0..24 {
        for y in 0..24 {
            if count_b + 1 == b { break; }
            count_b += 1;
            lower_grid[y * 2 + 1][x * 2 + 1] ^= true;
        }
    }
    writeln!(output, "100 100").unwrap();
    for row in upper_grid.into_iter().chain(lower_grid) {
        for column in row {
            write!(output, "{}", if column { '.' } else { '#' }).unwrap();
        }
        writeln!(output, "").unwrap();
    }
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "3
3 5 -1
",
            "12
8
10
",
        );
    }

    #[test]
    fn case2() {
        test(
            "5
1 1 1 2 0
",
            "4
4
4
2
4
",
        );
    }

    #[test]
    fn case3() {
        test(
            "6
-679 -2409 -3258 3095 -3291 -4462
",
            "21630
21630
19932
8924
21630
19288
",
        );
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    for (int i = n - m; i >= 0; --i)
    {
        bool good = true;
        for (int j = i; j < i + m; ++j)
            if (!(s[j] == '?' || s[j] == t[j - i]))
                good = false;
        
        if (good)
        {
            for (int j = 0; j < i; ++j)
                cout << (s[j] == '?' ? 'a' : s[j]);
            for (int j = i; j < i + m; ++j)
                cout << t[j - i];
            for (int j = i + m; j < n; ++j)
                cout << (s[j] == '?' ? 'a' : s[j]);
            return 0;
        }
    }
    cout << "UNRESTORABLE";
}


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

string s;
int use;

void ReplaceAll(string &s,string a, string b){
  int p = s.find(a);
  while(p!=string::npos){
    s.replace(p,a.size(),b);
    p = s.find(a);
  }
}

bool parse(int l,int r){
  int p = 0;
  for(int i=l;i<r;i++){
    if(s[i] == '(')p++;
    if(s[i] == ')')p--;
    if(!p){
      if(s[i] == '*')return parse(l,i) && parse(i+1,r);
      if(s[i] == '+')return parse(l,i) || parse(i+1,r);
      if(s[i] == '-' && s[i+1] == '>')return !parse(l,i) || parse(i+2,r);
    }
  }

  if(s[l] == '-')return !parse(l+1,r);
  if(s[l] == '(' && s[r-1] == ')')return parse(l+1,r-1);
  if(s[l] == 'T')return true;
  if(s[l] == 'F')return false;
  return ( ( use >> (s[l]-'a') ) & 1);
}

int main(){
  while(cin >> s,s!="#"){
    ReplaceAll(s,"--","");
    int x = s.find("="),all = 1<<11;
    bool f = true;
    for(use=0;use<all;use++){
      f &= (parse(0,x) == parse(x+1,s.size()));
      if(!f)break;
    }
    cout << (f?"YES\n":"NO\n");
  }
}

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

int main() {
  int a, b, c, d, e;

  cin>>a>>b>>c>>d;

  if (a==0)
  {
    cout<<1;
  }

  else if (b==0)
  {
    cout<<2;
  }

  else if (c==0)
  {
    cout<<3;
  }

  else if (d==0)
  {
    cout<<4;
  }

  else
  {
    cout<<5;
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

int length(int N, int X, int Y,int i,int j){
  int a,b,c;
  a=abs(i-j);
  b=abs(i-X)+1+abs(j-Y);
  c=abs(i-Y)+1+abs(j-X);
  return min(min(a,b),c);
}

vi count(int N,int X,int Y,int i){
  vi data(N,0);
  for(int j=1;j<N+1;j++){
    if(i!=j){
      data.at(length(N,X,Y,i,j))++;
    }
  }
  return data;
}

int main(){
  int N,X,Y;
  cin>>N>>X>>Y;
  vi ans(N,0);
  for(int i=1;i<N+1;i++){
    vi d(N,0);
    d=count(N,X,Y,i);
    rep(j,N){
      ans.at(j)+=d.at(j);
    }
  }
  for(int i=1;i<N;i++){
    cout<<ans.at(i)/2<<endl;
  }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

if n == 1:
    print(1)
    exit()

if len(set(a)) == 1:
    print(n)
    exit()

n_dict = {}
min_n = 10**9
max_n = 0
for i in range(n):
    t = a[i]
    if t in n_dict:
        n_dict[t] += 1
    else:
        n_dict[t] = 1
    
    max_n = max(t, max_n)
    min_n = min(t, min_n)

ans = 0
for x in range(min_n+1, max_n+1):
    tmp = 0
    if x-1 in n_dict: tmp += n_dict[x-1]
    if x in n_dict: tmp += n_dict[x]
    if x+1 in n_dict: tmp += n_dict[x+1]
    
    ans = max(ans, tmp)
print(ans)

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

bool check(string &s){
    bool flag = true;
    REP(i,s.size()/2){
        if(s[i] != s[s.size()-1-i]){
            flag = false;
            break;
        }
    }
    return !flag;
}

int main(void){
    string s; cin >> s;
    string rmv = "";
    REP(i,s.size()) if(s[i]!='x') rmv += s[i];
    if(check(rmv)){
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    
    int l = 0, r = s.size()-1;
    while(l < r){
        if(s[l]!=s[r]){
            if(s[l]=='x') l++;
            else r--;
            ans++;
        }
        else{
            l++;
            r--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define N 5000005
#define sag (root+root+1)
#define sol (root+root)
#define ort  ((bas+son)/2)
#define mod 1000000007
 
using namespace std;
typedef long long ll;
 
 
int main() {
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0;i<n;i++)cin>>arr[i];
    for(int i = 0;i<n;i++){
        if(arr[i] % 2 == 0){
        	if(!(arr[i]%3 == 0 or arr[i] % 5 == 0)){
        		cout << "DENIED"<<endl;
        		//cout << arr[i];
        		return 0;
			}
		}
    }
    cout<<"APPROVED";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <cstdlib>
#include <cstdio>
using namespace std;

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop() {
  top--;
  return S[top+1];
}

int main() {
  int a, b;
  top = 0;
  char s[100];

  while ( scanf("%s", s) != EOF ) {
    if ( s[0] == '+' ) {
      a = pop();
      b = pop();
      push(b + a);
    } else if ( s[0] == '-' ) {
      a = pop();
      b = pop();
      push(b - a);
    } else if ( s[0] == '*' ) {
      a = pop();
      b = pop();
      push(b * a);
    } else if ( s[0] == '/' ) {
      a = pop();
      b = pop();
    } else {
      push(atoi(s));
    }
  }

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

  return 0;
}

Measured memory_bytes: 3204
def main():
    n = input()
    dic = {}
    for i in xrange(1, n + 1):
        s = str(i)
        key = (s[0], s[-1])
        try:
            dic[key] += 1
        except KeyError:
            dic[key] = 1
    ans = 0
    for a, b in dic:
        ans += dic[(a, b)] * dic.get((b, a), 0)
    print ans


main()


Measured memory_bytes: 32668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=53,INF=1<<30;
vector<int> dh={0,1,0,-1},dw={1,0,-1,0};
bool seen[MAX][MAX][MAX][MAX],can[MAX][MAX][2];

int sh1,sw1,sh2,sw2,gh1,gw1,gh2,gw2;

int H,W;

struct point{
    int hh1;
    int ww1;
    int hh2;
    int ww2;
};

void DFS(int h11,int w11,int h22,int w22){
    stack<point> ST;
    ST.push(point{h11,w11,h22,w22});
    seen[h11][w11][h22][w22]=1;
    
    while(!ST.empty()){
        point p=ST.top();ST.pop();
        int h1=p.hh1,w1=p.ww1,h2=p.hh2,w2=p.ww2;
        
        for(int k=0;k<4;k++){
            int toh1,tow1,toh2,tow2;
            toh1=h1+dh[k];
            tow1=w1+dw[k];
            toh2=h2+dh[k];
            tow2=w2-dw[k];
            
            if(toh1<0||toh1>=H||tow1<0||tow1>=W||can[toh1][tow1][0]==0){
                toh1=h1;
                tow1=w1;
            }
            
            if(toh2<0||toh2>=H||tow2<0||tow2>=W||can[toh2][tow2][1]==0){
                toh2=h2;
                tow2=w2;
            }
            
            if(h1==toh1&&h2==toh2&&w1==tow1&&w2==tow2) continue;
            
            if(toh1==gh1&&tow1==gw1){
                if(toh2!=gh2||tow2!=gw2) continue;
            }
            
            if(toh2==gh2&&tow2==gw2){
                if(toh1!=gh1||tow1!=gw1) continue;
            }
            
            if(seen[toh1][tow1][toh2][tow2]==0){
                seen[toh1][tow1][toh2][tow2]=1;
                ST.push(point{toh1,tow1,toh2,tow2});
                //break;
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        cin>>W>>H;
        if(H+W==0) break;
        memset(seen,0,sizeof(seen));
        memset(can,0,sizeof(can));
        //int sh1,sw1,sh2,sw2,gh1,gw1,gh2,gw2;
        
        for(int i=0;i<H;i++){
            string S,T;cin>>S>>T;
            for(int j=0;j<W;j++){
                if(S[j]!='#') can[i][j][0]=1;
                if(S[j]=='L'){
                    sh1=i;
                    sw1=j;
                }
                if(S[j]=='%'){
                    gh1=i;
                    gw1=j;
                }
            }
            for(int j=0;j<W;j++){
                if(T[j]!='#') can[i][j][1]=1;
                if(T[j]=='R'){
                    sh2=i;
                    sw2=j;
                }
                if(T[j]=='%'){
                    gh2=i;
                    gw2=j;
                }
            }
        }
        
        DFS(sh1,sw1,sh2,sw2);
        
        if(seen[gh1][gw1][gh2][gw2]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}






Measured memory_bytes: 28768
N = int(input())
A = [int(x) for x in input().split()]

s_sum = sum(A)

ans = [None] * N

ans[0] = s_sum
for i in range(1, N, 2):
    ans[0] -= 2 * A[i]

for i in range(N-1):
    ans[i + 1] = 2 * A[i] - ans[i]

print(*ans)


Measured memory_bytes: 64612
N,M,K = [int(i) for i in raw_input().split()]
 
OK = False
 
for a in range(N+1):
    for b in range(M+1):
        if(a*(M-b) + b*(N-a)==K):OK =True
 
 
if(OK):print("Yes")
else:print("No")

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}
ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up

//Start from Here
int main(){
    int N;
    cin>>N;
    ll a[(N+1)/2][3];
    ll c[N];
    rep(i, N){
        cin>>c[i];
    }
    if(N%2==1){
        a[0][0]=0;
        a[0][1]=0;
        a[0][2]=c[0];
        rep2(i, (N-1)/2){
            a[i][1]=max(a[i-1][0],a[i-1][1])+c[2*i];
            a[i][0]=max(c[2*i-1]+a[i-1][0],a[i-1][2]);
            a[i][2]=a[i-1][2]+c[2*i];
        }
        cout<<max(a[(N-1)/2][0],a[(N-1)/2][1])<<endl;
    }else{
        a[0][0]=0;
        a[0][1]=c[0];
        rep2(i, N/2-1){
            a[i][0]=max(a[i-1][0]+c[2*i-1],a[i-1][1]);
            a[i][1]=a[i-1][1]+c[2*i];
        }
        cout<<max(a[N/2-1][0]+c[N-1],a[N/2-1][1])<<endl;
    }

}

Measured memory_bytes: 7540
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <queue>
using namespace std;

#define rep(i,n)for(int i=0; i<(int)(n); i++)
#define bitrep(tmp, N)for (int tmp=0; tmp < (1<<N);tmp++)
#define all(v) v.begin(), end.bigin()

int INF = -10e6;


pair<int, int> start;
pair<int, int> goal;


int main(){
  int R,C;
  cin >> R >> C;
  start = make_pair(0,0);
  goal = make_pair(R-1,C-1);
  int ans =0;
  vector<vector<char>> field(R, vector<char>(C));
  rep(i,R){
    rep(j,C){
      cin >> field.at(i).at(j);
      if (field.at(i).at(j)=='.') ans ++;
    } 
  }
  vector<vector<int>> count(R, vector<int>(C, INF));
  count.at(start.first).at(start.second) = 0;
  
  queue<pair<int,int>> que;
  que.push(start);
  int x;
  int y;
  while(que.size()){
    
    pair<int,int> p = que.front();
    x = p.first;
    y= p.second;
    que.pop();
    if(x-1>=0 && field[x-1][y]!='#' && count[x-1][y]==INF){
      que.push(make_pair(x-1,y));
      count[x-1][y] = count[x][y] + 1;
    }
    if(x+1<R && field[x+1][y]!='#' && count[x+1][y]==INF){
      que.push(make_pair(x+1,y));
      count[x+1][y] = count[x][y] + 1;
    }
    if(y-1>=0 && field[x][y-1]!='#' && count[x][y-1]==INF){
      que.push(make_pair(x,y-1));
      count[x][y-1] = count[x][y] + 1;
    }
    if(y+1<C && field[x][y+1]!='#' && count[x][y+1]==INF){
      que.push(make_pair(x,y+1));
      count[x][y+1] = count[x][y] + 1;
    }
  }
  if (count[R-1][C-1]==INF){
    cout << -1<<endl;
    return 0;
  } 
  int root = count[R-1][C-1];
  ans = ans -root-1;
  cout << ans <<endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if(0 == a*b % 2)
    cout << "Even" << endl;
    
  if(1 == a*b % 2)
    cout << "Odd" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;
int* A;

void print_array(int* arr) {
    cout << arr[0];
    for (int k = 1; k < N; k++) {
      cout << " " << arr[k];
    }
    cout << endl;
}

void solve() {
  print_array(A);

  for (int i = 1; i < N; i++) {
    int key = A[i];
    int j = i - 1;
    while(j >= 0 && A[j] > key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;

    print_array(A);
  }
}

int main() {
  cin >> N;
  A = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  solve();

  return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
	int n;
	int count = 0;
	int top;

	cin >> n;

	vector<int> d(n);

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

	sort(d.begin(), d.end());

	top = d[0];
	count++;

	for (int i = 1; i < n; i++) {
		if (top != d[i]) {
			top = d[i];
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x,val) memset(x,val,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
    template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
    bool IN(ll x,ll l,ll r){return l<=x and x<=r;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    bool ok[N];int cnt[N];
    void main()
	{
        int n=qread(),m=qread();
        int A=0,B=0;
        while(m--)
        {
            int now=qread();string s;cin>>s;
            if(s=="AC")
            {
                if(!ok[now]) {ok[now]=1,A++,B+=cnt[now];}
            }
            else
            {
                cnt[now]++;
            }
        }write1(A),write(B);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>

#define X first
#define Y second
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;

int x[500];

int main(void){
  int n, m;
  cin >> n >> m;
  int a,b;
  rep(i,m){
    cin >> a >> b;
    a--;
    b--;
    x[a]++;x[b]++;
  }
  rep(i,n){
    cout << x[i] << endl;
  }
  return 0;
}


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

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

int main() {
	
	int n; cin >> n;
	vector<int> h(n);
	for(int i=0; i<n; i++) cin >> h.at(i);
	vector<int> dp(n,(int)1e9+7);
	dp.at(0)=0;
	for(int i=0; i<n-1; i++){
		chmin( dp.at(i+1), dp.at(i)+abs(h.at(i+1)-h.at(i)));
		if(i==n-2) break;
		chmin( dp.at(i+2), dp.at(i)+abs(h.at(i+2)-h.at(i)));
	}
	cout << dp.at(n-1) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>

int main(){
    long H1,M1,H2,M2,K;
    std::cin >> H1 >> M1 >> H2 >> M2 >> K;
    std::cout << H2*60+M2-H1*60-M1-K << std::endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL H,W; cin >> H >> W;
    LL ans = LINF;

    REP(i,H+1)
    {
        LL bl[3];
        bl[0] = i * W;
        bl[1] = (H - i) * (W - W/2);
        bl[2] = (H - i) * (W/2);
        LL cand[3];
        cand[0] = abs(bl[0] - bl[1]);
        cand[1] = abs(bl[0] - bl[2]);
        cand[2] = abs(bl[1] - bl[2]);

        LL cand_all = max(cand[0],max(cand[1], cand[2]));
        if(cand_all < ans) ans = cand_all;

    }
    REP(i,H+1)
    {
        LL bl[3];
        bl[0] = i * W;
        bl[1] = ((H - i) / 2) * W;
        bl[2] = (H - i - (H-i)/2) * W;

        LL cand[3];
        cand[0] = abs(bl[0] - bl[1]);
        cand[1] = abs(bl[0] - bl[2]);
        cand[2] = abs(bl[1] - bl[2]);

        LL cand_all = max(cand[0],max(cand[1], cand[2]));
        if(cand_all < ans) ans = cand_all;
    }
    swap(H,W);

    REP(i,H+1)
    {
        LL bl[3];
        bl[0] = i * W;
        bl[1] = (H - i) * (W - W/2);
        bl[2] = (H - i) * (W/2);
        LL cand[3];
        cand[0] = abs(bl[0] - bl[1]);
        cand[1] = abs(bl[0] - bl[2]);
        cand[2] = abs(bl[1] - bl[2]);

        LL cand_all = max(cand[0],max(cand[1], cand[2]));
        if(cand_all < ans) ans = cand_all;

    }

    REP(i,H+1)
    {
        LL bl[3];
        bl[0] = i * W;
        bl[1] = ((H - i) / 2) * W;
        bl[2] = (H - i - (H-i)/2) * W;

        LL cand[3];
        cand[0] = abs(bl[0] - bl[1]);
        cand[1] = abs(bl[0] - bl[2]);
        cand[2] = abs(bl[1] - bl[2]);

        LL cand_all = max(cand[0],max(cand[1], cand[2]));
        if(cand_all < ans) ans = cand_all;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.*;
import java.math.BigDecimal;

class Main{
  static double r;
    
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    r = sc.nextDouble();
    BigDecimal rb = BigDecimal.valueOf(r);
    BigDecimal b2 = new BigDecimal(2);
    BigDecimal pye = new BigDecimal("3.14159265358979323846");
    BigDecimal rr = rb.multiply(rb);
    BigDecimal rrpye = pye.multiply(rr);
    BigDecimal rpye = pye.multiply(rb);
    BigDecimal r2pye = rpye.multiply(b2);
    System.out.println(rrpye + " " + r2pye);
  }
}




Measured memory_bytes: 28328
#include<stdio.h>

int main(void){
  int L,A,B,C,D;

  scanf("%d",&L);
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  scanf("%d",&D);
  while(A>0 || B>0){
      A-=C;
      B-=D;
      L--;
  }
  printf("%d\n",L);

  return 0;
}



Measured memory_bytes: 2140
counter = {}
while line = gets
  while c = line.slice!(0)
    c.downcase!
    if counter.has_key?(c)
      counter[c] += 1
    else
      counter[c] = 1
    end
  end
end

("a".."z").each do |i|
  puts "#{i} : #{counter[i].to_i}"
end

Measured memory_bytes: 8960
import sys
    
A=[]
fp =0
bp =0

n=int(raw_input())
while n:
    s = raw_input()
    if s[0] == 'i':
        A.append(int(s[7:]))
        fp += 1
    elif s[6] == ' ':
        try:
            i = A[::-1].index(int(s[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif s[6] == 'F':
        A.pop()
        fp -=1
    elif s[6] == 'L':
        bp +=1
    n -=1

for e in A[bp:fp+1][::-1]:
    print int(e),

Measured memory_bytes: 40328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

const int mod = 1000*1000*1000 + 7;
vector<int> fact(200005), ifact(200005);

int mod_expo(int a, int x)
{
    int res = 1;
    while(x)
    {
        if(x&1)
            res *= a, res %= mod;
        a *= a, a %= mod;
        x /= 2;
    }
    return res;
}

int mod_inv(int a) { return mod_expo(a, mod-2); }

int solveEmptyGrid(int n, int m) { return (fact[n+m]*((ifact[n]*ifact[m])%mod))%mod; }

int32_t main()
{
    fact[0] = ifact[0] = 1;
    for(int i = 1; i < 200005; i++)
        fact[i] = (fact[i-1]*i)%mod, ifact[i] = mod_inv(fact[i]);
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<pair<int,int>> v;
    int h, w, n;
    cin >> h >> w >> n;
    for(int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        v.pb({x, y});
    }
    v.pb({h, w});
    sort(v.begin(), v.end());
    map<pair<int,int>, int> dp;
    for(int i = 0; i < sz(v); i++)
    {
        int ways = solveEmptyGrid(v[i].first-1, v[i].second-1);
        for(int j = 0; j < i; j++)
            if(v[j].first <= v[i].first && v[j].second <= v[i].second)
                ways -= (dp[v[j]]*solveEmptyGrid(v[i].first-v[j].first, v[i].second-v[j].second))%mod, ways += mod, ways %= mod; 
        dp[v[i]] = ways;
    }
    cout << dp[{h, w}] << endl;
}

Measured memory_bytes: 6636
#include <stdio.h>
#include <stdlib.h>
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
int main(){
  int i,n,a[200009];
  long long ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",a+i);
  qsort(a,n,4,dn);
  for(i=1;i<n;i++)ans+=a[i/2];
  printf("%lld",ans);
}

Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int[] B = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int[] C = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int ans = 0;

            //料理Bの満足度は全て反映されるので最初に足しておく
            ans += B.Sum();

            //Aのオーダーで順番が連続しているときのみ、ボーナスが追加される
            for (int i = 0; i < A.Length - 1; i++) {
                if (A[i] + 1 == A[i + 1]) {
                    ans += C[A[i] - 1];
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
<?php
fscanf(STDIN, "%d%d%d", $N, $M, $Q);
for($i = 0; $i <= $N; $i++){
  for($j = 0; $j <= $N; $j++){
    $map[$i][$j] = 0;
  }
}
for($i = 0; $i < $M; $i++){
  fscanf(STDIN, "%d%d", $L, $R);
  $map[$L][$R] += 1;
}
for($i = 1; $i <= $N; $i++){
  for($j = 1; $j <= $N; $j++){
    $map[$i][$j] = $map[$i][$j] + @$map[$i][$j-1];
  }
}
for($i = 1; $i <= $Q; $i++){
  fscanf(STDIN, "%d%d", $L, $R);
  if(!isset($q[$L][$R])){
    $sum = 0;
    for($j = $L; $j <= $R; $j++){
      $sum += $map[$j][$R] - @$map[$j][$L-1];
    }
    $q[$L][$R] = $sum;
  }
  echo $q[$L][$R],"\n";
}


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

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,max;
	int count[N_MAX];
	bool so[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		so[i]=true;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	so[0]=so[1]=0;
	for(i=2;i<=1000;i++){
		if(so[i]==0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=false;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  ll n;
  cin >> n;

  vl h(n);
  REP(i,n) cin >> h[i];
  vl t(n);
  REP(i,n) t[i] = -h[i]-i;

  ll ans = 0;
  map<ll,ll> mp;
  REP(i,n){
    ll iv = h[i]-i;
    if(mp.find(iv) != mp.end()){
      ans += mp[iv];
    }
    ll tv = -h[i]-i;
    if(mp.find(tv) != mp.end()){
      mp[tv] += 1;
    }else{
      mp.insert({tv,1});
    }
  }

  
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int s;
  double x;
    cin>>s;
    for(int i=s;i>=1;i--){
        x=log(i)/log(2);
        if(x-int(x)==0){
            cout<<i;
            break;
        }
    }

}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N/1000 == N%1000/100 && N%1000/100 == N%100/10){
    cout << "Yes" << endl;
  }
  else if(N%1000/100 == N%100/10 && N%100/10 == N%10){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# n = int(input())
n, k, q = map(int, input().split())
point_list = [k-q]*n

for i in range(q):
  winner = int(input())
  point_list[winner-1] += 1


for i in point_list:
  if i > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 6596
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int ctr[100010];
	memset(ctr,0,sizeof(ctr));
	int ntr;
	int m=-1;
	for(int i=0;i<n;i++){
		scanf("%d",&ntr);
		m=max(m,ntr);
		ctr[ntr]++;
	}
	int mx=0;
	for(int i=0;i<=m;i++){
		mx=max(mx,ctr[i]+ctr[i+1]+ctr[i+2]);
	}
	cout << mx << endl;
	return 0;
}

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

vector<string> rotate(vector<string> &v){
    int w = v[0].size(), h = v.size();
    vector<string> r(w);
    REP(i,w) r[i].resize(h);
    REP(y,h) REP(x,w) r[x][h-y-1] = v[y][x];
    return r;
}

int main(){
    vector<string> v(8);
    REP(i,8) cin >> v[i];
    FROMTO(i,1,4){
        cout << 90*i << endl;
        v = rotate(v);
        REP(j,v.size()) cout << v[j] << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)



int main()
{
	ll n, m;
	cin >> n >> m;
	vector<ll> a(m);
	rep(i, m) cin >> a[i];
	vector<ll> b(n + 100,-1);
	b[0] = b[1] = 1;
	for (ll i = 0; i < m ; i++)
	{
		b[a[i]] = 0;
	}
	
	for (ll i = 2; i < n + 5; i++)
	{
		if (b[i] != 0)
		{
			b[i] = b[i - 1] + b[i - 2];
		}
		b[i] = b[i] % 1000000007;
	}


	cout << b[n] << "\n";
	return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef unsigned long long ULL;

#define MP make_pair
#define PB push_back
#define EB emplace_back
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
#define f first
#define s second
#define FILL(a, b) memset(a, b, sizeof(a))

 
void dout() { cerr << endl; }
 
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}	

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	vector<vector<PII>> g(n);
	for (int i = 0; i < m; ++i)
	{
		int l, r, c;
		cin >> l >> r >> c;
		--l, --r;
		g[l].EB(r, c);
		g[r].EB(l, c);
	}

	for (int i = 1; i < n; ++i)
	{
		g[i].EB(i - 1, 0);
	}
	vector<LL> dist(n, 1e18);
	dist[0] = 0;
	set<PLL> st;
	st.insert({dist[0], 0});
	while(!st.empty())
	{
		auto [d, v] = *st.begin();
		st.erase(st.begin());
		for (auto [to, w] : g[v])
		{
			if (dist[to] > dist[v] + w)
			{
				auto it = st.find({dist[to], to});
				if (it != st.end())
				{
					st.erase(it);
				}
				dist[to] = dist[v] + w;
				st.insert({dist[to], to});
			}
		}
	}

	if (dist[n - 1] > (LL)1e18 - 7)
	{
		cout << -1 << "\n";
	}
	else
	{
		cout << dist[n - 1] << "\n";
	}

	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	n *= 3;
	multiset<int> S;
	FOR (i, 0, n)
	{
		int x;
		scanf("%d", &x);

		S.insert(x);
	}

	LL res = 0;

	while(SZ(S) >= 3)
	{
		int x = *S.begin();
		S.erase(S.find(x));

		int y = *S.rbegin();
		S.erase(S.find(y));

		int z = *S.rbegin();
		S.erase(S.find(z));

		res += z;
	}

	cout<<res<<endl;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}



int main(){

  ll a,b,n;
  cin >> a >> b >> n;

  ll x = b-1;
  if(x > n)x = n;
  ll ans = (a*x)/b - (x/b)*a;

  cout << ans << endl;



}


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

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

signed main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
#define mn -
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define NEG(i,a,b) for (int i = b; i >= a; i--)
/**  '' "\n" ^ - **/
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
int five=5;
int six=6;
int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n;
    sf(n);
    int k;
    sf(k);
    int x,count=0;
    in(i,n)
    {
        sf(x);
        if(x>=k)count++;
    }
    pf(count);
}


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

using namespace std;

int main(){
    int a[4];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<< a[0];
    for(int i=1;i<3;i++)cout<<" "<<a[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 1176
n,a=map(int,input().split())
l=[int(i) for i in input().split()]
ans=0
#dp=[[[0 for i in range(51)] for j in range(51)] for k in range(2501)]
dp=[[[0 for i in range(2501)] for j in range(51)] for k in range(51)]
dp[0][0][0]=1

for i in range(n):
    for j in range(50):
        for k in range(2501):
            if dp[i][j][k]:
                dp[i+1][j][k]+=dp[i][j][k]
                dp[i+1][j+1][k+l[i]]+=dp[i][j][k]
for i in range(1,n+1):
    ans+=dp[n][i][i*a]
print(ans)

Measured memory_bytes: 95580
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	int n;
	int d[1500];
	int e[1500];
	
	while (scanf("%d", &n) && n){
		
		memset(d, -1, sizeof(d));
		for (int i = 0; i < n; i++){
			scanf("%d", &d[i]);
		}
		
		int ct = 0;
		while (ct <= 10000){
			bool flag = true;
			for (int i = 0; i < 1500; i++){
				if (~d[i] && d[i] != i + 1){
					flag = false;
					break;
				}
			}
			
			if (flag == true){
				printf("%d\n", ct);
				goto end;
			}
			
			int nxt = 0;
			for (int i = 0; i < 1500; i++){
				if (~d[i]){
					d[i]--;
					nxt++;
				}
			}
			
			int idx = 0;
			int ok = 1;
			memset(e, -1, sizeof(e));
			for (int i = 0; i < 1500; i++){
				if (d[i] > 0){
					e[idx++] = d[i];
					ok = 1;
				}
				else if (d[i] == 0){
					ok = 0;
				}
			}
			e[idx] = nxt;
			
			for (int i = 0; i < 1500; i++){
				d[i] = e[i];
			}
			ct++;
		}
		
		printf("-1\n");
		end:;
	}
	
	return (0);
}

Measured memory_bytes: 1052
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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 (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(), a.end(), greater<>());
    vector<ll> b;
    b.push_back(a[0]);
    for (int i = 1; i < n; ++i) {
        b.push_back(a[i]); b.push_back(a[i]);
    }
    ll ans = 0;
    rep(i,n-1) ans += b[i];
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 9024
#include <iostream>
#include <vector>
#include <stdio.h>
#define FOR(i,k,n) for((i)=(k);(i)<(n);(i)++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define pb push_back
#define all(a) (a).begin(),(a).end()
using namespace std;

int main(){
	int n,q,s,temp,i,j;
	int count=0;
	vector<int> S;
	cin>>n;
	REP(i,n){
		cin>>s;
		//S.push_back(s);
		S.pb(s);
	}
	
	//sort(S.begin(),S.end());
	//sort(all(S));

	//REP(i,n){
		//FOR(j,i+1,n){
			//if(S[i]==S[j])S[i]=-1;
			//else if(S[i]<S[j])break;
		//}
	//}

	cin>>q;
	REP(i,q){
		cin>>temp;
		REP(j,n){
			if(temp==S[j]){
				count++;
				break;}
		}
	}
	cout<<count<<endl;
	return 0;
}

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

typedef long long ll;


ll calc(ll r, ll m)
{
    r = r % m;
    if (r < m / 2) return 0;
    return (r - m / 2 + 1) & 1;
}
ll f(ll r)
{
    ll res = (((r + 1) / 2) & 1);
    for (int i = 1; i < 50; ++i)
        res ^= (1LL << i) * calc(r, 1LL << (i + 1));
    return res;
}

int main()
{
    ll l, r;
    scanf("%lld%lld", &l, &r);
    printf("%lld", f(r) ^ f(l) ^ l);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n,m,sum;
  cin>>n>>m;
  vector<int> v(n);
  sum=0;
  for(int i=0;i<n;i++) {
    cin>>v[i];
    sum+=v[i];
  }
  int w=sum/(4*m);
  int rem=sum%(4*m);
  if(rem!=0) w++;
  int c=0;
  for(int i=0;i<n;i++)
		if(v[i]>=w) c++;
  if(c>=m) cout<<"Yes";
  else cout<<"No";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 400
#define N 40
#define INF 1000000
using namespace std;
int memo[MAX+1][MAX+1][N+1];
struct package
{
	int a, b, c;
	package(){}
	package(int a, int b, int c):a(a),b(b),c(c){}
};
package packages[N+1];
int dp(int a, int b, int i)
{
	if(a<0 || b<0) return INF;
	if(a==0 && b==0) return 0;
	if(i<=0) return INF;
	if(memo[a][b][i]!=-1) return memo[a][b][i];
	
	return memo[a][b][i] = min(dp(a,b,i-1),packages[i].c+dp(a-packages[i].a,b-packages[i].b,i-1));
}
int main()
{
	ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);

	memset(memo,-1,sizeof memo);

	int n, Ma, Mb; cin >> n >> Ma >> Mb;
	for(int i = 1; i <= n; i++)
	{
		int a, b, c; cin >> a >> b >> c;
		packages[i] = package(a,b,c);
	}
	int best = INF;
	for(int k = 1; k <= 40; k++)
		best = min(best,dp(Ma*k,Mb*k,n));
	cout<<(best>=INF ? -1 : best)<<endl;

	return 0;
}

Measured memory_bytes: 25984
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  tmp = input[0].split(" ");
  //文字列から10進数に変換するときはparseIntを使います
  var x = parseInt(tmp[0], 10);
  var a = parseInt(tmp[1], 10);

  if (x < a) {
    console.log('0');
  } else {
    console.log('10');
  }

  //出力
  // console.log('%d %s', b, c);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 20936
X,Y = map(int,raw_input().split())
if((X >= 1)and(X <= 205))and((Y >= 1)and(Y <= 205)):
    if(X == 1)and(Y == 1): print("1000000")
    elif((X == 1)and(Y == 2))or((Y == 1)and(X == 2)): print("500000")
    elif((X == 1)and(Y == 3))or((Y == 1)and(X == 3))or((X == 2)and(Y == 2)): print("400000")
    elif((X == 2)and(Y == 3))or((X == 1)and(Y > 3))or((Y == 1)and(X > 3))or((X == 3)and(Y == 2)): print("300000")
    elif((X == 3)and(Y == 3))or((X == 2)and(Y > 3))or((Y == 2)and(X > 3)): print("200000")
    elif((X == 3)and(Y > 3))or((Y == 3)and(X > 3)): print("100000")
    elif(X > 3)and(Y > 3): print("0")

Measured memory_bytes: 2696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOPSIC2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ABCK = Console.ReadLine().Split(' ');
            long A = long.Parse(ABCK[0]);
            long B = long.Parse(ABCK[1]);
            long C = long.Parse(ABCK[2]);
            long K = long.Parse(ABCK[3]);

            long ans = 0;

            if (A <= K)
            {
                ans += A;

                if (A + B <= K)
                {
                    ans -= K - A - B;
                }
            }
            else
            {
                ans = K;
            }

            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;
using ll=long long;

void solve() {
    int n; cin >> n;
    ll res = 0;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        res += cnt[i-x];
        cnt[i+x]++;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 20572
from functools import reduce

def gcd(x, y):
    if x < y:
        x, y = y, x
    if x%y == 0:
        return y
    else:
        return gcd(y, x%y)

n, x = map(int, input().split())
s = list(map(int, input().split()))
s.append(x)
s.sort()
S = []

for i in range(n):
    S.append(abs(s[i]-s[i+1]))

MAX = reduce(gcd, S)

print(MAX)

Measured memory_bytes: 14596
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    string S;
    cin >> S;
    rep2(i, 1, S.size())
    {
        if ((S.size() - i) % 2 == 0)
        {
            string before;
            rep(j, (S.size() - i) / 2)
            {
                before.push_back(S[j]);
            }
            string after;
            rep2(l, (S.size() - i) / 2, (S.size() - i))
            {
                after.push_back(S[l]);
            }
            if (before == after)
            {
                cout << before.size() * 2 << endl;
                return 0;
            }
        }
    }
}


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

int main(void){
  int n;
  int sum = 0;
  double ave = 0;
  
  cin >> n;
  
  int X[n];
  for(int i = 0; i < n; ++i){
    cin >> X[i];
    sum += X[i];
  }
  
  ave = (double)sum / (double)n;
  
  int intave = round(ave);
  
  int sumave = 0;
  
  for(int j = 0; j < n; ++j){
    sumave += (X[j] - intave) * (X[j] - intave);
  }
  
  cout << sumave << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  long long N;
  cin >> N;
  long long ans = 0;
  ans += N / 500 * 1000;
  N %= 500;
  ans += N / 5 * 5;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	a[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int dp[n+1]={0};
	for(int i=2;i<=n;i++)
	{
		int temp=INT_MAX;
		for(int j=1;j<=k;j++)
		{
			if((i-j)>=1)
			temp=min(temp,dp[i-j]+abs(a[i]-a[i-j]));
			else
			break;
		}
		dp[i]=temp;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024