akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  string S; cin >> S;
  set<char> st;
  map<char,int> mp;
  rep(i,4){
    st.insert(S[i]);
    mp[S[i]]++;
  }
  bool flag=true;
  for(auto v:st){
    if(mp[v]!=2) flag=false;
  }
  if(flag)
    cout << "Yes" <<endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int x,y,z;
  int i,j,k;

  scanf("%d %d %d",&x,&y,&z);

  if(x<y)
  {
    if(y<z)
    {
      i=x;
      j=y;
      k=z;
    }
    else
    {
      if(x<z)
      {
        i=x;
        j=z;
        k=y;
      }
      else
      {
        i=z;
        j=x;
        k=y;
      }
    }
  }

  else
  {
    if(x<z)
    {
      i=y;
      j=x;
      k=z;
    }
    else
    {
      if(y<z)
      {
        i=y;
        j=z;
        k=x;
      }
      else
      {
        i=z;
        j=y;
        k=x;
      }
    }
  }

  printf("%d %d %d\n",i,j,k);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]+a[1]==a[2])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define max 300000

typedef struct process{
  char name[256];
  int time;
} p;

int  head = 0, tail = 0, n;
p Q[max+1];

void enqueue(p);
p dequeue(void);

int main(){
  int i, q, temp, passage = 0;
  p dq;

  scanf("%d%d", &n, &q);

  head = 1; 
  tail = n + 1;

  for(i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
  }

  while( !(tail == head)){
    p dq = dequeue();
    if(q > dq.time)   temp = dq.time;
    else               temp = q;
    passage += temp;
    dq.time -= temp;
    if(dq.time > 0)   enqueue(dq);
    else                     printf("%s %d\n", dq.name, passage);
  }
      
  return 0;
}

void enqueue(p x){
  Q[tail] = x;
  if(tail + 1 == max)    tail = 0;
  else                           tail++;
}

p dequeue(void){
  p x = Q[head];
  if(head + 1 == max)    head = 0;
  else                              head++;
  return x;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end(), greater<int>());
    int ai = a.at(0);
    int aj = 0, min_dist = INT_MAX;
    for (int j = 1; j < n; j++)
    {
        int dist = abs(ai - 2 * a.at(j));
        aj = (dist < min_dist) ? a.at(j) : aj;
        min_dist = (dist < min_dist) ? dist : min_dist;
    }
    cout << ai << " " << aj << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define rep(i,n) for(int (i)=0;(i)<n;(i)++)
#define read(n) scanf("%d",&n);
#define readll(n) scanf("%lld",&n);
#define readdb(n) scanf("%lf",&n);
#define readch(n) scanf("%c",&n);
#define readstr(n) scanf("%s",n);
#define test printf("test\n");
#define init(n) memset(n,0,sizeof(n));

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
typedef struct p1{
	int first,second;	
}p; 
bool cmp (p a , p b){
	return a.first>b.first;
}
double qpow(double a, ll b) {
      double res = 1;
      while(b) {
          if (b & 1) res = res * a;
          a = a * a;
         b >>= 1;
     }
     return res;
}
ll C(ll n,ll x)
{
	ll ans = 1;
	for(ll i = n , j = 1 ; i >= n-x+1 ; i -- , j ++){
		ans *= i ;
		ans /= j ;
	}
	return ans;
}
int main(){
	int n , t;
	read(n);
	read(t);
	int mmin = (int)1e9;
	for(int i = 0 ; i < n ; i ++){
		int a , b;
		read(a);
		read(b);
		if(b <= t){
			mmin = min(mmin,a);
		}
	}
	if(mmin == 1e9) printf("TLE");
	else{
		printf("%d",mmin);
	}
	
	
	
	
	
	
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 return 0; 
}












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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}



int main(void)
{
  string s;
  cin >> s;
  s += "ooooooooooooooo";
  int cnt = 0;
  REP(i, 15) {
    cnt += (s[i]=='o'?1:0);
  }
  cout << (cnt>=8?"YES":"NO") << endl;
}


Measured memory_bytes: 256
from collections import Counter
from copy import deepcopy

s = input()
c = Counter(list(s))

lS = len(set(list(s)))

if lS == 1:
    print(0)
    exit()
