akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  bool c = true;
  if(s.at(a)!='-'){
    c=false;
  }
  rep(i,a+b+1){
    if(i==a) continue;
    if(s.at(i)=='-'){
      c = false;
    }
  }
  if(c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

#define int long long
#define INF ((int)1e18)
#define MOD ((int)(1e9) + 7)

string a, b;
vector<pair<string, string> > t;

int solve(string x){
  int mi = INF;

  if(x == b) return 0;
  if(x.size() > b.size()) return INF;
  
  for(int i = 0; i < t.size(); i++){
    string w;
    int f = 0;
    bool flag2 = false;
    for(int j = 0; j < x.size(); j++){
      bool flag = true;
      if(j >= x.size() - t[i].second.size() + 1){
	string temp = x;
	w += temp.erase(0, j);
	break;
      }
      for(; f < j + t[i].second.size() && f < x.size(); f++){
      }
      
      for(int k = 0; k < t[i].second.size(); k++){
	if(t[i].second[k] != x[j+k]){
	  flag = false;
	  break;
	}
      }
      if(flag){
	flag2 = true;
	w += t[i].first;
	j += t[i].second.size() - 1;
      } else {
	w += x[j];
      }
    }

    if(flag2){
	mi = min(mi, solve(w) + 1);
    }
  }
  return mi;
}
signed main(){
  
  while(true){
    int n;
    t.clear();

    cin>>n;

    if(!n) break;

    t.resize(n);
    
    for(int i = 0; i < n; i++){
      cin>>t[i].second>>t[i].first;
    }
    
    cin>>a>>b;

    int temp = solve(a);

    cout<<(temp == INF ? -1 : temp)<<endl;
  }
}




Measured memory_bytes: 3088
#include <stdio.h>


bool withInRectangle(int W, int H, int x, int y, int r) {
  return (x-r >= 0 && x+r <= W &&
          y-r >= 0 && y+r <= H);
}



int main()
{
  int W, H, x, y, r;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
  
  if (withInRectangle(W, H, x, y, r))
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}



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

int gcd(long long a, long long b) {
  int tmp;
  while ( a%b != 0 ) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  long long a[n];
  long long t;
  cin >> a[0];
  a[0] /= 2;
  t = a[0];
  for ( int i = 1; i < n; i++ ) {
    cin >> a[i];
    a[i] /= 2;
    t = lcm(t, a[i]);
  }

  long long ans = m/(2*t) + (m/t)%2;
  for ( int i = 0; i < n; i++ ) {
    if ( (t/a[i])%2 == 0 ) { ans = 0; break; }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
int k;
  cin >>k;
  cout <<(k/2)*((k+1)/2);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e5+5;
const long long inf=0x3f3f3f3f;
const long long mod=1e9+7;
long long quick_pow(long long a,long long b)
{
	return b?quick_pow(a*a%mod,b/2)*(b%2?a:1)%mod:1;
}
long long k;
string s;
long long fac[2<<20],inv[2<<20];
long long comb(long long x,long long y)
{
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long k;
	cin>>k>>s;
	long long t=k+s.size();
	fac[0]=1;
	for(long long i=1;i<=t;i++)
		fac[i]=fac[i-1]*i%mod;
	inv[t]=quick_pow(fac[t],mod-2);
	for(long long i=t;i--;)
		inv[i]=inv[i+1]*(i+1)%mod;
	long long ans=0;
	for(long long i=s.size();i<=k+s.size();i++)
		ans+=comb(t,i)*quick_pow(25,t-i)%mod;
	cout<<ans%mod<<endl;
	return 0;
}




Measured memory_bytes: 35572
import java.awt.Rectangle;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static Rectangle[] rec = new Rectangle[26];
	static boolean[] check = new boolean[26];
	
	public static void main(String[] args) {
		int n;
		n = sc.nextInt();	// input
		while(n-- > 0) {
			for(int i=0; i < 26; i++) {	// initialize
				rec[i] = new Rectangle();
				rec[i].x = rec[i].y = 50;
				rec[i].width = rec[i].height = 0;
				check[i] = false;
			}
			int h, w, cnt = 0;
			h = sc.nextInt();	// input
			w = sc.nextInt();	// input
			int map[][] = new int[h][w];
			for(int y=0; y < h; y++) {
				String str = sc.next();
				for(int x=0; x < w; x++) {
					map[y][x] = (int)str.charAt(x); // input
					if(map[y][x] == '.') continue;
					int idx = map[y][x] - 'A';
					if(rec[idx].x > x) rec[idx].x = x;				// start
					if(rec[idx].y > y) rec[idx].y = y;				// start
					if(rec[idx].width < x) rec[idx].width = x;		// end
					if(rec[idx].height < h) rec[idx].height = y;	// end
					check[idx] = true;
				}
			}
			for(int i=0; i < 26; i++) if(check[i]) cnt++;
			boolean flg = true;
			while(flg) {
				flg = false;
				for(int i=0; i < 26; i++) {
					if(check[i]){
						int mozi = 'A' + i;
						boolean success = true;
						for(int y=rec[i].y; y <= rec[i].height && success; y++)
							for(int x=rec[i].x; x <= rec[i].width && success; x++){
								if(map[y][x] != mozi && map[y][x] != -1) {
									success = false;
								}
							}
						if(success){
							for(int y=rec[i].y; y <= rec[i].height; y++)
								for(int x=rec[i].x; x <= rec[i].width; x++){
									map[y][x] = -1;
								}
							flg = true;
							check[i] = false;
							cnt--;
						}
					}
				}
			}
			if(cnt == 0)
				System.out.println("SAFE");
			else
				System.out.println("SUSPICIOUS");
		}
	}
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<ll> a(n + 1);
	vector<ll> b(n);
	for (int i = 0; i < n + 1; i++)
	{
		cin >> a.at(i);
	}

	for (int i = 0; i < n; i++)
	{
		cin >> b.at(i);
	}

	ull sum = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			if (i + j <= n)
			{
				if (a.at(i + j) >= b.at(i))
				{
					sum += b.at(i);
					a.at(i + j) -= b.at(i);
					b.at(i) = 0;
				}
				else
				{
					sum += a.at(i + j);
					b.at(i) -= a.at(i + j);
					a.at(i + j) = 0;
				}
			}
		}
		
	}

	cout << sum << endl;
}

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


