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

int main(){
    string s, t;
    char S, T;
    cin >> s;
    cin >> t;

    S = s[0];
    T = t[0];

    string res;
    res = "No";

    for(int i = 0; i < s.size(); i++){
        if(S > s[i]) S = s[i];
    }

    for(int i = 0; i < t.size(); i++){
        if(T < t[i]) T = t[i];
    }

    if(S < T) res = "Yes";

    bool check = true;
    for(int i = 0; i < s.size(); i++){
        if(S != s[i]) check = false;
    }

    if(check && S == T && s.size() < t.size()) res = "Yes";

    cout << res << endl;


}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <set>
using namespace std;

int m, n;
string s[128];
int rec[177147];
bool check[128];

void trinary(int bit)
{
	int pow = 1;
	for (int i = 1; i < m; i++) pow *= 3;
	for (; pow; pow /= 3) printf("%d", bit / pow % 3);
	printf("\n");
}

int calc(int bit)
{
	//trinary(bit);
	if (rec[bit] >= 0) return (rec[bit]);
	
	int count = 0, nums = 0, mul = 0;
	
	for (int i = 0; i < n; i++) check[i] = true;
	
	for (int bits = 0; bits < m; bits++){
		mul = (mul == 0 ? 1 : mul * 3);
		if ((bit / mul) % 3 == 2) continue;
		nums++;
		for (int i = 0; i < n; i++){
			if (s[i][m - 1 - bits] - '0' != (bit / mul) % 3){
				check[i] = false;
			}
		}
	}
	
	for (int i = 0; i < n; i++) count += check[i];
	if (count <= 1) return (nums);
	
	int ret = m;
	mul = 0;
	for (int i = 0; i < m; i++){
		mul = (mul == 0 ? 1 : mul * 3);
		if ((bit / mul) % 3 != 2) continue;
		int nb = bit - 2 * mul;
		ret = min(ret, max(calc(nb), calc(nb + mul)));
	}
	
	return (rec[bit] = ret);
}

int main()
{
	while (scanf("%d %d", &m, &n) && n){
		
		for (int i = 0; i < n; i++){
			char buf[128];
			scanf("%s", buf);
			s[i] = (string)buf;
		}
		
		memset(rec, -1, sizeof(rec));
		
		int pow = 1;
		for (int i = 0; i < m; i++) pow *= 3;
		
		printf("%d\n", calc(pow - 1));
	}
	
	return (0);
}

Measured memory_bytes: 1772
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int short
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 104, OO = 100, T = 10, M = 100, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
char s[N][N];
int dp[N][N], dk[N][N], cnt[N][N][N][N], ans;

int32_t main() {
	use_fast;
	int n, m, x = 0, y = 0;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= m; j++)
			cin >> s[i][j];
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			dp[i][j] = dp[i][j - 1] + (s[i][j] == 'o');
			dk[i][j] = dk[i - 1][j] + (s[i][j] == 'o');
			if(s[i][j] == 'E') 
				x = i, y = j;
		}
	}
	for(int i = x; i; i--) for(int j = y; j; j--) for(int k = x; k <= n; k++) for(int p = y; p <= m; p++) {
		if (1 < i && k + 1 < x + i) {
			cnt[i - 1][j][k][p] = max((int32_t)cnt[i - 1][j][k][p], cnt[i][j][k][p] + dp[i - 1][min((int32_t)p, m - y + j)] - dp[i - 1][max(j - 1, p - y)]);
			ans = max(ans, cnt[i - 1][j][k][p]);
		}
		if(k < n && x + k < n + i) {
			cnt[i][j][k + 1][p] = max((int32_t)cnt[i][j][k + 1][p], cnt[i][j][k][p] + dp[k + 1][min((int32_t)p, m - y + j)] - dp[k + 1][max(j - 1, p - y)]);
			ans = max(ans, cnt[i][j][k + 1][p]);
		}
		if(1 < j && p + 1 < y + j) {
			cnt[i][j - 1][k][p] = max((int32_t)cnt[i][j - 1][k][p], cnt[i][j][k][p] + dk[min((int32_t)k, n - x + i)][j - 1] - dk[max(i - 1, k - x)][j - 1]);
			ans = max(ans, cnt[i][j - 1][k][p]);
		}
		if(p < m && y + p < m + j) {
			cnt[i][j][k][p + 1] = max((int32_t)cnt[i][j][k][p + 1], cnt[i][j][k][p] + dk[min((int32_t)k, n - x + i)][p + 1] - dk[max(i - 1, k - x)][p + 1]);
			ans = max(ans, cnt[i][j][k][p + 1]);
		}
	}
	cout << ans << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



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

using namespace std;

int main(void) {
  // stringをそのまま使うと前方挿入でTLE
  string s;
  cin >> s;
  
  deque<char> S;
  
  for (int i = 0;i < s.size();i++) {
    S.push_back(s[i]);
  }
  
  bool rev_flag = false;
  
  int N;
  cin >> N;
  
  int cmd;
  int sub_cmd;
  char ch;
  for (int i = 0;i < N;i++) {
    cin >> cmd;
    
    if (cmd == 1) {
      rev_flag = !rev_flag;
    } else {
      // cmd == 2
      cin >> sub_cmd >> ch;
      if ((sub_cmd == 1 && !rev_flag) || (sub_cmd == 2 && rev_flag)) S.push_front(ch);
      else S.push_back(ch);
    }
  }
  
  if (rev_flag) {
    for_each(S.rbegin(), S.rend(), [](auto a){cout << a;});
  } else {
    for_each(S.begin(), S.end(), [](auto a){cout << a;});
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

string s,t;

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

    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<>());

    string ans="No";
    if(s<t) ans="Yes";

    cout<<ans<<endl;
}

