akhauriyash/Code-Regression huggingface dataset:
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
#include<bits/stdc++.h>
using namespace std;
int a;
string s;
int main()
{
	cin>>a>>s;
	if(a>=3200)cout<<s<<endl;
	else cout<<"red\n";
} 


Measured memory_bytes: 256
H, W = map(int, input().split())

A = []
B = []
abs_diff = [[0]*(W+1) for h in range(H+1)]

for h in range(H):
  A.append(list(map(int, input().split())))
  
for h in range(H):
  B.append(list(map(int, input().split())))

max_diff = 0
for h in range(H):
  for w in range(W):
    d = abs(A[h][w] - B[h][w])
    max_diff = max(max_diff, d)
    abs_diff[h+1][w+1] = d

base = max_diff*(H + W)
dp = [[0 for w in range(W+1)] for h in range(H+1)]
dp[0][1] = dp[1][0] = 1 << base
for h in range(1, H+1):
  for w in range(1, W+1):
    dp[h][w] = (
      (dp[h-1][w] << abs_diff[h][w]) | (dp[h-1][w] >> abs_diff[h][w]) 
      | (dp[h][w-1] << abs_diff[h][w]) | (dp[h][w-1] >> abs_diff[h][w]))


positive = bin(dp[H][W] >> base)
print(positive[::-1].find('1'))

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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  int a,b,t; cin >> a >> b >>t;
  int ans = t / a * b;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int length=s.size();
  int result=1;
  for(int i=0;i<(length-1)/2;i++){
    if(s.at(i)==s.at(length-1-i)){
      continue;
    }else{
      result=0;
      break;
    }
  }
  
    for(int i=0;i<(length-1)/2;i++){
    if(s.at(i)==s.at((length-1)/2-1-i)){
      continue;
    }else{
      result=0;
      break;
    }
    }
  
    for(int i=0;i<(length-1)/2;i++){
    if(s.at(length-1-i)==s.at((length-1)/2+1+i)){
      continue;
    }else{
      result=0;
      break;
    }
  }
  if(result==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>
 
using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
//#define MODE 1
//#undef MODE
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) (f)? cout<<"true ":cout<<"false ";
#define FORDEB(n,X) for(int i=0;i<(n);i++)ARDEB(i,X)
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define ARDEB(i,X) {}
#define TFDEB(f) {}
#define FORDEB(n,X) {}
#define END {}
#endif
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
#define YN(f) cout<<((f)?"Yes":"No")<<endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000; 

int main(){
	ll n,m,ans1,ans2;
	cin>>n>>m;
	if(n%3==0||m%3==0){
		cout<<0<<endl;
		return 0;
	}
	else{
		ll min=1000000000000;
		for(int i=1;i<=n;i++){
			ll sc1=m*i;
			ll sc2=(m/2)*(n-i);
			ll sc3=(m-m/2)*(n-i);
			ll dim=std::max({sc1,sc2,sc3})-std::min({sc1,sc2,sc3});
			if(dim<min){
				min=dim;
			}
		}
		ans1=min;
		min=INF;
		for(int i=1;i<=m;i++){
			ll sc1=n*i;
			ll sc2=(n/2)*(m-i);
			ll sc3=(n-n/2)*(m-i);
			ll dim=std::max({sc1,sc2,sc3})-std::min({sc1,sc2,sc3});
			if(dim<min){
				min=dim;
			}
		}
		ans2=min;
	}
	cout<<std::min({ans1,ans2,n,m})<<endl;
	return 0;
}


Measured memory_bytes: 256
A,B=map(int,input().split())

if A==0:
    n=(B+1)//2
    if n%2==0:
        if B%2==0:
            print(B)
        else:
            print(0)
    else:
        if B%2==0:
            print(1^B)
        else:
            print(1)
else:
    m=A//2
    if m%2==0:
        if (A-1)%2==0:
            a=A-1
        else:
            a=0
    else:
        if (A-1)%2==0:
            a=1^(A-1)
        else:
            a=1
    n=(B+1)//2
    if n%2==0:
        if B%2==0:
            b=B
        else:
            b=0
    else:
        if B%2==0:
            b=1^B
        else:
            b=1
    ans=a^b
    print(ans)

