akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

ll ans = 1;
int a[maxN];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	ll f = 1;
	for (int i = 2; i <= n; i++) f = (f * i) % MOD;
	string s; cin >> s;
	if (s[0] == 'W' || s[2 * n - 1] == 'W') return cout << "0\n" << flush, 0;
	a[0] = 0;
	for (int i = 1; i < 2 * n; i++){
		if (s[i] == s[i - 1]) a[i] = 1 - a[i - 1];
		else a[i] = a[i - 1];
	}
	int l = 0, r = 0;
	for (int i = 1; i < 2 * n; i++){
		if (a[i - 1] == 0) l++;
		else r++;
		if (a[i] == 1) ans = (ans * (l - r)) % MOD;
	}
	cout << (abs(r - l) == 1 ? (ans * f) % MOD : 0) << endl;
	return 0;
}



Measured memory_bytes: 1360
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long A, long long B){
  cout << (A - (B*2) > 0 ? (A-(B*2)) : 0) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll num[3010];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &num[i]);
		num[i]--;
	}

	ll res = 0;
	for (int i = 0; i < n; i++)
	{
		res += num[i];
	}
	printf("%lld", res);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){
    ll h,w;cin>>h>>w;
    ll k1=(h+1)/2;
    ll k2=h/2;
    ll l1=(w+1)/2;
    ll l2=w/2;
    if(h==1 || w==1){
        cout<<1<<endl;
    }else{
        cout<<k1*l1+k2*l2<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    d = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                continue

            num = 0
            for x, y in d:
                if 0 <= i + x <= H - 1 and 0 <= j + y <= W - 1:
                    if S[i + x][j + y] == "#":
                        num += 1

            S[i][j] = num

    for strings in S:
        strings = map(str, strings)
        print("".join(strings))


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

bool prime(int N) {
    bool ans = true;
    for (int i = 2; i * i <= N; ++i) {
        if (N % i == 0) ans = false;
    }
    return ans;
}

int main() {
    int N;
    cin >> N;
    
    vector<int> a;
    int x = 11;
    while (a.size() < N) {
        if (prime(x)) a.push_back(x);
        x = x + 10;
    }
    
    for (int i = 0; i < N - 1; ++i) cout << a[i] << " ";
    cout << a[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
  string[] str=Console.ReadLine().Split(' ');
      int N=int.Parse(str[0]);
      int A=int.Parse(str[1]);
      int B=int.Parse(str[2]);
      int ans=0;
      for(int i=1;i<=N;i++){
       string Istr=i.ToString();
         int count=0;
        for(int j=0;j<Istr.Length;j++){
        count+=int.Parse(Istr.Substring(j,1));
          
        }
        if((A<=count)&&(count<=B)){
          ans+=i;
        }
      }
      Console.WriteLine(ans);
}
  }

}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    int dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
string s;
for(int i=0;i<h;i++){
    cin>>s;
    for(int j=0;j<w;j++){
        if(s[j]=='#'){
            dp[i+1][j+1]=-1;
        }
    }
}
if(dp[1][1]!=-1)dp[1][1]=1;

for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
        if(dp[i][j]!=-1&&!(i==1&&j==1)){
            int tt=0;
           
            if(dp[i][j-1]!=-1)tt+=dp[i][j-1];
            if(dp[i-1][j]!=-1)tt+=dp[i-1][j];
            dp[i][j]=(tt)%mod;
        }
    }
}

