akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<int> m;
    long long res = 1;
    int cnt = 1;
    string s;
    while(N > 0){
        N--;
        int t = N % 26;
        N /= 26;
        m.push_back(t);
    }
    for(int i = 0; i < m.size(); i++){
        s += 'a' + m[m.size() - 1 - i];
    }
    cout << s << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] A = new int[N];
        int total = 0;

        for (int i = 0 ; i < N ; i++) {
            A[i] = scanner.nextInt();
            total += A[i];
        }

        int count = 0;
        for (int i = 0 ; i < N ; i++) {
            if (A[i] * 4 * M >= total) count++;
            if (count >= M) {
                System.out.println("Yes");
                return;
            }
        }

        System.out.println("No");
    }
}


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

int main(){
  int n; cin >> n;
  vector<double> value(n);
  for(int i = 0; i < n; i++){
    cin >> value[i];
  }
  sort(value.begin(), value.end());
  double sum = (value[0] + value[1]) / 2;
  if(n > 2){
    for(int i = 2; i < n; i++){
      sum = (sum + value[i]) / 2;
    }
  cout << fixed << setprecision(10) << sum << endl;
  }
  else if (n == 2) cout << (value[0] + value[1]) / 2;
}

Measured memory_bytes: 256
N = int(input())

answer = 0
for i in range(1, N+1, 1):
  if i % 3 == 0 and i % 5 == 0:
  	pass
  elif i % 3 == 0:
  	pass
  elif i % 5 == 0:
  	pass
  else:
  	answer += i
else:
  print(answer)

Measured memory_bytes: 9180
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		int s[] = new int[M];
		int c[] = new int[M];
		int a[] = new int[N];
		if (N != 1) {
			a[0] = 1;
		} else {
			a[0] = 0;
		}
		for (int i = 1; i < N; i++) {
			a[i] = 0;
		}

		for (int i = 0; i < M; i++) {
			s[i] = sc.nextInt() - 1;
			c[i] = sc.nextInt();
			if (N != 1) {
				if ((a[0] == 1 && s[i] == 0) || a[s[i]] == 0 || a[s[i]] == c[i]) {
					if (s[i] != 0 || c[i] != 0) {
						a[s[i]] = c[i];
					} else {
						System.out.println(-1);
						sc.close();
						return;
					}
				} else {
					System.out.println(-1);
					sc.close();
					return;
				}
			} else if (N == 1) {
				if (a[0] == 0 || a[0] == c[i]) {
					a[0] = c[i];
				} else {
					System.out.println(-1);
					sc.close();
					return;
				}
			}
		}
		sc.close();
		for (int i = 0; i < N; i++) {
			System.out.print(a[i]);
		}
	}
}


Measured memory_bytes: 22612
#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define REV(v) reverse(v.begin(),v.end())
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
#define v1out(v) FOR(j,0,v.size()){cout<<v[j]; if(j!=(ll)v.size()-1)cout<<" ";else cout<<endl; }
#define v2out(v) FOR(i,0,v.size())v1out(v[i]);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,n;
    cin>>a>>b>>n;
    ll x = min(n,b-1);
    cout<<(a*x/b) - a*(x/b)<<endl;
}

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

int main(){
    char a[4];
    for(int i=0;i<4;i++)cin >> a[i];

    if((a[0]==a[1]&&a[1]==a[2]) || (a[1]==a[2]&&a[2]==a[3]))cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	char c1,c2,c3,c4,c5,c6,c7,c8,c9;
	cin>>c1>>c2>>c3>>c4>>c5>>c6>>c7>>c8>>c9;
	cout<<c1<<c5<<c9;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var N int
	var S string
	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &S)

	var count int = 1
	for i := 0; i < N-1; i++ {
		if S[i] != S[i+1] {
			count++
		}
	}

	fmt.Println(count)
}


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

