akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int n, m;
    scanf("%d %d",&n,&m);
    
    int a[n][m]; //行列
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    int b[m]; //ベクトル
    
    for(int i = 0;i < m;i++){
        scanf("%d",&b[i]);
    }
    
    int c[n];
    
    //c[n]の初期化
    for(int i = 0;i < n;i++){
        c[i] = 0;
    }
    
    //行列とベクトル積の計算
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            c[i] += a[i][j] * b[j];
        }
    }
    
    //出力
    for(int i = 0;i < n;i++){
        printf("%d\n",c[i]);
    }
    
    return 0;
}



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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007

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

   int N;
   cin>>N;
   vector<vector<int> >e(N);
   for(int i=0;i<N-1;i++){
      int x,y;
      cin>>x>>y;
      x--,y--;
      e[x].push_back(y);
      e[y].push_back(x);
   }
   string first = "Fennec",second = "Snuke";

   vector<int>bd(N,0),wd(N,0);

   queue<int>black;
   black.push(0);
   bd[0] = 0;
   vector<bool>b_used(N,false);
   while(black.size()){
      int now = black.front();
      black.pop();
      if(b_used[now])continue;
      b_used[now]=true;
      for(auto it:e[now]){
         bd[it] = bd[now]+1;
         black.push(it);
      }
   }

   queue<int>white;
   white.push(N-1);
   wd[N-1] = 0;
   vector<bool>w_used(N,false);
   while(white.size()){
      int now = white.front();
      white.pop();
      if(w_used[now])continue;
      w_used[now]=true;
      for(auto it:e[now]){
         wd[it] = wd[now]+1;
         white.push(it);
      }
   }

   int sum_w = 0;
   int sum_b = 0;

   for(int i=0;i<N;i++){
      if(wd[i]==bd[i])sum_b++;
      else if(wd[i] < bd[i])sum_w++;
      else if(wd[i] > bd[i])sum_b++;
   }

   if(sum_w == sum_b)cout<<second<<endl;
   else if(sum_w < sum_b)cout<<first<<endl;
   else if(sum_w > sum_b)cout<<second<<endl;
   return 0;
}


Measured memory_bytes: 6656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int count = 0;

		while (b >= a) {
			count++;
			b -= a;
			if (count >= c) {
				break;
			}
		}
		System.out.print(count);

	}
}

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define mp make_pair

#define NIL -1

#define list_itr list<ll>::iterator

#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define rep_cs(i, l, n) for (int i = (l); i <= (n); i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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;
}

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

bool binary_search(int a[], int n, int key)
{
    int l = 0;
    int r = n;
    int middle;
    while (l < r)
    {
        middle = (l + r) / 2;
        if (key == a[middle])
        {
            return true;
        }

        if (key > a[middle])
        {
            l = middle + 1;
        }
        else if (key < a[middle])
        {
            r = middle;
        }
    }
    return false;
}

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long combination(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = k; i <= n + 1; i++)
    {
        ll f = i * (i - 1) / 2;
        ll fin = (n * 2 - i + 1) * i / 2;
        ll add = fin - f + 1;
        ans = (ans + add) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

template<typename TT, int MX, int LG, ll INF> struct SparseTable //Warning : Change query return value manually if needed. INF is the dummy val
{
	TT st[LG][MX];
	TT initial[MX];
	
	TT combine(TT a, TT b) //warning : change if neccesary
	{
		if(a<b) return a;
		return b;
	}
	
	SparseTable()
	{
		for(int i = 0; i < MX; i++) initial[i] = INF;
	}
	
	void init()
	{
		for(ll j = 0; j < LG; j++)
		{
			for(ll i = 0; i < MX; i++)
			{
				st[j][i] = INF;
				if(i + (1<<j) - 1 < MX)
				{
					if(j == 0) st[j][i] = initial[i];
					else st[j][i] = combine(st[j-1][i], st[j-1][i + (1<<(j-1))]);
				}
			}
		}
	}
	
	TT query(int l, int r)
	{
		int k = 31 - __builtin_clz(r-l);
		if(l==r) k=0;
		return combine(st[k][l], st[k][r - (1<<k) + 1]);
	}
};

SparseTable<int, 200001, 19, int(1e9)> st[2];

int query(int l, int r, int type)
{
	return st[type].query(l/2,r/2);
}

int p[200001];
int iperm[200001];

priority_queue<pair<int,ii>,vector<pair<int,ii> >,greater<pair<int,ii> > > pq;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	//n = 200000;
	for(int i = 0; i < n; i++)
	{
		cin>>p[i];
		//p[i] = i;
		iperm[p[i]]=i;
		st[i&1].initial[i/2] = p[i];
	}
	st[0].init(); st[1].init();
	vector<ii> ans;
	pq.push(mp(query(0,n-2,0),mp(0,n-1)));
	while(!pq.empty())
	{
		int l = pq.top().se.fi; int r = pq.top().se.se; pq.pop();
		int tmp = query(l,r-1,l&1);
		int R1 = iperm[tmp];
		int tmp2 = query(R1+1,r,r&1);
		int L2 = iperm[tmp2];
		ans.pb(mp(tmp,tmp2));
		if(l<=R1-1)
		{
			pq.push(mp(query(l,R1-2,l&1),mp(l,R1-1)));
		}
		if(R1+1<=L2-1)
		{
			pq.push(mp(query(R1+1,L2-2,(R1+1)&1),mp(R1+1,L2-1)));
		}
		if(L2+1<=r)
		{
			pq.push(mp(query(L2+1,r-1,(L2+1)&1),mp(L2+1,r)));
		}
	}
	for(int i=0;i<n/2;i++)
	{
		cout<<ans[i].fi<<' '<<ans[i].se;
		if(i+1<n/2) cout<<' ';
	}
	cout<<'\n';
}


