akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.List

type Pair = (Int, Int)

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  abs <- replicateM n readPair
  print $ f m $ sortOn fst abs

f :: Int -> [Pair] -> Int
f m = fst . foldl' f e
  where
    e = (0,0)
    f (s,n) (a,b)
      | n == m = (s,n)
      | n+b > m = until ((m==).snd) (\(s,n) -> (s+a,n+1)) (s,n)
      | n+b < m = (s+a*b, n+b)
      | n+b == m = (s+a*b, n+b)
      | otherwise = error ":("

readPair :: IO Pair
readPair = do
  [x,y] <- map read . words <$> getLine
  return (x,y)

Measured memory_bytes: 93052
#include <stdio.h>

#define DATA_SET_MAX 100

int main() {
    int H[DATA_SET_MAX];
    int W[DATA_SET_MAX];
    int cnt;

    for (int i = 0; i < DATA_SET_MAX; i++){
        scanf("%d %d", &H[i], &W[i]);

        if ((H[i] == 0) && (W[i] == 0)) {
            cnt = i;
            break;
        }
        else {
            /* NOP */
        }
    }

    for (int i = 0; i < cnt; i++) {
        for (int tate = 0; tate < H[i]; tate++) {
            for (int yoko = 0; yoko < W[i]; yoko++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
      
}


Measured memory_bytes: 2060
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    x = list(map(int, readline().split()))
    for i in range(1, 6):
        if i not in x:
            print(i)
            break


if __name__ == '__main__':
    main()


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

int main(){
	vector<int> h(10);
	for(int i = 0 ; i < 10 ; i++) cin >> h[i];
	sort(h.begin(),h.end());
	for(int i = 0 ; i < 3 ; i++)
		cout << h[9-i] << endl;
}

Measured memory_bytes: 3124
x,n=map(int, input().split())
p=list(map(int, input().split()))

ans = x

min_num = 10**9
for i in range(-200,301):
    if p.count(i) == 0:
        if min_num > abs(x-i):
            min_num = abs(x-i)
            ans = i

print(ans)


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

const long long INF = 1e10;

int main() {
    int N, M;
    while (cin >> N >> M, N) {
        vector<int> C(M);
        for (int i=0; i<M; ++i) cin >> C[i];
        vector<int> x(N);
        for (int i=0; i<N; ++i) cin >> x[i];

        vector<long long> cost(256, INF);
        cost[128] = 0;
        for (int i=0; i<N; ++i) {
            vector<long long> cost2(256, INF);
            for (int cd: C) {
                for (int k=0; k<256; ++k) {
                    int kk = max(min(k+cd, 255), 0);
                    cost2[kk] = min(cost2[kk], cost[k] + (kk - x[i]) * (kk - x[i]));
                }
            }
            cost = cost2;
        }

        long long ans = *min_element(cost.begin(), cost.end());
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3168
// AtCoder Regular Contest 069
// C - Scc Puzzle

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;


ll N, M;
ll ans;

int main() {

  ll x;

  scanf("%lld%lld", &N, &M);
  x = max((M - 2 * N) / 4, (ll)0);
  ans = min(N + x, M / 2 - x);

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

  return 0;

}




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

int main() {
    string S, T; cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i]) ans++;
    }
    cout << ans << endl;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  int a,b,c,d; cin>>a>>b>>c>>d;
  int i = 0;
  while(1){
    c-=b;
    if(c<=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    a-=d;
    if(a<=0){
      cout<<"No"<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstring>
using namespace std;
int a[200005];
int b[200005];
bool vis[200005];
int main(){
	int N,M,i;
	cin>>N>>M;
	memset(vis,false,sizeof(vis));
	for(i=0;i<M;i++){
		cin>>a[i]>>b[i];
		if(a[i]==1)
			vis[b[i]]=true;
	}
	for(i=0;i<M;i++){
		if(b[i]==N){
			if(vis[a[i]]==true){
				cout<<"POSSIBLE"<<endl;
				break;
			}
		}
	}
	if(i==M)
		cout<<"IMPOSSIBLE"<<endl;
	return 0;
} 

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

struct CARD{
        char ch;
        int n;
};

template<class T>
void bubbleSort(T* array, int size)
{
        for(int i=size; i>0; i--){
                for(int j=0; j<i-1; j++){
                        if( array[j].n > array[j+1].n ){
                                T tmp = array[j+1];
                                array[j+1] = array[j];
                                array[j] = tmp;
                        }
                }
        }
}

template<class T>
void selectionSort(T* array, int size)
{
        int min;
        for(int i=0; i<size-1; i++){
                min = i;
                for(int j=i+1; j<size; j++){
                        if( array[j].n < array[min].n ){ min = j; }
                }
                T tmp;
                if( min != i){
                        tmp = array[min];
                        array[min] = array[i];
                        array[i] = tmp;
                }
        }
}



int main()
{
        int n;
        cin >> n;
        struct CARD array1[n], array2[n];
        for(int i=0; i<n; i++){
                string str;
                cin >> str;
                array1[i].ch = str[0];
                array2[i].ch = str[0];
                array1[i].n = str[1] - '0';
                array2[i].n = str[1] - '0';
                if( str.length() == 3){
                        array1[i].n *=10;
                        array2[i].n *=10;
                        array1[i].n += str[2] - '0';
                        array2[i].n += str[2] - '0';
                }
        }
        
        /* BubbleSort */
        bubbleSort(array1, n);
        cout << array1[0].ch << array1[0].n;
        for(int i=1; i<n; i++){
                cout << " " << array1[i].ch << array1[i].n;
        }
        cout << endl;
        cout << "Stable" << endl;

        /* SelectionSort */
        selectionSort(array2, n);
        bool flag = true;
        for(int i=0; i<n; i++){
                if( array1[i].n != array2[i].n || array1[i].ch != array2[i].ch ){
                        flag = false;
                }
        }
        cout << array2[0].ch << array2[0].n;
        for(int i=1; i<n; i++){
                cout << " " << array2[i].ch << array2[i].n;
        }
        cout << endl;
        if(flag == true){
                cout << "Stable" << endl;
        }else{
                cout << "Not stable" << endl;
        }

        return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll N;
string S;

char SW(char a1, char a2, char xo){
  if(((a1 == a2) && (xo == 'o')) || ((a1 != a2) && (xo == 'x'))){
    return 'S';
  } else{
    return 'W';
  }    
}

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

  vc r(N);

  vector<pair<char, char>> init(4);

  init[0] = {'S', 'S'};
  init[1] = {'S', 'W'};
  init[2] = {'W', 'S'};
  init[3] = {'W', 'W'};
  
  rep(i, 4){
    r[0] = init[i].first;
    r[1] = init[i].second;

    rep2(j, 2, N) r[j] = SW(r[j - 2], r[j - 1], S[j - 1]);

    if((SW(r[N - 2], r[N - 1], S[N - 1]) == r[0]) && (SW(r[N - 1], r[0], S[0]) == r[1])){
      rep(j, N) cout << r[j];
      cout << endl;

      return 0;
    }
  }

  cout << -1 << endl;
  
  return 0;
}


Measured memory_bytes: 512
/*
    Code written by Talant I.D.
*/
   
#include <bits/stdc++.h>
   
using namespace std;
   
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
   
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);
#define curMod 998244353

int main(){
		//do_not_disturb
		string s;
		cin >> s;
		if(s == "Sunny")	cout << "Cloudy";
		else if(s == "Cloudy") cout << "Rainy";
		else cout << "Sunny";
		cout << endl;
		
    return 0;
} // What is to be written here?


Measured memory_bytes: 256
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mInt = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 100000000



int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<string> S(N);
	rep(i,N)cin>>S[i];
	
	mf_graph<int> G(N*M+2);
	int from = N*M,to = N*M+1;
	
	vector<int> dx = {1,0,-1,0},dy = {0,-1,0,1};
	
	rep(i,N){
		rep(j,M){
			if(S[i][j]=='#')continue;
			if((i+j)%2==0){
				G.add_edge(from,i*M+j,1);
				rep(k,4){
					int y = i+dy[k];
					int x = j+dx[k];
					if(y<0||y>=N||x<0||x>=M)continue;
					if(S[y][x]=='#')continue;
					G.add_edge(i*M+j,y*M+x,1);
				}
			}
			else{
				G.add_edge(i*M+j,to,1);
			}
		}
	}
	
	cout<<G.flow(from,to)<<endl;
	
	vector<mf_graph<int>::edge> E = G.edges();
	
	rep(i,E.size()){
		if(E[i].flow==0)continue;
		if(E[i].from==from||E[i].to==to)continue;
		pair<int,int> a(E[i].from/M,E[i].from%M),b(E[i].to/M,E[i].to%M);
		if(a>b)swap(a,b);
		if(a.first+1==b.first){
			S[a.first][a.second] = 'v';
			S[b.first][b.second] = '^';
		}
		else{
			S[a.first][a.second] = '>';
			S[b.first][b.second] = '<';
		}
	}
	
	rep(i,N)cout<<S[i]<<endl;
	
    return 0;
}

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

int main(){
    int n,m;
    int acsum = 0,wasum = 0;
    cin >> n >> m;
    int WA[100001];
    bool AC[100001];
    rep(i,n){
        WA[i] = 0;
        AC[i] = 0;
    }
    
    int j;
    string han;
    rep(i,m){
        cin >> j >> han;
        if(han == "AC" && AC[j] == true) continue;
        else if(han == "AC" && AC[j] == false){
            AC[j] = true;
            acsum++;
            wasum += WA[j];
        }
        else if(han == "WA") WA[j]++;
    }
    cout << acsum << ' ' << wasum;
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>

int main(){
	char a;
	scanf("%c", &a);
	
	if(a <= 'z' && a >= 'a'){
		printf("a\n");
	}
	else if(a <= 'Z' && a>='A'){
		printf("A\n");
	}
	
	return 0;
}

Measured memory_bytes: 1576
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;cin>>n;
	map<ll,ll> p;
	for(int i = 0; i < n; i++) {
		ll key;
		cin>>key;
		auto it = p.find(key);
		if(it != p.end()){
			p[key]++;
			if(p[key] >= 3){
				p[key] = 1;
			}
		}
		else{
			p[key] = 1;
		}
	}
	int c = 0;
	for(auto i = p.begin(); i != p.end(); i++) {
		if(p[i->first] == 2){
			c++;
		}
	}

	if(c % 2 == 0){
		cout << p.size() << endl;
	}
	else{
		cout << p.size() - 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 6528
#include <iostream>

using namespace std;

int main() {
  int k;
  cin >> k;
  int x = 7 % k;
  for (int it = 0; it < 3 * k; it++) {
    if (!x) {
      cout << it + 1 << endl;
      return 0;
    }
    x = (x * 10 + 7) % k;
  }
  cout << -1 << endl;
}



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
const double INF = 1e10;
const double EPS = 1e-8;

struct Point {
	double x, y;
	Point() : x(0), y(0) { }
	Point(double x, double y) : x(x), y(y) { }
	Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
	Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
	Point operator*(double s) const { return Point(x * s, y * s); }
	Point operator/(double s) const { return Point(x / s, y / s); }
	Point &operator+=(const Point &p){ x += p.x; y += p.y; return *this; }
	Point &operator-=(const Point &p){ x -= p.x; y -= p.y; return *this; }
	Point &operator*=(double s){ x *= s; y *= s; return *this; }
	Point &operator/=(double s){ x /= s; y /= s; return *this; }
	bool operator==(const Point &p) const { return x == p.x && y == p.y; }
	bool operator!=(const Point &p) const { return x != p.x || y != p.y; }
	bool operator<(const Point &p) const {
		return (x == p.x) ? (y < p.y) : (x < p.x);
	}
};
inline Point operator*(double s, const Point &p){ return p * s; }

inline double norm(const Point &p){ return p.x * p.x + p.y * p.y; }
inline double abs(const Point &p){ return sqrt(norm(p)); }
inline double arg(const Point &p){ return atan2(p.y, p.x); }
inline Point unit(const Point &p){ return p / abs(p); }
inline Point ortho(const Point &p){ return Point(-p.y, p.x); }

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<Point> p(n);
		for(int i = 0; i < n; ++i){ cin >> p[i].x >> p[i].y; }
		const double limit = (1.0 + EPS) * (1.0 + EPS);
		int answer = 1;
		for(int i = 0; i < n; ++i){
			const Point a = p[i];
			for(int j = i + 1; j < n; ++j){
				const Point b = p[j];
				if(abs(b - a) > 2.0){ continue; }
				const Point c = (a + b) * 0.5;
				const Point v = unit(ortho(b - a));
				const double t = sqrt(1.0 - norm(b - c));
				const Point q[2] = { c + v * t, c + v * -t };
				for(int k = 0; k < 2; ++k){
					int count = 0;
					for(int l = 0; l < n; ++l){
						if(norm(p[l] - q[k]) <= limit){ ++count; }
					}
					answer = max(answer, count);
				}
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


vector<ll> Eratosthenes( const ll N )
{
    std::vector<bool> is_prime( N + 1 );
    for( ll i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<ll> P;
    for( ll i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( ll j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}


int main(){
    vl A=Eratosthenes(101);
    ll N;
    cin >> N;
    Map count;
    for(auto p: A){
        ll s=N;
        ll ret=0;
        while(s>0){
           s/=p;
           ret+=s; 
        }
        count[p]=ret;
    }
    Map R;
    for(auto p: count){
        R[p.second]++;
    }
    ll N75=0,N25=0,N15=0,N5=0,N3=0;
    for(ll i=100;i>=74;i--)N75+=R[i];
    N25+=N75;
    for(ll i=73;i>=24;i--)N25+=R[i];
    N15+=N25;
    for(ll i=23;i>=14;i--)N15+=R[i];
    N5+=N15;
    for(ll i=13;i>=4;i--)N5+=R[i];
    N3+=N5;
    for(ll i=3;i>=2;i--)N3+=R[i];
    ll ans=0;
    //3,5,5
    if(N5>=2&&N3>=3)ans+=(N5*(N5-1)/2)*(N3-2);
    //3,25
    if(N25>=1&&N3>=2)ans+=N25*(N3-1);
    //5,15
    if(N15>=1&&N5>=2)ans+=N15*(N5-1);
    //75
    if(N75)ans+=N75;

    print(ans)

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
const int N = 303;
int n;
ll a[N][N];
ll ans = 0;
 
int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
 
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			scanf("%lld", &a[i][j]);
		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < i; j++) {
			ll w = a[i][j] + 1;
			for (int k = 0; k < n; k++) {
				if (i == k || j == k) continue;
				w = min(w, a[i][k] + a[k][j]);
			}
			if (w < a[i][j]) {
				printf("-1\n");
				return 0;
			}
			if (w > a[i][j]) ans += a[i][j];
		}
	printf("%lld\n", ans);
 
	return 0;
}

Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var x int
	fmt.Fscan(r, &x)

	quotient := x / 11
	remainder := x % 11
	if remainder == 0 {
		fmt.Println(quotient * 2)
	} else if remainder <= 6 {
		fmt.Println(quotient*2 + 1)
	} else {
		fmt.Println(quotient*2 + 2)
	}
}


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

int main() {
	int n,m,ans;
	cin >> n>>m;
	ans =1;
	if(n==1){
		ans=m;
	}else{
		for(int i=1;i<=m;++i) {
			if(i*n<=m){
				if(m%i==0){
					ans = i;
				}
			}else{
				break;
			}
		}
	}
	
	cout<< ans<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    #define lim 100000
    int num[lim];
    
    rep(i, lim){
        num[i] = 0;
    }
    int a;
    rep(i, n){
        cin >> a;
        if(a == 0){
            num[0]++;
            num[1]++;
        }else if(a == 100000 - 1){
            num[lim - 1]++;
            num[lim - 2]++;
        }else{
            num[a - 1]++;
            num[a]++;
            num[a + 1]++;
        }
    }
    int ans = 0, ans_num;
    
    rep(i, lim){
        if(ans < num[i]){
            ans_num = i;
            ans = num[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    sort(ALL(v));
    double ans = v[0];
    for (ll i = 1; i < n; i++)
    {
        ans = (ans + v[i]) / 2;
    }
    cout << SP(10) << ans << endl;
}

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

using namespace std;

#define ma 100000
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int lcm(int a,int b){
  return (a*b)/(gcd(a,b));
  
}
int main() {
  int n,a,b;
 ios_base::sync_with_stdio(false);
 cin.tie(0);
 int t;
 cin>>t;
 int k=lcm(t,360);
 int x=k/t;
 cout<<x;
 
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int N,D;
    int ans=0;
    cin>>N>>D;
    double sqrtx=0;
    vector<vector<double>> x(N,vector<double>(D));
    rep(i,N){
        rep(j,D){
            cin>>x[i][j];

        }
    }
    rep(i,N-1){
        FOR(j,i+1,N-1){
            sqrtx=0;
            rep(k,D){
                sqrtx+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            sqrtx=sqrt(sqrtx);
            if(floor(sqrtx)==sqrtx){
                ans++;
            }
        }
    }
    

    Out(ans);
    return 0;
}

Measured memory_bytes: 256
N=int(input())
r=0
W=[]
for i in range(N):
    W.append(input())

for i in range(N-1):
    if W[i+1][0]!=W[i][-1]:
        r = r+1
for i in range(N):
    for p in range(N):
        if W[i]==W[p]:
            r = r+1
if r == N:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n=int(input());s=input()
w=[0]*(n+1);e=[0]*(n+1)

for i in range(0,n):
  w[i+1]=w[i]
  if (s[i]=='W'):
    w[i+1]+=1

for i in range(n,0,-1):
  e[i-1]=e[i]
  if (s[i-1]=='E'):
    e[i-1]+=1
    
a=2*n
for i in range(n+1):
  a=min(a,w[i]+e[i])
print(a)

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

int main (){
	int n;
	cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        ans.at(a.at(i)-1)=i+1;
    }  
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }

}


Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	int e[100]={};
	for(int i=2; i<=n; i++){
		int i0=i;
		for(int p=2; p<=n; p++){
			if(i0%p==0){
				int e1=0;
				while(i0%p==0){
					i0/=p;
					e1++;
				}
				e[p]+=e1;
			}
		}
	}
	int dp[100][76]={};
	dp[1][1]=1;
	for(int i=2; i<100; i++){
		for(int j=1; j<=75; j++){
			for(int k=1; k<=e[i]+1; k++){
				if(j%k==0){
					dp[i][j]+=dp[i-1][j/k];
				}
			}
		}
	}
	cout<<dp[99][75]<<endl;
	return 0;
}

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

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main (){
    int n;
    ll ans=0;
    cin >> n;
    map<char,ll>mp;
    rep(i,n){
        string s;
        cin >>s;
        char c=s[0];
        if(c=='M'||c=='A'||c=='R'||c=='C'||c=='H'){
            mp[c]++;
        }
    }
    int l=mp.size();
    if(l<3){
        cout << 0 << endl;
        return 0;
    }
    else{
        vector<ll>march(l);
        int s=0;
        for(auto p:mp) {
            march[s]=p.second;
            s++;
        }
        for(int i=0;i<l;i++){
            for(int j=i+1;j<l;j++){
                for(int k=j+1;k<l;k++){
                    ans+=march[i]*march[j]*march[k];
                }
            }
        }
        cout << ans <<endl;
        return 0;
    }
}



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

using ll = long long;
//typedef long long ll;

#define INF ((1LL << 31) - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

struct edge {
    int u, v, cost;
    edge() {}
    edge(int u, int v, int cost) : u(u), v(v), cost(cost) {}
};
  

/* UnionFindTree Begin
   --------------------------------------------------------------------------
*/
class UnionFind {
private:
  int size_;
  vector<int> par, rank;
  
public:
  UnionFind() : size_(0), par(vector<int>(0)), rank(vector<int>(0)) {}
  UnionFind(int size_) : size_(size_) {
    par.resize(size_), rank.resize(size_);
    rep(i,size_) par[i] = i, rank[i] = 0;
  }
  
  // 現在のsize_を返す
  int size() { return size_; }
  
  // 親を返す
  int root(int x) { return (par[x] == x) ? x : par[x] = root(par[x]); }
  
  // ２つの頂点を連結する
  void unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  
  // 親が同じかを判定する
  bool same(int x, int y) { return root(x) == root(y); }
};
/* UnionFindTree End
   --------------------------------------------------------------------------
*/

/* Kruskal Begin
   -------------------------------------------------------------------------
*/

bool comp(const edge &e1, const edge &e2) {
  return e1.cost < e2.cost;
}

// 100000 の部分は適宜変更
int n, m;
edge e[51];

bool kruskal(int x) {
  //sort(e, e + m, comp);
  UnionFind uf(n);
  int ret = 0, cnt = 0;

  for (int i = 0; i < m; ++i) {
    if (i == x) continue;
    edge a = e[i];
    if (!uf.same(a.u, a.v)) {
      uf.unite(a.u, a.v);
      cnt++;
    }
  }

  return (cnt == n - 1) ? true : false;
}

/* Kruskal End
   -------------------------------------------------------------------------
*/

int a, b;

int main() {
    init();
    cin >> n >> m;
    rep(i,m) {
        cin >> a >> b;
        a--, b--;
        e[i] = {a, b, 1};
    }

    int ans = 0;

    rep(i,m) {
        if (!kruskal(i)) ans++;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main(void) {
	int n;
	cin>>n;
	string str;
	cin >> str;
	int x = 0,max=0;

	for (auto i = 0; i < str.length(); i++) {
		if (str[i] == 'I') {
			x++;
			if (max < x)max = x;
		}
		else
			x--;
	}

	cout << max << endl;
	return 0;
}

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

using namespace std;

int main()
{ int a,b;
  cin>>a>>b;
  std::string str;
  std::string str1;
  for (int i=0;i<a;i++){
    str +=std::to_string(b);
  }
  for (int i=0;i<b;i++){
    str1 += std::to_string(a);
  }
  if (str==str1){
    cout<<str<<endl;
  }
  else if (str<str1){
    cout<<str<<endl;
  }
  else{
    cout<<str1<<endl;
  }
    return 0;
}

Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
s = input()
K = int(input())

dic = set()

for i in range(len(s)):
  for j in range(1, 6):
    if len(s[i:i+j])>0:
      dic.add(s[i:i+j])

ans = sorted(list(dic))
print(ans[K-1])

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

int main(void) {
	string A, B, C;
	cin >> A >> B >> C;
	int Aend = A.length() - 1;
	int Bend = B.length() - 1;
	string ans = "NO";
	if ((A[Aend] == B[0]) && (B[Bend] == C[0]))
		ans = "YES";
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#050_C
n=int(input())
a=sorted(list(map(int,input().split())))
mod=10**9+7

if n%2:
    if all(-(-i//2)*2==a[i] for i in range(n)):
        print(pow(2,n//2,mod))
    else:
        print(0)
else:
    if all((i//2)*2+1==a[i] for i in range(n)):
        print(pow(2,n//2,mod))
    else:
        print(0)

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if ((A == B && A != C) || (A == C && A != B) || (B == C && B != A))
    {
        cout << "Yes" << endl;
    } else
    {
        cout << "No" << endl;
    }
    
    
    
  return 0;
}


Measured memory_bytes: 256
n, y = [int(x) for x in input().split(' ')]
q, mod = divmod(y, 10000)

if n * 10000 > y and y > (n-1)* 10000 + 5000:
	print('-1 -1 -1')
else:
	if q == n and mod == 0:
		print('{} 0 0'.format(q))
	else:
		for a in range(q+1):
			b = int((y - 1000 * n - 9000 * a) / 4000)
			c = int((5000 * n - y + 5000 * a) / 4000)
			if a + b + c == n and a >= 0 and b >= 0 and c >= 0 and 10000 * a + 5000 * b + 1000 * c == y:
				print('{} {} {}'.format(a, b, c))
				break
		else:
			print('-1 -1 -1')


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
    char s1[11],s2[11],s3[11];
    int dig;
    scanf("%s %s %s",s1,s2,s3);
    if('A'<='a'){
        dig='a'-'A';
        printf("%c%c%c",s1[0]-dig,s2[0]-dig,s3[0]-dig);
    }
    else{
        dig='A'-'a';
        printf("%c%c%c",s1[0]+dig,s2[0]+dig,s3[0]+dig);
    }
    return 0;
}

Measured memory_bytes: 128
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd

mod=10**9+7
#N=int(input())
S=input()
Q=int(input())
Query=[list(input().split()) for i in range(Q)]


lst=deque(S)

flag=0
for query in Query:
    if len(query)==1:
        flag+=1
        flag%=2
    else:
        _,F,C=query
        if (int(F)+flag)%2:
            lst.appendleft(C)
        else:
            lst.append(C)

if flag:
    lst.reverse()
print("".join(lst))


Measured memory_bytes: 136276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll n; cin >> n;
    vector<int> a(n);
    bool ok = false;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 2) ok = true;
        a[i]--;
    }
    if (!ok) {
        cout << "-1" << endl;
        return 0;
    }

    int button = 0;
    int count = 1;
    while (a[button] != 1 && count <= n) {
        button = a[button];
        count++;
    }
    if (a[button] == 1) {
        cout << count << endl;
    }
    else {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 3784
import heapq
N,M = list(map(int, input().split(" ")))
Xs = sorted(list(map(int, input().split(" "))))

if N >= M :
	print(0)
	exit()
	
darr = [Xs[i+1] - Xs[i]for i in range(M-1)]

# print(darr)
heapq.heapify(darr)
res = 0

for _ in range(M - N):
	res += heapq.heappop(darr)
	
print(res)

Measured memory_bytes: 13960
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    const int nh = 100000 / 2;
    std::array<int, nh> a;
    std::array<int, nh> b;
    
    const int vwmax = 100000;
    std::array<int, vwmax> v = {};
    std::array<int, vwmax> w = {};
    
    int n;
    cin >> n;
    
    for (int i = 0; i < n / 2; i++){
        cin >> a[i] >> b[i];
    }
    
    for (int i = 0; i < n / 2; i++){
        v[a[i]]++;
        w[b[i]]++;
    }
    
    int* vp = max_element(v.begin(), v.end());
    int* wp = max_element(w.begin(), w.end());
    
    int vval = *vp;
    int wval = *wp;
    
    long int vpos = vp - v.begin();
    long int wpos = wp - w.begin();
    
    if(vpos != wpos) {
        cout << (n/2 - vval) + (n/2 - wval) << endl;
    } else {
        v[vpos] = 0;
        w[wpos] = 0;
        int* vp2 = max_element(v.begin(), v.end());
        int* wp2 = max_element(w.begin(), w.end());
        if(*vp2 >= *wp2) {
            cout << (n/2 - *vp2) + (n/2 - wval) << endl;
        } else {
            cout << (n/2 - vval) + (n/2 - *wp2) << endl;
        }
    }
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll H, W, N;
ll i, j;
int main(){
    scanf("%lld%lld%lld", &H,&W,&N);
    ll b=max(H,W);
    printf("%lld", (N - 1) / b + 1);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cstring>
#include <stack>
#include <numeric>
#include<climits>
#include<cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
#include<unordered_map>
#define vi vector<float>
#define vl vector<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define loop(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<float,float>
#define umap unordered_map<ll,float>
using namespace std;

#define xx first
#define yy second

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

// #ifndef ONLINE_JUDGE
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// #endif

	ll n, k;
	cin >> n >> k;

	vector<int> vec;
	while (n) {
		vec.pb(n % k);
		n /= k;
	}

	//reverse(all(vec));
	int count = 0;
	for (int i = 0; i < vec.size(); i++) {
		if (i == vec.size() - 1) {
			if (vec[i] == 0) {
				continue;
			}
			count += to_string(vec[i]).size();
		} else
			count += to_string(vec[i]).size();
	}
	cout << count << endl;






	return 0;
}










Measured memory_bytes: 256
from collections import*
input=open(0).readline
n=int(input())
e=[[]for _ in range(n)]
for _ in range(n-1):
    a,b,c=map(int,input().split())
    e[a-1].append((b-1,c))
    e[b-1].append((a-1,c))
q,k=map(int,input().split())
d=[0]*n
f=[0]*n
f[k-1]=1
s=deque([(k-1,0)])
while s:
    t,c=s.pop()
    f[t]=1
    d[t]=c
    for i,v in e[t]:
        if not f[i]:
            s.append((i,v+c))
for _ in range(q):
    x,y=map(int,input().split())
    print(d[x-1]+d[y-1])

Measured memory_bytes: 73648
#include<stdio.h>

int main(void){

	int n,i,max,min,tmp,j,v,k,z,x,cnt;
  cnt=0;
		z=0;
	x=1;
	scanf("%d",&n);
	int a[1000001],g[20];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	for(i=0; x<=n; i++) {
    g[i]=x;
    x=x*3+1;
    z++;
  }

for(k=z-1; k>=0; k--) {
	for(i=g[k];i<n;i++)
   {
		 v=a[i];
	   j=i-g[k];

	  	while(j>=0&&a[j]>v)
	  	{
	  	 a[j+g[k]]=a[j];
	  	 j=j-g[k];
	     cnt++;
	  	}
   	a[j+g[k]]=v;
   }
}
	 printf("%d\n",z);
	for(i=z-1; i>=0; i--) {
    printf("%d",g[i]);
    if(i){
			printf(" ");
		}
  }
	printf("\n%d\n",cnt);

  for(i=0; i<n; i++)
		{
			printf("%d\n",a[i]);
		}
	return 0;
}


Measured memory_bytes: 5620
l = [0] * (100 + 1)
a, b, c, d = map(int, input().split())
l[a] += 1
l[b] += -1
l[c] += 1
l[d] += -1
cnt = 0
t = 0
for i in range(101):
    t += l[i]
    if t == 2:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>	
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vi; 



int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int t = 1;
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		if(x == t) {
			++t;
		}
	}
	if(t == 1) cout << -1 << endl;
	else cout << n - (t - 1) << endl;
	return 0;
}

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

const int MAX_N = 1e5 + 3;
int num[MAX_N];

int main()
{
    int N;
    cin >> N;
    int cnt = 0;
    
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if(a > N || num[a] >= a) cnt += 1;
        else ++num[a];
    }
    for(int i = 0; i <= N; ++i) 
        if(num[i] < i) cnt += num[i];
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll n;
  cin >> n;
  vll a(n);
  rep(i,0,n) cin >> a[i];
  
 ll ans=0;
  ll now=a[0];
 rep(i,1,n){
  if(a[i]<=now){
   ans+=now-a[i];
  }else{
   now=a[i];  
  }
   
 }
  
 cout << ans << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define MOD 1000000007
#define F first
#define S second

typedef long long ll;
using namespace std;

int n, a[200010];
ll sum;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] -= i;
    }
    sort(a, a + n);
    for (int i = 0; i < n; ++i)
        sum += abs(a[n / 2] - a[i]);
    cout << sum;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include<vector>

using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i =0;i<n;++i)
//#define mod (ll)(1e9+7)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n>>k;
    vector<int> x(n);
    REP(i,n) cin >> x[i];
    int ans = 300000000;
    for(int i=0;i<=n-k;i++){
        if(x[i]<0&&x[i+k-1]>=0){
            ans = min(ans,min(abs(x[i]),abs(x[i+k-1]))*2+max(abs(x[i]),abs(x[i+k-1])));
        }else{
            ans = min(ans,max(abs(x[i]),abs(x[i+k-1])));
        }
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e18
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000
#define ll long long
#define P pair<int,int>
#define cout_set(n) cout << setprecision(10) << (n) << endl; 
const double PI=3.14159265358979323846;
using namespace std;
const int mod = 1000000007; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

signed main(){
    int x,n; cin >> x >> n;
    int p[100]; rep(i,n) cin >> p[i];

    int ans = 0;
    rep(i,102){
        int flg = 1;
        rep(k,n){
            if(p[k] == i) flg = 0;
        }
        if(flg == 0) continue;
        if(abs(ans-x) > abs(i-x)) ans = i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
# B - Can you solve this?
# https://atcoder.jp/contests/abc121/tasks/abc121_b

N, M, C = map(int, raw_input().split())
B = list(map(int, raw_input().split()))

num_solve = 0
for _ in range(N):
    A = list(map(int, raw_input().split()))
    D = sum( a*b for (a,b) in zip(A, B)) + C
    if D > 0:
        num_solve += 1

print '{}'.format(num_solve)


Measured memory_bytes: 2568
s=[]
for i in range(3):
  s.append(input())
member=["A","B","C"]
turn=0

while True:
  if s[turn]=="":
      winner=turn
      break
  if s[turn][0]=="a":
    next=0
  elif s[turn][0]=="b":
    next=1
  else:
    next=2
  s[turn]=s[turn][1:]
  turn=next

print(member[winner])


Measured memory_bytes: 9008
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;
	vector<bool> color(8, false);
	int rainbow = 0;
	int ans = 0;

	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;

		if (3200 <= tmp)
			rainbow++;
		else
			color[tmp / 400] = true;
	}

	for (int i = 0; i < 8; i++)
	{
		if (color[i])
			ans++;
	}

	cout << max(1, ans) << " " << ans + rainbow << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
K = int(input())
lunlun =[]
luncnt = 0

def SUM(num,cnt,keta):
    global luncnt
    if luncnt > 10**5:
        return
    if int(cnt) > int(keta):
        lunlun.append(int(num))
        luncnt += 1
        return


    if len(num) == 0:
        for i in range(1,10):
            SUM(num+str(i),str(int(cnt)+1),keta)
    else:
        min = int(num[(len(num)-1)])-1
        max = min + 3
        for i in range(min,max):
            if i < 0 or i > 9:
                continue
            SUM(num+str(i),str(int(cnt)+1),keta)

keta = 0
while True:
    SUM('','0',str(keta))
    if luncnt > 10**5:
        break
    keta += 1

print(lunlun[K-1])

Measured memory_bytes: 12972
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>

using namespace std;

typedef long long LL;

int n, a, b;
int cntA, cntB;

int main() {
  cin >> n >> a >> b;
  string s;
  cin >> s;
  cntA = 0;
  cntB = 0;
  int m = a + b;
  for (int i = 0; i < n; i += 1) {
    if (s[i] == 'c') {
      cout << "No\n";
      continue;
    } else if (s[i] == 'a') {
      if (cntA + cntB < m) {
        cntA += 1;
        cout << "Yes\n";
        continue;
      }
      cout << "No\n";
      continue;
    } else {
      if (cntA + cntB < m && cntB < b) {
        cntB += 1;
        cout << "Yes\n";
        continue;
      }
      cout << "No\n";
      continue;
    }
  }
  return 0;
}


Measured memory_bytes: 896
from collections import Counter
N, P = map(int, input().split())
S = input()

if 10 % P == 0:
    ans = 0
    for i, s in enumerate(S, start=1):
        if int(s) % P != 0:
            continue
        ans += i
    print(ans)

else:
    X = [0]
    for i, s in enumerate(S[::-1]):
        X.append((X[-1] + pow(10, i, P) * int(s)) % P)

    C = Counter(X)
    ans = 0
    for v in C.values():
        ans += v * (v - 1) // 2
    print(ans)


Measured memory_bytes: 12052
#include<bits/stdc++.h>
 using namespace std;
 
#define FIO                     ios_base::sync_with_stdio(false); cin.tie(0)
#define mod                     1000000007
#define setbits                 __builtin_popcount
#define gcd                     __gcd
#define rep(i,a,b)              for(int i=a;i<=b;i++)
#define repr(i,b,a)             for(int i=b;i>=a;i--)
#define foreach(itr, c)         for( __typeof__( (c).begin()) itr = (c).begin();  itr != (c).end(); ++itr)
#define foreachr(itr, c)        for( __typeof__( (c).rbegin()) itr = (c).rbegin();  itr != (c).rend(); ++itr)
#define forn(i,n)               for(int i=0;i<n;i++)
#define all(a)                  a.begin(), a.end()
#define in(a,b)                 ( (b).find(a) != (b).end())
#define pb                      push_back
#define fill(a,v)               memset(a, v, sizeof a)
#define endl                    "\n"
#define ff                      first
#define ss                      second
#define mp                      make_pair
#define minin(a)                *min_element (all(a))
#define maxin(a)                *max_element(all(a))
#define asort(c)                sort(all(c))
#define dsort(c)                sort(all(c), greater<int>()) 
typedef  long long                   ll;
typedef  vector<int>                 vi;
typedef  pair<int, int>              ii;
typedef  vector<ii>                 vii;
typedef  set<int>                    si;
typedef  unordered_map<int, int>    mii;



int main()
{
  FIO;
 
 
  string s,sb;
  int k,n;
  cin>>s>>k;
  n=s.size();

  set<string> st;

  rep(i,1,min(5,n))
  {
    rep(j,0,n-i)
    {
      sb=s.substr(j,i);
      st.insert(sb);
    }
  }
  
  int cnt=1;

  for(auto str: st)
  {
    if(cnt==k)
    {
      cout<<str<<endl;
      break;
    }
    cnt++;
  }
 return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  for (int i = 0; i < W+2; i++) {
    cout << '#';
  }
  cout << endl;
  
  string line;
  for (int i = 0; i < H; i++) {
    cin >> line;
    cout << '#' << line << '#' << endl;
  }
  
  for (int i = 0; i < W+2; i++) {
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q, k, t;
    cin >> n >> k >> q;
    int ar[n];
    memset(ar, 0, sizeof(ar));
    for (int ctr1 = 0; ctr1 < q; ++ctr1)
        cin >> t, ++ar[t - 1];
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        cout << ((q - ar[ctr1] < k) ? "Yes" : "No") << "\n";
    return 0;
}

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

int main() {

    string S;
    cin >> S;

    if (S[0] == S[1] && S[1] == S[2]) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;
static const int root = 0;
static const int INF = 1 << 30;

int v, e, prenum[MAX], lowest[MAX], p[MAX], order = 0;
vector<int> V[MAX];
set<int> out;
bool vis[MAX];

int dfs(int u){
  vis[u] = true;
  prenum[u] = ++order;
  lowest[u] = prenum[u];

  for ( int i = 0; i < V[u].size(); i++){
    int s = V[u][i];
    if ( !vis[s] ){
      p[s] = u;
      lowest[u] = min(lowest[u], dfs(s));
    } else {
      lowest[u] = min(lowest[u], prenum[s]);
    }
  }

  return lowest[u];
}

void ap(){
  for ( int i = 0; i < v; i++){
    vis[i] = false;
    p[i] = NIL;
  }
  dfs(root);

  // rootの子がいくつあるか
  int cnt = 0;
  for ( int i = 0; i < v; i++){
    if ( p[i] == root ) cnt++;
    if ( cnt > 1){
      out.insert(root);
      break;
    }
  }

  // prenum[p[i]] <= lowest[i]
 for ( int i = 1; i < v; i++){
   if ( prenum[p[i]] <= lowest[i] && p[i] != root ){
     out.insert(p[i]);
   }
 }
}

int main(){
  cin >> v >> e;
  int s, t;
  for ( int i = 0; i < e; i++){
    cin >> s >> t;
    V[s].push_back(t);
    V[t].push_back(s);
  }

  ap();

  for ( set<int>::iterator it = out.begin(); it != out.end(); it++){
    cout << *it << endl;
  }

  return 0;
}


Measured memory_bytes: 6676
#include<iostream>
using namespace std;
int main()
{
    int A,B;
    cin >> A >> B;
    if(((A % 2)== 0) or ((B % 2) == 0)){
      cout << "Even" << endl;
    }else{
      cout << "Odd" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

int main() {
    int datas[] = {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}; 
    int input;
    std::cin >> input;
    std::cout << datas[input - 1];
    return 0;
}

Measured memory_bytes: 256