akhauriyash/Code-Regression huggingface dataset:
a,b,c,k=list(map(int,input().split()))
c=c*(-1)
sum=a
if sum>=k:
    print(k)
elif sum<k:
    if sum+b>=k:
        print(sum)
    elif sum+b<k:
        if sum+b+c==k:
            print(sum-c)
        else:
            num=0
            num=k-a-b
            print(sum-num)

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

using namespace std;

int LcsLen(string &s, string &t, vector<vector<int>> &memo, int i, int j) {
  if (i < 0 || j < 0) {
    return 0;
  }

  if (memo[i][j] < 0) {
    if (s[i] == t[j]) {
      memo[i][j] = LcsLen(s, t, memo, i - 1, j - 1) + 1;
    } else {
      memo[i][j] =
          max(LcsLen(s, t, memo, i - 1, j), LcsLen(s, t, memo, i, j - 1));
    }
  }

  return memo[i][j];
}

string Lcs(string &s, string &t, vector<vector<int>> &memo, int i, int j) {
  if (i < 0 || j < 0) {
    return "";
  }

  if (s[i] == t[j]) {
    return Lcs(s, t, memo, i - 1, j - 1) + s[i];
  }

  if (LcsLen(s, t, memo, i, j - 1) < LcsLen(s, t, memo, i - 1, j)) {
    return Lcs(s, t, memo, i - 1, j);
  } else {
    return Lcs(s, t, memo, i, j - 1);
  }
}

int main(int argc, char *argv[]) {
  string s, t;
  cin >> s >> t;
  vector<vector<int>> memo(s.size(), vector<int>(t.size(), -1));
  cout << Lcs(s, t, memo, s.size() - 1, t.size() - 1) << '\n';
  return 0;
}

Measured memory_bytes: 35968
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s, t; cin >> s >> t;
    int A, B; cin >> A >> B;
    string U; cin >> U;
    if (s == U)
        A--;
    if (t == U)
        B--;
    cout << A << ' ' << B << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=200005;
ll sum[maxn],a[maxn];
ll n,b,c,d,e;
ll ans=1e15+7;
bool check(ll x,ll y,int i)
{
    if(abs((x+a[i])-(y-a[i]))<abs(x-y))
    return 1;
    return 0;
}
int main()
{
    cin>>n;
    ll s=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
        sum[i]=s;
    }
    int j=0,k=2;
    for(int i=1;i<n-2;i++)
    {
        b=sum[j];
        c=sum[i]-sum[j];
        d=sum[k]-sum[i];
        e=sum[n-1]-sum[k];
        while(check(b,c,j+1) && j+1<i)
        {
            j++;
            b=sum[j];
            c=sum[i]-sum[j];
        }
        while(check(d,e,k+1) && k+1<n-1)
        {
            k++;
            d=sum[k]-sum[i];
            e=sum[n-1]-sum[k];
        }
        ans=min(ans,std::max({b,c,d,e})-std::min({b,c,d,e}));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    print(N-K+1);
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int x;
	int y;
} data;

int  main()
{
	string s;
	cin >> s;
	vector<string> d;
	int i = 0;
	while (i < s.size())
	{
		if (s[i] == s[i + 1])
		{
			if (d.empty())
			{
				d.push_back(s.substr(i, 1));
			}
			else if (s.substr(i, 1) != d[d.size() - 1] )
			{
				d.push_back(s.substr(i,1));
			}
			else
			{
				d.push_back(s.substr(1, 2));
				i++;
			}
		}
		else if (s[i] != s[i + 1])
		{
			if (d.empty())
			{
				d.push_back(s.substr(i, 1));
			}
			else if (s.substr(i, 1) != d[d.size() - 1] )
			{
				d.push_back(s.substr(i,1));
			}
			else if (s[i + 1] != '\0')
			{
				d.push_back(s.substr(1, 2));
				i++;
			}
		}
		i++;
	}

	cout << d.size() << endl;
	return (0);
}


Measured memory_bytes: 10996
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f(i,n) for(ll i=0;i<n;i++)
#define fi(i,j,n) for(ll i=j;i<=n;i++)
#define fr(i,n) for(ll i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF LLONG_MAX
#define ALL(a) a.begin(),a.end()
#define MAX 2005