Measured memory_bytes: 3588
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [] data = new int[n];
			int [] data2 = new int[n];
			String s = sc.next();
			for(int i = 0; i < n; i++){
				data[i] = s.charAt(i) == 'W' ? 1 : 0;
				data2[i] = s.charAt(i) == 'E' ? 1 : 0;
			}
			
			int [] acc = new int[n];
			int [] acc2 = new int[n];
			acc[0] = data[0];
			acc2[n-1] = data2[n-1];
			for(int i = 1; i < n; i++){
				acc[i] = acc[i-1] + data[i];
			}
			for(int i = n-2; i >= 0; i--){
				acc2[i] = acc2[i+1] + data2[i];
			}
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < n; i++){
				int now;
				if(i == 0){
					now = acc2[1];
				}
				else if(i == n-1){
					now = acc[n-2];
				}
				else{
					now = acc[i-1] + acc2[i+1];
				}
				min = Math.min(min, now);
			}
			System.out.println(min);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 32764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            String input = br.readLine();
            int ans = 0;
            for (int i = 0; i < input.length() / 2; i++) {
                if (input.substring(0, i).equals(input.subSequence(i, i + i))){
                    ans = input.substring(0, i).length() * 2;
                }
            }

            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 23252
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    count = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if (i < j < k):
                    if i+j+k == x:
                        count += 1
    print(count)

Measured memory_bytes: 7676
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    vector<ll> s(n+1);
    rep(i, n) {
        ll a; cin >> a;
        s[i+1] = s[i] + a;
    }
    ll cnt = 0;
    ll weight = 0;
    bool negative = true;
    for(int i=1;i<=n;i++) {
        ll num = s[i] + weight;
        if(!negative && num <= 0) {
            cnt += 1 - num;
            weight += 1 - num;
        }
        else if(negative && num >= 0) {
            cnt += num + 1;
            weight -= num + 1;
        }
        negative = !negative;
    }
    ll ans = cnt; cnt = 0;
    weight = 0;
    negative = false;
    for(int i=1;i<=n;i++) {
        ll num = s[i] + weight;
        if(!negative && num <= 0) {
            cnt += 1 - num;
            weight += 1 - num;
        }
        else if(negative && num >= 0) {
            cnt += num + 1;
            weight -= num + 1;
        }
        negative = !negative;
    }
    cout << min(ans, cnt);
}


Measured memory_bytes: 1024
#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 rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

void solve(){
    string s,t; cin>>s>>t;
    cout<<t<<s<<endl;

    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll x; cin >> x;
    ll e = x%11, ee = x/11;
    if(1 <= x && x <= 6) cout << 1 << endl;
    else if(7 <= x && x <= 11) cout << 2 << endl;
    else{
        if(1 <= e && e <= 6) cout << ee*2+1 << endl;
        else if(7 <= e && e <= 10) cout << ee*2+2 << endl;
        else cout << ee*2 << endl;
    }
    //cout << ee << " " << e << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define sll set<ll>
#define str string
#define rev reverse
#define mp make_pair
#define pb push_back
#define acc accumulate
#define vll vector<ll>
#define eb emplace_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define dq deque<ll>
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back

void solve()
{
    ll n,k,i,j;
    cin >> n >> k;
    ll a[n],ans[n];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        ans[i]=INT64_MAX;
    }
    ans[0]=0;
    for(i=0;i<n;i++)
    {
        ll q=0;
        ll p=max(q,i-k);
        for(j=i-1;j>=p;j--)
        {
            ans[i]=min(ans[i],ans[j]+abs(a[i]-a[j]));
        }
        //cout << ans[i] << " ";
    }
    //cout << endl;
    cout << ans[n-1];
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll cases;
    //cin >> cases;
    cases=1;
    for(ll i=0;i<cases;i++)
        solve();

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime> 
#define full(a) a.begin(), a.end()

#define sz(x) ((ll)(x).size())
#define ll long long
#define ull unsigned long long
using namespace std;

ll inp() {
    ll n; cin >> n;
    return n;
}

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

template<class T>

void prvc(vector<T> vec) {
    for (auto i : vec)cout << i << " ";
    cout << endl;
}

pair<int, int> hat(pair<int, int> l, pair<int, int> r) {
    pair<int, int> ans;
    if (l.first > r.first)swap(l, r);
    if (r.first > l.second) {
        return pair<int, int>(-2e9, -2e9);
    }
    ans.first = r.first;
    ans.second = min(l.second, r.second);
    return ans;
}

ll cnm(ll n, ll m) {
    ll k = n - m;
    if (k < m)std::swap(k, m);
    ll l1 = 1;
    for (int i = k + 1; i <= n; i++) {
        l1 *= i;
        if (l1 % m == 0)l1 /= m, m--;
    }
    for (int i = 2; i <= m; i++)
    {
        l1 /= i;
    }
    return l1;
}

vector<ll> divs(ll n) {
    vector<ll> divisors;
    for (ll i = 1; i <= n; i++) {
        if (n % i == 0)divisors.push_back(i);
    }
    return divisors;
}

std::vector<std::string> split(const std::string& s, char delimiter)
{
    std::vector<std::string> tokens;
    std::string token;
    std::istringstream tokenStream(s);
    while (std::getline(tokenStream, token, delimiter))
    {
        tokens.push_back(token);
    }
    return tokens;
}

void solve() {
    ll n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int k = n - i;
        int divc = 0;
        for (int j = 1; j * j <= k; j++) {
            if (k % j == 0)divc++;
            if (j * j == k)break;
            if (k % j == 0)divc++;
        }
        ans += divc;
    }
    cout << ans << endl;
}


