akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;

    if(a + b <= 2 * c){
        ans += (a + b) * min(x, y);
    }
    else{
        ans += (2 * c) * min(x, y);
    }

    if(x < y){
        if(b <= 2 * c){
            ans += b * (y - x);
        }
        else{
            ans += (2 * c) * (y - x);
        }
    }
    else{
        if(a <= 2 * c){
            ans += a * (x - y);
        }
        else{
            ans += (2 * c) * (x - y);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3556
n = int(input())
a = [int(i) for i in input().split()]

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


for i in range(n):
    dp[i][i] = 0


for j in range(1, n + 1):
    for i in range(n+1):
        if i + j <= n:
            if j % 2 == n % 2:
                dp[i][i+j] = max(dp[i][i+j-1]+a[i+j-1], a[i]+dp[i+1][i+j])
            else:
                dp[i][i+j] = min(dp[i][i+j-1], dp[i+1][i+j])

print(2*dp[0][n]-sum(a))


Measured memory_bytes: 113628
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <algorithm>
#include <tuple>
#include <utility>
#include <cassert>
using namespace std;

const int INF = 1 << 29;
int dp[4010][4010], nval[4010][4010], visited[4010][4010];
pair<int, int> nxt[4010][4010];

int main() {
    string s, t; cin >> s >> t;
    int N = s.size(), M = t.size();

    // 何もないのを追加するので
    vector< vector<int> > nxtS(N+2, vector<int>(2));
    vector< vector<int> > nxtT(M+2, vector<int>(2));

    // 逆向きだった・・・
    {
        int p[2] = {N+1, N+1};
        nxtS[N+1][0] = nxtS[N+1][1] = N+1;
        nxtS[N  ][0] = nxtS[N  ][1] = N+1;
        for(int i=N-1; i>=0; i--) {
            p[ s[i] - '0' ] = i + 1;
            for(int j=0; j<2; j++) {
                nxtS[i][j] = p[j];
            }
        }
    }
    
    {
        int p[2] = {M+1, M+1};
        nxtT[M+1][0] = nxtT[M+1][1] = M+1;
        nxtT[M  ][0] = nxtT[M  ][1] = M+1;
        for(int i=M-1; i>=0; i--) {
            p[ t[i] - '0' ] = i + 1;
            for(int j=0; j<2; j++) {
                nxtT[i][j] = p[j];
            }
        }
    }

    fill(dp[0], dp[N+5], INF);
    fill(nval[0], nval[N+5], INF);
    dp[N+1][M+1] = 0;
    for(int i=N+1; i>=0; i--) {
        for(int j=M+1; j>=0; j--) {
            for(int k=0; k<2; k++) {
                int ni = nxtS[i][k], nj = nxtT[j][k];
                if(dp[i][j] > dp[ni][nj] + 1 or
                   (dp[i][j] == dp[ni][nj] + 1 and nval[i][j] > k)) {
                    dp[i][j] = dp[ni][nj] + 1;
                    nval[i][j] = k;
                    nxt[i][j] = make_pair(ni, nj);
                }
            }
        }
    }

    int x = 0, y = 0;
    string ans = "";
    while(x != N+1 or y != M+1) {
        ans += (char)('0' + nval[x][y]);
        tie(x, y) = nxt[x][y];
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 254276
//ビームサーチ
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

const int N = 26;
int D;
int c[N];
int s[365][N];

struct State {
	int lasts[N];
	int day, score;
	
	State() {}
	State(int lasts[], int day, int score) {
		for (int i = 0; i < 26; i++) this->lasts[i] = lasts[i];
		this->day = day;
		this->score = score;
	}

	//次の日t(0～25). 状態の更新.
	State next_state(int t) {
		State ret = *this;
		ret.lasts[t] = day;
		ret.score = score + s[day][t];
		for (int i = 0; i < N; i++) {
			ret.score -= c[i] * (day - ret.lasts[i]);
		}
		ret.day++;
		return ret;
	}

	bool operator>(const State &r) const {
		return score > r.score;
	}

	bool operator==(State &r) {
		if (day != r.day) return false;
		if (score != r.score) return false;
		for (int i = 0; i < 26; i++) if (lasts[i] != r.lasts[i]) return false;
		return true;
	}
};

int width = 300;
priority_queue<State, vector<State>, greater<State>> que[366];
vector<State> states[366];

int main() {
	int i, j;

	cin >> D;
	rep(i, N) cin >> c[i];
	rep(i, D) rep(j, N) cin >> s[i][j];

	int lasts[N];
	rep(i, N) lasts[i] = -1;
	State init_state(lasts, 0, 0);

	que[0].push(init_state);
	rep(i, D) {
		while (!que[i].empty()) {
			State now = que[i].top();
			states[i].push_back(now);
			que[i].pop();
			
			rep(j, N) {
				State next_s = now.next_state(j);
				que[i + 1].push(next_s);
				if (que[i + 1].size() > width) {
					que[i + 1].pop();
				}
			}
		}
	}

	State final_state = que[D].top();
	
	//というわけで出力.
	int ans[365];
	for (i = D - 1; i >= 0; i--) {
		for (j = 0; j < states[i].size(); j++) {
			int k;
			rep(k, N) {
				State next_state = states[i][j].next_state(k);
				if (next_state == final_state) {
					ans[i] = k;
					final_state = states[i][j];
					break;
				}
			}
			if (k < N) break;
		}
		if (j == states[i].size()) assert(0);
	}

	for (i = 0; i < D; i++) {
		cout << ans[i] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 30352
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
  h=min(h,2*q);
  s=min(s,2*h);
  d=min(d,2*s);
  cout << n/2*d+n%2*s << endl;
}

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

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

  char ans='a';
  bool flg;
  for(char c='a'; c<='z'; c++){
    flg=true;
    for(int i=0; i<s.size(); i++){
      if(c==s[i]){
        flg=false;
        break;
      }
    }
    if(flg){
      cout<<c<<endl;
      break;
    }
  }
  if(!flg)cout<<"None"<<endl;
}


Measured memory_bytes: 512
n,y=map(int,input().split())

yn=""
na=min(y//10000,2000)
nb=min(y//5000,2000)
for a in range(na+1):
    for b in range(nb+1):
        if y==10000*a+5000*b+1000*(n-a-b) and n>=a+b:
            print(a,b,n-a-b)
            yn="YES"
            break
    if yn=="YES":
        break
if yn!="YES":
    print(-1,-1,-1)
        

Measured memory_bytes: 3064
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

total = 0
for i in range(n):
    temp = min(aa[i], bb[i])
    total += temp
    aa[i] -= temp
    if aa[i] < bb[i]:
        temp_n = min(bb[i]-temp, aa[i+1])
        total += temp_n
        aa[i+1] -= temp_n
print(total)
    

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

int main(void) {
  int r, g, b;
  cin >> r >> g >> b;
  int x = r * 100 + g * 10 + b;
  if(x % 4) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> S.at(i);
		sort(S.at(i).begin(), S.at(i).end());
	}
	vector<vector<int>> chara(26, vector<int>(N));
	for (size_t i = 0; i < N; i++)
	{
		for (size_t j = 0; j < S.at(i).size(); j++)
		{
			chara.at(int(S.at(i).at(j) - 'a')).at(i)++;
		}
	}
	for (size_t i = 0; i < 26; i++)
	{
		sort(chara.at(i).begin(), chara.at(i).end());
	}
	for (size_t i = 0; i < 26; i++)
	{
		for (size_t j = 0; j < chara.at(i).at(0); j++)
		{
			cout << char('a' + i);
		}
	}
	
}

Measured memory_bytes: 256
package main
 
import "fmt"
 
func main(){
	var a, b int
	fmt.Scan(&a,&b)
	if a+b == 15 {
		fmt.Println("+")
	} else if a*b == 15 {
		fmt.Println("*")
	} else {
		fmt.Println("x")
	}
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
 int i, j, x, y;
 do {
  scanf("%d%d", &x, &y);
  for(i = 0; i < x; i++) {
   for(j = 0; j < y; j++) {
    printf("#");
   }
   printf("\n");
  }
  if(x != 0 && y != 0)
   printf("\n");
  
 } while(x != 0 && y != 0);
 return 0;
}

Measured memory_bytes: 572
#include <cstdio>

int main()
{
	int InArray[200000] = {0};		// end is linked to start (Baumkuchen is round)
	int N;							// total data input
	int i;							// for counter
	int inputBuffer;				// buffer for input data
	int a1, a2, a3;					// the start index of each region
	long long sum;					// buffer for sum
	long long average, average2;	// sum / 3, (sum - region1) / 2
	long long a1_sum, a2_sum;		// sum of region1, region2
	long long MaxMin;				// final result
	
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d", &inputBuffer);
		InArray[i] = inputBuffer;
		InArray[i + N] = inputBuffer;
	}

	
	// Calculate sum and average
	sum = 0;
	for(i = 0; i < N; i++){
		sum += InArray[i];
	}
	if(sum % 3 == 0){
		average = sum / 3;
	}else{
		average = sum / 3 + 1;
	}
	
	MaxMin = 0;
	for(a1 = 0; a1 < N; a1++){
		a1_sum = 0;
		for(a2 = a1 + 1; a2 < (a1 + N); a2++){
			a1_sum += InArray[a2 - 1];
			if(a1_sum < average) continue;
			
			if((sum - a1_sum) % 2 == 0){
				average2 = (sum - a1_sum) / 2;
			}else{
				average2 = (sum - a1_sum + 1) / 2;
			}
			
			a2_sum = 0;
			for(a3 = a2 + 1; a3 < (a1 + N); a3++){	// left 1 for a3_sum
				a2_sum += InArray[a3 -1];
				if(a2_sum < average2) continue;
								
				if(a2_sum - InArray[a3 -1] > MaxMin){
					MaxMin = a2_sum - InArray[a3 -1];
				}
				if(sum - a1_sum - a2_sum   > MaxMin){
					MaxMin = sum - a1_sum - a2_sum;
				}
				break;
			}
			break;
		}
	}
	
	printf("%lld\n", MaxMin);
	
	return 0;
}

Measured memory_bytes: 3504
n=int(input())
s=[0 for i in range(4)]

for i in range(n):
    ss=input()
    if("AC"==ss):s[0]+=1
    if("WA"==ss):s[1]+=1
    if("TLE"==ss):s[2]+=1
    if("RE"==ss):s[3]+=1

print("AC","x",s[0])
print("WA","x",s[1])
print("TLE","x",s[2])
print("RE","x",s[3])

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000
int N,M,L,A,B;
int K[MAX_N];
int ans;
vector<char> C;
bool bool_ans;

int solve(void) {


  return ans;
}

int main (void)
{
  cin >> N >> A >> B;
  rep(i,0,N) {





  }

  ans = min(N*A,B);


  // ans = solve();
  put(ans);
  // if (ans) {
  //   put("Yes");
  // } else {
  //   put("No");
  // }

  return 0;
}


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

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)

//変数
ll N;
vector<ll> A;

//解法
void solve() {

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

	ll b1 = A[(N-1) / 2];
	ll b2 = A[(N-1) / 2 + 1];

	ll ans1 = 0,ans2=0;
	rep(i, N) {
		ans1 += abs(A[i] - b1);
		ans2 += abs(A[i] - b2);
	}

	cout << min(ans1,ans2);

	return;
}

int main() {
	//入力
	cin >> N;
	A.resize(N);
	rep(i, N) {
		cin >> A[i];
		A[i] -= i + 1;
	}
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#define endl "\n"
#define SRK ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EPS 1e-6
typedef long long ll;
using namespace std;



int main()
{
    SRK;
    int x;
    cin >> x;
    if (x == 0)
    {
        cout << "1\n";
    }
    else
    {
        cout << "0\n";
    }
}


Measured memory_bytes: 3604
from itertools import accumulate

n = int(input())
csfs = [[int(x) for x in input().split()] for _ in range(n-1)]

def make_func(c, s, f):
    def func(t):
        t = max(t, s)
        a, b = divmod(t, f)
        return f * (a + (b != 0)) + c
    return func

funcs = [make_func(*csf) for csf in csfs]
funcs2 = accumulate(funcs[::-1], func=lambda f1, f2: lambda x: f1(f2(x)))

res = [0] + [f(0) for f in funcs2]
for time in reversed(res):
    print(time)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if( U == S ){
  	A--;
  }
  if( U == T){
    B--;
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main(){
	IOS;
	{
		cout<<"? 10000000000"<<endl;
		string type;
		cin>>type;
		if(type[0]=='Y'){
			string tmp="2";
			while(1){
				cout<<"? "<<tmp<<endl;
				string an;
				cin>>an;
				if(an[0]=='Y'){
					tmp[0]='1';
					cout<<"! "<<tmp<<endl;
					return 0;
				}
				tmp.pb('0');
			}
		}
	}

	int len=0;
	{
		string tmp="1";
		while(len<15){
			len++;
			cout<<"? "<<tmp<<endl;
			string an;
			cin>>an;
			if(an[0]=='Y');
			else break;
			tmp.pb('0');
		}
	}
	len--;


	ll l=1,r=1;
	REP(I,len-1) l*=10;
	r=l*10-1;
	while(l!=r){
		ll mid=(l+r)/2;
		// cout<<l<<' '<<r<<endl;
		cout<<"? "<<mid<<'9'<<endl;
		string an;
		cin>>an;
		if(an[0]=='Y') r=mid;
		else l=mid+1;
	}
	cout<<"! "<<l<<endl;
	return 0;
}


Measured memory_bytes: 596
#include <stdio.h>

using namespace std;

using ll = long long;

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

const ll mod = 998244353;

class matrix {
public:
  ll d[2][2];
  matrix operator*(const matrix& m) {
    matrix r;
    rep(i, 2) {
      rep(j, 2) {
        r.d[i][j] = 0;
      }
    }
    rep(i, 2) {
      rep(j, 2) {
        rep(k, 2) {
          r.d[i][j] = (r.d[i][j] + d[i][k] * m.d[k][j]) % mod;
        }
      }
    }
    return r;
  }
};

ll fibo(ll n) {
  matrix r;
  rep(i, 2) {
    rep(j, 2) {
      if(i == j) {
        r.d[i][j] = 1;
      }
      else {
        r.d[i][j] = 0;
      }
    }
  }
  matrix m;
  m.d[0][0] = 1;
  m.d[0][1] = 1;
  m.d[1][0] = 1;
  m.d[1][1] = 0;
  while(n > 0) {
    if(n & 1) {
      r = r * m;
    }
    m = m * m;
    n >>= 1;
  }
  return r.d[1][0];
}

ll inv(ll n) {
  ll r = 1;
  ll w = mod - 2;
  while(w > 0) {
    if(w & 1) {
      r = (r * n) % mod;
    }
    n = (n * n) % mod;
    w >>= 1;
  }
  return r;
}

int main() {
  ll n, m;
  scanf("%lld%lld", &n, &m);
  ll a = fibo(m + (n - 1) * 2);
  ll now = 1;
  ll l = m + (n - 1) * 2 - 1;
  ll r = 0;
  for(int i = 2; i <= n; i++) {
    a = (a + mod - now) % mod;
    now = (now * ((l - r) % mod)) % mod;
    now = (now * ((l - r - 1) % mod)) % mod;
    now = (now * inv(l % mod)) % mod;
    now = (now * inv(r + 1)) % mod;
    l--;
    r++;
  }
  printf("%lld\n", a);
}


Measured memory_bytes: 256
#include <stdio.h>

int n;
char s[30010];
int g[30010];
int ch[20][20];
int sum;

int main(void)
{
	scanf("%d", &n);
	scanf("%s", s);
	
	for(int i = 0 ; i < n ; i++)
	{
		int check[20] = {0, };
		
		for(int j = i + 1 ; j < n ; j++)
		{
			if(check[s[j] - '0'] == 0)
			{
				check[s[j] - '0'] = 1;
				g[i]++;
			}
		}
	}
	
	for(int i = 0 ; i < n ; i++)
	{
		for(int j = i + 1 ; j < n ; j++)
		{
			if(ch[s[i] - '0'][s[j] - '0'] == 1)
				continue;
			
			ch[s[i] - '0'][s[j] - '0'] = 1;
			
			sum += g[j];
		}
	}
	
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int n,p;
int solve(){
  int cnt=0;
  int t[50]={};
  for(int i=0;;i=(i+1)%n){
    if(p==0){
      if(t[i]>0)cnt--;
      p=t[i];
      t[i]=0;
    }else{
      if(t[i]==0)cnt++;
      t[i]++;
      p--;
      if(p==0&&cnt==1)return i;
    }
  }
}
int main(){
  while(1){
    cin>>n>>p;
    if(n==0&&p==0)break;
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
# import numpy as np
# import itertools as it

n = int(input())
a = list(map(int, input().split()))

res = 0
for i in range(n):
    res += a[i] * a[i]

ans = sum(a) * sum(a)
print(((ans - res)//2) % (10 ** 9 + 7))


# sum = 0
# for i in range(n):
#     sum += 1 / a[i]
#print(sum)

# ans = int(sum * np.prod(a))
# print(ans % (10 ** 9 + 7))


Measured memory_bytes: 31656
#include <iostream>
#include <vector>
#include <cstdlib>

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

const long long INF = 1LL << 60;

#define MOD 1000000007

int N;

int main(){

    int n;

    cin >> n;

    vector<int> nlist;

    while(n != 0){
        nlist.push_back(n);
        cin >> n;
    }

    vector<int> res(30+1, 0);

    res[0] = 0;
    res[1] = 1;
    res[2] = 2;
    res[3] = 4;

    for(int i = 4; i <= 30; i++){
        res[i] = res[i-3] + res[i-2] + res[i-1];
    }

    for(int i = 0; i < nlist.size(); i++){
        cout << res[nlist[i]]/(365*10) + 1 << endl;
    }
}


Measured memory_bytes: 3124
#include<iostream>
using namespace std;
int main(){
    int asd[100];
    int i,num;
    cin>>num;
    for(i=0;i<num;i++){
        cin >> asd[i];
        
    }
    cout << asd[num-1];
    for(i=1;i<num;i++){
        cout <<" "<< asd[num-i-1];
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3088
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.trim().split_whitespace();
	for i in iter {
		let s:Vec<char> = i.chars().collect::<Vec<char>>();
		print!("{}", s[0]);
	}
	println!("");
}

Measured memory_bytes: 4352
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val str = inputs(1)

  println(solve(str))

  private def solve(str: String): Int = {
    val size   = str.size

    var result = 0

    (1 until size).foreach { i =>
      val part = str.splitAt(i)
      val left = part._1.toSet
      val right = part._2.toSet

      val count = left.filter(right.contains(_)).size
      if (result < count) {
        result = count
      }
    }
    result
  }
}

Measured memory_bytes: 60524
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

vector<int> to[101];
int d[101][101];
vector<tuple<int,int,int>> e;

int main(){
    int n,m;
    cin >> n>> m;
    rep(i,n){
        rep(j,n){
            d[i][j]=INF;
            if(i==j){
                d[i][j]=0;
            }
        }
    }
    cerr<<"ch1"<<endl;
    rep(i,m){
        int a,b,c;
        cin >> a>> b>> c;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
        d[a][b]=c;
        d[b][a]=c;
        e.emplace_back(a,b,c);
    }
    cerr<<endl;
    cerr<<"ch2"<<endl;
    rep(k,n){
        rep(i,n){
            rep(j,n){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    rep(i,n){
        rep(j,n){
            cerr<<d[i][j]<<' ';
        }
        cerr<<endl;
    }
    cerr<<"ch3"<<endl;
    int ans=0;
    rep(p,m){
        int i,j,k;
        int q=1;
        tie(i,j,k)=e[p];
        rep(s,n){
            rep(t,n){
                if(d[s][i]+k+d[j][t]==d[s][t]){
                    if(q>0){
                        cerr<<s+1<<' '<<t+1<<' ';
                        cerr<<i+1<<' '<<j+1<<' '<<k<<endl;
                    }
                    q=0;
                }
            }
        }
        if(q>0){
            cerr<<i+1<<' '<<j+1<<' '<<k<<endl;
        }
        ans+=q;
    }
    cerr<<"ch4"<<endl;
    cout<<ans<<endl;
    return 0;
}

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

ll f=1000000007;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void ncrinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long ncr(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ncrinit();
  
  ll n;
  ll k;
  cin>>n>>k;
  ll s=0;
  ll a;
  
  rep(i,min(n,k+1)){
    a=ncr(n-1,i)*ncr(n,i)%f;
    s=(s+a)%f;
  }
  cout<<s<<endl;
  
  
} 
  


Measured memory_bytes: 12160
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			String str = scanner.next();

			for (int i = 0; i < n; i++) {
				StringBuilder builder = new StringBuilder();
				int count = 1;
				str = str + " ";
				for (int j = 1; j < str.length(); j++) {
					if (str.charAt(j) == str.charAt(j - 1))
						count++;
					else {
						builder.append(count);
						builder.append(str.charAt(j - 1));
						count = 1;
					}
				}
				str = builder.toString();
			}
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 24240
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  VI a(n); for (int i = 0; i < n; i++) cin >> a[i];
  
  for (int i = 0; i < n; i++) {
    a[i] -= i;
  }
  sort(a.begin(), a.end());
  lint res = 0;
  int m = a[(n - 1) / 2];
  for (int i = 0; i < n; i++) {
    res += abs(a[i] - m);
  }
  m = a[n / 2];
  lint tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp += abs(a[i] - m);
  }
  res = min(res, tmp);
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	int N,i;

	int a[3];

	cin >> N;

	for(i=0;i<N;i++){
		a[0] = (N+i)/100;
		a[1] = ((N+i)%100)/10;
		a[2] = ((N+i)%10);

		if(a[0] == a[1] && a[1] == a[2]){
			cout << N+i << endl;
			return 0;
		}
	}

	cout << "Not" << endl;

	return 0;
}

Measured memory_bytes: 256
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#endif

#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;

int main(){
	fastIO;
	string s;
	cin >> s;
	if (s.size() == 2) cout << s;
	else {
		reverse(all(s));
		cout << s;
	}
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n,m,l; cin>>n>>m>>l;
  Graph dist(n,vi(n,INF));
  rep(i,n) dist[i][i]=0;
  rep(i,m){
    int a,b,c; cin>>a>>b>>c;
    a--;b--;
    dist[a][b]=dist[b][a]=c;
  }
  rep(k,n)rep(i,n)rep(j,n) dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
  vvi dist2(n,vi(n,INF));
  rep(i,n)rep(j,n){
    if(dist[i][j]<=l) dist2[i][j]=1;
  }
  rep(k,n)rep(i,n)rep(j,n) dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]);
  int q; cin>>q;
  rep(i,q){
    int s,t; cin>>s>>t; s--; t--;
    int ans=dist2[s][t]-1;
    if(dist2[s][t]==INF) ans=-1;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 4296
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;

int a, b;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a >> b;
    if (b%a)
        cout << b - a << "\n";
    else
        cout << a + b << "\n";
	system("pause");
	//return 0;
}

Measured memory_bytes: 504
"use strict";

const main = arg => {
    const N = arg.split("\n")[0].split(" ").map(n=>parseInt(n)).sort((a,b)=>a-b);
    const K = arg.split("\n")[1];
    const target = N.reduce((m,n)=>m>n?m:n) * Math.pow(2, K);
    N.pop();
    N.push(target);
    
    console.log(N.reduce((m,n)=>m+n));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21184
package main

import (
	"fmt"
)

func solution(a, b, k int64) []int64 {
	ans := make([]int64, 0, 2)
	if a >= k {
		a -= k
		ans = []int64{a, b}
	} else if a < k {
		k -= a
		a = 0
		b -= k
		if b < 0 {
			b = 0
		}
		ans = []int64{a, b}
	}
	return ans
}

func main() {
	var a, b, k int64
	fmt.Scan(&a, &b, &k)
	ans := solution(a, b, k)
	fmt.Printf("%d %d", ans[0], ans[1])
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j);a×b行列の入力
 
int main() {
  string s,t;
  ci(s>>t);
  ll a=0;
  for(i,0,3)
    if(s[i]==t[i])
      a++;
  co(a);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


int main() {
	int N;
	cin >> N;
	int z = 0, o = 0, t = 0;
	int cur;
	for (int i = 0; i < N; i++) {
		cin >> cur;
		if (cur % 4 == 0) t++;
		else if (cur % 2 == 0) o++;
		else z++;
	}
	if (z == t + 1 && o == 0) {
		cout << "Yes" << endl;
	}
	else if (z > t) {
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;
}

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

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)
 
def lcm(a, b):
    return a // gcd(a, b) * b

def calc(x,c,d):
    return x - x//c - x //d + x//lcm(c,d)

print(calc(b,c,d) - calc(a-1,c,d))

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

//#ifdef LOCAL
//#define eprintf(...) fprintf(stderr, __VA_ARGS__)
//#else
//#define NDEBUG
//#define eprintf(...) do {} while (0)
//#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


LL D;
int K;
int X[25];
LL TEN[25];
LL ans;
const LL INF = 1LL<<60;
LL diff;
void rec(int k) {
    if (K < k*2) {

	if (D == diff) {
	    LL base = 1;
	    for (int i=1; i*2<=K; i++) {
		base *= 10 - abs(X[i]);
	    }
	    base *= 9 + X[0];
	    ans += base;
	}
    } else if (K == k*2) {
	X[k] = 0;
	rec(k+1);
    } else {
	int h = 9;
	if (k == 0) h = 0;
	for (int i=-9; i<=h; i++) {
	    diff += i * (TEN[k] - TEN[K-k]);
	    if (D - (TEN[k] + TEN[K-k]) * 2 <= diff && diff <= D + (TEN[k] + TEN[K-k]) * 2) {
		X[k] = i;
		X[K-k] = -i;
		rec(k+1);
	    }
	    diff -= i * (TEN[k] - TEN[K-k]);
	}
    }
}

void MAIN() {
    TEN[0] = 1;
    REP (i, 24) TEN[i+1] = TEN[i] * 10;

    scanf("%lld", &D);
    for (K=1; K<=18; K++) {
	rec(0);
    }

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

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 a[] = new int[str.length + 1];

		for (int i = 0; i < str.length; i++) {
			if (str[i].equals("<")) {
				a[i + 1] = a[i] + 1;
			}
		}
		for (int i = str.length - 1; i >= 0; i--) {
			if (str[i].equals(">")) {
				a[i] = Math.max(a[i], a[i + 1] + 1);
			}
		}

		long sum = 0;
		for (int i : a) {
			sum += i;
		}

		System.out.println(sum);
	}

	static long getSum(int s, int e) {
		long sum = 0;
		for (int i = s; i <= e; i++) {
			sum += i;
		}
		return sum;
	}
}

Measured memory_bytes: 80676
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> h(n);
    for(int i=0;i<n;i++)cin>>h[i];
    vector<int> edge[d5];
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    int res=0;
    for(int i=0;i<n;i++){
        bool ok=true;
        for(auto it:edge[i]){
            if(h[i]<=h[it])ok=false;
        }
        res+=ok;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 9764
// Problem : C - String Transformation
// Contest : AtCoder - AtCoder Beginner Contest 110
// URL : https://atcoder.jp/contests/abc110/tasks/abc110_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	map<char,char> map,map2;
	string s ,t;
	cin>>s>>t;
	loop(i,sz(s))
	{
		if(map.find(s[i])!=map.end())
		{
			if(map[s[i]]!=t[i])
			{
				cout<<"No";
				return 0;
			}
		}
		else
			map[s[i]]=t[i];
		if(map2.find(t[i])!=map2.end())
		{
			if(map2[t[i]]!=s[i])
			{
				cout<<"No";
				return 0;
			}
		}
		else
			map2[t[i]]=s[i];
	}
	cout<<"Yes"<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3788
h,w=map(int,input().split())
grid=[["."]*(w+2)]+[list("."+input()+".")for i in range(h)]+[["."]*(w+2)]
for s in range(1,1+h):
    for t in range(1,1+w):
        if grid[s][t]=="#" and all([grid[s+x][t+y]=="."for x,y in ([0,-1],[0,1],[1,0],[-1,0])]):
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3064
let swap a i j =
  let temp = a.(i) in
  a.(i) <- a.(j);
  a.(j) <- temp
;;

let partition a p r =
  let x = a.(r) and
      i = ref (p-1) in
  for j = p to r-1 do
    if a.(j) <= x then
      begin
        i := !i + 1;
        swap a (!i) j;
      end;
  done;
  swap a (!i+1) r;
  !i+1
;;

let print a p =
  for i = 0 to ((Array.length a)-1) do
    if i = p then
      Printf.printf "[%d]" a.(i)
    else
      Printf.printf "%d" a.(i);
    if i != ((Array.length a)-1) then
      Printf.printf " "
    else
      Printf.printf "\n"
  done
;;

let () =
  let n = read_int () and
      a = read_line ()
          |> Str.split (Str.regexp " ")
          |> List.map int_of_string
          |> Array.of_list
  in
  let p = partition a 0 (n-1) in
  print a p
;;

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

using namespace std;

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

	int Q = max({ A,B,C });
	int W = (A + B + C) - min({ A,B,C }) - Q;

	cout << Q * 10 + W + min({ A,B,C }) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
const int p[]={-1,0,1,0};
const int v[]={0,-1,0,1};

int main(){
  int h,w; cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  int ans=0;
  
  rep(i,h)rep(j,w){
      if(s[i][j]=='#') continue;
      vector<vector<int>> d(h,vector<int>(w,-1));
      queue<P> wa;
      wa.push(P(i,j));
      d[i][j]=0;
      while(!wa.empty()){
          int nowi=wa.front().first;
          int nowj=wa.front().second;
          wa.pop();
         rep(dir,4){
             int ni=nowi+p[dir]; int nj=nowj+v[dir];
             if(ni<0||ni>=h||nj<0||nj>=w) continue;
             if(s[ni][nj]=='#') continue;
             if(d[ni][nj]!=-1) continue;
             wa.push(P(ni,nj));
             d[ni][nj]=d[nowi][nowj]+1;
         }
      }
    rep(aa,h)rep(bb,w){
        ans=max(ans,d[aa][bb]);
    }
  }
  cout << ans << endl;
 return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a[5];
    scanf("%d\n%d\n%d\n%d\n%d", &a[0], &a[1], &a[2], &a[3], &a[4]);
    int ans = 0;
    int minMod = 10;
    for (int i=0; i<5; i++)
    {
        int mod = a[i] % 10;
        if (mod != 0)
        {
            ans += a[i] + 10 - a[i] % 10;
            if (mod < minMod)
                minMod = mod;
        }
        else
            ans += a[i];
    }
    printf("%d\n", ans - 10 + minMod);
}

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

using namespace std;

typedef long long ll;

const int MAXN = 300 + 5;
const int MOD = 1e9 + 7;

int n, m, d[MAXN][MAXN][MAXN];
int ans = 0;

int main(){
	cin >> n >> m;
	d[0][1][0] = 1;
	for (int i = 0; i < m; i++)
		for (int j = 1; j <= n; j++)
			for (int w = 0; w <= n; w++){
				if (j + w < n){
					d[i + 1][j + 1][w] = (d[i + 1][j + 1][w] + 1ll * (n-j-w) * d[i][j][w]) % MOD;
					d[i + 1][j][w + 1] = (d[i + 1][j][w + 1] + 1ll * (n-j-w) * d[i][j][w]) % MOD;
				}
				d[i + 1][j - 1][w + 1] = (d[i + 1][j - 1][w + 1] + 1ll * j * d[i][j][w]) % MOD;
				d[i + 1][j][w] = (d[i + 1][j][w] + 1ll * j * d[i][j][w]) % MOD;
			}

	cout << d[m][0][n] << "\n";
	return 0;
}


Measured memory_bytes: 109056
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
ll N, C;

ll cal(vll x, vll v) {
	vll a(N +1,0), b(N + 1,0);

	repn(i, N)a[i] = a[i - 1] + v[i];
	for (ll i = N - 1; i >= 0; i--) { b[i] = b[i + 1] + v[i + 1]; }
	
	rep(i, N+1)a[i] -= x[i] * 2;
	rep(i, N)b[i] -= (C - x[i + 1]);

	//rep(i, N + 1)cout << a[i] << " ";
	//cout << endl;
	//rep(i, N + 1)cout << b[i] << " ";
	//cout << endl;

	vll bmx(N + 1);
	bmx[N] = b[N];
	for (ll i = N - 1; i >= 0; i--) { bmx[i] = max(b[i], bmx[i + 1]); }

	ll ans = -INF;
	rep(i, N + 1)ans = max(ans, a[i] + bmx[i]);

	return ans;
	
}
int main() {
	cin >> N >> C;
	vll x(N + 1,0), v(N + 1,0);
	repn(i, N) cin >> x[i] >> v[i];

	ll ans = cal(x, v);

	vll xrev(N + 1,0), vrev(N + 1,0);
	repn(i, N) {
		xrev[i] = C - x[N + 1 - i];
		vrev[i] = v[N + 1 - i];
		//cout << xrev[i] << vrev[i] << endl;
	}

	ll ans2 = cal(xrev, vrev);

	cout << max(ans, ans2) << endl;
}

Measured memory_bytes: 10252
n = int(input())
a = list(map(int,input().split()))
dist = [0]*100000
ans = sum(a)
for i in a:
    dist[i-1] += 1

q = int(input())
for i in range(q):
    b,c = map(int,input().split())
    if dist[b-1] != 0:
        dist[c-1] += dist[b-1]
        ans += dist[b-1] * (c-b)
        dist[b-1] = 0
    print(ans)


Measured memory_bytes: 84468
#include<bits/stdc++.h>
using namespace std;
int swap(int *a,int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
}
int main()
{
    int n,count=1,p=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n-1;i++)
    {   if(a[i+1]<a[i])
          count++;
          else
          swap(a+i+1,a+i);
    }
    cout<<count;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  map<int,int> v1,v2;
  rep(i,n/2) {
    int a,b;
    cin >> a >> b;
    v1[a]++; v2[b]++;
  }
  priority_queue<P> q1,q2;
  for(auto i:v1) q1.emplace(i.second,i.first);
  for(auto i:v2) q2.emplace(i.second,i.first);
  vector<P> p1(2,P(n/2,0)),p2(2,P(n/2,0));
  rep(i,2) if(!q1.empty()){ P p = q1.top(); q1.pop(); p1[i] = p;}
  rep(i,2) if(!q2.empty()){ P p = q2.top(); q2.pop(); p2[i] = p;}
  int ans = n;
  rep(i,2)rep(j,2) {
    if(p1[i].second == p2[j].second) continue;
    int res = n;
    if(p1[i].second!=0) res -= p2[j].first;
    if(p2[j].second!=0) res -= p1[i].first;
    ans = min(ans,res);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6136
#include <iostream>
#include <stdio.h>

using namespace std;

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

	for (int i = 1; i <= n; i++){
		if (i % 3 == 0) cout << " " << i;
		else {
			x = i;
			do {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /=  10;
			} while (x);
		}
	}
	cout << endl;
}


Measured memory_bytes: 3092
[x, n] = [int(stdin) for stdin in input().split()]
p = [int(stdin) for stdin in input().split()]

diff = 0
while True:
    if (x - diff) not in p:
        ans = x - diff
        break
    elif (x + diff) not in p:
        ans = x + diff
        break
    else:
        diff += 1

print(ans)


Measured memory_bytes: 9176
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));

    int min = 0;
    int max = n;    
    while(max - min > 1) {
        int mid = (max + min) / 2;
        if(abs(a[mid] * 2 - a.back()) - abs(a[mid - 1] * 2 - a.back()) < 0) min = mid;
        else max = mid;
    }
    cout << a.back() << " " << a[min] << endl;
      
    return 0;
}


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

int main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double kaku;
    if(h/12.0 + m/720.0 > m/60.0) kaku = h/12.0 + m/720.0 - m/60.0;
    else kaku = m/60.0 - (h/12.0 + m/720.0);

    if(kaku > 0.5) kaku = 1 - kaku;
    
    kaku *= 2;
    kaku *= 3.1415926535;

    double ans = a*a + b*b;
    ans -= 2*a*b*cos(kaku);
    ans = sqrt(ans);

    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 4212
//解法①

#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {

	string s;
	cin >> s;
	rep(i, s.size()) {
		for (int j = i + 1; j < s.size(); j++) {
			if (s[i] == s[j]) {
				cout << "no" << rt;
				return 0;
			}
		}
	}
	cout << "yes" << rt;

	please AC;
}
//参考：---;

Measured memory_bytes: 256