akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define PI acos(-1)
#define de(x) cout<<#x<<'='<<x<<" , "
#define dee(x) cout<<#x<<'='<<x<<endl
#define sz(x) x.size()
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define mset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int MAXN=1e5+55;
int a[MAXN];
int N;

int main(){
    scanf("%d",&N);
    rep(i,1,N+1) scanf("%d",&a[i]);
    int cnt=0;
    if(a[N]==N) swap(a[N],a[N-1]),cnt++;
    if(a[1]==1) swap(a[1],a[2])  ,cnt++;
    rep(i,2,N){
        if(a[i]!=i) continue;
        cnt++;
        if(a[i+1]>i) swap(a[i+1],a[i]);
        else if(a[i-1]<i) swap(a[i-1],a[i]);
        else if(a[i+1]!=i) swap(a[i+1],a[i]);
        else swap(a[i-1],a[i]);
    }
    cout<<cnt<<endl;
}


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

#define ll long long
#define ull unsigned long long 

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

    for(int i=1; i<=n; ++i)
        cin >> a[i];

    int count=0;
    set<int> processed;

    int i=1;
    while(1){
        if(processed.count(i)){
            cout << -1;
            return 0;
        }
        count++;
        processed.insert(i);
        i = a[i];

        if(i == 2){
            cout <<count;
            return 0;
        }
    }
}


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

int main(){
	vector<pair<int,long long> > v;
	int n,a;
	long long b,c;
	while(cin>>n&&n){
		v.clear();
		while(n--){
			cin>>a>>b>>c;
			int index = -1;
			for(int i=0;i<v.size();i++){
				if(a==v[i].first){
					index = i;
					break;
				}
			}
			if(index==-1)v.push_back(make_pair(a,b*c));
			else v[index].second += b*c;
		}
		bool flag = false;
		for(int i=0;i<v.size();i++){
			if(v[i].second >= 1000000){
				flag = true;
				cout<<v[i].first<<endl;
			}
		}
		if(!flag)cout<<"NA\n";
	}
	return 0;
}

Measured memory_bytes: 1240
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

const int INF = 1 << 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> grid(H);
    rep(i, 0, H) cin >> grid[i];
    // いちごが出現する区間を調べる.
    int left = INF, right = -1;
    rep(i, 0, H) rep(j, 0, W) {
        if (grid[i][j] == '#') {
            left = min(left, j);
            right = max(right, j);
        }
    }
    vector<vector<int>> ans(H, vector<int>(W));
    int color = 0;
    rep(i, left, right + 1) {
        // i列目から塗っていく
        bool is_exist = false;
        rep(j, 0, H) {
            // i列目にいちごが存在するか確かめる.
            if (grid[j][i] == '#') {
                is_exist = true;
                break;
            }
        }
        if (is_exist) {
            // いちごが存在
            // 上の行にある空白を埋める.
            int start_row = 0;
            rep(j, 0, H) {
                if (grid[j][i] == '#') {
                    start_row = j;
                    break;
                }
                ans[j][i] = color + 1;
            }
            rep(j, start_row, H) {
                if (grid[j][i] == '#') {
                    ++color;
                }
                ans[j][i] = color;
            }
        }
        else {
            // いちごが存在しない場合は左側と同じ色にする.
            rep(j, 0, H) ans[j][i] = ans[j][i - 1];
        }
    }
    // いちごが存在しない両端の処理をする.
    // 左側
    rrep(i, left, 0) {
        rep(j, 0, H) ans[j][i] = ans[j][i + 1];
    }
    // 右側
    rep(i, right + 1, W) {
        rep(j, 0, H) ans[j][i] = ans[j][i - 1];
    }
    rep(i, 0, H) {
        rep(j, 0, W) cout << ans[i][j] << ' ';
        cout << endl;
    }
    return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = false;
  ll n;cin>>n;
  vector<vector<ll>>ret;
  rep(i,1,1000){
    buf+=i;
    if(n==buf){
      judge=true;
      ret.assign(i+1,vector<ll>());
      ll tmp=1;
      rrep(j,i+1,1){
        rep(o,0,j)ret[i-j].push_back(tmp+o);
        rep(o,0,j)ret[i-j+1+o].push_back(tmp+o);
        tmp+=j;
      }
    }
  }
  ans1(judge);
  if(judge){
    cout<<ret.size()<<endl;
    rep(i,0,ret.size()){
      cout<<ret[i].size() <<" ";
      debug(ret[i],ret[i].size());
    }
  }
  return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

int n;

