akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int maxn = 1e6+5;


int main()
{
    ll n, a, b; cin >> n >> a >> b;
    if(a == 0) cout << 0 << endl;
    else {
        ll c = a+b;
        if(c >= n) cout << min(a, n) << endl;
        else {
            ll q = n/c;
            ll p = n-n/c*c;
            cout << q*a + min(p, a) << endl;
        }
    }
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;

int n,W;
long long ans=-1e18;
long long w[107],v[107];
const int Maxd=1e5+7;
const long long INF=1e15+7;
long long dp[Maxd*2];

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>W;
	REP(i,n)cin>>w[i]>>v[i];
	for(int i=0;i<=W;i++)dp[i]=-INF;
	dp[0]=0;
	REP(i,n)
		for(int j=W;j>=0;j--)
			dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
	for(int i=0;i<=W;i++)ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#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 vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}


int main()
{
	int n;
	cin >> n;
	vector<int>p(n);
	rep(i, n) {
		cin >> p[i];
	}
	int count = 0;
	rep(i, n) {
		if (i != 0 && i != n - 1) {
			if ((p[i] < p[i + 1] && p[i - 1] < p[i])or(p[i-1]>p[i]&&p[i]>p[i+1])) {
				count++;
			}
		}
	}
	cout << count << endl;
}


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

#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 ll long long

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n){cin >> a[i];}
	while (true) {
		ll min = *min_element(a.begin(), a.end());
		bool flag = true;
		REP(i, n){
			if (a[i]%min == 0){
				a[i] = min;
			} else {
				a[i] %= min; 
				flag = false;
			}
		}
		if (flag){
			cout << a[0] << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

int main(int argc, const char* argv[]) {
  u64 a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if(e - a > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  return 0;
}

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

int main()
{
    long long int i, j, k, n, gcd, sum=0;

    cin>>n;

    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            for(k=1; k<=n; k++)
            {
                gcd = __gcd(j,k);
                sum = sum + __gcd(i,gcd);
                //cout<<sum<<endl;
            }
        }
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
Int const INF = 1e9;

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

    Int a,b,c,d; cin>>a>>b>>c>>d;
    cout<<(b-b/c-b/d+b/(c*d/__gcd(c,d)))-((a-1)-(a-1)/c-(a-1)/d+(a-1)/(c*d/__gcd(c,d)))<<'\n';
}

Measured memory_bytes: 256
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if match-A[k][1] >= 0:
            if dp[match-A[k][1]] == keta-1:
                ans += str(A[k][0])
                match -= A[k][1]
                keta -= 1
                break
print(ans)

Measured memory_bytes: 3420
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 147483600

int k;

void solve(vector<char> &s, vector<int> &ans, string str){
  int n = s.size();
  if(n==0) return;
  for(auto c : str){
    vector<vector<int>> dp(n, vector<int>(k+1,-INF));
    dp[0][0] = (s[0]==c);
    dp[0][1] = (s[0]!=c);
    repl(i,1,n){
      dp[i][0] = dp[i-1][0] + (s[i]==c);
      repl(j,1,k+1){
        if(j%2==0) dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]) + (s[i]==c);
        else dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]) + (s[i]!=c);
      }
    }
    rep(i,k+1) ans[i] = max(ans[i], 2*dp[n-1][i]-n);
  }
}

int main(){
  string s;
  cin>>s>>k;

  vector<char> x,y;
  for(auto c: s){
    if(c=='R' || c=='L') x.pb(c);
    else y.pb(c);
  }

  vector<int> xx(k+1,0),yy(k+1,0);

  solve(x, xx, "RL");
  solve(y, yy, "UD");

  int ans = 0;
  rep(i,k+1) rep(j,k+1) if(i+j<=k) ans = max(ans, xx[i]+yy[j]);

  cout << ans << endl;

  return 0;
}

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

void merge(vector<pair<int,int>> left, vector<pair<int,int>> right, vector<pair<int,int>> &merged_a) {
    int i = 0, j = 0;
    while (i < left.size() || j < right.size()) {
        if ((i < left.size() && left[i].second <= right[j].second) || j == right.size()) {
            merged_a[i+j] = left[i];
            i++;
        } else {
            merged_a[i+j] = right[j];
            j++;
        }
    }
}