int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //ll n; cin >> n;
    //while (n--)
        solve();

    return 0;
}

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

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

	int n; cin >> n;
	
	int left = 0, right = n + 1;
	int mid;
	while (left < right){
		int n2 = n;
		bool flag = false;
		mid = (left + right) / 2;
		for (int i = mid; i > 0;i--){
			if (n2 > i){
				n2 -= i;
			}
			else if (n2 == i){
				flag = true;
				break;
			}
		}
		if (flag){
			right = mid;
		}
		else{
			left = mid + 1;
		}
	}

	vector<int>x;
	for (int i = left; i > 0; i--){
		if (n > i){
			n -= i;
			x.push_back(i);
		}
		else if (n== i){
			x.push_back(i);
			break;
		}
	}
	reverse(x.begin(), x.end());

	for (int i = 0; i < x.size(); i++){
		cout << x[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
char s[2010];
int a[2010],b[2010],stk[2010],l[2010],r[2010];
int n,ans,sum,cnt,top,minn,maxx;
bool f[2010];
 bool init()
{
	bool juda=0,judb=0;
	scanf("%s",s+1);
	n=strlen(s+1);	
	for (int i=1;i<=n;++i)
	{
		a[i]=(s[i]=='1')?1:0;
		if (a[i]) juda=1;
	}
	scanf("%s",s+1);
	for (int i=1;i<=n;++i)
	{
		b[i]=(s[i]=='1')?1:0;
		if (b[i]) judb=1;
	}
	if (!judb&&!juda)
	{
		printf("0\n");
		return 0;
	}
	if (!judb&&juda)
	{
		printf("-1\n");
		return 0;
	}
	return 1;
}
 bool cmpl(int a,int b)
{
	return l[a]<l[b];
}
 bool cmpr(int a,int b)
{
	return r[a]<r[b];
}
 int main()
{
	if (!init()) return 0;
	for (int i=1;i<=n;++i)
	{
		int pos=i;
		while (!b[pos])
		{
			++l[i];
			--pos;
			if (pos==0) pos=n;	
		}
		pos=i;
		while (!b[pos])
		{
			++r[i];
			++pos;
			if (pos==n+1) pos=1;	
		}
	}
	ans=0x3f3f3f3f;
	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=n;++j) f[j]=0;
		sum=0;
		int pos=i;
		for (int j=1;j<=n;++j)
		{
			if (a[pos]!=b[j]) f[pos]=1,++sum;
			++pos;
			if (pos==n+1) pos=1;
		}
		if (i==1) cnt=0;
		else cnt=n-i+1;
		top=0;
		for (int j=1;j<=n;++j)
		if (f[j]&&r[j]>cnt) stk[++top]=j;
		sort(stk+1,stk+top+1,cmpl);
		maxx=0;minn=0x3f3f3f3f;
		if (top) minn=min(minn,l[stk[top]]*2+cnt);
		for (int j=top;j>=1;--j)
		{
			maxx=max(maxx,r[stk[j]]);
			if (j>1) minn=min(minn,l[stk[j-1]]*2+maxx*2-cnt);
		}
		if (top) minn=min(minn,maxx*2-cnt);
		if (!top) minn=cnt;
		ans=min(ans,minn+sum);
		cnt=i-1;
		top=0;
		for (int j=1;j<=n;++j)
		if (f[j]&&l[j]>cnt) stk[++top]=j;
		sort(stk+1,stk+top+1,cmpr);
		maxx=0;minn=0x3f3f3f3f;
		if (top) minn=min(minn,r[stk[top]]*2+cnt);
		for (int j=top;j>=1;--j)
		{
			maxx=max(maxx,l[stk[j]]);
			if (j>1) minn=min(minn,r[stk[j-1]]*2+maxx*2-cnt);
		}
		if (top) minn=min(minn,maxx*2-cnt);
		if (!top) minn=cnt;
		ans=min(ans,minn+sum);
	}
	printf("%d\n",ans);
}





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

int main() {
  	int P,Q,R;
  	cin >> P >> Q >> R;
	vector<int> H = { P , Q , R };
  	sort( H.begin() , H.end() );
  
  	cout << H.at(0) + H.at(1) << endl;
}


Measured memory_bytes: 256
from math import factorial

N, M = input().split()
N = int(N)
M = int(M)

i=0
j=0
if N == 0 or N == 1:
  i += 0
else:
  i = factorial(N) / factorial(2) / factorial(N - 2)

if M == 0 or M == 1:
  j += 0
else:
  j = factorial(M) / factorial(2) / factorial(M - 2)

  
print(int(i+j))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;


 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 

 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-7;

const int MAX_N = 1<<20;

int n;
pii dat[2*MAX_N-1];
void init(int n_){
    n = 1;
    while(n < n_) n *= 2;
    for(int i = 0; i < 2 * n-1; i++){
        dat[i].fi = -INF;
        dat[i].se = -(i-n+1);
    }
}
 