int main()
{
    scanf("%d",&n);int ans=0;
    for (int i=1;i<=n;i++)
    {
        int x,k;scanf("%d%d",&x,&k);
        while (x%k>0) x-=((x%k-1)/(x/k+1)+1)*(x/k+1);
        ans^=x/k;
    }
    if (ans) puts("Takahashi");
    else puts("Aoki");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        String result = ":(";
        if (A <= 8 && B <= 8) {
            result = "Yay!";
        }
        System.out.println(result);
    }
}


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

int main(){
    string s;
    cin>>s;
    int n = s.length();
    if((int)s.length()&1 == 1) s.pop_back();
    while((int)s.length()){
        string part1 = s.substr(0, (((int)s.length())/2));
        string part2 = s.substr((((int)s.length())/2), (((int)s.length())/2));
        if(part1 == part2 && s.length() != n){
            cout<<(int)s.length()<<endl;
            break;
        }
        s.pop_back();
        s.pop_back();
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std ;

int main(void){
    int N,c=0,ans=0;

    cin >> N;
    
    for(int i=1; i<=N; i++) {
        c=0;
        for(int j=1; j<=i; j=j+2) {
            if(i % j == 0){
                c++;
            }
        }
        if(c == 8) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->N = $a[0];
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->A[]=$a[0];
  }
}
$key->PAIR = 0;
for($i=0;$i<$key->N;$i++) {
  $key = mkpair($i,$key);
}
function mkpair($i,$key) {
  $p = floor($key->A[$i]/2);
  $key->PAIR += $p;
  $key->A[$i]-= $p*2;
  if (isset($key->A[$i+1])) {
    $p = min($key->A[$i],$key->A[$i+1]);
    $key->A[$i]-=$p;
    $key->A[$i+1]-=$p;
    $key->PAIR += $p;
  }
  return $key;
}
printf("%d\n",$key->PAIR);


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

struct P { int x, y; };

char A[800][800];
int used[800][800];

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

int main()
{
	int H, W, K;
	P s;
	cin >> H >> W >> K;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
			if (A[i][j] == 'S') {
				s.x = i;
				s.y = j;
			}
		}
	}
	vector<P> q;
	q.push_back(s);
	used[s.x][s.y] = 1;
	int res = min(s.x, min(s.y, min(H - s.x - 1, W - s.y - 1)));
	for (int i = 0; i < K && !q.empty(); i++) {
		auto tmp = q; q.clear();
		for (auto p : tmp) {
			for (int j = 0; j < 4; j++) {
				int tx = p.x + dx[j], ty = p.y + dy[j];
				if (tx >= 0 && tx < H && ty >= 0 && ty < W && A[tx][ty] != '#' && used[tx][ty] == 0) {
					used[tx][ty] = 1;
					q.push_back((P){ tx, ty });
					res = min(res, min(tx, min(ty, min(H - tx - 1, W - ty - 1))));
				}
			}
		}
	}
	cout << ((res + K - 1) / K + 1) << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int result = 0;
    for (int i = 0; i < N; i++) {
        int t;
        cin >> t;
        result += t - 1;
    }
    cout << result << endl;
    return 0;
}


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    string s;
    cin >> s;

    sort(all(s));
    if(s[0] == s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
lines = sys.stdin.readlines()
sizes = lines[0].split(" ")
H = int(sizes[0])
W = int(sizes[1])
field = []
for line in lines[1:]:
    field.append(line.rstrip())

#print (field)
count=0
for f in field:
    for i in range(W):
        s = f[i:i+1]
        if s=="#":
            count+=1


posQ = [[0,0]]

now = [0,0]
before = [-1,0]

while(now[0]+1<H or now[1]+1<W):
    if (before==now):
        break
    #print (now)
    if now[1]+1<W:
        if field[now[0]][now[1]+1:now[1]+2] == "#":
            posQ.append([now[0],now[1]+1])
    if now[0]+1<H:
        if field[now[0]+1][now[1]:now[1]+1] == "#":
            posQ.append([now[0]+1,now[1]])
    before = now
    now = posQ[len(posQ)-1]

"""
now = [0,0]

if field[now[0]][now[1]+1:now[1]+2] == "#":
    posQ.append([now[0],now[1]+1])
if field[now[0]+1][now[1]:now[1]+1] == "#":
    posQ.append([now[0]+1,now[1]])

now = posQ[len(posQ)-1]

if field[now[0]][now[1]+1:now[1]+2] == "#":
    posQ.append([now[0],now[1]+1])
if field[now[0]+1][now[1]:now[1]+1] == "#":
    posQ.append([now[0]+1,now[1]])


"""

#print (posQ)
#print (len(posQ))
if (len(posQ)!=H+W-1):
    print("Impossible")
else:
    if (count>len(posQ)):
        print("Impossible")
    else:
        print("Possible")


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int w = in.nextInt();
		Obj[] object = new Obj[n+1];
		for (int i = 1; i < object.length; i++) {
			object[i] = new Obj(in.nextInt(), in.nextInt());
		}
		int[][] value = new int[n+1][w+1];

		for (int i = 1; i < n+1; i++) {
			for (int j = 0; j < w+1; j++) {
				if (j < object[i].weight) {
					value[i][j] = value[i-1][j];
					continue;
				}
				int a = value[i-1][j];
				int b = value[i][j-object[i].weight] + object[i].value;
				value[i][j] = Math.max(a, b);
			}
		}

		System.out.println(value[n][w]);

	}
	static class Obj {
		int value;
		int weight;

		public Obj(int v, int w) {
			value = v;
			weight = w;
		}
	}

}



