akhauriyash/Code-Regression huggingface dataset:
N = int(input())
h = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
  dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
  dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print(dp[N-1])

Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll dfs(ll n, vector<ll> arr[],ll dist[],bool visited[])
{
	if(visited[n]==true)
		return dist[n];
	visited[n]=true;
	for(ll i=0;i<arr[n].size();i++)
	{
		dist[n]=max(dist[n],dfs(arr[n][i],arr,dist,visited)+1);
	}
	return dist[n];
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("test.txt","r",stdin);
	ll n,m;
	cin>>n>>m;
	vector<ll> arr[n+1];
	ll x,y;
	for(ll i=0;i<m;i++)
	{
		cin>>x>>y;
		arr[x].push_back(y);
	}
	ll dist[n+1];
	bool visited[n+1];
	for(ll i=0;i<=n;i++)
	{
		dist[i]=0;
		visited[i]=false;
	}
	for(ll i=1;i<=n;i++)
	{
		if(visited[i]==0){

			dist[i]=dfs(i,arr,dist,visited);
		}
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
		ans=max(ans,dist[i]);
	cout<<ans<<endl;



}

Measured memory_bytes: 9344
#16D8101012J 伊藤惇 dj Python3 

def area(a,b):
    c=a*b
    return c

def perimeter_of_the_rectangle(a,b):
    c=(a+b)*2
    return c

def Rectangle():
    a,b=map(int,input().split())
    c=area(a,b)
    d=perimeter_of_the_rectangle(a,b)
    print("{} {}".format(c,d))

if __name__ == '__main__':
    Rectangle()



Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define fi first
#define se second

const ll INF = 1e15;

int W, H;
vector<string> brd;
vector<vector<ll> > dist_spring;
vector<vector<ll> > dist_goal;

bool check(int y, int x) {
	return 0 <= y && y < H && 0 <= x && x < W;
}

void bfs(queue<pii> q, vector<vector<ll> > & res) {
	ll d = 0;
	queue<pii> nex;
	while(q.size()) {
		while(q.size()) {
			pii crd;
			crd = q.front(); q.pop();
			res[crd.fi][crd.se] = min(res[crd.fi][crd.se], d);
			rep(i,4) {
				const int dxy[] = {0,1,0,-1,0};
				int ny, nx;
				ny = crd.fi + dxy[i];
				nx = crd.se + dxy[i+1];
				if(check(ny,nx) && (brd[ny][nx] == '.' || brd[ny][nx] == 's')
						&& res[ny][nx] == INF) {
					nex.push(pii(ny,nx));
					res[ny][nx] = d+1;
				}
			}
		}
		q = nex;
		while(nex.size()) nex.pop();
		d++;
	}
}

void make_dist_spring() {
	queue<pii> q;
	rep(i,H) {
		dist_spring.push_back(vector<ll>(W, INF));
		rep(j,W) {
			if(brd[i][j] == '*')
				q.push(pii(i,j));
		}
	}
	bfs(q, dist_spring);
}

void make_dist_goal() {
	queue<pii> q;
	rep(i,H) {
		dist_goal.push_back(vector<ll>(W,INF));
		rep(j,W) {
			if(brd[i][j] == 'g')
				q.push(pii(i,j));
		}
	}
	bfs(q, dist_goal);
}

int main() {
	pii st;
	cin >> W >> H;
	rep(i,H) {
		string s;
		cin >> s;
		brd.push_back(s);
		rep(j, W) {
			if(s[j] == 's')
				st = pii(i,j);
		}
	}
	make_dist_spring();
	make_dist_goal();

	double l, r, m;
	l = 0; r = INF;
	rep(i,100) {
		m = (l+r) / 2;
		double a, b;
		ll c, d, e;
		a = b = 0;
		c = d = e = 0;
		rep(j, H) {
			rep(k, W) {
				if(brd[j][k] == '.' || brd[j][k] == 's') {
					a += min((double)dist_goal[j][k], dist_spring[j][k] + m);
					if(dist_goal[j][k] > dist_spring[j][k] + m) {
						d += dist_spring[j][k];
						e++;
					}
					else {
						d += dist_goal[j][k];
					}
					c++;
				}
			}
		}
		a = d + e * m;
		b = c * m;
		if(a > b)
			l = m;
		else
			r = m;
	}
	cout << setprecision(15) << fixed <<
		min((double)dist_goal[st.fi][st.se], dist_spring[st.fi][st.se] + m) << endl;
}

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

using namespace std;

typedef long long ll;

ll dp[105][100005], v[105], w[105];
int N;

ll const INF = 1<<30;

ll f(int i, ll sum){
	if(sum<0)
		return INF;
	if(sum==0)
		return 0;
	if(i==N)
		return INF;
	if(dp[i][sum] != -1)
		return dp[i][sum];
	dp[i][sum] = min(f(i+1, sum), f(i+1, sum-v[i])+w[i]);
	return dp[i][sum];
}

int main(){
	int W;
	cin>>N>>W;
	for(int i=0;i<N;i++){
		cin>>w[i]>>v[i];
	}
	memset(dp, -1, sizeof dp);
	for(int i=100000;i>=0;i--){
		if(f(0, i) <= W){
			cout<<i<<"\n";
			break;
		}
	}
	return 0;
}

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

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

  int ans = 0;
  int cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') {
      cnt++;
      ans = max(cnt, ans);
    }
    else {
      ans = max(cnt, ans);
      cnt = 0;
    }
  }
  cout << ans << endl;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    vector<i64> X(5);
    REP(i, 5) {
        cin >> X[i];
        if (X[i] == 0) {
            cout << (i + 1) << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	static class Card {
		String mark;
		int num;
		int order;
		public Card(String mark, int num, int order) {
			this.mark = mark;
			this.num = num;
			this.order = order;
		}
		public String toString() {
			return String.format("%s %d", mark, num);
		}
	}
	
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		Card[] cards = new Card[n];
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			String mark = st.nextToken();
			int num = Integer.parseInt(st.nextToken());
			cards[i] = new Card(mark, num, i);
		}
		reader.close();
		
		quickSort(cards, 0, n - 1);
		boolean stable = checkStability(cards);
		if (stable) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}		
		for (Card card : cards) {
			System.out.println(card);
		}
	}

	private static boolean checkStability(Card[] cards) {		
		for (int i = 1; i < cards.length; i++) {
			Card c1 = cards[i - 1];
			Card c2 = cards[i];
			if (c1.num == c2.num && c1.order > c2.order) {
				return false;
			}
		}		
		return true;
	}

	private static void quickSort(Card[] cards, int p, int r) {
		if (p < r) {
			int q = partition(cards, p, r);
			quickSort(cards, p, q - 1);
			quickSort(cards, q + 1, r);
		}
	}

	private static int partition(Card[] cards, int p, int r) {
		int x = cards[r].num;
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (cards[j].num <= x) {
				i ++;
				swap(cards, i, j);
			}
		}
		swap(cards, i + 1, r);
		return i + 1;
	}

	private static void swap(Card[] cards, int i, int j) {
		Card tmp = cards[i];
		cards[i] = cards[j];
		cards[j] = tmp;
	}	
}


