akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n,m;
  cin >> n >> m;
  bool g[n][n] = {};
  for(int i = 0; i < m; i++){
    int a,b;
    cin >> a >> b;
    a--;b--;
    g[a][b] = g[b][a] = true;
  }
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    p[i] = i;
  }
  int ans = 0;
  do{
    if(p[0] != 0) break;
    bool ok = true;
    for(int i = 0; i < n-1; i++){
      int from = p[i];
      int to = p[i+1];
      if(!g[from][to]) ok =false;
    }
    if(ok) ans++;
  }while(next_permutation(p.begin(), p.end()));
  cout << ans << endl;
  return 0;
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	ll N, M, X;
	cin >> N >> M >> X;
	vector<ll> C(N);
	vector<vector<ll>> A(N, vector<ll>(M));
	for (ll i = 0; i < N; ++i)
	{
		cin >> C[i];
		for (ll j = 0; j < M; ++j)
		{
			cin >> A[i][j];
		}
	}

	ll m = LONG_LONG_MAX;
	for (ll i = 0; i < (1 << N); ++i)
	{
		vector<ll> a(M, 0);
		ll c = 0;
		for (ll j = 0; j < N; ++j)
		{
			if ((i >> j) & 1)
			{
				c += C[j];
				for (ll k = 0; k < M; ++k)
				{
					a[k] += A[j][k];
				}
			}
		}
		bool ok = true;
		for (ll j = 0; j < M; ++j)
		{
			if (a[j] < X)
			{
				ok = false;
				break;
			}
		}
		if (ok)
		{
			m = min(m, c);
		}
	}
	if (m == LONG_LONG_MAX)
	{
		m = -1;
	}
	cout << m << endl;

	return 0;
}


Measured memory_bytes: 3516
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int factrial(int n){
    if(n==0){
        return 1;
    }else{
        return n*factrial(n-1);
    }
}