cout<<dp[h][w];
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
ull s[1000000];
ull a[100500];
int main()
{
    
    
    int n;
    ull sb=1e18;
    memset(s,0,sizeof(s));
    scanf("%d",&n);
    int flag=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            flag=0;
        }
    }   
    if(flag==0)
    {
        printf("0\n");
        return 0;
    }
    sort(a,a+n);
    int k=0;
    while(a[0])
    {
        s[k++]=a[0]%10;
        a[0]/=10;
    }   
    int flag1=1;
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<k;j++)
        {
            s[j]=s[j]*a[i];
        }
        int g=0;
        while(a[i])
        {
            a[i]/=10;
            g++;
        }
        for(int h=0;h<k+g;h++)
        {
            s[h+1]+=s[h]/10;
            s[h]%=10;
        }
        k+=g;
        while(s[k]==0)
        {
            k--;
        }
		if(k>=19){
			
			flag1=0;
			break;
		}
        k++; 
    }
    k--;
    if(flag1){
    	ull ggg=0;
    	for(k;k>=0;k--)
    	{
    		ggg=ggg*10+s[k];
		}
    	if(ggg>sb)
    	{
    		cout<<-1<<endl;
    		return 0;
		}
    	cout<<ggg<<endl;
    }else{
    	cout<<-1<<endl;
	}
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int flg=0;
    for(int i=1;i<10;i++){
        if(n%i==0&&(n/i)<10) flg=1;
    }
    if(flg==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,l,num,s,x;
int main(){
	cin>>n>>l;
	x=l-1;
	for(int i=1;i<=n;i++) x++,num+=x;
	if(x==0||l==0||(l<0&&x>=0)) cout<<num;
	else if(abs(l-s)>abs(x-s)) cout<<num-x;
	else cout<<num-l;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>
#include <ctime>
#include <numeric>
#include <cstdlib>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int H, W;
string S[500];

bool flag[500][500];

ll c[2];
ll ans;
int dx[4] = { 0, -1, 0, 1 };
int dy[4] = { 1, 0, -1, 0 };

void dfs( int x, int y ){
	flag[y][x] = false;
	REP( i, 4 ){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if( 0 > nx || nx >= W || 0 > ny || ny >= H ) continue;
		if( S[ny][nx] != S[y][x] && flag[ny][nx] ){
			if( S[ny][nx] == '#' ) c[0]++;
			if( S[ny][nx] == '.' ) c[1]++;
			dfs( nx, ny );
		}
	}
}

int main(){
	
	cin>>H>>W;
	REP( i, H ) cin>>S[i];
	
	fill( flag[0], flag[500], true );
	ans = 0;
	
	
	REP( i, H ){
		REP( j, W ){
			c[0] = c[1] = 0;
			if( S[i][j] == '#' ) c[0]++;
			if( S[i][j] == '.' ) c[1]++;
			if( flag[i][j] ) dfs( j, i );
			ans += c[0] * c[1];
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
	
}

Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	int N;
	cin >> N;
	cout << (N-2)*180 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pi pair <ll,ll>
#define vi vector <ll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define SQ(a) (a)*(a)
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>       //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll i,j,k,n,m,c,d,t,l=0,x,prev=0,max1=0,flag=0,cnt=0,y,min1,q;
    cin>>k;
    cin>>i;
    cin>>j;
    for(n=i;n<=j;n++){
        if(n%k==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;



    return 0;
}


Measured memory_bytes: 3596
import itertools

N, K = list(map(int, input().split()))
D = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
Dx = list(input().split())
for i in Dx:
	D.remove(i)

c = float("inf")
for i in range(1, 6):
	for x in itertools.product(D, repeat = i):
		z = list(x)
		while True:
			if z[0] == "0" and len(z) >= 2:
				z = z.pop(0)
			else:
				break

		y = int("".join(z))
		if N <= y and y < c:
			c = y

print(c)

Measured memory_bytes: 3064
import sys;input=sys.stdin.readline
N, = map(int, input().split())
G = [set() for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a].add(b)
    G[b].add(a)

xs = [[] for _ in range(2)]
g2 = [set() for _ in range(N+1)]
vs = set()
stack = [1]
depth = [0]*(N+1)
dfs_vs = []
vs.add(1)
while stack:
    v = stack.pop()
    xs[depth[v] % 2].append(v)
    dfs_vs.append(v)
    for u in G[v]:
        if u in vs:
            continue
        depth[u] = depth[v] + 1
        g2[v].add(u)
        stack.append(u)
        vs.add(u)

xs.sort(key=lambda x:len(x))
rs = []
if len(xs[0]) <= N//3:
    i=j=k=0
    for x in xs[0]:
        i+=1
        rs.append((x, 3*i))
    for x in xs[1]:
        if i+1 <= N//3:
            i+=1
            rs.append((x, 3*i))
        elif j <= (N-1)//3:
            rs.append((x, 3*j+1))
            j+=1
        else:
            rs.append((x, 3*k+2))
            k+=1
else:
    i=j=k=0
    for x in xs[0]:
        if j <= (N-1)//3:
            rs.append((x, 3*j+1))
            j+=1
        elif i+1 <= N//3:
            i+=1
            rs.append((x, 3*i))
    for x in xs[1]:
        if i+1 <= N//3:
            i+=1
            rs.append((x, 3*i))
        else:
            rs.append((x, 3*k+2))
            k+=1

#print(rs)
rs.sort(key=lambda x:x[0])
print(" ".join(str(x[1]) for x in rs))


Measured memory_bytes: 166136
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;

int main() {
	string a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
		a[i][0] += ('A' - 'a');
		cout << a[i][0];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
inpl = lambda: list(map(int,input().split()))
N, Z, W = inpl()
a = inpl()[::-1]
a.append(W)
X = [0]*(N+1)
Y = [10**9]*(N+1)
if N == 1:
    print(abs(W-a[0]))
    exit()
# i = 1
Xmin = Ymax = abs(a[0]-a[1])
for i in range(2,N+1):
    X = max(Ymax,abs(a[i]-a[0]))
    Y = min(Xmin,abs(a[i]-a[0]))
    Ymax = max(Ymax, Y)
    Xmin = min(Xmin, X)
print(X)

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

int main() {
  int N;
  string S;
  cin >> N;
  for (int i=0;i<N;i++){
    cin >> S;
    if (S == "Y"){
      S = "Four";
      cout << S << endl;
      break;
    }
    else{
    }
  }
  if (S == "Four"){
  }
  else{
    cout << "Three" << endl;
  }
}


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

const int N = 205, M = 50000, inf = 0x3fffffff;
int n, m, l, x, y, z, e, s, t, d[N][N], hd[N], to[M], f[M], nxt[M], ch[N];

void add(int x, int y, int z) {
	to[e] = y, nxt[e] = hd[x], f[e] = z, hd[x] = e++;
	to[e] = x, nxt[e] = hd[y], f[e] = 0, hd[y] = e++;
}

bool tell() {
	memset(ch, -1, sizeof ch);
	queue<int> q;
	ch[s] = 0;
	q.push(s);
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for(int i = hd[u]; ~i; i = nxt[i]) if(ch[to[i]] == -1 && f[i])
			ch[to[i]] = ch[u] + 1, q.push(to[i]);
	}
	return ch[t] != -1;
}

int zeng(int a, int b) {
	if(a == t) return b;
	int r = 0;
	for(int i = hd[a]; ~i && b > r; i = nxt[i]) if(ch[to[i]] == ch[a] + 1 && f[i]) {
		int t = zeng(to[i], min(b-r, f[i]));
		f[i] -= t, r += t, f[i^1] += t;
	}
	if(!r) ch[a] = -1;
	return r;
}

int dinic() {
	int r = 0, t;
	while(tell()) while(t = zeng(s, inf)) r += t;
	return r;
}

int main() {
	while(~scanf("%d%d%d", &n, &m, &l)) {
		e = 0, t = n*2+1;
		memset(d, 0x3f, sizeof d);
		memset(hd, -1, sizeof hd);
		for(int i = 1; i <= n; i++) d[i][i] = 0;
		while(m--) scanf("%d%d%d", &x, &y, &z), d[x][y] = d[y][x] = z;
		for(int k = 1; k <= n; k++)
		for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		for(int i = 1; i <= n; i++) {
			scanf("%d", &x);
			add(0, i, x);
			for(int j = 1; j <= n; j++) if(d[i][j] < l) add(i, n+j, inf);
		}
		for(int i = 1; i <= n; i++) scanf("%d", &x), add(n+i, t, x);
		printf("%d\n", dinic());
	}
	return 0;
}

Measured memory_bytes: 1456
package main

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

var sc *bufio.Scanner

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	adj := make([]map[int]struct{}, n+1)
	for i := 1; i < n+1; i++ {
		adj[i] = make(map[int]struct{}, n)
		for j := 1; j < n+1; j++ {
			if i == j {
				continue
			}
			adj[i][j] = struct{}{}
		}
	}

	m := n
	if n%2 == 1 {
		m = n - 1
	}
	for i := 1; i < m-i+1; i++ {
		delete(adj[i], m-i+1)
		delete(adj[m-i+1], i)
	}

	k := 0
	for i := 1; i < n+1; i++ {
		k += len(adj[i])
	}
	fmt.Println(k / 2)
	for i := 1; i < n+1; i++ {
		for j := range adj[i] {
			if i < j {
				fmt.Println(i, j)
			}
		}
	}
}


Measured memory_bytes: 896
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]

t = 0
x = 0
y = 0
flag = True

for i in range(N):
    t_next = P[i][0] - t
    d_next = abs(P[i][1] - x) + abs(P[i][2] - y)
    # 次までの距離より時間が短いと無理
    # または、次までの距離と時間との差が奇数なら無理（同じところにとどまれないので）
    if (t_next - d_next)%2 == 1 or t_next < d_next:
        flag = False
        break
    t = P[i][0]
    x = P[i][1]
    y = P[i][2]

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 60376
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))

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 (b < a) { a = b; return true; } return false; }

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

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

		if(s == "-")
			break;

		int m;
		cin >> m;

		REP(i, m){
			int h;
			cin >> h;

			s =  s.substr(h) + s.substr(0, h);
		}

		cout << s << endl;
	}

	return 0;
}



