akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int k, x;
    cin >> k >> x;

    int mn = x - k + 1;
    int mx = x + k - 1;

    for (int i = mn; i < mx; i++)
    {
        cout << i << " ";
    }
    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i = 0;i<n;i++)
    {
        cin>>a[i];
    }
    int c = 1;
    int curr_max =a[0];
    for(int i = 1;i<n;i++)
    {
        if(a[i]>=curr_max)
        {
            c++;
            curr_max = a[i];
        }
    }
    cout<<c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int h,w; cin >> h >> w;
	vector<vector<bool>> f(h,vector<bool>(w,0));
	char c;
	REP(i,h)REP(j,w){
		cin >> c;
		if(c=='#')f[i][j]=1;
	}
	int dp[101][101]={0};
	REP(i,w-1){
		dp[0][i+1]=dp[0][i];
		if(f[0][i+1]!=f[0][i])
			dp[0][i+1]++;
	}
	REP(i,h-1){
		dp[i+1][0]=dp[i][0];
		if(f[i+1][0]!=f[i][0])
			dp[i+1][0]++;
	}
	REP(i,h-1)REP(j,w-1){
		int a=dp[i+1][j], b=dp[i][j+1];
		if(f[i+1][j]!=f[i+1][j+1])
			a++;
		if(f[i][j+1]!=f[i+1][j+1])
			b++;
		dp[i+1][j+1]=min(a,b);
	}
	cout << (dp[h-1][w-1]+1+f[0][0])/2 << endl;
	return 0;
}

Measured memory_bytes: 256
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    string s; cin >> s;
    string ans = s[0] + to_string(s.size()-2) + s[s.size()-1];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const double EPS = 1e-9;

class Point {
public:
  double x;
  double y;
  double c;

  Point(double x = 0.0, double y = 0.0, double c = 1.0) {
    this->x = x;
    this->y = y;
    this->c = c;
  }

  Point operator+(Point p) { return Point(x + p.x, y + p.y); }

  Point operator-(Point p) { return Point(x - p.x, y - p.y); }

  Point operator*(double a) { return Point(a * x, a * y); }

  Point operator/(double a) { return Point(x / a, y / a); }

  double norm() { return x * x + y * y; }

  double abs() { return sqrt(norm()); }

  double arg() { return atan2(y, x); }

  bool operator<(const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator==(const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};

typedef Point Vector;

class Circle {
public:
  Point c;
  double r;

  Circle(Point c = Point(), double r = 0.0) {
    this->c = c;
    this->r = r;
  }

  pair <Point, Point> getCrossPoints(Circle c2) {
    double d = (c - c2.c).abs();
    double a = acos((r * r + d * d - c2.r * c2.r) / (2 * r * d));
    double t = (c2.c - c).arg();

    return make_pair(c + polar(r, t + a), c + polar(r, t - a));
  }

private:

  Vector polar(double a, double r) {
    return Point(cos(r) * a, sin(r) * a);
  }
};

double getDistance(Point a, Point b) {
  return (a - b).abs();
}

bool intersect(Circle c1, Circle c2) {
  return abs(c1.r - c2.r) <= getDistance(c1.c, c2.c) && getDistance(c1.c, c2.c) < c1.r + c2.r + EPS;
}

int N, K;
vector<Point> points;

bool f(double t) {
  vector<Circle> circles;

  for (auto p : points) {
    double r = t / p.c;

    circles.push_back(Circle(p, r));
  }

  vector<Point> crossPoints;

  for (int i = 0; i < N; ++i) {
    Circle c1 = circles[i];

    crossPoints.push_back(c1.c);

    for (int j = i + 1; j < N; ++j) {
      Circle c2 = circles[j];

      if (!intersect(c1, c2)) continue;
      pair<Point, Point> res = c1.getCrossPoints(c2);

      crossPoints.push_back(res.first);
      crossPoints.push_back(res.second);
    }
  }

  for (auto p : crossPoints) {
    int cnt = 0;

    for (auto c : circles) {
      double d = getDistance(p, c.c);

      if (d <= c.r + EPS) {
        ++cnt;
      }
    }

    if (cnt >= K) {
      return true;
    }
  }

  return false;
}

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

  if (N == 1 || K == 1) {
    cout << fixed << setprecision(10) << 0 << endl;
    return 0;
  }

  int x, y, c;

  for (int i = 0; i < N; ++i) {
    cin >> x >> y >> c;

    points.push_back(Point(x, y, c));
  }

  double ng = 0.0;
  double ok = 10000000.0;
  int loop_cnt = 100;

  for (int i = 0; i < loop_cnt; ++i) {
    double t = (ok + ng) / 2.0;

    if (f(t)) {
      ok = t;
    } else {
      ng = t;
    }
  }

  cout << fixed << setprecision(10) << ok << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);

int main(){
  int X, N;
  cin >> X >> N;
  if (N == 0) {
    cout << X << endl;
    return 0;
  }

  int a[102] = {0};
  int p[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    a[p[i]] = 1;
  }

  int min_num = 200;
  int min_val = 0;

  for (int i = 0; i < 102; i++) {
    if (a[i] == 0) {
      if (min_num > abs(X - i)) {
        min_num = abs(X - i);
        min_val = i;
      }
    }
  }

  cout << min_val << endl;

  return 0;
}

Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {

	static int[][] field;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int N = cin.nextInt();
		while(N--!=0){
			field = new int[5][5];
			for(int i = 0;i<5;i++)
				for(int j = 0;j<5;j++)
					field[i][j]=cin.nextInt();
			int max=0;
			for(int x = 0;x<5;x++){
				for(int y = 0;y<5;y++){
					for(int i = 0;i+x<5;i++){
						for(int j = 0;j+y<5;j++){
							boolean f = true;
							for(int k = 0;k<=x;k++){
								for(int h = 0;h<=y;h++){
									if(field[i+k][j+h]==0){
										f=false;
									}
								}
							}
							if(f){
								max=Math.max((x+1)*(1+y),max);
							}
						}
					}
				}
			}
			System.out.println(max);
		}
	}

}

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

