akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

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

pii a[123456];
long long int N;
long long int v[123466];

vector<pii> radj[123456];

vector<pii> adj[123456];

bool seen[123456];
long long int dist[123456];
long long int small[123456];
long long int sec[123456];
void dfs(long long int at, long long int d, long long int sector) {
    //cerr << "DFS " << at << endl;;
    if(!seen[at]) {
        dist[at] = d;
        sec[at] = sector;
        small[sector] = min(small[sector], d);
        seen[at] = true;
        for(auto edge : adj[at]) {
            dfs(edge.first, d + edge.second, sector);
        }
    }
}
long long int R, C;
int main() {
    //cerr << "Begin" << endl;
    cin >> R >> C >> N;
    for(long long int i = 1; i <= N; i++) {
        cin >> a[i].first >> a[i].second >> v[i];
        radj[a[i].first].push_back({a[i].second, v[i]});
    }
    //cerr << "Read lines" << endl;

    for(long long int i = 1; i <= R; i++) {
        for(long long int j = 0; j < (long long int)radj[i].size()-1; j++) {
            //cerr << "NEXT " << radj[i].size()-1 << endl;
            pii c1 = radj[i][j];
            pii c2 = radj[i][j+1];
            //cerr << c1.first << " " << c2.first << endl;
            long long int diff = c2.second - c1.second;
            adj[c1.first].emplace_back(c2.first, diff);
            adj[c2.first].emplace_back(c1.first, -diff);
        }
    }
    //cerr << "Readinput" << endl;

    for(long long int i = 1; i <= C; i++) {
        small[i] = 1e12;
        dfs(i, 0, i);
    }

    for(long long int i = 1; i <= C; i++) {
        for(auto edge: adj[i]) {
            if(dist[i] != dist[edge.first] - edge.second) {
                //cerr << "Not consistent columns " << i << " " << edge.first << "\n";
                //cerr << dist[i] << " " << dist[edge.first] << " " << edge.second << "\n";
                cout << "No\n";
                return 0;
            }
        }
    }

    long long int lowest = 1e12;
    for(long long int i = 1; i <= N; i++) {
        long long int curd = v[i];
        long long int delta = dist[a[i].second];
        long long int offset = curd-delta;
        long long int sector = sec[a[i].second];
        long long int mylow = small[sector];
        lowest = min(lowest, mylow+offset);
    }
    if(lowest >= 0) {
        //cerr << "Lowest was only " << lowest << "\n";
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 18304
N = -1

def _input():
    global N
    N = int(input())

def solve():
    _input()
    snuke_power = 1
    for i in range(1, N+1):
        snuke_power *= i
        snuke_power %= (10 ** 9 + 7)
    print(snuke_power)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 2940
N = int(input())
A = sorted([int(_) for _ in input().split()])
summed = [0] * N
summed[0] = A[0]
for n in range(1, N):
    summed[n] = summed[n - 1] + A[n]

impossible = 0
for n in range(1, N):
    if summed[n - 1] * 2 < A[n]:
        impossible = n
print(N - impossible)

Measured memory_bytes: 14308
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll now[ohara];

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

  cin >> n;
  rep(i, n + 1) cin >> a[i];
  if (n == 0) {
    if (a[0] == 1) {
      Cout(1);
    } else {
      Cout(-1);
    }
    return 0;
  }
  if (a[0] != 0) {
    Cout(-1);
    return 0;
  }
  now[0] = 1;
  now[n] = a[n];
  rrrep(i, n - 1, 1) {
    now[i] = now[i + 1];
    now[i] += a[i];
  }
  ll curr = 2;
  rrep(i, 1, n + 1) {
    now[i] = min(now[i], curr);
    ll nex;
    nex = now[i];
    nex -= a[i];
    if (nex < 0) {
      Cout(-1);
      return 0;
    }
    if (nex == 0 && i != n) {
      Cout(-1);
      return 0;
    }
    nex *= 2;
    curr = nex;
  }
  rep(i, n + 1) ans += now[i];
  Cout(ans);
  return 0;
}

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

#define start          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nl            endl;
#define end_            system("pause");
#define sz(v)            ((int)((v).size()))
#define sc(x)            scanf("%d",&x)
#define sc2(x,y)         scanf("%d%d",&x,&y)
#define sc3(x,y,z)       scanf("%d%d%d",&x,&y,&z)
#define sc4(x,y,z,a)     scanf("%d%d%d%d",&x,&y,&z,&a)
#define sc5(x,y,z,a,b)   scanf("%d%d%d%d%d",&x,&y,&z,&a,&b)
#define sc6(x,y,z,a,b,c) scanf("%d%d%d%d%d%d",&x,&y,&z,&a,&b,&c)
#define scl(x)           scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define lp(i,n)        for(int i=0;i<n;i++)
#define lp1(i,f,l)     for(int i=f;i<l;i++)
#define R_(s)         freopen(s, "r", stdin)
#define W_(s)        freopen(s, "w", stdout)
#define R_W R_("input.txt"),W_("output.txt")
#define PI           acos(-1)
#define INF             1<<30
#define mp(a,b) make_pair(a,b)
typedef string            S;
typedef long long         ll;
typedef long long int     lli;
typedef pair <int, int>   pii;
typedef pair<S, int>     si;
typedef pair<int, S>     is;
typedef pair<char, int>  chi;
typedef pair<S, S>       SS;
typedef vector<pii>        vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<S>        vs;
typedef vector<ll>       vll;
typedef vector<vll>     vvll;
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll gcd(ll a, ll b)  { return (b == 0 ? a : gcd(b, a % b)); }
ll sd(ll x)  { return x<10 ? x : x % 10 + sd(x / 10); }
ll lcm(ll a, ll b){ return ((a*b) / gcd(a, b)); }
vector<ll> get_divisors(ll n){vector<ll> arr;ll i=1;for(i;i*i<=n;i++){if(n%i==0)arr.push_back(i),arr.push_back(n/i);}return arr;}
int dx[4]={0 , 1 , 0 , -1};
int dy[4]={1 , 0 , -1 , 0};

lli diff(lli i, lli h, lli w){
  lli s[3];
  s[0] = i*w;
  s[1] = (h-i)*(w/2);
  s[2] = (h-i)*(w-(w/2));
  sort(s, s+3);
  return s[2]-s[0];
}
int main()
{
    start;
	lli h,w,ans;		
	cin>>h>>w;
	if(h*w%3 == 0)
	{
		cout<<0<<endl;
		return 0;
	}
	ans = min(h, w);
	for(int i = 1; i < h; i++) 
		ans = min(ans, diff(i, h, w));
	for(int i = 1; i < w; i++)
		ans = min(ans, diff(i, w, h));
	cout << ans << endl;
	//end_;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

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

int dp[32][16][256];

int dfs(int n, int k, int s){
  if(n==0){
    if(s==0&&k==0) return 1;
    return 0;
  }
  int &res = dp[n][k][s];
  if(res>=0) return res;
  res = 0;
  if(k && s>=n) res += dfs(n-1,k-1,s-n);
  res += dfs(n-1,k,s);
  return res;
}

int main(){
  int N,K,S;
  while(scanf("%d%d%d",&N,&K,&S) && N+K+S){
    memset(dp, -1, sizeof(dp));
    printf("%d\n", dfs(N,K,S));
  }
  return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int mod = 1000000007;

int32_t main() {

    int n, m; cin >> n >> m;
    vector<int> s(n+1), t(m+1);
    for(int i = 1; i <= n; ++i) cin >> s[i];
    for(int i = 1; i <= m; ++i) cin >> t[i];

    vector<vector<int>> dp(n+1, vector<int>(m+1, 1));

    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
            
            if(s[i] == t[j]) {
                dp[i][j] += dp[i-1][j-1];
            }
            
            dp[i][j] %= mod;
            if(dp[i][j] < 0) dp[i][j] += mod;
        }
    }

    cout << dp[n][m] << endl;
    
    return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
map <char,char> mp;
int main()
{
    go;
    mp['G']='C';
    mp['C']='G';
    mp['A']='T';
    mp['T']='A';
    char ch;
    cin>>ch;
    cout<<mp[ch];
    return 0;
}


Measured memory_bytes: 256
# AOJ ITP2_1_A: Vector
# Python3 2018.6.24 bal4u

from collections import deque
Q = deque()
q = int(input())
for i in range(q):
	a = input()
	if   a[0] == '0': Q.append(a[2:])      # pushBack
	elif a[0] == '1': print(Q[int(a[2:])]) # randomAccess
	else:             Q.pop()              # popBack


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

#define int long long

int n;
int a,b;

signed main()
{
	cin>>n;
	for(a=sqrt(n);a>=1;a--)
		if(n%a==0)
		{
			b = n/a;
			break;
		}
	cout<<a+b-2<<endl;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	vector<long long> a(n);
	map<long long,bool> check;
	for(long long i=0;i<n;i++) cin>>a.at(i);

	for(long long tmp=0;tmp<(1<<n);tmp++){
		bitset<20> bits=tmp;
		long long pre=0;
		for(long long i=0;i<n;i++){
			if(bits.test(i)) pre+=a.at(i);
		}
		check[pre]=true;
	}

	long long q;
	cin>>q;
	for(long long i=0;i<q;i++){
		long long hoge;
		cin>>hoge;
		if(check.count(hoge)) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}

	return 0;
}



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

using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int add=a+b;
    int sub=a-b;
    int mul=a*b;
    int ans = max(max(add,mul),sub);
    cout << ans << endl;
    return 0;
}

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


int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i, m) {
    cin >> b[i];
  }
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    rep(j, m) {
      cin >> a[i][j];
    }
  }


  int ans = 0;
  rep(i, n) {
    int sum = c;
    rep(j, m) {
      sum += a[i][j] * b[j];
    }
    if (sum > 0) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int a, b, c, k; cin>>a>>b>>c>>k;
    int nmax=max({a, b, c});
    int num=nmax;
    for(int i=0; i<k; i++) nmax*=2;
    cout << a+b+c+nmax-num << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[]) {
  long h, w;
  std::cin >> h >> w;

  if (h == 1 || w == 1)
    std::cout << 1 << std::endl;
  else
    std::cout << (h * w / 2) + (h * w % 2) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
//#include <fstream>	// require freopen

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.splitup", "r", stdin );
	int n;

	while (cin >> n && n ){
		vector <int> party(n);
		for (int i = 0; i < n; ++i ){
			cin >> party[i];
		} // end for

		int termA = 0, termB = 0; 
		int res = INT_MAX;

		termA = party[0];

		if (n == 1 ){
			return termA;
		}else if (n == 2 ){
			termB = party[1];
			res = abs (termA - termB );
			cout << res << endl;
		}else{ // end if

			for (int i = 0; i < (1 << n); ++i ){
				termA = 0, termB = 0;
				for (int j = 0; j < n; ++j ){
					if (i & (1 << j ) ){
						termA += party[j];
					}else{
						termB += party[j];
					} // end if
				} // end for
				int diff = abs (termA - termB );
				res = min (res, diff );
			} // end for
			cout << res << endl;
		} // end if
	} // end loop
		
	return 0;
}

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

