akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>


using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void) {
  double n;
  cin>>n;
  if((int)n%2==0)
    std::cout << ((int)n/2)/n << std::endl;
  else
    std::cout <<  (((int)n/2)+1)/n << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int mod=998244353;
int n,b[200010],ans=1;
P a[200010];
set<P>st;
vector<int>v[200010];
int dfs(int x){
    int res=1;
    for(int i:v[x]){
        res*=dfs(i);
        res%=mod;
    }
    return (res+1)%mod;
}
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i].fi>>a[i].se;
        a[i].se+=a[i].fi;
    }
    sort(a,a+n);
    for(int i=n-1;i>=0;i--){
        while(!st.empty()&&st.begin()->fi<a[i].se){
            v[i].pb(st.begin()->se);
            st.erase(st.begin());
        }
        st.insert({a[i].fi,i});
    }
    for(P p:st){
        ans*=dfs(p.se);
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int x, n, a = 0, b = 301, c = 301, d = 301;
  cin >> n >> x;
  while (x > 0 || n > 0) {
    for (int i = 1; i <= n - 2; i++) {
      for (int o = i + 1; o <= n - 1; o++) {
        for (int p = o + 1; p <= n; p++) {
          if (i + o + p == x) a++;
        }
      }
    }
    cout << a << endl;
    a = 0;
    cin >> n >> x;
  }
}


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#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 ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i,n)cin >> a[i];
    int max = -1;
    int answer = 1000000000;
    REP(i,n){
        int count = 0;
        ll tmp = a[i];
        while(tmp >0){
            if(tmp%2 == 0){
                tmp/=2;
                count++;
                //cout  << tmp << endl;
            }
            else{
                break;
            }
        }
        answer = min(answer,count);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#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 unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x),end(x)

#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n - 1; i >= 0; --i)

const int N = 2e5 + 5; // check bounds
const int M = 1e9 + 7;
const char nl = '\n';

template< typename T > inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template< typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <class T> void ckmin(T& a, T b) {a = min(a, b);}
template <class T> void ckmax(T& a, T b) {a = max(a, b);}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



void solve() {
	int x,  y;
	cin >> x >> y;
	for (int i = 0; i <= 100; ++i) {
		for (int j = 0; j <= 100; ++j) {
			if (i * 2 + j * 4 == y && i + j == x) {
				cout << "Yes" << nl;
				return;
			}
		}
	}
	cout << "No" << nl;
}

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

	int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    string S;
    cin>>S;
    sort(S.begin(),S.end());
    if(S[0]==S[1] && S[2]==S[3] && S[1]!=S[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
n,p = list(map(int,input().split()))
S = input()

if p == 2 or p == 5:
  ans = 0
  for i,s in enumerate(S):
    if int(s)%p == 0:
      ans += i+1
  print(ans)
  exit()

def MS(i,s,pre):
  return (s*i +pre)%p
 
M = [0]*p
M[0] = 1
t = 1
now = 0
for i in S[::-1]:
    i = int(i)
    now += i*t
    now %= p
    M[now] += 1
    t = t*10%p

ans = sum(map(lambda m:(m*(m-1))//2, M))
print(ans)


Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <bitset>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

ll dp[105][1 << 16];
ll L[105], S[105];

int main() {
	int n;
	while(cin >> n && n) {

		memset(L, 0, sizeof(L));
		memset(S, 0, sizeof(S));

		rep(i, n) {
			int m;
			cin >> m >> L[i];

			rep(j, m) {
				int s, t;
				cin >> s >> t;

				REP(k, s, t) {
					S[i] |= 1 << (k-6);
				}
			}
		}

		memset(dp, 0, sizeof(dp));

		rep(i, n) {
			rep(j, 1<<16) {
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			}

			rep(j, 1<<16) {
				if(j & S[i]) continue;
				dp[i+1][j | S[i]] = max(dp[i+1][j | S[i]], dp[i][j] + L[i]);
			}
		}

		ll ans = 0;
		rep(i, n + 1) {
			rep(j, 1<<16) {
				ans = max(ans, dp[i][j]);
			}
		}
		
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 54932
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#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;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#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 MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

signed main(){
    int N, K;
    cin >> N >> K;

    bool okasi[1000];

    for(int i = 0; i < 1000; i++){
        okasi[i] = false;
    }

    for(int i = 0; i < K; i++){
        int n;
        cin >> n;
        for(int j = 0; j < n; j++){
            int hito;
            cin >> hito;
            okasi[hito - 1] = true;
        }
    }

    int count = 0;
    for(int i = 0; i < N; i++){
        if(!okasi[i]){
            count++;
            //cout << "no : " << i << endl;
        }
    }

    cout << count << endl;
    
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int n=s.size()-1;
    ll ans=0;
    for(int bit=0;bit<(1<<n);++bit){
        ll res=0;
        for(int i=0;i<=n;++i){
            res*=10;
            res+=s[i] - '0';
            if(bit&(1<<i)){
                ans+=res;
                res=0;
            }
        }
        ans+=res;
    }
    
    cout << ans << "\n";
    return 0;
}   

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

using namespace std;

int main()
{
   ll ans=0,n,x,t;
  cin>>n>>x>>t;
  if(n%x==0)
  {
      ans = (n/x)*t;
  }  
  else
  {
       ans = ((n/x)+1) * t;
  }    
  cout<<ans<<endl;
    return 0; 
} 
  

Measured memory_bytes: 3620
n = int(input())
x = input()

c = x.count('1')
cp = c+1
cn = c-1

rp = [0] * n
if cp > 1:
    rp[0] = 1
rn = [0] * n
if cn > 1:
    rn[0] = 1
for i in range(1, n):
    rp[i] = (rp[i-1] * 2) % cp
    if cn > 0:
        rn[i] = (rn[i-1] * 2) % cn

xp = 0
xn = 0
for i in range(n):
    xx = x[i]
    if xx == '1':
        xp = (xp + rp[n-i-1]) % cp
        if cn > 0:
            xn = (xn + rn[n-i-1]) % cn

for i in range(n):
    o = 1
    if x[i] == '1':
        if cn == 0:
            print(0)
            continue
        xx = (xn-rn[n-i-1]) % cn
    else:
        xx = (xp+rp[n-i-1]) % cp
    while xx > 0:
        cc = bin(xx)[2:].count('1')
        xx = xx % cc
        o += 1
    print(o)


Measured memory_bytes: 25192
import sys
input = sys.stdin.readline
N = int(input())
a = [int(x) for x in input().split()]
x = a[0]
y = sum(a[1:])
ans = [abs(x - y)]
for i in range(1,N-1):
    x += a[i]
    y -= a[i]
    ans.append(abs(x - y))
print(min(ans))

Measured memory_bytes: 24932
#include<bits/stdc++.h>
#include<ext/rope>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;
using namespace __gnu_cxx;

const double g=10.0,eps=1e-7;
const int N=100+10,maxn=100000+10,inf=0x3f3f3f;

string s;
int main()
{
    cin>>s;
    //cout<<string(s.size(),'x')<<endl;
    if(s==string(s.size(),'x'))
    {
        cout<<0<<endl;
        return 0;
    }
    string p="";
    for(int i=0;i<s.size();i++)
        if(s[i]!='x')
            p+=s[i];
    for(int i=0;i<p.size()/2;i++)
    {
        if(p[i]!=p[p.size()-1-i])
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    int mid,ans=0;
    stack<char>z;
    if(p.size()%2==0)
    {
        mid=p.size()/2;
       // cout<<mid<<endl;
        p="";
        for(int i=0; i<s.size(); i++)
        {
            if(s[i]!='x')p+=s[i];
            if(p.size()==mid)
            {
                mid=i;
                break;
            }
        }
       // cout<<mid<<endl;
        int i=0;
        while(i<s.size()&&i<=mid)
        {
            z.push(s[i]),i++;
          //  if(!z.empty())cout<<z.top()<<endl;
        }
        while(mid<s.size()&&s[mid+1]=='x')mid++;
        mid++;
    }
    else
    {
        mid=p.size()/2+1;
       // cout<<mid<<endl;
        p="";
        for(int i=0;i<s.size();i++)
        {
            if(s[i]!='x')p+=s[i];
            if(p.size()==mid)
            {
                mid=i;
                break;
            }
        }
       // cout<<mid<<endl;
        int i=0;
        while(i<s.size()&&i<mid)
        {
            z.push(s[i]),i++;
        //    if(z.size()!=0)cout<<z.top()<<endl;
        }
        mid++;
    }
   // cout<<mid<<endl;
    for(int i=mid; i<s.size(); i++)
    {
        if(z.size()==0)
        {
            if(s[i]=='x')ans++;
            continue;
        }
      //  cout<<z.top()<<" "<<s[i]<<" "<<ans<<endl;
        if(z.top()=='x'&&s[i]=='x')z.pop();
        else if(z.top()!='x'&&s[i]=='x')ans++;
        else if(z.top()=='x'&&s[i]!='x')z.pop(),i--,ans++;
        else z.pop();
    }
    while(!z.empty())z.pop(),ans++;
    cout<<ans<<endl;
    return 0;
}
/*******************
axbba
********************/


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

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

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

  int cnt = 0;
  for ( int i = 1; i <= n-2; i++){
    if((A[i-1] < A[i]) && (A[i] < A[i+1])){
      cnt ++;
    } else if ((A[i-1] > A[i]) && (A[i] > A[i+1])){
      cnt ++;
    }
  }

  cout << cnt << endl;


  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            if (int.Parse(ReadLine()) >= 3200)
            {
                WriteLine(ReadLine());
            }
            else WriteLine("red");
        }

    }
}



Measured memory_bytes: 13140
#include <stdio.h>
#include <limits.h>

long long int chmin(long long int a,long long int b){
  //b -> min
  if(a < b){
    b = a;
  }
  return b;
}

int main(){
  int n,max_w;
  scanf("%d%d",&n,&max_w);
  int w[n],v[n],max_v=0;
  for(int i=0; i<n; i++){
    scanf("%d%d",&w[i],&v[i]);
    max_v += v[i];
  }
  long long int dp[n+1][max_v+1];
  for(int i=0; i<=n; i++){
    for(int j=0; j<=max_v; j++){
      dp[i][j]= 1LL << 62;
    }
  }
  dp[0][0] = 0;
  
  for(int i=0; i<n; i++){
    for(int value=0; value<=max_v; value++){
      if(value - v[i] >= 0){
        dp[i+1][value] = chmin(dp[i+1][value], dp[i][value-v[i]] + w[i]);
      }
      dp[i+1][value] = chmin(dp[i+1][value],dp[i][value]);
    }
  }
  
  for(int check=max_v; check>=0; check--){
    if(dp[n][check] <= max_w){
      printf("%d",check);
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
string str;
int K,l=0;
void solve(){
	if(str[l] != '1'){
		cout << str[l] << endl;
	} else if(l < K-1){
		l++; solve();
	} else{
		cout << str[l] << endl;
	}
}
int main(){
	cin >> str;
	cin >> K;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,A;
  cin>>N>>A;
  if(N%500==0){cout<<"Yes"<<endl;
              }
  else if(N%500<=A){cout<<"Yes"<<endl;
                   }
  else {cout<<"No"<<endl;}
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int N; cin >> N;
	vector < pair<int, int>>ps;
	for (int i = 0; i < N; ++i) {
		string st; cin >> st;
		int sum = 0;
		int amin = 0;
		int amax = 0;
		for (int j = 0; j < st.size(); ++j) {
			if (st[j] == '(') {
				sum++;
			}
			else {
				sum--;
				amin = min(amin, sum);
			}
		}
		ps.push_back(make_pair(-amin, sum));
	}
	int nsum = 0;
	sort(ps.begin(), ps.end(), [](const pair<int, int>&l, const pair<int, int>&r) {	
		if (l.second >= 0 && r.second >= 0) {
			return l.first < r.first;
		}
		else if (l.second < 0 && r.second < 0) {
			return  l.first + l.second >r.first + r.second;

		}
		else if(l.second>=0){
			return true;
		}
		else {
			return false;
		}
		});
	bool ok = true;
	for (auto p : ps) {
		if (nsum >= p.first) {
			nsum += p.second;
		}
		else {
			ok = false;
		}
		if (nsum < 0)ok = false;
	}
	if (ok&&!nsum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) (v).begin(), (v).end()
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int n;
int a[200005];
vector<int> edges[200005];

vector<int> A;
vector<int> dp(200005, INF);
vector<int> ans(200005, INF);

void dfs(int v, int p){
    int idx = lower_bound(all(dp), a[v]) - dp.begin();
    int tmp = dp[idx];
    dp[idx] = a[v];
    ans[v] = lower_bound(all(dp), INF) - dp.begin();

    for (auto vi : edges[v]){
        if(vi != p) dfs(vi, v);
    }
    dp[idx] = tmp;    
}


int main(){    
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n-1){
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }

    dfs(0, -1);

    rep(i, n) cout << ans[i] << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 27968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n,d;
  cin >> n >> d;
  double e = 2*d+1;
  cout << (int)ceil(n/e) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll n,k;
	cin >> n >> k;

	if((n==2 && k>0) || k > (n-1)*(n-2)/2){
		cout << -1 << endl;
		return;
	}
	if(n==2 && k==0){
		cout << 1 << endl;
		cout << 1 << " " << 2 << endl;
		return;
	}

	ll m = n-1;
	m += (n-1)*(n-2)/2 - k; // kが少ないなら増やす
	cout << m << endl;

	// まず木を構成(nをrootとする)
	rep(i,n-1){
		ll u,v;
		u = n;
		v = i+1;
		assert(u>v);
		cout << u << " " << v << endl;
	}

	// kが少ないなら横に連結
	ll cnt = 0;
	for(ll u = 1; u < n; u++){
		for(ll v = u+1; v < n; v++){
			if(cnt == (n-1)*(n-2)/2 - k) return;
			cout << u << " " << v << endl;
			cnt++;
			
		}
	}

	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 256
def rek(erg, rest):
    if not rest:
        return erg
 
    p = []
 
    for i in erg:
        p.append(i+"+"+rest[0])
        p.append(i+rest[0])
 
    return rek(p, rest[1:])
 
 
a = input()
 
erg = 0
comb = rek([a[0]], a[1:])
 
for i in comb:
    erg += eval(i)
 
print(erg)

Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    int N,M;
    cin >> N >> M;
    vector<int> a(M),b(M),c(M);
    int d[N][N];
    rep(i,M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
    }
    rep(i,N) rep(j,N){
        if(i == j) d[i][j] = 0;
        else d[i][j] = 1e9;
    }
    
    rep(i,M){
        d[a[i]][b[i]] = min(d[a[i]][b[i]],c[i]);
        d[b[i]][a[i]] = min(d[b[i]][a[i]],c[i]);
    }
    
    rep(k,N) rep(i,N) rep(j,N) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    
    int ans = M;
    rep(k,M){
        bool flag = false;
        rep(i,N) if(d[i][a[k]] + c[k] == d[i][b[k]]) flag = true;
        if(flag) ans--;
    }
    pr(ans);
}

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

using namespace std;
const int MAXN = 22;
int adj[MAXN][MAXN];
const int MAXS = (1 << 21);
int dp[MAXS + 2];
int n;
const int MOD = 1e9 + 7;

int num_set_bits(int val){
    int count = 0;
    while(val){
        val &= val - 1;
        ++count;
    }
    return count;
}

vector<int> get_bitmask(int val){
    vector<int> bitmask(n, 0);
    int index = 0;
    while(val){
        bitmask[index++] = val % 2;
        val /= 2;
    }
    return bitmask;
}

int bitmast_to_int(vector<int> bitmask){
    int ans = 0;
    for(int i = n - 1; i >= 0; --i){
        ans *= 2;
        ans += bitmask[i];
    }
    return ans;
}

inline int mod(int val, int mod){
    if(val >= mod)
        return val - mod;
    return val;
}

int find_ans(int val = (1 << n) - 1){
    // std::cerr << "DP[" << val << "]\n";
    if(val == 0){
        return 1;    
    }else if(dp[val] != -1){
        return dp[val];
    }else{
        int num_unmatched = num_set_bits(val);
        vector<int> unmatched_women = get_bitmask(val);
        int man = num_unmatched - 1;
        int total_ways = 0;
        for(int woman = 0; woman < n; ++woman){
            if(adj[man][woman] && unmatched_women[woman]){
                int temp_val = val - (1 << woman);
                total_ways = mod(total_ways + find_ans(temp_val), MOD);
            }
        }
        dp[val] = total_ways;
        return total_ways;
    }
}

int main(){
    cin >> n;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> adj[i][j];
        }
    }
    
    for(int i = 0; i < MAXS; ++i){
        dp[i] = -1;
    }
    
    cout << find_ans() << "\n";
    
    return 0;
}

Measured memory_bytes: 11804
d={} ; a=[]
from collections import Counter
for _ in range(int(input())):
    s=input()
    a.append(s)
d=Counter(a)
maxx=max(d.values())
ans=[]
for i in d:
    if d[i]==maxx:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)
    

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

using namespace std;

using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;


pair<long long,long long> dp[110][110*1100];
//long long dpv[110][110*11000];
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);

	int n = 0;
	int w = 0;
	cin >> n >> w;
	vector<pll> data(n);
	long long vs = 0;
	for(int i = 0;i < n;++i){
		cin >> data[i].first >> data[i].second;
		vs+=data[i].second;
	}
	/*for(int i = 0;i < 110; ++i){
		for(int j = 0; j < 110*1100; ++j){
			dp[i][j].first = 1e18;
		}
	}*/
	memset(dp,127,sizeof(dp));
/*	for(int i = 0;i < 110; ++i){
		dp[i][0].first = 0;
	}*/
	dp[0][0].first = 0;
/*	for(int i = 0;i < 110 * 1100; ++i){
		dp[0][i].first = 0;
	}*/

	//dp[0][0].first = 0;

	for(int i = 0;i <= vs;++i){
		for(int j = 0;j < n; ++j){
			if(dp[j][i].first /*+ data[j].first*/ < w){
				dp[j + 1][i + data[j].second].first = min(dp[j + 1][i + data[j].second].first,dp[j][i].first + data[j].first);
				dp[j+1][i].first = min(dp[j+1][i].first,dp[j][i].first);
			}
		}
	}
	for(int i = vs; i >=0; --i){
			if(dp[n][i].first <= w)
			{
				cout << i;
				return 0;
			}
	}

	return 0;
}

Measured memory_bytes: 208256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  double H,A;
  cin>>H>>A;
  cout<<(int)(ceil(H/A))<<endl;
}

Measured memory_bytes: 3728
n=int(input())
A=list(map(int,input().split()))
Amax=max(A)
Amin=min(A)
ans=0
B=[]
if Amin>=0:
    ans=n-1
    for i in range(n-1):
        B.append([i+1,i+2])
elif Amax<=0:
    ans=n-1
    for i in range(n-1):
        B.append([n-i,n-i-1])
elif Amax>=-Amin:
    a=A.index(Amax)
    for i in range(n):
        if A[i]!=Amax:
            ans+=1
            B.append([a+1,i+1])
    for i in range(n-1):
        ans+=1
        B.append([i+1,i+2])
else:
    a=A.index(Amin)
    for i in range(n):
        if A[i]!=Amin:
            ans+=1
            B.append([a+1,i+1])
    for i in range(n-1):
        ans+=1
        B.append([n-i,n-i-1])
print(ans)
for b in B:
    print(' '.join(map(str,b)))

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    call(n);
}


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

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

int main() {
    int n;cin>>n;
    int a[n+1];
    ll ans=0,tmp;
    
    rep(i,n)cin>>a[i];
    a[n]=0;
    
    rep(i,n){
        tmp=a[i]/2;
        if(a[i]%2==1 && a[i+1]>0){
            tmp++;
            a[i+1]--;
        }
        ans+=tmp;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

ans = 0
def main():
    N, M, Q = map(int, readline().split())
    query = []
    for _ in range(Q):
        a, b, c, d = map(int, readline().split())
        query.append((a, b, c, d))

    def getScore(array):
        res = 0
        for a, b, c, d in query:
            if array[b-1]-array[a-1] == c:
                res += d
        return res

    A = [0]*N

    def dfs(idx):
        global ans
        if idx == N:
            ans = max(getScore(A), ans)
        else:
            if idx == 0:
                k = 1
            else:
                k = A[idx-1]
            for i in range(k, M+1):
                A[idx] = i
                dfs(idx+1)

    dfs(0)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9304
n = int(input())
p = [int(s) for s in input().split()]

count = 0

for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        count += 1
print(count)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define int long long
using namespace std;
using II = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;
class Grid {
  // queryを計算しやすいようにaccの範囲外の値も便宜的に定義
  int point(int i, int j) {
    if (i + j < 0 || H + W - 1 <= i + j) return 0;
    if (i < 0 || j >= W) return 0;
    if (j < 0 && i + j < H) return acc[i + j][0];
    if (i >= H && i + j >= H) return acc[H - 1][i + j - (H - 1)];
    return acc[i][j];
  }
public:
  VVI t; int H, W;
  VVI acc;
  Grid(VVI tbl) : t(tbl), H(tbl.size()), W(tbl[0].size()) {
    set_acc();
  }
  VI& operator[](int i) {
    return t[i];
  }
  bool exist(int i, int j) {
    return 0 <= i && i < H && 0 <= j && j < W && t[i][j];
  }
  // 左下方向への累積和
  void set_acc() {
    acc = VVI(H, VI(W));
    REP (i, H) {
      REP (j, W) {
        int before = (i == 0 || j == W - 1) ? 0 : acc[i - 1][j + 1];
        acc[i][j] = before + t[i][j];
      }
    }
  }
  // 時計回りに90度回転
  void rotate() {
    VVI t2(W, VI(H));
    REP (i, H) {
      REP (j, W) {
        t2[j][H - i - 1] = t[i][j];
      }
    }
    t = t2;
    swap(H, W);
    set_acc();
  }
  // [i0, i1)の斜めのsum
  int query(int i0, int j0, int i1, int j1) {
    assert(i0 + j0 == i1 + j1);
    assert(i1 > i0);
    return point(i1 - 1, j1 + 1) - point(i0 - 1, j0 + 1);
  }
};

signed main() {
  int H, W; cin >> H >> W;
  VVI t(H, VI(W));
  REP (i, H) {
    REP (j, W) {
      t[i][j] = in<char>() == '#';
    }
  }
  Grid g(t);
  int ans = 0;
  int times = 4;
  while (times--) {
    REP (i, g.H) {
      REP (j, g.W) {
        if (!g.exist(i, j)) continue;
        REPI (k, 1, g.H + g.W - 1) {
          if (!g.exist(i + k, j - k)) continue;
          ans += g.query(i + k, j + k, i + 2 * k, j);
        }
      }
    }
    g.rotate();
  }
  cout << ans << endl;
}


Measured memory_bytes: 3896
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s, t;
	cin >> s >> t;
	int res = 0;
	for (int i = 0; i < sz(s); i++)
		if (s[i] == t[i])
			res++;
	cout << res;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()
A = inputIL()

sumA = sum(A)

if sumA > N:
  print("-1")
else:
  print(N-sumA)

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

int binarySearch(int A[], int n, int key) {
    int left = 0, right = n;
    while(left < right) {
        int mid = (left + right) / 2;
        if(A[mid] == key) {
            return 1;
        } else if(key < A[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }

    return 0;
}

int main() {
    int n, S[100001], q, key, sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> S[i];
    }
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> key;
        if(binarySearch(S, n, key)) {
            sum++;
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 3392
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashSet;

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [(usize1, usize1); m]
    }
    let mut g: Vec<HashSet<usize>> = vec![HashSet::new(); n];
    for &(a, b) in v.iter() {
        g[a].insert(b);
        g[b].insert(a);
    }
    let mut d4: Vec<usize> = Vec::new();
    let mut f6 = false;
    for i in 0..n {
        let d = g[i].len();
        if d % 2 != 0 {
            println!("No");
            return;
        } else if d >= 6 {
            f6 = true;
        } else if d == 4 {
            d4.push(i);
        }
    }
    if f6 {
        println!("Yes");
        return;
    }
    if d4.len() > 2 {
        println!("Yes");
        return;
    } else if d4.len() < 2 {
        println!("No");
        return;
    }
    let ans = flow(&g, d4[0], d4[1]);
    println!("{}", if ans {"Yes"} else {"No"});
}

fn flow(g: &Vec<HashSet<usize>>, s: usize, t: usize) -> bool {
    for &v in g[s].iter() {
        let mut ps: HashSet<usize> = vec![s].iter().cloned().collect();
        if !dfs(&g, v, t, &mut ps) {
            return true;
        }
    }
    false
}

fn dfs(g: &Vec<HashSet<usize>>, s: usize, t: usize, ps: &mut HashSet<usize>) -> bool {
    if s == t {
        return true;
    }
    for &c in g[s].iter() {
        if !ps.insert(c) {
            continue;
        }
        if dfs(g, c, t, ps) {
            return true;
        }
        ps.remove(&s);
    }
    return false;
}


Measured memory_bytes: 63996
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define pb push_back
#define mp make_pair
ll knapSack(int W, int wt[], int val[], int n)
{
	int i, w;
	ll K[n + 1][W + 1];
	for (i = 0; i <= n; i++)
	{
		for (w = 0; w <= W; w++)
		{
			if (i == 0 || w == 0)
				K[i][w] = 0;
			else if (wt[i - 1] <= w)
				K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
			else
				K[i][w] = K[i - 1][w];
		}
	}

	return K[n][W];
}
void solve()
{
	int n, k;
	cin >> n >> k;
	int wt[n], val[n];
	for (int i = 0; i < n; i++)
	{
		cin >> wt[i] >> val[i];
	}
	cout << knapSack(k, wt, val, n) << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 82492
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
        	String s = in.next();
        	out.println(s.charAt(0) == s.charAt(1) || 
        			s.charAt(1) == s.charAt(2) ||
        			s.charAt(2) == s.charAt(3) ? "Bad" : "Good");
        }
    }
    
    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() { return Integer.parseInt(next()); }
        
        int[] nextIntArray(int n) {
        	int[] arr = new int[n];
        	for (int i = 0; i < n; ++i) {
        		arr[i] = nextInt();
        	}
        	return arr;
        }

        long nextLong() { return Long.parseLong(next()); }

        long[] nextLongArray(int n) {
        	long[] arr = new long[n];
        	for (int i = 0; i < n; ++i) {
        		arr[i] = nextLong();
        	}
        	return arr;
        }
    }
}


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

int main() {
  int s, s1, s2, s3;
  cin >> s;
  s1 = s / 100;
  s = s - (s1 * 100);
  s2 = s / 10;
  s3 = s - (s2 * 10);
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>
#include <iostream>

using namespace std;

int main() {
  int a;
  string s;
  cin >> a >> s;
  cout << (a >= 3200? s : "red") << "\n";
  return 0;
}


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

int main(){
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	int x[1005] = {0}, y[1005] = {0};
	for(int i = 1; i <= a; i++)
		x[i] = 1;
	for(int i = a + 1; i <= w; i++)
		y[i] = 1;
	int f = 1;
//	if(a <= h / 2 && b <= w / 2){
//		
//	}
	for(int i = 1; i <= h; i++){
		if(f <= b){
			for(int j = 1; j <= w; j++)
				cout << x[j];			
		}
		else{
			for(int j = 1; j <= w; j++)
				cout << y[j];			
		}
		f++;
		cout << endl;			
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int h, w;
string a[2000];
string b[2000];

int main() {
	int i, j;
	
	cin >> h >> w;
	rep(i, h) cin >> a[i];
	rep(i, h) cin >> b[i];
	
	int ans = 0;
	rep(i, h) rep(j, w) if (a[i][j] != b[i][j]) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11304
a,b,x = gets.split.map(&:to_i)
def f(n,x)
  if n >= 0
    n/x+1
  else
    0
  end
end
# 対象範囲はa以上b以下なので、差を求めるにはa-1を使う
p f(b,x) - f(a-1,x)

Measured memory_bytes: 3836
#include<cstdio>
#include<iostream>
#include<cstring>

int main() {
    long long n,a,b; 
    std::cin >> n >> a >> b;
    long long ans = n / (a + b) * a;
    n %= (a + b);
    if(n <= a) ans += n;
    else ans += a;
    std::printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

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

int main () {
    int k;
    cin >> k;
    queue<ll> q;
    
    for (int i =1; i < 10; ++i){
        q.push(i);
    }
    rep(i,k-1){
        ll s = q.front();
        q.pop();
        ll d = s%10;
        if (d > 0) q.push(s*10 + d-1);
        q.push(s*10 + d);
        if (d < 9) q.push(s*10 + d+1);
    }
    cout << q.front() << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a, count = 0;
  vector<int> button(N);
  for (int i=0; i < N; i++) {
    cin >> a;
    button.at(i) = a - 1;
  }
  int now = 0;
  for (int i=0; i < N; i++) {
    if (now == 1 ) {
      cout << count << endl;
      break;
    }
    if (i == N - 1) {
      cout << -1 << endl;
      break;
    }
    now = button.at(now);
    count++;
  }
}

Measured memory_bytes: 768
import java.util.*;

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

    long x = sc.nextLong();
    long ans = 0;

    if(x >= 500){
      ans += (x / 500) * 1000;
    }

    if(x % 500 >= 5){
      ans += ((x % 500) / 5) * 5;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 22740
x1, y1, x2, y2 = map(int,input().split())

dx = abs(x1-x2)
dy = abs(y1-y2)
if x1>x2 and y1>=y2 :
    print(x2+dy,y2-dx,x1+dy,y1-dx)
elif x1>=x2 and y1<y2 :
    print(x2-dy,y2-dx,x1-dy,y1-dx)
elif x1<=x2 and y1>y2 :
    print(x2+dy,y2+dx,x1+dy,y1+dx)
elif x1<x2 and y1<=y2 :
    print(x2-dy,y2+dx,x1-dy,y1+dx)

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

int n;
int par[100010];
int Rank[100010];

void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        Rank[i] = 0;
    }
}
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}
void unit(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return;

    if (Rank[x] < Rank[y])
    {
        par[x] = y;
    }
    else
    {
        par[y] = x;
        if (Rank[x] == Rank[y])
            Rank[x]++;
    }
}
bool same(int x, int y)
{
    return find(x) == find(y);
}

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

    int m;
    cin >> n >> m;
    vector<int> cnt[100010];
    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int a;
            cin >> a;
            a--;
            cnt[a].push_back(i);
        }
    }
    init(n);
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < cnt[i].size(); j++)
        {
            unit(cnt[i][0], cnt[i][j]);
        }
    }
    bool f = true;
    for (int i = 0; i < n; i++)
    {
        f = f && same(0, i);
    }
    if (f)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 4736
