akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=[int(input()) for _ in range(n)]

max_index=0
_max=max(a)
s=0

for i in range(n):
    if a[i]==_max and s<1:
        s+=1
        max_index=i
    elif a[i]==_max and s>=1:
        s+=1
        break

if s==1:
    for i in range(n):
        if i==max_index:
            print(max(a[:max_index]+a[max_index+1:]))
        else:
            print(_max)
else:
    for i in range(n):
        print(_max)

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

vector<int> G[100005];
int N,M;
int S,T;
int D[100005][3];

struct Edge {
  ll dist;ll parity;ll v;
  bool operator<(const Edge& rhs) const
  {
      return dist >= rhs.dist;
  }
};

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  cin>>N>>M;
  for(int i=0;i<M;i++){
    int u,v;cin>>u>>v;u--;v--;
    G[u].push_back(v);
  }
  cin>>S>>T;S--;T--;
  for(int i=0;i<100005;i++){
    for(int j=0;j<3;j++)D[i][j]=1000*1000*1000;
  }
  D[S][0] = 0;

  priority_queue<Edge> pq;
  pq.push({0,0,S});
  while(!pq.empty()){
    Edge e = pq.top(); pq.pop();
    ll v = e.v;
    ll parity=e.parity;
    int next=(parity+1)%3;

    ll dist=e.dist;
    if(D[v][parity]<dist) continue;
    for(auto u : G[v]){
      if(D[u][next]>D[v][parity]+1){
        D[u][next] = D[v][parity]+1;
        pq.push({D[u][next], next, u});
      }
    }
  }

  if(D[T][0]==1000*1000*1000){
    cout<<-1<<endl;
  }else{
    cout<<D[T][0]/3<<endl;
  }

  return 0;
}


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

int main()
{
    int a, b, c, A, B;
    cin >> A >> B;
    a = A + B;
    b = A - B;
    c = A * B;

    int max;
    max = (a > b) ? a : b;
    max = (max > c) ? max : c;
    cout << max;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int MOD = 1e9 + 7;



//AGCT⇒0123
//…012
//…021
//…102
//…01*2
//…0*12
//がダメ
int main() {

    int N;
    cin >> N;
    int dp[101][4][4][4] = {};

    dp[0][3][3][3] = 1;
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                for (int l = 0; l < 4; l++) {
                    if (dp[i][j][k][l] == 0)continue;
                    for (int a = 0; a < 4; a++) {
                        if (k == 0 && l == 1 && a == 2)continue;
                        if (k == 0 && l == 2 && a == 1)continue;
                        if (k == 1 && l == 0 && a == 2)continue;
                        if (j == 0 && k == 1 && a == 2)continue;
                        if (j == 0 && l == 1 && a == 2)continue;
                        dp[i + 1][k][l][a] += dp[i][j][k][l];
                        dp[i + 1][k][l][a] %= MOD;
                    }
                }
            }
        }
    }

    int ans=0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                ans += dp[N][i][j][k];
                ans %= MOD;
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,t[1000],size;
int main(){
  while(cin>>n&&n!=-1){
    size=0;
    while(n>0){
      t[size++]=n%4;
      n/=4;
    }

    if(size==0)cout<<0<<endl;
    else{
      for(int i=size-1;i>=0;i--){
	cout<<t[i];
      }
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int minus_manzoku(int c[], int last[], int d)
{
    int sum = 0;
    int i;
    for (i = 0; i < 26; i++) {
        sum += c[i] * (d - last[i]);
    }
    return sum;
}

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

    int c[26];
    int last[26];
    int i;
    for (i = 0; i < 26; i++) {
        cin >> c[i];
        last[i] = 0;
    }

    int s[D][26];
    int j;
    for (i = 0; i < D; i++) {
        for (j = 0; j < 26; j++) cin >> s[i][j];
    }

    int t[D];
    int max = 0;
    for (i = 0; i < 26; i++) {
        if (max < s[0][i]) {
            max = s[0][i];
            t[0] = i + 1; 
        }
    }

    long score = 0;
    for (i = 0; i < D; i++) {
        if (i == 0) {
            last[t[i] - 1] = i + 1;
            score += s[i][t[i] - 1] - minus_manzoku(c, last, i + 1);
            continue;
        }

        long max = -2000000000;
        long max_index = 0;
        for (j = 0; j < 26; j++) {
            int tmp_last = last[j];
            last[j] = i + 1;
            long tmp_score = score + s[i][j] - minus_manzoku(c, last, i + 1);
            if (max < tmp_score) {
                max = tmp_score;
                max_index = j;
            }
            last[j] = tmp_last;
        }
        score = max;
        last[max_index] = i + 1;
        t[i] = max_index + 1;
    }

    for (i = 0; i < D; i++) {
        cout << t[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3576
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split("");
  
	//出力
  var count = 0;
  for(var i=0; i<tmp.length ; i++){
  tmp[i]==1 && count++;
  }
	console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
    int n, m, l, i, j, k;
    scanf("%d %d %d", &n, &m, &l);
    int a[n][m], b[m][l];
    long long c[n][l] = {};

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }
    for (i = 0; i < m; i++)
    {
        for (j = 0; j < l; j++)
            scanf("%d", &b[i][j]);
    }

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < l; j++)
        {
            for (k = 0; k < m; k++)
            {
                c[i][j] += a[i][k] * b[k][j];
            }
            if (j == l - 1)
                printf("%lld\n", c[i][j]);
            else
                printf("%lld ", c[i][j]);
        }
    }
}


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

int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  cout << min(b/a,c) << endl;
}

Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'UTF-8');

