akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int lli;
typedef pair<int,int> pii;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vector){
	os << "[";
	for (const auto &v : vector) {
		os << v << ",";
	}
	os << "]";
	return os;
}

class SegmentTree{
	private:
	public:
	int size;
	vector<lli> data;
	void Init(int n){
		size=1;
		while(size<n) size*=2;
		data=vector<lli>(size*2-1,INF_);
	}
	void Update(int k,lli a){
		k+=size-1;
		data[k]=a;
		while(k>0){
			k=(k-1)/2;
			data[k]=min(data[k*2+1],data[k*2+2]);
		}
	}	
	lli Query(int a,int b,int k,int l,int r){
		if(r<=a||b<=l) return INF_;
		if(a<=l&&r<=b) return data[k];
		else {
			lli vl=Query(a,b,k*2+1,l,(l+r)/2);
			lli vr=Query(a,b,k*2+2,(l+r)/2,r);
			return min(vl,vr);
		}
	}
};

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	cin >> N;
	vector<int> x(N);
	REP(i,0,N) cin >> x[i];
	vector<lli> s(N);
	s[0]=x[0];
	REP(i,1,N) s[i]+=s[i-1]+x[i];
	vector<vector<lli>> dp(N,vector<lli>(2));
	dp[0][0]=x[0];
	SegmentTree st;
	st.Init(N);
	st.Update(x[0]-1,-s[0]);
	REP(i,1,N){
		dp[i][0]=min(dp[i-1][0],dp[i-1][1])+x[i];
		dp[i][1]=min(s[i-1],st.Query(0,x[i],0,0,st.size)+s[i-1]);
		st.Update(x[i]-1,dp[i][1]-s[i]);
	}
	cout << min(dp[N-1][1],dp[N-1][0]) << endl;
	return 0;
}

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