int main()
{
  ll n,x;
  cin >> n >> x;
  vector<ll> a(n+1);
  for(ll i = 0;i < n;i++){
    cin >> a[i];
  }
  a[n] = x;
  sort(a.begin(),a.end());
  vector<ll> l(n);
  ll min_i = 10000000000;
  for(ll i = 0;i < n;i++){
    l[i] = a[i+1] - a[i];
    min_i = min(min_i,l[i]);
  }
  bool flag = 1;
  ll max = 1;
  for(ll i = min_i;i >= 1;i--){
    flag = 1;
    for(ll j = 0;j < n;j++){
      if(l[j]%i != 0) flag = 0;
    }
    if(flag){
      max = i;
      i = 0;
    }
  }
  cout << max << endl;
  return 0;

}


Measured memory_bytes: 1792
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	//iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return;
		int going[100000] = {};
		REP(i, n) {
			vector<int> go;
			REP(q, 2) {
				int a, b, c;
				scanf("%lld:%lld:%lld", &a, &b, &c);
				go.push_back(a * 3600 + b * 60 + c);
			}
			going[go[0]]++;
			going[go[1]]--;
		}
		int ans = 0;
		for (int i = 0; i < 100000 - 1; ++i) {
			ans = max(ans, going[i]);
			going[i + 1] += going[i];
		}
		cout << ans << endl;
	}
}
#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3944
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

char to_Num(char in) {
	if(in == 'a' || in == 'b' || in == 'c')
		return '2';
	if(in == 'd' || in == 'e' || in == 'f')
		return '3';
	if(in == 'g' || in == 'h' || in == 'i')
		return '4';
	if(in == 'j' || in == 'k' || in == 'l')
		return '5';
	if(in == 'm' || in == 'n' || in == 'o')
		return '6';
	if(in == 'p' || in == 'q' || in == 'r' || in == 's')
		return '7';
	if(in == 't' || in == 'u' || in == 'v')
		return '8';
	if(in == 'w' || in == 'x' || in == 'y' || in == 'z')
		return '9';
	return -1;
}

vector< vector<string> > ans;
multimap<string, string> dic;
string in;

void dfs(int s, int cnt, vector<string> v) {
	if(s+cnt > in.size())
		return;
	dfs(s, cnt+1, v);
	if(dic.count(in.substr(s, cnt))) {
		auto range = dic.equal_range(in.substr(s, cnt));
		for(auto it = range.first; it != range.second; it++) {
			vector<string> v2(v);
			v2.pb(it->second);
			if(s+cnt == in.size())
				ans.pb(v2);
			else
				dfs(s+cnt, 1, v2);
		}
	}
}

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

	int n;
	while(cin >> n, n) {
		ans.clear(); dic.clear();
		REP(i, n) {
			cin >> in;
			string s;
			REP(j, in.size())
				s += to_Num(in[j]);
			dic.insert(mp(s, in));
		}

		cin >> in;
		dfs(0, 1, vector<string>());

		REP(i, ans.size()) {
			bool flg = false;
			REP(j, ans[i].size()) {
				if(flg) cout << ' ';
				flg = true;
				cout << ans[i][j];
			}
			cout << '.' << endl;
		}
		cout << "--" << endl;
	}
	return 0;
}

Measured memory_bytes: 3344
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define T tuple<int, int, int, int>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int H, W;
    cin >> H >> W;

    int a[H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> a[i][j];
        }
    }

    int N = 0;
    vector<T> move;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int y = i;
            int x = i % 2 == 0 ? j : W - 1 - j;
            int dx = i % 2 == 0 ? 1 : -1;

            if (j == W - 1) {
                if (i == H - 1) continue;

                if (a[y][x] % 2 == 1) {
                    a[y][x]--;
                    a[y + 1][x]++;
                    N++;
                    move.push_back(make_tuple(y+1, x+1, y+2, x+1));
                }
            } else {
                if (a[y][x] % 2 == 1) {
                    a[y][x]--;
                    a[y][x + dx]++;
                    N++;
                    move.push_back(make_tuple(y+1, x+1, y+1, x+dx+1));
                }
            }
        }
    }

    cout << N << endl;
    for (int i = 0; i < N; i++) {
        T t = move[i];
        cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << " " << get<3>(t) << endl;
    }
    

    return 0;
}

