akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int comb(int N,int two){
  if(two==1){
    return N;
  }
  else if(N==two||two==0){
    return 1;
  }
  else{
    return (comb(N-1,two-1)+comb(N-1,two));
  }
}

int main(){
  int N,M,sum_s=0,sum_m=0;
  cin>>N>>M;
  if(N>=2){
    sum_s=comb(N,2);
  }
  if(M>=2){
    sum_m=comb(M,2);
  }
  cout<<sum_s+sum_m<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, ll> P;

const ll MOD=1000000007;
int l[200010], r[200010];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin>>N>>M;
    rep(i,0,N){
        ll L,R;
        cin>>L>>R;
        if(L) l[L-1]++;
        if(R<=M) r[R-1]++;
    }
    rer(i,M-1,0){
        l[i]+=l[i+1];
    }
    rep(i,1,M){
        r[i]+=r[i-1];
    }
    int res=1e8;
    ll ans=0;
    rep(i,0,M){
        res=min(res-1,l[i]);
        if(res==0){
            ans=i;
            break;
        }
        if(i==M-1) ans=M;
    }
    res=1e8;
    rep(i,0,M){
        res=min(res-1,r[M-1-i]);
        if(res==0){
            ans+=i;
            break;
        }
        if(i==M-1) ans+=M;
    }
    cout <<max(0LL,N-min(ans,M))<<"\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <math.h>
typedef long long int ll;
#define pb(b) push_back(b)
vector<ll> inc,dec;
  
int main()
{
    cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
    
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

    ll n,k,ans=0,a,b,c;
    string s,t;
    bool found = false;
 
    cin>>a>>b>>c>>k;
    if( k <= a)
        ans = k;
    else if ( k <= (a+b))
    {
        ans = a;
    }
    else
    {
        ans = a;
        k -= (a+b);
        ans -= k;
    }
    
    
    cout<<ans<<"\n";
    
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    long a,b,c,d;
    cin >> a >> b >> c >> d;
    long long ans,ans1;
    ans = a*c;
    ans1 = a*d;
    if(ans<ans1) ans = ans1;
    ans1 = b*c;
    if(ans<ans1) ans = ans1;
    ans1 = b*d;
    if(ans<ans1) ans = ans1;
    
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

signed main() {

	fastio();
//	#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/
	int n;
	cin>>n;
	cout<<(n*n*n);
	return 0;
 
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,m,k,ans,x,b,n,sum,c,a;
    	cin>>x>>a;
    	if(x<a)
    	cout<<0;
    	else
    	cout<<10;
		    	
    } 
	return 0;
}

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

const double PI = acos(-1);

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int a, b, x;
	cin >> a >> b >> x;
	if (a * a * b <= 2 * x) {
		double t = a * a * b - x;
		t = t * 2 / (1.0 * a * a);
		double angle = atan(a / t);
		cout << setprecision(10) << fixed << (PI / 2 - angle) * 180 / PI;
	} else {
		long double t = ((double)2 * x) / (a * b);
		long double angle = atan(b / t);
		cout << setprecision(10) << fixed << angle * 180 / PI;
	}
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  int N;
  int A[100000];
  long long int head[100000];
  long long int tail[100000];
  
  scanf("%d",&N);
  for(int i=0;i<N;i++)
    scanf("%d",&A[i]);

  head[0] = 0;
  for(int i=1;i<N;i++)
    head[i] = A[i-1]-head[i-1];

  tail[N-1] = A[N-1];
  for(int i=N-2;i>=0;i--)
    tail[i] = A[i]-tail[i+1];

  for(int i=0;i<N-1;i++)
    printf("%lld ",head[i]+tail[i]);
  printf("%lld\n",head[N-1]+tail[N-1]);

  return 0;
}


Measured memory_bytes: 3200
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=list(map(lambda x:int(x)-1,readline().split()))

    d=[]
    x=0
    while pow(2,x)<k:
        li=[0]*n
        if x==0:
            for i in range(n):
                li[i]=a[i]
            d.append(li)
        else:
            for i in range(n):
                j=d[x-1][i]
                li[i]=d[x-1][j]
            d.append(li)
        x+=1

    l=bin(k)[2:]
    x=len(l)
    ans=0
    for i in range(x):
        j=x-i-1
        if l[i]=="1":
            ans=d[j][ans]

    print(ans+1)

if __name__=="__main__":
    main()

Measured memory_bytes: 176232
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>
#include<limits>
#include <unordered_map>
#include <numeric>
#include <array>
#include <queue>
#include <chrono>

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

#define rep(i,n,m) for(long long int i=n;i<(long long int)(m);i++)
#define INF (1<<29)
#define MD 1000000007