Measured memory_bytes: 3064
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: i,n
    character(26):: s
    logical:: cuse(ichar('a'):ichar('z'))

    read*, s
    n = len_trim(s)
    cuse(:) = .false.
    do i=1,n
        cuse(ichar(s(i:i)))=.true.
    end do

    do i=ichar('a'),ichar('z')
        if (.not.cuse(i)) then
            print'(a)', trim(s)//char(i)
            stop
        end if
    end do

    do i=n-1,1,-1
        if (s(i:i) < s(i+1:i+1)) then
            print'(a)', trim(s(:i-1))//change(s(i:))
            stop
        end if
    end do

    print'(i0)', -1

contains
    function change(str) result(ret)
        character(*):: str
        character(1),allocatable:: ret
        integer(int32):: i,ln

        ln = len_trim(str)
        do i=ln,2,-1
            if (str(i:i) > str(1:1))then
                ret=str(i:i)
                return
            end if
        end do
    end function
end program name

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	VS s(2*n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		s[i] += s[i];
		s[n+i] = s[i];
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int tmp = 1;
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < n; ++k) {
				if (j == k) {continue;}
				if (s[i+j][k] != s[i+k][j]) {
					tmp = 0;
				}
			}
		}
		ans += tmp*(n-i);
	}
	for (int i = 1; i < n; ++i) {
		int tmp = 1;
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < n; ++k) {
				if (j == k) {continue;}
				if (s[j][i+k] != s[k][i+j]) {
					tmp = 0;
				}
			}
		}
		ans += tmp*(n-i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
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(){
    int n,k;
    cin >> n >> k;
    COMinit();
    //青球の選び方K個のボールをi個のグループに分ける... k-1個の隙間からi個選ぶ
    //赤球の選び方N-K個のボールをk+1このグループに分ける...k-1個(ボールの隙間)には必ず一つ以上のボールが入るが2こ(青球の両端)にはボールが入らなくてもよい.
    //N-K-1+2個の隙間にiこのグループを割り付ける...n-k+1Ci
    for(int i = 1; i <= k ; i++){
        cout << COM(n-k+1,i)*COM(k-1,i-1)%MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 12160
M = 10**9 + 7
n, a, b = map(int, input().split())
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 == a:
    r -= c * pow(f, M - 2, M)
print((r - c * pow(f, M - 2, M)) % M)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=1e18;

int n,m;
vector<ll> x(1000),y(1000),z(1000);
ll solve(int a,int b,int c){
    vector<ll> res(n);
    for(int i=0;i<n;i++){
        res[i]=x[i]*(a?1:-1)+y[i]*(b?1:-1)+z[i]*(c?1:-1);
    }
    sort(res.begin(),res.end(),greater<ll>());
    ll sum=0;
    for(int i=0;i<m;i++) sum+=res[i];
    return sum;
}

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i];
    ll ans=0;
    for(int b=0;b<(1<<3);b++){
        ans=max(ans,solve((b&1),((b>>1)&1),((b>>2)&1)));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  bool ans = true;
  if (s.size() % 2 == 0) {
    ans = false;
  }

  string t = s;
  reverse(s.begin(), s.end());
  if (s != t) {
    ans = false;
  }

  int m = (s.size() - 1) / 2;
  string u = "", v = "";
  for (int i = 0; i < m; i++) {
    u += s.at(i);
    v += s.at(m + i + 1);
  }

  string uu = u, vv = v;
  reverse(u.begin(), u.end());
  reverse(v.begin(), v.end());
  if ((uu != u) || (vv != v)) {
    ans = false;
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  ll n,k,Q;
  cin >> n >> k >> Q;
  vec a(n);
  vector<pll> b(n);
  vec al(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    b[i]={a[i],i};
  }
  sort(b.begin(),b.end());
  ll ans=inf;
  for(ll i=0;i<n;i++) {
    ll id=b[i].second;
    priority_queue<ll,vec,greater<ll>> q;
    vec c;
    for(ll j=0;j<n;j++) {
      if(al[j]) {
        while(q.size()) q.pop();
      }
      else {
        q.push(a[j]);
        if(q.size()==k) {
          c.push_back(q.top());
          q.pop();
        }
      }
    }
    al[id]=1;
    if(c.size()<Q) break;
    sort(c.begin(),c.end());
    ans=min(ans,c[Q-1]-c[0]);
  }
  cout << ans << endl;
}

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

int main()
{
    int N,M;
    cin >> N >> M;
    long long sPos[N][2];
    long long cPos[M][2];
    long long maxDist = 500000000;

    for(int i=0; i<N; i++) cin >> sPos[i][0] >> sPos[i][1];
    for(int i=0; i<M; i++) cin >> cPos[i][0] >> cPos[i][1];

    for(int i=0; i<N; i++)
    {
        int num = 0;
        for(int j=0; j<M; j++)
        {
            long long temp = abs(sPos[i][0]-cPos[j][0]) + abs(sPos[i][1]-cPos[j][1]);
            if(temp < maxDist)
            {
                maxDist = temp;
                num = j+1;
            }
        }
        cout << num << endl;
        maxDist = 500000000;
    }

    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	vi v(3);
	cin >> v[0] >> v[1] >> v[2];

	DESCSORT(v);

	cout << (v[0] == v[1] + v[2] ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = {}
for i in range(1, n+1):
    s = str(i)
    t = (int(s[0]), int(s[-1]))
    if t in d:
        d[t] += 1
    else:
        d[t] = 1

ans = 0
for i, c in d.items():
    r = (i[1], i[0])
    if r in d:
        ans += d[r] * c

print(ans)

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

// header area

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

    int ans=0;
    ans = a + a*a + a*a*a;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
    int a,c,f,g;
    char b;
    scanf("%d %c %d",&a,&b,&c);
    f=a+c;
    g=a-c;
    if(b== '+') {
        printf("%d",f);
    }
    else if (b=='-'){
        printf("%d",g);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<vector<int>> c(10, vector<int>(10));
	vector<vector<int>> a(h, vector<int>(w));
	rep(i, 10) cin >> c[i];
	rep(i, h) cin >> a[i];
	rep(k, 10)rep(i, 10)rep(j, 10) {
		mins(c[i][j], c[i][k] + c[k][j]);
	}
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == -1) continue;
			ans += c[a[i][j]][1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3784
H, W, A, B = map(int, input().split())

ansss = [[1]*(A) + [0]*(W-A) for _ in range(B)]
ansss += [[0]*(A) + [1]*(W-A) for _ in range(H-B)]

print('\n'.join([''.join(map(str, anss)) for anss in ansss]))


Measured memory_bytes: 14032
#include<iostream>
#include<set>
using namespace std;
int main()
{
 int n,m,i,t,max;
 set<int> s;
 set<int>::iterator it;
 while(cin>>n>>m,n|m){
  s.clear();
  for(i=0;i<n+m;i++){cin>>t;s.insert(t);}
  max=t=0;
  for(it=s.begin();it!=s.end();it++){
   if(max<*it-t)max=*it-t;
   t=*it;
  }
  cout<<max<<endl;
 }
}

Measured memory_bytes: 1156
#include<stdio.h>
int ta[100010],nt[200010],to[200010],co[200010],gg;
int MAX(int a,int b){return a<b?b:a;}
int d[100010];
void mkls(int v,int e,int *a,int *b,int *c){
  int i;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[b[i]]=i+e]=co[ta[a[i]]=i]=c[i];
  }
}
int f(int s,int p){
  int m=0,i;
  for(i=ta[s];i+1;i=nt[i]){
    if(to[i]==p)continue;
    m=MAX(m,f(to[i],s)+co[i]);
  }//printf("%d %d\n",s,m);
  return d[s]=m;
}
int g(int s,int p){//printf("\ns%d p%d",s,p);
  int a=d[s],b=0,i,c=0,m=0;
  if(p+1){
    b=d[p];
    for(i=ta[p];i+1;i=nt[i]){//????????´??°
      if(to[i]==s)c=co[i];
      else m=MAX(m,d[to[i]]+co[i]);
    }//printf(" b%d c%d m0:%d",b,c,m);
    d[p]=m;
    m+=c;
    //d[p]=m;
  }
  for(i=ta[s];i+1;i=nt[i]){//????????´??°
    if(to[i]==p)continue;
    m=MAX(m,d[to[i]]+co[i]);
  }//printf(" m1:%d",m);
  d[s]=m;
  for(i=ta[s];i+1;i=nt[i]){//??????
    if(to[i]==p)continue;
    m=MAX(m,g(to[i],s));
  }//printf(" m2:%d\n",m);
  if(p+1)d[p]=b;//???????????????
  d[s]=a;//printf("a:%d b:%d\n",a,b);
  return m;
}
int main(){
  int n,m,a[100010],b[100010],c[100010],i;
  scanf("%d",&n);
  for(i=0;i<n-1;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);//printf("c\n");
  mkls(n,n-1,a,b,c);//printf("a\n");
  f(n/2,-1);//printf("b\n");
  //for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);
  printf("%d\n",g(n/2,-1));//,tyokkei(n));
  return 0;
}

Measured memory_bytes: 8800
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,k,x,s[2005],t[2005],ans;
vector<int>g[2005];
void dfs(int v,int d,int p){
    x++;
    if(d<k/2)for(int i=0;i<g[v].size();i++)if(g[v][i]!=p)dfs(g[v][i],d+1,v);
}
int main(void){
    cin>>n>>k;
    for(int i=0;i<n-1;i++){
        cin>>s[i]>>t[i];
        g[--s[i]].push_back(--t[i]);
        g[t[i]].push_back(s[i]);
    }
    if(k%2==0){
        for(int i=0;i<n;i++){
            x=0;
            dfs(i,0,i);
            ans=max(x,ans);
        }
    }else{
        for(int i=0;i<n-1;i++){
            x=0;
            dfs(s[i],0,t[i]);
            dfs(t[i],0,s[i]);
            ans=max(ans,x);
        }
    }
    cout<<n-ans<<endl;
}


Measured memory_bytes: 384
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
inline int
toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

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

//math
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

//repetition
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    for (int &x : d)
    {
        cin >> x;
    }
    sort(ALL(d));
    cout << d[N / 2] - d[(N / 2 - 1)] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  cout << std::min(N * A, B) << endl;

  return 0;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<stack>
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<iomanip>
#include<string.h>
using namespace std;

int main(){
    while(true){
        int n,m;
        cin>>n;
        if(n==0)
            break;
        cin>>m;
        string s;
        cin>>s;
//        for(int i=0;i<m;i++){
//            cout<<i<<"_"<<s[i]<<" ";
//        }
//        cout<<endl;
        int i=0,j=0,ans=0;
        for(i=0;i<m-n;){
            if(s[i]=='O'){
                i++;
                continue;
            }
            int t=1;
            for(j=i;j<2*n+1+i;j++){
                if((j-i)%2==0&&s[j]!='I'){
                    //cout<<"i: "<<i<<"   j: "<<j<<endl;
                    t=0;
                    i=j+1;
                    break;
                }
                if((j-i)%2==1&&s[j]!='O'){
                    //cout<<"i: "<<i<<"   j: "<<j<<endl;
                    t=0;
                    i=j;
                    break;
                }
            }
            int q;
            if(t==1){
                //cout<<"i : "<<i<<endl;
                ans++;
                for(q=j;q<m-2;q+=2){
                    
                    if(s[q]!='O'||s[q+1]!='I')
                        break;
                    ans++;
                    //cout<<"q "<<q<<endl;
                }
                i=q;
            }
            
            //cout<<"i : "<<i<<endl;
        }
        cout<<ans<<endl;
        //cout<<"***********************"<<endl;
    }
}

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

string solve() {
    int N; cin >> N;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    int all = 0;
    for(auto &e : A) all = gcd(all, e);
    if(all != 1) return "not coprime";
    int M = 1e6;
    map<int, int> mp;
    for(auto &e : A) mp[e]++;
    for(int i = 2; i <= M; ++i) {
        int cnt = 0;
        for(int j = i; j <= M; j += i) {
            if(mp.find(j) != mp.end()) cnt += mp[j];
        }
        if(cnt > 1) return "setwise coprime";
    }
    return "pairwise coprime";
}

int main() {
    cout << solve() << '\n';
    return 0;
}


Measured memory_bytes: 53708
# include <cstdio>
int N ;
int main ()
{
scanf ("%d" ,&N );
int res = N ;
for ( int i =0; i <= N ; i ++)
{
int cc =0;
int t = i ;
while (t >0) cc += t %6 , t /=6;
t=N - i ;
while (t >0) cc += t %9 , t /=9;
if ( res > cc ) res = cc ;
}
printf ("%d\n" , res );
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

    private static Scanner sc;
    private static int[][] neg8 = new int[][]{{-1, -1}, {0, -1}, {1, -1}, {-1, 0}, {1, 0}, {-1, 1}, {0, 1}, {1, 1}};

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int A, B, C, D;
            A=sc.nextInt();
            B=sc.nextInt();
            C=sc.nextInt();
            D=sc.nextInt();

            Set<Integer> alice = new HashSet<>();
            Set<Integer> bob = new HashSet<>();
            for (int i = A; i < B; i++) {
                alice.add(i);
            }
            for (int i = C; i < D; i++) {
                bob.add(i);
            }

            alice.retainAll(bob);
            System.out.println(alice.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}



Measured memory_bytes: 23124
//#include"pch.h"
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<algorithm>

int main() {

	char S[30];

	scanf("%s", S);

	if (S[5] == '1' || S[6] > '4')puts("TBD");
	else puts("Heisei");


	return(0);
}

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

char a;

int main(){
    int cnta=1;
    int cntb=1;
    int cntc=1;
    for(int i=0;i<3;i++){
        cin>>a;
        if(a=='a')cnta--;
        if(a=='b')cntb--;
        if(a=='c')cntc--;
    }
    if(cnta==0&&cntb==0&&cntc==0)cout<<"Yes"<<endl;
    else  cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<int,int> A;
    int a,b,c;
    cin >> a >> b >> c;
    A[a]++;
    A[b]++;
    A[c]++;
    if(A[5]==2 && A[7]==1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
	double x1, x2, y1, y2;
	int q;
	cin >> x1 >> y1 >> x2 >> y2;
	cin >> q;
	for (int i = 0; i < q; i++)
	{	double x3, y3;
		cin >> x3 >> y3;
		double l_d = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
		double l = (x3 - x1) * ((x2 - x1) / l_d) + (y3 - y1) * ((y2 - y1) / l_d);
		double x4 = x1 + l * (x2 - x1) / l_d;
		double y4 = y1 + l * (y2 - y1) / l_d;
		cout << fixed
			 << setprecision(10)
			 << x4 << " " << y4
			 << endl;
	}
	return 0;
}

Measured memory_bytes: 3284
#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;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	ll n, i, k;
	cin >> n >> k;
	vll a(n), dp(n + k);
	for(i = 0; i < n; i++)
		cin >> a[i];
	for(i = 1; i < dp.size(); i++)
		dp[i] = LLONG_MAX;
	for(i = 0; i < n; i++)
	{
		for(ll j = 1; j <= k; j++)
			dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

int main() {
  int N,A,B,C,D;
  cin >> N;
  A = N / 1000;
  B = (N / 100) - 10*A;
  C = (N / 10) - 100*A - 10*B;
  D = N - 1000*A - 100*B - 10*C;
  if(A == B && B == C || B == C && C == D){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3604
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>

using namespace std;

int main() {

	string S;
	cin >> S;
	if (S == "SUN") {
		cout << 7 << endl;
	}
	if (S == "MON") {
		cout << 6 << endl;
	}
	if (S == "TUE") {
		cout << 5 << endl;
	}
	if (S == "WED") {
		cout << 4 << endl;
	}
	if (S == "THU") {
		cout << 3 << endl;
	}
	if (S == "FRI") {
		cout << 2 << endl;
	}
	if (S == "SAT") {
		cout << 1 << endl;
	}
	return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	string s;
	cin >> s;
	int i, j;
	for (i = 1; i < s.size(); i++) {
		if (s[i] == s[i - 1]) {
			cout << i << " " << i + 1 << endl;
			return 0;
		}
	}
	for (i = 2; i < s.size(); i++) {
		if (s[i] == s[i - 2]) {
			cout << i - 1 << " " << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
const int N = 2e5 + 7;
using namespace std;
using pi = pair<int, int>;
pi a[N];
auto main() -> int {
    int n; cin >> n;
    for (int i = 1; i <= n ; ++i) cin >> a[i].first >> a[i].second;

    vector<int> mi, ma;
    for (int i = 1; i <= n; ++i) {
        mi.emplace_back(a[i].first - a[i].second);
        ma.emplace_back(a[i].first + a[i].second);
    }
    sort(mi.begin(), mi.end());
    sort(ma.begin(), ma.end());
    cout << max(mi[n-1] - mi[0], ma[n-1] - ma[0]) << '\n';
    return 0;
}

Measured memory_bytes: 6612
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def main():
    a = int(input())
    b = int(input())
    for i in range(1,4):
        if i==a:
            continue
        elif i==b:
            continue
        else:
            print(i)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 38636
import sys
sys.setrecursionlimit(200000)
n,e = map(int,input().split())
g = [[] for i in range(n)]
for i in range(e):
  a,b,c = map(int,input().split())
  g[a].append([b,c,len(g[b])])
  g[b].append([a,0,len(g[a])-1])
def dfs(x,t,f):
  if x == t:
    return f
  global used
  used[x] = 1
  for j in range(len(g[x])):
    y, cap, rev = g[x][j]
    if cap and not used[y]:
      d = dfs(y,t,min(f,cap))
      if d:
        g[x][j][1] -= d
        g[y][rev][1] += d
        return d
  return 0

flow = 0
f = INF = float("inf")
while f:
  used = [0]*n
  f = dfs(0,n-1,INF)
  flow += f
  
print(flow)


Measured memory_bytes: 5760
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print . fst . foldl step (1, (0, 0, 0)) $ as

step :: (Int, (Int, Int, Int)) -> Int -> (Int, (Int, Int, Int))
step (k, cs@(c0, c1, c2)) a = ((k * (length . filter (== True) $ [b0, b1, b2])) `mod` modulus, cs')
  where
    b0 = c0 == a
    b1 = c1 == a
    b2 = c2 == a
    cs' | b0 = (succ c0, c1, c2)
        | b1 = (c0, succ c1, c2)
        | b2 = (c0, c1, succ c2)
        | otherwise = cs

modulus = 1000000007 :: Int

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 34428
#include<bits/stdc++.h>
#define fi first
#define er erase
#define in insert
#define se second
#define pp pop_back
#define pb push_back
#define mp make_pair
#define ll long long
#define vec vector<int>
#define pii pair<int,int>
#define smin(a,b) (a=min(a,b))
#define smax(a,b) (a=max(a,b))
#define fl(a,x) memset(a,x,sizeof a)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define cs ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
const int mx=110,edg=1010;
vector<pair<pii,int> >adj[mx];
int mark[mx],ans[edg],a[edg],b[edg],c[edg],dp[mx];
set<pii >s;
int main(){
    cs;
    int n,m;
    cin>>n>>m;
    rep(i,m){
        cin>>a[i]>>b[i]>>c[i];
        adj[a[i]].pb(mp(mp(b[i],c[i]),i));
        adj[b[i]].pb(mp(mp(a[i],c[i]),i));
    }
    for(int v=1;v<=n;v++){
        fl(mark,0);
        fl(dp,63);
        dp[v]=0;
        rep(j,n) s.in(mp(dp[j],j));
        while(s.size()){
            int now=(*s.begin()).se;
            s.er(s.begin());
            mark[now]=1;
            for(auto u:adj[now]){
                int ver=u.fi.fi,w=u.fi.se;
                if(!mark[ver] && w+dp[now]<dp[ver]){
                    s.er(mp(dp[ver],ver));
                    dp[ver]=dp[now]+w;
                    s.in(mp(dp[ver],ver));
                }
            }
        }
        rep(i,m){
            if(dp[a[i]]+c[i]==dp[b[i]] || dp[b[i]]+c[i]==dp[a[i]])
                ans[i]=1;
        }
    }
    int jav=0;
    rep(i,m) jav+=!ans[i];
    cout<<jav;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N_MAX = 300001;
typedef long long ll;
typedef pair<int,int> P;
int main()
{
  int h,w,m,hh,ww,i,ti,j,res;
  ll dr,dc;
  bool f=1;
  vector<P> r,c;
  vector<int> vr[N_MAX],vc[N_MAX];
  decltype(r)::iterator ir,ic;
  vector<int>::iterator it;
  cin >> h >> w >> m;
  for(i=1;i<=h;i++)
    r.push_back(P(0,i));
  for(i=1;i<=w;i++)
    c.push_back(P(0,i));
  for(i=0;i<m;i++){
    cin >> hh >> ww;
    r[hh-1].first++;
    vr[hh].push_back(ww);
    c[ww-1].first++;
    vc[ww].push_back(hh);
  }
  sort(r.begin(),r.end(),greater<P>());
  sort(c.begin(),c.end(),greater<P>());
  for(i=1;i<=h;i++)
    sort(vr[i].begin(),vr[i].end());
  for(i=1;i<=w;i++)
    sort(vc[i].begin(),vc[i].end());
  ir=upper_bound(r.begin(),r.end(),P(r[0].first,0),greater<P>());
  dr=(ll)distance(r.begin(),ir);
  ic=upper_bound(c.begin(),c.end(),P(c[0].first,0),greater<P>());
  dc=(ll)distance(c.begin(),ic);
  if(dr*dc<=m){
    f=0;
    for(i=0;i<dr;i++){
      ti=r[i].second;
      for(j=0;j<dc;j++){
        it=lower_bound(vr[ti].begin(),vr[ti].end(),c[j].second);
        if(it==vr[ti].end()||(*it)!=c[j].second){
          f=1;
          break;
        }
      }
      if(f==1)
        break;
    }
  }
  res=r[0].first+c[0].first;
  if(f==0)
    res--;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 40712
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
 
int main(){
    string s;
    int alp[26] = {};
    while(true){
        getline(cin, s);
        if(s=="") break;    
        for(int i=0;i<s.size();i++){
            if('a' <= s[i] && s[i] <= 'z'){
                alp[s[i]-'a']++;
            }else if('A' <= s[i] && s[i] <= 'Z'){
                alp[s[i]-'a'+32]++;
            }
        }
    }

    for(int i=0;i<26;i++){
        printf("%c : %d\n", 'a'+i, alp[i]);
    }
}


Measured memory_bytes: 3356
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<cstdint>

int const MAXN = 50;
int const MAXM = 20;
int N, M;
std::vector<int> G[MAXN];

int tmp[MAXN];

struct conditions {
  mutable std::set<int> s;
  std::pair<int, int> diff[MAXM][3];
  
  void add_cond(int v, int u, int ci) {
    s.clear();
    dfs(u, -1, v);
    std::fill_n(tmp, N, 0);
    dfs2(0, -1);
    diff[ci][2].first = MAXN;
    int cp = 0;
    for(int i = 0; i < N; ++i) if(tmp[i]!=0) {
      diff[ci][cp++] = std::make_pair(i, tmp[i]);
    }
  }
  
  bool dfs(int v, int p, int u) {
    bool res = (v==u);
    if(!res) for(auto c: G[v]) if(c != p) {
      res = dfs(c, v, u);
      if(res) break;
    }
    if(p >= 0 && res) s.insert(p*MAXN+v);
    return res;
  }
  
  void dfs2(int v, int p) {
    if(p >= 0 && s.count(p*MAXN+v)+s.count(v*MAXN+p) > 0) {
      --tmp[p]; ++tmp[v];
    }
    for(auto c: G[v]) if(c != p) dfs2(c, v);
  };
  
  void add_cond(int j) {
    for(int k = 0; k < 3; ++k) if(diff[j][k].first < N) {
      auto& pa = diff[j][k];
      tmp[pa.first] += pa.second;
    }
  }
  
  int sum() { return sum_cond(0, -1).first; }
  
  std::pair<int, int> sum_cond(int v, int p) {
    std::pair<int, int> res(0, 0);
    for(auto c: G[v]) if(c != p) {
      auto pa = sum_cond(c, v);
      res.first += pa.first;
      res.second += pa.second;
    }
    res.second += tmp[v];
    if(res.second > 0) ++res.first;
    return res;
  }
};

int main() {
  std::cin >> N;
  for(int i = 0; i < N-1; ++i) {
    int a, b; std::cin >> a >> b; --a; --b;
    G[a].push_back(b); G[b].push_back(a);
  }
  conditions cond;
  std::cin >> M;
  for(int i = 0; i < M; ++i) {
    int u, v; std::cin >> u >> v; --u; --v;
    cond.add_cond(v, u, i);
  }
  
  int64_t ans = 0;
  for(int s = 0; s < 1<<M; ++s) {
    int64_t i = 1;
    std::fill_n(tmp, N, 0);
    for(int j = 0; j < M; ++j) if(s>>j&1) {
      cond.add_cond(j);
      i *= -1;
    }
    ans += i*((int64_t)1 << N-1-cond.sum());
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
	vector<int> A(3);
	rep(i, 0, 3) {
		cin >> A[i];
	}
	sort(all(A));
	cout << A[2] - A[0] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>

using namespace std;

main ( )
{
  for ( ; ; )
  {
    int lc = 0, lm = 0;
    int dc = 0, dm = 0;
    int mc = 0, mm = 0;
    int n;

    scanf ( " %d", &n );
    if ( n == 0 ) break ;
    while ( n-- )
    {
      int h, m, d;
      int res;

      scanf ( " %d:%d %d", &h, &m, &d );
      res = ( ( d + 60 - m ) % 60 ) <= 8;
      if ( h >= 11 && h < 15 ) { lc += res; ++lm; }
      if ( h >= 18 && h < 21 ) { dc += res; ++dm; }
      if ( h >= 21 && h < 24
        || h >= 0  && h < 2  ) { mc += res; ++mm; }
    }

    if ( lm ) printf ( "lunch %d\n", lc * 100 / lm );
    else      printf ( "lunch no guest\n" );
    if ( dm ) printf ( "dinner %d\n", dc * 100 / dm );
    else      printf ( "dinner no guest\n" );
    if ( mm ) printf ( "midnight %d\n", mc * 100 / mm );
    else      printf ( "midnight no guest\n" );
  }
}

Measured memory_bytes: 0
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n=int(arr_data[0][0])

print(111+999-n)



Measured memory_bytes: 2940
from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split()]

d = defaultdict(int)
# balls = [0 for _ in range(N)]

ans = 0
for n in range(N, 0, -1):
    a_i = a[n-1]
    cnt = 0
    n2 = n*2
    while n2 <= N:
        cnt += d[n2]
        n2 += n
    if cnt % 2 != a_i:
        d[n] = 1
        ans += 1

print(ans)
if ans >= 1:
    for k, v in d.items():
        if v == 1:
            print(k)


Measured memory_bytes: 84316
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  float n;
  cin >> n;
  float ans = 2 * n * 3.1415926535;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 3228
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 1001
#define MAX_M 2001
using namespace std;
typedef long long ll;
const ll INF   = 10000000000000;
struct edge {ll from; ll to; ll cost;};
vector<edge> es;
ll d[MAX_N];
bool neg[MAX_N];
ll N, M;
ll ans;

void bellman_ford() {
  
  for (int i = 0; i < MAX_N; i++) {
    d[i] = INF;
    neg[i] = false;
  }

  ll s = 1;
  ll g = N;
  d[s] = 0;

  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < M; j++) {
      edge e = es[j];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
	d[e.to] = d[e.from] + e.cost;
      }
    }
  }

  ans = d[N];
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      edge e = es[j];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
	d[e.to] = d[e.from] + e.cost;
	neg[e.to] = true;
      }
      if(neg[e.from] == true) neg[e.to] = true;
    }
  }
  
}


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

    cin >> N >> M;

    ll a, b, c;
    for (int i = 0; i < M; i++) {
      cin >> a >> b >> c;

      edge e;
      e.from = a;
      e.to   = b;
      e.cost = -c;
      es.push_back(e);
    }

    bellman_ford();
    if (neg[N] == false) cout << -ans << endl;
    else cout << "inf" << endl;

    return 0;
}


Measured memory_bytes: 384