akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true){

			String[] token = br.readLine().split(" ");
			int h = Integer.parseInt(token[0]);
			int w = Integer.parseInt(token[1]);

			if(h == 0 && w == 0){
				break;
			}

			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					sb.append("#");
				}
				sb.append("\n");
			}

			sb.append("\n");

		}

		System.out.print(sb);

	}
}

Measured memory_bytes: 25212
#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 ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

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

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector< vector<int> > A;
vector<P> q; // Match queue

// Check the remaining matches. If match can be made, push it to queue.
void check(int i) {
  if (A[i].size() == 0) { return; }
  int j = A[i].back();
  if (A[j].back() == i) {
    if (i > j) { swap(i, j); }  // Force i < j
    q.emplace_back(i, j);
  }
}

int main(int argc, char** argv) {
  int N;
  cin >> N;

  A.assign(N, vector<int>(N-1));
  rep(i, N) {
    rep(j, N-1) {
      cin >> A[i][j];
      --A[i][j];
    }
    reverse(all(A[i]));
  }

  // Push first matches.
  rep(i, N) {
    check(i);
  }

  int day = 0;
  while (q.size() > 0) { // Repeat until match que
    sort(all(q));
    q.erase(unique(all(q)), q.end());

    vector<P> prevQ;
    prevQ.swap(q); // Set q to prevQ, set empty vector to q.
    for (auto p : prevQ) {
      A[p.first].pop_back(); // pop match
      A[p.second].pop_back(); // pop match
    }
    for (auto p : prevQ) {
      check(p.first);
      check(p.second);
    }

    ++day;
  }

  // Check the remaining of A
  rep(i, N) {
    if (A[i].size() != 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << day << endl;
}


Measured memory_bytes: 4224
#include <stdio.h>

#define N_MAX 10000
#define Q_MAX 500

int main(void) {
  int S[N_MAX+1];
  int T[Q_MAX];
  int n, q, i, j, C = 0;

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

  scanf("%d", &q);
  for(i=0; i<q; ++i) {
    scanf("%d", &T[i]);
  }

  for(i=0; i<q; ++i) {
    S[n] = T[i];

    for(j=0; j<n; ++j) {
      if(S[j] == T[i]) break;
    }

    if(j != n) ++C;
  }

  printf("%d\n", C);

  return 0;
}



Measured memory_bytes: 2144
n = int(input())
s_p_index = []
for i in range(n):
    s, p = input().split()
    s_p_index.append([s, int(p), i+1])

s_p_index.sort(key=lambda x:(x[0],-x[1]))

for i in range(n):
    print(s_p_index[i][2])

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

	        int N = sc.nextInt();


            String ans1 = "Hello World";

     
             int n1 = 1;
             
             

             
             if( N == 1){
            	System.out.println(ans1);
            
            } else{

                int A = sc.nextInt();
                int B = sc.nextInt();

                int ans2 = A+B;
            	
            	System.out.println(ans2);        	     
            }
        }
            }


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

#define ll long long

const ll mod = 998244353;
int N, S, A[3001];
ll dp[3001][3001][3];

void solve() {
	cin >> N >> S;
	for (int i=0; i<N; ++i)
		cin >> A[i+1];
	dp[0][0][0] = 1;
	for (int i=1; i<=N; ++i) {
		for (int j=0; j<=S; ++j) {
			dp[i][j][0] += (dp[i-1][j][0] + (j >= A[i] ?  dp[i-1][j-A[i]][0] : 0));
			dp[i][j][1] += (dp[i-1][j][1] + (j >= A[i] ?  dp[i-1][j-A[i]][1] : 0));
			if (j == 0)
				dp[i][j][1] += dp[i-1][j][0];
			if (j == A[i])
				++dp[i][j][1];	
			dp[i][j][0] %= mod;
			dp[i][j][1] %= mod;
			dp[i][j][2] = (dp[i][j][1] + dp[i-1][j][2])%mod;
		}
	}
	cout << dp[N][S][2] << endl;
}


int main() {
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 214688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)

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

	ll n,h,w;
	cin >> n >> h >> w;
	cout << (n-h+1)*(n-w+1) << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rg register