Measured memory_bytes: 3204
// traP is kyopuro circle
// -> true

#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
  int n,m,p;
  int d[10000];
  scanf("%d%d%d",&n,&m,&p);
  for(int i=0;i<m;i++){
    scanf("%d",&d[i]);
  }
  d[m] = p;
  m++;
  sort(d,d+m);
  int ans = 830252521;
  for(int i=0;i<m;i++){
    int x = d[i];
    int y = d[(i-1+m)%m];
    int left = 0;
    int right = 0;
    if(x<=p){
      left = (p-x);
    }else{
      left = (p-(x-n));
    }
    if(y>=p){
      right = (y-p);
    }else{
      right = (y-(p-n));
    }
    int dist = min(left,right)*2 + max(left,right);
    ans = min(ans,dist);
    // printf("x:%d, y:%d, left:%d, right:%d, dist:%d\n",x,y,left,right,dist);
  }
  printf("%d\n",ans*100);
  return 0;
}

Measured memory_bytes: 1080
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <random>

int main() {
	long long int n; std::cin >> n;
	long long int result = n * (n - 1) / 2;
	std::cout << result << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define in(i,S) ((S>>(i-1))&1)
#define ll long long
using namespace std;
int n,c0[20],c1[20],tp0,tp1;
ll f[20][20],ans;
char s[40];
int read()
{
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;	
}
int pc(int x)
{
	int r=0;
	while(x) r+=(x&1),x>>=1;
	return r;
}
int main()
{
	n=read();
	scanf("%s",s+1);
	for(int u=0;u<(1<<n);u++)
	{
		memset(f,0,sizeof(f));
		f[0][0]=1;tp0=tp1=0;
		int cnt=n-pc(u);
		for(int i=1;i<=n;i++)
			if(in(i,u)) c1[++tp1]=s[i];
			else c0[++tp0]=s[i];
		
		for(int t=1;t<=n;t++)
			for(int i=0,j;i<=cnt;i++)
			{
				j=t-i;
				if(i&&s[n*2-t+1]==c0[i]) f[i][j]+=f[i-1][j];
				if(j&&s[n*2-t+1]==c1[j]) f[i][j]+=f[i][j-1];
			}
		ans+=f[cnt][n-cnt];	
	}
	printf("%lld",ans);
	return 0;
}

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

Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	L = [[] for i in range(N)]
	for i in range(N):
		A = int(input())
		for j in range(A):
			x, y = getlist()
			x -= 1
			L[i].append([x, y])
	#print(L)

	ans = 0
	for i in range(1 << N):
		output = [0] * N
		cnt = 0
		for j in range(N):
			if ((i >> j) & 1) == 1:
				output[j] = 1
				cnt += 1
		judge = "Yes"
		for j in range(N):
			if output[j] == 1:
				for x, y in L[j]:
					if output[x] != y:
						judge = "No"
						break

		if judge == "Yes":
			ans = max(ans, cnt)
	print(ans)



if __name__ == '__main__':
	main()

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

int K;
string S;
vector<string> VS;
set<string> st;

int main(void){
    // Your code here!
    cin >> S >> K;
    
    int length = K;
    for(int i = 1; i <= length; i++){
        for(int left =0; left < S.size() - i + 1; left++){
            VS.push_back(S.substr(left, i));
        }
    }
    
    for(int i = 0; i < VS.size(); i++) {
        st.insert(VS[i]);
    }
    
    int idx = 0;
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        if(idx==K-1) cout << *itr << endl;
        idx++;
    }
}


