akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdlib>
#include <sstream>
using namespace std;
string itos(unsigned long long x){stringstream ss; ss<<x;return ss.str();}


string simulate(unsigned long long l,unsigned long long r){
	stringstream ss;
	while( l < r ){
		ss << (l%15==0?"FizzBuzz":l%3==0?"Fizz":l%5==0?"Buzz":itos(l));
		l++;
	}
	return ss.str();
}
vector<unsigned long long> border;
int f(unsigned long long x){
	unsigned long long ten = 10;
	border.push_back(0);
	for(int i = 1 ; i <= 18 ; i++){
		border.push_back(ten);
		border.push_back(ten+(15-ten%15)%15);
		ten *= 10;
		border.push_back(ten-ten%15);
	}
	//for(int i = 0 ; i < border.size() ; i++) cout << border[i] << endl;
	
	for(int i = 0 ; i + 1 < border.size() ; i++){
		unsigned long long from = border[i];
		unsigned long long to   = border[i+1];
		if( to - from < 20 ){
			string str = simulate(from,to);
			unsigned long long sz = str.size();
			if( x <= sz ){
				cout << simulate(from,from+100).substr(x,20) << endl;
				exit(0);
			}else x -= sz;
		}else{
			int len = itos(from).size();
			unsigned long long sub = 32 + len * 8;
			unsigned long long sz = sub * (to-from) / 15;
			if( x <= sz){
				long long superFrom = from + 15 * (x / sub);
				x %= sub;
				cout << simulate(superFrom,superFrom+100).substr(x,20) << endl;
				exit(0);
			}else x -= sz;			
		}
		
	}
}