#define ll long long
using namespace std;
const int N=3e2+5,mod=1e9+7;
int n,m,T,k,ans,len;
//int a[N],vis[N],dp[N];
struct node
{
    int x,y;
}a[N];
bool cmp(node xx,node yy)
{
    return xx.y<yy.y;
}
int main()
{
    ll ans=0;
    for(rg int i=1;i<=5;i++)
    {
        cin>>a[i].x;
        a[i].y=(10-a[i].x%10)%10;
        ans+=a[i].x;
    }
    sort(a+1,a+6,cmp);
    for(rg int i=1;i<5;i++)
        ans+=a[i].y;
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	vector<int> a,b;
	for(int i=1;i<=sqrt((double)m);i++){
		if(m%i==0){
			a.push_back(i);
			b.push_back(m/i);
		}
	}
	int s=a.size();
	for(int i=0;i<s;i++){
		if(m/b[i]<n) continue;
		cout<<b[i]<<endl;
		return 0;
	}
	for(int i=s-1;i>=0;i--){
		if(m/a[i]<n) continue;
		cout<<a[i]<<endl;
		return 0;
	}
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	long ans;
	foreach (i; 1..N+1)
	{
		auto cnt = i.to!string.length;
		if (cnt % 2 == 1)
			++ans;
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 1276
n = int(input())
a = list(map(int, input().split()))
mx = []
mn = []
for i in range(n):
  mx.append(max(a[i], mx[-1] if mx else 0))
c = 0
for i in range(n)[::-1]:
  if i > 0 and mx[i - 1] > a[i]:
    c += mx[i - 1] - a[i]
print(c)

Measured memory_bytes: 32240
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
s = []
for i in range(m):
  x, y, c = map(int, input().split())
  s.append(A[x-1] + B[y-1] - c)
s.append(min(A) + min(B))
print(min(s))

Measured memory_bytes: 18736
class Combination:
    def __init__(self, mod, max_n):
        self.MOD = mod
        self.MAX_N = max_n

        self.f = self.factorial(self.MAX_N)
        self.f_inv = [self.inv(x) for x in self.f]

    def inv(self,x):
        return pow(x, self.MOD-2, self.MOD)
    
    def factorial(self, n):
        res = [1]
        for i in range(1,n+1):
            res.append(res[-1] * i % self.MOD)
        return res
    
    def comb(self, n, r):
        return (self.f[n] * self.f_inv[r] % self.MOD) * self.f_inv[n-r] % self.MOD


S = int(input())
CB = Combination(10**9+7, S)

ans = 0
for i in range(1,S):
    if S - 3*i < 0: break
    ans += CB.comb(S-2*i-1,i-1)
    ans %= CB.MOD
print(ans)

Measured memory_bytes: 64984
#include<stdio.h>
#include<stdlib.h>
#define MAX (2000000 + 1)
typedef struct node{
  int key;
  struct node *p, *l, *r;
}T_node;
T_node **heap;
int n;
void mahpy(int);
void insert(int);
int extract();
int main(){
  char buf[256];
  int v;
  n = 0;
  heap = (T_node **)malloc(sizeof(T_node *) * MAX);
  int i;
  for(i = MAX; i > MAX / 2; i--){
    heap[i] = (T_node *)malloc(sizeof(T_node));
    heap[i]->key = -1;
    heap[i]->p = heap[i]->l = heap[i]->r = NULL;
  }
  for(i = MAX / 2; i > 0; i--){
    heap[i] = (T_node *)malloc(sizeof(T_node));
    heap[i]->key = -1;
    heap[i]->l = heap[i * 2];
    heap[i]->r = heap[i * 2 + 1];
    heap[i * 2]->p = heap[i * 2 + 1]->p = heap[i];
  }
  heap[1]->p = NULL;
  while(scanf("%s", buf) & strcmp(buf, "end")){
    if(!strcmp(buf, "insert")){
      n++;
      scanf("%d", &v);
      insert(v);
    }
    else if(!strcmp(buf, "extract")){
      printf("%d\n", extract());
      n--;
    }
  }
  for(i = MAX; i > 0; i--)
    free(heap[i]);
  free(heap);
  return 0;
}

void insert(int v){
  heap[n]->key = v;
/*  if(n /2){
    heap[n]->p = heap[n / 2];
    if(n % 2)
      heap[n / 2]->r = heap[n];
    else
      heap[n / 2]->l = heap[n];
  }*/
  T_node *ma;
  for(ma = heap[n]; ma->p != NULL; ma = ma->p){
    if(ma->key > ma->p->key){
      ma->key = ma->p->key;
      ma->p->key = v;
    }
    else
      break;
  }
/*  int i;
  for(i = n / 2; i > 0; i--)
    mahpy(i);*/
}

int extract(){
  int tmp = heap[1]->key;
  heap[1]->key = heap[n]->key;
  heap[n]->key = -1;
/*  heap[1]->key = -1;*/
  //  int i;
  //  for(i = n / 2; i > 0; i--)
    mahpy(1);
  return tmp;
}

void mahpy(int i){
  T_node *max;
  int tmp, ni = 0;
  if(heap[i]->r != NULL){
    if(heap[i]->l->key >= heap[i]->r->key){
      max = heap[i]->l;
            if(max->key >= 0)
	ni = i * 2;
    }
    else{
      max = heap[i]->r;
            if(max->key >= 0)
	ni = i * 2 + 1;
    }
  }
  else if(heap[i]->l != NULL){
    max = heap[i]->l;
        if(max->key >= 0)
      ni = i * 2;
  }
  else
    max = heap[i];
  if(max->key > heap[i]->key){
    tmp = heap[i]->key;
    heap[i]->key = max->key;
    max->key = tmp;
  }
  if(ni)
    mahpy(ni);
  else if(heap[i]->key < 0){
    heap[i]->key = heap[n]->key;
    heap[n]->key = -1;
/*    heap[n]->p = heap[n]->l = heap[i]->r = NULL;
    if(n % 2)
      heap[n / 2]->r = NULL;
    else
      heap[n / 2]->l = NULL;*/
  }
}

Measured memory_bytes: 109780
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>arr(n);
  for(int i=0;i<n;i++)cin>>arr[i];
  vector<bool>visited(1000001,true);
  sort(arr.begin(),arr.end());
  unordered_map<int,int>m;
  for(int i=0;i<n;i++){
    m[arr[i]]++;
  }
  for(auto i:m){
    if(visited[i.first]){
        for(int j=2*i.first;j<1000001;j+=i.first){
            visited[j]=false;
        }
    }
  }
  int ans=0;
  for(auto i:m){
    if(i.second<=1 && visited[i.first])ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12272
# encoding: utf-8
N = int(input())
X = list(map(int, input().split()))

X_sort = sorted(X)
m = X_sort[N // 2]

for i, Xi in enumerate(X):
    if N % 2:
        if Xi <= m: print(X_sort[N // 2 + 1])
        else: print(m)
    else:
        if Xi >= m: print(X_sort[N // 2 - 1])
        else: print(m)


Measured memory_bytes: 26016
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    student = []
    for _ in range(N):
        a, b = map(int, input().split())
        student.append((a, b))
    checkpoint = []
    for _ in range(M):
        c, d = map(int, input().split())
        checkpoint.append((c, d))

    for a, b in student:
        point, dist = -1, 10**18
        for i in range(M):
            c, d = checkpoint[i]
            if abs(a - c) + abs(b - d) < dist:
                point = i
                dist = abs(a - c) + abs(b - d)
        print(point + 1)



if __name__ == "__main__":
    main()


Measured memory_bytes: 67304
#include <bits/stdc++.h>
using namespace std;
 
 
 
 
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> v;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        v.push_back(x);
    }
    
    int dp[100005];
    dp[0]=-1;
    for(int i=1;i<=k;i++){
        bool found=false;
        for(int j=0;j<n;j++){
            if(i-v[j]>=0){
                if(dp[i-v[j]]==-1){
                    found=true;
                    break;
                }
            }
        }
        if(found){
            dp[i]=1;
        }
        else{
            dp[i]=-1;
        }
    }
   
   if(dp[k]==1){
       cout<<"First";
   }
   else{
       cout<<"Second";
   }
 
 
 
}

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

using namespace std;

#define int long long

signed main(){
	int n;
	cin >> n;
	int C[n+1][3];
	C[0][0]=1;
	for(int i=1;i<=n;i++){
		C[i][0]=1;
		if(i<=2)
			C[i][i]=1;
		for(int j=1;j<i&&j<=2;j++){
			C[i][j]=C[i-1][j]+C[i-1][j-1];
			//cout << "i " << i << " j " << j << " C " << C[i][j] << endl;
		}
	}
	int a[n];
	int cnt[n+1]={0};
	for(int i=0;i<n;i++){
		cin >> a[i];
		cnt[a[i]]++;
	}
	int tot=0;
	for(int i=1;i<=n;i++){
		if(cnt[i]>=2){
			//cout << cnt[i] << " " << i << " " << C[cnt[i]][2] << endl;
			tot+=C[cnt[i]][2];
		}
	}
	//cout << "tot " << tot << endl;
	for(int i=0;i<n;i++){
		if(cnt[a[i]]<2){
			cout << tot << endl;
		}
		else if(cnt[a[i]]-1<2){
			cout << tot-C[cnt[a[i]]][2] << endl;
		}
		else{
			cout << tot-C[cnt[a[i]]][2]+C[cnt[a[i]]-1][2] << endl;
		}
	}
}

Measured memory_bytes: 10876
#include<bits/stdc++.h>
#define int long long
#define vin vector<int>
#define vcn vector<char>
#define ver pair<int,int>
#define ld long double
#define pb push_back
#define x first
#define y second
#define blush fflush(stdout);fflush(stdin);
#define $(a) (int)a.size()
#define scanf ;
#define printf ;
using namespace std;
void i_love_misaka_mikoto();
int32_t main(){
    #ifdef RNS
        freopen("input.txt","r",stdin);
        #ifndef DBG
        freopen("output.txt","w",stdout);
        #endif
    #else
        ios_base::sync_with_stdio(false);
    #endif
    i_love_misaka_mikoto();
    #ifdef RNS
        cout<<'\n'<<(ld)clock()/CLOCKS_PER_SEC<<" セクンド\n";
    #endif
    return 0;
}

void i_love_misaka_mikoto(){
    int n;
    cin>>n;
    multiset<int> s;
    for(int i=0,v;i<n;i++){
        cin>>v;
        s.insert(v);
    }
    //while(s.size()>1){
        for(auto it=s.begin();it!=s.end();it++){
            if(*it%*s.begin()!=0){
                int b=*it;
                s.erase(it);
                s.insert(b%*s.begin());
            }
        }
    //}
    cout<<*s.begin();
}

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

#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

const int N=3005;
ll dp[N][N][4];
int v[N][N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,K;
    cin>>n>>m>>K;
    for(int i=0;i<K;i++){
        int x,y,val;
        cin>>x>>y>>val;
        x--,y--;
        v[x][y]=val;
    }
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) for(int k=0;k<4;k++) dp[i][j][k]=-1e18;
    dp[0][0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            for(int k=2;k>=0;k--){
                if(dp[i][j][k]>=0)   dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+v[i][j]);
            }
            for(int k=0;k<4;k++){
                if(dp[i][j][k]>=0){
                    if(i+1<n) dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
                    if(j+1<m) dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
                }
            }
        }
    }
    ll ans=-1e18;
    for(int i=0;i<4;i++) ans=max(ans,dp[n-1][m-1][i]);
    cout<<ans;
    return 0;
}



Measured memory_bytes: 320416
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int K = in.i();
        int[] p = in.ii(N);
        int[] sum = new int[N + 1];
        for (int i = 0; i < N; i++) {
            sum[i + 1] = sum[i] + p[i];
        }

        int ans = 0;
        for (int i = 0, M = N - K + 1; i < M; i++) {
            ans = Math.max(sum[i + K] - sum[i] + K, ans);
        }
        out.println(ans / 2.0);
    }

    static class MyReader extends BufferedReader {
        char[] cbuf = new char[1 << 16];
        int head = 0;
        int tail = 0;

        MyReader(){
            super(new InputStreamReader(System.in));
        }

        char next() {
            if (head == tail) {
                try {
                    tail = super.read(cbuf, 0, cbuf.length);
                } catch (IOException e) {}
                head = 0;
            }
            return cbuf[head++];
        }

        void back() {
            head--;
        }

        int i() {
            boolean minus;
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    if (!(minus = c == '-')) back();
                    break;
                }
            }
            int n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            for (int j = 0; j < a.length; j++) a[j] = i();
            return a;
        }
    }
}


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

