akhauriyash/Code-Regression huggingface dataset:
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n,a,b;
int dp[5005][5005][2],sum[5005][5005][2];
inline void add(int &x,int y){
	x+=y;if(x>=mod)x-=mod;
}
inline void sub(int &x,int y){
	x-=y;if(x<0)x+=mod;
}
inline int Add(int x,int y){
	return x+y>=mod?x+y-mod:x+y;
}
inline int Sub(int x,int y){
	return x>=y?x-y:x-y+mod;
}
int main(){
	cin>>n>>a>>b;
	if(a>b)swap(a,b);
	dp[1][0][0]=1;
	dp[1][0][1]=1;
	add(sum[1][0][1],dp[1][0][1]);
	add(sum[1][0][0],dp[1][0][0]); 
	for(int i=2;i<=n+1;i++){
		for(int j=0;j<=5000;j++){
			if(j)add(sum[i][j][1],sum[i-1][j-1][1]);
			if(j)add(sum[i][j][0],sum[i-1][j-1][0]);
			if(j)add(dp[i][0][1],Sub(sum[i-1][j-1][0],(i>=a&&j>=a?sum[i-a][j-a][0]:0)));
			if(j>=b)continue;
			if(j)add(dp[i][j][0],sum[i-1][j-1][1]);
			add(dp[i][j][1],(i>=a&&j>=a?sum[i-a][j-a][0]:0));
		}
		for(int j=0;j<b;j++){
			add(sum[i][j][1],dp[i][j][1]);
			add(sum[i][j][0],dp[i][j][0]);
//			cerr<<i<<" "<<j<<" "<<dp[i][j][0]<<" "<<dp[i][j][1]<<endl;
		}
	}
	int ans=0;
	for(int i=0;i<b;i++){
		add(ans,dp[n+1][i][0]);
		add(ans,dp[n+1][i][1]);
	}
	ans=Sub(modpow(2,n,mod),ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 394628
// ※※※ 解答不能 ※※※
// ksun48氏.
// https://atcoder.jp/contests/code-festival-2017-qualc/submissions/1703120
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define MOD 1000000007

LL mult(LL a, LL b){
    return ((a % MOD) * (b % MOD)) % MOD;
}

LL solve2(LL a, LL b, LL c, LL d){
    LL ans = 0;
    LL i = 1;
    while(i < (c - d)){
        LL go = 1e9;
        LL go1 = 0;
        //if(i < 1000000 || (c - d - i) < 1000000) go1 = 1;
        LL x = a * i / c;
        LL y = b * i / c;
        LL l1 = min(a - 1, x + d) - max(0LL, x - d);
        LL l2 = min(b - 1, y + d) - max(0LL, y - d);
        
        if(l1 == 2 * d) go = min(go, c * (a - d - 1) / a - i);
        else            go = min(go, (c * (x + 1) - 1) / a - i);
        
        if(l2 == 2 * d) go = min(go, c * (b - d - 1) / b - i);
        else            go = min(go, (c * (y + 1) - 1) / b - i);
        
        if(go1) go = 1;
        go = max(go, 1LL);
        go = min(go, c - d - i);
        ans += mult(go, mult(l1 + 1, l2 + 1));
        ans %= MOD;
        i += go;
    }
    return ans % MOD;
}

LL solve(LL a, LL b, LL c, LL d){
    LL ans = 0;
    for(LL i = 1; i < c - d; i++){
        LL x = a * i / c;
        LL y = b * i / c;
        LL l1 = min(a - 1, x + d) - max(0LL, x - d);
        LL l2 = min(b - 1, y + d) - max(0LL, y - d);
        ans += mult(l1 + 1, l2 + 1);
        ans %= MOD;
    }
    return ans;
}

int main(){
    LL a, b, c, d;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    LL ans = mult(min(a, d + 1), mult(min(b, d + 1), min(c, d + 1)));
    // solve each dimension
    ans += solve2(a, b, c, d);
    ans += solve2(b, c, a, d);
    ans += solve2(c, a, b, d);
    ans %= MOD;
    while(ans < 0) ans += MOD;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
S = input()
def judge(s):
    if len(s) % 2 == 0:
        if s[:(len(s)//2)] == s[len(s)//2:]:
            return True
        else:
            return False
    else:
        return False
ans = 0
for i in range(len(S)):
    if judge(S[:i]):
        ans = i
print(ans)


Measured memory_bytes: 2940
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
    }

    int ans = 0;
    rep(a, n + 1){
        int cnt = 0;
        rep(i, n){
            if(p[i] >= a){
                ++cnt;
            }
        }
        if(cnt >= a){
            chmax(ans, a);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int a = 0;
	string S;
	cin >> S;

	if (S.size() == 2) {
		if (S.at(0) == S.at(1))
			cout << "1 2" << endl;
		else cout << "-1 -1" << endl;
		return 0;
	}


	for (int i = 2; i < S.size(); i++) {
		if (S.at(i - 2) == S.at(i - 1)) {
			cout << i - 1 << ' ' << i << endl;
			return 0;
		}
		else if (S.at(i - 2) == S.at(i)) {
			cout << i - 1 << ' ' << i + 1 << endl;
			return 0;
		}
	}
	cout << "-1 -1" << endl;
	return 0;
}

Measured memory_bytes: 512
class UnionFindTree:
    '''
    Union Find Tree
    '''

    def __init__(self):
        self.p = {}
        self.rank = {}

    def make(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def find(self, x):
        if x in self.p:
            if self.p[x] != x:
                # 経路圧縮
                self.p[x] = self.find(self.p[x])
            return self.p[x]
        return None

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        self._unite(self.find(x), self.find(y))

    def _unite(self, x, y):
        if self.rank[x] < self.rank[y]:
            self.p[x] = y
        else:
            self.p[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


V, E = map(int, input().split())
e = []
for i in range(E):
    s, t, w = map(int, input().split())
    e.append([w, s, t])

'''
クラスカルのアルゴリズム
最小全域木の総重み
辺をソートし、UnionFindTreeで同じ集合に属する辺を作らずに集合を構築
'''
e.sort()
uft = UnionFindTree()
for i in range(V):
    uft.make(i)

ans = 0

for w, s, t in e:
    if not uft.same(s, t):
        uft.unite(s, t)
        ans += w

print(ans)



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

int main()
{
     int hours, minutes, seconds;

     while (cin >> hours >> minutes >> seconds) {
          if (hours == -1) break;
          int times = 120 * 60;
          int sum = hours * 60 * 60 + minutes * 60 + seconds;
          times -= sum;
          seconds = times % 60;
          times /= 60;
          minutes = times % 60;
          times /= 60;
          hours = times % 24;

          printf("%02d:%02d:%02d\n", hours, minutes, seconds);

          sum = hours * 60 * 60 + minutes * 60 + seconds;
          times = sum;
          times *= 3;
          seconds = times % 60;
          times /= 60;
          minutes = times % 60;
          times /= 60;
          hours = times % 24;

          printf("%02d:%02d:%02d\n", hours, minutes, seconds);

     }

     return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <string.h>

int main() {
	char str[20];
	char c;
	int i = 0;

	memset(str, '\n', 20);

	while ((c = getchar()) != '\n') {
		str[i++] = c;
	}
	while (i--) {
		printf("%c", str[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 520
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int s[15],d[15],v[15];
double dp[1<<15][15];
int sum[1<<15];
int parent[1<<15][15];
void print(int k,int a)
{
	int l=k&~(1<<a);
	if(l)
	{
		print(l,parent[k][a]);
		cout<<" ";
	}
	cout<<s[a];
}
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>d[i]>>v[i];
		for(int j=0;j<1<<n;j++)dp[j][i]=1e300;
	}
	for(int i=0;i<1<<n;i++)
	{
		for(int j=0;j<n;j++)if(i&1<<j)sum[i]+=v[j];
	}
	for(int i=0;i<n;i++)dp[0][i]=0;
	for(int i=1;i<1<<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(!(i&1<<j))continue;
			int k=i&~(1<<j);
			double ans=dp[i][j];
			int p;
			for(int l=0;l<n;l++)
			{
				double now=dp[k][l]+(70+sum[k]*20)/2e3*abs(d[l]-d[j]);
				if(ans>now)
				{
					ans=now;
					p=l;
				}
			}
			dp[i][j]=ans;
			parent[i][j]=p;
		}
	}
	double m=1e300;int p,k=(1<<n)-1;
	for(int i=0;i<n;i++)if(m>dp[k][i])m=dp[k][i],p=i;
	print(k,p);
	cout<<endl;
}




Measured memory_bytes: 8888
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, b, c;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
	int ans=0;
  	int keta=1;
    for (int i = 0; i < 3; i++)
    {
      int t=n%10;
      n/=10;
      if(t==1){
      t=9;
      }
      else{
      t=1;
      }
      ans+=keta*t;
      keta*=10;
    }
    cout << ans << "\n";
}



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

int main() {
  int N;
  cin >> N;
  map<string, int> MA;
  int mx = 0;
  string S;
  while (cin >> S) mx = max(mx, ++MA[S]);
  for (auto ma : MA) if (ma.second == mx) cout << ma.first << "\n"; 
}

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

INF = float('inf')

v,e = mi()
dp = [[float('inf') for i in range(v)] for j in range(v)]

path = [[] for i in range(v)]
for i in range(e):
    s,t,d = mi()
    path[s].append((t,d))
    dp[s][t] = d

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


for k in range(v):
    for i in range(v):
        for j in range(v):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])



for i in range(v):
    if dp[i][i] < 0:
        print('NEGATIVE CYCLE')
        break
else:
    for i in range(v):
        for j in range(v):
            c = dp[i][j]
            if c == INF:
                c = 'INF'
            if j != v-1:
                print(c,end=" ")
            else:
                print(c)


Measured memory_bytes: 7320
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <limits.h>
#include <cmath>
#include <cstring>
#include <queue>
#include <stdlib.h>

using namespace std;

#define mod (1000000007)
typedef long long  ll;
typedef vector<int> vi;


ll exp(ll a, ll n) {
  if (n==0) return 1;
  if (n == 1) return a;
  if (n%2) {
    ll s = exp(a,n-1);
    return s * a;
  } else {
    ll s = exp(a,n/2);
    return s*s;
  }
}

long max(long a, long b) {
  if (a < b) return b;
  return a;
}

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


void solve() {
  int n, k;
  cin >> n;
  vi a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  
  vector<vector<int> > dp(n, vector<int> (3, 0));
  
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  
  
  for (int i = 1; i < n; i++) {
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
  }
  
  int ans = 0;
  for (int i = 0; i < 3; i++) ans = max(ans, dp[n-1][i]);
  
  cout << ans << "\n";
 
}

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



Measured memory_bytes: 9848
#include <stdio.h>

int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if((a==5||a==7)&&(b==5||b==7)&&(c==5||c==7)&&(a+b+c==17))
    printf("YES");
    else printf("NO");

    return 0;
}

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const int MOD = 1000000007;
const int INF = 1000000000;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

llong powmod(llong a, llong n)
{
    llong res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }

    return res;
}

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);
    /* ifstream in("input.txt");
    ifstream in("input.txt"); */

    int n;
    cin >> n;
    vector<llong> A(n);
    rep(i, n) cin >> A[i];

    vector<vector<int> > bicnt(n, vector<int>(60, 0));
    rep(i, n) {
        llong bit = 0;
        rep(j, 60) {
            if (A[i] & (1LL << bit)) bicnt[i][j] = 1;
            ++bit;
        }
    }

    /* rep(i, n) {
        rep(j, 60) cout << bicnt[i][j] << ' ';
        cout << endl;
    } */

    vector<vector<int> > cumbicnt(60, vector<int>(n + 1));
    rep(i, 60) cumbicnt[i][0] = 0;
    rep(i, 60) {
        rep(j, n) {
            cumbicnt[i][j + 1] = cumbicnt[i][j] + bicnt[j][i];
        }
    }

    /* rep(i, 60) {
        rep(j, n + 1) cout << cumbicnt[i][j] << ' ';
        cout << endl;
    }*/

    llong ans = 0;
    rep(i, n) {
        rep(j, 60) {
            llong tmp = cumbicnt[j][n] - cumbicnt[j][i + 1];
            if (bicnt[i][j]) tmp = n - (i + 1) - tmp;
            ans += powmod(2, j) * tmp;
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main()
{
    FAST;
    ll n,k;
    cin>>n>>k;
    ll ans=1;
    for(int i=1;i<=n;i++)
    {
        if(i==1)
        {
            ans*=(k);
        }
        else
        {
            ans*=(k-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

public class Main {
    public static void main(String[] args){
    	
    	try {
    		InputStreamReader isr = new InputStreamReader(System.in);
    		BufferedReader br = new BufferedReader(isr);
    		String buf = br.readLine();
    		StringTokenizer st=new StringTokenizer(buf," ");
    		int a = Integer.parseInt(st.nextToken());
    		int b = Integer.parseInt(st.nextToken());

    		if(a < b)
    			System.out.println("a < b");
    		else if(a > b)
    			System.out.println("a > b");
    		else if(a == b)
    			System.out.println("a == b");

    	} catch(IOException e) {
		    System.err.println(e);
		}
    }
}

Measured memory_bytes: 16856
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
class Main{
    public static void main(String[] a) throws IOException{
    	
    	Scanner scan = new Scanner(System.in);
    	while (scan.hasNext()){ 
    	String[] string = scan.nextLine().split(" ");
    	Stack <Double> que = new Stack<Double>();
 
    	for(int i = 0;i < string.length;i++){
    		if(string[i].equals("+")){
    			double x = que.pop();
    			double y = que.pop();
    			que.push(x+y);
    		}
    		else if(string[i].equals("-")){
    			double x = que.pop();
    			double y = que.pop();
    			que.push(y-x);
    			
    		}
    		else if(string[i].equals("*")){
    			double x = que.pop();
    			double y = que.pop();
    			que.push(x*y);
    		
    		}
    		else if(string[i].equals("/")){
    			double x = que.pop();
    			double y = que.pop();
    			que.push(y/x);
    		
    		}else{
    			que.push(Double.parseDouble(string[i]));
    		}
    		
    	}
    	
    	System.out.printf("%.6f\n", que.pop());

    }
 }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int N = 5;
vector<int> tyouriTime(5);

int main(){
    REP(i, N){
        cin >> tyouriTime.at(i);
    }

    int yojo = 9;
    int lastOrder = 0;
    REP(i, N){
        int nowYojo = tyouriTime.at(i) % 10;
        if(yojo >= nowYojo && nowYojo != 0){
            yojo = nowYojo;
            lastOrder = i;
        }
    }

    int ans = 0;
    REP(i, N){
        if(i != lastOrder){
            if(tyouriTime.at(i) % 10) ans += tyouriTime.at(i) + (10 - tyouriTime.at(i) % 10);
            else ans += tyouriTime.at(i);
        }else{
            ans += tyouriTime.at(i);
        }
    }

    cout << ans;


//    REP(i,5)cin>>v[i];
//    cin>>k;
//    bool ok = true;
//    REP(i,5){
//        REP(j,i){
//            int d = v[i]-v[j];
//            if(d>k)ok=false;
//        }
//    }
//    puts(ok ? "Yay!" : ":(");
//    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    A = []
    B = []
    for _ in range(n):
        a,b = map(int, input().split())
        A.append(a)
        B.append(b)
    import numpy as np
    a = np.array(A[::-1], dtype=int)
    ans = 0
    for i, b in enumerate(B[::-1]):
        tmp = (b - (a[i] + ans)%b) % b
        ans += tmp
    print(ans)


        

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    rep2(i, 1, n + 1)
    {
        if (a <= degit(i) && degit(i) <= b)
        {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> win[n+1];
  vector<int> in(n+1,0);
  for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      win[a].push_back(b);
      in[b]++;
  }

  queue<int> Q;
  for(int i=1;i<=n;i++){
      if(in[i]==0) Q.push(i);
  }

  vector<int> ans;
  int res=Q.size()==1?0:1;
  while(!Q.empty()){
      int tp=Q.front();
      Q.pop();

      ans.push_back(tp);
      int cnt=0;
      for(int i=0;i<win[tp].size();i++){
          int nex=win[tp][i];
          in[nex]--;
          if(in[nex]==0){
              Q.push(nex);
              cnt++;
          }
      }
      if(cnt>=2) res=1;
  }

  for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
  cout<<res<<endl;

  return 0;
}



Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C;
  cin>>A>>B>>C;
  int K;
  cin>>K;
  int no = true;
  while(B<=A)
  {
    if(K == 0)
    {
      no = false;
      break;
    }
    B=2*B;
    K--;
  }
  while(C<=B)
  {
    if(K == 0)
    {
      no = false;
      break;
    }
    C=2*C;
    K--;
  }
  if(no) cout<<"Yes";
  else cout<<"No";

}


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

signed main() {
    int N;  cin >> N;
    long res = 0;
    for (int i = 1; i <= N; ++i) res += (i % 3 != 0 and i % 5 != 0) * i;
    cout << res << endl;
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		Node T = null;
		for(int i = 0; i < n; ++i) {
			String[] str = br.readLine().split(" ");
			if(str[0].equals("insert")){
				T = Node.insert(T, new Node(Integer.parseInt(str[1])));
			}else if(str[0].equals("find")){
				if(Node.find(T, Integer.parseInt(str[1]))){
					System.out.println("yes");
				}else{
					System.out.println("no");
				}
			}else if(str[0].equals("delete")){
				Node.delete(T, Integer.parseInt(str[1]));
			}else{
				Node.printInOrder(T);
				Node.printPreOrder(T);
			}
		}
	
	}
}

class Node{
	public int key;
	public Node left;
	public Node right;
	public Node p;
	public Node(int key){
		this.key = key;
	}
	public static Node insert(Node T, Node z){
		Node y = null;
		Node x = T;
		while(x != null){
			y = x;
			if(z.key < x.key){
				x = x.left;
			}else{
				x = x.right;
			}
		}
		z.p = y;
		
		if(y == null){
			T = z;
		}else if(z.key < y.key){
			y.left = z;
		}else{
			y.right = z;
		}
		return T;
	}
	public static boolean find(Node T, int key){
		Node x = T;
		while(x != null){
			if(key == x.key){
				return true;
			}else if(key < x.key){
				x = x.left;
			}else{
				x = x.right;
			}
		}
		return false;
	}
	public static void delete(Node T, int key){
		Node z = T;
		while(key != z.key){
			if(key < z.key){
				z = z.left;
			}else{
				z = z.right;
			}
		}
		
		if(z.left == null || z.right == null){
			// case 1, 2
			Node c = null;
			if(z.left != null){
				c = z.left;
				c.p = z.p;
			}else if(z.right != null){
				c = z.right;
				c.p = z.p;
			}
			if(z.p.left == z){
				z.p.left = c;
			}else{
				z.p.right = c;
			}
		}else{
			// case 3
			Node n = z.right;
			while(n.left != null){
				n = n.left;
			}
			z.key = n.key;
			if(n.right == null){
				// case 1
				if(n.p.left == n){
					n.p.left = null;
				}else{
					n.p.right = null;
				}
			}else{
				// case 2
				n.p.left = n.right;
				n.right.p = n.p;
			}
		}
	}
	public static void printInOrder(Node T){
		StringBuilder sb = new StringBuilder();
		sb.append(' ');
		inOrder(T, sb);
		System.out.println(sb);
	}
	public static void inOrder(Node z, StringBuilder sb){
		if(z == null){
			return;
		}

		if(z.left != null){
			inOrder(z.left, sb);
			sb.append(' ');
		}
		sb.append(z.key);
		if(z.right != null){
			sb.append(' ');
			inOrder(z.right, sb);
		}
	}
	public static void printPreOrder(Node T){
		StringBuilder sb = new StringBuilder();
		sb.append(' ');
		preOrder(T, sb);
		System.out.println(sb);
	}
	public static void preOrder(Node z, StringBuilder sb){
		if(z == null){
			return;
		}
		sb.append(z.key);
		if(z.left != null){
			sb.append(' ');
			preOrder(z.left, sb);
		}
		if(z.right != null){
			sb.append(' ');
			preOrder(z.right, sb);
		}
	}
}

Measured memory_bytes: 129004
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    print((100000 - ni()) % 1000)
    return

solve()


Measured memory_bytes: 9120
#include<stdio.h>

main(){

  int a,b,i,x,y=0;

  while(1){ /* 無限ループ */
    x=0; 
    y++;
    scanf("%d %d",&a,&b);
    if(a==0 && b==0){
      break; //ループを抜ける
    }
    if(y!=1){
      printf("\n");
    }
    for(i=a;i<=b;i++){
      if(i%400==0){
	printf("%d\n",i);
	x=1; 
      }

      else if(i%4==0 && i%100!=0){
	printf("%d\n",i);
	x=1;
      }
    }
    if(x==0){
      printf("NA\n");
    }
  }
  return 0;
}

Measured memory_bytes: 616
n = int(input())
h = list(map(int, input().split()))
dp = [0] * (n+1)
dp[1] = 0
dp[2] = abs(h[1]-h[0])

for i in range(3, n+1):
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i-2]), dp[i-2]+abs(h[i-1]-h[i-3]))

print(dp[-1])

Measured memory_bytes: 13928
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

#define INF 999999999;
#define MOD 1000000007

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int N;
unsigned long long int A[35];

int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
    A[0] = 1;
    for(int i=1; i <= 30; i++){
        if(i==1)A[i] = A[i-1];
        else if(i==2)A[i] = A[i-1]+A[i-2];
        else if(i>=3)A[i] = A[i-1]+A[i-2]+A[i-3];
    }
    while(1){
        cin >> N;
        if(N == 0)break;
        cout << (A[N]+3650)/3650<< '\n';
    }

    return 0;
}


Measured memory_bytes: 3120
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
print(A*B if 1<=A<10 and 1<=B<10 else -1)

Measured memory_bytes: 5140
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int D = 0;
		int A = 0;
		
		
		int ans[]=new int[N+1];
		int anss = 0;
		
		for(int i=1;i<=K;i++){
			D = sc.nextInt();
			for(int j=1;j<=D;j++){
				A = sc.nextInt();
				ans[A]=1;	
			}
		}

		for(int k=1;k<=N;k++){
			if (ans[k]!=1) {
			anss=anss+1;
			}
		}

		System.out.println(anss);
    }
}

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

using namespace std;

int main(void){
    int h,w;
    cin >> h >> w;
    char arr[h][w];
    int mod = pow(10, 9.0) + 7;
    for (int i=0;i<h;i++){
        for (int j=0;j<w;j++){
            cin >> arr[i][j];
        }
    }

    long long dp[h][w];
    memset(dp, 0, sizeof(dp));

    for (int i=0;i<h;i++){
        if (arr[i][0] == '.'){
            dp[i][0] = 1;
        }else{
            break;
        }
    }

    for (int i=0;i<w;i++){
        if (arr[0][i] == '.'){
            dp[0][i] = 1;
        }else{
            break;
        }
    }
    
    for (int i=1;i<h;i++){
        for (int j=1;j<w;j++){
            if (arr[i][j] == '#'){
                continue;
            }
            if (arr[i-1][j] != '#'){
                dp[i][j] = dp[i][j] + dp[i-1][j];
                dp[i][j] = dp[i][j] % mod;
            }
            if (arr[i][j-1] != '#'){
                dp[i][j] = dp[i][j] + dp[i][j-1];
                dp[i][j] = dp[i][j] % mod;
            }
        }
    }

    if (arr[h-1][w-1] != '#'){
        cout << dp[h-1][w-1] << "\n";
    }else{
        cout << "0" << endl;
    }

    // for (int i=0;i<h;i++){
    //     for (int j=0;j<w;j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    return 0;
}

Measured memory_bytes: 9088
S = input()
X, Y = map(int, input().split())

X_move = [len(s) for s in S.split("T")[::2]]
Y_move = [len(s) for s in S.split("T")[1::2]]

X_reached = {X_move.pop(0)}
Y_reached = {0}

for x in X_move:
    tmp = set()
    for nx in X_reached:
        tmp.add(nx + x)
        tmp.add(nx - x)
    X_reached = tmp

for y in Y_move:
    tmp = set()
    for ny in Y_reached:
        tmp.add(ny + y)
        tmp.add(ny - y)
    Y_reached = tmp

print("Yes" if (X in X_reached) and (Y in Y_reached) else "No")


Measured memory_bytes: 49116
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL K;
LL A[200001];
LL B[200001];
map<LL,int>m;
int main(){
	LL ans=0;
	LL now=0;
	cin>>N>>K;
	REP(i,N){
		cin>>A[i];
		A[i]--;
	}
	m[0]=1;
	REP(i,N){
		now+=A[i];
		now%=K;
		B[i]=now;
		if(i==K-1){
			m[0]--;
		}
		if(i>K-1){
			m[B[i-K]]--;
		}
		ans+=m[now];
		m[now]++;
		//cout<<now<<endl;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	register short f=1;x=0;char c=getchar();
	while(!isdigit(c)){ if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
template<typename T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void writeln(T x){
	write(x),putchar('\n');
}
int main(){
	int n,a[100010],ans=1;short flag=0;
	read(n);
	for(int i=1;i<=n;i++)read(a[i]);
	for(int i=2;i<=n;i++){
		if(flag==1){
			if(a[i]<a[i-1])
				ans++,flag=0;
		}
		else if(flag==0){
			if(a[i]>a[i-1])flag=1;
			else if(a[i]<a[i-1])flag=-1;
		}
		else{
			if(a[i]>a[i-1])
				ans++,flag=0;
		}
	}
	writeln(ans);
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
long long int fif(long long int n){
  return n*n*n*n*n;
}
int main(void){
  long long int x,i,j;
  scanf("%lld",&x);
  /*for(i=0;fif(i)<x;i++){
    for(j=0;fif(j)+fif(i)<x;j++){
      if(fif(i)+fif(j)==x){
        printf("%lld -%lld\n",i,j);
        return 0;
      }
    }
  }*/
  for(j=0;;j++){
    for(i=0;fif(i)<=fif(j)+x;i++){
      if(fif(i)-fif(j)==x){
        printf("%lld %lld\n",i,j);
        return 0;
      }
      if(fif(i)+fif(j)==x){
        printf("%lld -%lld\n",i,j);
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1728
#include<stdio.h>

int main(void){
  int p,q,r;
  scanf("%d", &p);
  scanf("%d", &q);
  scanf("%d", &r);
  int d[3];
  d[0] = p+q;
  d[1] = p+r;
  d[2] = r+q;
  int min = d[0];
  if(d[1]<min){
    min = d[1];
  }
  if(d[2]<min){
    min = d[2];
  }
  printf("%d",min);
}

Measured memory_bytes: 128
def input_from_console():
    n, m = map(int, input().split())
    ab_list = []
    h_list = map(int, input().split())
    for i in range(m):
        a,b = map(int, input().split())
        ab_list.append((a, b))
    return n, m, list(h_list), list(ab_list)


def solve(n, m, h_list, ab_list):
    good_observatory = [True] * n
    for (a, b) in ab_list:
        if h_list[a-1] < h_list[b-1]:
            good_observatory[a - 1] = False
        if h_list[a-1] > h_list[b-1]:
            good_observatory[b - 1] = False
        if h_list[a-1] == h_list[b-1]:
            good_observatory[a - 1] = False
            good_observatory[b - 1] = False

    return sum(good_observatory)


def main():
    n, m, h_list, ab_list = input_from_console()
    print(solve(n, m, h_list, ab_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 33656
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
bitset<1000005>state,segtree[66];
bitset<10005>dp[2020];
int pos[2020];
string s[2020];
int n,k;
char get(){
	int now=1;
	while(now<32){
		if((state&segtree[now<<1]).none())now=now*2+1;
		else now*=2;
	}
	return 'a'+now-32;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>s[i];
	dp[n].set(0);
	for(int i=n-1;i>=0;i--){
		dp[i]=dp[i+1]|(dp[i+1]<<((int)s[i].size()));
	}
	string tmp="";
	for(int i=0;i<n;i++){
		pos[i]=tmp.size();
		tmp+=s[i];
	}
	pos[n]=tmp.size();
	for(int i=0;i<64;i++)segtree[i].reset();
	for(int i=0;i<tmp.size();i++){
		segtree[tmp[i]-'a'+32].set(i);
	}
	for(int i=31;i>=1;i--)segtree[i]=segtree[i<<1]|segtree[i<<1|1];
	state.reset();
	state[0]=1;
	string ans="";
	for(int i=0;i<k;i++){
		for(int j=0;j<n;j++)if(state[pos[j]])state.set(pos[j+1]);
		for(int j=0;j<n;j++)if(k-i-(int)s[j].size()<0||!dp[j+1][k-i-(int)s[j].size()])state.reset(pos[j]);
		char c=get();
		ans.push_back(c);
		state&=segtree[32+c-'a'];
		state<<=1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 13196
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    private static final int MOD = 1000003;
    private static final int[] STD = {5, 7, 5, 7, 7};

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        outer:
        while (true) {
            int n = in.nextInt(), m = in.nextInt();
            if (n == 0 && m == 0) break;
            int[] a = IntStream.range(0, n).map(x -> in.nextInt()).toArray();
            int[] b = IntStream.range(0, m).map(x -> in.nextInt()).toArray();
            int suma = IntStream.of(a).sum(), sumb = IntStream.of(b).sum();
            int inda = -1, indb = -1;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (suma - 2 * a[i] == sumb - 2 * b[j]) {
                        if (inda == -1 && indb == -1) {
                            inda = i;
                            indb = j;
                        } else if (a[inda] + b[indb] > a[i] + b[j]) {
                            inda = i;
                            indb = j;
                        }
                    }
                }
            }
            if (inda == -1)
                out.println(-1);
            else
                out.println(a[inda] + " " + b[indb]);
        }
        out.flush();
    }
}



Measured memory_bytes: 33832
n = int(input())
s = input()

b_cnt = [0] * (n + 1)
for i in range(n):
    if s[i] == '#':
        b_cnt[i + 1] = b_cnt[i] + 1
    else:
        b_cnt[i + 1] = b_cnt[i]

ans = n
for i in range(n + 1):
    ans = min(ans, ((n - i) - (b_cnt[n] - b_cnt[i])) + b_cnt[i])

print(ans)


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

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main() {
    
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    for(int i=0;i<N;i++){
        cin >> x.at(i) >> y.at(i);
    }
    map<string, int> pq;
    int max = 0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            long long p = x.at(i)-x.at(j);
            long long q = y.at(i)-y.at(j);
            string key = to_string(p) + "_" + to_string(q);
            if(pq.count(key) == 0){
                pq[key] = 1;
            }
            else{
                pq[key] += 1;
            }
            if(max < pq[key]){
                max = pq[key];
            }
            p = x.at(j)-x.at(i);
            q = y.at(j)-y.at(i);
            key = to_string(p) + "_" + to_string(q);
            if(pq.count(key) == 0){
                pq[key] = 1;
            }
            else{
                pq[key] += 1;
            }
            if(max < pq[key]){
                max = pq[key];
            }
        }
    }
    cout << N - max << endl;
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int arr[30];
int main(void)
{
    int N;
    cin >> N;

    for (int i = 0; i < 26; ++i)
        arr[i] = 1e9;

    for (int i = 0; i < N; ++i)
    {
        string s;
        cin >> s;
        int alph[26];
        for (int j = 0; j < 26; ++j)
            alph[j] = 0;

        for (int j = 0; j < s.size(); ++j)
        {
            alph[s[j] - 'a']++;
        }

        for (int j = 0; j < 26; ++j)
        {
            arr[j] = min(arr[j], alph[j]);
        }
    }

    string ans = "";
    for (int i = 0; i < 26; ++i)
    {
        for (int j = 0; j < arr[i]; ++j)
        {
            ans += (char)('a' + i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
///a = 97  z = 122
///A = 65  Z = 90

#include <bits/stdtr1c++.h>
//#include <boost/algorithm/string.hpp>

using namespace std;

#define endl                "\n"
#define pb                  push_back
#define pii                 pair<int, int>
#define mp                  make_pair
#define x                   first
#define y                   second
#define all(v)			    ((v).begin()), ((v).end())
#define sz(v)			    ((int)((v).size()))
#define ll                  long long
#define rep(i,n)            for(int i=0 ; i<sz(n) ; i++)
#define lp(i, n)            for(int i = 0 ; (int)i<n ; i++)
#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)
#define ms(arr, v)      memset(arr, v, sizeof arr)
typedef vector<vector<char>> vcc;
typedef vector<int> vi;
typedef deque<int> de;

int n;
const int N = 105;
int arr[N];

int mn, res;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif*/

    cin >> n;
    mn = INT_MAX;
    loop(i, 1, n) cin >> arr[i];
    loop(i, 1, 100)
    {
        res = 0;
        loop(j, 1, n)
        {
            res += (arr[j] - i) * (arr[j] - i);
        }
        mn = min(mn, res);
    }
    cout << mn << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    for(int i=1; i<=n; ++i){
        int x=i;
        if(i%3==0){
            cout<<" "<<i;
            continue;
        }
        while(x!=0){
            if(x%10==3){
                cout<<" "<<i;
                break;
            }
            x/=10;
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(void)
{
	int line,n;
	scanf("%d",&line);
	scanf("%d",&n);

	int values[line],i;
	for(i=0;i<line;i++)
	{
		values[i] = i+1;
	}


	for(i=0;i<n;i++)
	{
		int a,b;
		scanf("%d,%d",&a,&b);
		int value = values[a-1];
		values[a-1] = values[b-1];
		values[b-1] = value;
	}

	for(i=0;i<line;i++)
	{
		printf("%d\n",values[i]);

	}

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>

#define MAX_LENGTH 100

using namespace std;

int main(){

    unsigned int n, i, score[2] = {0};
    string taro, hanako;

    cin >> n;

    for( i = 0; i < n; i++ ){
        
        cin >> taro >> hanako;
        
        unsigned int flag = 0;

        if(taro == hanako){
            score[0]++;
            score[1]++;

        }else{

            unsigned int j = 0;

            while( taro[j] != '\0' || hanako[j] != '\0'){
                if( taro[j] > hanako[j] ){
                    score[0] += 3;
                    flag = 1;
                    break;
                }else if( taro[j] < hanako[j] ){
                    score[1] += 3;
                    flag = 1;
                    break;
                }
                j++;
            }

            if(flag == 0){
                if( taro.length() > hanako.length() ){
                    score[0] += 3;
                }
                else{
                    score[1] += 3;
                }
            }
        }

    }

    cout << score[0] << " " << score[1] << endl;

    return 0;

}


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

int r, c, n, x, y, num, cnt;
bool v[105][105];
int main()
{
    int i, j, k;
//    freopen ("input.txt", "r", stdin);
    cin >>  c >> r >> n;
    for (i = 0; i < n; i++) {
        scanf ("%d %d %d", &x, &y, &num);
        if (num == 1) {
            for (j = 1; j <= r; j++) {
                for (k = 1; k <= x; k++) {
                    v[j][k] = true;
                }
            }
        } else if (num == 2) {
            for (j = 1; j <= r; j++) {
                for (k = x + 1; k <= c; k++) {
                    v[j][k] = true;
                }
            }
        } else if (num == 3) {
            for (j = 1; j <= y; j++) {
                for (k = 1; k <= c; k++) {
                    v[j][k] = true;
                }
            }
        } else if (num == 4) {
            for (j = r; j >= y + 1; j--) {
                for (k = 1; k <= c; k++) {
                    v[j][k] = true;
                }
            }
        }
    }
    for (i = 1; i <= r; i++) {
        for (j = 1; j <= c; j++) {
            if (!v[i][j]) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

ll n,q,k;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main(){
    cin >> n;
    Graph G(n);
    for(ll i=0;i<n-1;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back(Edge(b, c));
        G[b].push_back(Edge(a, c));
    }
    cin >> q >> k;
    k--;
    queue<ll> que;
    vector<ll> dist(n,-1);
    que.push(k);
    dist[k]=0;
    while(!que.empty()){
        auto v=que.front();
        que.pop();
        for(auto nv:G[v]){
            if(dist[nv.to]!=-1) continue;
            que.push(nv.to);
            dist[nv.to]=dist[v]+nv.weight;
        }
    }
    for(ll i=0;i<q;i++){
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        cout << dist[x]+dist[y] << endl;
    }
}  


Measured memory_bytes: 11140
/*input
WBBBW
*/

#include <iostream>

using namespace std;

int main()
{

	string S;
	cin >> S;
	// cout << "str: " << S << endl;

	if(S.size() == 1){
		cout << 0 << endl;
		return 0;
	}

	int count = 0;

	string s;
	s = S.substr(0,1);
	for(int i=1;i<S.size();i++){
		if(s != S.substr(i,1)){
			count++;
			s = S.substr(i,1);
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 512
n,m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i).sort

if n >= m
    puts 0
else
    l = []
    (m-1).times{|i| l << x[i+1] - x[i]}
    l.sort_by!{|e| -e}

    puts x[m-1] - x[0] - (n == 1 ? 0 : l[0..n-2].inject(:+))
end

Measured memory_bytes: 13168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


ll ansc,ansd,anse,ansf;


int main() {
  ll s;
  cin >> s;
  ll up = sqrt(s);
  ll wd = up;
  while(up*wd<s && wd<pow(10,9)){
    wd++;
    if(wd==pow(10,9)){
      ++up;
      wd = up;
    }
  }

  bool flag = false;

  ll area = up*wd*2;

  if(up*wd==s) {
    flag = true;
    ansc = wd;
    ansd = 0;
    anse = 0;
    ansf = up;
  }

  else{

  for(ll i=1;i<up;++i){
    for(ll j=1;j<wd;++j){
      ll rec = area - (wd*i+up*j+(wd-j)*(up-i));
      if(rec==s){
        flag = true;
        ansc = wd;
        ansd = i;
        anse = j;
        ansf = up;
        break;
        // cout << 9999 << endl;
      }
      else if(rec<s) break;
    }
    if(flag == true) break;
  }

  }

  cout << 0 << " " << 0 << " " << ansc << " " << ansd << " " << anse << " " << ansf << endl;


}



Measured memory_bytes: 256
n = gets.to_i
s = gets.split("")
w = 0
e = 0
s_sum = []
for i in 0..n-1 do
  if s[i] == "W"
    w += 1
  else
    e += 1
  end
  s_sum << [w,e]
end

res = []
res << s_sum[n-1][1] -s_sum[0][1] #i==0
res << s_sum[n-2][0] #i==n-1
for i in 1..n-2 do #リーダーの場所
  num = s_sum[n-1][1] - s_sum[i][1] #eにあるe
  num += s_sum[i-1][0] #wにあるw
  res << num
end

puts res.min

Measured memory_bytes: 41740