akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main(){
  int w,h,dire,i,j,l,x,y;
  string order;
  while(1){
    cin >> w >> h;
    if(w==0&&h==0) break;
    x=1;
    y=1;
    dire=0;//テ、ツクツ?テ・ツ渉ウ1テ、ツクツ?テ・ツキツヲ3
    while(1){
      cin >> order;
      if(order=="STOP") break;
      else if(order=="LEFT"){
	dire--;
	if(dire==-1) dire=3;
      }
      else if(order=="RIGHT"){
	dire++;
	if(dire==4) dire=0;
      }
      else if(order=="FORWARD"){
	cin >> l;
        if(dire==0){
	  if(y+l>h) y=h;
          else y+=l;
	}
	else if(dire==1){
	  if(x+l>w) x=w;
	  else x+=l;
	}
	else if(dire==2){
	  if(y-l<1) y=1;
	  else y-=l;
	}
	else if(dire==3){
	  if(x-l<1) x=1;
	  else x-=l;
	}
      }
      else if(order=="BACKWARD"){
	cin >> l;
        if(dire==0){
	  if(y-l<1) y=1;
	  else y-=l;
	}
	else if(dire==1){
	  if(x-l<1) x=1;
	  else x-=l;
	}
	else if(dire==2){
	  if(y+l>h) y=h;
          else y+=l;
	}
	else if(dire==3){
	  if(x+l>w) x=w;
	  else x+=l;
	}
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}

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

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000'000'007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)


ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//



int main()
{
	IOS

	ll n;
	cin >> n;
	vector<ll> c(n);
	for (ll i = 0; i < n; ++i)
	{
		cin >> c[i];
	}
	vector<ll> no_rep;
	for (ll i = 0; i < n; ++i)
	{
		ll ind = i;
		no_rep.push_back(c[i]);
		while (ind < n && c[i] == c[ind])
		{
			++ind;
		}
		--ind;
		i = ind;
	}

	vector<ll> last(202020 + 100, -1);
	vector<ll> prev(202020 + 10, -1);
	for (ll i = 0; i < no_rep.size(); ++i)
	{
		prev[i] = last[no_rep[i]];
		last[no_rep[i]] = i;
	}

	vector<ll> dp(n + 200, 0);
	dp[0] = 1;
	for (ll i = 1; i < no_rep.size(); ++i)
	{
		if (prev[i] == -1)
		{
			dp[i] = dp[i - 1];
			dp[i] %= MOD;
		} else
		{
			dp[i] = dp[i - 1] + dp[prev[i]];
			dp[i] %= MOD;
		}
	}
	cout << dp[no_rep.size() - 1];

	return 0;
}

Measured memory_bytes: 8304
#include<iostream>
#include<stack>
#include<string>

using namespace std;

bool isParindrome(string input) {
  auto left = input.begin();
  auto right = input.end()-1;
  while(left < right) {
    if (*left++ != *right--) return false;
  }
  return true;
}

int main() {
  string input = "";
  cin >> input;
  string first = input.substr(0, (input.size()-1)/2);
  string second = input.substr( (input.size()+3)/2 - 1 );
  bool res = isParindrome(input) && isParindrome(first) && isParindrome(second);
  if (res) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
typedef pair<int,int> P;
#define mod 1000000007

int main(){
    int a,b;
    cin >> a >> b;
    int ans=0;
    for(int i=a;i<=b;i++){
        string x;
        x=to_string(i);
        int keta=log10(i);
        int count=0;
        for(int j=0;j<=keta/2;j++){
            if(x[j]==x[keta-j]) count++;
        }
        if(count==1+keta/2) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
def solve(N, As):
    costs = [abs(As[0])]
    costs.extend([abs(s - d) for s, d in zip(As, As[1:])])
    s = sum(costs) + abs(As[-1])

    skipcosts = [abs(As[1])]
    skipcosts.extend([abs(s - d) for s, d in zip(As, As[2:])])
    skipcosts.append(0)
    ans = []
    for i, c in enumerate(skipcosts):
        if i < N - 1:
            ans.append(str(s - costs[i] - costs[i + 1] + c))
        else:
            ans.append(str(s - costs[i] - abs(As[-1]) + abs(As[-2])))
    return "\n".join(ans)


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


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

const int N = 100005;

int n, m;
int par[N];
long long a[N];
long long w[N];
bool visit[N];
bool good[N];
vector<pair<int,int>> g[N];
int cnt;

struct edge {
	int from, to, id;
	edge(int from = 0, int to = 0,int id = 0) : from(from), to(to), id(id) {}
	bool operator < (const edge &e) const {
		return w[id] < w[e.id];
	}
};

vector<edge> eds;

int anc(int u) {
	if (par[u] == u) {
		return u;
	} else {
		return par[u] = anc(par[u]);
	}
}

void join(int u,int v) {
	u = anc(u), v = anc(v);
	if (u ^ v) {
		par[v] = u;
		a[u] += a[v];
	}
}

void dfs(int u,long long lim) {
	for (auto e : g[u]) {
		int v = e.first;
		int id = e.second;
		if (visit[id]) {
			continue;
		} else if (w[id] <= lim) {
			++cnt;
			visit[id] = true;
			dfs(v, lim);
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", a + i);
		par[i] = i;
	}
	for (int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d %d %lld", &u, &v, w + i);
		g[u].push_back(make_pair(v, i));
		g[v].push_back(make_pair(u, i));
		eds.push_back(edge(u, v, i));
	}
	sort(eds.begin(), eds.end());
	int l = 0;
	while (l < m) {
		int r = l;
		while (r + 1 < m && w[eds[r + 1].id] == w[eds[r].id]) {
			++r;
		}
		for (int i = l; i <= r; ++i) {
			join(eds[i].from, eds[i].to);
		}
		for (int i = l; i <= r; ++i) {
			good[i] = w[eds[i].id] <= a[anc(eds[i].from)];
		}
		l = r + 1;
	}
	for (int i = eds.size() - 1; ~i; --i) {
		if (visit[eds[i].id]) {
			continue;
		} else if (good[i]) {
			dfs(eds[i].from, w[eds[i].id]);
		}
	}
	printf("%d\n", m - cnt);
}

Measured memory_bytes: 12084
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int ans[310][310];
int cnt[310];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    string S[310];
    rep(i, H) cin >> S[i];
    int kind = 0;
    
    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '#' && ans[i][j] == 0) {
                kind++;
                ans[i][j] = kind;
                int r = j;
                while(S[i][r + 1] != '#' && r + 1 < W && ans[i][r + 1] == 0) ans[i][++r] = kind;
                int l = j;
                while(S[i][l - 1] != '#' && l - 1 >= 0 && ans[i][l - 1] == 0) ans[i][--l] = kind;
                //cout << kind << " " << l << " " << r << endl;
                bool possible = true;
                int u = i - 1;
                while(possible && u >= 0) {
                    REP(k, l, r) {
                        if(S[u][k] != '#' && ans[u][k] == 0) continue;                       
                        possible = false;
                        break;            
                    }
                    if (possible) {
                        REP(k, l, r) ans[u][k] = kind;
                        u--;
                    }
                    //dump(u);
                }
                int d = i + 1;
                possible = true;
                while(possible && d < H) {
                    REP(k, l, r) {
                        if(S[d][k] != '#' && ans[d][k] == 0) continue;                       
                        possible = false;
                        break;            
                    }
                    if (possible) {
                        REP(k, l, r) ans[d][k] = kind;
                        d++;
                    }
                    //dump(d);
                }
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}


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

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

char D[105][105];
int vst[105][105];

int chk(int a, int b){
	int v = !vst[a][b];
	vst[a][b] = 1;
	return v;
}

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 0; i < N; i++) scanf("%s", D[i]);
	int cnt[26] = {};
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			cnt[D[i][j]-'a']++;
		}
	}

	vector<int> L;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			if( vst[i][j] ) continue;
			int ans = 0;
			ans += chk(i, j);
			ans += chk(N-i-1, j);
			ans += chk(i, M-j-1);
			ans += chk(N-i-1, M-j-1);
			L.push_back(ans);
		}
	}
	sort(L.begin(), L.end());
	for(int c : L){
		int v = -1;
		for(int i = 0; i < 26; i++){
			if( cnt[i] >= c && cnt[i]%(2*c) != 0 && cnt[i]%c == 0 ) v = i;
		}
		if( v == -1 ){
			for(int i = 0; i < 26; i++){
				if( cnt[i] >= c ) v = i;
			}
		}
		cnt[v] -= c;
	}
	int x = 0;
	for(int i = 0; i < 26; i++)x |= cnt[i];
	if( x == 0 ) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
    
    cin >> s;
    
    vector<string> v(4);
    v[0] = "dream", v[1] = "erase", v[2] = "eraser", v[3] = "dreamer";
    
    int n = s.size();
    bool flag = true;
    while(flag){
        flag = false;
        for(int i = 0; i < 4; ++i){
            if(n < v[i].size()) continue;
            string temp = s.substr(n - v[i].size());
            if(temp == v[i]){ s = s.substr(0, n - v[i].size()), n -= v[i].size(); flag = true; break; }
        }
    }
    printf("%s\n", (n == 0) ? "YES" : "NO");
    
    return 0;
}

