akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
struct UnionFind {
    vector<int> par, rank;
 
    UnionFind(int n) : par(n , -1), rank(n, 0) { }
    void init(int n) { par.assign(n, -1), rank.assign(n, 0); }
 
    int root(int x) {
        if (par[x] == -1) return x;
        else return par[x] = root(par[x]);
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
 
const int nmax = 8;
bool graph[nmax][nmax];
 
int dfs(int v, int N, bool visited[nmax]){
  bool all_visited = true;
  
  rep(i,N){
    if(visited[i]==false)
      all_visited = false;
  }
  if(all_visited) return 1;
  
  int ret=0;
  
  rep(i,N){
    if(graph[v][i] == false) continue;
    if(visited[i]) continue;
    
    visited[i] = true;
    ret += dfs(i,N,visited);
    visited[i] = false;
  }
  return ret;
}
 
int main(){
    int N,M;
  	cin >> N >> M;
  	rep(i,M) {
      int a,b;
      cin >> a >> b;
      graph[a-1][b-1] = graph[b-1][a-1] = true;
    }
  
  	bool visited[nmax];
  	rep(i,N) visited[i]=false;
  
  	visited[0] = true;
  	cout << dfs(0,N,visited) << endl;
}

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

using namespace std;

typedef long long ll;
const double eps=1e-6,pi=acos(-1);
const int N=1e5+5,M=1e9+7,SEGM=4*N,OO=0x3f3f3f3f;
int t,n,m;
vector<int> adj[N];
int mem[N];

int getMax(int u){
    int &ret=mem[u];
    if(~ret) return ret;
    ret=0;
    for(int v : adj[u])
        ret=max(ret,getMax(v)+1);
    return ret;
}

int main(){
    //freopen("myfile.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=0,u,v;i<m;++i){
        scanf("%d%d",&u,&v);
        adj[--u].push_back(--v);
    }
    memset(mem,-1,sizeof mem);
    int ans=0;
    for(int i=0;i<n;++i)
        ans=max(ans,getMax(i));
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 11520
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:String = read!();
    let mut v:Vec<char> = n.chars().collect();
    for i in 0..v.len() {
        if i%2 == 0 {
            if v[i]=='L' {
                println!("No");
                exit(0);
            }
        }
        else {
            if v[i]=='R' {
                println!("No");
                exit(0);
            }
        }
    }
    println!("Yes");
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    int N, M; cin >>N>>M;
    vector<pii> AB(N); cin >> AB; // A日後に報酬B
    
    int ans = 0;
    sort(all(AB));
    priority_queue<int> q;
    int i = 0;
    for (int m = 1; m <= M; m++) {
        for (; AB[i].first <= m; i++) {
            q.push(AB[i].second);
        }
        if (!q.empty()) {
            int b = q.top(); q.pop();
            ans += b;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1660
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<queue>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)

#define f first
#define s second

int main(){
	while(1){
		int n;
		cin>>n;
		
		if(n==0)break;
		
		set<vector<int> > ch;
		
		rep(pp,n){
			vector<int> a;
			rep(j,6){
				string sa;
				cin>>sa;
				switch(sa[0]){
					case 'C':a.push_back(0);break;
					case 'Y':a.push_back(1);break;
					case 'R':a.push_back(2);break;
					case 'M':a.push_back(3);break;
					case 'G':a.push_back(4);break;
					case 'B':a.push_back(5);break;
				}
			}
			
			rep(i,4){
				int temp=a[0];
				a[0]=a[4];
				a[4]=a[5];
				a[5]=a[1];
				a[1]=temp;
				
				rep(j,4){
					temp=a[0];
					a[0]=a[2];
					a[2]=a[5];
					a[5]=a[3];
					a[3]=temp;
					
					rep(k,4){
						temp=a[1];
						a[1]=a[2];
						a[2]=a[4];
						a[4]=a[3];
						a[3]=temp;
						
						ch.insert(a);
					}
				}
			}
			
		}
		
		printf("%d\n",(n-ch.size()/24));
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long int n,m;
  cin>>n>>m;
  long long int h[100001];
  for(long long int i=1;i<=n;i++){
    cin>>h[i];
  }
  
  long long int g[100001];
  for(long long int i=1;i<=n;i++){
    g[i]=1;
  }
  long long int c[100001];
  for(long long int i=1;i<=n;i++){
    c[i]=1;
  }

  long long int a[100001],b[100001];
  for(long long int j=1;j<=m;j++){
    cin>>a[j]>>b[j];
    if(h[a[j]]>h[b[j]]){
       g[a[j]]=1;
    }else{
      c[a[j]]=0;
    }
    if(h[a[j]]<h[b[j]]){
       g[b[j]]=1;
    }else{
      c[b[j]]=0;
    }
    
  }
  int l=0;
  for(long long int i=1;i<=n;i++){
    if(c[i] && g[i]){
      l++;
    }
  }
  cout<<l;

  
    

}

Measured memory_bytes: 7564
using System;
using System.Linq;

class Program {
    static void Main() {
        int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int m = n[0];
        int f = n[1];
        int b = n[2];
        if (m + f < b) {
            Console.WriteLine("NA");
        } else if (m >= b) {
            Console.WriteLine(0);
        } else {
            Console.WriteLine(b - m);
        }
    }
}


Measured memory_bytes: 9624
//#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int,int>;

#define MOD 1000000007
ll powll(ll x,ll t)
{
    if(!t) return 1;
    ll a = powll(x,t>>1);
    a*=a;
    if(t&1) a*= x;
    a %= MOD;
    return a;
}

int main(){
    int n;
    int zero = 0;
    map<pair<ll,ll>,P> mp;
    cin >> n;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if(x == 0 && y == 0) {
            zero++;
            continue;
        }
        ll g= gcd(x,y);
        x /= g;
        y /= g;
        if(y < 0) x = -x, y = -y;
        bool rot90 = (x<=0);
        if(rot90){
            ll temp = x;
            x = y;y = -temp;
        }
        if(rot90) mp[{x,y}].first++;
        else mp[{x,y}].second++;
    }
    ll ans = 1;
    for(auto p:mp){
        int s = p.second.first;
        int t = p.second.second;
        ll now = 1;
        now += powll((ll)2,s) -1;
        now += powll((ll)2,t) -1;
        ans *= now;
        ans %= MOD;
    }
    ans-=1;
    ans += (zero + MOD);
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15920
N = int(raw_input())
A = map(int, raw_input().split())

result = 1
flagFirst = True
status = "same"

for i in range(len(A) - 1):
    if flagFirst:
        flagFirst = False
        if A[i] < A[i + 1]:
            status = "up"
        elif A[i] == A[i + 1]:
            status = "same"
        else:
            status = "down"
    else:
        if ((A[i] < A[i + 1]) and status == "down") or (A[i] > A[i + 1] and status == "up"):
            flagFirst = True
            result += 1
        if status == "same":
            if A[i] < A[i + 1]:
                status = "up"
            elif A[i] > A[i + 1]:
                status = "down"

print(result)

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

int main() {
    int N; cin >> N;
    int a = N % 10;
    if(a == 3) cout << "bon" << '\n';
    else if(a == 0 or a == 1 or a == 6 or a == 8) cout << "pon" << '\n';
    else cout << "hon" << '\n';
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	int a,b,c;
	string s,t;
	vi v;
	cin>>a>>b>>c;
	if(a*b<c)
cout<<a*b;
else
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

using Edge = pair<int,int>; // (隣接頂点, 辺番号)
using Graph = vector<vector<Edge>>;

int main(){
    int N;
    cin >> N;
    Graph G(N,vector<Edge>());
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(make_pair(b,i));
        G[b].push_back(make_pair(a,i));
    }
    int cnt=0;
    rep(i,N) cnt = max(cnt,(int)G[i].size());
    cout << cnt << endl;
    deque<pair<int,int>> dq;
    dq.push_back(make_pair(0,-1));
    vector<int> seen(N);
    while(!dq.empty()){
        auto p = dq.front(); dq.pop_front();
        int node = p.first;
        int c = p.second;
        int num = 1;
        for(int i=0;i<G[node].size();i++){
            int n_node = G[node][i].first;
            int n_edge = G[node][i].second;
            if(seen[n_edge]>0){
                continue;
            }
            if(num==c){
                num++;
            }
            dq.push_back(make_pair(n_node,num));
            seen[n_edge] = num;
            num++;
        }
    }
    rep(i,N-1) cout << seen[i] << endl;
    return 0;
}

Measured memory_bytes: 9772
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    string s; cin >> s;
    if(s[s.size()-1] == 's'){
        cout << s << "es" << endl;
    }
    else{
        cout << s << "s" << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int A[100200] = {};

int main(void) {

	int X;
	cin >> X;

	if (X >= 2000) {
		COUT(1);
	}
	else {
		if (X % 100 <= (X / 100) * 5) {
			COUT(1);
		}
		else {
			COUT(0);
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <queue>
using namespace std;

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

#if 0
char str[512];
int num_queries;

int query(const char *s) {
  num_queries++; 
  vector<int> edit[130];
  int n = strlen(s);
  FOR(i,130) edit[i].resize(n+2, 123456789);
  edit[0][0] = 0;
  for (int i = 0; i < 129; i++)
    for (int j = 0; j < n+1; j++) {
      if (s[j] == str[i]) edit[i+1][j+1] = min(edit[i+1][j+1], edit[i][j]);
      edit[i+1][j] = min(edit[i+1][j], edit[i][j]+1);
      edit[i][j+1] = min(edit[i][j+1], edit[i][j]+1);
      edit[i+1][j+1] = min(edit[i+1][j+1], edit[i][j]+1);
    }
  //fprintf(stdout, "query %s = %i\n", s, edit[128][n]);
  return edit[128][n];
}

void answer(const char *s) {
  if (strcmp(s, str)) {
    printf("failed after %i queries\n", num_queries);
    printf("string was %s\n", str);
    exit(-1);
  }
  printf("%i guesses to find %s\n", num_queries, str);
}
#else
int query(const char *s) {
  printf("? %s\n", s); fflush(stdout);
  int ans;
  scanf("%i", &ans);
  return ans;
}
void answer(const char *s) {
  printf("! %s\n", s); fflush(stdout);
  exit(0);
}
#endif

string merge(string s, string t) {
  string ans;
  int cur = query(t.c_str());
  while (s.size() && t.size()) {
    string here = ans + s[0] + t;
    int qhere = query(here.c_str());
    if (qhere < cur) cur = qhere, ans += s[0], s = s.substr(1);
    else ans += t[0], t = t.substr(1);
  }
  return ans + s + t;
}

void doit() {
  vector<string> strings;
  string allchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ0123456789";
  for (char c : allchars) {
    int cnt = query(string(128, c).c_str());
    if (cnt < 128) {
      strings.push_back(string(128-cnt, c));
    }
  }
  while (strings.size() > 1) {
    std::sort(strings.begin(), strings.end(), [](const string &a, const string &b) { return a.size()>b.size();});
    string a = strings.back(); strings.pop_back();
    string b = strings.back(); strings.pop_back();
    strings.push_back(merge(a, b));

  }
  answer(strings[0].c_str());
}

int main() {
  while (1) {
    #if 0
    FOR(i,128) str[i] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ0123456789"[rand()%62];
    num_queries = 0;
    #endif
    doit();
  }
}


Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	int a[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	bool b = true;
	for (int i = 0; i < 2; i++) {
		if (a[0][i + 1] - a[0][i] != a[1][i + 1] - a[1][i] || a[1][i + 1] - a[1][i] != a[2][i + 1] - a[2][i]) b = false;
		if (a[i+1][0] - a[i][0] != a[i+1][1] - a[i][1] || a[i+1][1] - a[i][1] != a[i+1][2] - a[i][2]) b = false;
	}
	if (b) cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int a,s,d,f,g,h,i,j;
	scanf("%d %d %d",&a,&s,&d);
	if(a==1&&s==1||d==1){
		printf("Open\n");
	}
	else{
		printf("Close\n");
	}
	return 0;
}

Measured memory_bytes: 1012
##たて a cm よこ b cm の長方形の面積と周の長さを求めるプログラムを作成して下さい。
#Input
#a と b が１つの空白で区切られて与えられます。
a,b = map(int, input().split())
s = a * b
l = 2 * (a + b)
print('{} {}'.format(s, l))


Measured memory_bytes: 5580
import math
import sys
import itertools
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
XY = [[float(x) for x in input().split()] for _ in range(N)]

ans = 1500.
eps = 10. ** -8


def circumcenter(A, B, C):
    ax = A[0]
    ay = A[1]
    bx = B[0]
    by = B[1]
    cx = C[0]
    cy = C[1]
    d = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by))

    if d == 0.:
        return None

    ux = ((ax * ax + ay * ay) * (by - cy) + (bx * bx + by * by)
          * (cy - ay) + (cx * cx + cy * cy) * (ay - by)) / d
    uy = ((ax * ax + ay * ay) * (cx - bx) + (bx * bx + by * by)
          * (ax - cx) + (cx * cx + cy * cy) * (bx - ax)) / d
    return (ux, uy)


def check(center_x, center_y, R2):
    ok = True
    for x, y in XY:
        d = (center_x - x) ** 2. + (center_y - y) ** 2.
        if R2 + eps < d:
            ok = False
            break

    return ok


# 2点
for i, j in itertools.combinations(range(N), 2):
    ax, ay = XY[i]
    bx, by = XY[j]

    center_x = (ax + bx) / 2.
    center_y = (ay + by) / 2.
    R2 = (ax - center_x) ** 2 + (ay - center_y) ** 2
    R = math.sqrt(R2)

    if check(center_x, center_y, R2):
        ans = min(R, ans)


# 3点
for a, b, c in itertools.combinations(range(N), 3):
    d = circumcenter(XY[a], XY[b], XY[c])

    if d is None:
        continue

    center_x = d[0]
    center_y = d[1]

    ax = XY[a][0]
    ay = XY[a][1]
    R2 = (ax - center_x) ** 2. + (ay - center_y) ** 2.
    R = math.sqrt(R2)

    ok = check(center_x, center_y, R2)

    if check(center_x, center_y, R2):
        ans = min(ans, R)

print(ans)


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


int main() {
    bool h[100004] = {};
    h[0] = true;
    h[1] = true;

    for(int i = 2; i < 100004; i++) {

        if(h[i] == true || i * 2 > 100003) continue;
        for(int j = i * 2; j < 100004; j += i) {
            h[j] = true;
        }
    }

    int x;
    cin >> x;
    for(int i = x; i < 100004; i++) {
        if(h[i] == false) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*********************************************START**************************************************************************/



int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T = 1;
	//int T;
	//cin >> T;
	// cin.ignore(); //must be there when using getline(cin, s)
	while (T--)
	{
		int n; cin >> n; 
		string a , b; 
		cin >> a >> b; 
		for(int i=0; i<n; i++){
			cout << a[i] << b[i]; 
		}cout << endl; 
	}
	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	int N, X, ans=1;
	scanf("%d %d", &N, &X);
	int curr = 0;
	for (size_t i = 0; i < N; i++)
	{
		int temp;
		scanf("%d", &temp);
		curr += temp;
		if (curr <= X) ans++;
	}
	printf("%d", ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;

int h, w, n;
char field[1024][1024];

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

int bfs(char st, char en)
{
	static int minTime[1024][1024];
	queue<P> q;
	
	memset(minTime, -1, sizeof(minTime));
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (field[i][j] == st){
				q.push(P(i, j));
				minTime[i][j] = 0;
			}
		}
	}
	
	for (; !q.empty(); q.pop()){
		P now = q.front();
		if (field[now.first][now.second] == en) return (minTime[now.first][now.second]);
		
		for (int i = 0; i < 4; i++){
			int ny = now.first + dy[i], nx = now.second + dx[i];
			if (0 <= ny && ny < h && 0 <= nx && nx < w && minTime[ny][nx] == -1 && field[ny][nx] != 'X'){
				minTime[ny][nx] = minTime[now.first][now.second] + 1;
				q.push(P(ny, nx));
			}
		}
	}
	return (-1);
}

int main()
{
	scanf("%d %d %d", &h, &w, &n);
	
	for (int i = 0; i < h; i++){
		scanf("%s", field[i]);
	}
	
	int cost = bfs('S', '1');
	
	for (int i = 1; i < n; i++){
		cost += bfs(i + '0', i + 1 + '0');
	}
	
	printf("%d\n", cost);
	
	return (0);
}

Measured memory_bytes: 6156
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(H);
    scanInt(W);
    scanInt(N);
    scanVecInt(A, N);
    vector<vector<int>> result(H, vector<int>(W));
    int i = 0;
    int j = 0;
    loop(h, H){
        loop(w, W){
            if (h % 2 == 0){
                result[h][w] = i + 1;
            }else{
                result[h][W - 1 - w] = i + 1;
            }
            ++j;
            if (A[i] <= j){
                ++i;
                j = 0;
            }
        }
    }
    loop(h, H){
        loop(w, W - 1){
            printf("%d ", result[h][w]);
        }
        printf("%d\n", result[h][W - 1]);
    }
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int a,b;
  cin >> a >> b;
  if(a%3==0 || b%3==0 || (a+b)%3==0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
x = [list(map(int, input().split()))for _ in range(N)]
ans = 0
if M == 0:
    print(0)
    exit(0)
for i in range(8):
    m = [0] * 3
    arr = [0] * N
    for j in range(N):
        for k in range(3):
            if (i >> k) & 1:
                arr[j] += x[j][k]
            else:
                arr[j] -= x[j][k]
    arr.sort()
    ans = max(ans, sum(arr[-M:]))
print(ans)


Measured memory_bytes: 3316
import sys
stdin = sys.stdin
sys.setrecursionlimit(100001)
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
fact = 1
for i in range(2, n+1):
        fact = (i * fact) % mod

print(fact)

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

int main(){

  int N,X,ans=1,num=0;
  cin >> N >> X;
  int L[N];
  for(int i=0; i<N; i++) cin >> L[i];

  for(int i=0; i<N; i++){
    num += L[i];
    if(X<num) break;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


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

long long a, b;
long long cal(long long x){
	if(x<=0)	return 0;
	if(x % 4 == 3)	return 0;
	else if(x % 4 == 1)	return 1;
	else if(x%4 == 0)	return x;
	else	return x+1;
}
int main() {
	cin>>a>>b;
	cout<<(cal(b)^cal(a-1));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int A, B;
  cin >> A >> B;
  if(A + B == 15)cout << '+' << endl;
  else if(A * B == 15)cout << '*' << endl;
  else cout << 'x' << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    int p[n];

    for (int i = 0; i <n ; ++i) {
        scanf("%d", &p[i]);
    }
    int k=0;
    for (int i = 0; i <n ; ++i) {
        if(p[i]!=i+1) k++;
    }
    if(k <= 2) puts("YES");
    else
        puts("NO");
}

Measured memory_bytes: 128
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,c,d;
    c = 0;
    d = 0;
    scanf("%d %d",&a,&b);
    while(a != 0 && b !=0){
        while(a > d){
            while(b > c){
                printf("#");
                c ++;
            }
            printf("\n");
            c = 0;
            d ++;
        }
        printf("\n");
        d = 0;
        scanf("%d %d",&a,&b);
    }
    return 0;
}



Measured memory_bytes: 2104
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

INF = 1 << 60

N = read()
A = reads()

maxf = [-1] * (3*N+1)
minl = [INF] * (3*N+1)

hp = A[:N]; heapify(hp)
maxf[N] = sum(hp)
for i in range(N, 2*N):
  removed = heappushpop(hp, A[i])
  maxf[i+1] = maxf[i] + A[i] - removed

hp = [-x for x in A[2*N:]]; heapify(hp)
minl[2*N] = -sum(hp)
for i in range(2*N-1, N-1, -1):
  removed = -heappushpop(hp, -A[i])
  minl[i] = minl[i+1] + A[i] - removed

ans = max(maxf[i] - minl[i] for i in range(N, 2*N+1))
print(ans)

Measured memory_bytes: 121760
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int> 

int main(){
  int N, M; cin >> N >> M;
  int P[M], Y[M];
  vector<vector<int>> YM(100010);
  rep(i,M){
    cin >> P[i] >> Y[i];
    YM.at(P[i]).push_back(Y[i]);
  }

  rep(i,N+1) sort(all(YM.at(i)));

  rep(i,M){
    auto x = lower_bound(all(YM.at(P[i])),Y[i]) - YM[P[i]].begin();
    //cout << P[i] << " " << 1+int(x) << endl;
    //printf("%06d",P[i]);
    //printf("%06d",int(x)+1);
    //printf("\n");
    printf("%012lld\n",ll(P[i])*1000000+ll(x)+1);
  }

  return 0;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	cout<<(n+1)/2<<endl;
	return 0;
}


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////

const int N = 5e3 + 5;

int S[N], F[N], DP[2][N][N], PD[2][N];
vector<int> G[N];

void DFS(int v, int p = 0) {
	S[v] = 1;
	DP[0][v][1] = 1;
	memset(PD, 0, sizeof PD);
	for (int u : G[v]) if (u != p) {
		DFS(u, v);
		for (int i = 0; i <= S[v]; i++) for (int j = 0; j <= S[u]; j++)
			for (int k = 0; k < 2; k++) for (int t = 0; t < 2; t++) 
				PD[(k + t) % 2][i + j] = (PD[(k + t) % 2][i + j] + 1LL * DP[k][v][i] * DP[t][u][j] % MOD) % MOD,
				PD[(k + t + 1) % 2][i] = (PD[(k + t + 1) % 2][i] + 1LL * DP[k][v][i] * (1LL * F[j] * DP[t][u][j] % MOD) % MOD) % MOD;  
		S[v] += S[u];
		for (int i = 0; i < 2; i++) for (int j = 0; j <= S[v]; j++) DP[i][v][j] = PD[i][j], PD[i][j] = 0;
	}
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	F[0] = 1;
	for (int i = 2; i < N; i += 2) F[i] = 1LL * F[i - 2] * (i - 1) % MOD;

	int n; cin >> n;
	for (int i = 1; i < n; i++) {
		int v, u; cin >> v >> u;
		G[v].push_back(u), G[u].push_back(v);
	}
	DFS(1);
	int ans = 0;
	for (int i = 1; i <= n; i++) ans = (ans + 1LL * F[i] * (DP[0][1][i] + MOD - DP[1][1][i]) % MOD) % MOD;
	cout << ans << endl;

	return 0;
}


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

using ll=long long;
const ll PLUS=-1;
const ll MINUS=-2;

const ll INF=1e15;
int main(){
    int n;
    cin>>n;
    vector<ll> aop(n*2-1);
    for(int i=0;i<2*n-1;i++){
        string x;
        cin>>x;
        if(x=="+"){
            aop[i]=PLUS;
        }
        else if(x=="-"){
            aop[i]=MINUS;
        }
        else{
            aop[i]=stoi(x);
        }
    }
    vector<vector<ll>> dp(2*n,vector<ll>(3,-INF));
    dp[0][0]=0;
    for(int i=0;i<2*n-1;i++){
        for(int j=0;j<3;j++){
            if(aop[i]==PLUS){
                dp[i+1][j]=dp[i][j];
            }
            else if(aop[i]==MINUS){
                if(j!=2) dp[i+1][j+1]=dp[i][j];
            }
            else{
                if(j%2){
                    for(int k=0;k<=j;k++){
                        dp[i+1][k]=max(dp[i+1][k],dp[i][j]-aop[i]);
                    }
                }
                else{
                    for(int k=0;k<=j;k++){
                        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+aop[i]);
                    }
                }
                
            }
        }
    }
    cout<<dp[2*n-1][0]<<endl;
    return 0;
}

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

using namespace std;

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

 string s;
  cin >> s;
 int n=s.length(); 
  
  if(n<26){
   for(char c='a';c<='z';c++){
    if(s.find(c)==string::npos) {
      cout << s << c << endl;
      return 0;
    }
    }
  }
  else {
    for(int i=n-2;i>=0;i--){ 
     if(s[i]<s[i+1]){
      char b=s[i+1];
       for(int j=i+1;j<n;j++) if(s[j]>s[i]) b=min(b,s[j]);
     
      s[i]=b;
      s=s.substr(0,i+1);
      cout << s << endl;
      return 0;
    }
    }
  
  cout << -1 << endl; 
  }
  }


Measured memory_bytes: 256
import math
H = float(input())
enemy_list = [H, 1]
attack_times = 0
while (len(enemy_list) > 0):
  enemy_hp = enemy_list[0]
  enemy_num = enemy_list[1]
  attack_times += enemy_num
  if (enemy_hp == 1):
    enemy_list = []
  if (enemy_hp > 1):    
    new_enemy_hp = math.floor(enemy_hp/2)
    new_enemy_num = enemy_num * 2
    enemy_list[0] = new_enemy_hp
    enemy_list[1] = new_enemy_num
print(attack_times)

Measured memory_bytes: 62196
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

struct edge{int to, cost;};
const int VV=222222;
int V,M;
vector<edge> G[VV];
int d[VV];

void dijkstra(int s){
    // 最短距離firstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d,d+V,INF);
    d[s] = 0;
    que.push(P(0,s));

    while(que.size()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i < G[v].size();i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>V>>M;
    REP(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back({b,1});
        G[b].push_back({a,1});
    }
    dijkstra(0);
    if(d[V-1]==2) puts("POSSIBLE");
    else puts("IMPOSSIBLE");

}

Measured memory_bytes: 15592
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, A, B = lr()
time = N // (A+B)
remain = N - (A+B) * time
answer = A * time + min(A, remain)
print(answer)


Measured memory_bytes: 3060
//Plush Toys
#include <iostream>
#include <climits>

using namespace std;

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

    int A[N + 1], cumsum[M][N + 1];
    for(int i = 0; i < M; i++) {
        for(int j = 0; j < N + 1; j++) {
            cumsum[i][j] = 0;
        }
    }

    for (int i = 1; i < N + 1; i++) {
        cin >> A[i];
        A[i]--;
        cumsum[A[i]][i]++;
    }

    for(int i = 0; i < M; i++) {
        for(int j = 1; j < N + 1; j++) {
            cumsum[i][j] += cumsum[i][j - 1];
        }
    }

    int dp[1 << M];
    for(int i = 0; i < (1 << M); i++) dp[i] = INT_MAX;
    dp[0] = 0;
    for(int s = 0; s < (1 << M); s++) {
        int p = 0;
        for(int i = 0; i < M; i++) {
            if(s & 1 << i) p += cumsum[i][N];
        }
        for(int i = 0; i < M; i++) {
            if(s & 1 << i) continue;
            int cost = dp[s] + (cumsum[i][N] - cumsum[i][p + cumsum[i][N]] + cumsum[i][p]);
            dp[s + (1 << i)] = min(dp[s + (1 << i)], cost);
        }
    }

    cout << dp[(1 << M) - 1] << endl;
}


Measured memory_bytes: 15388
#include<iostream>
#include<vector>
#include<utility>
using namespace std;

int main(){
    int V, E;
    cin >> V >> E;
    vector<pair<int, int> > edge(E);
    for (int i = 0; i < E; i++) {
        cin >> edge[i].first >> edge[i].second;
    }
    vector<int> ans;
    vector<int> state(V, 1);
//0: edge[i].secondに載っているため設定できない
//1: 設定できる状態
//2: すでに設定済みなので除外

    

    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            if (state[i] != 2) state[i] = 1;
        }
        for (int i = 0; i < edge.size(); i++) {
            state[edge[i].second] = 0;
        }
        for (int i = 0; i < V; i++) {
            if (state[i] == 1) {
                ans.push_back(i);
                state[i] = 2;
                for (int j = 0; j < edge.size(); j++) {
                    if (edge[j].first == i) {
                        edge[j] = edge.back();
                        edge.pop_back();
                        j--;
                    }
                }
                break;
            }
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3440
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  int n,m,x,y;
  cin>>n>>m>>x>>y;
  int xMax = -101;
  int yMin = 101;
  REP(i,n){
    int t;
    cin>>t;
    xMax = max(t,xMax);
  }
  REP(i,m){
    int t;
    cin>>t;
    yMin = min(t,yMin);
  }
  if(xMax>=yMin||xMax>=y||yMin<=x){
    cout<<"War"<<endl;
  }else{
    cout<<"No War"<<endl;
  }
  

    return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1, 1, 1, -1, -1};
int ix[]={1, -1, 0, 0, 1, -1, -1, 1};

int n, m;
string s[55];


int main(){
	cin >> n >> m;
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='.'){
				int a=0;
				for(int k=0;k<8;k++){
					if((i+iy[k]>=0&&i+iy[k]<n)&&(j+ix[k]>=0&&j+ix[k]<m)){
						if(s[i+iy[k]][j+ix[k]]=='#')a++;
					}
				s[i][j]=a+'0';
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		cout << s[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
constexpr int N = 25;
constexpr int P[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int I[N];
int main()
{
    int Q;
    std::cin >> Q;
    for (int i = 0; i < N; i++) {
        for (int n = Q; n > 0; n /= P[i]) { I[i] += n / P[i]; }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (I[i] >= 74) { ans++; }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) { continue; }
            if (I[i] >= 24 and I[j] >= 2) { ans++; }
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) { continue; }
            if (I[i] >= 14 and I[j] >= 4) { ans++; }
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            for (int k = 0; k < N; k++) {
                if (i == k or j == k) { continue; }
                if (I[i] >= 4 and I[j] >= 4 and I[k] >= 2) { ans++; }
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
//This Code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<time.h>
// #include<windows.h>
#define int long long
#define PI 3.14159265358979323
#define INF 0x3fffffffffffffff
using namespace std;
int n,k,p[5005],c[5005],dis[5005],dfn[5005],ans=-INF;
signed main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;++i)
    {
        cin>>p[i];
    }
    for(int i=1;i<=n;++i)
    {
        cin>>c[i];
    }
    for(int i=1;i<=n;++i)
    {
        fill(dis+1,dis+1+n,0);
        fill(dfn+1,dfn+1+n,0);
        int now=p[i],v=c[now],tim=1;
        dis[now]=v;
        dfn[now]=tim;
        ans=max(ans,v);
        while(v>0&&tim<k)
        {
            ++tim;
            now=p[now];
            v+=c[now];
            ans=max(v,ans);
            if(dis[now])
            {
                if(dis[now]<v)
                {
                    int len=tim-dfn[now],sum=v-dis[now];
                    int cnt=(k-tim)/len;
                    tim+=len*cnt;
                    v+=cnt*sum;
                    ans=max(ans,v);
                    while(tim<k)
                    {
                        ++tim;
                        now=p[now];
                        v+=c[now];
                        ans=max(ans,v);
                    }
                }
            }
            else
            {
                dfn[now]=tim;
                dis[now]=v;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3808
#include<cstdio>


void max_u(int&m, int v)
{
	if(m<v) m=v;
}


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		int ans=-1;

		for(int i=1;i*i<=m;i++)
		{
			if(m%i==0)
			{
				int d=m/i;
				if(i>=n) max_u(ans, d);
				if(d>=n) max_u(ans, i);
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
    clock_t start = clock();
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //const ll p = 1e9 + 7;
    //const ll p = 998244353;
    
    ll d; cin >> d;
    vector<ll> c(26);
    for (ll i = 0; i < 26; i++) cin >> c[i];
    vector<vector<ll>> s(d, vector<ll>(26));
    for (ll i = 0; i < d; i++) {
        for (ll j = 0; j < 26; j++) cin >> s[i][j];
    }
    
    vector<ll> w(0);
    for (ll i = 0; i < 26; i++) {
        w.push_back(i);
        for (ll j = 0; j < c[i]; j++) w.push_back(i);
    }
    ll m = w.size();
    
    vector<ll> t(d);
    random_device rand;
    for (ll i = 0; i < d; i++) t[i] = w[rand() % m];
    
    ll score = 0;
    {
        vector<ll> v(26, -1);
        for (ll i = 0; i < d; i++) {
            v[t[i]] = i;
            score += s[i][t[i]];
            for (ll j = 0; j < 26; j++) score -= c[j] * (i - v[j]);
        }
    }
    
    vector<set<ll>> v(26);
    for (ll i = 0; i < 26; i++) v[i].insert(-1);
    for (ll i = 0; i < d; i++) v[t[i]].insert(i);
    for (ll i = 0; i < 26; i++) v[i].insert(d);
    
    auto modified_score = [&] (ll day, ll into) {
        ll ret = score;
        ret += s[day][into] - s[day][t[day]];
        auto itr1 = v[t[day]].find(day);
        ll p = *(--itr1), q = *(++itr1), r = *(++itr1);
        ret += ((q - p) * (q - p - 1) + (r - q) * (r - q - 1)) * c[t[day]] / 2;
        ret -= (r - p) * (r - p - 1) * c[t[day]] / 2;
        auto itr2 = v[into].upper_bound(day);
        p = *(--itr2); q = day; r = *(++itr2);
        ret -= ((q - p) * (q - p - 1) + (r - q) * (r - q - 1)) * c[into] / 2;
        ret += (r - p) * (r - p - 1) * c[into] / 2;
        return ret;
    };
    
    while (clock() - start <= 1.95 * CLOCKS_PER_SEC) {
        ll day = rand() % d, into = w[rand() % m];
        ll x = modified_score(day, into);
        if (x >= score) {
            score = x;
            v[t[day]].erase(day);
            v[into].insert(day);
            t[day] = into;
        }
    }
    
    for (ll i = 0; i < d; i++) cout << t[i] + 1 << endl;
    xout << score << endl;
}

Measured memory_bytes: 3764
//d
#include <iostream>
using namespace std;
const int aa=100001;
int main(){

    int N,Q,B,C,A;
    cin>>N;
    int ct[aa];
    for(int i=0;i<aa;i++){
        ct[i]=0;
    }
    long long int total=0;
    for(int i=0;i<N;i++){
        cin>>A;
        total+=A;
        ct[A]++;
    }
    cin >>Q;
    for(int i=0;i<Q ;i++){
        cin>>B>>C;
        int temp=C-B;
        total+=temp*ct[B];
        cout<<total<<endl;
        ct[C]+=ct[B];
        ct[B]=0;
    }
}

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

int n, f[110], p[110][11];


int main(){
  cin >> n;
  rep(i, n){
    int val = 0;
    rep(j, 10){
      int tmp;
      cin >> tmp;
      val *= 2;
      val += tmp;
    }
    f[i] = val;
  }
  
  //rep(i, n) cerr << bitset<32>(f[i]) << endl;
  //rep(i, n) cerr << val[i] << " ";
  //rep(i, 11) cerr << i << " "; cerr << endl;
  
  rep(i, n){
    rep(j, 11){
      cin >> p[i][j];
    }
  }
  
  //rep(i, n){rep(j, 11) cerr << p[i][j]; cerr << endl;
  
  int res = -1000000000;
  for(int S = 1; S < (1 << 10); S++){
    int sum = 0;
    rep(i, n){
      int num = p[i][__builtin_popcount(S & f[i])];
      sum += num;
    }
    res = max(sum, res);
  }   
  cout << res << endl;
  //cout << __builtin_popcount(a) << endl;
  return 0;
}


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

int main(){

    string s;
    cin >> s;


    if(s[0] == s[1]|| s[1] == s[2]|| s[2] == s[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const LL INF=1e9;

int main(){
    int N;
    cin>>N;
    vector<int>A(N+2);
    A[0]=A[N+1]=0;
    int sum=0;
    REP(i,N){
        cin>>A[i+1];
        sum+=abs(A[i+1]-A[i]);
    }
    sum+=abs(A[N+1]-A[N]);
    FOR(i,1,N+1){
        cout<<sum-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1])<<endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M), a(N + 1, 0), b(M + 1, 0);
    rep(i, N) {
        cin >> A[i];
        a[i + 1] = A[i];
    }

    rep(i, M) {
        cin >> B[i];
        b[i + 1] = B[i];
    }

    rep(i, N) { a[i + 1] += a[i]; }
    rep(i, M) { b[i + 1] += b[i]; }

    ll ans = 0;
    rep(i, N + 1) {
        ll kk = K - a[i];
        if (kk < 0)
            continue;
        ll itr = upper_bound(all(b), kk) - b.begin() - 1;
        ans = max(ans, itr + i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 9516