akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(50000)

def findset(x,element,weight):
    if(x != element[x]):
        element[x],s = findset(element[x],element,weight)
        weight[x] += s
    return element[x],weight[x]

def union(x,y,element,weight,w):
    x,wx = findset(x,element,weight)
    y,wy = findset(y,element,weight)
    link(x,wx,y,wy,w,element)
def link(x,wx,y,wy,z,element):
    z = z+wy-wx

    element[x] = y
    weight[x] = z

n,q = map(int, input().split());

element = [i for i in range(n)]
weight = [0 for i in range(n)]

for i in range(q):
    inp = map(int, input().split());
    inp = list(inp)    
    if(inp[0] == 0):
        x,y,w = inp[1],inp[2],inp[3]
        union(x,y,element,weight,w)
    else:
        x,y = inp[1],inp[2]
        x,wx = findset(x,element,weight)
        y,wy = findset(y,element,weight)
        if(x == y):
            print(wx-wy)
        else:
            print('?')



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

const int N = 1e5 + 123; 
int n, dp[N][5];
int main() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a;
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b;
        dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]) + c;
    }
    cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int sai[6][6] = { {0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0} };
int sai2[6], sai3[6], cnt[8], n, a, b, cx, cy, T1, takasa[600][600], men[600][600], L = 1, R = 2, F = 3, B = 4;
void p() { for (int i = 0; i < 6; i++) { sai2[i] = sai3[i]; } }
void LEFT() { sai3[3] = sai2[0]; sai3[1] = sai2[1]; sai3[0] = sai2[2]; sai3[5] = sai2[3]; sai3[4] = sai2[4]; sai3[2] = sai2[5]; p(); cx--; }
void RIGHT() { sai3[2] = sai2[0]; sai3[1] = sai2[1]; sai3[5] = sai2[2]; sai3[0] = sai2[3]; sai3[4] = sai2[4]; sai3[3] = sai2[5]; p(); cx++; }
void FRONT() { sai3[4] = sai2[0]; sai3[0] = sai2[1]; sai3[2] = sai2[2]; sai3[3] = sai2[3]; sai3[5] = sai2[4]; sai3[1] = sai2[5]; p(); cy--; }
void BACK() { sai3[1] = sai2[0]; sai3[5] = sai2[1]; sai3[2] = sai2[2]; sai3[3] = sai2[3]; sai3[0] = sai2[4]; sai3[4] = sai2[5]; p(); cy++; }
int main() {
	while (true) {
		for (int i = 0; i < 360000; i++) { takasa[i / 600][i % 600] = 0; men[i / 600][i % 600] = 0; sai2[i % 6] = 0; cnt[i % 8] = 0; }
		cin >> n; if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a >> b; sai2[0] = a; sai2[1] = b; sai2[2] = sai[a - 1][b - 1];
			sai2[3] = 7 - sai[a - 1][b - 1];sai2[4] = 7 - b;sai2[5] = 7 - a;
			cx = 300, cy = 300; vector<pair<int, int>>dice;
			while (true) {
				if (sai2[3] >= 4 && takasa[cy][cx] > takasa[cy][cx - 1]) { dice.push_back(make_pair(sai2[3], L)); }
				if (sai2[2] >= 4 && takasa[cy][cx] > takasa[cy][cx + 1]) { dice.push_back(make_pair(sai2[2], R)); }
				if (sai2[4] >= 4 && takasa[cy][cx] > takasa[cy - 1][cx]) { dice.push_back(make_pair(sai2[4], F)); }
				if (sai2[1] >= 4 && takasa[cy][cx] > takasa[cy + 1][cx]) { dice.push_back(make_pair(sai2[1], B)); }
				sort(dice.begin(), dice.end()); if (dice.size() >= 1) { T1 = dice[dice.size() - 1].second; }
				if (dice.size() == 0) { takasa[cy][cx]++; men[cy][cx] = sai2[0]; break; }
				if (T1 == 1) { LEFT(); }if (T1 == 2) { RIGHT(); }
				if (T1 == 3) { FRONT(); }if (T1 == 4) { BACK(); } dice.clear();
			}
		}
		for (int i = 0; i < 360000; i++) { cnt[men[i / 600][i % 600]]++; }
		cout << cnt[1] << ' ' << cnt[2] << ' ' << cnt[3] << ' ' << cnt[4] << ' ' << cnt[5] << ' ' << cnt[6] << endl;
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<char> C(N);
  for (int i = 0; i < N; i++) cin >> C.at(i);
  
  int r = 0;
  for (int i = 0; i < N; i++) {
    if (C.at(i) == 'R') r++;
  }
  int ans = 0;
  for (int i = 0; i < r; i++) {
    if (C.at(i) == 'W') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;


int main() {
    int n, m, ss;
    cin >> n >> m;
    vector<int> k(m);
    vector<vector<int> > s(m);
    for (int i=0;i<m;i++) {
        cin >> k[i];
        for (int j=0;j<k[i];j++) {
            cin >> ss;
            s[i].push_back(ss-1);
        }
    }
    vector<int> p(m);
    for (int i=0;i<m;i++) {
        cin >> p[i];
    }

    int answer = 0;
    int smax = (1<<n);
    for (int i=0;i<smax;i++) {
        bool isAll = true;
        for (int j=0;j<m;j++) {
            int qq = 0;
            for (int q=0;q<k[j];q++) {
                if (i & (1<<(s[j][q]))) {
                    qq++;
                }
            }
            if (qq % 2 != p[j]) {
                isAll = false;
                break;
            }
        }
        if (isAll) {
            answer ++;
        }
    }

    cout << ( answer ) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		double a[]=new double[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextDouble();
		}
		double dp[][]=new double[n+1][n+1];
		dp[0][0]=1;
		double count=0;
		for(int h=0;h<=n;h++)
		for(int t=0;t<=n;t++){
			if(h+t>n)
			continue;
			if(h>0){
				dp[h][t]+=dp[h-1][t]*a[h+t-1];
			}
			if(t>0){
				dp[h][t]+=dp[h][t-1]*(1-a[h+t-1]);
			}
			if(h+t==n&&h>t){
				//pw.println(h+" "+t+" "+dp[h][t]);
				count+=dp[h][t];
			}
		}
		System.out.println(count);

	}
}


Measured memory_bytes: 123036
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  int k = (n + x - 1) / x;
  cout << t * k << endl;
  return 0;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n, l;
    cin >> n >> l;
    int sum = 0;
    sum = ((l + l + (n - 1)) * n) / 2;
    if(l * (l + n - 1) <= 0){
        cout << sum << endl;
    }
    else if(l < 0){
        cout << sum - (l + n - 1) << endl;
    }
    else{
        cout << sum - l << endl;
    }
}



Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;



