akhauriyash/Code-Regression huggingface dataset:
int Primejudgment(int m[], int loop);
 
int main()
{
    int n,r[10000],i,j=0,k=0,ans,count=0;
 
    scanf("%d",&n);
    for (i = 0;i < n;i++) scanf("%d", &r[i]);
     
    while (j < n) {
 
    ans= Primejudgment(r,j);
    if (ans == 1) count++;
    j++;
    ans = 0;
 
    }
    printf("%d\n",count);
    return 0;
}
 
int Primejudgment(int m[],int loop)
{
    int i;
    if (m[loop] < 2)
        return 0;
    else if (m[loop] == 2) {
     
        return 1;
    }
 
    if (m[loop] % 2 == 0)
        return 0;
 
    for (i = 3; i <= m[loop] / i; i += 2)
        if (m[loop] % i == 0)
            return 0;
 
    return 1;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

map<vector<int>, int> mp;

void init(vector<int> v) {
   queue<vector<int>> que;
   que.push(v); // 最終状態をpush
   while (que.size()) {
      vector<int> cur = que.front(); que.pop();

      int idx = find(all(cur), 0) - cur.begin();

      rep (k, 4) {
         int nx = (idx / 4) + dx[k];
         int ny = (idx % 4) + dy[k];
         if (nx < 0 || nx >= 2 || ny < 0 || ny >= 4) continue;
         int nc = nx * 4 + ny;
         vector<int> tmp = cur;
         swap(tmp[nc], tmp[idx]);
         if (mp.count(tmp)) continue;
         mp[tmp] = mp[cur] + 1;
         que.push(tmp);
      }
   }
}

int main() {
   vector<int> v(8);
   iota(all(v), 0);
   mp[v] = 0;
   init(v);

   string s;
   while (getline(cin, s)) {
      stringstream ss(s);
      vector<int> vs;
      int val;
      while (ss >> val) vs.push_back(val);
      cout << mp[vs] << endl;
   }

   return 0;
}


Measured memory_bytes: 5700
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int n , k , price[1005];
int dp[1005][1005];

int solve(int idx, int rem){
  if(rem < 0)
    return OO;
  if(idx == n){
    if(rem == 0)
      return 0;
    return OO;
  }
  int &ret = dp[idx][rem];
  if(~ret) return ret;
  int leave = solve(idx+1 , rem);
  int take = solve(idx+1 , rem-1) + price[idx];
  return ret = min(leave , take);
}

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

  scanf("%d %d", &n , &k);
  for(int i = 0 ; i < n ; ++i)
    scanf("%d", &price[i]);

  memset(dp , -1 , sizeof dp);
  printf("%d\n" , solve(0 , k));



  return 0;
}


Measured memory_bytes: 7796
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	cout << s[0] << s.size()-2 << s.back() << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<int> >a(n);
    vector<pair<long long,int> >dis(n);
    dis[0]=make_pair(0,0);
    for(int i=0;i<m;i++)
    {
        int A,B;
        cin>>A>>B;
        a[A-1].push_back(B-1);
        a[B-1].push_back(A-1);
    }
    queue<int>q;
    vector<int>vis(n);
    q.push(0);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(auto x:a[u])
        {
            if(vis[x])continue;
            vis[x]=1;
            dis[x].first=dis[u].first+1;
            dis[x].second=u;
            q.push(x);
        }
    }
    for(auto e:vis)
    {
        if(!e)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    int f=0;
    for(auto y:dis)
    {
        if(!f)
        {
            f=1;
            continue;
        }
        cout<<y.second+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 11692
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    int a[200000]={};

    int ki=0;
    for(int i=0;i<n;i++){
        int tmp;cin >> tmp;
        if(a[tmp]++==0) ki++;
    }
    sort(a,a+200000,greater<>());

    long long res=0;
    for(int i=k;i<ki;i++){
        res += a[i];
    }
    p(res)
} 

Measured memory_bytes: 1024
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
height = [max(A[:i+1]) for i in range(N)]

ans = 10**11
for i in range(2**N):
    task = []
    for j in range(N):
        if (i >> j) & 1:
            task.append(j)
    if len(task) != K:
        continue
    c = 0
    h = -1
    for t in task:
        h = max(height[t], A[t], h+1)
        c += h-A[t]
    ans = min(ans, c)
print(ans)

Measured memory_bytes: 67900
N = gets.to_i
R = Array.new(N).map{
  gets.chomp.split(" ").map(&:to_i)
}.sort_by{|x, y| -y}
B = Array.new(N).map{
  gets.chomp.split(" ").map(&:to_i)
}.sort_by{|x, y| x}

ans = 0
B.each{|x, y|
  idx = R.index{|u, v|
    u < x && v < y
  }
  if not idx.nil? then
    ans += 1
    R.delete_at(idx)
  end
}

puts ans


Measured memory_bytes: 1788
#include "bits/stdc++.h"

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) cin >> S[i];
    vector<map<char, int>> count(N, map<char,int>());
    for (int i = 0; i < N; i++) {
        for (char s : S[i]) {
            count[i][s]++;
        }
    }
    string short_s;
    for (char s = 'a'; s <= 'z'; s++) {
        int min_s = 10;
        for (int i = 0; i < N; i++) {
                    min_s = min(count[i][s], min_s);
        }
        for( int i = 0; i < min_s; i++){
            short_s += s;
        }
    }
    sort(all(short_s));
    cout << short_s << endl;
}