Measured memory_bytes: 512
h, n = gets.to_s.split.map{|t|t.to_i}

inf = h * (10**4)

dp = [ inf ] * ( h + 1 )
dp[0] = 0

n.times do
  a, b = gets.to_s.split.map{|t|t.to_i}
  0.upto(h) do |mp|
    if mp - a <= 0
      dp[mp] = b if dp[mp] > b
    else
      dp[mp] = dp[mp - a] + b if dp[mp] > dp[mp - a] + b
    end
  end
end

puts dp[h]

Measured memory_bytes: 1916
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def bellman_ford(N: int, edges: list, src: int) -> list:
    """ ベルマンフォード(頂点数, 辺集合(0-indexed), 始点) """

    # 頂点[ある始点からの最短距離] (経路自体を知りたい時はここに前の頂点も持たせる)
    res = [INF] * N
    res[src] = 0
    # 各辺によるコストの置き換えを頂点数N-1回繰り返す
    for i in range(N-1):
        for src, dest, cost in edges:
            if res[dest] > res[src] + cost:
                res[dest] = res[src] + cost
    # 負の閉路(いくらでもコストを減らせてしまう場所)がないかチェックする
    for i in range(N):
        for src, dest, cost in edges:
            if res[dest] > res[src] + cost:
                res[dest] = res[src] + cost
                if dest == N-1:
                    # 頂点Nがそれに該当していたら空リストを返却
                    return []
    # 問題なければ頂点リストを返却
    return res

