akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int64_t a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if(w>=v && a!=b){
        cout << "NO" << endl;
    }else{
        int64_t delta_x = abs(a-b);
        int64_t delta_v = v-w;
        if(delta_v*t < delta_x){
            cout << "NO" << endl;
        }else{
            cout << "YES" << endl;
        }
    }
    

    
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>

using namespace std;

#define For(i,a,b) for(int i = (a);i < (b);i++)
#define rep(i,n)	For(i,0,n)
typedef pair<int, int> P;

int d[100001];
bool f[100001];
bool sf[100001];

int main(){

	int n;
	cin >> n;
	vector<int> p;
	rep(i, n){
		int tp;
		cin >> tp;
		p.push_back(tp);
	}

	fill(d, d + 100001, 1e9);
	fill(sf, sf + 100001, false);

	d[0] = 0;
	queue<int> q;
	q.push(0);
	while (q.size()){
		int nw = q.front();
		q.pop();

		fill(f, f + 100001, false);
		vector<int> tv;
		tv.push_back(nw);
		f[nw] = true;

		bool tf = false;
		int c = d[nw];

		while (p[nw]){
			nw += p[nw];

			if (f[nw]){
				tf = true;
				break;
			}

			d[nw] = min(d[nw],c);
			f[nw] = true;
			tv.push_back(nw);
		}
		if (tf){
			rep(i, tv.size()){
				sf[tv[i]] = true;
			}
			continue;
		}

		for (int i = 1; i <= 6; i++){
			if (nw + i < n && d[nw + i] > d[nw] + 1 && !sf[nw + i]){

				d[nw + i] = d[nw] + 1;
				q.push(nw + i);

			}
		}
	}

	cout << d[n - 1] << endl;


	return 0;
}

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

int main() {
	int a,b; cin>>a>>b;
	if(a>b){cout<<"a > b"<<endl;return 0;}
	if(a<b){cout<<"a < b"<<endl;return 0;}
	if(a==b){cout<<"a == b"<<endl;return 0;}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3076
d = int(input())
c = list(map(int,input().split()))
like=0
but=0
s=[]
last=[]
show=''
for i in range(26):
    last.append(0)
for i in range(d):
    keys=list(map(int,input().split()))
    s.append(keys)
for i in range(d):
    show+=str(s[i].index(max(s[i]))+1)
    if i < d-1:
        show+='\n'
print(show)

Measured memory_bytes: 9392
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int y, m, d;

    void run(){
	while(sc.hasNext()){
	    y = sc.nextInt();
	    m = sc.nextInt();
	    d = sc.nextInt();
	    solve();
	}
    }

    void solve(){
	// pre-meiji
	if(y<1868){ show("pre-meiji"); }
	// pre-meiji and meiji
	else if(y==1868){
	    if(m<9){ show("pre-meiji"); }
	    else if(m==9){
		if(d<8){ show("pre-meiji"); }
		else{ show("meiji"); }
	    }
	    else{ show("meiji"); }
	}
	// meiji
	else if(y<1912){ show("meiji"); }
	// meiji and taisho
	else if(y==1912){
	    if(m<7){ show("meiji"); }
	    else if(m==7){
		if(d<30){ show("meiji"); }
		else{ show("taisho"); }
	    }
	    else{ show("taisho"); }
	}
	// taisho
	else if(y<1926){ show("taisho"); }
	// taisho and showa
	else if(y==1926){
	    if(m<12){ show("taisho"); }
	    else if(m==12){
		if(d<25){ show("taisho"); }
		else{ show("showa"); }
	    }
	    else{ show("showa"); }
	}
	// showa
	else if(y<1989){ show("showa"); }
	// showa and heisei
	else if(y==1989){
	    if(m==1){
		if(d<8){ show("showa"); }
		else{ show("heisei"); }
	    }
	    else{ show("heisei"); }
	}
	// heisei
	else{ show("heisei"); }
    }

    void show(String mes){
	if(mes.equals("pre-meiji"))
	    show(mes, 0);
	else if(mes.equals("meiji"))
	    show(mes, y-1868+1);
	else if(mes.equals("taisho"))
	    show(mes, y-1912+1);
	else if(mes.equals("showa"))
	    show(mes, y-1926+1);
	else
	    show(mes, y-1989+1);
    }

    void show(String mes, int year){
	if(mes.equals("pre-meiji"))
	    System.out.println(mes);
	else
	    System.out.println(mes+" "+year+" "+m+" "+d);
    }
}

Measured memory_bytes: 17168
#include <iostream>
#include <algorithm>
#include <cmath>
#define REP(i,N) for(int i = 0; i < (N); i++)
using namespace std;