Measured memory_bytes: 384
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s,t = nn()
a,b = na()
u = ns()

if s == u:
    a -= 1
if t == u:
    b -= 1

print(a,b)

Measured memory_bytes: 3064
//失敗するからこそそこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/prettyprint.hpp"
#define deb(x...) cerr << "[" << #x << "] = " << x << "\n";
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

const int MOD = 1e9 + 7;
const int MAX_N = 1e6 + 5;
const long long INF = 1e12;
int dp[10][MAX_N];
int a[] = {0, 100, 101, 102, 103, 104, 105};
int main() {
	FIO

	int n;cin >> n;
	for(int i = 0; i <= 6;i++)dp[i][0] = 1;
	for(int i = 1; i <= 6;i++){
		for(int j = 1; j <= n;j++){
			if(j - a[i] >= 0)
				dp[i][j] |= dp[i][j - a[i]];
			dp[i][j] |= dp[i - 1][j];
		}
	}
	cout << dp[6][n];
	return 0;
}


Measured memory_bytes: 16640
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define RG register
using namespace std;
const int N=1e3+10;
struct node{
	int cc,tt;
}pt[N];
int n,t,minn=2e9;
inline bool cmp(node a,node b){return a.cc<b.cc;}
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;}
int main()
{
//	freopen("Time Limit Exceeded.in","r",stdin);
//	freopen(".out","w",stdout);
	n=read(); t=read();
	for(int i=1;i<=n;i++)
	{
		int a=read(), b=read();
		pt[i]=(node){a,b};
		minn=min(minn,b);
	}
	if(minn>t)
	{
		printf("TLE\n");
		return 0;
	}
	sort(pt+1,pt+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		if(pt[i].tt<=t)
		{
			printf("%d\n",pt[i].cc);
			return 0;
		}
	}
//	fclose(stdin); fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const *argv[]) {
  unsigned long long n, a, b, t, c;
  std::cin >> n >> a >> b;
  t = n / (a + b);
  c = n % (a + b);
  if(c >= a){
    std::cout << (t+1)*a << std::endl;
  }else{
    std::cout << (t*a+c) << std::endl;
  }
  return 0;
}


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

int main(){
	int n,l;
	cin >> n >> l;
	string vs[n];
	for(int i = 0; i < n; i ++) {
		cin >> vs[i];
	}
	sort(vs,vs+n,[](string a,string b){return a + b < b + a;});
	string ans;
	for(auto s: vs) ans += s;
	cout << ans << endl;

}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

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