if lS == len(s):
    print(len(s) // 2)
    exit()
else:
    maxN = len(s)
    for key in c:
        ss = list(s)
        count = 0
        # print(">", key)
        # print(ss)
        while True:
            count += 1
            new_ss = []
            for j in range(len(ss) - 1):
                if ss[j] == key or ss[j + 1] == key:
                    new_ss.append(key)
                else:
                    new_ss.append(ss[j])
            # print(new_ss)
            ss = deepcopy(new_ss)
            if len(set(new_ss)) == 1:
                break
        # print(">", key, count)
        maxN = min(maxN, count)
    print(maxN)

Measured memory_bytes: 46140
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll y[101010];
ll a[101010];
ll k[101010];
ll b[101010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin>>S;
    rep(i,0,3){
        if(S[i]==S[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}


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

const int MAX_N = 1e5 + 5, MOD = 1e9 + 7;
int n;
int dp[2][MAX_N];
vector <int> G[MAX_N];

int _sum (int a, int b) {
	int c = a + b;
	if (MOD <= c)
		c -= MOD;
	
	return c;
}

int _mul (int a, int b) {
	int c = 1LL * a * b % MOD;
	return c;
}

void dfs (int v, int p = 0) {
	int res1 = 1, res2 = 1;
	for (int u: G[v])
		if (u != p) {
			dfs(u, v);
			res1 = _mul(res1, _sum(dp[0][u], dp[1][u]));
			res2 = _mul(res2, dp[0][u]);
		}

	dp[0][v] = res1;
	dp[1][v] = res2;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;

		G[v].push_back(u);
		G[u].push_back(v);
	}

	dfs(0);

	cout << _sum(dp[0][0], dp[1][0]);
	return 0;
}

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

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;

    int N = S.size();
    vector<int> r(N,0), l(N,0);
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if(S[i] == 'R'){
            cnt++;
        } else {
            r[i] = cnt;
            cnt = 0;
        }
    }
    cnt = 0;
    for (int i = N-1; i >=0; i--)
    {
        if(S[i] == 'L'){
            cnt++;
        } else {
            l[i] = cnt;
            cnt = 0;
        }
    }

    for (int i = 1; i < N; i++)
    {
        if(r[i] > 0){
            int r_i = r[i];
            r[i] = r[i]/2;
            r[i-1] = r_i - r[i];
        }
    }

    for (int i = N-2; i >= 0; i--)
    {
        if(l[i] > 0){
            int l_i = l[i];
            l[i] = l[i]/2;
            l[i+1] = l_i - l[i];
        }
    }
    
    for(int i = 0; i < N; i++){
        cout << l[i] + r[i] <<' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4308
#define min(a,b) ((a)<(b)?(a):(b))
#define M 16
int m[M][M+1];
int a[1<<M];
int main(){
	int N,i,j,k;
	for(;scanf("%d",&N),N;printf("%d\n",a[(1<<N)-1])){
		for(i=0;i<N;i++)for(j=0;j<=N;j++)scanf("%d",m[i]+j);
		for(i=1;i<1<<N;i++)a[i]=1<<30;
		for(i=0;i<1<<N;i++)for(j=0;j<N;j++)if(((i>>j)&1)==0){
			int x=m[j][0];
			for(k=0;k<N;k++)if(((i>>k)&1)!=0)x=min(x,m[j][k+1]);
			a[i|(1<<j)]=min(a[i|(1<<j)],a[i]+x);
		}
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

bool Solve() {
    int H, W, N;
    cin >> H >> W >> N;

    using P = pair<int, int>; // 行，列
    P s;
    cin >> s.first >> s.second;

    string S, T;
    cin >> S >> T;

    P h(1, W), v(1, H);
    for (int i = N - 1; 0 <= i; --i) {
        if (T[i] == 'U') v.second = min(H, v.second + 1);
        else if (T[i] == 'D') v.first = max(1, v.first - 1);
        else if (T[i] == 'L') h.second = min(W, h.second + 1);
        else if (T[i] == 'R') h.first = max(1, h.first - 1);

        if (S[i] == 'U') ++v.first;
        else if (S[i] == 'D') --v.second;
        else if (S[i] == 'L') ++h.first;
        else if (S[i] == 'R') --h.second;

        if (h.second < h.first || v.second < v.first) return false;
    }

    bool can_stay = (v.first <= s.first && s.first <= v.second)
        && (h.first <= s.second && s.second <= h.second);

    return can_stay;
}

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

    if (Solve()) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 920
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    int H, W;
    cin >> H >> W;

    vector<vector<char> > a(H+2,vector<char>(W+2));

    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i <= H+1; ++i) {
        for (int j = 0; j <= W+1; ++j) {
            if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
                if (j == W + 1) {
                    cout << "#" << endl;
                }
                else {
                    cout << "#";
                }
            }
            else {
                cout << a[i][j];
            }
        }
    }

}

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

int n,ans,s[100];

char c;

int main()
{
	while(1)
	{
		c=getchar();
		if('A'<=c&&c<='Z')
			s[++n]=c=='A'||c=='G'||c=='T'||c=='C';
		else break;
	}
	for(int i=1;i<=n;i++)
		if(s[i])
			s[i]+=s[i-1],ans=max(ans,s[i]);
	cout<<ans;	
	return 0;
}

Measured memory_bytes: 256
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        mut k: usize,
    }
    let mut q: VecDeque<usize> = VecDeque::new();
    for i in 1..=9 {
        q.push_back(i);
    }
    while let Some(qi) = q.pop_front() {
        k -= 1;
        if k == 0 {
            println!("{}", qi);
            return;
        }
        let f = qi % 10;
        let n = qi * 10 + f;
        if f != 0 {
            q.push_back(n - 1);
        }
        q.push_back(n);
        if f != 9 {
            q.push_back(n + 1);
        }
    }
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    cout << a * (n/(a+b)) + min(n%(a+b), a) << endl;
}

Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int> >;
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const double PI = acos(-1.0);
#pragma endregion
// cout << fixed << setprecision(14);