Measured memory_bytes: 152384
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;
#define N 200000
bool sx[N + 1], xe[N + 1];
int n, m, a, b;


int main() {
	//九日目

	cin >> n >> m;
	rep(i, m) {
		cin >> a >> b;
		if (a == 1) {
			sx[b] = true;
		}
		else if (b == n) {
			xe[a] = true;
		}
	}
	string ans = "IMPOSSIBLE";
	rep(i, n) {
		if (sx[i] && xe[i]) {
			ans = "POSSIBLE";
			break;
		}
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0, 0, -1};
const vector<int> dy = {0, 1, -1, 0};

// 約数全列挙
set<ll> enum_div(ll n){
  set<ll> ret;
  for (ll i=1; i*i<=n; i++){
    if (n%i==0){
      ret.insert(i);
      if (i!=1&&i*i!=n) ret.insert(n/i);
    }
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  map<int, int> dict; // 登場する数字と登場回数
  for (int i=0; i<N; i++) {
    if (dict.count(A[i])) dict[A[i]]++;
    else dict[A[i]] = 1;
  }
  for (auto p: dict) {
    auto key = p.first;
    auto value = p.second;
    if (value!=1) dict[key] = 0;
  }
  for (auto p: dict) {
    auto key = p.first;
    auto value = p.second;
    if (value==0) continue;
    set<ll> s = enum_div(key);
    for (auto value2: s) {
      if (dict.count(value2)&&key!=1) dict[key] = 0;
    }
  }
  int res = 0;
  for (auto p: dict) {
    auto value = p.second;
    res += value;
  }
  cout << res << endl;
  return 0;
}


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

int gcd(int m, int n) {
    if (m == 0 || n == 0) {
        return 0;
    }
    while (m != n) {
        if (m > n) {
            m = m - n;
        } else {
            n = n - m;
        }
    }
    return m;
}

int main() {
    int a, b;
    while (cin >> a >> b) {
        int g = gcd(a, b);
        int l = a / g * b;
        cout << g << " " << l << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi acos(-1)
#define lli long long int
using namespace std;

int main() 
{
    lli t,n,i,j,tmp;
    cin >> t;
    vector<lli> arr(t+2);
    string s[t],str;
    
    for ( i = 0; i < t; i++)
        cin >> s[i] >> arr[i];
    
    cin >> str;

    for ( i = 0; i < t; i++)
    {
        if(str.compare(s[i]) == 0) {
            tmp = i;
            break;
        }
    }
    lli ans = 0;
    for ( i = tmp+1; i < t; i++)
    {
        ans += arr[i];
    }
    cout << ans << endl;


    return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int difx = x1 - x2;
  int dify = y1 - y2;
  int x3 = x2 + dify;
  int y3 = y2 - difx;
  int x4 = x3 + difx;
  int y4 = y3 + dify;
  cout << x3 <<" " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;

int main(void) {
    ll H, W;
    cin >> H >> W;
    ll i;
    ll ans=INF, tmax, tmin;
    for(i=1; i<=H; i++) {
        tmax=max(i, max((H-i)/2, (H-i)-(H-i)/2));
        tmin=min(i, min((H-i)/2, (H-i)-(H-i)/2));
        ans=min(ans, (tmax-tmin)*W);
        
        tmax=max(i*W, max((H-i)*(W/2), (H-i)*(W-W/2)));
        tmin=min(i*W, min((H-i)*(W/2), (H-i)*(W-W/2)));
        ans=min(ans, tmax-tmin);
    }
    
    for(i=1; i<=W; i++) {
        tmax=max(i, max((W-i)/2, (W-i)-(W-i)/2));
        tmin=min(i, min((W-i)/2, (W-i)-(W-i)/2));
        ans=min(ans, (tmax-tmin)*H);
        
        tmax=max(i*H, max((W-i)*(H/2), (W-i)*(H-H/2)));
        tmin=min(i*H, min((W-i)*(H/2), (W-i)*(H-H/2)));
        ans=min(ans, tmax-tmin);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()

result = S
while True:
    while True:
        t = S.replace('()', '')
        if t == S:
            break
        S = t
    if S == '':
        break
    elif S[0] == ')':
        S = '(' + S
        result = '(' + result
    elif S[0] == '(':
        S = S + ')'
        result = result + ')'
print(result)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
	int balls;
	int bx;
	cin >> balls;
	cin >> bx;
	
	int dist = 0;
	for (int i = 0; i < balls; ++i) {
		int x;
		cin >> x;
		
		dist += 2*(min(bx-x, x));
	}
	
	cout << dist << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<ll>A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	int flag_u=false, flag_d=false;
	int count = 0;
	for (int i = 1;i < N;i++) {
		if (A[i] - A[i - 1] >0) {
			flag_u = true;
			if (flag_d) {
				count++;
				flag_d = false;
				flag_u = false;
			}
		}
		if (A[i] - A[i - 1] < 0) {
			flag_d = true;
			if (flag_u) {
				count++;
				flag_u = false;
				flag_d = false;
			}
		}
	}
	cout << count+1 << endl;
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	string s; cin >> s;
	if (s.size() < 4) return cout << "No\n", 0;
	if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') cout << "Yes\n";
	else cout << "No\n";
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll calc(ll used, ll n,ll num)
{
	if (n < num)
	{
		return 0;
	}
	ll sum = 0;
	if (used == 0b111)
	{
		sum++;
	}
	sum += calc(used | 0b001, n, num * 10 + 3);
	sum += calc(used | 0b010, n, num * 10 + 5);
	sum += calc(used | 0b100, n, num * 10 + 7);

	return sum;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	
	cout << calc(0, n, 0) << endl;
	debug;
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main(){
  int N,K;
  cin>>N>>K;
  long long h[100010];
  long long dp[101000];
  for (int i=0; i<N; i++) cin>>h[i];
  
  for (int i=0; i<N; i++) dp[i]=INF;
  
 dp[0]=0;
  
  for (int i=0; i<N-1; i++){
    for (int j=1;j<=K; j++){
  
  chmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout<<dp[N-1]<<endl;
}
  

Measured memory_bytes: 1792
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;
  
  int x, k;
  rd(x); rd(k);
  auto r=readln.split.to!(int[]);
  alias Q=Tuple!(int, "t", int, "a");
  auto qs=new Q[](0);
  foreach(t; r) qs~=Q(t, -1);
  int q; rd(q);
  foreach(_; 0..q){
    int t, a; rd(t, a);
    qs~=Q(t, a);
  }

  sort(qs);
  int p=0, l=0, u=x;
  int d=0, f=-1;
  foreach(e; qs){
    int dd=(e.t-p)*f;
    u=min(x, max(0, u+dd));
    l=max(0, min(x, l+dd));
    d+=dd; p=e.t;
    if(e.a==-1){// reverse
      f*=-1;
    }else{
      int y=e.a+d;
      writeln(min(u, max(l, y)));
    }
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}


Measured memory_bytes: 9464
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}

lli n, t, a;
vector<lli> h;
int main() {
  cin >> n >> t >> a;
  read_n(h, n);
  lli ans = 0, best = 1e10;
  for (int i=0; i<n; ++i) {
    lli cur = abs((1000*t - 6*h[i]) - 1000*a);
    if (best > cur) {
      best = cur;
      ans = i+1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        long[] c = new long[m];
        long[] d = new long[m];
        for(int i = 0;i < n;i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        for(int i = 0;i < m;i++){
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        long dist;
        for(int i = 0;i < n;i++){
            int index = 0;
            long dmin = 500000000;
            for(int j = 0;j < m;j++){
                dist = Math.abs(a[i]-c[j]) + Math.abs(b[i]-d[j]);
                if(dist < dmin){
                    index = j+1;
                    dmin = dist;
                }
            }
            System.out.println(index);
        }
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> S;
    if (S == "RRR")
        cout << 3 << endl;
    else if (S == "RRS" || S == "SRR")
        cout << 2 << endl;
    else if (S == "SSS")
        cout << 0 << endl;
    else
        cout << 1 << endl;
}

Measured memory_bytes: 3616
a, b = map(int, input().split())

lst = list()
la = ""
lb = ""

for i in range(0, b):
    lb = lb + str(a)
for i in range(0, a):
    la = la + str(b)

lst.append(la)
lst.append(lb)
lst.sort()

print(lst[0])

Measured memory_bytes: 3060
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b = rm()
print(max(a+b, a-b, a*b))

















Measured memory_bytes: 27080
n=int(input())
s=list(input())
if n%2!=0:
    print("No")
else:
    ans=0
    for i in range(int(n/2)):
        if s[i] != s[i+int(n/2)]:
            ans += 1
    if ans == 0:
        print("Yes")
    else:
        print("No")

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<bool> e(n);
    for (auto _ : irange(0L, m)) {
        int64_t a, b;
        cin >> a >> b;
        --a;
        --b;

        e[a] = !e[a];
        e[b] = !e[b];
    }

    if (count(e.begin(), e.end(), true) == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int64_t> H(N);
  for(int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  sort(H.begin(), H.end());
  int64_t S = 0;
  for(int i = 0; i < N - K; i++) {
    S += H.at(i);
  }
  cout << S << endl;
}

Measured memory_bytes: 1792
function Main(raw: string) {
  const input = raw.split("\n");
  const S = input[0];
  const N = S.length;
  let min = 100000;
  for (let start = 0; start < 2; start++) {
    let count = 0;
    for (let i = 0; i < N; i++) {
      let expected = (start + i) % 2 === 0 ? "0" : "1";
      if (S[i] !== expected) {
        count++;
      }
    }
    min = Math.min(min, count);
  }
  //出力
  console.log(min);
}

//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
X, K, D = map(int, input().split())


def sign(x):
    return 1 if x >= 0 else -1


if abs(X) >= D * K:
    ans = X - sign(X) * D * K
else:
    l = abs(X) // D
    mod = abs(X) % D

    residual = K - l

    if residual % 2 == 0:
        ans = mod
    else:
        ans = mod - sign(mod) * D

print(abs(ans))




Measured memory_bytes: 9152
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
base = 2019


L,R = LI()
l = L % base
r = R % base
if (L // base + 1) * base <= R:
    ans = 0
    # print("hoge")
elif l >= r:
    ans = 0
else:
    ans = mod
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans = min(ans,i * j % base)
print(ans)


Measured memory_bytes: 5712
# include<iostream>
using namespace std;
int main (){
 int a,b,c;
 cin>>a>>b>>c;
 int y =max(max(a,b),c);
 if (y==a){
    cout<<(a*10)+b+c;
 }
 else if (y==b){
  cout<<(b*10)+a+c;
 }
 else
    cout<<(c*10)+b+a;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,m,i,cnt=0;
    scanf("%d%d",&n,&m);
    for(i=n;i<=m;i++){
        int x=i/10000,y=i%10;
        int p=i/1000%10,q=i/10%10;
        if(x==y && p==q) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 20;
char ans[maxn];
int ly[maxn], ry[maxn];
int check(ll x, ll y)
{
	if(x <= y && to_string(x) <= to_string(y)) return 1;
	if(x > y && to_string(x) > to_string(y)) return 1;
	return 0;
}
int main()
{
	ll l, r = 1;
	for(int i = 1; i <= 10; ++i)
	{
		printf("? %lld\n", r);
		fflush(stdout);
		scanf("%s", ans);
		ly[i] = (ans[0] == 'Y');
		
		r = r * 10; 
		
		printf("? %lld\n", r - 1);
		fflush(stdout);
		scanf("%s", ans);
		ry[i] = (ans[0] == 'Y');
	}
	int pos;
	for(int i = 10; i; --i)
		if(ly[i] + ry[i] != ly[i - 1] + ry[i - 1])
		{
			if(ly[i] + ry[i] == 2) pos = i;
			else pos = i - 1;
			break;
		}
	r = 1;
	while(pos--) r *= 10;
	l = r / 10;
	r = r - 1;
	while(l <= r)
	{
		ll mid = l + r >> 1;
		
		printf("? %lld\n", mid * 10);
		fflush(stdout);
		scanf("%s", ans);
		
		if(ans[0] == 'Y') r = mid - 1;
		else l = mid + 1;
	}
	printf("! %lld\n", l);
	return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll a[5];
    rep(i,5) cin >> a[i];
    ll x[5];
    ll ans=0;
    rep(i,5){
        x[i] = 10 - a[i]%10;
        if(x[i]==10) x[i]=0;
        ans += a[i]+x[i];
    }
    sort(x,x+5);
    cout << ans-x[4] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
void makeFibonacci(int n) {
  int F[n],i;
  F[0] = 1;
  F[1] = 1;
  for (i = 2;i <= n;i++) {
    F[i] = F[i-2] + F[i-1];
	  }
  printf("%d\n",F[n]);
}

  int main() {
	int n;
	scanf("%d",&n);
	makeFibonacci(n);
	return 0;
      }
  

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <stack>



void dfs(std::vector<std::vector<char> > &map, int i, int j, char self_color, char other_color, int &total) {
    int first;
    int second;

    int count = 0;
    bool check_surrounded = true;
    bool check_only_wall = false;

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

    std::stack<std::pair<int, int> > st;
    st.push(std::make_pair(i, j));
    map[i][j] = '$';

    while (1) {
        if (st.empty() == 1) {
            break; 
        }
        first = st.top().first;
        second = st.top().second;
        st.pop();
        ++count;
        for (int k = 0; k < 4; k++) {
            if (map[first + dx[k]][second + dy[k]] == '.') {
                st.push(std::make_pair(first + dx[k], second + dy[k])); 
                map[first + dx[k]][second + dy[k]] = '$';
            } else if (map[first + dx[k]][second + dy[k]] == other_color) {
                check_surrounded = false; 
            }
            if (map[first + dx[k]][second + dy[k]] == self_color) {
                check_only_wall = true;
            }
        }
    }
    if (check_surrounded == true && check_only_wall == true) {
        total += count;
    } else {
        check_surrounded = true;
        check_only_wall = false;
    }
    return;
}

int whole_search(std::vector<std::vector<char> > map, int w, int h, char self_color, char other_color) {
    int total = 0;

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (map[i][j] == '.') {
                dfs(map, i, j, self_color, other_color, total);
            }
        }
    }
    return total; 
}

int main(void) {
    int w;
    int h;

    while (1) {
        std::cin >> w >> h;
        if (w == 0 && h == 0) {
            break;
        }

        std::vector<std::vector<char> > map_b(h+2, std::vector<char>(w+2, '#'));
        std::vector<std::vector<char> > map_w(h+2, std::vector<char>(w+2, '#'));

        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                std::cin >> map_b[i][j];
                map_w[i][j] = map_b[i][j];
            }
        }
        std::cout << whole_search(map_b, w, h, 'B', 'W') << " " << whole_search(map_w, w, h, 'W', 'B') << std::endl;
    }


    return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	string s;
	cin >> n >> s;
	
	vector<int> b(n + 1, 0), w(n + 1, 0);
	for(int i = 0; i < n; ++i) {
		b[i + 1] = b[i];
		w[i + 1] = w[i];
		
		if( s[i] == '#' ) b[i + 1]++;
		else w[i + 1]++;
	}
	
	int ans = 1e9;
	for(int i = 0; i < n + 1; ++i) {
		ans = min(ans, b[i] + w[n] - w[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2180
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;

int main() {
    int n;cin>>n;
    pair<int, int>a[100001];
    pair<int, int>b[100001];

    for(int i=0;i<100001;++i){
        a[i].first = 0;
        a[i].second = i;
        b[i].first = 0;
        b[i].second = i;
    }
    
    int tmp1,tmp2;
    for(int i=0;i<n/2;++i){
        cin>>tmp1>>tmp2;
        a[tmp1-1].first +=1;
        b[tmp2-1].first +=1;
    }

    sort(a,a + 100001,greater<pair<int, int>>());
    sort(b,b + 100001,greater<pair<int, int>>());
    
    int c,ans;
    
    if(a[0].second == b[0].second){
      ans = n - (a[0].first + max(a[1].first, b[1].first));
    } 
    else ans = n - (a[0].first + b[0].first);

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

Measured memory_bytes: 1792
//shara's here
//私は私は大きい男の子
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll> >
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
ll cnt(ll k){
	ll ans=0;
	while(k!=0){
	ans++;
	k/=10;
	}
	return ans;
}
ll power(ll b,ll p){
	ll ans=1;
	for(ll i=1;i<=p;i++)ans*=b;
	return ans;
}
bool isSqr(ll n){
	for(ll i=0;i<=1000;i++){
	if(i*i==n)return true;	
	}
	return false;
}
int main(){
	ll n,t,ne;
	cin>>n>>t;
	ll x=power(10,cnt(t));
	n*=x;
	ne=n+t;
	if((isSqr(ne)))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	
	
	
	
	
	
	
	
	
	






return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


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

#turu = (4*x-y)//2

# if (turu < 0) or (2*x > y):
#    print("No")
#    exit()

# if ((y-turu*2) % 4 == 0):
#    print("Yes")
# else:
#    print("No")

ans = "No"
for c in range(x+1):
    t = x-c
    if 2*c + 4*t == y:
        ans = "Yes"
        break

print(ans)


Measured memory_bytes: 9152
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
int ses=1;
int r=0,c=0,cnt=0,x;
map<int,int>vis;
 main()

{
    fast
    int n,m;
    cin>>n>>m;
    set<int>s;
    f(i,1,n)
    {
        cin>>x;
        if(s.find(x)!=s.end())
        {
            cout<<"0"<<endl;return 0;
        }
        s.insert(x);
        vis[x]=1;
    }
    s.clear();
    f(i,1,m)
    {
        cin>>x;
        if(s.find(x)!=s.end())
        {
            cout<<"0"<<endl;return 0;
        }
        s.insert(x);
        if(vis[x]==0)vis[x]=2;
        else vis[x]=3;
    }
    rf(i,n*m,1)
    {
        if(vis[i]==1)
        {
            ses=gun(ses,c);
            r++;
        }
        else if(vis[i]==2)
        {
            ses=gun(ses,r);
            c++;
        }
        else if(vis[i]==3)
        {
             r++;c++;
        }
        else
        {
            ses=gun(ses,sub(r*c,cnt));
        }
        cnt++;
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 66104
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  map<long long,bool> mp;
  long long ma = 0;
  long long ma2 = 0;
  cin >> n;
  rep(i,n){
    long long t;
    cin >> t;
    if(mp[t]){
      mp[t] = false;
      if(ma <= t){
        ma2 = ma;
        ma = t;
      }else if(ma2 <= t){
        ma2 = t;
      }
    }else mp[t] = true;
  }
  cout << ma*ma2 << endl;
  return 0;
}


Measured memory_bytes: 6528
n, k, q = map(int, input().split())
A = [0] * q
for i in range(q):
    A[i] = int(input())
score = [k - q] * n
for a in A:
    score[a-1] += 1
# print(score)
for i in range(n):
    if score[i] <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 10416
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var rectangle, diamond int
	for sc.Scan() {
		l := strings.Split(sc.Text(), ",")
		a, _ := strconv.Atoi(l[0])
		b, _ := strconv.Atoi(l[1])
		c, _ := strconv.Atoi(l[2])

		if a*a+b*b == c*c {
			rectangle++
		}
		if a == b {
			diamond++
		}
	}
	fmt.Println(rectangle)
	fmt.Println(diamond)
}



Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B,C,D,E;
  cin >> A;
  B=(A-A%1000)/1000;
  C=(A%1000-A%1000%100)/100;
  D=(A%1000%100-A%1000%100%10)/10;
  E=A%1000%100%10;
  if ((B==C && C==D) || (C==D&&D==E)) {
    cout << "Yes" << endl;
  }else{
    cout << "No" <<endl;}
 
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  bool flag=1;
  int i=0;;
  while(i<S.size()){
    if(S.substr(i,5)=="dream" or S.substr(i,5)=="erase"){
      i+=5;
      continue;
    }
    if(i>=5 and S.substr(i-5,7)=="dreamer"){
      i+=2;
      continue;
    }
    if(i>=4 and S.substr(i-5,6)=="eraser"){
      i+=1;
      continue;
    }
    // cout<<S.substr(i)<<endl;
    flag=0;
    break;
  }
  if(flag)cout<<"YES"<<endl;
  else  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*;

class Main {
	Scanner sc;

	Main() {
		sc = new Scanner(System.in);
	}
	
	void calc() {
		int N = sc.nextInt();
		for (int i = 1; i <= 9; i++) {
			if (N%i==0 && (N/i)<10) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

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

int main() {
    vector<int> a(3);
    rep(i,0,3) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << a[0] + a[1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {

	int d;
	cin >> d;
	int c[26];
	int i, j;
	for (i = 0; i < 26; i++) {
		cin >> c[i];
	}
	int s[365][26];
	for (i = 0; i < d; i++) {
		for (j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}
	int last[26];
	for (i = 0; i < 26; i++) {
		last[i] = 0;
	}
	int jmax, jindex;
	for (i = 1; i <= d; i++) {

		jmax = 0;
		jindex = -1;
		for (j = 0; j < 26; j++) {
			if (c[j] *(i - last[j]) > jmax) {
				jmax = c[j] *(i - last[j]);
				jindex = j;
			}
			else if (c[j] *(i - last[j]) == jmax) {
				if (s[i-1][j] > s[i-1][jindex]) {
					jindex = j;
				}
			}
		}
		for (j = 0; j < 26; j++) {
			if (s[i - 1][j] + c[j] * (i - last[j]) >= jmax) {
				jmax = s[i - 1][j] + c[j] * (i - last[j]);
				jindex = j;
			}
		}
		last[jindex] = i;
		cout << jindex + 1 << endl;
		


	}
	return 0;


}

Measured memory_bytes: 3664
n=int(input())
la=input().split(" ")
l=[]
ans=0
c=1
for i in range(len(la)):
    l.append(int(la[i]))
for k in range(len(l)):
    if(l[k]==c):
        ans+=1
        c+=1
#print(ans,c)
if(ans==0):
    print(-1)
else:
    print(len(l)-ans)

Measured memory_bytes: 26268
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int H,W;
int dist_table[10][10];

int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row <= 9; row++){
		for(int col = 0; col <= 9; col++){

			scanf("%d",&dist_table[row][col]);
		}
	}

	//ワーシャルフロイド
	for(int mid = 0; mid <= 9; mid++){
		for(int start = 0; start <= 9; start++){
			for(int goal = 0; goal <= 9; goal++){

				dist_table[start][goal] = min(dist_table[start][goal],dist_table[start][mid]+dist_table[mid][goal]);
			}
		}
	}

	int ans = 0,tmp;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			scanf("%d",&tmp);
			if(tmp == -1)continue;

			ans += dist_table[tmp][1];
		}
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256
N = int(raw_input())
A = map(int, raw_input().split())   
even = 0
odd = 1
for ai in A:
    if ai % 2 == 0:
        even = 3*even + odd
        odd = 2*odd
    else:
        even = 3*even + 2*odd
        odd = odd
print even


Measured memory_bytes: 2568
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	public class pair implements Comparable {
		int a;
		int b;

		pair(int a, int b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Object arg0) {
			return  b- ((pair) arg0).b;
		}
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		pair[] data = new pair[n];
		for (int i = 0; i < n; i++) {
			data[i] = new pair(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(data);
		int[] fastMost = new int[n+1];
		Arrays.fill(fastMost, (1<<30));
		fastMost[0] = 0;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int[] fastMost2 = fastMost.clone();
			for (int j = 1; j < n+1; j++) {
				if (fastMost[j - 1] == 1<<30) {
					break;
				}
				if (fastMost[j - 1] + data[i].a <= data[i].b) {
					fastMost2[j] = Math.min(fastMost2[j], fastMost[j - 1]
							+ data[i].a);
					ans = Math.max(ans, j);
				}
			}
			fastMost = fastMost2.clone();
		}
//		System.out.println(Arrays.toString(fastMost));
		System.out.println(ans);
	}

	public static void main(String Args[]) {
		Main t = new Main();
		t.run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

int ans;
int h, w;
int ttm[30][30];

int c;

bool ok(int x, int y){
    return x == 0 ||
        y == 0 ||
        ttm[y][x] == ttm[y][x - 1] ||
        ttm[y][x - 1] == ttm[y - 1][x - 1] ||
        ttm[y - 1][x - 1] == ttm[y - 1][x] ||
        ttm[y - 1][x] == ttm[y][x];
}

void dfs(int x, int y){
    if (x == w){
        if (y == h - 1){
            ans++;
        }
        else dfs(0, y + 1);
        return;
    }

    if (ttm[y][x]){
        dfs(x + 1, y);
        return;
    }
    if (x + 1 != w && ttm[y][x + 1] == 0){
        ttm[y][x] = ttm[y][x + 1] = c++;
        if (ok(x, y)) dfs(x + 2, y);
        ttm[y][x] = ttm[y][x + 1] = 0;
    }
    if (y + 1 != h && ttm[y + 1][x] == 0){
        ttm[y][x] = ttm[y + 1][x] = c++;
        if (ok(x, y)) dfs(x + 1, y);
        ttm[y][x] = ttm[y + 1][x] = 0;
    }
}

int main(){
    while (cin >> h >> w && h){
        ans = 0;
        c = 1;
        memset(ttm, 0, sizeof(ttm));
        dfs(0, 0);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1172
a,b,c,d,e,f=map(int,input().split())
ans=-1
sugarwater=0
sugar=0
for i in range(101):
    for j in range(101):
        for k in range(101):
            for l in range(101):
                if (c*k+d*l) > e*(a*i+b*j):
                    break
                if (100 * a * i + 100 * b * j == 0 or 100 * a * i + 100 * b * j + c * k + d * l > f):
                    break
                if ans < 100*(c*k+d*l)/(100 * a * i + 100 * b * j + c*k + d*l):
                    ans=100*(c*k+d*l)/(100 * a * i + 100 * b * j + c*k + d*l)
                    sugarwater = 100 * a * i + 100 * b * j + c*k + d*l
                    sugar = c*k+d*l
print("{} {}".format(sugarwater,sugar))

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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



int main(){
    int a, b; cin >> a >> b;
    if(a >= 13) cout << b << endl;
    else if(a >= 6) cout << b/2 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int a[105];
map<int,int> mp;
int main(){
    /// input
    int n,x;
    cin>>x>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    /// process
    for(int i=0;i<n;i++){
        mp[a[i]] = 1;
    }
    int dis = 1e9;
    int ans = 1000;
    for(int i=0;i<=101;i++){
        int found = mp[i];
        if(found==1)continue;
        int tmp = abs(x-i);
        if(tmp<dis){
            dis = tmp;
            ans = i;
        }
    }
    /// output
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>

using namespace std;

int main() {

    int K;
    cin >> K;

    if (K % 2 == 0) {
        int hanbun = K / 2;
        cout << hanbun * hanbun << endl;
    } else {
        int hanbun = K / 2;
        cout << hanbun * (hanbun + 1) << endl;
    };
}

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


using namespace std;


string S;
int Q;

class Part{
public:
	string s;
	bool rev;
	int order;

	Part(string _s, bool _rev, int _order)
		:s(_s),rev(_rev),order(_order)
	{
	}
		

};



int main()
{

	cin >> S;
	cin >> Q;



	auto ary = vector<Part>();

	ary.push_back(Part(S,false,0));

	bool rev = false;

	int cp = 1;
	int cm = -1;

	for (int i = 0; i<Q ; i++) {

		int t;
		cin >> t;

		if (t == 1) {
			rev = !rev;
		}
		else {
			int f;
			cin >> f;
			string t;
			cin >> t;

			if (f == 1) {
				if (!rev) {
					ary.push_back(Part(t, false, cp));
					cp++;
				}
				else {
					ary.push_back(Part(t, true, cm));
					cm--;
				}
			}
			else {
				if (!rev) {
					ary.push_back(Part(t, false, cm));
					cm--;
				}
				else {
					ary.push_back(Part(t, true, cp));
					cp++;
				}
			}
		}

	}

	if (rev) {
		sort(ary.begin(), ary.end(), [](Part const& lhs, Part const& rhs) {
			return lhs.order < rhs.order;
		});
	}
	else {
		sort(ary.begin(), ary.end(), [](Part const& lhs, Part const& rhs) {
			return lhs.order > rhs.order;
		});
	}

	for (unsigned i = 0; i < ary.size(); i++) {
		string a = ary[i].s;

		if (rev ^ ary[i].rev) {
			reverse(a.begin(), a.end());
		}

		cout << a;

	}

	cout << endl;



	return 0;
}


Measured memory_bytes: 13808
from collections import defaultdict

def dfs(here, connect, visited, answer):
    global time
    answer[here][1] = time
    time += 1
    visited[here] = 1
    for c in connect[here]:
        if not visited[c]:
            dfs(c, connect, visited, answer)
    answer[here][2] = time
    time += 1

v_num = int(input())
connect = defaultdict(list)
for _ in range(v_num):
    inp = [int(n) - 1 for n in input().split(" ")]
    connect[inp[0]].extend(sorted(inp[2:]))
answer = [[n + 1 for m in range(3)] for n in range(v_num)]
time = 1
visited = [0 for n in range(v_num)]
for i in range(v_num):
    if not visited[i]:
        dfs(i, connect, visited, answer)
for v in range(v_num):
    print(*answer[v])

Measured memory_bytes: 8144