N, M, P = MAP()
edges = []
for i in range(M):
    a, b, c = MAP()
    # Pは最後に請求される、だけど、ようは動く度に支払ってると思ってもいい
    edges.append((a-1, b-1, -c+P))

res = bellman_ford(N, edges, 0)
if not len(res):
    print(-1)
else:
    # 正負を直す
    ans = -res[N-1]
    # スコアがマイナスなら0
    print(max(0, ans))


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

#define INF (1<<30)

signed main(){
	long long n,m,v,p;	cin>>n>>m>>v>>p;
	vector<long long> A(n+1);	A[0]=INF;
	for(long long i=1;i<=n;i++)cin>>A[i];
	sort(A.begin(), A.end(), greater<>());
	A[0]=-1;

	long long L_Bound=A[p];

	long long OK=1, NG=n+1;
	while(NG-OK>1){
		long long mid=(OK+NG)/2;

		if(mid<=p)OK=mid;
		else if(A[mid]+m < L_Bound)NG=mid;
		else{
			long long tmp=0;
			for(long long i=0;i<n;i++){
				if(i<p || mid<=i)tmp+=m;
				else{
					// p<=i<mid
					tmp+=A[mid]+m-A[i];
				}
			}

			if(tmp<m*v)NG=mid;
			else OK=mid;
		}
	}
	cout<<OK<<endl;


	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
int M;

vector<string> u,t;

set<string> id;

int main(){
  cin >> N;
  u.resize(N);
  rep(i,0,N - 1) cin >> u[i];
  rep(i,0,N - 1) id.insert(u[i]);
  cin >> M;
  string me[] = {"Opened by " , "Closed by "};
  int cou = 0;

  rep(i,0,M - 1){
    string s;
    cin >> s;
    if(!id.count(s)){
      cout << "Unknown " << s << endl;
    }
    else{
      cout << me[cou] << s << endl;
      cou = 1 - cou;
    }
  }
}


Measured memory_bytes: 3208
#include <stdio.h>

int main()
{
        int n, a, b, c;
        scanf("%d", &n);
        while (n--) {
                scanf("%d%d%d", &a, &b, &c);
                a = a * a;
                b = b * b;
                c = c * c;
                int m = (a + b == c) + (b + c == a) + (c + a == b);
                printf(m ? "YES\n" : "NO\n");
        }
        return 0;
}



Measured memory_bytes: 2024
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9+7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# nC0~nCn odd or even
def nCk(n):
    num = [0]*(n+1)
    for i in range(n+1):
        now = 2
        while now <= i:
            num[i] += i//now
            now *= 2
    #cumnum = [num[0]]
    #for i in range(1,n+1):
    #    cumnum.append(cumnum[-1]+num[i])
    ret = [0]*(n+1)
    for i in range(n+1):
        if num[n] > num[i]+num[n-i]:
            ret[i] = 0
        else:
            ret[i] = 1
    return ret

N = I()

A = list(input())
a = [0]*N
for i in range(N):
    a[i] = int(A[i])

b = [0]*(N-1)
for i in range(N-1):
    b[i] = abs(a[i]-a[i+1])

flag = False
for i in range(N-1):
    if b[i] == 1:
        flag = True
        break

nlist = nCk(N-2)

ans = 0
if not flag:
    for i in range(N-1):
        ans += nlist[i]*b[i]
        ans %= 4
    print(ans)
    #raise(ValueError)
else:
    for i in range(N-1):
        ans += nlist[i]*(b[i]%2)
        ans %= 2
    print(ans)
    #raise(ValueError)

Measured memory_bytes: 125408
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] data = new int[3];
		for(int i = 0; i < 3; i++) {
			data[i] = sc.nextInt();
		}
		int K = sc.nextInt();
		
		int maxIdx = 0;
		int max = data[0];
		for(int i = 1; i < 3; i++) {
			if(max < data[i]) {
				max = data[i];
				maxIdx = i;
			}
		}
		
		for(int i = 0; i < K; i++) {
			data[maxIdx] *= 2;
		}
		
		System.out.println(data[0] + data[1] + data[2]);
		
		sc.close();

	}

}