int main() {

	double a, g;
	cin >> a >> g;

	cout << g * 2 - a << endl;


	

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=a%10;
a/=10;
int c=a%10;
a/=10;
a%=10;
int ans=Int(a)+Int(b)+Int(c);
System.out.println(ans);
	}

	public static int Int(int i) {

		int op=0;
		if(i==1) {
		op=1;
		}
		
		// TODO 自動生成されたメソッド・スタブ
		return op;
	}
}

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

int main(){
  long long n;
  cin>>n;
  long long arr[n];
  long long a=0, ans=0;
  for(long long i =0;i<n;i++){
    cin>>arr[i];
    if(arr[i]<=a){
      ans += a-arr[i];
    }
    else{
      a= arr[i];
    }
   
  }
  cout<<ans;

}



Measured memory_bytes: 5080
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

const ll mod = 1e9 + 7;

ll power_ll_p(ll a, ll b, ll p)	//F_pでのべき
{
  if (b > p)
  {
    b %= (p - 1);//位数p-1
  }
  if (b == 0)
  {
    return 1;
  }
  if (b % 2 == 0)
  {
    ll t = power_ll_p(a, b / 2, p);
    return t * t % p;
  }
  else
  {
    return a * power_ll_p(a, b - 1, p) % p;
  }
}


ll combination_p(ll n, ll r, ll p)	//コンビネーション
{
  if (r > n - r)
  {
    r = n - r;
  }
  ll ans = 1;
  for (ll i = 0; i < r; i++)
  {
    ans *= n - i;
    ans %= p;
  }
  ll subans = 1;
  for (ll i = 0; i < r; i++)
  {
    subans *= i + 1;
    subans %= p;
  }
  ans *= power_ll_p(subans, p - 2, p);		//逆元は^(p-2)
  ans %= p;
  return ans;
}

ll extgcd(ll a, ll b, ll&x, ll&y)
{
  if (b == 0)
  {
    x = 1;
    y = 0;
    return a;
  }
  else
  {
    ll q = a / b;
    ll g = extgcd(b, a - q * b, x, y);
    ll z = x - q * y;
    x = y;
    y = z;
    return g;
  }
}

//modp逆元
ll inversemod(ll a, ll p)
{
  ll x, y;
  extgcd(a, p, x, y);
  x %= p;
  if (x < 0)
  {
    x += p;
  }
  return x;
}

