akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
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(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string s;
	cin >> s;
	set<char> se;
	REP(i,SZ(s)){
		se.insert(s[i]);
	}
	string ans = "Yes";
	if(se.count('N') and !se.count('S')){
		ans = "No";
	}
	if(!se.count('N') and se.count('S')){
		ans = "No";
	}
	if(se.count('W') and !se.count('E')){
		ans = "No";
	}
	if(!se.count('W') and se.count('E')){
		ans = "No";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NIL NULL

struct node{
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};
typedef struct node * Node;

void insert(int);
void inorder(Node);
void preorder(Node);

Node root;

void insert(int k){

  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);

  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d",&n);

  for (i=0;i<n;i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 25128
import std.algorithm,
       std.string,
       std.array,
       std.range,
       std.stdio,
       std.conv;

M min(M, N)(M m, N n) if (is(typeof(m < n))) {
  return m < n ? m : n;
}

void main() {
  int N = readln.chomp.to!int;
  int[] L = readln.chomp.split.to!(int[]);

  std.algorithm.sort!"a>b"(L);

  int answer;

  foreach (i; 0..(L.length / 2)) {
    answer += min(L[i*2], L[i*2 + 1]);
  }

  writeln(answer);
}


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

const long long maxn = 2e5+10, inf = 1e18+10;
long long n, d, a;
pair<long long,long long> p[maxn];
long long tag[maxn];

signed main() {
	cin >> n >> d >> a;
	for (long long i = 0; i < n; ++i) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p+n);
	p[n].first = inf;
	long long cur = 0, ans = 0;
	for (long long i = 0; i < n; ++i) {
		cur += tag[i];
//		cout << i << ' ' << cur << ' ' << ans << endl;
		if (cur < p[i].second) {
			long long y = upper_bound(p, p+n, make_pair(p[i].first+2*d, inf))-p, tmp = ((p[i].second-cur+a-1)/a);
			tag[y] -= tmp*a, cur += tmp*a;
			ans += tmp;
		}
	}
	cout << ans << endl;
	return 0;
}


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

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;

    for(int i = 0; i < 1 << (n - 1); i++){
        ll cur = s[0] - '0';
        ll sum = 0;
        for(int j = 0; j < n - 1; j++){
            //+を挿入するときは、位を変えずそのまま足す
            if(i & (1 << j)){
                sum += cur;
                cur = 0;
            }
            //位を上げて次の桁を足す
            cur = cur * 10 + s[j + 1] - '0';
        }
        sum += cur;
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

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

//dikstra
int a[300010];

signed main(){

  int n; cin >> n;
  for(int i = 0; i < 3*n; i++){
    cin >> a[i];
  }

  sort(a,a+3*n);
  int ans1 = 0;
  for(int i = n-1; i < 2*n-1; i++) ans1 += a[i];
  int ans2 = 0;
  for(int i = 3*n-2; i >= n-1; i-=2) ans2 += a[i];
  cout << max(ans1,ans2) << endl;

  return 0;
}


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

int main(void){
  char C[2][3];
  int cnt = 0;
  for(int i = 0 ; i < 2; i++){
    for(int j = 0; j < 3; j++){
      cin >> C[i][j];
    }
  }
  if(C[0][0] == C[1][2])
    cnt++;
  if(C[0][1] == C[1][1])
    cnt++;
  if(C[0][2] == C[1][0])
    cnt++;
  if(cnt == 3) cout << "YES" << "\n";
  else cout << "NO" << "\n";
  return 0;
}


Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
#define int long long

int a,b,k;
vector<int> v;

signed main() {
	cin >> a >> b >> k;
	int bigger = 0;
	if (a < b) {
		bigger = b;
	}
	else {
		bigger = a;
	}
	int cnt = 0;
	int save = 0;
	for (size_t i = bigger; i > 0; i--)
	{
		if (a % i == 0 && b % i == 0) {
			cnt++;
			if (cnt == k) {
				save = i;
			}
		}
	}


	cout << save  << endl;
}




Measured memory_bytes: 256
N, M = map( int, input().split() )
imos = [ 0 for i in range( N + 1 ) ]
for i in range( M ):
  a, b = map( int, input().split() )
  imos[ a - 1 ] += 1
  imos[ b - 1 ] -= 1
for i in range( 1, N ):
  imos[ i ] += imos[ i - 1 ]
print( "NO" if any( imos[ i ] & 1 for i in range( N ) ) else "YES" )


Measured memory_bytes: 46896
using namespace std;
#include<string>
#include<cmath>
#include<list>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ml map<ll,ll>
#define pb push_back
#define mp make_pair
#define ppl pair<ll,ll>
#define F first
#define S second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define PI 3.141592654
const ll N = 1e9 + 7;
#include<iterator>
#define EPSILON numeric_limits<double>::epsilon()




void solve() {
	ll n, x, T; cin >> n >> x >> T;
	ll d = n / x;
	if (n % x)d++;
	cout << d*T;
}





int main() {
	fio;
#ifndef ONLINE_JUDGE
	// for getting input
	freopen("input.txt", "r", stdin);
	//for writing output
	freopen("jout.txt", "w", stdout);
#endif

	ll t;
	if (1)
		t = 1;
	else
		cin >> t;
	while (t--) {
		//cout << "Case #" << h << ":\n";
		solve();
		//h++;
		cout << '\n';
	}
	return 0;
}






Measured memory_bytes: 3644
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N];
        int total = 0;

        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            total += A[i];
        }
        sc.close();

        double standard = 1/(4 * (double)(M));
        int count = 0;

        for(int i = 0; i<N; i++){
            if((double)(A[i]) >= total * standard){
                count++;
            }
        }
        if(count >= M){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 27052
//#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline int kthbit(long long x, int k) {return (x>>k)&1;}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    int N; cin >> N;
    ll ans = 0;
    for (int a = 1; a <= N; a++) {
        ans += (N-1)/a;
    }

    cout << ans << ln;
}


Measured memory_bytes: 3648
a = int(input())
c = list(map(int,input().split()))
c1=c2=c4=0
for i in c:
    if i%2==1:
        c1+=1
    elif i%4==0:
        c4+=1
    else:c2+=1
if c1+c2-c4==1:print("Yes")
elif c1<=c4:print("Yes")
else:print("No")

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string S; cin >> S;
  string result = "No";
  rep(i,S.length()-1) if (S[i]=='A'&&S[i+1]=='C') result = "Yes";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
S=input()

a=int(S[:2])
b=int(S[2:])
if (a>12 or a==0) and (b>12 or b==0):
    print('NA')
elif a>12 or a==0:
    print('YYMM')
elif b>12 or b==0:
    print('MMYY')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3060
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> h(N);
  for (auto& v : h)cin >> v;
  int prev = 0;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (prev < h[i])
      ans += h[i] - prev;
    prev = h[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
ワーシャルして、3の候補
それの組み合わせ、nC2かな
ああ、追加した道も通っていいのか…
毎回やり直しは無理
逆に候補減らしていくとか？
数学的なやつか
二部グラフなら違う色同士結べる。＝B*W-M
そうじゃないなら完全グラフ。=nC2-M
*/
vector<vector<ll>> G;
int colors[200005];
bool is_bipartite_graph(int v, int c) {
    colors[v] = c;
    for (int u: G[v]) {
        if (colors[u] == c) {
            return false;
        }
        if (colors[u] == 0 && !is_bipartite_graph(u, -c)) {
            return false;
        }
    }
    return true;
}

int main(){
  ll N,M; cin>>N>>M;
  G.assign(N+1, vector<ll>(0,0));
  rep(i,M){
    ll a,b; cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans=0;
  if(is_bipartite_graph(1, 1)==true){
    ll w=0, b=0;
    for(ll i=1; i<=N; i++){
      if(colors[i]>0) w++;
      else if(colors[i]<0) b++;
    }
    ans=w*b-M;
  }
  else ans=(N*(N-1))/2-M;
  cout<<ans<<endl;
}

Measured memory_bytes: 9940
# include <iostream>
# include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    vector<int> p(n+1);
    for (int k=1; k<=n; ++k) {
        cin >> p[k];
    }

    int cnt = 0;
    for (int k=1; k<=n; ++k) {
        // IMPORTANT: You are allowed to swap elements **once**
        if (p[k] != k) {
            cnt++;
        }
    }

    if (cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}




Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  set<int> s;
  for(int i=0;i<n;i++)
  {
    int x;
    cin>>x;
    s.insert(x);
  }
  if(s.size()==n)
    cout<<"YES";
  else
    cout<<"NO";
  return 0;
}

Measured memory_bytes: 12972
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
long long num[100000];
int main(){
	int h,w;
	cin>>h>>w;
	char a[100][101],b[102][102];
	for(int i=0;i<h;i++){
		cin>>a[i];
	}
	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			b[i][j]='#';
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			b[i+1][j+1]=a[i][j];
		}
	}
	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			cout<<b[i][j];
		}
		cout<<endl;
	}
	return 0;
}

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