int main(){
    int a,b,c,d,i;
    cin >> d;
    for(i=0;i<d;i++){
        if(cin >> a >> b >> c &&(a*a+b*b==c*c||b*b+c*c==a*a||c*c+a*a==b*b)){
            cout << "YES" << endl;
        }
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    R=[[] for _ in range(n)]
    for _ in range(m):
        a,b,c=map(int,input().split())
        a-=1; b-=1
        E[a].append((b,-c))
        R[b].append((a,-c))

    from collections import deque
    state=[0]*n
    state[0]=1
    state[n-1]=2

    Q=deque([0])
    while(Q):
        v=Q.popleft()
        for nv,w in E[v]:
            if(state[nv]&1): continue
            state[nv]+=1
            Q.append(nv)

    Q=deque([n-1])
    while(Q):
        v=Q.popleft()
        for nv,w in R[v]:
            if(state[nv]&2): continue
            state[nv]+=2
            Q.append(nv)

    dist=[INF]*n
    dist[0]=0
    for k in range(n):
        for v in range(n):
            if(state[v]!=3): continue
            for nv,w in E[v]:
                if(state[nv]!=3): continue
                if(dist[nv]>dist[v]+w):
                    dist[nv]=dist[v]+w
                    if(k==n-1):
                        print("inf")
                        return
    print(-dist[-1])
resolve()

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef pair<int, int> P;


int main() {
    ll a;
    string b;
    cin >> a >> b;
    b.replace(b.size() - 3, 1, "");
    ll bb = stoi(b);
    cout << a * bb / 100 << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

/**
 *
 */
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N+1];
        w[0] = 0;
        int[] v = new int[N+1];
        v[0] = 0;
        for (int i = 1; i < N+1; i++){
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }

        long[][] dp = new long[105][W+1];

        /**
         * ナップサックDPなのだ！
         * dp[i]=(i番目までの品物を、重さがW以下になるように選んだときの価値の最大値)
         * じゃやっぱりダメで、次の品物を使っていいかどうかがわからないのだ。
         * 次の品物を使っていいかどうかは、前までの重さがわかってればわかりそうな気がするから
         * dp[i][j]=(i番目までの品物を、重さがj以下になるように選んだときの価値の最大値)
         * を考えるのだ。するとdp[i][j]は、
         * i番目の品物を使うとき「i−1番目までで重さがj−w[i]以下の価値の最大値+v[i]」
         * 使わないとき「i−1番目までの重さがj以下の価値の最大値」
         * という2つの場合の大きい方になるのだ
         */

        for(int i = 1; i < N+1; i++){ //遍历所有商品
            for(int j = 0; j < W + 1; j++){ //遍历直到背包中最大大小
                if(j-w[i]>=0) { //如果商品i能够被放入重量为j的背包
                    dp[i][j] = Math.max(dp[i-1][j], v[i] + dp[i-1][j-w[i]]);
                    //这里是背包问题更新的核心
                    //两个要点 dp[i-1][j] 就是不把新的商品放入背包的选项，有可能放了还没有以前价值高
                    //dp[i-1][], 就是放这个商品i前的最大价值
                    //dp[i-1][j-w[i]] 就是重量j抛去了i商品的重量的最大价值
                    //再加上i商品的最大价值，那就是能计算i商品价值的极限了
                }else {//商品i不能放入重量为j的背包
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
        System.out.println(dp[N][W]);

    }
}

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

bool cheak(ll x,ll y,vector<vector<ll>> z){
  vector<bool> ok(z.size()+1,false);
  queue<ll> a;
  a.push(x);
  ok[x]=true;
  while(!a.empty()){
    for(int i=0;i<z[a.front()].size();i++){
      if(!((a.front()==x)&&(z[a.front()][i]==y)||ok[z[a.front()][i]]==true)){
        a.push(z[a.front()][i]);
      }
    }
    ok[a.front()]=true;
   // cout<<a.front()<<endl;
    a.pop();
  }
  if(ok[y]==true){
    return true;
  }
  else{
    return false;
  }
}
    
      
      

int main() {
  ll N,M,ans=0;
  cin>>N>>M;
  vector<vector<ll>> Bri(N+1,vector<ll>(0));
  pair<ll,ll> bri[M];
  for(int i=0;i<M;i++){
    ll a,b;
    cin>>a>>b;
    Bri[a].push_back(b);
    Bri[b].push_back(a);
    bri[i]={a,b};
  }
  for(int i=0;i<M;i++){
    if(!cheak(bri[i].first,bri[i].second,Bri)){
      ans++;
     // cout<<"ok"<<endl;
    }
  }
  cout<<ans;
    
}


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

using namespace std;

int main(){
  int n, p;

  while(1){
    cin >> n >> p;
    if(n == 0 && p == 0){
      break;
    }else{
      int kouho[n],wan;
      for(int i = 0 ; i < n ; i++){
	kouho[i] = 0;
      }
      wan = p;
      // shokika owari

      
      while(1){
	int id = 0;
	for(int i = 0; i < n;i++){
	  if(wan != 0){
	    wan--;
	    kouho[i]++;
	  }else {
	    wan = kouho[i];
	    kouho[i] = 0;
	  }
	  
	  if(kouho[i] == p){
	    cout << i << endl;
	    id = i;
	    break;
	  }
	  //cout << kouho[i] << endl;
	}
	//1 syu owari
	if(kouho[id] == p){
	  break;
	}
      }
      
      
    }
    
  }

}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifdef APURBA
#define debug(a) cout<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) cout<<#a<<" --> "<<(a)<<" ";
#define HERE cout<<"here - "<<__LINE__<<"\n";
#else
#define debug(a)
#define debug2(a)
#define HERE
#endif
const ll mod = 1e9+7;
const int N = 2e5 +5;
typedef pair<int,int> pii;


void TEST_CASES(int cas)
{
    ll n,d;
    cin>>n>>d;
    d= d*d;
    ll cnt =0;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        ll dist = x*x + y*y;
        if(dist<=d)
        {
            cnt++;
        }
    }
    printf("%lld\n",cnt);

}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }
    return 0;
}


