akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main(void)
{
    int i,j,n,m;
    char *msg1,*msg2;
    scanf("%d%d",&n,&m);

    msg1=new char [n+1];
    msg2=new char [m+1];

    scanf("%s",msg1);
    scanf("%s",msg2);
    i=0;
    j=0;
    while(i<n && j<m)
    {
       if(msg1[i]!=msg2[j])
            break;
        i+=n/__gcd(n,m);
        j+=m/__gcd(m,n);
    }
    if(i>n-1)
        printf("%lld\n",((long long)n*m)/__gcd(n,m));
    else
        printf("-1\n");

    delete [] msg1;
    delete [] msg2;
    return 0;

}



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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────


struct UnionFind {
	vi d;
	UnionFind(int n = 0) : d(n, -1) {}

	int find(int x) {
		if (d[x] < 0) return x;
		return d[x] = find(d[x]);
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);

		if (x == y) return false;

		if (d[x] > d[x]) swap(d[x], d[x]);
		d[x] += d[y];
		d[y] = x;
		return true;
	}

	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -d[find(x)]; }
};

struct Edge {
	int a, b, cost;

	bool operator<(const Edge& o) const {
		return cost < o.cost;
	}
};

struct Graph
{
	int n;  // 頂点数
	vector<Edge> es;  // 辺集合

	// クラスカル法で無向最小全域木のコストの和を計算する
	// グラフが非連結のときは最小全域森のコストの和となる
	int kruskal() {
		// コストが小さい順にソート
		sort(es.begin(), es.end());

		UnionFind uf(n);
		int min_cost = 0;

		rep(ei, es.size()) {
			Edge& e = es[ei];
			if (!uf.same(e.a, e.b)) {
				// 辺を追加しても閉路ができないなら、その辺を採用する
				min_cost += e.cost;
				uf.unite(e.a, e.b);
			}
		}

		return min_cost;
	}
};


Graph input_graph() {
	Graph g;
	int m;
	cin >> g.n >> m;
	rep(i, m) {
		Edge e;
		cin >> e.a >> e.b >> e.cost;
		g.es.push_back(e);
	}
	return g;
}


int main()
{
	Graph g = input_graph();
	cout << g.kruskal() << endl;
	return 0;
}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool flag;
	while (1) {
		c -= b;
		if (c <= 0) {
			flag = false;
			break;
		}
		a -= d;
		if (a <= 0) {
			flag = true;
			break;
		}

	}
	if (flag == false)cout << "Yes";
	else cout << "No";

	return 0;

}

Measured memory_bytes: 3676
x, y, z = map(int, input().split())