Measured memory_bytes: 5104
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う

int main(){
  const int S = 3 ;
  string eat;
  int i,A;
  cin >> eat ;
  
  A=0;
  for(i=0;i<=3;i++){
   if(eat[i] == '+'){
   	A++;
   }
   else{
   	A--;
   }
  }

  cout << A << endl;
  
  return 0;
}



Measured memory_bytes: 256
//smtb2019_d.cpp
//Sun Dec  1 20:57:16 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;

	int code[1000];
	fill(code,code+1000,0);
	int left[10];
	fill(left,left+10,0);
	int right[10];
	fill(right,right+10,0);
	for (int i=0;i<s.length();i++){
		int temp = ctoi(s[i]);
		right[temp]++;
	}

	right[ctoi(s[0])]--;

	for (int i=1;i<s.length()-1;i++){
		int temp = ctoi(s[i]);
		left[ctoi(s[i-1])]++;
		right[temp]--;
		for (int j=0;j<10;j++){
			for (int k=0;k<10;k++){
				if (left[j] && right[k]){
//					cout << j*100+temp*10+k << endl;
					code[j*100+temp*10+k]++;
				}
			}
		}
	}

	int ans = 0;
	for (int i=0;i<1000;i++){
		if (code[i]){
//			cout << code[i] << endl;
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <math.h>
int main(void){
int A,B,C,X,x;

scanf("%d",&A);
scanf("%d",&B);
scanf("%d",&C);
scanf("%d",&X);
for (int a=0 ;a<=A ;a++) {
  for (int b=0 ;b<=B ;b++) {
    for (int c=0 ;c<=C ;c++) {
        int total = 500*a + 100*b + 50*c;
        if(total == X) x++;
	  }
  }
}
printf("%d\n", x);
return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long l[100];
int main()
{
    l[0]=2;
    l[1]=1;
    for(int i=2;i<100;i++)l[i]=l[i-1]+l[i-2];
    int n;
    cin>>n;
    cout<<l[n]<<endl;
return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

vector<lli> places[210000];
lli dp[210000];

void add(lli &a,lli b){a+=b; if(a>=MOD)a-=MOD;}

signed main(){

	lli N;cin>>N;

	vector<lli> c(N);
	REP(i,0,N)cin>>c[i];

	REP(i,0,210000)places[i].clear();
	REP(i,0,N)places[c[i]].push_back(i);

	dp[0]=1;

	for(lli i=1;i<=N;i++){
		//特に操作しない
		add(dp[i],dp[i-1]);

		//操作する
		lli color = c[i-1];
		lli it = lower_bound(places[color].begin(),places[color].end(),i-1)-places[color].begin();
		if(it>0){
			lli j = places[color][it-1];
			if((i-1)-j>1)add(dp[i],dp[j+1]);
		}
	}

	cout<<dp[N]<<endl;

	return 0;
}

Measured memory_bytes: 14592
import sys
from collections import deque

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))


def solve():
    h, w, k = nm()
    sy, sx, gy, gx = nm()
    d = [(0, 1), (1, 0), (-1, 0), (0, -1)]
    sx -= 1; sy -= 1
    gx -= 1; gy -= 1
    C = [ns() for _ in range(h)]
    G = [[10**7]*w for _ in range(h)]
    G[sy][sx] = 0
    q = deque([(sy, sx)])
    while q:
        y, x = q.popleft()
        for i in range(4):
            dy, dx = d[i]
            ny, nx = y, x
            for _ in range(k):
                ny += dy; nx += dx
                if ny < 0 or h <= ny or nx < 0 or w <= nx:
                    break
                if C[ny][nx] == '@' or G[ny][nx] <= G[y][x]:
                    break
                if G[ny][nx] > G[y][x] + 1:
                    G[ny][nx] = G[y][x] + 1
                    q.append((ny, nx))
                    if ny == gy and nx == gx:
                        print(G[y][x] + 1)
                        return
    print(-1)
    return

solve()


Measured memory_bytes: 36768
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_12_B: Single Source Shortest Path I

#include <algorithm>
#include <cstdio>

using uint = unsigned int;

class Graph {
  const uint n_;
  uint* const g_;
  const uint INFINIT;
  
public:

  Graph(uint n) : n_(n), g_(new uint[(n_*n_)]), INFINIT(100000*(n_-1)+1) {
    std::fill_n(g_, (n_*n_), INFINIT);
  }

  ~Graph() { delete[] g_; }
  
  uint* operator [](uint i) const { return g_+(n_*i); }

  void dijkstra(uint* dist)
  {
    std::fill_n(dist, n_, INFINIT);
    bool visited[n_];
    std::fill_n(visited, n_, false);
    auto i = 0u; // 0-start
    visited[i] = true;
    dist[i] = 0u;
    for (auto n = 0u; n < n_-1; ++n) {
      auto cur_min = INFINIT;
      auto es = (*this)[i];
      auto base_dist = dist[i];
      for (auto j = 0u; j < n_; ++j) {
        if (visited[j]) continue;
        dist[j] = std::min(dist[j], base_dist+es[j]);
        if (cur_min > dist[j]) {
          cur_min = dist[j];
          i = j;
        }
      }
      visited[i] = true;
      dist[i] = cur_min;
    }
  }
};

int main()
{
  uint n;
  std::scanf("%u", &n);

  Graph g(n);

  uint u, k, c, v;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u %u", &c, &v);
      g[u][c] = v;
    }
  }

  uint dist[n];
  g.dijkstra(dist);
  for (auto i = 0u; i < n; ++i) {
    std::printf("%u %u\n", i, dist[i]);
  }
}