const calculator = input => {
  const data = input.split('\n');
  const result = [];

  data.forEach(val => {
    const [a, op, b] = val.split(' ').map((val, index) => {
      return index === 1 ? val : Number(val);
    });

    if (op === '?') return false;
    switch (op) {
      case '+':
        result.push(a + b);
        break;
      case '-':
        result.push(a - b);
        break;
      case '*':
        result.push(a * b);
        break;
      case '/':
        result.push(Math.floor(a / b));
    }
  });

  console.log(result.join('\n'));
};

calculator(input);



Measured memory_bytes: 15404
#include <cstdio>
#include <climits>
#include <vector>
#include <queue>

constexpr int MAX_N = 100000;
constexpr int INF = INT_MAX;

template<class T>
using vec = std::vector<T>;

struct Edge {
    int to, age;
    Edge (int to, int age) : to{to}, age{age} {}
};

struct State {
    int c, v;
    State (int c, int v) : c{c}, v{v} {}

    bool operator < (const State &s) const {
        return c > s.c;
    }
};

int main()
{
    int N, M, a, b, c;
    scanf("%d %d", &N, &M);
    
    vec<Edge> G[MAX_N];
    for (int i = 0; i < M; i++) {
        scanf("%d %d %d", &a, &b, &c); a--; b--;
        G[a].push_back(Edge(b, c));
    }
    
    vec<int> d(MAX_N + 1, INF);
    d[0] = 1;

    std::priority_queue<State> pq;
    pq.push(State(1, 0));
    int res = -1;
    
    while (!pq.empty()) {
        State s = pq.top(); pq.pop();
        if (s.v == N - 1 || d[s.v] < s.c) continue;
        
        for (Edge &e : G[s.v]) {
            if (d[s.v] > e.age) continue;
            if (e.to == N - 1) {
                res = std::max(res, e.age);
            }
                
            if (e.age < d[e.to]) {
                d[e.to] = e.age;
                pq.push(State(d[e.to], e.to));
            }
        }
    }
    
    printf("%d\n", res);
    return 0;
}

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

int h, w, th;
string s[10];
int t[1001];

int sub(int q) {
  int d = __builtin_popcount(q) + 1;
  vector<int> masks(d);
  int cnt = 0;
  for (int i = 0; i < h; ++i) {
    masks[cnt] |= 1 << i;
    if (q & (1 << i)) ++cnt;
  }
  
  int ans = d - 1;
  vector<int> cur(d);
  for (int j = 0; j < w; ++j) {
    vector<int> del(d);
    for (int k = 0; k < d; ++k) {
      del[k] = __builtin_popcount(t[j] & masks[k]);
      cur[k] += del[k];
    }
    if (*max_element(del.begin(), del.end()) > th) return 1e9;
    if (*max_element(cur.begin(), cur.end()) > th) {
      for (int k = 0; k < d; ++k) {
        cur[k] = del[k];
      }
      ++ans;
    }
  }
  return ans;
}

int main() {
  cin >> h >> w >> th;
  for (int i = 0; i < h; ++i) cin >> s[i];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      t[j] |= (s[i][j] - '0') << i;
    }
  }
  ++w;
  
  int mn = 1e9;
  for (int q = 0; q < (1 << (h - 1)); ++q) {
    mn = min(mn, sub(q));
  }
  cout << mn << endl;
}


Measured memory_bytes: 256
// failed to generate code

#include <bits/stdc++.h>
using namespace std;