int a,b;

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

    cin >> a >> b;
    if (a + b <= 9){
        cout << a+b << "\n";
    }
    else{
        cout << "error" << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    string A , B;
    cin >> A;
    cin >> B;
    reverse(A.begin() , A.end());
    if(A == B){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string st;
    cin>>st;
    int l=st.length();
    string f;
    for(int i=0; i<st.length(); i++)
        if(i==st.length()-1)
    {
        {
          f=st[i];
        }
    }
   // cout<<f;
    if(f=="s")
    {
        cout<<st<<"es"<<endl;
    }
    else
    {
        cout<<st<<"s"<<endl;
    }
}


Measured memory_bytes: 3596
#include<iostream>
#include <bits/stdc++.h>
//1000000000000223
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, k, vis[100009], ans[100009];
vector<int> v[100009];
priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > q;
int main()
{
    IO
    cin>>n;
    for(int i=1; i<n; i++)
    {
        int x,  y;
        cin>>x>>y;
        v[x].push_back(y), v[y].push_back(x);
    }
    fill(ans,ans+n+1,1e9);
    cin>>k;
    while(k--)
    {
        int x, y;
        cin>>x>>y;
        vis[x]=1;
        ans[x]=y;
        q.push({y,x});
    }
    while(!q.empty())
    {
        int node=q.top().second;
        q.pop();
        for(auto i : v[node])
        {
            if(vis[i])
            {
                if(abs(ans[i]-ans[node])!=1)
                    return cout<<"No", 0 ;
                continue;
            }
            if(ans[i]>ans[node]+1)
                ans[i]=ans[node]+1, q.push({ans[i],i});
        }
    }
    cout<<"Yes\n";
    for(int i=1; i<=n; i++)
        cout<<ans[i]<<"\n";
    return 0;
}


Measured memory_bytes: 8308
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	ll n,a,b;
	cin>>n>>a>>b;
	ll z=(n/(a+b));
	ll rem=(n-z*(a+b));
	ll zz=min(a,rem);
	cout<<z*a+zz;
	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, t, a[210000];
long long res;
int main(void){
    // Your code here!
    cin >> n >> t;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        res += (a[i] - a[i - 1] < t ? a[i] - a[i - 1] : t);
    }
    cout << res + t << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n,m,r;
  cin >> n >> m >> r;
  vint R(r);
  rep(i,0,r){
    int r;
    cin >> R[i];
    R[i]--;
  }
  vvint to(n,vint(n,INF));
  rep(i,0,n){
    to[i][i] = 0;
  }
  rep(i,0,m){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    to[a][b] = c;
    to[b][a] = c;
  }
  rep(i,0,n){
    rep(j,0,n){
      rep(s,0,n){
        to[j][s] = min(to[j][s],to[j][i] + to[i][s]);
      }    
    }
  }
  sort(R.begin(),R.end());
  int ans = INF;
  do{
    int tmp = 0;
    rep(i,0,r-1){
      tmp += to[R[i]][R[i+1]];
    }
    ans = min(ans,tmp);
  }while(next_permutation(R.begin(),R.end()));
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii> 
using vec = vector<T>;

const ll INF = 1e18, MOD = 1e9 + 7;

const int MAX = 2e3;

ll dp[MAX][MAX];
vii a, b;

ll f(const int i, const int j) {
    if (i == -1 or j == -1)
        return 0;
    ll &res = dp[i][j];
    if (res != -1)
        return res;
    res = (f(i - 1, j) + f(i, j - 1)) % MOD;
    if (a[i] == b[j])
        res++;
    else
        res += MOD - f(i - 1, j - 1);
    res %= MOD;
    return res;
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);
    
    memset(dp, -1, sizeof dp);
    int n, m;
    cin >> n >> m;
    a.resize(n);
    b.resize(m);
    for (auto &e : a) {
        cin >> e;
    }
    for (auto &e : b) {
        cin >> e;
    }
    cout << (f(n - 1, m - 1) + 1) % MOD << '\n';
}

Measured memory_bytes: 31872
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

int fact[N], inv[N], a[N];

int mul(int a, int b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return 1ll * a * b % mod;
}

int add(int a, int b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (a + b) % mod;
}

int fp(int b, int p){
    if(!p) return 1;
    ll ret = fp(b, p >> 1);
    ret = ret * ret % mod;
    if(p&1) ret = ret * b % mod;
    return ret;
}

void pre(){
    fact[0] = inv[0] = 1;
    for(int i = 1; i < N; i++){
        fact[i] = mul(fact[i - 1], i);
        inv[i] = fp(fact[i], mod - 2);
    }
}

int ncr(int n, int r){
    int ret = mul(fact[n], inv[n - r]);
    return mul(ret, inv[r]);
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    pre();
    int n, k;
    cin >> n >> k;
    ll mn = 0, mx = 0;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for(int i = 0; i < n; i++){
        int kam = n - i - 1;
        int r = k - 1;
        if(kam < r) break;
        mn = add(mn, mul(a[i], ncr(kam, r)));
    }
    for(int i = n - 1; i >= 0; i--){
        int kam = i;
        int r = k - 1;
        if(kam < r) break;
        mx = add(mx, mul(a[i], ncr(kam, r)));
    }
    cout << add(mx, -mn);

    return 0;
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if ((A == B && A != C) or (A == C && A != B) or (B == C && A != B)) puts("Yes");
    else puts("No");
}

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

typedef long long ll;
typedef unsigned long long ull;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < n; ++i)

using namespace std;

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

	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 1; i < n; ++i) {
		if (s[i] == s[i - 1]) ++ans;
	}

	cout << min(n - 1, ans + 2 * k) << "\n";
 }


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