Measured memory_bytes: 31024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in); 
    int H = sc.nextInt();
    int W = sc.nextInt();
    int K = sc.nextInt();
    int ans =0;
    String[] c = new String[H];
    for (int i =0; i<H; i++) {
      c[i] = sc.next();
    }
    boolean[][] cc = new boolean[H][W];
    boolean[][] cd = new boolean[H][W];
    for (int i =0; i<H; i++) {
      for (int j =0; j<W; j++) {
        if(c[i].charAt(j) == '.') cc[i][j] = false;
        if(c[i].charAt(j) == '#') cc[i][j] = true;
      }
    }
    for (int k =0; k<Math.pow(2,H+W); k++) {
      String bit = Integer.toBinaryString(k);//iをビットに変換
      int length = bit.length();
      for (int i =0; i<H+W-length; i++) {
        bit = "0" + bit;
      }
      int count =0;
      for (int i =0; i<H; i++) {
        for (int j =0; j<W; j++) {
          cd[i][j] = cc[i][j];
        }
      }
      for (int i =0; i<H; i++) {
        if (bit.charAt(i) == '1') {
          for (int j =0; j<W; j++) {
            cd[i][j] = false;
          }
        }
      }
      for (int i =H; i<W+H; i++) {
        if (bit.charAt(i) == '1') {
          for (int j =0; j<H; j++) {
            cd[j][i-H] = false;
          }
        }
      }
      for (int i =0; i<H; i++) {
        for (int j =0; j<W; j++) {
          if (cd[i][j] == true) count++;
        }
      }
      if (count == K) ans++;
    }
  System.out.println(ans);
  }
}

Measured memory_bytes: 40500
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
 
typedef long long ll;
 
 
int main(){
	int a,b;
	cin >> a >> b;
	int c = a - b*2;
	cout << max(0,c) <<endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>
//#include "vector.hh"

using namespace std;

#define debug false

int main(int argc, char *argv[]){

  unsigned long long X, Y, Z;
  int i;
  cin >> X >> Y;
  for(i = 0; ; i++){
    if(Y < (unsigned long long)pow(2, i)*X) break;
  }
  cout << i << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();

		System.out.println((H * W) + (h * w) - (h * W) - (H * w));
	}

}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    string X;
    cin >> N >> X;

    vector<int> cnt(N + 1);

    repd(i, 1, N + 1) {
        int c = i;
        while (c != 0) {
            cnt[i] += c % 2;
            c /= 2;
        }
    }

    int cnt1 = 0;
    rep(i, N) {
        if (X[i] == '1') cnt1++;
    }

    vector<int> mod01(2);
    int md = 0;
    if (cnt1 == 1) md = 1;
    ll ct0 = 1 % (cnt1 + 1), ct1 = 1 % (cnt1 - 1 + md);

    for (int i = N - 1; i >= 0; i--) {
        if (X[i] == '1') {
            mod01[0] += ct0;
            mod01[1] += ct1;
            mod01[0] %= (cnt1 + 1);
            mod01[1] %= (cnt1 - 1 + md);
        }
        ct0 *= 2;
        ct1 *= 2;
        ct0 %= (cnt1 + 1);
        ct1 %= (cnt1 - 1 + md);
    }

    vector<int> ans(N, 1);

    ct0 = 1 % (cnt1 + 1);
    ct1 = 1 % (cnt1 - 1 + md);

    for (int i = N - 1; i >= 0; i--) {
        int num;
        int res = 1;
        if (X[i] == '1') {
            num = mod01[1] - ct1;
            num %= (cnt1 - 1 + md);
            if (num < 0) num += (cnt1 - 1 + md);
        }
        else {
            num = mod01[0] + ct0;
            num %= (cnt1 + 1);
            if (num < 0) num += (cnt1 + 1);
        }
        while (num != 0) {
            num %= cnt[num];
            res++;
        }
        ans[i] = res;
        if (md == 1 && X[i] == '1') ans[i] = 0;
        ct0 *= 2;
        ct1 *= 2;
        ct0 %= (cnt1 + 1);
        ct1 %= (cnt1 - 1 + md);
    }

    rep(i, N) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5240
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int a, b, k;
	cin >> a >> b >> k;
	vector<int> x;
	eFOR1(i, 100) {
		if (a%i == 0 && b%i == 0)x.push_back(i);
	}
	int size = x.size();
	cout << x[size-k] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < double,double> pt;