int main(){
	long long N, M, C;
	scanf("%lld",&N);
	scanf("%lld",&M);
	scanf("%lld",&C);
	long long B[M],A[N][M];
	for (int i=0; i<M; i++) {
		scanf("%lld",&B[i]);
	}
	for (int i=0; i<N; i++) {
		for (int j=0; j<M; j++) {
			scanf("%lld",&A[i][j]);
		}
	}

	long long res = 0;
	for (int i=0; i<N; i++) {
		long long sum = 0;
		for (int j=0; j<M; j++) {
			sum += A[i][j]*B[j];
		}
		sum += C;
		if (sum > 0) res++;
	}
	cout << res << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

int x,y,tu[11]={31,29,31,30,31,30,31,31,30,31,30};

int main(){
	while(1){
		cin>>x>>y;
		if(!x&&!y) break;
		int num=0;
		for(int i=0;i<x-1;i++) num+=tu[i];
		num+=y;
		int ans=num%7;
		if(ans==1) cout<<"Thursday"<<endl;
		else if(ans==2) cout<<"Friday"<<endl;
		else if(ans==3) cout<<"Saturday"<<endl;
		else if(ans==4) cout<<"Sunday"<<endl;
		else if(ans==5) cout<<"Monday"<<endl;
		else if(ans==6) cout<<"Tuesday"<<endl;
		else if(!ans) cout<<"Wednesday"<<endl;
	}
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
signed main()
{
    IOS
    int r,g,b,n; cin>>r>>g>>b>>n;
    int ans = 0;
    for(int i=0;i<=(n/r+1);i++)
    {
      for(int j=0;j<=(n/g + 1);j++)
      {
        int num = n - i*r - j*g;
        if(num < 0) continue;
        if(num%b == 0) ans++;
      }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(int argc, char const *argv[]) {
  char W[100][11];
  int N, flag = 1;

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", W[i]);
    if (i > 0 && W[i - 1][strlen(W[i - 1]) - 1] != W[i][0]) {
      flag = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) break;
      if (strcmp(W[i], W[j]) == 0) {
        flag = 0;
      }
    }
  }
  if (flag == 1) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int h, w, m, y, x;
    cin >> h >> w >> m;
    vector<Pii> hw(m);
    vector<Pii> cnth(h), cntw(w);
    for(int i=0;i<h;++i) cnth[i] = Pii(0, i);
    for(int i=0;i<w;++i) cntw[i] = Pii(0, i);
    for(int i=0;i<m;++i) {
        cin >> y >> x;
        --y; --x;
        hw[i] = Pii(y, x);
        ++cnth[y].first;
        ++cntw[x].first;
    }

    vector<Pii> cnth_unsort(cnth), cntw_unsort(cntw);
    sort(cnth.rbegin(), cnth.rend());
    sort(cntw.rbegin(), cntw.rend());
    // クロスした部分に爆破対象がある場合を考慮しないときの最大値
    int max_cnt = cnth[0].first + cntw[0].first;

    {
        y = 0;
        while(y < h && cnth[y].first == cnth[0].first) ++y;
        x = 0;
        while(x < w && cntw[x].first == cntw[0].first) ++x;
    }
    int point_has_max_cnt = y * x;

    // クロスした部分に爆破対象があり，かつ縦と横を足した値が max_cnt であるような場所は何箇所か
    int tmp_cnt = 0;
    {
        for(int i=0;i<m;++i) {
            tie(y, x) = hw[i];
            if(cnth_unsort[y].first + cntw_unsort[x].first == max_cnt) {
                ++tmp_cnt;
            }
        }
    }

    if(tmp_cnt == point_has_max_cnt) --max_cnt;

    cout << max_cnt << endl;    
}


Measured memory_bytes: 15052
#include<iostream>
#include<algorithm>
#include<cstring>
 using namespace std;
 typedef long long ll;
 int main()
 {
 	int n,m;
 	scanf("%d%d",&n,&m);
 	ll ans=0;
 	for(int i=1;i<=n;i++) ans+=n-i;
 	for(int i=1;i<=m;i++) ans+=m-i;
 	cout<<ans;
 	return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL);
#define fr(i,a,b)  for(int i=a;i<=b;i++)
#define rf(j,b,a)  for(int j=b;j>=a;j--)
#define frr(k,a,b) for(int k=a;k<=b;k++)
#define mp make_pair
#define pb push_back
#define MOD 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
signed main()
{   
	IOS
  /* #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif*/
int h,w;
cin>>h>>w;
char maze[h+1][w+1];
for(int i=1;i<=h;i++)
{
	for(int j=1;j<=w;j++)
	{
	cin>>maze[i][j];	
	}
}
int dp[h+1][w+1]={0};
memset(dp, 0, sizeof(dp));
dp[0][1]=0;
dp[1][0]=1;
for(int i=1;i<=h;i++)
{
	for(int j=1;j<=w;j++)
	{
	if(maze[i][j]=='.')
    {
    	dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
    }
    else
    {
    	continue;
    }
	}
}

cout<<dp[h][w]<<endl;
}









Measured memory_bytes: 9088
import numpy as np
import math
stdin = open(0)

N,K = map(int,input().split())
A = np.array([int(Ai) for Ai in input().split()])
A = np.sort(A)

maxA = max(np.abs(A))

z = A[A==0]
p = A[A>0]
n = A[A<0]

def check(x):
    ret = 0
    if x >= 0:
        ret += N*len(z)
    ret += np.searchsorted(A,x//p,side='right').sum()
    ret += (N - np.searchsorted(A, (x+1) // n, side='right')).sum()
#     ret += (N-np.searchsorted(A,np.ceil(x/n))).sum()
    ret -= np.count_nonzero(A*A<=x)
    return ret//2;

ub = maxA*maxA
lb = -ub-1
while ub-lb > 1:
    mid = (ub+lb)>>1
    if check(mid) < K:
        lb = mid
    else:
        ub = mid
print(ub)

Measured memory_bytes: 32252
N = int(input())
A = list(map(int, input().split()))
ans = []
S = sum(A)
S_2 = 0
for i in range(1, N - 1, 2):
    S_2 += A[i]
X1 = S - 2 * S_2
ans.append(str(X1))

for i in range(1, N):
    X = 2 * A[i - 1] - int(ans[i - 1])
    ans.append(str(X))
print(" ".join(ans))


Measured memory_bytes: 17224
#include <bits/stdc++.h>
using namespace std;
int a[5],b[5],ans;
int main(void){
    // Your code here!
    for(int i=0;i<5;i++)cin>>a[i];
    for(int i=0;i<5;i++)b[i]=a[i]%10;

    for(int i=0;i<5;i++){
        if(a[i]%10!=0)a[i]=((a[i]/10)+1)*10;
        ans+=a[i];
    }
    sort(b,b+5);
    int ppap=0;
   
    for(int i=5;i>=0;i--)if(b[i]>0)ppap=10-b[i];
    
    cout<<ans-ppap<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    ll x, k, d;
    cin >> x >> k >> d;
    ll over = abs(x)%d;
    ll steps = abs(x)/d;
    if(steps > k){
        cout << (abs(x) - d*k) << "\n";
        return 0;
    }
    ll rem = k - steps;
    if(rem%2 == 0){
        cout << over << "\n";
    } else{
        cout << abs(over-d) << "\n";
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;
typedef unsigned int i64;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define bye(x) return void (cout <<(x) << endl);
#define all(e) (e).begin(), (e).end()
#define pb push_back

template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}


template <typename T>
void printV(vector<T> A) {
  if (A.empty()) cerr << "EMTPY\n";
  else { 
    cerr << "[";
    for (int i = 0; i < A.size() -1 ; ++i) {
      cerr << A[i] << ", ";
    }
    if (A.size()) cerr << A.back() << "]\n";
  }
}


template <typename T>
void printVV(vector<vector<T>> A) {
  cerr << "[";
  for (auto v : A) {
    printV<T>(v);
  }
  cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  if (s == "SUN") cout << 7 << endl;
  if (s == "MON") cout << 6 << endl;
  if (s == "TUE") cout << 5 << endl;
  if (s == "WED") cout << 4 << endl;
  if (s == "THU") cout << 3 << endl;
  if (s == "FRI") cout << 2 << endl;
  if (s == "SAT") cout << 1 << endl;
  return 0;
}



Measured memory_bytes: 256
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N,A,B,C=rl()
l=[ri() for _ in range(N)]
ans = 10**18
import itertools
for seq in itertools.product(range(4),repeat=N):
    a,b,c=0,0,0
    rst = 0
    for i in range(N):
        if seq[i]==1:
            a+=l[i]
            rst+=10
        elif seq[i]==2:
            b+=l[i]
            rst+=10
        elif seq[i]==3:
            c+=l[i]
            rst+=10
    if a*b*c != 0:
        rst += abs(A-a)+abs(B-b)+abs(C-c)-30
        if ans > rst:
            ans = rst

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ALL(a) a.begin(),a.end()
int main(){
  int n;
  while( cin >> n , n ){
    vector < int > p[n],L;
    for(int i = 0, q, d ; i < n && cin >> q ; sort(ALL(p[i])), i++ ){
      while(q--) cin >> d, p[i].push_back(--d);
    }
    int K, l, ans = -1, flg = -1;
    cin >> K;
    while(K--) cin >> l, L.push_back(--l);
    sort(ALL(L));
    for(int i = 0 ; i < n && flg<=0 ; i++ ){
      if(includes(ALL(p[i]),ALL(L))) ans = i + 1, flg++;
    }
    cout << (flg ? -1 : ans) << endl;
  }
}

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


int main()
{
    int n; string s;
    cin>>n;
    map<string, int>ip;
    map<string, int>::iterator itr;
    for(int i=0; i<n; i++){
        cin>>s;
        itr = ip.find(s);
        if(itr==ip.end()){
            ip[s] = 1;
        }else{
            itr->second++;
        }
    }
    cout<<ip.size()<<endl;
}


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

typedef long long ll;
int num[24*60*60]; //?????????,?§?????????£???????????°??°

int main(){
  int n;
  while(cin>>n, n!=0){
    for(ll i=0; i<24*60*60; i++)num[i]=n;
    for(int i=0; i<n; i++){
      int sh, sm, ss, eh, em, es;
      scanf("%2d:%2d:%2d %2d:%2d:%2d", &sh, &sm, &ss, &eh, &em, &es);
      for(ll j=(sh*60*60)+(sm*60)+ss; j<(eh*60*60)+(em*60)+es; j++)
	num[j]--;
    }
    int mini=n;
    for(ll i=0; i<24*60*60; i++)
      if(mini>num[i])mini=num[i];
    cout<<n-mini<<endl;
  }
  return 0;
}

Measured memory_bytes: 1576
import sys
input=sys.stdin.readline

Q,H,S,D = map(int, input().split())
N = int(input())

p = [Q,H,S,D]
for i in range(1,4):
    q = [p[i]]
    for j in range(0,i):
        q.append(p[j]*2**(i-j))
    p[i] = min(q)
#print(p)

ans = 0
N *= 4
while N>0:
    if N>=8:
        x = N//8
        ans += p[3]*x
        N-=8*x
    elif N>= 4:
        ans += p[2]
        N-=4
    elif N>= 2:
        ans += p[1]
        N-=2
    else:
        ans += p[0]
        N-=1
print(ans)


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
l = [0] * N

for i in range(1, N + 1):
    count = 0
    c = i
    while c < K:
        c *= 2
        count += 1
        
    l[i - 1] = (1 / N * (0.5 ** count))
    
print(sum(l))

Measured memory_bytes: 6132
import Control.Monad
import Control.Monad.Primitive (PrimState)
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.IORef

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    as <- V.fromList . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    mv <- MV.unsafeNew (n + 1) :: IO (MV.MVector (PrimState IO) Int)
    l <- newIORef (n `div` 2)
    r <- newIORef (n `div` 2 + 1)
    forM_ [0..(n - 1)] $ \i ->
        if i `mod` 2 == (n - 1) `mod` 2
            then do
                m <- readIORef l
                MV.unsafeWrite mv m (as V.! i)
                modifyIORef l pred
            else do
                m <- readIORef r
                MV.unsafeWrite mv m (as V.! i)
                modifyIORef r succ
    j <- readIORef l
    v <- V.unsafeFreeze $ MV.slice (j + 1) n mv
    putStrLn $ unwords $ map show $ V.toList v


Measured memory_bytes: 14076
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,x=0,y=0;
    string str;
    cin>>str;
    for(i=0; str[i]; i++)
    {
        if(i%2==0 && str[i]=='1')
            x++;
        else if(i%2==1 && str[i]=='0')
            x++;
        if(i%2==0 && str[i]=='0')
            y++;
        else if(i%2==1 && str[i]=='1')
            y++;
    }
    cout<<min(x,y)<<endl;

    return  0;
}


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

#define PMAX 323456

using namespace std;

int main(){
	vector<int> prime;
	bool pr[PMAX]={0};
	pr[0] = pr[1] = true;
	for(int i=0; i<PMAX; i++){
		if( !pr[i] ){
			prime.push_back(i);
			for(int j=2*i; j<PMAX; j+=i)
				pr[j] = true;
		}
	}
	int n;
	while( cin >> n, n){
		int ans=0;
		for(int i=0; i<prime.size(); i++){
			if( n < prime[i] && prime[i] <= 2*n )
				ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int D;
    cin >> D;
    int d[26];
    vector<int> last(26, 1);

    rep(i, 26) {
        cin >> d[i];
    }

    vector<vector<int>> s(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> ans(D);

    ll level = 0;
    rep(i, D) {
        ll now = 0;
        ll maxnow = -INF;

        if (i <= D - 3) {
            maxnow = -INF;
            rep(j, 26) {
                rep(k, 26) {
                    rep(l, 26) {
                        now = 0;
                        int t[3] = {j, k, l};
                        vector<int> tlast = last;

                        rep(m, 3) {
                            now += s[i + m][t[m]];
                            tlast[t[m]] = 0;

                            rep(n, 26) {
                                now -= d[n] * tlast[n];
                                tlast[n]++;
                            }
                        }

                        //更新
                        if (now > maxnow) {
                            maxnow = now;
                            ans[i] = j;
                            ans[i + 1] = k;
                            ans[i + 2] = l;
                        }
                    }
                }
            }
        }
        //計算
        level += s[i][ans[i]];
        last[ans[i]] = 0;
        rep(j, 26) {
            level -= d[j] * last[j];
            last[j]++;
        }
    }

    vector<int> koho(D);
    koho = ans;

    mt19937 rd(1);
    while (clock() * 1000 / CLOCKS_PER_SEC <= 1970) {
        koho = ans;
        vector<int> tlast(26, 1);
        koho[rd() % D] = rd() % 26;

        ll tmp = 0;
        rep(i, D) {
            tmp += s[i][koho[i]];
            tlast[koho[i]] = 0;

            rep(j, 26) {
                tmp -= d[j] * tlast[j];
                tlast[j]++;
            }
        }

        if (tmp > level) {
            ans = koho;
            level = tmp;
        }
    }

    rep(i, D) {
        cout << ans[i] + 1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 3728
#include<iostream>

using namespace std;

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	int min = 0,minx = 100000,miny = 100000;
	int* x = new int[A];
	int* y = new int[B];
	for (int i = 0; i < A; i++) {
		cin >> x[i];
		if (x[i] < minx)
			minx = x[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> y[i];
		if (y[i] < miny)
			miny = y[i];
	}
	min = minx + miny;
	for (int i = 0; i < M; i++) {
		int xi, yi, c;
		cin >> xi >> yi >> c;
		if (x[xi -1] + y[yi - 1] - c < min)
			min = x[xi - 1] + y[yi-1] - c;
	}
	cout << min;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	char s[15];
	scanf("%s", s);
	
	int yes = 1;
	for(int i = 0, n = a + b + 1; i < n ; i++)
	{
		if((i != a && s[i] >= '0' && s[i] <= '9') || (s[i] == '-' && i == a)) continue;
		yes = 0;
		break;
	}
	if(yes) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,m;cin>>n>>m;
    ll g=m/n;
    for(;g>=1;g--){
        if(m%g==0){
            cout<<g<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define BIG_NUM 1000000000000000000LL

int main()
{
    int n;
    cin >> n;
    vector<unsigned long long> vec(n);
    long long int ans = 1;
    for(int i = 0; i < n; ++i)
    {
        cin >> vec[i];
        if(vec[i] == 0)
        {
            ans = 0;
        }
    }

    if(ans == 0)
    {
        cout << ans << endl;
        return 0;
    }

    for(int i = 0; i < n; ++i)
    {
        unsigned long long preb = ans;
        ans *= vec[i];
        if(preb > BIG_NUM / vec[i])
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define sc second
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define sp(n) cout << fixed << setprecision(n)
#define ma(n, o) map<n, o>
#define pr(n, o) pair<n, o>
#define so(n) sort(n.begin(), n.end())
#pragma endregion
// abs 絶対値, rtsq ルート, pow(a, n) aのn乗

int main() {
  int A, B;
  ci(A, B);
  if(A >= 13) {
    co(B);
  }
  else if(5 < A && A <= 12) {
    co(B / 2);
  }
  else {
    co(0);
  }
} 


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

A = LI()
ans = INF
for x, y, z in permutations(A, 3):
    ans = min(ans, abs(y-x)+abs(z-y))
print(ans)


Measured memory_bytes: 64492
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  string s;
  cin >> s;
  bool f = (s[0] == 'A');
  int c_num = 0, small_num = 0;
  REP(i, s.length()) if(s[i] >= 'a') small_num++;
  FOR(i, 2, s.length() - 1) if(s[i] == 'C') c_num++;

  f &= (c_num == 1) && (small_num == (int)s.length() - 2);

  cout << (f ? "AC" : "WA") << endl;

  return 0;
}

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

int main()
{
	long long int n,l;
	cin >> n >> l;
	long long int sum=n*l+n*(n+1)/2-n;
	int a=l;
	int b=l+n-1;
	if(a<=0 &&  b>=0)
		cout << sum;
	else if(b<=0)
		cout << sum-b;
	else
		cout << sum-a;
}


Measured memory_bytes: 256
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

typedef vector <int> vi;
typedef vector <long long> vl;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define ll long long
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second

ll modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x;
    cin >> n >> x;
    int arr[n];
    FOR(i,0,n)
        cin >> arr[i];
    sort(arr, arr+n);
    int cnt = 0, ans = 0;
    while (x >= arr[cnt] and cnt < n-1)
    {
        x -= arr[cnt];
        ++cnt;
        ++ans;
    }
    if (arr[n-1] == x)
        ++ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
# Aizu Problem 00161: Sport Meet
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = 1000000
hamming = [False] * (N + 1)
ans = [0] * (N + 1)
hamming[1] = True
ans[1] = 1
for k in range(2, N + 1):
    if (k % 2 == 0 and hamming[k//2]) or \
       (k % 3 == 0 and hamming[k//3]) or (k % 5 == 0 and hamming[k//5]):
        hamming[k] = True
    ans[k] = ans[k-1]
    if hamming[k]:
        ans[k] += 1


while True:
    s = [int(_) for _ in input().split()]
    if len(s) == 1 and s[0] == 0:
        break
    m, n = s[:]
    print(ans[n] - ans[m-1])

Measured memory_bytes: 23056
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use std::collections::HashMap;

fn gcv(a: usize, b:usize) -> usize {
  if b == 0 {
    a
  } else {
    gcv(b, a % b)
  }
}

#[fastout]
fn main() {
  input! {
    n: usize,
    x: usize,
    mut arr: [usize;n],
  }
  
  arr.push(x);
  arr.sort();
  
  let mut vals: Vec<usize> = vec![0;n];
  for i in 1..n+1 {
    vals[i-1] = arr[i] - arr[i-1];
  }
  
  let mut v = vals[0];
  for i in 0..vals.len() {
    v = gcv(v, vals[i]);
  }
  
  println!("{}", v);
}

Measured memory_bytes: 4472
#include <iostream>

using namespace std;

int a[10010]={0};



int main()
{
    int n,m;
    cin>>n;
    int i,j,k;
    for(i=1;i<=50;i++)
        for(j=i;j<=60;j++)
            for(k=j;k<=100;k++)
    {
        if((i*i+j*j+k*k+i*j+j*k+k*i)>10000) continue;
        if(i==j&&j==k) m=1;
        else if(i==j||j==k||k==i) m=3;
        else m=6;
        a[i*i+j*j+k*k+i*j+j*k+k*i]+=m;
    }
    for(i=1;i<=n;i++)
        cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 3580
// ABC 148-A
// 2019.12.22 bal4u

#include <stdio.h>

int a[4];

int main()
{
	int i, A, B;
	
	scanf("%d%d", &A, &B);
	a[A] = 1, a[B] = 1;
	for (i = 1; i <= 3; ++i) if (a[i] == 0) {
		printf("%d\n", i);
		break;
	}
	return 0;
}


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



int main() {
	string S;
	int A;
	cin >>A>> S;
	
	rep(0, S.size()) {

		if ((S.at(i) + A) > (int)'Z') {
			cout << (char)(('A' - 1) + (((int)S.at(i) + A) - 'Z'));
			continue;
		}
		cout << (char)(S.at(i) + A) ;
		
	}
	cout << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
    int d;cin>>d;
    ll c[26];
    rep(i,26)cin>>c[i];
    ll s[d][26];
    rep(i,d)rep(j,26)cin>>s[i][j];
    ll t[d];
    rep(i,d){
        cin>>t[i];
        t[i]--;
    }
    ll v=0;
    vi pas(26,0);
    rep(i,d){
        v+=s[i][t[i]];
        pas[t[i]]=i+1;
        rep(j,26){
            if(j==t[i])continue;
            v-=c[j]*(i+1-pas[j]);
        }
        cout<<v<<endl;
    }
}

Measured memory_bytes: 3704
#include<cmath>
#include<iostream>
using namespace std;
#define SQ(x)((x)*(x))
int main(){
    int N;
    cin >> N;

    while(N){
	N--;
	int x,y,ax,ay;
	x=y=0;
	ax=ay=0;
	for(;;){
	    int dx,dy;
	    cin >>dx>>dy;
	    x+=dx;
	    y+=dy;
	    //cout << "#" << dx<<" " << dy<<endl;
	    if (dx==0 && dy==0)break;
	    if (SQ(x)+SQ(y)>=SQ(ax)+SQ(ay)){
		if(SQ(x)+SQ(y)==SQ(ax)+SQ(ay)){
		    if(x>ax){
			ax=x;
			ay=y;
		    }

		}
		else{
		    ax=x;
		    ay=y;
		}
	    }
	}
	cout << ax << " " << ay << endl;
    }
    return 0;
}
			

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

int main() {
    int n, m;
    cin >> n >> m;
    
    cout << (n * (n-1)) / 2 + (m * (m-1)) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int gcd(int x,int y){
	
	if(x%y==0){
		return y;
	}else{
		return gcd(y,x%y);
	}
	
}

int main() {
	
	int n;
	cin>>n;
	map<int,int> S;
	int i=1;
	while(true){
		if(S[n]!=0){
			ce(i)
			break;
		}else{
			S[n]=1;
			if(n%2==0){
				n/=2;
			}else{
				n=3*n+1;
			}
			
		}
		i++;
	}
	
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main()
{
    int n;
    cin >> n;
    int ans=1;
    int cc = 0;
    trep(i, 1, n + 1)
    {
        int j = i;
        int count = 0;
        while (j % 2 == 0)
        {
            j /= 2;
            count++;
        }
        if (count > cc)
        {
            cc = count;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 105;
const ll K = 1e5 + 10;
const ll M = 1e9 + 7;
ll n, k;
ll a[N], dp[N][K], ps[N][K];

ll subs(ll a , ll b) {
  return (((a % M) - (b % M)) + 2 * M) % M;
}

ll add(ll a , ll b) {
  return ((a % M) + (b % M)) % M;
}

ll rsum(ll l , ll r , ll idx) {
  if (l > r) return 0;
  return subs(ps[idx][r] , ps[idx][l - 1]);
}

int main() {
  scanf("%lld%lld" , &n , &k);
  for (ll i = 1 ; i <= n ; i++) {
    scanf("%lld" , &a[i]);
  }
  for (ll cur = 0 ; cur <= n ; cur++) {
    for (ll rem = 0 ; rem <= k ; rem++) {
      ll &sol = dp[cur][rem];
      if (cur == 0) {
        sol = (rem == 0);
      } else {
        sol = rsum(rem - min(rem , a[cur]) , rem , cur - 1);
      }
      if (rem) {
        ps[cur][rem] = add(ps[cur][rem - 1] , sol);
      } else {
        ps[cur][rem] = sol;
      }
    }
  }
  printf("%lld\n" , dp[n][k]);
  return 0;
}

void in(ll &x){
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 161668
#include <stdio.h>
#include <iostream>
#include <math.h>

using namespace std;

void func(int h,int w){
    double min_orig;
    double min_l;
    int min_w,min_h;
    min_orig = sqrt(w*w + h*h);
    min_l = sqrt(150*150 + 150*150);
    for(int i=1;i<=150;i++){
        for(int j=i+1;j<=150;j++){
            if(i!=h||j!=w){
                if(min_orig<=sqrt(i*i + j*j)&&min_l>=sqrt(i*i+j*j)){
                    if(min_orig==sqrt(i*i + j*j)&&min_l==sqrt(i*i+j*j)){
                        if(i>h&&i<min_h){
                            min_l = sqrt(i*i + j*j);
                            min_w = j;
                            min_h = i;                    
                        }
                    }else if(min_orig==sqrt(i*i + j*j)){
                        if(i>h){
                            min_l = sqrt(i*i + j*j);
                            min_w = j;
                            min_h = i;                    
                        }
                    }else if(min_l==sqrt(i*i+j*j)){
                        if(i<min_h){
                            min_l = sqrt(i*i + j*j);
                            min_w = j;
                            min_h = i;                    
                        }                        
                    }else{
                        min_l = sqrt(i*i + j*j);
                        min_w = j;
                        min_h = i;                        
                    }
                }
            // }
            }
        }
    }
    cout << min_h << " " << min_w << endl;
}

int main(){
    int h,w;
    while(1){
        cin >> h >> w;
        if(w==0&&h==0) break;
        func(h,w);
    }
    
}







Measured memory_bytes: 3084
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e5+5;
int A[maxn],B[maxn];

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    int N,K;
    while (cin >> N >> K) {
        LL ans = 0;
        FOR(i,0,N) {
            cin >> A[i] >> B[i];
            if ((A[i]&K) == A[i])
                ans += B[i];
        }
        FORR(i,30,0) {
            const int x = 1<<i;
            LL res = 0;
            if (K & x) {
                const int mask = (K^x) | (x-1);
                FOR(i,0,N) if ((mask&A[i]) == A[i]) 
                    res += B[i];
            }
            ans = max(ans,res);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#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>;
static const double PI = acos(-1);



int main(){
  ll n, k;
  cin >> n >> k;
  vector<int> a(n); //テレポート先を記録
  vector<int> cnt(n);
  vector<bool> flg(n);

  REP(i,n){
    int x;
    cin >> x;
    --x;
    a[i] = x;
  }
  REP(i,n) flg[i] = true;

  ll pos = 0;
  ll roop = 0;
  ll s = 0;
  for(ll i = 0; i < k ; ++i){
    //cout << pos << endl;

    if(flg[pos]){
      // cout << "Pos:" << pos+1 << endl;
      cnt[pos] = i;
      flg[pos] = false;
      pos = a[pos];  //テレポート
    }
    else{
      roop = i - cnt[pos];
      s = cnt[pos];
      break;
    }

    //閉路がなかった場合
    if(i == k - 1){
      ++pos;
      cout << pos << endl;
      return 0;
    }
  }

  // cout << "Pos:" << pos << endl;
  // cout << "roop:" << roop << endl;

  //自己ループ
  if(roop == 0){
    ++pos;
    cout << pos << endl;
    return 0;
  }
  // cout << "===="<< endl;
  // cout << k%roop << endl;
  if((k-s)%roop == 0){

    ++pos;
    cout << pos << endl;
    //REP(i,n) cout << a[i] << endl;
    return 0;

  }
  else{
    REP(i,(k-s)%roop){
    //  cout << "Pos:" << pos+1 << endl;
      pos = a[pos];
    }
    ++pos;
    cout << pos << endl;
    //REP(i,n) cout << a[i] << endl;
    return 0;
  }
  cout << k%roop << endl;

}

Measured memory_bytes: 4812
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define elif else if
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main()
{
    ffast;
    //freopen("0in.txt","r",stdin);
    //freopen("0out.txt","w",stdout);


    unsigned long long int t;
    cin>>t;
    unsigned long long int ans = 0;
    while(t)
    {

        if(t%3==0)
        {
            t--;
            continue;
        }
        else if(t%5==0)
        {
            t--;
            continue;
        }
        else
        {
            ans += t;
            //cout<<t<<endl;
            t--;
        }

    }
    cout<<ans<<"\n";
    return 0;
}






Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;
using ll = long long int;

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

int main(){
    ll L, R;
    cin >> L >> R;

    bool t = false, s = false;

    for(ll i = L; i <= R; ++i){
        if(i % 3 == 0) t = true;
        if(i % 673 == 0) s = true;
        if(t && s) break;
    }
    if(t && s){
        cout << 0 << endl;
        return 0;
    }

    ll minv = 2019;
    for(ll i = L; i <= R; ++i){
        for(ll j = i+1; j <= R; ++j){
            auto tmp = (i * j) % 2019;
            if(minv > tmp) minv = tmp;
        }
    }
    cout << minv << endl;
}


Measured memory_bytes: 256