akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000

int n, M[MAX][MAX];

void dijkstra(){
  int minv=0, i, u=0, v;
  int d[MAX], color[MAX];

  for(i=0; i<n; i++){
    d[i] = INF;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INF;
    u = -1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
        u = i;
        minv = d[i];
      }
    }
    if(u==-1) break;
    color[u] = BLACK;
    for(v=0; v<n; v++){
      if(color[v]!=BLACK && M[u][v]!=INF){
        if(d[v]>d[u]+M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(i=0; i<n; i++){
    printf("%d %d\n", i, d[i] == INF ? -1 : d[i]);
  }
}

int main(){
  int i, j, k=0, c=0, u=0, v=0;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j] = INF;
    }
  }
  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    for(j=0; j<k; j++){
      scanf("%d%d", &v, &c);
      M[u][v] = c;
    }
  }
  dijkstra();

  return 0;
}

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

int main()
{
    int k;
    int a[5];
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;

    bool can_contact = true;

    for(int i=0;i<4;++i)
    {
        for(int j=i+1;j<5;++j)
        {
            can_contact &= (a[j]-a[i]) <= k;
        }
    }

    string ret;
    if(can_contact)
        ret = "Yay!";
    else
        ret = ":(";

    cout << ret << endl;
    return 0;
}

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

using namespace std;

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

	vector<int> a(N + 2, 0);
	for (int i = 1; i < N + 1; i++)
	{
		cin >> a[i];
	}

	vector<int> ans(N, 0);
	int sum = 0;
	for (int i = 1; i < N + 1; ++i)
	{
		sum += abs(a[i] - a[i - 1]);
		ans[i - 1] = -abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]);
	}
	sum += abs(a[N] - a[N + 1]);
	for (int i = 0; i < N; i++)
	{
		cout << sum + ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <math.h>
 
using namespace std;
 
int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0) break;
    int a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    double m = 0.0;
    for (int i = 0; i < n; i++)
      m += a[i];
    m /= n;
    double d = 0.0;
    for (int i = 0; i < n; i++)
      d += pow(a[i]-m, 2);
    d /= n;
    cout << fixed << sqrt(d) << endl;
  }
  return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,z,w;
int a[3000];
signed main(){
    cin>>n>>z>>w;
    rep(i,n)cin>>a[i];
    if(n==1){
        cout<<abs(w-a[0])<<endl;
    }
    else{
        int x=abs(a[n-2]-a[n-1]),y=abs(a[n-1]-w);
        cout<<max(x,y)<<endl;
    }
    return 0;
}


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

int main(){
  vector<char> str(19);
  for(int i = 0; i < 19; i++){
    cin >> str.at(i);
  }
  str.at(5) = ' ';
  str.at(13) = ' ';
  for(int i = 0; i < 19; i++){
    cout << str.at(i);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(A, B));

        sc.close();
    }

    static int solve(int A, int B) {
        return (int) IntStream.rangeClosed(A, B).filter(x -> isPalindrome(String.valueOf(x))).count();
    }

    static boolean isPalindrome(String s) {
        return s.equals(new StringBuilder(s).reverse().toString());
    }
}

Measured memory_bytes: 41520
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)

//your code here!
ll f(ll X){
    ll ret=0;
    while(X){
        ret += X%10;
        X /= 10;
    }
    return ret;
}

