akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <ctype.h>

int main(){
    char ch;
    while(1){
        scanf("%c", &ch);
        if(ch=='\n'){
            printf("\n");
            break;
        }else if(islower(ch)){
            printf("%c", toupper(ch));
        }else if(isupper(ch)){
            printf("%c", tolower(ch));
        }else{
            printf("%c", ch);
        }
    }

    return 0;
}



Measured memory_bytes: 2068
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 1000000;
const int MOD = 1000000007;

int n;

int f[MAXN + 1];

int inv[MAXN + 1];
int fac[MAXN + 1];
int ifac[MAXN + 1];

int C(int n, int k) {
	if (k<0 || k>n) return 0;
	return (ll)fac[n] * ifac[k] % MOD*ifac[n - k] % MOD;
}

int calc(int nop) {
	int nspace = n, nhash = n - nop;
	if (nhash == 0) return 0; else --nhash, nspace -= 2;
	if (nspace < 2 * nhash) return 0;
	return (ll)C(nspace - nhash, nhash)*fac[nop] % MOD*fac[n - 1 - nop] % MOD;
}

int bf() {
	vector<int> p(n - 1); REP(i, n - 1) p[i] = i;
	int ret = 0;
	map<int, int> tmp;
	do {
		int mask = 0; int cnt = 0;
		REPSZ(i, p) {
			REP(j, 2) {
				int x = p[i] + j;
				if (mask&(1 << x)) continue;
				mask |= 1 << x; ++cnt;
			}
			if (cnt == n) {
				int ans = i + 1;
				ret += ans;
				if (ans <= n - 2) {
					int pmask = 0; REP(j, n - 2) pmask |= 1 << p[j];
					++tmp[pmask];
				}
				break; 
			}
		}
		assert(cnt == n);
	} while (next_permutation(p.begin(), p.end()));
	for (auto it = tmp.begin(); it != tmp.end(); ++it) { int mask = it->first; REP(i, n) printf("%c", mask&(1 << i) ? '+' : '.'); printf(" = %d\n", it->second); }
	return ret;
}

