akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cctype>
using namespace std;
int main(){
	char ch;
	while(1){
		scanf("%c",&ch);
		if(isalpha(ch)){
			if(islower(ch))cout<<(char)toupper(ch);
			else if(isupper(ch))cout<<(char)tolower(ch);
		}
		else {cout<<ch;}
		if(ch=='\n')break;
	}
return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll         long long int 
#define pb         push_back
#define umap       unordered_map
#define mod        1000000007
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(int i=0;i<n;i++)
#define f1(i,x,y)  for(int i=x;i<=y;i++)
#define f2(i,x,y)  for(int i=x;i>=y;i--)
#define yes        cout<<"YES"<<"\n"
#define no         cout<<"NO"<<"\n"
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 ll n,k;cin>>n>>k;
 vector <ll> h(n);
 f(i,n){cin>>h[i];}
 vector <ll> dp(n,0);
dp[0]=0;
for(int i=1;i<n;i++)
{
  ll mn=1e9;
  int x=k,j=i-1;
  while(x>0 && j>=0)
  {
    mn=min(mn,dp[j]+abs(h[i]-h[j]));
    j--;x--;
  }
  dp[i]=mn;
}
cout<<dp[n-1];
}
   

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

#define endl "\n"
using namespace std;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	string s, t;
	cin >> s >> t;
	int cont=0;
	for(int i=0;i<3;i++){
		if(s[i]==t[i]) cont++;
	}
	cout << cont << endl;
	return 0;
}

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

using namespace std;

int tmp;
int N;
int n[10];
int ans;
int main() {

  cin >> N;

  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if(a >= 3200) tmp++;
    else n[a / 400]++;
  }

  for(int i = 0; i < 10; i++) {
    if(n[i] > 0) ans++;
  }
  if(ans == 0 && tmp > 0) cout <<"1"<<" "<<tmp<<endl;
  else cout << ans <<" "<<ans + tmp <<endl;
}
  


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

int main() {
  int a, b, c, r1, r2;
  cin >> a >> b >> c;
  
  if (a>b) r1 = a-b;
  else r1 = b-a;
  
  if (a>c) r2 = a-c;
  else r2 = c-a;

  if (r1 < r2) cout << "A" << endl;
  else cout << "B" << endl;
}

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


int main() {

    int T, N, up, down, prev, curr;

    std::scanf("%d", &T);
    for (int t = 0; t < T; t++) {
        up = down = 0;
        std::scanf("%d", &N);
        std::scanf("%d", &prev);

        for (int i = 1; i < N; i++) {
            std::scanf("%d", &curr);
            if (prev > curr) down = std::max(down, prev - curr);
            else up = std::max(up, curr - prev);
            prev = curr;
        }

        std::cout << up << " " << down << std::endl;
    }

    return 0;

}



Measured memory_bytes: 3140
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($P,$Q,$R) =  explode(" ",trim(fgets(STDIN)));
$W = explode(" ",trim(fgets(STDIN)));

$res = $N;
for($i=1;$i<$N;$i++) {
  $res = min($res,sum($i));
}
printf("%d\n",$res);

function sum($i) {
  global $W,$N;
  $r = 0;
  for($j=0;$j<$i;$j++) {
    $r+=$W[$j];
  }
  $x = 0;
  for($j=$i;$j<$N;$j++) {
    $x += $W[$j];
  }
  if ($r > $x) {
    return $r - $x;
  }
  else {
    return $x - $r;
  }
}