void update(int k, int add){
    k += n-1;
    dat[k].fi += add;
    while(k > 0) {
        k = (k - 1) / 2;
        dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}
 
pii query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return pii(-INF, n-1);
    if(a <= l && r <= b) return dat[k];
    else{
        pii vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        pii vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}

vector<pii> q[1000010];

int main(){
	int r, l;
	cin>>n>>r>>l;
	init(n);
	rep(i, n) update(i, INF);
	vi v(n, 0);
	int d, t, x, tt = 0;
	pii p;
	rep(i, r){
		cin>>d>>t>>x;
		q[t].pb(pii(d-1, x));
		//p = query(0, n, 0, 0, n);
		//cout<<-p.se<<endl;
		// v[-p.se] = t-tt;
		// tt = t;
		// update(d-1, x);
	}
	rep(i, l+1){
		rep(j, q[i].size()){
			update(q[i][j].fi, q[i][j].se);
		}
		p = query(0, n, 0, 0, n);
		v[-p.se]++;
		//cout<<-p.se<<endl;
	}
	//p = query(0, n, 0, 0, n);
	//v[-p.se] = l-tt;
	int ans = 0;
	for(int i = 1; i < v.size(); i++){
		if(v[ans] < v[i]) ans = i;
	}
	// rep(i, v.size()){
	// 	cout<<v[i]<<endl;
	// }
	cout<<ans+1<<endl;
}

Measured memory_bytes: 46000
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18,MOD = 1000000007,loop = 88*88;

int dp[88][88][88*88*2];

signed main(){
	int H,W;
	cin>>H>>W;
	vector<vector<int>>a(H,vector<int>(W)),b(H,vector<int>(W));
	REP(i,H)REP(j,W)cin>>a[i][j];
	REP(i,H)REP(j,W)cin>>b[i][j];
	dp[0][0][88*88+a[0][0]-b[0][0]]=1;
	dp[0][0][88*88+b[0][0]-a[0][0]]=1;
	REP(i,H){
		REP(j,W){
			REP(k,88*88*2){
				if(dp[i][j][k]==0)continue;
				if(j!=W-1){
					if(IN(0,k+a[i][j+1]-b[i][j+1],88*88*2))
					dp[i][j+1][k+a[i][j+1]-b[i][j+1]]=dp[i][j][k];
					if(IN(0,k+b[i][j+1]-a[i][j+1],88*88*2))
					dp[i][j+1][k+b[i][j+1]-a[i][j+1]]=dp[i][j][k];
				}
				if(i!=H-1){
					if(IN(0,k+a[i+1][j]-b[i+1][j],88*88*2))
					dp[i+1][j][k+a[i+1][j]-b[i+1][j]]=dp[i][j][k];
					if(IN(0,k+b[i+1][j]-a[i+1][j],88*88*2))
					dp[i+1][j][k+b[i+1][j]-a[i+1][j]]=dp[i][j][k];
				}
			}
		}
	}
	int ans = INF;
	REP(i,88*88*2){
		if(dp[H-1][W-1][i])CHMIN(ans,abs(88*88-i));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 850560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=3010;
vec a(N);
mat dp(N,vec(N,inf));
ll n;

ll dfs(ll l,ll r) {
  ll use=n-(r-l+1);
  if(l==r) {
    if(use%2) return -a[l];
    else return a[l];
  }
  if(dp[l][r]!=inf) return dp[l][r];
  ll res;
  if(use%2) {
    res=min(dfs(l+1,r)-a[l],dfs(l,r-1)-a[r]);
  }
  else {
    res=max(dfs(l+1,r)+a[l],dfs(l,r-1)+a[r]);
  }
  return dp[l][r]=res;
}

int main() {
  cin >> n;
  for(ll i=0;i<n;i++) cin >> a[i];
  cout << dfs(0,n-1) << endl;
}

Measured memory_bytes: 71296
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long int ll;

int main(){

    ll X, t;
    cin >> X >> t;

    if(X < t){
        cout << 0 << endl;
    }else{
        cout << X - t << endl;
    }

} 

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int[] a = getIntArray(sc);

		double reciprocal = 0;
		for (int num : a) {
			reciprocal += 1.0 / num;
		}

		System.out.println(1.0 / reciprocal);
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}
}


Measured memory_bytes: 22356
s = list(input())
K = int(input())
def plus(c,i):
    return chr((ord(c)-ord('a')+i)%26+ord('a'))
# 上から順に回るなら回す
for i,ss in enumerate(s):
    want = (ord('z') + 1 - ord(ss))%26
    if K >= want:
        s[i] = plus(s[i],want)
        K = K - want
    
K = K % 26
if K >= 1:
    s[-1] = plus(s[-1],K)
print("".join(s))

Measured memory_bytes: 4152
#include<iostream>
using namespace std;
typedef long long ll;

int main() {
	int N;
	string S;
	cin >> N >> S;

	ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') cnt1++;
		if (S[i] == 'G') cnt2++;
		if (S[i] == 'B') cnt3++;
	}

	ll ans = cnt1 * cnt2 * cnt3;

	for (int d = 1; d <= N; d++) {
		for (int m = d; m < N; m++) {
			if (m + d >= N) continue;
			if ((S[m - d] != S[m + d]) && (S[m] != S[m + d]) && S[m - d] != S[m]) ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){

  int n;

  while(cin >> n, n){
    int a[1000];
    int b[1000];

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

    for(int i=0;i<=n;i++){

      int k=0;
      for(int j=0;j<=n;j++){
	if(j != i){
	  b[k] = a[j];
	  k++;
	}
      }

      bool d = true;
      for(int j=1;j<n-1;j++){
	if(b[j+1]-b[j] != b[j]-b[j-1]) d = false;
      }

      if(d){
	cout << a[i] << endl;
	break;
      }

    }
  }
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
vector<pair<lld, lld> > G[555555];
lld dis[555555];
void dfs(lld u, lld par = -1)
{
    for(lld i = 0; i < G[u].size(); i++) {
        lld to = G[u][i].first;
        lld w = G[u][i].second;
        if(to != par) {
            dis[to] += dis[u] + w;
            dfs(to, u);
        }
    }
    return;
}
int main()
{
    std::ios::sync_with_stdio(false);

    lld n;
    cin >> n;
    for(lld i = 0; i < n - 1; i++) {
        lld u, v, w;
        cin >> u >> v >> w;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }
    dfs(1);
    vector<lld> color(n + 1, 0);
    for(lld i = 1; i <= n; i++) {
        if(dis[i] % 2) {
            color[i] = 0;
        } else {
            color[i] = 1;
        }
    }
    for(lld i = 1; i <= n; i++) {
        cout << color[i] << "\n";
    }
}

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

namespace C_sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var W = Console.ReadLine();

            var cnt = 0;
            while (true)
            {
                var line = Console.ReadLine();
                if (line == "END_OF_TEXT")
                {
                    break;
                }

                var words = line.Split(' ').Select(x => x.ToLower());
                cnt += words.Where(x => x == W).Count();
            }

            Console.WriteLine(cnt);
        }
    }
}