int main(int argc, char const *argv[])
{
	int n;
	LL a[100];
	cin >> n;
	a[0] =2;a[1] = 1;
	for(int i=2; i <=n; i++){
		a[i] = a[i-1] + a[i-2];
	}
	cout << a[n]<< endl;
	return 0;
}


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

int  map[100][100];
bool visited[100][100];
int  w,h;
int  xs,ys;
int  xg,yg;
int  n;

int dfs(int x,int y) {
	static int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
	if(x==xg&&y==yg) return 1;
	visited[x][y]=true;
	for(int i=0;i<4;i++) {
		int nx=x+dx[i],ny=y+dy[i];
		if(0<=nx&&nx<w&&0<=ny&&ny<h&&map[x][y]==map[nx][ny]&&!visited[nx][ny]) {
			if(dfs(nx,ny)) return 1;
		}
	}
	return 0;
}

int main() {
	int c,d,x,y;

	while(1) {
		memset(map,0,sizeof(map));
		memset(visited,0,sizeof(visited));
		scanf("%d %d",&w,&h);
		if(w==0&&h==0) break;
		scanf("%d %d",&xs,&ys);xs--;ys--;
		scanf("%d %d",&xg,&yg);xg--;yg--;
		scanf("%d",&n);
		for(int i=0;i<n;i++) {
			scanf("%d %d %d %d",&c,&d,&x,&y);x--;y--;
			int X,Y;
			if(d==1) {
				X=2;Y=4;
			}else {
				X=4;Y=2;
			}
			for(int j=0;j<X;j++) {
				for(int k=0;k<Y;k++) {
					map[x+j][y+k]=c;
				}
			}
		}
		printf("%s\n",dfs(xs,ys)?"OK":"NG");
	}
}

Measured memory_bytes: 1076
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;
using ll = long long;