template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os,set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


Measured memory_bytes: 3748
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		List<char> L = new List<char>();
		for(int i=0;i<O.Length;i++){
			L.Add(O[i]);
			if(i < E.Length) L.Add(E[i]);
		}
		Console.WriteLine(new String(L.ToArray()));
	}
	String O,E;
	public Sol(){
		O = rs(); E = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11220
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func bs(a int, b []int) int {
	l,r := -1, len(b)
	c := (l+r)/2
	for ;; {

		if l == r-1 {
			break
		}

		if b[c] > a {
			r = c
		} else {
			l = c
		}

		c = (l+r)/2

	}
	return r
}

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	a := make([]int,n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}

	ans := 0
	b := make([]int, 1)
	ans++
	b[0] = a[n-1]
	for i := 1; i < n; i++ {
		c := bs(a[n-i-1], b)
		if c == len(b) {
			ans++
			b = append(b,a[n-i-1])
		} else {
			b[c] = a[n-i-1]
		}
	}

	fmt.Println(ans)
}


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

int main()
{
	int N;
	int X[105], Y[105], H[105];
	
	int idx = -1;
	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		cin >> X[i] >> Y[i] >> H[i];
		if ( H[i] > 0 ) {
			idx = i;
		}
	}

	for ( int y = 0; y <= 100; y++ ) {
		for ( int x = 0; x <= 100; x++ ) {
			int pdist = abs(y - Y[idx]) + abs(x - X[idx]);
			int ph = H[idx] + pdist;
			bool flag = true;	
			for ( int i = 0; i < N; i++ ) {
				if ( max(0, ph - abs(y - Y[i]) - abs(x - X[i])) != H[i] ) {
					flag = false;
					break;
				}
			}
			if ( flag ) {
				cout << x << " " << y << " " << ph << endl;
				return ( 0 );
			}
		}
	}
}