int queen[8];
bool lock[8];
char board[]="........";

bool canPut(int r, int c) {
    for(int i=0; i<r; i++) {
        if(queen[i]==c) return false;
        if((i+queen[i])==r+c) return false;
        if((i-queen[i])==r-c) return false;
    }
    return true;
}

bool search(int r)
{
    if(r>=8) return true;
    if(lock[r]) {
        if(canPut(r, queen[r])) return search(r+1);
        else return false;
    }
    for(int c=0; c<8; c++) {
        if(canPut(r, c)) {
            queen[r]=c;
            if(search(r+1)) return true;
        }
    }
    return false;
}

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

    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        int r,c;
        cin>>r>>c;
        queen[r]=c;
        lock[r]=true;
    }
    
    if(search(0)) {
        for(int r=0; r<8; r++) {
            cout.write(board,queen[r]);
            cout.put('Q');
            cout.write(board,7-queen[r]);
            cout.put('\n');
        }
    }
    
    return 0;
}

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

using namespace std;

char field[101][101];

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

bool check(int x,int y,int angle){
	if(!(y>=0&&x>=0&&y<n&&x<n)){
		return false;
	}

	for(int i = 0; i < 4; i++){
		if(angle==i)
			continue;
		int nx=dx[i]+x;
		int ny=dy[i]+y;
		if(!(ny>=0&&nx>=0&&ny<n&&nx<n)){
			continue;
		}
		if(field[ny][nx]=='#'){
			return false;
		}
	}
	return true;
}

int main(){

	int nn;
	cin>>nn;
	for(int i = 0; i < nn; i++){
		if(i!=0)
			cout<<endl;
		cin>>n;
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				field[j][k]=' ';
			}
		}

		// 0:ツ右,1:ツ可コ,2:ツ債カ,3:ツ湘」
		int angle=3;
		int cx=0;
		int cy=n-1;
		int cnt=0;
		field[cy][cx]='#';
		while(1){
			if(angle==3){
				int ny=cy-1;
				int nx=cx;
				if(check(nx,ny,angle)){
					field[ny][nx]='#';
					cnt=0;
					cy=ny;
					cx=nx;
				}
				else{
					if(cnt>=1){
						break;
					}
					cnt++;
					angle=0;
				}
			}
			else if(angle==2){
				int ny=cy;
				int nx=cx-1;
				if(check(nx,ny,angle)){
					field[ny][nx]='#';
					cnt=0;
					cy=ny;
					cx=nx;
				}
				else{
					if(cnt>=1){
						break;
					}
					cnt++;
					angle=3;
				}
			}
			else if(angle==1){
				int ny=cy+1;
				int nx=cx;
				if(check(nx,ny,angle)){
					field[ny][nx]='#';
					cnt=0;
					cy=ny;
					cx=nx;
				}
				else{
					if(cnt>=1){
						break;
					}
					cnt++;
					angle=2;
				}
			}
			else if(angle==0){
				int ny=cy;
				int nx=cx+1;
				if(check(nx,ny,angle)){
					field[ny][nx]='#';
					cnt=0;
					cy=ny;
					cx=nx;
				}
				else{
					if(cnt>=1){
						break;
					}
					cnt++;
					angle=1;
				}
			}
		}
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				cout<<field[j][k];
			}
			cout<<endl;
		}
	}

	return 0;
}

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

using namespace std;

#define all(x) begin(x), end(x)

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

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

    int n, w;
    cin >> n >> w;

    // what is the max value for weight i
    vector<ll> dp(w + 1, 0);

    for (int i = 0; i < n; ++i) {
        ll wi, vi;
        cin >> wi >> vi;
        for (int j = w - wi; j >= 0; --j) {
            dp[j + wi] = max(dp[j + wi], vi + dp[j]);
        }
    }

    cout << dp[w] << '\n';
    
    return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

int H,W,sy,sx,gy,gx;
int N;

int C[100][100];
bool vis[100][100];

void dfs(int y,int x){
    vis[y][x]=true;
    rep(i,4){
        int ny=y+dy[i],nx=x+dx[i];
        if(ny<0||ny>=H||nx<0||nx>=W||C[ny][nx]!=C[y][x]||vis[ny][nx])continue;
        dfs(ny,nx);
    }
}