Measured memory_bytes: 16152
n = int(input())
s = input()
ret = 0
for i in range(len(s)):
    sa = s[:i]
    sb = s[i:]
    bot = [0]*26
    for j in range(26):
        c = chr(j+ord('a'))
        if c in sa and c in sb:
            bot[j] += 1
    ret = max(ret,sum(bot))
print(ret)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=2e5+10;
int n;
int main() {
    //freopen("test.txt","r",stdin);
    int h,a;
    cin>>h>>a;
    int ans=h/a;
    if(h%a) ans++;
    cout<<ans<<endl;
    return 0;
}

/*
1.变量范围经常搞错，也就是临界情况不清晰
  1.1 加上一点，诸如下标从0~n-1的情况，对于某个其中的值，经常搞错个数和下标
2.经常性读错题目，尤其是看英文题面的情况下
3.结合上一点，如果是英文题面，一定要英文，只准翻译单个单词，逼着自己看英文题面
4.for循环中的i爆LL可能很难注意到
5.千万不要忽视轻视简单的问题
*/





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=305;
const int MOD=998244353;
int n;
char s[N];
long long dp[N][N][N];
bool f[N][N][N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	dp[n][0][0]=1;
	for(int i=n;i>=1;i--)
		for(int c0=0;c0<i;c0++)
			for(int c1=0;c0+c1<i;c1++)
			{
				dp[i-1][c0][c1]=(dp[i-1][c0][c1]+dp[i][c0][c1])%MOD;
				if(s[i]=='0') dp[i][c0][c1+1]=(dp[i][c0][c1+1]+dp[i][c0][c1])%MOD;
				else if(s[i]=='1') dp[i][c0+1][c1]=(dp[i][c0+1][c1]+dp[i][c0][c1])%MOD;
			}
	f[0][0][0]=true;
	for(int i=0;i<=n;i++)
		for(int c0=0;c0<=i;c0++)
			for(int c1=0;c0+c1<=i;c1++)
			{
				if(i+1<=n)
				{
					f[i+1][c0][c1]|=f[i][c0][c1];
					if(s[i+1]=='0'&&c1>0) f[i+1][c0+1][c1-1]|=f[i][c0][c1];
					if(s[i+1]=='1'&&c0>0) f[i+1][c0-1][c1+1]|=f[i][c0][c1];
				}
				if(i+2<=n)
				{
					if(s[i+1]=='0'||s[i+2]=='0') f[i+2][c0+1][c1]|=f[i][c0][c1];
					if(s[i+1]=='1'||s[i+2]=='1') f[i+2][c0][c1+1]|=f[i][c0][c1];
				}
			}
	f[n][0][0]=false;
	long long ans=0;
	for(int i=0;i<=n;i++)
		for(int c0=0;c0<=i;c0++)
			for(int c1=0;c0+c1<=i;c1++)
				if(f[i][c0][c1]) ans=(ans+dp[i][c0][c1])%MOD;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 127004
N = int(input())
p = list(map(int,input().split()))
def f(a):
    return all([ a[i] < a[i+1] for i in range(N-1)])
for i in range(N):
    for j in range(i+1, N):
        ls = [x for x in p]
        tmp = ls[i]
        ls[i] = ls[j]
        ls[j] = tmp
        if f(ls):
            print("YES")
            exit(0)
if f(p):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
/*input
5
1 2 3 4 5 6
1 3 5 6 8 4
1 2 3 4 5 8
1 2 4 5 10 11
1 2 3 6 9 11
*/
#include <bits/stdc++.h>
using namespace std;

int dp[30][1 << 13], Alice[13], Bob[13];
int mask1, mask2;

bool solve(int turn, int mask) {
	if(((mask & mask1) == mask1) && ((turn & 1) == 0)) return 1;
	if(((mask & mask2) == mask2) && (turn & 1)) return 0;
	if(dp[turn][mask] != -1) return dp[turn][mask];

	int ans, flag = 0;
	if(turn & 1) {
		ans = 0;
		for(int i = 0; i < 13; ++i) if(i != 6)
			if(Alice[i] && ((mask & (1 << i)) == 0)) {
				int ok = 0;
				if(i > 0) ok |= mask & (1 << (i - 1));
				if(i < 12) ok |= mask & (1 << (i + 1));
				if(ok) ans |= solve(turn + 1, mask | (1 << i)), flag = 1;
			}
		if(!flag) ans = solve(turn + 1, mask);
	}
	else {
		ans = 1;
		for(int i = 0; i < 13; ++i)
			if(Bob[i] && ((mask & (1 << i)) == 0)) {
				int ok = 0;
				if(i > 0) ok |= mask & (1 << (i - 1));
				if(i < 12) ok |= mask & (1 << (i + 1));
				if(ok) ans &= solve(turn + 1, mask | (1 << i)), flag = 1;
			}
		if(!flag) ans = solve(turn + 1, mask);
	}
	return (dp[turn][mask] = ans);
}

int main(){
	int test; scanf("%d", &test);

	while(test --) {
		mask1 = 0, mask2 = 1 << 6;
		memset(dp, - 1, sizeof dp);
		memset(Alice, 0, sizeof Alice);
		memset(Bob, 0, sizeof Bob);

		for(int i = 0; i < 6; ++i) {
			int a; scanf("%d", &a);
			mask1 |= 1 << (a - 1);
			Alice[a - 1] = 1;
		}

		for(int i = 0; i < 13; ++i)
			if((mask1 & (1 << i)) == 0) mask2 |= 1 << i, Bob[i] = 1;

		puts(solve(1, 1 << 6) ? "yes" : "no");
	}
	// cerr << fixed << setprecision(6) << (double)clock() / CLOCKS_PER_SEC << endl;
}	


Measured memory_bytes: 4132
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int num = Integer.parseInt(br.readLine());
            int max = num;
            int maxCount = 0;
            for (int i = num; i > 0; i--) {
                int tmp = checkCount(i);
                if (maxCount < tmp) {
                    max = i;
                    maxCount = tmp;
                }
            }
            System.out.println(max);
        } catch (IOException e) {
            e.printStackTrace();
           }
    }

    public static int checkCount(int num) {
        int ret = 0;
        while (true) {
            if (num % 2 == 0) {
                num = num / 2;
                ret++;
            } else {
                break;
            }
        }
        return ret;
    }
}

