akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

//公約数列挙
void div(long long a, vector<long long> &n) {
  n.push_back(1);
  for (long long i = 2; i <= sqrt(a); i++)
    if (a % i == 0) n.push_back(i);
  if (n.at(n.size() - 1) == sqrt(a))
    for (long long i = n.size() - 2; i >= 0; i--)
      n.push_back(a / n.at(i));
  else
    for (long long i = n.size() - 1; i >= 0; i--)
      n.push_back(a / n.at(i));
  return;
}

void comdiv(long long a, long long b, vector<long long> &n) {
  if (a > b) swap(a, b);
  vector<long long> m(0);
  div(a, m);
  for (long long i = 0; i < m.size(); i++)
    if (b % m.at(i) == 0) n.push_back(m.at(i));
  return;
}

int main() {
  ll n, x;
  cin >> n >> x;
  vector<ll> city(n), leng(n);
  for (int i = 0; i < n; i++) {
    cin >> city.at(i);
    leng.at(i) = max(x - city.at(i), city.at(i) - x);
  }
  if (n == 1) {
    cout << max(x - city.at(0), city.at(0) - x) << endl;
    return 0;
  }
  sort(leng.begin(), leng.end());
  vector<ll> m(0);
  comdiv(leng.at(0), leng.at(1), m);
  for (int i = 0; i < m.size() - 1; i++) {
    for (int j = 2; j < n; j++) {
      if (leng.at(j) % m.at(m.size() - 1 - i) != 0) break;
      if (j == n - 1) {
        cout << m.at(m.size() - 1 - i) << endl;
        return 0;
      }
    }
  }
  cout << 1 << endl;
}

Measured memory_bytes: 1792
cards = []
nums = []
while True:
    card = raw_input()
    if card == '-':
        break
    cards += [card]
    n = 0
    for _ in range(int(raw_input())):
        n += int(raw_input())
    nums += [n]

for c, n in zip(cards, nums):
    w = c * ((n / len(c)) + 2)
    print w[n:n+len(c)]