Measured memory_bytes: 21972
#include <iostream>
#include <queue>
#include <utility>
#include <set>
#include <vector>
using namespace std;

int main(void) {
	int X, Y;

	while(cin >> X >> Y, X | Y) {
		pair<int,int> t, k;
		vector<vector<int> > depart;
		set<pair<pair<int,int>,pair<int,int> > > moved;
		queue<pair<pair<pair<int,int>, pair<int,int> >, int> > q;
		int ans = -1;

		cin >> t.second >> t.first; t.first--; t.second--;
		cin >> k.second >> k.first; k.first--; k.second--;

		for(int i = 0; i < Y; i++) {
			vector<int> v;
			for(int j = 0; j < X; j++) {
				int tmp;
				cin >> tmp;
				v.push_back(tmp);
			}
			depart.push_back(v);
		}

		moved.insert(make_pair(t, k));
		q.push(make_pair(make_pair(t,k), 0));

		for(int i = 0;; i++) {
			pair<pair<int,int>, pair<int, int> > p;
			pair<int, int> next_t, next_k;
			int n;

			if(q.empty()) {
				break;
			}

			p = q.front().first; n = q.front().second; q.pop();
			if(p.first == p.second) {
				ans = n;
				break;
			}
			if(n > 100)
				break;

			int direction[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
			for(int j = 0; j < 4; j++) {
				next_t.first = p.first.first; next_t.second = p.first.second;
				next_k.first = p.second.first; next_k.second = p.second.second;
				if(0 <= p.first.first + direction[j][0] && p.first.first + direction[j][0] < Y 
						&& 0 <= p.first.second + direction[j][1] && p.first.second + direction[j][1] < X 
						&& depart[p.first.first + direction[j][0]][p.first.second + direction[j][1]] == 0) {
					next_t.first = p.first.first + direction[j][0];
					next_t.second = p.first.second + direction[j][1];
				}
				if(0 <= p.second.first - direction[j][0] && p.second.first - direction[j][0] < Y 
						&& 0 <= p.second.second - direction[j][1] && p.second.second - direction[j][1] < X 
						&& depart[p.second.first - direction[j][0]][p.second.second - direction[j][1]] == 0) {
					next_k.first = p.second.first - direction[j][0];
					next_k.second = p.second.second - direction[j][1];
				}
				if(moved.insert(make_pair(next_t, next_k)).second) {
					q.push(make_pair(make_pair(next_t, next_k),n + 1));
				}
			}
		}

		if(ans != -1)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 12052
#include<bits/stdc++.h>
using namespace std;
bool check(int x)
{
	int a,b;
	for(a=-1000;a<=1000;a++)
	{
    for(b=-1000;b<=1000;b++)
    {
    long long int c=pow(a,5);
    long long int d=pow(b,5);
    if(c-d==x)
    {
    cout<<a<<" "<<b;
    return 1;
    }
	}
    }
	return 0;
}
int main()
{
	long long int x;
	cin>>x;
	int f=check(x);
    return 0;
}

Measured memory_bytes: 3908
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> a >> b >> c;

	for(i=1;i<=b;i++) {
		if ( (i*a % b) == c ) ans = 1;
	}

	if (ans) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
    int n,m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
    return 0;
}

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

int main(){
  string a,b,c;
  int N;
  cin >>N>>a>>b>>c;
  int ans = 0;
  
  for(int i=0;i<N;i++){
    set<char> st;
    st.insert(a[i]);
    st.insert(b[i]);
    st.insert(c[i]);
    ans += st.size()-1;
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    char s[n+2];
    scanf("%s",s);
    s[n]='?';
    int res=0;
    int a=0,b=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]==s[i+1]) res++;
        else
        {
            if(s[i]=='L') a++;
            else b++;
        }
    }
    if(a>b) swap(a,b);
    if(a!=b) res+=min(a,k)*2;
    else
    {
        int t=min(a-1,k);
        res+=2*t;
        k-=t;
        if(k>0) res++;
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int k  =sc.nextInt(), s = sc.nextInt();
		
		int cnt = 0;
		for(int x=0;x<=k;x++){
			for(int y=0;y<=k;y++){
				if(x+y<=s && x+y+k>=s)
					cnt++;
			}
		}
		
		System.out.println(cnt);
	}

}