void run() {
	scanf("%d", &n);
	inv[1] = 1; FORE(i, 2, n) inv[i] = (ll)(MOD - MOD / i)*inv[MOD%i] % MOD;
	fac[0] = 1; FORE(i, 1, n) fac[i] = (ll)fac[i - 1] * i%MOD;
	ifac[0] = 1; FORE(i, 1, n) ifac[i] = (ll)ifac[i - 1] * inv[i] % MOD;

	REP(i, n) f[i] = calc(i);
	//printf("f:"); REP(i, n) printf(" %d", f[i]); puts("");
	int ret = 0;
	FOR(i, 1, n) {
		int cur = (f[i] - f[i - 1] + MOD) % MOD;
		ret = (ret + (ll)i*cur) % MOD;
	}
	printf("%d\n", ret);
	//if (n <= 11) printf("bf=%d\n", bf());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 15872
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
a = a1 - b1
b = a2 - b2
if a < 0:
    a = -a
    b = -b
p = t1 * a + t2 * b
if p > 0:
    print(0)
    exit()
if p == 0:
    print('infinity')
    exit()
top = a * t1
p = -p
ans = (top // p + 1) * 2 - 1 - (top % p == 0)
print(ans)

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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.first << ", " << p.second << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int n;
    string w;
    cin >> n;
    string last;
    uset<string> s;
    for (int i = 0; i < n; i++) {
        cin >> w;
        if (i > 0 && (s.find(w) != s.end() || w.front() != last.back())) {
            cout << "No";
            return 0;
        }
        s.insert(w);
        last = w;
    }
    cout << "Yes";
}


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

int main()
{
  int K ;
  string S ;
  cin>>K>>S ;
  
  if(S.size()<=K) cout<<S<<endl ;
  else{
    for(int i=0;i<K;i++) cout<<S.at(i) ;
    cout<<"..."<<endl ;
  }
  
  return 0 ;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
string S1;
cin>>S1;
string S2;
cin>>S2;
int c=0;
	for(int i=0;i<3;i++)
	{
		if(S1[i]==S2[i])
	
	c++;
}
	cout<<c;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, m, a, b, CNT;
bool dc[709][709], flag;
int vis[709];
bool dp[1000][1000];
vector<int> vec[2];

int co_cnt(int x, bool t)
{
	if (t)
		vis[x] = 1;
	else
		vis[x] = 2;
	int retval = 0;
	if (t) retval++;
	for (int i = 0; i < n; i++) {
		if (i == x) continue;
		if (vis[i] == 0 && !dc[x][i]) {
			retval += co_cnt(i, !t);
		}
		else if (!dc[x][i] && vis[i]) {
			if (vis[i] == vis[x]) flag = true;
		}
	}
	return retval;
}

void cnt(int x)
{
	vis[x] = 1;
	CNT++;
	for (int i = 0; i < n; i++) {
		if (i == x) continue;
		if (vis[i] == 0 && !dc[x][i]) {
			cnt(i);
		}
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		a--; b--;
		dc[a][b] = true;
		dc[b][a] = true;
	}
	for (int i = 0; i < n; i++) {
		if (vis[i] == 0) {
			int tmp = co_cnt(i, true);
			if (flag) {
				cout << -1 << E;
				return 0;
			}
			vec[0].pb(tmp);
		}
	}
	memset(vis, 0, sizeof(vis));
	for (int i = 0; i < n; i++) {
		if (vis[i] == 0) {
			CNT = 0;
			cnt(i);
			vec[1].pb(CNT);
		}
	}
	int sz = vec[0].size();
	dp[0][vec[0][0]] = true;
	dp[0][vec[1][0] - vec[0][0]] = true;
	//dp[0][0] = true;
	for (int i = 1; i < sz; i++) {
		int a = vec[0][i];
		int b = vec[1][i] - a;
		for (int j = 0; j < 1000; j++) {
			if (dp[i - 1][j]) {
				dp[i][j + a] = true;
				dp[i][j + b] = true;
			}
		}
	}
	int ans = 1e9;
	for (int i = 0; i < 1000; i++) {
		if (dp[sz - 1][i]) {
			int tmp = i * (i - 1) / 2;
			tmp += (n - i)*(n - i - 1) / 2;
			ans = min(ans, tmp);
		}
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int> v;
int main() {
	cin >> N;
	int n = N;
	cout << N << ":";
	for (int i = 2; i*i <N; ++i) {
		while (n%i == 0) {
			cout <<" " << i;
			n /= i;
		}
		if (n == 1) break;
	}
	if (n != 1) cout << " " << n;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>

int main(void){
    int n,x,i,j,k,cnt;
    scanf("%d %d",&n,&x);
    while(n || x){
        cnt = 0;
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                for(k=j+1;k<=n;k++){
                    if(i + j + k == x){
                        cnt++;
                    }    
                }
            }
        }
        printf("%d\n",cnt);
        scanf("%d %d",&n,&x);
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <set>
#define INF 0x3f3f3f3f
#define LL long long
#define pii pair<int,int>
using namespace std;
const double pi = 2*acos(0.0);
const int maxn = 3e5 + 30;
const int inf=2e9;
const int maxm = 1e7 + 10;
const int mod = 1e9+7;
const int base = 5e6+10;

int main()
{
    LL x,y;
    cin >> x >> y;
    int cnt = 0;
    for(LL i=x;i<=y;) {
        cnt++;
        i = i*2;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << setprecision(16);
    string s; cin >> s;
    int cur = 0;
    reverse(s.begin(), s.end());
    vector<string> t = {"dream","dreamer","erase","eraser"};
    rep(i,4) reverse(t[i].begin(), t[i].end());
    while(cur != SIZE(s)){
        if(s.substr(cur,5) == t[0]) cur += 5;
        else if(s.substr(cur,7) == t[1]) cur += 7;
        else if(s.substr(cur,5) == t[2]) cur += 5;
        else if(s.substr(cur,6) == t[3]) cur += 6;
        else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
int main(){//D問題
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    for(int i=0;i<n;++i){
        cin >> x[i];
    }
    ll ans=0;
    for(int i=1;i<n;++i){
        ans += min(a*(ll)(x[i]-x[i-1]), (ll)b);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
import math
N = int(input())
sum = math.factorial(N)
X = [0] * N
Y = [0] * N
ans = 0
for i in range(N):
    X[i], Y[i] = map(int,input().split())
for i in range(N):
    x1 = X[i]
    y1 = Y[i]
    for j in range(i+1,N):
        x2 = X[j]
        y2 = Y[j]
        ans += (((x1-x2)**2+(y1-y2)**2)**(1/2)) * (sum//N) * 2
print(ans/sum)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;

int main()
{
ll n , m ;
cin >> n >> m ;
if(n%2){
  rep(i,m){
cout << i+1 <<' '<<n-i<< endl;
  }
}
else{
  ll cnt=1;
  ll b=n/2-1;
  for (ll i = 1; i <= (b+1)/2; i++)
  {
    if(cnt>m)break;
    cout << i <<' '<<b-(i-1)+1<< endl;
    cnt++;
  }
  for (ll i = 1; i <= (b+1)/2; i++)
  {
    if(cnt>m)break;
    cout << i+b+1 <<' '<<b-(i-1)+1+b<< endl;
    cnt++;
  }
}
return 0;
}

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

int main(){
     int  k;
    cin>>k;
    long long int  count=0;
    for ( int  i = 1; i <= k; i++)
    {
        
      for (int h = 1; h <= k; h++)
      {
          for (int o = 1; o <= k; o++)
          {
              if(i==1 || h==1 || o==1){
                  count+=1;
                  
              }else{
              int a=i;int b= h; int c=o;
              while (b) { a %= b; swap(a, b); } 
              while (c) { a %= c; swap(a, c); } 
              count+=a;}
          }
          
        
      }
      
    }
    cout<< count <<endl;

}

Measured memory_bytes: 3648
#include <iostream>
#include <cmath>

int main()
{
    int x, pow = 0, i, j, ans = 1;

    std::cin >> x;

    for (i = 2;;i++){
        for (j = 2;;j++){
            pow = std::pow(i, j);
            //std::cout << pow<<std::pow(i, j) <<" " << i <<" " <<j<<"\n";
            if(pow > x){
                break;
            }
            ans = std::max(pow, ans);
        }
        if(j == 2){
            break;
        }
    }

    std::cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010
ll ex(ll a,ll b){
	ll ans=1;while(b){
		if(b&1)ans=(ans*a)%md;a=(a*a)%md;b/=2;
	}
	return ans;
}
int main(){
	IOS;
	ll n;cin>>n;
	ll a[n],b[n];
	rep(i,0,n)cin>>a[i];
	rep(i,0,n){
		if(i==0)b[i]=n-1;
		else b[i]=b[i-1]-2;
	}
	for(ll i=n-1;i>=0;--i){
		if(i==n-1)b[i]=max(b[i],n-1);
		else b[i]=max(b[i],b[i+1]-2);
	}
	ll f[n+1]={0};
	rep(i,0,n)f[b[i]]++;
	rep(i,0,n)f[a[i]]--;
	bool ok=1;
	rep(i,0,n+1)if(f[i]<0)ok=0;
	if(!ok)cout<<0;
	else cout<<ex(2,n/2)%md;
	
	
	
	
	return 0;
}



Measured memory_bytes: 2560
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    A, B, X = map(int, readline().split())

    if A <= X <= A + B:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

class iv{
    
};

class ie{

};


class edge{
    public:

    int frm;
    int to;
    int cost;

    edge(int f,int t):frm(f),to(t){};
    edge(int f,int t,int c):frm(f),to(t),cost(c){};
};



class Graph{
    public:

    int nV;
    int nE;

    vector<iv> vinfo;
    vector<ie> einfo;

    vector< vector< edge > > g;

    Graph(int _nV,int _nE):nV(_nV),nE(_nE){

        g.resize(nV);
        vinfo.resize(nV);
        einfo.resize(nE);

    }

    void addE(int u,int v){//無効グラフの時は逆方向もちゃんと張ろう
        edge e(u,v,1);
        g[u].eb(e);
    }

    void addE(int u,int v,int cost){ //無効グラフの時は逆方向もちゃんと張ろう
        edge e(u,v,cost);
        g[u].eb(e);
    }

    vector<int> dijkstra(int s){ //0idx_
        vector<int> dist(nV,INF);
        dist[s] = 0;

        vector<bool> vis(nV,false);
        priority_queue< P, vector<P> , greater<P> > que;
        que.push(P(0,s));

        while(!que.empty()){
            P vd = que.top(); que.pop();

            int cur = vd.se;
            int cdist = vd.fi;
            vis[cur] = true;

            // cout<<"visit : "<<cur<<endl;

            rep(i , g[cur].size()){
                edge e = g[cur][i];
                int nex = e.to;
                int cost = e.cost;

                if(vis[nex])continue;//ここで親じゃない頂点引いたら閉路あり？

                if(chmin( dist[nex] , cdist+cost )){
                    //cout<<s<<" -- "<<nex<<" => "<<dist[nex]<<endl;
                }else{

                }

                que.push(P(dist[nex],nex));
            }
        }

        return dist;
    }



};

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int V,E,r;
    cin>>V>>E>>r;

    Graph g(V,E);

    rep(i,E){
        int u,v,c;
        cin>>u>>v>>c;

        g.addE(u,v,c);
        //g.addE(v,u,c);
    }

    vector<int> dist = g.dijkstra(r);
    for(int d:dist){
        if(d!=INF)cout<<d<<endl;
        else puts("INF");
    }
    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}



Measured memory_bytes: 22724
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  qsort(a, n, sizeof(long), cmpnum);
  long zero = 0;
  long minus = 0;
  long plus = 0;
  for (long i = 0; i < n; i++) {
    if (a[i] == 0) {
      zero++;
    } else if (a[i] < 0) {
      minus++;
    } else {
      break;
    }
  }
  plus = n-zero-minus;
  long all = n*(n-1)/2;
  long mul_minus = minus*plus;
  long mul_plus = minus*(minus-1)/2+plus*(plus-1)/2;
  long mul_zero = all-mul_minus-mul_plus;

  long start,end,center;
  long less_count,last;

  if (k <= mul_minus) {
    start = a[0]*a[n-1]-1;
    end = 0;
    while (1) {
      if (start+1 == end) {
        break;
      }
      center = (start+end)/2;
      less_count = 0;
      last = n-plus;
      for (long i = 0; i < minus; i++) {
        if (a[i]*a[n-1] >= center) {
          break;
        }
        for (long j = last; j <= n-1; j++) {
          if (a[i]*a[j] < center) {
            less_count += n-j;
            last = j;
            break;
          }
        }
      }
      if (less_count < k) {
        start = center;
      } else {
        end = center;
      }
    }
    printf("%ld\n", start);
  } else if (k <= mul_minus+mul_zero) {
    printf("0\n");
  } else {
    k -= mul_minus+mul_zero;
    start = 0;
    end = pow(10,18)+1;
    while (1) {
      if (start+1 == end) {
        break;
      }
      center = (start+end)/2;
      less_count = 0;
      last = 0;
      for (long i = minus-1; i > 0; i--) {
        if (a[i]*a[i-1] >= center) {
          break;
        }
        for (long j = last; j < i; j++) {
          if (a[i]*a[j] < center) {
            less_count += i-j;
            last = j;
            break;
          }
        }
      }
      last = n-1;
      for (long i = n-plus; i < n-1; i++) {
        if (a[i]*a[i+1] >= center) {
          break;
        }
        for (long j = last; j > i; j--) {
          if (a[i]*a[j] < center) {
            less_count += j-i;
            last = j;
            break;
          }
        }
      }
      if (less_count < k) {
        start = center;
      } else {
        end = center;
      }
    }
    printf("%ld\n", start);
  }

  return 0;
}

Measured memory_bytes: 3324
// 72 72 72 72 72 72 72 72 72 72 72
#include <bits/stdc++.h> 
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef double ld;
typedef string st;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
const ll MOD = 1e9 + 7 ;
const ll INF=1e17;                                                                                                  
ll mpow(ll a,ll b){a=a%MOD;ll res=1;while(b>0){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b=b>>1;}return res%MOD;}             

int main()
{ 
ios_base::sync_with_stdio(false);
cin.tie(NULL);
///freopen("input.txt", "r", stdin);
//freopen("output.txt","w",stdout);
ll n;
cin>>n;
ll s=0;
ll p=n;
while(p)
{
    s+=p%10;
    p/=10;
}
cout<<(n%s?"No":"Yes");
return 0;    
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,y,i,j,k;
  int ans10000,ans5000,ans1000;
  scanf("%d %d",&n,&y);
  for(i=0;i<=n;i++){
    for(j=0;j<=n;j++){
        k=n-i-j;
      if( i+j<n && 10000*i+5000*j+1000*k==y){
          ans10000=i;
          ans5000=j;
          ans1000=k;
          printf("%d %d %d \n",ans10000,ans5000,ans1000);
          return 0;
      }else if( i+j == n && 10000*i+5000*j==y){
        ans10000=i;
        ans5000=j;
        ans1000=0;
        printf("%d %d %d \n",ans10000,ans5000,ans1000);
        return 0;
      }
    }
  }
  printf("%d %d %d",-1,-1,-1);
  return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int H,W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> v(N);
    REP(i,N) cin >> v[i];

    bool is_reverse = false;
    vector<int> vec;
    FOR(i,1,N+1) {
        REP(j,v[i-1]) vec.push_back(i);
    }

    REP(i,H) {
        vector<int> av;
        REP(j,W) av.push_back(vec[(i*W)+j]);
        if(is_reverse) reverse(ALL(av));
        REP(j,W-1) {
            cout << av[j] << " ";
        }
        cout << av[W-1] << endl;
        is_reverse = !is_reverse;
    }




}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main(void) {
	int h,w;
	scanf("%d %d",&h,&w);
	int mapv[h][w];
	int mova[h*w][4];
	int movi = 0;
	for (int i=0;i<h;i++) {
		for (int j=0;j<w;j++) {
			scanf("%d",&mapv[i][j]);
		}
	}
	for (int i=0;i<h;i++) {
		for (int j=0;j<w;j++) {
			if (mapv[i][j]&1) {
				mapv[i][j]--;
				if (j+1<w) {
					mapv[i][j+1]++;
					mova[movi][0] = i+1;
					mova[movi][1] = j+1;
					mova[movi][2] = i+1;
					mova[movi][3] = j+2;
					movi++;
				}
				else if (i+1<h) {
					mapv[i+1][j]++;
					mova[movi][0] = i+1;
					mova[movi][1] = j+1;
					mova[movi][2] = i+2;
					mova[movi][3] = j+1;
					movi++;
				}
			}
		}
	}
	printf("%d\n",movi);
	for (int i=0;i<movi;i++) {
		printf("%d %d %d %d\n",mova[i][0],mova[i][1],mova[i][2],mova[i][3]);
	}
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  int N = 1, M;
  for (int i = 0; i < 2; i++) {
    N = N * (n - i);
  }
  ans = ans + N / 2;
  N = 1;
  for (int i = 0; i < 2; i++) {
    N = N * (m - i);
  }
  ans = ans + N / 2;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

d = {}
for i in range(len(S)):
  d[S[i]] = T[i]

t = []
for i in range(len(S)):
  t.append(d[S[i]])

if ''.join(t) != T or len(d.values()) != len(set(d.values())):
  print('No')
else:
  print('Yes')


Measured memory_bytes: 5296
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    StringBuilder sb = new StringBuilder();

    if(a < b){
      for(int i=0; i<b; i++)
        sb.append(a);
    }else{
      for(int i=0; i<a; i++)
        sb.append(b);
    }
    String ans = sb.toString();
	System.out.println(ans);
  }
}


Measured memory_bytes: 23892
//#include <ext/pb_ds/assoc_container.hpp> 
 //#include <ext/pb_ds/tree_policy.hpp>
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=998244353;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a,ll md) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution
const int ce=998244353;
ll fast_mod(ll input)
{
    return input < ce ? input : input%ce;
}
#define pi acos(-1)

int32_t main()
{
    IOS
 
    set<string> s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s1;
        cin>>s1;
        s.insert(s1);
    }
    cout<<(int)s.size();
}       


Measured memory_bytes: 19236
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int n, q;
int a[N], pref1[N], pref2[N], pref[N];

void precompute()
{
	for(int i=1;i<=n;i++)
	{
		pref1[i]=pref1[i-1];
		pref2[i]=pref2[i-1];
		pref[i]=pref[i-1]+a[i];
		if(i%2)
			pref1[i]+=a[i];
		else
			pref2[i]+=a[i];
	}
}

int check(int x, int k)
{
	int cnt=upper_bound(a+1, a+n+1, x+k) - lower_bound(a+1, a+n+1, x-k);
	int have=n + 1 - (upper_bound(a+1, a+n+1, x+k) - a);
	return have>=cnt;
}

int binsearch(int x, int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi+1)/2;
		if(check(x, mid))
			lo=mid;
		else
			hi=mid-1;
	}
	return lo;
}


int32_t main()
{
	IOS;
	cin>>n>>q;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	precompute();
	while(q--)
	{
		int x;
		cin>>x;
		if(x>=a[n])
		{
			int ans;
			if(n%2==0)
				ans=pref2[n];
			else
				ans=pref1[n];
			cout<<ans<<endl;
			continue;
		}
		if(x<=a[1])
		{	
			int cnt=n/2 + n%2;
			int ans=pref[n] - pref[n-cnt];
			cout<<ans<<endl;
			continue;
		}
		int k=binsearch(x, 0, 1e9);	
		auto u = upper_bound(a+1, a+n+1, x+k) - a - 1;
		auto v = lower_bound(a+1, a+n+1, x-k) - a - 1;
		int have=n + 1 - (upper_bound(a+1, a+n+1, x+k) - a);
		int cnt=upper_bound(a+1, a+n+1, x+k) - lower_bound(a+1, a+n+1, x-k);
		while(have>cnt)
			v--, have--;
		int ans = pref[n] - pref[u];
		if(v%2)
			ans+=pref1[v];
		else
			ans+=pref2[v];
		cout<<ans<<endl;
	}	
	return 0;
}

Measured memory_bytes: 4864
eval"N,*D="+`dd`.split*?,
A=[0]*N
m=998244353
f=->a,b{b>0?a**b[0]*f[a,b/2]**2%m:1}
D.map{|d|A[d]+=1}
s=q=0**D[A[0]-1]
A.map{|a|s=s*f[q,q=a]%m}
p s

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef int64_t ll;
typedef long double ld;
using namespace std;
const ll mod=1000000007;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
    init();
    ll H,N;cin>>H>>N;
    rep(i,N){
      ll a;cin>>a;
      H-=a;
    }
    if(H<=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

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

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
// inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

const int N = 2e5 + 10;

vi fac(N), vis(N), ans(N), sub(N), num(N);

vvi adj(N), chld(N);

int n;

void pre(){
	fac[0] = 1;
	for(int i = 1; i < N; i++)
		fac[i] = mul(fac[i - 1], i);
}

void dfs(int i){
	vis[i] = 1;
	num[i] = 1;
	int numer = 1, denom = 1;
	for(auto j : adj[i]){
		if(!vis[j]){
			dfs(j), num[i] += num[j];
			chld[i].pb(j);
			numer = mul(numer, sub[j]);
			denom = mul(denom, fac[num[j]]);
		}
	}
	sub[i] = mul(fac[num[i] - 1], mul(numer, inv(denom)));
}

void dfs1(int i, int parsub){
	int myans = parsub, denom = fac[n - num[i]];
	for(auto j : chld[i]){
		myans = mul(myans, sub[j]);
		denom = mul(denom, fac[num[j]]);
	}
	ans[i] = mul(fac[n - 1], mul(myans, inv(denom)));
	for(auto j : chld[i]){
		int newparsub = mul(myans, inv(sub[j]));
		newparsub = mul(newparsub, mul(fac[n - num[j] - 1], mul(fac[num[j]], inv(denom))));
		dfs1(j, newparsub);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	pre();
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		int a, b;
		cin >> a >> b;
		--a, --b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(0);
	dfs1(0, 1);
	for(int i = 0; i < n; i++)
		cout << ans[i] << endl;
}

Measured memory_bytes: 25856
#include <stdio.h>
#define SIZE 100
#define nil -1

typedef struct{
  int par,right,left;
} node;

int n;
node t[SIZE];

void Preorder(int);
void Inorder(int);
void Postorder(int);

int main(){
  int i,root;
  scanf("%d",&n);
  for(i=0; i<SIZE; i++)t[i].par = t[i].left = t[i].right = nil;
  
  for(i=0; i<n; i++){
    int id,l,r;
    scanf("%d %d %d",&id,&l,&r);
    t[id].left = l;
    t[id].right = r;
    if(l != nil)t[l].par = id;
    if(r != nil)t[r].par = id;
  }
  
  for(i=0; i<n;i++)
    if(t[i].par == nil) root = i;

  printf("Preorder\n");
  Preorder(root);
  printf("\n");

  printf("Inorder\n");
  Inorder(root);
  printf("\n");

  printf("Postorder\n");
  Postorder(root);
  printf("\n");

  return 0;
}

void Preorder(int u){
  printf(" %d",u);
  if (t[u].left != nil)Preorder(t[u].left);
  if(t[u].right != nil)Preorder(t[u].right);
}

void Inorder(int u){
  if (t[u].left != nil) Inorder(t[u].left);
  printf(" %d",u);
  if(t[u].right != nil) Inorder(t[u].right);
}

void Postorder(int u){
  if (t[u].left != nil) Postorder(t[u].left);
  if(t[u].right != nil) Postorder(t[u].right);
  printf(" %d",u);
}



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

using namespace std;

#define INF 1234567890
#define N (int)(2e5 + 5)
const double pi = 3.14159265358979323846;
typedef long long ll;

void solve()
{
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
#=============================================================================
# サイクル検出 AOJ2891の解答例
#=============================================================================
import queue

N=int(input())
Graph=[[] for _ in range(N)]
deg=[0 for _ in range(N)]
que=queue.Queue()
circle=[True for _ in range(N)]

for _ in range(N):
    a,b=map(int,input().split())
    a-=1
    b-=1
    Graph[a].append(b)
    Graph[b].append(a)
    deg[a]+=1
    deg[b]+=1

for v in range(N):
    if deg[v]==1:
        que.put(v)
        circle[v]=False

while not que.empty():
    v=que.get()
    for nv in Graph[v]:
        deg[nv]-=1
        if deg[nv]==1:
            que.put(nv)
            circle[nv]=False

Q=int(input())
for _ in range(Q):
    a,b=map(int,input().split())
    if circle[a-1] and circle[b-1]:
        print(2)
    else:
        print(1)



Measured memory_bytes: 25204
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int main()
{
	int h,w,a,b;
	scanf("%d%d%d%d",&h,&w,&a,&b);
	for(int i=0;i<b;i++)
	{
		for(int j=0;j<a;j++)
			putchar('0');
		for(int j=a;j<w;j++)
			putchar('1');
		putchar('\n');
	}
	for(int i=b;i<h;i++)
	{
		for(int j=0;j<a;j++)
			putchar('1');
		for(int j=a;j<w;j++)
			putchar('0');
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;
typedef pair<int, pair<int, int> > Team;
typedef pair<int, pair<int, pair<int, int> > > input;

int m, t, p, r;

int main()
{
    while (cin >> m >> t >> p >> r, m) {
        vector<Team > team(t);
        vector<vector<int> > check(t, vector<int>(p, 0));
        vector<input > data(r);
        rep(i, t) {
            team[i].second.second = i+1;
            team[i].first = 0;
            team[i].second.first = 0;
        }
        rep(i, r) {
            cin >> data[i].first >> data[i].second.second.second
                >> data[i].second.second.first 
                >> data[i].second.first;
            data[i].second.second.second--;
            data[i].second.second.first--;
            data[i].second.first *= -1;
        }
        sort(data.begin(), data.end());
        rep(i, r) {
            int a = data[i].first, b = data[i].second.second.second, 
                c = data[i].second.second.first, 
                d = data[i].second.first;
            if (d) {
                if (check[b][c] != -1) {
                    check[b][c]++;
                }
            } else {
                if (check[b][c] != -1) {
                    team[b].first++;
                    team[b].second.first 
                        -= data[i].first + check[b][c] * 20;
                    check[b][c] = -1;
                }
            }
        }
        sort(team.begin(), team.end(), greater<Team>());
        cout << team[0].second.second;
        for (int i = 1; i < t; i++) {
            if (team[i].first == team[i-1].first && 
                    team[i].second.first == team[i-1].second.first) {
                cout << "=" << team[i].second.second;
            } else {
                cout << "," << team[i].second.second;
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3140
n,m=map(int,input().split())

if n==1 and m==1:
  ans=1
if n==1 and m>1:
  ans=m-2
if n>1 and m==1:
  ans=n-2
if n>1 and m>1:
  ans=(m-2)*(n-2)
print(ans)

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

using namespace std;

int a, b, c, d;

int main() {
  cin >> a >> b >> c >> d;
  if (b < c || d < a) {
    cout << 0 << endl;
  } else {
    cout << min(b, d) - max(a, c) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 998244353LL
#define N 4096
ll p[N][N], q[N][N] = {};

int main(){
	int n, s; scanf("%d%d", &n, &s);
	q[0][0] = 1;
	REP(i, n){
		int a; scanf("%d", &a);
		REP(j, s+1){
			p[i+1][j] = (p[i+1][j] + p[i][j]) % MOD;
			q[i+1][j] = (q[i+1][j] + q[i][j] * 2) % MOD;
			if(j + a <= s){
				p[i+1][j+a] = (p[i+1][j+a] + p[i][j]) % MOD;
				q[i+1][j+a] = (q[i+1][j+a] + q[i][j]) % MOD;
			}
		}
	}
	printf("%lld\n", q[n][s]);
}


Measured memory_bytes: 147820
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    if(a>=6&&a<13){
      b = b/2;
    }else if(a<6){
      b = 0;
    }
    System.out.println(b);
  }
}

Measured memory_bytes: 20948
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define _USE_MATH_DEFINES
#define mp       make_pair
#define pb       push_back
#define fst      first
#define snd      second
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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


int main()
{
    int H, W; cin >> H >> W;
    string s[50];
    rep(y, H) cin >> s[y];
    
    int cnt_w = 0, cnt_b = 0;
    int n[50][50];
    rep(y,H) rep(x,W) {
        if(s[y][x] == '.')
            cnt_w++;
        n[y][x] = -1;
    }

    queue<pii> Q_yx;
    Q_yx.push(mp(0,0));
    s[0][0] = 'o';
    n[0][0] = 1;
    bool brk = false;
    while(!Q_yx.empty() && !brk) {
        pii yx = Q_yx.front(); Q_yx.pop();
        int y = yx.fst, x = yx.snd;
        rep(i,4) {
            int ny = y + dy[i], nx = x + dx[i];
            if(ny >= 0 && ny < H && nx >= 0 && nx < W && s[ny][nx] == '.') {
                n[ny][nx] = n[y][x] + 1;
                if(ny == H-1 && nx == W-1) {
                    brk = true;
                    break;
                }
                s[ny][nx] = 'o';
                Q_yx.push(mp(ny, nx));
            }
        }
    }

    if(n[H-1][W-1] > 0)
        cout << cnt_w - n[H-1][W-1] << endl;
    else
        cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
c_list = [] 
a_list = []
for i in range(0, n):
  c, *a = map(int, input().split())
  c_list.append(c)
  a_list.append(a)
ans = float("inf")

for x1 in [0, 1]:
  for x2 in [0, 1]:
    for x3 in [0, 1]:
      for x4 in [0, 1]:
        for x5 in [0, 1]:
          for x6 in [0, 1]:
            for x7 in [0, 1]:
              for x8 in [0, 1]:
                for x9 in [0, 1]:
                  for x10 in [0, 1]:
                    for x11 in [0, 1]:
                      for x12 in [0, 1]:
                        if n == 1:
                          x_list = [x1]
                        elif n == 2:
                          x_list = [x1, x2]
                        elif n == 3:
                          x_list = [x1, x2, x3]
                        elif n == 4:
                          x_list = [x1, x2, x3, x4]
                        elif n == 5:
                          x_list = [x1, x2, x3, x4 ,x5]
                        elif n == 6:
                          x_list = [x1, x2, x3, x4 ,x5, x6]
                        elif n == 7:
                          x_list = [x1, x2, x3, x4 ,x5, x6, x7]
                        elif n == 8:
                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8]
                        elif n == 9:
                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8, x9]
                        elif n == 10:
                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8, x9, x10]
                        elif n == 11:
                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8, x9, x10, x11]
                        elif n == 12:
                          x_list = [x1, x2, x3, x4 ,x5, x6, x7, x8, x9, x10, x11, x12]
                        cost = 0
                        gaku_list = [0] * m
                        for i in range(0, n):
                          if x_list[i] == 1:
                            for j in range(0, m):
                              gaku_list[j] += a_list[i][j]
                            cost += c_list[i]
                        flag = 1
                        for gaku in gaku_list:
                          if gaku < x:
                            flag = 0
                            break
                        if flag == 1 and cost < ans:
                          ans = cost
if ans == float("inf"):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9264
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 10000

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool check[NUM];

int group_index;
int table[NUM],out_num[NUM],in_num[NUM];

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id); //group[group_index]にノードを突っ込む
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}


int main(){

	int N,M;

	scanf("%d %d",&N,&M);

	int from,to;

	for(int i = 0; i < M; i++){
		scanf("%d %d",&from,&to);

		G[from].push_back(to);
		reverse_G[to].push_back(from);
	}

	for(int i = 0; i < N; i++)check[i] = false;

	//まずは帰りがけ順を計算
	for(int i = 0; i < N;i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < N;i++)check[i] = false;

	group_index = -1;
	//ノードを、帰りがけ順の逆順に、各強連結成分(グループ)に分解
	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	int next_group;

	//SCC分解した状態で、DAGにおける入出次数を計算する
	for(int i = 0; i <= group_index; i++){
		in_num[i] = 0;
		out_num[i] = 0;
	}

	for(int i = 0; i <= group_index; i++){
		for(int k = 0; k < group[i].nodes.size(); k++){
			for(int p = 0; p < G[group[i].nodes[k]].size(); p++){
				next_group = table[G[group[i].nodes[k]][p]];
				if(next_group != i){
					out_num[i]++;
					in_num[next_group]++;
				}
			}
		}
	}

	int in_0 = 0,out_0 = 0;

	for(int i = 0; i <= group_index; i++){
		if(in_num[i] == 0)in_0++;
		if(out_num[i] == 0)out_0++;
	}

	if(group_index == 0 && in_0 == 1 && out_0 == 1){
		printf("0\n");
	}else{
		printf("%d\n",max(in_0,out_0));
	}

	return 0;
}



Measured memory_bytes: 5708
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      String s = scn.next();
      int cr = 0;
      int cb = 0;
      for(int i=0; i<n; ++i){
        if(s.charAt(i)=='R'){
          cr = cr + 1;
        }
        if(s.charAt(i)=='B'){
          cb = cb + 1;
        }
      }
      if(cr>cb){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
	}
}


Measured memory_bytes: 35840
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b ] <- readInts
	print $ a - 1 + ( which 1 0 ( a <= b ) )

Measured memory_bytes: 508
#!/usr/bin/env python3

'''
Author: andyli
Time: 2020-08-29 19:58:34
'''

import os
from io import BytesIO, IOBase
import sys

MOD =  10**9+7

def inv(x): return pow(x,MOD-2,MOD)
def main():
    n = int(input())
    a = list(map(int,input().split()))
    S = [1]
    for i in range(1,n):
        S.append(S[i-1]+a[i])
    ans=0
    for i in range(n):
        ans += a[i]*(S[n-1]-S[i])%MOD
        ans %= MOD
    print(ans)
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda: self.buffer.read().decode('ascii')
        self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()


Measured memory_bytes: 100424