akhauriyash/Code-Regression huggingface dataset:
class Combination:
    def __init__(self, mod):
        self.mod = mod
        self.fact = [1] * (2 * 10 ** 5 + 1)
        for i in range(1, 2 * 10 ** 5 + 1):
            self.fact[i] = i * self.fact[i - 1] % self.mod

    def nCr(self, n, k):
        a = self.fact[n] % self.mod
        b = (self.fact[k] * self.fact[n - k]) % self.mod
        c = pow(b, self.mod - 2, self.mod)
        return a * c % self.mod


def main():
    H, W, A, B = map(int, input().split())
    MOD = 10 ** 9 + 7
    c = Combination(mod=MOD)

    ans = 0
    for i in range(W - B):
        h, w = H - A - 1, B + i
        a = c.nCr(h + w, h) % MOD

        h, w = A - 1, W - B - i - 1
        b = c.nCr(h + w, h) % MOD

        ans = (ans + a * b) % MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()



Measured memory_bytes: 10868
#include<iostream>
using namespace std;
long long GCD(long long a,long long b);
long long LCM(long long a,long long b);
int main(){
    int n;
    cin>>n;
    int a;
    long long ans=1;
    for(int i=0;i<n;i++){
        cin>>a;
        ans=LCM(ans,a);
    }
    cout<<ans<<"\n";
    return(0);
}
long long GCD(long long a,long long b){
    while(b!=0){
        long long r=a%b;
        a=b;
        b=r;
    }
    return(a);
}
long long LCM(long long a,long long b){
    return(a/GCD(a,b)*b);
}


Measured memory_bytes: 3088
n = int(input())
lst = list(map(int, input().rstrip().split()))
# start with positive number
cur, cnt_1 = 0, 0
for i, j in enumerate(lst):
    new = cur + j
    if i % 2 == 0 and new <= 0:
        cnt_1 += abs(new) + 1
        cur = 1
    elif i % 2 == 1 and new >= 0:
        cnt_1 += abs(new) + 1
        cur = -1
    else:
        cur = new

# start with negative number
cur, cnt_2 = 0, 0
for i, j in enumerate(lst):
    new = cur + j
    if i % 2 == 0 and new >= 0:
        cnt_2 += abs(new) + 1
        cur = -1
    elif i % 2 == 1 and new <= 0:
        cnt_2 += abs(new) + 1
        cur = 1
    else:
        cur = new
print(min(cnt_1, cnt_2))

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

int main(){
	vector<string> t={"maerd"s,"remaerd"s,"esare"s,"resare"s};
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();){
		string f;
		bool yes=false;
		for(int j=0;j<t.size();++j){
			f=s.substr(i,t.at(j).size());
			if(f==t.at(j)){
				yes=true;
				i+=t.at(j).size();
				break;
			}
		}
		if(!yes){
			cout<<"NO\n"s;
			return 0;
		}
	}
	cout<<"YES\n"s;
}

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