Measured memory_bytes: 21972
import java.io.*;

class Main
{
	public static void main (String[] args) throws Exception
	{
		BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
		String s[]=bu.readLine().split(" ");
		int k=Integer.parseInt(s[0]),n=Integer.parseInt(s[1]);
		int a[]=new int[n],i;
		s=bu.readLine().split(" ");
		for(i=0;i<n;i++)
		a[i]=Integer.parseInt(s[i]);
		int min=a[n-1]-a[0];
		for(i=1;i<n;i++)
		{
			int temp=a[i-1]+(k-a[n-1])+(a[n-1]-a[i]);
			if(temp<min) min=temp;
		}	
		System.out.print(min);
	}
}

Measured memory_bytes: 52564
/* ex_4-2. nknm */

#include <stdio.h>
#include <math.h>

//関数を宣言
double length(double len_h, double len_m, double hour, double min);

int main(void){

    double len_h, len_m, hour, min, ans;

    scanf("%lf%lf%lf%lf", &len_h, &len_m, &hour, &min);

    //関数の計算結果を出力
    ans = length(len_h, len_m, hour, min);
    printf("%.20f\n", ans);
    
    return 0;
}

double length(double len_h, double len_m, double hour, double min){

    //針が作る角度のコサインを求め余弦定理を計算
    double result, ang;
    ang = cos((2 * M_PI * min / 60) - ((2 * M_PI * hour / 12) + (2 * M_PI * min /12 / 60)));
    result = sqrt(len_h * len_h + len_m * len_m - 2 * len_h * len_m * ang);

    return result;
}

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

using namespace std;

typedef long long ll;