void merge_sort(vector<pair<int,int>> &a) {
    if (a.size() > 1) {
        int l_size = a.size() / 2;
        int r_size = a.size() - l_size;
        vector<pair<int,int>> left(l_size);
        vector<pair<int,int>> right(r_size);
        rep(i, l_size) {
            left[i] = a[i];
        }
        rep(i, r_size) {
            right[i] = a[l_size + i];
        }
        merge_sort(left);
        merge_sort(right);
        merge(left, right, a);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    vector<pair<int,int>> a(n+1);
    rep(i, n+1) {
        if (i == 0) continue;
        a[i].first = i;
        scanf("%d", &a[i].second);
    }
    merge_sort(a);
    rep(i, n+1) {
        if (i == 0) continue;
        printf("%d", a[i].first);
        if (i != n) printf(" ");
        else printf("\n");
    }
}

Measured memory_bytes: 6088
#include <stdio.h>

int main(void)
{
    long int N;
    long int sum = 0;
    scanf("%ld", &N);

    for(long int j = 0; j < N; j++){
        if((j + 1) % 3)
            if((j + 1) % 5)
                sum = sum + j + 1;
    }
    printf("%ld\n", sum);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    int n,m; cin>>n>>m;
    vector<set<int>> path(n);
    rep(i,0,m){
        int x,y; cin>>x>>y;
        x--; y--;
        path[x].insert(y);
        path[y].insert(x);
    }
    bool ok=false;
    for(auto &i:path[0]){
        if(path[i].count(n-1)) ok=true;
    }
    if(ok) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 28416
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str = sc.nextLine().split(" ",0);
		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long k = Long.parseLong(str[2]);
		sc.close();
		Main main = new Main();
		long[] ans_arr = new long[2];
		ans_arr = main.solve(a, b, k);
		System.out.println(ans_arr[0] +" "+ans_arr[1]);
	}

	public long[] solve(long a,long b,long k) {
		long[] ans = new long[2];
		if(k == 0) {
			ans[0] = a;
			ans[1] = b;
			return ans;
		}
		if (a >= k) {
			ans[0] = a - k;
			ans[1] = b;
			return ans;
		}else {
			ans[0] = 0;
			k = k - a;
			if (b >=k) {
				ans[1] = b-k;
				return ans;
			} else {
				ans[1] = 0;
				return ans;
			}
		}

	}
}

Measured memory_bytes: 23124
import sys
from collections import Counter
from itertools import combinations


def input(): return sys.stdin.readline().strip()


def solve(S):
    c = Counter(S)

    # 文字が3種類未満
    if len(c.keys()) < 3:
        return 0

    # 人数が3人未満
    if sum(c.values()) < 3:
        return 0

    ans = 0
    for i, j, k in combinations('MARCH', 3):
        ans += c[i] * c[j] * c[k]

    return ans


def main():
    N = int(input())
    S = [input()[0] for _ in range(N)]
    print(solve(S))


if __name__ == "__main__":
    main()


Measured memory_bytes: 4216
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n,a[N];

int main(){
    readi(n);
    lp(i,1,n) readi(a[i]);
    lp(i,1,n) readi(a[n+1]), a[i] -= a[n+1];

    ll can = 0;
    lp(i,1,n){
        if(a[i] < 0) can += -a[i] / 2;
        else can -= a[i];
    }

    if(can < 0) cout <<"No";
    else cout <<"Yes";
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int w = scanner.nextInt();
        int h = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int r = scanner.nextInt();

        if(0 <= x-r && 0 <= y-r && x+r<=w && y+r<=h)System.out.println("Yes");
        else System.out.println("No");
    }
}



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

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> h(n);
	for (ll i = 0; i < n; ++i)cin >> h[i];
	vector<ll> ans(n, 1);
	for (ll i = 0; i < m; ++i) {
		ll a, b;
		cin >> a >> b;
		--a; --b;
		if (h[a] <= h[b])ans[a] = 0;
		if (h[a] >= h[b])ans[b] = 0;
	}
	cout << accumulate(ans.begin(), ans.end(), 0ll) << endl;
}


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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M;
	cin >> N >> M;
	vector<vector<int>> G(N);
	for (int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v; --u, --v;
		G[u].push_back(v);
	}
	int s, t;
	cin >> s >> t; --s, --t;
	vector<vector<int>> dp(N, vector<int>(3, -1));
	queue<pair<int, int>> q;
	dp[s][0] = 0;
	q.emplace(s, 0);
	while (!q.empty()) {
		int id, r;
		tie(id, r) = q.front(); q.pop();
		int l = (r + 1) % 3;
		for (auto to : G[id]) if (dp[to][l] == -1) {
			dp[to][l] = dp[id][r] + 1;
			q.emplace(to, l);
		}
	}
	cout << (dp[t][0] == -1 ? -1 : dp[t][0] / 3) << endl;
	return 0;
}