int main(void){
    ll N;
    scanf("%lld", &N);
    puts( !(N%f(N)) ? "Yes":"No");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int tate,yoko;
  int hyo[100][100];
  int i,j;
  int num;
  int sum_r; /*横の列の和*/
  int sum_c[100]; /*縦の各列の和*/
  int total = 0; /*全ての合計*/

  for(i = 0;i < 100;i++){
    for(j = 0;j < 100;j++){
      hyo[i][j] = 0;
    }
  }

  for(i = 0;i < 100;i++){
    sum_c[i] = 0;
  }

 
  scanf("%d %d",&tate,&yoko);
  /*
  
  for(i = 0;i < tate;i++){
    for(j = 0;j < yoko;j++){
      printf("%d ",hyo[i][j]);
    } 
    printf("\n");
 }

  */

 
  for(i = 0;i < tate;i++){
    for(j = 0;j < yoko;j++){
      scanf("%d",&hyo[i][j]);
    }
  }




  for(i = 0;i < tate;i++){
    sum_r = 0;
    for(j = 0;j < yoko;j++){
      printf("%d ",hyo[i][j]);
      sum_r += hyo[i][j];
      sum_c[j] += hyo[i][j];
    }
    printf("%d\n",sum_r);
  }

 
    for(j = 0;j < yoko;j++){
      printf("%d ",sum_c[j]);
      total += sum_c[j];
    }
    printf("%d\n",total);

  return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n,x,count;
        while(true){
            count = 0;
            n = sc.nextInt();
            x = sc.nextInt();
            
            if(n ==0 && x==0) break;
            
            for(int i=1; i<=n-2; i++){
                for(int j=i+1; j<=n-1; j++){
                    for(int k=j+1; k<=n; k++){
                    	if(i+j+k==x){
                    		count++;
                    	}
                    }
                }
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 26584
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
dp = [0] * n
for i in range(n):
    dp[alis[i] -1] += 1
dpp = [0] * n
summ = 0
for i in range(n):
    ima = dp[i] * (dp[i]-1) // 2
    summ += ima
for i in range(n):
    if dp[alis[i] -1] <=1:
        print(summ)
    else:
        mi = dp[alis[i]-1] -1 
        print(summ -mi)


Measured memory_bytes: 83280
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
aaa = na()
c = Counter(aaa)
ans = 0
for k, v in c.items():
    if k > v:
        ans += v
    elif k < v:
        ans += v - k
print(ans)

Measured memory_bytes: 20012
#include<bits/stdc++.h>
#define ll long long

const int N = 100010;

int n, a[N];
std::map <int, int> Hash;
std::stack <int> s;
ll ans[N];

int main(){ 
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i){
		scanf("%d", &a[i]);
		if (s.empty() || a[i] > a[s.top()]){
			s.push(i);
		}
		++ Hash[-a[i]];
	}
	while (!s.empty()){
		int x = s.top();
		s.pop();
		int y = s.empty() ? 0 : -a[s.top()];
		auto u = Hash.begin();
		while (u != Hash.end() && u -> first < y && u -> first){
			ans[x] += 1ll * (y - u -> first) * u -> second;
			Hash[y] += u -> second;
			Hash.erase(u);
			u = Hash.begin();
		}
	}
	for (int i = 1; i <= n; ++ i){
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 7296
import java.util.Scanner;
import java.util.HashSet;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++)
		{
			String str = sc.next();
			HashSet<String> set = new HashSet<String>();
			int length = str.length();
			for (int j = 1; j < length; j++)
			{
				String str1 = str.substring(0, j);
				String str2 = str.substring(j);
				set.add(str1 + str2);
				set.add(str1 + (new StringBuffer(str2)).reverse().toString());
				set.add((new StringBuffer(str1)).reverse().toString() + str2);
				set.add((new StringBuffer(str1)).reverse().toString()
					+ (new StringBuffer(str2)).reverse().toString());
				set.add(str2 + str1);
				set.add(str2 + (new StringBuffer(str1)).reverse().toString());
				set.add((new StringBuffer(str2)).reverse().toString() + str1);
				set.add((new StringBuffer(str2)).reverse().toString()
					+ (new StringBuffer(str1)).reverse().toString());
			}
			System.out.println(set.size());
		}
	}
}

Measured memory_bytes: 13000
#include <stdio.h>

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);

    if (( a==1 && b==2 ) || ( a==2 && b==1 ))
    {
        printf("3");
    }
    else if (( a==2 && b==3 ) || ( a==3 && b==2 ))
    {
        printf("1");
    }
    else if (( a==1 && b==3 ) || ( a==3 && b==1 ))
    {
        printf("2");
    }

    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main()
{
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
        int ans = 0;
        if(b<=c||d<=a){
            ans = 0;
            cout<<0<<endl;
            continue;
        }
        a =  max(a,c);
        b =  min(b,d);
        ans = b-a;
        cout<<ans<<endl;
    }
    return 0;
}


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

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

using namespace std;

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

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

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

LL N;
LL A[3];
LL B[3];

