akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'



using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
		ll n;
        cin>>n;
        map<char,ll>m1;
        string s;
        cin>>s;
        ll i,j;
        rep(i,0,n)
        {
            if(!m1[s[i]])
            {
                m1[s[i]]=1;
            }
            else
                m1[s[i]]++;
        }
        ll ans;
        ans=1;
        for(auto i:m1)
        {
            ans=(ans*(i.S+1)%hell)%hell;
        }
        cout<<ans-1;

	
	return 0;
}

Measured memory_bytes: 640
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Measured memory_bytes: 9256
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

string str;
int p, q, r;

int negation( int &pt);
int prod( int x, int y );
int disj( int x, int y );
int calc( int &pt );
int getv( char ch);
int getlhs( int &pt );
int getrhs( int &pt );

int solve(){

	int cnt = 0;
	cin >> str;
	if( str == "." ) { return 0; }
	
	
	for( p = 0; p < 3; p++ )
		for( q = 0; q < 3; q++ )
			for( r = 0; r < 3; r++ ) {
				int ptr = 0;
				if( calc( ptr ) == 2 )
					cnt ++;
			}

	cout << cnt << endl;

	return 1;

}

int main( void ) {

	while( solve() ) {}

	return 0;
}

int getvalue( int &pt ) {
	switch( str[pt] ) {
		case '0':
			return 0;
		break;
		case '1':
			return 1;
		break;
		case '2':
			return 2;
		break;
		case 'P':
			return p;
		break;
		case 'Q':
			return q;
		break;
		case 'R':
			return r;
		break;
	}
	return 0;
}
int negation( int &pt ) {
	if( str[pt] == '-' ) {
		pt ++;
		return 2 - negation(pt);
	}
	if( str[pt] == '(' ) {
		pt ++;
		return 2-calc(pt);
	}
	int ret = 2-getvalue(pt);
	pt ++;
	return ret;
}
int disj( int x, int y ) {
	//?????????
	if( x == y ) { return x; }
	if( x + y > 2 ) { return 2; }
	return x + y;
}
int prod( int x, int y ) {
	//?????????
	if( x == 0 || y == 0 ) { return 0; }
	if( x == 2 && y == 2 ) { return 2; }
	return 1;
}

int calc( int &pt ) {

	//?????????????????????
	int lhs;
	if( str[pt] == '-' ) {
		lhs = negation(++pt);
	} else if( str[pt] == '(' ) {
		lhs = calc(++pt);
	} else {
		lhs = getvalue(pt);
		++pt;
	}

	
	//????????????lhs?????????
	if( ( pt >= str.length() - 1 ) || ( str[pt] == ')' ) ) {
		++pt;
		return lhs;
	}

	//?????????????????????
	char op = str[pt];
	++pt;

	//?????????????????????
	int rhs;
	if( str[pt] == '-' ) {
		rhs = negation(++pt);
	} else if( str[pt] == '(' ) {
		rhs = calc(++pt);
	} else {
		rhs = getvalue(pt);
		++pt;
	}

	if( pt < str.length() && str[pt] == ')' ) {
		pt ++;
	}


	switch( op ) {
		case '+':
			return disj( lhs, rhs );
		break;
		case '*':
			return prod( lhs, rhs );
		break;
	}

	return -1;

}

Measured memory_bytes: 3036
#include <stdio.h>