int main(){ 
        ll n,m,p[100011],y[100011];
        cin >> n >> m;
        vector<ll> pd[100001];
        for(ll i=0;i<m;i++){
                cin >> p[i] >> y[i];
                pd[p[i]].push_back(y[i]);
        }
        for(ll i=0;i<n;i++)     sort(pd[i+1].begin(),pd[i+1].end());
        for(ll i=0;i<m;i++){
                printf("%012lld\n",p[i]*1000000+1+int(lower_bound(pd[p[i]].begin(),pd[p[i]].end(),y[i])-pd[p[i]].begin()));
        }
        return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


        
    int n;
    cin>>n;

    vl v1(n+1),v(n);    

    forn(i,0,n+1)
    {
        cin>>v1[i];
    }


    forn(i,0,n)
    {
        cin>>v[i];
    }

    ll ans = 0;
    forn(i,0,n)
    {
        if(v1[i] <= v[i])
        {
            ans += v1[i];
            v[i] -= v1[i];
            v1[i] = 0;
        }
        else
        {
            ans += v[i];
            v1[i] -= v[i];
            v[i] = 0;
        }
        // cout<<ans<<" ";
        if(v1[i+1] <= v[i])
        {
            ans += v1[i+1];
            v[i] -= v1[i+1];
            v1[i+1] = 0;
        }
        else
        {
            ans += v[i];
            v1[i+1] -= v[i];
            v[i] = 0;
        }

        // cout<<ans<<" ";
    }

    cout<<ans;







    return 0;
}

Measured memory_bytes: 1792
s = list(str(input()))
list_s = []
_s = s[0]
cnt = 1
for x in s[1:]:
    if x == _s:
        cnt += 1
    else:
        list_s += [cnt]
        _s = x
        cnt = 1
list_s += [cnt]

proc = 0
frg = 0
ans = [0]*(len(s)+1)
for x2 in list_s:
    if frg == 0:
        proc += x2
        ans[proc] += (x2+1)//2
        ans[proc+1] += x2-((x2+1)//2)
        frg = 1
    else:
        ans[proc] += x2 - ((x2+1)//2)
        ans[proc+1] += (x2+1)//2
        proc += x2
        frg = 0

print(' '.join(map(str, ans[1:])))


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

const int maxN = 1000 + 5;
int order[maxN][maxN];
int opponent[maxN];
int newOpponent[maxN];
int idx[maxN];

signed main() {
  int n = read();
  vi que;
  REP(i, n) {
    REP(j, n - 1) order[i][j] = read();
    opponent[i + 1] = order[i][0];
    newOpponent[i + 1] = order[i][0];
  }
  int btlCnt = 0, total = n * (n - 1) / 2;
  bool isBattle = false;
  int ans = 0;
  while (btlCnt < total) {
    isBattle = false;
    for (int i = 1; i <= n; i++) {
      if (i == opponent[opponent[i]]) {
        newOpponent[i] = order[i - 1][++idx[i]];
        newOpponent[opponent[i]] = order[opponent[i] - 1][++idx[opponent[i]]];
        opponent[i] = 0;
        opponent[opponent[i]] = 0;
        isBattle = true;
        btlCnt++;
      }
    }
    if (isBattle == false) {
      print(-1);
      return 0;
    }
    ans++;
    FOR(i, 1, n + 1) opponent[i] = newOpponent[i];
  }
  print(ans);
}


Measured memory_bytes: 8448
<?php
$str = trim(fgets(STDIN));

$len = strlen($str);
$p = 0;
while($p < $len){
  if(substr($str, $p, 8) != 'dreamera' && substr($str, $p, 7) == 'dreamer'){
    $p+=7;
  }elseif(substr($str, $p, 5) == 'dream'){
    $p+=5;
  }elseif(substr($str, $p, 6) == 'eraser'){
    $p+=6;
  }elseif(substr($str, $p, 5) == 'erase'){
    $p+=5;
  }else{
    echo "NO";
    exit;
  }
}
echo "YES";


Measured memory_bytes: 4732
import java.util.*;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		long A = Long.parseLong(tokens[0]);
		long B = Long.parseLong(tokens[1]);
		long gcd = gcd(A, B);
		Set<Long> set = func(gcd);
		System.out.println(set.size());
	}

	static Set<Long> func(long value) {
		Set<Long> result = new HashSet<>();
		if (value == 1L) {
			result.add(1L);
			return result;
		}
		if (isPrime(value)) {
			result.add(value);
			result.add(1L);
			return result;
		}
		long v = 2;
		boolean flag = false;
		for (; v < Math.sqrt(value) + 1; v++) {
			if (value % v == 0) {
				flag = true;
				break;
			}
		}
		if (flag) {
			result.add(v);
			result.addAll(func(value / v));
			return result;
		} else {
			result.add(1L);
			result.add(value);
			return result;
		}
	}

	static long gcd(long large, long small) {
		if (small > large) {
			return gcd(small, large);
		}
		if (large % small == 0) {
			return small;
		}
		return gcd(small, large % small);
	}

	static boolean isPrime(long val) {
		if (val == 2) {
			return true;
		}
		if ((val > 2) && val % 2 == 0) {
			return false;
		}
		long s = 0;
		long t = val - 1;
		while (t % 2 == 0) {
			s += 1;
			t = t >> 1;
		}
		long a = (long) (Math.random() * (val - 1));
		if (a < 1) {
			a = 1L;
		}
		if ((long) Math.pow(a, t) % val == 1) {
			return true;
		}
		for (long i = 0; i < s; ++i) {
			if (Math.pow(a, i) * t % val == (val - 1)) {
				return true;
			}
		}
		return false;
	}

}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int n;
double L[10][10];
float total = 0;
void dfs (vector<bool> visited,float sum,int i){
    bool all_visited = true;
    for (int j = 0; j < n; j++)
    {
        if(!visited[j]) all_visited = false;
    }
    
    if(all_visited) total += sum;
    else{
        visited[i] = true;
        for (int j = 0; j < n; j++)
        {
            if(!visited[j]){
                sum += L[i][j];
                dfs(visited,sum,j);
            }
        }
        
    }
}
int main(){
    cin >>  n;
    vector<int> x(n),y(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] ;
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            L[i][j] = L[j][i] = sqrt((x[i] - x[j])*(x[i] - x[j])+(y[i] - y[j])*(y[i] - y[j]));
        }
        
    }
    double sum = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if(i != j)
            sum += L[i][j];
        }
    }
    cout << fixed<<setprecision(10)<< sum/n << endl;
    
    
    
    

}