void MAIN() {
    scanf("%lld", &N);
    REP (i, 3) scanf("%lld", A+i);
    REP (i, 3) scanf("%lld", B+i);


    REP (t, 2) {
	vector<pair<LL, LL> > H;
	REP (s, 3) if (A[s] < B[s]) H.emplace_back(A[s], B[s]);

	if (H.empty()) {
	    ;
	} else if (H.size() == 1u) {
	    LL x = N / H[0].first;
	    N = N + x * (H[0].second-H[0].first);
	} else if (H.size() == 2u) {
	    LL nxt = N;
	    LL hi0 = N / H[0].first;
	    for (LL x0=0; x0<=hi0; x0++) {
		LL x1 = (N - x0*H[0].first) / H[1].first;
		amax(nxt, N + x0*(H[0].second-H[0].first) + x1*(H[1].second-H[1].first));
	    }
	    N = nxt;
	} else {
	    LL nxt = N;
	    LL hi0 = N / A[0];
	    for (LL x0=0; x0<=hi0; x0++) {

		LL hi1 = (N - x0*A[0]) / A[1];
		for (LL x1=0; x1<=hi1; x1++) {
		    LL x2 = (N-x0*A[0]-x1*A[1]) / A[2];
		    amax(nxt, N + x0*(B[0]-A[0]) + x1*(B[1]-A[1]) + x2*(B[2]-A[2]));
		}
	    }
	    N = nxt;
	}
	REP (s, 3) swap(A[s], B[s]);
    }

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

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    ll X, K, D; cin >> X >> K >> D;
    X = abs(X);
    if (X == 0) {
        if (K % 2 == 0) {
            cout << 0 << endl;
        } else {
            cout << D << endl;
        }
    } else {
        // 正の最小値へ到達するまでの回数
        ll a = X / D;

        ll ans = 0;
        if (a >= K) {
            ans = X - D * K;
        } else {
            ll diff = K - a;
            if (diff % 2 == 0) {
                ans = X - a * D;
            } else {
                ans = abs(X - (a + 1) * D);
            }
        }
        cout << ans << endl;
    }
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int64 a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k < a) cout << k << endl;
  else if (k > a + b) {
    cout << a - (k - a - b) << endl;
  } else {
    cout << a << endl;
  }
}

Measured memory_bytes: 3652
#include<stdio.h>
 
int main(){
     
    double a,b,c,d,e,f;
    double y,x;
     
    while (1) {
         
    scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f);
        if (getchar() == EOF)break;
        y=(c*d-f*a)/(b*d-e*a);
        x=(c-b*y)/a;
        printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 656
N = int(input())

def solve(N):
    for a in range(1, 3501):
        Na = N * a
        a4N = 4*a-N
        for b in range(a, 3501):
            d = a4N*b-Na
            if d:
                w, r = divmod(Na*b, d)
                if r == 0 and w > 0:
                    print(a,b,w)
                    return
solve(N)


Measured memory_bytes: 39408
X, K, D = map(int,  input().split())
X = abs(X)
if K%2 == 1:
  K -= 1
  X -= D
  
K_ = K // 2

min_Y = X - K_ * (2 * D)

if min_Y > 0:
  print(min_Y)
else:
  min_Y_p = X % (2 * D)
  min_Y_m = 2 * D - X % (2 * D)
  print(min(min_Y_p, min_Y_m ))

Measured memory_bytes: 9108
#include "bits/stdc++.h"

using namespace std;



int main() {
	int N, M;
	cin >> N >> M;
	vector<int>H(N);
	//vector<int>A(M);
	//vector<int>B(M);
	vector<bool>Peaks(N, true);
	for (int i = 0;i<N;++i) {
		cin >> H[i];
	}
	for (int i = 0; i < M; ++i) {
		int A, B;
		cin >> A >> B;
		if (H[A-1] > H[B-1]) {
			Peaks[B - 1] = false;
		}
		else if(H[A - 1] < H[B - 1]) {
			Peaks[A - 1] = false;
		}
		else {
			Peaks[B - 1] = false;
			Peaks[A - 1] = false;
		}
	}

	int nAns = 0;
	for (int n = 0;n<N;++n) {
		if (true == Peaks[n]) {
			++nAns;
		}
	}
	cout << nAns << endl;
	return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, m, i, j, k, a, b, ct;
	cin >> n >> m;
	vector<pair<int, int>> plist;
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		plist.push_back({ a, b });
	}
	sort(plist.begin(), plist.end());
	
	priority_queue<int> q;
	ct = 0;
	for (i = 0; i < m; i++) {
		if (!q.empty() && (-q.top() <= plist[i].first)) {
			ct++;
			while (!q.empty()) q.pop();
		}
		q.push(-plist[i].second);
	}
	if (!q.empty()) ct++;

	cout << ct << "\n";

	return 0;
}


