akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = input()
cnt = {"R":0,"G":0,"B":0}

"""
前のがよく分からなかったので
"""
ans = 1
mod = 998244353
for i in range(3*n):
    cnt[s[i]] += 1
    rem = []
    for k in {"R","G","B"}:
        if k != s[i]:
           rem.append(cnt[k])
    rem.sort()
    if rem[0]>=cnt[s[i]]:#最少色が来た場合
        ans *=  (rem[0]-cnt[s[i]]+1) 
    elif cnt[s[i]]<=rem[1]:#中間色
        ans *= (rem[1]-cnt[s[i]]+1)
    else:#最多色
        ans*=(n-cnt[s[i]]+1)
    ans %=mod
print(ans)


Measured memory_bytes: 43944
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    l_n = [True] * n
    for i in range(m):
        a, b = map(int, input().split())
        if h[a-1] == h[b-1]:
            l_n[b-1] = False
            l_n[a-1] = False
        elif h[a-1] <= h[b-1]:
            l_n[a-1] = False
        elif h[a-1] >= h[b-1]:
            l_n[b-1] = False
    print(sum(l_n)) 

if __name__ == '__main__':
    main()

Measured memory_bytes: 20088
import math
a,b,C = map(int, input().split())
t = math.radians(C)
S = 0.5*a*b*math.sin(t)
L = a + b + math.sqrt((a**2)+(b**2)-(2*a*b*math.cos(t)))
h = b*math.sin(t)
print("{:.5f}\n{:.5f}\n{:.5f}".format(S,L,h))