int x[5001];
int n;
pair<int,int> dp[1001];
vector<int> e[1001];
bool juu;
void solve(int y)
{
    int sum = 0;
    bitset<5001> p;
    p[0] = 1;
    for (int c: e[y])
    {
        pair<int,int> a = dp[c];
        p = (p<<a.first)|(p<<a.second);
        sum += (a.first+a.second);
    }
    for (int i = x[y]; i >= 0; --i)
        if (p[i])
        {
            dp[y] = {x[y],sum-i};
            return;
        }
    cout << "IMPOSSIBLE";
    exit(0);
    //juu=true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int c;
    for(int i=2;i<=n; ++i)
    {
        cin >> c;
        e[c].push_back(i);
    }
    for(int i=1; i<=n; ++i) cin >> x[i];
    for(int i=n; i; --i) solve(i);
    //if(juu) cout<<"IMPOSSIBLE"<<endl;
    cout << "POSSIBLE"<<endl;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int an = in.nextInt();
		int bn = in.nextInt();
		int[][] a = new int[an][an];
		int[][] b = new int[bn][bn];
		for(int i=0;i<an;i++){
			String row = in.next();
			for(int j=0;j<an;j++){
				a[i][j] = row.charAt(j);
			}
		}
		for(int i=0;i<bn;i++){
			String row = in.next();
			for(int j=0;j<bn;j++){
				b[i][j] = row.charAt(j);
			}
		}
		boolean work = false;
		for(int i=0;i<an;i++){
			for(int j=0;j<an;j++){
				if(compare(a,b,i,j)){
					work = true;
					break;
				}
			}
		}
		System.out.println(work ? "Yes" : "No");
	}
	public static boolean compare(int[][] a, int[][] b, int ai, int aj){
		if(ai + b.length > a.length || aj + b.length > a.length) return false;
		for(int i=ai;i<ai+b.length;i++){
			for(int j=aj;j<aj+b.length;j++){
				if(a[i][j] != b[i-ai][j-aj]) return false;
			}
		}
		return true;
	}
}


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

int main()
{
  int n ;
  long int d ;
  cin >> n >> d ;
  d = d * d ;

  vector<long int> x(n) ;
  vector<long int> y(n) ;

  for (int i = 0; i < n; i++) {
    long int a, b ;
    cin >> a >> b ;
    x.at(i) = a * a ;
    y.at(i) = b * b ;
  }

  int ans = 0 ;
  for (int i = 0; i < n ; i++) {
    if ( x.at(i) + y.at(i) <= d ) {
      ans++ ;
    }
  }

  cout << ans << endl ;

  return 0 ;
}

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

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

  int m = (A + K - 1) / K;
  int M = B / K;

  if ((M - m) >= 0) cout << "OK" << endl;
  else cout << "NG" << endl;
}


Measured memory_bytes: 3628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");

 //    String nyu=sc.nextLine();
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu);


//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

int res=Math.max(A,B);

if(res>8){

System.out.println(":"+"(");
}else{
System.out.println("Yay!");

}


	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int n; cin>>n;
  int a[n]; 
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  int ans=1;
  for(int i=0;i<n-1;i++){
	if(a[i]<a[i+1]) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

int cnt = 0;
int n;
void dfs(int m) {
  if (n < m) return;
  set<int> x;
  int now = m;
  while (now > 0) {
    x.insert(now % 10);
    now /= 10;
  }
  if (x.size() == 3) ++cnt;
  dfs(m * 10 + 3), dfs(m * 10 + 5), dfs(m * 10 + 7);
}

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  cin >> n;
  dfs(0);
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int max=0;
		int min=1000;
		List<Integer> list = new ArrayList<Integer>();
		for(int i=0;i<n;i++) {
			list.add(scan.nextInt());
			max=Math.max(max, list.get(i));
			min=Math.min(min, list.get(i));
		}

		System.out.println(max-min);


	}

}


Measured memory_bytes: 21716
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//素数判定O(√n)
bool is_prime(ll n){
  for(ll i=2;i*i<=n;i++){
    if(n%i==0)return false;
  }
  return n!=1;
}
int main(){
  ll n;cin>>n;
  vl vec;
  ll i=1;
  while(true){
    ll k=5*i+1;
    if(is_prime(k))vec.push_back(k);
    if(vec.size()==n)break;
    i++;
  }
  rep(i,n-1){
    cout<<vec[i]<<" ";
  }
  cout<<vec[n-1]<<endl;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


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

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


int main()
{
  ll n, m, lcmnm;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  lcmnm = lcm(n, m);
  forll(i, 0, m){
	if (n * i % m == 0){
	  if (t[i] != s[i * n / m]){
		cout << -1 << endl;
		return 0;
	  }
	}
  }
  cout << lcmnm << endl;
}


Measured memory_bytes: 512
// Contest: AtCoder Beginner Contest 177 (https://atcoder.jp/contests/abc177)
// Problem: E: Coprime (https://atcoder.jp/contests/abc177/tasks/abc177_e)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

bool seen[1'000'005];

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

    int n; cin >> n;
    vi a(n);
    trav(ai, a) cin >> ai;

    int g = a[0];
    reps(i, 1, n)
        g = gcd(g, a[i]);

    bool pairwise = true;
    trav(ai, a) {
        for (int i = 2; pairwise && i * i <= ai; ++i) {
            if (ai % i) continue;
            pairwise &= !seen[i];
            seen[i] = true;
            while (ai % i == 0) ai /= i;
        }
        if (ai > 1)
            pairwise &= !seen[ai], seen[ai] = true;
        if (!pairwise)
            break;
    }

    if (pairwise)
        cout << "pairwise coprime\n";
    else if (g == 1)
        cout << "setwise coprime\n";
    else
        cout << "not coprime\n";

    return 0;
}


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

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

