akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// use gp_hash_table<int,int,custom_hash> m;
// in place of map
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
// This custom_hash is for unordered_map 
// use map<int, int, custom_hash> mp;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
	int n,k;
	cin>>n>>k;
	int r,s,p;
	cin>>r>>s>>p;
	string t;
	cin>>t;
	int dp[n][3];
	// dp[0][0]
	if(t[0] == 'p'){
		dp[0][0] = 0;
		dp[0][1] = s;
		dp[0][2] = 0;
	}
	else if(t[0] == 's'){
		dp[0][0] = r;
		dp[0][1] = 0;
		dp[0][2] = 0;
	}
	else {
		dp[0][0] = 0;
		dp[0][1] = 0;
		dp[0][2] = p;
	}
	repa(i,1,k){
		if(t[i] == 'p'){
			dp[i][0] = 0;
			dp[i][1] = s;
			dp[i][2] = 0;
		}
		else if(t[i] == 's'){
			dp[i][0] = r;
		dp[i][1] = 0;
		dp[i][2] = 0;
		}
		else{
			dp[i][0] = 0;
			dp[i][1] = 0;
			dp[i][2] = p;
		}
	}
	repa(i,k,n){
		if(t[i] == 'p'){
			dp[i][0] = max(dp[i-k][1],dp[i-k][2]);
			dp[i][1] = s+max(dp[i-k][0],dp[i-k][2]);
			dp[i][2] = max(dp[i-k][1],dp[i-k][0]);
		}
		else if(t[i] == 's'){
			dp[i][0] = r+max(dp[i-k][1],dp[i-k][2]);
			dp[i][1] = max(dp[i-k][0],dp[i-k][2]);
			dp[i][2] = max(dp[i-k][1],dp[i-k][0]);
		}
		else{
			dp[i][0] = max(dp[i-k][1],dp[i-k][2]);
			dp[i][1] = max(dp[i-k][0],dp[i-k][2]);
			dp[i][2] = p+max(dp[i-k][1],dp[i-k][0]);
		}
	}
	ll ans=0;
	repr(i,k){
		// cout<<max(dp[n-i-1][0],max(dp[n-i-1][1],dp[n-i-1][2]))<<"\n";
		ans += max(dp[n-i-1][0],max(dp[n-i-1][1],dp[n-i-1][2]));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1616
import java.util.*;

class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int d = scan.nextInt();
        long[][] xy = new long[n][2];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                xy[i][j] = scan.nextInt();
            }
        }
        int out = 0;
        for(int i = 0; i < n; i++){
            if(Math.sqrt(xy[i][0] * xy[i][0] + xy[i][1] * xy[i][1]) <= d) out++;
        }
        System.out.println(out);
        scan.close();
    }
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 57000
import sys

# convolve
# derive from https://atcoder.jp/contests/practice2/submissions/16789717
MOD = 998244353
G = 3
InvG = 332748118  # mod_inverse(3, 998244353)
W = [pow(G, (MOD - 1) >> i, MOD) for i in range(24)]
iW = [pow(InvG, (MOD - 1) >> i, MOD) for i in range(24)]


def fft(k, f):
    for l in range(k, 0, -1):
        d = 1 << l - 1
        U = [1]
        for i in range(d):
            U.append(U[-1] * W[l] % MOD)

        for i in range(1 << k - l):
            for j in range(d):
                s = i * 2 * d + j
                fs = f[s]
                fsd = f[s + d]
                f[s] = (fs + fsd) % MOD
                f[s+d] = U[j] * (fs - fsd) % MOD


def ifft(k, f):
    for l in range(1, k + 1):
        d = 1 << l - 1
        for i in range(1 << k - l):
            u = 1
            for j in range(i * 2 * d, (i * 2 + 1) * d):
                f[j + d] *= u
                fj = f[j]
                fjd = f[j+d]
                f[j] = (fj + fjd) % MOD
                f[j+d] = (fj - fjd) % MOD
                u = u * iW[l] % MOD


def convolve(a, b):
    n0 = len(a) + len(b) - 1
    k = (n0).bit_length()
    n = 1 << k
    a = a + [0] * (n - len(a))
    b = b + [0] * (n - len(b))
    fft(k, a)
    fft(k, b)
    for i in range(n):
        a[i] = a[i] * b[i] % MOD
    ifft(k, a)
    invn = pow(n, MOD - 2, MOD)
    for i in range(n0):
        a[i] = a[i] * invn % MOD
    del a[n0:]
    return a


def debug(*x):
    print(*x, file=sys.stderr)


def solve(AS, BS):
    return convolve(AS, BS)


def main():
    # parse input
    N, M = map(int, input().split())
    AS = list(map(int, input().split()))
    BS = list(map(int, input().split()))
    print(*solve(AS, BS), sep=" ")


# tests
T1 = """
4 5
1 2 3 4
5 6 7 8 9
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
5 16 34 60 70 70 59 36
"""