Measured memory_bytes: 2300
#include<iostream>
#include<iomanip>
#include<math.h>

#define PI M_PI

using namespace std;

int main()
{

    double a,b,c;

    cin>>a>>b>>c;

    cout<<fixed<<setprecision(5)<<
    a*b*sin(c*PI/180)/2<<endl<<
    a+b+sqrt(a*a+b*b-2*a*b*cos(c*PI/180))<<endl<<
    b*sin(c*PI/180)<<endl;

    return 0;
}



Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	private static final String[] reversedWords = {"dream", "dreamer", "erase", "eraser"};

	public static void main(String[] args) {
		String s;
		try (Scanner scanner = new Scanner(System.in)) {
			s = scanner.next();
		}

		boolean canObtain = s.replaceAll("eraser",  "")
				.replaceAll("erase",   "")
				.replaceAll("dreamer", "")
				.replaceAll("dream",   "")
				.isEmpty();

		if (canObtain) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

distance = [0]*n

for i in range(n-1):
  distance[i] = a[i+1] - a[i]
distance[n-1] = k-a[n-1] + a[0]

distance.sort(reverse=True)
print(sum(distance[1:]))

Measured memory_bytes: 26444
#include<iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    int a[N];
    for(int i=0; i<N; i++) cin >> a[i];

    sort(a, a+N, greater<int>());
    
    int Alice=0;
    int Bob=0;
    for(int i=0; i<N; i+=2){
        Alice += a[i];
        Bob += a[i+1];
    }
    cout << abs(Alice - Bob);

}