Measured memory_bytes: 256
n=int(input())
d={}
a=[int(i) for i in input().split()]

for i in a:
    if(d.get(i,None)==None):
        d[i]=0
    d[i]+=1
for i in range(1,n+1):
    if(d.get(i,None)==None):
        print(0)
    else:
        print(d[i])

Measured memory_bytes: 33580
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    ll n, a, b; cin >> n >> a >> b;
    if ((b - a) % 2 == 0){
        cout << (b - a) / 2 << endl;
        return 0;
    }
    cout << min((a+b-3)/2+1,(2*n-a-b-1)/2+1) << endl;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    
    vector<vector<int> > graph(N);
    vector<int> ecnt(N, 0);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        ecnt[a]++; ecnt[b]++;
    }

    vector<int> is_in_loop(N, true);
    
    queue<int> q;
    for (int i = 0; i < N; i++) {
        if (ecnt[i] == 1) {
            q.push(i);
        }
    }
    
    while(!q.empty()) {
        int c = q.front(); q.pop();
        is_in_loop[c] = false;
        for (int nc : graph[c]) {
            if (--ecnt[nc] == 1) q.push(nc);
        }
    }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (is_in_loop[a] && is_in_loop[b]) cout << 2 << endl;
        else cout << 1 << endl;
    }
    
}


Measured memory_bytes: 9208
N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
B_ = B[:]

B.sort(key=lambda x: x[0])

for i, b in enumerate(B):
    matchR = [(j, r) for j, r in enumerate(R) if r[0] < b[0] and r[1] < b[1]]
    if matchR:
        matchR.sort(key=lambda x: x[1][1], reverse=True)
        del R[matchR[0][0]]
    else:
        B_[i] = None

print(len([b for b in B_ if b is not None]))



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;



int main()
{
	int N;

	cin >>N;
	ll ans = 1;
	for (int i = 1; i <= N; i++)
	{
		ans = (ans * i)%mod;
	}
	
	cout << ans << endl;


	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const int INF = 1<<29;

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int change_d[5] = {0, 1, 2, 3, 0};
  while (true) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    int ope[31][31], dist[31][31][4], ch_cost[4];
    REP(i, h) REP(j, w) cin >> ope[i][j];
    REP(i, 4) cin >> ch_cost[i];
    REP(i, h) REP(j, w) REP(k, 4) dist[i][j][k] = INF;
    dist[0][0][1] = 0;
    priority_queue<T> pque;
    pque.push(T(0, 0, 1));
    while (!pque.empty()) {
      int d, r, c, dir;
      tie(d, r, dir) = pque.top(); pque.pop();
      d = -d, c = r % w, r /= w;
      //cout << c << ',' << r << ',' << dir << ':' << d << endl;
      if (dist[r][c][dir] < d || (r == h-1 && c == w-1)) continue;
      int default_d = ope[r][c] != 4 ? (dir + change_d[ope[r][c]]) % 4 : 4;
      REP(i, 4) {
	int nd = (dir + i) % 4, nr = r + dr[nd], nc = c + dc[nd], cost = (nd == default_d ? 0 : ch_cost[i]);
	//cout << nr << ',' << nc << endl;
	if (0 <= nr && nr < h && 0 <= nc && nc < w && dist[nr][nc][nd] > d + cost) {
	  dist[nr][nc][nd] = d + cost;
	  pque.push(T(-dist[nr][nc][nd], nr * w + nc, nd));
	}
      }      
    }
    int ret = INF;
    REP(i, 4) ret = min(ret, dist[h-1][w-1][i]);
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout<<a[j]<<" "
#define wh(t) ll t; cin>>t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define arr(a,n) ll a[n]; fab(i,0,n) cin>>a[i]
#define fab(i,a,b) for(ll i=a;i<b;i++)
#define fba(i,b,a) for(ll i=b;i>=a;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 1000000007
#define MAX 10000007
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define pl pair<ll,ll>
#define mxe(x,n) *max_element(x,x+n)
#define mne(x,n) *min_element(x,x+n)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
#define N 3005

bool rsort1(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.second>b.second);}
bool sort2(const pair<ll,ll> &a,const pair<ll,ll> &b){ return (a.second < b.second);}

ll dp[N][N],vis[N];
string s,t,ans;
map<pl,ll>m,v;


ll solve(ll i,ll j)
{
    if(i<0 || j<0)
    return 0;
    if(dp[i][j]!=-1)
    return dp[i][j];
    if(s[i]==t[j])
        return dp[i][j]=1+solve(i-1,j-1);
    else
        return dp[i][j]=max(solve(i-1,j),solve(i,j-1));
}