string s;
int x, y;
bool a[2][16010];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> s >> x >> y;
	s += 'T';
	a[0][8000] = true;
	a[1][8000] = true;
	int t = 0, f = 0;
	while(t < s.size() && s[t] == 'F') ++t;
		x -= t;
	for(int i=t; i<s.size(); ++i){
		if(s[i] != 'T') continue;
		if(i - t > 1){
//			cout << i - t - 1 << "\n";
			int u = i - t - 1;
			bool b[16010] = {};
			for(int j=0; j<16010; ++j){
				if(!a[f][j]) continue;
				if(0 <= j-u && j-u < 16010) b[j-u] = true;
				if(0 <= j+u && j+u < 16010) b[j+u] = true;
			}
			for(int j=0; j<16010; ++j) a[f][j] = b[j];
		}
		t = i;
		f = 1 - f;
	}
	if(0 <= 8000 + x && a[0][8000+x] && a[1][8000+y]) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if (W>0 && H>0 && ((x - r >= 0) && (x + r <= W)) && ((y - r >= 0) && (y + r <= H)) || W<0 && H<0 && ((x - r <= 0) && (x + r >= H)) && ((y - r <= 0) && (y + r >= W)))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

ll a, b, n, l, r, m1, m2, mux = -1000000000;
ll f(ll x)
{
    return ((ll)(a * x / b) - a * (ll)(x / b));
}

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b >> n;
    l = 0;
    r = n;
    while (r - l > 2)
    {
        m1 = l + (r - l) / 3;
        m2 = l + (r - l) * 2 / 3;
        if (f(m1) > f(m2))
            r = m2;
        else
            l = m1;
    }
    for (ll i = l; i <= r; i ++)
        mux = max(mux, f(i));
    cout << mux;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