Measured memory_bytes: 6336
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
#include<cmath>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
const int mod=998244353;
int dp[200005][3][3][2];
int n;
char str[200005];
int main()
{
	scanf("%s",str);
	n=strlen(str);
	bool as=1;
	for(int i=1;i<n;i++)
		as&=(str[i-1]==str[i]);
	if(as)
	{
		printf("1\n");
		return 0;
	}
	if(n==3)
	{
		int ans=0;
		if(str[0]!=str[1] && str[1]!=str[2] && str[0]!=str[2])	ans=3;
		else if(str[0]==str[2])	ans=7;
		else	ans=6;
		cout<<ans<<endl;
		return 0;
	}
	dp[1][0][0][0]=1;
	dp[1][1][1][0]=1;
	dp[1][2][2][0]=1;
	for(int i=1;i<n;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
				for(int l=0;l<3;l++)
				{
					if(l==k)
						dp[i+1][(j+l)%3][l][1]=(0ll+dp[i+1][(j+l)%3][l][1]+dp[i][j][k][0]+dp[i][j][k][1])%mod;
					else
					{
						dp[i+1][(j+l)%3][l][1]=(dp[i+1][(j+l)%3][l][1]+dp[i][j][k][1])%mod;
						dp[i+1][(j+l)%3][l][0]=(dp[i+1][(j+l)%3][l][0]+dp[i][j][k][0])%mod;
					}
				}
	bool gg=0;
	for(int i=1;i<n;i++)
		if(str[i-1]==str[i])	gg=1;
	int rr=0;
	for(int i=0;i<n;i++)
		rr=(rr+str[i]-'a')%3;
	int ans=0;
	for(int i=0;i<3;i++)
		ans=(ans+dp[n][rr][i][1])%mod;
	if(!gg)	ans++;
	ans%=mod;
	cout<<ans<<endl;
	return 0;
}

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

const int INF = 1e9+1;
int v[5002][5002] = {};

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++){
        scanf("%d %d", x.begin()+i, y.begin()+i);
    }
    vector<int> ax = x, ay = y;
    ax.push_back(-INF); ax.push_back(INF);
    ay.push_back(-INF); ay.push_back(INF);
    sort(ax.begin(), ax.end());
    ax.erase(unique(ax.begin(),ax.end()),ax.end());
    sort(ay.begin(), ay.end());
    ay.erase(unique(ay.begin(),ay.end()),ay.end());
    int nx = ax.size(), ny = ay.size();
    auto fx = [&](int val)->int{
        return lower_bound(ax.begin(),ax.end(),val)-ax.begin();
    };
    auto fy = [&](int val)->int{
        return lower_bound(ay.begin(), ay.end(), val)-ay.begin();
    };
    for(int i = 0; i < n; i++){
        v[fx(x[i])][fy(y[i])]++;
    }
    for(int i = 0; i < nx; i++){
        for(int j = 1; j < ny; j++){
            v[i][j] += v[i][j-1];
        }
    }
    for(int j = 0; j < ny; j++){
        for(int i = 1; i < nx; i++){
            v[i][j] += v[i-1][j];
        }
    }
    auto get = [&](int lx, int rx, int ly, int ry)->int{
        return v[rx][ry]-v[rx][ly-1]-v[lx-1][ry]+v[lx-1][ly-1];
    };
    for(int i = 0; i < m; i++){
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        cout << get(fx(a),fx(c+1)-1,fy(b),fy(d+1)-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 101064
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, m = MAP()
H = LIST()
low = []
for i in range(m):
    a, b= MAP()
    if H[a-1] == H[b-1]:
        low.append(a-1)
        low.append(b-1)
    elif H[a-1] < H[b-1]:
        low.append(a-1)
    else:
        low.append(b-1)

print(n-len(set(low)))

Measured memory_bytes: 91156
#include <stdio.h>

int main(){
    int a,b,c,d,e,k;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
    
    if(e-a > k){
        printf(":(");
    }
    else{
        printf("Yay!");
    }
}


Measured memory_bytes: 128
#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: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int MOD = 1e9 + 7;
int main() {
	string S;
	cin >> S;
	int N = S.size();
  	int x=-1,y=-1;
	if (N == 2) {
		if (S[0] == S[1])cout << 1 << " " <<2<< endl;
		else cout << -1 << " " << -1 << endl;
	}
	else {
		for (int i = 0; i < N; i++) {
			if (S[i] == S[i + 1]) {
				x = i + 1, y = i + 3;
				break;
			}
			if (S[i] == S[i + 2]) {
				x = i + 1, y = i + 3;
				break;
			}
		}
	cout << x << " " << y << endl;
    }
}

Measured memory_bytes: 512
#ciが R のとき赤、W のとき白です。
#入力
#N
#c1...cN

N = int(input())
C = input()
Rednum = C.count('R')
#print(Rednum)
#Rの数 - 左にある赤の数が答
NewC = C[:Rednum]
#print(NewC)
Whinum = NewC.count('R')

print(Rednum - Whinum)


Measured memory_bytes: 9380
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

using namespace std;
using ll=long long;

void solve(){
  int num,ma,mb;
  cin >> num >> ma >> mb;
  vector<vector<int>> abc(num,vector<int>(3));
  for(int i=0;i<num;i++)
    cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
  vector<vector<int>> dp(405,vector<int>(405));
  for(int i=0;i<401;i++)
    for(int j=0;j<401;j++)
      dp[i][j]=1000;
  dp[0][0]=0;
  for(int i=0;i<num;i++){
    vector<vector<int>> newdp(405,vector<int>(405));
    for(int j=0;j<401;j++)
      for(int k=0;k<401;k++)
        if(j-abc[i][0]>=0&&k-abc[i][1]>=0)
          newdp[j][k]=min(dp[j][k],dp[j-abc[i][0]][k-abc[i][1]]+abc[i][2]);
        else newdp[j][k]=dp[j][k];
    dp=newdp;
  }
  int m=1000;
  for(int i=1;i<401;i++)
    for(int j=1;j<401;j++)
      if(i*mb==j*ma)
        m=min(m,dp[i][j]);
  cout << (m==1000?-1:m) << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1616
a = input()
x = 0
y = 0
z = 0
for i in a:
        if i == "a":
                x += 1
        elif i == "b":
                y += 1
        else:
                z += 1
if x == 1 and y == 1 and z == 1:
        print("Yes")
else:
        print("No")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int d = Integer.parseInt(str[0]);
		int g = Integer.parseInt(str[1]);

		int p[] = new int[d];
		int c[] = new int[d];

		for (int i = 0; i < d; i++) {
			str = br.readLine().split(" ");

			p[i] = Integer.parseInt(str[0]);
			c[i] = Integer.parseInt(str[1]);
		}

		int ans = Integer.MAX_VALUE;
		for (int bit = 0; bit < (1 << d); bit++) {
			int problem = 0;
			int point = 0;

			for (int i = 0; i < d; i++) {
				if ((bit & (1 << i)) != 0) {
					problem += p[i];
					point += (1 + i) * 100 * p[i] + c[i];
				}
			}
			if (point >= g) {
				ans = Math.min(ans, problem);
				continue;
			}
			for (int i = 0; i < d; i++) {
				if ((bit & (1 << i)) != 0)
					continue;
				if ((g - point) / ((i + 1) * 100) <= p[i]) {
					problem += (g - point) / ((i + 1) * 100);
					ans = Math.min(ans, problem);
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
from sys import exit
import bisect

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A) < sum(B):
    print(-1)
    exit()
L = [a - b for a, b in zip(A, B)]
L.sort()
x = bisect.bisect_left(L, 0)
low = abs(sum(L[:x]))
s = 0
ans = x  
L.reverse()
for l in L:
    if s >= low:
        break
    s += l
    ans += 1
print(ans)


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);

    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    vector<int> ans(n);

    for(int i = 0; i < n; i++)
        ans[a[i]-1] = i+1;

    for (int i = 0; i < n; i++) {
        cout << ans[i] << ' ';
        if (i == n-1)
        cout << '\n';
    }
    return 0;
}

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

int main() {
  int A, B, s;
  cin >> A >> B;

  for(int i = A; i <= B; i++){
    if(i / 10000 == i % 10 && i % 10000 / 1000 == i % 10000 / 10 % 10)
    	s++;
  }
  cout << s << endl;
  
}


Measured memory_bytes: 256
from bisect import bisect_left


def main(N, L):
    L.sort()
    ans = 0
    for i in range(0, N-1):
        for j in range(i+1, N):
            r = bisect_left(L, L[i] + L[j])
            ans += r - (j + 1)
    return ans

if __name__ == "__main__":
    N = int(input())
    L = list(map(int, input().split()))
    print(main(N, L))


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
const int MOD=1000000007;
const int INF=1000000000;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
ll p=0;
bool zerodiv=false;
string t;

ll ppow(ll x,ll num,ll mod)
{
  ll ret=1;
  while(num>0)
    {
      if(num&1)
	{
	  ret=(ret*x)%mod;
	}
      x=(x*x)%mod;
      num=num>>1;
    }
  return ret%mod;
}

class Parser{
public:

  ll number(State &begin)
  {
    ll ret=0;
    while(isdigit(*begin))
      {
	ret*=10;
	ret+=(*begin-'0');
	begin++;
      }
    return ret;
  }

  ll expression(State &begin)
  {
    ll ret=term(begin);
    for(;;)
      {
	if(*begin=='+')
	  {
	    begin++;
	    ret=(ret+term(begin))%p;
	  }
	else if(*begin=='-')
	  {
	    begin++;
	    ret=(ret+(p-term(begin)))%p;
	  }
	else
	  {
	    break;
	  }
      }
    return ret%p;
  }

  ll term(State &begin)
  {
    ll ret=factor(begin);
    for(;;)
      {
	if(*begin=='*')
	  {
	    begin++;
	    ret=(ret*factor(begin))%p;
	  }
	else if(*begin=='/')
	  {
	    begin++;
	    State tmp=begin;
	    if(factor(tmp)==0)
	      {
		zerodiv=true;
		return 0;
	      }
	    ret=(ret*(ppow(factor(begin),p-2,p)))%p;
	  }
	else
	  {
	    break;
	  }
      }
    return ret;
  }

  ll factor(State &begin)
  {
    ll ret;
    if(*begin=='(')
      {
	begin++;
        ret=expression(begin);
	begin++;
	return ret;
      }
    else
      {
	ret=number(begin)%p;
      }
    return ret;
  }
};


int main(int argc,char const* argv[])
{
  while(1)
    {
      getline(cin,t);
      zerodiv=false;
      if(t=="0:") break;
      p=0;
      Parser ps;
      while (t.find(' ') != string::npos)t.erase(t.find(' '), 1);
      while(isdigit(t[0]))
	{
	  p*=10;
	  p+=int(t[0]-'0');
	  t.erase(0,1);
	}
      t.erase(0,1);
      State begin=t.begin();
      ll ans=ps.expression(begin);
      if(!zerodiv)
	{
	  cout << t << " = " << ans << " (mod " << p << ')' << endl;
	}
      else
	{
	  cout << "NG" << endl;
	}
    }
  return 0;
}



Measured memory_bytes: 3312
mod = 998244353

N, S, *A = map(int, open(0).read().split())

dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i, a in enumerate(A, 1):
    for j in range(S + 1):
        dp[i][j] = (2 * dp[i - 1][j] + (dp[i - 1][j - a] if j >= a else 0)) % mod

print(dp[N][S])

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

int main() {
    int n, m, d, t;
    map<int, int> mpd, mpt;
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &d);
        mpd[d]++;
    }
    cin >> m;
    bool ret = true;
    for (int i = 0; i < m; i++) {
        scanf("%d", &t);
        if (--mpd[t] < 0) {
            ret = false;
            break;
        }
    }
    
    puts(ret ? "YES" : "NO");
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
map<long long,int> reps;
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    cout << (s[0] == s[2] ? "Yes" : "No");
}


Measured memory_bytes: 256
s=input()
if s=='SAT':
	print(1)
elif s=='SUN':
	print(7)
elif s=='MON':
	print(6)
elif s=='TUE':
	print(5)
elif s=='WED':
	print(4)
elif s=='THU':
	print(3)
else:
	print(2)

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

using namespace std;

typedef vector<vector<int> > Matrix;
const int INF = (1<<28);

int minimumSteinerTree(const vector<int>& T, const Matrix& m){
  if(T.size() <= 1) return 0;
  Matrix mat = m;
 
  for(int k = 0; k < (int)mat.size(); k++)
    for(int i = 0; i < (int)mat.size(); i++)
      for(int j = 0; j < (int)mat.size(); j++)
	mat[i][j] = min(mat[i][j],mat[i][k]+mat[k][j]);

   int Opt[(1<<T.size())][m.size()];

  for(int i = 0; i < (1<<T.size()); i++)
    for(int j = 0; j < (int)m.size(); j++) Opt[i][j] = INF;

  for(int i = 0; i < (int)T.size(); i++)
    for(int j = 0; j < (int)m.size(); j++)
      Opt[(1<<i)][j] = mat[T[i]][j];
  

  for(int i = 1; i < (1<<T.size()); i++){
    if(!(i & (i-1))) continue;
    
    for(int j = 0; j < (int)m.size(); j++)
      for(int k = 0; k < i; k++)
	if((k|i) == i) Opt[i][j] = min(Opt[i][j],Opt[k][j]+Opt[i-k][j]);

    for(int j = 0; j < (int)m.size(); j++)
      for(int k = 0; k < (int)m.size(); k++)
	Opt[i][j] = min(Opt[i][j], Opt[i][k]+mat[j][k]);
  }

  int ans = INF;
  for(int i = 0; i < (1<<T.size()); i++)
    for(int j = 0; j < (int)m.size(); j++)
      ans = min(ans,Opt[i][j]+Opt[((1<<T.size())-1)-i][j]);
  return ans;
}

const int MAX = 15;
int H,W,field[MAX][MAX];

bool isInside(int h, int w){ return 0<=h&&h<H&&0<=w&&w<W;}
int main(){
  while(cin >> H >> W && H+W){

    vector<int> V;
    for(int i = 0; i < H; i++)
      for(int j = 0; j < W; j++){
	cin >> field[i][j];
	if(field[i][j] == 1) V.push_back(i*W+j);
      }

    Matrix mat(H*W,vector<int>(H*W));
    
    for(int i = 0; i < H*W; i++)
      for(int j = 0; j < H*W; j++) mat[i][j] = INF;

    int dx[] = {-1,1,0,0};
    int dy[] = {0,0,1,-1};
    for(int i = 0; i < H*W; i++)
      for(int j = 0; j < 4; j++){
	int h = i/W;
	int w = i%W;
	h += dy[j];
	w += dx[j];
	if(isInside(h,w)) mat[i][h*W+w] = 1;
      }

    for(int i = 0; i < H*W; i++) mat[i][i] = 0;
    cout << H*W-minimumSteinerTree(V,mat)-1 << endl;
  }
  return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    string s; std::cin >> s;
    int rw = 0, wr = 0;
    rep(i, s.size()) rw += s[i] == 'R';
    int ans = rw;
    rep(i, n) {
        if (s[i] == 'W') wr++;
        else rw--;
        chmin(ans, max(rw, wr));
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 3744
#include <iostream>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.walkinghospital", "r", stdin );
	int n;

	while (cin >> n && n ) {

		int maxd = 0;
		int maxp = -1;
		for (int i = 0; i < n; ++i){
			int p, d1, d2;
			cin >> p >> d1 >> d2;
			if (maxd < d1 + d2 ){
				maxd = d1 + d2;
				maxp = p;
			} // end if
		} // end for
		cout << maxp << " " << maxd << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[1114514];
int main(){
	ll n,ma=0;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		cnt[x]++;
		ma=max(ma,x);
	}
	ll ans=0;
	for(int i=1;i<=ma;i++){
		if(cnt[i]){
			if(cnt[i]==1)ans++;
			for(int j=2*i;j<=ma;j+=i)cnt[j]=0;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11452
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
#define X second
#define Y first

int w,h;

void move(pii &A,pii &B,int p){
    if(p==0){
        if(A.Y==h-1 && A.X==0) A = pii(-1,-1);
        else if(A.Y==h-1)A.X--;
        else if(A.X==w-1)A.Y++;
        else A.X++;
    }else{
        if(B.Y==h-2 && B.X==0) B = pii(-1,-1);
        else if( B.Y==h-2 )B.X--;
        else if(B.X==w-2)B.Y++;
        else B.X++;
    }
}


bool is(pii A,pii B){
    int dx[4]={0,1,0,-1};
    int dy[4]={1,0,-1,0};
    rep(i,4){
        if( A.X+dx[i]==B.X &&
            A.Y+dy[i]==B.Y){
                return true;
            }
    }
    return false;
}


int main(){
    cin>>w>>h;
    int n;
    cin>>n;
    
    pii A,B;
    A = pii(0,0);
    B = pii(1,0);
    
    int c=0;
    rep(i,n){
        int p;
        cin>>p;
        move(A,B,p);
        if(is(A,B))c++;
    }
    cout<<c<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll A, B; cin >> A >> B;
  ll result = -1;
  rep(i,100000) {
    if (floor((double)i*0.08)==A&&floor((double)i*0.1)==B) {
      result = i;
      break;
    } 
  }
  cout << result << endl;
  return 0;
}

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

int n;
int load[200005];
int train[200005];

int root(int x, int par[]){
    if (par[x] == x) return x;
    else return par[x] = root(par[x],par);
}

bool same(int x, int y, int par[]){
    return root(x,par) == root(y,par);
}

void unit(int x, int y, int par[]){
    x = root(x,par);
    y = root(y,par);

    if (x == y) return;

    par[y] = x;
}

void reset(int par[]){
    for (int i=0; i<n; i++){
        par[i] = i;
    }
}

int main(){
    int k,l;
    int p,q,r,s;
    char spc;
    cin >> n >> k >> l ;

    reset(load);
    for (int i=0; i<k; i++){
        cin >> p >> q ;
        p-=1;
        q-=1;
        unit(p,q,load);
    }

    reset(train);
    for (int i=0; i<l; i++){
        cin >> r >> s ;
        r--;
        s--;
        unit(r,s,train);
    }

    for (int i=0; i<n; i++){
        root(load[i],load);
        root(train[i],train);
    }

    map<pair<int,int>,int> mp;
    int a,b;
    for (int i=0; i<n; i++){
        a = root(load[i],load);
        b = root(train[i],train);
		mp[{a,b}]++;
    }

    for (int i=0; i<n; i++){
        a = root(load[i],load);
        b = root(train[i],train);
		cout << mp[{a,b}] << endl;
    }
/*
    cout << endl;
    for (int i=0; i<n; i++){
        cout << load[i] << endl;
    }
    cout << endl;
    for (int i=0; i<n; i++){
        cout << root(train[i],train)<< endl;
    }
    
    cout << endl;

    cout << root(train[4],train) << endl;
*/
    return 0;
}

Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
int ar[200005];
int main()
{
    int k, n, ans = 0;
    cin >> k >> n;
    for (int i = 0; i < n; i++)
        cin >> ar[i];
    int gap = 0, prev = 0, i;
    for (i = 0; i < n; i++){
        gap = max(gap, abs(prev - ar[i]));
        prev = ar[i];
    }
    gap = max(gap, k + ar[0] - ar[n - 1]);
    ans = k - gap;
    cout << ans << nl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#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
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll D;
	cin >> D;
	vector<ll> c(27);
	vector<vector<ll>> s(D+1, vector<ll>(27));
	vector<ll> zenkai(27);/*各nameコンテストが前回行われた日*/

	for (ll name = 1; name <= 26; name++)cin >> c.at(name);

	for (ll day = 1; day <= D; day++) { 
		for (ll name = 1; name <= 26; name++) { 
			cin >> s.at(day).at(name); 
		}
	}
	vector<ll> t(D+1); 

	/*for (ll day = 1; day <= D; day++) {
		cin >> t.at(day);
	}*/
	
	for (ll name = 1; name <= 26; name++) {
		zenkai.at(name) = 0;
	}

	ll an =0;/*満足度*/
	ll n = 0;/*各日のコンテスト仮*/
	for (ll day = 1; day <= D; day++) {
		ll karimax = an-999999999999;
		n = -1;
		for (ll kariname = 1; kariname <= 26; kariname++) {
			ll karian = an;
			
			karian += s.at(day).at(kariname);
			/*zenkai.at(t.at(day)) = day;*/

			for (ll name = 1; name <= 26; name++) {
				if (name != kariname) {
					karian -= c.at(name) * (day - zenkai.at(name));
				}
			}
			
			if (karian >= karimax) {
				n = kariname;
				karimax = karian;
			}
		}
		if (n == -1) {
			n = 1;
		}
		an += s.at(day).at(n);
		zenkai.at(n) = day;

		for (ll name = 1; name <= 26; name++) {
			
				an -= c.at(name) * (day - zenkai.at(name));
			
		}
		
			cout << n << endl;
	

	}
	/*cout << an << endl;*/

}

Measured memory_bytes: 3676
def main():
    num=[0]*9
    num[0],num[1],num[2]= map(int,input().split())
    num[3],num[4],num[5]= map(int,input().split())
    num[6],num[7],num[8]= map(int,input().split())

    n=int(input())
    li=[int(input()) for i in range(n)]
    flg = 0
    cnt = 0
    bg = [0]*9


    for i in num:
        if i in li:
            # print('okay')
            bg[cnt]=1

        cnt+=1

    if bg[0]==bg[1]==bg[2]==1 or bg[0]==bg[3]==bg[6]==1 or bg[6]==bg[7]==bg[8]==1 or bg[2]==bg[5]==bg[8]==1 or bg[3]==bg[4]==bg[5]==1 or bg[1]==bg[4]==bg[7]==1 or bg[0]==bg[4]==bg[8]==1 or bg[2]==bg[4]==bg[6]==1:
        print('Yes')
    else:
        print('No')

    # print(bg)

if __name__ == '__main__':
    main()

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


#include <bits/stdc++.h>


using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define endl '\n'

/**********************************************/




class ALucky7 {
public:
    void solve(istream &in, ostream &out) {

        string s;
        in >> s;

        bool found = false;
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] == '7') {
                out << "Yes" << endl;
                found = true;
                break;
            }
        }

        if (!found) out << "No" << endl;


    }
};


int main() {
    ALucky7 solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 512;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int mat[MAX][MAX], cnt[MAX], indices[MAX];
bool used[MAX];

void solve(void){
    int N, M;
    cin >> N >> M;
    rep(N, i) {
        rep(M, j) {
            scanf("%d ", &mat[i][j]);
            mat[i][j]--;
        }
        scanf("\n");
    }

    int ans = INF;
    bool stop = false;
    rep(M, m) {
        if (stop) break;
        memset(cnt, 0, sizeof(cnt));
        int maxi = -1, spo = -1;
        rep(N, n) {
            cnt[mat[n][indices[n]]]++;
        }
        rep(M, i) {
            if (cnt[i] > maxi) {
                maxi = cnt[i];
                spo = i;
            }
        }
        used[spo] = true;
        ans = min(ans, maxi);
        rep(N, n) {
            while (used[mat[n][indices[n]]] && indices[n] < M) {
                indices[n]++;
            }
            if (indices[n] == M) stop = true;
        }
    }
    cout << ans << endl;
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		if (i != 0) {
			cout << endl << flush;
		}
		int hyou[9][9][2] = {0};
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				cin >> hyou[j][k][0];
			}
		}
		int hantei3[9][9] = {0};
		for (int j = 0; j < 9; j++) {
			int hantei[9] = {0};
			int hantei2[9] = {0};
			for (int k = 0; k < 9; k++) { 
				int p;
				hantei[hyou[j][k][0]-1]++; // yoko
			    hantei2[hyou[k][j][0]-1]++; // tate
				if (0 <= k && k <= 2) {
					if (0 <= j && j <= 2) {
						p = 0;
					} else if (3 <= j && j <= 5) {
						p = 3;
					} else {
						p = 6;
					}
				} else if (3 <= k && k <= 5) {
					if (0 <= j && j <= 2) {
						p = 1;
					} else if (3 <= j && j <= 5) {
						p = 4;
					} else {
						p = 7;
					}
				} else {
					if (0 <= j && j <= 2) {
						p = 2;
					} else if (3 <= j && j <= 5) {
						p = 5;
					} else {
						p = 8;
					}
				}
				hantei3[p][hyou[j][k][0]-1]++;
			}
			for (int k = 0; k < 9; k++) {
				if (hantei[hyou[j][k][0]-1] > 1) {
					hyou[j][k][1]++;
				}
				if (hantei2[hyou[k][j][0]-1] > 1) {
					hyou[k][j][1]++;
				}
			}
		}
		for (int j = 0; j < 9; j++) {
			int p;
			for (int k = 0; k < 9; k++) { 
				if (0 <= k && k <= 2) {
					if (0 <= j && j <= 2) {
						p = 0;
					} else if (3 <= j && j <= 5) {
						p = 3;
					} else {
						p = 6;
					}
				} else if (3 <= k && k <= 5) {
					if (0 <= j && j <= 2) {
						p = 1;
					} else if (3 <= j && j <= 5) {
						p = 4;
					} else {
						p = 7;
					}
				} else {
					if (0 <= j && j <= 2) {
						p = 2;
					} else if (3 <= j && j <= 5) {
						p = 5;
					} else {
						p = 8;
					}
				}
				if (hantei3[p][hyou[j][k][0]-1] > 1) {
					hyou[j][k][1]++;
				}
			}
		}
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 9; k++) {
				if (hyou[j][k][1] > 0) {
					cout << "*" << flush;
				} else {
					cout << " " << flush;
				}
				cout << hyou[j][k][0] << flush;
			}
			cout << endl << flush; 
		}
	}
	return 0;
}