ll INF = (1LL << 60);

template <typename A>
string to_string(A x[], signed n) {
    string result = "{";
    for (signed i=0; i<n; ++i) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

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

    ll N, M, P;
    cin >> N >> M >> P;

    vector<tuple<int, int, int>> edges (M);
    
    for (int i = 0; i < M; ++i) {
        ll A, B, C;
        cin >> A >> B >> C;
        tuple<int, int, int> tmp (A-1, B-1, P - C);
        edges[i] = tmp;
    }

    ll dist[N];
    for (int i = 0; i < N; ++i) dist[i] = INF;

    dist[0] = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (auto edge : edges) {
            ll s, e, c;
            tie(s, e, c) = edge;
            if (dist[s] != INF && dist[s] + c < dist[e]) {
                dist[e] = dist[s] + c;
            }
        }
    }

    // long cycles
    ll score = dist[N-1];
    
    for (int i = 0; i < M; ++i) {
        for (auto edge : edges) {
            ll s, e, c;
            tie(s, e, c) = edge;
            if (dist[s] != INF && dist[s] + c < dist[e] && e == N - 1) {
                cout << -1 << "\n";
                return 0;
            } else if (dist[s] != INF && dist[s] + c < dist[e]) {
                dist[e] = -INF;
            }
        }
    }
    cout << max(0LL, -score) << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define out(x) cout << x << endl;
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int cnt = 0;
	string s;
	cin >> s;
	for(int i = 2;i < s.length() - 1;i++){
		if(s[i] == 'C'){
			cnt++;
			s[i] = 'c';
		}
	}
	if(s[0] != 'A' || cnt != 1) cout << "WA" << endl;
	else{
		for(int i = 1;i < s.length();i++){
			if(s[i] >= 'A' && s[i] <= 'Z'){
				cout << "WA" << endl;
				return 0;
			}   
		}
		cout << "AC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main(){
  int f[31] = {}, in;
  for(int i = 0; i < 28; i++){
    scanf("%d", &in);
    f[in] = 1;
  }

  for(int i = 1; i <= 30; i++) if(!f[i]) printf("%d\n", i);

  return 0;
}

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