#include <cstring>
#include <string>
#include <cstdlib>
#include <map>
using namespace std;

#define VALUE(c) ( ((c)>='a' && (c)<='z') ? ((c)-'a') : ((c)-'A'+26) )
#define VALID(c) ( (((c)>='a' && (c)<='z') || ((c)>='A' && (c)<='Z') || ((c)>='0' && (c)<='9') || ((c)=='[') || ((c)==']') || ((c)=='=')) ? true : false )

map<string,string> v;
int l[52];

string eval(string s) {//evalua una expresion recursivamente
	if (s[0] >='0' && s[0] <= '9') return s;
	else {
		string tmp = eval(s.substr(2, s.size()-3));
		if (tmp != "") {
			int tmpi = atoi(tmp.c_str());
			tmp = s[0] + "[" + tmp + "]";
			if (tmpi >= l[VALUE(s[0])] || v.find(tmp) == v.end()) return "";
			else return v[tmp];
		} else return "";
	}
}

int main() {

int CUR, ipos;
bool analyze;
string cur, tmp, tmp2;
char input[128];

while (1) {

CUR = 1; analyze = true; v.clear();
memset(l, 0, sizeof(l));
while (cin.getline(input, 128) && strcmp(input, ".") != 0) {
	cur = "";
	for (int i=0; input[i]!='\0'; i++) if (VALID(input[i]) == true) cur += input[i];
	if (!analyze) continue;

	ipos = cur.find("=");

	if (ipos == string::npos) {
//		cout << CUR << ": " << cur << " (D)" << endl; <== DECLARACION

		tmp = eval(cur.substr(2, cur.size()-3));

		if (tmp == "" || cur[2] < '0' || cur[2] > '9') {
			cout << CUR << endl;
			analyze = false;
		} else {
			l[VALUE(cur[0])] = atoi(tmp.c_str());
		}
	} else {
//		cout << CUR << ": " << cur << " (A)" << endl; <== ASIGNACION

		tmp = eval(cur.substr(ipos+1));

		if (tmp == "") {
			cout << CUR << endl;
			analyze = false;
		} else {
			tmp2 = eval(cur.substr(2, ipos-3));
			if (tmp2 == "" || atoi(tmp2.c_str()) >= l[VALUE(cur[0])]) {
	   		cout << CUR << endl;
   			analyze = false;
			} else {
				tmp2 = cur[0] + "[" + tmp2 + "]";
				v[tmp2] = tmp;
			}
		}
	}
   CUR++;
}
if (CUR == 1) break;
if (analyze) cout << 0 << endl;

}

return 0;
}

Measured memory_bytes: 1388
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int D, T, S;
  cin >> D >> T >> S;
  if (S * T >= D) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int r,g;
    cin>>r>>g;
    cout<<2*g-r<<endl;
}

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