Measured memory_bytes: 11264
n = gets.to_i
require 'prime'
a = n.prime_division
ans = 0
a.each do |i|
  y = i[1]
  x = (1..(10**6)).find{|k| k <= ((2*y.to_f)/(k+1)) && (k+2) > ((2*y.to_f)/(k+1))}
  ans += x
end
puts ans

Measured memory_bytes: 14476
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int n , k ;
    cin >> n >> k;

    long long int ans = k ;
    for(int i = 0 ; i < n -1 ; i++){
        ans = ans * (k-1) ;
    }

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

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
  int a,b;
  char op;
  int ans;
  
  scanf("%d %c %d", &a, &op, &b);
  while(op!='?'){
    switch(op){
    case '+': ans=a+b; break;
    case '-': ans=a-b; break;
    case '*': ans=a*b; break;
    case '/': ans=a/b; break;
    default: break;
    }
    printf("%d\n", ans);
    scanf("%d %c %d", &a, &op, &b);
  }
  return(0);
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
#define INF (ll)1e18
#define s(v) v.size()
#define e(v) v.empty()

using namespace std;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
// bool sortbysec(const pll &a, const pll &b){return (a.second < b.second);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n, m;
        cin>>n>>m;
        if(n >1 && m> 1) cout<<(n*m+1)/2;
        if(n == 1 || m == 1)    cout<<1;  
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		for(int i = 0; i < S.length(); i++) {
			int num = S.charAt(i)+N;
			if(num > 90)
				num -= 26;
			System.out.print((char)num);
		}
		System.out.println();

	}

}


Measured memory_bytes: 26708
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
} 
ll Logn(ll  n, ll r) 
{ 
    return (n > r - 1) ? 1 + Logn(n / r, r) : 0; 
}
 
int main()
{
	FAST
	int t=1;
//	cin>>t;
	while(t--)
	{	
		int n,m;
		cin>>n>>m;
		map<int,int> m1;
		int l1=1,l2=n;
		int c1=n-1,c2=1;
		if(n%2==1)
		{
			l1=1, l2=n-1;
			for(int i=0;i<m;i++)
			{
				cout<<l1<<" "<<l2<<endl;
				l1++;
				l2--;
			}
			return 0;
		}
		for(int i=0;i<m;i++)
		{
			if(m1[c1]==0 && m1[c2]==0 && c1!=c2)
			{
				cout<<l1<<" "<<l2<<endl;
			}
			else
			{
				while(m1[c1]==1 || m1[c2]==1)
				{
					l2--;
					c1--;
					c2++;
				}
				if(c1==c2)
				{
					l2--;
					c1--;
					c2++;
				}
				cout<<l1<<" "<<l2<<endl;
			}
			m1[c1]=1;
			m1[c2]=1;
			l1++;
			l2--;
			c1-=2;
			c2+=2;
		}
	}
    return 0;
}
  
 
 
 
 






Measured memory_bytes: 9928
#include<bits/stdc++.h>
using namespace std;
#define  IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
typedef long long ll;


int main()
{
	IOS;

	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	if (d >= x) {

		if (k % 2 == 0)cout << x;
		else cout << abs(d - x);


	}

	if (d < x) {

		ll temp = x / d;
		x = x % d;
		k = k - temp;
		if (k >= 0) {
			if (k % 2 == 0)cout << x;
			else cout << abs(d - x);
		}
		else if (k < 0) {
			cout << abs(x - k * d);
		}


	}





}

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

int main()
{
	int n;
	cin >> n;
	
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	
	double sum;
	
	for (int i = 0; i < n; ++i)
	{
		sum += 1.0 / (double)a[i];
	}
	cout << 1 / sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {

  int N, K;

  cin >> N >> K;
  string s;
  cin >> s;

  s[K - 1] += 32;

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pil pair<int,along long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define pb push_back
#define mk make_pair
#define eps 1e-12
#define maxn 100009
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin>>s;
	int ans1=0,ans2=0,ans3=0,ans4=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='N')
		{
			ans1=1;
		}
		else if(s[i]=='S')
		{
			ans2=1;
		}
		else if(s[i]=='E')
		{
			ans3=1;
		}
		else
		{
			ans4=1;
		}
	}
	ans1=ans1-ans2;
	ans3-=ans4;
	if(ans1==0&&ans3==0)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <climits>