void print(ll i,ll j)
{
    if(i<0 || j<0 || !dp[i][j] || dp[i][j]==-1)
    return;
    if(m[mp(i,j)] || vis[dp[i][j]])
    return;
    m[mp(i,j)]=1;
    if(s[i]==t[j])
    {
        vis[dp[i][j]]=1;
        print(i-1,j-1);
        ans+=s[i];
    }
    else
    {
        if(i && dp[i][j]==dp[i-1][j])
            print(i-1,j);
        if(j && dp[i][j]==dp[i][j-1])
            print(i,j-1);
    }
}


int main()
{
	sup; 
	cin>>s>>t;
	memset(dp,-1,sizeof(dp));
	solve(sz(s)-1,sz(t)-1);
	print(sz(s)-1,sz(t)-1);
	pr(ans);
    return 0;
}


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

int main() {
        int n;
        cin >> n;
        int x, flag = 0;
        while(n--) {
                cin >> x;
                if(x % 2 == 0) {
                        if(x % 3 == 0 || x % 5 == 0);
                
                        else
                                flag = 1; 
                }

        }
        if(flag == 0)
                cout << "APPROVED\n";
        else 
                cout << "DENIED\n";
        return 0;
}

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

using namespace std;
using ll = long long;

struct Person {
    ll B_A;
    ll C_A;
    bool operator<(const Person& p) const
    {
        return B_A - C_A > p.B_A - p.C_A;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y, Z;
    cin >> X >> Y >> Z;
    const int N = X + Y + Z;
    vector<Person> p(N);
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        ll A, B, C;
        cin >> A >> B >> C;
        p[i].B_A = B - A;
        p[i].C_A = C - A;
        sum += A;
    }
    sort(p.begin(), p.end());
    multiset<ll> bset;
    multiset<ll> cset;
    ll bsum = 0;
    vector<ll> bvalue(N);
    for (int i = 0; i < Y; i++) {
        bsum += p[i].B_A;
        bset.insert(p[i].B_A);
    }
    bvalue[Y - 1] = bsum;
    for (int i = Y; i + Z < N; i++) {
        bsum += p[i].B_A;
        bset.insert(p[i].B_A);
        bsum -= *bset.begin();
        bset.erase(bset.begin());
        bvalue[i] = bsum;
    }

