akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

ll dp[3001][3001][4];

int main()
{
    int R,C,K;cin >> R >> C >> K;
    vector<vector<ll>> item(R+1,vector<ll>(C+1,0));
    ll r,c,v;
    for (int i=0;i<K;i++)
    {
        cin >> r >> c >> v;
        item[r][c]=v;
    }
    if (item[1][1]!=0)
    {
        dp[1][1][1]=item[1][1];
    }
    for (int i=1;i<R+1;i++)
    {
        for (int j=1;j<C+1;j++)
        {
            if (i+1<=R)
            {
                if (item[i+1][j]!=0)
                {
                    for (int k=0;k<4;k++)
                    {
                        dp[i+1][j][1]=max(dp[i][j][k]+item[i+1][j],dp[i+1][j][1]);
                    }
                    for (int k=0;k<4;k++)
                    {
                        dp[i+1][j][0]=max(dp[i][j][k],dp[i+1][j][0]);
                    }
                }
                else
                {
                    for (int k=0;k<4;k++)
                    {
                        dp[i+1][j][0]=max(dp[i][j][k],dp[i+1][j][0]);
                    }
                }
            }
            if (j+1<=C)
            {
                if (item[i][j+1]!=0)
                {
                    for (int k=0;k<3;k++)
                    {
                        dp[i][j+1][k+1]=max(dp[i][j][k]+item[i][j+1],dp[i][j+1][k+1]);
                    }
                    for (int k=0;k<3;k++)
                    {
                        dp[i][j+1][k]=max(dp[i][j][k],dp[i][j+1][k]);
                    }
                    dp[i][j+1][3]=max(dp[i][j][3],dp[i][j+1][3]);
                }
                else
                {
                    for (int k=0;k<4;k++)
                    {
                        dp[i][j+1][k]=max(dp[i][j][k],dp[i][j+1][k]);
                    }
                }
            } 
        }
    }
    cout << max({dp[R][C][0],dp[R][C][1],dp[R][C][2],dp[R][C][3]}) << endl;
    return 0;
}

Measured memory_bytes: 354888
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  char c;
  cin >> c;
  if(c == 'A') cout << 'T' << endl;
  if(c == 'T') cout << 'A' << endl;
  if(c == 'C') cout << 'G' << endl;
  if(c == 'G') cout << 'C' << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int x,y,s,i,j,max=0;
  while(1){
    scanf("%d%d%d",&x,&y,&s);
    if(x+y+s==0)break;
    max = 0;
    for(i=1;i<s;i++)for(j=i;j<s;j++)if((i*(100+x)/100+j*(100+x)/100)==s&&i*(100+y)/100+j*(100+y)/100>max)max=i*(100+y)/100+j*(100+y)/100;
    printf("%d\n",max);
  }
  return 0;
}


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