using namespace std;

int main(){
    int h, w; cin >> h >> w;
    vector<vector<int>> cmat(10, vector<int>(10));
    for(int i=0; i<10; ++i){
        for(int j=0; j<10; ++j){
            cin >> cmat[i][j];
        }
    }
    vector<vector<int>> amat(h, vector<int>(w));
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            cin >> amat[i][j];
        }
    }

    for(int k=0; k<10; ++k){
        for(int i=0; i<10; ++i){
            for(int j=0; j<10; ++j){
                int d=cmat[i][k]+cmat[k][j];
                cmat[i][j]=min(cmat[i][j], d);
            }
        }
    }
    int ans=0;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            int a=amat[i][j];
            if(a==-1 || a==1) continue;
            ans+=cmat[a][1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define ll long long
#define M 100000007
#define fr first
#define sc second
#define endl "\n"
#define vc vector
#define pb push_back
#define pii pair<ll, ll>
#define psi pair<string, ll>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265
#define r0 return 0
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const char char_max = (char)(((unsigned char) char(-1)) / 2);

int main() {
  fast
    ll r;
    cin>>r;
    cout<<2*M_PI*r;
}



Measured memory_bytes: 3804
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
///*二進数割り算*/div2(ll x,ll y){}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll a,b;
 cin>>a>>b;
 if((a*b)%2==1)py;
 else pn;
return 0;}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		for (int i = x-k+1; i < x+k; i++)
			System.out.print(i + " ");
		System.out.println();
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0;i < n;i++){
    cin >> a[i];
  }
  
  int c = 1;
  
  for (int i = 0;i < n;i++){
    if (a[i] == c){
      c++;
    }
  }
  
  if (c == 1){
    cout << -1 << endl;
  }
  else{
    cout << n - c + 1 << endl;
  }
}

Measured memory_bytes: 4056
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <assert.h>
#include <algorithm>

using namespace std;

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

int h[111];
int hh[111];