# width = x cm, ycm の幅を取りつつ、間隔Zcmあけて座る
add_s = x % (y + z)  # additional_space
if add_s < z:
  print(x // (y+z) - 1)
else:
  print(x // (y+z))

Measured memory_bytes: 2940
n = int(input())
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

print(sum(num_divisors_table(n-1)))

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

using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> C(N+1),S(N+1),F(N+1),t(N+1);
  rep(i,N-1){cin >> C[i+1] >> S[i+1] >> F[i+1];}

  rep(i,N+1)t[i]=0;
  S[N]=0;
  int touchaku=0,noru=0,taiki=0;
  for(int st=1;st<=N;st++){
    for(int now=st;now<N;now++){
      touchaku = max( t[st], S[now]);
      taiki = touchaku%F[now];
      if(taiki==0)noru = touchaku;
      else noru = touchaku + F[now] - taiki;
      t[st] = noru+C[now];
      //cout<<touchaku<<","<<taiki<<","<<noru<<","<<t[st]<<endl;
    }
  }


  for(int i=1;i<=N;i++)cout << t[i] << endl;
}

/*
駅数1
 0(最初から到着しているので)
駅数2
 1→2 S1+C1
駅数3
 s1→2 S1+C1 2→3 max(S1+C1,S2)+C2
 s2→3 S2+C2
 ここでs2→3の時間をt2とすると
 s1→3の時間t1 = max(S1+C1+C2,S2+C2) = max(S1+C1+C2,t2)
後ろから求める？
 駅3に対してもt3=0とすれば
 t2 = max(S2+C2,t3) といえる
 ↑ちがったわ↑

駅数1
 0(最初から到着しているので)
駅数2
 1→2 S1+C1
駅数3
 s1→2 S1+C1 
 2→3 2到着時がS[2]以上なら
 S1+C1以上のmodF[2]=0まで待たないといけない
 x=max(S1+C1,S2)がmod(f)=0ならそのまま
  mod(f)!=0なら切り上げる処理
 → x%f = m として x + (m!=0)*(f-m) でどう？
 ↑普通にifか三項演算子のほうが良いな
 こういうxtにたいしてxt+C2を行う

 N<500だから単純に全探索でもON^2だしいけるやろ～
*/

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

#define INF 1000000000

using namespace std;

int main() {
    int n;
    vector< pair<int, string> > s = {{1199, "ABC"}, {2799, "ARC"}, {INF, "AGC"}};
    cin >> n;
    cout << (*lower_bound(s.begin(), s.end(), pair<int, string>(n, ""))).second << endl;
    return 0;
}


Measured memory_bytes: 256
<?php

$n = (int)trim(fgets(STDIN));
$args = [];
for ($i=0; $i < $n; $i++) { 
	$args[] = (int)trim(fgets(STDIN));
}
rsort($args);
$sum = 0;
for ($i=0; $i < $n; $i++) { 
	$tmp = $args[$i];
	if ($i == 0) {
		$sum += floor($tmp/2);
	}else{
		$sum += $tmp;
	}
}

echo $sum;

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

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

    for(int i=1; i<10; i++) {
        for (int j=i; j<10; j++) {
            if (i*j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
dd = list(map(int, open(0).read().rstrip()))
n = len(dd)

ans = sum(dd)
tmp = 0

for i in range(n):
    if dd[i] > 0:
        tmp += dd[i]
        ans = max(ans, tmp - 1 + (n-i-1)*9)

print(ans)

Measured memory_bytes: 61596
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,int> pli;
typedef pair<long long, long long> pll;

int d[33][33];

ll wrongness(vector<int>& perm, vector<pii>* count) {
  ll sum = 0;
  for(int i=0; i<3; i++) {
    for(int j=0; j<count[i].size(); j++) {
      pii p = count[i][j];
      sum += d[p.first-1][perm[i]-1] * p.second;
    }
  }
  return sum;
}

int main (int argc, char*argv[]) {
  int n , m;
  cin >> n >> m;


  for(int i=0; i<m; i++) {
    for(int j=0; j<m; j++) {
      cin >> d[i][j];
    }
  }

  vector<int> arr[3];
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      int c;
      cin >> c;
      arr[(i+j)%3].push_back(c);
    }
  }
  for(int i=0; i<3; i++) {
    sort(arr[i].begin(), arr[i].end());
  }

  vector<pii> countColors[3];

  for(int z=0; z<3; z++) {
    int cnt = 0;
    int color = -1;
    for(auto c : arr[z]) {
      if(c == color) {
        cnt ++;
      } else {
        if (color != -1) {
          countColors[z].push_back(make_pair(color, cnt));
        }
        color = c;
        cnt = 1;
      }
    }
    if(color != -1) {
      countColors[z].push_back(make_pair(color, cnt));
    }
  }

  // for(int i=0; i<3; i++) {
  //   for(auto p : countColors[i]) {
  //     cout << "(" << p.first << ", " << p.second << "), ";
  //   }
  //   cout << endl;
  // }

  ll best = LLONG_MAX;
  for(int i=1; i<=m; i++) {
    for(int j=i+1; j<=m; j++) {
      for(int k=j+1; k<=m; k++) {
        vector<int> perm = {i, j, k};
        do {
          ll w = wrongness(perm, countColors);
          //cout << perm[0] << " " << perm[1] << " " << perm[2] << ": " <<  w << endl;
          best = min(best, w);
        } while(next_permutation(perm.begin(), perm.end()));
      }
    }
  }
  cout << best << endl;
  return 0;
}


Measured memory_bytes: 1520
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

ll fc(ll b, ll n){
  if(n < b) return n;
  else return fc(b, n/b) + (n%b);
}
int main() {
  ll n, s;
  cin >> n >> s;
  if(s > n){
    cout << -1 << endl;
    return 0;
  }
  if(n == s){
    cout << n+1 << endl;
    return 0;
  }
  ll ans = INF;
  REP(i, 1000000){
    if(i != 0 && (n-s) % i == 0){
      ll k = fc(i+1, n);
      if(k == s) ans = min(ans, i+1);
      k = fc(((n-s)/i)+1, n);
      if(k == s) ans = min(ans, ((n-s)/i)+1);
    }
  }
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>

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

    double w;

    while (std::cin >> w) {
        if (w > 91.) {
            std::cout << "heavy";
        }
        else if (w > 81.) {
            std::cout << "light heavy";
        }
        else if (w > 75.) {
            std::cout << "middle";
        }
        else if (w > 69.) {
            std::cout << "light middle";
        }
        else if (w > 64.) {
            std::cout << "welter";
        }
        else if (w > 60.) {
            std::cout << "light welter";
        }
        else if (w > 57.) {
            std::cout << "light";
        }
        else if (w > 54.) {
            std::cout << "feather";
        }
        else if (w > 51.) {
            std::cout << "bantam";
        }
        else if (w > 48.) {
            std::cout << "fly";
        }
        else {
            std::cout << "light fly";
        }

        std::cout << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1228
#include<iostream>
using namespace std;
int main()
{
    int n,i,k=1,Max=0;
    int a[1000]={0};
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>Max)
            Max=a[i];
        if(a[i]>=Max && i!=0)
            k++;
    }
    cout<<k<<endl;
    return 0;
}


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

using namespace std;

int n, a;
int x[50];
int64_t dp[2][51][50*50+1];

int main()
{
  cin >> n >> a;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 51; j++)
      for (int k = 0; k < 50*50+1; k++)
        dp[i][j][k] = 0;

  for (int i = 0; i < n; i++)
    cin >> x[i];

  dp[0][0][0]++;
  for (int i = 1; i <= n; i++) {
    for (int k = 0; k <= i; k++) {
      for (int v = 0; v <= 50*k; v++) {
        dp[i&1][k][v] = dp[(i+1)&1][k][v] + (k > 0 && v >= x[i-1] ? dp[(i+1)&1][k-1][v-x[i-1]] : 0);
      }
    }
  }

  int64_t c = 0;
  for (int k = 1; k <= n; k++)
    c += dp[n&1][k][a*k];

  cout << c << endl;

  return 0;
}


Measured memory_bytes: 2176
/*
 * Author: RainAir
 * Time: 2019-10-27 19:59:26
 */
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define U unsigned
#define P std::pair
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a >= 1 && a <= 9 && b >= 1 && b <= 9){
        printf("%d\n",a*b);
        return 0;
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define SZ(x) ((int)(x).size())
#define TC(tc) while (tc--)
#define VI vector<int>
#define PII pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	string s; cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes";
	else cout << "No";
	
	return 0;
}

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