int main(void) {
	int a, b, c; cin >> a >> b >> c;
	int sum = 0;
	int x=max({ a,b,c });

	if ((x * 3-(a-b-c) )% 2 == 0) { cout << (x * 3 - (a + b + c)) / 2 << endl; }
	else { cout << ((x + 1) * 3 - (a + b + c)) / 2 << endl; }

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int k;
  string s;
  cin >> k;
  cin >> s;
  
  int len = (int)s.length();
  
  if (len <= k)
    cout << s << endl;
  else{
    cout << s.substr(0, k) + "..." << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3628
using System;

class Program {
  static void Main() {
    var t = "CODEFESTIVAL2016";
    var s = Console.ReadLine();
    int ans = 0;
    for (int i = 0; i < t.Length; i++) {
      if (t[i] != s[i]) ans++;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 11092
//minamoto
#include<iostream>
#include<cstdio>
using namespace std;
int n,r,b;char s[100005];
int main(){
	scanf("%d%s",&n,s+1);
	for(int i=1;s[i];++i)s[i]=='R'?++r:++b;
	puts(r>b?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
if n==1:
  print(1)
  exit()
d=defaultdict(lambda:0)
for i in range(n-1):
  for j in range(i+1,n):
    dx=xy[i][0]-xy[j][0]
    dy=xy[i][1]-xy[j][1]
    d[(dx,dy)]+=1
    d[(-dx,-dy)]+=1
print(n-max(d.values()))
#for k,v in d.items():
#  print(k,v)


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

int main(){
  int a,b,k;
  cin >> a >> b >>k;
  
  int cnt=0;
  for(int i=100;i>=1;i--){
    if(a%i==0 && b%i==0){
      cnt++;
      if(cnt==k) cout << i << endl;
    }  
  }

return 0;
}



Measured memory_bytes: 3628
dic = {}

N,K = [int(i) for i in input().split()]

dic = {}

for i in range(N):
    a,b = [int(i) for i in input().split()]
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b


ans = sorted(dic.items())

for i,j in ans:
    K -= j
    if K <= 0:
        print(i)
        break



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

int n, m;
string s;
vector<int> c;
vector<int> pos;
vector<int> pat;

int known;

bool check() {
    int p = 0;
    for (int i = 0; i < pat.size(); i++) {
        if (pos[i] % 2) {
            p += pat[i];
        } else {
            p += (pat[i] * 2 % 10 + pat[i] * 2 / 10);
        }
    }
    return (known + p) % 10 == 0;
}

int rec(int index) {
    if (index == pos.size()) 
        return (check() ? 1 : 0);
    int cnt = 0;
    for (int i = 0; i < m; i++) {
        pat[index] = c[i];
        cnt += rec(index+1);
    }
    return cnt;
}

int main() {
    cin >> n >> s >> m;
    c.resize(m); for (int i = 0; i < m; i++) cin >> c[i];
    known = 0;
    for (int i = 1; i <= n; i++) {
        if (s[n-i] == '*') {
            pos.push_back(i);
            continue;
        }
        if (i % 2) {
            known += s[n-i] - '0';
        } else {
            known += ((s[n-i] - '0') * 2 % 10 + (s[n-i] - '0') * 2 / 10);
        }
    }
    pat.resize(pos.size());
    cout << rec(0) << endl;
    return 0;
};

Measured memory_bytes: 1356
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
    def inpf() a=gets.chomp.split(" ").map(&:to_f)end
    def inps() a=gets.chomp.split(" ")end  
    def copy(a) Marshal.load(Marshal.dump(a)) end
    def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
    def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
    def na(n,d=0) Array.new(n,d)end
    def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
    def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
    def bit(n) n.to_s(2).split("").map(&:to_i) end
    def inp() a=gets.chomp.split(" ").map(&:to_i)end
    t = inp
    puts (t.count(7) == 1 and t.count(5) == 2)? "YES" : "NO"

Measured memory_bytes: 1788
// RAM RAM
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55
const int MOD=1000000007;
using namespace std;


int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	


    int n;cin>>n;
    if(n<1200){
    	cout<<"ABC"<<endl;
    }else{
    	cout<<"ARC"<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
n = int(input())
dp = [0]+ [float("INF")]*(n)

h = list(map(int, input().split()))
for i in range(n):
    dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[n-1])

Measured memory_bytes: 14436
using System;

namespace agc041a
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] read = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            long N = read[0];
            long A = read[1];
            long B = read[2];
            long roundNum = 0;
            if(Math.Abs(A-B) %2 ==0){
                roundNum = (B-A)/2;
            }else{
                roundNum = Math.Min(A-1,N-B)+1+(B-A-1)/2;
            }
            Console.WriteLine(roundNum);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
 
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define all(x) x.begin(),x.end()
#define trav(i,x) for(auto& i:x)
#define endl cout<<"\n";
const int mod = 1e9+7;
 
int main()
{
 
    FAST_IO;
    ll n;
    cin>>n;
    array<int,2> a[n+1];
    ll fl=0,ans=0,i;
    for(i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1];
		if(a[i][0]==a[i][1]){
			ans++;
		}
		else
			ans=0;
		if(ans==3)
			fl=1;
	}
	if(fl==1)	cout<<"Yes";
	else
	{
		cout<<"No";
	}
	return 0;
}


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

  if(a < b){
   if(b < c){
    printf("Yes\n"); 
 } else {
   printf("No\n");
 }
} else {
  printf("No\n");
 }
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<cmath>

#define LL	long long
using namespace std;
const int MAXN = 2010;
const int MAXA = 1e9;

pair<int, int> A[MAXN];
LL f[MAXN][MAXN];
int N;
LL ans;

int main() {
	cin >> N;
	memset(f, 0, sizeof(f));
	for(int i=1; i<=N; i++) {
		cin >> A[i].first;
		A[i].second = i;
	}
	
	sort(A+1, A+N+1);
	//sort(A+1, A+N+1, greater<int>());
	
	/*
	for(int i=1; i<=N; i++) {
		printf("%d, %d\n", A[i].first, A[i].second);
	}
	*/
	for(int len = N; len>=1; len--) {
		for(int i=1; i+len-1<=N; i++) {
			int j = i+len-1;
			if(len == 1) {
				ans = max(ans, f[i][i] + 1LL*A[len].first*abs(A[len].second-i));
			}
			f[i+1][j] = max(f[i+1][j], f[i][j] + 1LL*A[len].first*abs(A[len].second-i));
			f[i][j-1] = max(f[i][j-1], f[i][j] + 1LL*A[len].first*abs(A[len].second-j));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 35184
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x=1,g=0,n,h,w,k,m,l,ans=1,ptr=0;
    string s,s1,s2;
    cin >> h >> w >> n;
    VI a(n);
    VI b(n);
    VVI c(h, vector<int>(w));
    rep(i,n){
        cin >> a[i];
	}

    int count = 0;
    while(count < h){
        for(int i=0; i<h;i++){
            for(int j=0; j<w;j++){
                c[i][j] = x;
                b[x-1]++;
                if(b[x-1]==a[x-1]){
                    x++;
                }
            }
            i++;      
            count++;
            if(i>=h){
                break;
            }            
            for(int j=w-1; j>=0; j--){
                c[i][j] = x;
                b[x-1]++;
                if(b[x-1]==a[x-1]){
                    x++;
                }
            }
            count++;
        }   
    }

    for(int i=0; i<h;i++){
        for(int j=0;j<w;j++){
            cout << c[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import bisect
from collections import deque
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
# mod = 10 ** 9 + 7
mod = 998244353

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]



def main():
    S = input().strip()
    if S[-1] == "s":
        S += "es"
    else:
        S += "s"
    print(S)


if __name__ == "__main__":
    main()



Measured memory_bytes: 68676
#include <iostream>

using namespace std;

int selectionSort(int buf[], int n)
{
	int index, i, j, sw = 0;
	for(i = 0; i < n; i++) {
		index = i;
		for(j = i + 1; j < n; j++) {
			if(buf[j] < buf[index]) {
				index = j;
			}
		}
		swap(buf[i],buf[index]);
		if(i != index)
			sw++;
	}
	return sw;
}

int main()
{
	int buf[100], n, sw;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> buf[i];
	sw = selectionSort(buf, n);

	for(int i = 0; i < n; i++) {
		if(i > 0) cout << " ";
		cout << buf[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}



Measured memory_bytes: 3136
#pragma gcc optimize("Ofast")
#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 (int i = 0; i < (n); ++i)
#define SORT(V) sort((V).begin(),(V).end())
#define pb push_back
#define endl '\n'
#define int long long

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// 変数定義
int n,ans=0;
//

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> b(n,MOD);
  REP(i, n-1) {
    cin >> b[i];
  }
  REP(i, n-2) {
    ans += min(b[i], b[i+1]);
  }
  cout << ans + b[0] + b[n-2] << endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e3 + 5);
const int MAX_H = (int)(1e4 + 5);

int h, n;

int a[MAX_N], b[MAX_N];

ll dp[MAX_N][MAX_H];

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &n);

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

  for (int j = 0; j <= h; ++j) {
    for (int i = 0; i <= n; ++i) {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0LL;

  for (int j = 0; j <= h; ++j) {
    for (int i = 0; i < n; ++i) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);

      int target_index = j + a[i];
      target_index = target_index >= h ? h : target_index;

      dp[i + 1][target_index] =
          min(dp[i + 1][target_index], dp[i + 1][j] + b[i]);
    }
  }

  ll ans = dp[n][h];

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 78464
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};


typedef struct _state{
  int from,vis;
  double cost;
  bool operator<(const _state&r)const{
    return cost>r.cost;
  };
}state;

vector<PI> V[30];

main(){
ios::sync_with_stdio(false);
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    --a,--b;
    int ti[n];
    rep(i,n)cin>>ti[i];

    rep(i,m)V[i].clear();

    rep(i,p){
      int x,y,z;
      cin>>x>>y>>z;
      --x,--y;
      V[x].pb(mp(y,z));
      V[y].pb(mp(x,z));
    }

    priority_queue<state> Q;
    state st;
    st.cost=0;
    st.vis=0;
    st.from=a;
    Q.push(st);

    double cost[1<<n][m];
    rep(i,1<<n)rep(j,m)cost[i][j]=1<<26;
    double ans=-1;

    while(!Q.empty()){
      int from=Q.top().from,cti=Q.top().vis;
      double ccost=Q.top().cost;
      Q.pop();
      if(cost[cti][from]<=ccost)continue;
      cost[cti][from]=ccost;
      if(from==b){
	ans=ccost;
	break;
      }

      rep(i,n){
	if(cti>>i&1)continue;
	rep(j,V[from].size()){
	  int to=V[from][j].first;
	  int cc=V[from][j].second;
	  double ncost=ccost+1.0*cc/ti[i];
	  st.from=to;
	  st.vis=cti|1<<i;
	  st.cost=ncost;
	  Q.push(st);
	}
      }
    }
    if(ans<0)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
}

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

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

    vector<set<int64_t>> left(N);
    vector<set<int64_t>> right(N);

    set<int64_t> st;
    for (int64_t i = 0; i < N; i++) {
        left[i] = st;
        st.insert(S[i]);
    }

    st.clear();
    for (int64_t i = N - 1; i >= 0; i--) {
        right[i] = st;
        st.insert(S[i]);
    }

    set<string> ans;
    for (int64_t i = 1; i < N - 1; i++) {
        for (int64_t l : left[i]) {
            for (int64_t r : right[i]) {
                ans.insert(to_string(l) + S[i] + to_string(r));
            }
        }
    }
    cout << ans.size() << endl;
}

Measured memory_bytes: 31360
n = int(input())
s = input()
l = [0] * n
r = [0] * n
ans = n
for i in range(n):
    if i == 0:
        if s[0] == "W":
            l[0] = 1
    elif s[i] == "W":
        l[i] = l[i - 1] + 1
    else:
        l[i] = l[i - 1]
    if i == 0:
        if s[-1] == "E":
            r[0] = 1
    elif s[-i-1] == "E":
        r[i] = r[i - 1] + 1
    else:
        r[i] = r[i - 1]
for i in range(n):
    if i == 0:
        ans = min(ans, r[n - 1 - i])
    elif i == n - 1:
        ans = min(ans, l[i - 1])
    else:
        ans = min(ans, l[i - 1] + r[n - 1 - i])
print(ans)

Measured memory_bytes: 23512
#include <stdio.h>
int main(void){
    int x, n, i, j, k, b, f, r, v;
    int count[4][3][10];
    scanf("%d", &n);
    
    x=0;
    i=0;
    j=0;
    k=0;
    
    while(i<4){
        while(j<3){
            while(k<10){
                count[i][j][k]=0;
                k++;
            }
            k=0;
            j++;
        }
        j=0;
        i++;
    }
    
    while(x<n){
        scanf("%d %d %d %d", &b, &f, &r, &v);
        count[b-1][f-1][r-1]=count[b-1][f-1][r-1] + v;
        x++;
    }
    
    i=0;
    j=0;
    k=0;
    while(i<4){
        while(j<3){
            while(k<10){
                printf(" %d", count[i][j][k]);
                k++;
            }
            printf("\n");
            k=0;
            j++;
        }
        if(i<3){
            printf("####################\n");
        }
        j=0;
        i++;
    }
    return 0;
}



Measured memory_bytes: 2100
#ABC071C
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
before=0
c=0
x=-1
for a in A:
	if before==a:
		c+=1
		if c==2:
			if x==-1:
				x=a
			else:
				print(x*a)
				break
		if c==4:
			print(a**2)
			break
	else:
		before=a
		c=1
else:
	print(0)

Measured memory_bytes: 15020
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, res, m[3] = {3, 5, 7};

void rec(int x, bool a, bool b, bool c) {
	if (x>n) return;
	if (a && b && c) res++;
	rep(i,3) rec(x*10+m[i], a|(i==0), b|(i==1), c|(i==2));
}

signed main() {
	cin >> n;
	rec(0,0,0,0);
	cout << res << endl;
}

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

int main()
{
	ll n,k;
	cin >> n >> k;
	if(k==0)
	{
		cout<<n*n<<endl;
		return 0;
	}
	ll ans = 0;
	for(ll i = 1;i<=n;i++)
	{
		if(i-k<=0)continue;
		ll  asd = n/i * (i-k);
		ans += asd;
		ll  qwe = max(n%i-k+1,0LL);
		ans += qwe;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    if (S <= W) {
      System.out.println("unsafe");
    } else {
      System.out.println("safe");
    }
  }
}


Measured memory_bytes: 35808
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int coin[4] = {10, 50, 100, 500};

int f(int n){
    int ret = 0;
    rrep(i, 4){
        ret += n / coin[i];
        n %= coin[i];
    }
    return ret;
}

int main(){
    int n, a, b, c, d;
    scanf("%d", &n);
    while(true){
        scanf("%d%d%d%d", &a, &b, &c, &d);
        int ans[4];
        int before = a+b+c+d;
        int after = MAX;
        rep(i, a+1)rep(j, b+1)rep(k, c+1)rep(l, d+1){
            int sum = 10*i + 50*j + 100*k + 500*l;
            if(sum < n) continue;
            if(chmin(after, before - (i+j+k+l) + f(sum-n))){
                ans[0] = i;
                ans[1] = j;
                ans[2] = k;
                ans[3] = l;
            }
        }
        rep(i, 4)if(ans[i]) printf("%d %d\n", coin[i], ans[i]);
        scanf("%d", &n);
        if(n) printf("\n");
        else break;
    }
}


Measured memory_bytes: 3132
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let towers: Vec<i32> = (1..1000).map(|i| (1..i + 1).sum()).collect();

    for tower in towers.windows(2) {
        if b - a == tower[1] - tower[0] {
            println!("{}", tower[0] - a);
            return;
        }
    }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
S = input()
a = []
b = 0

for i in range(len(S)):

    if S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C':

        b += 1

    else:

        a.append(b)
        b = 0

a.append(b)

print(max(a))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

  if (N % 2 == 0) cout << N << endl;
  else cout << N * 2 << endl;
}

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

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

int knapsack(vector<int> &w, vector<int> &v, int t){
	int n = w.size();
	int cur = 0;
	int nxt = 1;
	vector<vector<int>> dp(2, vector<int>(t+1,-1));
	dp[0][0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= t; j++){
			if(dp[cur][j] == -1) continue;
			dp[nxt][j] = max(dp[nxt][j], dp[cur][j]);
			if(j + w[i] <= t) dp[nxt][j + w[i]] = max(dp[nxt][j + w[i]], dp[cur][j] + v[i]);
		}

		swap(cur, nxt);
	}
	
	int ret = 0;
	for(auto x : dp[cur]) ret = max(ret, x);
	return ret;
}

void dfs_imp(vector<vector<char>> &m, map<string, int> &cnt, int i, int j, vector<vector<bool>> &visited, string &str){
	visited[i][j] = true;
	str.push_back(m[i][j]);
//	cerr << str << endl;
	if(cnt.find(str) != cnt.end()) cnt[str]++;
	if(str.size() >= 8){
		visited[i][j] = false;
		str.pop_back();
		return;
	}
	for(int k = 0; k < 8; k++){
		int nextx = i+dx[k], nexty = j+dy[k];
		if(nextx < 0 || 4 <= nextx || nexty < 0 || 4 <= nexty)continue;
		if(!visited[nextx][nexty]){
			dfs_imp(m, cnt, i+dx[k], j+dy[k], visited, str);

		}
	}
	visited[i][j] = false;
	str.pop_back();
}

void dfs(vector<vector<char>> &m, map<string, int> &cnt, int i, int j){
	vector<vector<bool>> visited(4, vector<bool>(4,false));
	visited[i][j] = true;
	string str;
	str.push_back(m[i][j]);
	if(cnt.find(str) != cnt.end()) cnt[str]++;
	for(int k = 0; k < 8; k++){
		int nextx = i+dx[k], nexty = j+dy[k];
		if(nextx < 0 || 4 <= nextx || nexty < 0 || 4 <= nexty)continue;
		dfs_imp(m, cnt, nextx, nexty, visited, str);
	}
	visited[i][j] = false;
}

signed main(){
	
	cin.tie(0);
    ios::sync_with_stdio(false);
	int n; cin >> n;
	map<string, int> words;
	for(int i = 0; i < n; i++){
		string w; cin >> w;
		int s; cin >> s;
		words[w] = s;
	}
	vector<vector<char>> m(4, vector<char>(4));
	for(auto &a : m)for(auto &e : a)cin >> e;
	int t; cin >> t;

	map<string, int> cnt;
	for(auto e : words)cnt[e.first] = 0;
	for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++){
		dfs(m, cnt, i, j);
	}
//	for(auto e : cnt)cerr << e.first << ":" << e.second << endl;

	vector<int> v,w;
	for(auto e : words){
		if(cnt[e.first] == 0)continue;
        int sum = 0;
		for(int i = 1;; i *= 2){
			if(sum + i < cnt[e.first]){
                w.push_back(i * e.first.size());
			    v.push_back(i * e.second);
            }else{
                i = cnt[e.first] - sum;
                w.push_back(i * e.first.size());
                v.push_back(i * e.second);
                break;
            }
		    sum += i;
        }
	}
	cout << knapsack(w,v, t) << endl;

	return 0;
}








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


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

    if(n == 1 || n % 2){
        cout << "No" << endl;
        return 0;
    }
    
    for(int i = 0; i < n / 2; i++){
        if(s[i] != s[n/2 + i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
using namespace std;

int main(){
    int K;
    cin >> K;
    vector<bool> vis(K, false);
    deque<pair<int, int>> dq;
    dq.push_back(make_pair(1, 1));
    while(!dq.empty()){
        auto p = dq.front();
        dq.pop_front();
        int x = p.first;
        int d = p.second;
        if(vis[x]) continue;
        vis[x] = true;
        if(x == 0){
            cout << d << endl;
            return 0;
        }
        dq.push_back(make_pair((x+1)%K, d+1));
        dq.push_front(make_pair((10*x)%K, d));
    }
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace AtCorder
{
    public static class Program
    {   
        static public void Main(string[] args)
        {
            int[] score = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            string output = "";
            if (score[0] == score[1])
            {
                output = "Yes";
            }
            else
            {
                output = "No";

            }
            Console.WriteLine(output);
        } 
    }
}




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

const int N=200010;
int a[N],b[N],n;

int main(){
	scanf("%d",&n);
	int x;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	reverse(b+1,b+1+n);
	int l=0,r=-1,t=0,L=0,R=0;
	for(int i=1;i<=n;i++) if(a[i]==b[i]) {
		if(!l) l=i,r=i,t=a[i];
		else r++;
	}
	for(int i=1;i<=n;i++) if(a[i]!=b[i]){
		while(l<=r && b[i]!=a[l] && b[l]!=a[i]) swap(b[i],b[l]),l++;
	}
	else break;
	for(int i=n;i>=1;i--) if(a[i]!=b[i]){
		while(l<=r && b[i]!=a[r] && b[r]!=a[i]) swap(b[i],b[r]),r--;
	}
	else break;
	if(l<=r) printf("No\n");
	else{
		printf("Yes\n");
		for(int i=1;i<=n;i++) printf("%d ",b[i]);
	}
}

Measured memory_bytes: 5380
#表計算を行うプログラムを作成。

r,c=gets.split(" ").map(&:to_i)
h = Array.new(r+1).map{Array.new(c+1,0)} 

for i in 0..r-1                                       # 変数 i を1からrまで増やして繰り返し処理する。
    
a= gets.split.map(&:to_i)
    for j in 0..c-1                                   # 変数 i を0からc-1回まで増やして繰り返し処理する。
    h[i][j] = a[j]                                  # 
    h[i][c] += a[j]
    h[r][j] += a[j]
    h[r][c] += a[j]
    end
end
for i in 0..r
    for j in 0..c
      print " " unless j == 0
      print h[i][j]
    end
    print "\n"
  end




Measured memory_bytes: 7040
function Main(args){

  const input = args.split(" ");

  const a_max = Number(input[0]);
  const a_current = Number(input[1]);
  const b_current = Number(input[2]);
  const a_capacity = a_max - a_current;
  console.log( Math.max(b_current - a_capacity, 0) );

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
class Dice
	def initialize(array)
		@a = Array.new(array)
		@a = @a[0..5]
	end
	
	def rotate(direction)
		if direction == "N" then
			tmp = @a[0]
			@a[0] = @a[1]
			@a[1] = @a[5]
			@a[5] = @a[4]
			@a[4] = tmp
		elsif direction == "S" then
			tmp = @a[0]
			@a[0] = @a[4]
			@a[4] = @a[5]
			@a[5] = @a[1]
			@a[1] = tmp
		elsif direction == "E" then
			tmp = @a[0]
			@a[0] = @a[3]
			@a[3] = @a[5]
			@a[5] = @a[2]
			@a[2] = tmp
		elsif direction == "W" then
			tmp = @a[0]
			@a[0] = @a[2]
			@a[2] = @a[5]
			@a[5] = @a[3]
			@a[3] = tmp
		end
	end
	
	def get_top
		@a[0]
	end
	
	def get_right
		@a[2]
	end
	
	def get_front
		@a[1]
	end
	
	def get_left
		@a[3]
	end
	
	def get_bottom
		@a[5]
	end
	
	def get_rear
		@a[4]
	end
	
	def is_same_dice(d)
		if self.get_top == d.get_top &&
		   self.get_bottom == d.get_bottom &&
		   self.get_front == d.get_front &&
		   self.get_rear == d.get_rear &&
		   self.get_left == d.get_left &&
		   self.get_right == d.get_right
		then
			return true
		else
			return false
		end
	end
	
	def get_dice
		@a
	end
end

def array_to_i(a)
	0.upto(a.length) {|i|
		a[i] = a[i].to_i
	}
	return a
end

read_a = STDIN.gets.chomp.split(" ")
read_a = array_to_i(read_a)
read_a = read_a[0..5]
dice_a = Dice.new(read_a)
read_a.sort!

read_b = STDIN.gets.chomp.split(" ")
read_b = array_to_i(read_b)
read_b = read_b[0..5]
dice_b = Dice.new(read_b)
read_b.sort!

answer = "No"

0.upto(1) {
	0.upto(3) {
		0.upto(3) {
			if dice_a.is_same_dice(dice_b) then
				answer = "Yes"
				break
			else
				dice_b.rotate("E")
			end
		}
		break if answer == "Yes"
		dice_b.rotate("S")
	}
	dice_b.rotate("E")
}

print answer, "\n"



Measured memory_bytes: 6892
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
string s;
string t;
int n;
int ss;
int cc;
vector<string> hai;
int main()
{
	cin>>s;
	cin>>n;
	ss=s.size();
	rep(i,ss)
	{
		rep(j,5)
		{
			if(i+j>=ss)break;
			t=s.substr(i,j+1);
			hai.push_back(t);
		}
	}
	sort(all(hai));
	rep(i,hai.size())
	{
		//cout<<hai[i]<<endl;
		if(cc==n-1)
		{
			cout<<hai[i]<<endl;
			return 0;
		}
		if(hai[i]!=hai[i+1])cc++;
	}
	//cout<<hai[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1660
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

random_device seed_gen;
mt19937 engine(seed_gen());
// 0, 1, 2 のどれかが得られる一様分布
// uniform_int_distribution<> dist(0, 2);
// cout << dist(engine) << endl;
// みたいに、先に確率分布を宣言して、そこにengineを与えて使う。

// =========ここまでテンプレ============

int main()
{
    vector<char> s(3);
    rep(i, 3)
    {
        cin >> s[i];
    }
    if (s[1] == 'R')
    {
        if (s[0] == 'R')
        {
            if (s[2] == 'R')
            {
                cout << 3 << endl;
            }
            else
            {
                cout << 2 << endl;
            }
        }
        else
        {
            if (s[2] == 'R')
            {
                cout << 2 << endl;
            }
            else
            {
                cout << 1 << endl;
            }
        }
    }
    else
    {
        if (s[0] == 'R' || s[2] == 'R')
        {
            cout << 1 << endl;
        }
        else
        {
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll ans=0;
  REP(i,1,n+1) {
    if(i%3&&i%5) ans+=i;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int Nmax = 1000;

vector<int> Prime(Nmax, 1);  // Prime[i] : iが素数のとき1、iが素数でないとき0

void Eratosthenes(int n) {  // n未満の素数を求める

    Prime[0] = Prime[1] = 0;
    for(int i = 2; i*i < n; i++) {
        if(Prime[i]) {
            for(int j = 2; i*j < n; j++) {
                Prime[i*j] = 0;
            }
        }
    }
}

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

    Eratosthenes(1000);

    vector<ll> e(1000, 1);  // e[i] : n!の素因数iの指数 + 1 (iが素数でないときは1)
    for(int i = 2; i <= n; i++) {
        int k = i;
        for(int j = 2; j*j <= n; j++) {
            if(Prime[j]) {
                while(k%j == 0) {
                    k /= j;
                    e[j]++;
                }
            }
        }
        if(k != 1) {
            e[k]++;
        }
    }

    ll ans = 1LL;
    rep(i, 1000) {
        ans *= e[i];
        ans %= mod;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,W;cin >> n >> W;
	vector<int> w(n),v(n);
	rep(i,n) cin >> w.at(i) >> v.at(i);
	vector<vector<ll>> dp(n+1,vector<ll>(100010,1000000000000000000));
	dp[0][0]=0;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=100000;++j){
			if(j-v.at(i-1)>=0) dp[i][j]=min(dp[i-1][j],dp[i-1][j-v.at(i-1)]+w.at(i-1));
			else dp[i][j]=dp[i-1][j];
		}
	}
	for(int j=100000;j>=0;--j){
		if(dp[n][j]<=W){
			cout << j << endl;
			break;
		}
	}
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,n) for(i=0;i<n;i++)
typedef long long ll;
#define mod 1000000007
#define __builtin_popcountll bitc
int main()
{
	
	ll n,i,j,c=0;
	cin>>n;
	ll a[n];
	rep(i,n)
	{
		cin>>a[i];

	}
	for(i=1;i<n;i++)
	{
		if(a[i]==a[i-1]){
			c++;
			a[i]=0;
		}
	}
	cout<<c;
}

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
constexpr ll M2 = 998244353;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e, ll M = ::M2) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll modinv(ll x) {
    return pow_f(x, M2-2, M2);
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * ((n-i+1)% M2)) % M2;
        ans = (ans * modinv(i)) % M2; 
    }
    return ans % M2;
}

// ll nCr(tuple<ll,ll> t) {
//     auto n = get<0>(t);
//     auto k = get<1>(t);
//     return nCr(n+k-1, k);
// }

template<typename T>
void print(const T &v) {
    cout << v << " ";
}

template<typename T>
void print(const vector<T> &v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    ll n, m, k;
    cin >> n >> m >> k;

    ll ans = (m%M2 * pow_f(m-1, n-1, M2)) % M2;
    ll coeff = 1;
    for (ll i = 1; i <= k; ++i) {
        ll temp;
        coeff = (coeff * ((n-i)% M2)) % M2;
        coeff = (coeff * modinv(i)) % M2;
        temp = (m%M2 * coeff) % M2;
        temp = (temp * pow_f(m-1, n-1-i, M2)) % M2;
        ans = (ans + temp) % M2;
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func printIntArray(values []int) {
	arraySize := len(values)
	strValues := make([]string, arraySize)
	for i, elm := range values {
		strValues[i] = strconv.Itoa(elm)
	}

	fmt.Printf("%v\n", strings.Join(strValues, " "))
}

func bubbleSort(values []int) int {
	flag := true
	count := 0
	for {
		if !flag {
			break
		}
		flag = false

		for j := len(values) - 1; j >= 1; j-- {
			if values[j] < values[j-1] {
				tmp := values[j]
				values[j] = values[j-1]
				values[j-1] = tmp
				count++
				flag = true
			}
		}
	}
	return count
}

func main() {
	var arraySize int
	fmt.Scan(&arraySize)
	// fmt.Println("arraySize", arraySize)

	values := make([]int, arraySize)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < arraySize; i++ {
		sc.Scan()
		s := sc.Text()
		// fmt.Println("scan", s)
		values[i], _ = strconv.Atoi(s)
	}

	count := bubbleSort(values)
	printIntArray(values)
	fmt.Printf("%d\n", count)

}



Measured memory_bytes: 1204
n = gets.to_i
tree = Struct.new(:parent, :sibling, :degree, :depth, :height, :type, :children)
node = Array.new(n) {tree.new}
n.times do
  ar = gets.split.map(&:to_i)
  node[ar[0]].children = ar[1..-1]
  node[ar[0]].degree = ar[1..-1].reject {|x| x == -1}.size
  node[ar[0]].parent = -1
  node[ar[0]].sibling = -1
  node[ar[0]].type = "internal node"
end

node.each_with_index do |nd, i|
  nd.children.each {|child| node[child].parent = i unless child == -1}
  case nd.degree
  when 0
    nd.type = "leaf"
    nd.height = 0
  else
    node[nd.children[0]].sibling = nd.children[1] unless nd.children[0] == -1
    node[nd.children[1]].sibling = nd.children[0] unless nd.children[1] == -1
  end
end

root_index = 0
node.each_with_index {|nd, i| root_index = i if nd.parent == -1}
node[root_index].type = "root"

search = ->(index, depth) {
  node[index].depth = depth
  children = node[index].children.reject {|x| x == -1}
  return 0 if children.empty?
  height_max = 0
  children.each do |child|
    h = search.(child, depth + 1) + 1
    height_max = h if h > height_max
  end
  node[index].height = height_max
}
search.(root_index, 0)

node.each_with_index do |nd, i|
  puts "node #{i}: parent = #{nd.parent}, sibling = #{nd.sibling}, degree = #{nd.degree}, depth = #{nd.depth}, height = #{nd.height}, #{nd.type}"
end


Measured memory_bytes: 8876
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a=['A','B','C','D','E','F']
    b,c=STRM()
    if a.index(b) < a.index(c):
        print('<')
    elif a.index(b) == a.index(c):
        print('=')
    else:
        print('>')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
import collections 

n = int(input())
input_list = [int(i) for i in input().split(' ')]

counter = collections.Counter(input_list)


unique_list = list(counter.keys())
counts = list(counter.values())

if (all(num == 0 for num in unique_list)):
    print('Yes')
else:
    if n % 3 == 0:
        zero_count = counter[0] 
        if zero_count == n / 3 and len(unique_list) == 2:
            print('Yes')
        else: 
            if len(unique_list) != 3:
                print('No')
            elif (unique_list[0] ^ unique_list[1] == unique_list[2]):
                if (all(counts[0] == num for num in counts)):
                    print('Yes')
                else:
                    print('No')
            else:
                print('No')
    else:
        print('No')

Measured memory_bytes: 14460
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <cmath>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;

#define rep(i, m) for(ll i=0;i<(m);i++)
#define rep1(i, m) for(ll i=1;i<=(m);i++)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

struct BIND {int s, t, v; };

int main() {
   int N; cin >> N;
   vector<int> t(N), v(N);
   rep(i, N) {
      cin >> t[i]; t[i] *= 4;
   }
   rep(i, N) {
      cin >> v[i]; v[i] *= 4;
   }
   vector<int> s(N+1);
   rep(i, N) {
      s[i+1] = s[i] + t[i];
   }

   vector<BIND> bs;
   rep(i, N) {
      bs.push_back((BIND){s[i], s[i+1], v[i]});
   }
   bs.push_back((BIND){0,0,0});
   bs.push_back((BIND){s[N],s[N],0});

   int prev_v = 0; int dist = 0;
   for (int u=2;u<=s[N];u+=2) {
      int minval = 10000000;
      rep(i, N+2) {
         BIND b = bs[i];
         if (u < b.s) {
            minval = min(minval, b.v + b.s - u);
         } else if (u > b.t) {
            minval = min(minval, b.v + u-b.t);
         } else {
            minval = min(minval, b.v);
         }
      }
      dist += prev_v + minval;
      prev_v = minval;
   }
   printf("%.91f\n", dist/16.0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	vector<vector<int> > number(3, vector<int>(3));
	vector<int> yoko(3);
	vector<int> tate(3);
	int yes = 0;
	int no = 0;
	for (int i = 0;i <= 2;i++) {
		for (int j = 0;j <= 2;j++) {
			cin >> number[i][j];
		}
	}
	for (int i = 0;i <= number[0][0] + 1;i++) {
		for (int j = 0;j <= number[1][1] + 1;j++) {
			for (int k = 0;k <= number[2][2] + 1;k++) {
				no = 0;
				yoko[0] = i;
				yoko[1] = j;
				yoko[2] = k;
				tate[0] = number[0][0] - i;
				tate[1] = number[1][1] - j;
				tate[2] = number[2][2] - k;
				for (int l = 0;l <= 2;l++) {
					for (int m = 0;m <= 2;m++) {
						if (yoko[l] + tate[m] != number[l][m]) {
							no = 1;
						}
					}
				}
				if (no == 0) {
					yes = 1;
					i = number[0][0] + 1;
					j = number[1][1] + 1;
					k = number[2][2] + 1;
				}
			}
		}
	}
	if (yes == 1) {
		cout << "Yes" << endl;
	}
	else if (yes == 0) {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int sx, sy, tx, ty;
    scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
    int x = sx;
    int y = sy;
    while(x<tx){
        x++;
        printf("R");
    }
    while(y<ty){
        y++;
        printf("U");
    }
    while(x>sx){
        x--;
        printf("L");
    }
    while(y>=sy){
        y--;
        printf("D");
    }
    while(x<=tx){
        x++;
        printf("R");
    }
    while(y<ty){
        y++;
        printf("U");
    }
    x--;
    printf("L");
    y++;
    printf("U");
    while(x>=sx){
        x--;
        printf("L");
    }
    while(y>sy){
        y--;
        printf("D");
    }
    x++;
    printf("R\n");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,a,b,c,d,e,f,g,h,x,y;
    int s[7]={1,3,5,7,8,10,12};
    int v[4]={4,6,9,11};
    int o[1]={2};
    while(~scanf("%d %d",&x,&y))
    {
        if(x==2&&y==2)
        {
            printf("Yes\n");
        }
        else
        {
        d=0;
        for(c=0;c<7;c++)
        {
            if(s[c]==x)
            {
                d++;
            }
            if(s[c]==y)
            {
                d++;
            }
        }
        f=0;
        for(e=0;e<4;e++)
        {
            if(v[e]==x)
            {
                f++;
            }
            if(v[e]==y)
            {
                f++;
            }
        }
        h=0;
        if(h==2||f==2||d==2)
        {
            printf("Yes\n");
        }
        else
            printf("No\n");
        }
    }
  return 0;
}

Measured memory_bytes: 128