signed main(){
    while(cin>>W>>H,W||H){
        cin>>sx>>sy>>gx>>gy;
        cin>>N;
        sy--;sx--;gy--;gx--;
        memset(C,0,sizeof(C));
        rep(i,N){
            int c,d,x,y;
            cin>>c>>d>>x>>y;
            x--;y--;
            for(int dy=0;dy<2;dy++){
                for(int dx=0;dx<4;dx++){
                    int ny,nx;
                    if(!d)ny=y+dy,nx=x+dx;
                    else ny=y+dx,nx=x+dy;
                    C[ny][nx]=c;
                }
            }
        }
        if(!C[sy][sx]){
            cout<<"NG"<<endl;
            continue;
        }
        memset(vis,0,sizeof(vis));
        dfs(sy,sx);
        if(vis[gy][gx])cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define N 140000
#define mod 1000000007
#define pp pair<ll,ll>
typedef long long int ll;
typedef long double ld;
#define MP make_pair

#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++)     
void fastIO(void);

void decimal(int);
ll modmulti(ll, ll, ll);
ll modadd(ll, ll, ll);
ll modpower(ll, ll, ll);
ll gcd(ll, ll );
ll modinv(ll, ll);


ll a[N];

int main()
{  
   string s;
   cin>>s;
   
   ll n = s.length();
   s.push_back('a');
   ll r=0,l=0;
   for(ll i=0;i<n;){
      while(i<n && s[i]=='R'){
         r++;
         i++;
      }
      if(s[i-1]=='R') a[i-1] = r;
     // cout<<i-1<<" "<<r<<endl;
      r = 0;
      while(i<n && s[i]=='L'){
         l++;
         i++;
      }
      
      //cout<<i<<endl;
   }
   l=0;
   for(ll i=n-1;i>=0;){
      while(i>=0 && s[i]=='R'){
         r++;
         i--;
      }
     // a[i-1] = r;
      r = 0;
      while(i>=0 && s[i]=='L'){
         l++;
         i--;
      }
      if(s[i+1]=='L') a[i+1] = l;
      l=0;
      //cout<<i<<endl;
   }
/* rep(i,n)
      cout<<a[i]<<" ";
   cout<<endl;*/
   rep(i,n){
      if(a[i]!=0){
         if((a[i]+a[i+1])%2==0){
            a[i] = (a[i]+a[i+1])/2;
            a[i+1] = a[i];
         }
            
         else{
            l = a[i];
            r = a[i+1];
            if(a[i]%2==0){
               a[i] = (l+r)/2;
               a[i+1] = l+r-a[i];
               //cout<<l<<" "<<r<<" "<<a[i]<<" "<<a[i+1]<<endl;
            }
            else{
               a[i+1] = (l+r)/2;
               a[i] = l+r-a[i+1];
            }
         }
         i++;
      }
   }
   rep(i,n)
      cout<<a[i]<<" ";
   cout<<endl;
}























void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}

void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b, ll m){
   return ((a%m)*(b%m))%m;
}
ll modadd(ll a, ll b, ll m){
   return ((a%m)+(b%m))%m;
}
ll modpower(ll a, ll n, ll m){
   if(n==0)
      return 1;
   ll result = 1;
   while(n>0){
      if(n%2==1)
         result = modmulti(result,a,m);
      a = modmulti(a,a,m);
      n = n/2;
   }
   return result;
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a, ll m){
   return modpower(a,m-2,m);
}


Measured memory_bytes: 1408
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

int n, m, c, b[22], a[22], res;

int main() {
  init_ios();
  cin >> n >> m >> c;
  for (int i = 1; i <= m; ++i)
    cin >> b[i];
  while (n--) {
    int tmp = c;
    for (int i = 1; i <= m; ++i) {
      int x;
      cin >> x;
      tmp += x*b[i];
    }
    if (tmp > 0)
      ++res;
  }
  cout<<res<<"\n";
}

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

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