int main() {
    int K;
    cin >> K;
    rep(i, K) { cout << "ACL"; }
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define memo(a,v) memset(a,v,sizeof(a))
#define all(v) (v.begin(), v.end())
#define sar(a,n) ll a[n];for(i=0; i<n; i++)cin>>a[i] //*declare* and scan array
#define pars(a,n) for(ll i=0; i<n; i++)cout<<a[i]<<" " //prints array with spaces between the elements
#define parl(a,n) for(ll i=0; i<n; i++)cout<<a[i]<<"\n" //prints array with new line between the elements
#define debug(x) cout << '>' << #x << ':' << x << endl
#define debuga() cout<<"AAAAA\n"
#define debugb() cout<<"BBB\n"
#define rep(n) for (ll i=0; i<n; i++)
#define elif else if
#define eb emplace_back
#define pb push_back
#define bitcount __builtin_popcount
using namespace std;
using ll = long long;

ll fastpow(ll a, ll p, ll mod){ll ans=1; a%=mod; for(; p; p>>=1){ if(p&1) ans=ans*a%mod; a=a*a%mod;} return ans;}

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int>s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if (s.size() == 2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "rt", stdin);
    //     freopen("output.txt", "wt", stdout);
    // #endif
    
    fastIO;
    int T;
    T=1;
    // cin>>T;
    for (int tt = 1; tt <= T; tt++){
        // cout << "Case #" << tt << ": ";
        solve();
    }
	// your code goes here
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

class Main {public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		Queue<String> name = new ArrayDeque<>();
		Queue<Integer> time = new ArrayDeque<>();
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		for(int i = 0; i < n; i++) {
			name.add(sc.next());
			time.add(sc.nextInt());
		}
		
		int t = 0;
		while(!name.isEmpty()) {
			String tmpname = name.poll();
			int tmptime = time.poll();
			
			if(tmptime - q <= 0) {
				t += tmptime;
				System.out.println(tmpname + " " + t);
			}else {
				t += q;
				name.add(tmpname);
				time.add(tmptime - q);
			}
		}
	}
}


Measured memory_bytes: 72464
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  ll z=0,k,n,m,h,w,ans=0,sum=0,Max=-1,Min=1e9+1;
  bool ok = true;
  string s,t,r;
  cin >> k >> n;
  VI a(n),b(n); 
  rep(i,n) {
    cin >> a[i];
  }
  rep(i,n-1){
    b[i] = a[i+1]-a[i];
  }
  b[n-1] = k - a[n-1] + a[0];
  rep(i,n){
    chmax(Max,b[i]);
  }
  cout << k-Max << endl;
  return 0;
}

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