int main(){
	long long n;
	cin >> n;
	n--;
	n += 8;
	f(n);
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    int a,p;
    cin >> a >> p;
    
    p += 3*a;
    
    cout << p/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
	int sieve[1000000] = {'0'};
	int i,j,n,t;
	
  sieve[0] = sieve[1] = 1;
  for (i = 2; i * i <= 1000000; i++){
    
    for (j = i*2; j <= 1000000; j += i){
      sieve[j] = 1;
    }
  }
  while(scanf("%d", &n) != EOF){
  	t = 0;
  for(i=1; i<=n ;i++){
  	if(sieve[i] == 0)t++;
  }
  printf("%d\n", t);
  }
  return (0);
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int a[4],b[4];
  while(~scanf("%d%d%d%d%d%d%d%d",a,a+1,a+2,a+3,b,b+1,b+2,b+3)){
    int hit = 0;
    REP(i,4)if(a[i]==b[i])++hit;
    set<int> S;
    REP(i,4)S.insert(a[i]);
    int blow = -hit;
    REP(i,4)if(S.find(b[i])!=S.end())++blow;
    printf("%d %d\n",hit,blow);
  }
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000000
void chmax(ll &x,ll y){x = x>y ? x:y;}
void chmin(ll &x,ll y){x = x<y ? x:y;}
ll dpa[100010],dpb[100010],dpc[100010];

int main()
{
  ll N;cin>>N;
  ll a[N],b[N],c[N];
  for(ll i=0;i<N;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  for(ll i=0;i<100010;i++)dpa[i]=dpb[i]=dpc[i]=-INF;
  dpa[0]=a[0];
  dpb[0]=b[0];
  dpc[0]=c[0];
  for(ll i=1;i<N;i++){
    chmax(dpa[i],dpb[i-1]+a[i]);
    chmax(dpa[i],dpc[i-1]+a[i]);
    chmax(dpb[i],dpc[i-1]+b[i]);
    chmax(dpb[i],dpa[i-1]+b[i]);
    chmax(dpc[i],dpa[i-1]+c[i]);
    chmax(dpc[i],dpb[i-1]+c[i]);
  }
  ll ans=-INF;
  chmax(ans,dpa[N-1]);
  chmax(ans,dpb[N-1]);
  chmax(ans,dpc[N-1]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
char str[maxn];
int  main(){
     scanf("%s",str+1);
     if(str[3]==str[4]&&str[5]==str[6]){
        puts("Yes");
     }
     else{
        puts("No");
     }
    return 0;
}

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

int main() {
        ll n, d, x, y, ans;
        ans = 0;
        cin >> n >> d;
        rep(i,n) {
                cin >> x >> y;
                if (x*x+y*y <= d*d) {
                        ++ans;
                }
        }
        cout << ans << endl;
}

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

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3, y3, x4, y4;
  x3 = x2 - y2 + y1;
  y3 = x2 + y2 - x1;
  x4 = x3 - y3 + y2;
  y4 = x3 + y3 - x2;
  cout << x3 << ' ' <<y3 << ' ' << x4<< ' '  <<y4 << endl;
}
  
  

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

int card[255][14] = {{0}};

int main(void){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        char c;
        int num;
        cin >> c >> num;
        card[(int)c][num] = 1;
    }
    for(int i = 1; i <= 13; i++){
        if(card[(int)'S'][i] == 0){
            cout << "S " << i << endl;
        }
    }
    for(int i = 1; i <= 13; i++){
        if(card[(int)'H'][i] == 0){
            cout << "H " << i << endl;
        }
    }
    for(int i = 1; i <= 13; i++){
        if(card[(int)'C'][i] == 0){
            cout << "C " << i << endl;
        }
    }
    for(int i = 1; i <= 13; i++){
        if(card[(int)'D'][i] == 0){
            cout << "D " << i << endl;
        }
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
double w,h,x,y;
  cin >>w>> h>> x >> y;
double ans = w*h/2;
  
  if(x==w/2.0 && y==h/2.0)
    cout << ans << " "<< 1  <<endl;
  else
    cout << ans << " "<<0<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  string a;
  cin>>h>>w;
  for(int i=0; i<=h+1; i++){
    for(int j=0; j<=w+1; j++){
      if(i==0|i==h+1){cout<<"#";} else {continue;}
    }
    if(i!=h+1&&i!=0){
      cout<<"#";
      cin>>a; cout<<a;
      cout<<"#";
    }
    cout<<endl;
  }
}

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

int main(){
    int a , b , c , ans =0;
    cin >> a >> b >> c;
    if(a == b){
        ans++;
    }
    if(a == c){
        ans++;
    }
    if(b == c){
        ans++;
    }
    if(ans == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int ans = 1;  
  for(int i = 1; i < N; i++){
    if(S[i] != S[i-1]){
      //cout << S[i] << " ";
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
import math
a, b, h, m = map(int, input().split())
time = m + h*60
angle = time * 0.5 - time * 6
radian = math.radians(angle)
rad = math.cos(radian)
ans = a**2 + b**2 - 2*a*b*rad
print(math.sqrt(ans))

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

int main()
{
    ll N; cin >> N;
    if (N <= 999) {
        cout << "ABC" << endl;
    }
    else {
        cout << "ABD" << endl;
    }
 

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using ll = long long;

int main()
{
    int r;
    cin >> r;

    cout << 2*r*M_PI << endl;
    return 0;
}

Measured memory_bytes: 3764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

struct data {
    int sz, c;
    data(int sz, int c) : sz(sz), c(c) {}
};

int c[100010];

int main()
{
    int n;

    while (n = in(), n) {
        rep(i, n) {
            c[i] = in();
        }

        vector<data> hoge;

        hoge.PB(data(1, c[0]));

        for (int i = 1; i < n; ++i) {
            if (i % 2 == 0) {
                if (hoge.back().c == c[i]) {
                    hoge.back().sz += 1;
                } else {
                    hoge.PB(data(1, c[i]));
                }
            } else {
                if (hoge.back().c == c[i]) {
                    hoge.back().sz += 1;
                } else {
                    int a = hoge.back().sz;
                    hoge.pop_back();
                    if (hoge.empty()) hoge.PB(data(a + 1, c[i]));
                    else hoge.back().sz += a + 1;
                }
            }
        }

        int ans = 0;

        while (hoge.size()) {
            if (hoge.back().c == 0) ans += hoge.back().sz;
            hoge.pop_back();
        }

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

Measured memory_bytes: 3524
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N, D;
	int X[11][11];
	cin >> N >> D;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> X[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			double sum = 0.0;
			for (int k = 0; k < D; k++) {
				sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			}
			sum = sqrt(sum);
			if (sum == (int)sum) ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
values = list(map(int,input().split()))
costs = list(map(int,input().split()))
values_np = np.array(values)
costs_np = np.array(costs)

profits = values_np - costs_np
ans = 0

for p in profits:
    if p > 0:
        ans += p

print(ans)

Measured memory_bytes: 21548
#n,l = map(int,input().split())
#l = kist(input())

n = int(input())
l = list(map(int,input().split()))

ttl = sum(l)

m = int(input())

for i in range(m):
    p,x = map(int,input().split())
    print(ttl-l[p-1]+x)

Measured memory_bytes: 3060
#include <iostream>
#include <map>
using namespace std;
 
int main() {
    using Int = long long;
    
    const Int mod = 1000000007;
    
    int n;
    cin >> n;
    
    map<int, int> m;
    
    m[0] = 3;
    
    Int ans = 1;
    
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        
        ans = (ans * m[a]) % mod;
        
        m[a]--;
        m[a+1]++;
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<cstdint>
#include<algorithm>
using namespace std;

const int MAX = 500;
const int MAX2 = 10000;
int main() {
	int N;
	cin >> N;
	if (N == 2) { // 例外ケース
		cout << 4 << " " << 7 << endl << 23 << " " << 10;
		return 0;
	}
	vector<int> prime;
	static bool num[MAX2];
	for (int i = 0;i < MAX2;++ i) num[i] = true;
	for (int i = 2, c = N << 1;c > 0;++ i) {
		if (num[i]) { // この数は素数！
			prime.push_back(i);
			-- c;
			for (int j = i << 1, l = MAX2 - i;j < l;j += i) num[j] = false;
		}
	}
	static int64_t a[MAX][MAX];
	for (int i = 0;i < N;++ i) {
		for (int j = 0;j < N;++ j) {
			if ((i + j & 1) == 0) { // 素数
				a[i][j] = prime[N / 2 + (i - j) / 2] * prime[N + (i + j) / 2];
			} else { // 上下左右4つの素数の積+1
				if (i == 0 && j == N - 1) a[i][j] = (int64_t)prime[N / 2 + (i - j + 1) / 2] * prime[N + (i + j - 1) / 2] * prime[N + (i + j + 1) / 2] + 1;
				else if (i == N - 1 && j == 0) a[i][j] = (int64_t)prime[N + (i + j - 1) / 2] * prime[N / 2 + (i - j - 1) / 2] * prime[N + (i + j + 1) / 2] + 1;
				else a[i][j] = (int64_t)prime[N / 2 + (i - j + 1) / 2] * prime[N + (i + j - 1) / 2] * prime[N / 2 + (i - j - 1) / 2] * prime[N + (i + j + 1) / 2] + 1;
			}
		}
	}
	/*
	vector<int64_t> chk;
	for (int i = 0;i < N;++ i) { // 要らないけど、整合性チェック
		for (int j = 0;j < N;++ j) {
			int d[] = {0, 1, 0, -1, 0};
			int check[] = {-1, -1, -1, -1};
			for (int k = 0;k < 4;++ k) {
				if (i + d[k] >= 0 && i + d[k] < N && j + d[k + 1] >= 0 && j + d[k + 1] < N) {
					check[k] = max(a[i][j], a[i + d[k]][j + d[k + 1]]) % min(a[i][j], a[i + d[k]][j + d[k + 1]]);
				}
			}
			sort(check, check+4);
			for (int i = 0;i < 3;i ++) {
				if (check[i] >= 0 && check[i] != check[i + 1]) {
					cerr << "err" << endl;
				}
			}
			if (a[i][j] >= 1000000000000000) cerr << "err" << endl;
			chk.push_back(a[i][j]);
		}
	}
	sort(chk.begin(), chk.end());
	for (int i = 1;i < chk.size();++ i) {
		if (chk[i] == chk[i - 1]) cerr << "err" << endl;
	}
	cerr << chk[chk.size() - 1] << endl;
	*/
	
	for (int i = 0;i < N;++ i) {
		for (int j = 0;j < N;++ j) {
			if (j > 0) cout << " ";
			cout << a[i][j];
		}
		cout << endl;
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

解説AC
まず、割った余りは……がヤバそうなので先にこれをどうにかする
あるマスについて、常にその値を上下左右の値の最小公倍数+1にするものとしようか
この時、上下左右が相異なる素数ならば、最小公倍数は要するに4つの積なので常に相異なる
そして、これの余りは1だからセーフ
後は素数を配置だけど、500×500/2=12500……あれ、これはヤバい
何がヤバいって12500番目の素数って値幾つだ、一度試してみよう
試した結果、答えは1655131とのこと
ちなみに6250番目は780469
これ、そのまま4乗すると10^15を超えてしまう……でもある程度は行けそう……順番を調整してみよう
解説でやってるような方法を取ってみようか
ここで、500番目の素数は3571で、4乗すると162614549665681=1.6*10^14はセーフ
なら1と1000を、2と999を……のペアを作っていけばセーフっぽい

さて、使う本数を考えていこう
まず左上→右下への線の本数はN+(N&1)-1本
次に右上→左下への線の本数はN本
後はこれを、交差する数の素数番目の和が2Nを超えないようにしてみようか
これは簡単で、左上→右下に小さい数番目から配置する……とかで十分達成可能
*/

Measured memory_bytes: 5120
#include<stdio.h>
int main(void)
{
	int h,m,s;
	scanf("%d",&s);
	if(s<60){
		printf("0:0:%d\n", s);
	}
	else if(s<3600){
		m=s/60;
		s=s%60;
		printf("0:%d:%d\n", m, s);
	}
	else if(s>=3600){
		m=s/60;
		s=s%60;
		h=m/60;
		m=m%60;
		printf("%d:%d:%d\n", h, m, s);
	}
	return 0;
}

Measured memory_bytes: 592
#include <cstdio>
#include <algorithm>
#define maxn 200010
int a[maxn],b[maxn],n;
using namespace std;
int main(){
	int i,l,r;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
	sort(a+1,a+1+n),sort(b+1,b+1+n);
	if(n%2)l=a[(n+1)/2],r=b[(n+1)/2];
	else l=a[n/2]+a[n/2+1],r=b[n/2]+b[n/2+1];
	printf("%d\n",r-l+1);
	return 0;
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a <= b + c ? b + c - a : 0) << endl;
}

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


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

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

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

int W, H;
char B[111][111];

void dfs(int y, int x, char c) {
   B[y][x] = '-';
   rep (i, 4) {
      int nx = x + dx[i] , ny = y + dy[i];
      if (nx >= 0 && nx < W && ny >= 0 && ny < H && B[ny][nx] == c) dfs(ny, nx, c);
   }
}

int main() {
   while (cin >> H >> W, W) {
      rep (i, H) cin >> B[i];
      int cnt = 0;
      rep (i, H) rep (j, W) if (B[i][j]!='-') cnt++, dfs(i, j, B[i][j]);
      cout << cnt << endl;
   }
   
   return 0;
}


Measured memory_bytes: 3616
using System;

class Program
{
    static void Main()
    {
        var a = int.Parse(Console.ReadLine());
        var b = int.Parse(Console.ReadLine());
        var c = int.Parse(Console.ReadLine());
        var d = int.Parse(Console.ReadLine());
        var e = int.Parse(Console.ReadLine());
        var k = int.Parse(Console.ReadLine());
        if(e-a <= k){
            Console.WriteLine("Yay!");
        }
        else{
            Console.WriteLine(":(");
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll L, R;
    cin >> L >> R;
    if(R - L >= 2018) {
        cout << 0 << endl;
    } else {
        ll ans = 2018;
        for(ll i = L; i <= R; i++) {
            for(ll j = i + 1; j <= R; j++) {
                ans = min(ans, i * j % 2019);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int   ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll N;
        string s;
        cin>>N>>s;
        if(s.size()<=N)
            cout<<s<<endl;
        else
        {
            for(ll i=0;i<N;i++)
                cout<<s[i];
            cout<<"..."<<endl;
        }
    }
}

Measured memory_bytes: 3656
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int maxA = sc.nextInt();
        long res = 0;
        for(int i=1; i<N; i++){
            int A = sc.nextInt();
            maxA = Math.max(maxA,A);
            res = res + maxA - A;
            
        }
		System.out.println(res);
	}
}

Measured memory_bytes: 60124
// 2020-07-18 11:59:45
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
struct mint {
  ll divisor = 1000000007;
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % divisor) {
    if (val < 0) val += divisor;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = divisor, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += divisor;
    u %= divisor;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= divisor) val -= divisor;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += divisor;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % divisor;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % divisor;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
  friend std::string debug_s (mint a) noexcept {
    return std::to_string(a.val);
  }
};

const int MX = 100010;
int n, k;
vector<int> G[MX];
mint ans = 1;
void dfs(int u, int p, int d, int s) {
  ans *= k-min(d, 2)-s;
  int t = 0;
  for(int v : G[u]) if(v != p) {
    dfs(v, u, d+1, t);
    t++;
  }
}
void answer() {
  cin >> n >> k;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0, -1, 0, 0);
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 13668
#include <stdio.h>
#include <string.h>
 
int main(void){
 
char c1[101];
int i;
  
scanf("%s", c1);
 
for(i = 0; i< strlen(c1);i++){
	c1[i] = 'x';
}
 
printf("%s",c1);
  
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        String s = Integer.toString(N);
        if(s.contains("7")){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }


    }

}

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

int main(){
    string s;
    int n;
    cin >> n;
    cin >> s;
    rep(i,s.size()){
        int v = s[i];
        v=65+((v-65+n)%26);
        s[i] = v;
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,ans;
int main()
{
    cin >> n >> m >> k;
    if(n <= m)
	    {
	        cout<<"1\n";
	        return 0;
	    }
    if(m <= k)
	    {
	        cout<<"-1" << endl;
	        return 0;
	    }
    cout<<((n-m) % (m-k) == 0?(n-m)/(m-k):(n-m) / (m-k) + 1) * 2 + 1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
    int l,k;
    cin >> l >> k;
    lli dp[l+k][2] = {};
    dp[0][0] = 1;
    lli ans = 0;
    for(int i=0; i<l; i++){
        dp[i+1][1] += dp[i][0];
        dp[i+k][1] += dp[i][0];
        dp[i+1][0] += dp[i][1];
        ans += dp[i+1][1];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3124
#include <stdio.h>

void fact(int ,int, int);
void count(void);

int a[10][10],i,j;

int main(){
  int x,y,size;

  for(i = 0 ; i < 10 ; i++){
    for(j = 0 ; j < 10 ; j++){
      a[i][j] = 0;
    }
  }
  while(scanf("%d,%d,%d",&x,&y,&size) == 3){
    fact(x,y,size);
  }
  count();
  return 0;
}
void fact(int x, int y, int size){
  int size1[2] = {1,-1};
  int size2[2] = {2,-2};

  a[y][x] += 1;
  if(size == 1){
    for(i = 0 ; i < 2 ; i++){
      if(x+size1[i] >= 0 && x+size1[i] < 10)
	a[y][x+size1[i]] += 1;
      if(y+size1[i] >= 0 && y+size1[i] < 10)
	a[y+size1[i]][x] += 1;
    }
  }
  if(size == 2){
    for(i = 0 ; i < 2 ; i++){
      for(j = 0 ; j < 2 ; j++){
	if(x+size1[j] >= 0 && x+size1[j] < 10 && y+size1[i] >= 0 && y+size1[i] < 10)
	  a[y+size1[i]][x+size1[j]] += 1;
      }
    }
    for(i = 0 ; i < 2 ; i++){
      if(x+size1[i] >= 0 && x+size1[i] < 10)
	a[y][x+size1[i]] += 1;
      if(y+size1[i] >= 0 && y+size1[i] < 10)
	a[y+size1[i]][x] += 1;
    }
  }
  if(size == 3){
    for(i = 0 ; i < 2 ; i++){
      for(j = 0 ; j < 2 ; j++){
	if(x+size1[j] >= 0 && x+size1[j] < 10 && y+size1[i] >= 0 && y+size1[i] < 10)
	  a[y+size1[i]][x+size1[j]] += 1;
      }
    }
    for(i = 0 ; i < 2 ; i++){
      if(x+size1[i] >= 0 && x+size1[i] < 10)
	a[y][x+size1[i]] += 1;
      if(y+size1[i] >= 0 && y+size1[i] < 10)
	a[y+size1[i]][x] += 1;
    }
    for(i = 0 ; i < 2 ; i++){
      if(x+size2[i] >= 0 && x+size2[i] < 10)
	a[y][x+size2[i]] += 1;
      if(y+size2[i] >= 0 && y+size2[i] < 10)
	a[y+size2[i]][x] += 1;
    }
  }
}
void count(void){
  int sum = 0,x = 0;

  for(i = 0 ; i < 10 ; i++){
    for(j = 0 ; j < 10 ; j++){
      if(a[i][j] == 0)
	sum++;
      else if(x < a[i][j])
	x = a[i][j];
    }
  }
  printf("%d\n%d\n",sum,x);
}

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

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

int main() {
  int n;
  cin >> n;
  ll mi=0;
  ll k = 100000000000000005;
  vector<int>x(n);
  rep(i,n){
    cin >> x[i];
  }
  rep(i,101){
    rep(j,n){
      mi+=(x[j]-i)*(x[j]-i);
    }
    k=min(k,mi);
    mi=0;
  }
  cout << k << endl;
    
    

  return 0;

}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
    int ans=0;
    string S; cin>>S;
    if (S=="RSS" || S=="SRS" || S=="SSR" || S=="RSR") ans=1;
    if (S=="RRS" || S=="SRR") ans=2;
    if (S=="RRR") ans=3;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
//omajinai c++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <map>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
constexpr auto mod = 1000000007;
using ll = long long;
using namespace std;
int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}

	sort(all(a));
	string ans = "YES";
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			ans = "NO";
			break;
		}
	}

	cout << ans;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int total = sc.nextInt();
		int count = 0;
		Rabbit[] rab = new Rabbit[100000];

		int j = 1;
		for (int i = 0; i < total; i++) {
			rab[i] = new Rabbit(sc.nextInt(), j);
			j++;
		}

		for (int i = 0; i < total; i++) {
			int tempIdx = rab[i].number;
			int tempNum = rab[i].index;
			if (rab[i].number == rab[tempIdx-1].index && rab[i].index == rab[tempIdx-1].number && rab[i].index < rab[tempIdx-1].index)
				count++;
		}

		System.out.println(count);
	}
}

class Rabbit {
	int number;
	int index;

	public Rabbit(int num, int idx) {
		this.number = num;
		this.index = idx;
	}

	public int getNumber() {
		return number;
	}

	public int getIndex() {
		return index;
	}

}

Measured memory_bytes: 49800
#include<iostream>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a==1&&b==2){
    cout << 3 << endl;
  }
    else if(a==2&&b==3){
      cout << 1 << endl;
    }
  else if(a==3&&b==1){
    cout << 2 << endl;
  }
  else if(a==1&&b==3){
    cout << 2 << endl;
  }
    else if(a==2&&b==1){
      cout << 3 << endl;
    }
      else if(a==3&&b==2){
        cout << 1 << endl;
      }
}

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

char low(char x){return ('A'<=x && x<='Z')?x+32:x;}
char up(char x){return ('a'<=x && x<='z')?x-32:x;}

int main(){
  string s;
  char o;

  while(cin >> s >> o && o!='X'){
    cout << ((o-'U')?low(s[0]):up(s[0]));

    for(int i=1;i<(int)s.size();i++){
      if(s[i]=='_' && o-'D'){
	s.erase(s.begin()+i);
	cout << up(s[i]);
      }else if('A'<=s[i] && s[i]<='Z' && o=='D'){
	cout << '_' << low(s[i]);
      }else cout << s[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
from collections import defaultdict

def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    d = defaultdict(list)

    for i in range(3):
        for j in range(3):
            d[A[i][j]].append(i)
            d[A[i][j]].append(j)

    bingo = [[False] * 3 for _ in range(3)]
    N = int(input())
    for _ in range(N):
        b = int(input())
        if d[b]:
            i, j = d[b]
            bingo[i][j] = True

    for i in range(3):
        flag = True
        for j in range(3):
            if bingo[i][j] == False:
                flag = False
                break
        if flag:
            print('Yes')
            exit()

    for j in range(3):
        flag = True
        for i in range(3):
            if bingo[i][j] == False:
                flag = False
                break
        if flag:
            print('Yes')
            exit()
    
    if bingo[0][0] == True and bingo[1][1] == True and bingo[2][2] == True:
        print('Yes')
        exit()

    if bingo[2][0] == True and bingo[1][1] == True and bingo[0][2] == True:
        print('Yes')
        exit()

    print('No')
if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
s=input()

a=s[0]
b=s[1]
c=s[2]
d=s[3]

op=['+','-']

for i in op:
    for j in op:
        for k in op:
            if eval(str(a)+i+str(b)+j+str(c)+k+str(d))==7:
                ans=str(a)+i+str(b)+j+str(c)+k+str(d)+'=7'

print(ans)

Measured memory_bytes: 3064
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  int N,K; cin>>N>>K;

  int n = N;
  int k = 0;
  while (n>0) {
    n /= K;
    k++;
  }

  int  ans = k;
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        var s1 = new int[n, 2];
        var s2 = new int[n + 1, 2];
        var s3 = new int[n + 1, 2];
        s2[0, 0] = 1; s2[0, 1] = 0;
        var a = new List<int>();
        var jc = 0; var ic = 0;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'J') jc++;
            else if (s[i] == 'O') a.Add(i);
            else ic++;
            s1[i, 0] = jc;
            s1[i, 1] = ic;
            s2[i + 1, 0] = jc + 1;
            s2[i + 1, 1] = ic;
            s3[i, 0] = jc;
            s3[i, 1] = ic;
        }
        s3[n, 0] = s3[n - 1, 0];
        s3[n, 1] = s3[n - 1, 1] + 1;
        var ans1 = getIJ(s2, a, 1);
        var ans2 = getIJ(s3, a, 0);
        var ans3 = getO(s1, a);
        var ans = Max(ans1, Max(ans2, ans3));
        Console.WriteLine(ans);
    }
    static long getO(int[,] s, List<int> a)
    {
        var ans1 = getIJ(s, a, 0);
        var ans = new List<long>();
        var sL = s.GetLength(0);
        for (int i = 0; i < sL - 1; i++)
        {
            var t = s[i, 0] * (s[sL - 1, 1] - s[i, 1]);
            ans.Add(t);
        }
        return ans.Max() + ans1;
    }
    static long getIJ(int[,] s, List<int> a, int d)
    {
        var sL = s.GetLength(0);
        var ans = new List<long>();
        foreach (var x in a)
        {
            var t = s[x + d, 0] * (s[sL - 1, 1] - s[x + d, 1]);
            ans.Add(t);
        }
        return ans.Sum();
    }
}





Measured memory_bytes: 26848
#include<cstdio>

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

    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            int tot=0;
            tot=i*m+j*n-i*j*2;
            if(tot==k){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
class Node:
    
    def __init__(self, parent = -1, left = -1, right = -1):
        self.parent = parent
        self.left = left
        self.right = right
    
    def get_degree(self):
        d = 0
        if self.left != -1:
            d += 1
        if self.right != -1:
            d += 1
        return d

class BinaryTree:
    
    def __init__(self, size):
        self.tree = [Node() for i in range(N)]
    
    def set(self, node_id, left, right):
        self.tree[node_id].left = left
        self.tree[node_id].right = right

        if left != -1:
            self.tree[left].parent = node_id
        if right != -1:
            self.tree[right].parent = node_id
    
    def get_root(self):
        for i in range(len(self.tree)):
            node = self.tree[i]
            if node.parent == -1:
                return i
    
    def walk_preorder(self, node):
        if node == -1:
            return
        print(' %d' % (node), end = '')
        self.walk_preorder(self.tree[node].left)
        self.walk_preorder(self.tree[node].right)
    
    def walk_inorder(self, node):
        if node == -1:
            return
        self.walk_inorder(self.tree[node].left)
        print(' %d' % (node), end = '')
        self.walk_inorder(self.tree[node].right)
    
    def walk_postorder(self, node):
        if node == -1:
            return
        self.walk_postorder(self.tree[node].left)
        self.walk_postorder(self.tree[node].right)
        print(' %d' % (node), end = '')

N = int(input())

# 二分木初期化
binary_tree = BinaryTree(N)

# 値設定
for _ in range(N):
    node_id, left, right = list(map(int, input().split()))
    binary_tree.set(node_id, left, right)

root = binary_tree.get_root()

print('Preorder')
binary_tree.walk_preorder(root)
print('\n', end = '')
print('Inorder')
binary_tree.walk_inorder(root)
print('\n', end = '')
print('Postorder')
binary_tree.walk_postorder(root)
print('\n', end = '')


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,w;
ll dp[N];
int main()
{
    scanf("%d%d",&n,&w);
    while(n--)
    {
        int x,v;scanf("%d%d",&x,&v);
        for(int i=w;i>=x;i--)
            dp[i]=max(dp[i],dp[i-x]+v);
    }
    printf("%lld\n",dp[w]);
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int a[3], i, j, dif, indx1, indx2;
    for(i=0; i<3; i++)
    {
      scanf("%d", &a[i]);
    }
    int sum[3][2], min_sum;
    for(i=0; i<3; i++)
    {
        for(j=0; j<2; j++)
        {
            sum[i][j]=a[i]-a[i];
            indx1 = i+1;
            indx1 = indx1%3;
            dif = a[indx1] - a[i];
            if(dif<0)
            {
                dif = dif*(-1);
            }
            sum[i][j] += dif;
            indx2 = i+2;
            indx2 = indx2%3;
            dif = a[indx2] - a[indx1];
            if(dif<0)
            {
                dif = dif*(-1);
            }
            sum[i][j] += dif;
        }
    }
    min_sum = sum[0][0];
    for(i=0; i<3; i++)
    {
        for(j=0; j<2; j++)
        {
            if(min_sum > sum[i][j])
            {
                min_sum = sum[i][j];
            }
        }
    }
    printf("%d\n", min_sum);
    return 0;
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a);

        a = (a * a); 
        b >>= 1;
    }
    return res;
}

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

#define N 200010
#define MOD 1000000007


int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    string s;
    cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

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

using namespace std;

#define to first
#define cost second

const int N = 3000;
vector<pair<int , int> > adj[N];
vector<int> rev[N];
int cycle[N] , cnt[N];
int vis[N];

void reach (int node) {
    cnt[node]++;
    vis[node] = 1;
    for (auto &e : adj[node])
        if (!vis[e.to])
            reach(e.to);
}

void reach2 (int node) {
    cnt[node]++;
    vis[node] = 2;
    for (int child : rev[node])
        if (vis[child] != 2)
            reach2(child);
}

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#ifdef LOCAL
    freopen("input.in" , "r" , stdin);
#endif
    int n , m , p;
    cin >> n >> m >> p;

    while (m--) {
        int a , b , c;
        cin >> a >> b >> c;
        adj[a].push_back({b , c - p});
        rev[b].push_back(a);
    }

    vector<int> dp(n + 1 , -1e9);
    dp[1] = 0;

    for (int j = 1 ;j <= n ;j++) {
        for (int i = 1 ;i <= n ;i++) {
            for (auto &e : adj[i]) {
                if (dp[e.to] < dp[i] + e.cost) {
                    dp[e.to] = dp[i] + e.cost;
                    if (j == n)
                        cycle[e.to] = 1;
                }
            }
        }
    }

    reach(1);
    reach2(n);

    for (int i = 1 ;i <= n ;i++) {
        if (cnt[i] == 2 && cycle[i]) {
            cout << -1;
            return 0;
        }
    }

    cout << max(0 , dp[n]);
}


Measured memory_bytes: 4060
n, m = map(int, input().split())
MOD = 1000000007

def fac(n):
    ans = 1
    for i in range(1, n + 1):
        ans = (ans * i) % MOD
    return ans

if abs(m - n) > 1:
    print(0)
elif m == n:
    print((2 * fac(m) * fac(n)) % MOD)
else:
    print((fac(m) * fac(n)) % MOD)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int sum = 0;
  int num = n;
  while (num != 0) {
    sum += num % 10;
    num /= 10;
  }
  if (n % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int ans = 1;
	int n;
	cin >> n;
	map<int, int> mc;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		mc[x]++;
	}
	if (n % 2 == 1 && mc[0] != 1)
	{
		puts("0");
		return 0;
	}
	for (int i = (n & 1) + 1; i < n; i += 2)
	{
		if (mc[i] != 2) puts("0"), exit(0);
		ans = ans * 2 % INF;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3200
n,m = map(int, input().split())

min_num = 1
max_num = n
for i in range(m):
  l,r = map(int, input().split())
  if min_num < l:
    min_num = l
  if max_num > r:
    max_num = r

if max_num-min_num >= 0:
  print (max_num-min_num + 1)
else:
  print(0)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main(){

    int a;
    int b,c;
    cin >> a >> b >>c;

    if(a>b){
        int tesuto;
        tesuto=a;
        a=b;
        b=tesuto;
    }
    if(b>c){
        int tesuto;
        tesuto=b;
        b=c;
        c=tesuto;
    }
    if(a>b){
        int tesuto;
        tesuto=a;
        a=b;
        b=tesuto;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 3068
n, c = gets.split.map(&:to_i)
pairs = [[0,0]]

n.times do 
  pairs << gets.split.map(&:to_i)
end

f1 = []
f2 = []
sum = 0
pairs.each do |pair|
  sum += pair[1]
  f1 << sum - pair[0]
  f2 << sum - 2 * pair[0]
end

g = []
max = f1[0]
f1.each do |a|
  max = a if max < a
  g << max
end

h = []
max = f2[0]
f2.each do |a|
  max = a if max < a
  h << max
end

sum = 0
smax = 0

n.downto(0) do |bx|
  sum += pairs[bx][1]
  if bx == 0
    ts1 = g[n]
    ts2 = h[n]
  else
    ts1 = sum - 2 * (c - pairs[bx][0]) + g[bx - 1]
    ts2 = sum -     (c - pairs[bx][0]) + h[bx - 1]
  end
  ts = ts1 > ts2 ? ts1 : ts2
  smax = ts if smax < ts
end

smax = 0 if smax < 0
puts smax

Measured memory_bytes: 13708
#include<bits/stdc++.h>
using namespace std;
template<typename V>
bool tomin(V&x,V y){if(y<x){x=y;return true;}return false;}
template<typename V>
bool tomax(V&x,V y){if(x<y){x=y;return true;}return false;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
#define lowbit(x) ((x)&-(x))
#define EOR(x,y) for(int x##_=head[x],y=edge[x##_].e;x##_;y=edge[x##_=edge[x##_].to].e)
const int M=1e5+5;
int n,m,Q;
struct node{
	int id,t,c,d;
};
vector<node>q[M];
struct Edge{
	int e,c,d,to;
}edge[M<<1];
int head[M],tot;
void Add(int x,int y,int c,int d){
	edge[++tot]=(Edge){y,c,d,head[x]};
	head[x]=tot;
}
int fa[M],son[M],sz[M],top[M],dep[M];
void dfs(int u,int f){
	dep[u]=dep[f]+1;
	fa[u]=f;
	son[u]=0;
	sz[u]=1;
	EOR(u,v)if(v!=f){
		dfs(v,u);
		sz[u]+=sz[v];
		if(sz[son[u]]<sz[v])son[u]=v;
	}
}
void dfs_top(int u,int tp){
	top[u]=tp;
	EOR(u,v)if(v!=fa[u])
		dfs_top(v,v==son[u]?tp:v);
}
int LCA(int x,int y){
	while(top[x]!=top[y]){
		if(dep[top[x]]>dep[top[y]])x=fa[top[x]];
		else y=fa[top[y]];
	}return dep[x]>dep[y]?y:x;
}
namespace YD{
	#define lson ls[od],ls[pr],L,mid
	#define rson rs[od],rs[pr],mid+1,R
	const int maxm=M*20;
	int ls[maxm],rs[maxm],rt[maxm];
	int num[maxm];
	int sum[maxm];
	int tot;
	void Create(int od,int &pr){
		pr=++tot;
		ls[pr]=ls[od];
		rs[pr]=rs[od];
		sum[pr]=sum[od];
		num[pr]=num[od];
	}
	void update(int od,int &pr,int L,int R,int c,int d){
		Create(od,pr);
		sum[pr]+=d;
		num[pr]++;
		if(L==R)return;
		int mid=L+R>>1;
		if(c<=mid)update(lson,c,d);
		else update(rson,c,d);
	}
	int query_sum(int od,int pr,int L,int R,int c){
		if(L==R)return sum[pr]-sum[od];
		int mid=L+R>>1;
		if(c<=mid)return query_sum(lson,c);
		return query_sum(rson,c);
	}
	int query_num(int od,int pr,int L,int R,int c){
		if(L==R)return num[pr]-num[od];
		int mid=L+R>>1;
		if(c<=mid)return query_num(lson,c);
		return query_num(rson,c);
	}
	void Add(int x,int c,int d){
		update(rt[x-1],rt[x],1,n-1,c,d);
	}
	int query(int x,int y,int c,int d){
		return sum[rt[y]]-sum[rt[x]]-query_sum(rt[x],rt[y],1,n-1,c)+d*query_num(rt[x],rt[y],1,n-1,c);
	}
}
int ans[M];
void solve(int u,int f){
    for(int i=0;i<q[u].size();i++)
		ans[q[u][i].id]+=YD::query(dep[q[u][i].t],dep[u],q[u][i].c,q[u][i].d);
	EOR(u,v)if(v!=f){
		int c=edge[u_].c,d=edge[u_].d;
		YD::Add(dep[v],c,d);
		solve(v,u);
	}
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>Q;
	int x,y,c,d;
    for(int i=1;i<n;i++){
        cin>>x>>y>>c>>d;
		Add(x,y,c,d);
		Add(y,x,c,d);
	}
	dep[0]=-1;
	dfs(1,0);
	dfs_top(1,1);
    for(int i=1;i<=Q;i++){
        cin>>c>>d>>x>>y;
		int lca=LCA(x,y);
		if(x!=lca)q[x].push_back((node){i,lca,c,d});
		if(y!=lca)q[y].push_back((node){i,lca,c,d});
	}
	solve(1,0);
    for(int i=1;i<=Q;i++)
        cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 51456
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;
int g[1000];
int dp[50][101010];

int main() {
  rep(i, 0, 50) {
    rep(j, 1, 101000) { dp[i][j] = inf; }
  }

  cin >> N;
  g[1] = 1;
  g[2] = 6;
  int cnt = 3;
  for (int i = 2; i <= 100; i++) {
    g[cnt] = g[cnt - 1] * 6;
    if (g[cnt] > 100000) break;
    ++cnt;
  }
  ++cnt;

  g[cnt] = 9;
  ++cnt;
  for (int i = 2; i <= 100; i++) {
    g[cnt] = g[cnt - 1] * 9;
    if (g[cnt] > 100000) break;
    ++cnt;
  }

  for (int i = 1; i <= cnt; ++i) {
    for (int j = 1; j <= N; ++j) {
      if (j < g[i]) {
        dp[i][j] = dp[i - 1][j];
      } else {
        dp[i][j] = min(dp[i - 1][j], dp[i][j - g[i]] + 1);
      }
    }
  }

  cout << dp[cnt][N] << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    int a = n%10;
    int b = (n/10) %10;
    int c =(n/100) %10;
    if(a==7 || b==7 || c==7){
        cout << "Yes" << endl;
    }else{
        cout <<  "No" << endl;
    }
}

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

int main(){

    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i=0; i<N; i++) cin >> p.at(i);

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

    int sum = 0;
    for (int i=0; i<K; i++){
        sum += p.at(i);
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3628