T2 = """
1 1
10000000
10000000
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
871938225
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 210364
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int col[1005];
int res[1005][1005];
int main(){
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	int xn=-1,xm=-1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int b1=i*a+(n-i)*(m-a);
			int b2=j*b+(m-j)*(n-b);
			if(b1==b2){
				xn=i,xm=j;
				break;
			}
		}
	}
	if(xn==-1) {
		cout<<-1;
		return 0;
	}
	xn=b,xm=a;
	for(int i=0;i<xn;i++){
		int cnt=a,j=0;
		while(cnt&&j<m){
			if(j<xm&&col[j]<b){
				col[j]++;
				res[i][j]=1;
				cnt--;
			}
			else if(j>=xm&&col[j]<n-b){
				col[j]++;
				res[i][j]=1;
				cnt--;
			}
			j++;
		}
		if(cnt) {
			cout<<-1;
			return 0;
		}
	}
	for(int i=xn;i<n;i++){
		int cnt=m-a,j=0;
		while(cnt&&j<m){
			if(j<xm&&col[j]<b){
				col[j]++;
				res[i][j]=1;
				cnt--;
			}
			else if(j>=xm&&col[j]<n-b){
				res[i][j]=1;
				col[j]++;
				cnt--;
			}
			j++;
		}
		if(cnt){
			cout<<-1;
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
		{
			printf("%d",res[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 5120
#include <stdio.h>

int gcd(int p, int q) {
  while (q != 0) {
    int r = p % q;
    p = q;
    q = r;
  }
  return p;
}

int main() {
  int k;
  scanf("%d", &k);

  long sum = 0;
  for (int a=1; a<=k; a++)
    for (int b=1; b<=k; b++)
      for (int c=1; c<=k; c++)
        sum += gcd(gcd(a, b), c);

  printf("%ld\n", sum);  

  return 0;
}

Measured memory_bytes: 1724
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>

int main() {
	int n;
	double w, h;
	while (scanf("%d,%lf,%lf", &n, &w, &h) != EOF) 
		if (w / (h*h) >= 25.0)printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 628
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val A = Array.fill(N)(sc.nextInt())

    // 0 が来たら新しい色
    // カウンタは最大3つ, 最小1つあると考えられる
    // カウンタが交差する箇所では, 分岐が発生する

    // 人は必ずどれかの帽子をかぶる.
    // 常にi番目の人間の前には,
    // 色xを被っている人間がnxi人, 色yを被っている人間がnyi人, 色zを被っている人間がnzi人いる
    // つまりi番目の人間はAi人同じ色の帽子を被っている人がいるということは,
    // nxi, nyi, nziのうちAiと同じ数だけの通りがある
    // 最初は, nxi=0,nyi=0,nzi=0なので, A0 = 0で T0 = 3からスタートする

    // 常に3つの数を管理する. Ai - 1の数を1増やす
    def solve(N: Int, A: Array[Int]): Long = {
      val MAX = 1000000007
      val counts = new Array[Int](3)
      def loop(i: Int, acm: Long): Long =
        if (i < N) {
          val updated = (counts.count(_ == A(i)).toLong * acm) % MAX
          def update(j: Int): Unit =
            if (j < 3) {
              if (counts(j) == A(i)) counts(j) += 1
              else update(j + 1)
            }
          update(0)
          loop(i + 1, updated)
        } else acm
      loop(0, 1L)
    }

    println(solve(N, A))
  }

}


Measured memory_bytes: 52092
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

string top, bot;

int main(){
  FAST_IO
  cin >> top >> bot;

  reverse(ALL(top));
  if(top == bot) cout << "YES\n";
  else cout << "NO\n";

  return 0;
}

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int a[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int up = 0, down = 0;
        for (int i = 0; i < n - 1; i++) {
            int res = a[i + 1] - a[i];
            if (res > 0) {
                up = max(up, res);
            } else {
                down = min(down, res);
            }
        }
        cout << up << " " << -down << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;

string app() {
  int n;
  cin>>n;

  vector<int> a(n);
  rep_range(i,1,n){
    cin>>a[i];
  }

  vector<int> c(n);
  rep(i,n){
    c[i]=0;
  }
  rep_range(i,1,n){
    c[a[i]-1]+=1;
  }

  rep(i,n){
    cout<<c[i]<<endl;
  }
  return "";
}

int main(){cout<<app()<<endl;return 0;}


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

int main(void) {
	// input
	int n, k;
	std::cin >> n >> k;
	std::string s;
	std::cin >> s;

	// substitute
	if(s[k-1] == 'A') s[k-1] = 'a';
	else if(s[k-1] == 'B') s[k-1] = 'b';
	else if(s[k-1] == 'C') s[k-1] = 'c';

	std::cout << s << std::endl;

	return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    cout << x2+y1-y2 << " " << y2-x1+x2 << " " << x1+y1-y2 << " " << y1-x1+x2 << endl;
}


Measured memory_bytes: 256
#import 
s=input()
t=input()
#=int(input())
#=map(str,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

cnt = 0
i = 0
while i <= (len(s)-1):
    if s[i] != t[i]:
        cnt += 1
    i += 1
print(cnt)

Measured memory_bytes: 9288
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
)

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

func main() {
	list := strings.Split(nextLine(), " ")
	Xint, _ := strconv.Atoi(list[0])
	Yint, _ := strconv.Atoi(list[1])
	X := int64(Xint)
	Y := int64(Yint)

	if X%Y == 0 {
		fmt.Println(-1)
		return
	}

	var num int64 = 1
	for {
		if len(fmt.Sprint(X*num)) > 18 {
			fmt.Println(-1)
			return
		}
		if (X*num)%Y != 0 {
			fmt.Println(X*num)
			return
		}
		num++
	}

}


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

int main() {
    string S;
    cin >> S;
    int X = S.size()-1;
    while(X >= 2) {
        bool ok = true;
        if(X%2 == 1) {
            X--;
            continue;
        }
        for(int i = 0; i < X/2; i++) {
            if(S[i] != S[i+X/2]) {
                ok = false;
            }
        }
        if(ok) {
            cout << X << endl;
            return 0;
        }
        X--;
    }
}

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

int main() {
	string ABCD = "", result = "";
	cin >> ABCD;

	int A = ABCD[0] - '0';
	int B = ABCD[1] - '0';
	int C = ABCD[2] - '0';
	int D = ABCD[3] - '0';
	bool is_exist = false, op_1, op_2, op_3;
	bool operators[] = {true, false};
	int size = sizeof(operators) / sizeof(operators[0]);
	int sum = 0;
	const int ANSWER = 7;

	repeat(i, size) {
	 	op_1 = operators[i];
		repeat(j, size) {
			op_2 = operators[j];
			repeat(k, size) {
				op_3 = operators[k];

				sum = (op_1) ? A + B : A - B;
				sum = (op_2) ? sum + C : sum - C;
				sum = (op_3) ? sum + D : sum - D;
				if (sum == ANSWER) is_exist = true;
				if (is_exist) break;
			}
			if (is_exist) break;
		}
		if (is_exist) break;
	}
	cout << ABCD[0];
	cout << (op_1 ? "+" : "-");
	cout << ABCD[1];
	cout << (op_2 ? "+" : "-");
	cout << ABCD[2];
	cout << (op_3 ? "+" : "-");
	cout << ABCD[3];
	cout << "=7" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second


void solve(){
	
	int N,W;
	cin>>N>>W;

	int item[N][2];

	rep(i,0,N)
		cin>>item[i][0]>>item[i][1];

	int dp[N+1][W+1];
	memset(dp, 0, sizeof(dp));

	rep(i,0,N+1){
		rep(j,0,W+1){
			if(i==0 || j==0){
				dp[i][j]=0;
				continue;
			}
			if(item[i-1][0]<=j){
				dp[i][j] = max(dp[i][j], dp[i-1][j-item[i-1][0]] + item[i-1][1]);
			}
			dp[i][j] = max(dp[i][j], dp[i-1][j]);
		}
	}

	cout<<dp[N][W]<<endl;



}
signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 79104
#include<iostream>
#include<algorithm>
#include<cstdio>
//f = 108.233533
//puts sprintf( "%.3f", f )
using namespace std;
int main(){
	double a,b,c,d,e,f;
	//scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f);
	while(cin>>a>>b>>c>>d>>e>>f){
	double x,y;
	y=/*(double)*/ (c*d-a*f)/(b*d-a*e);
	x=/*(double)*/ (c-b*y)/a;
	printf("%.3f %.3f\n",x,y);
	}
	//printf("%.5f",f);
	return 0;
}

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

using namespace std;

int main(void){

    int N;

    cin >> N;

    vector<pair<int, int>> lists;

    for(int i = 0;i < N;i++){
        int a,b;
        cin >> a >> b;
        lists.emplace_back(b, a);
    }

    sort(lists.begin(), lists.end());

    int sum = 0;
    bool isyes = true;

    for(auto a: lists){
        sum += a.second;

        if(sum > a.first){
            isyes = false;
            break;
        }
    }

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

    return 0;
}

Measured memory_bytes: 2420
MOD = 10**9 + 7


def mpow(a,b):
    ans = 1
    while (b> 0):
        if b&1:
            ans = (ans*a)%MOD
        a= (a*a)%MOD
        b= b>>1
    
    return ans


n = int(input())
arr =[int(c) for c in input().split()]
s = sum(arr)

ans = 0
for i in arr:
    su = s-i
    ans = (ans + ((su)*i)%MOD)%MOD

ans = ans * mpow(2,MOD-2)
if ans < 0:
    ans+=MOD

print(ans%MOD)

Measured memory_bytes: 94064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

using namespace std;

typedef pair<int,int> paii;
typedef long long ll;

int n;

int solve(vector<int> cmd)
{	
	int dice[] = {1, 2, 3, 4, 5, 6};
	
	FOR(i, 0, n)
	{
		int swp;
		
		switch(cmd[i])
		{
			case 1:
				swp = dice[1];
				dice[1] = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = swp;
				break;
			case 2:
				swp = dice[3];
				dice[3] = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = swp;
				break;
			case 3:
				swp = dice[4];
				dice[4] = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = swp;
				break;
			case 4:
				swp = dice[2];
				dice[2] = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = swp;
				break;
		}
	}
	
	return dice[0];
}

int main()
{
	while(cin >> n, n)
	{
		vector<int> cmd;
		string str;
		
		FOR(i, 0 ,n)
		{
			cin >> str;		
			cmd.push_back(str == "north" ? 1 : (str == "east" ? 2 : (str == "south" ? 3 : 4)));
		}
		
		cout << solve(cmd) << endl;
	}
		
	return 0;
}

Measured memory_bytes: 1252
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int cntr=0;
        while(n>0)
        {
            cntr++;
            n/=k;
        }
        System.out.println(cntr);
    }
}

Measured memory_bytes: 21204
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#include<iomanip>
#include<stdio.h>
#include<deque>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N,K;
	cin>>N>>K;
	int h[N+1],i,dp[N+1],j;
	fill(dp,dp+N+1,1e15);
	for(i=1;i<=N;i++)
	{
		cin>>h[i];
		if(i==1)
			dp[i]=0;
		else
		{
			for(j=i-1;j>=max((int)1,i-K);j--)
				dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
		}
	}
	cout<<dp[N]<<endl;
}


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

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

    int A[N];
    for (int &tmp: A) {
        cin >> tmp;
    }

    int totalVote = 0;
    for (int tmp: A) {
        totalVote += tmp;
    }

    double border = (double)totalVote / (4 * M);

    int popularItem = 0;
    for (int tmp: A) {
        if (tmp >= border) {
            popularItem++;
        }
    }

    if (popularItem >= M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex>
using namespace std;
using ll = int64_t;
using P = pair<int,int>;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
 vector<int>c(9);
 rep(i,9){
   cin>>c.at(i);
 }
 
 if(((c.at(1)-c.at(0))==(c.at(4)-c.at(3)))&&((c.at(1)-c.at(0))==(c.at(7)-c.at(6)))){
   //cout<<1<<endl;
   if((c.at(2)-c.at(1))==(c.at(5)-c.at(4))&&(c.at(2)-c.at(1))==(c.at(8)-c.at(7))){
     //cout<<2<<endl;
     if((c.at(3)-c.at(0))==(c.at(4)-c.at(1))&&(c.at(3)-c.at(0))==(c.at(5)-c.at(2))){
       //cout<<3<<endl;
       if((c.at(6)-c.at(3))==(c.at(7)-c.at(4))&&(c.at(6)-c.at(3))==(c.at(8)-c.at(5))){
         cout<<"Yes"<<endl;
         return 0;
       }
     }
   }
 }
 cout<<"No"<<endl;
}




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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int n;
    cin >> n;
    int cnt = 0;
    bool ok = 0;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        if (x == y)
        {
            cnt++;
        }
        else
        {
            cnt = 0;
        }
        if (cnt >= 3)
        {
            ok = 1;
        }
    }
    if (ok)
    {
        cout << "Yes\n";
    }
    else
        cout << "No\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3632
n, l = map(int, input().split())
min = 9999999
wa = 0
pm = 'p'
for i in range(1, n+1):
    wa += l+i-1
    if abs(l+i-1) < min:
        min = abs(l+i-1)
        if 0 < l+i-1:
            pm = 'm'
        else:
            pm = 'p'
if pm != 'p':
    print(wa-min)
else:
    print(wa+min)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int dp[1<<16];
int item[17][17];
#define INF (1<<21)
int main(){
	int N;
	while(cin >> N && N){
		rep(i,1<<16)dp[i] = INF;
		
		rep(i,N){
			rep(j,N+1){
				if(j)cin >> item[i][j-1];
				else cin >> item[i][N];
			}
		}
		
		dp[0] = 0;
		
		rep(i,1<<N){
			rep(j,N){
				rep(k,N){
					if(i >> j & 1)
						dp[i|(1<<k)] = min(dp[i|(1<<k)] , dp[i] + item[k][j]);
					dp[i|(1<<k)] = min(dp[i|(1<<k)],dp[i] + item[k][N]);
				}
			}
		}
		cout << dp[(1<<N)-1] << endl;
	}
}

Measured memory_bytes: 1120
n=int(input())
R=[list(map(int,input().split())) for _ in range(n)]
B=[list(map(int,input().split())) for _ in range(n)]
B.sort()
ans=0
for b in B:
    L = [ r for r in R if r[0]<b[0] and r[1]<b[1]]
    if len(L)!=0:
        s = L[0]
        for l in L:
            if s[1]<l[1]: s=l
        R.remove(s)
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c;

  	if(b>=c)
     cout<<"delicious"<<endl;
    else if(c-b<=a)
      cout<<"safe"<<endl;
    else
      cout<<"dangerous"<<endl;
    
      
  return(0);
}

Measured memory_bytes: 256
#!/usr/bin/ python3.8
N=int(input())
A=[int(x) for x in input().split()]
a=[0]*N
for i in range(N):
    if i%2==0:
        a[0]+=A[i]
    else:
        a[0]-=A[i]
assert a[0]>=0 and a[0]%2==0
A[0]-=a[0]//2
A[N-1]-=a[0]//2
for i in range(0,N-1):
    a[i+1]=2*A[i]
    A[i]-=a[i+1]//2
    A[i+1]-=a[i+1]//2
print(*a)


Measured memory_bytes: 20680
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <deque>
# include <iomanip>
# include <queue>
# include <sstream>
# include <unordered_set>
# include <unordered_map>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define MP make_pair
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define STRING(x) string x;cin>>x;
# define STR(x) STRING(x);
# define DOUBLE(x) double x;cin>>x;
# define DBL(x) DOUBLE(x); 
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl
# define INIT(a) memset(a,-1,sizeof a)
# define CLR(a) memset(a,0,sizeof a)
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
//const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const int M = 1000000007;
template<class T> void debug(T a) { for ( auto i : a )cout << i << endl; }

int main()
{
	string a;
	cin >> a;
	string x[4] = { "mew","m*ew","me*w","m*e*w" };
	bool loop = true;
	while ( loop )
	{
		loop = false;
		FOR(i, 4)
		{
			size_t t=a.find(x[i]);
			if ( t != string::npos )
			{
				loop = true;
				FOR(j, x[i].size())a.erase(a.begin() + t);
				a.insert(a.begin() + t, '*');
			}
		}
	}
	if ( a == "*" )cout << "Cat" << endl;
	else cout << "Rabbit" << endl;
}

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

int N, M;
int B[20], Pt[20], P[20];

void read();
void solve();

int main() {
  read();
  solve();
  return 0;
}

void read() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i)
    cin >> B[i];

  for (int i = 0; i < M; ++i)
    cin >> Pt[i];
}

void solve() {
  int q, res = 100, tmp;

  q = 0;
  for (int i = 0, k = 0; i < M; ++i, q = 1 - q)
    for (int j = 0; j < Pt[i]; ++j)
      P[k++] = q;

  tmp = 0;
  for (int i = 0; i < N; ++i)
    if (B[i] != P[i]) {
      for (int j = i + 1; j < N; ++j) {
        ++tmp;
        if (B[i] == P[j]) {
          swap(P[i], P[j]);
          break;
        }
      }

      if (B[i] != P[i]) {
        tmp = 100;
        break;
      }
    }

  res = min(res, tmp);

  q = 1;
  for (int i = 0, k = 0; i < M; ++i, q = 1 - q)
    for (int j = 0; j < Pt[i]; ++j)
      P[k++] = q;

  tmp = 0;
  for (int i = 0; i < N; ++i)
    if (B[i] != P[i]) {
      for (int j = i + 1; j < N; ++j) {
        ++tmp;
        if (B[i] == P[j]) {
          swap(P[i], P[j]);
          break;
        }
      }

      if (B[i] != P[i]) {
        tmp = 100;
        break;
      }
    }

  res = min(res, tmp);

  cout << res << "\n";
}

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

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

Measured memory_bytes: 1024
// finish date: 2018/01/11
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

#define bigmod 1000000007
using namespace std;

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

int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int factorial(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans = ans * i;
    }
    return ans;
}

int main() {
    string A, B;
    cin >> A >> B;
    if (A.length() > B.length()) cout << "GREATER" << endl;
    else if (A.length() < B.length()) cout << "LESS" << endl;
    else {
        if (A > B) cout << "GREATER" << endl;
        else if (A < B)cout << "LESS" << endl;
        else cout << "EQUAL" << endl;
    }

    return 0;
}


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

string itos(int x){
  stringstream ss;
  ss << x;
  return ss.str();
}

int main(){
  int n;
  string s;

  while(cin >> n, n){
    cin >> s;

    for(int i = 0; i < n; i++){
      string ns = "";

      for(int j = 0; j < s.length(); j++){
	int cnt = 0;
	for(int k = j; k < s.length() && s[k] == s[j]; k++){
	  cnt++;
	}

	ns += itos(cnt) + s[j];
	j += cnt - 1;
      }

      s = ns;
    }

    cout << s << endl;
  }
}

Measured memory_bytes: 1360
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        if (n%(d*2+1) == 0) {
            System.out.println(n/(d*2+1));
        } else {
            System.out.println(n/(d*2+1)+1);
        }

    }

}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
    static int[] sp = {5,7,5,7,7};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true){
            int n = sc.nextInt();
            if(n==0) break;
            int[] w = new int[n];

            for (int i = 0; i < n; i++) {
                w[i] = sc.next().length();
            }

            int j = 0, k = 0, s = 0;
            for (int i = 0; i < n; i++) {
                k += w[i];
                if (k==sp[j]){
                    j++;
                    if (j==5) break;
                    k = 0;
                }else if (k>sp[j]){
                    j = 0;
                    i = s++;
                    k = 0;
                }
            }

            System.out.println(s+1);
        }
    }
}

Measured memory_bytes: 30284
// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
char n;
int main()
{
	cin>>n;
	if(n=='a'||n=='e'||n=='i'||n=='o'||n=='u')
	cout<<"vowel";
	else cout<<"consonant";
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<stdio.h>
#include<string>

typedef struct fox{ int val; fox *left, *right; } fox_n;

fox_n* init()
{
    fox_n* root = new fox_n;
    root->val = -2000000001;
    root->left = NULL;
    root->right = NULL;
    return root;
}

void insert(fox_n* root, int key)
{
    static bool first = true;
    static bool add_leaf = true;  // true:left, false:right.
    if(first){ first = false; root->val = key; return; }  // initialize.
    fox_n* canis;
    fox_n* water = root;  // water from root to leaf.
    do{
        canis = water;
        if(key < canis->val){  // canis chases water.
            water = canis->left;
            add_leaf = true;
        }else{
            water = canis->right;
            add_leaf = false;
        }
    }while(water != NULL);

    fox_n* leaf = new fox_n;  // add new leaf.
    leaf->val = key;
    leaf->left = NULL;
    leaf->right = NULL;
    if(add_leaf){ canis->left = leaf; }else{ canis->right = leaf; }
    return;
}

bool find(fox_n* root, int key)
{
    fox_n* fox = root;
    int val;
    do{
        val = fox->val;
        if(key < val){ fox = fox->left; }
        else if(val < key){ fox = fox->right; }
        else{ return true; }
    }while(fox);
    return false;
}

void inorder(fox_n* root)
{
    if(!root) return;
    inorder(root->left);
    printf(" %d", root->val);
    inorder(root->right);
    return;
}

void preorder(fox_n* root)
{
    if(!root) return;
    printf(" %d", root->val);
    preorder(root->left);
    preorder(root->right);
    return;
}

int main()
{
    fox_n* root = init();
    int i, n, key; string str;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        cin >> str;
        if(str[0] == 'i'){ scanf("%d", &key); insert(root, key); }
        else if(str[0] == 'f'){ scanf("%d", &key); (find(root, key) ? printf("yes\n") : printf("no\n")); }
        else{ inorder(root); printf("\n"); preorder(root); printf("\n"); }
    }
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> lst(n,0);
    rep(i,n)cin>>lst[i];
    int j = 1;
    rep(i,n){
        if(lst[i] == j)j++;
    } 
    if(j==1){
        cout<<-1<<endl;
        return 0;
    }
    cout<<n-j+1<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	char C;
	int next=1;
	cin >> C;
	printf("%c\n", C+next);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
     public static void main(String args[]){
        Scanner stdin = new Scanner(System.in);
        int N = stdin.nextInt();
        int X = stdin.nextInt();
        int T = stdin.nextInt();
        int try_num = N / X;
        if (N % X != 0) try_num++;
        System.out.println(try_num * T);
    }
}

Measured memory_bytes: 35644
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define deb(x) cout<<#x<<" is "<<x<<endl;
typedef long long ll;
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>h(n);
    
    for(int i=0;i<n;i++)
        cin>>h[i];
    
    vector<int>dp(n);
    //dp[i] is the minimum cost of reaching the ith step
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 4056
fun main(args: Array<String>) {
    val todayWeather = readLine()!!
    val tommorrowWeather = PredictTommorrowWeather(todayWeather)
    println(tommorrowWeather)
}

fun PredictTommorrowWeather(todayWeather: String): String = when(todayWeather) {
    "Sunny" -> "Cloudy"
    "Cloudy" -> "Rainy"
    "Rainy" -> "Sunny"
    else -> throw IllegalArgumentException()
}

Measured memory_bytes: 29740
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define reps(i,j,n) for(int i = j ; i < n ; ++i)
#define rep(i, n) reps(i,0,n)
#define fr first
#define sc second
#define SQR(x) ((x)*(x))
#define INF (1 << 28)
typedef pair< int , int > Pt;

int main(){
  int n,c;
  while(cin >> n , n){
    vector<Pt> mas;
    rep(i,n){
      cin >> c;
      int back = mas.size() - 1;
      if( i % 2 == 0 ){
        if( mas.empty() || c != mas[back].first ){
          mas.push_back(Pt(c,1));
        }else mas[back].second++;
      } else {
        if( c != mas[back].first ){
          int rec = 1 + mas[back].second;
          mas.pop_back();
          back--;
          if( mas.empty() ) mas.push_back(Pt(c,rec));
          else mas[back].second += rec;
        } else mas[back].second++;
      }
    }
    int rec = 0;
    rep(i,mas.size()) if(mas[i].first == 0) rec += mas[i].second;
    cout << rec << endl;
  }
}

Measured memory_bytes: 1196
//Varun
#include "bits/stdc++.h"
using namespace std;
 
#define si(x) scanf("%d",&x)
#define sll(x) scanf("%I64d",&x)
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define mp make_pair
#define F first
#define S second
#define SETBITS(x) __builtin_popcount(x)
#define ALL(x) (x).begin(),(x).end()
#define REP(a,b) for(int i=a;i<b;i++)
#define REP2(a,b,c) for(int i=a;i<b;i+=c)	
#define fastscan ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug(x) cerr<<#x<<" is "<<x<<endl
#define INF INT_MAX
#define N_INF INT_MIN
#define initialize(a,row,col,val) for (int i = 0; i < row*col; i++)*((int*)a + i) = val;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;

#define TRACE
     
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

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

// const int maxn = ;
 
int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
 
	fastscan;

	ll n;
	cin >> n;

	cout << (2*n-4)*90;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,v,i,j,k=0,flag=1;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)cin>>a[i];
    i=0;
    while(flag){
        flag=0;
        for(j=n-1;j>i;j--){
            if(a[j-1]>a[j]){
                v=a[j-1];
                a[j-1]=a[j];
                a[j]=v;
                flag=1;
                k++;
            }
        }i++;
    }
    for(i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<a[i];
    }cout<<endl<<k<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
ll dp[101][100005];
int main()
{
     ll n,we,i,j;
     cin>>n>>we;
  ll w[n+1],v[n+1];
  for(i=1;i<=n;i++)
  {
    cin>>w[i]>>v[i];
  }
    for(i=1;i<=n;i++)
    {
      for(j=0;j<=we;j++)
      {
          
        dp[i][j]= (j<w[i])?dp[i-1][j]:max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
      }
    }
  cout<<dp[n][we];
    return 0;
}

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

using ll = long long;
vector<vector<map<pair<int,int>, ll> > > z;
vector<ll> a;
ll compute(ll i, ll j, ll x, ll y);

ll dp(ll i, ll j, ll x, ll y){
	if(!z[i][j].count({x,y})) z[i][j][{x,y}] = compute(i, j, x, y);
	return z[i][j][{x,y}];
}
ll compute(ll i, ll j, ll x, ll y){
	if(i + 1 == j) return a[i] * x + a[j] * y;
	ll best = 1e18;
	for(int k = i + 1; k < j; k++){
		best = min(best, compute(i, k, x, x+y) + compute(k, j, x+y, y) - a[k] * (x + y));
	}
	return best;
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	a.resize(n);
	z.resize(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++){
		z[i].resize(n);
	}
	cout << dp(0, n-1, 1, 1) << '\n';
}

Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const S = input[0][0];
  const T = input[1][0];

  for (let i = 0; i <= S.length; i++) {
    if (`${S.slice(i)}${S.slice(0, i)}` === T) {
      return "Yes";
    }
  }

  return "No";
};

console.log(main(read()));


Measured memory_bytes: 29628
#include <stdio.h>
int main(){
  int a,b,n,gcd=1;
  
  scanf("%d%d",&a,&b);
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
    
  }
  gcd=b; 
  printf("%d\n",gcd);		    
  return 0;
}



Measured memory_bytes: 2084
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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; }

#define MAX_V 2200
int n;
vector<int> g[MAX_V];
int match[MAX_V];
bool used[MAX_V];
void init(int n_) {
	n = n_;
	rep(i, 0, n_)g[i].clear();
}
void addEdge(int u, int v) {
	g[u].emplace_back(v);
	g[v].emplace_back(u);
}
bool augment(int v) {
	used[v] = true;
	for (int u : g[v]) {
		int w = match[u];
		if (w == -1 || (!used[w] && augment(w))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int maximumMatching() {
	int cnt = 0;
	fill(match, match + MAX_V, -1);
	for (int v = 0; v < n; v++) {
		if (match[v] == -1) {
			fill(used, used + MAX_V, false);
			if (augment(v))cnt++;
		}
	}
	return cnt;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, M, L; cin >> N >> M >> L&&N;) {
		vector<vector<int>> g(N, vector<int>(N, INF));
		rep(i, 0, M) {
			int u, v, d; cin >> u >> v >> d;
			g[u][v] = g[v][u] = d;
		}
		rep(i, 0, N)
			g[i][i] = 0;
		rep(k, 0, N)rep(i, 0, N)rep(j, 0, N) {
			if (g[i][k] != INF&&g[k][j] != INF)
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		}

		vector<int> p(L), t(L); rep(i, 0, L) {
			cin >> p[i] >> t[i];
		}
		init(L + L);
		int source = L + L, sink = source + 1;
		rep(i, 0, L) {
			rep(j, 0, L) {
				if (i == j)continue;
				if (g[p[i]][p[j]] <= t[j] - t[i]) {
					addEdge(i, L + j);
				}
			}
		}
		auto ans = L - maximumMatching();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 11508
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n,w;
    cin >> n >> w;

    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));

    for(int i = 1; i <= n; i++){
        int tmpw;
        ll v;
        cin >> tmpw >> v;

        for(int j = 0; j <= w; j++){
            
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);

            int prevw = j - tmpw;

            if(prevw >= 0){
                dp[i][j] = max(dp[i][j], dp[i - 1][prevw] + v);
            }
        }
    }

    cout << dp[n][w] << endl;


    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
    int n,sum=0;
    long long ans=0,ans2=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    bool check1=true,check2=false;
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(sum+a[i]>0){
                sum+=a[i];
            }else{
                sum+=a[i];
                for(int j=1; ;j++){
                    sum++;
                    ans++;
                    if(sum>0){
                        break;
                    }
                }
            }
        }else{
            if(sum+a[i]<0){
                sum+=a[i];
            }else{
                sum+=a[i];
                for(int j=1; ;j++){
                    sum--;
                    ans++;
                    if(sum<0){
                        break;
                    }
                }
            }
        }
    }
    sum=0;
    for(int i=0;i<n;i++){
        if(i%2==1){
            if(sum+a[i]>0){
                sum+=a[i];
            }else{
                sum+=a[i];
                for(int j=1; ;j++){
                    sum++;
                    ans2++;
                    if(sum>0){
                        break;
                    }
                }
            }
        }else{
            if(sum+a[i]<0){
                sum+=a[i];
            }else{
                sum+=a[i];
                for(int j=1; ;j++){
                    sum--;
                    ans2++;
                    if(sum<0){
                        break;
                    }
                }
            }
        }
    }
    if(ans>ans2) cout<<ans2;
    else cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define input(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define int long long
using namespace std;
signed main(){
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,k;
    cin >> n;
    int a[n];
    input(a,n);
    int dp[n+1];
    memset(dp,0,sizeof(0));
    dp[n]=0;
    dp[n-1]=abs(a[n-2]-a[n-1]);
    for(int i=n-2;i>0;i--){
        dp[i]=min(dp[i+1]+abs(a[i-1]-a[i]),dp[i+2]+abs(a[i-1]-a[i+1]));
    }
    cout << dp[1] ;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

typedef long long ll;

ll n, k;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    cin >> n >> k;
    ll a0, x, y, maxA;
    
    cin >> a0;
    y = a0;
    maxA = a0;
    
    FOR(i, 1, n) {
        cin >> x;
        y = gcd(x, y);
        maxA = max(maxA, x);
    }
    
    if (k % y == 0 && k <= maxA) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint N;
llint a[100005];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> a[i];
	sort(a, a+N);
	
	llint sum = 0, ans = 0;
	for(int i = 0; i < N; i++){
		if(sum * 2 < a[i]) ans = 0;
		sum += a[i];
		ans++;
	}
	
	cout << ans << endl;
	return 0;
}


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

int main(){
    vector <string> ss;
    string temp;
    int counter[3];
    int ma[3];
    int curr = 0;
    cin >> temp; ss.push_back(temp);
    cin >> temp; ss.push_back(temp);
    cin >> temp; ss.push_back(temp);
    counter[0] = ss[0].size();
    counter[1] = ss[1].size();
    counter[2] = ss[2].size();
    ma[0] = ss[0].size();
    ma[1] = ss[1].size();
    ma[2] = ss[2].size();

    while (counter[curr] != 0) {
        char next = ss[curr][ma[curr] - counter[curr]];
        counter[curr]--;
        if (next == 'a') curr = 0;
        else if (next == 'b') curr = 1;
        else curr = 2;
    }
    if (curr == 0) cout << 'A' << endl;
    else if (curr == 1) cout << 'B' << endl;
    else cout << 'C' << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include<type_traits>

using namespace std;

int main() {
	long double n, m, d;
	
	cin >> n >> m >> d;
	if (d == 0) {
		cout << fixed;
		cout << setprecision(10)<< (m - 1)/n << endl;
		
	}
	else {
		cout << fixed;
		cout << setprecision(10)<<((m - 1) * 2 * (n - d) / (n*n)) << endl;;
	}
	
	return 0;
}


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

using namespace std;

#define ll long long int
#define vi vector<int>
#define prec fixed<<precision(10)
#define mod 1000000007
#define set(x) __builtin_popcount(x)
#define ffs(x) __builtin_ffs(x)

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	swap(a,b);
	swap(a,c);
	cout << a << ' ' << b <<' '<< c;
	
}


Measured memory_bytes: 256