#define repl(i,a,b) for(int (i)=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)

string alpha;

char rot(char c,int x){
  while(x>0){
    if(c=='A'){
      c='z';
    }else if(c=='a'){
      c='Z';
    }else{
      c--;
    }
    x--;
  }
  return c;
}

int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> a(n);
    rep(i,n)cin>>a[i];

    string s;
    cin>>s;
    int m=s.size();

    string res;
    rep(i,m){
      res+=rot(s[i],a[i%n]);
    }
    cout<<res<<endl;
  }

  return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n,m,k;
const int Maxn=10;
const int Maxm=1000;
string s[Maxn];
#define vec vector<int>
int solve(int mask){
	int ret=__builtin_popcount(mask);
	vector<vec>bag;
	bag.push_back({0});
	for(int i=1;i<n;i++){
		if(mask>>(i-1)&1)bag.push_back({i});
		else bag.back().push_back(i);
	}
	vector<int>cnt(__builtin_popcount(mask)+1);
	rep(j,m){
		rep(p,SZ(bag)){
			for(int x:bag[p]){
				cnt[p]+=(s[x][j]=='1');
			}
		}
		if(*max_element(all(cnt))>k){
			for(auto &x:cnt)x=0;
			ret++;
			rep(p,SZ(bag)){
				for(int x:bag[p]){
					cnt[p]+=(s[x][j]=='1');
				}
			}
			if(*max_element(all(cnt))>k){
				return INF;
			}
		}
	}
	return ret;
}
int main(){
	cin>>n>>m>>k;
	rep(i,n)cin>>s[i];
	int ans=INF;
	rep(mask,1<<(n-1))chkmin(ans,solve(mask));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define DEBUG_ARRAY(name, i, var) printf("the value of"#name"[%d] is %d\n", i, var)

using namespace std;

int B[25];
int N, M, C;
int ans;

int main(void) {
    scanf("%d %d %d", &N, &M, &C);

    REP(i, 0, M) scanf("%d", &B[i]);

    REP(i, 0, N) {
    	int sum = 0;
    	REP(j, 0, M) {
    		int A;
    		scanf("%d", &A);
    		sum += A * B[j];
    	}
    	if (sum > -C) ans++;
    }
    
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct cake{
  int w,d;
  cake(int a,int b){
    w=a;
    d=b;
  }

  bool operator<(const cake & a) const
  {
    return w*d < a.w*a.d;
  };
};


void f(int n,int w,int d){

  vector<cake> v;
  v.PB(cake(w,d));

  while(n--){
    int p,s;
    cin>>p>>s;
    p--;
    cake c = v[p];
/*    rep(i,v.size()){
      cout<<v[i].w*v[i].d<<' ';
    }
    cout<<endl;
    */
    v.erase(v.begin()+p);
  

    while(true){
//      cout<<s<<' '<<c.w<<" "<<c.d<<endl;
      if(s<c.w){
        cake a(c.w-s,c.d);
        cake b(s,c.d);
        if(s>c.w/2){
          v.PB(a);
          v.PB(b);
        }
        else{
          v.PB(b);
          v.PB(a);
        }
        break;
      }
      s-=c.w;
      if(s<c.d){
        cake a(c.w,c.d-s);
        cake b(c.w,s);
        if(s>c.d/2){
          v.PB(a);
          v.PB(b);
        }
        else{
          v.PB(b);
          v.PB(a);
        }
        break;
      }
      s-=c.d;
      if(s<c.w){
        cake a(c.w-s,c.d);
        cake b(s,c.d);
        if(s>c.w/2){
          v.PB(a);
          v.PB(b);
        }
        else{
          v.PB(b);
          v.PB(a);
        }
        break;
      }
      s-=c.w;
      if(s<c.d){
        cake a(c.w,c.d-s);
        cake b(c.w,s);
        if(s>c.d/2){
          v.PB(a);
          v.PB(b);
        }
        else{
          v.PB(b);
          v.PB(a);
        }
        break;
      }
      s-=c.d;
    }
/*    rep(i,v.size()){
      cout<<v[i].w*v[i].d<<' ';
    }
    cout<<endl;
    */
  }

 
  sort(all(v));
  rep(i,v.size()){
    if(i) cout<<' ';
    cout<<v[i].w*v[i].d;
  }
  cout<<endl;
  
}

int main(){
  int n,w,d;
  while(true){
    cin>>n>>w>>d;
    if(!n&&!w) break;
    f(n,w,d);
  }
}



Measured memory_bytes: 3000
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for(int i=1;i<=n;i++){
        ll res=0;
        for(int j=1;j*j<=i;j++){
            for(int k=1;k<=j&&j*j+k*k<=i;k++){
                for(int l=1;l<=k&&j*j+k*k+l*l<=i;l++){
                    if(j*j+k*k+l*l+j*k+k*l+l*j==i){
                        if(j==k&&k==l)res++;
                        else if(j==k||k==l){
                            res+=3;
                        }
                        else{
                            res+=6;
                        }
                    }
                }
            }
        }
        printf("%lld\n",res );
    }
}


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

int main(){
  string s;
  
  cin >> s;
  int flag =0;
  for(int i=0; i<s.length(); i+=2){
    if(s[i] != 'h' or s[i+1]!= 'i'){
      flag = 1;
      break;
    }
  }
  if(flag ==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000

int main(){
    int n, x, i = 0, j, k, l;
    int count1 = 0;
    int count2[MAX] = {};
    while(1){
        scanf("%d %d", &n, &x);
        if(x == 0 && n == 0) break;
        for(j = 1; j <= n; j++){
            for(k = 1; k <= n; k++){
                for(l = 1; l <= n; l++){
                    if(j + k + l == x && j != k && j != l && k != l){
                        count1++;
                    }
                }
            }
        }
        count2[i] = count1 / 6;
        i++;
        count1 = 0;
    }
    j = 0;
    while(1){
        if(i == j) break;
        printf("%d\n", count2[j]);
        j++;
    }
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int main(){
    int N; cin >> N;
    string S; cin >> S;

    int x = 0; int mx = 0;
    rep(i, S.length()){
        if(S[i] == 'I') x++;
        else x--;
        
        if(mx < x) mx = x;
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
C = [list(map(int, input().split())) for _ in range(3)]

ans = 'Yes'
for i in range(1, 3):
    if C[0][i] - C[1][i] != C[0][0] - C[1][0]:
        ans = 'No'
        break
    if C[0][i] - C[2][i] != C[0][0] - C[2][0]:
        ans = 'No'
        break
    if C[i][0] - C[i][1] != C[0][0] - C[0][1]:
        ans = 'No'
        break
    if C[i][0] - C[i][2] != C[0][0] - C[0][2]:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
#define ENDL printf("\n");
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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

int n , k;
vector<u64> w;

int func(u64 mid){
    int i = 0;
    rep(j ,::k){
        u64 sum = 0;
        while( sum + w[i] <= mid){
            sum += w[i]; ++i; 
            if(i == ::n) return ::n;
        }
    }
    return i;
}

u64 solve(){
    u64 maxP = 0;
    rep(i , ::n) maxP += w[i]; 
    u64 minP = 0;
    while( maxP - minP > 1){
        u64 midP = ( maxP + minP ) / 2;
        int v = func(midP);
        if( v >= ::n) maxP = midP;
        else minP = midP;
    }
    return maxP;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> ::n >> ::k;
    w.resize(::n);
    rep(i ,::n) cin >> w[i];
    cout << solve() << endl;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int l,r,tl,tr,n,m;
  scanf("%d%d",&n,&m);
  l=1;r=n;
  for(int i=0;i<m;i++){
    scanf("%d%d",&tl,&tr);
    l=max(l,tl);
    r=min(r,tr);
  }
  int ans=r-l+1;
  if(ans<0)ans=0;
  printf("%d\n",ans);
  return 0;
}

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

int findSumOfDigits(int n){
   int sum = 0;
   while (n > 0){
       sum += n % 10;
       n /= 10;
   }
   return sum;
}

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

    int total = 0;
    for (int i = 1; i <= N; ++i) {
        int sum = findSumOfDigits(i);

        if (sum >= A && sum <= B) total += i;
    }

    cout << total << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 3010;
const int mod = 1e9 + 7;

LL f[N][N][2];

void upd(LL &a, LL b) {a = (a + b) % mod;}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	f[0][0][1] = 1;
	Rep(i, n) f[0][i][0] = 1;
	Rep0(i, m - 1) Rep0(j, n) Rep0(k, 1){
		if (j){
			upd(f[i + 1][j - 1][k | (!(j - 1))], f[i][j][k]);
			upd(f[i + 1][j][k | (j == 1)], f[i][j][k]);
		}
		if (n - j) {
			upd(f[i + 1][j + 1][k], f[i][j][k]);
			upd(f[i + 1][j][k], f[i][j][k]);
		}
	}
	LL ans = 0;
	Rep0(i, n) upd(ans, f[m][i][1]);

	printf("%lld\n", ans);
	
	return 0;
}


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

int main(){
  int i,a[100002]={},n,sum=0;
  cin>>n;
  
  for(i=1;i<n+1;i++){
    cin>>a[i];
    sum+=abs(a[i-1]-a[i]);
    //cout<<sum<<endl;
  }
  sum+=abs(a[i-1]);
  for(i=1;i<n+1;i++){
    cout<<sum-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1])<<endl;
    //cout<<sum<<endl;
    //cout<<abs(a[i-1]-a[i])+abs(a[i]-a[i+1])<<endl;
  }
  return 0;
}

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

using namespace std;

const int N = 100010;

int n;
vector<pair<int, int>> adj[N];
int res[N];

void dfs(int u, int p) {
    for (auto v : adj[u]) {
        if (v.first == p) continue;
        res[v.first] = res[u] ^ v.second;
        dfs(v.first, u);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        w %= 2;
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) cout << res[i] << '\n';
    return 0;
}

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

int main () {
    int n;
    cin >> n;
    vector<string> s(n);
    rep (i,n) cin >> s.at(i);
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()),s.end());
    cout << s.size() << endl;
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int r0,w0,c,r;

int main(){
	while(1){
		cin>>r0>>w0>>c>>r;
		if(r0==0&&w0==0&&c==0&&r==0)break;
		if((double)r0/w0>=(double)c){
			cout<<0<<endl;
			continue;
		}
		int ans=(((c*w0)-r0)+r-1)/r;
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
	int h,w;
	cin >> h >> w;
	string board[50];
	const int dx[8]={1,0,-1,0,1,-1,1,-1};
	const int dy[8]={0,1,0,-1,1,1,-1,-1};
	for(int i=0;i<h;i++)cin >> board[i];
  for(int i=0;i<h;i++){
  	for(int j=0;j<w;j++){
  	if(board[i][j] == '#') continue;
  	
  	int num=0;
  	for(int d=0;d<8;d++){
  		const int ni = i+dy[d];
  		const int nj = j+dx[d];
  		if(ni < 0 || h <= ni) continue;
  		if(nj<0 || w <= nj) continue;
  		if(board[ni][nj] =='#')num++;
  	}
  	board[i][j] = char(num +'0');
       }
  }
  for(int i = 0;i<h;i++)cout << board[i] << endl;
  return 0;
}

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

int main(){
    int n,m,point,ans = 0;
    cin >> n;
    string s[n];

    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }

    cin >> m;
    string t[m];

    for(int i = 0; i < m; ++i){
        cin >> t[i];
    }

    for(int i = 0; i < n; ++i){
        point = 0;

        for(int j = 0; j < n; ++j){
            if(s[i] == s[j]) point++;
        }

        for(int j = 0; j < m; ++j){
            if(s[i] == t[j]) point--;
        }

        if(ans < point) ans = point;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long int ll;

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

  for(int i=1; i<=n; i+=2){
    int digit = 0;
    for(int j=1; j<=i; j+=2){
      if(i%j == 0)  digit++;
    }

    if(digit == 8){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())

c = list(input())

red = c.count('R')
white = n - red
redinred = 0
whiteinred = 0

for i in range(red):
  if c[i] == 'W':
    whiteinred += 1
  else:
    redinred += 1

redinwhite = red - redinred

trade = min(whiteinred, redinwhite)
change = abs(whiteinred - redinwhite)

print(trade + change)

Measured memory_bytes: 10700
//
//  main.cpp
//  CppTest
//
//  Created by Ryu on 2017/02/08.
//  Copyright ?? 2017??´ Ryu. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n[50];
    int comb[50];
    int m = 0;
    while (cin >> n[m]) {
        comb[m] = 0;
        for (int i = 0; i <= 9; i++) {
            for (int j = 0; j <= 9; j++) {
                for (int k = 0; k <= 9; k++) {
                    for (int l = 0; l <= 9; l++) {
                        if (i + j + k + l == n[m]) {
                            comb[m]++;
                        }
                    }
                }
            }
        }
        m++;
    }
    
    for (int i = 0; i < m; i++) {
        printf("%d\n", comb[i]);
    }
    
    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    map<pair<int, int>, int> mp;
    rep(i, 0, n) {
        mp[{i, 0}] = i;
    }
    int id = n;
    rep(i, 0, m) {
        int p, q, c;
        cin >> p >> q >> c;
        p--, q--;
        if (mp[{p, c}] == 0) {
            mp[{p, c}] = id;
            g.emplace_back();
            g[p].emplace_back(id);
            id++;
        }
        if (mp[{q, c}] == 0) {
            mp[{q, c}] = id;
            g.emplace_back();
            g[q].emplace_back(id);
            id++;
        }
        g[mp[{p, c}]].emplace_back(mp[{q, c}]);
        g[mp[{p, c}]].emplace_back(p);
        g[mp[{q, c}]].emplace_back(mp[{p, c}]);
        g[mp[{q, c}]].emplace_back(q);
    }
    vector<int> d(id, 1e9);
    deque<pair<int, int>> que;  // dist, pos
    que.push_front({0, 0});
    while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop_front();
        if (d[p.second] < p.first) continue;
        d[p.second] = p.first;
        int cost = 0;
        if (p.second < n) cost++;
        for (int to : g[p.second]) {
            if (d[to] > d[p.second] + cost) {
                d[to] = d[p.second] + cost;
                if (cost)
                    que.push_back({d[to], to});
                else
                    que.push_front({d[to], to});
            }
        }
    }
    debug(g);
    debug(d);
    if (d[n - 1] == 1e9) d[n - 1] = -1;
    cout << d[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 66280
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  bool flag = false;
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < 20; ++j) {
      int total = i * 4 + j * 7;
      if (total == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i = 0; i < n; i++)
const int MAX = 3e5+3;
const int INF = 1e9;

string s;
ll sum;

ll stoi2(string str){
  ll t = 0;
  ll c = 1;
  for(int i = str.size()-1; i >= 0; i--){
    if(str[i] == '+') c = 1;
    else {
      t += (str[i]-'0') * c;
      c *= 10;
    }
  }
  return t;
}

ll dfs(int i,string str){
  if(i == s.size()) {
    //cout << str << endl;
    sum += stoi2(str);
  }
  else {
    dfs(i + 1, str + s[i]);
    if(i != 0) dfs(i + 1, str + '+' + s[i]);
  }
  return sum;
}

int main(){

  cin >> s;
  cout << dfs(0,"") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 101;
const int maxv = 1e5 + 1;

int dp[maxn][maxv];

int main()
{
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#endif
    int n, w, v, ans = 0;
    memset(dp, -1, sizeof(dp));
    scanf("%d%d", &n, &dp[0][0]);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &w, &v);
        for (int j = 0; j != maxv; ++j)
            if (j < v)
                dp[i][j] = dp[i - 1][j];
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - v] - w);
                if (dp[i][j] != -1 && j > ans)
                    ans = j;
            }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 39680
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100+7;

int p[MAXN];
int dp[MAXN][MAXN];
int n;
void generate_dp(){
    for(int i = 1; i <= n; i++){
        dp[i][i] = 0;
    }
    for(int b = 1; b < n; b++){
        for(int i = 1; i <= n-b; i++){
            int j = i+b;
            int k; k = i;
            int min_x = dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j];
            for(k = i+1; k < j; k++){
                if(dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j] < min_x){
                    min_x = dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j];
                }
            }
            dp[i][j] = min_x;
        }
    }
}
int main(){

    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d %d", &p[i], &p[i+1]);
    }
    generate_dp();
    printf("%d\n", dp[1][n]);

    return 0;
}