int main() {
    vec a(5);
    int k;
    rep(i, 5) cin >> a[i];
    cin >> k;

    bool f = true;
    rep(i, 5) {
        for (int j = i+1; j < 5; j++) if (a[j] - a[i] > k) f = false;
    } 

    if (f) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1)
using namespace std;
int main()
{
	double a, b, x, tanx;
	cin >> a>> b>> x;
	if(x<=(0.5*a*b*a)) {
		tanx = 2*x/(a*b*b);
	} else {
		if(2*b-(2*x)/(a*a) == 0) {
			cout <<0 <<endl;
			return 0;
		}
		tanx = a/(2*b-(2*x)/(a*a));
	}
	
	double ans = atan(tanx);
	printf("%.10lf\n", 90.0-ans*180/PI);
	return 0;
}

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

A = [-1] * n

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        x = a[j]-1
        if A[x] == -1:
            A[x] = a[j]-1

ans = 0
for i in range(n):
    if A[i] == -1:
        ans += 1

print(ans)


Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,ans;
	cin>>n;
	if(n==0) cout<<"Yes"<<endl;
	else if(n<4) cout<<"No"<<endl;
	else
	{
		for(int i=0;i<=25;i++)
	    for(int j=0;j<=14;j++)
	    {
	    	if(4*i+7*j==n) ans++;
		}
		if(ans!=0) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
		return 0;
}

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

int main() {
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int n = (int)s.size();
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        int j = i;
        while (j < n && s[i] == s[j]) ++j;
        ++cnt;
        i = j - 1;
    }
    cout << cnt - 1 << endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class A
{
    public static void Main(string[] args)
    {
        int t = 1;
        while (t > 0)
        {
            string s = Console.ReadLine().Trim();
            if (s == "SUN")
                Console.WriteLine(7);
            if (s == "MON")
                Console.WriteLine(6);
            if (s == "TUE")
                Console.WriteLine(5);
            if (s == "WED")
                Console.WriteLine(4);
            if (s == "THU")
                Console.WriteLine(3);
            if (s == "FRI")
                Console.WriteLine(2);
            if (s == "SAT")
                Console.WriteLine(1);
            t--;
        }
    }
   
}

Measured memory_bytes: 13140
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

void rsort_d32(void *base, const int count){
	int32_t *a=base;
	int32_t *b=malloc(count*sizeof(int32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))+0x80]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

#define P 1000000007

int k[100001];
int rk[100001];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}
 
int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}

void comb_init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

int a[100000];
int main(void){
	int n=nextint();
	int k=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
	}
	rsort_d32(a, n);
	comb_init(n);
	long ans=0;
	for(int i=0; i<=n-k; i++){
		int c = comb(n-i-1, k-1);
		ans=((long)(a[n-i-1]-a[i])*c%P+ans+P)%P;
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 1300
mod = 10**9+7
L = input()
dp0 = [0] * (len(L)+1)
dp1 = [0] * (len(L)+1)
dp1[0] = 1
for i in range(1, len(L)+1):
    dp0[i] = dp0[i-1] * 3 if L[i-1] == '0' else dp0[i-1] * 3 + dp1[i-1]
    dp0[i] %= mod
    dp1[i] = dp1[i-1] if L[i-1] == '0' else dp1[i-1] * 2
    dp1[i] %= mod
print((dp0[-1] + dp1[-1]) % mod)


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
#define pqasc priority_queue<long long, vector<long long>, greater<long long>>

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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; }