signed main(){
    int r,D,x;
    scanf("%lld%lld%lld",&r,&D,&x);
    rep(i,10){
        x=r*x-D;
        cout<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val tmp = BooleanArray(55556)
    val primes = mutableListOf<Int>()
    
    for (i in 2..55555) {
        if (!tmp[i]) {
            primes.add(i)
            for (j in i..55555 step i) {
                tmp[j] = true
            }
        }
    }
    
    val N = readInputLine().toInt()
    
    val ans = mutableListOf<Int>()
    
    var cnt = 0
    
    for (p in primes) {
        if (p % 5 == 1) {
            ans.add(p)
            cnt++
            if (cnt == N) {
                break
            }
        }
    }

    println(ans.joinToString(" "))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 31972
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

int N;
vector<vector<bool>> a;
vector<ll> dp;

ll solve(int me, int oth)
{
	if(me == N)return 1;

	ll res = 0;
	if(dp[oth] != -1)return dp[oth];
	REP(i, N)
	{
		if((oth >> i & 1) == 1 && a[me][i])
		{
			res = (res + solve(me + 1, oth - (1 << i))) % MOD;
		}
	}
	dp[oth] = res;
	return res;
}

//メイン関数
int main()
{
	cin >> N;
	a.resize(N, vector<bool>(N));
	dp.resize(1 << N, -1);
	REP(i, N)REP(j, N)
	{
		int f;
		cin >> f;
		a[i][j] = (f == 1);
	}
	int oth = 0;
	REP(i, N)oth += (1 << i);

	cout << solve(0, oth) % MOD << endl;
	cin >> N;
	return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>

//find out the use of the below
#include <list>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    int n;
    scanf("%d", &n);
    int ve[n+1][3];
    for (int i = 1; i <= n; ++i)
        scanf("%d%d%d", &ve[i][0], &ve[i][1], &ve[i][2]);
    int dp[n+1][3];
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for (int i = 1; i <=n; ++i){
            dp[i][0] = max(dp[i-1][1]+ve[i][1], dp[i-1][2]+ve[i][2]);
            dp[i][1] = max(dp[i-1][2]+ve[i][2], dp[i-1][0]+ve[i][0]);
            dp[i][2] = max(dp[i-1][1]+ve[i][1], dp[i-1][0]+ve[i][0]);
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);
    return 0;
}
/* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



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

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    int num = 100 * r + 10 * g + b;
    if (num % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(ll, n, x);
    ll y = n-x, ans = 0;
    
    while(true){
        if(x > y) swap(x, y);
        if(x == 0) break;
        ans += y/x*x;
        y %= x;
    }

    Cout(3*ans);
}




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

 
int main(){
    int d,n;
    cin >> d >> n;
      
    if (d == 0){
      if(n == 100){
         cout << 101 << endl;}
      
      else{cout <<  n << endl;}
        }
    else if (d == 1){
      if(n == 100){
         cout << 10100 << endl;}
      
      else{ cout << n * 100 << endl;}

   }
    else if (d == 2){
      if(n == 100){
         cout << 1010000 << endl;}
       else{cout << n *10000 << endl;}
   }

    
   
}
 


Measured memory_bytes: 256
def solve():
    N, M = map(int, input().split())
    a = []
    for _ in range(M):
        a.append(int(input()))
    
    dp = [0] * (N + 1)
    dp[0] = 1
    a_ind = 0
    for i in range(1, N+1):
        if a_ind < M and i == a[a_ind]:
            a_ind += 1
            dp[i] = 0
            continue

        dp[i] += dp[i - 1]
        if i > 1:
            dp[i] += dp[i - 2]

    print(dp[N] % 1000000007)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 470648
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n;

	cin>>n;

	cout<<n/3<<endl;
}

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

using namespace std;
int main()
{
	int a,b,sum=0;
	cin >> a >> b;
	for(int i=a; i<=b; i++){
		bool flag = true; 
		if(i/10000 != i%10)
			flag = false;
		if((i/1000)%10 != (i/10)%10)
			flag = false;
		if(flag)
			sum++;
	}
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 256
a,b,c,k = map(int, input().split())

if k == 0:
    print(a-b)

else:
    if k % 2 ==0:
        ans = a-b
    else:
        ans = b-a
    if abs(ans) > 10**18:
        print("Unfair")
    else:
        print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

int main()
{
    ll N, M;
    cin >> N >> M;
    cout << (((N == 1) xor (M == 1)) ? (max(N, M) - 2) : (N - 2) * (M - 2)) << endl;
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M; ++i) cin >> A[i];

    // 1 個の場合
    if (A.size() == 1) {
        cout << A[0] << endl;
        if (A[0] > 1) {
            cout << 2 << endl;
            cout << A[0]-1 << " " << 1 << endl;
        }
        else {
            cout << 1 << endl;
            cout << 1 << endl;
        }
        return 0;
    }

    // 偶数 / 奇数
    vector<int> odd, even;
    for (int i = 0; i < A.size(); ++i) {
        if (A[i] % 2 == 1) odd.push_back(A[i]);
        else even.push_back(A[i]);
    }
    if (odd.size() > 2) {
        cout << "Impossible" << endl;
        return 0;
    }

    // 求める
    vector<int> resA;
    if (odd.size() >= 1) resA.push_back(odd[0]);
    for (int i = 0; i < even.size(); ++i) resA.push_back(even[i]);
    if (odd.size() == 2) resA.push_back(odd.back());

    vector<int> resB;
    resB.push_back(resA[0] + 1);
    for (int i = 1; i+1 < resA.size(); ++i) resB.push_back(resA[i]);
    if (resA.back() > 1) resB.push_back(resA.back() - 1);

    // 出力
    for (int i = 0; i < resA.size(); ++i) {
        if (i) cout << " ";
        cout << resA[i];
    }
    cout << endl;
    cout << resB.size() << endl;
    for (int i = 0; i < resB.size(); ++i) {
        if (i) cout << " ";
        cout << resB[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
<?php
$haveCardNum = trim(fgets(STDIN));
$cardCheckList = createCardCheckList();

for ($i = 0; $i < $haveCardNum; $i++) {
    list($mark, $num) = getSpacesByExplodeTrimInput();
    $cardCheckList[$mark][$num] = 'check';
}

foreach ($cardCheckList as $mark => $value) {
    for ($cardNum = 1; $cardNum <= 13; $cardNum++) {
        if (! isset($cardCheckList[$mark][$cardNum])) {
            echo sprintf('%s %d', $mark, $cardNum), PHP_EOL;
        }
    }
}

function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}
  
function createCardCheckList()
{
    return array(
        "S" => array_fill(1, 13, null),
        "H" => array_fill(1, 13, null),
        "C" => array_fill(1, 13, null),
        "D" => array_fill(1, 13, null)
    );
}

Measured memory_bytes: 15432
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

#define MX 8000000

bool vec[MX];

int main(){
  int n,m;
  while(cin>>m>>n, n|m){
    fill(vec, vec+MX, true);
    int cnt=0;
    int i=m;
    for(; cnt<n; i++){
      if(!vec[i])continue;
      else {
        for(int j=i*2; j<MX; j+=i) vec[j] = false;
        cnt++;
      }
    }
    while(!vec[i]) i++;
    printf("%d\n", i);
  }
  return 0;
}

Measured memory_bytes: 11024
#include<stdio.h>

int main(void){

  int a,i=0,j=0;
  int flag=0;
  scanf("%d",&a);
  if(a<0||a>100){
	printf("No");
  }else{
	for(i=0;i<9;i++){
	    for(j=0;j<9;j++){
        if((i+1)*(j+1)==a){
          flag = 1;
        	}
        }
    }
  }
  if(flag==1){
    printf("Yes");
  }else{
    printf("No");
  }
           
  return 0;
}

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

int main(){

  int a;
  char s[11];
  int b[4]={0};

  while(scanf("%d,%s",&a,s) != EOF){
    if(s[0]=='B') b[1]++;
    else if(s[0]=='O') b[3]++;
    else if(s[1]=='B') b[2]++;
    else b[0]++;
  }

  for(int i=0;i<4;i++){
    printf("%d\n",b[i]);
  }

  return 0;
}

Measured memory_bytes: 1188
n,m =map(int, input().split())
a =[list(input().split()) for i in range(m)]
ends = [0]*n
was = [0]*n
for num, kekka in a:
    num=int(num)-1
    if kekka=='AC':
        ends[num]=1
    else:
        if ends[num]!=1:
            was[num]+=1
for i in range(n):
    if ends[i]==0:
        was[i]=0
print(sum(ends), sum(was))

Measured memory_bytes: 27448
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

N, *abc = map(int, read().split())
c = abc[2 * (N - 1):]
c.sort()
graph = [[] for _ in range(N + 1)]
cnt = [0] * (N + 1)
for a, b in zip(*[iter(abc[:2 * (N - 1)])] * 2):
    graph[a].append(b)
    graph[b].append(a)

m = max(cnt)
nodes = [0] * (N + 1)
score = sum(c) - c[-1]
start = 1
nodes[start] = c.pop()
queue = deque([start])
while queue:
    V = queue.popleft()
    for v in graph[V]:
        if nodes[v] == 0:
            nodes[v] = c.pop()
            queue.append(v)

print(score)
print(' '.join(map(str, nodes[1:])))


Measured memory_bytes: 6864
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

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

int main()
{
    int a, b, c, k, ans = 0;
    cin >> a >> b >> c >> k;
    while (k > 0)
    {
        if (a > 0)
        {
            if (a >= k)
            {
                ans += k;
                a -= k;
                k = 0;
            }
            else
            {
                ans += a;
                k -= a;
                a = 0;
            }
        }
        else if (b > 0)
        {
            if (b >= k)
            {
                b -= k;
                k = 0;
            }
            else
            {
                k -= b;
                b = 0;
            }
        }
        else 
        {
            if (c >= k)
            {
                ans -= k;
                c -= k;
                k = 0;
            }
            else
            {
                ans -= c;
                k -= c;
                c = 0;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
//https://atcoder.jp/contests/abc150/tasks/abc150_a
#include <stdio.h>

int main(){
      
  int K, X;
  scanf("%d", &K);
  scanf("%d", &X);
  
  int L= 500*K;
  
  if(L<X)
    printf("No");
  else
    printf("Yes");
  
 return 0;
}

Measured memory_bytes: 1720
#include<stdio.h>
int main(void)
{
  int n,k,p,d,a[101]={0},i,j,m=0;
  scanf("%d%d",&n,&k);
  for(i=0;i<k;i++){
    scanf("%d",&p);
    for(j=0;j<p;j++){
      scanf("%d",&d);
      a[d]=1;
    }
  }
  for(i=1;i<=n;i++){
    if(a[i]==0){
      m++;
    }
  }
  printf("%d\n",m);
  return 0;
}


Measured memory_bytes: 1684
#include<stdio.h>
#include<string.h>		/* strcmp関数を使うために使用 */
#include<ctype.h>		/* tolower関数を使うために使用 */

int main(void)
{
	int i,count=0;
	char number[10]={0};
	char bun[1000]={0};

	scanf("%s",number);
	for(i = 0;i < 10;i++)
	{
		/* tolower関数:大文字を小文字に変換する関数 */
		number[i] = tolower(number[i]);

	}
	while(1)
	{
		scanf("%s",bun);
		/* strcmp関数:入力された文字が等しいなら0、左が大きければ正、右が大きければ負を返す */
		if(strcmp(bun,"END_OF_TEXT") == 0)
		{
			break;
		}
		for(i = 0;i < 1000;i++)
		{
			bun[i] = tolower(bun[i]);
		}
		if(strcmp(number,bun) == 0)
		{
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  cout<<((s[0]==s[n-1])^(n%2==0)?"Second":"First")<<endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int a, b;
    cin >> a >> b;
    if(a*b % 2 == 0){
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int top, s[1000];
	
void push(int x){
	top++;
	s[top] = x;
}
	
int pop(){
	top--;
	return s[top+1];
}
	

int main(void) {
	int a,b;
	top = 0;
	char str[100];

	while(scanf("%s",str) != EOF){
		if(str[0] == '+'){
			b = pop();
			a = pop();
			push(a+b);
		}else if(str[0] == '-'){
			b = pop();
			a = pop();
			push(a-b);
		}else if(str[0] == '*'){
			b = pop();
			a = pop();
			push(a*b);
		}else{
			push(atoi(str));
		}
		
	}
	
	printf("%d\n",pop());
	
	return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
const int maxn = 200005;
int a[maxn];
int n;
lli k;

bool can(int x){
	lli xx =0;
	for(int i=1; i <=n; i++){
		int veces = a[i]/x;
		if(a[i]%x == 0) veces--;
		xx+=veces;
	}

	return (xx <= k);
}

int main(){__
	cin >> n >> k;
	int ans = -1;

	for(int i=1; i <=n; i++){
		cin >> a[i];
		ans = max(ans,a[i]);
	}

	int l = 1, r = 1000000000;
	while( l <= r){
		int m = l + (r-l)/2;
		if(can(m)){
			ans = m;
			r = m-1;
		}
		else{
			l = m+1;
		}
	}

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



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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long long> H){
    LL ans = 0;
    LL max_h = -1;
    REP(i, N) {
        if(max_h <= H[i]) {
            ans++;
            max_h = H[i];
        }
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, std::move(H));
    return 0;
}


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

int main()
{
  typedef pair<char, int> pci;
  typedef pair<int, int> pii;
  stack<pci> s;
  stack<pii> L;
  string a;
  int A = 0, sum = 0;
  getline(cin, a);
  for(int i = 0; i < a.size(); i++){
    if(a[i] == '\\'){
      s.push(make_pair('\\', i));
    }else if(a[i] == '/'){
      if(!s.empty()){
	if(s.top().first == '\\'){
	  A += i - s.top().second;
	  if(!L.empty())
	    while(s.top().second < ((!L.empty()) ? L.top().first : 0)){
	      sum += L.top().second; 
	      L.pop();
	    }
	  L.push(make_pair(s.top().second, sum + i - s.top().second));
	  sum = 0;
	  s.pop();
	}
      }
    }
  }
  cout << A << endl;
  cout << L.size();
  stack<int> l;
  while(!L.empty()){
    l.push(L.top().second);
    L.pop();
  }
  for(int i = 0; !l.empty(); i++){
    cout << " " << l.top();
    l.pop();
  }
  cout << endl;
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
using ld = double;
using P  = complex <ld>;
const ld pi  = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P &a, const P &b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

ld dot(const P &a, const P &b) {
  return a.real() * b.real() + a.imag() * b.imag();
}

template <class iter>
std::pair <P, ld> min_ball(iter left, iter right, int seed=1333) {
  const int n = right - left;

  assert(n >= 1);
  if (n == 1) {
	  return { *left, ld(0) };
	}

  std::mt19937 mt(seed);
  std::shuffle(left, right, mt);
  // std::random_shuffle(left, right); // simple but deprecated

  iter ps = left;
  using circle = std::pair <P, ld>;

  auto make_circle_3 = [](const P &a, const P &b, const P &c) -> circle {
						 ld A = std::norm(b - c), B = std::norm(c - a), C = std::norm(a - b),
	S                          = cross(b - a, c - a);
						 P p   = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
						 ld r2 = std::norm(p - a);
						 return { p, r2 };
					   };

  auto make_circle_2 = [](const P &a, const P &b) -> circle {
						 P c   = (a + b) / (ld) 2;
						 ld r2 = std::norm(a - c);
						 return { c, r2 };
					   };

  auto in_circle = [](const P &a, const circle &c) -> bool {
					 return std::norm(a - c.first) <= c.second + eps;
				   };

  circle c = make_circle_2(ps[0], ps[1]);

  // MiniDisc
  for (int i = 2; i < n; ++i) {
	  if (!in_circle(ps[i], c)) {
		  // MiniDiscWithPoint
		  c = make_circle_2(ps[0], ps[i]);
		  for (int j = 1; j < i; ++j) {
			  if (!in_circle(ps[j], c)) {
				  // MiniDiscWith2Points
				  c = make_circle_2(ps[i], ps[j]);
				  for (int k = 0; k < j; ++k) {
					  if (!in_circle(ps[k], c)) {
						  c = make_circle_3(ps[i], ps[j], ps[k]);
						}
					}
				}
			}
		}
	}
  return c;
}

int main() {
  int n;
  cin >> n;
  vector <P> p(n);
  REP(i, n) {
	double x, y;
	cin >> x >> y;
	p[i] = P(x, y);
  }
  double ans =  sqrt(min_ball(p.begin(), p.end()).second);
  printf("%.16f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,K = II()
A = III()

r = [0]*N
l = [0]*N

for i in range(N):
    for j in range(i+1,N):
        if A[j]<A[i]:
            r[i] += 1
    for j in range(i):
        if A[j]<A[i]:
            l[i] += 1

ans = 0

for i in range(N):
    ans += r[i]*K*(K+1)//2
    ans %= mod
    ans += l[i]*(K-1)*K//2
    ans %= mod

print(ans)

Measured memory_bytes: 42588
n = int(input())
c = []
c.append(list(map(int,input().split())))
c.append(list(map(int,input().split())))
ans = 0

for i in range(n):
    x = sum(c[0][:i+1]) + sum(c[1][i:])
    if x > ans:
        ans = x

print(ans)

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

const int N=200009;
int n,a[N],b[N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int cur=1;
	for(int i=2;i<=n;i++)
		if(abs((a[n]+1)/2-a[i])<abs((a[n]+1)/2-a[cur]))
			cur=i;

	printf("%d %d\n",a[n],a[cur]);

	return 0;
}


Measured memory_bytes: 640
N = input()
S = list(input())

length = len(S)
min_num = 300000
left = 0
right = S.count("E")

for i in range(length):

  if i > 0:
    left += int(S[i - 1] == "W")

  if i < length:
    right -= int(S[i] == "E")

  if left + right < min_num:
    min_num = left + right

print(min_num)


Measured memory_bytes: 5836
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();
        System.out.println(s1.equals(u) ? (a-1) + " " + b : a + " " + (b-1));
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>

using namespace std;

/* 最大公約数 */
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

/* 最小公倍数 */
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return a / g * b;  // Be careful not to overflow
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  long long res = a[0];
  for (int i = 1; i < n; i++) {
    res = lcm(res, a[i]);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  ll N; cin>>N;
  vector<ll> vx(N), vy(N), vh(N);
  ll si = -1;
  for(int i=0; i<N; i++) {
    cin >> vx[i] >> vy[i] >> vh[i];
    if(vh[i] > 0) si = i;
  }

  ll ans_x = -1, ans_y = -1, ans_h = -1;
  for(int x = 0; x <= 100; x++) {
    for(int y = 0; y <= 100; y++) {
      ll maybe_h = vh[si] + abs(vx[si] - x) + abs(vy[si] - y);
      bool ok = true;
      for(int i = 0; i < N; i++) {
        ll distance = abs(x - vx[i]) + abs(y - vy[i]);
        if(vh[i] > 0 && maybe_h - vh[i] != distance) {
          ok = false;
        }
        if(vh[i] <= 0 && maybe_h > distance) {
          ok = false;
        }
      }

      if(ok) {
        ans_x = x; ans_y = y; ans_h = maybe_h;
      }
    }
  }

  printf("%lld %lld %lld\n", ans_x, ans_y, ans_h);
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if a%2 == 1 || b%2 == 1 || c%2 == 1 {
		fmt.Println(0)
		return
	} else if a == b && b == c && c == a {
		fmt.Println(-1)
		return
	}

	ans := math.MaxInt64
	for _, v := range []int{a + b, b + c, c + a} {
		cnt := 0
		for v%2 == 0 {
			v /= 2
			cnt++
		}
		ans = min(ans, cnt)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)




int main(){
    int n; cin>>n;
    int a=n, b=0;
    while(a){
        b+=a%10;
        a/=10;
    }
    if(n%b==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3604
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Graph{
    struct Edge{
        int cost, dest;
        Edge(int cost, int dest): cost(cost), dest(dest){ }
        ostream& operator >> (ostream& out){
            return out << '(' << cost << ':' << dest << ')';
        }
    };
    struct Node{
        vector<Edge> edges;
        ll height = 0;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    // vector<Edge> edges;
    // Graph(int nn, int en = 10): nodes(nn){
    //     edges.reserve(en);
    // }
    // void addEdge(int from, int dest, ll cost = 1){
    //     nodes[from].outEdges.emplace_back(edges.size());
    //     edges.emplace_back(from, dest, limit);
    // }
    void addEdge(int from, int dest, int cost = 1){
        nodes[from].edges.emplace_back(cost, dest);
    }
    void addEdge2(int from, int dest, int cost = 1){
        addEdge(from, dest, cost);
        addEdge(dest, from, cost);
    }
    void dfs(int idx, ll height, int from = -1){
        nodes[idx].height = height;
        for(auto& e : nodes[idx].edges){
            if(e.dest == from){ continue; }
            dfs(e.dest, height + e.cost, idx);
        }
    }
};

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        // scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        g.addEdge2(a, b, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    g.dfs(k, 0);
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        // scanf("%d %d", &x, &y);
        x--; y--;
        cout << g.nodes[x].height + g.nodes[y].height << '\n';
    }
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;
// mat dtable(M, vl(N, 0)); M行N列 のサイズで,0で初期化


const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
    ll N; cin >> N;
    // vl A(N), B(N);
    vector<pair<ll, ll>> P(N);
    REP(i, N){
        ll a, b; cin >> a >> b;
        P[i] = make_pair(a, b);
    }
    sort(ALL(P), compare_by_b);

    ll sum = 0;
    REP(i, N){
        sum += P[i].first;
        if (sum > P[i].second){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-6;
#define X real()
#define Y imag()
D dot(P a,P b) {return (conj(a)*b).X; }
D cross(P a,P b) {return(conj(a)*b).Y;}
int ccw(P a,P b,P c){
  b-=a;c-=a;
  if(cross(b,c) >EPS)return +1;
  if(cross(b,c)< -EPS)return -1;
  if(dot(b,c)< -EPS)return +2;
  if(norm(b)<norm(c))return -2;
  return 0;
}
bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}
bool isecSP(P a1,P a2,P b) {
  return !ccw(a1, a2, b);
  return abs(a1 - b) + abs(a2 - b) - abs(a2 - a1) < EPS;
}
P proj(P a1,P a2,P p){return a1+dot(a2-a1, p-a1)/norm(a2-a1)*(a2-a1);}
D distSP(P a1,P a2,P p) {
  P r=proj(a1,a2,p);
  if(isecSP(a1,a2,r))return abs(r-p);
  return min(abs(a1-p),abs(a2-p));
}
  
D distSS(P a1,P a2,P b1,P b2) {
  if (isecSS(a1,a2,b1,b2))return 0;
  return min(min(distSP(a1,a2,b1),distSP(a1,a2,b2)),min(distSP(b1,b2,a1),distSP(b1,b2,a2)));
}
int n,x,x1,y2;
double h,a[222][222];
vector<P>v[222];
main(){
  while(cin>>h>>n,h){
    r(i,222)r(j,222)a[i][j]=1e15;
    r(i,222)v[i].clear();
    v[n].push_back(P(0,0));
    v[n].push_back(P(0,1e9));
    v[n+1].push_back(P(h,0));
    v[n+1].push_back(P(h,1e9));
    r(i,n){
      cin>>x;
      while(x--){
        cin>>x1>>y2;
        v[i].push_back(P(x1,y2));
      }
    }
    r(i,n+2)r(j,n+2)r(k,v[i].size())r(l,v[j].size())
      a[i][j]=min(a[i][j],distSS(v[i][k],v[i][(k+1)%(int)v[i].size()],v[j][l],v[j][(l+1)%(int)v[j].size()]));
    r(k,n+2)r(i,n+2)r(j,n+2)a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
    printf("%.9f\n",a[n][n+1]);
  }
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, K; cin >> N >> K;
	vi h(N);
	REP(i, N) cin >> h[i];

	vi dp(N, numeric_limits<int>::max());
	dp[0] = 0;
	REP(i, N - 1) {
		FOR(j, 1, K + 1) {
			if (i + j >= N) continue;
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
		}
	}
	cout << dp[N - 1] << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 1024
n, m = map(int,input().split())
li = [list(map(int,input().split()))[1:] for i in range(m)]
p = list(map(int,input().split()))
ans = 0

for i in range(2 ** n):
    x = 0 #点灯してるかしてないか
    y = [[] for j in range(m)]
    for j in range(n):
        if ((i >> j) & 1): #フラグが立っていたら=スイッチon 
            for k in range(m):
                if j+1 in li[k]:
                    y[k].append(j+1)
    for j in range(m):
        if len(y[j]) %2 == p[j]:
            x += 1                   
    if x == m:
        ans += 1

print(ans)

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

int t[100005];
int main() {
	int n,m;
	cin>>n;
	int sum=0;
	for(int i=0; i<n; i++){
		cin>>t[i];
		sum+=t[i];
	}
	cin>>m;
	int p, x;
	while(m--){
		cin>>p>>x;
		x+=sum-t[p-1];
		cout<<x<<endl;
	}

	return 0;
}

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

int A=0,B=0,C=0;
string s;

int main()
{
    cin>>s;
    for(int i=0;i<s.size();i++)
        if(s[i]=='a')
            A++;
        else
        if(s[i]=='b')
            B++;
        else
            C++;
    if(max(max(A,B),C)-min(min(A,B),C)<=1)
        cout<<"YES";
    else
        cout<<"NO";
}


Measured memory_bytes: 512
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char s;
  int v;
};

struct Card L[MAX], R[MAX];

void merge(struct Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for( i = 0 ; i < n1 ; i++ ){
    L[i] = A[left + i];
  }
  for( i = 0 ; i < n2 ; i++ ){
    R[i] = A[mid + i];
  }
  L[n1].v = R[n2].v = SENTINEL;
  i = j = 0;
  for( k = left ; k < right ; k++){
    if( L[i].v <= R[j].v ){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

void m_sort(struct Card A[], int n, int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    m_sort(A, n, left, mid);
    m_sort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;

  x = A[r];
  i = p - 1;
  for( j = p ; j < r ; j++ ){
    if( A[j].v <= x.v ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(struct Card A[], int n ,int p, int r){
  int q;
  if( p < r ){
    q = partition(A, n, p, r);
    quickSort(A, n, p, q-1);
    quickSort(A, n, q+1, r);
  }
}

int main(){
  int i, n, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);
  for( i = 0 ; i < n ; i++){
    scanf("%s %d", S, &v);
    A[i].s = B[i].s = S[0];
    A[i].v = B[i].v = v;
  }
  m_sort(A, n, 0, n);
  quickSort(B, n, 0, n-1);

  for( i = 0 ; i < n ; i++){
    if( A[i].s != B[i].s ) stable = 0;
  }

  if( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n", B[i].s, B[i].v);
  }
  return 0;
}


Measured memory_bytes: 4012