Measured memory_bytes: 21076
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
ll N=1e9+7;
int main()
{
	ll n;
	cin>>n;

	if(n<=2)
	{
		cout<<0<<endl;
		return 0;
	}
	
		if(n<=5)
		{
			cout<<1<<endl;
			return 0;
		}

		vector<ll> dp(n+1);

		dp[3]=dp[4]=dp[5]=1;

		for(ll i=6;i<=n;i++)
		{
			dp[i]=1;
			for(int j=3;i-j>=3;j++)
			{
				dp[i]+=dp[i-j];
				dp[i]%=N;
			}
		}

		cout<<dp[n]<<endl;
		
	return 0;
}

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

int main(){
    long long n, m, x;
    cin >> n >> m >> x;

    vector<long long> cost(n+1, 0);

    for(long long i = 0; i < m; i++){
        long long a;
        cin >> a;
        cost[a] = 1;
    }
    long long ans = 0;
    for(long long i = x; i <= n; i++){
        ans += cost[i];
    }

    long long ans2 = 0;
    for(long long i = 0; i <= x; i++){
        ans2 += cost[i];
    }
    cout << min(ans, ans2) << endl;
    return 0;
}


Measured memory_bytes: 3612
from itertools import permutations
N = int(input())
A = list(map(int, input().split()))

# 1 ^ 2 ^ 3 ^ 4 ^ 4 などが0になる順番は関係ない
# 各桁のビットが偶数になるかカウントする
D = [0] * 30
for a in A:
    bit = bin(a)[2:][::-1]
    for i in range(len(bit)):
        D[i] += int(bit[i])
# print('D', D)

ans = 'Yes' if all([d % 2 == 0 for d in D]) else 'No'
print(ans)


Measured memory_bytes: 14496
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;


int main(){
  int n;
  cin >> n;
  bool ans = false;
  while(n > 0){
    if(n % 10 == 9) ans = true;
    n /= 10;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	int n, deep;
	int[] d, f;
	boolean[][] g;
	void run() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		g = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			int u = scan.nextInt();
			int k = scan.nextInt();
			for (int j = 0; j < k; j++) {
				int v = scan.nextInt();
				g[u - 1][v - 1] = true;
			}
		}
		deep = 0;
		d = new int[n];
		f = new int[n];
		dfs(0);
		for (int i = 0; i < n; i++)
			if (d[i] == 0)
				dfs(i);

		for (int i = 0; i < n; i++)
			System.out.println((i + 1) + " " + d[i] + " " + f[i]);
	}
	void dfs(int u) {
		if (d[u] > 0 || f[u] > 0)
			return;

		d[u] = ++deep;
		for (int i = 0; i < n; i++)
			if (g[u][i])
				dfs(i);
		f[u] = ++deep;
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 28340
/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout); 
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;



void solve()
{
	ll n,k;
	cin>>n>>k;
	ll r,s,p;
	cin>>r>>s>>p;
	string t;cin>>t;
	map<char,char> m1;
	map<char,ll> m2;
	m1['r']='p';
	m1['s']='r';
	m1['p']='s';

	m2['r']=r;
	m2['s']=s;
	m2['p']=p;

	ll i;
	ll ans=0;
	bool lose[n]={0};
	rep(i,n)
	{
		if(lose[i]) continue;
		if(i+k<n)
		{
			if(t[i]==t[i+k] && m2[m1[t[i]]]>=m2[m1[t[i+k]]])
			{
				lose[i+k]=1;
				ans+=m2[m1[t[i]]];
			}
			else ans+=m2[m1[t[i]]];
		}
		else ans+=m2[m1[t[i]]];
	}
	cout<<ans;
}