int main()
{
  ll n, m, k;
  cin >> n >> m >> k;
  ll x = m * (n * n - 1) + n * (m * m - 1);
  x %= mod;
  x *= m * n;
  x %= mod;
  x *= inversemod(6, mod);
  x %= mod;
  x *= combination_p(n * m - 2, k - 2, mod);
  cout << ((x % mod) + mod) % mod << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000000000000ll
#define N 1000005
#define M 4000005
using namespace std;

const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
int H,W,n,cnt,C,tot,fst[N],pnt[M],nxt[M];
int hsh[2010527],nxt_h[M],mn[M],pos[N];
ll d[N],len[M]; bool bo[N];
struct node{ int x,y,z,id; }p[N];
int getdct(char c){
	if (c=='N') return 0; else if (c=='S') return 1;
	else if (c=='W') return 2; else return 3;
}
int calc(int x,int y,int z){
	//if (x<=0 || x>H || y<=0 || y>W) return 0;
	int t=(x*100000ll+y)%2010527,i;
	for (i=hsh[t]; i; i=nxt_h[i]) if (p[i].x==x && p[i].y==y && p[i].z==z) return i;
		//cout<<x<<' '<<y<<' '<<z<<' '<<cnt+1<<endl;
	cnt++; p[cnt]=(node){x,y,z,cnt}; nxt_h[cnt]=hsh[t]; hsh[t]=cnt;
	return cnt;
}
void add(int x,int y,ll z){
	if (!x || !y) return;
	//	cout<<"				"<<x<<' '<<y<<' '<<z<<endl;
	pnt[++tot]=y; len[tot]=z; nxt[tot]=fst[x]; fst[x]=tot;
}
void build(int k,int l,int r){
	mn[k]=l; if (l==r){ pos[l]=k; return; }
	int mid=l+r>>1;
	build(k<<1,l,mid); build(k<<1|1,mid+1,r);
}
void mdy(int x){
	int i;
	for (i=pos[x]>>1; i; i>>=1)
		mn[i]=(d[mn[i<<1]]<d[mn[i<<1|1]])?mn[i<<1]:mn[i<<1|1];
}
bool cmpx(node u,node v){
	return u.x<v.x || u.x==v.x && u.y<v.y || u.x==v.x && u.y==v.y && u.z<v.z;
}
bool cmpy(node u,node v){
	return u.y<v.y || u.y==v.y && u.x<v.x || u.x==v.x && u.y==v.y && u.z<v.z;
}
int main(){
	scanf("%d%d%d%d",&H,&W,&n,&C);
	int x1,x2,y1,y2,i,j,k,l,x,y,cst; char c;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	calc(x1,y1,0); calc(x2,y2,0);
	for (i=1; i<=2; i++) add(calc(x2,y2,i),calc(x2,y2,0),0);
	for (i=1; i<=n; i++){
		scanf("%d%d %c%d%d",&x,&y,&c,&l,&cst);
	//	cout<<"("<<c<<")"<<endl;
		k=getdct(c);
	//	cout<<k<<endl;
	//	cout<<x<<' '<<y<<' '<<c<<' '<<l<<' '<<cst<<endl;
		for (j=1; j<=2; j++)
			add(calc(x,y,j),calc(x,y,0),0);
		for (j=0; j<4; j++)
			add(calc(x,y,0),calc(x+dx[j]*l,y+dy[j]*l,(j>1)?1:2),(j==k)?0:cst);
	}
	//cout<<cnt<<endl;
	sort(p+1,p+cnt+1,cmpx);
	for (i=1; i<=cnt; i=j)
		for (j=i,k=0; p[i].x==p[j].x; j++){
		//	cout<<p[j].x<<' '<<p[j].y<<' '<<p[j].z<<endl;
			if (p[j].z==1){
				add(p[j].id,p[k].id,(ll)(p[j].y-p[k].y)*C);
				add(p[k].id,p[j].id,(ll)(p[j].y-p[k].y)*C);
				k=j;
			}
		}
	sort(p+1,p+cnt+1,cmpy);
	for (i=1; i<=cnt; i=j)
		for (j=i,k=0; p[i].y==p[j].y; j++)
			if (p[j].z==2){
				add(p[j].id,p[k].id,(ll)(p[j].x-p[k].x)*C);
				add(p[k].id,p[j].id,(ll)(p[j].x-p[k].x)*C);
				k=j;
			}
	for (i=2; i<=cnt; i++) d[i]=inf;
	memset(bo,1,sizeof(bo));
	build(1,1,cnt);
	for (i=1; i<=cnt; i++){
		x=mn[1]; if (x==2) break;
		bo[x]=0;
		for (j=fst[x]; j; j=nxt[j]){
			y=pnt[j];
			if (bo[y] && d[x]+len[j]<d[y]){
		//	cout<<x<<"->"<<y<<endl;
				d[y]=d[x]+len[j]; mdy(y);
			}
		}
		d[x]=inf; mdy(x);
	}
	printf("%lld\n",(d[2]<inf)?d[2]:-1);
	return 0;
}


Measured memory_bytes: 73984
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, A[3][3], b[10];
  bool appear[3][3];
  bool jud = true;
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
      cin >> A[i][j];
    }
  }
  cin >> N;
  for (int i=0; i<N; i++){
    cin >> b[i];
  }
  for (int j=0; j<3; j++){
    for (int k=0; k<3; k++){
      appear[j][k] = false;
      for (int i=0; i<N; i++){
        if (A[j][k]==b[i]){
          appear[j][k]=true;
        }
      }
    }
  }
  string ans = "No";
  if (appear[0][0]==true && appear[1][1]==true && appear[2][2]==true){
    ans = "Yes";
  }
  if (appear[0][2]==true && appear[1][1]==true && appear[2][0]==true){
    ans = "Yes";
  }
  for (int i=0; i<3; i++){
    if (appear[i][0]==true && appear[i][1]==true && appear[i][2]==true){
      ans = "Yes";
    }
  }
  for (int i=0; i<3; i++){
    if (appear[0][i]==true && appear[1][i]==true && appear[2][i]==true){
      ans = "Yes";
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private final String s;

    public Main() {
	s = scan.next();

	scan.close();
    }

    public final void answer() {
	StringBuilder ans = new StringBuilder();

	for (int i = 0; i < s.length(); i++) {
	    if(i % 2 == 0)
		ans.append(s.charAt(i));
	}

	System.out.println(ans.toString());
    }
}


Measured memory_bytes: 25680
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int [] V = new int[N];
		int [] C = new int[N];
		int max = 0;
		for (int i=0;i<N;i++) {
			V[i]=sc.nextInt();		
		}
		for (int i=0;i<N;i++) {
			C[i]=sc.nextInt();
			if(V[i]-C[i]>0) {
				max+=V[i]-C[i];
			}
		}
		sc.close();
		System.out.print(max);
	}
}