Measured memory_bytes: 504
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication21
{
	class Program
	{
		static void Main(string[] args)
		{
			int a = int.Parse(Console.ReadLine());
			string b = Console.ReadLine();
			if (a >= 3200)
				Console.WriteLine(b);
			else
				Console.WriteLine("red");

		}
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
using ll = long long;
using namespace std;
constexpr ll INF = 1LL << 60;

ll n, r;

int main() {
	cin >> n >> r;
	ll ans = 0;
	ll un = 1;
	while (n >= un) {
		un *= r;
		++ans;
	}
	cout << ans;
	return 0;
}

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

int main(){
  int n,l,a[1000];
  cin>>n>>l;
  for(int i=1;i<=n;i++){
    a[i]=l+i-1;
  }
  int nu=0;
  for(int i=1;i<=n;i++){
    nu+=a[i];
  }
  int ma=100000000;
  for(int i=1;i<=n;i++){
    int t=nu-a[i];
    if(abs(t-nu)<abs(ma-nu)){
      ma=t;
    }
  }
  cout<<ma<<endl;
}
       
     
       
       
       
 


Measured memory_bytes: 256
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

dp = [[10**10] * (H + 1) for _ in range(N+1)]

for i in range(1, N+1):
    for h in range(1, H+1):
        if h - A[i-1] <= 0:
            dp[i][h] = min(dp[i-1][h], B[i-1])
        else:
            dp[i][h] = min(dp[i-1][h], dp[i][h-A[i-1]] + B[i-1])

print(dp[-1][-1])


Measured memory_bytes: 120428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	ll N;
	cin >> N;
	FOR(h, 3501, 1)
	{
		FOR(n, 3501, 1)
		{
			ll nhN = n*h*N;
			ll c = 4 * h*n - N*(h + n);
			if (c <= 0)continue;
			if (nhN%c == 0) {
				cout << h << " " << n << " " << nhN / c << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
K = int(input())
rem_set = set()
rem = 7%K
i = 1
while True:
    if rem == 0:
        print(i)
        break
    if rem in rem_set:
        print(-1)
        break
    i += 1
    rem_set.add(rem)
    rem = (rem*10 + 7)%K

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

int num = 0;

int main(){
    char c;
    for(int i = 0; i < 4; i++){
        cin >> c;
        if(c == '+'){
            num++;
        }else{
            num--;
        }
    }

    cout << num << endl;

    return 0;
}

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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 998244353;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e6 + 2;


const int maxn = NN;
int fact[maxn], inv[maxn], invFact[maxn];

int ncr(int n, int r){
    if(n < 0 || r < 0 || n < r) return 0;

    int v = (invFact[r] * invFact[n-r]) %mod;
    return (v*fact[n])%mod;
}

void pre(){
    int i;
    fact[0] = fact[1] = 1;
    for(i = 2; i < maxn; i++) {
        fact[i] = (fact[i-1]*i)%mod;
    }

    inv[0] = 0;
    inv[1] = 1;
    for (i = 2; i < maxn; i++) {
        inv[i] = mod - ((int) (mod / i) * inv[mod % i] % mod);
    }

    invFact[0] = 1;
    for (i = 1; i < maxn; i++) {
        invFact[i] = (inv[i] * invFact[i - 1] % mod);
    }
}

vi pows(NN);
void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0, ans = 0; 
      pre();
      cin >> n >> m >> k;
      pows[0] = 1;
      for(i = 1; i <= n; i++) {
            pows[i] = pows[i -1 ] * (m - 1) % mod;
      }

      for(i = 0; i <= k; i++) {
            int t = pows[n - 1 - i] * m % mod;
            t = t * ncr(n - 1, i) % mod;
            ans = (ans + t) % mod;
      }

      cout << ans << el;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

Measured memory_bytes: 34520
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int N;
	while (cin >> N, N) {
		bool f = false;
		int ans = 0;
		for (int i = 0; i < N; ++i) {
			int k; cin >> k;
			if (k >= 2) {
				f = true;
				++ans;
			}
			else ans += k;
		}
		if (f) cout << (ans + 1) << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <math.h>
int main(void){
	double x,h,S;
	while(scanf("%lf %lf",&x,&h)){
		if(x==0 && h==0) break;
		S=x*x+2*x*sqrt(h*h+x*x/4);
		printf("%f\n",S);
	}
	return 0;
}

Measured memory_bytes: 1072
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>

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

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    int X[5];
    rep(i, 5){
        cin >> X[i];
        if(X[i]==0) cout << to_string((i+1)) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;
int gcd(int a,int b){
   if(b == 0) return a;
   return gcd(b, a % b);
}

int main(){
   int n;
   cin>>n;
   vector<int> a(n+2);
   for(int i=0;i<n;i++){
      cin>>a[i];
   }
   int ans=gcd(a[0],a[1]);
   for(int i=2;i<n;i++){
      ans=gcd(ans,a[i]);
   }
   
   cout<<ans<<endl;
   

}

Measured memory_bytes: 640
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def size(self, x):
        return -self.parents[self.find(x)]

N,M=map(int,input().split())
uf=UnionFind(N)
for i in range(M):
  A,B=map(int,input().split())
  uf.unite(A-1,B-1)

ans=0
for i in range(N):
  ans=max(ans,uf.size(i))
  
print(ans)

Measured memory_bytes: 14396
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; --i)
#define rep(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using arr = vector<ll>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
constexpr int MAX = 100010;
ll x, y;

int main()
{

  cin >> x >> y;
  if (abs(x - y) <= 1) {
    cout << "Brown";
  } else {
    cout << "Alice";
  }
  return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
//#include <vector> 

int main(int argc, char* argv[])
{
	char str[4] = {0};
    scanf("%s", str);

	long a[3];
	a[0] = (str[0] - '0');
	a[1] = (str[1] - '0');
	a[2] = (str[2] - '0');

	long aa = a[0] * 100 + a[1] * 10 + a[2];
	long bb = a[0] * 111;

	if(bb>=aa) {
		printf("%d\n", bb);
	}
	else if (a[0] < 9) {
		printf("%d\n", (a[0]+1)*111);
	}
	else {
		printf("1111\n");
	}

    return 0;
}


Measured memory_bytes: 128
import sys
n,m=map(int,input().split())
if m > 0:
  a = set(map(int, sys.stdin))
else:
  a = set()

fibo=[0]*(n+1)
fibo[0]=1
fibo[1]=1 if 1 not in a else 0
mod=10**9+7
for i in range(2,n+1):
  if i in a:
    continue
  fibo[i]=(fibo[i-2]+fibo[i-1])%mod

print(fibo[-1])

Measured memory_bytes: 11884
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
for i in range(N-1,-1,-1) :
    num = i+1
    cnt = 0
    for j in range(i+num,N,num) :
        cnt += B[j]
    if A[i] == 0 and cnt % 2 == 1 :
        B[i] = 1
    elif A[i] == 1 and cnt % 2 == 0 :
        B[i] = 1
print(sum(B))
for i,b in enumerate(B) :
    if b == 1 :
        print(i+1)

Measured memory_bytes: 7100
#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)   _for (__VA_ARGS__)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  string s;
  cin >> s;

  auto ans = s [2] == s[3] && s[4] == s[5];
  cout << (ans ? "Yes" : "No") << endl;
}


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

long long int find(long long int a, long long int b) {
    for (int i=1; i<b+1; i++) {
        if ((a*i)%b==0) {
            return a*i;
        }
    }
}

int main(void) {
    long long int a, b;
    cin >> a >> b;
    cout << find(a,b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef long long ll;

int main() {
	fast;
	int n;
	cin >> n;
	if (n >= 30) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}



















Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,m;
  cin>>n>>m;
  int data[50][50];
  int p[50][50];
  int root[50][2];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      data[i][j]=0;
      p[i][j]=0;
    }
  }
  for(int i=0;i<m;i++){
    cin>>root[i][0]>>root[i][1];
    data[root[i][0]-1][root[i][1]-1]=1;
    data[root[i][1]-1][root[i][0]-1]=1;
    
    p[root[i][0]-1][root[i][1]-1]=1;
    p[root[i][1]-1][root[i][0]-1]=1;
  }
  int count=0;
  for(int i=0;i<m;i++){
    data[root[i][0]-1][root[i][1]-1]=0;
    data[root[i][1]-1][root[i][0]-1]=0;
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        for(int l=0;l<n;l++){
          if(data[k][j]==1 && data[j][l]==1){
            data[k][l]=1;
            data[l][k]=1;
          }
        }
      }
    }
    bool check=true;
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        if(j==k)continue;
        if(data[j][k]==0 && check){
          count++;
          check=false;
        }
        data[j][k]=p[j][k];
      } 
    }
  }
  cout<<count<<endl;
  return 0;
}

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

int main() {
	long long N, M, AC = 0, WA = 0;
	map<long long, long long> mpA;
	map<long long, bool> mpB;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		long long P;
		string S;
		cin >> P >> S;
		if (S == "AC") {
			if (!mpB[P]) AC++, WA += mpA[P], mpB[P] = true;
		}
		else {
			if (!mpB[P]) mpA[P]++;
		}
	}
	cout << AC << " " << WA << endl;
}