Measured memory_bytes: 3240
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[26] CS;

void main()
{
    auto S = readln.chomp.to!(char[]);
    foreach (c; S) ++CS[c-97];
    foreach (i, n; CS) {
        if (!n) {
            writeln(S ~ cast(char)(i+97));
            return;
        }
    }
    foreach_reverse (i, c; S) {
        while (c < 'z') {
            ++c;
            bool found;
            foreach (d; S[0..i]) {
                if (d == cast(char)c) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                writeln(S[0..i] ~ cast(char)c);
                return;
            }
        }
    }
    writeln("-1");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long
ll n,a[407],pre[407],dp[407][407];

int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		pre[i]=pre[i-1]+a[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n-i;j++){
			int k=i+j;
			dp[j][k]=1e18;
			for(int p=j;p<=i+j;p++){
				dp[j][k]=min(dp[j][k],dp[j][p]+dp[p+1][k]+pre[k]-pre[j-1]);
			}
		}
	}
	printf("%lld\n",dp[1][n]);
}


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

using namespace std;

#define rep(loop, N) for (int loop = 0; loop < N; loop++)

struct Node {
	Node* parent = NULL;
	vector<Node*> child;
	long long value = 0;
};
struct Edge {
	int parent = 0;
	int child = 0;
	bool operator <(const Edge& right) const { return parent < right.parent; }
};
struct Tree {
	vector<Node> node;
	Tree(int, vector<Edge>);
};
Tree::Tree(int nodeNum, vector<Edge> edge) {
	node.resize(nodeNum);
	for (Edge& it : edge) {
		node[it.child].parent = &node[it.parent];
		node[it.parent].child.push_back(&node[it.child]);
	}
}

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	long long m_module = 1000000007;
	vector<struct Memo> memo;