int main(void){

int n,k;
scanf("%d %d",&n,&k);

int p[1005];

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

int tmp;

for(int j=0;j<n-1;j++){
        for(int i=0;i<n-j-1;i++){
                if(p[i]>p[i+1]){
                        tmp=p[i];
                        p[i]=p[i+1];
                        p[i+1]=tmp;
                }   
        }   
}

int ans = 0;

for(int i=0;i<k;i++){
        ans+=p[i];
}

printf("%d\n",ans);
return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

int main() {
    ios::sync_with_stdio(false);
    int k;
    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> k;

    cout << v[k - 1] << endl;
    return 0;
}


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

int main()
{
  int n, a;
  cin >> n >> a;
  vector<int> x;
  for (int i = 0; i < n; i++) {
	int t;
	cin >> t;
	x.push_back(t);
  }
  sort(x.begin(), x.end());
  vector<vector<vector<long long>>> dp(n+1,vector<vector<long long>>(n+1, vector<long long>(x.back() * n + 1)));
  dp[0][0][0] = 1;
  for (int i = 1; i < n + 1 ; i++) {
	for (int j = 0; j < n + 1; j++) {
	  for (int k = 0; k < x.back() * n + 1; k++) {
		if (k < x[i-1]) {
		  dp[i][j][k] = dp[i - 1][j][k];
		  continue;
		}
		if (k >= x[i - 1] && j >= 1) {
		  dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
		  continue;
		}
	  }
	}
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
	ans += dp[n][i][a * i];
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 52224
import string
def solve(s):
    if len(s) < 26: # なにかの文字を末尾に追加できる
        for c in string.ascii_lowercase:
            if not c in s:
                return s + c
    # 繰り上げが存在
    i = len(s) - 2
    while i >= 0:
        for cand in sorted(s[i+1:]):
            if s[i] < cand:
                return s[:i] + cand
        i -= 1
    return -1

assert solve("atcoder") == "atcoderb"
assert solve("abc") == "abcd"
assert solve("zyxwvutsrqponmlkjihgfedcba") == -1
assert solve("abcdefghijklmnopqrstuvwzyx") == "abcdefghijklmnopqrstuvx"
s = input()
print(solve(s))

Measured memory_bytes: 4084
def main():
    s = input()

    n = len(s)
    pre = s[:(n-1)//2]
    suf = s[(n+3)//2-1:]
    print('Yes' if s == s[::-1] and pre == pre[::-1] and suf == suf[::-1] else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#define toggle(X) ((X) ? 0 : 1)
using namespace std;
using ll = long long;

string s;
ll x, y;
bool dp[2][8005][2 * 8005];
vector<ll> cmp;

int main() {
    cin >> s;
    cin >> x >> y;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            cmp.push_back(-1);
        }
        else {
            if (cmp.size() == 0 ||
                cmp.back() == -1) {
                cmp.push_back(1);
            }
            else {
                cmp.back()++;
            }
        }
    }

    int sw = 0;
    x += 8005;
    y += 8005;

    if (cmp.front() == -1) {
        sw = 1;
        dp[0][0][8005] = true;
        dp[1][0][8005] = true;
    }
    else {
        dp[0][0][8005 + cmp.front()] = true;
        dp[1][0][8005] = true;
    }

    for (int i = 1; i < cmp.size(); i++) {
        if (cmp[i] == -1) {
            sw = toggle(sw);
            for (int j = 0; j < 2 * 8005; j++) {
                dp[0][i][j] = dp[0][i - 1][j];
                dp[1][i][j] = dp[1][i - 1][j];
            }
            
            continue;
        }

        for (int j = 0; j < 2 * 8005; j++) {
            if (dp[sw][i - 1][j]) {
                dp[sw][i][j + cmp[i]] = true;
                dp[sw][i][j - cmp[i]] = true;
            }

            dp[toggle(sw)][i][j] = dp[toggle(sw)][i - 1][j];
        }
    }
    
    if (dp[0][cmp.size() - 1][x] && dp[1][cmp.size() - 1][y]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 250624
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;


int main()
{
	ll i, j, k, l, m, flag, N, M,K;
	char S[200001];
	cin >> S;
	ll cc = 0;
	vector<ll>W;
	ll ans;
	ans = 0;
	REP(i, 0, strlen(S)) {
		if (S[i] == 'W') {
			ans += i + 1;
			cc++;
		}
	}
	ll sum;
	sum = ((cc + 1)*cc )/ 2;
	output(abs(ans - sum));

	return 0;
}



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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define JD



int main(int argv, char* argc[])
{
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif


    ll n,sum=0;
    cin>>n;
    vll v(n);
    ll mp[100005]={};
    rep(i,n)
    {cin>>v[i];++mp[v[i]];sum+=v[i];}
    ll q;
    cin>>q;
    while(q--)
    {
        ll b,c;
        cin>>b>>c;
        sum+=(mp[b]*(c-b));
        mp[c]+=mp[b];
        mp[b]=0;
        cout<<sum<<"\n";
    }




    return 0;
}


Measured memory_bytes: 4752
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	string str;
	int score = 0;
	cin >> str;
	int len = str.length();
	int p = 0;
	int i;
	for (int i = 0; i < len; ++i) {
		if (str[i] == 'p') ++p;
	}
	if (len % 2 == 0) {
		score = len / 2 - p;
	}
	else {
		score = (int)floor(len / 2) - p;
	}
	cout << score << endl;
}

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

using ll = unsigned long long ;
int main()
{
    ll N, A, B;
    cin >> N >> A >> B;

    if(A == 0 && B == 0) 
    {
        cout << 0 << endl;
        return 0;
    }
    if(A == 0) 
    {
        cout << 0 << endl;
        return 0;
    }

    ll quotient = N /(A+B);
    ll rem = N % (A+B);


    ll result = A*quotient ;
    if(rem <= A)
    {
        result += rem;
    }
    else
    {
        result += A;
    }
    
    cout << result << endl;


    return 0;
}

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

typedef long long ll;
 
int main(){
  ll n, k;
  cin >> n >> k;
  ll cnt[100005] = {};
  for(int i=0; i<n; i++){
    ll ai, bi;
    cin >> ai >> bi;
    ai--;
    cnt[ai] += bi;
  }
  ll s=0;
  for(int i=0; i<100005; i++){
    s += cnt[i];
    if(s >= k){
      cout << i+1 << endl;
      return 0;
    }
  }
  return 0;
}


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

#define pb push_back
#define mp make_pair

typedef long long ll;

const ll mod = 1e9 + 7;

int cnt[100000];

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

  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    cnt[a]++;
  }

  if((n%2 and cnt[0] > 1) or (n%2==0 and cnt[0])){
    cout << 0 << endl;
    return 0;
  }

  for(int i = 1; i < n; i++){
    if(cnt[i] != 2 and cnt[i] != 0){
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  for(int i = 0; i < n/2; i++){
    ans = ans * 2 % mod;
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int a,k[n];

    for(int i=1;i<=n;i++)
    {
        cin>>a;
        k[a]=i;

    }
    for(int i=1;i<=n;i++)
    {
        if(i<n)
          cout<<k[i]<<" ";
        else
            cout<<k[i]<<endl;
    }

    return 0;
}


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

namespace io {
char buf[1<<21], *p1 = buf, *p2 = buf;
inline char gc() {
    if(p1 != p2) return *p1++;
    p1 = buf;
    p2 = p1 + fread(buf, 1, 1 << 21, stdin);
    return p1 == p2 ? EOF : *p1++;
}
#define G gc

#ifndef ONLINE_JUDGE
#undef G
#define G getchar
#endif

template<class I>
inline void read(I &x) {
    x = 0; I f = 1; char c = G();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = G(); }
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = G(); }
    x *= f;
}

template<class I>
inline void write(I x) {
    if(x == 0) {putchar('0'); return;}
    I tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
        buf[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while(cnt > 0) putchar(buf[--cnt]);
}

#define in(x) read(x)
#define outn(x) write(x), putchar('\n')
#define out(x) write(x), putchar(' ')

} using namespace io;

#define ll long long
const int N = 200010;

int n, a[N];
multiset<int> S;

int main() {
	read(n);
	for(int i = 1; i <= n; ++i) read(a[i]);
	for(int i = n; i; --i) {
		multiset<int>::iterator it = S.upper_bound(a[i]);
		if(it != S.end()) S.erase(it);
		S.insert(a[i]);
	}
	outn((int)S.size());
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

int main()
{

int n,i,j;
cin>>n;
int a[n];
ll sum=0;
for(i=0;i<n;i++)
    cin>>a[i];
for(i=0;i<n;i++)
{
    for(j=i+1;j<n;j++)
    {
       sum+=a[i]*a[j];
    }
}
cout<<sum;





}


Measured memory_bytes: 256
S = input()


if S[0] == S[1]:
    if S[2] == S[3] and S[0] != S[2]:
        print('Yes')
    else:
        print('No')
elif S[0] == S[2]:
    if S[1] == S[3] and S[0] != S[1]:
        print('Yes')
    else:
        print('No')
elif S[0] == S[3]:
    if S[1] == S[2] and S[0] != S[1]:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define int long long


signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string a,s,d;
    
    
    
    cin >> a >> s >> d;
    
    
    
    cout << a[0] << s[1] << d[2] << endl;
    
    return 0;
}


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


int main (){
    long long N;
    cin>>N;
    long long M=pow(N, 0.5);
    for(long long i=M; i>0; i--){
        if(N%i==0){
            cout<<N/i + i -2<<endl;
            break;
        }
    }
}

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

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

int main()
{
    ll a, b;
    cin >> a >> b;
    cout << (a*b)/gcd(a, b) << endl;
    return 0;
}


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

using namespace std;

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

	long long ans = 0;
	for (long long i = sqrtl(n); i >= 1; i--) {
		if (n % i != 0) {
			continue;
		}

		ans = n / i + i;
		break;
	}

	cout << ans - 2LL << endl;
	return 0;
}


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

#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;

static const int INF = 1LL << 60;
static const int MOD = 1000000007;

int fact[200010];

int mpow(int x, int y) {
    if (y == 0) return 1;
    int tmp = mpow(x, y / 2);
    tmp *= tmp;
    tmp %= MOD;
    if (y % 2) {
        tmp *= x;
        tmp %= MOD;
    }
    return tmp;
}

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

    fact[0] = 1;
    for (int i = 1; i < 200010; ++i) fact[i] = fact[i - 1] * i % MOD;

    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int res = 0;
    for (int i = 1; i <= h - a; ++i) {
        int tmp = 1;
        tmp *= fact[b + i - 2];
        tmp *= mpow(fact[b - 1], MOD - 2);
        tmp %= MOD;
        tmp *= mpow(fact[i - 1], MOD - 2);
        tmp %= MOD;

        int tmp2 = 1;
        tmp2 *= fact[w - b + h - i - 1];
        tmp2 *= mpow(fact[w - b - 1], MOD - 2);
        tmp2 %= MOD;
        tmp2 *= mpow(fact[h - i], MOD - 2);
        tmp2 %= MOD;

        res += (tmp * tmp2) % MOD;
        res %= MOD;
    }

    cout << res << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <unordered_map>

using namespace std;

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

int main()
{
  int n;
  cin >> n;
  switch (n % 10)
  {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    puts("hon");
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    puts("pon");
    break;
  default:
    puts("bon");
    break;
  }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ll h,w,n,sr,sc;
	cin >> h >> w >> n >> sr >> sc;
	string S,T;
	cin >> S >> T;
	sr--;
	sc--;
	ll x = sr;
	FOR(i,0,n){// 上にはみ出せるか
		if(S[i]=='U'){
			x--;
		}
		if(x<0){
			cout << "NO" << endl;
			return 0;
		}
		if(T[i]=='D'&&x<(h-1)){
			x++;
		}
	}
	x = sr;
	FOR(i,0,n){// 下にはみ出せるか
		if(S[i]=='D'){
			x++;
		}
		if(x>=h){
			cout << "NO" << endl;
			return 0;
		}
		if(T[i]=='U'&&(x>0)){
			x--;
		}
	}


	ll y = sc;
	FOR(i,0,n){// 右にはみ出せるか
		if(S[i]=='R'){
			y++;
		}
		if(y>=w){
			cout << "NO" << endl;
			return 0;
		}
		if(T[i]=='L'&&y>0){
			y--;
		}
	}
	y = sc;
	FOR(i,0,n){// 左にはみ出せるか
		if(S[i]=='L'){
			y--;
		}
		if(y<0){
			cout << "NO" << endl;
			return 0;
		}
		if(T[i]=='R'&&(y<w-1)){
			y++;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 776
#include<stdio.h>

int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    if((a == 1 || a == 2) && (b == 2 || b == 1)){
        printf("3");
    }else if((a == 1 || a == 3) && (b == 3 || b == 1)){
        printf("2");
    }else{
        printf("1");
    }

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int count=0;
  for(int i=1;i<=n;i++){
    int x=log10(i)+1;
    if(x%2==0){
      continue;
    }else{
      count++;
    }}
    
  cout << count << endl; 
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair


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

    ll n,k;
    cin>>n>>k;
    string str;
    cin>>str;
    ll i,j;
    bool arr[n];
    for(i=0;i<n;i++){
        if(str[i]=='L')
            arr[i]=0;
        else
            arr[i]=1;
        // cout<<arr[i]<<" ";
    }
    // cout<<"\n";
    ll flag=0;
    i=0;
    j=n-1;
    ll ans=0;
    while(i<=j){
        if(k==0)
            break;        
        
        while(arr[i]==arr[i+1]&&i+1<n){ ans++; i++;}
        
        while(arr[j]==arr[j-1]&&j-1>=0){ ans++; j--; }
        // cout<<i<<" "<<j<<"\n";
        if(abs(i-j)==1 && arr[i]!=arr[j] && k){
            cout<<n-1<<endl;
            return 0;
            break;
        }
        
        if(k){
            arr[i]=!arr[i];
            arr[j]=!arr[j];
            k--;
        }
    }
    // cout<<i<<" "<<j<<"\n";
    while(i<=j){
        if(arr[i]==arr[i+1] && i+1<n){
            ans++;
        }
        i++;
    }
    cout<<min(ans,n-1);
    return 0;  
}

Measured memory_bytes: 592
#include <iostream>

using namespace std;

int d(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  int mn = 1e9;
  for (int i = 1; i < n; ++i) {
    mn = min(mn, d(i) + d(n - i));
  }
  cout << mn << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int larger(int a,int b){
 if(a<b)return b;
 else   return a;
}

int main(){
 long long  n,m;
 scanf("%lld%lld",&n,&m);
 long long  h[n],a[m],b[m];
 long long i;
 for(i=0;i<n;i++)
  scanf("%lld",&h[i]);
 
 for(i=0;i<m;i++)
  scanf("%lld%lld",&a[i],&b[i]);
  
 long long  cnt[n],tmp[n],x;
  
 for(i=0;i<n;i++){
  cnt[i]=0;tmp[i]=0;}
  
 for(i=0;i<m;i++){
  cnt[a[i]-1]++;cnt[b[i]-1]++;
  if(h[a[i]-1]>h[b[i]-1])tmp[a[i]-1]++;
  if(h[a[i]-1]<h[b[i]-1])tmp[b[i]-1]++;
 }
 
 long long ans=0;
 for(i=0;i<n;i++){
 // printf("%lld %lld %lld\n",i+1,cnt[i],tmp[i]);
  if(cnt[i]==tmp[i])ans++;}
  
 printf("%lld\n",ans);
  
return 0;}

Measured memory_bytes: 5628
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] s = new String[N];
        for(int i = 0; i < N; i++){
            s[i] = sc.next();
        }
        int M = sc.nextInt();
        String[] t = new String[M];
        for(int i = 0; i < M; i++){
            t[i] = sc.next();
        }

        int ans = 0;
        for(int i = 0; i < N; i++){
            int sum = 0;
            for(int j = 0; j < N; j++){
                if(s[j].equals(s[i])) sum++;
            }
            for(int j = 0; j < M; j++){
                if(t[j].equals(s[i])) sum--;
            }
            ans = Math.max(ans, sum);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	x := nextFloat64()
	a := 100.0
	cnt := 0
	for a < x {
		a *= 1.01
		a = math.Floor(a)
		cnt++
	}
	fmt.Println(cnt)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 1756
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int A[3];
	for (int i = 0; i < 3; ++i) {
		cin >> A[i];
	}
	sort(A,A+3,greater<int>());
	cout << 10 * A[0] + A[1] + A[2] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=1e9+7;
const int inv2=(mod+1)/2;
#define N 5005
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int dp[N][N],n,m;
int pw[N],inv[N],s[N];
int main(){
	n=read(),m=read();
	pw[0]=inv[0]=1;
	for(int i=1;i<=m;++i){
		pw[i]=(pw[i-1]<<1)%mod;
		inv[i]=1LL*inv[i-1]*inv2%mod;
	}
	for(int i=1;i<=m;++i){
		dp[1][i]=pw[i];
		s[i]=(s[i-1]+1LL*dp[1][i]*i%mod*inv[i+1])%mod;
	}
	for(int i=2;i<=n;++i){
		for(int j=1;j<=m;++j){
			dp[i][j]=(1LL*dp[i-1][j]*(j+1)+1LL*s[j-1]*pw[j])%mod;
		}
		for(int j=1;j<=m;++j){
			s[j]=(s[j-1]+1LL*dp[i][j]*j%mod*inv[j+1])%mod;
		}
	}
	printf("%d\n",dp[n][m]);
	return 0;
}


Measured memory_bytes: 101572
#include <bits/stdc++.h>
using namespace std;
int main(){
	while(1){
	int x,y;
	cin >> x >> y;
	if (x==0 && y==0) break;
	
	if (x>y) swap(x,y);
	cout << x << " " << y << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
typedef long long ll;

using namespace std;

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

	cin>>a>>b;
	string ans;

	if (a >= b) {
		for (size_t i = 0; i < a; i++) {
            ans += to_string(b);
		}
	} else {
		for (size_t i = 0; i < b; i++) {
			ans += to_string(a);
		}
	}
	cout << ans;

	return 0;
}


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

#define ll long long
#define pii pair<int,int>
#define two(x) (x<<1)
#define towd(x) (x>>1)
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define x first
#define y second

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

	ll a[3],k;
	cin>>a[0]>>a[1]>>a[2];
	cin>>k;
	ll res=0;
	ll ed=0;
	for (int i=0;i<3;i++){
		if (k>=a[i]){
			k-=a[i];
			if (i==0) res+=a[i];
			if (i==2) res-=a[i];
		}
		else{
			ed=i;
			break;		
		}
	}
	if (ed==0) res+=k;
	if (ed==2) res-=k;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3624
;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(declaim (type (integer 1 200000) *num-n*))
(defvar *num-n* (read))

(declaim (type (integer 1 200001) *select-n*))
(defvar *select-n* (read))

;; 10^100のおかげで選択数が異なるなら和も異なる
;; 0..n から i 個の数を選んだ時のありうる和の数を数える問題に還元される

(declaim (inline count-sum))
(defun count-sum (n i)
  (declare (type fixnum n i))
  (1+ (* i (1+ (- n i)))))

(princ (let ((sum 0))
	 (declare (type (integer 0 1000000007) sum)) ;; mod 1e9+7
	 (loop for i from *select-n* to (1+ *num-n*) do
	       (setf sum (mod (+ sum (count-sum *num-n* i)) 1000000007)))
	 sum))


Measured memory_bytes: 24480
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    string s;
    cin >> s;
    int flag=0;
    
    if(s[0]==s[1]){
        if(s[0]!=s[2] && s[2]==s[3]){
            flag=1;
        }
    }
    else if(s[0]==s[2]){
        if(s[1]==s[3]){
            flag=1;
        }
    }
    else if(s[0]==s[3]){
        if(s[1]==s[2]){
            flag=1;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	string mo = "aiueo";
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<string>ports;
		for (int i = 0; i < N; ++i) {
			string st; cin >> st;
			ports.emplace_back(st);
		}
		int ans = -1;
		for (int k = 1; k <= 50; ++k) {
			set<string>sts;
			for (int i = 0; i < N; ++i) {
				string name;
				string st = ports[i];
				name.push_back(st[0]);
				for (int j = 0; j < st.size() - 1; ++j) {
					if (find(mo.begin(), mo.end(), st[j]) == mo.end()) {

					}
					else {
						name.push_back(st[j + 1]);
					}
				}
				if (name.size() > k)name = name.substr(0, k);
				sts.emplace(name);
			}
			if (sts.size() == N) {
				ans = k;
				break;
			}
		}
		cout << ans << endl;
		

	}
	
	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
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; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin>>n;
    vector<int> d(n),cnt(13,0);
    cnt[0]++;
    for(int i = 0; i < n; i++) {
        cin>>d[i];
        cnt[d[i]]++;
        if(cnt[d[i]]>2) {
            cout<<0<<endl;
            return 0;
        }
    }
    if(cnt[0]>1 || cnt[12]>1) {
        cout<<0<<endl;
        return 0;
    }

    vector<int> one,two;
    for(int i = 0; i < 13; i++) {
        if(cnt[i]==1) {
            one.push_back(i);
        }
        if(cnt[i]==2) {
            two.push_back(i);
            two.push_back((24-i)%24);
        }
    }

    int ans=0;
    int k=sz(one);
    for(int bit = 0; bit < (1<<k); bit++) {
        vector<int> time;
        for(int x:two) time.push_back(x);
        for(int i = 0; i < k; i++) {
            if(bit&(1<<i)) time.push_back(one[i]);
            else time.push_back((24-one[i])%24);
        }
        sort(all(time));
        time.push_back(24);

        int now=24;
        for(int i = 0; i < sz(time)-1; i++) {
            chmin(now,abs(time[i]-time[i+1]));
        }
        chmax(ans,now);
    }

    cout<<ans<<endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
bool chmin(T &a,T b){
    if(a<=b)return 0;
    a=b;
    return 1;
}

long double eps = 1e-10;

typedef long double ld;

ld x[222],y[222],z[222],r[222];
ld dx[222],dy[222],dz[222],dr[222];

ld f(ld a,ld b){
    return (a-b)*(a-b);
}

ld dist(int i,int j,ld t){
    return  {f(x[i]+dx[i]*t, x[j]+dx[j]*t) +
             f(y[i]+dy[i]*t, y[j]+dy[j]*t) +
             f(z[i]+dz[i]*t, z[j]+dz[j]*t)};
}

ld d_r(int i,int j,ld t){
    return (r[i]-dr[i]*t+r[j]-dr[j]*t)*(r[i]-dr[i]*t+r[j]-dr[j]*t);
}

signed main(){
    cout << fixed << setprecision(20);
    //ofstream cout("out.txt");

    int n;
    while(cin>>n){
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>x[i]>>y[i]>>z[i]>>dx[i]>>dy[i]>>dz[i]>>r[i]>>dr[i];
        }
        vector<pair<ld,pair<int,int>>> v;
        for(int i=0;i<n;i++){
            // sizen
            v.push_back({(ld)(r[i]/dr[i]),{i,i}});
            for(int j=i+1;j<n;j++){
                // sanbu
                ld low=-eps,up=max(r[i]/dr[i],r[j]/dr[j])+eps,mid1,mid2;
                for(int _=0;_<77;_++){
                    mid1 = (low*2.0+up)/3.0;
                    mid2 = (low+up*2.0)/3.0;
                    ld d1 = dist(i,j,mid1) - d_r(i,j,mid1);
                    ld d2 = dist(i,j,mid2) - d_r(i,j,mid2);
                    if(d1<=0.0){
                        up=mid1;
                        continue;
                    }
                    if(d1>d2)low=mid1;
                    else up=mid2;
                }
                ld d = dist(i,j,low) - d_r(i,j,low);
                if(low>=0.0 && d <= eps){
                    v.push_back({low,{i,j}});
                }

            }
        }
        sort(v.begin(),v.end());
        bool used[n]={};
        ld ans[n];
        for(int i=0;i<v.size();i++){
            if(used[v[i].second.first] || used[v[i].second.second]) continue;
            ans[v[i].second.first] = v[i].first;
            ans[v[i].second.second] = v[i].first;
            used[v[i].second.first] =1;
            used[v[i].second.second] = 1;
        }
        for(int i=0;i<n;i++){
            cout << ans[i] << "\n";
        }
    }
}


Measured memory_bytes: 3544
while True:
	n = input()
	if n == 0: break
	words = []
	for i in xrange(n):
		words += raw_input().split()
	candidates = {}
	for w in set(words):
		c = words.count(w)
		candidates.setdefault(w[0], [])
		candidates[w[0]] += [(-c, w)]
	try:
		print " ".join([w for c, w in sorted(candidates[raw_input()])][:5])
	except KeyError:
		print "NA"

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

typedef long long ll;
 
 



int main()
{
    //freopen("in.txt", "r", stdin);
   
   string a;
   cin>>a;

   int i=0,j=a.size()-1,cost=0;

   while(i<=j){
     if(a[i]!=a[j])
        cost++;
     
     i++;
     j--;
   }


   cout<<cost;

    return 0;
}




    

  

Measured memory_bytes: 256
# coding: utf-8
S = list(input())

def check(s):
    l=len(s)
    for i in range(round(l/2)):
        if s[i]!=s[l-1-i]:
            return False
    return True

ans=("No")
s1 = (len(S)-1)//2
s2 = (len(S)+3)//2
if check(S):
    if S[:s1]==S[s2-1:]:
        if check(S[:s1]):
            ans=("Yes")
print(ans)
        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a + a - 1, b + b - 1}) << endl;
    return 0;
}


Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
import fractions
#from scipy.misc import comb

N = int(input())
T = [int(input()) for i in range(N)]

ans = T[0]
for t in T:
    ans = ans*t//fractions.gcd(ans,t)

print(ans)

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
int main(int argc, char** argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  
  auto solve = [&]() {
    double r;
    cin >> r;
    cout << (2*3.1415926*r) << '\n';
  };
  
  int t;
  t = 1;
  while (t--)
    solve();
  
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define INF 1125899906842624
#define MAX_N 100'000
using P = pair<i64, i64>;
vector<P> G[MAX_N];

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

    REP(i, M) {
        i64 l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        G[l].emplace_back(r, d);
        G[r].emplace_back(l, -1 * d);
    }

    bool ok = true;
    vector<i64> d(N, INF);
    REP(s, N) {
        if (d[s] != INF) continue;

        queue<i64> que;
        d[s] = 0;
        que.push(s);
        while (!que.empty()) {
            i64 u = que.front(); que.pop();
            for (P p : G[u]) {
                i64 x = d[u] + p.second;
                if (d[p.first] == INF) {
                    d[p.first] = x;
                    que.push(p.first);
                } else if (d[p.first] != x) {
                    ok = false;
                }
            }
        }
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 14080
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var K = consoleReader.Int();
            return (K / 2) * ((K + 1) / 2);
        }

        public const int mod = 1000000007;
        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

    #region Console
    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int() => int.Parse(String()); public long Long() => long.Parse(String()); public ulong ULong() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt() => String().Split().Select(int.Parse).ToArray(); public long[] SplitLong() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitULong() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt(int count) { for (int i = 0; i < count; i++) yield return Int(); } public IEnumerable<long> RepeatLong(int count) { for (int i = 0; i < count; i++) yield return Long(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt(int count) { for (int i = 0; i < count; i++) yield return SplitInt(); } }
    #endregion
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[550][550];
int main(){
	ll h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)cin>>a[i][j];
	ll cnt=0;
	vector<pair<pair<ll,ll>,pair<ll,ll>>>v;
	for(int i=1;i<=h;i++){
		if(i%2){
			for(int j=1;j<=w;j++){
					if(i==1&&j==1)continue;
					if(j==1){
						if(a[i-1][j]%2){
							cnt++;
							a[i][j]++;
							v.push_back({{i-1,j},{i,j}});
						}
					}else{
						if(a[i][j-1]%2){
							cnt++;
							a[i][j]++;
							v.push_back({{i,j-1},{i,j}});
						}
					}
			}
		}else{
			for(int j=w;j>=1;j--){
					if(j==w){
						if(a[i-1][j]%2){
							cnt++;
							a[i][j]++;
							v.push_back({{i-1,j},{i,j}});
						}
					}else{
						if(a[i][j+1]%2){
							cnt++;
							a[i][j]++;
							v.push_back({{i,j+1},{i,j}});
						}
					}
			}
		}
	}
	cout<<cnt<<endl;
	for(int i=0;i<v.size();i++){
		cout<<v[i].first.first<<' '<<v[i].first.second<<' '<<v[i].second.first<<' '<<v[i].second.second<<endl;
	}
	return 0;
}


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

int main(){
  int H,M;
  cin>>H>>M;

  vector<string> vec(H);
  rep(i,H){
    cin>>vec.at(i);
  }

  rep(i,M+2){
    cout<<'#';
  }
  cout<<endl;

  rep(i,H){
    cout<<'#'<<vec.at(i)<<'#'<<endl;
  }

  rep(i,M+2){
    cout<<'#';
  }

  cout<<endl;
  



}

Measured memory_bytes: 256
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                int N = scan.nextInt();
                int[] A = new int[N+1];
                
                long ans = 0;
                A[0]=0;

                for(int i=1; i<=N;i++){
                    A[i] = scan.nextInt();
                }               
                Arrays.sort(A);

                
                for(int i=1; i<N;i++){
                    int p=0;
                    if((i%2)==0){
                        p = N-i/2;
                    }else{
                        p = N-i/2;
                    }
                    ans = ans + A[p];
                } 
                System.out.println(ans);
        }               
}

Measured memory_bytes: 60788
dice = {v: k for k, v in enumerate(list(map(int, input().split())))}
adjacent = {k: v for k, v in enumerate(sorted(dice.keys()))}
q = int(input())
p = [(-1,2,4,1,3,-1),(3,-1,0,5,-1,2),(1,5,-1,-1,0,4),(4,0,-1,-1,5,1),(2,-1,5,0,-1,3),(-1,3,1,4,2,-1)]
for _ in range(q):
    top, front = map(int, input().split())
    x = dice[top]
    y = dice[front]
    print(adjacent[p[x][y]])

Measured memory_bytes: 7688
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b >= 24)
    {
        cout << a + b - 24;
    }
    else
    {
        cout << a + b;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int[] a = new int[4];
        for (int i = 0; i < n; i++) {
            String s = scan.next();
            if (s.equals("AC")) {
                a[0]++;
            } else if (s.equals("WA")) {
                a[1]++;
            } else if (s.equals("TLE")) {
                a[2]++;
            } else {
                a[3]++;
            }
        }
        scan.close();

        System.out.println("AC x " + a[0]);
        System.out.println("WA x " + a[1]);
        System.out.println("TLE x " + a[2]);
        System.out.println("RE x " + a[3]);
    }
}


Measured memory_bytes: 58416
program ABC148B
    integer N
    character(100) S,T
    character(200) ans
    read*,N
    read*,S,T
    ans=""
    do i=1,N
        ans(2*i-1:2*i-1)=S(i:i)
        ans(2*i:2*i)=T(i:i)
    end do
    print"(A)",trim(ans)
end program

Measured memory_bytes: 640
# -*- coding: utf-8 -*- #

A, B, C, D = map(int, input().split())
ans = 0

if (C - A) > 0:
    if (D - B) > 0:
        ans = B - C
        if ans < 0:
            ans = 0
    else:
        ans = D - C
        if ans < 0:
            ans = 0
else:
    if (B - D) > 0:
        ans = D - A
        if ans < 0:
            ans = 0
    else:
        ans = B - A
        if ans < 0:
            ans = 0

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 1000000007
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define sz(x) int(x.size())
int main(){
	int n;
	int max=0;
	int tmp=0;
	cin>>n;
	vector<int> hn(n);
	rep(i,n){
		cin>>hn[i];
	}
	rep(i,n-1){
		if(hn[i]>=hn[i+1]){
			tmp++;
		}else{
			if(max<tmp){
				max=tmp;
				tmp=0;
			}
			tmp=0;
		}
	}
	if(max<tmp){
		max=tmp;
	}
	cout<<max<<endl;
	return 0;
}

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

using namespace std;

int main()
{

	int t;
	t=1;
//	cin>>t;
	while(t--)
	{
	  int n;
	  cin>>n;
	  
	  n=n%10;
	  
	   


	  if(n==2||n==4||n==5||n==7||n==9)
	  cout<<"hon";

	  else if(n==0||n==1||n==6||n==8)
	  cout<<"pon";
	  
	  else
	  cout<<"bon";
	   
	}



}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[200050];
	cin>>a;
	int l=strlen(a);
	
	for(int i=0;i<l;i++)
	{
//		if(a[i]=='?'&&a[i+1]=='D')
//		a[i]='P';
//		else
		if(a[i]=='?')
		a[i]='D';
	}

	
	for(int i=0;i<l;i++)
	{
		cout<<a[i];
	}
}

Measured memory_bytes: 3760
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<map>

using namespace std;

#define INF (1<<30)

int n;
int a[100001];

vector<int> enum_div(int n)//nの約数を列挙
{
	vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
			if(n%i == 0)
			{
				ret.push_back(i);
				ret.push_back(n/i);
			}
	}
	return ret;
}

int main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	vector<int> list = enum_div(a[0]);
	int ans = 0;
	for(int i = 0;i < list.size();i++){
		int target = list[i];
		int amount = 0;
		for(int j = 0;j < n;j++){
			if(a[j]%target==0)amount++;
		}
		// cout << amount << endl;
		if(amount == n || amount == n-1)ans = max(ans,target);
	}
	list = enum_div(a[1]);
	for(int i = 0;i < list.size();i++){
		int target = list[i];
		int amount = 0;
		for(int j = 0;j < n;j++){
			if(a[j]%target==0)amount++;
		}
		if(amount == n || amount == n-1)ans = max(ans,target);
	}
    cout << ans << endl;
}

Measured memory_bytes: 640