int main(void){
    string s,t;
    int a,b;
    cin >> s >> t >> a >> b;
    string u;
    cin >> u;

    if(u==s){
        a--;
    }
    if(u==t){
        b--;
    }
    cout << a << " " << b << 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);
	    int a = sc.nextInt();
	    int b = sc.nextInt();
	    if(a - b*2 <= 0) {
	        System.out.println(0);
	    }else {
	        System.out.println(a - b*2 );
	    }
	}
	
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  Int amari = 1000000007;
  Int n;cin >> n;
  Int ans = 1;
  for(int i=1;i<=n;i++){
    i%=amari;
    ans=(ans*i)%amari;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>

using u4t = std::uint32_t;
using i4t = std::int32_t;

int main() {
  i4t N, M;
  std::cin >> N >> M;

  std::vector<i4t> a;
  std::vector<i4t> b;
  std::vector<i4t> c, d;
  for (i4t i = 0; i<N; i++) {
    i4t aa, bb;
    std::cin >> aa >> bb;
    a.push_back(aa);
    b.push_back(bb);
  }
  for (i4t j = 0; j<M; j++) {
    i4t aa, bb;
    std::cin >> aa >> bb;
    c.push_back(aa);
    d.push_back(bb);
  }

  for (i4t i = 0; i<N; i++) {
    u4t mind = UINT32_MAX;
    i4t jmin = -1;
    for (i4t j = 0; j<M; j++) {
      u4t const dist = std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]);
      if (dist < mind) { jmin = j; mind = dist;}
    }
    std::cout << jmin + 1 << std::endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, M;
    cin >> N >> M;
    set<int> s1, s2;
    rep(i, M){
        int a, b;
        cin >> a >> b;
        if(a == 1) s1.insert(b);
        if(b == 1) s1.insert(a);
        if(a == N) s2.insert(b);
        if(b == N) s2.insert(a);
    }
    int ans = false;
    for(auto &e: s1){
        if(s2.count(e)) ans = true;
    }
    if(ans) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 9600
#!/usr/bin/env python
import numpy as np
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(min(K,X)):
    for j in range(min((K//(i+1),Y))):
        for k in range(min(((K//(i+1)+1)//(j+1)),Z)):
            D.append(A[i]+B[j]+C[k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))

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

template <class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template <class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}
struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};

signed main(){
    Init_On start;
    int k , a , b;
    cin >> k >> a >> b; 
    for( int i = a ; i <= b ; ++i ){
        if(i % k == 0) { cout << "OK" << endl; return 0; }
    }
    cout << "NG" << endl;

}

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

int dfs(char tebl[][20],int y,int x,int h,int w,int ans){
	tebl[y][x]='$';
	if(y>0&&tebl[y-1][x]=='.'){//up
		ans=max(ans,dfs(tebl,y-1,x,h,w,ans+1));
	}
	if(y<h&&tebl[y+1][x]=='.'){//down
		ans=max(ans,dfs(tebl,y+1,x,h,w,ans+1));
	}
	if(x>0&&tebl[y][x-1]=='.'){//left
		ans=max(ans,dfs(tebl,y,x-1,h,w,ans+1));
	}
	if(x<w&&tebl[y][x+1]=='.'){//right
		ans=max(ans,dfs(tebl,y,x+1,h,w,ans+1));
	}
	return ans;
}
	




int main(){
	while(true){
		char tebl[20][20]={};
		int w,h,sy,sx;
		cin>>w>>h;
		if(w==0||h==0){
			break;
		}
		for(int n=0;n<h;n++){
			for(int m=0;m<w;m++){
				cin>>tebl[n][m];
				if(tebl[n][m]=='@'){
					sy=n;
					sx=m;
				}
			}
		}
		cout<<dfs(tebl,sy,sx,h-1,w-1,1)<<endl;
	}
}


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

int main() {
	int K, A, B;
	cin >> K >> A >> B;
	for (int i = 1; K*i <= B ; i++)
		if (A <= K*i){
			cout << "OK" << endl;
			return 0;
		}
	cout << "NG" << endl;
	return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int num;
    cin >> num;
    int a = num / 100, b = num % 100;
    if(a && b)
    {
        if(a > 12 && b > 12)
        {
            cout << "NA" << endl;
        }
        else if(a > 12 && b <= 12 && b)
        {
            cout << "YYMM" <<endl;
        }
        else if(a <= 12 && b > 12 && a)
        {
            cout << "MMYY" << endl;
        }
        else if(a <= 12 && b <= 12)
        {
                cout << "AMBIGUOUS" << endl;           
        }
    }
    
    else
    {
        if(a)
        {
            if(a > 12)
            {
                cout << "NA" << endl;
            }
            else if(a <= 12)
            {
                cout << "MMYY" << endl;
            }
        }
        if(b)
        {
            if(b > 12)
            {
                cout << "NA" << endl;
            }
            if(b <= 12)
            {
                cout << "YYMM" << endl;
            }
        }
        if(!a && !b)
        {
            cout << "NA" << endl;
        }
    }
    
    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define pb(i) push_back(i)
#define INF 100100100
#define EPS 1e-9
#define itn int
typedef long long ll;
typedef vector<int> vi;
typedef map<string, int> msi;
const int dx[] = {0, 1, 0, -1, -1, 1, 1, -1};  //座標移動用
const int dy[] = {1, 0, -1, 0, -1, 1, -1, -1};

template<typename T, typename U>
T gcd(T a, T b) {return (b ? gcd(b, a%b) : a);}

template<typename T, typename U>
T lcm(T a, T b) {return (a * b / gcd(a, b));}

int in() {int x; cin >> x; return x;}

int main()
{
    int a, b;

    cin >> a >> b;

    cout << a - b + 1 << endl;
    return (0);
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  int sw = 0;
  REP(i, N) {
    int minj = i;
    for(int j = i; j < N; j++) {
      if(A[minj] > A[j]) {
        minj = j;
      }
    }
    swap(A[i], A[minj]);
    if(i != minj)
      sw++;
  }
  REP(i, N) {
    cout << A[i];
    if(i < N - 1)
      cout << " ";
  }
  cout << endl << sw << endl;
  return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  while(1) {
    int n, x[100];
    cin >> n;
    if(n==0) break;

    vector<int> a,b;
    for(int i=0; i<n; i++) cin >> x[i];
    sort(x, x+n);
    int k=0;
    for(int i=1; i<=n*2; i++) {
      if(x[k]==i) {
	a.push_back(i);
	k++;
      } else {
	b.push_back(i);
      }
    }

    int turn=0,check=0;
    int z;
    vector<int>::iterator it;
    while(a.size()>0 && b.size()>0) {
      if(turn==0) {
	if(check==0) {
	  z=*a.begin();
	  a.erase(a.begin());
	  check++;
	} else {
	  it=upper_bound(a.begin(), a.end(), z);
	  if(it==a.end()) check=0;
	  else {
	    z=*it;
	    a.erase(it);
	    check++;
	  }
	}
	turn++;
      } else {
	if(check==0) {
	  z=*b.begin();
	  b.erase(b.begin());
	  check++;
	} else {
	  it=upper_bound(b.begin(), b.end(), z);
	  if(it==b.end()) check=0;
	  else {
	    z=*it;
	    b.erase(it);
	    check++;
	  }
	}
	turn--;
      }
    }
    cout << b.size() << endl << a.size() << endl;
  }
  return 0;
}


Measured memory_bytes: 1220
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

vector<long> uses = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
unordered_map<long, long> nums;
unordered_map<long, string> memo;
unordered_map<long, bool> memo_exist;

bool string_lt(string a, string b) {
  if (a == "none") return true;
  if (a.size() != b.size()) return a.size() < b.size();
  return a < b;
}

string foo(long rest) {
  if (memo_exist[rest]) return memo[rest];
  if (rest == 0) {
    string ret = "";
    memo_exist[rest] = true;
    memo[rest] = ret;
    return ret;
  } else {
    string ret = "none";
    for (auto it: nums) {
      if (rest - it.first < 0) continue;
      string after = foo(rest - it.first);
      if (after == "none") continue;
      string tmp = to_string(it.second) + after;
      if (string_lt(ret, tmp)) ret = tmp;
    }
    memo_exist[rest] = true;
    memo[rest] = ret;
    return ret;
  }
}

void solve() {
  long N, M;
  cin >> N >> M;
  rep (i, M) {
    long A;
    cin >> A;
    if (nums[uses[A]] < A) nums[uses[A]] = A;
  }
  cout << foo(N) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll k;
	bool b=true;
	string s;
	cin >> s >> k;
	rep(i,SIZE(s)-1){
		if(s[i]!=s[i+1]) b=false;
	}
	if(b) cout << SIZE(s)*k/2 << endl;
	else{
		ll cnt=0,ans=0;
		rep(i,SIZE(s)){
			cnt++;
			if(s[i]!=s[i+1] || i==SIZE(s)-1){
				ans+=cnt/2;
				cnt=0;
			}
		}
		if(s[0]!=s[SIZE(s)-1]) cout << ans*k << endl;
		else{
			ll head=1,tail=1;
			while(s[head-1]==s[head]) head++;
			while(s[SIZE(s)-tail]==s[SIZE(s)-1-tail]) tail++;
			cout << ans*k-(head/2+tail/2-(head+tail)/2)*(k-1) << endl;
		}
	}
	return 0;
}


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

using namespace std;


struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x) return x<a.x;
        return y<a.y;
    }
};


long long x,y,z,mod=998244353;
vector<int> v;
int i,n,m,k,a,d,b,c;
int e;
int o[111111];
int l[1];
int j[1];

queue<int> q;
P u[1];

//char r[1];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

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


bool as(P a,P b)
{
    return a.x<b.x;
}

int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
        scanf("%d",&o[t]);
    sort(o+1,o+a+1);
    if(o[1]==o[a]&&o[1]==0)
    {
        puts("Yes");
        return 0;
    }
    if(a%3)
    {
        puts("No");
        return 0;
    }
    for(int t=1;t<=a/3;t++)
        if(o[t]!=o[1]||o[a/3+1]!=o[t+a/3]||o[a/3*2+1]!=o[a/3*2+t])
    {
        puts("No");
        return 0;
    }
    if((o[1]^o[a/3+1])==o[a/3*2+1]) puts("Yes");
    else puts("No");
}



Measured memory_bytes: 640
n,q = (int(i) for i in input().split())
v,k,ans = [1]*(n+1),[[] for i in range(n+1)],[0]*(n+1)
v[1],y = 0,[1]
for i in range(n-1):
    a,b = (int(i) for i in input().split())
    k[a].append(b)
    k[b].append(a)
for i in range(q):
    p,x = (int(i) for i in input().split())
    ans[p]+=x
v[1] = 0
while y:
    p = y.pop()
    v[p] = 0
    for i in k[p]:
        if v[i]:
            ans[i]+=ans[p]
            y.append(i)
print(" ".join(map(str,ans[1:])))

Measured memory_bytes: 66952
S=input()
sigma=0
li2=[1]*(len(S)+1)
li10=[1]*(len(S))
for k in range(1, len(S)):
    li2[k+1]=int(li2[k])*2
for k in range(len(S)-1):
    li10[k+1]=int(li10[k])*10
for k in range(1,len(S)+1):
    for j in range(1,k+1):
        sigma+=int(S[-k])*(li10[j-1])*(li2[len(S)-k+1])*(li2[k-j])
print(sigma)

Measured memory_bytes: 3064
func readTwoInts(separator: String.Element = " ") -> (a: Int, b: Int) {
    let ints = readLine()!.split(separator: separator).map { Int($0)! }
    return (a: ints[0], b: ints[1])
}

func mainA() {
    let (A, B) = readTwoInts()

    if B == 1 {
        print(0)
        return
    }

    var count = 0
    while true {
        count += 1
        if count * (A - 1) + 1 >= B {
            print(count)
            return
        }
    }
}

mainA()

Measured memory_bytes: 8240
/*
 * @Author: Kaizyn
 * @Date: 2020-05-23 20:18:02
 * @LastEditTime: 2020-05-23 20:33:20
 */ 
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 5e2+7;

int n;
int p[N*N], dp[N*N], a[N*N];
queue<int> q;

inline int mp(const int &x, const int &y) {
  return (x-1)*n+y;
}

inline void push(const int &x, const int &v) {
  if (v < dp[x]) {
    dp[x] = v;
    q.push(x);
  }
}

inline void bfs() {
  while (q.size()) {
    int u = q.front();
    q.pop();
    if (u%n != 1) push(u-1, dp[u]+a[u]);
    if (u%n != 0) push(u+1, dp[u]+a[u]);
    if (u-n > 0) push(u-n, dp[u]+a[u]);
    if (u+n <= n*n) push(u+n, dp[u]+a[u]);
  }
}

inline void solve() {
  cin >> n;
  memset(dp, 0x3f, sizeof dp);
  for (int i = 1; i <= n*n; ++i) a[i] = 1;
  for (int i = 1; i <= n; ++i) {
    push(mp(1, i), 0);
    push(mp(n, i), 0);
    push(mp(i, 1), 0);
    push(mp(i, n), 0);
  }
  bfs();
  int res = 0;
  for (int i = 1; i <= n*n; ++i) {
    cin >> p[i];
    res += dp[p[i]];
    a[p[i]] = 0;
    q.push(p[i]);
    // push(p[i], --dp[p[i]]);
    bfs();
  }
  cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 6588
#include <bits/stdc++.h>
using namespace std;
int root(int *uf, int *ufc,int k){
    if(uf[k]==k){
        return k;
    }else{
        ufc[uf[k]] += ufc[k];
        ufc[k]=0;
        uf[k]=root(uf,ufc, uf[k]);
        return uf[k];
    }
}
int main(){
    int n,m;
    cin >> n >> m;
    
    int uf[n];
    int ufc[n];
    int i;
    for(i=0;i<n;i++){
        uf[i]=i;
        ufc[i]=1;
    }
    int a,b;
    for(i=0;i<m;i++){
        cin >> a >>b ;
        int ar=root(uf,ufc, a-1);
        int br=root(uf,ufc, b-1);
        if(ar!=br){
            uf[ar]=br;
            ufc[br]+=ufc[ar];
            ufc[ar]=0;
        }
    }
    int count=0;
    for(i=0;i<n;i++){
        if(ufc[i]>count)count=ufc[i];
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 5160
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String args[]) { 

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();

        int count = 0;
        int[] arr1 = new int[N];
        int[] arr2 = new int[M];
        int k=2;
        for(int i=0; i<N; i++){
            arr1[i] = k;
            k = k + 2;
        }
        int j = 1;
        for(int i=0; i<M; i++){
            arr2[i] = j;
            j = j + 2;
        }

        for(int i=0; i<(arr1.length); i++){
            for(int p=(i+1); p<(arr1.length); p++) {
                if(((arr1[i] + arr1[p]) & 1) == 0)
                count++;
            }
        }

        for(int i=0; i<(arr2.length); i++){
            for(int p=(i+1); p<(arr2.length); p++) {
                if(((arr2[i] + arr2[p]) & 1) == 0)
                count++;
            } 
        }
        System.out.println(count);
        

        sc.close();
    }
}
    

Measured memory_bytes: 21844
#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define INIT(a) memset(a,0,sizeof(a))
#define fs first
#define sc second
using namespace std;
typedef pair<int,int> P;
const int INF = 1e9+7;

int v;
P seg[303000];

inline void init(int n){
  v = 1;
  while(v<n)v<<=1;
  rep(i,2*v-1)seg[i] = P(INF,INF);
}

inline void update(int x, P a){
  x += v-1;
  seg[x] = a;
  while(x){
    x = (x-1)>>1;
    seg[x] = min(seg[2*x+1],seg[2*x+2]);
  }
}

inline P query(int a, int b, int k ,int l, int r){
  if(b<=l || r<=a)return P(INF,INF);
  if(a<=l && r<=b)return seg[k];
  P ql = query(a,b,2*k+1,l,(l+r)/2);
  P qr = query(a,b,2*k+2,(l+r)/2,r);
  return min(ql,qr);
}

int n,r,l;
int d,t,x,prv=0;
int len[100100];

int main(){
  INIT(len);
  scanf("%d%d%d",&n,&r,&l);
  init(n);
  rep(i,n)update(i,P(0,i));

  rep(i,r){
    scanf("%d%d%d",&d,&t,&x);
    P tmp = query(0,n,0,0,v);
    len[tmp.sc] += t-prv;
    prv = t;
    update(d-1,P(seg[d-1 +v-1].fs-x,d-1));
  }
  len[query(0,n,0,0,v).sc] += l-prv;

  int ans = 0;
  rep(i,n){
    if(len[ans] < len[i])ans = i;
  }
  printf("%d\n",ans+1);
}

Measured memory_bytes: 3956
n = int(input())
h = list(map(int, input().split()))

ans = 0
while max(h) != 0:
  if h[0] > 0: flag = True
  else: flag = False
    
  if flag:
    for i in range(n):
      if h[i] == 0: break
      h[i] -= 1
    ans += 1
  else:
    for i in range(1,n):
      if flag == False and h[i] == 0: continue
      if flag == True and h[i] == 0: break
      flag = True
      h[i] -= 1
    ans += 1
      
print(ans)      

Measured memory_bytes: 9068
import sys
input = lambda: sys.stdin.readline().rstrip()

S = input()

ch_list = ["A", "C", "G", "T"]

ans = 0
tmp = 0
for ch in S:
    if ch in ch_list:
        tmp += 1
        ans = max(ans, tmp)
    else:
        tmp = 0 

print(ans)

Measured memory_bytes: 38256
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

//#if __cplusplus >= 201103
typedef long long ll;
//#endif
typedef pair<int, int> P;
typedef pair<int, P> IP;

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

const int INF = 100000000;
//#if __cplusplus >= 201103
const ll LINF = 10000000000000000ll;
//#endif
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
// }}}

int N, Z, W;
int a[2000];
map<pair<P, P>, int> m;

void init()
{
}

int rec(int n, int turn, int x, int y)
{
    if(n == 0) return abs(x - y);
    if(m.find(mp(mp(n, turn), mp(x, y))) != end(m)) return m[mp(mp(n, turn), mp(x, y))];

    int ret;
    if(turn == 1){
        ret = 0;
        FOR(i, 1, n+1){
            ret = max(ret, rec(n-i, -turn, a[N-n-1+i], y));
        }
    }else{
        ret = INF;
        FOR(i, 1, n+1){
            ret = min(ret, rec(n-i, -turn, x, a[N-n-1+i]));
        }
    }
    m.insert(mp(mp(mp(n, turn), mp(x, y)), ret));
    return ret;
}

void solve()
{
    //int x = Z, y = W;
    //cout << rec(N, 1, x, y) << endl;
    if(N == 1){
        cout << abs(W - a[0]) << endl;
    }else{
        cout << max(abs(W - a[N-1]), abs(a[N-1] - a[N-2])) << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> Z >> W;
    REP(i, N) cin >> a[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

int main() {
    int N, S;
    ll mod = 998244353;
    cin >> N >> S;
    vector<vector<ll>> dp(N, vector<ll>(S+1, 0));
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    // first
    if(a[0]<=S) dp[0][a[0]] += 1;
    ll total = dp[0][S];
    for(int i=1;i<N;i++){
        if(a[i]<=S) dp[i][a[i]] += i + 1;
        for(int j=1;j<S+1;j++){
            // dp[i][j] += dp[i-1][j];
            dp[i][j] += dp[i-1][j];
            dp[i][j] %= mod;
            if(dp[i-1][j] != 0 && j+a[i]<=S){
                dp[i][j+a[i]] += dp[i-1][j];
                dp[i][j+a[i]] %= mod;
            }
        }
        total += dp[i][S];
        total %= mod;
    }
    cout << total%mod << endl;
    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int W,a,b;
    cin >> W >> a >> b;
    if(min(a,b) + W >= max(a,b)) cout << 0 << endl;
    else cout << max(a,b) - min(a,b) - W << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

int main(){
    char a, b;
    int h, w, s, t;
    cin >> h >> w >> a >> b;
    s = a - 'A', t = b - 'A';

    char mat[h][w];
    for(int i = 0; i < h*w; i++)    cin >> mat[i/w][i%w];

    vector<int> v[26];
    for(int i = 1; i < h-1; i++){
        for(int j = 1; j < w-1; j++){
            if(!inRange(mat[i][j], 'A', 'Z'))   continue;
            int from = mat[i][j]-'A';
            if(i+2 < h && mat[i+2][j] == '|'){
                int ni = i+2;
                while(mat[ni][j]=='|')  ni++;
                ni++;
                int to = mat[ni][j]-'A';
                v[from].push_back(to);
                v[to].push_back(from);
            }
            if(j+2 < w && mat[i][j+2] == '-'){
                int nj = j+2;
                while(mat[i][nj]=='-')  nj++;
                nj++;
                int to = mat[i][nj]-'A';
                v[from].push_back(to);
                v[to].push_back(from);
            }
        }
    }
    const int INF = 1<<29;
    vector<int> dp(26, INF);
    queue<int> q;
    q.push(s);
    dp[s] = 0;
    while(!q.empty()){
        int x = q.front();  q.pop();
        for(int next : v[x]){
            if(dp[next] == INF){
                dp[next] = dp[x]+1;
                q.push(next);
            }
        }
    }
    cout << dp[t] << endl;
    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int ,int> P;
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
int main(){
ll n;
cin>>n;
ll ans=1;
for(int i=2;i<=n;i++) ans=ans*i%(1000000000+7);
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int sumE[300005];

signed main()
{
    int N; cin>>N;
    string s; cin>>s;

    REP(i,N){
        if(s[i]=='E') sumE[i+1]++;
        sumE[i+1]+=sumE[i];
    }

    int ans=1e9;
    REP(i,N){
        int cnt=(i-sumE[i])+(sumE[N]-sumE[i+1]);
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
 
}


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

using namespace std;

int main() {
  #ifdef _OFFLINE_
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  vector<int> arr;
  scanf("%d", &n);
  arr.resize(n + 1);
  for(int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
  }

  sort(arr.begin() + 1, arr.end());
  long long x = -1, y = -1;
  for(int i = n - 1; i >= 1; --i) {
    if(arr[i] == arr[i + 1]) {
      y = x;
      x = arr[i];
      arr[i] = arr[i + 1] = -1;
      if(y != -1) {
        cout << x * y;
        return 0;
      }
    }
  }

  printf("0");
}

Measured memory_bytes: 640
## https://atcoder.jp/contests/abc125/tasks/abc125_d

N = int(input())
N_List = list(map(int,input().split()))

dp = [[0] * 2 for i in range(N)]

dp[1][False] = N_List[0] + N_List[1]
dp[1][True] = (N_List[0] + N_List[1])*(-1)

for i in range(2,N):
    dp[i][False] = max(dp[i-1][True] + N_List[i],dp[i-1][False] + N_List[i])
    dp[i][True] = max(dp[i-1][True] + N_List[i-1]*2 + N_List[i]*(-1) ,
                      dp[i-1][False] + N_List[i-1]*(-2) + N_List[i]*(-1))

print(max(dp[N-1]))

Measured memory_bytes: 29472
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
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); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()

void Main()
{
    int n;
    cin >> n;
    int x = 800 * n;
    int y = (int)(n / 15) * 200;
    cout << x - y << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#include<bits/stdc++.h>
#define maxn 400010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define IL inline
#define ss system
using namespace std;

int a[maxn],n;
template <class T> void read(T &x){
	char ch=x=0;
	bool fl=false;
	while(!isdigit(ch))
		fl|=ch=='-',ch=getchar();
	while(isdigit(ch))
		x=x*10+ch-'0',ch=getchar();
	x=fl?-x:x;
}
int main(){
	read(n);
	int ans=0;
	for(int i=1;i<=n;i++)
		read(a[i]),ans=__gcd(ans,a[i]);
	sort(a+1,a+n+1);
	if(a[1]==a[n])
		printf("%d\n",a[1]);
	else
		printf("%d\n",ans);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

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


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

    ll n;
    cin >> n;

    ll ans = (n + 10) / 11 * 2;
    if(n % 11 <= 6 && n % 11 != 0){
        ans--;
    }

    cout << ans << endl;


    return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

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

  ll n;

  cin >> n;

  cout << "ABC" << n << "\n";
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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 (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  vi l(n);
  REP(i,n)cin >> l[i];
  int ans=0;
  REP(i,n)FOR(j,i+1,n)FOR(k,j+1,n){
    if(l[i]==l[j] || l[j] == l[k] || l[i] == l[k])continue;

    if(l[i] < l[j]+l[k] && l[j] < l[i]+l[k] && l[k] < l[i]+l[j]){
      ans++;
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
//#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int A,B,C;
	int K;
	cin>>A>>B>>C;
	cin>>K;
	int ans=0;
	int temp=max({A,B,C});
	ans+=A+B+C;
	for(int i=0;i<K;i++)
		temp*=2;
	ans+=temp;
	ans-=max({A,B,C});
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#coding: UTF-8

import sys
import math

class Algo:
  @staticmethod
  def insertionSort(r, n):
    count = 0
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if r[j] < r[minj]:
          minj = j
      if r[i] != r[minj]:
        r[i], r[minj] = r[minj], r[i]
        count += 1
    
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="")
    print(count)

N = int(input())
R= list(map(int, input().split()))
Algo.insertionSort(R, N)

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop(i,a,b) for(int i=a;i<(b);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

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

  int A[N];
  bool is_zero = true;
  rep(i, N) {
    in(A[i]);
    if (A[i] != 0)
      is_zero = false;
  }
  if (is_zero)
    out("Yes");
  else if (N % 3 != 0)
    out("No");
  else {
    sort(A, A+N);
    rep(k, 3) {
      rep(i, N/3) {
        if (A[N/3*k] != A[N/3*k+i]) {
          out("No");
          return 0;
        }
      }
    }
    int x = A[0], y = A[N/3], z = A[N/3*2];
    if ((x ^ y ^ z) == 0)
      out("Yes");
    else
      out("No");
  }

  return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc103_d
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            int n = input[0];
            int m = input[1];
            int[][] arr = new int[m][];

            for(int i=0; i<m; i++){
                int[] tmp = ReadLine().Split().Select(int.Parse).ToArray();
                arr[i] = new int[2];
                arr[i][0] = tmp[0];
                arr[i][1] = tmp[1];
            }

            Array.Sort(arr, (a,b) => a[1]-b[1]);

            int index=0;
            int cnt=0;
            for(int i=0; i<m; i++){
                if(index<arr[i][0]){
                    index = arr[i][1]-1;
                    cnt++;
                }
                //WriteLine($"index:{index} a: {arr[i][0]} b: {arr[i][1]}");
            }
            WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 23868
#include <stdio.h>
#define INF 1000000
#define MAX 100
#define W 0
#define G 1
#define B 2

int n,M[MAX][MAX];
void dik(void);

int main(){
  int i,j,k,c,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  dik();
  return 0;
}

void dik(){
  int minv,i,u,v;
  int d[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=W;
  }
  d[0]=0;
  color[0]=G;
  while(1){
    minv=INF;
    u=-1;
    for(i=0;i<n;i++){
      if((minv>d[i])&&(color[i]!=B)){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1){
      break;
    }
    color[u]=B;
    for(v=0;v<n;v++){
      if((color[v]!=B)&&(M[u][v]!=INF)){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=G;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INF){
      printf("-1\n");
    }
    else{
      printf("%d\n",d[i]);
    }
  }
}
/*
  #include <stdio.h>
  #define MAX 100
  #define INF 10000000
  #define W 0
  #define G 1
  #define B 2
  W,G,Bはcolor[v]を用いてvの訪問状態を表す
  int prim(void);

  int n,M[MAX][MAX];
  M[u][v]はuからvへの辺の重みを記録する
  int main(){
  int i,j,e;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  for(j=0;j<n;j++){
  scanf("%d",&e);
  if(e==-1){
  M[i][j]=INF;
  }
  else{
  M[i][j]=e;
  }
  }
  }

  printf("%d\n",prim());
  
  return 0;
  }

  int prim(){
  int u,minv,i,v,sum;
  int color[MAX],d[MAX],p[MAX];
  color[v]はW,G,Bを用いてvの訪問状態を表す
  d[v]は頂点をつなぐ辺の中で、重みが最小の辺の重みを記録する
  p[v]は頂点vの親を記録する
  
  初期化
  for(i=0;i<n;i++){
  d[i]=INF;
  p[i]=-1;
  color[i]=W;
  }
  d[0]=0;
  while(1){
  minv=INF;
  u=-1;
  for(i=0;i<n;i++){
  if((minv>d[i])&&(color[i]!=B)){
  u=i;
  minv=d[i];
  }
  }
  if(u==-1){
  break;
  }
  u=0の時はBに
  color[u]=B;
  for(v=0;v<n;v++){
  v=0の時はcolor[0]=Bで次のifは飛されるがforるーぷは回り、v=1の時、color[0]!=Bでifの条件に合い、d[v]>M[u][v]は辺の重みとINFで比べるので 
  d[v]=M[u][v];
  p[v]=u;
  color[v]=G;
  が実行される
  if((color[v]!=B)&&(M[u][v]!=INF)){ 
  if(d[v]>M[u][v]){
  d[v]=M[u][v];
  p[v]=u;
  color[v]=G;
  }
  }
  }
  }
  sum=0;
  for(i=0;i<n;i++){
  if(p[i]!=-1){
  sum+=M[i][p[i]];
  }
  }
  return sum;
  }

  for(i=0;i<n;i++){
  if(d[i]==INF){
  printf("-1 ");
  }
  else{
  if(i==n-1){
  printf("%d\n",d[i]);
  }
  else{
  printf("%d ",d[i]);
  }
  }
  }

*/



Measured memory_bytes: 2112
import kotlin.math.abs

fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    val (x, k, d) = longList()
    val xx = abs(x)
    val v = xx / d
    val a = xx - d * v
    val b = xx - (d * (v + 1))
    if (v < k) {
        if ((k - v) % 2 == 1L) {
            println(abs(b).toString())
        } else {
            println(abs(a).toString())
        }
    } else {
        println(abs(xx - (d * k)).toString())
    }
}

Measured memory_bytes: 36484
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read()
{
	int s=0,f=1; char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=25020;
const int mod=1e9+7;

int jc[maxn],jcn[maxn],inv[maxn];

inline void prepare()
{
	jc[0]=jc[1]=jcn[0]=jcn[1]=inv[1]=1;
	REP(i,2,25000)jc[i]=(ll)i*jc[i-1]%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)jcn[i-1]*inv[i]%mod;
}

inline int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%mod;
		b>>=1;
		a=(ll)a*a%mod;
	}
	return ans;
}

inline void pls(int &a,int b){ a+=b; a-=a>=mod?mod:0;}

int n,k,m;
int a[maxn];

int vis[maxn];
int type;

inline void init()
{
	n=read();k=read();m=read();
	REP(i,1,m)a[i]=read();
	REP(i,1,m-k+1)
	{
		static int vis[maxn];
		REP(j,1,k)vis[j]=0;
		REP(j,1,k)vis[a[i+j-1]]++;
		int flg=1;
		REP(j,1,k)if(vis[j]!=1){ flg=0;break;}
		if(flg)type=3;//allin
	}
	if(type!=3)
	{
		static int vis[maxn];
		REP(j,1,m)vis[a[j]]++;
		REP(j,1,k)if(vis[j]>1)type=2;
		if(!type)type=1;
	}
}

int ans;

inline void DP(int start,int *f)
{
	static int dp[maxn][420];
	memset(dp,0,sizeof(dp));
	dp[0][start]=1;
	f[0]=1;
	REP(i,1,n)
	{
		int sum=0;
		DREP(j,k-1,1)
		{
			sum=(sum+dp[i-1][j])%mod;
			dp[i][j]=(dp[i][j]+(ll)dp[i-1][j-1]*(k-j+1))%mod;
			dp[i][j]=(dp[i][j]+sum)%mod;
		}
	}
	REP(i,1,n)REP(j,1,k-1)f[i]=(f[i]+dp[i][j])%mod;
}

#define pii pair<int,int>

inline pii operator +(pii a,pii b){ pls(a.fi,b.fi); pls(a.se,b.se);return a;}
inline pii operator *(pii a,int b){ return mkr((ll)a.fi*b%mod,(ll)a.se*b%mod);}

inline void doing()
{
	if(type==3);
	else if(type==2)
	{
		static int vis[maxn],f[maxn],g[maxn];
		int L=1,R;
		for(L=1;!vis[a[L]];L++)vis[a[L]]=1;
		L--;
		memset(vis,0,sizeof(int)*(k+1));
		for(R=m;!vis[a[R]];R--)vis[a[R]]=1;
		R++;
		DP(L,f); DP(m-R+1,g);
		REP(i,0,n-m)ans=(ans+(ll)f[i]*g[n-m-i])%mod;
	}else
	{
		static pii dp[25020][420];
		dp[0][0]=mkr(1,0);
		REP(i,1,n)
		{
			pii sum=mkr(0,0);
			DREP(j,k-1,1)
			{
				sum=(sum+dp[i-1][j]);
				dp[i][j]=(dp[i][j]+dp[i-1][j-1]*(k-j+1));
				dp[i][j]=(dp[i][j]+sum);
			}
			REP(j,m,k-1)pls(dp[i][j].se,dp[i][j].fi);
		}
		pii sum=mkr(0,0);
		REP(j,1,k-1)sum=sum+dp[n][j];
		ans=(ll)sum.se*jcn[k]%mod*jc[k-m]%mod;
	}
	ans=((ll)power(k,n-m)*(n-m+1)-ans+mod)%mod;
	printf("%d\n",ans);
}

int main()
{
	prepare();
	init();
	doing();
	return 0;
}


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


int main(){

	int n, m;
	cin >> n >> m;
	vector<int> k(35), ans(35);
	for(int i = 0; i < n; i++)
	{
		cin >> k[i];
		for(int j = 0; j < k[i]; j++)
		{
			int p;
			cin >> p;
			ans[p]++;
		}
	}
	int cnt=0;
	for(int i = 0; i < 35; i++)
	{
		if(ans[i] == n) cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int array[100000000];
int main(){
	vector<P> vec;
	while(1){
		vec.clear();
		string s;
		for(int j=0;j<3;j++){
			cin >> s;
			if(s=="0")goto end;
			if(s[0]=='A'&&!vec.empty())vec.back().fi++;
			else if(s[0]=='B'&&!vec.empty())vec.back().sec++;
			int a = 0,b = 0;
			for(int i=1;i<s.size();i++){
				if(s[i]=='A')a++;
				else b++;
			}
			vec.pb(P(a,b));
		}
		if(vec.back().fi>=10&&vec.back().sec>=10){
			if(vec.back().fi>vec.back().sec)vec.back().fi++;
			else vec.back().sec++;
		}
		else{
			if(vec.back().fi>vec.back().fi)vec.back().fi++;
			else vec.back().sec++;
		}
		for(int i=0;i<vec.size();i++){
			printf("%d %d\n",vec[i].fi,vec[i].sec);
		}
	}
	end:;
	return 0;
}

Measured memory_bytes: 1188
import sys

def inp():
  return sys.stdin.readline().strip()

N = int(inp())
inAB = 0
sB = 0
eA = 0
both = 0
for _ in range(N):
  s = inp()
  inAB += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    both += 1
    continue
  if s[0] == 'B':
    sB += 1
  if s[-1] == 'A':
    eA += 1

pair = min(eA, sB)
if sB > 0 or eA > 0:
  ans = both + pair
else:
  ans = both - 1
print(inAB + max(ans, 0))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
signed main(){
  long long n,m,p,ac=0,wrong[100050],wa=0;
  bool dudge[100050];
  string s;
  cin>>n>>m;
  for(int i=1;i<=n;i++)
    dudge[i]=false,wrong[i]=0;
  
  for(int i=0;i<m;i++){
    cin>>p>>s;
    if(s == "AC")
      dudge[p]=true;

    else{
      if(dudge[p] == false)
	wrong[p]++;
    }
  }

  for(int i=1;i<=n;i++){
    ac+=dudge[i];
    if(dudge[i] == true)
      wa+=wrong[i];
  }
    
  cout<<ac<<' '<<wa<<endl;
  return(0);
}


Measured memory_bytes: 1152
#G-not再帰
import queue
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
adj=[[] for _ in range(N)]
deg_in=[0]*N#各頂点の入力次数

for i in range(M):
    x,y=map(int,input().split())
    x-=1
    y-=1
    adj[x].append(y)
    deg_in[y]+=1
    
dp=[0]*N#i番目からみた最長経路
L=[]#トポロジカルソート後
q=queue.Queue()#入力辺を持たないノード

for i in range(N):
    if deg_in[i]==0:
        q.put(i)

while not q.empty():
    v=q.get()
    L.append(v)
    for to in adj[v]:
        deg_in[to]-=1
        if deg_in[to]==0:
            q.put(to)
            dp[to]=max(dp[to],dp[v]+1)
        
print(max(dp))

Measured memory_bytes: 69164