int main() {
  string S, T;
  cin >> S >> T;
  sort(S.begin(), S.end());
  sort(T.rbegin(), T.rend());
  if (S < T)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int D = scan.nextInt();
    int X[][] = new int[N][D];
    int count = 0;
    
    for (int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        X[i][j] = scan.nextInt();
      }
      
      for(int k = 0; k < i; k++){
        int kyori = 0;
        for(int j = 0; j < D; j++){
          kyori += Math.abs(X[i][j]-X[k][j])*Math.abs(X[i][j]-X[k][j]);
        }
        if((Math.sqrt(kyori)*10)%10 == 0){
          count++;
        }
      }
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 21972
#include <stdio.h>

int main(void){
	int N;
	scanf("%d",&N);
	int sum=0;
	int i,j;
	for(i=0;i<=25;i++){
		for(j=0;j<=15;j++){
			sum = i*4 + j*7;
			if(sum==N){
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9
// fflush(stdout);
//lower_bound,upper_bound,equal_range
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	int n;
	cin>>n;
	vector<int>h(n+1);
	h[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	vector<int>dp(n+1,0);
	dp[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 3984
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i, n):
        leng = 0
        for k in range(d):
            leng += (x[i][k] - x[j][k]) ** 2
        for m in range(130):
            if leng == m ** 2:
                ans += 1
print(ans - n)

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

int main() {
  long long int n,c,k;
  cin>>n>>c>>k;
  long long int t[n];
  for(int i=0;i<n;i++)
    cin>>t[i];
  sort(t,t+n);
  
  long long int ans=1,cnt=1,time=t[0];
  
  for(int i=1;i<n;i++){
    if(cnt==c){
      ans++;
      cnt=1;
      time=t[i];
    }
    else if(t[i]-time<=k)
      cnt++;
    else {
      ans++;
      cnt=1;
      time=t[i];
    }
    
  }
  cout<<ans;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;
#define out(i) cout<<(i)<<endl

int main() {
  ll N,cnt=0;
  cin>>N;
  vector<ll> data(N);
  rep0(i,N){cin>>data[i];}
  ll flag=1;
  while(flag){
      flag=0;
      for(ll j=N-1;j>=1;j--){
          if(data[j]<data[j-1]){
              ll s=data[j];
              data[j]=data[j-1];
              data[j-1]=s;
              flag=1;
              cnt++;
          }
      }
      
  }
  rep0(i,N){if(i!=N-1){cout<<data[i]<<" ";} else{cout<<data[i]<<endl;}}
  cout<<cnt<<endl;
}


Measured memory_bytes: 3092
#include<iostream>
#include<string.h>

using namespace std;

int main(){
	string s;
	cin >> s;
	long scr = 0, t = 0;
	for (long i = 0; i < s.length(); i++){
		if (s[i] == 'g'){
			if (t < i - t){
				scr++;
				t++;
			}
		} else {
			if (t < i - t){
				t++;
			} else {
				scr--;
			}
		}
	}
	cout << scr;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std; 
typedef long long int ll;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h, n;
    cin >> h >> n;
    long long arr[n + 1];
    ll sum = 0;
    for(ll i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    if(sum >= h)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long
#define vi vector<int>

int main(){
    string s,ret;
    int k,c;

    cin >> s;
    k = s.length();
    c = 0;

    REP(i, k)
    {
        if (s.at(i) == 'o')
        {
            c++;
        }
    }

    if (c >= 8 || (8 - c) <= (15 - k))
    {
        ret = "YES";
    }
    else
    {
        ret = "NO";
    }


    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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


int main() {

	ll A, B;
	cin >> A >> B;
	cout << (A + B) % 24;
	
	system("PAUSE");
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int main()
{	
	int a,b,c;
	long long int k;
	cin >> a >> b >> c >> k;
	if(k%2==0){
		cout << a-b << endl;
	}
	else{
		cout << b-a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
#include <map>
#include <cmath>
#include <string>

using namespace std;

int main(){
    int n, p[50], cnt=0;
    cin >> n;
    for(int i=0;i<n;i++) cin >> p[i];

    for(int i=1;i<n-1;i++){
        if(p[i]<p[i+1] && p[i-1]<p[i]) cnt++;
        else if(p[i]<p[i-1] && p[i+1]<p[i]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
s = Hash.new(0)
t = Hash.new(0)
gets.to_i.times do
    s[gets.chomp] += 1
end
gets.to_i.times do
    t[gets.chomp] += 1
end

ans = 0
s.each do |k,v|
    ans = [ans,v-t[k]].max
end
puts ans

Measured memory_bytes: 1788
import java.awt.Color;
import java.awt.Graphics;
import java.util.*;

import javax.swing.JFrame;
import javax.swing.Box.Filler;

public class Main {
	Coin[] coins;
	Scanner sc = new Scanner(System.in);
	int n;
	byte[] state;
	Visualizer vis;
	
	void run() {
//		vis = new Visualizer();
		while (true) {
			n = sc.nextInt();
			if( n == 0 ) break;
			coins = new Coin[n];
			for(int i=0;i<n;i++) coins[i] = new Coin();
			int S=(1<<n)-1;
			state = new byte[1<<n];
			for(int i=0;i<(1<<n);i++) state[i] = -1;
			System.out.println(solve(S));
		}
	}
	
	byte solve( int S ) {
	//	System.out.println(S);
		if (state[S] >= 0) return state[S];
		boolean[] lapped = new boolean[n];
		analyseLapped(S, lapped);
//		for(int i=0;i<n;i++) System.out.print((S>>i)&1);
//		System.out.println();
//		vis.setS(S);
//		vis.repaint();
//		sc.next();
		byte cnt = 0;
		for(int i=0;i<n;i++) {
			if( lapped[i] ) continue;
			for(int j=i+1;j<n;j++) {
				if ( !lapped[j] && coins[i].c == coins[j].c ) {
					cnt = (byte) Math.max(cnt, solve(S-((1<<i) + (1<<j)))+2);
				}
			}
		}
		return state[S] = cnt;
	}
	
	void analyseLapped(int S, boolean[] lapped) {
		for(int i=0;i<n;i++) lapped[i] = false;
		for(int i=0;i<n;i++) {
//			System.out.println( (S>>i) & 1 );
			if( ((S>>i) & 1) != 1 ) { lapped[i] = true ; continue; }
			for(int j=i+1;j<n;j++) {
//				System.out.println(coins[i].isLapped(coins[j]));
				if( coins[i].isLapped(coins[j]) ) lapped[j] = true;
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	class Coin {
		int x, y, r, c;
		
		public Coin() {
			scan();
		}
		
		void scan() {
			x = sc.nextInt();
			y = sc.nextInt();
			r = sc.nextInt();
			c = sc.nextInt();
		}
		
		boolean isLapped( Coin c ) {
			return (c.x-x)*(c.x-x)+(c.y-y)*(c.y-y) < (r+c.r)*(r+c.r);
		}
	}
	class Visualizer extends JFrame {
		int offset = 100;
		int S;
		Visualizer () {
			this.setSize(300, 300);
			this.setVisible(true);
			S = 1<<n-1;
		}
		void setS(int S) {
			this.S = S;
		}
		public void paint(Graphics g) {
			g.clearRect(0, 0, 300, 300);
			for(int i=n-1;i>=0;i--) {
				if(((S>>i)&1) == 1 )oval(coins[i], g);
			}
		}
		Color[] colors = {Color.black, Color.BLUE, Color.red, Color.gray, Color.green, Color.yellow};
		void oval (Coin c, Graphics g) {
			g.setColor(colors[c.c-1]);
			g.fillOval(offset+c.x-c.r, offset+c.y-c.r, 2*c.r, 2*c.r);
			g.setColor(Color.white);
			g.drawOval(offset+c.x-c.r, offset+c.y-c.r, 2*c.r, 2*c.r);
		}
	}
}

Measured memory_bytes: 47000
use proconio::input;
fn main() {
    input! {
        a: i64,
        b: i64,
        n: i64,
    }
    let mut _max = 0;
    if n >= b - 1 {
        _max = a * (b - 1) / b - a * ((b - 1) / b);
    } else {
        _max = a * n / b - a * (n / b);
    }
    println!("{}", _max);
}

Measured memory_bytes: 2084
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var s = o.a(1);
  var y = "Heisei";
  var n = "TBD";
  if(s[5] > 0)return n;
  if(s[6] > 4)return n;
  return y;
}

Measured memory_bytes: 22076
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
#include <assert.h>
#include <iomanip>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ansn() printf("%d\n",ans)
#define lansn() printf("%lld\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(aa,bb) make_pair(aa,bb)
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
double pi = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
const double eps=1e-12;
const int inf=0x3f3f3f3f;
//const ll infl = 100000000000000000;//1e17
const int maxn=  2e6+20;
const int maxm = 5e3+20;
//muv[i]=(p-(p/i))*muv[p%i]%p;
inline int in(int &ret) {
    char c;
    int sgn ;
    if(c=getchar(),c==EOF)return -1;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    sgn = (c=='-')?-1:1;
    ret = (c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
    ret *=sgn;
    return 1;
}
int a[maxn];
ll lcm(ll x,ll y)
{
    ll gcd = __gcd(x,y);
    return x/gcd*y;
}
int main() {
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    int n;
    sd(n);
    ll ans = 0;
    r1(i,n)sd(a[i]),ans += a[i] - 1;
    lansn();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


/*atcoder版comb，mintの部分は適した型に変える*/
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

int main() {
  int n, m, k;
  cin >> n >> m >> k;
 
  mint ans = 0;
  mint col = m;
  for (int x = n-1; x >= 0; --x) {
    mint now = col;
    now *= c(n-1,x);
    if (x <= k) ans += now;
    col *= m-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6204
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
	int n;
	double p;
	scanf("%d", &n);
	p = (n / 2 + (n % 2)) / (double)n;
	printf("%f", p);
}


Measured memory_bytes: 128
s = input()
k = int(input())

s_head = sorted(list(set(s)), reverse=True)
res = [s_head.pop()]
while len(res) < k:
    tmp = res[-1]
    tmp_list = []
    for i in range(len(s)-len(tmp)):
        if s[i:i+len(tmp)] == tmp:
            tmp_list.append(s[i:i+len(tmp)+1])
    if len(tmp_list) == 0:
        res.append(s_head.pop())
    elif min(tmp_list) == tmp:
        res.append(s_head.pop())
    else:
        res.append(min(tmp_list))

print(res[k-1])

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

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

map<int,int> factor(int m){
    map<int,int> vec;
    int end=pow(m,0.5)+2;
    reps(i,2,end){
        while(m%i==0){
            m/=i;
            vec[i]++;
        }
    }
    if(m!=1)vec[m]=1;
    return vec;
}

int main(){
    ll n;
    cin>>n;
    vll table;
    ll ans=0;
    reps(i,1,(int)pow(n,0.5)+1){
        if(n%i==0){
            table.pb(i);
            if(i*i!=n){
                table.pb(n/i);
            }
        }
    }
    sort(all(table));

    rep(i,table.size()){
        if(i==0)continue;
        //if(table[i]==table[i-1]+1)continue;
        if(n/(table[i]-1)==n%(table[i]-1)){
            ans+=table[i]-1;
            //cout<<table[i]-1<<endl;
        }

    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define TOP 0
#define FRONT 1
#define LEFT 2
#define RIGHT 3
#define BACK 4
#define BOTTOM 5
using namespace std;

//TOP,FRONT,LEFT,RIGHT,BACK,BOTTOM
int dice[6]={1,2,4,3,5,6};

//?\\?????¢??????
void rotN(){
  swap(dice[TOP],dice[FRONT]);
  swap(dice[FRONT],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[BACK]);
}

//???????????¢??????
void rotS(){
  //rotN(),rotN(),rotN();
  swap(dice[TOP],dice[BACK]);
  swap(dice[BACK],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[FRONT]);
}


//????????¢??????
void rotE(){
  swap(dice[TOP],dice[LEFT]);
  swap(dice[LEFT],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[RIGHT]);
}

//????????¢??????
void rotW(){
  //rotE(),rotE(),rotE();
  swap(dice[TOP],dice[RIGHT]);
  swap(dice[RIGHT],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[LEFT]);
}

//???????????????????¨????????????????
void rotCW(){
  swap(dice[FRONT],dice[RIGHT]);
  swap(dice[RIGHT],dice[BACK]);
  swap(dice[BACK],dice[LEFT]);
}

//??????????????????????¨???????????????????
void rotCCW(){
  //rotCW(),rotCW(),rotCW();
  swap(dice[FRONT],dice[LEFT]);
  swap(dice[LEFT],dice[BACK]);
  swap(dice[BACK],dice[RIGHT]);
}


int main(){
  cin>>dice[TOP]>>dice[FRONT]>>dice[RIGHT];
  cin>>dice[LEFT]>>dice[BACK]>>dice[BOTTOM];
 
  int q;
  cin>>q;
  while(q--){
    int top, front;
    cin>>top>>front;
    for(int i=0;i<3&&dice[TOP]!=top;i++) rotN();
    for(int i=0;i<3&&dice[TOP]!=top;i++) rotE();
    while(dice[FRONT]!=front) rotCCW();
    cout << dice[RIGHT]<<endl;
  }
   
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    ll n, m; cin >> n >> m;
    ll ans = 0;
    if(2*n < m){
        ans += n;
        m -= 2*n;
        ans += m/4;
    }
    else{
        ans += m/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
#define N 10000005

int f[N];
int main()
{
    long long sum = 0;
    long long n, i, j;
    
    scanf("%lld", &n);
    for(i = 1; i <= n; i++)
        for(j = 1; j * i <= n; j++)
            f[i*j]++;

    for(i = 1; i <= n; i++) sum += i*f[i];
    printf("%lld\n", sum);

    return 0;
}

Measured memory_bytes: 40772
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
typedef long long ll;
using namespace std;

//main
int main(){
  ll L,R;
  cin >> L >> R;
  ll m = 2019;
  if(R-L>673) cout << 0 << endl;
  else{
    for(ll i=L; i<R; i++){
      for(ll j=i+1; j<= R; j++){
        m = min(m,i*j%2019);
      }
    }
    cout << m << endl;
  }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1<<18;
multiset<int>st[N];
int n,ans;
int main(){
//	freopen("readin.txt","r",stdin);
	scanf("%d",&n);
	for(int i = 0,a;i < (1<<n);i++){
		scanf("%d",&a);
		st[i].insert(a);
	}
	for(int i = 0;i < n;i++)
		for(int j = 0;j < (1<<n);j++)
			if(!(j&(1<<i))){
				for(auto k : st[j])st[j|(1<<i)].insert(k);
				while(st[j|(1<<i)].size() > 2)st[j|(1<<i)].erase(st[j|(1<<i)].begin());
			}
	for(int i = 1,sum;i < (1<<n);i++){
		sum = 0;
		for(auto j : st[i])sum+=j;
		ans = max(ans,sum);
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 39936
from collections import Counter


class UnionFind:

    def __init__(self, size):
        self.size = size
        self.par = list(range(size))
        self.rank = [0]*size

    def find_par(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find_par(self.par[x])
            return self.par[x]

    def unite_tree(self, x, y):
        x, y = self.find_par(x), self.find_par(y)
        if x == y:
            return

        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def in_the_same(self, x, y):
        return self.find_par(x) == self.find_par(y)


if __name__ == "__main__":
    N, M = map(int, input().split())
    uf = UnionFind(N)
    C = Counter()
    for _ in range(M):
        a, b = map(lambda x: int(x)-1, input().split())
        uf.unite_tree(a, b)
    for i in range(N):
        C[uf.find_par(i)] += 1
    print(C.most_common()[0][1])


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

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

   cin >> a >> b;
   if(a == 1)   a = 100;
   if(b == 1)   b = 100;
   if(a > b)    cout << "Alice\n";
   else if(a < b)   cout << "Bob\n";
   else{
       cout << "Draw\n";
   }

    return 0;
}

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

class UnionFind {
    vector<int> parent;

    public:
        UnionFind(int size) {
            parent = vector<int>(size, -1);
        }

        int find(int x) {
            if (parent[x] < 0) {
                // parent itself
                return x;
            } else {
                return parent[x] = find(parent[x]);
            }
        }

        bool unite(int x, int y) {
            int rX, rY;
            if ((rX = find(x)) == (rY = find(y))) {
                // already united
                return false;
            }
            if (size(rX) < size(rY)) {
                int tmp = rX;
                rX = rY;
                rY = tmp;
            }
            parent[rX] += parent[rY];
            parent[rY] = rX;
            return true;
        }

        int size(int x) {
            return -parent[find(x)];
        }

        bool isSame(int x, int y) {
            return find(x) == find (y);
        }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind road(n);
    UnionFind train(n);

    int p, q;
    for (int i = 0; i < k; i++) {
        cin >> p >> q;
        road.unite(p - 1, q - 1);
    }
    for (int i = 0; i < l; i++) {
        cin >> p >> q;
        train.unite(p - 1, q - 1);
    }

    vector<pair<int, int>> keys;
    map<pair<int, int>, int> count;
    for (int i = 0; i < n; i++) {
        pair<int, int> key = make_pair(road.find(i), train.find(i));
        keys.push_back(key);
        count[key]++;
    }

    for (const auto key : keys) {
        cout << count[key] << endl;
    }
}


Measured memory_bytes: 15088
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  set<int> w;
  int df = f / 100;
  for (int i = 0; i*a <= df; ++i) {
    for (int j = 0; i*a + j*b <= df; ++j) {
      int t = i*a+j*b;
      if (t) w.insert(t);
    }
  }
  set<int> s;
  for (int i = 0; i*c <= f; ++i) {
    for (int j = 0; i*c+j*d <= f; ++j) {
      int t = i*c+j*d;
      s.insert(t);
    }
  }
  int mxt = *w.begin() * 100;
  int mxs = 0;
  for (int cw : w) {
    for (int cs : s) {
      if (cs > e * cw) break;
      int ct = 100*cw + cs;
      if (ct > f) break;
      if (cs * mxt > mxs * ct) {
        mxt = ct;
        mxs = cs;
      }
    }
  }
  cout << mxt << " " << mxs << endl;
  return 0;
}


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

#define All(x) x.begin(),x.end()
using namespace std;
template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}
int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  vector<int> v(m),v2(m);Inparray(v,m);sort(All(v));
  v2[0]=0;
  for (int i = 1; i < m; ++i){
  	v2[i]=v[i]-v[i-1];
  }
  sort(All(v2));
  // Printarray(v2,m);
  int ans=0;
  for (int i = 0; i < m-n+1; ++i)ans+=v2[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

struct Mod {
	static ll gcd(ll x, ll y, ll* out_cx, ll* out_cy) {
		if (x < 0) {
			ll d = gcd(-x, y, out_cx, out_cy);
			if (out_cx) {
				*out_cx *= -1;
			}
			return d;
		}
		if (y < 0) {
			ll d = gcd(x, -y, out_cx, out_cy);
			if (out_cy) {
				*out_cy *= -1;
			}
			return d;
		}
		if (x > y) {
			return gcd(y, x, out_cy, out_cx);
		}
		if (x == 0) {
			if (out_cx && out_cy) {
				*out_cx = 0;
				*out_cy = 1;
			}
			return y;
		}
		ll q = y / x;
		ll r = y % x;
		ll d = gcd(r, x, out_cy, out_cx);
		if (out_cx) {
			*out_cx -= q * *out_cy;
		}
		return d;
	}
	static ll BASE;
	ll value = 0;
	static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
	Mod()
	: value(0) {}
	Mod(ll value)
	: value(residue(value)) {}
	Mod operator+(const Mod& rhs) const { return Mod(value + rhs.value); }
	void operator+=(const Mod& rhs) { *this = *this + rhs; }
	Mod operator-(const Mod& rhs) const { return Mod(value - rhs.value); }
	void operator-=(const Mod& rhs) { *this = *this - rhs; }
	Mod operator*(const Mod& rhs) const { return Mod(value * rhs.value); }
	void operator*=(const Mod& rhs) { *this = *this * rhs; }
	Mod operator/(const Mod& rhs) const { return *this * rhs.inv(); }
	void operator/=(const Mod& rhs) { *this = *this / rhs; }
	Mod inv() const {
		if (value == 0) {
			assert(false);
			throw "[Mod::inv] div by zero";
		}
		ll ans, sub;
		ll d = Mod::gcd(value, BASE, &ans, &sub);
		if (d != 1) {
			assert(false);
			throw "[Mod::inv] not invertible";
		}
		return ans;
	}
};
ll Mod::BASE = 1000000007;

int main() {
	ll N;
	cin >> N;
	vector<ll> as(N);
	rep(i,0,N) {
		cin >> as[i];
	}
	Mod ans = 1;
	ll room = 0;
	ll prev = -1;
	ll removed = 0;
	rep(i,0,N) {
		room += as[i] - prev - 2;
		if (room < 0) {
			ans *= i+1-removed;
			room+=2;
			removed++;
		}
		prev = as[i];
	}
	rep(n,1,N-removed+1) {
		ans *= n;
	}
	cout << ans.value << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
using namespace std;


int main()
{
    int n;
    cin >> n;
    
    int result = 0;
    for (int i = 1; i <= n; i++) {
        int count = 0;
        int A = i;
        while(A != 0){
            A = A / 10;
            count++;
        }
        if (count % 2 == 1) {
            result++;
        }
    }
    
    cout << result << endl;

    return 0;   
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct Trump {
    initilize_idx: usize,
    number: u32,
    token: String,
}

fn paritition(array: &mut Vec<Trump>, p: usize, r: usize) -> usize {
    let x = array[r].number;
    let mut i: i32 = (p as i32) - 1;

    for j in p..r {
        if array[j].number <= x {
            i += 1;
            array.swap(i as usize, j);
        }
    }
    array.swap((i + 1) as usize, r);

    (i + 1) as usize
}

fn quick_sort(array: &mut Vec<Trump>, p: usize, r: usize) {
    if p < r {
        let q = paritition(array, p, r);
        quick_sort(array, p, q - 1);
        quick_sort(array, q + 1, r);
    }
}

fn main() {
    let n: usize = read();

    let mut array: Vec<Trump> = (0..n)
        .map(|idx| {
            let token: String = read();
            let number: u32 = read();
            Trump {
                token,
                number,
                initilize_idx: idx,
            }
        })
        .collect();

    quick_sort(&mut array, 0, n - 1);

    let mut stable_flag = true;

    for idx in 1..n {
        if array[idx].number == array[idx - 1].number
            && array[idx].initilize_idx < array[idx - 1].initilize_idx
        {
            stable_flag = false;
            break;
        }
    }

    if stable_flag {
        println!("Stable");
    } else {
        println!("Not stable");
    }

    for idx in 0..n {
        if idx != n - 1 {
            println!("{} {}", array[idx].token, array[idx].number);
        } else {
            println!("{} {}", array[idx].token, array[idx].number);
        }
    }
}



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

int main(void){
  char b;
  cin >> b;

  if(b == 'A') cout << 'T' << endl;
  if(b == 'T') cout << 'A' << endl;
  if(b == 'C') cout << 'G' << endl;
  if(b == 'G') cout << 'C' << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	while (true) {
		int n; cin >> n;
		if (n == 0)return 0;
		vector<int>dp(n+1);
		rep(i, n+1)dp[i] = INF;
		dp[0] = 1;
		if(1<=n)dp[1] = 2;
		if(2<=n)dp[2] = 4;
		FOR(i, 3, n + 1) {
			dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1];
		}
		dp[n-1] = (dp[n-1]+9)/10;
		cout << (dp[n-1]+364)/365 << endl;
	}

	return 0;
}


Measured memory_bytes: 3176
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	string s;

	cin >> s;

	bool flag1 = false, flag2 = false, flag3 = false;

	for (i = 0; i < 3; i++) {
		if (s[i] == 'a') flag1 = true;
		if (s[i] == 'b') flag2 = true;
		if (s[i] == 'c') flag3 = true;
	}

	if (flag1 == true && flag2 == true && flag3 == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}










	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
int main() {
	vector<int> v;
	string S,T;

	cin >> S >> T;;
	
	if (S == T)
	{
		cout << "Yes" << endl;
		return 0;
	}

	for (int i = 0; i < S.length(); ++i)
	{
		char c = S.back();
		S.pop_back();
		S.insert(0,1,c);

		if (S == T)
		{
			cout << "Yes" << endl;
			return 0;
		}


	}

	cout << "No" << endl;

	return 0;
}

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

// 入力
int n;
vector<vector<P>> v;

// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {
  // i 人目の証言を検証する
  rep(i, n) {
    // i 人目が「不親切」だったら、証言はすべて無意味
    if (!(bit & (1 << i))) continue;

    // それぞれ確認
    for (P xy : v[i]) {
      int x = xy.first;   // x が
      int y = xy.second;  // y = 1: 正直、y = 0: 不親切

      // y = 1 なのに「不親切」だったらダメ
      if (y == 1 && !(bit & (1 << x))) return false;

      // y = 0 なのに「正直者」だったらダメ
      if (y == 0 && (bit & (1 << x))) return false;
    }
  }
  return true;
}

int main() {
  cin >> n;
  v.resize(n);

  rep(i, n) {
    int a;
    cin >> a;
    v[i].resize(a);
    rep(j, a) {
      cin >> v[i][j].first >> v[i][j].second;
      --v[i][j].first;  // 0-indexed に
    }
  }

  int res = 0;
  for (int bit = 0; bit < (1 << n); ++bit) {
    // 矛盾 check
    if (judge(bit)) {
      // bit に含まれる人数を数える
      int count = 0;
      rep(i, n) {
        if (bit & (1 << i)) ++count;
      }
      res = max(res, count);
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <map>
#include <vector>
#include <numeric>

using namespace std;

int gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main(void){
    long long n, m;
    cin >> n >> m;
    string s, t;
    cin >> s;
    cin >> t;

    long long lcm = (n * m) / gcd(n, m);

    long long si = 0, ti = 0;
    long long sii = 0, tii = 0;
    long long ans = -1;
    while (true){
        while(si < ti) {
            sii++;
            si = sii * (lcm / n);
        }

        if (sii >= n) {
            ans = lcm;
            break;
        }

        if (si == ti && s.at(sii) != t.at(tii)){
            break;
        }

        tii++;
        ti = tii * (lcm / m);
        while (ti < si){
            tii++;
            ti = tii * (lcm / m);
        }

        if (tii >= m) {
            ans = lcm;
            break;
        }
        if (si == ti && s.at(sii) != t.at(tii)){
            break;
        }

        sii++;
        si = sii * (lcm / n);
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
num = gets
car_m = gets
sum = car_m.to_i
sum_ar = Array.new
num.to_i.times do |index|
	car_i = gets.split(nil)
	sum = sum + car_i[0].to_i - car_i[1].to_i
	if sum < 0
		puts "0"
		break
	end
	sum_ar[index] = sum
end
if sum >= 0
	sorted = sum_ar.sort
	puts sorted[-1]
end

Measured memory_bytes: 8856
from math import ceil

n = int(input())
csfl = [tuple(map(int, input().split())) for _ in range(n-1)]

for i in range(n-1):
    c,s,f = csfl[i]
    t = s+c
    for j in range(i+1,n-1):
        c,s,f = csfl[j]
        if t <= s:
            t = s
        else:
            t = ceil(t/f)*f
        t += c
    print(t)

print(0)

Measured memory_bytes: 74080
#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;
	int main()
	{
		std::ios::sync_with_stdio(false);
		int n,m;
		cin>>n>>m;
		int a[m];
		for(int i=0;i<m;i++) cin>>a[i];

		int sum=accumulate(a,a+m,0);
		if(sum>n)
			cout<<-1<<endl;
		else
			cout<<n-sum<<endl;
		return 0;
	}


Measured memory_bytes: 3656
#include <iostream>
#define M 100000
#define S 2000000000
using namespace std;

struct card{
  int num;
  char d;
};

void merge(card *a, int l,int m,int r){

  card L[M / 2 + 2];
  card R[M / 2 + 2];

  int n1 = m - l;
  int n2 = r - m;
  int b = 0,c = 0;
  for(int i = 0;i < n1;i++) L[i] = a[l + i];
  for(int i = 0;i < n2;i++) R[i] = a[m + i];
  L[n1].num = R[n2].num = S;
  for(int k = l;k < r;k++){
    if(L[b].num <= R[c].num){
      a[k] = L[b++];
    }
    else{
      a[k] = R[c++];
    }

  }
}


void mergeSort(card *a,int l,int r){
  int m;
  if(l + 1 < r){
    m = (l + r) / 2;
    mergeSort(a,l,m);
    mergeSort(a,m,r);
    merge(a,l,m,r);
  }
}

int partition (card *a,int p,int r){

  int i;
  card t,x;
  x = a[r];

  i = p - 1;

  for(int j = p;j < r;j++){

    if(a[j].num <= x.num){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }

  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;
  return i + 1;
}

void quickSort(card *a,int p,int r){
  int q;
  if(p < r){
    q = partition(a,p,r);
    quickSort(a,p,q - 1);
    quickSort(a,q + 1,r);
  }
}


int main(){

  int n;
  cin >> n;
  char in;
  bool flag = true;

  card a[100000];
  card b[100000];

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

mergeSort(a,0,n);
quickSort(b,0,n-1);

for(int i = 0;i < n;i++){
  if(a[i].d != b[i].d) flag = false;
}

  if(flag) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  for(int i = 0;i < n;i++){
    cout << b[i].d << ' ' << b[i].num << endl;
  }
}

Measured memory_bytes: 5424
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
struct edge
{
    int to, cost;
};
vector<vector<edge>> G(1e5 + 1);
int V, E;

vector<ll> dijkstra(int s) {
    vector<ll> dis(V, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    dis[s] = 0;
    while (!que.empty()) {
        P p = que.top(); que.pop();
        if (dis[p.second] < p.first) continue;
        for (auto e : G[p.second]) {
            if (dis[p.second] + e.cost < dis[e.to]) {
                dis[e.to] = dis[p.second] + e.cost;
                que.push(P(dis[e.to], e.to));
            }
        }
    }

    return dis;
}
int main()
{
    int s;
    cin >> V >> E >> s;
    rep(i, E) {
        int s, t, d;
        cin >> s >> t >> d;
        G[s].push_back({t, d});
    }

    vector<ll> dis = dijkstra(s);
    rep(i, V) {
        if (dis[i] == INF) cout << "INF" << endl;
        else cout << dis[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 13392
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(5)]

    ans = 0
    neck = min(A)

    ans += N // neck + 4
    if N % neck != 0:
        ans += 1

    return ans


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


Measured memory_bytes: 3060
def f():
    s = input()
    t = input()
    ls, lt = len(s), len(t)
    dp = [[0] * (ls + 1) for _ in range(lt + 1)]
    for i in range(lt):
        for j in range(ls):
            if s[j] == t[i]:
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])
    r = ''
    i += 1
    j += 1
    while (i > 0 and j > 0):
        if dp[i][j] == dp[i][j - 1]:
            j -= 1
        elif dp[i][j] == dp[i - 1][j]:
            i -= 1
        else:
            r = s[j - 1] + r
            j -= 1
            i -= 1
    return r
 
 
if __name__ == '__main__':
    ans = f()
    print(ans)

Measured memory_bytes: 112348
#include<bits/stdc++.h>
using namespace std;
long long sa[100000];
int main(void){
	long long n,k,t,tt,ans,i;
	cin>>n>>k;
	ans=n;
	cin>>t;
	t++;
	for(i=0;i<n-1;i++){
		cin>>tt;
		sa[i]=tt-t;
		t=tt+1;
	}
	sort(sa,sa+n-1);
//	cout<<53653535<<endl;
	n=n-k;
	i=0; 
	while(n>0){
		ans+=sa[i];
		i++; n--;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3920
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	int c=0;
	for(int i=2;i<s.size();i+=2){
		if(s.substr(0,i/2)==s.substr(i/2,i/2))c=i;
	}
	cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }


int main() {
	
	int q;
	cin >> q;
	for(int cnt=0; cnt<q; cnt++){
		string s,t;
		cin >> s >> t;
		vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1));
		for(int i=0; i<s.size(); i++){
			for(int j=0; j<t.size(); j++){
				if(s.at(i)==t.at(j)) dp.at(i+1).at(j+1) = dp.at(i).at(j) + 1;
				else  dp.at(i+1).at(j+1) = max( dp.at(i).at(j+1) , dp.at(i+1).at(j) );
			}
		}
		cout << dp.at(s.size()).at(t.size())<<endl;
	}
}


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

int main() {
  int q, h, s, d, n;
  scanf("%d%d%d%d%d", &q, &h, &s, &d, &n);
  if (h > 2 * q) {
    h = 2 * q;
  }
  if (s > 2 * h) {
    s = 2 * h;
  }
  if (d > 2 * s) {
    d = 2 * s;
  }
  printf("%lld\n", (long long) (n / 2) * d + (n % 2) * s);
}


Measured memory_bytes: 256