int main() {
 int l, r;
  int d;
  cin>>l>>r>>d;
  int count=0;
  for(int i=l; i<=r; i++) {
    if(i%d==0)
      count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int minv=a[0];
  int maxv=a[1]-a[0];
  for(int i=1;i<n;i++){
    maxv = max(maxv,a[i]-minv);
    minv = min(minv,a[i]);
  }
  cout << maxv << endl;
}



Measured memory_bytes: 3856
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int maxn = 17;
int N, a[maxn][maxn];
long long sum[1<<maxn], dp[1<<maxn];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>N;
    for(int i = 0; i< N; i++){
        for(int j = 0; j < N; j++){
            cin>>a[i][j];
        }
    }
    
    for(int i = 1; i< (1<<N); i++){
        for(int j = 0; j< N;j++)
            if(i&(1<<j)){
                sum[i] = sum[i-(1<<j)];
                for(int k = j+1; k< N; k++)if(i&(1<<k))
                    sum[i] += a[j][k];
                break;
            }
    }
    
    for(int i = 1; i< (1<<N); i++){
        for(int j = i; j; j = (j-1)&i){
            dp[i] = max(dp[i], sum[j] + dp[i-j]);
        }
    }
    cout<<dp[(1<<N)-1]<<endl;
    return 0;
}



Measured memory_bytes: 1280
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    double a, b, x, ans;
    double rad;
    cin >> a >> b >> x;
    double s = x/a;
    if(s >= a*b/2){
        double h;
        h = (a*b-s)*2/a;
        rad = atan2(h, a);
    }
    else{
        double w;
        w = 2*s/b;
        rad = atan2(b, w);
    }
    double PI = acos(-1);
    double deg = rad*180/PI;
    printf("%.10f\n",deg);
    return 0;
}

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

int main() {
    int x, y;

    cin >> x >> y;
    while(x!=0 || y!=0){
        if(x > y){
            cout << y << " " << x << endl;            
        }else{
            cout << x << " " << y << endl;
        }
        cin >> x >> y;
    }
    return 0;
}


Measured memory_bytes: 3100
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		do{
			double a=sc.nextDouble();
			double sum=a;
			
			for(int i=2; i<=10; i++){
				if(i%2==0) a *= 2;
				else a /= 3;
				sum += a;
			}
			System.out.printf("%.8f%n",sum);
		} while(sc.hasNext());
	}

}

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).e();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).e();++it,++i)
#define ALL(c) (c).begin(), (c).e()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).e())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#eif
*/
// }}}

//{{{ Array
template<class T>
struct Array{
	int sz;
	int l,r;
	vector<T> a;
	Array(const pair<int,int> &p,const T &d=0):l(p.first),r(p.second){
		sz = r-l+1;
		a.assign(sz,d);
//		a = (T*)malloc(sz*sizeof(T));
//		for(int i=0;i<sz;i++)a[i] = d;
	}
	T& operator[](int i){
		return a[i-l];
	}
};
//}}}

//{{{ Imos
template<class T>
struct Imos{
	vector<T> v;
	int cur_i;
	T cur_sum;
	Imos(int n){
		v.assign(n+1,0);
		cur_i = -1;
		cur_sum = 0;
	}
	void add(int l,int r,T diff){
		v[l]+=diff;
		v[r]-=diff;
	}
	T get(int i){
		assert(cur_i<=i);
		for(;cur_i<i;cur_i++,cur_sum+=v[cur_i]);
		assert(cur_i==i);
		return cur_sum;
	}
};
//}}}

int N, V;
const int D = 200010;
vector<Array<int>> rts,lts;

int x[D];

vector<int> dp0,dp1;