typedef pair < int,int> pii;

const int N = 1e5 + 500;
const int M = 1e6 + 500;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int BASE = 31337;

int n,a[2][N];
int dp[2][N];

int main(){
    scanf("%d",&n);
    for(int i = 0;i<n;i++)
        scanf("%d",&a[0][i]);
    for(int i = 0;i<n;i++)
        scanf("%d",&a[1][i]);
    dp[0][0] = a[0][0];
    dp[1][0] = dp[0][0] + a[1][0];
    for(int i = 1;i<n;i++){
        dp[0][i] = a[0][i] + dp[0][i - 1];
        dp[1][i] = max(dp[1][i - 1], dp[0][i]) + a[1][i];
    }
    printf("%d\n",dp[1][n - 1]);
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>

struct ProcessElement
{
    std::string name;
    int time;
};

int main()
{
    int n{}, q{};
    std::cin >> n >> q;
    std::queue<ProcessElement> processes{};
    for (auto i = 0; i < n; i++)
    {
        ProcessElement p{};
        std::cin >> p.name >> p.time;
        processes.push(p);
    }
    int processing_time{};
    while (processes.size())
    {
        ProcessElement p{processes.front()};
        processes.pop();
        processing_time += std::min(q, p.time);
        p.time -= q;
        if (p.time > 0)
        {
            processes.push(p);
        }
        else
        {
            std::cout << p.name << " " << processing_time << std::endl;
        }
    }
}



Measured memory_bytes: 6348
import math

#-桁dpなる書き方に挑戦-#
#-dp[k][j][i] 先頭からi桁目まで決めたときに,
    #- 0でない要素をj個使っていて、k=0 小さいことが確定していない , k=1 確定

def solve(sN):
    dp = [[[0]*105 for _ in range(4)] for _ in range(2) ] #余分に取っておく。あとでlen(N)の要素を取り出し
    #初期条件
    dp[0][0][0]=1 #なにも決めていな状態。空集合。一致
    for i in range(len(sN)):
        for j in range(4):
            for k in range(2):
                nd = int(sN[i])#sNの今の桁をnd。これから決める桁数字をdとする
                for d in range(10):
                    ni = i+1;nj=j;nk=k
                    if d != 0: #dが0でないならnjを１つ足す
                        nj +=1
                    if nj > K:#使える0以外の数字の個数を超えていたらだめ
                        continue
                    if k ==0:#これまでの桁が一致している。
                        if d > nd:#数字が超えるからだめ
                            continue
                        if d < nd:#小さいなら、以降小さくなることが確定
                            nk = 1
                    dp[nk][nj][ni]+=dp[k][j][i]
    ans = dp[0][K][len(sN)]+dp[1][K][len(sN)]#小さいものが確定＆一致
    return ans

sN = input()
K = int(input())
lenN = len(sN)
ans = solve(sN)
print(ans)


Measured memory_bytes: 9156
n, m = map(int, input().split())
graph = [[0] * n for _ in range(n)]  #隣接行列
edge = []
for i in range(m):
	a, b = map(int, input().split())
	graph[a-1][b-1] = 1
	graph[b-1][a-1] = 1
	edge.append([a-1,b-1])

def dfs(x):
	if(vis[x] == 1):
		return
	vis[x] = 1
	for i in range(n):
		if(graph[x][i] == 1):
			dfs(i)


ans = 0
for i in range(m):
	graph[edge[i][0]][edge[i][1]] = 0
	graph[edge[i][1]][edge[i][0]] = 0
	vis = [0] * 60
	dfs(0)
	for j in range(n):
		if(vis[j] == 0):
			ans += 1
			break
	graph[edge[i][0]][edge[i][1]] = 1
	graph[edge[i][1]][edge[i][0]] = 1
print (ans)

Measured memory_bytes: 3064
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		int max = 1000000;
		boolean[] af = new boolean[max];
		Integer[] ai = new Integer[max];
		Arrays.fill(af, true);
		Arrays.fill(ai, 0);
		af[0] = false;
		af[1] = false;
		int sum = 0;
		for(int i = 2 ;i < max; i++ ){
			if(af[i] == true){
				sum++;
				for(int j = 2*i;j< max;j= j+i){
					af[j]= false;
				}
			}
			ai[i] = sum;
		}
		
		Scanner in = new Scanner(System.in);
		while((in.hasNext())){
			
			System.out.println(ai[Integer.parseInt(in.nextLine())]);
			}
		
		
	}

}