Measured memory_bytes: 1160
S = input()
ans = 0
ACGT = ["A","C","G","T"]
for i in range(len(S)):
    for j in range(i,len(S)+1):
        clipped_list = list(S[i:j])
        clipped = set(clipped_list)
        for acgt in ACGT:
            try:
                clipped.remove(acgt)
            except:
                pass
        if clipped == set():
            ans = max(ans,len(clipped_list))

print(ans)



Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"case #" << x << ": " << endl
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-15;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vector<int> a(n), b(n);
	rep(i, n)	cin >> a[i];
	rep(i, n)	cin >> b[i];
	sort(all(a));
	sort(all(b));
	int ret = 0;
	vector<int> amod(n), bmod(n);
	rep(i, 29) {
		rep(j, n)	amod[j] = a[j] % (2 << i);
		rep(j, n)	bmod[j] = b[j] % (2 << i);
		sort(all(bmod));
		int cnt = 0;
		rep(j, n) {
			if (amod[j] & (1 << i)) {
				// ooxxxxxxoo
				cnt += lower_bound(all(bmod), (2 << i) - amod[j]) - bmod.begin();
				cnt += bmod.end() - lower_bound(all(bmod), (3 << i) - amod[j]);
			}
			else {
				// xxxxoooooxx
				auto s = lower_bound(all(bmod), (1 << i) - amod[j]);
				auto t = lower_bound(all(bmod), (2 << i) - amod[j]);
				cnt += t - s;
			}
		}
		ret ^= ((cnt&1) << i);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  int a,b;
  long int ant,kazu[100000],maxt;
  while(1){
    maxt=0;
    scanf("%d%d",&a,&b);
    if(a==0&&b==0) return 0;
    for(int i=0;i<a;i++)scanf("%ld",&kazu[i]);
    for(int i=0;i<b;i++) maxt=maxt+kazu[i];
    ant=maxt;
    for(int i=0;i<a-b;i++) {maxt=max(maxt,ant-kazu[i]+kazu[i+b]); 
      ant=ant-kazu[i]+kazu[i+b];
    }
    printf("%ld\n",max(maxt,ant));
  }
  
}