int main() {

	vector<int> prime;
	vector<bool> used(10001, false);
	used[0] = used[1] = true;
	for (int i = 2; i * i <= 10000; i++) {
		if (!used[i]) prime.push_back(i);
		used[i] = true;
		for (int j = i * 2; j <= 10000; j += i) {
			used[j] = true;
		}
	}
	REP(i, 10000 + 1) if (!used[i]) {
		prime.push_back(i);
		used[i] = true;
	}
	
	vector<int> ans;
	FOR(i, 1, prime.size()) {
		if (prime[i] == prime[i - 1] + 2) ans.push_back(prime[i]);
	}
	sort(ans.begin(), ans.end());
	
	int n;
	while (cin >> n, n) {
		int b = *(upper_bound(ans.begin(), ans.end(), n) - 1);
		int a = b - 2;
		cout << a << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
//Author - Soumik Roy
//Date & Time - August 29, 2020 6:16 PM
//Problem name - C - Sum of product of pairs
//Problem url - https://atcoder.jp/contests/abc177/tasks/abc177_c
//Time limit - 2000 ms
//Memory Limit - 1024 MB    

#include<bits/stdc++.h>
#define ll                    long long int
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define vi                    vector<int>
#define vll                   vector<ll>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define eb                    emplace_back
#define ull                   unsigned long long
#define bug(x)				  cout<<"  [ "#x<<" = "<<x<<" ]"<<endl;
#define KAMEHAMEHA            ios_base::sync_with_stdio(0);
#define RASENGAN              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int dir[]={0,1,0,-1,1,0,-1,0};
const ll MOD=1e9+7;
ll modInverse(ll n,ll p)
{
	if(p==0)
		return 1;
	ll x=modInverse(n,p/2)%MOD;
	x=(x*x)%MOD;
	if(p%2)
		x=(x*n)%MOD;
	return x%MOD;
}
void solve()
{
	ll n;
	cin>>n;
	ll sumofsquare=0,squareofsum=0;
	for(ll i=0,temp;i<n;i++)
	{
		cin>>temp;
		squareofsum=(temp+squareofsum)%MOD;
		ll sq=(temp*temp)%MOD;
		sumofsquare=(sumofsquare+sq)%MOD;
	}
	squareofsum=squareofsum*squareofsum;
	ll ans=(squareofsum-sumofsquare+MOD)%MOD;
	ll inmod=modInverse(2,MOD-2);
	//cout<<inmod<<endl;
	ans=(ans*inmod)%MOD;
	cout<<ans<<endl;
}
int main()
{
    KAMEHAMEHA
	int t=1;
	//cin>>t;
	for(int cn=1;cn<=t;cn++)
	{
		solve();
	}
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i,l,r) for(int i=(l);i<(r);i++)
#define forb(i,r,l) for(int i=(r);i>(l);i--)
#define log2i(x) 32 - __builtin_clz((x)) - 1
#define log2ll(x) 64 - __builtin_clzll((x)) - 1
#define Pi acos(-1.0)
#define sz(x) (int)x.size()
#define pw(x,y) trunc(exp(log((x))*(y)))
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

int q, p[2]={1,2}, cnt=0;
string st;
deque<char> a;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
#endif
    fastIO;
    cin >> st;
    forw(i,0,sz(st)) a.push_back(st[i]);
    cin >> q;
    while(q--) {
        int t;
        cin >> t;
        if(t==1) swap(p[0],p[1]), cnt++;
        else {
            char c;
            cin >> t >> c;
            if(p[t-1]==1) a.push_front(c);
            else a.push_back(c);
        }
    }
    if(cnt&1) while(sz(a)) cout << a.back(), a.pop_back();
    else while(sz(a)) cout << a.front(), a.pop_front();
    return 0;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  string s;cin >> s;
  rep(i,s.length()) s[i] = (s[i]-'A'+N)%26 + 'A';
  cout << s << endl;
  return 0;
}


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

int m, n, a[81][81], b[81][81];
bitset<25601> f[81][81];

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>m>>n;
    for (int i=1; i<=m; ++i)
        for (int j=1; j<=n; ++j)
            cin>>a[i][j];
    for (int i=1; i<=m; ++i)
        for (int j=1; j<=n; ++j)
            cin>>b[i][j];

    f[0][1].set(12800);
    f[1][0].set(12800);
    for (int i=1; i<=m; ++i) {
        for (int j=1; j<=n; ++j) {
            int d=abs(a[i][j]-b[i][j]);
            f[i][j] |= f[i-1][j]<<d | f[i][j-1]<<d;
            f[i][j] |= f[i-1][j]>>d | f[i][j-1]>>d;
        }
    }
    int ans=1e9;
    for (int bit=0; bit<=25600; ++bit) {
        if (f[m][n][bit]) ans=min(ans, abs(12800-bit));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 20608
sa=input()
sb=input()
sc=input()

a=int(0)
b=int(0)
c=int(0)

now=sa[0]
sa.lstrip()
a+=1

n=int(0)
while 1:
    if now=='a':
        if a==len(sa):
            print('A')
            break
        else:
            now=sa[a]
            a+=1
        
    elif now=='b':
        if b==len(sb):
            print('B')
            break
        else:
            now=sb[b]
            b+=1

    else:
        if c==len(sc):
            print('C')
            break
        else:
            now=sc[c]
            c+=1

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define rrng(obj) (obj).rbegin(), (obj).rend()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<pii>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,v.size())i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(v.size())o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
bool comp(pii a,pii b){
  return a.se<b.se;
}
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  int n;
  cin>>n;
  vl a(3*n);
  cin>>a;
  sort(rrng(a));
  ll ans=0;
  rep(i,n){
    ans+=a[2*i+1];
  }
  cout<<ans<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>

using namespace std;

int main() 
{
    int K, N;
    cin >> K >> N;
    int max_diff = 0;
    int sum = 0;
    int temp;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
        if(0 != i) {
            temp = vec.at(i) - vec.at(i - 1);
            sum += temp;
            if (max_diff < temp) {
                max_diff =temp;
            }
        }
    }

    sum += vec.at(0) + (K - vec.at(N - 1));
    if (max_diff < vec.at(0) + (K - vec.at(N-1))) {
        max_diff = vec.at(0) + (K - vec.at(N - 1));
    }

    sum -= max_diff;
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>
#include<string>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

int main(void){
	int X,ans;
	cin >> X;
	ans = 1000*(X/500) +5*((X%500)/5);
	cout << ans <<endl; 
	return 0;
}

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

int main() {
    int n,count=0,a,b;
    cin>>n>>a>>b;
    int m;
    for (int i=1; i<=n; i++) {
        int res=0;
        m=i;
        while(m) {
            res+=m%10;
            m/=10;
        }
        if (a<=res&&res<=b) count+=i;
    }
    cout<<count<<endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool a[1005];
int n,x,ans,temp;
int main(){
    cin>>n;
    while(n--){
        cin>>x;
        if(x<400&&!a[1]) a[1]=true,ans++;
        if(x>=400&&x<800&&!a[2]) a[2]=true,ans++;
        if(x>=800&&x<1200&&!a[3]) a[3]=true,ans++;
        if(x>=1200&&x<1600&&!a[4]) a[4]=true,ans++;
        if(x>=1600&&x<2000&&!a[5]) a[5]=true,ans++;
        if(x>=2000&&x<2400&&!a[6]) a[6]=true,ans++;
        if(x>=2400&&x<2800&&!a[7]) a[7]=true,ans++;
        if(x>=2800&&x<3200&&!a[8]) a[8]=true,ans++;
        if(x>=3200) temp++;
    }
    cout<<max(ans,1)<<" "<<ans+temp<<endl;
    return 0;
  }

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


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

    for(int i=0; i<s.size(); i++){
        if((i+1)%2==0){
            if(s[i]=='R'){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            if(s[i]=='L'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}

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

using namespace std;

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

vector<int> G[100000];
int n;

int main(){
    cin >> n;
    int a[n-1], b[n-1];
    rep(i, n - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[b[i]].push_back(a[i]);
        G[a[i]].push_back(b[i]);
    }
    // 1からの最短距離
    int dis1[n];
    // nからの最短距離
    int disn[n];
    rep(i, n) {dis1[i] = -1; disn[i] = -1;}
    dis1[0] = 0;
    disn[n-1] = 0;
    queue<int> q1, q2;
    q1.push(0);
    q2.push(n-1);
    while(q1.size() > 0){
        int num = q1.front();
        q1.pop();
        rep(j, G[num].size()){
            int idx = G[num][j];
            if (dis1[idx] != -1) continue;
            dis1[idx] = dis1[num] + 1;
            q1.push(idx);
        }
    }
    while(q2.size() > 0){
        int num = q2.front();
        q2.pop();
        rep(j, G[num].size()){
            int idx = G[num][j];
            if (disn[idx] != -1) continue;
            disn[idx] = disn[num] + 1;
            q2.push(idx);
        }
    }
    int countF = 0;
    rep(i, n){
        if (dis1[i] <= disn[i]){
            countF++;
        }
    }
    if (countF > n / 2){
        cout << "Fennec" << endl;
    }else{
        cout << "Snuke" << endl;
    }
    
}

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

using namespace std;

int l, n, q;
int x[100005];
int par[100005];
int pare[100005][21];

void initt()
{
    memset(pare, -1, sizeof(pare));
    for (int i = 1; i <= n; i++){
        pare[i][0] = par[i];
    }
    for (int j = 1; j <= 20; j++){
        for (int i = 1; i <= n; i++){
            if (pare[i][j-1] != -1)
                pare[i][j] = pare[pare[i][j-1]][j-1];
        }
    }
}

signed main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &x[i]);
    }
    x[n+1] = INT_MAX;
    scanf("%d%d", &l, &q);
    int ri = 1;
    for (int i = 1; i <= n; i++) {
        while (x[ri] - x[i] <= l) ri++; ri--;
        par[i] = ri;
    }
    initt();
    int a, b;
    for (int i = 1; i <= q; i++) {
        scanf("%d%d", &a, &b);
        if (a == b) {
            cout << 0 << "\n";
            continue;
        }
        if (a > b) swap(a, b);
        int res = 0;
        for (int j = 20; j >= 0; j--) {
            if (pare[a][j] < b && pare[a][j] != -1)
            {
                a = pare[a][j];
                res += 1 << j;
            }
        }
        res += 1;
        printf("%d\n", res);
    }
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

int main()
{
    string s, t;
    cin >> s >> t;
    
    bool result = true;
    rep(i,s.length()){
      if(s.at(i) != t.at(i)) result = false;
    }

    if(result) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){
  int a;int b;int c;
  cin >>a >> b >> c;
  if(a>b){
    swap(a,b);
  }
  if(b>c){
    swap(b,c);
    }
  if(a>b){
  swap(a,b);
  }
  if(b>c){
    swap(b,c);
    }
  cout <<a<<" "<<b<<" "<<c<<endl;

  return 0;
}


Measured memory_bytes: 3032
using System;
using System.Linq;

class Problem {
    public class Dice {
        public int Top    { get; private set; }
        public int South  { get; private set; }
        public int East   { get; private set; }
        public int West   { get; private set; }
        public int North  { get; private set; }
        public int Bottom { get; private set; }
        
        private int[] init;
        
        public void Init() {
            Top    = init[0];
            South  = init[1];
            East   = init[2];
            West   = init[3];
            North  = init[4];
            Bottom = init[5];
        }
        public Dice(int[] nums) {
            init = nums;
            Init();
        }
        public void Roll(string coms) {
            foreach (var com in coms) {
                var tmp = Top;
                switch (com) {
                    case 'E': Top = West;  West  = Bottom; Bottom = East;  East  = tmp; break;
                    case 'N': Top = South; South = Bottom; Bottom = North; North = tmp; break;
                    case 'S': Top = North; North = Bottom; Bottom = South; South = tmp; break;
                    case 'W': Top = East;  East  = Bottom; Bottom = West;  West  = tmp; break;
                }
            }
        }
        public void RollY(string coms) {
            foreach (var com in coms) {
                var tmp = South;
                switch (com) {
                    case 'R': South = West; West = North; North = East; East = tmp; break;
                    case 'L': South = East; East = North; North = West; West = tmp; break;
                }
            }
        }
        public char Position(int num) {
            return num == Top   ? 'T' :
                   num == South ? 'S' :
                   num == East  ? 'E' :
                   num == West  ? 'W' :
                   num == North ? 'N' : 'B';
        }
        public bool Equal(Dice d) {
            return Top    == d.Top   &&
                   South  == d.South &&
                   East   == d.East  &&
                   West   == d.West  &&
                   North  == d.North &&
                   Bottom == d.Bottom;
        }
    }
    
    public static bool Check(Dice d1, Dice d2) {
        var checkComs = new[] {"", "N", "W", "E", "S", "NN"};
        foreach (var com in checkComs) {
            d1.Roll(com);
            if (d1.Equal(d2)) return true;
            d1.RollY("R");
            if (d1.Equal(d2)) return true;
            d1.RollY("R");
            if (d1.Equal(d2)) return true;
            d1.RollY("R");
            if (d1.Equal(d2)) return true;
            d1.Init();
        }
        return false;
    }
    
    public static void Main() {
        var n = int.Parse(Console.ReadLine());
        var res = "Yes";
        var d = new Dice(Console.ReadLine().Split().Select(int.Parse).ToArray());
        for (var i = 1; i < n; i++) {
            var cd = new Dice(Console.ReadLine().Split().Select(int.Parse).ToArray());
            if (res == "Yes") res = Check(d, cd) ? "No" : res;
            else continue;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 9416
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	ll N, K;
	string S;
	cin >> N >> S >> K;

	char c = S[K - 1];

	rep(i, N) {
		if (S[i] != c) { S[i] = '*'; }
	}
	cout << S;
	system("PAUSE");
}


Measured memory_bytes: 504
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = lr()
lcm = 1
answer = 0
for a in A:
    coef =  a // gcd(lcm, a)
    answer *= coef
    lcm *= coef
    answer += lcm // a

print(answer%MOD)


Measured memory_bytes: 6136
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

typedef tuple<int,int,int> T;

int main(){
    vector<T> V;
    V.emplace_back(1,0,0);
    V.emplace_back(0,1,0);
    V.emplace_back(0,0,1);
    
    V.emplace_back(1,1,0);
    V.emplace_back(1,-1,0);
    V.emplace_back(1,0,1);
    V.emplace_back(1,0,-1);
    V.emplace_back(0,1,1);
    V.emplace_back(0,1,-1);

    V.emplace_back(1,1,1);
    V.emplace_back(1,-1,1);
    V.emplace_back(-1,1,1);
    V.emplace_back(-1,-1,1);

    int N,M,P;
    while(cin>>N>>M>>P,N){
        int H[N][N];
        int B[N][N][N];
        fill(H[0],H[N],0);
        fill(B[0][0],B[N][0],-1);
        bool Draw=true;
        for(int p=0;p<P;p++){
            int X,Y;
            cin>>X>>Y;
            X--;Y--;
            if(!Draw) continue;
            int Z=H[X][Y]++;
            B[X][Y][Z]=p%2;
            int L=0;
            for(auto v:V){
                int x,y,z;
                tie(x,y,z)=v;
                int i=0,l=1;
                while(true){
                    i++;
                    if(X+x*i<0||X+x*i>=N) break;
                    if(Y+y*i<0||Y+y*i>=N) break;
                    if(Z+z*i<0||Z+z*i>=N) break;
                    if(B[X][Y][Z]!=B[X+x*i][Y+y*i][Z+z*i]) break;
                    l++;
                }
                i=0;
                while(true){
                    i--;
                    if(X+x*i<0||X+x*i>=N) break;
                    if(Y+y*i<0||Y+y*i>=N) break;
                    if(Z+z*i<0||Z+z*i>=N) break;
                    if(B[X][Y][Z]!=B[X+x*i][Y+y*i][Z+z*i]) break;
                    l++;
                }
                L=max(L,l);
            }
            if(L>=M&&Draw){
                cout<<(p%2?"White ":"Black ")<<p+1<<endl;
                Draw=false;
            }
        }
        if(Draw) cout<<"Draw"<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 3084
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream> 

using namespace std;
typedef long long int ll;
typedef long double ld;

//repetition
#define REP(i,n)  for(ll i=0;i<n;i++)

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


int main() {
  ll n,k;
  ll r,s,p;
  cin >> n >> k;
  cin >> r >> s >> p;
  vector<string> v(k, "");
  vector<bool> vb(k, false);

  ll total = 0;

  REP(i, n) {
    char c;
    cin >> c;
    string sc{c};

    //flagが立っている->1個前が同じだった場合はフラグを立ててカウントをしない
    if(v.at(i%k) == sc) {
      if(vb.at(i%k)) {
        if (sc == "p") {
          total = total + s;
        } else if(sc == "r") {
          total = total + p;
        } else if (sc == "s") {
          total = total + r;
        }
        vb.at(i%k) = false;
      } else {
        vb.at(i%k) = true;
      }
    } else {
      if (sc == "p") {
        total = total + s;
      } else if(sc == "r") {
        total = total + p;
      } else if (sc == "s") {
        total = total + r;
      }
      vb.at(i%k) = false;
    }
    v.at(i%k) = sc;
  }

  cout << total << endl;
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
int main()
{
	string S, T, U, K;
	bool ans = false;
	int n;
	cin >> S >> T;
	n = S.size();

	loop(i, 0, n){
		if(S == T){
			ans = true;
			break;
		}
		S = S.back() + S.substr(0, n-1);
	}
	if(ans) cout<<"Yes"<<endl;
	else cout << "No" <<endl;
	return 0;
}

Measured memory_bytes: 256
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

#include <bits/stdc++.h>
using namespace std;

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

int main() {
    int h = read(), w = read(), a = read(), b = read();
    for (int i = 0; i < h; ++i) {
        int c1 = i < b, c2 = c1 ^ 1;
        for (int j = 0; j < w; ++j) {
            putchar(48 ^ (j < a ? c1 : c2));
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = 1e9;


int main()
{
	int h, w;
	vector<vector<bool>> dbl;

	scanf("%d%d", &h, &w);
	dbl.resize(h);
	for(int i = 0; i < h; ++i) {
		dbl[i].resize(w);
		char buf[512];
		scanf("%s", buf);
		for(int j = 0; j < w; ++j)
			dbl[i][j] = (buf[j] == '#');
	}

	vector<vector<bool>> red(h), blue(h);

	for(int i = 0; i < h; ++i) {
		red[i].resize(w);
		blue[i].resize(w);
	}

	for(int i = 0; i < h; ++i) {
		red[i][0] = true;
		blue[i][w - 1] = true;
	}

	for(int i = 0; i < w - 1; ++i)
		red[0][i] = true;

	bool r_main = true;
	int prev_main = 0;

	for(int x = 1; x < h - 1; ++x) {

		bool exist = false;
		vector<vector<bool>>& pri = (r_main ? red : blue);
		vector<vector<bool>>& sub = (r_main ? blue : red);

		for(int y = 1; y < w - 1; ++y) {

			if(!dbl[x][y]) continue;
			exist = true;

			for(int t = prev_main + 1; t <= x; ++t)
				pri[t][y] = true;
		}

		if(exist) {
			for(int y = 1; y < w - 1; ++y)
				sub[x][y] = true;
			r_main = !r_main;
			prev_main = x;
		}
	}

	for(int x = 0; x < h; ++x) {
		for(int y = 0; y < w; ++y)
			printf("%c", red[x][y] ? '#' : '.');
		printf("\n");
	}

	printf("\n");

	for(int x = 0; x < h; ++x) {
		for(int y = 0; y < w; ++y)
			printf("%c", blue[x][y] ? '#' : '.');
		printf("\n");
	}

	for(int x = 0; x < h; ++x) {
		for(int y = 0; y < w; ++y) {
			assert((blue[x][y] && red[x][y]) == dbl[x][y]);
		}
	}

	return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

vector<int> g[maxn];

void bfs(int src, vector<int> &dist, vector<bool> &visited) {
    queue<int> q;
    q.push(src);
    visited[src] = true;
    dist[src] = 0;

    while (!q.empty()) {
        int node = q.front();
        q.pop();
        for (auto x : g[node])
            if (!visited[x]) {
                dist[x] = 1 + dist[node];
                q.push(x);
                visited[x] = true;
            }
    }
}

void solve() {
    int n, x, y;
    cin >> n >> x >> y;

    for (int i = 2; i <= n; i++) {
        g[i].push_back(i - 1);
        g[i - 1].push_back(i);
    }

    g[x].push_back(y);
    g[y].push_back(x);

    map<int, int> an;
    for (int i = 1; i <= n; i++) {
        vector<int> dist(n + 1);
        vector<bool> visited(n + 1);
        bfs(i, dist, visited);
        for (int j = 1; j <= n; j++) {
            if (j == i)continue;
            an[dist[j]]++;
        }
    }
    for (int i = 1; i <= n - 1; i++)cout << an[i]/2 << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 2816
#!/usr/bin/env python3
# coding:utf-8

def main():
    sx, sy, tx, ty = map(int, input().split())
    stdOut = solve(sx, sy, tx, ty)
    print(stdOut)

"""
方針
sx < tx , sy < tyなので
進路としては
1sx,syから右にtx,syまで移動後上にtx,tyまで移動
2tx,tyから左にsx,tyまで移動後下にsx,syまで移動
3下に1移動、右にtx+1,sy-1まで移動、上にtx+1,tyまで移動、左に1移動
4上に1移動、左にsx-1,ty+1まで移動、下にsx-1,syまで移動、右に1移動

"""

up = 'U'
down = 'D'
left = 'L'
right = 'R'

def solve(sx, sy, tx, ty):
    deltax = tx - sx
    deltay = ty - sy
    movelog = ''
    movelog += up * deltay + right * deltax
    movelog += down * deltay + left * deltax
    movelog += down + right * (deltax + 1) + up * (deltay + 1) + left
    movelog += up + left * (deltax + 1) + down * (deltay + 1) + right

    return movelog

if __name__ == "__main__":
    main()


Measured memory_bytes: 9128