akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    string s;
    cin >> s;
    vector<int> ck(26, 0);
    rep(i, s.size())
    {
        ck[s[i] - 'a']++;
    }

    rep(i, 26)
    {
        if (ck[i] == 0)
        {
            cout << char(i + 'a') << endl;
            return 0;
        }
    }

    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	var n, t, ti, ti_plus1 int
	fmt.Scan(&n, &t)
	fmt.Scan(&ti)
	total := t

	for i := 0; i < n-1; i++ {
		fmt.Scan(&ti_plus1)
		total += min(ti_plus1-ti, t)
		ti = ti_plus1
	}
	fmt.Println(total)

}


Measured memory_bytes: 5504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		char[] c = sc.next().toCharArray();
		int ans = 0;
		int tmp = 0;
		for (int i = 0; i < n; i++) {
			if (c[i] == 'I') {
				tmp++;
			} else {
				tmp--;
			}
			ans = Math.max(ans, tmp);
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 23508
tenki = list(input())
ans = 0
max_ans = 0
for i in tenki:
  if i == "R":
    ans = ans + 1
    flag = 0
  else:
    flag = 1
  if flag == 1:
    if max_ans < ans:
      max_ans = ans
    ans = 0
if max_ans > ans:
  print(max_ans)
else:
  print(ans)

Measured memory_bytes: 9112
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int A, B, C, X; cin >> A >> B >> C >> X;
    int ans = 0;
    for(int i=0; i<=A; i++) {
        for(int j=0; j<=B; j++) {
            for(int k=0; k<=C; k++) {
                int money = 500 * i + 100 * j + 50 * k;
                if(money == X) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,start,end) for(ll i = start; i < end; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define dwn2(i,start,end) for(ll i = start; i >= end; --i)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll mode = 1e9 + 7;


int main(){
	string s1,s2;
	cin>>s1>>s2;
	int len = 0;
	int n = s1.length();
	rep(i,n){
		if(s1[i] == s2[i]){
			len++;
		}
	}
	cout<<len<<endl;


	return 0;
}








Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
		// 整数の入力
        
        int num = sc.nextInt();
        
        int leg = sc.nextInt();
        
        for(int i = 0;i < num + 1;i++){
            if((i*2 + (num-i)*4) == leg) {
                System.out.println("Yes");
                System.exit(0);
            }
        }
		// 出力
		System.out.println("No");

    }
}

Measured memory_bytes: 35836
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    char c;
    cin>>n;

    int rw[n];
    int r[n];
    int w[n];

    int ans=n;
    for(int i=0;i<n;i++){
        cin>>c;
        if(c=='R'){
            rw[i]=0;
        }else{
            rw[i]=1;
        }

    }
    for(int i=0;i<n;i++){
        if(i==0)w[i]=rw[i];
        else if(rw[i]==1) w[i]=w[i-1]+1;
        else w[i]=w[i-1];
    }
    for(int i=n-1;i>=0;i--){
        if(i==n-1)r[i]=(!rw[i]);
        else if(rw[i]==0) r[i]=r[i+1]+1;
        else r[i]=r[i+1];
    }
    for(int i=-1;i<n;i++){
      	if(i==-1)ans=min(ans,max(0,r[i+1]));
      	else if(i==n-1)ans=min(ans,max(w[i],0));
        else ans=min(ans,max(w[i],r[i+1]));
    }
    cout<<ans;
}

Measured memory_bytes: 5920
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(30) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> S;
  N=S.size();
  T=S.substr(N/2,N);
  S=S.substr(0,N/2);
  if(S==T)Out("Yes");
  else Out("No");
}


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

int main(){
  int N,i;
  long sum=0;
  string a;
  cin >> N;
  vector<string> s(N);
  map<string,int> m;

  for(i=0;i<N;i++){
    cin >> a;
    sort(a.begin(),a.end());
    s.at(i) = a;
  }
  for(i=0;i<N;i++){
    if(m.count(s.at(i))){
      sum += m.at(s.at(i));
      m.at(s.at(i))++;
    }else
    m[s.at(i)] = 1;
  } 
  cout << sum << endl; 
}

Measured memory_bytes: 12032
#include <stdio.h>