int a[111111];
int n,now;
long long ans;

int main()
{
   
    scanf("%d",&n);
    
    
    for (int i = 0; i < n; ++i){
        scanf("%d",&a[i]);
    }
    ans = a[0]-1;
    now =2;
    for (int i = 1; i < n; ++i){
        if(a[i]<now) continue;
        if(a[i]==now) {
            now++;
            continue;
        }
        ans= ans+ (a[i]-1)/now;
    }
    cout <<ans <<endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int a[SIZE],p[SIZE],d[SIZE],an[SIZE];
set<int>D,U,H;
VI e[SIZE];
int main()
{
	DRII(N,K);
	REPP(i,1,N+1)
	{
		RI(a[i]);
		p[a[i]]=i;
	}
	int rr=1;
	D.insert(N+1);
	D.insert(0);
	REPP(i,1,N+1)
	{
		if(i-K>0) D.erase(a[i-K]);
		set<int>::iterator it;
		it=D.lower_bound(a[i]);
		if(*it!=N+1)d[i]++,e[p[*it]].PB(i);
		it--;
		if(*it!=0)d[p[*it]]++,e[i].PB(p[*it]);
		D.insert(a[i]);
	}

	REPP(i,1,N+1)  if(d[i]==0)H.insert(i);
	REP(kk,N)
	{
		int x=*H.rbegin();
		H.erase(x);
		an[x]=N-kk;
		REP(i,SZ(e[x]))
		{
			d[e[x][i]]--;
			if(!d[e[x][i]])  H.insert(e[x][i]);
		}
	}

	for(int i=1; i<=N; i++)printf("%d%c",an[i],i<N?' ':'\n');

	return 0;
}


Measured memory_bytes: 82048
#include <iostream>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  if (s[1] == s[2] && (s[0] == s[1] || s[2] == s[3])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std; 

int a[1000];

int main() 
{ 
	int n;
	cin>>n;
	for (int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	int mx=a[0];
	int mn=a[0];
	for (int i=0; i<n; i++)
	{
		if (a[i]>mx)
		{
			mx=a[i];
		}
		if (a[i]<mn)
		{
			mn=a[i];
		}
	}
	cout<<mx-mn;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

const int N = 200005;
vector<int> sc;
int n, q;
vector<vector<int> > G(N);

void dfs(int v, int p) {
  for (int nv : G[v]) {
    if (nv == p) continue;
    sc[nv] += sc[v];
    dfs(nv, v);
  }
}
void solve() {
  cin >> n >> q;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].eb(b);
    G[b].eb(a);
  }

  sc.resize(n);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    sc[p] += x;
  }
  
  dfs(0, -1);
  cout << sc << endl;
}


Measured memory_bytes: 23552
#include<stdio.h>
#include<algorithm>
using namespace std;
const int MAX=100000;
int main()
{int n;
scanf("%d",&n);
int i,j,count;
int xr[MAX];
for(i=0;i<n;i++)
{scanf("%d",&xr[i]);
}
sort(xr,xr+n);
count=n;
i=0;
while(i<n)
{if(xr[i+1]==xr[i])
{count=count-2;
i=i+2;
}
else i++;
}
printf("%d\n",count);
return 0;
 } 

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  int H, W, h, w;
  std::cin >> H >> W;
  std::cin >> h >> w;
  std::cout << W * H - (h * W + w * H - h * w) << '\n';
  return 0;
}