Measured memory_bytes: 1400
//D
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int N;
	scanf("%d", &N);
	LL ans = 0;
	for (int i = 1; i <= N; i++) {
		LL cnt = N / i;
		ans += (cnt * (2 * i + i * cnt - i)) / 2;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3828
N=int(input())
a=list(map(int,input().split()))
b=0
for i in range(len(a)):
    b+=a[i]
b=b/len(a)
c=[]
for i in range(len(a)):
    c.append(abs(a[i]-b))
for i in range(len(c)):
    if c[i]==min(c):
        print(i)
        break

Measured memory_bytes: 61932
sticks = Hash.new(0)

gets
gets.split.each {|a| sticks[a.to_i] += 1}

selected = sticks.select {|length, num| num >= 2}.sort_by {|length, num| -length}
s = selected.size
result = if s >= 1 && selected[0][1] >= 4
           selected[0][0] ** 2
         elsif s >= 2 && selected[0][1] >= 2 && selected[1][1] >= 2
           selected[0][0] * selected[1][0]
         else
           0
         end
         
puts result

Measured memory_bytes: 15752
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

template <typename T>
struct WeightedUnionFind {
  int n,num;
  vector<int> r,p;
  vector<T> diff_weight;
  WeightedUnionFind() {}
  WeightedUnionFind(int n) : n(n), num(n), r(n,1), p(n,0), diff_weight(n) {
    iota(p.begin(),p.end(),0);
  }
  int find(int x) {
    if (p[x] == x) return x;
    int r = find(p[x]);
    diff_weight[x] += diff_weight[p[x]];
    return p[x] = r;
  }
  void unite(int x, int y, T w) {
    w += weight(x); w -= weight(y);
    x = find(x); y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) swap(x,y), w = -w;
    r[x] += r[y];
    p[y] = x;
    diff_weight[y] = w;
    num--;
  }
  T weight(int x) {
    find(x);
    return diff_weight[x];
  }
  T diff(int x, int y) {
    assert(same(x,y));
    return weight(y) - weight(x);
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int size(int x) {
    return r[find(x)];
  }
  int count() {
    return num;
  }
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N,M;
  while (cin >> N >> M, N) {
    WeightedUnionFind<int> wuf(N);
    REP(i,M) {
      char c;
      cin >> c;
      if (c == '!') {
        int a,b,w;
        cin >> a >> b >> w;
        a--; b--;
        wuf.unite(a,b,w);
      } else {
        int a,b;
        cin >> a >> b;
        a--; b--;
        if (wuf.same(a,b)) {
          cout << wuf.diff(a,b) << endl;
        } else {
          cout << "UNKNOWN" << endl;
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 5232
#include<stdio.h>

#define MAX_N 100

int main(){
	int n, i;
	int a[MAX_N] = {0};
	int flag = 0;

	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
		if(a[i] % 2 == 0){
			if((a[i] % 3 != 0)&&(a[i] % 5 != 0)){
				flag = 1;
			}
		}
	}

	if(flag == 0){
		printf("APPROVED");
	}else{
		printf("DENIED");
	}

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <list>
#include <iomanip>

using namespace std;

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
#define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++)
const int MAX_N = 1000000;
const Int MAX_N_Int = 1000000000000;

template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}

bool isPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}


Int fact_mod(Int n, Int mod) {
    Int f = 1; repq(i,2,n) f = f * (i % MOD) % MOD;
    return f;
}

// 繰り返し二乗法 (modの世界での累乗)
Int mod_pow(Int x, Int n, Int mod) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

// 組み合わせ nCr を求める
Int combination_mod(Int n, Int r, Int mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    Int a = 1;
    rep(i, 0, r) a = a * ((n-i) % mod) % mod;
    Int b = mod_pow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}

int main() {
    //COMinit();
    IOS;
    prec;
    Int a,b,c,n,m,k,x,y=0,ans=1;
    string str,s="CODEFESTIVAL2016",t,u;
    cin>>t;

    for (int i = 0; i < s.length(); ++i) {
        if(s[i]!=t[i])y++;
    }
    cout<<y;




    cout<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L;
  cin >> N >> L;
  int sum = N*L+N*(N-1)/2;
  if (L > 0) {
    sum -= L;
  } else if  (L+N <= 0) {
    sum -= N+L-1;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int c[201]={0},ba=0,n,i,a,t=0,o;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=1;i<=n*2;i++){
			c[i]=0;
		}
		ba=0;
		t=0;
		for(i=0;i<n;i++){
			scanf("%d",&a);
			c[a]=1;
		}
		while(1){
			if(ba==0){
				for(i=1;i<=n*2;i++){
					if(c[i]==(t+1)%2){
						ba=i;
						c[i]=2;
						break;
					}
				}
			}
			else{
				o=0;
				for(i=1;i<=n*2;i++){
					if(c[i]==(t+1)%2&&ba<i){
						o=1;
						ba=i;
						c[i]=2;
						break;
					}
				}
				if(o==0){
					ba=0;	
				}
				}
			o=0;
			for(i=1;i<=n*2;i++){
			if(c[i]==1){
					o=2;
				}
			}
			if(	o==0){
					break;
			}
			o=1;
			for(i=1;i<=n*2;i++){
				if(c[i]==0){
					o=2;
				}
			}
			if(o==1){
					break;
			}
			t++;
		}
		int cnt=0;
		if(o==0){
			for(i=1;i<=n*2;i++){
				if(c[i]==o){
						cnt++;
				}
			}
			printf("%d\n",cnt);
			printf("0\n");
		}
		else{	
			for(i=1;i<=n*2;i++){
				if(c[i]==o){
					cnt++;
					}
			}
			printf("0\n");
			printf("%d\n",cnt);
		}
	}
	return 0;
}

Measured memory_bytes: 2580
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
bool codejam = 0;
 
typedef long long li;
typedef long double ld;
 
void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
const int N = 500;
int n;
int want[N], arr[N];
void solve() {
	for (int i = 0; i < N; ++i)
		want[i] = i + 1;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			swap(arr[i], arr[j]);
			bool ok = true;
			for (int k = 0; k < n; ++k) {
				if (arr[k] != want[k]) ok = false;
			}
			if (ok) {
				cout << "YES";
				return;
			}
			swap(arr[i], arr[j]);
		}
	}
	cout << "NO";
}	

Measured memory_bytes: 256
import sys

s = str(input())
n = len(s)
left = s[0:int((n-1)/2)]
right = s[int(((n+3)/2)-1):n]
l = len(left)

for i in range(int((n-1)/2)):
    if s[i] == s[n-1-i]:
        continue
    else:
        print("No")
        sys.exit()

for i in range(int((n-1)/4)):
    if left[i] == left[l-1-i] and right[i] == right[l-1-i]:
        continue
    else:
        print("No")
        sys.exit()

print("Yes")

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

using namespace std;

int main(){
   long n,m;

   cin>>n>>m;
   vector<pair<long, long>> a(n);
   for(int i=0;i<n;i++){
       cin>>a[i].first>>a[i].second;
   }
    sort(a.begin(),a.end());
    long ans=0;
    for(int i=0;i<n;i++){
        if(a[i].second>=m){
            ans+=a[i].first*m;
            cout<<ans<<endl;
            return 0;
        }
        m-=a[i].second;
        ans+=a[i].first*a[i].second;
    }
    return 0;
}

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

int main(){
	int n;
  	cin>>n;
  	int a,b,c;
  	int v1[n],v2[n],v3[n];
  for(int i=0;i<n;i++){
  	cin>>v1[i]>>v2[i]>>v3[i];
  	}
  a=v1[0];
  b=v2[0];
  c=v3[0];
  for(int i=1;i<n;i++){
  		int t1=a;int t2=b;int t3=c;
    	a=v1[i]+max(t3,t2);
    b=v2[i]+max(t1,t3);
    c=v3[i]+max(t1,t2);
  }
  int ans=max(a,max(b,c));
  cout<<ans<<endl;




}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i = x;i < y;i++)
using namespace std;
int main(){
  int A,B,C,D=1;
  cin >> A >> B >> C;
  FOR(i,1,min(A,B)+1)if(A%i == 0 && B%i == 0)D = i;
  C%D ? cout << "NO" << endl : cout << "YES" << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
dp = [0] * (n)
dp[0] = 0
dp[1] = abs(a[1]-a[0])
for i in range(2,n):
  dp[i]=(min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i-2]-a[i])+dp[i-2]))