Measured memory_bytes: 7860
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
    std::ios::sync_with_stdio(false);
    ll n,k;
    while(cin>>n>>k)
    {
        ll ans=1;
      /*  for(n;n&&k;n--,k--)
        {
            ans*=k;
        }*/
        cout<<k*qpow(k-1,n-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
a = list(input())
b = list(input())
c = list(input())

turn = "a"
while True:
    if turn == "a":
        if a:
            turn = a.pop(0)
        else:
            print("A")
            break
 
    if turn == "b":
        if b:
            turn = b.pop(0)
        else:
            print("B")
            break
 
    if turn == "c":
        if c:
            turn = c.pop(0)
        else:
            print("C")
            break

Measured memory_bytes: 3060
def main():
  n = int(input())
  bef = 0
  ans = 0
  for i in range(n):
    now = int(input())
    ans += min(bef, now)
    now -= min(bef, now)
    ans += now//2
    bef = now % 2
  print(ans)
  
if __name__ == "__main__":
  main()

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k,r,s,p; string t; cin>>n>>k>>r>>s>>p>>t;
	int64_t ans=0;
	for(int i=0;i<n;++i){
		if(t.at(i)=='-')break;
		char prev='-';
		for(int j=i;j<n;j+=k){
			if(prev==t.at(j)){
				t.at(j)='-';
				prev='-';
				continue;
			}
			if(t.at(j)=='r')ans+=p;
			else if(t.at(j)=='s')ans+=r;
			else ans+=s;
			prev=t.at(j);
			t.at(j)='-';
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<list>
#include<map>
#define ll long long
#define INF 2000000000
#define NINF -2000000000
#define MOD 1000000007
#define br '\n'
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ll x;
	cin>>x;
	ll ans=x/11;
	x=x-(ans*11);
	ans*=2;
	if(x>0&&x<=6)
		ans++;
	else if(x>6)
		ans+=2;
	cout<<ans<<br;
	return 0;
}


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

int main() {
    int n,a;
    vector<pair<int,int>> p;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        p.push_back(make_pair(a,i));
    }
    sort(p.begin(),p.end());
    for (int i=0;i<n;i++) {
        cout << p.at(i).second+1;
        cout << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 1780
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

int main()
{
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		double s[1000];
		double m = 0;
		for(int i = 0; i < n; i++){
			cin >> s[i];
			m += s[i];
		}
		m = m / n;
		double ans = 0;
		for(int i = 0; i < n; i++){
			ans += (s[i] - m) * (s[i] - m);
		}
		ans = ans / n;
		ans = sqrt(ans);
		printf("%f\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1244
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  T, A = map(int, input().split())
  H = [int(h) for h in input().split()]
  dif = float('inf')
  pos = 0
  for i in range(N):
    d = abs(A - (T - H[i] * 0.006))
    if d < dif:
      dif = d
      pos = i+1
  print(pos)


if __name__ == '__main__':
  main()

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

int main () { 
  string s;
  cin >> s;
  int l = s.size();
  printf("%c%d%c\n", s[0], l-2, s[l-1]);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
const int N = 1e5 + 5;
 
int n, m, k;
int x11, y11, x2, y2;
int dx[4]={-1, +1, 0, 0};
int dy[4]={0, 0, +1, -1};
vector<vector<char> > a;
vector<vector<int> > vis, ways, dist;
 
void bfs(int x, int y)
{
	queue<pair<int, int> > q;
	q.push({x, y});
	vis[x][y] = 1;
	dist[x][y] = 0;
	while(!q.empty())
	{
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		for(int dir=0;dir<4;dir++)
		{
			for(int len = 1; len <= k; len++)
			{
				int nx=x+dx[dir] * len;
				int ny=y+dy[dir] * len;
				if(nx<1 || ny<1 || nx>n || ny>m)
					break;
				if(vis[nx][ny] && dist[x][y] + 1 > dist[nx][ny])
					break;
				if(a[nx][ny] == '@')
					break;
				if(vis[nx][ny])
					continue;
				dist[nx][ny]=dist[x][y]+1;
				vis[nx][ny]=1;
				q.push({nx, ny});
			}
		}
	}
}
 
int32_t main()
{
	IOS;
	cin >> n >> m >> k;
	cin >> x11 >> y11 >> x2 >> y2;
	a = vector<vector<char> > (n + 1, vector<char> (m + 1));
	vis = ways = dist = vector<vector<int> > (n + 1, vector<int> (m + 1, 0));
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	bfs(x11, y11);
	if(!vis[x2][y2])
		cout << -1;
	else
		cout << dist[x2][y2];
	return 0;
}


Measured memory_bytes: 32456
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n,x,sum=0,ans=0;
	cin>>n>>x;
	vector<int> a;
	for(int i=0;i<n;i++){
		ll tmp;
		cin>>tmp;
		a.pb(tmp);
	}
	sort(a.begin(),a.end());
	for(int i=1;i<=n;i++){
		sum += a[i-1];
		if(sum<=x){
			ans++;
		}
	}
	if(sum==x){
		cout<<n<<endl;
		return 0;
	}
	else if(ans==n){
		cout<<n-1<<endl;
		return 0;
	}
	else{
		cout<<ans<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

S = input()
n = len(S)

def dfs(i, f):
    # 文末？の最後まで行ったらreturn
    if i == n - 1:
        return f
    # +を入れるか入れないか
    return dfs(i + 1, f + S[i + 1]) + "+" + dfs(i + 1, f + "+" + S[i + 1])

def main():
    print(eval(dfs(0,S[0])))

if __name__ == '__main__':
    main()

Measured memory_bytes: 4136
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
	int n, x; scanf("%d%d", &n, &x);
	if(x == 1 || x == 2 * n - 1) return puts("No"), 0;
	puts("Yes"); int t = 1;
	for(int i = 1; i < n - 1; i ++) {
		while(abs(t - x) <= 1) t ++;
		printf("%d\n", t ++);
	}
	printf("%d\n%d\n%d\n", x - 1, x, x + 1);
	for(int i = n + 2; i < 2 * n; i ++) {
		while(abs(t - x) <= 1) t ++;
		printf("%d\n", t ++);
	}
	return 0;
}


Measured memory_bytes: 1408
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

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

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

ll h[maxn], dp[maxn];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++)  scanf("%lld", &h[i]);

    memset(dp, 0x3f, sizeof(dp));
    dp[1] = 0;
    for(int i = 1; i <= n; i++)
    {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    printf("%lld\n", dp[n]);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    string S;

    cin >> N >> S;

    if(S.size()<=N){
        cout << S << endl;
    }
    else{
        for(int i=0;i<N;i++){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
string weather(string t){
  if(t=="Sunny") return "Cloudy";
  else if(t=="Cloudy") return "Rainy";
  else return "Sunny";
}
int main(){
  string s;
  cin >> s;
  cout << weather(s) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s==u){
        cout << a-1 << " " << b << endl;
    }else{
        cout << a << " " << b-1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] arr = new int[n];
        boolean[] win = new boolean[k+1];
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for (int i=0;i<n;i++){
            arr[i] = scanner.nextInt();
        }
        for(int i = 1 ; i<=k;++i){
            for(int j = 0 ;j<n;++j){
                win[i] |= arr[j] <= i && !win[i-arr[j]];
            }
        }
        System.out.println(win[k]?"First":"Second");
    }
}

Measured memory_bytes: 37288
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <stack>
#include <queue>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;


int main() {
	vector<int> v = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	cout << v[k - 1];
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<string> res(30000);
int cnt;
string s;

void dfs(int n) {
	if(n == 0) {
		res[cnt] = s;
		++cnt;
		return;
	}
	bool ex = false;
	REP(i, s.size()) {
		if(s[i] == 'a' + n) {
			ex = true;
			break;
		}
		if(s[i] == 'a' + (n - 1)) {
			s[i] = 'a' + n;
			dfs(n - 1);
			s[i] = 'a' + (n - 1);
		}
	}
	if(!ex) {
		dfs(n - 1);
	}
}

int main(void) {
	while(true) {
		cin>>s;
		if(s == "#") break;
		cnt = 0;
		dfs(25);
		sort(res.begin(), res.begin() + cnt);
		cout<<cnt<<endl;
		if(cnt <= 10) {
			REP(i, cnt) {
				cout<<res[i]<<endl;
			}
		} else {
			REP(i, 5) {
				cout<<res[i]<<endl;
			}
			REP(i, 5) {
				cout<<res[cnt - 5 + i]<<endl;
			}
		}
	}
}

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

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


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

typedef long long int ll;


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

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

    ll ans = 0, m = a[n - 1];

    for(ll i = 0;i < n;i++){
        if(m > abs(a[n - 1] - a[i] * 2)){
            ans = a[i];
            m = a[n - 1] - a[i] * 2;
        }
    }

    cout << a[n - 1] << " " << ans;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

#define MAXN 8

bool graph[MAXN][MAXN]; // 頂点の隣接情報
//int path[MAXN]; // 経路

// 始点から終点までの経路を表示
/*void print_path(int n)
{
	for (int i = 0; i < n - 1; i++) {
		cout << path[i] << " ";
	}
	cout << path[n - 1] << endl;
}*/

// 頂点vから深さ優先探索(全頂点数n)
int dfs(int v, int n, bool visited[MAXN])
{
	bool a_visited = true;

	// 全頂点を訪問済みなら1を返す
	for (int i = 0; i < n; i++) {
		if (visited[i] == false) a_visited = false;
	}
	if (a_visited) {
		//print_path(n);
		return (1);
	} else {
		int ans = 0;
		// vに隣接している点iを深さ優先探索
		for (int i = 0; i < n; i++) {
			// vとiは隣接しているか
			if (graph[v][i] == false) continue;
			// iは既に訪問しているか
			if (visited[i] == true) continue;
			// 隣接していて未訪問なら訪問
			visited[i] = true;
			/*path[count] = i + 1;
			count++;*/
			// 深さ優先探索
			ans += dfs(i, n, visited);
			// 未訪問にする
			visited[i] = false;
			//count--;
		}
		return (ans);
	}
}

int main()
{
	int n, m;
	int ans;
	//int count = 1; // 訪問した頂点の個数
	bool visited[MAXN]; // 各頂点の訪問状況
	// 読み込み
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		graph[a - 1][b - 1] = graph[b - 1][a - 1] = true; // 隣接
	}
	// 始点(1)以外の訪問状況を初期化(全て未訪問)
	for (int i = 1; i < n; i++) {
		visited[i] = false;
	}
	// 始点(1)は訪問済みとする
	visited[0] = true;
	//path[0] = count;
	// 始点1、頂点数nで深さ優先探索
	ans = dfs(0, n, visited);
	cout << ans << endl;

	return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<complex>
using namespace std;
int main(){
	int a,b,x;cin>>x>>a>>b;
	if(abs(x-a)>abs(x-b))cout<<"B"<<endl;
	else cout<<"A"<<endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#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>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

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

    bool valid = false;
    for(int i=0; i<3; i++){
        int sum = 0;
        for(int j=0; j<3; j++){
            sum += (a[i][j] == -1);
        }
        if(sum == 3) valid = true;
    }

    for(int i=0; i<3; i++){
        int sum = 0;
        for(int j=0; j<3; j++){
            sum += (a[j][i] == -1);
        }
        if(sum == 3) valid = true;
    }

    if(a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1) valid = true;
    if(a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1) valid = true;

    cout << (valid ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a,b,c,x,ans,i,j,k;
  scanf("%d %d %d %d",&a,&b,&c,&x);
  ans = 0;

  for(i = 0;i <= a;i++){
    for(j = 0;j <= b;j++){
      for(k = 0;k <= c;k++){
        if(i*500 + j*100 + k*50 == x){
          ans++;
        }
      }
    }
  }

  printf("%d\n",ans);
  return(0);
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  uint64_t g = gcd(m,n);
  if(m%g==0) return (m/g)*n;
  if(n%g==0) return (n/g)*m;
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

// keyが降順ソートされるmap
// map<int, int, std::greater<int>> edges;

signed main() {
  int n,m;
  cin >> n >> m;
  
  if(abs(n-m)>1){
    cout << "0" << endl;
    return 0;
  }
  
  ll pattern = 1;
  if(m==n) pattern *= 2;
  
  while(n>1){
    pattern *= n;
    n--;
    pattern %= MOD;
  }

  while(m>1){
    pattern *= m;
    m--;
    pattern %= MOD;
  }
  pattern %= MOD;
  
  cout << pattern << endl;

  
  return 0;
}



Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int N;cin>>N;
    cout<<N/3<<endl;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n, k;
    cin >> n >> k;

    vector<int> x(n);
    for(int in=0;in<n;in++) {
        cin >> x.at(in);
    }

    int ans = 0;
    for(int in=0;in<n;in++) {
        ans += min(x.at(in), abs(x.at(in)-k));
    }
    ans *= 2;
    cout << ans << endl;
    return 0;
}


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

int main(){
int a,b,c;
cin>>a>>b>>c;
vector<int>vec={a,b,c};
  
  sort(vec.begin(), vec.end());
  for(int i=0;i<3;i++){
    if(i==2)
cout<<  vec.at(i) <<endl;
    else
    cout<<  vec.at(i) <<" ";  
                     }
}


Measured memory_bytes: 3080
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int X = sc.nextInt();
    System.out.println(X >= A && X <= A+B ? "YES" : "NO");
  }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=100001 ;
int main()
{
   fast ;
   ll n ;
   cin>>n ;

   ll a[n],b[n],c[n-1] ;
   for(ll i=0;i<n;i++) cin>>a[i] ;

   for(ll i=0;i<n;i++) cin>>b[i] ;

   for(ll i=0;i<n-1;i++) cin>>c[i] ;

   ll ans=0 ;
   for(ll i=0;i<n;i++)
   {
      ans+=b[a[i]-1] ;
      if(i+1<n&&a[i+1]==a[i]+1) ans+=c[a[i]-1] ;
   }
   cout<<ans ;

}




Measured memory_bytes: 256
#include <iostream>
using namespace std;   
int main()  
{ 
int x;
cin>>x;
int sum=0;
int a,b,m;
for(int i=1;i<=x;i++)
{
cin>>a>>b;
if(a>=b)m=a-b+1;
if(a<b)m=b-a+1;
sum+=m;
}
cout<<sum;
system("pause");  
return 0;  
} 


Measured memory_bytes: 504
n,k = map(int,input().split())
A = list(map(int,input().split()))

mod = 10**9 + 7

A.sort(key = lambda x:abs(x),reverse = True)
ans = 1
last = -1
lastp = -1
cnt = 0
for a in A:
    if a >= 0:break
else:
    if k&1:
        for i in range(k):
            ans *= A[n-i-1]
            ans %= mod
    else:
        for i in range(k):
            ans *= A[i]
            ans %= mod
    print(ans)
    exit()
for i in range(k):
    ans *= A[i]
    ans %= mod
    if A[i] < 0:
        last = i
        cnt += 1
    if A[i] > 0:
        lastp = i
if n == k:
    print(ans%mod)
    exit()
if cnt&1:
    first = 0
    firstp = 0
    for a in A[k:]:
        if a > 0 and firstp == 0:
            firstp = a
        if a < 0 and first == 0:
            first = a
    if first == 0 and firstp == 0:
        ans = 0
    elif first == 0 or lastp == -1:
        ans *= pow(A[last],mod-2,mod)*firstp%mod
        ans %= mod
    elif firstp == 0:
        ans *= pow(A[lastp],mod-2,mod)*first%mod
        ans %= mod
    else:
        if A[lastp]*firstp <= A[last]*first:
            ans *= pow(A[lastp],mod-2,mod)*first%mod
            ans %= mod
        else:
            ans *= pow(A[last],mod-2,mod)*firstp%mod
            ans %= mod
print(ans%mod)


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

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

Measured memory_bytes: 3620
c = [list(map(int, input().split())) for _ in range(3)]
a = [0] * 3
b = c[0]
a[1] = c[1][0] - b[0]
a[2] = c[2][0] - b[0]
flag = False
for i in range(3):
    if flag:
        break
    for j in range(3):
        if c[i][j] != a[i] + b[j]:
            flag = True
            break

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

Measured memory_bytes: 3064
import java.util.*;
import java.util.stream.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int mod = (int)1e9 + 7;
        int n = sc.nextInt();
        System.out.println((int)Math.pow(n,3));
    }

}


Measured memory_bytes: 21972
#include <stdio.h>
int main (){
	int n,check = 1;
	scanf("%d", &n);
	char s[n+1];
	scanf("%s", s);
	if(n%2 == 1){
		check = 0;
	}else{
		int temp = (n/2) + 1;
		for(int i = 0; i < n/2; i++){
			if(s[i] != s[i + (n/2)]){
				check = 0;
				break;
			}
		}
	}
	if(check == 1){
		puts("Yes");
	}else{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 1624
#include <iostream>
using namespace std;
int main() {
    // insert code here...
    int a, b;
    while (1){
        cin >> a >> b;
        if (a == 0 && b == 0)break;
        for (int i = 0; i < a; i++){
            for (int j = 0; j < b; j++){
                if ((i + j) % 2 == 0){
                    cout << "#";
                }
                else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3080
#include <stdio.h>
#include <string.h>
int main(){
  int N, L;
  char s[100][101] = {{0}};
  char tmp[101];

  scanf("%d%d", &N, &L);

  for(int cnt = 0; cnt < N; cnt++){
    scanf("%s", s[cnt]);
  }

  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      if(strcmp(s[i], s[j]) > 0){
	strcpy(tmp, s[i]);
	strcpy(s[i], s[j]);
	strcpy(s[j], tmp);
      }
    }

  }

  for(int cnt = 0; cnt < N; cnt++){
    printf("%s", s[cnt]);
  }  

  printf("\n");
  
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 1000000007;

struct node{
	vector<pii> cnode;
};

int solve(node* nodes, int p, int color) {
	int maxNum = nodes[p].cnode.size() + 1;
	if (p == 0) --maxNum;

	int t = 1;

	rep(i, nodes[p].cnode.size()) {
		if (t == color) ++t;
		nodes[p].cnode[i].second = t;
		maxNum = max(maxNum, solve(nodes, nodes[p].cnode[i].first, t));
		++t;
	}

	return maxNum;
}

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

	int n;
	cin >> n;
	node* nodes;
	nodes = new node[n];

	pii* ab;
	ab = new pii[n-1];
	rep(i, n-1) {
		cin >> ab[i].first >> ab[i].second;
		--ab[i].first;
		--ab[i].second;

		nodes[ab[i].first].cnode.push_back(pii(ab[i].second , 0));
	}

	int k = solve(nodes, 0, 0);
	cout << k << "\n";

	rep(i, n - 1) {
		rep(j, nodes[ab[i].first].cnode.size()) {
			if (nodes[ab[i].first].cnode[j].first == ab[i].second) {
				cout << nodes[ab[i].first].cnode[j].second << "\n";
				break;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 8576
#include <string>
#include <cstdio>
#include <iostream>
using namespace std;

int main ()
{
    int a_tmp;
    int n;
    scanf("%i",&n);
    bool all_even = true;
    for (int i = 0; i < n;++i) {
        scanf("%i", &a_tmp);
        if (a_tmp % 2 == 1) {
            all_even = false;
            break;
        }
    }
    cout << (all_even ? "second" : "first");

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>
#include<map>
using namespace std;

int main(){
    int n,t;
    cin >> n;
    int h[n];
    for(int i = 0;i < n;i++){
        cin >> t;
        h[i] = t;
    }
    int total = 1;
    int a = 0;
    for(int i = 1;i < n;i++){
        a = 0;
        for(int  j= 0;j < i;j++){
            if(h[i] < h[j]){
              a = 1;
              
              break;
            }
        }
        if(a == 0)total++;
    }

    cout << total << endl;
}

Measured memory_bytes: 384
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q;
ll dp[1000 + 100][10000 + 100];

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> h >> n;
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, n + 5) {
    rep(j, h + 5) { dp[i][j] = LINF; }
  }
  dp[0][h] = 0;

  rrep(i, 1, n + 1) {
    ll mi = LINF;
    rrrep(j, h, 0) {
      if (j + a[i - 1] <= h)
        dp[i][j] =
            min({dp[i - 1][j], dp[i][j], dp[i - 1][j + a[i - 1]] + b[i - 1],
                 dp[i][j + a[i - 1]] + b[i - 1]});
      else
        dp[i][j] = min({dp[i - 1][j], dp[i][j]});
    }
    rep(j, a[i - 1] + 1) {
      mi = min(mi, dp[i - 1][j]);
      mi = min(mi, dp[i][j]);
    }
    dp[i][0] = min({dp[i][0], mi + b[i - 1], dp[i - 1][0]});
  }
  
  Cout(dp[n][0]);
  return 0;
}

Measured memory_bytes: 84224
def sum_of_digits(i: int) -> int:
    result = 0
    for _ in range(len(str(i))):
        i, mod = divmod(i, 10)
        result += mod

    return result


def answer(n: int, a: int, b: int) -> int:
    some_sums = 0
    for i in range(1, n + 1):
        if a <= sum_of_digits(i) <= b:
            some_sums += i

    return some_sums


def main():
    n, a, b = map(int, input().split())
    print(answer(n, a, b))


if __name__ == '__main__':
    main()

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

int main() {
  string S,T;
  cin >> S >> T;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3860
using System;

namespace B___ss
{
    class Program
    {
        static void Main (string[] args)
        {
            var s = Console.ReadLine ();
            var count = 1;
            var str="";
            for (var i = s.Length - 1; i > 0; i--)
            {
                str = s.Remove (i, count);
                if (str.Length % 2 == 0 && str.Substring (0, str.Length / 2) == str.Substring (str.Length / 2, str.Length / 2))
                {
                    Console.WriteLine (str.Length);
                    break;
                }
                count++;
            }
        }
    }
}

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

int main() {
  string input;
  cin >> input;
  int n[4];
  int i, j;
  for (i = 0; i < 4; i++) {
    n[i] = input.at(i) - '0';
  }

  char op[2] = {'+', '-'};
  int lc[3];
  for (lc[0] = 0; lc[0] < 2; lc[0]++) {
    for (lc[1] = 0; lc[1] < 2; lc[1]++) {
      for (lc[2] = 0; lc[2] < 2; lc[2]++) {
        int sum = n[0];
        for (i = 0; i < 3; i++) {
          if (!lc[i]) {
            sum += n[i + 1];
          } else {
            sum -= n[i + 1];
          }
        }
        if (sum == 7) {
          for (i = 0; i < 3; i++) {
            cout << n[i] << op[lc[i]];
          }
          cout << n[3] << "=7" << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define LIM 500000
#define HALF LIM / 2
#define MAX 1000000000
int n, A[LIM], sum = 0;

void print(int A[]) {
  for ( int i = 0; i < n; i++ ) {
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void merge(int A[], int left, int mid, int right) {
  int l = mid - left;
  int r = right - mid;

  int L[l], R[r];
  for ( int i = 0; i < l; i++ ) L[i] = A[left + i];
  for ( int i = 0; i < r; i++ ) R[i] = A[mid + i];
  L[l] = MAX;
  R[r] = MAX;

  l = 0; r = 0;
  for (int i = left; i < right; i++ ) {
    if ( L[l] <= R[r] ) {
      A[i] = L[l];
      l++;
    } else if (R[r] < L[l]) {
      A[i] = R[r];
      r++;
    }
    sum++;
  }
}

void mergeSort(int A[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
int main() {
  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);

  mergeSort(A, 0, n);

  print(A);

  printf("%d\n", sum);
  return 0;
}



Measured memory_bytes: 6484
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long
#define ld long double
#define MAX 1000000000
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	for(int cc=1;cc<=t;cc++){
        //cout<<"Case #"<<cc<<": ";
        ld r;
        cin>>r;
        cout<<(2*M_PI*r)<<endl;

	}
}


Measured memory_bytes: 3804
#include <stdio.h>

int main (void)
{
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if(13<=a)
	printf("%d",b);
  else if(6<=a && a<=12)
	printf("%d",b/2);
  else
	  putchar('0');
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b;
    cin >> a >> b;
    if (a + b == 15)
        cout << "+" << endl;
    else if (a * b == 15)
        cout << "*" << endl;
    else
        cout << "x" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a=1000000000,b=0,n,i;
	
	scanf("%d",&n);
	while(n--)
 {scanf("%d",&i);
 if(i<a)a=i;
 if(i>b)b=i;
 }
 printf("%d",b-a);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n;
  cin>>n;
  vector<vi> a(n,vi(n)),b(n,vi(n,1));
  rep(i,n)rep(j,n)cin>>a[i][j];
  rep(k,n)rep(i,n)rep(j,n)if(k!=i && k!=j)
    if(a[i][j]>a[i][k]+a[k][j]){
      cout<<-1<<endl;
      return 0;
    }else if(a[i][j]==a[i][k]+a[k][j]){
      b[i][j]=0;
    }
  ll ans=0;
  rep(i,n)rep(j,i)if(b[i][j])ans+=a[i][j];
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main(){
  ll n;cin>>n;
  ll a[n][n];for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)cin>>a[i][j];
  ll ans=0;
  for(ll i=0;i<n;i++){
    for(ll j=i;j<n;j++)ans+=a[i][j];
  }
  for(ll i=0;i<n-2;i++){
    for(ll j=i+1;j<n-1;j++){
      for(ll k=j+1;k<n;k++){
        ll p=a[i][j],q=a[i][k],r=a[j][k];
        if(p+q<r||q+r<p||p+r<q){
          cout<<-1<<endl;
          return 0;
        } 
      }
    }
  }
  for(ll i=0;i<n-1;i++){
    for(ll j=i+1;j<n;j++){
      ll s=a[i][j];
      ll che=0;
      for(ll k=0;k<n;k++){
        if(k==i||k==j)continue;
        ll e=a[i][k],f=a[j][k];
        if(s==e+f){
          che=1;
          break;
        }
      }
      if(che==1)ans-=s;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 896
#include <cstdio>

using namespace std;

const int N = 2e5 + 500;

int n, x, p[N], c = 1;

int main(){
	scanf("%d%d", &n, &x);
	if(x == 1 || x == 2 * n - 1){
		printf("No\n");
		return 0;
	}
	if(x <= n){
		p[n - 1] = x;
		p[n] =     x - 1;
		p[n - 2] = x + 1;
		p[n + 1] = x + 2;
	}
	else{
		p[n - 1] = x;
		p[n] =     x + 1;
		p[n - 2] = x - 1;
		p[n + 1] = x - 2;
	}
	printf("Yes\n");
	for(int i = 0;i < 2 * n - 1;i++){
		if(!p[i]){
			if((x <= n && c == x - 1))
				c = x + 3;
			if((x > n && c == x - 2))
				c = x + 2;
			p[i] = c++;
		}
		printf("%d\n", p[i]);
	}
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define ms(v,n) memset((v),n,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define nl endl
#define inf 1e18
#define cases ll t;cin>>t;while(t--)
#define BLOCK 500
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
 
using namespace std;



int32_t main()
{
    fast
    ll n;
    cin>>n;
    ll v[n][3];

    f(i,n)
    {
        cin>>v[i][0]>>v[i][1]>>v[i][2];

    }

    ll dp[n][3];
    ms(dp,0);

    f(i,n)
    {
        f(j,3)
        {
            if(i==0)
            {
                dp[0][j]=max(dp[0][j],v[0][j]);
                
                continue;
            }
            f(k,3)
            {
                if(k!=j)
                dp[i][k]=max(dp[i][k],dp[i-1][j]+v[i][k]);
            }

        }
    }



    cout<<*max_element(dp[n-1],dp[n-1]+3);


    
    

       
    return 0;
    
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int diff(string s,string t) {
    int ans=0;
    for(int i=0;i<s.size();i++) {
        ans+=s[i]!=t[i];
    }
    return ans;
}
int main() {
    string s,t;
    cin>>s>>t;
    int ans=1e9;
    for(int i=0;i<s.size()-t.size()+1;i++) {
        string tmp=s.substr(i,t.size());
        ans=min(ans,diff(tmp,t));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i = 0
visit = []
visit_set = set()
while i not in visit_set:
    visit.append(i)
    visit_set.add(i)
    i = A[i] - 1
find = visit.index(i)
if K < find:
    print(visit[K] + 1)
else:
    root = visit[find:]
    K = (K-find) % len(root)
    print(root[K] + 1)

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

int main()
{
    int n,k,a[200006];
    long long int ans=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){ 
        cin>>a[i];
    } 
    sort(a,a+n);
    for(int i=0;i<n-k;i++)ans+=a[i];
    cout<<ans<<'\n';
    
    

         
      
        

    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

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

// multi-dimensional vector (require c++14)
template <typename T, typename U>
static inline vector<U> make_nd_vector(T &&n, U &&val) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
static inline decltype(auto) make_nd_vector(T &&n, Args &&... args) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<decltype(make_nd_vector(forward<Args>(args)...))>(
      forward<T>(n), make_nd_vector(forward<Args>(args)...));
}
//
// Print from Iterator
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
//
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  int n;
  cin >> n;
  int ans = INT32_MAX;
  for (int i = 0; i <= n; i++) {
    int ci = i;
    int tem = 0;
    while (ci > 0)
      tem += ci % 6, ci /= 6;
    ci = n - i;
    while (ci > 0)
      tem += ci % 9, ci /= 9;
    chmin(ans, tem);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cmath>
#define inf 0x3f3f3f3f
#define PI acos((double)-1)
using namespace std;

typedef long long ll;
const int maxn=55;
struct node
{
    int vis[26];
};

node v[maxn];
char s[maxn][maxn];
int cnt[26];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%s",s[i]);
    for(int i=0;i<n;i++)
    {
        int len=strlen(s[i]);
        for(int j=0;j<len;j++)
        {
            v[i].vis[s[i][j]-'a']++;
        }
    }
    int num=0,flag=0;
    for(int i=0;i<26;i++)
    {
        num=0;
        for(int j=0;j<n;j++)
        {
            if(v[j].vis[i]>0)
                num++;
        }
        if(num==n)
        {
            flag=1;
            break;
        }
    }
    if(!flag)
    {
        cout << endl;
        return 0;
    }
    for(int i=0;i<26;i++)
    {
        num=0;
        int maxx=inf;
        for(int j=0;j<n;j++)
        {
            if(v[j].vis[i]>0)
            {
                num++;
                maxx=min(v[j].vis[i],maxx);
            }
        }
        if(num==n)
        {
            cnt[i]=maxx;
        }
    }
    for(int i=0;i<26;i++)
    {
        for(int j=0;j<cnt[i];j++)
            printf("%c",'a'+i);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N, A, B, i, num, sum = 0;
	scanf("%d %d %d", &N, &A, &B);

	for(i = 1; i <= N; i++) {
        num = i;
        int cont = 0;
		do {
			cont += num % 10;
			num /= 10;
		}while (num > 0);
		if (cont >= A && cont <= B)
			sum += i;
	}

	printf("%d", sum);

	return 0;
}



Measured memory_bytes: 128
/*
god taekyu
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n;
int A[100005], dp[100005];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>A[i];

    dp[2] = abs(A[2]-A[1]);
    for(int i=3;i<=n;i++) {
        dp[i] = min(dp[i-2] + abs(A[i] - A[i-2]) , dp[i-1] + abs(A[i] - A[i-1]));
    }
    cout<<dp[n];
    return 0;
}

/*
god taekyu
*/


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m=0;cin>>n;
  vector<string>w(n);
  for(int i=0;i<n;i++){
    cin>>w.at(i);
    if(i>0){
      if(w.at(i-1).at(w.at(i-1).size()-1)!=w.at(i).at(0)){
        cout<<"No"<<endl;
        m++;
      }
      else{
        for(int j=0;j<i;j++){
          if(w.at(j)==w.at(i)){
            cout<<"No"<<endl;
            m++;
            break;
          }
        }
      }
    }
    if(m>0)break;
  }
  if(m==0)cout<<"Yes"<<endl;
}
     
         
        

Measured memory_bytes: 256
import sys

def topological_sort(E, D):
    n = len(E)
    Q = [i for i in range(n) if D[i] == 0]
    L = []
    while Q:
        p = Q.pop()
        L.append(p)
        for vf in E[p]:
            D[vf] -= 1
            if not D[vf]:
                Q.append(vf)
    
    if len(L) != n:
        return False
    return L

N, M = map(int, input().split())
Edge = [[] for _ in range(N)]
Dim = [0]*N
for _ in range(M):
    x, y = map(int, sys.stdin.readline().split())
    x -= 1
    y -= 1
    Edge[x].append(y)
    Dim[y] += 1

dp = [0]*N

for v in topological_sort(Edge, Dim):
    d = dp[v] + 1
    for vf in Edge[v]:
        dp[vf] = max(dp[vf], d)

print(max(dp))

Measured memory_bytes: 60336
#include <iostream>
#include <vector>
#include <limits.h>

using namespace std;

const long long INF = 1e18L + 7;

struct Knapsack {
    int weight, value;
    Knapsack () : weight(-1) , value(-1) {}
    Knapsack (int w, int v) : weight(w), value(v) {}
};

long long getMaxValue (vector <Knapsack> &knapsack, int capacity) {
    if (knapsack.empty()) {
        return 0;
    }
    int n = knapsack.size(), totalValue = 0;

    for (auto &k : knapsack) {
        totalValue += k.value;
    }
    vector <long long> dp(totalValue + 1, INF);
    dp[0] = 0;
    
    for (int i = 0; i < n; ++i) {
        int currWeight = knapsack[i].weight;
        int currValue = knapsack[i].value;
        for (int v = totalValue; v >= currValue; --v) {
                dp[v] = min(dp[v], dp[v - currValue] + currWeight);
        }
    }
    long long result = 0;

    for (long long v = 0; v <= totalValue; ++v) {
        if (dp[v] <= capacity) {
            result = max(result, v);
        }
    }
    return result;
}

int  main () {
    int n = 0, capacity = 0;
    scanf("%d%d", &n, &capacity);
    vector <Knapsack> knapsack;
    for (int i = 0; i < n; ++i) {
        int w, v;
        scanf("%d%d", &w, &v);
        knapsack.emplace_back(Knapsack{w, v});
    }
    printf("%llu\n", getMaxValue(knapsack, capacity));
    return 0;
}

Measured memory_bytes: 1024