int main()
{
//	fio();
	fast
	ll t=1;
	//cin>>t;

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

Measured memory_bytes: 592
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var hList = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int ans = 1;
            for (int i = 1; i < N; i++)
            {
                if (hList.Take(i).Any(x => x > hList[i]))
                {
                }
                else
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 8;
int N, A, B, C, L[Nmax];

int main(){
	cin >> N >> A >> B >> C;
	for(int i=0; i<N; i++) cin >> L[i];

	int ans = 1e8;
	for(int k=0; k<(1<<(2*N)); k++){
		int xa=0, xb=0, xc=0;
		int na=0, nb=0, nc=0;
		for(int i=0; i<N; i++){
			int j=(k>>(2*i))&3;
			if(j == 1){
				xa+=L[i];
				na++;
			}
			else if(j==2){
				xb+=L[i];
				nb++;
			}
			else if(j==3){
				xc+=L[i];
				nc++;
			}
		}
		if(na==0||nb==0||nc==0) continue;

		ans=min(ans, 10*(na+nb+nc-3)+abs(A-xa)+abs(B-xb)+abs(C-xc));
	}

	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int sum=0;
  for(int i=0;i<s.length();i++)
    sum+=s[i]-'0';
  if(sum%9==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}  

Measured memory_bytes: 3760
#include<iostream>
#include<vector>
using namespace std;
int v[100005];
int d[100005];
vector <pair<int,int> > g[100005];
bool f(int x,int y)
{
	if(v[x])return d[x]!=y;
	v[x]=1;
	d[x]=y;
	for(int i=0;i<g[x].size();i++)
	    if(f(g[x][i].first,g[x][i].second+y))
	        return true;
	return false;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b,d;
		cin>>a>>b>>d;
		g[a].push_back(make_pair(b,d));
		g[b].push_back(make_pair(a,-d));
	}
	for(int i=0;i<n;i++)
	    if(!v[i]&&f(i,0))
	    {
	    	cout<<"No";
	    	return 0;
		}
	cout<<"Yes";
	return 0;
}

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

int main(){

	int H , R;
	cin >> H >> R;

	//各、太陽の位置の比較をする
	if(H+R == 0) cout << 0 << endl;  //日の入り、日の出
	else if(H+R > 0) cout << 1 << endl;  //昼間
	else cout << -1 << endl;  //夜間

	return 0;
}


Measured memory_bytes: 3120
n, a, b = map(int, input().split())
res = n
if a % 2 == b % 2:
    res = abs(a - b) // 2
else:
    av = (a - 1) + (b - 1) + 1
    bv = (n - a) + (n - b) + 1
    res = min(av, bv) // 2
print(res)

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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	sort(a.begin(), a.end());
	int an = a[n - 1], ar = a[0];
	long long d = abs(an - ar * 2);
	for (int i = 1; i < n - 1; i++) {
		if (d > abs(an - a[i] * 2)) { d = abs(an - a[i] * 2); ar = a[i]; }
	}
	cout << an << ' ' << ar << endl;
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            ulong[] dArray = Console.ReadLine().Split(' ').Select(i => ulong.Parse(i)).ToArray();
            ulong total = 1;
            ulong max = Convert.ToUInt64(Math.Pow(10d, 18d));
            Array.Sort(dArray);
            for (int d = 0; d < N; d++)
            {
                try
                {
                    checked
                    {
                        total *= dArray[d];
                    }
                    if (total > max||total<0)
                    {
                        Console.WriteLine("-1");
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine("-1");
                    return;
                }
            }
                Console.WriteLine(total);
        }
    }
}

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();


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

#define ll long long
using namespace std;
const int kmod = 1e9 + 7;
double ans = 0;


double solve(int idx ,int h ,vector<double>& coins , vector<vector<double>>&dp ,int n )
{
    if(idx == n)
    {
        int t = n - h;
        if( h > t)
         return 1.0;
        return 0.0;
    }
    
    if(dp[idx][h] != -1)
     return dp[idx][h];
    
    double my = 0;
     
     my = solve(idx + 1 , h + 1 , coins , dp , n  )*coins[idx] ;

    my = my + solve(idx + 1 , h , coins , dp , n )*(1 - coins[idx]);
   
    
    return dp[idx][h] = my;

}
int main()
{
    
   
   int n;
   cin>>n;
   
   vector<double>coin(n);

   vector<vector<double>>dp(n+1 , vector<double>(n+1 ,-1));

   for(int i = 0; i<n ;i++)
   cin>>coin[i];

    double ans = solve(0 , 0 , coin , dp , n);
   
   
   printf("%.9lf\n" ,ans);
   
}


Measured memory_bytes: 74024
x, y = map(int, input().split())
MOD = 10 ** 9 + 7

if (x+y) % 3 != 0:
    print(0)
    exit()

#m: (i+2, j+1), n (i+1, j+2)

m = (2*x - y) // 3
n = (2*y - x) // 3

if m < 0 or n < 0:
    print(0)
    exit()

ans = 1
i = 1

if n > m:
    n, m = m, n

while i <= n:
    ans *= (m+i) * pow(i, MOD-2, MOD)
    ans %= MOD
    i += 1

print(ans)

Measured memory_bytes: 41324
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