Measured memory_bytes: 40952
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

map<ll,ll> primes(ll n){
    map<ll, ll> r;
    for(int i=2; i*i<=n; i++){ 
        while(n % i ==0){
            r[i]++;
            n /= i;
        }
    }

    if(n != 1) r[n] = 1;
    r[1]=0;
    return r;
}

int main(){FIN
    
  ll n,k=0;;cin>>n;
  ll i;
  vector<ll> v;
  for( i=2;i*i<=n;i++){
  	//cout<<i<<" ";
  	if(n%i==0){
     	k=0;
     	while(n%i==0){
          n/=i;
		k++;
      	//cout<<i<<" "<<n<<"\n";
		}
	v.push_back(k);
    }
  }
  if(n!=1)v.push_back(1);
  //cout<<endl<<i<<endl;
  ll ans=0;
  for(auto i:v){
	  ll p=sqrt(1+8*i)-1;
	  p/=2;
	  ans+=p;
  }
  cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	ll N;
	cin >> N;
	vstring S(2);
	cin >> S[0] >> S[1];


	ll ans = 1;

	ll start = 0;
	if (S[0][0] == S[1][0])
	{
		// o?
		// o?
		ans *= 3;
		start = 1;
	}
	else
	{
		ans *= 6;
		start = 2;
	}


	for (ll i = start; i < N; i++)
	{
		if (S[0][i - 1] == S[1][i - 1])
		{
			//  o??
			//  o??

			if (S[0][i] == S[1][i])
			{
				//  ox
				//  ox
				ans *= 2;
			}
			else
			{
				//  oxx
				//  ott
				ans *= 2;
				i++;
			}
		}
		else
		{
			// oo??
			// xx??
			if (S[0][i] == S[1][i])
			{
				//  oot
				//  xxt
				ans *= 1;
			}
			else
			{
				//  oorr
				//  xxtt
				ans *= 3;
				i++;
			}			
		}

		ans %= MOD;
	}

	cout << ans % MOD << endl;






}





Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