int main(){
  ll n1, n2, num=0;
  cin >> n1;
  n2 = n1;
  int len_n = to_string(n1).length();
  for(int i=1;i<=len_n;i++){
    num += (n1 % 10);
    n1 /= 10;
  }
  if (n2 % num == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=5e5+5;
char s[N];int a[N],b[N],c[N],st[N],n,res,tot,t;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%s",&n,s+1);
	fp(i,1,n)a[i]=s[i]-'0';
	n<<=1;
	fp(k,1,n)if(n%k==0&&((n/k)&1)){
		++tot,b[tot]=k,c[tot]=0;
		fp(i,1,k>>1)c[tot]=((c[tot]<<1ll)+a[i])%P;
		fp(i,1,k>>1)st[i]=a[i];
		fp(i,(k>>1)+1,n>>1)st[i]=st[i-(k>>1)]^1;
		++c[tot];
		fp(i,(k>>1)+1,n>>1)if(a[i]!=st[i]){
			c[tot]-=(a[i]<st[i]);
			break;
		}
	}
	fp(i,1,tot)fp(j,1,i-1)if(b[i]%b[j]==0)upd(c[i],P-c[j]);
	fp(i,1,tot)upd(res,mul(c[i],b[i]));
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

vector<int> dijkstra(int i, int n, vector<vector<pair<int, int>>> graph) {
  vector<int> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}

signed main() {
  int N, M; 
  cin >> N >> M;

  vector<vector<pair<int, int>>> graph(N);
  REP(i, M){
    int u, v, d;
    cin >> u >> v >> d;
    u--; v--;
    graph[u].emplace_back(v, d);
  }
  REP(i, N-1){
    graph[i+1].emplace_back(i, 0);
  }

  auto dist = dijkstra(0, N, graph);

  if(dist[N-1] == INF) dist[N-1] = -1;
  cout << dist[N-1] << "\n";

  return 0;
}

Measured memory_bytes: 15992
// abc059.a

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	int t = a + b;
	if (t >= 24) {
		cout << t - 24 << endl;
	} else {
		cout << t << endl;
	}
}

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

vector<vector<int>> G(100001);
int dis[100001];
int depth[100001];
bool visited[100001];
bool reachable[100001];

int f(int x){
	return max(0LL, x - 1);
}

void dfs1(int st, int d){
	visited[st] = 1;
	dis[st] = d;
	for(auto i : G[st]){
		if(!visited[i]){
			dfs1(i, d + 1);
		}
	}
}

void dfs2(int st, int d){
	visited[st] = 1;
	depth[st] = d;
	for(auto i : G[st]){
		if(!visited[i]){
			dfs2(i, d + 1);
		}
	}
}

int32_t main(){
	int n, a, b;
	cin >> n >> a >> b;
	for(int i = 0; i < n - 1; i++){
		int v1, v2;
		cin >> v1 >> v2;
		G[v1].push_back(v2);
		G[v2].push_back(v1);
	}
	dfs1(a, 0);
	fill(visited, visited + n + 1, 0);
	dfs2(b, 0);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(dis[i] < depth[i]){
			ans = max(ans, dis[i] + f(depth[i] - dis[i]));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 10112
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v = read_vec::<i32>();
    if v[0] * v[1] % 2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}


Measured memory_bytes: 4352
import java.util.Map.Entry;
import java.util.*;
 
//import org.w3c.dom.css.Counter;
 
public class Main {
//public class App {
 
    public static void main(final String[] args){
     //スキャン
     final Scanner s = new Scanner(System.in);
      int A = Integer.parseInt(s.next());
      int B = Integer.parseInt(s.next());
      int C = Integer.parseInt(s.next());
     final int X = Integer.parseInt(s.next());
     int count =0;
    
     while (A>=B) {
        B = B *2;
        //System.out.println(B);
        count++;
     }
    
     while (B>=C) {
        C = C *2;
        //System.out.println(B);
        count++;
     }
     if(count<=X){
        System.out.println("Yes");
     }else{
        System.out.println("No");
     }
     
 

    
/*
     for(int i=0; i< K;i++){
        int di = Integer.pa rseInt(s.next());
        String blank = s.nextLine();
        String huge = s.nextLine();

        String[] hage = huge.split(" ",0);
        int hageN= hage.length;
        for (int num =0;num<hageN;num++){
            if(!hashSet.contains(hage[num])){
                hashSet.add(hage[num]);
            }
        }

     }
     s.close();

     System.out.println(N-hashSet.size());


}
*/
}
}

Measured memory_bytes: 35636
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//split delimiter??§?????????
vector<string> split(const string &input, char delimiter) {
	vector<string> ret;
	istringstream stream(input);
	string s;
	while (getline(stream, s, delimiter)) ret.push_back(s);
	return ret;
}
string stoupper(string s) { transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
string stolower(string s) { transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }

signed main() {
	for (string s, t; cin >> s >> t&&t != "X";) {
		vector<string> a;
		if (s.find("_") != string::npos) {
			a = split(s, '_');
		}
		else {
			int l = 0;
			rep(i, 1, s.size()) {
				if (isupper(s[i])) {
					a.push_back(stolower(s.substr(l, i - l)));
					l = i;
				}
			}
			a.push_back(stolower(s.substr(l, s.size())));
		}
		string ans = "";
		if (t == "L") {
			ans += a[0];
			rep(i, 1, a.size()) {
				a[i][0] = toupper(a[i][0]);
				ans += a[i];
			}
		}
		else if (t == "U") {
			rep(i, 0, a.size()) {
				a[i][0] = toupper(a[i][0]);
				ans += a[i];
			}
		}
		else {
			ans += a[0];
			rep(i, 1, a.size()) {
				ans += "_" + a[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define ll long long

#define loop(i,start,end,in) for (int i=start;i<end ;i = i+in)
#define rloop(i,start,end,in) for (int i=start;i>end ;i = i-in)

int main()
{

    ll x,k,d;
    cin>>x>>k>>d;

    if(x<0)
        x = -x;
    ll tm = x/d ;
    if(x%d)tm++;
    if(k<tm)
    {
        cout<<abs(x - (k*d))<<endl;
    }
    else
    {
        ll st = k-tm;
        if(st%2)
            cout<<abs(x - ((tm-1)*d))<<endl;
        else
            cout<<abs(x - (tm*d))<<endl;
    }

}





Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::set;
using std::vector;
using std::pair;
using std::make_pair;
using std::priority_queue;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

#define INF 0x7fffffffffffffff

ull i, j, k, l, m, n;
ull H, W, Q;
ull a, b, c, x, y,p;
ull K, L, N, M;
string str;

int main()
{
	cin >> N;
	c = 0;
	x = 0;
	for (i = 1; i <= N; ++i)
	{
		cin >> p;
		if (x)
		{
			c++;
			x = 0;
		}
		else
		{
			if (p == i)
			{
				x++;
				if (i == N)c++;
			}
		}
	}
	cout << c << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {

  import ExtendedString._

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val cards = Vector.fill(n)(sc.next())

    val bubCared = bub(n, ArrayBuffer.apply(cards: _*))
    val selCared = sel(n, ArrayBuffer.apply(cards: _*))
    println(bubCared.mkString(" "))
    println(isStable(cards, bubCared.toVector))
    println(selCared.mkString(" "))
    println(isStable(cards, selCared.toVector))
  }

  def bub(n: Int, cards: ArrayBuffer[String]): ArrayBuffer[String] = {
    (0 to n - 1).foreach { i =>
      (n - 1 to(i + 1, -1)).foreach { j =>
        if (cards(j).getCardValue < cards(j - 1).getCardValue) {
          val cj = cards(j)
          val cjMinusOne = cards(j - 1)
          cards(j) = cjMinusOne
          cards(j - 1) = cj
        }
      }
    }
    cards
  }

  def sel(n: Int, cards: ArrayBuffer[String]): ArrayBuffer[String] = {
    (0 to n - 1).foreach { i =>
      var minj = i
      (i to n - 1).foreach { j =>
        if (cards(j).getCardValue < cards(minj).getCardValue) {
          minj = j
        }
      }
      val ci = cards(i)
      val cmin = cards(minj)
      cards(i) = cmin
      cards(minj) = ci
    }
    cards
  }

  def isStable(before: Vector[String], after: Vector[String]): String = {
    val afterGroup = after.groupBy(_.getCardValue)
    before.groupBy(_.getCardValue).forall { case (i, b) =>
      afterGroup(i) == b
    } match {
      case true => "Stable"
      case false => "Not stable"
    }
  }

}

object ExtendedString {

  implicit class CardString(str: String) {
    def getCardValue = str.last.toInt
  }

}


Measured memory_bytes: 45396
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll W, H, x, y;

void solve() {
	cin >> W >> H >> x >> y;
	cout << W * H / 2.0 << " ";
	if(x * 2 == W && y * 2 == H) cout << 1 << "\n";
	else cout << 0 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
  Edge(){}
};

int main() {
  int n;
  while(cin >> n,n) {
    Edge g[n][2];
    REP(i, n) {
      int a,p,b,q;
      cin >>a>>p>>b>>q;
      g[i][0] = Edge(i,a,p);
      g[i][1] = Edge(i,b,q);
    }
    vector<bool> visited(n);
    long long res = 1;
    REP(i,n) {
      int cnt = 1;
      int ma = -INF;
      //     cout << "i=" << i << endl;
      Edge now = g[i][0];
      while(1) {
        if (visited[now.dst]) break;
        visited[now.dst] = 1;
//        printf("%d,%d,%d %d\n",now.src,now.dst, now.weight,ma);
        if(now.weight > ma) {
          ma = now.weight;
          cnt = 1;
        } else if (now.weight == ma) {
          cnt++;
        }
        if (g[now.dst][0].dst != now.src)
          now = g[now.dst][0];
        else
          now = g[now.dst][1];
      }
//      cout << cnt << endl;
      res = (res * cnt) % 10007;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <climits>
#include <utility>
#include <map>
#include <set>
#include <complex>
#include <numeric>

#include <time.h>
#include <float.h>

#define loop(i, start, end) for(i = (start); i <= (end); i++)
#define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
#define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
#define loopRev(i, start, end) for(i = (start); i >= (end); i--)
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCases(t) cin >> t; while(t--)
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PNN1(n) cout << (n) << endl
#define PNN2(a, b) cout << (a) << " " << (b) << endl
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define PrintArray(ar, n) for(i = 0; i < n; i++) cout << ar[i] << " "; cout << endl
#define PrintObject(ar, it) loopIterators(it, ar) cout << *it << " "; cout << endl
#define PrintMap(map, it) loopIterators(it, map) PNN2(it->first, it->second)
#define sz(a) sizeof(a)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define SWAP(a, b, c) c = a; a = b; b = c
#define STRSP(s) scanf("%[^\n]%*c", s)
#define ENTER PNN1("");
#define MOD7 1000000007
#define MOD9 10000009
#define MAX 1000000000
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int, int>
#define ONLINE_JUDGE

typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
typedef long double ld;

using namespace std;

bool isPalin(std::string s) {
	int i = 0, j = s.length() - 1;
	while(i < j) if(s.at(i++) != s.at(j--)) return false;
	return true;
}

int main(void){
	FLASH

	#ifndef ONLINE_JUDGE
		freopen("input-stream.txt", "r", stdin);
		freopen("output-stream.txt", "w", stdout);
	#endif

	std::string s;
	IN1(s);
	int n = s.length();

	PNN1(isPalin(s) && isPalin(s.substr(0, n - 1 >> 1)) && isPalin(s.substr((n + 3) / 2 - 1))? "Yes": "No");

	#ifndef ONLINE_JUDGE
		fclose(stdin);
		fclose(stdout);
	#endif

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}


int main() {
    int k,s;
    cin >> k >> s;
    int cnt = 0;
    for(int i = 0;i <= k;i++){
        for(int j =0;j <= k;j++){
            if(s-(i+j) <= k && s-(i+j) >= 0){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}




Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7


a,b,c,d = rm()
if a+b > c+d:
  print('Left')
else:
  print('Balanced' if a+b == c+d else 'Right')









Measured memory_bytes: 26848
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    long long n;
    cin >> n;
    cout << n << ":";
    long long x=n;
    for(long long i=2; i*i<=x; i++){
        if(n%i==0){
            while(n%i==0){
                cout << ' ' << i;
                n/=i;
            }
        }
    }
    if(n>1) cout << ' ' << n;
    cout << endl;
}



Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int h, w, n;
Int r, c;
string s, t;
Int uds[216000], udt[216000], lrs[216000], lrt[216000];

bool win(Int *s, Int *t, Int pos, Int len){
    Int losel = 1, loser = len;
    for(int i = n-1;i >= 0;i--){
//        cout << losel << " " << loser << endl;
        if(t[i] == 1)losel = max(1LL, losel-1);
        if(t[i] == -1)loser = min(loser + 1, len);
        if(s[i] == 1)loser--;
        if(s[i] == -1)losel++;
        if(loser < losel)return true;
    }
    if(pos < losel || loser < pos)return true;
    return false;
}

void ok(){
    cout << "YES" << endl;
    exit(0);
}

void ng(){
    cout <<  "NO" << endl;
    exit(0);
}

int main(){
    cin >> h >> w >> n;
    cin >> r >> c;
    cin >> s >> t;
    for(int i = 0;i < n;i++){
        if(s[i] == 'U')uds[i] = -1;
        if(s[i] == 'D')uds[i] = 1;
        if(s[i] == 'L')lrs[i] = -1;
        if(s[i] == 'R')lrs[i] = 1;
        if(t[i] == 'U')udt[i] = -1;
        if(t[i] == 'D')udt[i] = 1;
        if(t[i] == 'L')lrt[i] = -1;
        if(t[i] == 'R')lrt[i] = 1;
    }
    if(win(uds, udt, r, h))ng();
    if(win(lrs, lrt, c, w))ng();
    ok();
    return 0;
}

Measured memory_bytes: 7304
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
    int a,b;
    cin>>a>>b;
    cout<<max(a-2*b,0LL)<<endl;
   
   
    return 0;
}

Measured memory_bytes: 256
/*
 * Author : Sadi
 * Mon 20/07/2020
 * 13:50:20.07
 */
#include <bits/stdc++.h>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    vector<int> v(n);
    int L = 1e5, R = - 1e5;
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        L = min(L, v[i]);
        R = max(R, v[i]);
    }
    int ans = 1e9;
    for(int i = L; i <= R; ++i) {
        int cost = 0;
        for(int j = 0; j < n; ++j) {
            cost += (v[j] - i) * (v[j] - i);
        }
        ans = min(ans, cost);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
 
using namespace std;
 
 
int main()
{
	int a,b ,c;
	int  k;
	cin >> a >> b>>c;
	cin >> k;
	cout << a + b + c + max(max(a, b), c)*(pow(2, k) - 1)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        String[] s1 = stdIn.next().split("");
        String[] s2 = stdIn.next().split("");
        String[] s3 = stdIn.next().split("");

        System.out.println(s1[0].toUpperCase()+s2[0].toUpperCase()+s3[0].toUpperCase());


    }
}


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

int main(){
  int A,B,C,K;
  int x=0;
  cin >> A >> B >> C >> K;
  
  if(K>=A+B){
    x+=A-(K-(A+B));
  }
  else if(K>=A){
    x+=A;
  }
  else{
    x+=K;
  }
  cout << x << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin >> s;
    cin >> t;
    int cnt = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] != t[i])
            cnt++;
    }
    cout << cnt;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

ll dp[10101][105][2];
string K;
ll D;

ll rec(ll i, ll sum, bool tight){
	if(dp[i][sum][tight]>=0) return dp[i][sum][tight];
	if(i==K.size()) return (sum%D==0);

	ll r = (tight?K[i]-'0':9);

	ll res = 0;
	for(int k=0;k<=r;k++){
		res += rec(i+1, (sum+k)%D, tight&&(k==r));
		res %= mod;
	}
	dp[i][sum][tight] = res;
	return res;
}

int main(){
	cin >> K >> D;
	memset(dp, -1, sizeof(dp));

	cout << (rec(0, 0, true) + mod - 1)%mod << endl;

    return 0;
}

Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N; cin >> N;
    int X; cin >> X;
    int T; cin >> T;
    int ans = 0;
    int tako = 0;

    while(true){
        ans += T;
        tako += X;
        if(tako >= N){
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616