Measured memory_bytes: 12800
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<stack>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007

typedef long long ll;

using namespace std;


int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
int gcd(int x, int y)
{
    if(x%y==0)return y;
    else if(y%x==0)return x;
    else return gcd(x%y,y%x);
}
ll gcd(ll x, ll y)
{
    if(x%y==0)return y;
    else if(y%x==0)return x;
    else return gcd(x%y,y%x);
}
//AGC018B
int main()
{
    ll n,m,q,r=0,ans=0;
    cin >> n >> m;
    map<ll,ll> M;
    M[0]=1;
    rep(i,n)
    {
        cin >> q;
        r=(r+q)%m;
        ans+=M[r]++;
    }
    W(ans)
    return 0;
}

Measured memory_bytes: 4224
S = input()
S_rev = S[::-1]
N = len(S)
s_bef = S[:int((N-1)/2)]
s_bef_rev = s_bef[::-1]
s_aft = S[int((N+2)/2):]
s_aft_rev = s_aft[::-1]
if (S==S_rev)and(s_bef==s_bef_rev)and(s_aft==s_aft_rev):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N = int(input())
a_list = list(map(int, input().split()))

odd_sum = [0]
even_sum = [0]

for i in range(N):
    if i % 2 == 0:
        odd_sum.append(odd_sum[-1] + a_list[i])
        even_sum.append(even_sum[-1] - a_list[i])
    else:
        odd_sum.append(odd_sum[-1] - a_list[i])
        even_sum.append(even_sum[-1] + a_list[i])