// eof

Measured memory_bytes: 2744
#include<bits/stdc++.h>
#define N 3
using namespace std;
typedef unsigned long long ull;
bool im[1010][1010],pa[110][110];
int w,h,p,ans;
vector<ull> used;

void ppp(){
 ull a=0;
 ull roll[1001][1001]={};
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)a=a*N+pa[i][j];
 for(int i=0;i<used.size();i++)
   if(used[i]==a)return;
 used.push_back(a);
 for(int j=0;j<h;j++){
   ull b=0,g=1;
   for(int i=0;i<p;i++)b=b*N+im[j][i],g*=N;
   roll[j][p-1]=b;
   for(int i=p;i<w;i++){
     b=b*N+im[j][i]-im[j][i-p]*g;
     roll[j][i]=b;
   }
 }
 for(int j=p-1;j<w;j++){
   ull b=0,g=1,n=1;
   for(int i=0;i<p;i++)n*=N;
   for(int i=0;i<p;i++)b=b*n+roll[i][j],g*=n;
   if(b==a)ans++;
   for(int i=p;i<h;i++){
     b=b*n+roll[i][j]-roll[i-p][j]*g; 
     if(b==a)ans++;
   }
 }
}

void ch(){
 bool npa[110][110];
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)npa[i][j]=pa[j][p-i-1];
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)pa[i][j]=npa[i][j];
}

void ch1(){
 for(int i=0;i<p;i++)
   for(int j=0;j<p/2;j++)swap(pa[i][j],pa[i][p-j-1]);
}

int main(){
 int D[256];
 for(int i='A';i<='Z';i++)D[i]=i-'A';
 for(int i='a';i<='z';i++)D[i]=i-'a'+26;
 for(int i='0';i<='9';i++)D[i]=i-'0'+52;
 D['+']=62,D['/']=63;
 while(cin>>w>>h>>p,w){
   string s;
   used.clear();
   for(int i=0;i<h;i++){
     cin>>s;
     for(int j=0;j<s.size();j++){
       int t=D[s[j]],a=6;
	while(a--)im[i][j*6+a]=t%2,t/=2;
     }
   }
   for(int i=0;i<p;i++){
     cin>>s;
     for(int j=0;j<s.size();j++){
       int t=D[s[j]],a=6;
	while(a--)pa[i][j*6+a]=t%2,t/=2;
     }
   }
   ans=0;
    for(int i=0;i<4;i++){
     ppp();
     ch1();
     ppp();
     ch1();
     ch();
   }
   cout<<ans<<endl;
 }
 return 0;
}