int main() {
    int a,b,c;
    cin >> a >> b >> c;

    if(a == b && b != c) {
        cout << "Yes" << '\n';
        return 0;
    }
    if(a != b && b == c) {
        cout << "Yes" << '\n';
        return 0;
    }
    if(a == c && b != c) {
        cout << "Yes" << '\n';
        return 0;
    }

    cout << "No" << '\n';

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n; // ????????°
vector<int> G[MAX]; // ??£??\?????????
int color[MAX]; // ??????????????????

void dfs(int r, int c){ // ??????r?????\?¶????????????????????????????c??§??????
	stack<int> S;
	S.push(r);
	color[r] = c; // ??????r??????c?????????
	while(!S.empty()){
		int u = S.top();S.pop();
		for(int i=0;i<G[u].size();i++){
			int v = G[u][i];
			if(color[v] == NIL){ // ???????????????u??¨??£??\????????????????????????????????£??????????????£???????????????u??¨??????????????????
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor(){ // ????????????????????????
	int id = 1; // ????????´??°???????????????????????\??????????????????1???????§???????1???????¢???????
	for(int i=0;i<n;i++) color[i] = NIL; // ???????±??????£??????????????¶???
	for(int u=0;u<n;u++){
		if(color[u] == NIL) dfs(u,id++); // ??????????????????????????????????§???????
	}
}

int main(){
	int s, t, /* ??????s??¨??????t????????????????????¨?????? */ m /* ????????° */, q /* ???????????±????????° */;

	cin >> n >> m;

	for(int i=0;i<m;i++){
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	assignColor();

	cin >> q;

	for(int i=0;i<q;i++){
		cin >> s >> t;
		if(color[s] == color[t]){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 8988
m = int(input())
for i in range(m):
    s = list(input())
    kouho = []
    for i in range(1, len(s)):
        this1 = s[:i]
        this2 = s[i:]
        kouho.append([this1 + this2])
        kouho.append([this1[::-1] + this2])
        kouho.append([this1[::-1] + this2[::-1]])
        kouho.append([this1 + this2[::-1]])
        kouho.append([this2 + this1])
        kouho.append([this2[::-1] + this1])
        kouho.append([this2[::-1] + this1[::-1]])
        kouho.append([this2 + this1[::-1]])
    kouho.sort()
    #print(len(kouho))
    cnt = 0
    i = 1
    while i < len(kouho):
        if kouho[i] == kouho[i - 1]:
            del kouho[i]
            i -= 1
        i += 1
    print(len(kouho))


Measured memory_bytes: 6220
#include<bits/stdc++.h>
using namespace std ;
int const maxn=200;
int ar[maxn];
int main()
{
	string s;
	cin >> s;
	int s1=0,t=0,ans=0;
	bool a=0,b=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i] == 'S' && b==1)
		{
			ans+=min(t,s1);
			s1=(s1-min(t,s1))+1;
			t=0;
			b=0;
			a=1;
			
		}
		else if(s[i] == 'S')
		{
			a=1;
			s1++;
		}
		else if(s[i] == 'T')
		{
			if(a==1)
			{
				t++;
				b=1;
			}
			else
			{
				s1=0;
				t=0;
			}
		}
	}
	if(s[s.size()-1] == 'T')
		ans+=min(t,s1);
	
	cout << s.size()-(ans*2);
	
}


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

using namespace std;


int main(){
	long long int x,a,b,c;
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>x;
	long long int count=0;
	long long int temp =0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				temp = i*500 + j*100 + k*50;	
				if(temp==x) count++;	
			}
		}
	}
	cout<<count;
	return 0;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	string s = to_string(n);
	int digit_sum = 0;
	for(int i = 0;i < s.size();i++){
		digit_sum += s[i] - '0';
	}

	if(n % digit_sum == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#! /usr/bin/python
# -*- coding: utf-8 -*-

def rec(csum, chi, cval):
    global n
    global k 
    global s 
    global cnt
    if chi == k:
        if csum != s:
            return
        elif csum == s:
            cnt += 1
            return
    elif chi < k:
        for i in range(cval+1, n+1):
            if csum+i > s:
                return
            else:
                rec(csum+i, chi+1, i)

(n, k, s) = map(int, raw_input().split())
while n!=0:
    cnt = 0
    rec(0, 0, 0)
    print cnt

    (n, k, s) = map(int, raw_input().split())

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
using namespace std;
int dis(int a,int b) {
    return (a-b)*(a-b);
}
int main(){
    int n,x[110];
    while (scanf("%d",&n)!=EOF) {
        int mn = 1e9;
        for (int i=0;i<n;i++)
            scanf("%d",&x[i]);
        for (int i=1;i<=100;i++){
            int sum = 0;
            for (int j=0;j<n;j++) {
                sum += dis(i,x[j]);
            }
            mn = min(sum,mn);
        }
        printf("%d\n",mn);

    }
    return 0;
}


Measured memory_bytes: 256
def solve(A, B, C, X):
    r = 0
    for i in range(0, A + 1):
        for j in range(0, B + 1):
            t = i * 500 + j * 100
            if t > X:
                break
            if 0 <= (X - t) / 50 <= C:
                r += 1
    return r

A = int(input())
B = int(input())
C = int(input())
X = int(input())

if __name__ == '__main__':
    print(solve(A, B, C, X))


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

typedef  long long ll;

#define rep(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(ll (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007


using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}


void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

ll divisors(ll n) {
    vector<ll> res;

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i-1);
        if(n/i == i) continue;
        res.push_back((n/i)-1);
    }

    ll ans = 0;

    rep(i,0,res.size()){
        if(res[i] != 0)
        if(n/res[i] == n%res[i]) ans += res[i];
    } 
    return ans;
}

void solve(void){
   int a,b;
   scanf("%d %d",&a,&b);
   double ans = 0;
   rep(i,1,a+1){
       double tmp = 1.0/a;
       int n = i;
       while(n < b){
           n*=2;
           tmp/=2;
       }
       ans+=tmp;
   }
   printf("%.12f\n",ans);

}

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


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
pos =0
cnt=0
roop = []
visit =[0]*n
while visit[pos]!=2:
    if visit[pos]==0:
        visit[pos]+=1
        if pos == 1:
            print(cnt)
            break
        else:
            cnt+=1
            pos=a[pos]-1
    else:
        print(-1)
        break

Measured memory_bytes: 7852
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;
ll gcd(ll a,ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
int main() {
	ll N, K;
	cin >> N >> K;
	ll ans = 0;
	vector<ll> num(N);
	for (int i = 0; i < N; i++) cin >> num[i];
	if (N <= K)cout << "0" << endl;
	else {
		sort(all(num));
		for (int i = 0; i < N - K; i++) {
			ans += num[i];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1792
/**
 * ２つの整数 a, b を読み込んで、a と b の大小関係を出力するプログラム
 * @author 前島佑介
 *@version 2014/12/1
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


// 2-A ２つの整数 a, b を読み込んで、a と b の大小関係を出力するプログラム
class Main {

	// プログラムのエントリポイント
	public static void main(String[] args) {

		//入力値1つ目
		int intNum1 = 0;

		//入力値2つ目
		int intNum2 = 0;

		try{
			//キーボードからの入力準備
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			//キーボードからの入力をString型で受け取る
			String strLine = br.readLine();

			//文字列の分割:入力値を" "で分ける
			//分けた文字列はstrLineAry[0]とstrLineAry[1]に分けられる
			String[] strLineAry = strLine.split(" ");

			//入力値の１つ目は縦
			intNum1 = Integer.parseInt(strLineAry[0]);

			//２つ目は横
			intNum2 = Integer.parseInt(strLineAry[1]);

			//intNum1よりintNum2のほうが大きいなら
			if(intNum1 < intNum2) {

				//結果を出力
				System.out.println("a < b");

			//intNum1よりintNum2のほうが小さいなら
			}else if(intNum1 > intNum2) {

				//結果を出力
				System.out.println("a > b");

			//それ以外のintNum1とintNum2が同じなら
			}else {

				//結果を出力
				System.out.println("a == b");
			}

			//例外処理
			}catch(IOException e) {

				//例外時の出力
				System.out.println(e);

			}catch(NumberFormatException e) {

				//数値以外の入力値で出力
				System.out.println("数値で入力して下さい");
			}
	}
}

Measured memory_bytes: 16888
def main():
    n, *abc = map(int, open(0).read().split())
    x, y, z = 0, 0, 0
    for i, (a, b, c) in enumerate(zip(*[iter(abc)] * 3), 1):
        x, y, z = a + max(y, z), b + max(z, x), c + max(x, y)
    
    ans = max([x, y, z])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 35636
import java.util.*;

public class Main {
    static final long DIV = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.close();

        if(n == 1 || m == 1){
            System.out.println(1);
            return;
        }

        int div = 2;
        int count = 0;
        ArrayList<Integer> num = new ArrayList<Integer>();
        while(div <= m){
            if(m % div == 0){
                count++;
                m /= div;
            }else{
                if(count > 0){
                    num.add(count);
                    count = 0;
                }
                div++;
            }
        }
        if(count > 0) num.add(count);
        if(m != 1) num.add(1);

        long[] fact = new long[2*n+10];
        long[] ifact = new long[2*n+10];
        fact[0] = 1;
        fact[1] = 1;
        ifact[0] = 1;
        ifact[1] = 1;
        for(int i=2; i<2*n+10; i++){
            fact[i] = (fact[i-1]*i) % DIV;
            ifact[i] = inverseElement(fact[i], DIV);
        }

        long ans = 1;
        for(int i=0; i<num.size(); i++){
            ans *= fact[n+num.get(i)-1];
            ans %= DIV;
            ans *= ifact[num.get(i)];
            ans %= DIV;
            ans *= ifact[n-1];
            ans %= DIV;
        }

        System.out.println(ans);
    }

    public static long inverseElement(long a, long n){
        long b = n, u=1, v=0;
        while(b > 0) {
            long t = a/b;
            a -= t*b;
            u -= t*v;
            //swap
            t = a;
            a = b;
            b = t;
            t = u;
            u = v;
            v = t;
        }
        u = u % n;
        if(u < 0) u += n;
        return u;
    }
}

Measured memory_bytes: 28756
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define int long long
using namespace std;
static const int MAX_N = 100000;
static const int inf  = 1ll<<60;
static const int MAX_SEG=1<<17;
typedef pair<int,int> pii;
int dat[2*MAX_SEG];

class segment{
public:
    int n;
    void init(int n_){
        for(int i=0;i<2*MAX_SEG-1;++i)dat[i]=0;

    }
    void update(int a,int b,int x,int k=0,int l=0,int r=MAX_SEG){
        if(r<=a||b<=l)return;
        if(a<=l&&r<=b){
            dat[k]=max(dat[k],x);
            return;
        }
        update(a,b,x,k*2+1,l,(l+r)/2);
        update(a,b,x,k*2+2,(l+r)/2,r);
    }
    int query(int k){
        k+=MAX_SEG-1;
        int ret=dat[k];
        while(k){
            k=(k-1)/2;
            ret=max(ret,dat[k]);
        }
        return ret;
    }
};

int N,M;
vector<int> g[MAX_N+5];
int depth[MAX_N+5];
int par[20][MAX_N];
int tin[2*MAX_N+5],tout[2*MAX_N+5];
int k=0;

void dfs(int v,int p,int d){
    par[0][v]=p;
    depth[v]=d;
    tin[v]=k++;
    for(int u=0;u<g[v].size();++u){
        dfs(g[v][u],v,d+1);
        //k++;
    }
    tout[v]=k;
}

void fill_table(){
    for(int i=0;i<19;i++){
        for(int j=0;j<N;j++){
            if(par[i][j]==-1)par[i+1][j]=-1;
            else par[i+1][j]=par[i][par[i][j]];
        }
    }
}

signed main(){
    while(1){
        int ans=0;
        cin>>N>>M;
        if(N==0&&M==0)break;
        for(int i=0;i<N;++i)g[i].clear();
        memset(par,0,sizeof(par));
        for(int i=1;i<N;++i){
            int p;
            cin>>p;
            p--;
            g[p].PB(i);
        }
        k=0;
        dfs(0,-1,0);
        fill_table();
        segment seg;
        seg.init(N);
        for(int t=0;t<M;++t){
            char que;
            int v;
            cin>>que;
            cin>>v;
            v--;
            //cout<<tin[v]<<" "<<tout[v]<<" "<<depth[v]<<endl;
            if(que=='M'){
                seg.update(tin[v],tout[v],depth[v]);
            }
            else{
                int q=seg.query(tin[v]);
                for(int i=19;i>=0;--i){
                    if((depth[v]-q)>>i&1)v=par[i][v];
                }
                ans+=v+1;
            }
        }
        cout<<ans<<endl;
    }
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int c[101010];
vector<vector<PII>> edge(101010);
bool used[101010];
void dfs(int node,int cost){
  if(used[node]) return;
  used[node] = true;

  c[node] = cost;
  rep(i,edge[node].size()){
    if(used[edge[node][i].first]) continue;
    dfs(edge[node][i].first,(cost+edge[node][i].second) % 2);
  }

}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  memset(c,-1,sizeof(c));
  rep(i,n-1){
    int u,v,w;
    cin >> u >> v >> w;
    u--; v--;
    edge[u].push_back(make_pair( v , w%2 ));
    edge[v].push_back(make_pair( u , w%2 ));
  }
  dfs(0,0);
  rep(i,n){
    cout << c[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 7808
#include <iostream>
using namespace std;
void inning() {
  int out = 0, runner = 0, score = 0;
  string ev;
  while(out < 3) {
	cin >> ev;
	if(ev == "OUT") {
	  out++;
	  if(out == 3) break;
	}
	else if(ev == "HOMERUN") {
	  score += runner + 1;
	  runner = 0;
	}
	else if(ev == "HIT") {// hit
	  if(runner == 3) score++;
	  else runner++;
	}
  }
  cout << score << endl;
}
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
	inning();
  }
  return 0;
}

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

#define sz(x) (int)x.size()
#define ld long double
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

const ll MOD = 1e9 + 7;

ll n, res, k = 0;
vector<ll> f, p, r, s, v, x;
vector<vector<ll>> dp;
ll exp(ll a, ll n){
    if(n == 0) return 1;
    ll tmp = exp(a, n/2);
    tmp *= tmp;
    tmp %= MOD;
    if(n%2) tmp *= a;
    tmp %= MOD;
    return tmp;
}
ll find(ll u){
    if(p[u] != u) p[u] = find(p[u]);
    return p[u];
}
void merge(ll u, ll v){
    u = find(u);
    v = find(v);
    if(u != v){
        if(r[u] > r[v]){
            r[u]++;
            s[u] += s[v];
            p[v] = u;
        }
        else{
            r[v]++;
            s[v] += s[u];
            p[u] = v;
        }
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    v.assign(n, 0);
    r.assign(n, 0);
    p.assign(n, 0);
    s.assign(n, 1);
    f.assign(1e5 + 1, 1);
    for(int i = 0; i < n; ++i){
        cin >> v[i];
        if(v[i] > 0) v[i]--;
        else k++;
        p[i] = i;
    }
    set<ll> un, d;
    for(int i = 0; i < n; ++i){
        if(v[i] != -1) merge(i, v[i]);
    }
    res = (exp(n - 1, k) * n)%MOD;
    for(int i = 0; i < n; ++i){
        find(i);
        if(v[i] == -1) un.insert(p[i]);
    }
    for(int i = 0; i < n; ++i){
        if(un.find(p[i]) == un.end()) d.insert(p[i]);
    }
    res -= exp(n - 1, k) * sz(d);
    res %= MOD;
    for(auto i : un) x.pb(s[i]);
    // for(auto i : un) cout << i << " ";
    // cout << "\n";
    // for(auto i : d) cout << i << " ";
    // cout << "\n";
    // for(auto i : x) cout << i << " ";
    // cout << "\n";
    //dp[i][j] = total sum of products of j elements out of first i elements
    dp.assign(sz(x) + 1, vector<ll>(sz(x) + 1, 0));
    if(!sz(x)) goto end;
    dp[1][0] = 0;
    dp[1][1] = x[0];
    for(int i = 1; i < sz(x); ++i){
        dp[i][0] = 1;
        for(int j = 0; j <= sz(x); ++j){
            if(j < sz(x)){
                dp[i + 1][j + 1] += dp[i][j] * x[i];
                dp[i + 1][j + 1] %= MOD;
            }
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= MOD;

        }
    }
    // for(auto i : dp){
    //     for(auto j : i){
    //         cout << j << " ";
    //     }
    //     cout << "\n";
    // }
    // cout << sz(x) << " " << k << "\n";
    for(int i = 1; i <= 1e5; ++i){
        f[i] = f[i - 1] * i;
        f[i] %= MOD;
    }
    // for(int i = 0; i < 10; ++i) cout << f[i] << " ";
    // cout << "\n";
    for(int i = 2; i <= sz(x); ++i){
        res -= (dp[sz(x)][i] * ((f[i - 1] * exp(n - 1, k - i))%MOD))%MOD;
        res %= MOD;
    }
    for(auto i : x){
        res -= (i - 1) * exp(n - 1, k - 1);
        res %= MOD;
    }
    end:;
    cout << (res%MOD + MOD)%MOD;
    return 0;
}

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

namespace ABC134B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var N = input[0];
            var D = input[1];

            int result;
            var div = Math.DivRem(N, D * 2 + 1, out result);

            Console.WriteLine(div + (result > 0 ? 1 : 0));
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
#include<math.h>
int main()
{
	int n;
	scanf("%d", &n);
	double x[10], y[10];
	int i, j;
	for (i = 0; i < n; i++)
		scanf("%lf %lf", &x[i], &y[i]);
	double d = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			d += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
	int k[10];
	k[0] = 1;
	for (i = 1; i < 10; i++)
		k[i] = k[i - 1] * i;
	d *= (double)k[n - 1];
	printf("%.20lf\n", d / (double)k[n]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
	
    string n;
    cin >> n;
    rep(i,n.length()){
        if(n[i]=='7'){
            Yes();
            return 0;
        }
    }
    No();
    return 0;

}

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



Measured memory_bytes: 32964
loop do
a, op, b = gets.split
a = a.to_i
b = b.to_i
  if op == '?'
    break
  elsif op == "+"
    puts a + b
  elsif op == "-"
    puts a - b
  elsif op == "*"
    puts a * b
  elsif op == "/"
    puts a / b
  end
end



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

#define double long double

const int N = 105;

struct P {
    ll x, y;

    double len() {
        return sqrt(x * x + y * y);
    }

} p[N];

double ans[N];

ll operator * (P a, P b) {
    return a.x * b.y - a.y * b.x;
}

ll operator / (P a, P b) {
    return a.x * b.x + a.y * b.y;
}

P operator - (P a, P b) {
    return {a.x - b.x, a.y - b.y};
}


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

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        p[i] = {x, y};
    }

    for (int i = 0; i < n; i++) {
        vector<P> v;

        for (int j = 0; j < n; j++) {
            if (i != j) {
                v.push_back(p[j] - p[i]);
            }
        }

        bool emp = false;

        for (int j = 0; j < v.size(); j++) {
            for (int k = j + 1; k < v.size(); k++) {
                if (v[j] * v[k] == 0 &&
                    v[j] / v[k] < 0) {
                    emp = true;
                }
            }
        }

        if (!emp) {
            for (int j = 0; j < v.size(); j++) {
                bool ok = true;
                for (int k = 0; k < v.size(); k++) {
                    if (v[j] * v[k] > 0) {
                        ok = false;
                        break;
                    }
                }


                if (ok) {
                    P z = v[j];

                    for (int k = 0; k < v.size(); k++) {
                        if (z * v[k] < 0) {
                            z = v[k];
                        }
                    }

                    // cout << -(z / v[j]) / z.len() / v[j].len() << "\n";
                    if (z * v[j] == 0) {
                        ans[i] = 0.5;
                    }
                    else {
                        double ang = acos(-(z / v[j]) / z.len() / v[j].len());
                        ans[i] = ang / acos(-1) / 2;
                    }

                    break;
                }
            }
        }
        // cout << "\n";
    }

    cout << fixed << setprecision(15);

    for (int i = 0; i < n; i++) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

int main(void)
{
    int a, b;
    scanf("%d%d", &a, &b);

    if (a * 12.5 >= b * 10.0 + 10 || (a+1)*12.5 <= b * 10.0){
        printf("-1");
    }

    else if(a * 12.5 <= b * 10.0 && b * 10.0 < (a+1)*12.5){
        printf("%d", b * 10);
    }

    else if(a * 12.5 >= b * 10.0 && a * 12.5 < b * 10.0 + 10){
        printf("%d", (int)ceil(a*12.5));
    }
}

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

// 入力された文字cが母音か子音かを判定するプログラム
// 母音ならvowel、子音ならconsonantと出力する
// >> a
// vowel
// >> z
// consonant
// >> s
// consonant
int main() {
    char c;
    cin >> c;

    bool isVowel = (c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u');

    if(isVowel)
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int ans[300005];
int mm[300005];
vector<int>v[300005];
int res[300005];

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

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

    int tot=0;
    for(int i=1;i<=n;i++)
    {
        v[mm[i]].push_back(i);
        tot+=mm[i];
    }

    int cnt=0;
    for(int i=n;i>=1;i--)
    {
        for(auto j:v[i])
        {
            tot-=i;
            cnt++;
        }
        int z=tot+cnt*i;
        z/=i;
        res[z]=max(res[z],i);
    }
    for(int i=n;i>=1;i--)
    {
        res[i]=max(res[i],res[i+1]);
    }

    for(int i=1;i<=n;i++)
        cout<<res[i]<<'\n';


} 



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

int main(){
  int N;
  ios::sync_with_stdio(false);
  while(cin >> N,N){
    vector<string> S(N);
    map<char,int> C;
    map<char,bool> not_zero;
    long long int ans = 0;
    for(int i = 0; i < N; ++i){
      cin >> S[i];
      long long int t = 1;
      if(S[i].length() > 1) not_zero[S[i][0]] = true;
      for(int j = S[i].length()-1; j >= 0; --j){
        if(i < N-1) C[S[i][j]] += t;
        else C[S[i][j]] -= t;
        t *= 10;
      }
    }
    int n = C.size();
    vector<int> A;
    for(int i = 0; i < 10; ++i) A.push_back(i);
    do{
      long long int sum = 0;
      int t = 0;
      for(map<char,int>::iterator itr = C.begin(); itr != C.end(); ++itr){
        if(A[t] == 0 && not_zero[itr->first]){
          sum = -1;
          break;
        }
        sum += A[t]*(itr->second);
        ++t;
      }
      if(sum == 0){
        ++ans;
      }
      sort(A.begin()+n, A.end());
      reverse(A.begin()+n,A.end());
    }while(next_permutation(A.begin(), A.end()));
    cout << ans << endl;
  }
  return 0;
}



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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MOD 1e9+7

int main(){
  ll i;
  ll s;
  vector<ll> a(1000000);
  cin >> s;
  a[s - 1] = 1;
  for(i = 0; ;i++){
    if(s % 2 == 1)
      s = 3 * s + 1;
    else
      s /= 2;
    if(a[s - 1] == 1)
      break;
    else
      a[s - 1] = 1;
  }
  
  cout << i + 2 << endl;

  return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;
int n,m,k;
int mat[3001][3001];
int dp[4][3001][3001];
int dfs(int i,int j,int cur){
    if(i == n or j == m or cur == 3){
        return 0;
    }
    if(dp[cur][i][j] != -1){
        return dp[cur][i][j];
    }
    int &ans = dp[cur][i][j];
    ans = 0;
    if(mat[i][j] == 0){
        ans = max({ans,dfs(i+1,j,0),dfs(i,j+1,cur)});
    }
    else{
        ans = max({ans,mat[i][j] + dfs(i+1,j,0),mat[i][j] + dfs(i,j+1,cur+1),dfs(i,j+1,cur),dfs(i+1,j,0)});
    }
    return ans;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> k;
    memset(dp,-1,sizeof(dp));
    f(i,0,k){
        int x,y,val;
        cin >> x >> y >> val;
        x--;
        y--;
        mat[x][y] = val;
    }
    cout << dfs(0,0,0);
    return 0;
}
 


Measured memory_bytes: 356112
nmc = list(map(int, input().split()))
n = nmc[0]
m = nmc[1]
c = nmc[2]

b = list(map(int, input().split()))
a = []
count = 0

for i in range(n):
    a = list(map(int, input().split()))
    x = 0
    for j in range(m):
        x = x + a[j] * b[j]
    x = x + c
    if x > 0:
        count = count + 1

print(count)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n, a, b;

int main() {
	cin >> n >> a >> b;
	rep(i, 300) {
		if (i % 2 == 0) {
			if (a + 1 == b) {
				a--;
				if (a == 0) {
					cout << "Borys" << endl;
					return 0;
				}
			}
			else a++;
		}
		else {
			if (a + 1 == b) {
				b++;
				if (b == n + 1) {
					cout << "Alice" << endl;
					return 0;
				}
			}
			else b--;
		}
	}
	cout << "Draw" << endl;
}

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

int card [255][14]={{0}};

int main(void){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        char c;
        int num;
        cin >> c >> num;
       card[(int)c][num]=1;
            
        }
        for(int i=1;i<=13;i++){
            if(card[(int)'S'][i]==0){
                cout << "S" << " " << i << endl;
            }
        }
        
             for(int i=1;i<=13;i++){
            if(card[(int)'H'][i]==0){
                cout << "H" << " " << i << endl;
        }
    }
    for(int i=1;i<=13;i++){
            if(card[(int)'C'][i]==0){
                cout << "C" << " " << i << endl;
                
            }
    }
    
     for(int i=1;i<=13;i++){
            if(card[(int)'D'][i]==0){
                cout << "D" << " " << i << endl;
                
            }
     }
     
                
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define itoc(c)               ((char)(((int)'0')+c))
#define vl                    vector<ll>
#define SZ(x)                 (x).size()
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define sv()                  ll t,n; scanf("%lld",&t);n=t; while(t--)
#define tcase()               ll t,n; cin>>t;n=t; while(t--)
#define iscn(num)             scanf("%d ",&num);
#define scn(num)              scanf("%lld ",&num);
using namespace std;
const ll INF = 2e18 + 99;
typedef pair<ll,ll> Pair;
typedef vector<ll> vll;
bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////

int main()
{

    FAST_IO();
    ////////////////////////
    ll item, weight ; scn(item); scn(weight);
    vector<vector<ll>>dp(item+1,vector<ll>(weight+1,0));
    vector<Pair>input;
    input.pb(make_pair(0,0));
    for(int i=0; i< item ; i++){
        ll w, value;
        scn(w); scn(value);
        input.pb(make_pair(w,value));
    }
    for(int i=1; i<=item ; i++){
        ll w=input[i].first;
        for(int j=1 ; j<= weight ; ++j){
            if(j<w)
                dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=max(dp[i-1][j],input[i].second+dp[i-1][j-w]);
            }
        }
    }
    printf("%lld\n",dp[item][weight]);

    ////////////////////////
    if(rt && file){
     printf("\nTime taken: %.6fs", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    }
    return 0;
   }

void FAST_IO()
{
    // ios_base::sync_with_stdio(0);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);
    if(rt && file){ tStart = clock(); }
    if(file){
    #ifndef _offline
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    }
}


Measured memory_bytes: 80256
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int a, b, l, c[10], j, cnt, ans = 0;
  scanf("%d %d", &a, &b);
  
  for(int k = a; k <= b; k++){
    l = k; j = 0; cnt = 0;
    while(l > 0){
      c[j++] = l % 10;
      l /= 10;
    }
    for(int i = 0; i < j; i++){
      if(c[i] != c[j - 1 - i]) {cnt++; break;}
    }
    if(cnt == 0) ans++;
  }
  
  printf("%d\n", ans);
  
  return 0;
}
    


Measured memory_bytes: 128
#解答参照した
n,x=map(int,input().split(" "))

P=[1]
M=[1]

for i in range(1,n):
  P.append(2*P[i-1]+1)
  M.append(2*M[i-1]+3)
  
def F(n,x):
  if n==0:
    return 0 if x<=0 else 1
  elif x<=1:
    return 0
  elif 1<x<=M[n-1]+1:
    return F(n-1,x-1)
  elif x==M[n-1]+2:
    return P[n-1]+1
  elif M[n-1]+2<x<2*M[n-1]+3:
    return P[n-1]+1+F(n-1,x-2-M[n-1])
  elif x==2*M[n-1]+3:
    return 2*P[n-1]+1
  else:
    return P[n-1]+1+F(n-1,x-2-M[n-1])
    #print("OH!"+str(n))
    
print (F(n,x))

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

int main(){
  int y,m,d;
  char c1,c2;
  cin >>y >>c1 >>m >>c2 >>d;
  if(m<=4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin >> n, n) {
		vector<pii> point;
		vector<pii> sub;
		REP(i, n + 1) {
			int m;
			cin >> m;
			vector<pii> point2;
			vector<vector<pii>> sub2(2);
			REP(j, m) {
				int x, y;
				cin >> x >> y;
				if (i == 0)
					point.push_back(pii(x, y));
				else
					point2.push_back(pii(x, y));
			}
			if (i == 0) {
				REP(j, m-1) {
					sub.push_back(pii(point[j + 1].first - point[0].first, point[j + 1].second - point[0].second));
				}
				continue;
			}
			REP(j, m - 1) {
				sub2[0].push_back(pii(point2[j + 1].first - point2[0].first, point2[j + 1].second - point2[0].second));
			}
			REP(j, m - 1) {
				sub2[1].push_back(pii(point2[m - 1 - 1 - j].first - point2[m-1].first, point2[m-1-1-j].second - point2[m-1].second));
			}
			bool clear = false;
			
			REP(j, 2) {
				REP(k, 4) {
					vector<pii> sub3 = sub2[j];
					if(k%2==1)
						REP(l, sub3.size()) {
						swap(sub3[l].first, sub3[l].second);
						sub3[l].second *= -1;
					}
					if (k > 1)
						REP(l, sub3.size()) {
						sub3[l].first *= -1;
						sub3[l].second *= -1;
					}
					if (sub3 == sub) {
						clear = true;
						break;
					}
				}
				if (clear)
					break;
			}
			if (clear)
				cout << i << endl;
		}
		cout << "+++++" << endl;
	}
}

Measured memory_bytes: 3104
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds; 
ll n,r,s,p,k;
string t;
ll f(char c)
{
    if(c=='r') return p;
    else if(c=='s') return r;
    else return s;
}	
signed main()
{
    fast;
  
    ll i,j;
    cin>>n>>k>>r>>s>>p>>t;
    ll ans=0;
    for(i=0;i<k;i++)
    {
        ans += f(t[i]);
    }
    for(i=k;i<n;i++)
    {
        if(t[i]!=t[i-k]) ans += f(t[i]);
        else t[i] = '0';
    }
    cout<<ans;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
ans = 0
for k in range(1,n+1):
  K = str(k)
  l = len(K)
  sun = 0
  for i in range(l):
    sun += int(K[i])
  if a <= sun <= b:
    ans += k
print(ans)

Measured memory_bytes: 3060
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class UnionFind:
    def __init__(self, n):
        self._parent = [i for i in range(n)]
        self._rank = [0 for _ in range(n)]
        self._group_size = [1 for _ in range(n)]
        self.num_of_groups = n

    def find(self, x):
        if self._parent[x] == x: return x
        px = self._parent[x]
        root = self.find(px)
        self._parent[x] = root
        return root

    def union(self, x, y):
        px, py = self.find(x), self.find(y)
        if px == py: return
        if self._rank[px] < self._rank[py]:
            self._parent[px] = py
            self._group_size[py] += self._group_size[px]
        else:
            self._parent[py] = px
            self._group_size[px] += self._group_size[py]
        if self._rank[px] == self._rank[py]:
            self._rank[py] += 1
        self.num_of_groups -= 1

    def is_same(self, x, y): return self.find(x) == self.find(y)
    def group_size(self, x): return self._group_size[self.find(x)]


def main():
    N, Q = LI()
    TUV = LIR(Q)

    uf = UnionFind(N+1)

    for t, u, v in TUV:
        if t == 0:
            uf.union(u, v)
        else:
            print(int(uf.is_same(u, v)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 130152
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}
public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long a = fs.nextLong();
        long b = fs.nextLong();
        long n = fs.nextLong();
        long max = Math.min(n,b-1);
        System.out.println(max*a/b);

    }
}

Measured memory_bytes: 32480
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):  # リストに重複した要素があるか判定（要素にリストがある場合）
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


#a, b, c, d = map(int, input().split())
#print(a, b, c, d)
#x = ((a-c)**2+(b-d)**2)**0.5
# print(x)
n = int(input())
# print(divisor(n))
for i in range((n//4)+1):
    for j in range((n//7)+1):
        if 4*i+7*j == n:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 3832