int main() {
  int n,m;
  cin >> n >> m ;
  vector<int>h(n);
  vector<bool>ok(n,true);
  rep(i,n){
    cin >> h.at(i);
  }
  rep(i,m){
    int a,b ;
    cin >> a >> b;
    a--; b--;
    if(h.at(a)<=h.at(b)) ok[a]=false;
    if(h.at(b)<=h.at(a)) ok[b]=false;
  }
  int ans=0;
  rep(i,n){
    if(ok[i]==true){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 3792
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 1005;

char c[N][N];
int dp[N][N];

signed main(){
    IOS;
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        if (c[i][0] == '.') dp[i][0] = 1;
        else break;
    }
    for (int i = 0; i < w; i++) {
        if (c[0][i] == '.') dp[0][i] = 1;
        else break;
    }
    for (int i = 1; i < h; i++) {
        for (int j = 1; j < w; j++) {
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            if (c[i][j] == '#') dp[i][j] = 0;
        }
    }
    cout << dp[h-1][w-1] % MOD << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int INF = INT_MAX / 2;

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

	while ( true )
	{
		int n, k;
		cin >> n >> k;

		if ( !( n | k ) )
		{
			break;
		}

		VVI G( n, VI( n, INF ) );
		REP( i, 0, n )
		{
			G[i][i] = 0;
		}

		REP( i, 0, k )
		{
			int q, a, b, e;
			cin >> q;
			switch ( q )
			{
				case 0:
					cin >> a >> b;
					a--;
					b--;
					cout << ( G[a][b] == INF ? -1 : G[a][b] ) << endl;
					break;
				case 1:
					cin >> a >> b >> e;
					a--;
					b--;
					G[a][b] = min( G[a][b], e );
					G[b][a] = min( G[b][a], e );

					REP( i, 0, n )
					{
						G[i][a] = min( G[i][a], G[i][b] + G[b][a] );
						G[i][b] = min( G[i][b], G[i][a] + G[a][b] );
					}

					REP( i, 0, n )
					{
						REP( j, 0, n )
						{
							G[i][j] = min( G[i][j], min( G[i][a] + G[a][j], G[i][b] + G[b][j] ) );
						}
					}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N,K;
  cin >> N >> K;

  vector<long long> H(N);
  for(int i = 0;i < N;i++) cin >> H.at(i);
  sort(H.rbegin(),H.rend());
  long long ans = 0;
  for(int i = K;i < N;i++) {
    ans += H.at(i);
  }

  cout << ans << endl;


  
}

Measured memory_bytes: 1792
//krk
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

string s;
int k;
vector<string> v;
int main()
{
cin>>s>>k;

for(int i=0;i<s.size();i++)
    {
     string cur;
     for(int j=i;j<s.size() and j<i+k;j++)
          {
           cur+=s[j];
           v.push_back(cur);
          }
    }
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
cout<<v[k-1];

system("pause");
return 0;
}

Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b;
	cin >> a >> b;
	int k = max({a + b, 2 * a - 1, 2 * b - 1});
	cout << k << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<functional>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

int main(){
    int N;
    double x[11];
    string s[11];
    cin>>N;
    double ans=0;
    for(int i=0;i<N;i++){
        cin>>x[i]>>s[i];
    
        if(s[i]=="JPY"){
            ans+=x[i];
        }else{
            ans+=x[i]*380000;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int j = 1;
    int count = 0;
    rep(i,N) {
        if (A[i] != j) count++;
        else j++;
    }
    if (count == N) cout << -1 << endl;
    else cout << count << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;
void swap(ll &a,ll &b){
    ll temp=a;
    a=b;
    b=temp;
}
ll gcd(ll a,ll b){
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
}

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




int main(){
    ll A,B;
    cin>>A>>B;
    out(lcm(A,B));

    return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int n1 = int.Parse(str[0]);
        int n2 = int.Parse(str[2]);

        if(str[1] == "+"){
            Console.WriteLine(n1 + n2);
        }else{
            Console.WriteLine(n1 - n2);
        }
    }
}

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

int main()
{
    int N;
    int A;
    int B;
    cin>>N>>A>>B;
    int diff=B-A;
    if (diff%2==1){
        cout<<"Borys"<<endl;
    }
 
    else
    {
        cout<<"Alice"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


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

    rep(i, s.size()){
        cout << "x";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int>Ts(N);
	for (int i = 0; i < N; i++)
	{
		cin >> Ts[i];
	}
	int M;
	cin >> M;
	vector<vector<int>>drink(M, vector<int>(2));
	for (int i = 0; i < M; i++)
	{
		//int P, X;
		cin >> drink[i][0] >> drink[i][1];
	}
	int defa = 0;
	for (int i = 0; i < N; i++)
	{
		defa += Ts[i];
	}
	vector<int>ans(M, defa);
	for (int i = 0; i < M; i++)
	{
		ans[i] = defa - Ts[drink[i][0]-1] + drink[i][1];
		cout << ans[i] << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;

typedef long long ll;
#define PII pair<ll,ll>
const int maxn=1e5+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-10;
using namespace std;
int main()
{
	int n,m,i,j,dp[109][109];
	
	scanf("%d%d",&n,&m);
	for(i=0;i<=n;i++)for(j=0;j<=m;j++)dp[i][j]=1e9;
	char s[109][109];
	for(i=1;i<=n;i++)scanf("%s",s[i]+1);
	if(s[1][1]=='#')dp[1][1]=1;
	else dp[1][1]=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(i==1&&j==1)continue;
			if(s[i][j]=='#'&&s[i][j-1]=='.')dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
			else dp[i][j]=min(dp[i][j],dp[i][j-1]);
			if(s[i][j]=='#'&&s[i-1][j]=='.')dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
			else dp[i][j]=min(dp[i][j],dp[i-1][j]);
		}
	}
	printf("%d\n",dp[n][m]);
}

Measured memory_bytes: 256
S1=input()
S2={}
for i in range(4):
    if S1[i] in S2:
        S2[S1[i]]+=1
    else:
        S2[S1[i]]=1
if len(S2)==2 and S2[S1[0]]==2:
    print("Yes")
else:
    print("No")


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

using namespace std;

const int MOD = (int)1e9+7;

int main(){
  int D,G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  for(int i=0;i<D;i++)  cin >> p.at(i) >> c.at(i);

  int ans=1e9;
  for(int bit=0;bit<(1<<D);bit++){
    int count=0;
    int x=0;
    int maxrest;
    for(int i=0;i<D;i++){
      if(bit&(1<<i)){
        x+=p.at(i)*100*(i+1);
        x+=c.at(i);
        count+=p.at(i);
      }
      else  maxrest=i;
    }
    for(int i=0;i<p.at(maxrest);i++){
      if(x>=G){
        ans=min(ans,count);
        break;
      }
      x+=100*(maxrest+1);
      count++;
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[m];
        int[] b = new int[m];

        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        int r = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < m; j++) {
                if (a[j] == i || b[j] == i) {
                    r++;
                }
            }
            System.out.println(r);
            r = 0;
        }
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;
 
int main()
{
  int a, b, c;
  cin >> a >> b;
  if(a == b) cout << "Draw" << endl;
  else if(a == 1 || b != 1 && a > b) cout << "Alice" << endl;
  else cout << "Bob" << endl;
  return 0;
}


Measured memory_bytes: 3472
n = int(input())
a = list(map(int, input().split()))

b = []
c = []
for i in range(len(a)):
    if i % 2 == 1:
        b.append(a[i])
    else:
        c.append(a[i])

b.reverse()
b += c

if len(a) % 2 == 1:
    b.reverse()

for bb in b:
    print(bb , end = ' ')
print()


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, Q;
vector<int> v[202020];
int d[202020];
i64 ans[202020];
void solve(){
	cin >> n >> Q;
	for(int i = 0; i < n-1; i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int t = 0; t < Q; t++){
		int a,b;
		cin >> a >> b;
		d[a-1] += b;
	}
	
	queue<P> q;
	q.push({0,d[0]});
	fill(ans, ans+n, -1);
	ans[0] = d[0];
	while(!q.empty()){
		P p = q.front(); q.pop();
		i64 pos = p.first, c = p.second;
		for(int i = 0; i < v[pos].size(); i++){
			int I = v[pos][i];
			if(ans[I] != -1) continue;
			ans[I] = c+d[I];
			q.push({I, ans[I]});
		}
	}
	
	for(int i = 0; i < n; i++){
		cout << ans[i] << " ";
	}
	cout << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = (base + base) % mod;
    }
    return tot;
}

int n, q, a;
string s;

long long solve(int k){

    long long d = 0, m = 0, dm = 0, tot = 0;

    for(int i = 0; i < n; ++i){
        if(s[i] == 'D') ++d;
        if(s[i] == 'M'){ ++m; dm += d; }
        if(s[i] == 'C') tot += dm;
        if(i >= k - 1){
            if(s[i - k + 1] == 'D'){--d; dm -= m;}
            if(s[i - k + 1] == 'M') --m;
        }
    }

    return tot;

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> s >> q;

    for(int i = 0; i < q; ++i){
        cin >> a;
        cout << solve(a) << "\n";
    }

    return 0;

}


Measured memory_bytes: 1948
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.rbegin(), a.rend());
  long long ans = 0;
  for (int i = k; i < n; i++) ans += a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    int a[1000],n;
    while(1){
        cin>>n;
        if(n==0)break;
        double m=0,b=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            m+=a[i];
        }
        m/=n;
        for(int i=0;i<n;i++){
            b+=pow((a[i]-m),2);
        }
        printf("%lf\n",sqrt(b/n));
    }
    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define l_ength size
using ll = long long;
const int mod = 1000000007;
const ll infll = (1ll<<60);
using namespace std;

bool dp[100010];

int main(){
	int sz, n; cin >> sz >> n;
	vector<int> a(sz);
	for( auto &k : a ) cin >> k;
	for( int i = n; 0 <= i; --i ){
		bool mark = false;
		for( auto k : a ){
			if( i+k <= n ) mark |= (!dp[i+k]);
		}
		dp[i] = mark;
	}
	cout << ( dp[0] ? "First" : "Second" ) << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define newline putchar('\n')
#define leave_space putchar(' ')
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
const int MAXN = 32;
int n, m, k;
char maze[MAXN][MAXN];
int use[MAXN][MAXN], cpy[MAXN][MAXN];
inline void falldown(int x, int y) {
	while (x && use[x - 1][y]) {
		swap(use[x][y], use[x - 1][y]); --x;
	}
}
inline lint dfs() {
	lint ret = 0;
	rep (i, 1, n) {
		int las = 0;
		vector<int> FD;
		rep (j, 1, m) {
			if (!use[i][j]) las = 0;
			else if (use[i][j] == use[i][j - 1]) ++las;
			else las = 1;
			if (las >= k) {
				ret += use[i][j];
				if (las == k) {
					ret += use[i][j] * (k - 1);
					rep (K, j - k + 1, j) {
						FD.pb(K);
					}
				} else {
					FD.pb(j);
				}
			}
		}
		for (auto p : FD) {
			use[i][p] = 0;
			falldown(i, p);
		}
	}
	if (ret) ret += dfs() * 2;
	return ret;
}
int main() {
	cin >> n >> m >> k;
	rep (i, 1, n) {
		cin >> (maze[i] + 1);
		rep (j, 1, m) {
			cpy[i][j] = maze[i][j] - '0';
		}
	}
	lint ans = 0;
	rep (i, 1, n) {
		rep (j, 1, m) {
			memcpy(use, cpy, sizeof(use));
			use[i][j] = 0;
			falldown(i, j);
			ans = max(ans, dfs());
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXK = -1;
const int MAXN = 1 << MAXK;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1.01e9;

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	int n, m;
	while (cin >> n >> m) {
		vector<pair<int, int> > ed(m);
		for (int i = 0; i < m; i++) {
			cin >> ed[i].first >> ed[i].second;
			ed[i].first--;
			ed[i].second--;
		}

		vector<int> deg(n);
		for (int i = 0; i < m; i++) {
			deg[ed[i].first]++;
			deg[ed[i].second]++;
		}
		bool ok = 1;
		for (int i = 0; i < n; i++) ok &= deg[i] % 2 == 0;
		cout << (ok ? "YES" : "NO") << endl;
	}

	return 0;
}

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

int n, a[4], mod = 1000000007, maxSt = 18;

inline bool pos ( int &mask ) {
    int cInd = 2, last = 0, sum = 0;
    for ( int i = 0 ; i < maxSt ; i ++ ) {
        if ( (1<<i)&mask ) {
            sum += i-last;
            last = i;
            if ( sum == a[cInd] ) {
                cInd --;
                if ( cInd < 0 ) { return 1; }
                sum = 0;
            }else if ( sum > a[cInd] ) { return 0; }
        }
    }
    return 0;
}
string toStr ( int mask ) {
    string ret = "";
    for ( int i = 0; i < maxSt ; i ++ ) {
        if ( (1<<i)&mask ) { ret += '1'; }
        else { ret += '0'; }
    }
    return ret;
}
int mem[42][(1<<18)][2];
inline int solve ( int ind, int mask, bool ok ) {

    ok |= pos ( mask );

    if ( ind == n && ok ) { return 1; }
    if ( ind == n ) { return 0; }
    if ( mem[ind][mask][ok] ) { return mem[ind][mask][ok] -1; }

    int ret = 0;
    for ( int i = 1 ; i <= 10 ; i ++ ) {
        ret += solve( ind+1, ( (mask<<i)|(1<<i) )&( ((1<<maxSt)-1) ), ok );
        if ( ret >= mod ) { ret -= mod; }
    }

    //cout << ind << " " << toStr ( mask ) << " " << ok << " : " << ret << "\n";
    mem[ind][mask][ok] = ret+1;
    return ret;
}
/*
in int 0 with mask A
in int 1 with mask B
in int 2 with mask C

pre * 1 2 2, 2 2 2 1, 2 1 2, * suff

pre: numberInt, sumH

pre and 1 2 2... doesnt contain Haiku

*/

/*
..... XXXXX YYYY ZZZZ ....
*/
int main () {
    cin >> n;
    cin >> a[0] >> a[1] >> a[2];

    cout << solve( 0, 0, 0 ) << "\n";

    return 0;
}


Measured memory_bytes: 82176
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;
    if (A * B % 2 == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 3010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
const long double pi=3.14159265358979323846264338328;
int a[maxn];
int n,l;
int main()
{
	n=read(); l=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	long double x=0,y=0;
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++){
			x+=cos(pi*(a[i]+a[j])/l)*(n-(j-i+1))+cos(pi*(a[i]+a[j])/l+pi)*(j-i-1);
			y+=sin(pi*(a[i]+a[j])/l)*(n-(j-i-1))+sin(pi*(a[i]+a[j])/l+pi)*(j-i+1);
		}
	x/=(ll)n*(n-1)*(n-2)/6;
	y/=(ll)n*(n-1)*(n-2)/6;
	printf("%.15Lf %.15Lf\n",x,y);
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int cnt = 1, f = 1;
    int n = s.length();
    for(int i = 1; i < n; i++){
        if(f && s[i - 1] == s[i]){
            f = 0;
            if(i == n - 1) break;
            cnt++, i++;
        }
        else{
            f = 1;
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll n, a[101], cnt, highest, lowest, hp, lp;
vii ans;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	highest = -INF;
	lowest = INF;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i]>highest){
			hp=i;
			highest=a[i];
		}
		if(a[i]<lowest){
			lp=i;
			lowest=a[i];
		}
	}
	if(lowest>0 || highest>=-lowest){
		for(int i = 0; i < n-1; i++){
			if(a[i]>a[i+1]){
				ans.pb(mp(hp,i+1));
				ans.pb(mp(hp,i+1));
				for(int j = i+1; j < n-1; j++){
					ans.pb(mp(j,j+1));
					ans.pb(mp(j+1,j+1));
				}
				cout << ans.size() << endl;
				for(int j = 0; j < ans.size(); j++){
					cout << ans[j].fi+1 << " " << ans[j].se+1 << endl;
				}
				return 0;
			}
		}
		cout << 0 << endl;
	}
	else{
		for(int i = n-1; i > 0; i--){
			if(a[i-1]>a[i]){
				ans.pb(mp(lp,i-1));
				ans.pb(mp(lp,i-1));
				for(int j = i-1; j > 0; j--){
					ans.pb(mp(j,j-1));
					ans.pb(mp(j-1,j-1));
				}
				cout << ans.size() << endl;
				for(int j = 0; j < ans.size(); j++){
					cout << ans[j].fi+1 << " " << ans[j].se+1 << endl;
				}
				return 0;
			}
		}
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(void)
{
	string word;
	int cnt = 0;

	cin >> word;

	for(int i = 0; i < word.size(); i++)
		word[i] = tolower(word[i]);

	for(string ch; cin >> ch, ch != "END_OF_TEXT"; ) {
		for(int i = 0; i < ch.size(); i++)
			ch[i] = tolower(ch[i]);
		if(ch == word || ch == word + '.')	cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1196
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N,M;
    cin >> N >> M;
    if(M>=N){
        cout << "Yes";
    }   
    else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <iostream>
int main(){
	long long n, mod = 1e9+7, ans = 1, x = 1, y = 1; 
	std::cin >> n;
	if(n==1) std::cout << "0\n";
	else if(n==2) std::cout << "2\n";
	else{
		for(int i = 0; i < n; i++) 
			ans = (ans*10)%mod, x = (x*9)%mod, y = (y*8)%mod;
		ans = (ans%mod - x%mod - x%mod + y%mod)%mod;
		if(ans<0) ans += mod;
		std::cout << ans << '\n';
	}
	return 0;
}



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

using namespace std;
using ll = long long;

int main()
{
    string S;
    string T;

    cin >> S;
    cin >> T;

    ll ans=0;

    for(int i=0;i<3;i++)
    {
        char s = S[i];
        char t = T[i];

        if(s==t)
        {
            ans++;
        }
    }

    cout << ans << endl;
    
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a * b % 2 == 0) cout << "Even" << endl;
  else cout << "Odd" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define A first
#define B second
#define lowbit(p) (p&(-p))
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
bool stttt;

#define mo 1000000007
#define M 100005
char str[M];
int cnt[30],n;
bool edddd;
int main(){
//	freopen("1.in","r",stdin);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	printf("%.2f\n",(&stttt-&edddd)/1024.0/1024.0);
	read(n);
	ll res=0,tmp;
	int i,j;
	scanf("%s",str+1);
	for (i=1;i<=n;i++){
		tmp=1;
		for (j=0;j<26;j++)if (j!=str[i]-'a'){
			tmp=tmp*(cnt[j]+1)%mo;
		}
		res=(res+tmp)%mo;
		cnt[str[i]-'a']++;
	}
	res=(res%mo+mo)%mo;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 384
import heapq

n = int(input())
happy = []
ans = 0
for i in range(n):
    a, b = tuple(map(int, input().split()))
    heapq.heappush(happy, - (a + b))
    ans += a
while len(happy) != 0:
    heapq.heappop(happy)
    if len(happy) != 0:
        h = heapq.heappop(happy)
        ans += h
    else:
        break
print(ans)


Measured memory_bytes: 7312
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    from collections import defaultdict
    D = defaultdict(list)
    for i in range(N-1):
        a,b,c = map(int,input().split())
        D[a].append([b,c])
        D[b].append([a,c])
        
    Q,K = map(int,input().split())
    fromK = [[0] for i in range(N+1)]
    
    visited = {}
    queue = [[K,0]]
    while queue != []:
        v,C = queue.pop()
        visited[v] = 1
        fromK[v] = C
        for i in D[v]:
            j,c = i
            if not j in visited:
                queue.append([j,C+c])
    for i in range(Q):
        x,y = map(int,input().split())
        print(fromK[x]+fromK[y])
    
    
main()

Measured memory_bytes: 118236
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
#define R(i,n) for(int i = 1; i<=n; i++)
typedef long long ll;
using namespace std;

int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t)cout << "Yes"<<endl;
  else cout << "No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		//static int[] parent;
		static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' '); //N,Q
			int N = Int32.Parse(input[0]);
			int Q = Int32.Parse(input[1]);
			List<HashSet<int>> edge = new List<HashSet<int>>();
			for(int i=0; i<N; i++)
			{
				HashSet<int> e = new HashSet<int>();
				edge.Add(e);
			}

	//	Console.WriteLine(" dev0 " + edge.Count);

			for(int i=1; i<N; i++)
			{
				input = Console.ReadLine().Split(' ');
				int a = Int32.Parse(input[0]);
				int b = Int32.Parse(input[1]);
		//	Console.WriteLine(a + "  " + b);
				edge[a-1].Add(b);
				edge[b-1].Add(a);
			}
//return;
			// 親ノード表を作る
			//parent = new int[N];
			writeParent(1, edge);

					// カウンター読み込み
			int[] count = new int[N];
			for(int i=0; i<Q; i++)
			{
				input = Console.ReadLine().Split(' ');
				int p = Int32.Parse(input[0]);
				int x = Int32.Parse(input[1]);
				count[p-1] += x;
			}
			// 頂点1から、一段ずつ繰り延べていく
			distributeCount(1,count, edge);
		//Console.WriteLine(" dev4 ");
			for(int i=0; i<N; i++)
			{
				Console.Write(count[i] + " ");
			}
			Console.WriteLine();
		}
		static void distributeCount(int i, int[] count, List<HashSet<int>> edge)
		{
				//Console.WriteLine(i + " dc " + edge[i-1].Count + " " + count[i-1]);
			foreach(var a in edge[i-1])
			{
				count[a-1] += count[i-1];
				distributeCount(a, count, edge);
			}
		}

		static void writeParent(int i, List<HashSet<int>> edge)
		{
			// 親iを、子供のますに書いていく
		//Console.WriteLine(i + " wp " + edge[i-1].Count);
			foreach(var a in edge[i-1])
			{
				//parent[a] = i;
				edge[a-1].Remove(i);
				writeParent(a, edge);
			}
		}
	}
}


Measured memory_bytes: 80200
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll X, N;
	cin >> X >> N;

	vector<ll> p(N);
	for (ll i = 0; i < N; ++i) cin >> p[i];
	
	ll ans = INF;
	for (ll d = 0; ; ++d)
	{
		ll x1 = X - d;
		if (find(p.begin(), p.end(), x1) == p.end())
		{
			ans = x1;
			break;
		}

		ll x2 = X + d;
		if (find(p.begin(), p.end(), x2) == p.end())
		{
			ans = x2;
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
char s[555][555];
int row[555],col[555],black;
int main(){
    DRI(N);
    REP(i,N)RS(s[i]);
    REP(i,N)REP(j,N){
        if(s[i][j]=='#'){
            black=1;
            row[i]++;
            col[j]++;
        }
    }
    if(!black)return 0*puts("-1");
    int full_col=0;
    REP(i,N){
        if(col[i]==N)full_col++;
    }
    int an=1e9;
    REP(i,N){
        if(row[i]==N){
            an=min(an,N-full_col);
            continue;
        }
        if(col[i])an=min(an,N-row[i]+N-full_col);
        else{
            an=min(an,1+N-row[i]+N-full_col);
        }
    }
    printf("%d\n",an);
    return 0;
}


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

int main() {
	int a[100], n;
	cin >> n;
	for(int i =0; i < n;  i++){
		cin >> a[i];
	}
	for (int i = n-1; i >= 0; i--){
		cout << a[i];
		if (i !=0){
			cout << " ";
		} else {
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>
int main(){
    int a,b;
    char op;
    scanf("%d %c %d",&a,&op,&b);

    if(op=='+'){
        printf("%d",a+b);
    }
    else if(op=='-'){
        printf("%d",a-b);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> T(5);
    for(int &e : T) cin >> e;
    int K;
    cin >> K;
    for(int e : T) for(int f : T) if(abs(e - f) > K) {
        cout << ":(" << endl;
        return 0;
    }
    cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int a, b, i, j, k;
	string s1, s2, ans;

	cin >> a >> b;
	s1 = "";
	for (i = 0; i < b; i++) {
		s1 = s1 + (char)('0' + a);
	}
	s2 = "";
	for (i = 0; i < a; i++) {
		s2 = s2 + (char)('0' + b);
	}
	ans = min(s1, s2);

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll sum = 0;
    rep(i, n) sum ^= a[i];
    rep(i, n) {
        ll ans = sum^a[i];
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  inline T query(int a,int b){
    T vl=d1,vr=d1;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[(l++)-1]);
      if(r&1) vr=f(dat[(--r)-1],vr);
    }
    return f(vl,vr);
  }
  
};
//END CUT HERE
signed main(){
    int n;
    cin >> n;
    SegmentTree<int,int> seg(n,
                [](int a,int b){return a | b;},
                [](int a,int b){return b;},
                0);
    string S;
    cin >> S;
    for (int i = 0; i < n; i++){
        seg.update(i, 1 << (S[i] - 'a'));
    }
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int a;
        cin >> a;
        if (a == 1){
            int j;
            char c;
            cin >> j >> c;
            j--;
            seg.update(j, 1 << (c - 'a'));
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            cout << __builtin_popcount(seg.query(l, r)) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4996
fn main() {
    let v = read_vec::<String>();
    let s = format!("{}{}", v[0], v[1]);
    let n: u32 = s.parse().ok().unwrap();

    for i in 1..317 {
        if i*i == n {
            println!("Yes");
            return
        }
    }

    println!("No");
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int c(const void*a,const void*b){
	return strcmp((char*)a,(char*)b);
}

char s[110][15];
int main(){
	ll n;
	scanf("%lld\n",&n);
	rep(i,0,n)scanf("%s",s[i]);
	rep(i,0,n-1){
		ll k=strlen(s[i]);
		if(s[i][k-1]!=s[i+1][0]){
			puts("No");
			return 0;
		}
	}
	qsort(s,n,15,c);
	rep(i,0,n-1){
		if(!strcmp(s[i],s[i+1])){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip> // for /* << std::fixed << std::setprecision(k) << */
using namespace std;

//defines

#define forn(n) for(int i = 0; i < n; i++)
#define pb push_back
#define int long long

int32_t main() {
	int h, ans = 1, base = 1;
	
	cin >> h;
	
	while (h > 1) {
		h = h/2;
		base *= 2;
		ans += base;
	}
	
	cout << ans;
}



Measured memory_bytes: 3596
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n;
    scanf("%d", &n);
    set<int> z;
    int i;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        if(!z.insert(tmp).second) {
            printf("NO\n"); return;
        }
    }
    printf("YES\n");

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 9600
import math
a,b,h,m=map(int,input().split())
ad=30*h+6*m/12
bd=6*m
ca=abs(ad-bd)
if 360-ca < ca:
    ca=360-ca
ans=a**2+b**2-(2*a*b)*math.cos(math.radians(ca))
print(math.sqrt(ans))

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

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> grid(h+5, vector<char>(w+5));
    rep(i, h) {
        rep(j, w) {
            cin >> grid[i][j];
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1<<h+w); ++bit) {
        vector<int> H(h);
        vector<int> W(w);
        for (int i = 0; i < h+w; ++i) {
            if (bit & (1<<i)) {
                if (i < h) {
                    H[i] = 1;
                } else {
                    W[i - h] = 1; 
                }
            }
        }
        int cnt = 0;
        rep(i, h) {
            rep(j, w) {
                if (H[i] || W[j]) continue;
                if (grid[i][j] == '#') cnt++;
            }
        }
        if (cnt == k) ans++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
    int  A, B, C;
    scanf("%d %d", &A, &B);
    if(A < B){
        C = B + (B-1);
    }else if(A > B){
        C = A + (A-1);
    }else{
        C = A + B;
    }
    printf("%d", C);
    return 0;
}

Measured memory_bytes: 128
n, y = map(int, input().split())

ans = [-1, -1, -1]
for i in range(n+1):
    for j in range(n-i+1):
        s = i*10000+j*5000+(n-i-j)*1000
        if s == y:
            ans = [i, j, n-i-j]
            break

print(*ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl
#define PII pair<int,int>
typedef long long ll;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=1e9;
const double ep=1e-7;
using namespace std;
int main()
{
	ll n;
	scanf("%lld",&n);
	if(n==2)
	{
		puts("1");return 0;
	}
	ll k=n,i,j,yz[maxn]={0},cnt1=0;
	for(i=2;i*i<=k;i++)
	{
		if(k%i==0)
		{
			yz[++cnt1]=i;
			if(i*i!=k)yz[++cnt1]=k/i;
		}
	}
	ll ans=1;
	map<ll,bool>mp;
	mp[n]=1;
	k-=1;
	for(i=2;i*i<=k;i++)
	{
		if(k%i==0)
		{
			mp[i]=1,ans++;
			if(i*i!=k)
			{
				mp[k/i]=1,ans++;
			}
		}
	}
	for(i=1;i<=cnt1;i++)
	{
		k=n;
		if(mp[yz[i]])continue;
		while(k%yz[i]==0)k/=yz[i];
		if(k%yz[i]==1)ans++;
	}
	if(mp[1])ans--;
	if(!mp[n-1])ans++;
	printf("%lld\n",ans);
}

Measured memory_bytes: 2176
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(int c=1;;c++) {
			int W = sc.nextInt();
			if(W == 0) break;
			
			int n = sc.nextInt();
			int[] w = new int[n], v = new int[n];
			for(int i=0;i<n;i++){
				String[] l = sc.next().split(",");
				v[i] = Integer.parseInt(l[0]); w[i] = Integer.parseInt(l[1]);
			}
			int[] dp = new int[W+1];
			for(int i=0;i<n;i++) for(int j=W;j>=w[i];j--) 
				dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
			
			int maxw = 0, maxv = 0;
			for(int i=0;i<=W;i++) if(maxv < dp[i]) {
				maxw = i; maxv = dp[i];
			}
			System.out.println("Case " + c + ":");
			System.out.println(maxv);
			System.out.println(maxw);
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 25064
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))


Measured memory_bytes: 73304