ans = []
for i in range(N):
    a = a_list[i]

    if i % 2 == 0:
        a += (odd_sum[-1] - odd_sum[i + 1])
        a += even_sum[i]
    else:
        a += (even_sum[-1] - even_sum[i + 1])
        a += odd_sum[i]
    print(a)


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

struct Drink
{
    long long money;
    long long number;

    Drink( long long m, long long n )
    {
        money  = m;
        number = n;
    }

    bool operator<(const Drink &another ) const
    {
        return money < another.money;
    }
};

int main()
{
    int N, M;
    cin >> N >> M;

    vector<Drink> drink;

    // データ格納
    for( int i=0 ; i<N ; i++ )
    {
        int money, number;
        cin >> money >> number;
        drink.push_back( Drink( money, number ) );
    }

    // データソート
    sort( drink.begin(), drink.end() );

    int count = 0;
    long long money = 0;

    for( int i=0 ; i<N ; i++ )
    {
        for( auto itr : drink )
        {
            for( int j=0 ; j < itr.number ; j++ )
            {
                money += itr.money;
                count++;
                if( M == count ) goto RESULT;
            }
        }
    }

RESULT:
    cout << money << endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>

using namespace std;


int main()
{
	int N, a[100000], d, s = 0, b[100000] = {};
		cin >> N;
		for (int i = 0; i < N; i++) {
			cin >> a[i];
		}
		if (a[0] == 2) {
			cout << 1 << endl;
		}
		else {
			d = a[0]-1;
			while(a[d] != 2) {
				d = a[d]-1;
				s++;
				b[a[d] - 1] += 1;
				if(b[a[d] - 1]==2){
					break;
				}
			}
			if (b[a[d] - 1] == 2) {
				cout << -1 << endl;
			}
			else {
				cout << s + 2 << endl;
			}
		}
	return 0;
}


Measured memory_bytes: 1024
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a)+min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1]+b[y-1]-c)

print(ans)


Measured memory_bytes: 70892
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

typedef long long ll ; 
typedef long double ld ; 
typedef pair<int,int> pii ; 
typedef pair<ll,ll> pll ;

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}
ll sq(int x) { ll ans = x*x ; return ans ; }
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void read(vt<int> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}
void read(vt<ld> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}

bool prime(ll t) {
	for(ll i  =2 ; i*i <= t ; ++i) {
		if(t%i==0) 
			return 0 ; 
	}
	return 1 ; 
}

// ==========Start Here==============

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	ll a, b ; 
	cin >> a >> b ; 
	ll hcf = gcd(a,b) ;
	//cout << hcf << endl ;
	vt<ll> tmp;  
	int ans = 0 ; 
	for(ll i = 1 ; i*i <= hcf ; ++i) {
		if(hcf%i == 0) {
			if(prime(i))
				ans++;
			if( i != hcf/i && prime(hcf/i))
				ans++ ; 
		}
	}
	
 	cout << ans ; 
 	return 0 ; 
 	
}

Measured memory_bytes: 3624
import copy
H,W,K= map(int,input().split())
c =[]
shape_count=0
count=0
ans_count=0
for i in range(H):
    c.append(list(input()))
    shape_count+=c[i].count("#")
ans_c = copy.deepcopy(c)
for i in range(2 ** H):
    for k in range(2 ** W):
        for j in range(H):
            if((i >> j) & 1):
                for test in range(W):
                    if(c[j][test]=="#"):
                        count+=1
                        c[j][test] = "."
        for l in range(W):
            if((k >> l) & 1):
                for test1 in range(H):
                    if(c[test1][l]=="#"):
                        count+=1
                        c[test1][l] = "."

        if(shape_count-count==K):
            ans_count+=1
        c = copy.deepcopy(ans_c)
        count=0        
print(ans_count)



Measured memory_bytes: 9320
//	-*- mode: C++ -*-
// Exhaustive Search
//	 Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.
//
//	 You are given the sequence A and q questions where each question contains Mi.
//
// Input
//	 In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.
//
// Output
//	 For each question Mi, print yes or no.

// Constraints
//	 n ≤ 20
//	 q ≤ 200
//	 1 ≤ elements in A ≤ 2000
//	 1 ≤ Mi ≤ 2000
// Sample Input 1
//	 5
//	 1 5 7 10 21
//	 8
//	 2 4 17 8 22 21 100 35
// Sample Output 1
//	 no
//	 no
//	 yes
//	 yes
//	 yes
//	 yes
//	 no
//	 no

#include <iostream>
#include <vector>

class CA
{
public:
	CA(){}
	~CA(){}
	void ExhaustiveSearch(void);

private:
	unsigned int	n	{0};
	unsigned int	q	{0};
	std::vector<unsigned int>	A	{};
	std::vector<unsigned int>	M	{};