Measured memory_bytes: 504
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  // val ar = new Array[Int](N)

  val lpq = new PriorityQueue[Int]()
  val rpq = new PriorityQueue[Int]()(Ordering.Int.reverse)
  var lnum = 0
  var rnum = 0
  var handFlag = false
  var hand: Int = 0

  var lcnt = 0L
  var rcnt = 0L

  var ans = 0L

  val Q = in.next().toInt
  for (_ <- 1 to Q) {
    val c = in.next().toInt

    if (c == 1) {
      val a, b = in.next().toInt

      ans += b

      if (!handFlag) {
        hand = a
        handFlag = true
      }
      else {
        if (a == hand) {
          if (lnum < rnum) {
            lnum += 1
            lpq.enqueue(a)
            lcnt += a
          }
          else {
            rnum += 1
            rpq.enqueue(a)
            rcnt += a
          }
        }
        else if (a < hand) {
          if (lnum <= rnum) {
            lnum += 1
            lpq.enqueue(a)
            lcnt += a
          }
          else {
            rnum += 1

            rpq.enqueue(hand)
            rcnt += hand

            lpq.enqueue(a)
            lcnt += a

            hand = lpq.dequeue()
            lcnt -= hand
          }
        }
        else if (a > hand) {
          if (lnum >= rnum) {
            rnum += 1
            rpq.enqueue(a)
            rcnt += a
          }
          else {
            lnum += 1

            lpq.enqueue(hand)
            lcnt += hand

            rpq.enqueue(a)
            rcnt += a

            hand = rpq.dequeue()
            rcnt -= hand
          }
        }
      }
    }
    else if (c == 2) {
      if (lnum > rnum) {
        rpq.enqueue(hand)
        rcnt += hand

        hand = lpq.dequeue()
        lcnt -= hand

        lnum -= 1
        rnum += 1
      }


      var hoge = ans
      // println(hand, ncnt, pcnt)

      hoge += Math.abs(rcnt - (hand.toLong * rnum))
      hoge += Math.abs(hand.toLong * lnum - lcnt)
      
      pw.println(s"$hand $hoge")
    }
  }

  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 77888
#include <bits/stdc++.h>
using namespace std;
string s, t, b = "~";
bool isok(string a1, string a2){
	for (int i = 0;i < a1.size();i++){
		if(a1[i] != '?' && a1[i] != a2[i]) return false;
	}
	return true;
}
int main(){
	cin >> s >> t;
	for (int i = 0;i <= (int)s.size()-(int)t.size();i++){
		string u = s.substr(i, t.size());
		if(isok(u, t) == true) {
			string v = s;
			for (int j = i;j < i+t.size();j++) v[j] = t[j-i];
			for (int j = 0;j < i;j++) {
				if(v[j] == '?') v[j] = 'a';
			}
			for (int j = i+t.size();j < v.size();j++){
				if(v[j] == '?') v[j] = 'a';
			}
			b = min(b, v);
		}
	}
	if(b == "~") cout << "UNRESTORABLE" << endl;
	else cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		double w = scn.nextDouble();
      	double h = scn.nextDouble();
      	double x = scn.nextDouble();
      	double y = scn.nextDouble();
      	double ans = w*h/2;
      	int check = 0;
      	if(x==w/2 && y==h/2) check = 1;
      	System.out.println(ans + " " + check);
	}
}


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