Measured memory_bytes: 3808
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(std::string s, long long K) {
  ll kTmp = K;
  ll ss = s.length();
  vector<char> ans(ss);

  ll i;
  for (i = 0; i < ss; i++) {
    char c = s[i];

    // aに出来るか
    if (c != 'a' && 'z' + 1 - c <= kTmp) {
      kTmp -= 'z' + 1 - c;
      ans[i] = 'a';
    } else {
      ans[i] = c;
    }

    if (kTmp <= 0) {
      break;
    }
  }

  // rest
  for (ll j = i + 1; j < ss; j++) {
    ans[j] = s[j];
  }

  if (kTmp > 0) {
    ans[ss - 1] = 'a' + (ans[ss - 1] - 'a' + kTmp) % 26;
  }

  rep(i, ss) { cout << ans[i]; }
  cout << endl;
}

int main() {
  std::string s;
  std::cin >> s;
  long long K;
  scanf("%lld", &K);
  solve(s, K);
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

class Main {
  public static void main(String args[]) {
    
    HashMap<String, Integer> weeks = new HashMap<String, Integer>();
    weeks.put("SUN", 7);
    weeks.put("MON", 6);
    weeks.put("TUE", 5);
    weeks.put("WED", 4);
    weeks.put("THU", 3);
    weeks.put("FRI", 2);
    weeks.put("SAT", 1);
    
    Scanner scanner = new Scanner(System.in);
    String today = scanner.next();
    System.out.println(weeks.get(today));
  }
}

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

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	string s="ACL";
	for(int i=0; i<n; ++i)
		cout << s;
}