    ll csum = 0;
    vector<ll> cvalue(N);
    for (int i = N - 1; i >= N - Z; i--) {
        csum += p[i].C_A;
        cset.insert(p[i].C_A);
    }
    cvalue[N - Z] = csum;
    for (int i = N - Z - 1; i >= Y; i--) {
        csum += p[i].C_A;
        cset.insert(p[i].C_A);
        csum -= *cset.begin();
        cset.erase(cset.begin());
        cvalue[i] = csum;
    }
    ll maxi = -(1LL << 60);
    for (int i = Y - 1; i < N - Z; i++) {
        maxi = max(maxi, bvalue[i] + cvalue[i + 1]);
    }
    cout << maxi + sum << endl;

    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

vector<ll> G[100010];
ll col[100010];

ll dfs1(ll x, ll p){
  ll c = 0;
  ll len = 0;
  ll od = 0;
  YYS(w, G[x]){
    if(w == p){
      continue;
    }
    len = dfs1(w, x) + 1;
    if(col[w] == 0){
      col[x] = 1;
    }
    c++;
    if(len >= 0 && len % 2 == 1){
      od++;
    }
  }
  if(od >= 2){
    puts("First");
    exit(0);
  }
  if(c <= 1){
    return len;
  }
  return -INFLL;
}

void dfs2(ll x, ll p, ll up){
  ll c = up;
  YYS(w, G[x]){
    if(w == p){
      continue;
    }
    c += 1 - col[w];
  }
  if(c == 0){
    // cout << x << endl;
    puts("First");
    exit(0);
  }
  YYS(w, G[x]){
    if(w == p){
      continue;
    }
    ll nc = c - (1 - col[w]);
    ll nup = 0;
    if(nc == 0){
      nup = 1;
    }
    dfs2(w, x, nup);
  }
}

int main(){

  ll n = in();

  REP(i, n-1){
    ll a = in() - 1;
    ll b = in() - 1;
    G[a].pb(b);
    G[b].pb(a);
  }

  ll r = -1;
  REP(i, n){
    if(SZ(G[i]) >= 3){
      r = i;
    }
  }
  if(r == -1){
    if(n % 2 == 1){
      puts("First");
    } else {
      puts("Second");
    }
    return 0;
  }
  // cout << "r = " << r << endl;
  dfs1(r, -1);
  /*
  REP(i, n){
    cout << col[i] << " ";
  }
  cout << endl;
  */
  dfs2(r, -1, 0);

  puts("Second");
  
  return 0;
}


Measured memory_bytes: 7936
x1, y1, x2, y2 = list(map(int, input().split()))

w = x2 - x1
h = y2 - y1

x3 = x2 - h
y3 = y2 + w
x4 = x3 - w
y4 = y3 - h

print(x3, y3, x4, y4)


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

int main(void){
  vector<int> a(4);
  vector<int> b(4);

  while(cin>>a[0]){
    int va[10] = {0};
    int vb[10] = {0};
    va[--a[0]]++;
    for(int i = 1 ; i < 4 ; i ++){
      cin>>a[i];
      va[--a[i]]++;
    }
    int hit = 0;
    for(int i = 0 ; i < 4 ; i ++){
      cin>>b[i];
      if(a[i] + 1 == b[i]){
	hit++;
      }
      vb[--b[i]]++;
    }
    int blow = 0;
    for(int i = 0 ; i < 10 ; i ++){
      blow += min(va[i],vb[i]);
    }
    cout<<hit<<" "<<blow-hit<<endl;
  }
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b;
  cin >> c >> d;
  //if(4<(int)(s.substr(5,2))) cout << "TBD" << endl;
  //else cout << "Heisei" << endl;
  cout << a*b - c*b - a*d + c*d << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
C, S, F = [], [], []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)
S.append(0)

import numpy as np
def theta(x): #ヘヴィサイドの段差関数
    return x if x > 0 else 0

def DptTimeAtNextSt(i, T): #時刻Tに駅iを出発した時、駅i+1を出発する時間
    global C, S, F
    arrT = T + C[i]
    if i == N-2: return arrT 
    return S[i+1] + np.ceil(theta(arrT-S[i+1])/F[i+1]) * F[i+1]

def solve(i, S): #駅iに対する解を再帰的に解く関数
    if i == N-1:
        return int(S)
    else:
        return solve(i+1, DptTimeAtNextSt(i,S))

for i in range(N):
    print(solve(i,S[i]))

Measured memory_bytes: 27412
#include <stdio.h>

int main(){
  int N;
  int count=0;
  scanf("%d",&N);
  for(int i=1;i<=N;i++){
    if(i%2!=0){
        count++;
    }
  }
  double ans=(double)count/(double)N;

  printf("%f",ans);
  return 0;
}


Measured memory_bytes: 128
private val scanner = java.util.Scanner(System.`in`)

private fun readInts(n: Int) = Array(n) { scanner.nextInt() }
private fun readLongs(n: Int) = Array(n) { scanner.nextLong() }
private fun readLineInts() = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()
private fun readLineLongs() = readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

fun main(args: Array<String>) {
    val S = readLine()!!

    var ans = Int.MAX_VALUE
    for (s in 2 until S.length) {
        val value = Math.abs("${S[s - 2]}${S[s - 1]}${S[s]}".toInt() - 753)
        if (ans > value) ans = value
    }

    println(ans)
}


Measured memory_bytes: 33416
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a*b/2;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll A;
  string B;
  cin >> A >> B;

  ll b = 100*(B[0] - '0') + 10*(B[2] - '0') + (B[3] - '0');

  ll ans = A * b / 100;

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


Measured memory_bytes: 3624
import java.io.*;
import java.util.*;

public class Main{
	
	static int mod=(int)1e9+7;
	
	public static void main(String[] args) throws IOException {
//		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		
		outer: while(ts-->0) {	
			
			char [] s=in.next().toCharArray();
			char [] t=in.next().toCharArray();
			int ans=Integer.MAX_VALUE;
			for(int i=0; i<=s.length-t.length; i++) {
				int k=value(s,t,i);
				ans=Math.min(k,ans);
			}
		
			out.println(ans);
		}
		out.close();		
		
	}

	
	static int value(char [] s,char [] t, int i) {
		int count=0;
		for(int j=0; j<t.length; j++) {
			if(s[i+j]!=t[j]) count++;
		}
		return count;
	}
	
	
/*********************************** UTILITY CODE BELOW **************************************/	
	
	static int ans=Integer.MAX_VALUE;
	
	
	
	static int abs(int a) {
		return a>0 ? a : -a;
	}
	static int pow(int n, int m) {
		if(m==0) return 1;
		int temp=pow(n,m/2);
		long res=(((long)temp*temp)%mod);
		if(m%2==0) return (int)res;
		return (int)((res*n)%mod);
	}
	
	static class Pair{
		int u, v;
		
		Pair(int u, int v){this.u=u; this.v=v;}
		
		static void sort(Pair [] coll) {		
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}	
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}
		
	}
	
	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static int [] array(int n, int value) {	
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}
	