int main(){
	cin>>N>>V;
	REP(i,N)cin>>x[i];
	int i;
	int v = V;
	for(i=0;;i++,v/=2){
		Array<int> rt({-1,N},-1),lt({-1,N},N);
		int j,e;
		for(e=j=0;j<N;j++,e=max(e,j)){
			while(e+1<N and x[e+1]-x[e]<=v){
				e++;
			}
			rt[j] = e+1;
		}
		for(e=j=N-1;j>=0;j--,e=min(e,j)){
			while(e-1>=0 and x[e]-x[e-1]<=v){
				e--;
			}
			lt[j] = e-1;
		}
		rt[N] = N;
		lt[-1] = -1;
		rts.push_back(rt);
		lts.push_back(lt);
		if(v==0)break;
	}
	i++;
	int d = i, B = (1<<d);
	dp0.assign(B,-1);
	dp1.assign(B,N);
	dp0[0] = 0;
	dp1[0] = N-1;
	for(int b=0;b<B-1;b++){
		int head0, head1;
		head0 = min(dp0[b],N);
		head1 = max(dp1[b],-1);
		for(int i=0;i<d;i++){
			if((b&(1<<i))==0){
				int b2 = (b|(1<<i));
				dp0[b2] = max(dp0[b2],rts[i][head0]);
				dp1[b2] = min(dp1[b2],lts[i][head1]);
			}
		}
	}
	Imos<int> imos(N);
	for(int b0=0;b0<B-1;b0++){
		if(b0&(1<<0))continue;
		int b1 = ((B-1)^1)-b0;
		int s0 = dp0[b0], s1 = dp1[b1];
		if(s1+1<=s0){
			// all possible
			REP(i,N){
				cout<<"Possible"<<endl;
			}
			return 0;
		}
		if(rts[0][s0]-1<s1)continue;
//		cerr<<"found: "<<lts[0][s0]+1<<" "<<rts[0][s0]-1<<endl;
//		dump(lts[0][s0]+1);
		imos.add(lts[0][s0]+1,rts[0][s0],1);
	}
	for(int i=0;i<N;i++){
		if(imos.get(i)>0){
			cout<<"Possible"<<endl;
		}else{
			cout<<"Impossible"<<endl;
		}
	}
	return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = (a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (a); i <= (long long)(n); i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

int main(void)
{
    int k;
    cin >> k;
    priority_queue<ll, v_ll, greater<ll> > ans;

    for(int i = 1; i <= 9; i++) { ans.push(i); }

    while(1) {
        if(k <= ans.size()) {
            irep(i, k-1) { ans.pop(); }
            cout << ans.top() << endl;
            return 0;
        }
        int loop = ans.size();
        k -= ans.size();
        irep(i, loop) {
            ll x = ans.top(); ans.pop(); 
            int d = x % 10;
            for(int i = -1; i < 2; i++) {
                int n = d + i;
                if(n < 0 || n > 9) { continue; }
                ans.push(x*10+n);
            }
        }
    }

    return 0;
}
/** atcoder **/


Measured memory_bytes: 1400
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a+b)%24<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    
    string a,b,c,d;
    cin>>a>>b;
    c=a;
    d=b;
    reverse(a.begin(),a.end());
    if(a==d)
    cout<<"YES";
    else
    cout<<"NO";
    return 0;
}



Measured memory_bytes: 256
n = int(input())
divisor = [0 for _ in range(n+1)]
for i in range(1,n+1):
    j = 1
    while j*i<=n:
        divisor[j*i]+=1
        j+=1
ans = 0
for ix,val in enumerate(divisor):
    ans += ix*val
print(ans)

Measured memory_bytes: 224260
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    // freopen("input.txt", "r", stdin);
    // freopen("output1.txt", "w", stdout);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<int> cost(n, 0);
    if(n > 1)
        cost[1] = abs(a[1] - a[0]);
    for(int i = 2; i < n; i++) {
        cost[i] = min(cost[i - 1] + abs(a[i] - a[i - 1]), cost[i - 2] + abs(a[i] - a[i - 2]));
    }

    cout << cost[n - 1];
    return 0;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    arc080d()
}

private enum class Direction { RIGHT, LEFT, UP, DOWN }

fun arc080d() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toInt() }

    val answer = Array(h) { IntArray(w) { -1 } }
    val queue = PriorityQueue(aList.mapIndexed { index, a -> (1..a).map { index + 1 } }.flatten())
    answer[0][0] = queue.poll()
    var direction = Direction.UP
    var x = 0
    var y = 0
    while (queue.isNotEmpty()) {
        when (direction) {
            Direction.RIGHT -> {
                if (x + 1 < w && answer[y][x + 1] == -1) {
                    answer[y][++x] = queue.poll()
                } else {
                    direction = Direction.DOWN
                }
            }
            Direction.LEFT -> {
                if (x - 1 >= 0 && answer[y][x - 1] == -1) {
                    answer[y][--x] = queue.poll()
                } else {
                    direction = Direction.UP
                }
            }
            Direction.UP -> {
                if (y + 1 < h && answer[y + 1][x] == -1) {
                    answer[++y][x] = queue.poll()
                } else {
                    direction = Direction.RIGHT
                }
            }
            Direction.DOWN -> {
                if (y - 1 >= 0 && answer[y - 1][x] == -1) {
                    answer[--y][x] = queue.poll()
                } else {
                    direction = Direction.LEFT
                }
            }
        }
    }

    println(answer.joinToString(System.lineSeparator()) { it.joinToString(" ") })
}


Measured memory_bytes: 39816
#include <bits/stdc++.h>
using namespace std;
//ask the right questions.		

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

	//minimum cost to reach stone n
	int dp[n+1];
	dp[0]=0;
	dp[1]=0;

	//you can reach stone i by jumps of 1,2,3,...K
	for(int i=2;i<=n;i++)
	{
		int mincost=INT_MAX;
		for(int j=1; j<=k && i-j>=0; j++)
		{
			mincost = min(mincost, dp[i-j] + abs(a[i-1]-a[i-1-j]));
		}
		dp[i] = mincost;
	}
	cout << dp[n];

	
	return 0;
	
}

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