class UnionFind{
private:
  vector<int> Parent; 
 public:
  UnionFind(int N){
    Parent = vector<int>(N, -1);
  }
  
  int root(int A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  int size(int A){
    return -Parent[root(A)]; 
  }
  
  bool connect(int A, int B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(int A, int B){
    return root(A) == root(B);
  }
};

long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

long long ngcd(vector<long long> a) {
  long long res = a[0];
  for(int i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}

long long nlcm(vector<long long> a){
  long long res = a[0];
  for(int i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}

bool is_prime(long long n) {
  if(n < 2) return false;
  for (long long i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}

int digsum(int n) {
  int res=0;
  while(n) res += n%10, n /= 10;
  return res;
}

int digcnt(int n){
  int res=0;
  while(n) res++, n /= 10;
  return res;
}

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  int ans=0;
  reps(i,n){
    if(digcnt(i)%2) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int mx = 0;
  map<string, int> ms;
  FOR(i,0,N) {
    string S;
    cin >> S;
    ms[S]++;
    mx = max(mx, ms[S]);
  }
  for (auto m : ms) {
    if (m.second == mx) {
      cout << m.first << endl;
    }
  }
}


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

int main(){ 
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  rep(i,n-1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  auto bfs = [&](int s1, int s2) {
    vector<int> color(n,0);
    queue<int> que;
    que.push(s1);
    color[s1] = 1;
    que.push(s2);
    color[s2] = 2;
    while (!que.empty()) {
      int u = que.front(); que.pop();
      for (auto v : g[u]) {
        if (color[v] != 0) continue;
        color[v] = color[u];
        que.push(v);
      }
    }
    return color;
  };
  auto c = bfs(0,n-1);
  int cnt_w = 0, cnt_b = 0;
  for (auto e : c) {
    if (e == 1) cnt_b++;
    else cnt_w++;
  }
  if (cnt_b > cnt_w) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
  return 0;
} 

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

const int val[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

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

  cout << (val[x] == val[y] ? "Yes" : "No") << 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(int i=0;i<N;i++)cin >> s[i];
  int cnt=0;
  int a=0,b=0,c=0;
  vector<int> q(N);
  for(int i=0;i<N;i++)q[i]=0;
  for(int i=0;i<N;i++){
    if(s[i][0]=='B' && s[i][s[i].size()-1]=='A')c++;
    else if(s[i][0]=='B')b++;
    else if(s[i][s[i].size()-1]=='A')a++;
    for(int j=0;j<s[i].size()-1;j++){
      if(s[i][j]=='A' && s[i][j+1]=='B')cnt++;
    }
  }
  if(c>0){
    cnt+=c-1;
    if(a>0){a--; cnt++;}
    if(b>0){b--; cnt++;}
  }
  cnt+=min(a,b);
  cout << cnt << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    if(n>m)swap(n,m);

    if(n==1 && m==1)cout<<1;
    else if(n==1)cout<<m-2;
    else cout<<(n-2)*(m-2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,ans = 0;
    string a,b,c;
    cin >> n >> a >> b >> c;
    rep(i, n){
        if ((a[i] == b[i]) && (b[i] == c[i])) {
        }else if ((a[i] != b[i]) && (b[i] != c[i]) && (a[i] != c[i])){
            ans += 2;
        }else{
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);

        int a = sn.nextInt();
        int b = sn.nextInt();

        int sum = a + b;
        int sub = a -b;
        int malti = a * b;

        int max = sum;
        if (max < sub) {
            max = sub;
        }
        if (max < malti) {
            max = malti;
        }

        System.out.println(max);

    }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("erasedream");
            //YES
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("dreameraser");
            //YES
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("dreamerer");
            //NO
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];

        if (Regex.IsMatch(S, "^(dream|dreamer|erase|eraser)*$"))
            Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }
}


Measured memory_bytes: 8068
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  string ans = "No";
  if (s < t)
    ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    REP(i, 0, n) {
        bool b = true;
        REP(j, 0, n) {
            if (s[(i + j) % n] != t[j]) {
                b = false;
                break;
            }
        }
        if (b) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

signed main() {
    solve();

    return 0;
}

Measured memory_bytes: 256