int main(){
    int n;
    cin >> n;
    //int ans = 0;
    vector<int> a(1e6+1);
    rep(i,1e6+1) a.at(i)=0;
    set<int> s;
    rep(i,n){
        int b;
        cin >> b;
        if(s.count(b)) a.at(b)++;
        s.insert(b);
    } 
    for(int i=1; i<=1e6; i++){
        if(s.count(i)>=1){
            for(int j=i; j<=1e6; j+=i){
                a.at(j)++;
            }
        }
    }
    int ans = 0;
    for(int i=1; i<=1e6; i++){
        if(s.count(i)>=1){
            if(a.at(i) == 1){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 16252
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 1005

int main(){

    string s;
    cin >> s;

    if(s.length() == 2 && s[0] == s[1]){
        cout << "1 2" << endl;
        return 0;
    }

    ll first,last;
    REP(i,s.length()-2){

        string t = s.substr(i,3);
        map<char,int> mp;
        REP(j,t.length()){
            mp[t[j]]++;
        }
        for(auto itr:mp){
            if(itr.second >= 2){
                first = i+1;
                last = i+1+2;
                cout << first << " " << last << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1" << endl;

    return 0;
}

Measured memory_bytes: 512
j,a['   '],s,z=1e6;main(i){for(;++i<998;)if(!a[i])for(j=i*i;a[j]=j<z;j+=i);for(i=1;++i<z||~scanf(s="%d\n",&j)&&printf(s,a[j]);a[i]=s+=!a[i]);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++)
    {
        ll l=i*(i-1)/2;
        ll r=(n+n-i+1)*i/2;
        ans=(ans+r-l+1)%mod;
    }
    cout<<ans;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn=1e5;
int n,t,x,m[103];
char c[11];
int main(){
	cin>>n>>x;
	for(int i=1;i<=n;i++){
		cin>>m[i];
		t+=m[i];
	}
	sort(m+1,m+1+n);
	n+=(x-t)/m[1];
	printf("%d\n",n);
}




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

int main()
{
	int N, M, count = 0,now;
	//string S;
	cin >> N >> M;
	vector<int> H(N),ma(N);
	rep(i, 0, N)
	{
		cin >> H[i];
	}
	rep(i, 0, M)
	{
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		ma[a] = max(ma[a], H[b]);//ノードAに対するノードBの中における最大値
		ma[b] = max(ma[b], H[a]);//ノードBに対するノードAの中における最大値
	}
	rep(i, 0, N)
	{
		if(H[i] > ma[i])
		++count;
	}
	cout << count << endl;
}

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

using namespace std;

int main() {
	cin.tie(0);
	cin.sync_with_stdio(0);
	
	int a, b, c;
	cin >> a >> b >> c;
	if((a==5 and b==5 and c==7) or (a==5 and b==7 and c==5) or (a==7 and b==5 and c==5)) cout << "YES" << '\n';
	else cout << "NO" << '\n';
}

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

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

    long long x = min(B-1,N);

    long long ans = 0;
    ans = A*x/B;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3576
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('e1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    s = list(map(int, read_str()))
    n = len(s)
    if s[0] != 1:
        return -1
    if s[n - 1] != 0:
        return -1
    for i in range(n - 1):
        if s[i] != s[n - 2 - i]:
            return -1
    x = [i for i in range(n) if s[i] == 1]
    k = len(x)
    body = list(range(1, k + 2))
    res = [[body[i], body[i + 1]] for i in range(k)]
    p = k + 2
    for j in range(1, k):
        for l in range(x[j] - x[j-1] - 1):
            edge = [body[j], p]
            p += 1
            res.append(edge)
    return res


def main():
    res = solve()
    if res == -1:
        print(res)
        return
    for edge in res:
        print(*edge)


if __name__ == '__main__':
    main()


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

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

#define MASK 2001
#define MOD 1000000007
#define FACT_MAX 1000000

LL fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }

  long long div(long long n1,long long n2){
    return n1*power(n2,mod-2)%mod;
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0;
    if(k==n || k==0) return 1;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};


int n;
LL a[200000],b[200000];
LL dp[4003][4003];

void dump(){
  REP(i,5){
    REP(j,5){
      cerr<<dp[MASK-2+i][MASK-2+j]<<" ";
    }
    cerr<<endl;
  }
  cerr<<endl;
}

int main(){
  cin>>n;
  REP(i,n)
    cin>>a[i]>>b[i];
  REP(i,n){
    dp[MASK-a[i]][MASK-b[i]]++;
    dp[MASK+a[i]][MASK+b[i]]++;
  }
  LL ret=0;
  FOR(i,1,4003){
    FOR(j,1,4003){
      if(i>MASK&&j>MASK){
	ret=(ret+dp[i][j]*(dp[i-1][j]+dp[i][j-1]))%MOD;
	dp[i][j]=0;
      }
      dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%MOD;
    }
  }
  Combinatrics comb;
  REP(i,n){
    ret=(MOD+ret-comb.nck((LL)(2*a[i]+2*b[i]),(LL)(2*a[i])))%MOD;
  }
  ret=comb.div(ret,2LL);
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 136320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b;
  cin >> a >> b;
  cout << a*a-b <<endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
# print(n, s)
ans = 0

for i in range(1000):
  num = '{:03}'.format(i)
  num_i = 0
  for j in range(n):
    if num[num_i] == s[j]:
      num_i += 1
      if num_i > 2:
        # 生成可能
        ans += 1
        break

print(ans)

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

using namespace std;
typedef long long ll;
typedef long double ld;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

//const ll MOD = 1e9+7;
//const ll MOD = 998244353;
//const ll MAX = 3e5+1;
//const ll INF = 1e20;
//const ld PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int K; in(K);
    vector<ll> A(K);
    rep(i, K) in(A[i]);
    ll l, r;
    l = r = 2;
    ll border;
    for (int i=K-1; i>=0; i--) {
        border = r / A[i] * A[i];
        if (border < l) {
            out(-1);
            exit(0);
        }
        l = (l + A[i] - 1) / A[i] * A[i];
        r = r / A[i] * A[i] + A[i] - 1;
    }
    cout << l << ' ' << r << endl;

    return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**7)
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
 
    def root(self, i):
        if self.parent[i] == i:
            return i
        else:
            self.parent[i] = self.root(self.parent[i])
            return self.parent[i]
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j):
        i = self.root(i)
        j = self.root(j)
        self.parent[j] = i
N, M = map(int, input().split())
tree = UnionFind(N)
for _ in range(M):
    x, y, z = map(int, input().split())
    tree.union(x-1, y-1)
for i in range(N):
    tree.root(i)
print(len(set(tree.parent)))

Measured memory_bytes: 13164
#include<stdio.h>

int main(void){
    unsigned long n,m;
    scanf("%ld %ld", &n, &m);

    unsigned long l[n], r[m], min=1, max=n, num=n;
    for(long i=0; i<m; i++){
        scanf("%ld %ld", &l[i], &r[i]);
        
        if(l[i]>min) min = l[i];
        if(r[i]<max) max = r[i];

        if(min > max) break;
    }
    if(min > max) num = 0;
    else num = max - min +1;

    printf("%ld\n", num);
    return 0;
}

Measured memory_bytes: 1664
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let ship: Vec<(usize,usize)> = (0..m).map(|_| (read(),read())).collect();
    let mut map = HashMap::new();


    for i in ship.iter(){
        if i.0 == 1 {
            let count = map.entry(i.1).or_insert(0);
            *count += 1;
        }
        if i.1 == n {
            let count = map.entry(i.0).or_insert(0);
            *count += 1;
        }
    }

    let mut ans = false;
    for (_key,value) in map.iter() {
        if *value >= 2{
            ans = true;
        } 
    }

    println!("{}",if ans {"POSSIBLE"}else{"IMPOSSIBLE"});


}


Measured memory_bytes: 21264
import sys
readline = sys.stdin.readline

def solve():
    X, N = map(int, readline().split())
    P = list(map(int, readline().split()))

    a = set(P)

    for i in range(1000):
        if not X - i in a:
            print(X - i)
            break
        
        if not X + i in a:
            print(X + i)
            break

solve()

Measured memory_bytes: 61752
#include<iostream>
using namespace std;
int max(int n,int m){
  return(n>m?n:m);
}
int main(){
  int nap; //重さ
  int n;//お宝の数
  int c = 1;
  int ans = 0;
  int ans2 = 0;
  int mv = 0; //最大の重さ
  int cach; //価値の合計
  while(cin>>nap){
    if(nap==0) break;
    cin >> n;
  int so[nap+1]; //総数
  int kach[n]; //価値
  int val[n]; //重さ
  char a;
  for(int i=1;i<=nap;i++){ 
    so[i] = -1;
    so[0] = 0;
  }
  for(int i=0;i<n;i++){
    cin >> kach[i] >> a >> val[i];
    mv = nap - val[i];
    for(int j=mv;j>=0;j--){
      if(so[j]!=-1){
	cach = kach[i] + so[j];
	so[val[i]+j] = max(so[val[i]+j],cach);
      }
    }
  }
  for(int i=0;i<=nap;i++){
    if(ans<so[i]){
      ans = so[i];
      ans2 = i;
    }
}    
  cout << "Case " << c++ << ':' << endl;
  cout << ans << endl << ans2 << endl;
  ans = 0;
  ans2 = 0;
}
  return 0;
}

Measured memory_bytes: 1168
#include<cstdio>
#define MAXN 4
int Ans;
int main(){
	for(int i=1;i<=MAXN;i++){
		char x;
		scanf("%c",&x);
		if(x=='+') Ans++;
		else Ans--;
	}
	printf("%d\n",Ans);
	return 0;
}

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

using namespace std;

#define rank fdskfjdlkfjkdsjfl

const int MAX_N = 100001;
int par[MAX_N];
int rank[MAX_N];
int club[MAX_N];
int repclub[MAX_N];
int N, M, K;

void init(int n) {
  for ( int i = 0; i < n; i++ ) {
    par[i] = i;
    rank[i] = 0;
    club[i] = 0;
    repclub[i] = 0;
  }
}

int find(int x) {
  if ( par[x] == x ) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(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);
}

int main()
{
  cin >> N >> M >> K;

  init(N + 1);
  
  int ans = -1;
  for ( int i = 0; i < K; i++ ) {
   
    int r, a, b;
    cin >> r >> a >> b;
    
    if ( r == 1 ) {
      int aclub = find(a);
      int bclub = find(b);
      if ( club[aclub] == 0 || club[bclub] == 0 ) {
	if ( club[aclub] ) club[bclub] = club[aclub];
	else if ( club[bclub] ) club[aclub] = club[bclub];
	unite(a, b);
	repclub[club[find(a)]] = find(a);
      } else {
	if ( !same(a, b) ) {
	  if ( ans == -1 ) ans = i; 
	}
      }
    } else {
      int aclub = find(a);
      if ( club[aclub] == 0 ) {
	if ( repclub[b] != 0 ) unite(a, repclub[b]);
	club[find(a)] = b;
	repclub[b] = find(a);
      } else {
	if ( club[aclub] != b ) {
	  if ( ans == -1 ) ans = i; 
	}
      }
    }
    /*for ( int j = 1; j <= N; j++ ) {
      cout << club[j] << " ";
    } cout << endl;

    for ( int j = 1; j <= M; j++ ) {
      cout << repclub[j] << " ";
      } cout << endl;*/
  }

  cout << ans + 1 << endl;
}

Measured memory_bytes: 4640
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
queue<pair<ll,ll>> q ;
//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

void BFS(vvc &g,vvll &cnt,int i,int j){
	if(g.at(i-1).at(j)=='.'&&cnt.at(i-1).at(j)>cnt.at(i).at(j)+1){
		cnt.at(i-1).at(j) = cnt.at(i).at(j)+1 ;
		q.push(make_pair(i-1,j)) ;
	}
	if(g.at(i+1).at(j)=='.'&&cnt.at(i+1).at(j)>cnt.at(i).at(j)+1){
		cnt.at(i+1).at(j) = cnt.at(i).at(j)+1 ;
		q.push(make_pair(i+1,j)) ;
	}
	if(g.at(i).at(j+1)=='.'&&cnt.at(i).at(j+1)>cnt.at(i).at(j)+1){
		cnt.at(i).at(j+1) = cnt.at(i).at(j)+1 ;
		q.push(make_pair(i,j+1)) ;
	}
	if(g.at(i).at(j-1)=='.'&&cnt.at(i).at(j-1)>cnt.at(i).at(j)+1){
		cnt.at(i).at(j-1) = cnt.at(i).at(j)+1 ;
		q.push(make_pair(i,j-1)) ;
	}
	if(q.empty()) return ;
	pair<ll,ll> sub = q.front() ;
	q.pop() ;
	BFS(g,cnt,sub.first,sub.second) ;
}

int main(){
	int h,w ;
	cin >> h >> w ;
	int b = 0 ;
	vvc g(h+2,vc(w+2,'#')) ;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++){ cin >> g.at(i).at(j) ; if(g.at(i).at(j)=='#') b++ ;}
	ll INF = 1000000000 ;
	vvll cnt(h+2,vll(w+2,INF)) ;
	cnt.at(1).at(1) = 1 ;
	BFS(g,cnt,1,1) ;
	if(cnt.at(h).at(w)==INF) cout << -1 << endl ;
	else cout << h*w-b-cnt.at(h).at(w) << endl ;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

constexpr ll mod = 1000000007;



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

  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<int> dp(n + 2, INF);

  dp[0] = 0;

  rep(i, n) {
    chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }

  cout << dp[n-1] << endl;

  return 0;
}


Measured memory_bytes: 1024
def f_(N, X, a, p):
    if X == 1:
        return 0
    elif X <= 1 + a[N - 1]:
        return f(N - 1, X - 1, a, p)
    elif X == 2 + a[N - 1]:
        return p[N - 1] + 1
    elif X <= 2 + 2 * a[N - 1]:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1], a, p)
    else:
        return 2 * p[N - 1] + 1
        
def f(N, X, a, p):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N - 1]:
        return f(N - 1, X - 1, a, p)
    else:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1], a, p)
        

N, X = map(int, input().split())
a = [1 for i in range(N + 1)]
p = [1 for i in range(N + 1)]
a[0] = 1;
p[0] = 1;

for i in range(1, N + 1):
    a[i] = 2 * a[i - 1] + 3
    p[i] = 2 * p[i - 1] + 1
    
print(f(N, X, a, p))

Measured memory_bytes: 3064