akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var a = Input();
		long max = 0;
		long min = 9999999999;
		for(int i = 0; i < n; i++)
		{
			var q = a[i].ToLong();
			max = Math.Max(max, q);
			min = Math.Min(min, q);
		}
		Console.WriteLine(max-min);
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	for (int i = 1; i <= B; i++) {
		if (A * i % B == C) {
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INF 100000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

int prim(void);
int M[MAX][MAX],n,d[MAX],p[MAX],color[MAX];

int main(){
    int i,j;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&M[i][j]);
        }
    }
    printf("%d\n",prim());
    return 0;
}

int prim(void){
    int mincost,i,j,u,v,sum=0;
    
    for(i=0;i<n;i++){
        d[i]=INF;
        //p[i]=NIL;
        color[i]=WHITE;
    }
    
    d[0]=0;
    p[0]=NIL;

    while(1){
        mincost=INF;
        for(i=0;i<n;i++){
            if(color[i]!=BLACK && d[i]<mincost){
                mincost=d[i];
                u=i;
            }
        }
        if(mincost==INF) break;
        sum+=mincost;
        color[u] = BLACK;
        
        for(v=0;v<n;v++){
            if(color[v]!=BLACK && M[u][v]!=NIL){
                if(M[u][v]<d[v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
    
    return sum;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
	int key;
	Node* next, *prev;
};

Node* nil;

Node* listSearch(int key) {
	Node* cur = nil->next;	// 番兵の次の要素からたどる
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node*)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printfList() {
	Node* cur = nil->next;
	int isf = 0;
	while (1) {
		if (cur == nil) break;
		if (isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node* t) {
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deletekey(int key) {
	// 検索したノードを削除
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node* x = (Node*)malloc(sizeof(Node));
	x->key = key;
	// 番兵の直後に要素を追加
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(int argc, char *argv[])
{
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') {
			insert(key);
			np++;
			size++;
		}
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') {
					deleteFirst();
				}
				else if (com[6] == 'L') {
					deleteLast();
				}
			}
			else {
				deletekey(key); 
				nd++;
			}
			size--;
		}
	}
	printfList();

	return 0;
}


Measured memory_bytes: 33972
import bisect
X,N = map(int,input().split())

p = list(map(int,input().split()))
p = sorted(p,reverse = False)
p_x = []
if p == []:
    print(X)
else:
    for i in range(200):
        if not(i in p):
            p_x.append(i)
    idx_x = bisect.bisect_left(p_x,X)
    if abs(X-p_x[idx_x-1]) < abs(X-p_x[idx_x]):
           print(p_x[idx_x-1])
    elif abs(X-p_x[idx_x-1]) > abs(X-p_x[idx_x]):
           print(p_x[idx_x])
    else:
        print(min(p_x[idx_x],p_x[idx_x-1]))

Measured memory_bytes: 9228
# C - Welcome to AtCoder
from collections import defaultdict


def main():
    N, M, *PS = open(0).read().split()
    is_correct = [0] * (int(N) + 1)
    wa_count = defaultdict(int)
    for p, s in zip(*[iter(PS)] * 2):
        p = int(p)
        if not is_correct[p]:
            if s == "AC":  # first AC
                is_correct[p] = 1
            else:  # not yet AC and get WA -> +1 penalty
                wa_count[p] += 1
    penalties = sum(cnt for i, cnt in wa_count.items() if is_correct[i])
    print(sum(is_correct), penalties)


if __name__ == "__main__":
    main()


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(3);
	double a,b,c,d,e,f;
	while(cin >> a >> b >> c >> d >> e >> f){
		double x = (e*c-b*f)/(e*a-b*d);
		double y = (d*c-a*f)/(d*b-a*e);

		x = round(x*1000)/1000+10e-5;
		y = round(y*1000)/1000+10e-5;

		cout << x << " " <<  y << endl;
	}

	return 0;
}



Measured memory_bytes: 3308
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> LLLL;

int main(int argc, char* argv[]) {
	LL t, n, a, b, c, d, ans;
	cin >> t;
	for (LL tt = 0; tt < t; ++tt) {
		cin >> n >> a >> b >> c >> d;
		ans = 1LL << 60;
		priority_queue<LLLL, vector<LLLL>, greater<>> q;
		q.emplace(make_pair(0, n));
		map<LL, LL> memo;
		const LL divs[3] = { 2, 3, 5 };
		const LL costs[3] = { a, b, c };
		while (!q.empty()) {
			LLLL top = q.top();
			q.pop();
			LL cost = top.first;
			LL x = top.second;
			if (cost > memo[x]) continue;

			if ((x >> 30) * d < (1LL << 30)) {
				ans = min(ans, cost + x * d);
			}

			memo[x] = cost;
			for (LL i = 0; i < 3; ++i) {
				LL y = x / divs[i];
				LL c = cost + costs[i] + (x - y * divs[i]) * d;
				if (memo.find(y) == memo.end() || memo[y] > c) {
					memo[y] = c;
					q.emplace(make_pair(c, y));
				}
				if (x != y * divs[i]) {
					++y;
					c = cost + costs[i] + (y * divs[i] - x) * d;
					if (memo.find(y) == memo.end() || memo[y] > c) {
						memo[y] = c;
						q.emplace(make_pair(c, y));
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

void solve(long long T, long long X)
{
    cout << (double)T / X << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long T;
    scanf("%lld", &T);
    long long X;
    scanf("%lld", &X);
    solve(T, X);
    return 0;
}


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

#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>


#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>



#include <assert.h>


using namespace std;
class A {
public:
	void solve(std::istream& in, std::ostream& out) {
    ios::sync_with_stdio(false);
		char a, b;
		in >> a >> b;
		if(a == 'H'){
			out << (b == 'H' ? 'H' : 'D') << endl;
		}else{
			out << (b == 'D' ? 'H' : 'D') << endl;
		}
	}
};


int main() {
	A solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
    int N;cin >> N;
    int idx_max;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int tmp = 0;
    for(int i = 0; i < N; i++){
        if(tmp < A[i]){
            tmp = A[i];
            idx_max = i;
        }
    }
    tmp = 0;
    for(int i = 0; i < N; i++){
        if(i == idx_max){
            for(int j = 0; j < N; j++) if(tmp < A[j] && j != idx_max) tmp = A[j];
            cout << tmp << endl;
        }else cout << A[idx_max] << endl;
    }
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int w,h,c;
    cin >>w >>h >>c;

    int g = __gcd(w,h);
    cout << c*w/g*h/g << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

ll n;
vector<ll> num;
unordered_map<ll, int> dp;

inline int rec(ll x){
	if(dp.count(x)) return dp[x];
	int &res = dp[x];
	if(x == 1) return res = 0;
	
	res = -inf;
	for(ll m : num){
		if(x % m == 0) res = max(res, 1 + rec(x / m));
		if(m >= x) break;
	}
	if(res < 0) res = -inf;
	return res;
}

int main(){
	for(int keta = 1; keta <= 18; keta++){
		rep(i, 1 << keta){
			ll m = 0;
			rep(j, keta){
				if(m * 10.0 > 1.1e18) {m = -1; break; }
				m *= 10;
				m += i >> j & 1 ? 8 : 2;
			}
			if(m > 0) num.pb(m);
		}
	}
	sort(all(num));
	
	cin >> n;
	int res = n > 1 ? rec(n) : -inf;
	cout << (res < 0 ? -1 : res) << endl;
	return 0;
}

Measured memory_bytes: 6892
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
#define N 505
struct Node
{
	int id,pl;
};
Node a[N];
int ans[N*N],n,l,r;
bool cmp(Node x,Node y){return x.pl<y.pl;}
bool spj()
{
	for(int i=1;i<=n;i++)
	{
		int cnt=0;
		for(int j=1;j<=a[i].pl;j++) if(ans[j]==a[i].id) cnt++;
		if(cnt!=a[i].id) return 0;
	}
	return 1;
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++) a[i].id=i,a[i].pl=read();
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) ans[a[i].pl]=a[i].id;
	l=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=2;j<=a[i].id;j++)
		{
			while(ans[l]) l++;
			ans[l++]=a[i].id;
		}
	}
	r=n*n;
	for(int i=n;i>=1;i--)
	{
		for(int j=a[i].id+1;j<=n;j++)
		{
			while(ans[r]) r--;
			ans[r--]=a[i].id;
		}
	}
	// for(int i=1;i<=n*n;i++) printf("%d ",ans[i]); cout<<"\n";
	if(!spj()) {cout<<"No\n"; return 0;}
	cout<<"Yes\n";
	for(int i=1;i<=n*n;i++) printf("%d ",ans[i]); cout<<"\n";
	return 0;
}




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

int main() {
  int N,i,j;
  cin>>N;
  vector<int> a(N);

  for(i=0;i<N;i++){
    cin>>a.at(i);
  }

sort(a.begin(), a.end());
int target=a.at(0);
int ind=0;
int count=0;
vector<int> item;
vector<int> item_num;

while(ind<N){
for(i=ind;i<N;i++){
    if(target==a.at(i)){
      count++;
      if(i==N-1){
        item.push_back(target);
        item_num.push_back(count);
        ind=N;
      }
    }else{
      item.push_back(target);
      item_num.push_back(count);
      target=a.at(i);
      ind=i;
      count=0;
      break;}
  }
  }

string ret ="No";
if(item.size()==1){
  if(item.at(0)==0) ret="Yes";
}else if(N%3==0){
  if (item.size()==2){
    if((item.at(0)==0&&item_num.at(0)==N/3)||(item.at(1)==0&&item_num.at(1)==N/3))ret="Yes";
  }else if (item.size()==3){
    if((item.at(0)^item.at(1))==item.at(2)){
      if(item_num.at(0)==N/3&&item_num.at(1)==N/3)ret="Yes";
    }
  }
}

cout<<ret<<endl;




}


Measured memory_bytes: 1532
#include <stdio.h>
int Lsearch(int[],int,int);
int main(){
  int x,y,i,j,k,key,res=0,same[500],A[10000+1];

  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&y);
  for(i=0;i<y;i++){
    scanf("%d",&key);
    if(Lsearch(A,x,key)==1)res++;
  }


  printf("%d\n",res);
  return 0;
}

int Lsearch(int B[],int n,int kkey){
  int i=0;
  B[n]=kkey;
  for(i=0;B[i]!=kkey;i++);
  if(i==n)return 0;
  else return 1;
}

Measured memory_bytes: 636
N = int(input())
W = [input() for _ in range(N)]

for i in range(N-1):
    for j in range(i+1, N):
        if W[i]==W[j]:
            print('No')
            exit()

    if W[i][-1]!=W[i+1][0]:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

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

    vector<int> n(128, 0);

    REP(i, w.size()){
        int val = w[i];
        //cout << val << endl;
        ++n[val];
    }

    REP(i, 128){
        if(n[i] % 2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())

H = list(map(int,input().split()))

HSorted = sorted(H)

HIndexToHeight = []
HHeightToIndex = {}

for i in range(N):
    if i != 0 and HSorted[i] == HSorted[i-1]:
        continue
    HIndexToHeight.append(HSorted[i])
    HHeightToIndex[HSorted[i]] = len(HIndexToHeight) - 1

INF = 10 ** 12

heightCount = len(HIndexToHeight)

DP = []
for i in range(N):
    DP.append([])
    for j in range(K + 1):
        DP[i].append([])
        for k in range(heightCount):
            DP[i][j].append(INF)

for k in range(heightCount):
    if k == HHeightToIndex[H[0]]:
        DP[0][0][k] = H[0]
    elif K != 0:
        DP[0][1][k] = HIndexToHeight[k]

for i in range(1,N):
    currentHeight = HHeightToIndex[H[i]]
    for j in range(K + 1):
        for k in range(heightCount):
            if currentHeight > k:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k] + HIndexToHeight[currentHeight] - HIndexToHeight[k], DP[i][j][currentHeight])
            elif currentHeight == k:
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
            else:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
ans = INF

for j in range(K + 1):
    for k in range(heightCount):
        if ans > DP[N-1][j][k]:
            ans = DP[N-1][j][k]
if K == N:
    print(0)
else:
    print(ans)




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

int main() {
  int N, L; cin >> N >> L;
  int maxL = L + N - 1;
  int sum = L*N;
  for(int i = 0; i < N; ++i){
    sum += i;
  }
  
  if(L >= 0) cout << sum - L << endl;
  if(L < 0 && maxL >= 0) cout << sum << endl;
  if(maxL < 0) cout << sum - maxL << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    for(int i=1;i<=1009;i++){
        if((i*8)/100==A&&(i*10)/100==B){
            cout << i << endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(){
    char letter;
		scanf("%c",&letter);
    if((letter>= 'a') && (letter<= 'z')){
		    printf("a\n");
		} else if((letter>= 'A') && (letter<= 'Z')){
		    printf("A\n");
		}
}

Measured memory_bytes: 1576
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>
#include <bitset>
#include <cstdio>
//#include <complex>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
//const ll INF = 1e9;
const ll MOD = 1e9 + 7;
//const double EPS = 1e-9;
//const double PI = acos(-1);
 
ll ten[100100];
 
void solve() {
    string s;
    cin >> s;
    int n = s.length();
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        if (s[i] == '?')
            a[i] = -1;
        else 
            a[i] = s[i] - '0';
    }
    
    ten[0] = 1;
    for (int i = 1; i < 100100; ++i)
        ten[i] = ten[i - 1] * 10 % 13;
 
    vector<vector<ll>> dp(n + 1, vector<ll>(13, 0));
    dp[n][0] = 1;
    for (ll i = n - 1; i >= 0; --i) {
        if (a[i] == -1) {
            for (ll k = 0; k < 13; ++k)
                for (ll d = 0; d <= 9; ++d)
                    dp[i][(ten[n - 1 - i] * d + k) % 13] = (dp[i][(ten[n - 1 - i] * d + k) % 13] + dp[i + 1][k]) % MOD;
        } else {
            for (ll k = 0; k < 13; ++k)
                dp[i][(ten[n - 1 - i] * a[i] + k) % 13] = (dp[i][(ten[n - 1 - i] * a[i] + k) % 13] + dp[i + 1][k]) % MOD;
        }
    }
    cout << dp[0][5] % MOD;
}   
 
 
int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout); 
    solve();
}

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

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

  string s;
  cin >> s;
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s << "\n";
}


Measured memory_bytes: 3768
import fractions


def main():
    def lcm(x, y):
        return (x * y) // fractions.gcd(x, y)
    A, B, C, D = map(int, input().split())
    l = lcm(C, D)
    print((B - (B//C + B//D - B//l)) -
          (A-1 - ((A-1)//C + (A-1)//D - (A-1)//l)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 5052
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let abs = Array.init (n - 1) @@ fun _ ->
    Scanf.scanf "%d %d\n" @@ fun a b -> a, b in
  let es = Array.make n [] in
  Array.iter (fun (a, b) ->
    es.(a - 1) <- b - 1 :: es.(a - 1);
    es.(b - 1) <- a - 1 :: es.(b - 1)) abs;
  let d = Array.make_matrix n n min_int in
  for s = 0 to n - 1 do
    let rec dfs v =
      List.iter (fun u ->
        if d.(s).(u) < 0 then 
          (d.(s).(u) <- 1 + d.(s).(v); dfs u)) es.(v) in
    d.(s).(s) <- 0; dfs s
  done;
  Printf.printf "%d\n" @@ Array.fold_left min max_int @@
  if k mod 2 = 0 then
    Array.init n @@ fun v ->
      Array.fold_left (fun acc u ->
        acc + (if k / 2 < d.(u).(v) then 1 else 0)) 0 @@
      Array.init n @@ fun u -> u
  else
    Array.map (fun (a, b) ->
      Array.fold_left (fun acc u ->
        acc + (if k / 2 < min d.(a - 1).(u) d.(b - 1).(u) then 1 else 0)) 0 @@
      Array.init n @@ fun u -> u) abs


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

bool cmp(int a,int b){
        return a>b;
}


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

    //Insert code
    
    string s;
    cin>>s;
    int n=s.length();
    for (int i=0;i<n;i++){
        for (int j=0;j<n;j++){
            string tmp=s;
            tmp.erase(i,j);
            if (tmp=="keyence"){
                cout<<"YES";
                return 0;
            }
        }
    }

    cout<<"NO";

    //End code


    cerr << "\nTime elapsed: " << 1000*clock() / CLOCKS_PER_SEC << "ms\n";
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int A, B;
  cin >> A >> B;
  int r = 0;
  for (int i = A; i <= B; i++)
  {
    string s = to_string(i);
    //cout << s << endl;
    if ((s.at(0) == s.at(4)) && (s.at(1) == s.at(3)))
    {
      r++;
    }
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
AL=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
N=input()
l=0
for i in AL:
  if N==i:
    print(AL[l+1])
  else:
    l+=1

Measured memory_bytes: 8932
from collections import Counter
n=int(input())
w=input().split()
a=Counter(w[::2]).most_common(2)
b=Counter(w[1::2]).most_common(2)
if a[0][0]!=b[0][0]:
	stay=a[0][1]+b[0][1]
else:
	if a[0][1]==b[0][1]==n//2:
		stay=a[0][1]
	elif a[0][1]>b[0][1]:
		stay=a[0][1]+b[1][1]
	elif a[0][1]<b[0][1]:
		stay=a[1][1]+b[0][1]
	else:
		if a[1][1]>=b[1][1]:
			stay=a[1][1]+b[0][1]
		else:
			stay=a[0][1]+b[1][1]
print(n-stay)

Measured memory_bytes: 16232
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> G[100000];
ll c[100000];
ll A[100000];
bool dfs(int v, int par) {
	bool leaf = 1;
	ll sum = 0;
	ll m = 0;
	for (int to : G[v]) {
		if (to == par) continue;
		if (!dfs(to, v)) return 0;
		sum += c[to];
		m = max(m, c[to]);
		leaf = 0;
	}
	if (leaf) {
		c[v] = A[v];
		return 1;
	}
	if (2 * A[v] < sum || sum < A[v]) return 0;
	ll T = 2 * A[v] - sum;
	if (min(sum - m, sum / 2) >= (sum - T) / 2) {
		c[v] = T;
		return 1;
	}
	return 0;
}
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	if (N == 2) {
		if (A[0] == A[1]) cout << "YES" << endl;
		else cout << "NO" << endl;
		return 0;
	}
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int v = 0;
	for (int i = 0; i < N; i++) {
		if (G[i].size() > 1) {
			v = i;
			break;
		}
	}
	bool ok = dfs(v, -1);
	if (c[v] > 0) ok = 0;
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 13952
while True:
    a, op, b = map(str, input().split())
    if op == "?":
        break
    if op == "+":
        print(int(a) + int(b))
    if op == "-":
        print(int(a) - int(b))
    if op == "*":
        print(int(a) * int(b))
    if op == "/":
        print(int(a) // int(b))


Measured memory_bytes: 5596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		long power = 1;
		for(int i = 1; i <= N; i++) {
			power = (i * power) % (long)(Math.pow(10,9) + 7);
		}
		System.out.println(power);
		scan.close();

	}

}


Measured memory_bytes: 21588
public class Main {
    public static void main(String[] args) {

        // ??????????????????????????????.
        // ???????????????????????´??° (?????°??¨?????°) ???????????????.
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();

        // ?????????????´????????????????????????????.
        // ???????????????????????´??° (?????????????´?) ???????????????.
        int[][] matrix1 = new int[n][m];
        int[][] matrix2 = new int[m][l];
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < m; j ++) { matrix1[i][j] = sc.nextInt(); }
        }
        for (int i = 0; i < m; i ++) {
            for (int j = 0; j < l; j ++) { matrix2[i][j] = sc.nextInt(); }
        }

        // ???????????????????????????.
        long sum = 0;
        for (int i = 0; i < n; i ++) {
            for (int j = 0; j < l; j ++) {
                sum = 0;
                for (int k = 0; k < m; k ++) { sum += matrix1[i][k] * matrix2[k][j]; }
                System.out.print(sum);
                if (j != l - 1) { System.out.print(" "); }
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 54692
fun main(args: Array<String>) {
  val (N, M) = readLine()!!.split(" ").map { it.toInt() }
  val st = (0..N).map { mutableSetOf<Int>() }
  for (i in 0 until M) {
    val (s, t) = readLine()!!.split(" ").map { it.toInt() }
    st[s].add(t)
  }
  val ts = (0..N).map { mutableSetOf<Int>() }
  for (s in 1..N) {
    st[s].forEach { t -> ts[t].add(s) }
  }
//  println(st)
//  println(ts)

  var min = Double.MAX_VALUE
  for (j in N - 1 downTo 1) {
    val dp = (0..N).map { 0.0 }.toMutableList()
    for (i in N downTo 1) {
      var set = st[i]
      if (i == j && set.size > 1) {
        val index = set.maxBy { dp[it] }
        index?.let {
          set = set.toMutableSet()
          set.remove(it)
//          println("remove $i to $it")
        }
      }
      dp[i] = set.sumByDouble { (dp[it] + 1) / set.size }
    }
//    println(dp)
    min = Math.min(min, dp[1])
  }
  println(min)
}


Measured memory_bytes: 94512
n = gets.to_i
a = gets.split.map(&:to_i)

count_4 = a.count { |i| i % 4 == 0 }
odd = a.count(&:odd?)

if a.index { |i| i % 4 != 0 && i.even? }
  puts odd <= count_4 ? :Yes : :No
else
  puts odd - 1 <= count_4 ? :Yes : :No
end

Measured memory_bytes: 9988
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007
typedef long long ll;

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

int
main(int argc, char *argv[])
{
  int n, a[200001];
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) scanf("%d", &a[i]);

  int h[200000]; int tmp; int m = 0;
  for(int i = n; i > n / 2; i--){
    h[i] = a[i];
    if(h[i] > 0) m++;
  }
  for(int i = n / 2; i > 0; i--){
    tmp = 0;
    for(int j = 2 * i; j <= n; j += i){
      tmp += h[j];
    }
    if(tmp % 2 == a[i]) h[i] = 0;
    else h[i] = 1;
    if(h[i] > 0) m++;
  }
  printf("%d\n", m);
  for(int i = 1; i <= n; i++){
    if(h[i] > 0) printf("%d ", i);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2432
S = input()
n = len(S)-1
ans = 0

for i in range(1 << n):
    op = [""] * n
    for j in range(n):
        if i & (1 << j):
            op[j] = "+"
    f = "".join([S[i//2] if i % 2 == 0 else op[i//2] for i in range(2*(n+1)-1)])
    ans += eval(f)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
   // #ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin);
   /// freopen("output.txt", "w", stdout);
   // #endif
    ll int n;
    cin>>n;
    ll int z=n/1000;
    if(n%1000==0)
    	cout<<0<<endl;
    else
    {
    	cout<<(z+1)*1000-n;
    }
}

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

//Aを超えた時の処理さえわかっていたら、なんてことはない

int main(){
	string input;
	cin >> input;
	for(int i=0; i < input.size(); i++){
		input[i] -= 3;
		if(input[i] < 'A') input[i] += 26;
	}
	cout << input << endl;
}

Measured memory_bytes: 1176
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define repe(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repi(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {
	int k, s;
	cin >> k >> s;
	ll cnt = 0;
	repi(i, 0, k)repi(j, 0, k) {
		int z = s - i - j;
		if (z >= 0 && z<=k) {
			cnt++;
		}

	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
#include<math.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。
//↑はあんまり気にしなくていい。


class unionFind{
      private:
      vector<int> parent;
      vector<int> rank;
      vector<int> sizes;

      public:
      unionFind(int n){
            rep0(i,n){
                  parent.push_back(i);
                  rank.push_back(0);
                  sizes.push_back(1);
            }
      }
      int root(int x){
            if(parent[x]==x){
                  return x;
            }
            else{
                  parent[x] = root(parent[x]);
                  return parent[x];
            }
      }
      void merge(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y) return;
            if(rank[x]<rank[y]) swap(x,y);
            if(rank[x]==rank[y]) rank[x]++;
            parent[y]=x;
            sizes[x]+=sizes[y];
      }
      bool same(int x,int y){
            return root(x)==root(y);
      }
      int size(int x){
            return sizes[root(x)];
      }
};


int main(){
    int n,m;
    cin>>n>>m;
    unionFind u(n);
    rep0(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        x--,y--;
        u.merge(x,y);
    }
    int r[n];
    fill(r,r+n,0);
    rep0(i,n){
        r[u.root(i)]++;
    }
    int ans=0;
    rep0(i,n){
        if(r[i]>0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 12800;

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

	int n;
	cin >> n;
	vi price(6, 100);
	vector<bool> dp(100001);
	for(int i = 0; i < 6; i++){
		price[i] += i;
		dp[price[i]] = true;
	}
	for(int i = 1; i <= 100000; i++){
		if(dp[i]){
			for(int j = 0; j < 6; j++){
				int next = i + price[j];
				if(next <= 100000){
					dp[next] = true;
				}
			}
		}
	}
	cout << (dp[n] ? 1 : 0) << endl;
	
}	

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


int main(){
    int r;
    double pi;
    pi = 3.141592;
    cin >> r;
    double l;
    l = 2*r*pi;
    cout << l << endl;

    return 0;
}



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

int par[100010]; //親
int height[100010];  //木の深さ

//n要素で初期化
void init (int n){
    for (int i=0;i<n;i++){
        par[i]=i;
        height[i]=0;
    }
}

//木の根を求める
int find (int x){
    if (par[x]==x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unite (int x, int y){
    x=find(x);
    y=find(y);
    if (x==y) return;
    
    if (height[x] < height[y]){
        par[x]=y;
    }
    else {
        par[y]=x;
        if (height[x]==height[y]) height[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same (int x, int y){
    return find(x) == find(y);
}

int main() {
    int N, M;
    cin >> N >> M;
    int p[N];
    for (int i=0;i<N; i++){
        cin >> p[i];
    }
    init(N);
    for (int i=0;i<M; i++){
        int x, y;
        cin >> x >> y;
        unite(x-1,y-1);
    }
    int c=0;
    for (int i=0;i<N; i++){
        if (same(i, p[i]-1)) c++;
    }
    printf("%d\n", c);
}

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

#define PI 4*atan(1)
#define INF 1e8

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

vector<string> button = {".,!?@",
           "abc",
           "def",
           "ghi",
           "jkl",
           "mno",
           "pqrs",
           "tuv",
           "wxyz"};


int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    int cnt = 0;
    for(int j = 0; j < s.size(); j++){
      if(s[j] == '0'){
        if(cnt != 0){
          char c;
          int num = s[j-1] - '0';
          // cout << "num: " << num - 1 << " " << (cnt-1)%button[num-1].size() << endl;
          if(num - 1 == 0 && (cnt-1)%button[num-1].size() == 4)c = ' ';
          else c = button[num - 1][(cnt-1)%button[num-1].size()];
          cout << c;
          cnt = 0;
        }
      }else{
        cnt++;
      }
    }
    cout << endl;
  }
}

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

#define mod 1000000007

using namespace std;
typedef long long ll;



int main() {
	int n, w;
	cin >> n >> w;
	vector<int> frnd;
	int sum=0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		frnd.push_back(x);
		sum += x;
	}
	sort(frnd.begin(), frnd.end());
	ll ans = 0;
	vector<vector<ll> > dp(n + 1, vector < ll >(w + 1, 0));
	for (int k = 0; k < n; k++) {//????°??????????????????????
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= w; j++) {
				dp[i][j] = 0;
			}
		}
		dp[0][0] = 1;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= w; j++) {
				if (frnd[i] + j <= w && i!=k) {
					dp[i + 1][frnd[i] + j] += dp[i][j];
				}
				if (i >= k)dp[i + 1][j] += dp[i][j];
			}
		}
		for (int i = w - frnd[k] + 1; i <= w; i++) {
			if (i < 0)continue;
			ans = (ans + dp[n][i]) % mod;
		}
		/*for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= w; j++) {
				cout << dp[i][j];
			}
			cout << endl;
		}
		cout << endl;
		*/
	}
	if (sum <= w)ans++;
	cout << ans << endl;
	

	return 0;

}

Measured memory_bytes: 18616
#include<stdio.h>
int main(){
	int m,f,r;
	while(1){
		
		scanf("%d%d%d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m==-1||f==-1||m+f<30){
			printf("F\n");
		}
		else if(80<=m+f){
			printf("A\n");
		}
		else if(65<=m+f&&80>m+f){
			printf("B\n");
		}
		else if(50<=m+f&&65>m+f){
			printf("C\n");
		}
		else if(30<=m+f&&50>m+f){
			if(50<=r){
				printf("C\n");
			}
			else{
				printf("D\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
int main() {
 nin(n);
  vector<int> h(n);
  vector<int> c(n);
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  c.at(0)=0;c.at(1)=abs(h.at(0)-h.at(1));
  for(int i=2;i<n;i++){
    c.at(i)=min(c.at(i-1)+abs(h.at(i)-h.at(i-1)),c.at(i-2)+abs(h.at(i)-h.at(i-2)));
  }
  cout << c.at(n-1) << endl;
}
                

Measured memory_bytes: 1024
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

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

    vector<int> v(n);
    rep(i, n) {
        cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<int>());

    LL sum = 0;
    for (int i = 1; i < n; i++) {
        sum += v[i];
    }
    if (sum > v[0]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W; cin>>H>>W;
    vector<string> f(H);
    rep(i,H) cin>>f[i];
    int cnt[26];
    memset(cnt,0,sizeof(cnt));
    rep(i,H){
        for(auto c:f[i]){
            int j = c-'a';
            cnt[j]++;
        }
    }
    if (H%2==0 && W%2==0){
        rep(i,26){
            if(cnt[i]%4!=0){
                cout<<"No\n";
                return 0;
            }
        }
        cout<<"Yes\n";
    }else if(H%2==1 && W%2==1){
        int odd=0;
        rep(i,26){
            if (cnt[i]&1) odd++, cnt[i]--;
        }
        if (odd>1){
            cout<<"No\n";
            return 0;
        }

        int p2=0;
        rep(i,26){
            if (cnt[i]%4==2) p2++;
        }
        int goal = W/2+H/2;
        if (p2>goal || p2%2!=goal%2){
            cout<<"No\n";
            return 0;
        }
        cout<<"Yes\n";
    }else{
        if (H&1) swap(H,W);
        int p2=0;
        rep(i,26){
            if (cnt[i]%4==2) p2++;
            cnt[i]-=2;
        }
        int goal = H/2;
        if (p2>goal || p2%2!=goal%2){
            cout<<"No\n";
            return 0;
        }

        int odd=0;
        rep(i,26){
            if (cnt[i]&1){
                cout<<"No\n";
                return 0;
            }
        }

        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys
from collections import Counter 
MOD = 1000000007 


def solve(n: int, a: "List[int]"):
    counter = Counter(a).most_common()
    twiceValue = counter[0][0]
    first_index = None
    second_index = None

    for i in range(n+1):
        if a[i] == twiceValue:
            if first_index == None:
                first_index = i
            else:
                second_index = i

    # 1つ目のtwiceValueより左にある数字の数  
    left = first_index

    # 2つ目のtwiceValueより右にある数字の数  
    right = n-second_index
    edge = left+right

    # nCk,edgeCkをO(1)で取れるようにするため
    combination_table = {n+1: [0]*(n+2), edge: [0]*(edge+1)}
    
    combination_table[n+1][0] = 1
    combination_table[n+1][n+1] = 1
    combination_table[edge][0] = 1
    combination_table[edge][edge] = 1
    c_value = 1

    # nCkをうめる
    for i in range(1,n+1):
        c_value *= (n+1 + 1 - i) * pow(i,MOD-2,MOD)
        c_value %= MOD
        combination_table[n+1][i] = c_value

    c_value = 1
    # edgeCkをうめる
    for i in range(1,edge):
        c_value *= (edge + 1 - i) * pow(i,MOD-2,MOD)
        c_value %= MOD
        combination_table[edge][i] = c_value

    for i in range(1,n+2):
        if i-1 <= edge:
            value = combination_table[n+1][i] - combination_table[edge][i-1]
        else:
            value = combination_table[n+1][i]
        print(value%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n + 1)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30776
import math
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
p1, p2, p3, p4 = 0, 0, 0, 0
hyp = 0
for i in range(n):
    p1 += math.fabs(a1[i] -a2[i])
    p2 += (a1[i]-a2[i])**2
    p3 += math.fabs((a1[i]-a2[i])**3)
    hyp = math.fabs(a1[i] -a2[i]) 
    if hyp > p4:
        p4 = hyp

p2 = math.sqrt(p2)
if p3 != 0:
    p3 = math.exp(math.log(p3)/3)
print(p1)
print(p2)
print(p3)
print(p4)

Measured memory_bytes: 7764
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

        while(!(line = br.readLine()).equals("-1")){
            int n = Integer.parseInt(line);
            double x = 1.0;
            double y = 0.0;
            double deg = 180;

            for(int i = 1; i < n; i++){
                deg -= 90;
                x += Math.cos(deg / 180.0 * Math.PI);
                y += Math.sin(deg / 180.0 * Math.PI);
                deg = Math.atan(y/x) * 180.0 / Math.PI;
                if(x <= 0 && y >= 0) deg += 180.0;
                if(x <= 0 && y <= 0) deg += 180.0;
                // System.out.println(x + ":" + y + ":" + deg);
            }

            System.out.printf("%.2f%n", y);
            System.out.printf("%.2f%n", x);
        }
    }
}


Measured memory_bytes: 24764
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define INF (1<<30)
#define LINF (1LL<<60)

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1126

#define MAXH 75
#define MAXW 75
vector<vector<string>> dp(MAXH, vector<string>(MAXW));
vector<vector<int>> f(MAXH, vector<int>(MAXW));
string ans;
int W, H;

inline bool str_check(string a,string b) {
	for (int i = 0; i < a.length();i++) {
		if (a[i] == '0') {
			if (i == a.length() - 1) a = "0";
			continue;
		}
		if (a[i] != '0') {
			a = a.substr(i); break;
		}
	}

	for (int i = 0; i < b.length();i++) {
		if (b[i] == '0') {
			if (i == b.length() - 1) b = "0";
			continue;
		}
		if (b[i] != '0') {
			b = b.substr(i); break;
		}
		if (i == b.length() - 1) b = "0";
	}

	if (a.size() > b.size()) return true;
	else if (a.size() < b.size()) return false;
	else {
		int Size = a.size();
		for (int i = 0; i < Size;i++) {
			if (a[i] != b[i]) return a[i] > b[i] ? true : false;
		}
	}
	return false;
}

void dfs(int h, int w, vector<vector<char>>& C) {
	f[h][w] = 1;

	bool dfs_f = false;
	if (C[h][w - 1] < 'A') {
		if (dp[h][w - 1] == "-") {
			dp[h][w - 1] = C[h][w - 1] + dp[h][w];
			dfs(h, w - 1, C);
			dfs_f = true;
		}
		else {
			if (str_check(C[h][w - 1] + dp[h][w], dp[h][w - 1])) {
				dp[h][w - 1] = C[h][w - 1] + dp[h][w];
				dfs(h, w - 1, C);
				dfs_f = true;
			}
		}
	}

	if (C[h - 1][w] < 'A') {
		if (dp[h - 1][w] == "-") {
			dp[h - 1][w] = C[h - 1][w] + dp[h][w];
			dfs(h - 1, w, C);
			dfs_f = true;
		}
		else {
			if (str_check(C[h - 1][w] + dp[h][w], dp[h - 1][w])) {
				dp[h - 1][w] = C[h - 1][w] + dp[h][w];
				dfs(h - 1, w, C);
				dfs_f = true;
			}
		}
	}

	if (!dfs_f) {
		if (str_check(dp[h][w], ans)) {
			ans = dp[h][w];
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (cin >> W >> H) {
		if (W == 0 && H == 0) break;
		ans = "0";
		for (int i = 0; i < MAXH; i++) for (int j = 0; j < MAXW;j++) {
			dp[i][j] = "-";
			f[i][j] = 0;
		}
		vector<vector<char>> C(H + 2, vector<char>(W + 2, 'A'));

		for (int i = 1; i <= H;i++) for (int j = 1; j <= W;j++) cin >> C[i][j];

		for (int i = H; i > 0; i--) {
			for (int j = W; j > 0;j--) {
				if (f[i][j] == 0 && C[i][j] < 'A') {
					dp[i][j] = C[i][j];
					dfs(i, j, C);
				}
			}
		}

		for (int i = 0; i < ans.length();i++) {
			if (ans[i] == '0') continue;
			if (ans[i] != '0') {
				cout << ans.substr(i); break;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 3424
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
 
int main() {
    int ma,mb,da,db;
    cin>>ma>>da;
    cin>>mb>>db;

    if(ma==mb)  cout<<0<<endl;
    else    cout<<1<<endl;
  
 return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

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

int main(){
  string s,t;
  cin >> s >> t;
  int ans=0;
  REP(i,s.size()){
    if(s[i]!=t[i])ans++;
  }
  PRINT(ans);
}



Measured memory_bytes: 3844