	static class Reader{
		
		BufferedReader br;
		StringTokenizer to;
		
		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}
		
		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());	
				}catch(IOException e) {}
				
			}
			return to.nextToken();
			
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}
		
	}
	
	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}
	
}

Measured memory_bytes: 32964
#include<iostream>

using namespace std;

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

    int k;
    cin >> k;

    int H[n];

    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> H[i];

        if(H[i] >= k){
            cnt++;
        }
    }

    cout << cnt << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define Tayeb ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;
int main()
{
    Tayeb;
    string s;
    cin >> s;

    if(s[2]==s[3]&&s[4]==s[5])
    cout << "Yes\n";
    else
    cout << "No\n";

    return 0;

}


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer a;

  a=nil->next;
  while(a->key!=key&&a!=nil)
    a=a->next;

  return a;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer s=nil->prev;
  deleteNode(s);
}

void delete(int key){
  deleteNode(listSearch(key));
    }


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  x->next->prev=x;
  nil->next=x;  
  x->prev=nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 33032
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<int>pasta(3), juce(2);
	for (int i = 0; i < 3; i++)cin >> pasta[i];
	for (int i = 0; i < 2; i++)cin >> juce[i];
	cout << *min_element(pasta.begin(), pasta.end()) + min(juce[0], juce[1]) - 50 << endl;
	return 0;
}

Measured memory_bytes: 3100
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

const int N=5009,M=1000000007;
int n,d[N],inv[N],F[N],f[N][N][2],flag;

void init()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&d[i]),flag+=(d[i]==2);
}

int ksm(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
			res=1LL*res*a%M;
		b>>=1,a=1LL*a*a%M;
	}
	return res;
}

void add(int &x,int y)
{
	x=(x+y)%M;
}

void work()
{
	F[0]=inv[0]=1;
	for (int i=1;i<=n;i++)
		F[i]=1LL*F[i-1]*i%M;
	inv[n]=ksm(F[n],M-2);
	for (int i=n-1;i>=1;i--)
		inv[i]=1LL*inv[i+1]*(i+1)%M;
	//printf("%d\n",(int)(1LL*F[n]*inv[n]%M));
	int inv2=ksm(2,M-2);
	if(flag==n)
	{
		printf("%d\n",(int)(1LL*F[n-1]*inv2%M));
		return;
	}
	f[0][0][0]=1;
	for (int i=0;i<n;i++)
		for (int j=0;j<=i;j++)
			for (int k=0;k<=1;k++)
			{
				if(f[i][j][k]==0)
					continue;
				add(f[i+1][j][k],1LL*f[i][j][k]*inv[d[i+1]-1]%M);
				if(d[i+1]>1)
					add(f[i+1][j+1][k],1LL*f[i][j][k]*inv[d[i+1]-2]%M);
				if(d[i+1]>2&&!k)
					add(f[i+1][j+1][1],1LL*f[i][j][k]*inv[d[i+1]-3]%M);
			}
	int ans=0;
	for (int i=3;i<n;i++)
		add(ans,1LL*f[n][i][1]*inv2%M*F[n-i-1]%M*F[i-1]%M);
	printf("%d\n",ans);
}

int main()
{
	init();
	work();
	return 0;
}


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