Measured memory_bytes: 0
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let nm: Vec<_> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();

    let mut xs = vec![vec![false; nm[0]]; nm[0]];

    for _ in 0..nm[1] {
        let mut s = String::new();
        io::stdin().read_line(&mut s).ok();
        let ab: Vec<usize> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();

        xs[ab[0] - 1][ab[1] - 1] = true;
        xs[ab[1] - 1][ab[0] - 1] = true;
    }
    let mut ts = vec![false; nm[0]];

    println!("{}", rec(&xs, nm[0], 0, &mut ts));
}

fn rec(xs: &Vec<Vec<bool>>, n: usize, idx: usize, ts: &mut Vec<bool>) -> u64 {
    ts[idx] = true;
    let mut f = true;
    for i in 0..n {
        f = f && ts[i];
    }

    if f {
        1
    }
    else {
        let mut res = 0;
        for (i, &x) in xs[idx].iter().enumerate() {

            if x && !ts[i] {
                res += rec(xs, n, i, ts);
                ts[i] = false;
            }
        }
        res
    }
}


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


int main()
{
  ll n,i;
  cin>>n;
  ll h[n],dp[n];
  for(i=0;i<n;i++)
    cin>>h[i];
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<dp[n-1];
}
  
  


Measured memory_bytes: 1792
import sys,collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = 0
def merge(a,left,mid,right):
  n1 = mid - left
  n2 = right - mid
  L = a[left:mid]
  R = a[mid:right]
  L.append(float("inf"))
  R.append(float("inf"))
  i = 0
  j = 0
  for k in range(left,right):
    global c
    c += 1
    if L[i] <= R[j]:
      a[k] = L[i]
      i += 1
    else:
      a[k] = R[j]
      j += 1