main(){
	int y,m,d,sum,n;
	cin >> n;
	while(n--){
		sum = 0;
		cin >> y >> m >> d;
		while(y!=1000 || m!=1 || d!=1){
			d ++;
			if(!(y%3)||m%2){
				if(d==21){d = 1;m ++;}
			}else{
				if(d==20){d = 1;m ++;}
			}
			if(m==11){m = 1;y ++;}
			sum ++;
		}
		cout << sum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 868
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        vector<vector<int>> A(N, vector<int>(N-1));
        for(auto& v : A){
            for(auto& t : v){
                cin >> t; --t;
            }
        }
        vector<int> day(N, 0);
        vector<int> idx(N, 0);
        queue<pair<int, int>> qu;
        for(int i=0;i<N;i++){
            if(i < A[i][0] && A[A[i][0]][0] == i){
                qu.emplace(i, A[i][0]);
                idx[i] = 1;
                idx[A[i][0]] = 1;
            }
        }
        int battle = 0;
        while(!qu.empty()){
            auto p = qu.front(); qu.pop();
            ++battle;
            int d = max(day[p.first], day[p.second]) + 1;
            day[p.first] = day[p.second] = d;
            auto check = [&](int t){
                if(idx[t] < N-1){
                    int next = A[t][idx[t]];
                    if(idx[next] < N-1 && A[next][idx[next]] == t){
                        qu.emplace(t, next);
                        ++idx[t];
                        ++idx[next];
                    }
                }
            };
            check(p.first);
            check(p.second);
        }
        if(battle < N*(N-1)/2){
            cout << -1 << endl;
        } else {
            cout << *max_element(day.begin(), day.end()) << endl;
        }
    }
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	vector <int> v(n),answer(n,0);
	for(int i =0;i<n;i++)cin>>v[i];
	answer[0]=0;
	answer[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++){
	    answer[i]=min(answer[i-1]+abs(v[i]-v[i-1]),answer[i-2]+abs(v[i]-v[i-2]));
	}
	cout<<answer[n-1]<<endl;
}


Measured memory_bytes: 4020
#include<bits/stdc++.h>
 
 
#define ll long long
#define max 1000000000
 
 
#define biggestFactor (n)      for (ll j = 2; j <= sqrt(n); j++){if (n % j == 0){cout << n / j << "\n";break;}}
                               //First find smallest factor and then divide that factor and the answer itself is biggest factor
                          
using namespace std;

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

    ll n;
    cin >> n;
    ll v = 7;
    ll flag = 0;
    ll cna = -1;
        for (ll i = 0; i < 10000000; i++)
        {
            if (v % n == 0)
            {
                cna = i + 1;
                break;
            }
            else
            {
                v = (v * 10 + 7)% n;
            }
        }
        cout << cna;
    
	return 0;
}

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