Measured memory_bytes: 23252
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		final int opened = -1;
		Scanner sc = new Scanner(System.in);

		//入力
		int [][]bingo = new int[3][3];
		for (int y = 0; y < 3; y++) {
			for (int x = 0; x < 3; x++) {
				bingo[x][y] = sc.nextInt();
			}
		}
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			for (int y = 0; y < 3; y++) {
				for (int x = 0; x < 3; x++) {
					if (bingo[x][y] == b) bingo[x][y] = opened;
				}
			}
		}

		//条件チェック
		boolean is_bingo = false;
		//縦
		for (int y = 0; y < 3; y++) {
			boolean width = true;
			for (int x = 0; x < 3; x++) {
				if (bingo[x][y] != opened) {
					width = false;
					break;
				}
			}
			if (width) is_bingo = true;
		}
		//横
		for (int x = 0; x < 3; x++) {
			boolean height = true;
			for (int y = 0; y < 3; y++) {
				if (bingo[x][y] != opened) {
					height = false;
					break;
				}
			}
			if (height) is_bingo = true;
		}
		//斜め
		if (bingo[2][0] == opened && bingo[1][1] == opened && bingo[0][2] == opened) {
			is_bingo = true;
		}
		if (bingo[0][0] == opened && bingo[1][1] == opened && bingo[2][2] == opened) {
			is_bingo = true;
		}

		if (is_bingo) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		/*for (int y = 0; y < 3; y++) {
			for (int x = 0; x < 3; x++) {
				System.out.print(bingo[x][y] + " ");
			}
			System.out.println();
		}*/
	}
}

Measured memory_bytes: 35780
a;long d[2<<17],*p,m=1e9+7;f(){*p+=p[1];d-p--&&f();*p=(*p-p++[a+1])%m;}main(k){scanf("%*d%d",&k);p=d+k;for(*p=1;~scanf("%d",&a);)f();printf("%ld",*d);}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

vector<int> prime_vector(int n) {
    int m = (int)sqrt(n - 1);

    vector<bool> q(n);
    for (int i = 2; i <= m; i++) {
        if (q[i]) continue;
        for (int j = i * i; j < n; j += i) {
            q[j] = true;
        }
    }

    vector<int> p; p.reserve(n / log(n * 0.329));
    for (int i = 2; i < n; i++) {
        if (!q[i]) p.push_back(i);
    }
    return p;
}

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

    auto pv = prime_vector(200000);

    for (auto &p : pv) {
        if (p >= x) {
            cout << p << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 768
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int N = GetInt();
		int A = GetInt();
		int B = GetInt();
		int max = Math.Min(A, B);
		int min = Math.Max(0, A + B - N);
		Console.WriteLine($"{max} {min}");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int count = 0;
		for (int i = 1; i < arr.length; i++) {
		    if (arr[i] == arr[i - 1]) {
		        count++;
		    }
		}
		System.out.println(Math.min(count + k * 2, n - 1));
   }
}




Measured memory_bytes: 26416
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	string N;
	cin >> N;
	for (int i = 0; i < N.size(); i++) {
		if (N[i] - '0' == 1)N[i] = 9 + '0';
		else if (N[i] - '0' == 9)N[i] = 1 + '0';
	}
	cout << N << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr long long int mod = 1000000007, MOD = 998244353;
constexpr double PI = 3.14159265358979323846;