int main(void)
{
	int w = 0;
	int d = 0;
	while (scanf("%d %d",&w,&d) != EOF && w && d)
	{
		for(int i = 0;i < w;i++) scanf("%d",&h[i]);
		for(int i = 0;i < d;i++) scanf("%d",&hh[i]);
		
		int ans = 0;
		for(int i = 0;i < w;i++) ans += h[i];
		sort(h,h+w); reverse(h,h+w);
		sort(hh,hh+d); reverse(hh,hh+d);
		bool okay[111] = {0};
		for(int i = 0;i < w;i++)
		{
			for(int j = 0;j < d;j++)
			{
				if(h[i] == hh[j] && !okay[j])
				{
					okay[j] = true;
					break;
				}
			}
		}
		for(int i = 0;i < d;i++) if(!okay[i]) ans += hh[i];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1044
#include <stdio.h>

int main(){
	int card[4][13] = {0}, i, j, x, n;
	char m,g;
	scanf("%d",&n);
	for(i = 0; i < n; i++){
		scanf("%c %c %d",&g ,&m, &x);
		x = x - 1;
		if(m == 'S'){
			card[0][x] = 1;
		} else if(m == 'H'){
			card[1][x] = 1;
		} else if(m == 'C'){
			card[2][x] = 1;
		} else if(m == 'D'){
			card[3][x] = 1;
		}
	}
	for(i = 0; i < 4; i++){
		for(j = 0; j < 13; j++){
			if(card[i][j] == 0){
				if(i == 0){
					printf("S %d\n", j + 1);
				} else if(i == 1){
					printf("H %d\n", j + 1);
				} else if(i == 2){
					printf("C %d\n", j + 1);
				} else if(i == 3){
					printf("D %d\n", j + 1);
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    vec<lint> a_list(N);
    range(i, 0, N) cin >> a_list.at(i);
    for (const auto& a : a_list) {
        if (a % 2 == 1) {
            cout << "first" << "\n";
            return 0;
        }
    }
    cout << "second" << "\n";
}

Measured memory_bytes: 1024
import Data.List

check s t c = if (drop ((length s) - c) s) == (take c t)then c else (check s t (c - 1))



main = do
      n <- readLn :: IO Int
      s <- getLine
      t <- getLine
      let c =(2 * n - (check s t n))
      if c < n then print(2*n) else print(c)

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100000000
#define pll pair<long,long>
#define se second
#define fi first
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update>pllordered_set;

pllordered_set s;

ll d;
ll dp[90005];
map<ll,pair<ll,ll> > m;
ll f(ll i)
{
	if(i<=0)
		return 0;
	if(dp[i]!=-1)
		return dp[i];
	ll ans=0;
	if(i-d<=0)
		ans=0;
	else
		ans=(abs(m[i].se-m[i-d].se)+abs(m[i].fi-m[i-d].fi));
	ans+=f(i-d);
	return dp[i]=ans;
}
int main()
{
			ios_base::sync_with_stdio(false);
			cin.tie(NULL);
			ll h,w;
			cin>>h>>w>>d;
			for(ll i=1;i<=h;i++)
			{
				for(ll j=1;j<=w;j++)
				{
					ll val;
					cin>>val;
					m[val]={i,j};
					dp[val]=-1;
				}
			}
			ll q;
			cin>>q;
			while(q)
			{
				q--;
				ll l,r;
				cin>>l>>r;
				//cout<<f(r)<<endl;
				cout<<f(r)-f(l)<<endl;
			}
}


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

int mod=1e9+7;


int minWays( vector<vector<char>> board){
    int n=board.size();
    int m=board[0].size();

    vector<vector<int>> dp(n,vector<int>(m,0));

    dp[0][0]=1;

    for(int i=1;i<m;i++){
        
        if(board[0][i]=='#'){
            break;
        }
        dp[0][i]=1;

    }


     for(int i=1;i<n;i++){
        
        if(board[i][0]=='#'){
            break;
        }
        dp[i][0]=1;
        
    }

    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(board[i][j]!='#'){
                dp[i][j]=dp[i-1][j]+dp[i][j-1];
                dp[i][j]%=mod;

            }
        }
    }

    return dp[n-1][m-1];


}


int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<char>> board(n,vector<char>(m));

    for(int row=0;row<n;row++){
        for(int col=0;col<m;col++){
            cin>>board[row][col];

        }
    }
    cout<<minWays(board);




}


Measured memory_bytes: 9244
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m, k = map(int, input().split())
uf = UnionFind(n)
friend = [set([]) for i in range(n)]
for i in range(m):
    ai, bi = map(int, input().split())
    ai -= 1; bi -= 1
    uf.union(ai, bi)
    friend[ai].add(bi)
    friend[bi].add(ai)

block = [set([]) for i in range(n)]
for i in range(k):
    ci, di = map(int, input().split())
    ci -= 1; di -= 1
    block[ci].add(di)
    block[di].add(ci)

for i in range(n):
    uf.find(i)

ans = []
for i in range(n):
    num = uf.size(i) - len(friend[i]) - 1
    for j in block[i]:
        if uf.find(i) == uf.find(j):
            num -= 1
    ans.append(num)

print(' '.join(map(str, ans)))

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

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

using namespace std;

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

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

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

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

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int A; int B; int C; int D;
    cin >> A >> B >> C >> D;
    int ans = 0;
    if (A < B)
        ans += A;
    else
        ans += B;
    if (C < D)
        ans += C;
    else
        ans += D;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, m;
    int A[100][100], b[100];
    int ans;
    int i, j;

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

    for (i = 0; i < n; i++) {
        ans = 0;
        for (j = 0; j < m; j++) {
            ans += A[i][j] * b[j];
        }
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 2100
#include <iostream>

using namespace std;


int main(){
    int int1, int2, n;
    cin >> int1 >> int2;
    int a = int2*2+1;
    if(int1 % a == 0){
        n = int1 / a;
    } else {
        n = int1 / a + 1;
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e3 + 5;
inline int read()
{
	rg int res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n, a[Maxn][Maxn], now[Maxn];
int ans;
struct str
{
	int x, y, d;
};
queue<str> q;
int Solve()
{
	rg int day, x, y, t, last = n, nx;
	for (day = 1;; day++)
	{
		while (!q.empty())
		{
			x = q.front().x;
			y = q.front().y;
			t = q.front().d;
			if (t == day)
				break;
			q.pop();
			nx = a[x][++now[x]];
			if (now[x] == n)
				last--;
			else if (a[nx][now[nx]] == x)
				q.push({nx, x, day});
			nx = a[y][++now[y]];
			if (now[y] == n)
				last--;
			else if (a[nx][now[nx]] == y)
				q.push({nx, y, day});
		}
		if (q.empty())
			return last ? -1 : day;
	}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j < n; j++)
			a[i][j] = read();
		now[i] = 1;
		if (a[a[i][1]][1] == i)
			q.push({a[i][1], i, 0});
	}
	printf("%d\n", Solve());
	return 0;
}


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

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, K;
vector<int> a;
vector<bool> dp;


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> N >> K;
    a.resize(N);
    dp.resize(K);

    REP(i, N) cin >> a.at(i);

    for (int i = 0; i < a[0]; i++) {
        dp.at(i) = false;
    }

    for (int i = a[0]; i <= K; i++) {
        bool flag = false;
        for (int j = 0; j < N; j++) {
            if (i - a[j] < 0) continue;
            if (dp.at(i - a[j]) == false) flag = true;
        }
        dp[i] = flag;
    }

    if (dp[K]) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 


def main():
    m, k = getList()
    if k == 0:
        ans = []
        for i in range(2**m):
           
            ans.append(i)
        
        for i in range(2**m-1, -1, -1):
            
            ans.append(i)

   
        print(*ans)
        return 
    if m <= 1 and k != 0:
        print(-1)
        return 
    if 2 ** m <= k:
        print(-1)
        return 
    ans = []
    for i in range(2**m):
        if i != k:
            ans.append(i)
    ans.append(k)
    for i in range(2**m-1, -1, -1):
        if i != k:
            ans.append(i)

    ans.append(k)
    print(*ans)

if __name__ == "__main__":
    main()
   

Measured memory_bytes: 96700
S = input()
s = []
cnt = 1
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        s.append([S[i], cnt])
        cnt = 1
if S[-2] == "R":
    s.append(["L", 1])
else:
    s.append(["L", cnt])
ans = []
for i in range(0, len(s), 2):
    ans += [0] * (s[i][1] - 1)
    ans += [-(-s[i][1] // 2) + (s[i + 1][1] // 2)]
    ans += [(s[i][1] // 2) + -(-s[i + 1][1] // 2)]
    ans += [0] * (s[i + 1][1] - 1)
print(*ans)


Measured memory_bytes: 65260
#include <iostream>
#include <string>
#include <cmath>


using namespace std;

long long kouyakusu(long long x,long long y){
  while(y > 0){
    long long tmp = y;
    y = x % y;
    x = tmp;
  }
  return x;
}

int main(){
  long long N,X;
  cin >> N >> X;
  long long i;
  long long x,y;
  cin >> y;
  y = llabs(X- y);
  for(i = 1; i < N;i++){
    cin >> x;
    y = kouyakusu(llabs(X-x),y);
  }

  cout  << y << endl;

  return 0;
}


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

int main() {
  int N;
  scanf("%d", &N);
  string a[N];

  int count = 0;
  int acount[N];
  int bcount[N];

  for(int i=0;i<N;++i){
    acount[i]=0;
    bcount[i]=0;
  }


  for(int i=0;i<N;++i){
    cin >> a[i];
    int len = a[i].length();
    for(int j=0;j<len-1;++j){
      if(a[i][j]=='A' && a[i][j+1]=='B') ++count;
    }
    if(a[i][0]=='B') bcount[i]=1;
    if(a[i][len-1]=='A') acount[i]=1;
  }

  bool flag=false;
  int counta = 0;
  int countb = 0;

  for(int i=0;i<N;++i){
    if(acount[i]!=bcount[i]){
      flag = true;
      break;
    }
  }

  for(int i=0;i<N;++i){
    counta += acount[i];
    countb += bcount[i];
  }
  
  if(counta==0 && countb == 0)  cout << count << endl;
  else if(flag) cout << count+min(counta,countb) << endl;
  else cout << count+min(counta,countb)-1 << endl;;

}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;
char s[10][10];

int main()
{
    int n, m, k, S, ans = 0;
    scanf("%d%d%d", &n, &m, &k); S = 1 << (n + m);
    for (int i = 0; i < n; i++)
        scanf("%s", s[i]);
    for (int i = 0; i < S; i++)
    {
        int w = 0;
        for (int j = 0; j < n; j++)
            for (int l = 0; l < m; l++)
                if (s[j][l] == '#' && (i & (1 << j)) == 0 && (i & (1 << (l + n))) == 0)
                    w++;
        ans += w == k;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,xa,ya,b,xb,yb,h,w,xc,yc,cnt=0,xy[110][110]={-1},sx=-1,sy=-1,dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
string s,t;
pair<int,int> p;
char c[110][110];
queue<pair<int,int>> que;
int bfs(int x,int y){
	rep(i,h){
		rep(j,w){
			xy[i][j]=-1;
		}
	}
	que.push(pair<int,int>(x,y));
	xy[x][y]=0;
	while(que.size()){
		p=que.front();
		que.pop();
		rep(i,4){
			int nx=p.first+dx[i];
			int ny=p.second+dy[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&c[nx][ny]!='#'&&xy[nx][ny]==-1){
				que.push(pair<int,int>(nx,ny));
				xy[nx][ny]=xy[p.first][p.second]+1;
			}
		}
	}
	return xy[p.first][p.second];
}
signed main()
{
	cin>>h>>w;
	rep(i,h){
		rep(j,w){
			cin>>c[i][j];
		}
	}
	rep(i,h){
		rep(j,w){
			if(c[i][j]=='.'){
				cnt=max(cnt,bfs(i,j));
			}
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 256
def l(n):
    return 2 ** (n+2) - 3


def p(n):
    return 2 ** (n+1) - 1


def countp(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    if 1 < x <= 1 + l(n-1):
        return countp(n-1, x-1)
    if x == 1 + l(n-1) + 1:
        return p(n-1) + 1
    if 1 + l(n-1) + 1 < x <= 1 + l(n-1) + 1 + l(n-1):
        return p(n-1) + 1 + countp(n-1, x-1-l(n-1)-1)
    return p(n-1) + 1 + p(n-1)


N, X = map(int, input().split())
print(countp(N, X))


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

int absdiff(int a,int b){
    return (abs(a-b));
}

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> height;
    for(int i=0;i<n;i++){
        int temp;
        cin>>temp;
        height.push_back(temp);
    }

    vector<int> cost(n,0);
    cost[1] = abs(height[1]-height[0]);
    for(int i=2;i<n;i++){
        int min_val = 1e9;
        for(int j=1;j<=k and i-j >= 0;j++){
            int temp = cost[i-j]+absdiff(height[i-j],height[i]);
            min_val = min(min_val,temp);
        }
        cost[i] = min_val;
    }

    cout<<cost[n-1];
    return 0;
}

Measured memory_bytes: 4012
// {{{
#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;
// }}}

int N, M;
vector<int> e[100000];
int m[100000];

void init()
{
}

int rec(int s)
{
    if(m[s] != -1) return m[s];
    int ret = 0;
    for(auto t: e[s]){
        ret = max(ret, rec(t)+1);
    }
    m[s] = ret;
    return ret;
}

void solve()
{
    int ans = 0;
    REP(i, N){
        m[i] = -1;
    }
    REP(i, N){
        ans = max(ans, rec(i));
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    REP(i, M){
        int s, t;
        cin >> s >> t;
        s--; t--;
        e[s].pb(t);
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 8192
def solve(n, d):
    if n < 3:
        return "No"
    else:
        for i in range(n-2):
            if d[i][0]==d[i][1]:
                if d[i+1][0]==d[i+1][1]:
                    if d[i+2][0]==d[i+2][1]:
                        return "Yes"
        return "No"

n = int(input())
d = []
for i in range(n):
    d += [list(map(int,input().split()))]
#print(d)
print(solve(n,d))    

Measured memory_bytes: 9136
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;
		int N = scanner.nextInt();
		int X = scanner.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int m = scanner.nextInt();
			list.add(m);
			X -= m;
		}
 
		Collections.sort(list);
		int min = list.get(0);
		for (int x = 0; x <= X/min; x++) {
			count = x;
			if (min * x > X) {
				break;
			}
		}
		count += N;
		System.out.println(count);
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair

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

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int N, K, Q, A[100001];

int main() {
    int p[100001];
    cin >> N >> K >> Q;
    REP (i, N) {
        p[i] = K;
    }
    REP (i, Q) {
        cin >> A[i];
        A[i]--;
        p[A[i]]++;
    }
    REP (i, N) {
        p[i] -= Q;
        cout << ((p[i] > 0) ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 1408