akhauriyash/Code-Regression huggingface dataset:
use std::collections::BinaryHeap;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<i64> = sc.vec(n);
    let mut b: Vec<i64> = sc.vec(n);
    let mut heap = BinaryHeap::new();
    for i in 0..n {
        let center = b[i];
        let prev = b[(i + n - 1) % n];
        let next = b[(i + 1) % n];
        if center - a[i] >= prev + next {
            let count = (center - a[i]) / (prev + next);
            heap.push((count, i));
        }
    }

    let mut ans = 0;
    while let Some((_, i)) = heap.pop() {
        let prev = b[(i + n - 1) % n];
        let next = b[(i + 1) % n];
        let count = (b[i] - a[i]) / (prev + next);
        ans += count;
        b[i] -= (prev + next) * count;

        let i = (i + 1) % n;
        let center = b[i];
        let prev = b[(i + n - 1) % n];
        let next = b[(i + 1) % n];
        if center - a[i] >= prev + next {
            let count = (center - a[i]) / (prev + next);
            heap.push((count, i));
        }

        let i = (i + n - 2) % n;
        let center = b[i];
        let prev = b[(i + n - 1) % n];
        let next = b[(i + 1) % n];
        if center - a[i] >= prev + next {
            let count = (center - a[i]) / (prev + next);
            heap.push((count, i));
        }
    }

    if a != b {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
#define NIL -1

struct Node{
    int p,l,r;
};

void setDepth(vector<Node> &T,vector<int> &D,int u,int p){
    D[u]=p;
    if(T[u].r!=NIL){
        setDepth(T,D,T[u].r,p+1);
    }
    if(T[u].l!=NIL){
        setDepth(T,D,T[u].l,p+1);
    }
}

int setHeight(vector<Node> &T,vector<int> &H,int u){
    int h1=0,h2=0;
    if(T[u].l!=NIL){
        h1=setHeight(T,H,T[u].l)+1;
    }
    if(T[u].r!=NIL){
        h2=setHeight(T,H,T[u].r)+1;
    }
    return H[u]=max(h1,h2);
}



int main(){
    int n;
    cin>>n;
    vector<Node> T(25);
    vector<int> D(25),H(25);
    for(int i=0;i<n;i++){
        T[i].p=T[i].l=T[i].r=NIL;
    }
    for(int i=0;i<n;i++){
        int x,y,z;
        cin>>x>>y>>z;
        if(y!=-1){
            T[x].l=y;
            T[y].p=x;
        }
        if(z!=-1){
            T[x].r=z;
            T[z].p=x;
        }
    }
    for(int i=0;i<n;i++){
        if(T[i].p==-1){
            setDepth(T,D,i,0);
            setHeight(T,H,i);
        } 
    }
    
    for(int i=0;i<n;i++){
        cout<<"node "<<i<<": parent = "<<T[i].p<<", sibling = ";
        if(T[i].p==-1){
            cout<<-1;
        }
        else{
            if(i==T[T[i].p].l){
            cout<<T[T[i].p].r;
            }
            else if(i==T[T[i].p].r){
            cout<<T[T[i].p].l;
            }
        }
        cout<<", degree = ";
        int cnt=0;
        if(T[i].l!=NIL) cnt++;
        if(T[i].r!=NIL) cnt++;
        cout<<cnt;
        cout<<", depth = "<<D[i]<<", height = "<<H[i]<<", ";
        if(T[i].p==-1){
            cout<<"root";
        }
        else if(T[i].l==-1&&T[i].r==-1){
            cout<<"leaf";
        }
        else{
            cout<<"internal node";
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (998244353);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    string s;
    cin >> n >> s >> k;
    for (auto&& c : s) {
        if (c != s[k - 1]) c = '*';
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
	int N, W;
	cin >> N >> W;

	vector<int> w(N);
	vector<long long> v(N);
	for (int i = 0; i < N; i++)
		cin >> w[i] >> v[i];

	vector<vector<long long>> dp(N+1, vector<long long>(W + 1, 0));
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= W; j++) {
			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);

			if (j - w[i - 1] < 0)
				continue;
			
			dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}


Measured memory_bytes: 80256
#include <stdio.h>
int main()
{
    long long int a,b,d;
    scanf("%lld %lld %lld",&d,&a,&b);
    {
        if( b <= a )
        {
            printf("delicious");
        }
        else if ( b > a + d )
        {
            printf("dangerous");
        }
        else
        {
            printf("safe");
        }
    }
return 0;
}

Measured memory_bytes: 1712
using System;
using System.Linq;
using System.Collections.Generic;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray();

            var count1 = 0;
            var count2 = 0;
            for(var i = 0; i < s.Length; i++){
                //0101…
                if(i % 2 == 0){
                    if(s[i] == '1'){
                        count1++;
                    }
                }else{
                    if(s[i] == '0'){
                        count1++;
                    }
                }

                //1010…
                if(i % 2 == 0){
                    if(s[i] == '0'){
                        count2++;
                    }
                }else{
                    if(s[i] == '1'){
                        count2++;
                    }
                }
            }

            Console.WriteLine(Math.Min(count1, count2));
        }
    }
}


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

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

    vector<int> vec(n);
    for (int i = 0; i < n; i++) cin >> vec.at(i);
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    int dan = 1;
    for (int i = 0; i < n - 1; i++) {
        if (vec.at(i) > vec.at(i + 1)) dan++;
    }

    cout << dan << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[100010],b[100010],sa,ans,su;