int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int x=n%10;
        if(x==2 || x==4 || x==5 || x==7 || x==9)
        cout<<"hon";
        else if(x==0 || x==1 ||x==6 ||x==8)
        cout<<"pon";
        else
        cout<<"bon";
    }
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
typedef unsigned long long ll;
constexpr ll MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  vector<double> v(N);
  for(int i = 0; i < N; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double result = 0;
  for(int i = 0; i < v.size()-1; i++){
    v[i+1] = (v[i] + v[i + 1])/2;
  }
  cout << v[v.size()-1] << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = []
(1..2).each do |i|
    a.push(gets.chomp.split(" ").map(&:to_i))
end

max = 0
(0..n-1).each do |i|
    top = a[0][0..i].inject(:+)
    btm = a[1][i..n-1].inject(:+)
    max = top + btm if max < (top + btm)
end

puts max

Measured memory_bytes: 1788
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

int cnt[10000];
int int_map[100][100];
int main() {
	cin >> H >> W >> N;
	rep(i, N) {
		cin >> cnt[i];
	}
	int index = 0;
	rep(i, H) {
		int j = (i % 2 == 0 ? 0 : W - 1);
		for (;;) {
			if ((i % 2 == 0 && j == W) || (i % 2 == 1 && j == -1)) break;
			int_map[i][j] = (index + 1);
			cnt[index]--;
			if (cnt[index] == 0) index++;
			j += (i % 2 == 0 ? 1 : -1);
		}
	}

	rep(i, H) {
		rep(j, W) {
			cout << int_map[i][j] << " ";
		}
        cout << endl;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
int main() {
    cin >> n;
    map<string, int> mp;

    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        mp[s]++;
    }

    cout << mp.size() << endl;
}

Measured memory_bytes: 19116
#include<bits/stdc++.h>
const int md = 1e9+7;
int n[2], k;
long long a = 1, b = 1, ans;

int main(){
    scanf("%d%d%d", n, n+1, &k);
    for(int i = 1; i <= k-2; i++){
        a = a * (n[0] * n[1] - 1 - i) % md;
        b = b * i % md;
    }
    for(int i = md-2; i; i/=2){
        if(i&1) a = a * b % md;
        b = b * b % md;
    }
    for(int i = 0; i < 2; i++){
        b = a * n[i] % md * n[i] % md;
        for(int j = 1; j < n[i^1]; j++) ans += b * j % md * (n[i^1]-j) % md;
    }
    printf("%lld\n", ans % md);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,T,A;
  cin>>N>>T>>A;
  
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  
  vector<double> ave(N);
  for(int i=0;i<N;i++){
    ave[i]=abs(A-(T-H[i]*0.006));
  }
  
  double mini=100000;
  
  
  for(int i=0;i<N;i++){
    mini=min(ave[i],mini);
  }
  
  for(int i=0;i<N;i++){
    if(mini==ave[i]){
      cout<<i+1<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
	FastIO
	lld n, i;
	cin >> n;
	dbl A[n];
	foi(i,n){
		cin >> A[i];
	}
		sort(A,A+n);
	dbl s = 0;
	s = (A[0]+A[1])/2;
	for(i = 2; i < n; i++){
		s = ((A[i]+s)/2);
	}
	cout << fixed << setprecision(12) << s;
	return 0;
}

Measured memory_bytes: 256
declare function require(x: string): any;

    const main = (input: string[][]) => {
        const s: string[] = input[1];
        if (s.every((c) => c != 'Y')) {
            console.log('Three');
        } else {
            console.log('Four');
        }
    };

const whole_input: string = require('fs').readFileSync('/dev/stdin', 'utf8');
main(whole_input.split('\n').map((s: string) => s.split(' ')));


Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <deque>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

#define int long long

const int inf = 2e9;
const int N = 2e5 + 15;
int n, a[N], b[N], ans;
priority_queue <pll> q;

#undef int

int main() {
	#define int long long
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> a[i];
	for(int i = 0; i < n; ++i) {
		cin >> b[i];
		if(b[i] > a[i])
			q.push({b[i], i});
	}
	while(!q.empty()) {
		int i = q.top().se;
		q.pop();
		int prev = (i - 1 + n) % n;
		int next = (i + 1) % n;
		if(b[i] < b[prev] + b[next]) {
			puts("-1");
			return 0;
		}
		if(a[i] >= (b[prev] + b[next])) {
			if((b[i] - a[i]) % (b[prev] + b[next])) {
				puts("-1");
				return 0;
			}
			ans += (b[i] - a[i]) / (b[prev] + b[next]);
			b[i] = a[i];
			continue;
		}
		else {
			ans += b[i] / (b[prev] + b[next]);
			b[i] %= (b[prev] + b[next]);
			if(b[i] < a[i]) {
				puts("-1");
				return 0;
			}
			if(b[i] > a[i])
				q.push({b[i], i});
		}
	}
	for(int i = 0; i < n; ++i) {
		if(a[i] != b[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8816
#include <iostream>
std::string str_repeat(char c, int n)
{
  std::string str = "";
  while (n--) {
    str += c;
  }
  return str;
}

int main(void)
{
  int h, w;
  while (std::cin >> h >> w) {
    if (h == 0 && w == 0) break;
    h -= 2;
    std::cout << str_repeat('#', w) << std::endl;
    while (h--) {
      std::cout << "#" << str_repeat('.', w - 2) << "#" << std::endl;
    }
    std::cout << str_repeat('#', w) << std::endl << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1216
# coding: utf-8
# Your code here!

import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*p = map(int,read().split())
N = n*n

dist = [0]*N

for a in range(n):
    for b in range(n):
        dist[a*n+b] = min(a,n-1-a,b,n-1-b)

#print(dist)


#ans = [0]*N
ans = 0
iru = [1]*N

for pi in p:
    pi -= 1

    ans += dist[pi]
    iru[pi] = 0

    q = [pi]
    #更新
    
    while q:
        #print(q)
        v = q.pop()
        for i in [-n,-1,1,n]:
            if i==1 and v%n==n-1: continue
            if i==-1 and v%n==0: continue
            nv = v+i
            if 0 <= nv < N and dist[nv] > dist[v] + iru[v]:
                q.append(nv)
                dist[nv] = dist[v] + iru[v]
        
                    
    #print(dist)        

print(ans)









Measured memory_bytes: 163232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, d,flag = 0;
    cin >> a >> b >> c >> d;
    while(a > 0)
    {
        c = c -b;
        if(c <= 0)
        {
            flag = 1;
            break;
        }
        a = a - d;
    }
    if(flag == 1)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 3624
/*
AizuOnline A2440
Title kagi sys
8/6 WA 13/51
*/
#include <stdio.h>
#include <string.h>
//Global data section
int M,N;
char msg[256][11];
char input[11];
//
main()
{
        int i,j,ff;

        ff=0;

        scanf("%d",&M);
        memset(&msg[0][0],'\0',256*11);
        for(i=0;i<M;i++)
                scanf("%s",&msg[i][0]);

        scanf("%d",&N);
        for(i=0;i<N;i++)
        {
                memset(input,'\0',11);
                scanf("%s",&input[0]);
                for(j=0;j<M;j++)
                        if(0==strcmp(&msg[j][0],input))
                        {
                                ff=1-ff;
                                printf("%s %s\n",ff?"Opened by":"Closed by",input);
                                goto END;
                        }
                printf("Unknown %s\n",input);
        END:
                ;
        }




return(0);
}

Measured memory_bytes: 604
package main

import (
	"fmt"
	"io"
	"os"
)

func answer(reader io.Reader, writer io.Writer) {
	var s string
	_, _ = fmt.Fscan(reader, &s)
	c:=0
	for i:=0; i<len(s); i++ {
		if string(s[i]) == "x" {
			c++
		}
	}
	if c <= 7 {
		_, _ = fmt.Fprint(writer,"YES")
	} else {
		_, _ = fmt.Fprint(writer,"NO")
	}
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int W = in.nextInt();
        int w[] = new int[N];
        int v[] = new int[N];
        for(int i=0;i<N;i++){
            w[i] = in.nextInt();
            v[i] = in.nextInt();
        }
        in.close();
        long dp[][] = new long[N+1][W+1];
        for(int i=0;i<W+1;i++){
            dp[N][i] = 0;
        }
        for(int i=N-1;i>=0;i--){
            for(int j=0;j<W+1;j++){
                if(j < w[i]){
                    dp[i][j] = dp[i+1][j];
                }
                else{
                    dp[i][j] = Math.max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
                }
            }
        }
        System.out.println(dp[0][W]);
    }
}

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

const int mx = 1e7;
bitset <mx> mark;
vector <int> primes;

void sieve() {
    mark[0] = mark[1] = 1;
    primes.push_back(2);
    int lim = sqrt(mx * 1.0) + 2;
    for (int i = 4; i < mx; i += 2) mark[i] = 1;
    for (int i = 3; i < mx; i += 2) {
        if (!mark[i]) {
            primes.push_back(i);
            if (i <= lim)
                for (int j = i * i; j < mx; j += i)
                    mark[j] = 1;
        }
    }
}


int main() {
    sieve();
    ll n; cin >> n;
    ll a[n + 2];
    ll g = 0;
    for(ll i = 0; i < n; i++) {
            cin >> a[i];
            g = __gcd(g, a[i]);

    }

    map<ll, ll>m;

    for(ll i = 0; i < n; i++) {
        for(auto p : primes) {
            if(p * p > a[i]) break;

            if(a[i] % p == 0) {
                m[p]++;
                while(a[i] % p == 0) {
                    a[i] = a[i] / p;
                }
            }
        }

        if(a[i] > 1) m[a[i]]++;
    }
    bool nafisa = true;

    for(auto p : m) {
        ll d = p.second;
        if(d > 1) {
            nafisa = false;
            break;
        }
    }

    if(nafisa) {
         cout << "pairwise coprime" << endl;
        return 0;
    }

    if(g == 1) {
         cout << "setwise coprime" << endl;
        return 0;
    }
    else {
            cout << "not coprime" << endl;
            return 0;
    }

    return 0;
}




Measured memory_bytes: 19620
#include <iostream>
#include <string>

using namespace std;

int main(){
  bool flag = true;
  string s;
  cin >> s;
  
  for(int i = 1; i < s.size(); i++)
    if(s[i] == s[i - 1])
      flag = false;
  
  if(flag)
    cout << "Good" << endl;
  else
    cout << "Bad" << endl;
  
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  string s;
  cin >> s;
  cout << (s[0] == s[2] ? "Yes" : "No");
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>

using namespace std;

int main() {
	string date;
	//int dates = 0;

	cin >> date;

	//dates = (int)date[0] * 10000000 + (int)date[1] * 1000000 + (int)date[2] * 100000 + (int)date[3] * 10000 + (int)date[5] * 1000 + (int)date[6] * 100 + (int)date[8] * 10 + (int)date[9];

	//for (int i=0;i<11;i++)	cout << date[i] << endl;
	
	//date.erase(date.begin() + 5);
	date.erase(date.end() - 3);
	date.erase(date.end() - 5);

	//cout << date << endl;

	if (atoi(date.c_str()) > 20190430) cout << "TBD" << endl;
	else cout << "Heisei" << endl;

	return 0;
}

Measured memory_bytes: 256
//noob
#include<bits/stdc++.h>
using namespace std;
#define fori(x) for(int i=0;i<x;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long int 
#define ld long double
#define ull unsigned long long int
#define pi acos(-1)
#define test() int T,t=1;cin>>T;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int(x.size()))
#define mod 1000000007
typedef vector<int> vi;
typedef pair<int,int> PI;
const int N = (int)1e6 + 7;

ll power(ll a, int b){
	ll k=1;
	for(int i=0;i<b;i++) k=(k*a)%mod;
	return k;
}
void solve()
{
	int n;cin>>n;
	ll a=power(9,n);
	ll ans=(power(10,n)-a-a+power(8,n))%mod;
	cout<<(ans+mod)%mod<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	//freopen("input.txt","r",stdin);
solve();
	return 0;
}

Measured memory_bytes: 3636
def main():
    mod=1000000007
    x,y=map(int,input().split())
    if (x+y)%3:
        return 0
    
    n=(x+y)//3
    Fact=[1]
    for i in range(1,n+1):
        Fact.append(Fact[i-1]*i%mod)
    Finv=[0]*(n+1)
    Finv[-1]=pow(Fact[-1],mod-2,mod)
    for i in range(n-1,-1,-1):
        Finv[i]=Finv[i+1]*(i+1)%mod
    def comb(n,r):
        if n<r:
            return 0
        return Fact[n]*Finv[r]*Finv[n-r]%mod
    
    a=(-x+2*y)//3
    b=(x*2-y)//3
    if a<0 or b<0:
        return 0
    return comb(a+b,a)
    
if __name__=='__main__':
    print(main())

Measured memory_bytes: 91504
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
    	int h,w,k,res=0;
    	cin>>h>>w>>k;
    	vector<vector<char> > v(h,vector<char>(w));
    	for(int i=0;i<h;i++)
    	{
    		for(int j=0;j<w;j++)
    		cin>>v[i][j];
    	}
    	for(int maskR=0;maskR<=(1<<h)-1;maskR++)
    	{
    		for(int maskC=0;maskC<=(1<<w)-1;maskC++)
    		{
    			int black=0;
    			for(int i=0;i<h;i++)
    			{
    				for(int j=0;j<w;j++)
    				if((maskR&(1<<i))==0&&(maskC&(1<<j))==0&&v[i][j]=='#') black++;
    			}
    			if(black==k) res++;
    		}
    	}
    	cout<<res<<endl;
    	return 0;
    }


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

int main()
{
  int64_t N, s = 0;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    s = s ^ A[i];
  }
  for (int i = 0; i < N; i++)
  {
    cout << (A[i] ^ s);
    if (i != N - 1)
      cout << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 4820
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();
 
        if(a < b && b < c){
            System.out.printf("Yes\n");
        }else{
            System.out.printf("No\n");
        }
    }
}


Measured memory_bytes: 26328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    ll n,a,b,ans = 0;
    cin >> n >> a >> b;
    vector<ll> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < n-1; ++i) {
        ans += min(a*(x[i+1]-x[i]),b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <list>
#include <vector>

using namespace std;

#define MIN(x, y) x<y?x:y

int main()
{
	int a, b, k;

	cin>>k>>a>>b;

	int x = b/k;

	if(x*k>=a){
		cout<<"OK"<<endl;
	} else {
		cout<<"NG"<<endl;
	}

	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

struct Tm
{
	int point;
	string name;
	Tm(string s, int p){name=s;point=p;}
	bool operator<(const Tm &t) const
	{
		return point>t.point;
	}
};

int main()
{
	bool f=false;
	int n,a,b,c;
	string str;

	while(cin >> n, n)
	{
		if(f) cout << endl; f=true;

		vector<Tm> v;
		while(n--)
		{
			cin >> str >> a >> b >> c;
			v.push_back(Tm(str,a*3+c));
		}
		stable_sort(v.begin(), v.end());

		for(int i=0; i<v.size(); i++)
		{
			cout << v[i].name << "," << v[i].point << endl;
		}
	}
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}


int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int sum = 0;
	REP(i, a + 1)REP(j, b + 1)REP(k, c + 1) {
		if (500 * i + 100 * j + 50 * k == x)sum++;
	}

	cout << sum << endl;
}



Measured memory_bytes: 256
/*
  filename:A2912.c
*/
#include<stdio.h>


int p[10],e[10];
int nc3table[]={1,4,10,20,35,56,84,120,165,220,286,364};

int factorize(int v)
{
  int a=v,i,j,k;
  k=0;
  for(j=2; j<=v/2 && 1<a; j+=1+(j&1))
    {for(i=0;a%j==0;i++)
	a/=j;
      if(i)
	{ p[k]=j;
	  e[k]=i;
	  k++;
	}
    }
  return k;
}

int main()
{
  int i,n,n2,c,ret;

  scanf("%d",&n);
  c=factorize(n);
  //for(i=0;i<c;i++)
  //  printf("%d^%d\n",p[i],e[i]);
  
  if(c==0)
    { 
    if(n==1)
      ret=1;
    else
      ret=4;
    }
  else if(p[0]==2)
    {
      ret = e[0]+1;
      for(i=1;i<c;i++)
	ret *= nc3table[e[i]];
    }
  else
    {
      ret=1; 
      for(i=0;i<c;i++) 
	ret *= nc3table[e[i]];
    }  
  printf("%d\n",ret);
  return 0;
}



Measured memory_bytes: 2064
N,M=map(int,input().split())
X=[int(i) for i in input().split()]
X.sort()
count=[]
sum=0
if N<M:
  for i in range(M):
    if i != 0:
      count.append(X[i]-get)
      sum+=count[i-1]
    get=X[i]
  count.sort(reverse=True)
  if count != []:
    for i in range(N-1):
      sum-=count[i]
print(sum)

Measured memory_bytes: 13832
n = int(input())
w = [input() for _ in range(n)]

if len(w) != len(set(w)):
    print('No')
    quit()
check = [w[0]]
siri = w[0][-1]
for i in range(1,n):
    if w[i][0] == siri:
        check.append(w[i])
        siri = w[i][-1]
    else:
        print('No')
        quit()
print('Yes')

Measured memory_bytes: 3064
#-*- coding:utf-8 -*-
N = int(input())

def lucas(M):
    a = 2
    b = 1
    
    if M > 1:
        for x in range(N-1):
            a,b = b,a+b
        return b
    elif M == 1:
        return 1
    elif M == 0:
        return 2 

print(lucas(N))

Measured memory_bytes: 2940
import math
X = int(input())
for i in range(X, 2*X):
  frag = False
  for j in range(2, math.ceil(math.sqrt(i))):
    if i % j != 0:
      continue
    else:
      break
  else:
    print(i)
    frag = True
  if frag:
    break

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

int main(){
  long long x, y;
  cin >> x >> y;

  long long prevAi = x;
  int cnt = 1;

  while(prevAi * 2 <= y) {
    prevAi *= 2;
    cnt++;
  }

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


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
  S = input().strip()
  s, t = int(S[:2]), int(S[2:])
  
  s_mm = (1 <= s <= 12)
  t_mm = (1 <= t <= 12)
  
  mapping = {
    (True, True): 'AMBIGUOUS',
    (True, False): 'MMYY',
    (False, True): 'YYMM',
    (False, False): 'NA'
  }
  
  print(mapping[(s_mm, t_mm)])



if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <stdio.h>

int H, W;
int N;
int a[114514];

int data[128][128];

int main(void) {
	int i, j;
	int x, y, dx, dy;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
	}
	for (i = 0; i <= W + 1; i++) {
		data[0][i] = data[H + 1][i] = 1;
	}
	for (i = 1; i <= H; i++) {
		data[i][0] = data[i][W + 1] = 1;
	}
	x = 0; y = 1; dx = 1; dy = 0;
	for (i = 0; i < N; i++) {
		for (j = 0; j < a[i]; j++) {
			if (data[y + dy][x + dx] != 0) {
				int t = dx;
				dx = -dy;
				dy = t;
			}
			x += dx;
			y += dy;
			data[y][x] = i + 1;
		}
	}
	for (i = 1; i <= H; i++) {
		printf("%d", data[i][1]);
		for (j = 2; j <= W; j++) printf(" %d", data[i][j]);
		putchar('\n');
	}
	return 0;
}


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

using namespace std;

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	int a,b;cin>>a>>b;

	cout << (a+b==0 ? 0 : a+b<0 ? -1 : 1) << endl;
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int n, s; std::cin >> n >> s;
  std::vector<int> A(n); rep(i,n) std::cin >> A[i];

  constexpr ll mod = 998244353;
  ll ans = 0;
  std::vector<int> f(3010, 0);
  rep(i,n) {
    f[0] += 1;  f[0] %= mod;
    auto d = f;
    rep(j,3010) {
      if ( j+A[i] > 3005 ) continue;
      f[j+A[i]] += d[j];
      f[j+A[i]] %= mod;
    }
    //std::cout << i << " : ";
    //rep(j,11) std::cout << f[j] << " ";
    //std::cout << std::endl;
    ans += f[s];
    ans %= mod;
  }
  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 300000+5
#define ll long long
using namespace std;
ll n,A[N],ans;
int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=3*n;i++) scanf("%lld",&A[i]);
	sort(A+1,A+1+3*n);
	for(ll i=(3*n)-1;i>=n+1;i-=2) ans += A[i];
	printf("%lld",ans);
	return 0;
}

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

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    // 場合分け
    /*int m = min(x, y);
    x -= m, y -= m;

    int ans = min(2 * m * c, m * (a + b));

    ans += min(x * a, 2 * c * x) + min(y * b, 2 * c * y);

    cout << ans << '\n';
    */

    // 全探索
    // 1. ２個セットを何個購入するかを探索
    // 2. 足りない分をA,Bで補う
    int ans = a * x + b * y;
    for(int i = 1; i <= 100000; i++) {
       ans = min(ans, i*2*c + a*max(0, x - i) + b*max(0, y - i)); 
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int sum = 0;
	for(int i = 0; i < 5; ++i){
		int score;
		cin >> score;
		if(score < 40)
			score = 40;
		sum += score;
	}
	
	cout << sum / 5 << endl;
		
	return 0;
}

Measured memory_bytes: 1192
import sys
N=int(sys.stdin.readline().strip())
cnt=0
for _ in range(N):
    d1,d2=map(int, sys.stdin.readline().split())
    if d1==d2:
        cnt+=1
    elif d1!=d2:
        cnt=0
    if cnt==3:
        print "Yes"
        quit()
else:
    print "No"


Measured memory_bytes: 64568
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>
//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long int;
//// 任意長整数型
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;



int main(int argc, char *argv[])
{
	string s,t;
	//input
	cin >> s;
	cin >> t;


	//calc
	int ans = 0;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] != t[i]){
			ans++;
		}
	}


	//ans
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3920
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(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;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll r;
    cin>>r;
    double pi=acos(-1);
    cout<<fixed<<setprecision(15);
    cout<<2*pi*r;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<pair<int, int> > p;
    rep (i, n) {
        int x;
        cin >> x;
        p.emplace_back(x, i);
    }
    sort(p.begin(), p.end());
    int maxi = 0;
    int s = 0, t = 0;
    rep (i, n) {
        int pos = i;
        while (p[i].second < p[i + 1].second) i++;
        maxi = max(maxi, i - pos + 1);
    } 
    cout << n - maxi << endl;
    
    return 0;
}



Measured memory_bytes: 2420
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, end) for (int i = begin; i > end; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int A[101010];
vector<int> b;

int main()
{
    cin >> N;
    rep(i, 0, N)
    {
        cin >> A[i];
    }

    b.push_back(A[N - 1]);
    repre(i, N - 2, 0)
    {
        if (b[b.size() - 1] <= A[i])
        {
            b.push_back(A[i]);
        }
        auto ub = upper_bound(b.begin(), b.end(), A[i]);
        *ub = A[i];
    }

    cout << b.size() << endl;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    ll n, k;
    cin >> n >> k;
    cout << (n - 2) / (k - 1) + 1 << "\n";
    return 0;
}

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

int main(){
	int a, b;
	double x;

	cin >> a >> b;

	x = (double)a / b;
	cout << a / b << " " << a % b << " " << fixed << setprecision(6) << x << endl;

	return 0;
}

Measured memory_bytes: 1244
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int inf=1e9;
const ll INF=1e18;
const double pi=3.1415926535897932384626433832;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,t,ans=1;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> t;
    ans=ans/__gcd(ans,t)*t;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
"use strict"

function Main(input) {
  input = input.split('\n');
  let N = parseInt(input.shift());
  let array = input.map(str => str.split(/\s/).map(value => value - 0));
  let result = 0;
  for (let i=0;i<N;i++){
    let tmp = array[0][i] - array[1][i];
    if(tmp > 0){
      result += tmp;
    }
  }
  console.log(result)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
/*
ID: arthurc4
TASK: test
LANG: C++11
*/

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<bool> vb;
typedef vector<vb> vvb;

typedef map<string,int> msi;
typedef map<int,int> mii;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll; // note 'single' ls

typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)

#define REPb(j, d, c) \
for (int j = int(d); j >= int(c); j--)

#define pb \
push_back

#define ff \
first

#define ss \
second

// LL OR INT ???
// DELETED IFSTREAM ???
int main()
{
	//ifstream cin("input.txt");
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	int N;
	cin >> N;

	bool is_odd = false;

	REP(i, 1, N)
	{
		int a;
		cin >> a;

		if(a%2 == 1) is_odd = true;
	}

	if(is_odd) cout << "first" << endl;
	else cout << "second" << endl;

	return 0;
}

Measured memory_bytes: 256
N = gets.to_i

A = gets.split(' ')
A.map!{|x| x.to_i}

B = gets.split(' ')
B.map!{|x| x.to_i}

C = gets.split(' ')
C.map!{|x| x.to_i}

sum = 0

N.times do |i|
  sum += B[A[i]-1]
  sum += C[A[i-1]-1] if i>0 && A[i-1]+1 == A[i]
end

p sum


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 1e3+7;

char s[N][N];
int vis[N][N];
int d[4][2] = {1,0,-1,0,0,1,0,-1};
int n,m,cx,cy,a,b;
queue<PII> Q , q;

void bfs2(int x,int y){
	q.push({x,y});
	while(!q.empty()){
		PII t = q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int xx = t.F + d[i][0];
			int yy = t.S + d[i][1];
			if(xx>=0&&xx<n&&yy>=0&&yy<m&&vis[xx][yy]==-1){
				if(s[xx][yy]=='.'){
					vis[xx][yy] = vis[t.first ][t.second ];
					q.push({xx,yy});
					Q.push({xx,yy});
				}
			}
		}
	}
}

void bfs(int x,int y){
	Q.push({x,y});
	vis[x][y]=0;
	while(!Q.empty()){
		PII t = Q.front();
		Q.pop();
		bfs2(t.first ,t.second);
		for(int i=-2;i<=2;i++){
			for(int j=-2;j<=2;j++){
				int xx = t.first + i,yy = t.second + j;
				if(xx>=0&&xx<n&&yy>=0&&yy<m&&vis[xx][yy]==-1){
					if(s[xx][yy]=='.'){
						vis[xx][yy] = vis[t.first ][t.second ] + 1;
						Q.push({xx,yy});
						q.push({xx,yy});
					}
				}
			}
		}
	}
}

int main()
{
	cin>>n>>m>>cx>>cy>>a>>b;
	cx--,cy--,a--,b--;
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	memset(vis,-1,sizeof vis);
	bfs(cx,cy);
	
//	for(int i=0;i<n;i++){
//		for(int j=0;j<m;j++){
//			cout<<vis[i][j]<<" ";
//		}
//		cout<<"\n";
//	}
//	
	cout<<vis[a][b]<<"\n";
	return 0;
}


Measured memory_bytes: 8704
import java.io.*;
import java.util.*;
 
class Main {
 
    public static long solve(int[] weights, int[] val, int W, int i, long[][] memo){
        if(W <= 0 || i >= weights.length)
            return 0;

        if(memo[i][W] > -1)
            return memo[i][W];

        long ans = Integer.MIN_VALUE;

        ans = Math.max(ans,solve(weights, val, W, i+1, memo));
        if(W-weights[i] >= 0){
            ans = Math.max(ans,val[i] +  solve(weights, val, W-weights[i], i+1, memo));
        }

        return memo[i][W] =  ans;
        
 
    }
 
    public static void main(String[] args) throws Exception {
        BufferedReader br  =  new BufferedReader(new InputStreamReader(System.in));
        String[] nw = br.readLine().trim().split(" ");
        int n = Integer.parseInt(nw[0]);
        int W = Integer.parseInt(nw[1]);
        int weights[] = new int[n];
        int val[] = new int[n];
 
        for(int i  = 0; i < n; i++){
            String[] input = br.readLine().trim().split(" ");
 
            weights[i] = Integer.parseInt(input[0]);
            val[i] = Integer.parseInt(input[1]);
        }
 
        long[][] memo = new long[n+1][W+1];
        for(int i = 0; i < memo.length; i++)
            Arrays.fill(memo[i],-1);
        System.out.println(solve(weights,val,W,0,memo));
 
    }
}

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

const int MAX = 1000000;
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;
}

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

int main() {
    ll N;
    string S, C;
    cin >> N >> S;
    C = S;
    while (S.find("()") != S.npos) {
        S.erase(S.find("()"), 2);
    }
    if (S.length() == 0) {
        cout << C << endl;
        return 0;
    }
    if (S.find(")(") == S.npos) {
        if (S[0] == ')') {
            cout << string(S.length(), '(');
            cout << C << endl;
        } else {
            cout << C;
            cout << string(S.length(), ')') << endl;
        }
    } else {
        string left = S.substr(0, S.find(")(") + 1);
        string right = S.substr(S.find(")(") + 1);
        cout << string(left.length(), '(');
        cout << C;
        cout << string(right.length(), ')') << endl;
    }

    return 0;
}


Measured memory_bytes: 256
S = input()
for i in range((len(S) - 1) ** 2 - 1):
    ope = ['-'] * (len(S) - 1)
    for j in range(len(S) - 1):
        if ((i >> j) & 1):
            ope[2 - j] = '+' # j=0->ope[2], j=1->ope[1], j=2->ope[0]
    ans = ''
    ans += S[0]+ope[0]+S[1]+ope[1]+S[2]+ope[2]+S[3]
    if eval(ans) == 7:
        ans += '=7'
        break

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
    int N,K,P,a;
    scanf("%d",&N);
    for(a=1; a<=N; a++){
        scanf("%d %d",&K,&P);
        if(K%P==0)
        printf("%d\n",P);
        else
        printf("%d\n",K%P);
    }
    return 0;
}

Measured memory_bytes: 596
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int N;
ll W;
ll w[101], v[101];
ll dp[101][100001];

void solve()
{
    REP (i, N+1) REP (j, 100001) dp[i][j] = LINF;
    REP (i, N+1) dp[i][0] = 0;
    FOR (i, 1, N+1) {
        REP (j, 100001) {
                dp[i][j] = min(dp[i-1][j], (j-v[i] >= 0 ? dp[i-1][j-v[i]] : 0) + w[i]);
        }
    }
    REPR (i, 100000) {
        if (dp[N][i] <= W) {
            cout << i << endl;
            break;
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> W;
    FOR (i, 1, N+1) cin >> w[i] >> v[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

int main(){

    int n;
    cin >> n;

    vector<int> a(n);

    int fs=0;
    int os=0;
    int es=0;

    rep(i,n){
        cin >> a[i];
        if(a[i]%4==0){
            fs++;
        }else if(a[i]%2==1){
            os++;
        }else{
            es++;
        }
    }

    if(es%2==0){
        n-=es;
    }else{
        n-=(es-1);
    }

    if(n-fs<=fs+1){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}
int K;
vector<vector<int>> SW, SB;
int calc(vector<vector<int>> &S, int x, int y){
    return S[y][x] - S[y - K][x] - S[y][x - K] + S[y - K][x - K];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N >> K;
    vector<vector<int>> W(K * 4, vector<int>(K * 4, 0)), B(K * 4, vector<int>(K * 4, 0));
    rep(i, N){
        int x, y;
        char c;
        cin >> x >> y >> c;
        x %= K * 2, y %= K * 2;
        rep(h, 2) rep(w, 2){
                if(c == 'W') W[y + h * 2 * K][x + w * 2 * K]++;
                else B[y + h * 2 * K][x + w * 2 * K]++;
            
        }
    }
//    cout << "W" << endl;
//    rep(i, K * 4) voutput(W[i]);
//    cout << "B" << endl;
//    rep(i, K * 4) voutput(B[i]);
    
    SW.assign(K * 4 + 1, vector<int>(K * 4 + 1, 0)), SB.assign(K * 4 + 1, vector<int>(K * 4 + 1, 0));
    rep(y, K * 4) rep(x, K * 4) {
        SW[y + 1][x + 1] = W[y][x];
        SB[y + 1][x + 1] = B[y][x];
    }
    rep(y, K * 4 + 1) {
        rep(x, 1, K * 4 + 1){
            SW[y][x] += SW[y][x - 1];
            SB[y][x] += SB[y][x - 1];
        }
    }
    
    rep(x, K * 4 + 1) {
        rep(y, 1, K * 4 + 1) {
            SW[y][x] += SW[y - 1][x];
            SB[y][x] += SB[y - 1][x];
        }
    }
    
//    cout << "SW" << endl;
//    rep(i, K * 4 + 1) voutput(SW[i]);
//    cout << "SB" << endl;
//    rep(i, K * 4 + 1) voutput(SB[i]);
    int ans = 0;
    rep(y, 1, 2 * K + 1) rep(x, 1, 2 * K + 1){
//        cout << x << "," <<  y << endl;
        int b = calc(SB, x + K - 1, y + K - 1) + calc(SB, x + 2 * K - 1, y + 2 * K - 1);
        int w = calc(SW, x + K - 1, y + 2 * K - 1) + calc(SW, x + 2 * K - 1, y + K - 1);
        ans = max(b + w, ans);
    }
    output(ans);
    
    return 0;
}


Measured memory_bytes: 251008