	bool	solve(const unsigned int	p,
				  const unsigned int	t);
};

void	CA::ExhaustiveSearch(void)
{

	std::cin >> n;

	for(unsigned int i = 0; i < n; i++){
		unsigned int	Ai	{0};
		std::cin >> Ai;
		A.push_back(Ai);
	}

	std::cin >> q;

	for(unsigned int i = 0; i < q; i++){
		unsigned int	Mi	{0};
		std::cin >> Mi;
		M.push_back(Mi);
	}

	for(unsigned int i = 0; i < q; i++){
		if(solve(0, M[i])){
			std::cout << "yes" << std::endl;
		}
		else{
			std::cout << "no" << std::endl;
		}
	}
}

bool	CA::solve(const unsigned int	p,
				  const unsigned int	t)
{
	if(t == 0){
		return	true;
	}

	if(p >= n){
		return	false;
	}

	bool	res	= solve(p + 1, t) || solve(p + 1, t - A[p]);

	return	res;
}

int	main(int	argc,
		 char*	argv[])
{
	CA	a;

	a.ExhaustiveSearch();

	return 0;
}



Measured memory_bytes: 3144
#include <iostream>

using namespace std;

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

    uint64_t ans = 0;

    for(int i=1;i<=n;i++){
        if((i%3 == 0) ||
           (i%5 == 0)){
            continue;
        }

        ans += i;
    }

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


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 114514
int main(){
    string H="2019/04/30";
    string hoge;
    cin>>hoge;
    if(hoge<=H)cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
}

Measured memory_bytes: 256
/*
Owner: dxxrk
Problem: ROT N
Date: 24/11/2019
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	
	for(long long i = 0; i < s.size(); i++){
		char c = s[i];
		if(int(c + n) > int('Z')){
			c = int('A') + int(c + n - int('Z')) - 1;
		}
		else {
			c = int(c) + n;
		}
		s[i] = char(c);
	}
	
	cout << s;
	
	
	return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int) x.size())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define makeunique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define endl '\n'

typedef pair<int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<string> vs;

template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }

const double pi = acos(-1.);
const int inf = 1e9 + 7;
const int N = 3e5 + 17;

int n, m;
vi g[N];

void dfs(int v, vi& d, vi& fp, int p = -1) {
	for (auto x : g[v])
		if (x != p) {
			d[x] = d[v] + 1;
			fp[x] = fp[v];
			dfs(x, d, fp, v);	 
	    }
}

int solve(int root) {
    vi d(n), fp(n);
	for (auto x: g[root]) {
		d[x] = 1; fp[x] = x;
		dfs(x, d, fp, root);
	}

	vi mi(n, -inf);
	for (int i = 0; i < n; i++)
		if (i != root)
			mi[fp[i]] = max(mi[fp[i]], d[i]);
	int t = inf;

	for (int i = 0; i < n; i++)
		if (mi[i] != -inf)
			t = min(t, mi[i]);		
	int ans = 0;
	if (m & 1) {
		vi tmp(n);
		for (int i = 0; i < n; i++) {
			if (i == root) continue; 
			if (d[i] > m / 2) ans++;
			if (d[i] == m / 2 + 1) tmp[fp[i]]++;
		}
		ans -= *max_element(all(tmp));
	} else {
		for (int i = 0; i < n; i++)
			if (d[i] > m / 2) ans++;
	}
	re ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n - 1; i++) {
		int x, y; cin >> x >> y;
		g[--x].pb(--y);
		g[y].pb(x);
	}
	int ans = inf;
	for (int i = 0; i < n; i++) {
	    //cout << i + 1 << " " << solve(i) << endl;
		ans = min(ans, solve(i));
	}
	cout << ans;
}


Measured memory_bytes: 10936
#include<bits/stdc++.h>
#define LL long long
#define inf 0x3fffffff
using namespace std;
 
int m,d;
 
int main()
{
    cin>>m>>d;
    int ans=0;
    for (int i=1;i<=m;i++)
        for (int j=10;j<=d;j++)
            if ((j%10)*(j/10)==i&&j%10>=2&&j/10>=2) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

LL a[100005];

int main(){
	int n;
	LL mi = 2,ma = 2,aa,bb;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = n;i >= 1;i--){
		if(mi % a[i] != 0){
			mi = a[i] * (mi / a[i] + 1);
		}
		ma = a[i] * (ma / a[i] + 1) - 1;
	}
	bool flag = true;
	aa = mi,bb = ma;
	for(int i = 1;i <= n;i++){
		aa = aa - aa % a[i];
		bb = bb - bb % a[i];
	}
	if(aa != 2 && bb != 2) cout << "-1";
	else cout << mi << ' ' << ma;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int X, T;
    cin >> T >> X;
    cout << static_cast<double>(T) / X << endl;

    return 0;
}

Measured memory_bytes: 384