vector<ll>yoy;
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		if(b[i]>a[i]){
			sa+=b[i]-a[i];
			ans++;
		}
		else{
			yoy.push_back(a[i]-b[i]);
			su+=a[i]-b[i];
		}
	}
	if(sa>su){
		cout << -1;
		return 0;
	}
	sort(yoy.begin(),yoy.end());
	reverse(yoy.begin(),yoy.end());
	for(int i=0;yoy.size();i++){
		if(sa<=0){
			break;
		}
		ans++;
		sa-=yoy[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 2936
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
    int R[MAX], n;

    cin >> n;

    for (int i = 0; i != n; ++i)
    {
        cin >> R[i];
    }

    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i != n; ++i)
    {
        maxv = max(maxv, R[i]-minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3888
#include <stdio.h>

int main(void)
{
	int path[100][60];
	int sum[100][60];
	int i, j;
	char temp;
	int num, flag;
	
	for (i = 0; i < 100; i++){
		for (j = 0; j < 60; j++){
			path[i][j] = 0;
			sum[i][j] = 0;
		}
	}
	i = j = num = flag = 0;
	while (scanf("%d%c", &path[i][j], &temp) != EOF){
		nevermind:;
		if (!flag){
			if (sum[i - 1][j] > sum[i - 1][j - 1] || j == 0){
				sum[i][j] = path[i][j] + sum[i - 1][j];
			}
			else {
				sum[i][j] = path[i][j] + sum[i - 1][j - 1];
			}
		}
		else {
			if (sum[i - 1][j] > sum[i - 1][j + 1]){
				sum[i][j] = path[i][j] + sum[i - 1][j];
			}
			else {
				sum[i][j] = path[i][j] + sum[i - 1][j + 1];
			}
		}
		j++;
		if (path[i][j] != -1 && flag && temp == '*'){
			goto nevermind;
		}
		
		if (temp == '\n' || path[i][j] == -1){
			if (j < num){
				flag = 1;
				temp = '*';
				path[i][j] = -1;
				j = num = 0;
				goto nevermind;
			}
			else if (!flag){
				num = j;
			}
			i++;
			j = 0;
		}
	}
	i--;
	
	printf("%d\n", sum[i][0]);
	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define MOD 998244353
template<typename ty1,typename ty2>
inline int add(ty1 x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x += y; return x < MOD ? x : x - MOD;
}
template<typename ty1,typename ty2>
inline void addto(ty1 &x, ty2 y) {
		  if(y>=MOD)y%=MOD;
		  if(x>=MOD)x%=MOD;
	      x += y; if (x >= MOD) x -= MOD;
}
template<typename ty1,typename ty2>
inline int sub(ty1 x, ty2 y) {
		if(y>=MOD)y%=MOD;
		 if(x>=MOD)x%=MOD;
        x -= y; return x < 0 ? x + MOD : x;
}
template<typename ty1,typename ty2>
inline void subto(ty1 &x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x -= y; if (x < 0) x += MOD;
}
template<typename ty1,typename ty2>
inline int mul(ty1 x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        return 1ll * x * y % MOD;
}
template<typename ty1,typename ty2>
void multo(ty1 &x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        x=1ll * x * y % MOD;
}
  
long long int gcd(long long int a, long long int b){
	if (a > b){
		swap(a, b);
	}
	while (a){
		swap(a, b);
		a %= b;
	}
	return b;
}
long long int lcm(long long int a, long long int b){
	return a / gcd(a, b)*b;
}
long long int ppow(long long int i, long long int j){
		long long int res = 1LL;
		while (j){
			if ((j & 1LL)){
				res *= i;
				if (res >= MOD){
					res %= MOD;
				}
			}
			j >>= 1;
			i *= i;
			if (i >= MOD){
				i %= MOD;
			}
		}
		return res;
	}
class Combination{
	
public:
	vector<long long int> k;
	vector<long long int> r;
	void resize(int N){
		k.resize(N + 2);
		r.resize(N + 2);
		k[0] = 1;
		for (int i = 1; i < N+2; i++){
			k[i] = k[i - 1];
			k[i] *= i;
			if (k[i] >= MOD)k[i] %= MOD;
		}
		long long int al = k[k.size() - 1];
		long long int iv = ppow(k[k.size() - 1],MOD-2);
		r[k.size() - 1] = iv;
		for (int i = (int)(r.size()) - 2; i >= 0; i--){
			r[i] = r[i + 1] * (i + 1);
			if (r[i] >= MOD){
				r[i] %= MOD;
			}
		}
	}
	long long int C(int a, int b){
		if (a < b)return 0;
		long long int up = k[a];
		long long int dw = r[b] * r[a - b];
		dw %= MOD;
		up *= dw;
		up %= MOD;
		return up;
	}
	long long int H(int a, int b){
		return C(a + b - 1, b);
	}
	long long int catalan_number(int n){
		return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD;
	}
};
Combination C;

int main(){
	string s;
	cin>>s;
	cout<<s.substr(0,3)<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int n,m,q,k;
struct node{
	int price,power[20];
}p[20];
int ans=inf;
void dfs(int cur,vector<int> sum,int cost)
{
	int f=1;
	for(int i=1;i<=m;i++){
		if(sum[i]<k){
			f=0;
			break;
		}
	}
	if(f) ans=min(ans,cost);	
	if(cur==n+1) return;
	for(int i=cur;i<=n;i++){
		vector<int>now=sum;
		for(int j=1;j<=m;j++){
			now[j]+=p[i].power[j];
		}
		dfs(i+1,now,cost+p[i].price);
	}
}
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		cin>>p[i].price;
		for(int j=1;j<=m;j++) cin>>p[i].power[j];
	}
	vector<int>s(14,0);
	dfs(1,s,0);
	if(ans==inf) cout<<-1;
	else cout<<ans;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		// 入力値を取得
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();

		// 差分の最大値
		int[] data = {Math.abs(a - b), Math.abs(a - c), Math.abs(a - d),
				Math.abs(a - e), Math.abs(b - c), Math.abs(b - d),
				Math.abs(b - e), Math.abs(c - d), Math.abs(c - e),
				Math.abs(d - e)};
		int BigDifference = data[0];
		for (int i = 0; i < data.length; i++) {
			int value = data[i];
			if (value > BigDifference) {
				BigDifference = value;
			}
		}

		// 差分の最大値とkを比較
		if (BigDifference > k) {
			System.out.println(":(");
		} else {
			System.out.println("Yay!");
		}

		// クローズ
		sc.close();

	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
    
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    int a[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int dp[n][3];
    for(int j=0;j<3;j++){
        dp[0][j]=a[0][j];
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            int l=-1;
            for(int k=0;k<3;k++){
                if(j==k) continue;
                l=max(l,dp[i-1][k]);
            }
            dp[i][j]=l+a[i][j];
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 2560
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

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

	if (n <= k) {
		cout << 1 << endl;
		return 0;
	}

	int cnt = 1;

	while (n / k) {
		n /= k;
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}

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

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  COMinit();
  for (int i = 1; i <= k; i++){
    ans = (COM(n - k + 1, i) * COM(k - 1, i - 1)) % MOD;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> x(n), s(n);
  rep(i, n){
    cin >> x.at(i);
    s.at(i) = x.at(i);
  }
  sort(ALL(s));
  int l = s.at(n/2-1), r = s.at(n/2);
  // cerr << l << " " << r << endl;
  rep(i, n){
    if(x.at(i) <= l){
      cout << r << endl;
    }else{
      cout << l << endl;
    }
  }
  return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t, x;
	cin >> t >> x;
	double ans = (double)t / x;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    int a, b, c;
    int x;
    cin >> a >> b >> c >> x;
    int counter = 0;
    for (int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for (int k = 0; k <= c; k++){
                if (500*i + 100*j + 50*k == x) counter++;
            }
        }
    }
    cout << counter << endl;

    return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

// A - Libra
// https://atcoder.jp/contests/abc083/tasks/abc083_a
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        int C = Integer.parseInt(scanner.next());
        int D = Integer.parseInt(scanner.next());
        scanner.close();

        if (A + B == C + D) {
            System.out.println("Balanced");

        } else if (A + B > C + D) {
            System.out.println("Left");
        } else {
            System.out.println("Right");
        }
    }
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main(){
    int icn;
    int iop;
    cin >> icn;
    cin >> iop;
    vector<int> v;
    vector<int> ke;
    for(int i = 0;i < icn*2;i++){
        v.push_back(i+1);
    }
    for(int i = 0;i < iop;i++){
        int op;
        cin >> op;
        if(op >= 1){
            ke = v;
            for(int k = 0;k < op;k++){
                v[icn*2-1-k] = v[op-1-k];
            }
            for(int k = 0;k < icn*2-op;k++){
                v[k] = ke[op+k];
            }
        }
        else if(op == 0){
            ke = v;
            for(int k = 0;k < icn;k++){
                v[k*2] = ke[k];
                v[k*2+1] = ke[k+icn];
            }
        }
    }
    for(int i = 0;i < icn*2;i++){
        cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3136
N, M = map(int, input().split())
A = [''] * N
B = [''] * M
for i in range(N):
    A[i] = input()
for i in range(M):
    B[i] = input()

match_cnt = 0
for i in range(N - M + 1):
    for j in range(N - M + 1):
        flag = True
        for y in range(M):
            for x in range(M):
                if A[y + i][x + j] != B[y][x]:
                    flag = False
        if flag:
            match_cnt += 1

if match_cnt > 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9112
import java.util.Scanner;

/**
 * D - Brick Break
 * N 個のレンガが横一列に並んでいます。
 * 左から i (1≤i≤N) 番目のレンガには、整数 ai が書かれています。
 * あなたはこのうち N−1 個以下の任意のレンガを選んで砕くことができます。
 * その結果、K 個のレンガが残っているとします。
 * このとき、任意の整数 i (1≤i≤K) について、残っているレンガの中で左から i 番目のものに書かれた整数が i であるとき、すぬけさんは満足します。
 * すぬけさんが満足するために砕く必要のあるレンガの最小個数を出力してください。
 * もし、どのように砕いてもそれが不可能な場合、代わりに -1 を出力してください。
 */
public class Main {

    public static void main( String[] args ) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        int n = sc.nextInt();   // レンガの数
        int[] a = new int[n];

        boolean judgement = false;
        int breakCnt = 0;   // 壊したレンガのカウント用
        int brickTemp = 0;   // 現在の残すレンガの数仮置き
        for( int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
            if( a[i] == 1 ) {
                judgement = true;
                brickTemp = 1;
            }

            // すでに1を確認している場合
            if( judgement ) {
                if( a[i] == brickTemp + 1 ) brickTemp = a[i];
                else breakCnt++;
            }
            else {
                breakCnt++;
            }
        }

        // 1がない場合、不可能なので-1を返却
        System.out.println( judgement ? breakCnt - 1 : -1 );

        sc.close();
    }
}

Measured memory_bytes: 60332
n,x = map(int,input().split())
l = list(map(int,input().split()))
wa = 0
d = [0]*(n+3)
d[1]=0
d.pop(0)
wa = 1
for i in range(2,n+2):
  d[i]=d[i-1]+l[i-2]
  if(d[i]>x):
    break
  wa+=1
print(wa)

Measured memory_bytes: 9188
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(args: Array<String>) {
    val (a,b) =  readInts()
    when {
        a >= 13 -> println(b)
        a in 6..12 -> println(b / 2)
        else -> println(0)
    }
}

Measured memory_bytes: 37868
#include <stdio.h>
int main(void){
   int n,i,j,k,l;
   int dice[24][6];
   int label[24][6]={{1,2,3,4,5,6},{1,3,5,2,4,6},{1,4,2,5,3,6},{1,5,4,3,2,6},{2,1,4,3,6,5},{2,3,1,6,4,5},
   {2,4,6,1,3,5},{2,6,3,4,1,5},{3,1,2,5,6,4},{3,2,6,1,5,4},{3,5,1,6,2,4},{3,6,5,2,1,4},{4,1,5,2,6,3},
   {4,2,1,6,5,3},{4,5,6,1,2,3},{4,6,2,5,1,3},{5,1,3,4,6,2},{5,3,6,1,4,2},{5,4,1,6,3,2},{5,6,4,3,1,2},
   {6,2,4,3,5,1},{6,3,2,5,4,1},{6,4,5,2,3,1},{6,5,3,4,2,1}};
    
   scanf("%d",&n);
   int dices[n][6];
    
   for(i=0;i<n;i++){
       for(j=0;j<6;j++) scanf("%d",&dices[i][j]);
   }
    
  
   for(i=0;i<n-1;i++){
       for(j=i+1;j<n;j++){
            
           for(k=0;k<24;k++){
               for(l=0;l<6;l++) dice[k][l]=dices[j][label[k][l]-1];
           }
            
         
           for(k=0;k<24;k++){
               for(l=0;l<6;l++) {
                   if(dice[k][l]!=dices[i][l]) {
                       break;
                   }
               }
               if(l==6){
                    printf("No\n");
                    return 0;
               }
           }
       }
   }
    
   printf("Yes\n");
   return 0;
}




Measured memory_bytes: 2140
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A
#include <iostream>
using namespace std;

int fibonacci(int n){
    if(n == 0 || n == 1){
        return 1;
    }
    else{
        return fibonacci(n-1)+fibonacci(n-2);
    }
}

int fib(int n){
    int a0 = 0, a1 = 1;
    int a2 = 0;
    for(int i=0; i<n; i++){
        a2 = a0+a1;
        a0 = a1;
        a1 = a2;
    }
    return a2;
}


int main(){
    int n;
    cin >> n;
    //cout << fibonacci(n) << endl;
    cout << fib(n) << endl;

}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f[10001],g[10001],h[10001],j,i,k=0,z=0,x,c,v;
	scanf("%d %d %d",&a,&s,&d);
	for(i=0;i<s;i++) scanf("%d",&f[i]);
	for(i=0;i<s;i++){
		if(d<f[i]){
			g[i]=f[i]-d;
			h[i]=d+a-f[i];
		}
		else if(d>f[i]){
			g[i]=(a+f[i])-d;
			h[i]=d-f[i];
		//	printf("%d %d\n",g[i],h[i]);
		}
		else{
			g[i]=0;
			h[i]=0;
		}
		if(g[i]>k) k=g[i];
		if(h[i]>z) z=h[i];
	}
	if(k<z) z=k;
	for(i=0;i<s;i++){
		for(j=i+1;j<s;j++){
			if(g[i]<g[j]){
				c=g[i];
				g[i]=g[j];
				g[j]=c;
				c=h[i];
				h[i]=h[j];
				h[j]=c;
			}
		}
	}
/*	for(i=0;i<a;i++){
		printf("")*/
	v=0;
	k=0;
	for(i=0;i<s-1;i++){
		v=h[i]*2+g[i+1];
		k=h[i]+g[i+1]*2;
		if(z>v) z=v;
		if(z>k) z=k;
	//	printf("1   %d\n",z);
		v=h[i+1]*2+g[i];
		k=h[i+1]+g[i]*2;
		if(z>v) z=v;
		if(z>k) z=k;
	//	printf("2   %d\n",z);
	}
	printf("%d\n",z*100);
	/*for(i=0;i<s;i++){
		printf("%d %d\n",g[i],h[i]);
	}*/
	return 0;
}

Measured memory_bytes: 2736
# AGC007a
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    h, w = map(int, input().split())

    cou = 0
    for _ in range(h):
        cou += input().count('#')
    if cou == h+w-1:
        print('Possible')
        exit(0)
    print('Impossible')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    int w,a,b,x;
    x=0;
    cin >> w >> a >> b;
    if(a+w<b)
        x=b-(a+w);
    else if(b+w<a)
        x=a-(b+w);
    cout << x << endl;
    return 0;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL H, W;
    cin >> H >> W;
    
    LL tate = H*(W%3 != 0);
    LL yoko = W*(H%3 != 0);

    LL tateyoko = W*H;
    FOR(i, 0, W + 1) {
        LL mx = max(H*i, (H/2 + (H%2 == 1))*(W - i));
        LL mn = min(H*i, (H/2)*(W - i));
        tateyoko = min(mx - mn, tateyoko);
    }

    LL yokotate = W*H;
    FOR(i, 0, H + 1) {
        LL mx = max(W*i, (W/2 + (W%2 == 1))*(H - i));
        LL mn = min(W*i, (W/2)*(H - i));
        yokotate = min(mx - mn, yokotate);
    }

    cout << min({tate, yoko, tateyoko, yokotate}) << endl;
    return 0;
}



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


def main():
    N = int(input())

    ans = 0
    p_max = 0
    for _ in range(N):
        p = int(input())
        ans += p
        p_max = max(p_max, p)
    
    print(ans - p_max//2)


if __name__ == '__main__':
    main()

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

void Main()
{
  ll N, M;
  cin >> N >> M;
  vector<pair<ll,ll>> AB(N);
  rep(i,N) {
    cin >> AB[i].first >> AB[i].second;
  }
  sort(AB.begin(), AB.end());
  ll money = 0;
  ll buy = 0;
  rep(i,N) {
    //cout << AB[i].first << " " << AB[i].second << endl;
    if (buy + AB[i].second >= M) {
      ll buyNum = M - buy;
      money += buyNum * AB[i].first;
      break;
    } else {
      money += AB[i].second * AB[i].first;
      buy += AB[i].second;
    }
  }
  cout << money << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
typedef long long ll;
typedef long double ld;

template <typename T, typename... Args>
T vmin(T x) { return x; }

template <typename T,typename... Args>
T vmin(T x, T y) { return x < y ? x : y; }

template <typename T,typename... Args>
T vmin(T x, Args... args) { return vmin(x, vmin(args...)); }

ll n, a, b;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2;
	}
	else {
		cout << vmin(b - 1, n - a, a+(b-a-1)/2, n-b+1+(n-(a+(n-b+1)))/2) << endl;
	}
}

Measured memory_bytes: 256
import static java.lang.System.out;
 public class Main{
     public static void main(String[] args){
         String str = new java.util.Scanner(System.in).nextLine();
         String[] tmp = str.split(" ");
         int W = Integer.parseInt(tmp[0]);
         int H = Integer.parseInt(tmp[1]);
         int x = Integer.parseInt(tmp[2]);
         int y = Integer.parseInt(tmp[3]);
         int r = Integer.parseInt(tmp[4]);
 
         if(r <= x && x <= (W - r) && r <= y && y <= (H - r)){
             out.println("Yes");
         }
         else{
             out.println("No");                                                                                                             
         }
 
     }
 }

Measured memory_bytes: 26140
N=int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
n = N-2
i = 1
ans = a[0]
while n > 0:
    if n > 1:
        ans += a[i]*2
        i += 1
        n -= 2
    elif n == 1:
        ans += a[i]
        i += 1
        n -= 1
    else:
        pass
print(ans)


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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_VAL = 1e5 + 5;

int N, W;
ll dp[MAX_VAL];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> W;
	fill(dp, dp + MAX_VAL, INF);
	dp[0] = 0;
	for (int i = 0; i < N; ++i) {
		int w, v; cin >> w >> v;
		for (int j = 1e5; j >= 0; --j) {
			if (j - v < 0) break;
			dp[j] = min(dp[j], dp[j - v] + w);
		}
	}

	for (int i = 1e5; i >= 0; --i) {
		if (dp[i] <= W) {
			cout << i << '\n'; break;
		}
	}

	return 0;
}

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

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

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

int main() {
	string s;
	cin >> s;
	bool f = 0;
	int n = s.size();
	rep(i, n-1) {
		if (s[i]=='A'&&s[i+1]=='C') {
			f = 1;
		}
	}
	puts(f?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
c = [[int(cn) for cn in input().split()] for _ in range(3)]
max_val = max(c[0])
ans = 'No'
for a1 in range(max_val + 1):
  b = [c[0][i] - a1 for i in range(3)]
  correct = True
  for i in range(2):
    ai_cand = []
    for j in range(3):
      cand = c[i + 1][j] - b[j]
      correct = cand >= 0
      if correct:
        ai_cand.append(cand)
      else:
        break
    correct = correct and (ai_cand[0] == ai_cand[1] and ai_cand[1] == ai_cand[2])
    if not correct:
      break
  if correct:
    ans = 'Yes'
    break
print(ans)


Measured memory_bytes: 62104
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String S = reader.readLine();

            final int alp = 26;

            boolean[] x = new boolean[alp];

            Arrays.fill(x, false);

            boolean flg = true;

            for (int i = 0; i < S.length(); i++) {
                if (x[S.charAt(i) - 'a']) {
                    flg = false;
                    break;
                }

                x[S.charAt(i) - 'a'] = true;
            }

            System.out.println(flg ? "yes" : "no");
        }
    }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		string s; cin >> s;
		rep(i, s.size()) cout << 'x';
		cout << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

using namespace std;

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

typedef pair<int, int> ii;

const int N = 1e5 + 5;

vector<ii> graph[N];

int n, m;

map<int, int> d[N];

struct State{
    int dist, f, c;
};

deque<State> q;

void lmao() {
    q.push_front({0, 1, 0});
    d[1][0] = 0;
    while(!q.empty()) {
        State frt = q.front();
        q.pop_front();
        if(frt.dist > d[frt.f][frt.c]) continue;
        int u = frt.f, c = frt.c;
        if(!d[u].count(0) || (d[u].count(0) && d[u][c] < d[u][0])) {
            d[u][0] = d[u][c];
            q.push_front({d[u][0], u, 0});
        }
        if(c) {
            int pos = lower_bound(graph[u].begin(), graph[u].end(), mp(c, 0)) - graph[u].begin();
            while(pos < graph[u].size() && graph[u][pos].fi == c) {
                ii v = graph[u][pos];
                if(!d[v.se].count(v.fi) || (d[v.se].count(v.fi) && d[v.se][v.fi] > d[u][c])) {
                    d[v.se][v.fi] = d[u][c];
                    q.push_front({d[v.se][v.fi], v.se, v.fi});
                }
                pos++;
            }
        }
        else {
            for(int i = 0; i < graph[u].size(); i++) {
                ii v = graph[u][i];
                if(!d[v.se].count(v.fi) || (d[v.se].count(v.fi) && d[v.se][v.fi] > d[u][c] + 1)) {
                    d[v.se][v.fi] = d[u][c] + 1;
                    q.push_back({d[v.se][v.fi], v.se, v.fi});
                }
            }
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; i++) {
        int u, v, c;
        scanf("%d%d%d", &u, &v, &c);
        graph[u].pb({c, v});
        graph[v].pb({c, u});
    }
    for(int i = 1; i <= n; i++)
        sort(graph[i].begin(), graph[i].end());
    lmao();
    if(!d[n].count(0))
        printf("-1");
    else
        printf("%d", d[n][0]);
}


Measured memory_bytes: 39412
import sys
N = int(input())
a = []
for i in range(N):
    A, B = map(int, input().split())
    a.append([A, B])
a = sorted(a, key=lambda x:x[1])
ans = 0
for x in a:
    ans += x[0]
    if ans > x[1]:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 39704
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 2019
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}

int main(){
    string s;
    cin >> s;
    map<int, int> m;
    int count = 0, cur = 0;
    for (int i = s.length()-1; i >= 0; i--){
        cur += (s[i]-'0') * powmod(10, s.length()-1-i);
        cur %= mod;
        if(cur == 0) count++;
        count += m[cur];
        m[cur]++;
    }
    printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 3752
/*
author: Hayato Kawakita
date: 
vertict: 
URL:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2156&lang=jp#
所要時間：
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }

//inputs s:Single, a:All m: size of vector
int n;
int hp[105];
int m;
string name, target;
int mp, damage;
vector<pair<int, int>> s, a;
int ms, ma;

int dps[100100], dpa[100100];

void solve() {
  fill(dps, dps + 100100, inf);
  fill(dpa, dpa + 100100, inf);
  dps[0] = 0, dpa[0] = 0;
  rep(i, ms) {
    rep(j, 100001) {
      if (j - s[i].second < 0) chmin(dps[j], s[i].first);
      else chmin(dps[j], dps[j - s[i].second] + s[i].first);
    }
  }
  rep(i, ma) {
    rep(j, 100001) {
      if (j - a[i].second < 0) chmin(dpa[j], a[i].first);
      else chmin(dpa[j], dpa[j - a[i].second] + a[i].first);
    }
  }
  ll ans = INF;
  rep(i, 100001) {
    ll res = dpa[i];
    rep(j, n) {
      if (hp[j] - i < 0) continue;
      res += dps[hp[j] - i];
    }
    chmin(ans, res);
  }
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  while (1) {
    s.clear();
    a.clear();
    cin >> n;
    if (n == 0) return 0;
    rep(i, n) cin >> hp[i];
    cin >> m;
    rep(i, m) {
      cin >> name >> mp >> target >> damage;
      if (target[0] == 'S') s.push_back({mp, damage});
      else a.push_back({mp, damage});
    }
    ms = s.size();
    ma = a.size();
    
    solve();
  }

  





  
  return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<long long> a(n), b(m), c(m);
    priority_queue<pair<long long, long long> > p;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        p.push(make_pair(a[i], 1));
    }

    for (int i = 0; i < m; i++) {
        cin >> b[i] >> c[i];
        p.push(make_pair(c[i], b[i]));
    }

    long long sum = 0;
    for (int i = 0; i < n; i++) {
        auto x = p.top(); //first element優先
        p.pop();
        sum += x.first;

        if (x.second > 1) {
            x.second--;
            p.push(x); //再生
        }
    }

    cout << sum << endl;
    return 0;
}

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

long solve(long a, long b)
{
  const auto k0 = a + b;
  return k0 % 2 ? -1 : k0 / 2;
}

int main()
{
  long a, b;
  std::cin >> a >> b;

  const auto k = solve(a, b);
  if (k < 0) {
    std::cout << "IMPOSSIBLE"  << std::endl;
  } else {
    std::cout << k << std::endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    int t=ceil(12.5*a);             //min number whose 8% is a
    int p=ceil(12.5*(a+1)) - 1;     //max number whose 8% is a
    int ans=-1;
    for(int i=t;i<=p;i++)
    {
        if(i/10 == b)
        {
            ans=i;
            break;
        }
    }
    cout<<ans;
    return 0;
}    

Measured memory_bytes: 256
AZ_list = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
N = int(input())
S = list(input())
for s in S:
    new_index = AZ_list.index(s) + N
    if new_index > 25:
        new_index -= 26
    print(AZ_list[new_index], end='')

Measured memory_bytes: 4596
import sys

# 周囲を'.'で囲む
H, W = map(int, input().split())
ss = ['.' + input() + '.' for i in range(H)]
ss = ['.' * (W + 2)] + ss + ['.' * (W + 2)]

dijs = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if ss[i][j] == '.': continue
        for di, dj in dijs:
            if ss[i + di][j + dj] == '#':
                break
        else:
            print('No')
            sys.exit(0)

print('Yes')


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main(){
	int sum, N, T; cin >> N >> T;
	vector<int> time;

	REP(i, N){
		int x; cin >> x;
		time.push_back(x);
	}

	REP(i, N - 1){
		sum += min(T, time[i + 1] - time[i]);
	}
	cout << sum + T << endl;

	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

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


Measured memory_bytes: 3600
def main():
    D = int(input())
    C = list(map(int,input().split()))
    S = [list(map(int,input().split()))for _ in range(D)]

    SELECT = []
    for i in range(D):
        SELECT.append(int(input())-1)

    M = int(input())
    d = []
    q = []
    for _ in range(M):
        td, tq = map(int,input().split())
        d.append(td-1)
        q.append(tq-1)

    L_ALL = [[0]*26 for _ in range(D)]
    L = [0]*26
    ans = 0
    for i in range(D):
        ans += S[i][SELECT[i]]
        L[SELECT[i]]=i+1
        if i != 0:
            L_ALL[i] = L_ALL[i-1][:]
        L_ALL[i][SELECT[i]] = i+1
        for j in range(26):
            ans -= C[j]*(i+1-L[j])

    for i in range(M):
        day = d[i]
        before = SELECT[day]
        after = q[i]
        ans -= S[day][before]
        ans += S[day][after]
        SELECT[day] = q[i]

        if day == 0:
            tmp = 0
        else:
            tmp = L_ALL[day-1][before]
        j = day
        while 0<=j<D and L_ALL[j][before]==day+1:
            L_ALL[j][before] = tmp
            ans -= C[before]*(day+1-tmp)
            j += 1

        if day == 0:
            tmp = 0
        else:
            tmp = L_ALL[day-1][after]
        j = day
        while 0<=j<D and L_ALL[j][after]==tmp:
            L_ALL[j][after]=day+1
            ans += C[after] * (day+1-tmp)
            j += 1

        print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 11956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define push_back pb
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> A(N);
	rep(i,N)cin>>A[i];
	sort(all(A));
	vector<int> cnt(N);
	rep(i,N)cnt[A[i]]++;
	bool f = true;
	if(N%2 == 1){
		if(cnt[0] !=1)f = false;
		for (int i = 1; 2*i < N; ++i){
			if(cnt[2*i] !=2)f = false;
		}
	}
	else{
		for (int i = 0; 2*i+1 < N; ++i){
			if(cnt[2*i+1]!=2)f = false;
		}
	}
	int ans = 0;
	if(f){
	ans = 1;
	for (int i = 0; i < N/2; ++i){
				ans*=2;
				ans%=MOD;
			}		
	}
	print(cnt);
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
import math
import collections
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    maxv = n*(n-1)//2
    a = [list(map(int, input().split())) for i in range(n)]
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1

    v = 0  # 頂点数
    # 頂点にIDをふる
    Id = [[-1 for i in range(n)] for j in range(n)]
    for i in range(n):
        for j in range(n):
            if i < j:  # 1-3 ,2-4など　3-1はダメ
                Id[i][j] = v
                v += 1

    def toId(i, j):
        if i > j:
            i, j = j, i
        return Id[i][j]

    # 頂点間の辺を貼る
    e = [[] for i in range(maxv)]
    for i in range(n):
        for j in range(n - 1):
            a[i][j] = toId(i, a[i][j])
        for j in range(n - 2):
            e[a[i][j + 1]].append(a[i][j])

    # トポロジカルソート
    calculated = [False for i in range(maxv)]
    dp = [-1 for i in range(maxv)]

    def dfs(v):
        if dp[v] != -1:  # サイクル検知
            if not calculated[v]:
                return -1
            return dp[v]
        dp[v] = 1
        for u in e[v]:
            ret = dfs(u)
            if ret == -1:
                return -1
            dp[v] = max(dp[v], ret + 1)
        calculated[v] = True
        return dp[v]

    ans = 0
    for i in range(v):
        ret = dfs(i)
        if ret == -1:  # detected cycle
            print(-1)
            exit()
        ans = max(ans, ret)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 214948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

string s, t;

int main()
{
    int N, M, ans = 0;
    cin >> N >> M;
    vector<int> imos(N + 5);
    for (int i = 0; i < M; i++)
    {
        int L, R;
        cin >> L >> R;
        imos[L]++, imos[R + 1]--;
    }
    for (int i = 0; i < N; i++)
    {
        imos[i + 1] += imos[i];
        if (imos[i + 1] == M)
            ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

void dfs(int pos, int n, int m, int q, ll &ans, vector<vector<int>> &req, vector<int> &buf) {
    if (pos == n) {
        ll sum = 0; 
        for (int i = 0; i < q; i++) {
            if (buf[req[i][1] - 1] - buf[req[i][0] - 1] == req[i][2]) {
                sum += req[i][3];
            }
        }
        ans = max(ans, sum);
    }
    else {
        for (int j = 1; j <= m; j++) {
            buf[pos] = j;
            if (pos > 0 && buf[pos] < buf [pos - 1]) continue;
            dfs(pos + 1, n, m, q, ans, req, buf);
        }
    }
}



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

    vector<vector<int>> req(q, vector<int> (4));

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < 4; j++) {
            cin >> req[i][j];
        }
    }

    ll ans = 0;
    vector<int> buf(n);
    dfs(0, n, m, q, ans, req, buf);

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> o_tree;

ld dist(ll x,ll y)
{
    ld res = x*x+y*y;
    res=sqrt(res);
    return res;
}

void solve()
{
    ll n;ld d;
    cin >> n >> d;
    ll res = 0;
    ll i;
    for (i = 0; i < n; i++)
    {
        ll x,y;
        cin>>x>>y;
        ld dis = dist(x,y);
        if(dis<=d)
        {
            res++;
        }
    }
    cout<<res<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    cout << setprecision(20);

    ll t = 1;

    // cin>>t;

    while (t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3768