P f(int x){
  int a=x%10;
  int b=0;
  while(x){
    b=x;
    x/=10;
  }
  return P(a,b);
}
int main(){
  int n;
  cin>>n;
  map<P,int> freq;
  for(int i=1;i<=n;i++){
    P p=f(i);
    freq[p]++;
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    P p=f(i);
    P q(p.second,p.first);
    ans+=freq[q];
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.math;

int main()
{

	//int n = to!(int)(chomp(readln()));
	int n = readln.chomp.to!int;

	foreach(int i;0..n)
	{

		string s = chomp(readln());
		string[] _s = s.split(" ");

		double x1 = to!double(_s[0]);
		double y1 = to!double(_s[1]);
		double x2 = to!double(_s[2]);
		double y2 = to!double(_s[3]);
		double x3 = to!double(_s[4]);
		double y3 = to!double(_s[5]);

		double a1 = 2*(x2 - x1);
		double b1 = 2*(y2 - y1);
		double c1 = x1*x1 - x2*x2 + y1*y1 - y2*y2;
		
		double a2 = 2*(x3 -x1);
		double b2 = 2*(y3 - y1);
		double c2 = x1*x1 - x3*x3 + y1*y1 - y3*y3;
		
		double x = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);
		double y = (c1*a2 - c2*a1) / (a1*b2 - a2*b1);
		
		double r_2 = (x1 - x)*(x1 - x) + (y1 - y)*(y1 - y);
		double r = sqrt(r_2);

		printf("%.3lf %.3lf %.3lf\n",x,y,r);

	}
	return 0;
}

Measured memory_bytes: 1108
import sys
N=int(input())
 
t0=0
x0=0
y0=0
 
for i in range(N):
    t,x,y=map(int,input().split())
    l=(t-t0)-abs(x+y-x0-y0)
    t0=t
    x0=x
    y0=y
    if l%2==0 and l>=0:
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 9140
#include<iostream>
#include<cassert>
#include<cstdlib>
#include<algorithm>
#include<numeric>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
const int N = 1000;
int adj[N][N];
int r[N];

int bestpoint(int n,int *esa,int l,int y,int x,ll tdist){
  int r=n-1;
  int ret=-1;
  if (esa[r] < x)return r;
  while(l <= r){
    int mid=(l+r)/2;
    ll mdist=esa[mid]-x;
    assert(mdist >= 0);
    if (mdist < tdist){
      ret=mid;
      l=mid+1;
    }else {
      r=mid-1;
    }
  }
  return ret;
}

void setdata(int n,int *esa,int m,int *y,int *x,int *num){
  rep(i,n){
    REP(j,i+1,n)adj[i][j]=0;
    rep(j,m){
      if (esa[i] < x[j]){
	ll tdist=llabs(esa[i]-x[j]);
	int ind=bestpoint(n,esa,r[j],y[j],x[j],tdist);
	//cout <<"check " << i <<" " << j <<" : " << esa[i] <<" " << x[j] << " " << ind << endl;
	if (ind == -1)ind=r[j]-1;
	if (ind >= 0)adj[i][ind]+=num[j];
      }
    }
    for(int j=n-2;j>i;j--){
      adj[i][j]+=adj[i][j+1];
    }

    /*
    for(int k=m-1;k>=0;k--){
      ll tmp=llabs(esa[i]-x[k]);
      REP(j,i+1,n){
	if (tmp > llabs(esa[j]-x[k]))adj[i][j]+=num[k];
      }
    }
    */
  }
}

int dp[N];
bool isok(int n,int lim,int total){
  rep(i,n){
    dp[i]=total;
    rep(j,i){
      if (dp[j]-adj[j][i] > lim)continue;
      dp[i]=min(dp[i],adj[j][i]);
    }
  }
  rep(i,n)if (dp[i] <= lim)return true;
  return false;
}

int solve(int n,int total){
  int l=0,r=total;
  int ret=total;
  while(l <= r){
    int mid=(l+r)/2;
    if (isok(n,mid,total))ret=mid,r=mid-1;
    else l=mid+1;
  }
  return ret;
}

main(){
  int n,m;
  static int x[N],y[N],num[N],esa[N];
  while(cin>>m>>n){
    if (m == 0 && n == 0)break;
    int total=0;
    rep(i,m)cin>>x[i]>>y[i]>>num[i],total+=num[i];
    rep(i,n)cin>>esa[i];
    sort(esa,esa+n);
    rep(i,m){
      r[i]=n-1;
      for(int j=n-1;j>=0;j--){
	if (x[i] <= esa[j] )r[i]=j;
      }
    }
    setdata(n,esa,m,y,x,num);
    //int total=accumulate(num,num+m,0);
    cout << solve(n,total) << endl;
  }
  return false;
}

Measured memory_bytes: 4808
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#pragma GCC optimization ("O3")

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;
#define row vector<ll>
#define matrix vector<row>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
/// find_by_order(x) -> x-th element in the set
/// order_of_key(x)  -> how many elements are smaller than x
/// insert(x) -> inserts x into the set

const int MOD = 1e9 + 7;

ll fp(ll b, ll p){
	if(p == 0) return 1;
	if(p == 1) return b % MOD;
	if(p & 1){
		return (fp(b, p - 1) * b) % MOD;
	}
	else{
		ll aux = fp(b, p / 2) % MOD;
		return (aux * aux) % MOD;
	}
}

int main(){
	/// ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n; cin >> n;
	if(n == 1){
		cout << "0\n";
	}
	else{
		cout << (((fp(10, n) - (2 * fp(9, n)) % MOD + MOD) % MOD) + fp(8, n)) % MOD << endl;
	}
}
/**

*/

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=(int)b-1;i>=(int)a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    cout <<"ABC"<<n<<"\n";

}









Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll ans;
ll d[100010];
int main(){
	int n;
	scanf("%d",&n);
	int t=0;
	while(n--){
		int m;
		scanf("%d",&m);
		if(t&&m){
			ans++;
			m--;
		}
		ans+=m/2;
		t=m%2;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    int N,M,C;
    cin >> N >> M >> C ;

    vector<int> B(M);
    for (int i = 0; i < M; ++i) {
        cin >> B.at(i);
    }

    vector<vector<int>> A(N,vector<int>(M));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> A.at(i).at(j);
        }
    }

    int count = 0;
    for (int i = 0; i < N; ++i) {
        int multi = 0;
        for (int j = 0; j < M; ++j) {
            multi += A.at(i).at(j) * B.at(j);
        }
        if(multi + C > 0) count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cctype>

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

using namespace std;

int p,q,r,now;
string s;

int formula(){
	
	if(isdigit(s[now])){return s[now++]-'0';}
	else if(s[now]=='P'){now++;return p;}
	else if(s[now]=='Q'){now++;return q;}
	else if(s[now]=='R'){now++;return r;}
	
	int res=0;
	if(s[now]=='-'){now++;return 2-formula();}
	else if(s[now]=='('){
		now++;
		res=formula();
		if(s[now]=='*'){now++;res=min(res,formula());}
		else if(s[now]=='+'){now++;res=max(res,formula());}
		now++;
	}
	return res;
}

int main(void){
	
	while(cin >> s,s!="."){
		
		int cnt=0;
		rep(p,3)rep(q,3)rep(r,3){
			now=0;
			if(formula()==2)cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	var sum, minus int
	min := int(math.Pow10(9))
	for i := 0; i < N; i++ {
		a := nextInt()
		if a < 0 {
			minus++
		}
		a = abs(a)
		sum += a
		if a < min {
			min = a
		}
	}

	if minus%2 == 0 {
		fmt.Println(sum)
		return
	}

	fmt.Println(sum - min*2)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 2304
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s[200005];
int n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int now=1;
	long long ans=0;
	for(int i=1;i<=n;i++)
	  if(s[i]=='W')
		ans+=i-now,now++;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#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 <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	int a, b, c, d, count = 0;
	cin >> a >> b >> c;
	d = max({ a, b, c });
	for (int i = 0; i < 1000; i++)
	{
		if (d - a >= 2)
		{
			a += 2;
			count++;
		}
		if (d - b >= 2)
		{
			b += 2;
			count++;
		}
		if (d - c >= 2)
		{
			c += 2;
			count++;
		}
	}
	if (a == b && b == c)
	{
		cout << count << "\n";
	}
	else if (a == b && a == d)
	{
		cout << count + 2 << "\n";
	}
	else if (a == c && a == d)
	{
		cout << count + 2 << "\n";
	}
	else if (b == c && c == d)
	{
		cout << count + 2 << "\n";
	}
	else
	{
		cout << count + 1 << "\n";
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define endll '\n'
#define sz(a) (int)(a).size()
#define RWFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int dx[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dy[] = { -1, 0, 1, 0, 1, -1, -1, 1 };
const int MOD = 1e9 + 7, N = 2e6 + 5, oo = 1e9;
const double pi = acos(-1);
using namespace std;

int main()
{
    assem99
    int n, k; cin>>n>>k;
    for(int i = 0; i < n; i++)
    {
        int a; cin>>a;
    }
    int i = k, ans = 1;
    while(i < n)
    {
        i += (k - 1);
        ans ++;
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 100005;
const int MM = 1000000007;

int D[MX];
int main()
{
	ll X, Y;
	scanf("%lld%lld", &X, &Y);
	if( abs(X-Y) > 1 ) printf("Alice\n");
	else printf("Brown\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int m, n, k;
int bunbo;
int bunshi = 0;

void calc(int res, int sum) { // resは残り回数。sumは今まで出た目の和。
  if (res == 0) {
    bunshi += (sum-k > 0) ? sum-k : 1;
  } else {
    for (int i=1; i<=m; i++) {
      calc(res-1, sum+i);
    }
  }
}

int main() {
  while(cin >> n >> m >> k && m) {
    bunshi = 0;
    calc(n, 0);
    bunbo = pow(m, n);
    // cerr << "bunshi = " << bunshi << ", bunbo = " << bunbo << endl;
    cout << fixed << setprecision(7) << (double)bunshi/bunbo << endl;
  }
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define NMAX 200005
using namespace std;
typedef long long ll;
ll x, k;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
}
int main()
{
    fast();
    cin>>k>>x;
    if(k*500>=x)
        cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


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

const int MAX=1e5+5;
int dp[MAX];
int arr[MAX];
int k;

int solve(int n){
    if(dp[n]!=-1) return dp[n];
    if(n<=0) return 0;
    if(n==1) return dp[n]=abs(arr[0]-arr[1]);
    int best = 1e9;
    for(int i=1;i<=k;i++){
        if(n-i>=0)
        best = min(best, solve(n-i)+abs(arr[n]-arr[n-i]));
    }
    return dp[n]=best;
}

int main(void){
    int n;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    memset(dp, -1, sizeof dp);

    cout<<solve(n-1)<<endl;
    //for(int i=0;i<n;i++) cout<<solve(i)<<endl;

    return 0;
}


Measured memory_bytes: 5760
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    string n;
    lli cnt = 0;
    cin >> n;
    rep(i,n.size()){
        cnt += (n[i]-'0');
    }
    Yes(cnt % 9 == 0);
}

Measured memory_bytes: 3728
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
n =  int(sys.stdin.readline())
h =  list(map(int, sys.stdin.readline().split()))
dp=[0]*(n)
dp[0]=0
dp[1]=abs(h[0]-h[1])

for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]) )
print(dp[n-1])


Measured memory_bytes: 16280
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;



int main(){
    LL N,X;
    cin >> N >> X;
    auto calc = [](LL i,LL j){
        return i/j*2*j;
    };
    LL ans = X+N-X;
    LL i = N-X,j = X;
    while(1){
        if(i == 0 || j == 0){
            ans -= i;
            break;
        }
        ans += calc(i,j);
        LL ins_i = i,ins_j = j;
        i = ins_j;
        j = (ins_i%ins_j);
    }
    cout<<ans<<endl;
}


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

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

    for(int i=0; i<n; i++) {
        if(i >= 1 && s[i][0] != s[i-1][s[i-1].size()-1]) {
            cout << "No" <<  endl;
            return 0;
        }
        if(count(s.begin(), s.end(), s[i]) >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3584
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let i = xs[1]+1
   let max = i + xs[1]
   let ans = 0;
   if(xs[0] <= xs[1]){
    ans = 1;
   }else{
     ans = Math.ceil(xs[0] / max);
   } 
   console.log(ans);   
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
// https://atcoder.jp/contests/abc168/tasks/abc168_e

#include <bits/stdc++.h>
#include <boost/rational.hpp>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)

//------------------------------------------------------------------------------
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//------------------------------------------------------------------------------
const int N_MAX = 2*1e5;
const ll A_I_MAX = 1e18;
const ll B_I_MAX = 1e18;
const int MOD = 1000000007;

int N;
ll A[N_MAX];
ll B[N_MAX];

map<boost::rational<ll>, int> mp;

ll non_pair_cmb(int c1, int c2) {
  ll ret = (mod_pow(2, c1, MOD) + mod_pow(2, c2, MOD)) % MOD;
  ret = (ret + MOD - 1) % MOD;
  return ret;
}

void solve() {
  int abz = 0;
  int az = 0;
  int bz = 0;
  REP(i, N) {
    ll a = A[i];
    ll b = B[i];
    if (a == 0 && b == 0) abz++;
    else if (a == 0) az++;
    else if (b == 0) bz++;
    else mp[boost::rational<ll>(a, b)]++;
  }

  // ITR(mp, it) cout << it->first << "->" << it->second << " ";
  // printf("\n");

  ll ans = 1;
  while (!mp.empty()) {
    auto it = mp.begin();
    boost::rational<ll> r1 = it->first;
    int c1 = it->second;
    boost::rational<ll> r2 = -1 / r1;
    int c2 = mp[r2];
    ans = ans * non_pair_cmb(c1, c2) % MOD;
    mp.erase(r1);
    mp.erase(r2);
  }
  ans = ans * non_pair_cmb(az, bz) % MOD;
  ans = (ans + abz) % MOD;
  ans = (ans + MOD - 1) % MOD;
  cout << ans << endl;
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%lld%lld", A + i, B + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 19176
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int a , b , c;
	
	cin >> a >> b >> c;
	
	if(abs(a - b) < abs(a - c)) {
		cout << "A";		
	}
	else {
		cout << "B";
	}
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 1e5 + 10;
int arr[MAX_N], bad[MAX_N];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x, n;
    int best = mod;
    cin >> x >> n;
    for(int i = 0; i < n; i ++) {
        cin >> arr[i];
        bad[arr[i]] = true;
    }
    for(int i = 0; i < MAX_N; i ++) {
        if(bad[i]) {continue;}
        chkmin(best, abs(x - i));
    }
    for(int i = 0; i <= x; i ++) {
        if(bad[i]) {continue;}
        if(x - i == best) {
            cout << i << endl;
            return 0;
        }
    }
    for(int i = x; i < MAX_N; i ++) {
        if(bad[i]) {continue;}
        if(i - x == best) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}




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

int main() {
  ll n;
  cin >> n;
  vec w(n),s(n),v(n);
  for(ll i=0;i<n;i++) cin >> w[i] >> s[i] >> v[i];
  vector<pll> a(n);
  for(ll i=0;i<n;i++) {
    a[i]={w[i]+s[i],i};
  }
  sort(a.begin(),a.end());
  mat dp(n+1,vec(2e4+10));
  for(ll i=0;i<n;i++) {
    ll id=a[i].second;
    for(ll j=0;j<=20000;j++) {
      dp[i+1][j]=dp[i][j];
      if(j) dp[i+1][j]=max(dp[i+1][j],dp[i+1][j-1]);
      if(j>=w[id]&&j-w[id]<=s[id]) {
        dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[id]]+v[id]);
      }
    }
  }
  cout << dp[n][20000] << endl;
}

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

#define debug(x) cout << #x << " = " << x << endl

const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> P;


int main(){
   string s;
   cin >> s;
   bool ok1 = false, ok2 = false;
   for(int i=0; i<s.size(); i++){
	  if(s[i] == 'C') ok1 = true;
	  if(ok1 == true && s[i] == 'F') ok2 = true;
   }

   if(ok1 && ok2) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 384