Measured memory_bytes: 3552
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n,k;	cin>>n>>k;
	int r,p,s;	cin>>r>>s>>p;
	string t;	cin>>t;
	int dp[n];
	int sum=0;
	for(int i=0;i<n;i++){
		int add;
		if(t[i]=='r')
			add=p;
		else if(t[i]=='p')
			add=s;
		else
			add=r;
		if(i<k){
			if(i==0)	dp[i]=add;
			else		dp[i]=dp[i-1]+add;
		}
		else{
			if(t[i-k]==t[i]){
				dp[i]=dp[i-1];
				t[i]='0';
			}
			else
				dp[i]=dp[i-1]+add;
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}







Measured memory_bytes: 4556
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7


def comb_mod(n, k, mod):
    numerator = 1
    denominator = 1
    for i in range(k):
        numerator = (numerator * (n - i)) % mod
        denominator = (denominator * (i + 1)) % mod

    return ((numerator % mod) * (pow(denominator, mod - 2, mod) % mod)) % mod


n_c_a = comb_mod(n, a, mod)
n_c_b = comb_mod(n, b, mod)

result = (pow(2, n, mod) - 1 - n_c_a - n_c_b) % mod
print(result)



Measured memory_bytes: 3064
import math

(a, b) = [int(s) for s in input().split()]

ans = -1
for i in range(1, 10001):
    c = math.floor(i * 0.08)
    d = math.floor(i * 0.10)

    if a == c and b == d:
        ans = i
        break

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
#define MAX_N 100
int d[MAX_N];

void init(){
	rep(i,MAX_N){
		d[i] = -1;
	}
}

int fib(int num){
	if( num == 0) return 1;
	if( num == 1) return 1;
	if(d[num] != -1) return d[num];
	d[num] = fib(num-1) + fib(num-2);
	return d[num];
}


int main()
{
	init();
	int n;
	cin>>n;
	cout<<fib(n)<<endl;
	return 0;
}




Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();	//notices
		int b = 0;		//buildings 4
		int f = 0;		//floors 3
		int r = 0;		//rooms	10
		int v = 0;		//persons
		
		//创建三维数组 值为0
		int[][][] buildings = new int[4][3][10];
		for(int i=0;i<4;i++) {
			for(int j=0;j<3;j++) {
				for(int k=0;k<10;k++) {
					buildings[i][j][k]=0;
				}
			}
		}
		
		for(int i=0;i<n;i++) {
			b = scanner.nextInt();
			f = scanner.nextInt();
			r = scanner.nextInt();
			v = scanner.nextInt();
			//三维数组
			buildings[b-1][f-1][r-1] += v;
		}
		for(int i=0;i<4;i++) {
			if (i!=0) {
				System.out.println("####################");
			}
			for(int j=0;j<3;j++) {
				for(int k=0;k<10;k++) {
					System.out.print(" " + buildings[i][j][k]);
				}
				System.out.println();
			}
		}
		scanner.close();
	}
}


Measured memory_bytes: 29872
rooms = [[[0 for i in range(10)] for j in range(3)] for h in range(4)]
n = input()
for i in range(n):
	b, f, r, v = map(int, raw_input().split())
	rooms[b-1][f-1][r-1] = rooms[b-1][f-1][r-1] + v

for i in range(len(rooms)):
	for j in rooms[i]:
		print " " + " ".join(map(str, j))
	if i != 3: print "#" * 20

Measured memory_bytes: 4232
import std.stdio;