int main(void)
{
	int train[100];
	int ans[100];
	int i, n;
	int now_train, now_ans;
	
	now_train = now_ans = 0;
	while (scanf("%d", &n) != EOF){
		if (n != 0){
			train[now_train] = n;
			now_train++;
		}
		else {
			now_train--;
			ans[now_ans] = train[now_train];
			now_ans++;
		}
	}
	
	for (i = 0; i < now_ans; i++){
		printf("%d\n", ans[i]);
	}
	
	return (0);
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;

public class TravelLake{
    public static void Main(){
        var input = Console.ReadLine().Split(' ');
        var total = int.Parse(input[0]);
        var house = int.Parse(input[1]);
        int distance = 0;
        int distance_r = 0;
        int distance_o = 0;
        int min = 0;
        
        var house_number = Console.ReadLine().Split(' ');
        
        for(var i = 0; i < house ;i++){
            if(i == 0){
                distance =int.Parse(house_number[house -1]) - int.Parse(house_number[i]);
                min = distance;
                distance = int.Parse(house_number[0]) +  total - int.Parse(house_number[1]);
                }else{
                    distance_r = (total - int.Parse(house_number[i]) + int.Parse(house_number[i - 1]));
                    if(i != house - 1){
                        distance_o = int.Parse(house_number[i]) + total - int.Parse(house_number[i + 1]);
                    }else{
                       distance_o = int.Parse(house_number[i -1]) + total - int.Parse(house_number[i]); 
                    }
                    distance = ((distance_r > distance_o) ? distance_o : distance_r);
                }
                  if(min > distance){
                    min = distance;
                }
            }
            
            Console.WriteLine(min);
    }
}

Measured memory_bytes: 32860
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(){
	char s[1500];
	int data[26];
	int num;
	int i;
	char c;

	for(i=0; i< 26; i++)
		data[i] = 0;

	while(fgets(s, sizeof(s), stdin) != NULL){

		for(i=0; i< strlen(s); i++){
			if((s[i] >= 'a') && (s[i] <= 'z')){
				data[s[i] - 'a'] = data[s[i] - 'a'] + 1;
			}
			else if((s[i] >= 'A') && (s[i] <= 'Z')){
				data[s[i] - 'A'] = data[s[i] - 'A'] + 1;
			}
		}
	}
	for(i=0; i< 26; i++){
		printf("%c : %d\n", 'a' + i, data[i]);
	}


	return 0;

}


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

namespace ABC174A
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            if (X >= 30)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 27468
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define stp setprecision(15)
#define eps 0.000001
#define endl '\n'
#define ll lli
 
using namespace std ;
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define N 200010
#define lg 19



int main() 
{ 

/////////////////////////////////////
    
    fastio;
 
/////////////////////////////////////    

    lli m,d;
    cin>>m>>d;

    lli cnt=0;
    loopl(i,22,d+1)
    {
        lli j = i/10;
        if(i%10  <2 || j%10<2) continue;
        if((i%10)*(j%10) <= m && (i%10)*(j%10) >= 1) 
            {
                cnt++;
            }
    }
    cout<<cnt;

}   




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long n,a,b,r,l,c,R,L;
    cin>>n>>a>>b;
    l=a-1;
    r=n-b;
    c=b-a;
    R=c+2*r;
    L=c+2*l;
    if(c%2==0){cout<<(b-a)/2;return 0;}
    else if(R>L){cout<<L/2+1;}
    else{cout<<R/2+1;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  int x=7%k;
  for(int i=1;i<=k;i++){
    if(x==0){
      cout<<i<<endl;
      return 0;
    }
    x=(x*10+7)%k;
  }
  cout<<-1<<endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<double> aji(n);
  for (int i = 0; i < n; i++) {
    cin >> aji.at(i);
  }
  
  sort(aji.begin(), aji.end());
  
  double x = aji.at(0);
  
  for (int i = 0; i < n - 1; i++) {
    x = (x + aji.at(i + 1)) / 2;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  unsigned long long i, N, res = 1;
  cin >> N;
  
  for (i = 1; i <= N; i++) {
    res = res*i % (10*10*10*10*10*10*10*10*10 + 7);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
inf = 10**15
mod = 10**9+7
x = int(input())
for i in range(-10**5, 10**5+1):
    tmp = i**5-x
    b = int(abs(tmp)**(1/5))
    if b**5 == abs(tmp):
        if tmp > 0:
            print('{} {}'.format(i, b))
        else:
            print('{} {}'.format(i, -b))
        sys.exit()

Measured memory_bytes: 68916
#include<iostream>
using namespace std;
char a,b;
int main (void) {
    cin >> a >> b;
    if (a < b) {
        cout << "<";
    }
    if (a > b) {
        cout << ">";
    }
    if (a == b) {
        cout << "=";
    }
    return 0;
}

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

int main(){
    string s;
    cin>>s;
    bool isyes=true;
    while(true){
        if(s.size()<=3){
            isyes=(s=="ABC");
            break;
        }
        string news="";
        for(int i=0;i<s.size();i++){
            if(i>=s.size()-2 || s.substr(i,3)!="ABC"){
                news+=s[i];
            }
            else{
                i+=2;
            }

        }
        vector<int> exist(3,0);
        for(int j=0;j<news.size();j++){
            exist[news[j]-'A']=1;
        }
        int num=-1;
        if(!exist[0]) num=0;
        if(!exist[1]){
            if(num!=-1) isyes=false;
            else num=1;
        }
        if(!exist[2]){
            if(num!=-1) isyes=false;
            else num=2;
        }
        if(num==-1) isyes=false;
        if(news.size()==s.size()) isyes=false;
        if(!isyes) break;
        string reals="";
        for(int i=0;i<s.size();i++){
            if(i<s.size()-2 && s.substr(i,3)=="ABC"){
                reals+=char('A'+num);
                i+=2;
            }
            else{
                reals+=s[i];
            }
        }
        s=reals;

    }
    cout<<(isyes ? "Yes" : "No")<<endl;

}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  ll m;
  in(m);
  vector<string> s(n);
  rep(i, n)
    in(s[i]);
  sort(all(s));
  rep(i, n)
    out(s[i]);
  memi;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line[] = br.readLine().split(" ");
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);
        int c = Integer.parseInt(line[2]);
        int x = Integer.parseInt(line[3]);
        int y = Integer.parseInt(line[4]);
        long price, minPrice = a * x + b * y;
        
        for (int i = 2; i <= Math.max(x, y)*2; i += 2) {
            price = a * Math.max(0, (x - i/2)) + b * Math.max(0, (y - i/2)) + c * i;
            if (price < minPrice) {
                minPrice = price;
            }
        }
        
        
        
        
        System.out.println(minPrice);
    }
}


Measured memory_bytes: 21204
from math import sqrt

primes=[2]
flag = False
x = int(input())
if x == 2:
  print(x)
else:
  i = 3
  while True:
    for p in primes:
      if sqrt(i) < p:
        flag = True
        break
      if i % p == 0:
        break
    if flag:
      primes.append(i)
      if x <= i:
        break
      flag = False
    i+=1
  print(i)

Measured memory_bytes: 3304
n,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
now=0
ans=0
if n==k:
  print(1)
else:
  while(True):
    n-=k
    ans+=1
    if n<=0:
      break
    else:
      n+=1
      
  print(ans)

Measured memory_bytes: 13812
#include <stdio.h>
#include <string.h>

int main(void) {
  char inbuf[1280];
  int alphabet[26], i;
  for (i = 0; i < 26; i++)
    alphabet[i] = 0;
  while (fgets(inbuf, sizeof(inbuf), stdin) != NULL) {
    int i;
    for (i = 0; i < strlen(inbuf); i++) {
      char theChar = inbuf[i];
      if ((theChar >= 0x41) && (theChar <= 0x5A))
        alphabet[theChar - 0x41]++;
      else if ((theChar >= 0x61) && (theChar <= 0x7A))
        alphabet[theChar - 0x61]++;
    }
  }
  for (i = 0; i < 26; i++) {
    printf("%c : %d\n", i + 0x61, alphabet[i]);
  }
  return 0;
}

Measured memory_bytes: 524
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#define INF 0x3f3f3f3f;
 
using namespace std;
 
string s[200005];
 
bool cmp(string a,string b) {
        return a.compare(b)<0;
}
 
int main() {
    int n,i;
    scanf("%d",&n);
    for(i=0; i<n; i++)
        cin>>s[i];
    sort(s,s+n,cmp);//按字母表排序 
    int m=1,cnt=1;
    for(i=1; i<n; i++) {
        if(s[i].compare(s[i-1])==0)//compare函数用来进行字符串以及其子串的比较
            cnt++;
        else
            cnt=1;
        m=max(cnt,m);//记录最大值 
    }
    cnt=1;
    if(m==1)
        cout<<s[0]<<endl;
    for(i=1; i<n; i++) {
        if(s[i].compare(s[i-1])==0)
            cnt++;
        else
            cnt=1;
        if(cnt==m)//输出最大值 
            cout<<s[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 14720
MOD = 998244353


def main():
    N, K = (int(i) for i in input().split())
    LR = [[int(i) for i in input().split()] for j in range(K)]

    dp = [0] * (N+2)
    dp[1] = 1
    dp[2] = -1
    for i in range(1, N+1):
        for le, ri in LR:
            if i+le <= N:
                dp[i+le] += dp[i]
                dp[i+le] %= MOD
            if i+ri+1 <= N:
                dp[i+ri+1] -= dp[i]
                dp[i+ri+1] %= MOD
        dp[i+1] += dp[i]
        dp[i+1] %= MOD
    print(dp[N])


if __name__ == '__main__':
    main()


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int H, W;
pii pmap[81][81];
bool DP[2][81][160 * 80];

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

	cin >> H >> W;
	rep(i, 0, H)rep(j, 0, W)
	{
		cin >> pmap[i][j].first;
	}
	rep(i, 0, H)rep(j, 0, W)
	{
		cin >> pmap[i][j].second;
	}

	DP[0][0][0] = true;
	int nxt = 1;
	rep(i, 0, H + 1)
	{
		rep(j, 0, W)rep(k, 0, 160 * 80)DP[nxt][j][k] = false;
		rep(j, 0, W)rep(k, 0, 160 * 80)
		{
			if (!DP[nxt ^ 1][j][k])continue;
			if (i > 0)
			{
				DP[nxt ^ 1][j + 1][k + abs(pmap[i - 1][j + 1].first - pmap[i - 1][j+1].second)] = true;
				DP[nxt ^ 1][j + 1][abs(k - abs(pmap[i - 1][j + 1].first - pmap[i - 1][j+1].second))] = true;
			}
			DP[nxt][j][k + abs(pmap[i][j].first - pmap[i][j].second)] = true;
			DP[nxt][j][abs(k - abs(pmap[i][j].first - pmap[i][j].second))] = true;
		}
		nxt ^= 1;
	}
	//nxt ^= 1;

	int ans = INF;
	rep(k, 0, 160 * 80)
	{
		if (DP[nxt][W - 1][k])
		{
			ans = k;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	string s,t;
	ll k;
	ll total=0,c=1,t2=0;

	cin>>s;
	cin>>k;
	t=s+s;
	for(int i=1; i<t.size(); i++){
		if(i==s.size()){
			total+=t2;
			t2=0;
			if(c==s.size()){
				cout<<s.size()/2*(k/2+k%2)+(s.size()/2+s.size()%2)*(k/2)<<endl;
				return 0;
			}
		}
		if(t[i]==t[i-1])c++;
		if(t[i]!=t[i-1])c=1;
		if(c%2==0)t2++;
	}
	cout<<total+t2*(k-1)<<endl;
	return 0;

}


Measured memory_bytes: 256
check :: String -> Bool
check "resare" = True
check "esare" = True
check "remaerd" = True
check "maerd" = True
check (c1:c2:c3:c4:c5:c6:c7:cs)
    | head5 == "resar" = if c6 == 'e'
                         then check (c7:cs)
                         else False
    | head5 == "esare" = check $ c6:c7:cs
    | head5 == "remae" = if (c6:c7:[] == "rd")
                         then (check cs)
                         else False
    | head5 == "maerd" = check $ c6:c7:cs
    | otherwise = False
    where head5 = c1:c2:c3:c4:c5:[]
check _ = False
 
main :: IO ()
main = do
    sentence <- getLine :: IO String
    putStr $ if (check $ reverse sentence) then "YES" else "NO"

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

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

void solve(int N, int M, int C, vector<int> B, vector<vector<int>> A) {
  int count = 0;
  rep(i, N) {
    auto Ai = A[i];
    int sum = C;
    rep(j, M) {
      sum += Ai[j] * B[j];
    }
    if (sum > 0)
      count++;
  }
  cout << count << endl;
}

int main(){
  // int 3E4
  // long 2E9
  // long long 9E18
  int N;
  scanf("%d",&N);
  int M;
  scanf("%d",&M);
  int C;
  scanf("%d",&C);
  vector<int> B(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%d",&B[i]);
  }
  vector<vector<int>> A(N, vector<int>(M));
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < M ; j++){
      scanf("%d",&A[i][j]);
    }
  }
  solve(N, M, C, move(B), move(A));
  return 0;
}


Measured memory_bytes: 256
package main
  
import (
    "fmt"
)

func main() {
    var r, g, b, n int
    fmt.Scan(&r, &g, &b, &n)
    var cnt int
    for i := 0; i <= int(n/r); i++ {
        for j := 0; j <= int((n-i*r)/g); j++ {
            rem := n - i*r - j*g
            if rem%b == 0 {
                cnt++
            }
        }
    }
    fmt.Println(cnt)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<unordered_set>
using namespace std;
// SHUBHAM KHANNA //
#define ff              first
#define ss              second
//#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define rep(x,y)        for(int i=x;i<y;i++)

void solve() {
	string s;
	cin >> s;
	int n = s.size();
	if (s[n - 1] == 's')
	{
		cout << s << "es" << endl;
	}
	else
	{
		cout << s << "s" << endl;
	}

}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();
	return 0;
}

Measured memory_bytes: 3640
N = int(input())
a = list(map(int, input().split()))

a.insert(0, 0) # 0番目に0をinsertして0indexed
ans = [0 for _ in range(N+1)]

for i in range(N, 0, -1): # iはNから1
    tmp = 0
    for j in range(2*i, N+1, i): # jは2i, 3i, 4i, ...(最大はN)
        tmp ^= ans[j] # 1, 0, 1, 0...を繰り返す(偶数個入ってたら0, 奇数個入ってたら1)
    ans[i] = tmp ^ a[i] # aに合わせてansに入れる

print(sum(ans)) # 入っているボールの個数
for i in range(1, N+1):
    if ans[i] == 1:
        print(i, end=' ')
else:
    print()


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef unordered_map<ll, ll> ump;

const ll mod = 1e9+7;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> cnt(5, 0); // M, A, R, C, H
	REP(i, n){
		string s;
		cin >> s;
		switch (s[0]){
			case 'M':
				cnt[0]++;
				break;
			case 'A':
				cnt[1]++;
				break;
			case 'R':
				cnt[2]++;
				break;
			case 'C':
				cnt[3]++;
				break;
			case 'H':
				cnt[4]++;
				break;
		}
	}
	ll ans = 0;
	REP(i, 3){
		FOR(j, i+1, 4){
			FOR(k, j+1, 5){
				ans += cnt[i]*cnt[j]*cnt[k];
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){
    vector<int> pasta(3);
    vector<int> juice(2);
    for(int i=0;i<3;i++) cin >> pasta[i];
    for(int i=0;i<2;i++) cin >> juice[i];
    sort(all(pasta));
    sort(all(juice));
    cout << pasta.front() + juice.front() - 50 << endl;
    return 0;
}

Measured memory_bytes: 1212
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
//	https://www.biduo.cc/biquge/1_1782/c1900912.html
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=998244353;
int qpow(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(LL)ret*x%mod;
		x=(LL)x*x%mod;
		y>>=1;
	}
	return ret;
}
inline void add(int&x,int y){x+=y;if(x>=mod)x-=mod;}

const int maxn=500111;
int fac[maxn],invf[maxn];
int comb(int x,int y){if(y<0||x<y)return 0;else return (LL)fac[x]*invf[y]%mod*invf[x-y]%mod;}
int n,k;

int main()
{
	fac[0]=1;for(int i=1;i<maxn;i++)fac[i]=(LL)i*fac[i-1]%mod;
	invf[maxn-1]=qpow(fac[maxn-1],mod-2);for(int i=maxn-1;i>=1;i--)invf[i-1]=(LL)i*invf[i]%mod;
	get2(n,k);
	int ans=0;
	for(int i=0;i<=k;i++)
	{
		int j=k-i;if(i<j)continue;
		if(i==j)
		{
			if(i>=n)
			{
				add(ans,comb(i+j-1,i-1));
				add(ans,mod-comb(i+j-1,n-2));
			}
		}
		else
		{
			if(i>=n)
			{
				add(ans,comb(i+j,i));
				add(ans,mod-comb(i+j,j-(i-n)-1));
			}
		}
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 4096
inp = [int(x) for x in input().split()]
ans = []

def findway():
    for x in range(inp[0] + 1):
        for y in range(inp[0] - x + 1):
                z = inp[0] - x - y
                sum = x * 1000 + y * 5000 + z * 10000
                if sum == inp[1] :
                    ans = [z,y,x]
                    return ans


    return [-1,-1,-1]

l = findway()

print(" ".join([str(x) for x in l]),end="")


Measured memory_bytes: 3064
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
int main()
{
    int n;
    long long ans = 0;

    

    cin >> n;
    vector<int>a(n);

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

    for (int i = 1; i < n; i++) {
        if (a[i - 1] > a[i]) {
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }

    cout << ans << endl;

    return 0;
}


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

uint64_t gcd(uint64_t A, uint64_t B)
{
	uint64_t r = A % B;
	if(r == 0){
		return B;
	} else {
		return gcd(B, r);
	}
}

int main()
{
	uint64_t A, B;
	cin >> A >> B;
	printf("%llu\n", A * B / gcd(A, B));
}


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

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        //if (n < 6) return n;

        var li6 = new List<int>();

        var v = 6;
        while(v <= 100000) {
            li6.Add(v);
            v *= 6;
        }

        var li9 = new List<int>();
        v = 9;
        while (v <= 100000) {
            li9.Add(v);
            v *= 9;
        }

        li6.Sort((x, y) => y - x);
        li9.Sort((x, y) => y - x);

        var min = int.MaxValue;

        for(int i=0; i<=n; i++) {
            var nn = i;
            var c = 0;
            c += F(ref nn, li6);

            nn = n - i + nn;
            c += F(ref nn, li9);
            min = Math.Min(min, c + nn);
        }

        return min;
    }

    static int F(ref int n, List<int> li) {
        var c = 0;
        var i = 0;

        while (n >= li.Last()) {
            while (li[i] > n) i++;
            n -= li[i];
            c++;
        }

        return c;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 11220
/*
ID: hafiz.i1
TASK: milk2
LANG: C++
*/
#include<bits/stdc++.h>

#define ll long long
#define debug(x) cout<<x<<"DE"<<endl;

using namespace std;



int main()
{
//    freopen("milk2.in", "r", stdin);
//    freopen("milk2.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll noo=0,noz=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0')noz++;
        else noo++;
    }
    cout<<2ll*min(noo,noz);
}


Measured memory_bytes: 3760
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=110;

int n,p[maxn][maxn],m,k,a[10010];

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=k;i++)scanf("%d",&a[i]);
    int now=1,nowx=a[1];
	for(int i=1;i<=n;i++)if(i&1){
		for(int j=1;j<=m;j++){//printf("now=%d nowx=%d\n",now,nowx);
			if(nowx==0){now++;nowx=a[now];}
			p[i][j]=now;nowx--;//printf("p[%d][%d]=%d\n",i,j,p[i][j]);
		}
	}
	else{
		for(int j=m;j>=1;j--){
			if(nowx==0){now++;nowx=a[now];}
			p[i][j]=now;nowx--;
		}
	}
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++)printf("%d ",p[i][j]);
    	printf("\n");
    }
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


bool used[2000005] = {};
void Main() {
	int N;  cin >> N;
	vector<Pi> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i].first;
		A[i].second = i;
	}
	sort(begin(A), end(A));
	
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		bool f = false;
		if (i < N-1 && A[i].first == A[i+1].first) {
			f = true;
		}
		if (i > 0 && A[i].first == A[i-1].first) {
			f = true;
		}

		for (int x = 1; x*x <= A[i].first; x++) {
			if (A[i].first % x == 0 && (used[x] || used[A[i].first/x])) {
				f = true;
			}
		}

		if (!f) cnt++;
		used[A[i].first] = true;
	}
	cout << cnt << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 5784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <set>

using namespace std;

int main() {
    int n, m;   cin >> n >> m;
    if (n == 1 && m == 0) {
        cout << 0 << endl;
        return 0;
    }
    int *s = new int[m], *c = new int[m];
    for (int i = 0; i < m; i++)
        cin >> s[i] >> c[i];

    int *ans = new int[n];
    for (int i = 0; i < n; i++)
        ans[i] = -1;

    for (int i = 0; i < m; i++) {
        if (ans[s[i]-1] != -1 && ans[s[i]-1] != c[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans[s[i]-1] = c[i];
    }

    if (ans[0] == 0) {
        if (n == 1) {
            cout << 0 << endl;
            return 0;
        }
        cout << -1 << endl;
        return 0;
    }


    for (int i = 0; i < n; i++) {
        if (ans[i] == -1) {
            if (i == 0)
                cout << 1;
            else
                cout << 0;
        }
        else 
            cout << ans[i];
    }

    cout << endl;
    return 0;
}

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

int main(void)
{
    using namespace std;
    char s[10000];
    char s2[1200];
    char p[10000];
    scanf("%s", s2);
    scanf("%s", p);

    strcat(s , s2);
    strcat(s , s2);
    
    if (strstr(s, p) == NULL) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    
    return 0;
}


Measured memory_bytes: 3168
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

ans_list = []
ans = []

for i,j in enumerate(a):
    tmp = [str(i+1)] * j
    ans_list.extend(tmp)

for _ in range(H//2):
    ans.append(ans_list[:W])
    ans_list = ans_list[W:]
    ans.append(list(reversed(ans_list[:W])))
    ans_list = ans_list[W:]

if H % 2 == 1:
    ans.append(ans_list)

for i in range(H):
    print(' '.join(ans[i]))

Measured memory_bytes: 3828
L,R=map(int,input().split())
if R-L>=2019:
    minimum=0
else:
    left,right=L%2019,R%2019
    minimum=2018**2
    for i in range(left,right+1):
        for j in range(i+1,right+1):
            minimum=min(minimum,i*j%2019)
print(minimum)

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

int main() {
	int n,i;
	cin>>n;
	int a[n];
	int dp[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	dp[0]=0;
	dp[1] = abs(a[1]-a[0]);
	for(i=2;i<n;i++)
	{
		dp[i] = min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i-1]-a[i]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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


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

    bool flag = true;
    
    if(s[0] != 'A') flag = false;

    int cnt = 0;
    int index = -1;
    rep2(i,2,s.length()-1){
        if(s[i]=='C'){
            index = i;
            cnt++;
        }
    }
    if(cnt != 1) flag = false;

    rep(i,s.length()){
        if(i == 0 || i == index) continue;
        else if(!(s[i] >= 'a' && s[i] <='z')) flag = false;
    }

    cout<< ( flag ? "AC" : "WA") <<endl;

    return 0;
}


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

using namespace std;

int n,k;
int a[nmax];
bool pre[nmax][nmax]={}, suf[nmax][nmax]={};


int main(){
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		a[i]=min(a[i],k);
	}

	pre[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<k;j++){
			pre[i][j]=pre[i-1][j];
			if(j>=a[i]){
				pre[i][j]|=pre[i-1][j-a[i]];
			}
		}

		for(int j=0;j<=k;j++){
			if(pre[i-1][j] &&j+a[i]>=k){
				pre[i][k]=1;
			}
		}
	}
	suf[n+1][0]=1;
	for(int i=n;i>=1;i--){
		for(int j=0;j<k;j++){
			suf[i][j]=suf[i+1][j];
			if(j>=a[i]){
				suf[i][j]|=suf[i+1][j-a[i]];
			}
		}

		for(int j=0;j<=k;j++){
			if(suf[i+1][j] &&j+a[i]>=k){
				suf[i][k]=1;
			}
		}
	}

	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]==k){
			continue;
		}

		int req = k-a[i];
		vector<int> v;
		for(int j=0;j<=k;j++){
			if(suf[i+1][j]){
				v.push_back(j);
			}
		}
		int val = INT_MAX;
		for(int j=0;j<=k;j++){
			if(pre[i-1][j]){
				auto it = lower_bound(v.begin(),v.end(), req-j);
				if(it!=v.end()){
					val=min(val,j+(*it));
				}
			}
		}
		if(val>=k){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

        if (s == "-") {
            break;
        }

        int m;
        cin >> m;

        for (size_t i = 0; i < m; i++) {
            int h;
            cin >> h;

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

        cout << s << endl;
    }
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string S;
    cin >> S;
    int loss = 0;
    REP(i, S.size()) {
        if(S[i] == 'x') {
            loss++;
        }
    }
    if(loss <= 7) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	int x;
	cin>>x;
	if(x>=30)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3628
//#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
 
template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL maxn=1e3+10;
LL MOD=1e9+7,inf=0x1f1f1f1f,mod=998244353;
db eps=1e-5;
LL t,n,m,q,ans,cnt[11];
LL d1x[]={-2,-2,-2,-1,-1,-1,0,0,0},d1y[]={-2,-1,0,-2,-1,0,-2,-1,0},
	d2x[]={0,0,0,1,1,1,2,2,2},d2y[]={0,1,2,0,1,2,0,1,2};
struct NODE{
	LL a,b,x,y;
};
map<PLL,LL> ma;
NODE tt;

bool check(LL a,LL b){
	if(a<1||a>n||b<1||b>m)return 1;
	return 0;
}

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v;
	cin>>n>>m>>q;
	cnt[0]=(n-2)*(m-2);
	repu(i,1,q){
		cin>>u>>v;
		repu(j,0,8){
			tt.a=u+d1x[j];
			tt.b=v+d1y[j];
			tt.x=u+d2x[j];
			tt.y=v+d2y[j];
			if(check(tt.a,tt.b)||check(tt.x,tt.y))continue;
			k=ma[mp(tt.a,tt.b)]++;
			cnt[k]--;
			cnt[k+1]++;
		}
	}
	repu(i,0,9)cout<<cnt[i]<<endl;
	return 0;
}

Measured memory_bytes: 56448
from itertools import permutations

N, M, R = map(int, input().split())
r = list(map(lambda x: int(x) - 1, input().split()))
d = [[float("inf") for _ in range(N)] for _ in range(N)] 
for i in range(M):
    x, y, z = map(int, input().split())
    d[x-1][y-1] = min(d[x-1][y-1], z)
    d[y-1][x-1] = min(d[x-1][y-1], z)
for i in range(N):
    d[i][i] = 0

def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

short_dist = warshall_floyd(d)

ans = float('inf')
for ptn in permutations(r):
    dist = 0
    for x, y in zip(ptn, ptn[1:]):
        dist += short_dist[x][y]
    ans = min(ans, dist)
        
print(ans)

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

namespace tes
{
	class contest
	{
		static void Main(string[] args)
		{
			var input = new List<int>();
            for(int i =0; i<4; i++)
            {
                input.Add(int.Parse(Console.ReadLine()));
            }

            if (input[0] <= input[1]) Console.WriteLine(input[0] * input[2]);
            else Console.WriteLine(input[1]*input[2]+(input[0]-input[1])*input[3]);
		}
		
	}
}

Measured memory_bytes: 2904
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include <iomanip>
using namespace std;

int main(){
  int ls, ll, hr, min;
  cin >> ls >> ll >> hr >> min;
  
  double rs = (hr/12.0)+(min/60.0)/12.0; // ratio short
  double rl = (min/60.0); // ratio long
  double minr = rs > rl? std::min(1.0+rl-rs, rs-rl) : std::min(1.0+rs-rl, rl-rs); // ratio min
  double dist = sqrt(ls*ls+ll*ll-2.0*ls*ll*cos(2.0*M_PI*minr));
  cout << std::setprecision(20) << dist << endl;
  return 0;
}

Measured memory_bytes: 4116
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;

#define MP make_pair
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//AOJ 1304
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};

set<int> vsi;
int n;

inline int getx(int a){return (a>>25 & 7);}
inline int gety(int a){return (a>>28 & 7);}
inline int getidx(int x, int y){return y*n+x;}
inline int getstate(int a, int x, int y){return ((a>>getidx(x,y))&1);}
inline int setstate(int a, int x, int y, int state){
	if(state){
		return a|(1<<getidx(x,y));
	}else{
		int p=1<<getidx(x,y);
		p = ~p;
		return a&p;
	}
}
inline int setpos(int a, int x, int y){
	int ret=a;
	ret &= ((1<<25)-1);
	ret |= x<<25;
	ret |= y<<28;
	return ret;
}

inline int count(int b){
	int ret = 0;
	REP(i,n)REP(j,n)if(getstate(b,i,j))ret++;
	return ret-1;
}

inline int step(int &b){
	int tb = b;
	int ret = 0;
	int x=getx(b);
	int y=gety(b);
	REP(i,n){
		REP(j,n){
			if(y==i&&x==j)continue;
			int cnt = 0;
			REP(k,8){
				int ny=i+dy[k];
				int nx=j+dx[k];
				if(nx<0 || ny<0 || nx>=n || ny>=n)continue;
				if(getstate(tb,nx,ny))cnt++;
			}
			if(getstate(tb,j,i)){
				if(cnt!=2&&cnt!=3)b=setstate(b,j,i,0);
			}else if(!getstate(tb,j,i)){
				if(cnt==3)b=setstate(b,j,i,1);
			}
		}
	}
	return ret;
}

int main(){
	while(cin>>n, n){
		vsi.clear();
		string b;
		REP(i,n){
			string tmp;
			cin>>tmp;
			b+=tmp;
		}
		int is=0;
		REP(i,n){
			REP(j,n){
				switch(b[i*n+j]){
				case '@':
					is = setpos(is, j, i);
				case '#':
					is |= (1LL<<i*n+j);
					break;
				}
			}
		}
		deque<pair<int, int> > q;
		q.push_back(MP(0,is));
		int ans=-1;
		while(!q.empty()){
			int x,y;
			pair<int, int> tmp=q.front();
			q.pop_front();
			if(EXIST(vsi,tmp.second))continue;
			vsi.insert(tmp.second);
			if(count(tmp.second)==0){
				ans=tmp.first;
				break;
			}
			x = getx(tmp.second);
			y = gety(tmp.second);
			REP(i,8){
				int nx=x+dx[i];
				int ny=y+dy[i];
				if(nx<0 || ny<0 || nx>=n || ny>=n || getstate(tmp.second, nx, ny)==1)continue;
				int tb = tmp.second;
				tb=setstate(tb,x,y,0);
				tb=setstate(tb,nx,ny,1);
				tb=setpos(tb,nx,ny);
				step(tb);
				if(EXIST(vsi,tb))continue;
				q.push_back(MP(tmp.first+1, tb));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1644
n = int(input())
dam = list(map(int, input().split()))
mount = [0]*n

for i in range(1, n):
  mount[i] = 2*dam[i-1] - mount[i-1]

diff = (mount[0] + mount[n-1]) // 2 - dam[n-1]
mount[0] -= diff

for i in range(1, n):
  mount[i] = 2*dam[i-1] - mount[i-1]
  
print(*mount)

Measured memory_bytes: 14028