int main(){
    int h,w;cin >> h >> w;
    char a[h][w];

    for (int i=0;i<h;i++) for(int j=0;j<w;j++){
        cin >> a[i][j];
    }
    for (int i=-1;i<=h;i++) for (int j=-1;j<=w;j++){
        if (i == -1 || i == h) {
            cout << "#";
            if (j==w){
                cout << endl;
            }
        } else if (j==-1 || j == w){
            cout << "#";

            if (j==w){
                cout << endl;
            }
        } else {
            cout << a[i][j];
        }

    }


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int w;
	int case_num = 1;
	
	while (scanf("%d", &w) * w != 0){
		int bag[1001] = {0};
		int i;
		int t;
		int min_w, max_v;
		
		scanf("%d", &t);
		while (t-- > 0){
			int v, wn;
			scanf("%d,%d", &v, &wn);
			for (i = w - wn; i >= 0; i--){
				if ((i == 0 || bag[i] != 0) && bag[i] + v > bag[i + wn]){
					bag[i + wn] = bag[i] + v;
				}
			}/*
			for (i = w; i >= 0; i--){
				if (bag[i] > 0){
					printf("%d\n", bag[i]);
					printf("%d\n", i);
					break;
				}
			}*/
		}
		min_w = 0;
		max_v = -1;
		for (i = 0; i <= w; i++){
			if (bag[i] > max_v){
				max_v = bag[i];
				min_w = i;
			}
		}
		printf("Case %d:\n", case_num);
		printf("%d\n", max_v);
		printf("%d\n", min_w);
		case_num++;
	}
	
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);

  if(x/d <= k){
    if((k - x/d)%2){
      cout << d - x%d << endl;
    }
    else{
      cout << x%d << endl;      
    }
  }
  else if(x/d > k){
    cout << x - k * d << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
int X;

//解法
void solve() {

	int ans = 1;
	for (int i = 2; i < sqrt(X) + 1;i++) {

		int j = 2;
		while (1) {
			if (pow(i, j) <= X) {
				ans = max((double)ans,pow(i, j));
				j++;
			}
			else {
				break;
			}
		}
	}
	cout << ans;

	return;
}

int main() {
	//入力
	cin >> X;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[] = {-1,0,1,0,-1,-1,1,1};
const int dy[] = {0,-1,0,1,1,-1,1,-1};

int main(){
  int n,w; cin>>n>>w;
  int value[n],weight[n];
  rep(i,n) cin>>value[i]>>weight[i];
  int dp[110][101010]; //dp[i]:重さi以下の時の最小値
  rep(i,w+1) dp[0][i]=0;
  rep(i,n){
    rep(j,w+1){
      dp[i+1][j]=dp[i][j];
      if(j-weight[i]>=0){
        dp[i+1][j]=max(dp[i+1][j],dp[i][j-weight[i]]+value[i]);
      }
    }
  }
  rep(i,n+1){
    //cout<<dp[i][w]<<endl;
  }
  cout<<dp[n][w]<<endl;
}



Measured memory_bytes: 7436
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	cout << N + N * N + N * N * N << endl;
}

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

using namespace std;

#define pb push_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const int N = 1e5 + 5;
ll n, a[N];

ll go1 (ll val, ll a, ll l, ll r) {
	ll bot = 0, top = 1e18;
	ll res = -1;
	while (bot <= top) {
		ll mid = (bot + top)>>1;

		if ( (mid - mid%a) >= val) {
			res = mid;
			top = mid - 1;
		} else {
			bot = mid + 1;
		}
	}

	ll ans = (res - res%a);
	if (ans < l or ans > r)
		res = -1;

	if (res == -1) {
		cout << -1 << endl;
		exit(0);
	}

	return res;
}

ll go2 (ll val, ll a, ll l, ll r) {
	ll bot = 0, top = 1e18;
	ll res = -1;
	while (bot <= top) {
		ll mid = (bot + top)>>1;
		if ( (mid - mid%a) <= val) {
			res = mid;
			bot = mid + 1;
		} else {
			top = mid - 1;
		}
	}

	ll ans = (res - res%a);
	if (ans < l or ans > r)
		res = -1;

	if (res == -1) {
		cout << -1 << endl;
		exit(0);
	}

	return res;
}

int main (void) {
	ios_base::sync_with_stdio(false);

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

	ll l = 2, r = 2;
	for (int i = n - 1; i >= 0; i--) {
		ll L = go1 (l, a[i], l, r);
		ll R = go2 (r, a[i], l, r);
		l = L;
		r = R;
	}

	if (l <= r)
		cout << l << " " << r << endl;
	else
		cout << -1 << endl;

	return 0;
}

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

int main(){
    int A, B, M;
    cin >> A >> B >> M;
    int a[A], b[B], c[M], x[M], y[M];
    for(int i=0; i<A; i++){
        cin >> a[i];
    }
    for(int i=0; i<B; i++){
        cin >> b[i];
    }
    for(int i=0; i<M; i++){
        cin >> x[i] >> y[i] >> c[i];
    }

    int payment, payment2, amin=a[0], bmin=b[0];
    for(int i=1; i<A; i++){
        if(a[i]<amin){
            amin=a[i];
        }
    }
    for(int i=1; i<B; i++){
        if(b[i]<bmin){
            bmin=b[i];
        }
    }
    payment= amin + bmin;
    // cout << payment << endl;

    for(int i=0; i<M; i++){
        payment2= a[x[i]-1]+b[y[i]-1]-c[i];
        if(payment2<payment){
            payment= payment2;
        }
        // cout << payment << endl;
    }
    cout << payment << endl;
    return 0;
}

Measured memory_bytes: 2176
from itertools import permutations


def check(queen):
    for r1, c1 in queen:
        if not all((r1 == r2 and c1 == c2) or (r1 != r2 and c1 != c2 and r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2) for r2, c2 in queen):
            return False
    return True


N = int(input())
row, col = list(range(8)), list(range(8))
queen = []
for _ in range(N):
    r, c = map(int, input().split())
    queen.append((r, c))
    row.remove(r)
    col.remove(c)
for l in permutations(col):
    queen_tmp = queen[:]
    for r, c in zip(row, l):
        queen_tmp.append((r, c))
    if check(queen_tmp):
        board = [''.join('Q' if (r, c) in queen_tmp else '.' for c in range(8)) for r in range(8)]
        print(*board, sep='\n')
        break

Measured memory_bytes: 7760
#include<iostream>
#include<utility>
#include<climits>
using namespace std;

int main(){
	
	int height[10] = {};

	for(int i = 0; i < 10; i++){
		cin >> height[i];
	}

	int f = INT_MIN, s = INT_MIN, t = INT_MIN;

	for (int i = 0; i < 10; i++){
		if (height[i] >= t){
			t = height[i];
		}
		if (t >= s){
			swap(s, t);
		}
		if (s >= f){
		swap(f,s);
		}
	}
    
	cout << f << "\n" << s << "\n" << t << endl;

		return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

using Input = tuple<int, int, int, int>;
using R = double;

int main(void){
    for(int n; cin >> n, n;){
        int pw; cin >> pw;
        vector<Input> in(n);
        for(auto & e : in){
            int vw, pf, vf, th; cin >> vw >> pf >> vf >> th;
            e = Input(vw, pf, vf, th);
        }

        auto f = [&](R w){
            R cost = w * pw;
            for(auto & e : in){
                R vw, pf, vf, th; tie(vw, pf, vf, th) = e;
                th -= w * vw;
                cost += pf * max(0.0, (R)th / vf);
            }
            return cost;
        };

        R lb = 0.0, ub = 100.0;
        rep(loop, 300){
            if(f((lb * 2 + ub) / 3) < f((lb + ub * 2) / 3)){
                ub = (lb + ub * 2) / 3;
            }
            else {
                lb = (lb * 2 + ub) / 3;
            }
        }

        cout.precision(20);
        cout << fixed << f((lb + ub) / 2.0) << endl;
    }

    return 0;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    if(a >= 3200){
        cout << s << endl;
    }
    else {
        cout << "red" << endl;
    }
}

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

int N;
bool jdg(int sum) {
  if(sum >= N) return sum == N;
  if(jdg(sum + 4)) return true;
  if(jdg(sum + 7)) return true;
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  if(jdg(0))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin>>n;
	vector<ll> v(n);
	for(int i=0;i<n;i++)
	    cin>>v[i];
	vector<ll> vv(n);
	vv[0]=v[0];
	for(int i=1;i<n;i++)
	    vv[i] = max(vv[i-1],v[i]);
	    
	long long ans=0;
	for(int i=1;i<n;i++){
	    ans+= vv[i]-v[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6356
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=998244353;
long long h,w,k;
long long v[3000][3000]={};
long long dp[3000][3000][4]={};
int main(){
	cin>>h>>w>>k;
	for(int i=0;i<k;i++){
		long long r,c,V;
		cin>>r>>c>>V;
		r--;
		c--;
		v[r][c]=V;
	}
	if(v[0][0]>0){
		dp[0][0][1]=v[0][0];
	}
	for(int i=1;i<h;i++){
		dp[i][0][0]=max(dp[i-1][0][0],dp[i-1][0][1]);
		if(v[i][0]>0){
			dp[i][0][1]=max(dp[i-1][0][0],dp[i-1][0][1])+v[i][0];
		}
	}
	for(int i=1;i<w;i++){
		dp[0][i][0]=dp[0][i-1][0];
		dp[0][i][1]=dp[0][i-1][1];
		dp[0][i][2]=dp[0][i-1][2];
		dp[0][i][3]=dp[0][i-1][3];
		if(v[0][i]>0){
			dp[0][i][1]=max(dp[0][i][1],dp[0][i-1][0]+v[0][i]);
			dp[0][i][2]=max(dp[0][i][2],dp[0][i-1][1]+v[0][i]);
			dp[0][i][3]=max(dp[0][i][3],dp[0][i-1][2]+v[0][i]);
		}
	}
	for(int i=1;i<h;i++){
		for(int j=1;j<w;j++){
			dp[i][j][0]=max(dp[i][j-1][0],dp[i][j][0]);
			dp[i][j][0]=max(dp[i-1][j][0],dp[i][j][0]);
			dp[i][j][0]=max(dp[i-1][j][1],dp[i][j][0]);
			dp[i][j][0]=max(dp[i-1][j][2],dp[i][j][0]);
			dp[i][j][0]=max(dp[i-1][j][3],dp[i][j][0]);
			dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][1]);
			dp[i][j][2]=max(dp[i][j][2],dp[i][j-1][2]);
			dp[i][j][3]=max(dp[i][j][3],dp[i][j-1][3]);
			if(v[i][j]>0){
				dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][0]+v[i][j]);
				dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][0]+v[i][j]);
				dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][1]+v[i][j]);
				dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][2]+v[i][j]);
				dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][3]+v[i][j]);
				//
				dp[i][j][2]=max(dp[i][j][2],dp[i][j-1][1]+v[i][j]);
				dp[i][j][3]=max(dp[i][j][3],dp[i][j-1][2]+v[i][j]);
			}
		}
	}
	long long ans=0;
	ans=max(ans,dp[h-1][w-1][0]);
	ans=max(ans,dp[h-1][w-1][1]);
	ans=max(ans,dp[h-1][w-1][2]);
	ans=max(ans,dp[h-1][w-1][3]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 354632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
const ll N = 1e3 + 200;
const ll INF = 0x3f3f3f;
const ll Mode = 1e9 + 7;
int main(){
	ll n;
	cin>>n;
	vector<ll> a(n+1),b(n);
	rep(i,n+1){
		cin>>a[i];
	}
	rep(i,n){
		cin>>b[i];
	}
	ll rst = 0;
	ll k = 0;
	rep(i,n){
//		cout<<rst<<endl;
		if(k >= a[i]){
			rst+=a[i];
			k -= a[i];
			a[i] = 0;
			if(k >= a[i+1]){
					rst+= a[i+1];
				a[i+1] = 0;

			}else{
				a[i+1] -= k;
				rst += k;
			}
		}else{
			a[i] -= k;
			rst += k;
		}
		k = 0;
		if(a[i] >= b[i]){
			rst += b[i];
			a[i] -= b[i];
			k = 0;
		}else{
			rst += a[i];
			b[i] -= a[i];
			a[i] = 0;
			if(a[i+1] >= b[i]){
				rst += b[i];
				a[i+1] -= b[i];
				b[i] = 0;
				k = 0;
			}else{
				rst += a[i+1];
				b[i] -= a[i+1];
				a[i+1] = 0;
				k = 0;
			}
		}
	}
	cout<<rst<<endl;
	return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>
#include <queue>


#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, long long>;

template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
pair<pair<string, int>, int> p[110];

int main(){
    int N, M; cin >> N >> M;
    
    vector<bool> isclack;
    isclack.assign(N+1, true);
    rep (i, M) {
        int a; cin >> a;
        isclack[a] = false;
    }
    
    vector<int> dp(N+1, 0);
    
    dp[0] = 1;
    if(isclack[1]) dp[1] = 1;
    
    for(int i = 2; i <= N; i++) {
        if(isclack[i-1]) dp[i] += dp[i-1];
        if(isclack[i-2]) dp[i] += dp[i-2];
        dp[i] %= MOD;
    }
    cout << dp[N] << endl;
}





Measured memory_bytes: 640
<?php
# スペース区切りの文字列の入力
fscanf(STDIN, "%d", $d);
$s = fgets(STDIN);

$lengths = array_map('intval', explode(' ', $s));

$size = count($lengths);
$count = 0;

// 総当たりで数える
// 同じ長さは使用不可
// 三角形の成立条件は a+b>c かつ b+c>a かつ c+a>b
for ($i = 0; $i < $size; $i++) {
	$l1 = $lengths[$i];
	$checks = [];

	for ($j = $i + 1; $j < $size; $j++) {
		$ln = $lengths[$j];
		if ($ln === $l1) {
			continue;
		}

		$checks[] = $ln;
	}

	$checkSize = count($checks);
	for ($j = 0; $j < $checkSize; $j++) {
		$l2 = $checks[$j];

		for ($k = $j + 1; $k < $checkSize; $k++) {
			$l3 = $checks[$k];
			if ($l2 !== $l3 && $l1 + $l2 > $l3 && $l2 + $l3 > $l1 && $l3 + $l1 > $l2) {
				++$count;
			}
		}
	}
}

# 出力
echo $count . "\n";

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

int used[8];
int connect[8][8];

int N,M;

int dfs(int now, int depth){
	if(used[now]) return 0;
	if(depth == N) return 1;
	used[now] = 1;
	int ans = 0;

	for(int i=0;i<N;i++){
		if(connect[now][i]){
			ans += dfs(i, depth+1);
		}
	}

	used[now] = 0;
	return ans;
}

int main(){
	cin >> N >> M;
	int a[30], b[30];
	for(int i=0;i<M;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}

	for(int i=0;i<M;i++){
		connect[a[i]][b[i]] = connect[b[i]][a[i]] = 1;
	}

	cout << dfs(0,1) << endl;
	return 0;
}


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

int n;
pair<int ,int> p[100001]; // 1 ~ N-1 edge
map< pair<int ,int>, int> m; // edge - color
vector< vector <int> > tree(100001);


int coloring(int idx, int beforeColor)
{
    int color = 1;
    for (int i = 0; i < tree[idx].size(); i++) {
        auto tmp = make_pair(idx, tree[idx][i]);
        if (color == beforeColor) {
            m[tmp] = ++color;
        } else {
            m[tmp] = color;
        }
        color++;
    }

    int maxNum = color - 1;
    for (int i = 0; i < tree[idx].size(); i++) {
        auto tmp = make_pair(idx, tree[idx][i]);
        maxNum = max(maxNum, coloring(tree[idx][i], m[tmp]));
    }
    return maxNum;
}

int main ()
{
    cin >> n;

    for (int i = 1; i < n; i++) {
        int tmpa, tmpb;
        cin >> tmpa >> tmpb;
        tree[tmpa].push_back(tmpb);
        p[i] = make_pair(tmpa, tmpb);
        m.insert(make_pair(p[i], 0));
    }

    cout << coloring(1, 0) << endl;;

    for (int i = 1; i < n; i++) {
        cout << m[p[i]] << endl;
    }
}


Measured memory_bytes: 14976
n, k = [int(i) for i in input().split()]

count = [1] * (10**5+1)

low = 1
high = k

while high - low != 0:
    for i in range(low,high):
        count[i] /= 2
    high = -(-high//2)

print(sum(count[1:n+1])/n)

Measured memory_bytes: 6132
n = int(input())
cnt = 0
divisor = []
for i in range(1,n+1,2) :
        for j in range(1,i+1) :
                if i % j == 0 :
                        cnt += 1
        divisor.append(cnt)
        cnt = 0
ans = 0
for i in divisor :
        if i == 8 :
                ans += 1
print(ans)                

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

int main(void){
    
    int N,M,p,x;
    cin >> N;
    int data_T[N];
    
    for(int i=0;i<N;i++) cin >> data_T[i];
    
    cin >> M;
    
    for(int i=0;i<M;i++){
        cin >> p >> x;
        int sum = 0;
        for(int i=0;i<N;i++){
            if(i == (p-1)) sum += x;
            else sum += data_T[i];
        }
        cout << sum << endl; 
    }
    
}

Measured memory_bytes: 3556
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
const double PI=3.141592;
int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  string S,T;
  cin >> S >> T;
  if (T.size() != S.size() + 1) {
    cout << "No" << endl;
  } else {
    for (int i = 0; i < S.size(); i++) {
      if (T[i] != S[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  return 0;

}



Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n,m,p,q,r,x,y;
	vector<int>::iterator itx,ity,it;
	for(;cin>>n>>m>>p>>q>>r;cout<<x<<endl){
		vector<int> v1,v2;
		v1.push_back(0);
		for(v1.push_back(r);m--;v2.clear()){
			cin>>x>>y;
			itx=upper_bound(v1.begin(),v1.end(),x);
			ity=upper_bound(v1.begin(),v1.end(),y);
			
//			if( ity-v1.begin()+1 & 1 )v2.push_back(0);
//			v2.push_back(0);
			v2.insert(v2.end(),ity-v1.begin()&1?1:2,0);
			for(it=ity;it!=v1.end();++it)
				v2.push_back(*it - y);
			
			if(v1.end()-itx & 1)v2.push_back(n-y);
			for(it=itx;it!=ity;++it)
				v2.push_back(*it-x+n-y);
			
			it = v1.begin();
			if(ity-v1.begin() & 1)++it;
			if(!it[1])it+=2;
			if(*it+n-x==v2.back()){++it;v2.pop_back();}
			for(;it!=itx;++it)
				v2.push_back(*it+n-x);
			
			v1.swap(v2);
		}
		v1.insert( upper_bound(v1.begin(),v1.end(),p-1), 2, p-1);
		v1.insert( lower_bound(v1.begin(),v1.end(),q), q );
		v1.push_back(n);
		it = upper_bound(v1.begin(),v1.end(),p-1);
		if(it-v1.begin() & 1) --it;
		for(x=0;*it<q;
			x+=*it++-m)
			m=*it++;
	}
}

Measured memory_bytes: 0
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    d = [-1]*(N+1)
    v = 1
    i = 0
    P = []
    while d[v] == -1:
        P.append(v)
        d[v] = i
        v = A[v-1]
        i += 1
    c_length = i - d[v]  # 閉路長
    pre_c_length = d[v]
    if K < i:
        return print(P[K])
    else:
        K -= pre_c_length
        K %= c_length
        return print(P[pre_c_length+K])


if __name__ == '__main__':
    main()


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

typedef complex<double> P;
typedef pair<double, pair<int, pair<int, int>>> PLI;

#define EPS 1e-10

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

double cross( P a, P b ) {
	return (a.real()*b.imag() - a.imag()*b.real());
}
/*
double distance( P a, P b, P c ) {
	return abs( cross( b - a, c - a ) ) / abs( b - a );
}*/

double distance_p2p( P a, P b ) {
	return sqrtl( powl( (a.real() - b.real()), 2 ) + powl( (a.imag() - b.imag()), 2 ) );
}

double distance_ls_p( P a, P b, P c ) {
	if( dot( b - a, c - a ) < EPS ) {
		return abs( c - a );
	}
	if( dot( a - b, c - b ) < EPS ) {
		return abs( c - b );
	}
	return abs( cross( b - a, c - a ) ) / abs( b - a );
}

int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<P>points( N + 1 );
	points[0] = { ( double )X,( double )Y };
	for( size_t i = 1; i <= N; i++ ) {
		double x, y;
		cin >> x >> y;
		points[i] = { x,y };
	}
	priority_queue<PLI, vector<PLI>, greater<PLI>>que;
	vector<bool>is_group( N + 1 );
	vector<double >alllength( N + 1, LDBL_MAX / 6 );
	alllength[0] = 0;
	is_group[0] = true;
	int now_group_num = 1;

	for( size_t i = 1; i <= N; i++ ) {
		double dis = distance_p2p( points[0], points[i] );
		que.push( make_pair( dis, make_pair( i, make_pair( 0, 0 ) ) ) );
	}
	double ans = 0.0L;
	while( now_group_num <= M&& que.size() ) {
		auto now = que.top(); que.pop();
		int point_id = now.second.first;
		if( is_group[point_id] ) {
			continue;
		}
		int point_next_id = 0;
		/*
		double lengefirst = distance_p2p( points[point_id], points[now.second.second.first] );
		double lengesecond = distance_p2p( points[point_id], points[now.second.second.second] );

		if( abs( lengefirst - lengesecond ) < EPS ) {
			point_next_id = min( now.second.second.first, now.second.second.second );
		} else {
			if( lengefirst < lengesecond ) {
				point_next_id = now.second.second.first;
			} else {
				point_next_id = now.second.second.second;
			}
		}
		*/
		double next_length = LDBL_MAX / 6;
		for( size_t i = 0; i <= N; i++ ) {
			if( is_group[i] ) {
				double x_length = distance_p2p( points[point_id], points[i] );
				if( next_length > x_length + EPS ) {
					point_next_id = i;
					next_length = x_length;
				}
			}
		}
		//cout << point_id << " " << fixed << setprecision( 20 ) << now.first << endl;
		ans += distance_p2p( points[point_id], points[point_next_id] );
		is_group[point_id] = true;
		now_group_num++;
		for( size_t i = 0; i <= N; i++ ) {
			if( !is_group[i] ) {
				double len = distance_ls_p( points[point_id], points[point_next_id], points[i] );

				//cout << "!" << i << " " << point_id << " " << point_next_id << " " << fixed << setprecision( 20 ) << distance_ls_p( points[point_id], points[point_next_id], points[i] ) << endl;
				if( len + EPS < alllength[i] ) {
					alllength[i] = len;
					que.push( make_pair( distance_ls_p( points[point_id], points[point_next_id], points[i] ), make_pair( i, make_pair( point_id, point_next_id ) ) ) );
				}
			}
		}
	}
	cout << fixed << setprecision( 20 ) << ans << endl;
}

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

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

	i = 0;
	res = 1;
	while (res < k && i < n)
	{
		res *= 2;
		i++;
	}
	while (i < n)
	{
		res += k;
		i++;
	}
	cout << res << endl;
}


Measured memory_bytes: 256