def mergeSort(a,left,right):
  if 1 < right - left:
    mid = (left+right)//2
    mergeSort(a,left,mid)
    mergeSort(a,mid,right)
    merge(a,left,mid,right)

mergeSort(a,0,n)
print(" ".join(map(str,a)))
print(c)


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

using namespace std;

typedef long long ll;

const double pi = 2 * asin(1.0);

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

const int inf = 1000 * 1000 * 1000;

int LIS(const vector<int>& a) {
  vector<int> d(a.size(), inf);
  for (int x : a) *lower_bound(d.begin(), d.end(), x) = x;
  return find(d.begin(), d.end(), inf) - d.begin();
}

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

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

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

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

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

  return 0;
}


Measured memory_bytes: 5232
#include <stdio.h>

int min(int a, int b) {
	return a < b ? a : b;
}

int max(int a, int b) {
	return a > b ? a : b;
}

int main() {
	int a, b, c, x, y, cost1, cost2, cost3;

	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
	if (x > y) {
		int tmp;

		tmp = x, x = y, y = tmp;
		tmp = a, a = b, b = tmp;
	}
	cost1 = x * a + y * b;
	cost2 = y * c * 2;
	cost3 = x * c * 2 + (y - x) * b;
	printf("%d\n", min(cost1, min(cost2, cost3)));
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	int dp[n];
	dp[0] = 0, dp[1] = abs(arr[1] - arr[0]);
	for(int i = 2; i < n; i++)
		dp[i] = min(abs(arr[i] - arr[i - 2]) + dp[i - 2], abs(arr[i] - arr[i - 1]) + dp[i - 1]);
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main(){
    ll n,s;
    scanf("%lld%lld",&n,&s);
    ll a[3]={1,5,10};
    s/=1000;
    int x=-1,y=-1,z=-1;
    for(int i=0;i<=2000;i++){
        if(i*a[2]>s)break;
        if(i>n)break;
        for(int j=0;j<=2000;j++){
            if(i*a[2]+j*a[1]>s)break;
            if(i+j>n)break;
            for(int k=0;k<=2000;k++){
                if(k+j+i>n)break;
                if((i*a[2])+(j*a[1])+(k*a[0])==s&&i+j+k==n){
                    cout<<i<<' '<<j<<' '<<k;
                    return 0;
                }
                if((i*a[2])+(j*a[1])+(k*a[0])>s){
                    break;
                }
            }
        }
    }
    cout<<-1<<' '<<-1<<' '<<-1;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll N;
vector<pair<string,pair<ll,ll>>> vec;

void solve() {
	cin >> N;
	vec.resize(N);
	rep(i, N) {
		cin >> vec[i].first >> vec[i].second.first;
		vec[i].second.second = i;
	}
	sort(vec.begin(), vec.end(), [](const pair<string, pair<ll, ll>>& x, const pair<string, pair<ll, ll>>& y) {
		if (x.first == y.first) return x.second.first > y.second.first;
		return x.first < y.first;
	});
	rep(i, N) cout << vec[i].second.second+1 << endl;
}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(s==u){
        cout<<a-1<<" "<<b;
    }
    else{
        cout<<a<<" "<<b-1;
    }
}


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

import java.util.ArrayList;
import java.util.List;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		//文字列読込み
		Scanner sc = new Scanner(System.in);

		//取り出し
		String scLline;	//1行
		int len;
		String scChar;

		StringBuffer resultTmp = new StringBuffer();
		ArrayList<String> resultAry = new ArrayList<String>();
		int result = 0;

		while (sc.hasNext()) {
			//文字読込み
			scLline = sc.nextLine();
			len = scLline.length();
			for (int i = 0; i < len; i++) {
				//1文字ずつ取り出し
				scChar = String.valueOf(scLline.charAt(i));

				if (isNumber(scChar)) {
					//数字→resultTmp入れる
					resultTmp.append(scChar);
					//System.out.print(scChar);
				} else {
					//文字→resultTmpあるならresult、ないなら何もしない
					if (resultTmp.length() > 0) {
						resultAry.add(resultTmp.toString());
						resultTmp.setLength(0);	//初期化
					}
					//System.out.print(".");
				}
			}
		}

		//result加算
		//System.out.println(Arrays.asList(result));
		len = resultAry.size();
		
		for (int i = 0; i < len; i++) {
			result += Integer.parseInt(resultAry.get(i));
		}
		System.out.println(result);
		
		
	}

	public static boolean isNumber(String val) {
	try {
		Integer.parseInt(val);
		return true;
	} catch (NumberFormatException nfex) {
		return false;
	}
}
}


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