Measured memory_bytes: 11928
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      if(i*j==n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define All(x) x.begin() , x.end()
#define mem(aa,x) memset(aa,x,sizeof aa)
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
const int maxn=4e5+5;

main(){
	ll x,y;
	int ans=0;
    cin>>x>>y;
    
    while(x<=y){
    	x*=2;
    	ans++;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy
print('R'*dx+'U'*dy+'L'*dx+'D'*(dy+1)+
      'R'*(dx+1)+'U'*(dy+1)+'LU'+'L'*(dx+1)+'D'*(dy+1)+'R')

Measured memory_bytes: 3316
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, map) for(auto it = m.begin(); it != m.end(); it++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll dig(ll a){
    ll ret = 0;
    while(a > 0){
        a /= 10; ret++;
    }
    return ret;
}

int main(){
    ll N; cin >> N;
    ll ret = LINF;
    for (ll i = 1; i * i <= N; i++) {
        if(N % i == 0){
            ll r = N / i; ll l = N / r;
            ll tmp = max(dig(l), dig(r));
            ret = min(ret, tmp);
        }
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    char s[201],f[201],b[201];
    int m,n;
    do{
        scanf("%s",&s);
        if (strcmp(s,"-")!=0){
            scanf("%d",&m);
            for (int i=0;i<m;i++){
                scanf("%d",&n);
                for (int j=0;j<n;j++){
                    f[j]=s[j];
                }
                f[n]='\0';
                int k=0;
                while(s[n+k]!='\0'){
                    b[k]=s[n+k];
                    k++;
                }
                b[k]='\0';
                strcpy(s,b);
                strcat(s,f);
            }
        printf("%s\n",s);
        }
    }while (strcmp(s,"-")!=0);
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0 ; i < 3 ; i ++ ){
    if(s[i] == '1'){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;

void Show(vector<vector<bool>> S) {
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < S[i].size(); j++) {
			if ((S[i][j])) {
				cout << '.';
			} else {
				cout << '#';
			}
		}
		cout << endl;
	}
}
int main() {
	int N, X;
	cin >> N >> X;
	vector<int> Ms;
	Ms.resize(N);
	int Sum = 0;
	int Smallest = X;
	for (int i = 0; i < N; i++) {
		cin >> Ms[i];
		Sum += Ms[i];
		Smallest = min(Smallest, Ms[i]);
	}
	cout << N + (X - Sum) / Smallest << endl;
}



Measured memory_bytes: 384
N, K = map(int,input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
dp = [[0]*3 for _ in range(N)]
for i in range(K):
    # dp[r, s, p]
    if T[i] == "r":
        dp[i][2] = P
        temp = P
    elif T[i] == "s":
        dp[i][0] = R
        temp = R
    else:
        dp[i][1] = S
        temp = S
    for j in range(i+K, N, K):
        if T[j] == "r":
            dp[j][2] = max(dp[j-K][0], dp[j-K][1]) + P
            dp[j][0] = max(dp[j-K][1], dp[j-K][2])
            dp[j][1] = max(dp[j-K][0], dp[j-K][2])
        elif T[j] == "s":
            dp[j][0] = max(dp[j-K][2], dp[j-K][1]) + R
            dp[j][1] = max(dp[j-K][2], dp[j-K][0])
            dp[j][2] = max(dp[j-K][0], dp[j-K][1])
        else:
            dp[j][1] =max(dp[j-K][0], dp[j-K][2]) + S
            dp[j][0] =max(dp[j-K][1], dp[j-K][2])
            dp[j][2] =max(dp[j-K][0], dp[j-K][1])
        temp = max(temp, dp[j][0], dp[j][1], dp[j][2])
    ans += temp
print(ans)

Measured memory_bytes: 16448
#include <iostream>

using namespace std;

int main(){
  long long N;
  long long ans=0;
  long long d=10;
  cin >> N;
  if(N%2==0){
    while(d<=N){
      ans+=N/d;
      d*=5;
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define upper(n,m) (n+m-1)/m
#define rounding(n) (int)((double)n+0.5)

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define ALL(a) a.begin(),a.end()

#define coutALL(i,a) {int i=0;for(int e:a) cout<<(i++?" ":"")<<e; cout<<endl;}
#define coutYN(a) cout<<(a?"Yes":"No")<<endl;
#define coutyn(a) cout<<(a?"yes":"no")<<endl;

#define deb cout<<"debug"<<endl
#define debn(n) cout<<"debug: "<<n<<endl

//#define int long long

const int INF=100000;
const int MOD=(int)1e9+7;
const int EPS=1e-12;
//const int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using namespace std;

typedef pair<int,int> P;
typedef long long LL;

const int MAX_V=2000;

void warshall(int v,int G[100][100]){
  for(int k=0;k<v;k++)
    for(int i=0;i<v;i++)
      for(int j=0;j<v;j++) G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
}

signed main(){

  ios::sync_with_stdio(false);

  int v,e;
  int e_list[100][100];
  int G[100][100];

  REP(i,100) fill(G[i],G[i]+100,INF),fill(e_list[i],e_list[i]+100,INF);

  cin>>v>>e;

  REP(i,e){

    int a,b,c;
    cin>>a>>b>>c; a--,b--;

    e_list[a][b]=c;
    G[a][b]=c;
    G[b][a]=c;

  }

  warshall(v,G);

  int r=0;

  REP(i,v)
    REP(j,v)
    if(e_list[i][j]!=INF)
      if(e_list[i][j]!=G[i][j])
	r++;

  cout<<r<<endl;

  return 0;

}

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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  // 各アルファベット (a, b, c, ...) が、S の何文字目に出現しているかを保持
  vector<set<int>> sets(26);
  for (int i = 0; i < N; i++) {
    int idx = S.at(i) - 'a';
    sets.at(idx).insert(i);
  }
  int Q; cin >> Q;
  for (int i = 0; i < Q; i++) {
    int com; cin >> com;
    if (com == 1) {
      int idx; cin >> idx; idx--;
      char c; cin >> c;
      sets.at(S.at(idx) - 'a').erase(idx);
      sets.at(c - 'a').insert(idx);
      S.at(idx) = c;
    }
    if (com == 2) {
      int left, right; cin >> left >> right;
      left--; right--;
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        // 各アルファベットが区間 [left, right] 内で出現するか
        auto iter = sets.at(i).lower_bound(left);
        if (iter != sets.at(i).end() && *iter <= right) cnt++;
      }
      cout << cnt << endl;
    }
  }
}

Measured memory_bytes: 24196
n = int(input())
s = list(input())
l = 0
for i in range(1,n-1):
  p = list(set(s[:i]))
  q = list(set(s[i:]))
  pq = set(p) & set(q)
  k = len(pq)
  if k>l:
    l=k
print(l)

Measured memory_bytes: 3060
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner ob=new Scanner(System.in);
        int n=ob.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=ob.nextInt();
        }
        int arr[]=new int[n];
        arr[0]=0;
        arr[1]=Math.abs(a[1]-a[0]);
        for(int i=2;i<n;i++){
            arr[i]=Math.min(arr[i-2]+Math.abs(a[i]-a[i-2]),arr[i-1]+Math.abs(a[i]-a[i-1]));
        }
        System.out.println(arr[n-1]);
        ob.close();
    }
}

Measured memory_bytes: 50780
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N; cin >> N;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	double sum = 0.0;
	rep(i,N){
		sum += 1.0/A[i];
	}
	double ans = 1.0/sum;
	cout << fixed;
	cout << setprecision(6) << ans << endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
int main(){
	//freopen("_inthesituationoflen.txt","r",stdin);
	long long a[3];
	int i = 0;
	while(scanf("%lld",&a[i])!=EOF){
		i++;
	}
	if(a[1]<a[2]){
		if(a[0] == 1){
			printf("0");
		}else{
			//long long tmp1 = a[1]+a[2];
			//long long tmp2 = tmp1;
			printf("%lld",(a[2]-a[1])*(a[0]-2)+1);
		}

	}else if(a[1] == a[2]){
		printf("1");
			
	}else{
		printf("0");
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int now=1,ans=0;
  for (int i=0;i<n;i++){
    if (a[i] == now) now++;
    else ans++;
  }
  cout << ((ans == n) ? -1 : ans) << endl;
}


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

const int SIZE = 1e6+1;
bool isprime[SIZE];
vector<ll> primes;
map<ll, ll> factors;
void make_primes(){
    for (int i = 0; i < SIZE; ++i)
        isprime[i] = true;
    isprime[0] = isprime[1] = false;
    for (int i = 2; i*i <= SIZE; ++i)
    {
        if (isprime[i]){
            int j = i+i;
            while (j < SIZE)
            {
                isprime[j] = false;
                j += i;
            }
        }
    }
    for (int i = 0; i < SIZE; i++)
        if (isprime[i])
            primes.push_back(i);
}

void prime_factorize(ll x){
    for (ll i : primes)
    {
        while (x % i == 0)
        {
            ++factors[i];
            x /= i;
        }
    }
    if (x != 1)
        ++factors[x];
}

void solve() {
   ll n;cin >> n;
   ll ans = 0;
   prime_factorize(n-1);
   ll x = 1;
   for (auto &&i : factors)
      x *= i.second+1;
   ans += x-1;
   factors.clear();
   prime_factorize(n);
   vector<ll> divisor;divisor.push_back(1);
   for (auto &&i : factors){
      ll x = 1;
      int size = divisor.size();
      rep(j,i.second){
         x *= i.first;
         rep(k,size){
            divisor.push_back(divisor[k]*x);
         }
      }
   }
   divisor.erase(divisor.begin());
   for (auto &&i : divisor){
      ll nc = n;
      while(nc>1 && nc%i==0)nc/=i;
      if(nc%i==1)ans++;
   }
   cout << ans << endl;
   
}
int main() {
   cin.tie(nullptr); ios::sync_with_stdio(false);
   make_primes();
   solve();
}

Measured memory_bytes: 5184
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<utility>
using namespace std;

int main(void)
{
    string S;
    cin >> S;

    long long K;
    cin >> K;

    vector<pair<char, int>> v;
    for (int i = 0; i < (int)S.size(); ) {
        int cnt = 1;
        for (int index = i + 1; index < (int)S.size() && S[i] == S[index]; index++) {
            cnt++;
        }
        v.push_back(make_pair(S[i], cnt));
        i += cnt;
    }

    //for (int i = 0; i < (int)v.size(); i++)
    //    cout << v[i].first << " " << v[i].second << endl;

    if (v.size() == 1) {
        long long ans = v[0].second * K;
        cout << ans / 2 << endl;

        return 0;
    }

    long long ans = 0;
    if (v.front().first == v.back().first) {
        for (int i = 0; i < (int)v.size(); i++) {
            if (i == 0 || i == (int)v.size() - 1)
                ans += v[i].second / 2;
            else
                ans += v[i].second / 2 * K;
        }

        int sum = v.front().second + v.back().second;
        ans += sum / 2 * (K - 1);
    }
    else {
        for (int i = 0; i < (int)v.size(); i++) {
            ans += v[i].second / 2 * K;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>

#include <algorithm>
#include <functional>
using namespace std;


int main(){
  int num;
  cin >> num;

  vector<int> vec(num);
  for (int i=0; i<num; i++ ){
    cin >> vec[i];
  }
  
  std::sort(vec.begin(),vec.end());//昇順ソート

　int middle = num/2;
  int count=0;
  if(vec[middle-1] == vec[middle]){
    cout << 0;
  }else{
    for(int j =vec[middle-1] ; j < vec[middle] ; j++){
         count++;
      }
    cout << count;

  }
  return 0;
}


Measured memory_bytes: 640
import cmath
import math

P = []
try:
    while True:
        # print("Hello!")
        x, y = map(float,input().split(","))
        P.append(complex(x,y))  
except  EOFError:
    pass

# def dot_product(a,b):
#     return (a.conjugate()*b).real
def cross_product(a,b):
    return (a.conjugate()*b).imag

N = len(P)
total = 0.0
for i in range(1,N-1):
    a, b, c = P[0], P[i], P[i+1]
    total += 0.5 * (cross_product(P[i]-P[0], P[i+1]-P[0]))

print("%.6f" % (abs(total)))


Measured memory_bytes: 5684
N = int(input())
stones = str(input())

mae = 0
ushiro = N - 1

swap = 0

while mae < ushiro:
    if stones[mae] == "W":
        while mae < ushiro:
            if stones[ushiro] == "R":
                swap += 1
                ushiro -= 1
                break
            else:
                ushiro -= 1
                
        else:
            break
        mae += 1
        
    else:
        mae += 1
        
print(swap)



Measured memory_bytes: 9464
#include<stdio.h>
int map[11][11];
int dx[12]={1,0,-1,0,1,1,-1,-1,0,2,0,-2};
int dy[12]={0,1,0,-1,1,-1,1,-1,2,0,-2,0};
void paint_map(int x,int y,int size){
  int n=size*4;
  int i;
  map[x][y]++;
  for(i=0;i<n;i++){
    if(x+dx[i]<0 || x+dx[i]>9 || y+dy[i]<0 || y+dy[i]>9) continue;
    map[x+dx[i]][y+dy[i]]++;
  }
}
main(){
  int x,y,size;
  int i,j;
  int max=0,count=0;
  while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
    paint_map(x,y,size);
  }
  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      if(map[i][j]==0)count++;
      if(map[i][j]>max)	max=map[i][j];
    }
  }
  printf("%d\n%d\n",count,max);
  return 0;
}

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

main() {
    int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k) cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 100

void push(int);
int pop();

int S[MAX];
int top=0;
int main(){
  int i=0,vb,vd,vc,x,y,t,result;
  char a[MAX];

  while(result!=EOF){
    result=scanf("%s",a);
    
    if(a[0]=='+'||a[0]=='-'||a[0]=='*'){
      y= pop();
      x= pop();
      if(a[0]=='+'){
	
	push(x+y);
      }
      else if(a[0]=='-'){
	
	push(x-y);
      }
      else{
	
	push(x*y);
      }
    }
    else{
      
      push(atoi(a));
   
    }
  }
  printf("%d\n",S[1]);

  return 0;
}


void push(int x){
 
  top++;
  S[top]=x;
  
}
int pop(){
 
  top--;
  return S[top+1];
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
string s;

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


	cin >> s;
	if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R'){
		cout << 3 << endl;
		return 0;
	}

	if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')){
		cout << 2 << endl; 
		return 0;
	}

	if(s[0] == 'S' && s[1] == 'S' && s[2] == 'S'){
		cout << 0 << endl;
		return 0;
	}

	cout << 1 << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b >= a - b && a + b >= a * b) {
        cout << a + b << endl;
    }
    else if (a - b >= a + b && a - b >= a * b) {
        cout << a - b << endl;
    }
    else if (a * b >= a + b && a * b >= a - b) {
        cout << a * b << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
package main

import (
	"fmt"
	"sort"
)

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func main() {
	var alice, bob, N int
	fmt.Scan(&N)
	nums := scanNums(N)
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))

	for i, num := range nums {
		if i % 2 == 0 {
			alice += num
		} else {
			bob += num
		}
	}

	fmt.Println(alice - bob)
}

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


int main() {
  int k, s;
  cin >> k >> s;
  int count = 0;
  rep(x,k+1){
    rep(y,k+1){
      int z = s-x-y;
        if(0 <=z && z <=k) ++count;
      
    }
  }
  cout << count << endl;
  return 0;
}

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

int main() {
	int n;
	std::cin >> n;

	std::vector<int> ans(n);
	for (int i = 0; i < n - 1; ++i) {
		int a;
		std::cin >> a;

		++ans[a - 1];
	}

	for (auto&& e : ans)
		std::cout << e << std::endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int ans=0, last=0;
  for(int i=0;i<5;i++){
    int x;cin>>x;
    int t=(x/10)*10+(x%10!=0)*10;
    last = max(last, t-x);
    ans+=t;
  }
  cout << ans - last << endl;
}


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

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

    long long int n, k;
    cin >> n >> k;
    
    if (n % k != 0) {
        if (n > k) {
            n = n % k;
        }
        while (abs(n-k) < n) {
            n = abs(n-k);
        }
        cout << n << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 4999999999999999999
#define ALL(n) n.begin(),n.end()

ll a, b, c, d, e;
vector<ll> s;
int main(){
	cin >> a >> b >> c >> d >> e;
	for (int i = 0; i <= max(d, e) * 2;i += 2) {
		ll n = 0;
		if (d > i / 2)n += (d - i / 2) * a;
		if (e > i / 2)n += (e - i / 2) * b;
		n += c * i;
		s.push_back(n);
	}
	sort(ALL(s));
	cout << s[0] << endl;	
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstring>
using namespace std;
int m[9][9][2];
int main()
{
  int n,i,j,k,l;
  bool f = false;
  cin >> n;
  while(n--){
    memset(m,0,sizeof(m));
    if(f) cout << endl;
    for(i=0;i<9;i++){
      for(j=0;j<9;j++){
	cin >> k;
	m[i][j][0] = k;
	for(k=0;k<i;k++){
	  if(m[i][j][0] == m[k][j][0]){
	    m[i][j][1] = 1;
	    m[k][j][1] = 1;
	  }
	}
	for(k=0;k<j;k++){
	  if(m[i][j][0] == m[i][k][0]){
	    m[i][j][1] = 1;
	    m[i][k][1] = 1;
	  }
	}
	for(k=(i/3)*3; k<=i; k++){
	  for(l=(j/3)*3; l<((k==i) ? j:((j/3)*3+3)); l++){
	    if(m[i][j][0] == m[k][l][0]){
	      m[i][j][1] = 1;
	      m[k][l][1] = 1;
	    }
	  }
	}
      }
    }
    for(i=0;i<9;i++){
      for(j=0;j<9;j++){
	if(m[i][j][1] == 1) cout << "*";
	else cout << " ";
	cout << m[i][j][0];
      }
      cout << endl;
    }
    f = true;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

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

  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for (int i=0; i<n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<vector<int>> dp(n, vector<int>(3));

  dp[0] = vector<int>{a[0], b[0], c[0]};
  for (int i=1; i<n; ++i) {
    dp[i] = vector<int>{
      a[i] + max(dp[i-1][1], dp[i-1][2]),
      b[i] + max(dp[i-1][0], dp[i-1][2]),
      c[i] + max(dp[i-1][0], dp[i-1][1])
    };
    // for (auto& num : dp[i]) {
    //   cout << num << " ";
    // }
  }
  sort(dp[n-1].begin(), dp[n-1].end());
  cout << dp[n-1].back() << endl;
  return 0;
}


Measured memory_bytes: 6912
#include<iostream>
using namespace std;int n,a[1<<17],G,F[31],res,R,i,j,cnt;main(){cin>>n;for(i=0;i<n;i++){cin>>a[i];res^=a[i];R=a[i]^(a[i]-1);for(j=1;j<31;j++){if(R==(1<<j)-1)F[j-1]++;}}for(i=29;i>=0;i--){if(res>=(1<<i)){if(F[i]==0){cout<<"-1\n";return 0;}res^=(1<<(i+1))-1;cnt++;}}if(res==0)cout<<cnt<<endl;else cout<<"-1\n";}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(void){
    
    //変数：各コインの金額の枚数
    int c1, c5, c10, c50, c100, c500;
    
    //変数：各コインの金額の枚数を入力
    cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
    
    //条件：コインの合計数が１０００以上なら両替するか考える
    if( 1000 <= (c1 + 5 * c5 + 10 * c10 + 50 * c50 + 100 * c100 + 500 * c500) ) cout << 1 << endl;
    else cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 3104
mod = 10**9 + 7
def cmb(n,r,mod):
	a=1
	b=1
	r = min(r,n-r)
	for i in range(r):
		a = a*(n-i)%mod
		b = b*(i+1)%mod
	return a*pow(b,mod-2,mod)%mod

X,Y = map(int,input().split())
if (X+Y)%3 != 0:
  ans = 0
else:
  n = (2*X-Y)//3
  m = (2*Y-X)//3
  if n < 0 or m < 0:
    ans = 0
  else:
    ans = cmb(n+m,m,mod)
print(ans)

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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;

	string str;
	cin>>str;
	int flag=0;
	for(int i=0;i<str.size();i++){
		if(i%2==0){
			if(str[i]!='R'&&str[i]!='U'&&str[i]!='D'){
				cout<<"No";
				return 0;
			}
			
		}else{
			if(str[i]!='L'&&str[i]!='U'&&str[i]!='D'){
				cout<<"No";
				return 0;
			}
		}
	}

	cout<<"Yes";

	return 0;
}

Measured memory_bytes: 256
import math
import itertools



N = int(input())
machi = [list(map(int,input().split())) for i in range(N)]
# print(machi)

comb = list(itertools.permutations(range(N), 2))

# print(comb)

dis = []
for i,j in comb:
    x = machi[i][0] - machi[j][0]
    y = machi[i][1] - machi[j][1]

    di = math.sqrt(abs(x**2+y**2))
    dis.append(di)
# print(dis)
print(sum(dis)/N)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
const int maxn = 105;
int a[maxn];
int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; i++)
	{
		int d;
		cin >> d;
		for (int j = 1; j <= d; j++)
		{
			int num;
			cin >> num;
			a[num]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (a[i] == 0)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<iomanip>

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

#define P pair<int, int>

typedef long long ll;

using namespace std;

#include <string>
#include <cctype>
typedef string::const_iterator State;
class ParseError {};


int main() {
	int N;
	cin >> N;
	int h[1005];
	rep(i, N) cin >> h[i];
	sort(h, h + N);
	int mid = (h[0] + h[N - 1]) / 2;
	cout << max(mid - h[0], h[N - 1] - mid) << endl;

	return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int A, B;
  cin >> A >> B;
  cout << max({A+B, A-B, A*B}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
  int a,b,c,count=0,tmp=0,d[100],e[100],f[100];
  cin>>a>>b>>c;
  for(int i=0;i<100;i++){
    d[i]=0;
    e[i]=0;
    f[i]=0;
  }
  for(int i=1;i<=a;i++){
    if(a%i==0)
      d[i]=i;
  }
  for(int i=1;i<=b;i++){
    if(b%i==0)
      e[i]=i;
    if(d[i]==e[i]&&d[i]!=0&&e[i]!=0)
      f[i]=d[i];
  }
   for (int i=0; i<100; ++i) {
    for (int j=i+1; j<100; ++j) {
      if (f[i] < f[j]) {
        tmp =  f[i];
        f[i] = f[j];
        f[j] = tmp;
      }
    }
  }
      cout<<f[c-1]<<endl;
}

Measured memory_bytes: 256