int main()
{
	double a,b,c,d,e,f,x,y;
	while(readf("%f %f %f %f %f %f %f",&a,&b,&c,&d,&e,&f))
	{
		x=(c*e-b*f)/(a*e-b*d);
		y=(c*d-a*f)/(b*d-a*e);
		if(-0.0004<x&&x<=0)x=0;
		if(-0.0004<y&&y<=0)y=0;
		printf("%.3lf %.3lf\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
#define LL long long
#define INF 1e10

using namespace std;

LL N, A, B;
vector<LL> h;

bool f(LL K){
    LL res = 0;
    for(int i = 0; i < N; ++i){
        LL remain = h[i] - B * K;
        if(remain > 0) res += (remain + A - B - 1) / (A - B);
    }
    return res <= K;
}

LL meguru_search(LL ok, LL ng){
    while(abs(ok - ng) > 1){
        LL mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> N >> A >> B;
    h = vector<LL>(N);
    for(int i = 0; i < N; ++i) cin >> h[i];
    cout << meguru_search(INF, 0) << endl;
}

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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
const int N=100003,M=5002;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a<=b) cout<<"unsafe";
    else cout<<"safe";
    return 0;
}

Measured memory_bytes: 3652
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;

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

    if(S=="SUN"){
        cout<<7<<endl;
    }
    else if(S=="MON"){
        cout<<6<<endl;
    }
    else if(S=="TUE"){
        cout<<5<<endl;
    }
    else if(S=="WED"){
        cout<<4<<endl;
    }
    else if(S=="THU"){
        cout<<3<<endl;
    }
    else if(S=="FRI"){
        cout<<2<<endl;
    }
    else if(S=="SAT"){
        cout<<1<<endl;
    }



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

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

    if (s.size() <= k) cout << s << endl;
    else cout << s.substr(0, k) << "..." << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
vector<mint> pten(200005),seq1(200005);
struct S{
  mint val;
  int nb;
};
struct F{
  mint b,c;
};
S op(S a, S b){
  return S{a.val*pten[b.nb]+b.val, a.nb+b.nb};
}
S e(){
  return S{0, 0};
}
S mapping(F f, S a){
  return S{f.b*a.val+f.c*seq1[a.nb], a.nb};
}
F composition(F f2, F f1){
  return F{f2.b*f1.b, f2.b*f1.c+f2.c};
}
F id(){
  return F{1,0};
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,q,l,r,d;
  cin >> n >> q;
  pten[0] = 1;
  for(int i = 1; i <= 200000; ++i){
    pten[i] = pten[i-1]*10;
    seq1[i] = seq1[i-1]*10+1;
  }
  vector<S> a(n,S{1,1});
  lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
  while(q--){
    cin >> l >> r >> d;
    seg.apply(l-1,r,F{0,d});
    cout << seg.all_prod().val.val() << '\n';
  }
  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n+1);
	vector<ll> pref(n+1);
	for (int q = 1; q <= n; q++)
	{
		cin >> a[q];
		pref[q] = pref[q-1] + a[q];
	}
	ll dp[n+1][n+1];
	for (int q = 1; q <= n; q++)
	{
		dp[q][q] = 0;
	}
	for (int q = 2; q <= n; q++)
	{
		for (int w = 1; w+q-1 <= n; w++)
		{
			dp[w][w+q-1] = LLONG_MAX;
			for (int e = w; e < w+q-1; e++)
			{
				dp[w][w+q-1] = min(dp[w][w+q-1], dp[w][e] + dp[e+1][w+q-1]+pref[w+q-1]-pref[w-1]);
			}
		}
	}
	cout << dp[1][n] << "\n";
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s1s2s3;
  
  cin >> s1s2s3;
  
  int s1 = s1s2s3 / 100;
  int s2 = s1s2s3 % 100 / 10;
  int s3 = s1s2s3 % 10;
  
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	string a,b;
	cin >> a >> b;
	int ans=2;
	if(a.length()>b.length()) ans=1;
	else if(a.length()<b.length()) ans=0;
	else {
		for(int i=0;i<a.length();i++){
			if(a[i]>b[i]) {
				ans=1;
				break;
			}else if(a[i]<b[i]){
				ans=0;
				break;
			}
		}
	}
	if(ans==1) cout << "GREATER" << endl;
	else if(ans==0) cout << "LESS" << endl;
	else cout << "EQUAL" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
#define all(x) begin(perm),end(perm)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    ll a,b; cin>>a>>b;
    cout<<a*b/__gcd(a,b)<<endl;return 0;
}


Measured memory_bytes: 256
n = int(input().rstrip())
p_string = input().rstrip().split()
p = [int(x) for x in p_string]

count = 0
for i in range(1, n - 1):
    if (p[i] > p[i - 1] and p[i] < p[i + 1]) or \
        (p[i] < p[i - 1] and p[i] > p[i + 1]):
        count += 1
print(count)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
  char m[8][8];
  while(cin>>m[0]){
    for(int i=1;i<8;i++) cin>>m[i];
    int p[4];
    int n=0;
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++){
	if(m[i][j]=='1') p[n++]=i*8+j;
      }
      if(n==4) break;
    }
    int x=p[1]+p[2]+p[3]-3*p[0];
    switch(x){
    case 18:
      cout<<"A";
      break;
    case 48:
      cout<<"B";
      break;
    case 6:
      cout<<"C";
      break;
    case 30:
      cout<<"D";
      break;
    case 20:
      cout<<"E";
      break;
    case 34:
      cout<<"F";
      break;
    case 16:
      cout<<"G";
      break;
    }
    cout<<endl;
  }
  return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {

    int N, Q; cin >> N >> Q;
    int v, w;
    if (N == 1) {
        rep(i, Q) {
            cin >> v >> w;
            cout << v << endl;
        }
        return 0;
    }
    rep(i, Q) {
        cin >> v >> w;
        while (v != w) {
            if (v > w) v = (v + N - 2) / N;
            else w = (w + N - 2) / N;
        }
        cout << v << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        if (n < 105) {
            System.out.println(0);
            return;
        }

        int count = 0;
        for (int i = 105; i <= n; i += 2) {
            int modCount = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    modCount++;
                }
            }
            if (modCount == 8) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int INF = 987654321;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

void solve() {
	int n, W;
	cin >> n >> W;
	vector<int> w(n), v(n);
	REP(n) cin >> w[i] >> v[i];
	vector<vector<long long>> dp(n + 1, vector<ll> (W + 1));
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= W; j++) {
			if(w[i - 1] <= j)
				dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
			else
				dp[i][j] = dp[i - 1][j];
		}
	}
	cout << dp[n][W] << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 83076
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

char s[200000 + 5];