Measured memory_bytes: 4856
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        long sum = 0;
        for (int i=0; i<n; i++) {
            arr[i] = sc.nextInt();
            arr[i] -= i+1;
        }
        Arrays.sort(arr);
        for (int i=0; i<arr.length; i++) {
            sum += Math.abs(arr[i] - arr[n/2]);
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 65656
#include<stdio.h>
signed main(){
    int K,A,B,a;
    a=0;
    scanf("%d %d %d",&K,&A,&B);
    while(A!=B+1){
        if(A%K==0){
            a++;
        }
        A++;
    }
    if(a>0){
        printf("OK\n");
    }else{
        printf("NG\n");
    }
    return(0);
}

Measured memory_bytes: 1620
from collections import deque

n, m = map(int, input().split())
graph = [[] * n for _ in range(n)]
for _ in range(m):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    z %= 2
    graph[x].append((y))
    graph[y].append((x))

seen = [False] * n
ans = 0
for i in range(n):
    if not seen[i]:
        seen[i] = True
        node = deque(graph[i])
        while node:
            v = node.popleft()
            if seen[v]:
                continue
            seen[v] = True
            node.extend(graph[v])
        ans += 1

print(ans)


Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <cmath>
 
using namespace std;
 
// typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<string> vs;
 
// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
// repetition
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
 
// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
 
//constant
const double    EPS     = 1e-10;
const double    PI      = acos(-1.0);
const int       INFTY   = (1<<21);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main() {
    const int MAX = 400;
    int dp[MAX + 1][MAX + 1];
    REP(a, MAX + 1) {
        REP(b, MAX + 1) {
            dp[a][b] = -1;
        }
    }
    dp[0][0] = 0;
    int n, m_a, m_b;
    vi v_a, v_b, v_c;
    cin >> n >> m_a >> m_b;
    REP(i, n) {
        int e_a, e_b, e_c; cin >> e_a >> e_b >> e_c;
        v_a.push_back(e_a);
        v_b.push_back(e_b);
        v_c.push_back(e_c);
    }
    REP(k, n) {
        RFOR(a, MAX + 1, 0) {
            RFOR(b, MAX + 1, 0) {
                int c = dp[a][b];
                if (c == -1) continue;
                int a_nxt = a + v_a[k], b_nxt = b + v_b[k];
                if (a_nxt > MAX || b_nxt > MAX) continue;
                int c_nxt = dp[a_nxt][b_nxt];
                if (c_nxt == -1) dp[a_nxt][b_nxt] = c + v_c[k];
                else dp[a_nxt][b_nxt] = min({c_nxt, c + v_c[k]});
            }
        }
    }
    int ans = -1;
    int a = m_a, b = m_b;
    while (a <= MAX && b <= MAX) {
        if (dp[a][b] == -1) {
            a += m_a;
            b += m_b;
            continue;
        }
        if (ans == -1) ans = dp[a][b];
        else ans = min({ans, dp[a][b]});
        a += m_a;
        b += m_b;
    }
    cout << ans << endl;
}

// dp[a][b] = タイプAをちょうどaグラム，タイプBをちょうどbグラム買うのに必要な金額の最小値

Measured memory_bytes: 896
import sys

def main(lines):
  N, K = map(int, lines[0].split())
  a = list(map(int, lines[1].split()))
  ans = 1000000000000
  for i in range(N):
    if i + K - 1 >= N:
      break
    b = a[i]
    c = a[i + K - 1]
    if b < 0 and c >= 0:
      ans = min(ans, max(abs(b), abs(c)) + 2*min(abs(b), abs(c)))
    else:
      ans = min(ans, max(abs(b), abs(c)))
  print(ans)


if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

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

int main(){
    string str;
    int i,num,sum=0;

    while(cin >> str){
        if(str[0] == '0') break;
        for(i=0;i < str.size(); i++){
            num = str[i] - '0';
            sum += num;
        }
        cout << sum << endl;
        sum = 0;
    }
    return 0;
}



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

const int maxn = 1e5 + 10;
vector<int> mp[maxn];
int n, sz[maxn], dep[maxn], fa[maxn];
int dfs(int u, int f, int d){
    dep[u] = d;
    fa[u] = f;
    sz[u] = 1;
    for(auto &v:mp[u])if(v != f){
        int ret = dfs(v, u, d + 1);
        sz[u] += ret;
    }
    return sz[u];
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i < n; ++i){
        int a, b;
        cin >> a >> b;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    dfs(1, 0, 1);
    int sum = 0, len = dep[n] / 2;
    for(int i = 1, p = n; i <= len; ++i){
        sum = sz[p];
        p = fa[p];
    }
    if(sum >= n - sum)
        cout << "Snuke" << endl;
    else
        cout << "Fennec" << endl;
    return 0;
}

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

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)par[i]=i;}
	int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
	void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
	bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main() {
    int n, m, x, t;
    cin >> n >> m >> x;
    vector<bool> a(n, false);
    rep(i, m) {
        cin >> t;
        t--;
        a[t] = true;
    }
    
    int ans = INF;
    t = 0;
    rreps(i, x) {
        if(a[i]) t++;
    }
    chmin(ans, t);
    
    t = 0;
    for(int i = x; i < n; i++) {
        if(a[i]) t++;
    }
    chmin(ans, t);
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
void trim(string &s)
{
    int index = 0;
    if( !s.empty())
    {
        while( (index = s.find(' ',index)) != string::npos)
        {
            s.erase(index,1);
        }
    }

}
int main()
{
	string h;
	cin>>h;
	int panduan=0;
	int length;
	
	while(panduan==0)
	{
		panduan=1;
		length=h.size()-1;
		for(int i=0;i<length;++i)
		{
			if(h[i]=='S' && h[i+1]=='T')
			{
				int l=i;int r=i+1;
				while(l>=0 && r<length+1 && h[l]=='S' && h[r]=='T')
				{
					h[l]=' ';h[r]=' ';
					l--;r++;
				}
				panduan=0;
			}
		}
		trim(h);
	}
	cout<<h.size()<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


int main(){
  ll n,s;
  cin>>n>>s;
  ll a[n];
  rep(i,n) cin>>a[i];
  
  mint dp[n+1][s+1];
  
  rep(i,n){
    rep(j,s+1){
      if(i-1>=0&&j-a[i]>=0) dp[i][j]=(mint)2*dp[i-1][j]+dp[i-1][j-a[i]];
      else if(i==0){
        dp[0][0]=2;
        dp[0][a[0]]=1;
      }
      //else if(j==0) dp[i][0]=1;
      else if(j<a[i]) dp[i][j]=(mint)2*dp[i-1][j];
    }
    
  }
  
  cout<<dp[n-1][s].x<<endl;
}

Measured memory_bytes: 73948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main(void) {
    
    string s;
    cin>>s;
    if(s[0]==s[2])fin("Yes");
    else fin("No");

}


Measured memory_bytes: 256
#include<iostream>

int main()
{
    int_fast16_t n,res,c;
    int_fast32_t y;
    std::cin >> n >> y;

    for (auto a = n; a >= 0; --a)
    {
        res = n-a;
        for (auto b = res; b >= 0; --b)
        {
            c = res - b;
            if(y == 10000*a+5000*b+1000*c)
            {
                std::cout << a << " " << b << " " << c << std::endl;
                goto fin;
            }
        }
    }
    std::cout << -1 << " " << -1 << " " << -1 << std::endl;
fin:;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char m[4];
  scanf("%s",m);
  if(m[0] == '7')
  printf("Yes\n");
  else if(m[1] == '7')
  printf("Yes\n");
  else if(m[2] == '7')
  printf("Yes\n");
  else
  printf("No\n");
  return 0;
}

Measured memory_bytes: 1608
n, T = map(int, input().split())
p = []
for i in range(n):
   tmp = [int(x) for x in input().split()]
   p.append(tmp)

cmin = 1001
for c, t in p:
   if (t <= T and c < cmin):
      cmin = c

if (cmin > 1000):
   print('TLE')
else:
   print(cmin)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
  	int n;
  	while (cin >> n, n > 0){
	   map<int, int> m;
	   int ret;
	   for (int i = 0; i < n; i++){
		  int x;
		  cin >> x;
		  m[x]++;   
		}
	  bool ok = false;
	  for (auto it : m){
		 if (it.s > n / 2){
			ok = true;
			ret = it.f;
			break; 
		  }
		}
	 if (ok) cout << ret << endl;
	 else cout << "NO COLOR" << endl;	
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 5128
#include <stdio.h>
#include <vector>

using namespace std;


int main() {
  int N, K;
  scanf("%d %d", &N, &K);

  int one_index;

  vector<int> A(N);
  for(int i = 0; i < N; i++){
    scanf("%d", &A[i]);
    if(A[i] == 1){
      one_index = i;
    }
  }

  int min = ((N - 1) + (K - 1) - 1) / (K - 1);

  printf("%d", min);

  return 0;
}


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

int main(){
	int n, w, v;
	while( scanf("%d %d", &n, &w), n || w ){
		int m[110] = {0}, maxi = 0, cnt = 0;
		for(int i = 0; i < n; i++){
			scanf("%d", &v);
			m[v/w]++;
			maxi = max(maxi, m[v/w]);
			cnt = max(cnt, v);
		}
		
		cnt = (cnt / w) + 1;
		
		double a = 1, ans = 0.01;
		for(int i = 0; i < cnt; i++){
			ans += a * ((double)m[i] / maxi);
			a -= 1.0 / (cnt - 1);
		}
		printf("%.7f\n", ans);
	}
}

Measured memory_bytes: 1068
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 2;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, C;
  cin >> n >> C;
  ll d[510][510], c[510][510];
  rep(i, C) rep(j, C) cin >> d[i][j];
  rep(i, n) rep(j, n)
  {
    cin >> c[i][j];
    c[i][j]--;
  }

  ll cnt[510][3] = {};
  rep(i, n) rep(j, n)
  {
    ll k = (i + j) % 3;
    cnt[c[i][j]][k]++;
  }

  ll Min = LINF;
  rep(i1, C) rep(i2, C) rep(i3, C)
  {
    if (i1 == i2 || i2 == i3 || i3 == i1)
      continue;
    ll sum = 0;
    ll use[] = {i1, i2, i3};
    rep(ci, C) rep(j, 3)
    {
      sum += d[ci][use[j]] * cnt[ci][j];
    }
    Min = min(Min, sum);
  }

  cout << Min << endl;
  return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_N = 200001;
const int INF = 2147483647;

// 要素の数、区間などを何からの値を覚えておく配列
int n, q, v[2 * MAX_N - 1];

// 初期化
void init(int _n){
  n = 1;
  while(n < _n) n *= 2;
  REP(i, 2 * n - 1) v[i] = INF;
}

// 添字がkのものをaに更新
void update(int k, int a){
  k += n - 1;
  v[k] = a;
  while(k > 0){
    k = (k - 1) / 2;
    v[k] = min(v[k * 2 + 1], v[k * 2 + 2]);
  }
}

// [a, b)の最小値を求める
// kは今見ている添字、l, rはそれに対応する[l, r)
// 呼び出す時はquery(a, b, 0, 0, n)として呼ぶ
int query(int a, int b, int k, int l, int r){
  if(b <= l || a >= r) return INF;
  if(a <= l && b >= r) return v[k];
  int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
  int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
  return min(vl, vr);
}

int main() {
  cin >>n >>q;
  init(n);
  REP(i, q){
    int Q, x, y;
    cin >>Q >>x >>y;
    if(Q)
      cout <<query(x, y + 1, 0, 0, n) <<endl;
    else
      update(x, y);
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;

typedef unsigned long long ull;
const ull p=1000000007;
const int SIZE=1000000;
ull H[SIZE+1],power[SIZE+1];
char S[SIZE+1],T[SIZE+1];

signed main(){
    scanf("%s%s",S,T);
    int ls=strlen(S),lt=strlen(T);
    power[0]=1;
    for(int i=1;i<=ls;i++){
        power[i]=power[i-1]*p;
        H[i]=H[i-1]*p+S[i-1];
    }

    ull ht=0;
    rep(i,lt)ht=ht*p+T[i];

    for(int i=lt;i<=ls;i++){
        ull hs=H[i]-H[i-lt]*power[lt];
        if(hs==ht)printf("%d\n",i-lt);
    }
    return 0;
}

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

using vi = vector<int>;

int main()
{
    string s,t;
    cin >>s >>t;
    int S = s.size(), T = t.size();

    int ans = 0;
    for(int i=1; i<=min(S,T); ++i)
    {
        set<vi> x;

        vi ct(26);
        rep(j,i) ++ct[s[j]-'a'];
        x.insert(ct);

        for(int j=i; j<S; ++j)
        {
            --ct[s[j-i]-'a'];
            ++ct[s[j]-'a'];
            x.insert(ct);
        }

        ct = vi(26);
        rep(j,i) ++ct[t[j]-'a'];
        if(x.count(ct)) ans = max(ans,i);

        for(int j=i; j<T; ++j)
        {
            --ct[t[j-i]-'a'];
            ++ct[t[j]-'a'];
            if(x.count(ct)) ans = max(ans,i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

//Prime Factorization(素因数分解)
map<ll,int> divisor; //約数を入れるmap
void PF(ll n){
    ll c = n;
    for(int i = 2; i<=sqrt(n); i++){
        while(c%i == 0){
            divisor[i]++;
            c /= i;
        }
    }
    if(c != 1) divisor[c]++;
    return ;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, p; cin >> n >> p;
    PF(p);
    ll res = 1;
    for(auto v: divisor){
        res *= pow(v.first, v.second / n);
    }
    cout << res << endl;
}

Measured memory_bytes: 3700
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  string S;
  cin >> S;
  int ans = 700;

  for (int i = 0; i < 3; i++){
    if(S[i] == 'o'){
      ans += 100;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[200002][33];
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=1e9+7;
bool cmp(ii x, ii y) {
    return (x.first)*(y.second+1)>y.first*(x.second+1);
}
vector<int> zero;
vector<ii> not0;
signed main() {
    int n,t,k;
    cin>>n>>t;
    for(int i=0 ; i<n ; i++) {
        int u,v;
        cin>>u>>v;
        if(u==0) zero.push_back(v);
        else not0.push_back(ii(u,v));
    }
    sort(not0.begin(),not0.end(),cmp);
    sort(zero.begin(),zero.end());
    n=not0.size();
    k=zero.size();
    for(int i=0 ; i<=n ; i++) {
        for(int j=0 ; j<=30 ; j++) {
            dp[i][j]=inf;
        }
    }
    for(int i=0 ; i<=n ; i++) dp[i][0]=0;
    for(int i=1 ; i<=n ; i++) {
        for(int j=1 ; j<=min(n,30ll) ; j++) {
            if(i==j) {
                dp[i][j]=min(inf,dp[i-1][j-1]+1+not0[i-1].first*(dp[i-1][j-1]+1)+not0[i-1].second);
            }
            else {
                dp[i][j]=min({inf,dp[i-1][j],dp[i-1][j-1]+1+not0[i-1].first*(dp[i-1][j-1]+1)+not0[i-1].second});
            }
        }
    }
    int ans=0;
    for(int i=0 ; i<=30 ; i++) {
        if(dp[n][i]<=t) {
            int cnt=i,cur=dp[n][i];
            for(int j=0 ; j<k ; j++) {
                if(cur+zero[j]<t) {
                    cur+=zero[j]+1;
                    cnt++;
                }
            }
            ans=max(ans,cnt);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 55660
#include<stdio.h>

int main(void){
  int x,y,w,h;
  int d,n,i,j;
  int ax,ay;

  scanf("%d",&d);
  for(j=0;j<d;j++){
    int cnt=0;

    scanf("%d%d%d%d",&x,&y,&w,&h);
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d%d",&ax,&ay);
      if( x<=ax && ax<=x+w && y<=ay && ay<= y+h )
	cnt++;
    }
    printf("%d\n",cnt);
  }
  return 0;
}

      

Measured memory_bytes: 0
n, k = [int(i) for i in input().split()]
mod = 10**9 + 7
ans = 0

for i in range(k, n + 2):
    first = i * (i - 1) / 2
    final = (n * 2 - i + 1) * i / 2
    add = final - first + 1
    ans = (ans + add) % mod

print(int(ans))


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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

inline int mult(int a, int b) {
	return (ll)a * b % MOD;
}

inline int add(int a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
	return a;
}

int power(int a, int b) {
	if (!b) {
		return 1;
	}
	if (b % 2) {
		return mult(a, power(a, b - 1));
	}
	return power(mult(a, a), b / 2);
}

inline int C(int n, int k, vector<int> &fact, vector<int> &rfact) {
	return mult(fact[n], mult(rfact[k], rfact[n - k]));
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int k;
	string s;
	cin >> k >> s;
	int n = s.size();
	vector<int> fact(n + k + 1, 1);
	for (int i = 1; i <= n + k; i++) {
		fact[i] = mult(fact[i - 1], i);
	}
	vector<int> rfact(n + k + 1, power(fact.back(), MOD - 2));
	for (int i = n + k; i; i--) {
		rfact[i - 1] = mult(rfact[i], i);
	}
	int ans = 0;
	for (int fir = 0; fir <= k; fir++) {
		ans = add(ans, mult(C(n + k - fir - 1, n - 1, fact, rfact), mult(power(26, fir), power(25, k - fir))));
	}
	cout << ans;
}

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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)

int main(){
    ll N;
    cin >> N;
    vector<ll> H(N);
    rep(i, N) {
        cin >> H[i];
    }
    ll highest = 0;
    ll counter = 0;
    rep(i, N) {
        if (highest <= H[i]) {
            counter++;
            highest = H[i];
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
namespace ztd{
    using namespace std;
    #define reg register
    #define ms(a) memset(a,0,sizeof(a))
    typedef long long ll;
    typedef unsigned long long ull;
    typedef unsigned int uint;
    typedef double db;
    //basic I/O
    template<typename T> inline T read(T& t) {//fast read
        t=0;short f=1;char ch=getchar();double d = 0.1;
        while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();}
        while (ch>='0'&&ch<='9') t=t*10+ch-'0',ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t*=f;
        return t;
    }}
using namespace ztd;
string s;
ll a;
signed main(){
    cin >> s;
    for(int i = 0; i < s.size(); ++i){
        a += (ll)(s[i] - '0');
    }
    if(a % 9) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define PI 3.14159265358979323846
ll power(ll a, ll b){ll res=1;a=a%mod; while(b){if(b&1)res=(res*a)%mod; a=(a*a)%mod;b/=2;}return res;}
ll invmod(ll a){return power(a,mod-2);}

int main(void)
{
	FIO	
	long double r;
	cin>>r;
	cout<<2*PI*r<<"\n";
	return 0;
}

Measured memory_bytes: 3808
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(void){
  string s;
  cin>>s;
  int state = 0 , cnt = 0;
  for(int i = 0 ; i < s.size() ; i ++){
    if(state == 0 && s[i] == 'A'){
      state = 1; 
    }else if(state == 1  && s[i] == 'Z'){
      cnt++;
      state = 0;
    }
  }
  if(cnt==0)cout<<-1;
  else
  for(int i = 0 ; i < cnt ; i ++){
    cout<<"AZ";
  }
  cout<<endl;
}

Measured memory_bytes: 1184
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = 700;
		for (int i = 0 ; i < s.length() ; i++) {
			if (s.charAt(i) == 'o') n += 100;
		}
		System.out.println(n);
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    vector<pair<bool, int>> sub(n, make_pair(false, 0));
    for (int i = 0; i < m; ++i) {
        int p; cin >> p; --p;
        string s; cin >> s;
        if (s == "WA") {
            if (!sub[p].first) sub[p].second += 1;
        }
        else {
            sub[p].first = true;
        }
    }

    int correct = 0, wrong = 0;
    for (int i = 0; i < n; ++i) {
        correct += sub[i].first;
        if (sub[i].first) wrong += sub[i].second;
    }

    cout << correct << ' ' << wrong << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int[] x = new int[5];
        int sum=0;
        for(int i=0;i<5;i++){
            x[i] = sc.nextInt();
            sum += x[i];
        }
        System.out.println(15-sum);
    }

}


Measured memory_bytes: 35772
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
struct nod{
	int value;
	int pos;
}vis[200];
bool cmp(nod a,nod b){
	return a.value>b.value;
}
int main(){
	int t;
	string a,b,c;
	set<char> left;
	set<char> s;
	set<char> right;
	set<char> final;
	cin>>t;
	cin>>a;
	queue<char> q;
	queue<char> po;
	int n=a.length();
	for(int i=0;i<n;i++){
		q.push(a[i]);
		s.insert(a[i]);
	}
	int m=s.size();
	int f;
	for(int i=0;i<n-1;i++){
		left.insert(a[i]);
		q.pop();
		po=q;
		right.clear();
		while(!po.empty()){
			right.insert(po.front());
			po.pop();
		}
		
		set<char>::iterator it;
		set<char>::iterator it2;
		for(it=left.begin();it!=left.end();it++){
			final.insert(*it);
		}
		for(it2=right.begin();it2!=right.end();it2++){
			final.insert(*it2);
		}
		int an=left.size()+right.size()-final.size();
		vis[i].value=an;
		vis[i].pos=i;
	}
	sort(vis,vis+n-1,cmp);
	cout<<vis[0].value <<endl;

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  int c = n % 10;
  
  if(c == 3){
    cout << "bon" << endl;
  }else if(c == 0 || c == 1 || c == 6 || c == 8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;

template<typename T,bool directed>
struct Fordfulkerson{
  struct edge{
    ll to,cap,rev;
    edge(){}
    edge(ll to,ll cap,ll rev):to(to),cap(cap),rev(rev){}
  };

  vector<vector<edge> > G;
  vector<ll> used;

  Fordfulkerson(){}
  Fordfulkerson(ll n):G(n),used(n){}

  void add_edge(ll from,ll to,T cap){
    G[from].emplace_back(to,cap,G[to].size());
    G[to].emplace_back(from,directed?0:cap,G[from].size()-1);
  }

  T dfs(ll v,ll t,T f){
    if(v==t) return f;
    used[v]=true;
    for(ll i=0;i<(ll)G[v].size();i++){
      edge &e = G[v][i];
      if(!used[e.to]&&e.cap>0){
        T d=dfs(e.to,t,min(f,e.cap));
        if(d>0){
          e.cap-=d;
          G[e.to][e.rev].cap+=d;
          return d;
        }
      }
    }
    return 0;
  }

  ll flow(ll s,ll t,T lim){
    T fl=0;
    while(1){
      fill(used.begin(),used.end(),0);
      T f=dfs(s,t,lim);
      if(f==0) break;
      fl+=f;
      lim-=f;
    }
    return fl;
  }

  ll flow(ll s,ll t){
    return flow(s,t,numeric_limits<T>::max()/2);
  }

};

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

int main() {
  while(1) {
    ll m,n;
    cin >> m >> n;
    if(m==0&&n==0) return 0;
    vec b(m),r(n);
    Fordfulkerson<ll,true> G(m+n+2);
    for(ll i=0;i<m;i++) {
      cin >> b[i];
      G.add_edge(m+n,i,1);
    }
    for(ll i=0;i<n;i++) {
      cin >> r[i];
      G.add_edge(m+i,m+n+1,1);
    }
    for(ll i=0;i<m;i++) {
      for(ll j=0;j<n;j++) {
        if(gcd(b[i],r[j])!=1) {
          G.add_edge(i,m+j,1);
        }
      }
    }
    cout << G.flow(m+n,m+n+1) << endl;
  }
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

int main() {
    int n;
    string s, r;
    vector<string> s1, s2;
    s1.reserve(50);
    s2.reserve(50);
    while(cin >> n, n) {
        s1.clear();
        rep(i,n) {
            cin >> s;
            r = s[0];
            REP(j,1,s.size()) {
                if(s[j-1]=='a'||s[j-1]=='i'||s[j-1]=='u'||s[j-1]=='e'||s[j-1]=='o')
                    r += s[j];
            }
            s1.push_back(r);
        }

        bool flag = false;
        int k;
        for(k=1; k<=50; ++k) {
            s2.clear();
            rep(j, s1.size()) {
                s2.push_back(s1[j].substr(0, min((int)s1[j].size(),k)));
            }
            sort(s2.begin(), s2.end());
            s2.erase(unique(s2.begin(),s2.end()),s2.end());
            if(s2.size()==n) {
                flag = true;
                break;
            }
        }
        if(flag) P(k);
        else P(-1);
    }
    return 0;
}

Measured memory_bytes: 3104
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;
#define bef(i) ((i)+n-1)%n
#define aft(i) ((i)+1)%n

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> b(n);
	FOR(i,0,n){
		cin>>a[i];
	}
	priority_queue<array<int,2>> pq;
	pq.push({0,n+2});
	FOR(i,0,n){
		cin>>b[i];
		if(a[i]!=b[i])pq.push({b[i],i});
	}
	LL ans=0;
	while(pq.size()>1){
		auto tpl=pq.top();
		pq.pop();
		int af=tpl[0],i=tpl[1];
		int sec=max(b[aft(i)],b[bef(i)]);
		int obj=max(a[i],sec);
		//cerr<<i<<" "<<af<<endl;
		int tmp=(af-obj)/(b[aft(i)]+b[bef(i)]);
		if(tmp==0){
			tmp=1;
		}
		int bf=af-tmp*(b[aft(i)]+b[bef(i)]);
		ans+=tmp;
		b[i]=bf;
		//cerr<<" "<<i<<" "<<bf<<endl;

		if(bf==a[i]){

		}else if(bf<a[i]){
			cout<<-1<<endl;
			return 0;
		}else{
			pq.push({bf,i});
		}
	}
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll X;
  cin>>X;
  for(ll i=-1000;i<=1000;i++) for(ll j=-1000;j<=1000;j++) if(i*i*i*i*i-j*j*j*j*j==X){
    cout<<i<<" "<<j<<endl;
    return 0;
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 998244353ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> w(n), v(n);
    REP(i, n) { cin >> w[i] >> v[i]; }

    // 定義
    // dp[i+1][j] := iまで見て重さがj以下の時の価値の最大値
    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));

    // 初期化
    // 1つも見ていないとき価値は0

    // 遷移
    REP(i, n){
        REP(j, m+1){
            dp[i+1][j] = dp[i][j];
            if(j - w[i] >= 0){
                chmax(dp[i+1][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }

    // 答え方
    cout << dp[n][m] << endl;
    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define maxn 100086

using namespace std;

const int p = 1e9 + 7;

inline int fpow(int x, int y){
	int ans = 1;
	while(y){
		if(y & 1) ans = 1ll * ans * x % p;
		x = 1ll * x * x % p, y >>= 1;
	}
	return ans;
}

int t;
int n;
int inv[maxn];

inline int C(int n, int m){
	int ans = 1;
	for(int i = 1;i <= m;i++) ans = 1ll * ans * (n--) % p;
	return 1ll * ans * inv[m] % p; 
}

int main(){
	inv[20] = 1;for(int i = 1;i <= 20;i++) inv[20] = 1ll * inv[20] * i % p;
	inv[20] = fpow(inv[20], p - 2);
	for(int i = 19;~i;i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % p;
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		if(n < 5){
			puts("0");
			continue;
		}
		int ans = 0;
		for(int i = 0;i <= 11 && i <= n - 5;i++){
			if((n - 5 - i) & 1) continue;
			int x = (n - 5 - i) / 2;
			ans = (ans + 1ll * C(11, i) * C(x + 15, 15)) % p;
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
int main(){
	int n,x;scanf("%d",&n);
	for(int i=1;i<n;i++)scanf("%d",&x),a[x]++;
	for(int i=1;i<=n;i++)printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 4536
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

const int MSQ = sqrt(N) + 5;

std::vector<int> wa;
bool  y[1000005];
void sieve(){
	for(int i=2;i<=1000000;i++){
		if(y[i])continue;
		wa.pb(i);
		for(int j=i;j<=1000000;j+=i){
			y[j]=1;
		}
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	file();
	int x;
	sieve();
	scanf("%d",&x);

	printf("%d\n",*lower_bound(all(wa),x));
}		



Measured memory_bytes: 1916
# -*- coding: utf-8 -*-
"""
Created on Sun May 12 12:43:59 2019

@author: Yamazaki Kenichi
"""

N = int(input())
S = [input() for i in range(N)]

ans = 0
firstB, lastA, u = 0, 0, 0
for s in S:
    flg = False
    for c in s:
        if flg and c == "B":
            ans += 1
        flg = False
        if c == 'A':
            flg = True
    if s[0] == 'B':
        firstB += 1
    if s[-1] == 'A':
        lastA += 1
    if s[0] == 'B' and s[-1] == 'A':
        u += 1
ans += min(firstB,lastA)
ans -= 1 if u == firstB and u == lastA and u != 0 else 0
print(ans)

Measured memory_bytes: 3700
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

map<int, ll> dp[210];
vint edge[210];
bool notroot[210];
ll nCm[500][500];

int n;

void dfs(int cur) {
	dp[cur][0] = 1;
	rep(i, edge[cur].size()) {
		int to = edge[cur][i];
		dfs(to);
		map<int, ll> next;
		for (auto a : dp[cur]) {
			for (auto b : dp[to]) {
				//a?????????i?????\??£?????????
				REP(i, min(a.fst, b.fst + 1)) {
					int j = b.fst + 1 - i;//j????????±???????¢???????
					ll select = nCm[a.fst + j][a.fst] * nCm[a.fst][i] % mod;
					next[a.fst + j] += (a.scn*b.scn%mod)*select%mod;
					next[a.fst + j] %= mod;
				}
			}
		}
		dp[cur] = next;
	}
}

int main() {
	nCm[0][0] = 1;
	srep(i, 1, 500)	REP(j, i) {
		if (j)	nCm[i][j] += nCm[i - 1][j - 1];
		nCm[i][j] += nCm[i - 1][j];
		nCm[i][j] %= mod;
	}
	cin >> n;
	srep(i, 1, n) {
		int a, b;	cin >> a >> b;
		edge[a].push_back(b);
		notroot[b] = true;
	}
	rep(i, n) {
		if (!notroot[i]) {
			dfs(i);
			ll ret = 0;
			for (auto it : dp[i]) {
				ret = (ret + it.second) % mod;
			}
			cout << ret << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 5196