public:
	long long calculate(int, int);
	Combination1(int, long long);
};
long long Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, long long module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Lucky_7(void) {

	string N; cin >> N;

	rep(index, 3) {
		if (N[index] == '7') {
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
	return;
}

void B_FizzBuzz_Sum(void) {

	int N; cin >> N;

	long long sum = 0;
	for (int num = 1; num <= N; num++) {
		if (num % 3 != 0 && num % 5 != 0) sum += num;
	}

	cout << sum << endl;
	return;
}

int main(void) {

	//A_Lucky_7();
	B_FizzBuzz_Sum();
	return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    string s;cin>>s;
    int l,r;
    l=(s[0]-'0')*10+s[1]-'0';
    r=(s[2]-'0')*10+s[3]-'0';
    vector<string> ans={"YYMM\n","MMYY\n","AMBIGUOUS\n","NA\n"};
    if(1<=l&&l<=12){
        if(1<=r&&r<=12)cout<<ans[2];
        else cout<<ans[1];
    }else{
        if(1<=r&&r<=12)cout<<ans[0];
        else cout<<ans[3];
    }
}


Measured memory_bytes: 256
def main():
    def dist(c1, c2):
        cur = 0
        for x1, x2 in zip(c1, c2):
            cur += (abs(x1-x2))**2
        return sqrt(cur)
    from math import sqrt
    N, D = (int(i) for i in input().split())
    c = [[int(i) for i in input().split()] for j in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if dist(c[i], c[j]).is_integer():
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};
int main(){
  ll n,m;cin>>n>>m;
  UnionFind<ll>uf(n);
  rep(i,m){
    ll l,r,d;cin>>l>>r>>d;
    l--;r--;
    if(uf.issame(l,r)){
      ll diff=uf.diff(l,r);
      if(diff!=d){
        cout<<"No"<<endl;
        return 0;
      }
    }
    else uf.merge(l,r,d);
  }
  cout<<"Yes"<<endl;
}


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

int main()
{
    int n, i, sum=0;
    cin>>n;
    int arr[n];

    for(i=0; i<n; i++){
        cin>>arr[i];
    }
    sort(arr, arr+n);

    for(i=0; i<n-1; i++){
        sum = sum + arr[i];
    }
    cout<<sum+(arr[n-1]/2);
}


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

using namespace std;

int main(){
 string S;
 cin >> S;
 int upper = 0;
 int answer = 0, so = 0;
 so = S.size() - 2;
 if(S.size() > 3){
  if(S.at(0) == 'A'){
    for(int i = 2; i <= so; i++){
      if(S.at(i) == 'C') answer++;
    }
  }
 }
 for(int i = 0; i < S.size(); i++){
  if(isupper(S.at(i))) upper++;
 }
 if(answer == 1 && upper == 2){
  cout << "AC" << endl;
 }else{
  cout << "WA" << endl;
 }
}


Measured memory_bytes: 256