int main() {
  scanf("%s", s);
  int bs = 0;
  long long result = 0;
  for (int i = 0; s[i]; ++ i) {
    if (s[i] == 'B') ++ bs;
    else result += bs;
  }
  printf("%lld\n", result);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;

int main() {

    int n;
    vector <int> a(200005);
    vector <int> b;
    cin>>n;
    rep(i,n)    cin>>a.at(i);
    int m=n%2;

    rep(i,n) {
        if(i%2==m) {
            b.pb(a[i]);
        }
        else {
            b.insert(b.begin(),a[i]);
        }
    }

    rep(i,n) {
        cout<<b[i]<<endl;
    } 

 return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

int n, m;
int path[10][10] = {};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	cin >> n >> m;

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		path[a][b]++;
		path[b][a]++;
	}

	vector<int> v;
	rep(i, n) v.push_back(i);

	int ans = 0;

	do {
		if (v[0] != 0) break;
		rep(i, n - 1) {
			if (path[v[i]][v[i + 1]] == 0) break;
			if (i == n - 2) ans++;
		}

	} while (next_permutation(all(v)));

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    long long Re=1, S[7]={0}, MOD=998244353; // R G B RG GB RB
    cin >> n >> s;
    S[0] = n;
    for (int i = 0; i < 3*n; i++)
    {
        if (s[i] == 'G')
        {
            if (S[6] != 0)
            {
                Re *= S[6];
                S[6]--;
            }
            else if (S[3] != 0)
            {
                Re *= S[3];
                S[3]--;
                S[5]++;
            }
            else if (S[1] != 0)
            {
                Re *= S[1];
                S[1]--;
                S[4]++;
            }
            else
            {
                Re *= S[0];
                S[0]--;
                S[2]++;
            }
        }
        else if (s[i] == 'R')
        {
            if (S[5] != 0)
            {
                Re *= S[5];
                S[5]--;
            }
            else if (S[3] != 0)
            {
                Re *= S[3];
                S[3]--;
                S[6]++;
            }
            else if (S[2] != 0)
            {
                Re *= S[2];
                S[2]--;
                S[4]++;
            }
            else
            {
                Re *= S[0];
                S[0]--;
                S[1]++;
            }
        }
        else
        {
            if (S[4] != 0)
            {
                Re *= S[4];
                S[4]--;
            }
            else if (S[2] != 0)
            {
                Re *= S[2];
                S[2]--;
                S[5]++;
            }
            else if (S[1] != 0)
            {
                Re *= S[1];
                S[1]--;
                S[6]++;
            }
            else
            {
                Re *= S[0];
                S[0]--;
                S[3]++;
            }
        }
        Re %= MOD;
    }
    cout << Re;
    return 0;
}


Measured memory_bytes: 3868
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
 
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  vector<int> d(n+1);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) d[j]++;
  }
    for (int i = 1; i <= n; i++) {
        ans += ll(i)*d[i];
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 44684
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9+5;

int main()
{
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    int dp[n][3]={0};
    
    for(int i=0;i<n;++i)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    
    for(int i=1;i<n;++i)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
        
    }
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}


Measured memory_bytes: 5776
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

void Main()
{
    ll n, m, K;
    cin >> n >> m >> K;

    vector<ll> A(m), B(m);
    rep(i, m) cin >> A[i] >> B[i];
    vector<ll> C(K), D(K);
    rep(i, K) cin >> C[i] >> D[i];
    
    UnionFind uf(n);
    rep(i, m) {
        uf.unite(A[i] - 1, B[i] - 1);
    }

    vector<int> grp(n);
    rep(i, n) {
        grp[uf.root(i)]++;
    }

    vector<int> invalid(n);
    rep(i, m) {
        int x = min(A[i] - 1, B[i] - 1);
        int y = max(A[i] - 1, B[i] - 1);
        if (uf.root(x) == uf.root(y)) {
            invalid[x]++;
            invalid[y]++;
        }
    }

    rep(i, K) {
        int x = min(C[i] - 1, D[i] - 1);
        int y = max(C[i] - 1, D[i] - 1);
        if (uf.root(x) == uf.root(y)) {
            invalid[x]++;
            invalid[y]++;
        }
    }

    rep(i, n) {
        cout << (grp[uf.root(i)] - invalid[i] - 1) << (i == n -1 ? "" : " ");
    }    
    cout << endl;
}
signed main(){ Main();return 0;}

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


int main() {
  int N;
  string S;
  cin >> N >> S;
  int sum = 1;
  
  for (int i = 0; i < S.size()-1; i++) {
    if (S.at(i) != S.at(i+1)){
    	sum++;
    }
  }
  
  cout << sum << endl;
  
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int a=0;
for(int i=0;i<4;i++){
	if(s[i]=='+'){
		++a;
	}
	else{
		--a;
	}
	
}
cout<<a<<endl;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())