using namespace std;

int main() {
  int N, D;
  cin >> N >> D;
  vector<double> X(N), Y(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (sqrt(pow(X[i], 2) + pow(Y[i], 2)) <= D) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6500
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


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

int N;
cin >> N;
double ans = 0;
rep(i,N) {
    double x;
    string u;
    cin >> x >> u;
    if(u == "BTC") x*= 380000.0;
    ans += x;
}

cout << fixed << setprecision(8) << ans << endl;

return 0;
}

Measured memory_bytes: 256
$/=get.words;$_=sort -*,get.words;$!={+.grep(*==.[$1-1])};
#say .[^$1].sum/$1;($!(.[^$1]),+$1..($!()min+$2))[.[$1-1]==.[0]]>>.&{combinations($!(),$_).elems}.sum.say
(.[^$1].sum/$1,($!(.[^$1]),+$1..($!()min+$2))[.[$1-1]==.[0]]>>.&{combinations($!(),$_).elems}.sum).put

Measured memory_bytes: 80752
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

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



int solve()
{
    int N;

    std::cin >> N;

    ll sum = 0;

    vector<vector<vector<ll>>> cache(201, vector<vector<ll>>(201, vector<ll>(201, -1)));
    vector<ll> tmp(3);

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            for (int k = 1; k <= N; ++k) {
/*
                tmp[0] = i;
                tmp[1] = j;
                tmp[2] = k;

                std::sort(tmp.begin(), tmp.end());

                if (cache[tmp[0]][tmp[1]][tmp[2]] != -1)
                    sum += cache[tmp[0]][tmp[1]][tmp[2]];
                else {
                    ll res = gcd(i, gcd(j, k));
                    sum += res;
                    cache[tmp[0]][tmp[1]][tmp[2]] = res;
                }
*/
                sum += gcd(i, gcd(j, k));
            }
        }
    }

    cout << sum << endl;

    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

Measured memory_bytes: 68260
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string.h>
using namespace std;

#define HUNDRED 100
#define THOUSAND 10000
#define TENTHOUSAND 10000
#define HUNDREDTHOUSAND 100000
#define ALPHABET 26

//int kaibun(int number);

int main() {
	int n,m;
	vector<int> a;
	vector<int> b;
	int temp1, temp2;

	vector<int> num(51,0);


	cin >> n >> m;


	for(int i=0; i < m; i++){
		cin >> temp1 >> temp2;
		a.push_back(temp1);
		b.push_back(temp2);
	}

	for(int j = 0; j < m; j++){
		num[a[j]]++;
		num[b[j]]++;
	}

	for(int k = 1 ; k <= n; k++){
		cout << num[k] << '\n';
	}
}

Measured memory_bytes: 256