int main() {
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    string s;
    int dx=tx-sx;
    int dy=ty-sy;
    for (int i=0;i<dx;i++) s.push_back('R');
    for (int i=0;i<dy;i++) s.push_back('U');
    for (int i=0;i<dx;i++) s.push_back('L');
    for (int i=0;i<dy;i++) s.push_back('D');
    s.push_back('D');
    for (int i=0;i<dx+1;i++) s.push_back('R');
    for (int i=0;i<dy+1;i++) s.push_back('U');
    s.push_back('L');
    s.push_back('U');
    for (int i=0;i<dx+1;i++) s.push_back('L');
    for (int i=0;i<dy+1;i++) s.push_back('D');
    s.push_back('R');
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n,TotalTime;
  cin>>n>>TotalTime;
  int MinCost=1009;
  rep(i,n){
    int c,t;
    cin>>c>>t;
    if(TotalTime>=t) MinCost=min(MinCost,c);
  }
  if(MinCost==1009) cout<<"TLE"<<endl;
  else cout<<MinCost<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

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

  int n;
  string s;
  cin >> n;
  cin >> s;
  if(n%2!=0){
    cout << "No" << endl;
    return 0;
  }
  rep(i,n/2){
    if(s[i]!=s[i+n/2]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
    

}


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

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,p) scanf("%d %d %d %d",&n,&m,&o,&p)
#define SINT5(n,m,o,p,q) scanf("%d %d %d %d %d",&n,&m,&o,&p,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 0x2aaaaaaa; // 715,827,882
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second


int n;
int c[512];
int s[512];
int f[512];



void solve(int a) {
	int r = 0;
	repft(i, a, n-1) {
		if (r < s[i]) r = s[i];
		if (r%f[i] != 0) r += f[i] - r%f[i];
		r += c[i];
	}
	cout << r << endl;
}


int main() {
	cin >> n;
	rep(i, n-1)cin >> c[i] >> s[i] >> f[i];

	rep(i,n)  solve(i);


	//for (;;)getchar();

	return 0;
}

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

using namespace std;
const int N = 400, Q = 1e5 + 5;
bitset <N> s[N];
int a[Q], b[Q];
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, q; cin >> n >> q;
    for (int i = 1; i <= q; i++) cin >> a[i] >> b[i], a[i]--, b[i]--;
    for (int i = 0; i < n; i++) {
        s[i][i] = 1;
        for (int j = q; j > 0; j--) {
            if (s[i][a[j]] == 1 && s[i][b[j]] == 1) {s[i].set(); continue ;}
            s[i][a[j]] = s[i][b[j]] = (s[i][a[j]] | s[i][b[j]]);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) ans += ((s[i]&s[j]).count() == 0);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
def main():
    X = int(input())

    a = -1
    
    while True:
        b1 = 0
        b2 = 0
        while b1 < a:
            
            if (X/(a-b1)).is_integer():
                if int(X/(a-b1)) == a**4 + b1*(a**3) + (a**2)*(b1**2) + a*(b1**3) + b1**4:
                    print("{} {}\n".format(a, b1))
                    return 0

            if (X/(a-b2)).is_integer():
                if int(X/(a-b2)) == a**4 + b2*(a**3) + (a**2)*(b2**2) + a*(b2**3) + b2**4:
                    print("{} {}\n".format(a, b2))
                    return 0

            b1 += 1
            b2 -= 1
            
        a += 1


if __name__ == "__main__":
    main()

          


Measured memory_bytes: 9052
N = gets.to_i
Hn = gets.split.map(&:to_i)
res = 'Yes'
prev = -999

N.times do |i|
  h = Hn[i]

  if prev <= h - 1
    prev = h - 1
  elsif prev <= h
    prev = h
  else
    res = 'No'
  end
end

puts res


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

using namespace std;
#define ll long long int
const int MAXN = 2 * 1e5 + 5;

void solve(){
    double a, b; 
    cin >> a >> b;
    bool poss = false;
    for(int i = 1; i <= 1e6; ++i){
        double x = floor(i * 0.08);
        double y = floor(i * 0.1);
        if( x == a and y == b){
            poss = true;
            cout << i << '\n';
            break;
        }
    }
    if(!poss)
        cout << -1 << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
	//int t; cin >> t;
	//while(t--)
		solve();
}







Measured memory_bytes: 256
#include <iostream>
using namespace::std;
int main(int argc, const char * argv[]) {
    int H, W;
    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for (int i = 0; i<H; i++) {
            for (int j = 0; j<W; j++) {
                if ((i+j)%2 == 0) {
                    cout << "#";
                }
                else{
                    cout <<".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#!/usr/bin/env python3
import sys


def solve(N: int, d_li: "List[int]"):
    s = 0
    for i in range(N):
        di = d_li.pop()
        s += sum([di * d for d in d_li])
    print(s)


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n, m = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(m)]
P = list(map(int, input().split()))
ct = 0
for i in range(2 ** n):
    sw = [0] * n
    on = [False] * m
    for j in range(n):
        if((i >> j) & 1):
            sw[j] = 1
    for k in range(m):
        tmp = 0
        for l in range(1, len(S[k])):
            if sw[S[k][l] - 1] == 1:
                tmp += 1
        if tmp % 2 == P[k]:
            on[k] = True
    if False not in on:
        ct += 1
print(ct)

Measured memory_bytes: 3064
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
X=A+B+C
n=int(input())
for i in range (n):
    y=int(input())
    X=['X' if j==y else j for j in X]
if X[0]==X[3]==X[6]=='X':
    print('Yes')
elif X[1]==X[4]==X[7]=='X':
    print('Yes')
elif X[2]==X[5]==X[8]=='X':
    print('Yes')
elif X[0]==X[1]==X[2]=='X':
    print('Yes')
elif X[3]==X[4]==X[5]=='X':
    print('Yes')
elif X[6]==X[7]==X[8]=='X':
    print('Yes')
elif X[0]==X[4]==X[8]=='X':
    print('Yes')
elif X[2]==X[4]==X[6]=='X':
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9200