ll dp[200200][2]; // dp[i][j]:i番目のグループで(j==0:左、j==1:右)を取った時の最大値
ll dp2[200200][2][2]; // dp2[i][j][k]:i番目のグループで(j==0:左、j==1:右)を取った時の最大値
					  // kは既に1グループ飛ばしたかどうか

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<=n;i++){
		// 初期化
		dp[i][0]=dp[i][1]=-1e18;
		dp2[i][0][0]=dp2[i][0][1]=dp2[i][1][0]=dp2[i][1][1]=-1e18;
	}
	int m=n/2;
	if(n%2==0){
		dp[1][0]=a[0],dp[1][1]=a[1];
		for(int i=1;i<m;i++){
			for(int j=0;j<2;j++){
				if(j==0){
					dp[i+1][0]=max(dp[i+1][0],dp[i][j]+a[2*i]);
				}
				dp[i+1][1]=max(dp[i+1][1],dp[i][j]+a[2*i+1]);
			}
		}
		cout << max(dp[m][0],dp[m][1]) << endl;
	}
	else{
		// a[n-1]を使わない場合　上の偶数の場合と一緒
		dp[1][0]=a[0],dp[1][1]=a[1];
		for(int i=1;i<m;i++){
			for(int j=0;j<2;j++){
				if(j==0){
					dp[i+1][0]=max(dp[i+1][0],dp[i][j]+a[2*i]);
				}
				dp[i+1][1]=max(dp[i+1][1],dp[i][j]+a[2*i+1]);
			}
		}
		// a[n-1]を使う場合
		dp2[1][0][0]=a[n-1]+a[0],dp2[1][1][0]=a[n-1]+a[1];
		dp2[1][0][1]=a[n-1];
		for(int i=1;i<m;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
					if(k==0){
						dp2[i+1][0][1]=max(dp2[i+1][0][1],dp2[i][j][k]);
					}
					if(j==0){
						dp2[i+1][0][k]=max(dp2[i+1][0][k],dp2[i][j][k]+a[i*2]);
					}
					// a[n-2]は使えない事に注意！
					if(i!=m-1)dp2[i+1][1][k]=max(dp2[i+1][1][k],dp2[i][j][k]+a[i*2+1]);
				}
			}
		}
		cout << max({dp[m][0],dp[m][1],dp2[m][0][1],dp2[m][1][1]}) << endl;
	}
}


Measured memory_bytes: 14256
#include <stdio.h>
#include <string.h>

int absn(int n){
  if(n>0){
    return n;
  }
  return -n;
}

void cint(char*S1,int*S,int N){
  int i;
  for(i=0;i<N;i++){
    S[i]=(int)S1[i]-(int)('0');
  }
}

int main(){
  long long int num;
  int i;
  scanf("%lld",&num);
  int N=0;
  long long int temp=num;
  while(num>0){
    num=num/10;
    N++;
  }
  int S[N];
  for(i=0;i<N;i++){
    S[N-i-1]=temp%10;
    temp=temp/10;
  }
  
  int min=absn(100*S[0]+10*S[1]+S[2]-753);
  for(i=1;i<=N-3;i++){
    if(absn(100*S[i]+10*S[i+1]+S[i+2]-753)<min){
      min=absn(100*S[i]+10*S[i+1]+S[i+2]-753);
    }
  }
  printf("%d",min);
  return 0;
}
  


Measured memory_bytes: 128
// KOI NI YAAR SAB SAHI HOEGA  BAS  CHORRO MAT
// ENJOR KARO YAAR
// HAAR MAT MAANO
// // APNA TIME AAYEGA
// BEILIEVE IN GOD
#include<bits/stdc++.h>
using namespace std;
#define lli int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
#define PI  3.14159265358979
#define pri  priority_queue<ll>
#define prim  priority_queue<ll,vector<ll>,greater<ll>>
#define flush  cout<<flush

const lli  N=3e3+10;
 
vector<vector<lld>> dp(N,vector<lld>(N,-1)); 
lli n;
vector<lld>a;



lld solve(lli index , lli tails)
{if(index == n)
{if(tails<=n/2)
{return 1;
}
else
{return 0;
}
}
if(dp[index][tails]!=-1)
{return dp[index][tails];
}
return dp[index][tails] = (a[index] *1.0 * solve(index+1,tails)) + (1-a[index])  * 1.0 * solve(index+1,tails+1);
}

int main()
{lli num;
fast();
cin>>n;
a.resize(n);
loop(i,0,n)
{cin>>a[i];
}

cout<<fixed<<setprecision(10)<<solve(0,0)<<"\n";
}


Measured memory_bytes: 145764
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxx = 100000 + 10;
struct Node {
    int key;
    Node *prev, *next;
};

Node *nil;

// 链表初始化
void init() {
    nil = (Node *)malloc(sizeof(Node));
    //C++ nil = new Node();
    nil->next = nil;
    nil->prev = nil;
}

// 从链表搜索出值为key的结点 O(n)
Node* listSearch(int key) {
    // 从链表头结点开始访问
    Node *cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

// 打印链表
void printList() {
    Node *cur = nil->next;
    int flag = 0;
    while (cur != nil) {
        if (flag++ > 0)
            printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

// 删除结点t
void deleteNode(Node *t) {
    // t为头结点不做处理
    if (t == nil)
        return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
    //C++ delete(t);
}

// 删除头结点
void deleteFirst() {
    deleteNode(nil->next);
}

// 删除尾结点
void deleteLast() {
    deleteNode(nil->prev);
}

// 删除指定的key O(n)
void deleteKey(int key) {
    deleteNode(listSearch(key));
}

// 在链表头部添加元素key
void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    //C++ Node *x = new Node();
    x->key = key;

    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}
int main() {
    int n, key, size = 0;
    char op[20];
    scanf("%d", &n);
    getchar();
    // 初始化链表
    init();
    for (int i = 0; i < n; i++) {
        scanf("%s %d", op, &key);
        if (op[0] == 'i') {
            insert(key);
            size++;
        }
        else {
            if (strlen(op) > 6) {
                if (op[6] == 'F') {//删除头结点
                    deleteFirst();
                }
                else {//删除尾结点
                    deleteLast();
                }
            }
            else { //删除结点
                deleteKey(key);
            }
            size--;
        }
    }
    printList();
    return 0;
}


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


int main (){
	int a,b,c,min=700000;
	cin>>a>>b>>c;
	int aux=a+b;
	int aux2=a+c;
	int aux3=b+c;
	int ar[3];
	ar[0]=aux;
	ar[1]=aux2;
	ar[2]=aux3;
	for(int i=0;i<3;i++){
		if(ar[i]<min){
			min=ar[i];
		}
	}

	cout<<min; 
	
}

Measured memory_bytes: 3604