Measured memory_bytes: 35852
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	string s;
	cin >> s;
	int r = 0;
	for (int i = 0; i < s.size() - 1; i++)if (s[i] != s[i + 1])r++;
	printf("%d\n", r);
}

Measured memory_bytes: 512
#include<cstdio>
int main(){
	int n,a,b;scanf("%d%d%d",&n,&a,&b);
	if(a>b)printf("0\n");
	else if(n==1){
		if(a==b)printf("1\n");
		else printf("0\n");
	}else{
		long long Min=b+a*1ll*(n-1),Max=a+b*1ll*(n-1);
		printf("%lld\n",Max-Min+1);
	}
	return 0;
}

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

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; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;



int64_t a;
double b;

int main(){
    cin >> a >> b;

    int64_t b2 = (int64_t)llround(b*100.0);

    cout << a*b2/100 <<endl;
}


Measured memory_bytes: 3744
#include<stdio.h>

int main(void) {

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

	if (a >= 1 && a <= 9) {
		if (b >= 1 && b <= 9) {
			printf("%d", a * b);

		}
		else {
			printf("-1");
		}

	}
	else {
		printf("-1");

	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(x) for x in input().split()]
count = 0
ab_sum = 0
min = 1000000000

for i in range(N):
    ab = 0

    if A[i] >= 0:
        ab_sum += A[i]
        ab = A[i]
    else:
        count += 1
        ab_sum -= A[i]
        ab = -A[i]
    if ab < min:
        min = ab

if(count % 2 == 0):
    print(ab_sum)
else:
    print(ab_sum-2*min)

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

int main(){
    int moun[10];
    int temp;
    
    
    for(int i=0;i<10;i++)
        cin >> moun[i];

    
        for(int i=0;i<9;i++){
        for(int j=i+1;j<10;j++){
            if(moun[i]<moun[j]){
               temp = moun[i];
               moun[i] = moun[j];
               moun[j] = temp;
            }
        }
    }

    for(int i=0;i<3;i++){
        cout << moun[i] << endl;
    }
    return 0;
}

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

#define pb push_back
#define mp make_pair

typedef long long ll;

int main()
{
  ll n, m;
  cin >> n >> m;

  ll a = min(n, m/2);

  m -= a*2;

  ll b = m/4;

  cout << a+b << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sc(x) scanf("%lld",&x);
signed main()
{
    int N,K;
    sc(N)sc(K)
    int cnt =0;
    while(N){
        N/=K;
        cnt ++;
    }
    cout<<cnt<<'\n';

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
const ll mod=1000000007;
int main() {
  ll n,k;cin>>n>>k;
  ll ans=0;
  for(int i=k;i<n+2;i++){
    ans+=i*(n-i+1)+1;
    ans%=mod;
  }
  cout<<ans%mod<<endl;
  return 0;
}

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

using namespace std;

using ll = long long;

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

    int n, max_s = 0;
    string s;

    cin >> n >> s;
    for (int i = 1; i < n - 1; ++i) {
        vector<bool> used(26, false);
        int cnt = 0;

        for (int j = 0; j <= i; ++j)
            used[(int)(s[j] - 'a')] = true;

        for (int j = i + 1; j < n; ++j)
            if (used[(int)(s[j] - 'a')]) {
                ++cnt;
                used[(int)(s[j] - 'a')] = false;
            }

        max_s = max(max_s, cnt);
    }

    cout << max_s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int ans = 0;
	if(a < b) ans += a;
	else ans += b;
	if(c < d) ans += c;
	else ans += d;

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner sc = new Scanner(System.in);
		    
		    String s = sc.nextLine();
		    
		    System.out.println(s.lastIndexOf("Z") - s.indexOf("A") + 1);
		    sc.close(); }
		  }


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

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

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

  ll mi = LINF;
  for(int i=1;i<=100;++i) {
    ll now = 0;
    for(int j=0;j<n;++j) {
      now += (x[j] - i) * (x[j] - i);
    }
    mi = min(mi, now);
  }
  cout << mi << endl;


}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(200002, 0), b(200002, 0);
  for(int i = 0; i < m; i++){
    int c, d;
    cin >> c >> d;
    if(c == 1) a.at(d) = 1;
    if(d == n) b.at(c) = 1;
  }
  for(int i = 0; i < 200002; i++){
    if(a.at(i) + b.at(i) == 2){
      cout << "POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

template<class T>
struct CumulativeSum {
  vector<T> v;

  CumulativeSum(size_t n) : v(n+1) {};
  CumulativeSum(vector<T> v_) : v(v_) {
    v.push_back(T());
  };

  void add(size_t i, T x) {
    v[i] += x;
  }

  // O(N)
  void build() {
    for (size_t i = v.size()-1; i > 0; i--)
      v[i-1] += v[i];
  }

  // O(1) sum [l, r]
  T sum(size_t l, size_t r) const {
    return v[l]-v[r+1];
  }

  // O(1) sum [0, r]
  T sum(size_t r) const {
    return sum(0, r);
  }
};

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

  ll n;
  string x;
  cin >> n;
  vector<string> s(n);
  vl t(n);
  rep(i, n) {
    cin >> s[i] >> t[i];
  }
  cin >> x;

  CumulativeSum<ll> cs(n);
  rep(i, n) {
    cs.add(i, t[i]);
  }
  cs.build();
  rep(i, n) {
    if (x == s[i]) {
      cout << cs.sum(i, n-1)-t[i] << endl;
    }
  }
}


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

int main(){
  string s;
  cin>>s;
  if(s=="SSS") cout<<0<<endl;
  if(s=="SSR") cout<<1<<endl;
  if(s=="SRS") cout<<1<<endl;
  if(s=="SRR") cout<<2<<endl;
  if(s=="RSS") cout<<1<<endl;
  if(s=="RSR") cout<<1<<endl;
  if(s=="RRS") cout<<2<<endl;
  if(s=="RRR") cout<<3<<endl;
}



Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
	int h, w, i, j=0;
	char p[110][110];
	scanf("%d %d", &h, &w);

	for(i=0; i<h; i++)
		scanf("%s", p[i]);

	for(i=0; i<h; i++){
		do{
			printf("%s\n", p[i]);
			j++;

		}while(j%2 != 0);
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n,m,ff=1,fa[maxn],dis[maxn];
inline int find(int x) {
	if(x!=fa[x]) {
		int tmp=fa[x];
		fa[x]=find(fa[x]);
		dis[x]+=dis[tmp];
	}
	return fa[x];
}
int main() {
	scanf("%d%d",&n,&m);
	for ( int i=1;i<=n;i++ ) fa[i]=i;
	for ( int i=1;i<=m;i++ ) {
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		int f1=find(u),f2=find(v);
		if(f1==f2&&dis[u]-dis[v]!=w) ff=0;
		if(f1!=f2) {
			fa[f1]=f2;
			dis[f1]=w+dis[v]-dis[u];
		}
	}
	(!ff)?printf("No\n"):printf("Yes\n");
	return 0;
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

string ans;
void dfs(vector <pair <int, string>> v) {
	if(v.size() == 1) {
		if(v[0].first == 10)
			ans = v[0].second;
		else
			return;
	}
	int n = v.size();
	for(int i = 0; i < n; i ++)
		for(int j = 0; j < n; j ++) if(i != j) {
			vector <pair <int, string>> nxt;
			for(int k = 0; k < n; k ++) if(i != k && j != k)
				nxt.pb({v[k]});
			nxt.pb({v[i].first + v[j].first, "(" + v[i].second + "+" + v[j].second + ")"});
			dfs(nxt); nxt.pop_back();
			nxt.pb({v[i].first - v[j].first, "(" + v[i].second + "-" + v[j].second + ")"});
			dfs(nxt); nxt.pop_back();
			nxt.pb({v[i].first * v[j].first, "(" + v[i].second + "*" + v[j].second + ")"});
			dfs(nxt); nxt.pop_back();
		}
}

int a[4];

int main() {
	ios :: sync_with_stdio(0);

	for(;;) {
		for(int i = 0; i < 4; i ++)
			cin >> a[i];
		if(*max_element(a, a + 4) == 0)
			break;
		vector <pair <int, string>> v;
		for(int i = 0; i < 4; i ++)
			v.pb({a[i], to_string(a[i])});
		ans = "";
		dfs(v);
		if(ans.size())
			cout << ans << '\n';
		else
			cout << "0\n";
	}

	return 0;
}

Measured memory_bytes: 3276
import java.util.Scanner;

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

	long N = sc.nextLong();
	long data[] = new long[5];
	data[0] = sc.nextLong();
	int min = 0;
	for (int i = 1; i < data.length; i++) {
	    data[i] = sc.nextLong();
	    if (data[min] > data[i]) {
		min = i;
	    }
	}

	System.out.println((long)((N + data[min] - 1) / data[min]) + 4);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int a,b,c,k,ans=0;
	cin>>a>>b>>c>>k;
	if(k<=a){
	    ans=k;
	}
	else{
	    ans=a;
	    k-=a;
	    ans-=max(0,k-b);
	}
	cout<<ans;
	return 0;
}


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

int main()
{
    int n, k, input;
    cin>> n >> k;

    vector<int> vec(n);

    for(int i = 0; i < n; i++)
        cin>>vec[i];


    sort(vec.begin(),vec.end());

    int sum = 0;

    for(int i = 0; i < k; i++)
        sum = sum + vec[i];


    cout<< sum;
    return 0;

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; //check the limits, dummy

int solve(int n, int m) {
    vector<int> v(n, 0), used(n, 0);
    for(int i = 0; i < m; i++) {
        int s, c; cin >> s >> c;
        s--;
        if(s == 0 && c == 0 && n != 1) return -1;
        if(used[s] && c != v[s]) return -1;
        v[s] = c;
        used[s] = 1;
    }

    if(v[0] == 0 && n != 1) v[0] = 1;
    int res = 0;
    for(int &i : v) {
        res *= 10;
        res += i;
    }

    return res;
}

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

    int n, m; cin >> n >> m;
    cout << solve(n, m) << endl;
}	

Measured memory_bytes: 256
N, *UV = [int(_) for _ in open(0).read().split()]
ans = N * (N + 1) * (N + 2) // 6
for u, v in zip(UV[::2], UV[1::2]):
    if v > u:
        u, v = v, u
    ans -= v * (N + 1 - u)
print(ans)


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

#define ll long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define viit vector<int>::iterator
#define MOD 1000000007
#define endl "\n"
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repe(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define modm(a, m) (((a) % m + m) % m)
#define mod(a) modm(a, MOD)
#define op_mod(op, a, b) mod(mod(a) op mod(b))

using namespace std;
vi topo;

void dfs(int v, vi adjlst[], bool visited[]) {
    if (visited[v])
        return;
    visited[v] = true;
    for (auto u : adjlst[v]) {
        dfs(u, adjlst, visited);
    }
    topo.push_back(v);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vi adjlst[n];
    int x, y;
    rep(i, 0, m) {
        cin >> x >> y;
        x--, y--;
        adjlst[x].push_back(y);
    }
    bool visited[n] = {0};
    rep(i, 0, n) {
        if (!visited[i])
            dfs(i, adjlst, visited);
    }
    vi dist(n, 0);
    reverse(topo.begin(), topo.end());
    for (auto v : topo) {
        for (auto w : adjlst[v]) {
            if (dist[w] < dist[v] + 1) {
                dist[w] = dist[v] + 1;
            }
        }
    }

    cout << *max_element(dist.begin(), dist.end());
    return 0;
}


Measured memory_bytes: 9464
#include <cstdio>

int max(int x, int y){
    return (x>y) ? x : y;
}

int main(){
    int A, B, C, D;
    scanf("%d%d%d%d", &A, &B, &C, &D);
    printf("%d\n", max(A*B, C*D));
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int H , W;cin >> H >> W;
  vector<vector<char>> C(H,vector<char>(W));
  rep(i,H){
    rep(j,W){
      cin >> C[i][j];
    }
  }
    rep(i,H){
    rep(j,W){
      cout << C[i][j];
  }
    cout << endl;
    rep(j,W){
      cout << C[i][j];
  }
    cout << endl;
    }
    }


Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((x >= r && x <= W-r) && (y >= r && y <= H-r))
        printf("Yes\n");
    else{
        printf("No\n");
    }
}


Measured memory_bytes: 2680
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

int main(void){
    string str,A,B;
    int a,b;
    cin >> a >> b;
    cin >> str;
    if(str[a] != '-'){
        cout << "No" << endl;
        return 0;
    }
    string num = "0123456789";
    for(auto itr = str.begin();itr!=str.end();++itr){
        if(itr == str.begin()+a)continue;
        if(find(num.begin(),num.end(),(*itr)) == num.end()){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

ll ans = 0;

void f(int x, ll n, deque<int> &q) {
    if (n == 0) return;
    if (n&1) q.push_back(x);
    int ct = 0;
    int v = 10 * x + x;
    while (v >= 10) {
        ct++;
        v -= (to_string(v)[0]-'0') * 9;
    }
    if (x == 0) ct++;
    ans += ct * (n/2);
    f(v,n/2,q);
}

int main() {
    int m; cin >> m;
    deque<int> q;
    rep(i,m) {
        int d;
        ll c; 
        cin >> d >> c;
        f(d,c,q);
    }
    while (q.size() != 1) {
        ans++;
        int a = q.front(); q.pop_front();
        int b = q.front(); q.pop_front();
        int sum = a + b;
        q.push_front(sum%10);
        sum /= 10;
        if (sum != 0) q.push_front(sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 16652
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int cur,cur2,num[11],perm[10];
char op[10];
string s;

int digit(){
	assert(isdigit(s[cur]));
	int n=s[cur++]-'0';
	return n;
}

set<int> number(){
	int n=digit();
	while(cur<s.size()&&isdigit(s[cur]))n=n*10+digit();
	set<int> res;
	res.insert(n);
	return res;
}

set<int> calc2(set<int> a,set<int> b,char c){
	set<int> res;
	set<int>::iterator it1;
	set<int>::iterator it2;
	for(it1=a.begin();it1!=a.end();it1++)for(it2=b.begin();it2!=b.end();it2++){
		int n;
		if((*it2)==0&&c=='/')continue;
		if(c=='+')n=*it1+(*it2);
		if(c=='-')n=*it1-(*it2);
		if(c=='*')n=*it1*(*it2);
		if(c=='/')n=*it1/(*it2);
		res.insert(n);
	}
	return res;
}

set<int> expression(){
	set<int> num[11];
	char op[10];
	int no=0;
	if(s[cur]=='('){
		cur++;
		num[no]=expression();
		cur++;
	}
	else num[no]=number();
	while(cur<s.size()&&(s[cur]=='+'||s[cur]=='-'||s[cur]=='*'||s[cur]=='/')){
		op[no++]=s[cur++];
		if(s[cur]=='('){
			cur++;
			num[no]=expression();
			cur++;
		}
		else num[no]=number();
	}
	set<int> dp[11][11];
	rep(i,no+1)dp[i][i]=num[i];
	for(int i=1;i<=no;i++)rep(j,no-i+1){
		rep(k,i){
			set<int> temp=calc2(dp[j][j+k],dp[j+k+1][j+i],op[j+k]);
			set<int>::iterator it;
			for(it=temp.begin();it!=temp.end();it++)dp[j][j+i].insert(*it);
		}
	}
	return dp[0][no];
	/*rep(i,no)perm[i]=i;
	do{
		int p[10],rest=no,flag=0;
		char o[10];
		set<int> n[11];
		rep(i,no+1)n[i]=num[i];
		rep(i,no)o[i]=op[i];
		rep(i,no)p[i]=perm[i];
		rep(i,no){
			set<int> a=n[p[i]],b=n[p[i]+1];
			char c=o[p[i]];
			n[p[i]]=calc2(a,b,c);
			for(int j=p[i]+1;j<rest;j++)n[j]=n[j+1];
			for(int j=p[i];j<rest-1;j++)o[j]=o[j+1];
			for(int j=i+1;j<no;j++)if(p[j]>=p[i])p[j]--;
			rest--;
		}
		set<int>::iterator it;
		for(it=n[0].begin();it!=n[0].end();it++)res.insert(*it);
	}while(next_permutation(perm,perm+no));
	return res;*/
}


int main(){
	ofstream o("tempDout.txt");
	while(cin>>s&&s!="#"){
		cur=0;
		set<int> a;
		set<int>::iterator it;
		o<<(a=expression()).size()<<endl;
		cout<<a.size()<<endl;
		//for(it=a.begin();it!=a.end();it++)cout<<*it<<" ";cout<<endl;
	}
}
		/*cur2=0;
		fill(num,num+11,0);
		fill(op,op+10,0);
		int N=expression();
		rep(i,N)perm[i]=i;
		set<int> ans;
		do{
			int n[11],p[10],rest=N,flag=0;
			char o[10];
			rep(i,N+1)n[i]=num[i];
			rep(i,N)o[i]=op[i];
			rep(i,N)p[i]=perm[i];
			rep(i,N){
				int a=n[p[i]],b=n[p[i]+1];
				char c=o[p[i]];
				if(b==0&&c=='/'){flag=1;break;}
				n[p[i]]=calc2(a,b,c);
				for(int j=p[i]+1;j<rest;j++)n[j]=n[j+1];
				for(int j=p[i];j<rest-1;j++)o[j]=o[j+1];
				for(int j=i+1;j<N;j++)if(p[j]>=p[i])p[j]--;
				rest--;
			}
			if(!flag)ans.insert(n[0]);
		}while(next_permutation(perm,perm+N));
		cout<<ans.size()<<endl;
		set<int>::iterator it;
		for(it=ans.begin();it!=ans.end();it++)cout<<*it<<" ";cout<<endl;
	}
}*/

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int MAX=1e5+10;
const ll INF=(1LL<<31)-1;
const double PI=acos(-1);

const int SEGLEN=1<<19;
vector<int> segtree(2*SEGLEN);

void update(int ind, int x) {
    ind+=SEGLEN;
    segtree[ind]=x;
    while (1) {
        ind/=2;
        if (ind==0) break;
        segtree[ind]=max(segtree[2*ind],segtree[2*ind+1]);
    }
}

int get_max(int l, int r) {
    l+=SEGLEN;
    r+=SEGLEN;
    int ans=0;
    while (l<r) {
        if (l%2==1) {
            ans=max(ans,segtree[l]);
            ++l;
        }
        l/=2;
        if (r%2==1) {
            ans=max(ans,segtree[r-1]);
            --r;
        }
        r/=2;
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    rep(i,n) {
        int a;
        cin >> a;
        int s=max(0,a-k),t=min(SEGLEN,a+k+1);
        update(a, get_max(s,t)+1);
    }
    int ans=1;
    rep(i,SEGLEN) ans=max(ans,segtree[i+SEGLEN]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7316
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int count = 0;
            int temp = 0;
            if (B > A)
            {
                while (temp < B)
                {
                    temp += A;
                    if (count > 0) temp -= 1;
                    count++;
                }
            }
            else
            {
                if (B == 1) count = 0;
                else count = 1;
            }
            Console.WriteLine(count.ToString());
//            Console.Read();
        }
    }
}

Measured memory_bytes: 13140
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w, m) = (v[0], v[1], v[2]);
    let mut count_y = vec![0; h];
    let mut count_x = vec![0; w];

    let mut points = HashSet::new();
    for i in 0..m {
        let v = read_vec::<usize>();
        let (y, x) = (v[0] - 1, v[1] - 1);
        count_y[y] += 1;
        count_x[x] += 1;
        points.insert((x, y));
    }
    let count_y_max = *count_y.iter().max().unwrap();
    let count_x_max = *count_x.iter().max().unwrap();
    let mut ans = count_x_max + count_y_max - 1;

    let count_max_ys = (0..h)
        .filter(|&y| count_y[y] == count_y_max)
        .collect::<Vec<_>>();
    let count_max_xs = (0..w)
        .filter(|&x| count_x[x] == count_x_max)
        .collect::<Vec<_>>();

    if count_max_xs.len() as i64 * count_max_ys.len() as i64 > m as i64 {
        ans += 1;
    } else {
        'o: for y in count_max_ys {
            for &x in &count_max_xs {
                if !points.contains(&(x, y)) {
                    ans += 1;
                    break 'o;
                }
            }
        }
    }

    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main() {
  ll N, W;
  cin >> N >> W;

  vector<vector<ll>> a(4);
  ll w0 = 0;
  vector<ll> w(N + 1), v(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> w[i] >> v[i];
    if(i == 1) w0 = w[i];
    int itr = w[i] - w0;
    a[itr].push_back(v[i]);
  }
  for (int i = 0; i < 4; i++) {
    sort(a[i].rbegin(),a[i].rend());
    a[i].insert(a[i].begin() + 0,0);
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 1; j < (int)a[i].size(); j++) {
      a[i][j] += a[i][j - 1];
    }
  }
  ll ans = 0;
  for (int i = 0; i < a[0].size(); i++) {
    for (int j = 0; j < a[1].size(); j++) {
      for (int k = 0; k < a[2].size(); k++) {
        for (int l = 0; l < a[3].size(); l++) {
          ll sum = w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l;
          if (sum > W) break;
          ll tmp = a[0][i] + a[1][j] + a[2][k] + a[3][l];
          ans = max(ans, tmp);
        }
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
local n, k = io.read("*n", "*n")
local c = 0
if k == 0 then
  print(n * n)
else
  for b = k + 1, n do
    local x, y = n // b, n % b
    c = c + (b - k) * x
    if 0 < y then
      c = c + math.max(0, y - k + 1)
    end
  end
  print(c)
end


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

using namespace std;

int main() {
    int x, n;
    cin >> x >> n;
    vector<bool> used(101);
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        used[p] = true;
    }

    int miDis = 100000, miValue = 0;
    for (int i = 0; i <= 101; i++) {
        if (miDis > abs(x - i) && !used[i]){
            miDis = abs(x - i), miValue = i;
        }
    }
    cout << miValue << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
 
int main(void)
{
  int a,b,t,f,d;
  double time;
  scanf("%d%d%d",&a,&b,&t);
  
  time = t + 0.5;
  f = time / a;
  d = f * b;
  printf("%d",d);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve(void)
{
  
  int N;cin>>N;
  vector<int> A (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>A[i];
  } 
  vector<int> B (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>B[i];
  }
  int E_A = 0, E_B = 0;
  for (int i = 0; i < N; i++)
  {
    if(A[i] >B[i]) E_A += A[i] - B[i];
    else E_B += (B[i]-A[i])/2*2;
  }
  // DEBUG(E_A,E_B);
  if(E_B < 2*E_A)
  {
    cout<<"No"<<endl;
  }
  else
  {
    cout<<"Yes"<<endl;
  }
  
  
  return;
}

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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// int main() {
//     // 前処理
//     COMinit();

//     // 計算例
//     cout << COM(100000, 50000) << endl;
// }


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

    int n,k;
    cin >> n >> k;
    ll ary[n];
    rep(i,n) cin >> ary[i];
    sort(ary, ary+n);
    ll MIN = 0;
    ll MAX = 0;
    rep(i,n-k+1)
    {
        MIN += ary[i] * COM(n-1-i, k-1);
        MIN %= MOD;
    }
    REP(i,k-1, n)
    {
        MAX += ary[i] * COM(i, k-1);
        MAX %= MOD;
    }
    ll ANS = (MAX+MOD-MIN) % MOD;
    cout << ANS << endl;


}




Measured memory_bytes: 13056
def main():
    n, m, x = map(int, input().split())
    As = list(map(int, input().split()))

    line = [0 for _ in range(n+1)]
    for i in range(n+1):
        if i in As:
            line[i] += 1
    ans = min(sum(line[:x]), sum(line[x:]))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<stdlib.h>
using namespace std;

int N, A, B, C, l[8] = {};
long long mpsum, mpmin = 9999999999;
void dfs(int depth, vector<int> v) {

	if (depth == N) {//ここから計算部
		int num[4] = {};//使われた回数を確認
		int a = 0, b = 0, c = 0;//a,b,cのmp消費前の竹の長さ
		for (int i = 0; i < N; i++) {
			num[v[i]] += 1;
			if (v[i] == 1)a += l[i];
			if (v[i] == 2)b += l[i];
			if (v[i] == 3)c += l[i];
		}
		if (num[1] != 0 && num[2] != 0 && num[3] != 0) {
			mpsum = (abs(A - a) + abs(B - b) + abs(C - c) + (num[1] + num[2] + num[3] - 3) * 10);
			if (mpsum < mpmin)mpmin = mpsum;
		}
		//ここまで計算部
	}
	else {
		for (int i = 0; i < 4; i++) {
			v[depth] = i;
			dfs(depth + 1, v);
		}
	}

}

int main() {
	cin >> N >> A >> B >> C;
	for (int i = 0; i < N; i++)cin >> l[i];
	vector<int> v(8,0);
	dfs(0, v);
	cout << mpmin << endl;

	return 0;
}

Measured memory_bytes: 256
function isLower(c)
	return string.lower(c) == c
end
function solve(s)
	if string.sub(s, 1, 1) ~= "A" then
		return false
	end
	if not isLower(string.sub(s, 2, 2)) or not isLower(string.sub(s, #s, #s)) then
		return false
	end
	local num = 0
	for i = 3, #s - 1 do
		local c = string.sub(s, i, i)
		if not isLower(c) then
			if num == 0 and c == "C" then
				num = 1
			else
				return false
			end
		end
	end
	if num == 0 then
		return false
	end
	return true
end
local s = io.read()
if solve(s) then
	print("AC")
else
	print("WA")
end

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N, ans=0;
	int X[200005];
	vector<int> v;

	cin >> N;
	rep(i,N){
		cin >> X[i];
		v.push_back( X[i] );
	}

	sort( all(v) );

	rep(i,N){
		if( X[i] <= v[N/2-1] ) cout << v[N/2] << endl;
		else cout << v[N/2-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] s = new int[n + 1];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int[] t = new int[q + 1];
		for (int i = 0; i < q; i++) {
			t[i] = sc.nextInt();
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < q; i++) {
			s[n] = t[i];
			int j = 0;
			while (s[j] != t[i]) {
				j++;
			}
			if (j != n) ans++;
		}
		System.out.println(ans);
	}
}

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

using namespace std;
typedef long long ll;

#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define out(ans) cout << ans << endl
#define in(n) cin >> n

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll n;
    in(n);
    map<string, vector<ll>> m;
    map<ll, ll> id;
    floop(i, n)
    {
        string s;
        long p;
        in(s);
        in(p);
        m[s].push_back(p);
        id[p] = i + 1;
    }
    for (auto it : m)
    {
        auto v = it.second;
        sort(v.begin(), v.end(), greater<int>());
        for (auto i : v)
        {
            out(id[i]);
        }
    }
}

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

int main()
{
  i64 n;
  cin >> n;
  vector<string> s(n);
  for (i64 i = 0; i < n; i++)
    cin >> s[i];
  i64 ans = 0, ea = 0, sb = 0, ba = 0;
  for (i64 i = 0; i < n; i++)
  {
    if (s[i][s[i].size() - 1] == 'A' && s[i][0] == 'B')
      ba++;
    else if (s[i][s[i].size() - 1] == 'A')
      ea++;
    else if (s[i][0] == 'B')
      sb++;
    for (i64 j = 0; j < s[i].size() - 1; j++)
      if (s[i].substr(j, 2) == "AB")
        ans++;
  }
  cout << ans + ba + (0 < ea + sb || ba == 0  ? min(ea, sb) : -1) << endl;
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int n, m;

	cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;

	return 0;
}


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

int a[5];

bool input() {
  cin >> a[0];
  if (!a[0]) {
    return false;
  }
  for (int i = 1; i < 5; ++i) {
    cin >> a[i];
  }
  return true;
}

void print_aiko() {
  for (int i = 0; i < 5; ++i) {
    cout << 3 << endl;
  }
}

void print_win_lose(int d) {
  for (int i = 0; i < 5; ++i) {
    if (a[i] == (d + 1) % 3 + 1) {
      cout << 1 << endl;
    } else {
      cout << 2 << endl;
    }
  }
}

void solve() {
  int c[3] = {0};
  for (int i = 0; i < 5; ++i) {
    ++c[a[i] - 1];
  }
  int b = 0;
  for (int i = 0; i < 3; ++i) {
    if (c[i]) {
      ++b;
    }
  }
  if (b == 1 || b == 3) {
    print_aiko();
    return;
  }
  int d = -1;
  for (int i = 0; i < 3; ++i) {
    if (!c[i]) {
      d = i;
      break;
    }
  }
  print_win_lose(d);
}

int main() {
  while (input()) {
    solve();
  }
}

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

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

  int ans = 1e9;

  for (int i = 0; i < S.size() - 2; i++) {
    ans = min(ans, abs(753 - stoi(S.substr(i, 3))));
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import copy

n = int(input())
am = list(map(int, input().split()))

pcnt = 0
mcnt = 0

f = 0  #前の項の符号（1:+、2:-）
wa = 0

#最初の数字を正とするとき
a = copy.copy(am)
f = 2

for i in range(n):
    wa += a[i]

    if f == 1:#-にする必要あり
        if wa > -1:
            pcnt += wa + 1
            wa = -1
        
        f = 2

    elif f == 2:  #+にする必要あり

        if wa < 1:
            pcnt += -wa + 1
            wa = 1

        f = 1

#最初の数字を負とするとき
a = copy.copy(am)
wa = 0
f = 1

for i in range(n):
    wa += a[i]

    if f == 1:  # -にする必要あり
        if wa > -1:
            mcnt += wa + 1
            wa = -1

        f = 2

    elif f == 2:  # +にする必要あり

        if wa < 1:
            mcnt += -wa + 1
            wa = 1

        f = 1

print(min(pcnt, mcnt))


Measured memory_bytes: 20508
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s: String = read(&mut stdin_lock, &mut buf, b'\n');
    let cs: Vec<char> = s.chars().collect();

    let mut ans = 0;
    for i in 0..cs.len() / 2 {
        if cs[i] != cs[cs.len() - i - 1] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n, res;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, counter = 0;
        cin >> a;
        while (a % 2 == 0) {
            counter++;
            a /= 2;
        }
        if (i > 0) res = min(res, counter);
        else res = counter;
    }
    cout << res << endl;
}


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

int n,m,s,d[505],sum;
int v[505],a[505],nxt[505],head[505];
long long dis[55][500005],ans[55],b[505],c[505];
bool vis[55][500005];

void spfa()
{
	queue<pair<int,int> > q;
	q.push(make_pair(1,s));
	while(!q.empty())
	{
		int u=q.front().first,x=q.front().second;
		q.pop(),vis[u][x]=0;
//		cout<<u<<' '<<x<<' '<<dis[u][x]<<endl;
		ans[u]=min(ans[u],dis[u][x]);
		for(int i=x+d[u],j=1;i<sum+d[u];i+=d[u],j++)
		{
			if(i>sum) i=sum;
			if(dis[u][i]>dis[u][x]+c[u]*j)
			{
				dis[u][i]=dis[u][x]+c[u]*j;
				if(!vis[u][i])
				{
					vis[u][i]=1,q.push(make_pair(u,i));
				}
			}
			else break;
			if(i==sum) break;
		}
		for(int i=head[u];i>0;i=nxt[i])
		{
			if(x<a[i]) continue;
			if(dis[v[i]][x-a[i]]>dis[u][x]+b[i])
			{
//				cout<<' '<<v[i]<<' '<<x-a[i]<<' '<<dis[u][x]+b[i]<<' '<<b[i]<<endl;
				dis[v[i]][x-a[i]]=dis[u][x]+b[i];
				if(!vis[v[i]][x-a[i]])
				{
					vis[v[i]][x-a[i]]=1;
					q.push(make_pair(v[i],x-a[i]));
				}
			}
		}
	}
}

int main()
{
	memset(ans,0x3f,sizeof(ans));
	scanf("%d%d%d",&n,&m,&s);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&v[i],&v[i+m]);
		nxt[i]=head[v[i+m]],head[v[i+m]]=i;
		nxt[i+m]=head[v[i]],head[v[i]]=i+m;
		scanf("%d%d",&a[i],&b[i]);
		a[i+m]=a[i],b[i+m]=b[i];
		sum+=a[i];
	}
	sum=sum*2,s=min(s,sum);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&d[i],&c[i]);
		d[i]=min(d[i],sum);
	}
	memset(dis,0x3f,sizeof(dis));
	dis[1][s]=0,vis[1][s]=1,spfa();
	for(int i=2;i<=n;i++) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 220436
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;


const int Max = 7368791+10;
int v[Max];

int main(){
	int n, m;
	while(scanf("%d %d", &m, &n) != EOF) {
		if(n == 0 && m == 0) break;
		// set<int> st;
		// REP(i, m , Max) st.insert(i);
		// rep(i, n) {
		// 	int t = *st.begin();
		// 	for(int j = t; j < Max; j += t) {
		// 		if(st.count(j)) st.erase(j);
		// 	}
		// }
		// cout << *st.begin() << endl;
		rep(i, Max) v[i] = 0;
		int cnt = 0;
		REP(i, m, Max) {
			if(v[i]) continue;
			if(cnt == n) {
				printf("%d\n", i);
				break;
			}
			cnt++;
			for(int j = i; j < Max; j += i) v[j] = 1;
		}
	}	
}

Measured memory_bytes: 31876