n = 0
for i in range(1, N + 1):
    s = 0
    a = i
    while a > 0:
        s += a % 10
        a = int(a / 10)
    if A <= s and s <= B:
        n += i
print(n)


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

struct edge{
	int to, cost;
	edge(int to_, int cost_){
		to = to_; cost = cost_;
	}
};
typedef pair<int,int> P;
typedef pair<int,P> State;
const int MAX_V = 101;
const int INF = 1e+8;
vector<edge> G[MAX_V];
int n, m;

void add_edge(int u, int v, int cost){
	G[u].push_back( edge(v,cost) );
	G[v].push_back( edge(u,cost) );
}

int solve(){
	// d[t][i] := 切符を使ったかどうか t で ノード i までの最小コスト
	int d[2][MAX_V];
	for(int i=0 ; i < MAX_V ; i++ ){
		d[0][i] = d[1][i] = INF;
	}
	priority_queue<State, vector<State>, greater<State> > q;
	q.push( State(0,P(1,0)) );
	d[0][0] = 0;
	int res = INF;
	while( !q.empty() ){
		int cost = q.top().first;
		int u = q.top().second.first;
		int t = q.top().second.second;
		q.pop();
		
		if( u == n ){
			res = cost;
			break;
		}
		
		for(int i=0 ; i < G[u].size() ; i++ ){
			int v = G[u][i].to;
			int add_cost = G[u][i].cost;
			if( cost + add_cost < d[t][v] ){
				d[t][v] = cost + add_cost;
				State next(d[t][v],P(v,t));
				q.push(next);
			}
			if( t == 0 ){
				for(int j=0 ; j < G[v].size() ; j++ ){
					int k = G[v][j].to;
					if( cost < d[t+1][k] ){
						d[t+1][k] = cost;
						State next(d[t+1][k],P(k,t+1));
						q.push(next);
					}
				}
			}
		}
	}
	return res;
}

int main(){
	while( cin >> n >> m , n || m ){
		for(int i=0 ; i < MAX_V ; i++ ){
			G[i].clear();
		}
		for(int i=0 ; i < m ; i++ ){
			int u, v, cost;
			cin >> u >> v >> cost;
			add_edge(u,v,cost);
		}
		int ans = solve();
		cout << ans << endl;
	}
}

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

int main()
{
    string s;
    int n, h;

    while (1) {
        cin >> s >> n;
        if (s == "-") break;
        while (n--) {
            cin >> h;
            string t;
            t += s.substr(h, s.length() - h);
            t += s.substr(0, h);
            s = t;
        }
        cout << s << endl;
    }

    return 0;
}

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

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

    int x, y, z;
    x = y = z = -1;
    int res;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n - i; j++) {
            int k = n - i - j;
            res = 10000 * i + 5000 * j + 1000 * k;
            if (res == sum) {
                x = i;
                y = j;
                z = k;
                break;
            }
        }
    }

    cout << x << ' ' << y << ' ' << z << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  long int i,flg1=0,flg2=0,flg3=0;
  char p[100000000];
  gets(p);
  for(i=0;i<strlen(p);i++)
  {
  	if(p[i]!=p[strlen(p)-1-i])
      break;
  }
  if(i==strlen(p))
    flg1=1;
  for(i=0;i<(strlen(p)-1)/2;i++)
  {
  	if(p[i]!=p[(strlen(p)-1)/2-i-1])
      break;
  }
  if(i==(strlen(p)-1)/2)
    flg2=1;
  for(i=0;i<(strlen(p)-1)/2;i++)
  {
  	if(p[(strlen(p)+1)/2+i]!=p[strlen(p)-1-i])
      break;
  }
  if(i==(strlen(p)-1)/2)
    flg3=1;
  if(flg1==1&&flg2==1&&flg3==1)
       	printf("Yes");
   else
       	printf("No");
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//H*Wの＃のフレームを持つ四角形を作成。中身は"."
		Scanner sc=new Scanner(System.in);
		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H==0 && W==0){
				break;
			}
			for(int i=1;i<=H;i++){
				for(int j=1;j<=W;j++){
					if(1<i && i<H && 1<j && j<W){
						System.out.print(".");
					}else{
						System.out.print("#");
					}
					if(j==W){
						System.out.println();
					}
				}
				if(i==H){
					System.out.println();
				}
			}
		}
	}

}



Measured memory_bytes: 34188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin >>n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i,n) cin>>s[i]>>t[i];
    string x;
    cin >>x;
    bool flag=false;
    int ans=0;
    rep(i,n){
        if (s[i]==x) {flag=true;continue;}
        if (flag) ans += t[i];
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256