template <typename T>
class FenwickTree {
	const int n;
	vector<T> data;
public:
	FenwickTree(int n_) : n(n_), data(n) {}
	T find(int p) const {
		T res = 0;
		while (p >= 0) {
			res += data[p];
			p = (p & (p + 1)) - 1;
		}
		return res;
	}
	T find(int l, int r) const {
		return find(r) - find(l - 1);
	}
	void add(int p, T val) {
		while (p < n) {
			data[p] += val;
			p |= p + 1;
		}
	}
	void update(int p, T val) {
		add(p, val - find(p));
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y;
	cin >> n >> q;
	FenwickTree<int> st(n);
	while (q--) {
		cin >> com >> x >> y; x--;
		if (com) {
			y--;
			printf("%d\n", st.find(x, y));
		}
		else {
			st.add(x, y);
		}
	}
	return 0;
}



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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

class unionfind {
	vector<int> par, rank;

public:
	void init(int n) {
		par.resize(n);
		rank.resize(n);

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

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

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

const int MN = 200010;

using P = pair<ll, int>;

vector<pii> g[MN];
int col[MN];
ll X[MN];
vector<P> dp[MN];

void mergevec(vector<P>& a, vector<P> b) {
	for (auto p : b) {
		a.eb(p);
	}
	sort(ALL(a));

	set<int> st;
	vector<P> res;

	for (P p : a) {
		if (res.size() == 2) {
			break;
		}
		if (!st.count(p.se)) {
			st.insert(p.se);
			res.eb(p);
		}
	}
	a = res;
}

void dfs_up(int v, int p) {
	dp[v].eb(X[v], col[v]);

	for (pii e : g[v]) {
		if (e.fi != p) {
			dfs_up(e.fi, v);

			vector<P> nx;

			for (auto t : dp[e.fi]) {
				nx.eb(t.fi + e.se, t.se);
			}

			mergevec(dp[v], nx);
		}
	}
}

void dfs_down(int v, int p, int pw) {
	if (p != -1) {
		vector<P> nx;
		for (auto t : dp[p]) {
			nx.eb(t.fi + pw, t.se);
		}
		mergevec(dp[v], nx);
	}

	for (pii e : g[v]) {
		if (e.fi != p) {
			dfs_down(e.fi, v, e.se);
		}
	}
}

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

	rep(i, N) cin >> X[i];

	rep(i, N-1) {
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		g[a].eb(b, c);
		g[b].eb(a, c);
	}

	uf.init(N);
	rep(i, N) {
		col[i] = i;
	}

	ll ans = 0;

	while (true) {
		bool one = true;
		for (int i = 1; i < N; ++i) {
			if (col[i] != col[0]) {
				one = false;
			}
		}
		if (one) {
			break;
		}

		rep(i, N) {
			dp[i].clear();
		}

		vector<P> mt(N, mp(LLONG_MAX, -1));

		dfs_up(0, -1);
		dfs_down(0, -1, -1);

		rep(i, N) {
			for (P p : dp[i]) {
				if (p.se != col[i]) {
					mt[col[i]] = min(mt[col[i]], mp(p.fi + X[i], p.se));
					break;
				}
			}
		}

		rep(i, N) if (mt[i] != mp(LLONG_MAX, -1)) {
			int u = i, v = mt[i].se;
			ll cost = mt[i].fi;
			if (!uf.same(u, v)) {
				uf.unite(u, v);
				ans += cost;
			}
		}

		rep(i, N) {
			col[i] = uf.find(col[i]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 74952
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

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

    ll ans = 0;

    while(true){
        bool check = true;
        for(int i = 0; i < N; i++){
            if(a[i] >= N) check = false;
        }

        if(check) break;

        ///////////////////////////////////
        ll s = 0;
        for(int i = 0; i < N; i++) s += a[i] / N;

        ans += s;

        for(int i = 0; i < N; i++){
            ll x = a[i] / N;
            a[i] -= x * N;
            a[i] += s - x;
        }
    }

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


Measured memory_bytes: 256
N = int(input())
*h, = map(int, input().split())
dp = [0] * N
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))
print(dp[-1])

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

#define INF 1e+9
#define MAX_V 1000000

struct edge
{
  int from;
  int to;
  int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];
vector<int> anss;

void dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty())
  {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;

    for (int i = 0; i < G[v].size(); ++i)
    {
      edge e = G[v][i];

      if (d[e.to] > d[v] + e.cost)
      {
        d[e.to] = d[v] + e.cost;
        anss[e.to] = e.from;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main()
{
  int n, m;
  cin >> n >> m;
  anss.resize(n);
  vector<int> as(m);
  vector<int> bs(m);
  rep(i, m)
  {
    cin >> as[i] >> bs[i];
  }

  V = n;

  rep(i, m)
  {
    int from = as[i] - 1;
    int to = bs[i] - 1;
    int cost = 1;
    edge e = {from, to, cost};
    G[from].push_back(e);
    edge e2 = {to, from, cost};
    G[to].push_back(e2);
  }
  dijkstra(0);

  string ans = "Yes";
  for (int i = 0; i < V; ++i)
  {
    if (d[i] != INFINITY)
    {

    }
    else
    {
      ans = "No";
      break;
    }
  }

  cout << ans << endl;
  if (ans == "No")
    return 0;
  rep(i, n - 1)
  {
    cout << anss[i+1] + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 37920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	ll n,k,mx=-1;
	cin>>n>>k;
	ll a[n][2];
	ll ts=0;
	for(ll i=0;i<n;i++){cin>>a[i][0]>>a[i][1];
	ts+=a[i][1];}
	ll dp[ts+1];
	for(ll i=0;i<=ts;i++)dp[i]=INT_MAX;
	dp[0]=0;
	for(ll i=0;i<n;i++){
		for(ll j=ts;j>=a[i][1];j--){
				dp[j]=min(dp[j],dp[j-a[i][1]]+a[i][0]);
				
		}
	}
	ll ans=0;
	for(ll i=0;i<=ts;i++)
	if(dp[i]<=k)ans=i;
	cout<<ans;	
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			final long N = scn.nextLong();

			long sum = 0;
			for (long l = 1; l <= N; l++) {
				if (l % 3 != 0 && l % 5 != 0) {
					sum += l;
				}
			}
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 27236
#include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	while (t--)
		{
			solve();
			cout << "\n";
		}

	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}
void solve()
{
	int n, c = 0, a, b, tr = 0;
	cin >> n;
	while (n--)
		{
			cin >> a >> b;
			if (a == b)
				{
					c++;
					if (c == 3) tr = 1;
				}
			else
				{
					c = 0;
				}
		}
	if (tr) cout << "Yes";
	else cout << "No";

}


Measured memory_bytes: 3796
# from pprint import pprint
# import math
# import collections

# n = int(input())
l, r, d = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
# a = []
# for i in range(n):
#     a.append(int(input()))
cnt = 0
for n in range(l, r + 1):
    if n % d == 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 9156
#ifndef _BLESS_MCLAREN_MCL32_
#define _BLESS_MCLAREN_MCL32_ true
#endif

#ifndef _BLESS_FERNANDO_ALONSO_14_
#define _BLESS_FERNANDO_ALONSO_14_ true
#endif

#ifndef _FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_
#define _FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_ true
#endif

#ifndef _1731_TRUE_LOVE_
#define _1731_TRUE_LOVE_ true
#endif

#ifndef _CIVILIZATION_
#define _CIVILIZATION_ true
#endif

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstdarg>
#include <climits>
#include <cassert>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
using namespace std;

const int MAX_N = (int)2e5 + 5;

int n, a[MAX_N];

int main() {
    {
        assert(_BLESS_MCLAREN_MCL32_);
        assert(_BLESS_FERNANDO_ALONSO_14_);
        assert(_FERNANDO_ALONSO_WILL_WIN_ANOTHER_CHAMPIONSHIP_);
        assert(_1731_TRUE_LOVE_);
        assert(_CIVILIZATION_);
    }

    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%d", min(a + b, min(a + c, b + c)));
    return 0;;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<functional>
#include<iterator>
#include<math.h>

using namespace std;

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

	int a,b;
	cin >> a >> b;

	cout << max(a+b,max(a-b,a*b)) << "\n";
	return 0;
}

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

using namespace std;

#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, s, n) for(int i = s; i < (int)(n); ++i)

int main() {
  int n;
  cin >> n;
  vector<int> L(n);
  Rep(i, n) cin >> L[i];
  sort(L.begin(), L.end());

  int answer = 0;
  Rep(i, n) {
    For(j, i + 1, n) {
      For(k, j + 1, n) {
        if (L[i] + L[j] > L[k] && L[i] != L[j] && L[j] != L[k] && L[i] != L[k]) {
          answer++;
        }
      }
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3628
inputlist=[]
while 1:
	inputnum=int(raw_input())
	if(inputnum==0):break
	inputlist.append(inputnum)
def octnpower(num):
	flag=0
	maxi=0
	maxj=0
	if(num<8):
		temp[-1]=num
		return
	for i in range(1,11):
		for j in range(1,8):
			if(num>=(8**i)*j):
				flag=(8**i)*j
				maxi=i
				maxj=j
			else:
				temp[-maxi-1]=maxj
				return octnpower(num-flag)

octdictionary={0:0,1:1,2:2,3:3,4:5,5:7,6:8,7:9}
for i in range(len(inputlist)):
	temp=[0]*10
	octnpower(inputlist[i])
	for j in range(len(temp)):
		index=j
		if(temp[j]!=0):break
	temp=temp[index:]
	for j in range(len(temp)):
		temp[j]=octdictionary[temp[j]]
	ansstr=""
	for j in range(len(temp)):
		ansstr+=str(temp[j])
	print ansstr

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

const int N=1e7+10;
typedef long long ll;
ll n,fac[N],invf[N],mi2[N],ans;//fac 阶乘，invf 阶乘得逆元 
const ll mod=998244353;

ll qpow(ll a,ll b) {
	ll ans=1ll;
	while(b) {
		if(b&1) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return ans;
}

ll C(int x,int y) {
	return fac[x]*invf[y]%mod*invf[x-y]%mod;
}

int main() {
	scanf("%d",&n);
	fac[0]=mi2[0]=1;
	for(int i=1; i<=n; i++)
		fac[i]=1ll*fac[i-1]*i%mod,mi2[i]=mi2[i-1]*2%mod;//fac阶乘，ci 2^2; 
	invf[n]=qpow(fac[n],mod-2);
	for(int i=n-1; i>=0; i--)
		invf[i]=1ll*invf[i+1]*(i+1)%mod;
	for(int i=n/2+1; i<=n; i++)
		ans=(ans+C(n,i)*mi2[n-i]%mod)%mod;
	ans=((qpow(3,n)-ans*2)%mod+mod)%mod;
	printf("%lld\n",ans);
}


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

using namespace std;

int main() {
   long long i,j,a,m,b,n,c,d,x,k;
   
   priority_queue<long long> q;
   cin>>n>>m;
   for(i=0;i<n;i++){
       cin>>x;
       q.push(x);
   }
   
   while(m--){
       a=q.top();
       q.pop();
       q.push(a/2);
       
   }
   c=0;
   while(!q.empty()){
       c+=q.top();
       q.pop();
   }
   cout<<c;
   
   
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m;
    cin >> m;
    ll ans = 0, lst = 0, d, c;
    vector<ll> nxt = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
    for (int i = 0; i < m; i++) {
        cin >> d >> c;
        while (c) {
            if (c % 2 == 1) {
                lst = 10 * lst + d;
                while (lst >= 10) {
                    lst = lst / 10 + lst % 10;
                    ans++;
                }
                c--;
            }
            c /= 2;
            if (d > 4) {
                ans += c * 2;
            } else {
                ans += c;
            }
            d = nxt[d];
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		ArrayList<String> list = new ArrayList<String>();
		int m = scan.nextInt(); //????????????????????°
		for(int i=0;i<m;i++){
			String train = scan.next();
			for(int j=1;j<train.length();j++){
				String front = train.substring(0,j);
				String back = train.substring(j,train.length());
				//System.out.println(j+"front="+front);
				//System.out.println(j+"back="+back);
				StringBuffer front_reverse = new StringBuffer(front);
				StringBuffer back_reverse = new StringBuffer(back);
				front_reverse.reverse(); 
				back_reverse.reverse();
				String front_rev = new String(front_reverse);
				String back_rev = new String(back_reverse);
				//System.out.println(j+"revfront="+front_rev);
				//System.out.println(j+"revback="+back_rev);
				//String conect = front+back;
				//System.out.println(j+conect);
				for(int k=0;k<2;k++){
					for(int l=0;l<2;l++){
						for(int n=0;n<2;n++){
							String conect = new String();
							if     (k==0 && l==0 && n==0) conect = front + back;
							else if(k==0 && l==0 && n==1) conect = front + back_rev;
							else if(k==0 && l==1 && n==0) conect = back + front;
							else if(k==0 && l==1 && n==1) conect = back + front_rev;
							else if(k==1 && l==0 && n==0) conect = front_rev + back;
							else if(k==1 && l==0 && n==1) conect = front_rev + back_rev;
							else if(k==1 && l==1 && n==0) conect = back_rev + front;
							else if(k==1 && l==1 && n==1) conect = back_rev + front_rev;
							list.add(conect);
						}
					}
				}
			}
			//System.out.println(list);
			HashSet<String> hashSet = new HashSet<String>();
			hashSet.addAll(list);
			System.out.println(hashSet.size());
			list.clear();
		}
	}
}

Measured memory_bytes: 61932
#include <cstdio>
#include <string>
#include <regex>
#include <iostream>
using namespace std;

int main(){
    string x;
    cin >> x;

    if(x > "2019/04/30"){
        cout << "TBD" << endl;
    }else{
        cout << "Heisei" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_N 8

using namespace std;

int P[MAX_N];
int Q[MAX_N];

int main() {
  int N;
  cin >> N;
  int *A;
  int *B;
  for (int i = 0; i < N; ++i) {
    cin >> P[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> Q[i];
  }

  int _cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (P[i] < Q[i]) {
      A = P;
      B = Q;
      break;
    } else if (Q[i] < P[i]) {
      A = Q;
      B = P;
      break;
    }
    ++_cnt;
  }
  if (_cnt == N) {
    printf("0\n");
    return 0;
  }

  int cnt = 0;
  do {
    bool flg = true;
    for (int i = 0; i < N; ++i) {
      if (A[i] != B[i]) {
        flg = false;
        break;
      }
    }
    if (flg) {
      printf("%d\n", cnt);
      return 0;
    }
    ++cnt;
  } while (next_permutation(A, A + N));
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
 string S;
	in(S);
  ll N = sz(S);
  ll z=0;ll i =0;
  rep(j,N){
   if(S[j] =='0') z++;
    if(S[j]=='1') i++;
  }
 out(min(z,i)*2);
}	

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int h, w;
	cin >> h >> w;
	//各数字を1にかえる時の最短魔力を求めておく
	//ダイクストラ法だと思う
	vector<vector<ll>>dp(10, vector<ll>(10, 100000000000));
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++)cin >> dp.at(i).at(j);
	}
	for (int i = 0; i < 10; i++)dp.at(i).at(i) = 0;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++)dp.at(j).at(k) = min(dp.at(j).at(k), dp.at(j).at(i) + dp.at(i).at(k));
		}
	}
	//行列について足していきans出力
	ll ans = 0;
	for (int i = 0; i < h * w; i++) {
		ll x;
		cin >> x;
		if(x!=-1)ans += dp.at(x).at(1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n, k = LI()
	D = set(LI())
	for num in range(n,10**5):
		if set(map(int,list(str(num)))) & D == set():
			print(num)
			break


if __name__ == '__main__':
    main()

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

int N,A,B,C;

int dfs(int cur, int a, int b, int c,vector<int> l){
  int ret0,ret1,ret2,ret3;
  if(cur == N) return min(a,min(b,c)) > 0 ? abs(a-A) +  abs(b-B) + abs(c-C) - 30 : 1e9;
  ret0 = dfs(cur+1,a,b,c,l);
  ret1 = dfs(cur+1,a+l[cur],b,c,l) + 10;
  ret2 = dfs(cur+1,a,b+l[cur],c,l) + 10;
  ret3 = dfs(cur+1,a,b,c+l[cur],l) + 10;
  return min(min(ret0,ret1),min(ret2,ret3));
}

int main(void){
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  int i;
  for(i=0; i<N; i++){
    cin >> l[i];
  }
  cout << dfs(0,0,0,0,l) << endl;
  return 0;
}

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

const int INF = (int)1e9;
signed main(void)
{
	int n;
	cin >> n;
	int h[n], dp[n];
	rep(i, n) cin >> h[i];
	rep(i, n) dp[i] = INF;
	dp[0] = 0;
	for(int i = 1; i < n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i]);
		if (i - 2 >= 0)
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i]);
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Text;

namespace ITP1_11_C
{
	class Program
	{
		// faces[] = { 0, 1, 2, 3, 4, 5, 6 };
		//   0
		// 3 1 2 4
		//   5
		static void Main(string[] args)
		{
			string s1 = Console.ReadLine();
			string[] faces1 = s1.Split();

			string s2 = Console.ReadLine();
			string[] faces2 = s2.Split();

			Dice dice1 = new Dice(faces1);

			bool f = false;
			for (int i = 0; i < 6; i++) {
				Dice dice2 = new Dice(faces2);
				switch (i) {
				case 0:
					break;
				case 1:
					dice2.MoveS();
					break;
				case 2:
					dice2.MoveN();
					break;
				case 3:
					dice2.MoveW();
					break;
				case 4:
					dice2.MoveE();
					break;
				case 5:
					dice2.MoveN();
					dice2.MoveN();
					break;
				}
				for (int j = 0; j < 4; j++) {
					if (dice1.Top == dice2.Top && dice1.Bottom == dice2.Bottom &&
						dice1.North == dice2.North && dice1.South == dice2.South &&
						dice1.East == dice2.East && dice1.West == dice2.West) {
						f = true;
						break;
					}
					dice2.MoveCW();
				}
				if (f) { break; }
			}
			if (f) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}
			// Console.WriteLine("Hit Any Key");
			// Console.ReadLine();
		}
	}

	class Dice
	{
		//   1
		// 4 2 3 5
		//   6
		public string Top { get; private set; }
		public string North { get; private set; }
		public string South { get; private set; }
		public string East { get; private set; }
		public string West { get; private set; }
		public string Bottom { get; private set; }
		public Dice(string[] faces)
		{
			Top = faces[0];
			North = faces[4];
			South = faces[1];
			East = faces[2];
			West = faces[3];
			Bottom = faces[5];
		}
		public void MoveN()
		{
			// T<-S<-B<-N<-T
			string tmp = Top;
			Top = South;
			South = Bottom;
			Bottom = North;
			North = tmp;
		}
		public void MoveS()
		{
			// T<-N<-B<-S<-T
			string tmp = Top;
			Top = North;
			North = Bottom;
			Bottom = South;
			South = tmp;
		}
		public void MoveE()
		{
			// T<-W<-B<-E<-T
			string tmp = Top;
			Top = West;
			West = Bottom;
			Bottom = East;
			East = tmp;
		}
		public void MoveW()
		{
			// T<-E<-B<-W<-T
			string tmp = Top;
			Top = East;
			East = Bottom;
			Bottom = West;
			West = tmp;
		}
		public void MoveCW()
		{
			// N<-W<-S<-E<-N
			string tmp = North;
			North = West;
			West = South;
			South = East;
			East = tmp;
		}
		public void MoveCCW()
		{
			// N<-E<-S<-W<-N
			string tmp = North;
			North = East;
			East = South;
			South = West;
			West = tmp;
		}
	}
}

Measured memory_bytes: 8932
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

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

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

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

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

    vector<ll> dp(n+1,0);

    for(int i = n; i > 0; i--){
        int j = (n/i)*i;
        int total = 0;
        for(; j > i; j -= i){
            total += dp[j];
        }
        if(total%2 == a[i]){
            dp[i] = 0;
        }else{
            dp[i] = 1;
        }
    }

    ll count = 0;

    for(int i = 0; i < n; i++){
        if(dp[i+1] == 1){
            count++;
        }
    }

    cout << count << endl;

    bool first = true;

    for(int i = 0; i < n; i++){
        if(dp[i+1] == 1){
            if(!first){
                cout << " ";
            }
            first = false;
            cout << i+1;
        }
    }
    if(!first){
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3968