int main() {
	int X, Y;
	cin >> X >> Y;
	for (size_t i = 0; i <= X; i++)
	{
		if (2 * i + 4 * (X - i) == Y) {
			cout << "Yes"; return 0;
		}
	}
	cout << "No";
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

int n,m;
int d[100][100];
int dp[1<<15][100];

signed main(){
  cin>>n>>m;
  for(int i=0; i<n; i++) for(int j=0; j<n; j++) d[i][j]=INF;
  for(int i=0; i<m; i++){
    int a,b,c; cin>>a>>b>>c;
    d[a][b]=c;
  }
  for(int s=0; s<(1<<15); s++){
    fill(dp[s], dp[s]+n, INF);
  }
  
  dp[(1<<n)-1][0]=0;
  
  for(int S=(1<<n)-2; S>=0; S--){
    for(int v=0; v<n; v++){
      for(int u=0; u<n; u++){
        if(!(S>>u&1)){
          dp[S][v]=min(dp[S][v], dp[S|1<<u][u]+d[v][u]);
        }
      }
    }
  }
  if(dp[0][0]<INF) cout<<dp[0][0]<<en;
  else cout<<-1<<en;
}



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

int main()
{
    ll h , w ;
    while(cin >> h >> w)
    {
        if(h == 0 && w == 0) break ;
        for(ll i = 0 ; i < h ; i++)
        {
            if(i == 0 || i == (h - 1))
            {
                for(ll j = 0 ; j < w ; j++) cout << '#' ;
            }
            else
            {
                cout << '#' ;
                for(ll j = 1 ; j < (w - 1) ; j++) cout << '.' ;
                cout << '#' ;
            }
            cout << endl ;
        }
        cout << endl ;
    }
}


Measured memory_bytes: 3020
import fractions
N = int(input())
num = list(map(int,input().split()))
ans = num[0]
for i in range(1,N) :
    ans = fractions.gcd(ans,num[i])

if ans % 2 == 1 :
    print(0)
else :
    cnt = 0
    while ans/2 == int(ans/2) :
        ans /= 2
        cnt += 1
    print(cnt)

Measured memory_bytes: 5048
#include <iostream>

using namespace std;

int main() {
    string a;
    cin >> a;
    if(a.at(0) == a.at(1)&&a.at(1) == a.at(2)){
        cout << "Yes" << endl;
    }
    else if(a.at(1) == a.at(2) && a.at(2) == a.at(3)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main() {
	int r;
	

	cin >> r;


	cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;
 
    ll x = n%k;
 
    out(min(x, k - x));
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main()
{
    int a, b; 
    cin >> a; 
    cin >> b; 
    if (a > 0 && a < 10 && b > 0 && b < 10)
        cout << a * b << endl; 
    else 
        cout << -1 << endl; 
    return 0; 
}

Measured memory_bytes: 256
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        x: usize
    }

    let mut money = 100;
    let mut year = 0;

    while money < x {
        money = (money as f64 * 1.01).floor() as usize;
        year += 1;
    }

    println!("{}", year);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2756
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

int main(void)
{
  int a, p;
  cin >> a >> p;
  int kakera;
  kakera = a * 3 + p;
  cout << kakera / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
    int n,l,a[200],sum;
    cin >> n >> l;
    rep(i,n) a[i] = l + i;
    int mini = 0;
    for(int i=0;i<n-1;i++){
         if(abs(a[mini]) > abs(a[i+1]) )mini = i+1;
    }
    a[mini] = 0;
    rep(i,n) sum += a[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	int d = scan.nextInt();
	int n = scan.nextInt();

	if(n == 100){
	    System.out.println((int)(n*Math.pow(100,d)+1*Math.pow(100,d)));
	}else{
	    System.out.println((int)(n*Math.pow(100,d)));
	}
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int a;
    int b;
}stu[105];
struct student
{
    int a;
    int b;
}st[105];
bool cmp(node x,node y)
{
    if(x.a!=y.a)
        return x.a>y.a;
    else return x.b>y.b;
}
bool comp(student x,student y)
{
    if(x.a!=y.a)
        return x.a>y.a;
    else return x.b>y.b;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d%d",&stu[i].a,&stu[i].b);
    sort(stu,stu+n,cmp);
    for(int i=0;i<n;i++)
        scanf("%d%d",&st[i].a,&st[i].b);
    sort(st,st+n,comp);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int x=300,y=300;
        for(int j=0;j<n;j++)
        {
            if(st[j].a!=300)
            {
                if(st[j].a>stu[i].a&&st[j].b>stu[i].b)
                {
                    if(st[j].a<x&&st[j].b<y)
                    {
                        x=st[j].a;
                        y=st[j].b;
                    }
                }
            }
        }
        for(int j=0;j<n;j++)
        {
            if(st[j].a!=300)
            {
                if(st[j].a>stu[i].a&&st[j].b>stu[i].b&&st[j].a==x&&st[j].b==y)
                {
                    ans++;
                    st[j].a=300;
                    break;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
A,B,C = map(int, input().split())
K=int(input())
X=0

X=max([A,B,C])

if(X==A):
    A=X*pow(2,K)
elif(X==B):
    B=X*pow(2,K)
else:
    C=X*pow(2,K)

print(A+B+C)

Measured memory_bytes: 3064
#codng utf-8
N, x = map(int,input().split())
A = list(map(int,input().split()))

A.sort()
ans = 0

for i in range(N):
    x -= A[i]
    if x >= 0:
        ans += 1
    else:
        break
if x > 0:
    ans -= 1
print(ans)

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

int main(){
	string S;
	cin >> S;
	int am = 0;
	for(int i=0;i<(int)S.length();i++){
		am += S[i] - '0';
		am %= 9;
	}
	if(am == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3708
#include <stdio.h>

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

	double pr = 0;
	if (k <= n) pr = n-k+1;

	for (int i = 1; i <= n && i < k; i++) {
		int s = i, cnt = 0;
		while (s < k) {
			cnt++;
			s *= 2;
		}
		pr += 1.0/(1<<cnt);
	}
	printf("%.9f\n", pr/n);
}


Measured memory_bytes: 128
// 物极必反

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 5e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 998244353;
const long long INF = 1e18 + 9;
const int SM = 3e3 + 5;
const int logN = 22, BL = 400;
const long double EPS = 1e-14;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, k; cin >> n >> k;

    long long ans = n, i = 1e6 * 1ll;

    while(i--){
        if(n >= k) n %= k;
        else n = abs(n - k);
        ans = min(ans, n);
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main(void){
    int num,park = 0,input[10];
    while(scanf("%d",&num) != EOF){
        if(num == 0){
            park --;
            printf("%d\n",input[park]);
        }
        else {
            input[park] = num;
            park ++;
        }
    }
    return 0;
}

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

#define MAX 50

int main(){
    int i, n;
    char c[MAX];
    cin >> n >> c;
    i = 0;
    int cnt = 0;
    for(i=0; i<n-2; i++){
        if(c[i] == 'A' && c[i+1] == 'B' && c[i+2] == 'C'){
            cnt++;
        }

    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  N, K=map(int,input().split())
  sushies=[list(map(int,input().split())) for i in range(N)]
  sushies.sort(reverse=True, key=lambda x:x[1])
  dsum=0
  tset=set()
  kubi=[]
  for i in range(K):
    dsum+=sushies[i][1]
    t=sushies[i][0]
    if t in tset:
      kubi.append(sushies[i])
    tset.add(t)
  x=len(tset)
  koho=[]
  for i in range(K,N):
    t=sushies[i][0]
    if not(t in tset):
      koho.append(sushies[i])
      tset.add(t)
  ind=0
  ans=dsum+x*x
  while(ind < len(kubi) and ind < len(koho)):
    dsum=dsum-kubi[-1-ind][1]+koho[ind][1]
    x+=1
    ans=max(ans, dsum+x*x)
    ind+=1
  print(ans)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 107944
from math import gcd

n, m = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
B = [a // 2 for a in set(A)]

lcm = 1
div2_count = -1
for b in B:
    lcm = lcm * b // gcd(lcm, b)
    if lcm > m:
        print(0)
        exit()
    count = 0
    while b % 2 == 0:
        b //= 2
        count += 1
    if div2_count == -1 or div2_count == count:
        div2_count = count
    else:
        print(0)
        exit()

limit = m // lcm
ans = (limit + 1) // 2
print(ans)

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

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  
  int sum=0;
  vector<int> a(m);
  for(int i=0;i<m;i++){
    cin >> a.at(i);
    sum+=a.at(i);
  }
  if(n-sum>=0){
    cout << n-sum << endl;
  }else{
    cout << "-1" << endl;
  }
}


Measured memory_bytes: 3672
use std::cmp::{max,min};
fn main() {
    let (n,w) = {
        let s = rv::<usize>();
        (s[0],s[1])
    };
    let mut wv = Vec::with_capacity(n);
    for _ in 0..n {
        let s = rv::<usize>();
        wv.push((s[0],s[1]));
    }
    let wm = wv.iter().map(|wv|wv.0).min().unwrap();
    let wn = wv.iter().map(|wv|wv.0-wm).max().unwrap();
    let mut dp = vec![vec![0;wn*n+1];n+1];
    for (i,(w,v)) in wv.into_iter().enumerate() {
        let w=w-wm;
        for j in (1..i+2).rev() {
            for k in 0..w {
                dp[j][k]=max(dp[j][k],dp[j-1][k]);
            }
            for k in 0..wn*(j-1)+1 {
                dp[j][k+w]=max(dp[j][k+w],dp[j-1][k]+v);
            }
            for k in wn*(j-1)+w+1..wn*j+1 {
                dp[j][k]=max(dp[j][k],dp[j][k-1]);
            }
        }
    }
    let mut t=0;
    for i in 1..n+1 {
        if wm*i>w {
            break;
        }
        t = max(t,dp[i][min(w-wm*i,wn*i)]);
    }
    println!("{}",t);
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

Measured memory_bytes: 4352
import Data.Int
import Data.List
import Data.Array
import Data.Ix (range)

modulo :: Int64
modulo = 10^9 + 7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod x y = (x + y) `rem` modulo
subMod x y = (x - y) `mod` modulo
mulMod x y = (x * y) `rem` modulo
sumMod :: [Int64] -> Int64
sumMod = foldl' addMod 0

data Base = A | C | G | T deriving (Eq,Show,Ord,Enum,Ix)

bases :: [Base]
bases = [A,C,G,T]

baseTripleInterval :: ((Base,Base,Base),(Base,Base,Base))
baseTripleInterval = ((A,A,A),(T,T,T))

baseTripleRange :: [(Base,Base,Base)]
baseTripleRange = range baseTripleInterval

sumArr :: Array (Base,Base,Base) Int64 -> Int64
sumArr = sumMod . elems

-- 出力 a:
--   a ! (s,t,u) : 問題文の条件を満たす長さ 3 の文字列のうち、stuから始まるもの
data3 :: Array (Base,Base,Base) Int64
data3 = array baseTripleInterval
        [ (i,val)
        | i <- baseTripleRange
        , let val | i `elem` [(A,G,C),(G,A,C),(A,C,G)] = 0
                  | otherwise = 1
        ]

-- sumArr data3 == 61

-- 入力 a:
--   a ! (s,t,u) : 問題文の条件を満たす長さ k の文字列のうち、stuから始まるもの
-- 出力 a':
--   a' ! (s,t,u) : 問題文の条件を満たす長さ k+1 の文字列のうち、stuから始まるもの
step :: Array (Base,Base,Base) Int64 -> Array (Base,Base,Base) Int64
step arr = let n = sumArr arr -- 問題文の条件を満たす長さ k の文字列の個数
           in array baseTripleInterval
              [ (i,val)
              | i@(s,t,u) <- baseTripleRange
              , let val | i `elem` [(A,G,C),(G,A,C),(A,C,G)] = 0
                        -- 4文字のダメなパターンで、3文字パターンを含まないもの：ATGC, AGTC, AGGC
                        | i == (A,T,G) = sumMod [arr ! (t,u,v) | v <- [A,G,T]]
                        | i == (A,G,T) = sumMod [arr ! (t,u,v) | v <- [A,G,T]]
                        | i == (A,G,G) = sumMod [arr ! (t,u,v) | v <- [A,G,T]]
                        | otherwise = sumMod [arr ! (t,u,v) | v <- [A,C,G,T]]
              ]

main = do
  n <- readLn
  print $ sumArr $ iterate step data3 !! (n - 3)


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

int main(){
    int A,B,C,X,Y;
    int min_c=100000000000;
    cin>>A>>B>>C>>X>>Y;

        for(int i=0;i<=X+Y;++i){
            int sum=2*C*i+A*max(0,X-i)+B*max(0,Y-i);
            min_c=min(min_c,sum);
        }
     cout<<min_c;
    

}

Measured memory_bytes: 3164
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		// 入力読み込み
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String S = scan.next();
		// 入力終わり
		scan.close();
		// ユニコードを取得し、Nを足した配列を生成
		byte[] charNum = new byte[S.length()];
		for(int i=0;i<S.length();i++){
			int tmp=S.codePointAt(i)+N;
			// Z(90)より大きいユニコードになった場合、A(65)から数えなおす
			while(tmp>90) {
				tmp=tmp-26;
			}
			// N足した後のユニコードを格納
			charNum[i]=(byte) (tmp);
		}
		// 生成した配列から文字変換、結果出力
		for(int i=0;i<S.length();i++){
			System.out.print((char) (charNum[i]));
		}
	}
}

Measured memory_bytes: 25124
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K; cin >> N >> K;
  cout << min(N%K, K-N%K) << endl;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> s(4,0);

    string str;
    REP(i, n){
        cin >> str;
        if(str == "AC") s[0]++;
        else if(str == "WA")s[1]++;
        else if(str == "TLE")s[2]++;
        else s[3]++;
    }

    cout << "AC x " << s[0] << endl;
    cout << "WA x " << s[1] << endl;
    cout << "TLE x " << s[2] << endl;
    cout << "RE x " << s[3] << endl; 

}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC117 {
	class ABC117_B {
		static void Main(string[] args) {
			var N = int.Parse(Console.ReadLine());
			var L = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
			var lmax = L.Max();
			L.Remove(lmax);
			if(lmax < L.Sum()) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}
		}
	}
}


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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

int main() {
    int N;
    cin >> N;
    int Nini = N;
    int f = 0;
    while ( N > 0 ){
        int x = N % 10, y = N / 10;
        f += x;
        N = y;
    }
    
    bool flg = false;
    if ( Nini % f == 0 ) flg = true;
    
    if ( flg ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3588
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    A = []
    A_num = {}
    A_num[1] = 2
    A_num[2] = 5
    A_num[3] = 5
    A_num[4] = 4
    A_num[5] = 5
    A_num[6] = 6
    A_num[7] = 3
    A_num[8] = 7
    A_num[9] = 6
    for i in range(M):
        A.append(int(input_raw[i]))

    dp = [0] * (N + 1)
    A.sort(reverse = True)

    for i in range(1, N + 1):
        max_num = -sys.maxint
        for a in A:
            if i - A_num[a] >= 0 and dp[i - A_num[a]] >= 0:
                max_num = max(max_num, dp[i - A_num[a]] + 1)
        dp[i] = max_num

    remain = N
    s = ""
    for i in range(dp[N]):
        for a in A:
            if remain - A_num[a] >= 0:
                if dp[remain - A_num[a]] == dp[remain] - 1:
                    s += str(a)
                    remain = remain - A_num[a]
                    break
    print s



if __name__ == '__main__':
    main()


Measured memory_bytes: 33512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t a,b,n;
  cin >> a >> b >> n;
  int64_t x,maxi=0;
  int64_t p=min(b-1,n);
  int64_t q=p/b;
  int64_t ans=a*p/b-a*q;
  cout << ans;
}

Measured memory_bytes: 3584
fun main(args: Array<String>) {
    val (n, m, x, y) = readLine()!!.split(' ').map(String::toInt)
    val xx = readLine()!!.split(' ').map(String::toInt).max()!!
    val yy = readLine()!!.split(' ').map(String::toInt).min()!!
    println(if (x < y && xx < yy && 1 < yy - x && 1 < y - xx) "No War" else "War")
}


Measured memory_bytes: 38300
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

const int INF = 1e9;

int N,M;
int u[100010];
int v[100010];
int S,T;
vector<int> G[100010];
int dist[3][100010];

int main ()
{
    cin >> N >> M;
    REP(i,M) cin >> u[i] >> v[i];
    cin >> S >> T;

    REP(i,M) {
        G[u[i]].push_back(v[i]);
    }

    REP(i,3)REP(j,100010) dist[i][j] = INF;

    // dist, idx
    reversed_priority_queue<tuple<int,int>> que;
    que.push(make_tuple(0, S));

    while (!que.empty()) {
        int dt,it;
        tie(dt,it) = que.top();
        que.pop();
        if (dist[dt % 3][it] < dt) {
            continue;
        }
        REP(i,G[it].size()) {
            int nit = G[it][i];
            int ndt = dt + 1;
            if (dist[ndt % 3][nit] > ndt) {
                dist[ndt % 3][nit] = ndt;
                que.push(make_tuple(ndt, nit));
            }
        }
    }

    cerr << "===" << endl;
    REP(i,3)REP(j,3) cerr << "mod:" << i << " " << "v:" << j + 1 << " " << dist[i][j] << endl;

    if (dist[0][T] == INF) {
        cout << -1 << endl;
    } else {
        cout << dist[0][T] / 3 << endl;
    }

    return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 60);

//==================================

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll H, W; cin >> H >> W;

    vector<Vi> S(H, Vi(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            char mas;
            cin >> mas;
            S[i][j] = (mas == '.') ? 1 : 0;
        }
    }

    vector<Vl> d(H * W, Vl(H * W, L_INF));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int idx = i * W + j;
            int idx2;
            if (S[i][j] != 1) {
                continue;
            }
            if (i - 1 >= 0 && S[i - 1][j] == 1) {
                idx2 = (i - 1) * W + j;
                d[idx][idx2] = 1;
                d[idx2][idx] = 1;
            }
            if (i + 1 < H && S[i + 1][j] == 1) {
                idx2 = (i + 1) * W + j;
                d[idx][idx2] = 1;
                d[idx2][idx] = 1;
            }
            if (j - 1 >= 0 && S[i][j - 1] == 1) {
                idx2 = i * W + j - 1;
                d[idx][idx2] = 1;
                d[idx2][idx] = 1;
            }
            if (j + 1 < W && S[i][j + 1] == 1) {
                idx2 = i * W + j + 1;
                d[idx][idx2] = 1;
                d[idx2][idx] = 1;
            }
        }       
    }

    int len = H * W;
    for (int k = 0; k < len; ++k) {
        for (int i = 0; i < len; ++i) {
            for (int j = 0; j < len; ++j) {
                if (d[i][k] == L_INF || d[k][j] == L_INF) {
                    continue;
                }
                if (i == j) {
                    continue;
                }
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }   
    }

    ll ans = 0;
    for (int i = 0; i < len; ++i) {
        for (int j = 0; j < len; ++j) {
            if (d[i][j] >= L_INF) {
                continue;
            }
            ans = max(ans, d[i][j]);
        }
    }

    cout << ans << endl;

    
    return 0;
}

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

using ll = long long;


ll cost[5100][5100];
// cost first i elements, cur max

int main(){
	int n;
	cin >> n;
	ll a, b;
	cin >> a >> b;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	if(a > b){
		swap(a, b);
		reverse(p.begin(), p.end());
		for(int i = 0; i < n; i++){
			p[i] = n + 1 - p[i];
		}
	}
	for(int i = 0; i < 5100; i++) for(int j = 0; j < 5100; j++) cost[i][j] = 1e17;
	cost[0][0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= n; j++){
			if(cost[i][j] >= ll(1e17)) continue;
			if(p[i] >= j){
				cost[i+1][j] = min(cost[i+1][j], cost[i][j] + a);
				cost[i+1][p[i]] = min(cost[i+1][p[i]], cost[i][j]);
			}
			cost[i+1][j] = min(cost[i+1][j], cost[i][j] + b);
		}
	}
	ll ans = 1e17;
	for(int j = 0; j <= n; j++){
		ans = min(ans, cost[n][j]);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 203520
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long n, m, k, x[100001], a[100001], b[100001], to[100001], cir[100001], ans[100001];
bool vis[100001];
int main(int argc, char const *argv[])
{
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &x[i]);
        b[i] = x[i] - x[i - 1];
        to[i] = i;
    }
    scanf("%lld%lld", &m, &k);
    for (int i = 1; i <= m; i++)
    {
        scanf("%lld", &a[i]);
        swap(to[a[i]], to[a[i] + 1]);
    }
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
        {
            int cnt = 0;
            for (int j = i; !vis[j]; j = to[j])
            {
                cir[++cnt] = j;
                vis[j] = 1;
            }
            for (int j = 1; j <= cnt; j++)
            {
                ans[cir[j]] = b[cir[(j + k - 1) % cnt + 1]];
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        ans[i] += ans[i - 1];
        printf("%lld.0\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 8480