print(dp[n-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    string s, t;
    cin >> s >> t;
    map<char, vector<ll>> idx;
    ll sl = s.length(), tl = t.length();
    rep(i, sl) idx[s[i]].push_back(i);
    ll ans = 0;
    rep(i, tl) {
        if (sz(idx[t[i]]) == 0) {
            cout << -1 << endl;
            return 0;
        }
        int pos = ans % sl;
        auto it = lower_bound(all(idx[t[i]]), pos);
        if (it == idx[t[i]].end()) {
            ans += sl - pos + idx[t[i]][0] + 1;
            pos = idx[t[i]][0];
        }
        else {
            ans += *it - pos + 1;
            pos = *it + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M,X = inputIL()
B = inputILL(N)

best = 1e20

for i in range(pow(2,N)):
  learn = [0 for _ in range(M)]
  cost = 0
  for j in range(N):
    if i>>j & 1:
      cost += B[j][0]
      for k in range(M):
        learn[k] += B[j][k+1]
  check = 1
  for item in learn:
    if item < X:
      check = 0
  if check:
    best = min(best,cost)
    
if best == 1e20:
  print(-1)
else:
  print(best)

Measured memory_bytes: 73572
#include <cstdio>
#include <string>
using namespace std;

char t[200001];
string s;
int l, r;

int main(){
	scanf("%s", t);
	s = t;

	for(int i=0; i<s.size(); i++){
		if(s[i] == 'A'){
			l = i;
			break;
		}
	}
	for(int i=s.size()-1; i>0; i--){
		if(s[i] == 'Z'){
			r = i;
			break;
		}
	}

	printf("%d\n", r - l + 1);
}

Measured memory_bytes: 640
package main 

import (
  "fmt"
)

func main() {
  var x1, y1, x2, y2 int
  fmt.Scan(&x1, &y1, &x2, &y2)
  
  move_x := x2 - x1
  move_y := y2 - y1
  
  fmt.Println(x2 - move_y,y2 + move_x,x1 - move_y,y1 + move_x)
}

Measured memory_bytes: 512
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
double p;
int n;
cin>>n;
int o=0;
for1(i,n)if(i%2)o++;

p=(double)o/n;
cout<<p;
    return 0;
  }


Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
int main(){
    int f=0,s=0,n;
    for(int i=0;i<3;i++){
        cin>>n;
        if(n==5)f++;
        if(n==7)s++;
    }
    if(f==2&&s==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
    std::ios::sync_with_stdio(false);
    ll a,b,x;
    while(cin>>a>>b>>x)
    {
        if(a==0)
        {
            cout<<b/x+1<<endl;
        }
        else
            cout<<b/x-(a-1)/x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
K = int(input())
A = list(map(int,input().split()))
I = [[-1,-1] for _ in range(K+1)]
I[K] = [2,2]
fg = True
for i in range(K-1,-1,-1):
    #consider range I[i]
    left = A[i]*((I[i+1][0]+A[i]-1)//A[i]) 
    I[i][0] = max(A[i],left)
    I[i][1] = A[i]*(I[i+1][1]//A[i] + 1) -1
    #print(i,*I[i])
    if(I[i][0] > I[i][1]):
        fg = False
        #break
if(not fg):
    print(-1)
else:
    print(*I[0])

Measured memory_bytes: 27900
#include <stdio.h>
int main(void) {
	int insdate = 0;
	int inhome = 0;
	int inhdate[10001] = { 0 };
	int output = 0;

	scanf("%d %d", &insdate,&inhome);
	for (int k = 0; k < inhome; k++) scanf("%d", &inhdate[k]);
	
	int num = 0;
	for (int i = 0; i < inhome ; i ++) num = num + inhdate[i];

	if(num > insdate) printf("%d\n", -1);
	else printf("%d\n", insdate - num);

	return 0;
}


Measured memory_bytes: 1772
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())

print(s[K-1])

Measured memory_bytes: 3060
#include<cstdio>
using namespace std;

int N, K;
int h[111111];
int memo[111111];

int abs(int a){
	if(a < 0) return -a;
	else return a;
}

int min(int a, int b){
	if(a < b) return a;
	else return b;
}

int main(){
	scanf("%d %d", &N, &K);
	for(int i = 0; i < N; i++) scanf("%d", &h[i]);
	for(int i = 1; i < N; i++) memo[i] = 1 << 30;
	for(int i = 0; i < N; i++){
		for(int j = 1; j <= K; j++){
			if(i - j < 0) continue;
			memo[i] = min(memo[i], abs(h[i] - h[i - j]) + memo[i - j]);
		}
	}
	printf("%d\n", memo[N - 1]);
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string> 
#define MAX 1000005 
using namespace std;
struct cpu{
	string name;
	int time;
}; 
cpu queue[MAX-1];
int head,tail;
void initialize(){
	head=tail=0;
}
bool isEmpty(){
	return head==tail;
}
bool isFull(){
	return head==(tail+1)%MAX;
}
void enqueue(cpu x){
	if(isFull()){
		cout<<"满了"<<endl;
	}
	else{
		queue[tail]=x;
		if(tail+1==MAX){
			tail=0;
		}
		else{
			tail++;
		}
	}
}
cpu dequeue(){
	if(isEmpty()){
		cout<<"空的"<<endl;
	}
	else{
		cpu x = queue[head];
		if(head+1==MAX){
			head=0;
		}
		else{
			head++;
		}
		return x;
	}
}
int main(){
	initialize();
	int n,q;
	cin>>n>>q;
	cpu* cc = new cpu[n];
	for(int i=0;i<n;i++){
		cin>>cc[i].name; 
		cin>>cc[i].time;
		enqueue(cc[i]);
	}
	int tot=0;
	while(!isEmpty()){
		cpu now = dequeue();
		if(now.time>q){
			now.time-=q;
			enqueue(now);
			tot+=q;
		}
		else{
			tot+=now.time;
			cout<<now.name<<" "<<tot<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 21904
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {
	fastio;

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if (b < c || d < a) cout << 0 << endl;
	else {
		cout << min(b, d) - max(c, a) << endl;
	}
}

Measured memory_bytes: 256
import heapq
n,a,b= map(int,input().split())
h =[int(input()) for i in range(n)]

p = a-b
def c(w):
    #w de umakuikkuka
    k = 0
    for i in range(n):
        l[i] = l[i]-b*w
        if l[i] > 0:
            k += l[i]//p
            if l[i] % p != 0:
                k += 1
    if w >= k:
        return True

s = 0
f = 10**9
while f-s >=2:
    m = (f+s)//2
    l = h[::]
    if c(m):
        f = m
    else:
        s = m
l = h[::]
if c(s):
    print(s)
else:
    print(f)

Measured memory_bytes: 11928
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>

#define rep(i,n) for (long long int i = 0; i < (n); i++)
#define rep1(i,n) for (long long int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

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

int main()
{
    string s; cin >> s;
    int ans = 1;
    string pre = "", cur = "";
    pre = s[0];

    rep1(i,s.length()) {
        cur += s[i];

        if (pre != cur) {
            pre = cur;
            ans++;
            cur = "";
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl cnt = 0;
    repi(i,1,n+1) cnt += (digit10(i)%2);
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.size()){
        ans += static_cast<int>(s[i])-48;
        ans %= 9;
    }
    if(ans == 0) cout<< "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3712
x,y = map(int,input().split())
if (x+y)%3 != 0:
    print(0)
    quit()
elif x < (x+y)//3 or y < (x+y)//3:
    print(0)
    quit()
else:
    n = (x+y)//3
    r = x-n

mod = 10**9+7
def cmb(n,r,mod):
    r = min(r, n-r)
    return (fact[n] * factinv[r] * factinv[n-r]) % mod
def makefact(n,mod):
    fact = [1,1]
    factinv = [1,1]
    inv = [0,1]
    for i in range(2,n+1):
        fact.append((fact[-1]*i) % mod)
        inv.append(-inv[mod%i]*(mod//i)%mod)
        factinv.append((factinv[-1]*inv[-1])%mod)
    return fact,factinv
fact,factinv = makefact(n,mod)

print(cmb(n,r,mod))

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

int main()
{
	int C[3][3];
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> C[i][j];
	int ok = 1;
	if (C[0][0] - C[1][0] != C[0][1] - C[1][1]) ok = 0;
	if (C[0][0] - C[1][0] != C[0][2] - C[1][2]) ok = 0;
	if (C[0][0] - C[2][0] != C[0][1] - C[2][1]) ok = 0;
	if (C[0][0] - C[2][0] != C[0][2] - C[2][2]) ok = 0;
	cout << (ok ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3584
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
        write("Bad");
    }
    else {
        write("Good");
    }
}

Measured memory_bytes: 764
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import random
#####################################
k=int(input())
s=input()
w=0
r=0
for i in s:
    if i=="W":
        w+=1
    else:
        r+=1
count=0
ans="R"*r + "W"*w
for i in range(k):
    if s[i]!=ans[i]:
        count+=1
print(int(M.ceil(count/2)))


Measured memory_bytes: 78432
S = input()
N = len(S)
ans = float('inf')
for i in range(97,123):
    if S == chr(i)*N:
        ans = 0
        break
    prev = S
    for j in range(1,N):
        string = ''
        flag = True
        for k in range(N-j):
            if prev[k]==chr(i) or prev[k+1]==chr(i):
                string += chr(i)
            else:
                string += prev[k]
                flag = False
        if flag:
            ans = min(ans,j)
            break
        prev = string
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define FUP(i,x,y) for(int i=(x);i<=(y);i++)
#define FDW(i,x,y) for(int i=(x);i>=(y);i--)
#define MAXN 5010
#define INF 0x7fffffff
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
ll read(){
    ll w=0,flg=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')flg=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){w=w*10-'0'+ch,ch=getchar();}
    return w*flg;
}
ll k,q,n,x,m,D[MAXN],d[MAXN],cnt,sum;
void init()
{
	n=x=m=cnt=sum=0;
	memset(d,0,sizeof(d));
}
int main(){
	k=read(),q=read();
	FUP(i,1,k)
	{
		D[i]=read();
	}
	while(q--)
	{
		init();
		n=read(),x=read(),m=read();
		n--;
		x%=m;
		FUP(i,1,k)
		{
			d[i]=D[i]%m;
			if(d[i]==0)
			{
				cnt++;
			}
			sum+=d[i];
		}
		cnt*=n/k,sum*=n/k;
		sum+=x;
		FUP(i,1,n%k)
		{
			if(d[i]==0)
			{
				cnt++;
			}
			sum+=d[i];
		}
		//printf("%lld,%lld,%lld\n",n,cnt,sum/m);
		printf("%lld\n",n-cnt-sum/m);
	}
    return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (y, x) = readLine()!!.split(" ").map { it.toInt() }
    val b = (0 until y).map{ readLine()!!}
    var nb = b.toMutableList()
    var t = 0
    for(i in 0 until y) {
        nb[i] = ""
            for(j in 0 until x){
            t = 0
            if (b[i][j] == '.'){
                for(ii in i - 1 .. i + 1){
                    for(jj in j - 1 .. j + 1){
                        if (ii in 0 until y && jj in 0 until x){
                            if (b[ii][jj] == '#') {
                                t += 1
                            }
                        }
                    }
                }
                nb[i] += t.toString()
            }
            else nb[i] += "#"
        }
    }
    nb.forEachIndexed { i, s ->  println(nb[i])}
}

Measured memory_bytes: 38636
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int>x(N), y(N), h(N);
	int minH = 0;
	rep(i, N) {
		scanf("%d %d %d", &x[i], &y[i], &h[i]);
		minH = max(minH, h[i]);
	}
	int minus[100][101][101];
	rep(cx, 101) {
		rep(cy, 101) {
			rep(i, N) {
				minus[i][cx][cy] =
					abs(cx - x[i]) + abs(cy - y[i]);
			}
		}
	}
	bool ans = true;
	for (int hh = minH; hh < 1e10; hh++) {
		rep(cx, 101) {
			rep(cy, 101) {
				ans = true;
				rep(i, N) {
					if (hh - minus[i][cx][cy] == h[i]) {
					}
					else if (hh - minus[i][cx][cy] <= 0
						&& h[i] == 0) {
					}
					else {
						ans = false;
						break;
					}
				}
				if (ans) {
					cout << cx << " " << cy << " " << hh << endl;
					break;
				}
			}
			if (ans)break;

		}
		if (ans)break;
	}



}


Measured memory_bytes: 4224