a,b,k = map(int,input().split(' '))
cnt=0
if a>b:
    max=a
else:
    max=b
for i in range(max,0, -1):
   # print(i)
    if (a%i==0) and (b%i==0):
        cnt+=1
    #    print(i)
    if cnt==k:
        print(i)
        break

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

using namespace std;

const int maxD = 1 << 9, maxQ = 100009, maxN = (1 << 18) + 9;
int maxL, N, Q, v[maxN], w[maxN], id[20], ans[maxQ];
vector < int > dp;
vector < pair < int, int > > qr[maxN];

void df0 (int nod)
{
    if (nod >= maxD)
    {
        if (!qr[nod].empty ())
        {
            int nr = 1;
            id[0] = nod;
            while (id[nr - 1] / 2 >= maxD)
                id[nr] = id[nr - 1] / 2, nr ++;
            for (auto q : qr[nod])
            {
                int L = q.first, pos = q.second;
                for (int msk = 0; msk < (1 << nr); msk ++)
                {
                    int tV = 0, tW = 0;
                    for (int i=0; i<nr; i++)
                        if (msk & (1 << i))
                            tV += v[id[i]],
                            tW += w[id[i]];
                    if (tW <= L && dp[L - tW] + tV > ans[pos])
                        ans[pos] = dp[L - tW] + tV;
                }
            }
        }
        if (nod * 2 <= N)
            df0 (nod << 1);
        if (nod * 2 < N)
            df0 (nod << 1 | 1);
        return ;
    }
    vector < int > old = dp;
    for (int i=w[nod]; i<=maxL; i++)
        if (old[i - w[nod]] + v[nod] > dp[i])
            dp[i] = old[i - w[nod]] + v[nod];
/*    printf ("%d: ", nod);
    for (int i=0; i<=maxL; i++)
        printf ("(%d, %d) ", i, dp[i]);
    printf ("\n");*/
    for (auto q : qr[nod])
    {
//        printf ("%d -> (%d, %d)\n", q.second, q.first, dp[q.first]);
        ans[q.second] = dp[q.first];
    }
    if (nod * 2 <= N)
        df0 (nod << 1);
    if (nod * 2 < N)
        df0 (nod << 1 | 1);
    dp = old;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d %d", &v[i], &w[i]);
scanf ("%d", &Q);
for (int i=1; i<=Q; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    if (y > maxL)
        maxL = y;
    qr[x].push_back ({y, i});
}
dp = vector < int > (maxL + 2, 0);
df0 (1);
for (int i=1; i<=Q; i++)
    printf ("%d\n", ans[i]);
return 0;
}


Measured memory_bytes: 18924