akhauriyash/Code-Regression huggingface dataset:
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160

#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;

int w, h;
bool F[60][60];

struct point {
  int x, y;
};

void init() {
  fill(&F[0][0], &F[0][0]+60*60, 0);
  for (int i=1; i<=h; i++) {
    for (int j=1; j<=w; j++) {
      int temp;
      scanf("%d", &temp);
      F[i][j] = (bool) temp;
    }
  }
}

int solve() {
  int ans = 0;
  for (int i=1; i<=h; i++) {
    for (int j=1; j<=w; j++) {
      if (F[i][j]) {
	stack<point> S;
	point p = { i, j };
	S.push(p);
	while (! S.empty()) {
	  p = S.top();
	  S.pop();
	  F[p.x][p.y] = false;
	  for (int i=-1; i<=1; i++) {
	    for (int j=-1; j<=1; j++) {
	      point q = { p.x + i , p.y + j };
	      if (F[q.x][q.y]) {
		S.push(q);
	      }
	    }
	  }
	}
	ans++;
      }
    }
  }
  return ans;
}

int main() {
  while(scanf("%d%d", &w, &h) != EOF && w && h) {
    init();
    printf("%d\n", solve());
  }
}

Measured memory_bytes: 1256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0;i < n;i++){
            a.add(sc.nextInt());
        }
        long cnt4 = 0;
        long cnt2 = 0;
        for(Integer it : a){
            if(it % 4 == 0){
                cnt4++;
            }
            else if(it % 2 == 0){
                cnt2++;
            }
        }
        if(cnt4 + (cnt2 / 2) >= n / 2){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 60996
#include <bits/stdc++.h>
using i64 = long long;

template <typename T>
struct ConvexHull {
private:
    using U = std::pair<T, T>;
    std::deque<U> q;
    
    T calc(const U &p, T x) {
        return p.first * x + p.second;
    }

    T calc(int i, T x) {
        return q[i].first * x + q[i].second;
    }

    bool isUnnecessary(const U &a, const U &b, const U &c) {
        return (a.second - c.second) * (b.first - a.first) <= (a.second - b.second) * (c.first - a.first);
    }

    bool isUnnecessary(int i) {
        return isUnnecessary(q[i - 1], q[i], q[i + 1]);
    }

public:
    void add(const U &p) {
        q.push_back(p);
        int s = q.size();
        while (s >= 3 && isUnnecessary(s - 2)) {
            std::swap(q[s - 1], q[s - 2]);
            q.pop_back();
            --s;
        }
    }

    void add(T a, T b) { add(std::make_pair(a, b)); }

    T query(T x) {
        int l = -1, r = (int)q.size() - 1;
        while (r - l > 1) {
            int k = (l + r) / 2;
            if (calc(k, x) >= calc(k + 1, x)) l = k;
            else r = k;
        }
        return calc(r, x);
    }
};

int main() {
    int n;
    i64 c, r;
    std::cin >> n >> c;
    ConvexHull<i64> cht;
    for (int i = 0; i < n; i++) {
        i64 h;
        std::cin >> h;
        r = i ? cht.query(h) + h * h : 0ll;
        cht.add(-2 * h, h * h + r + c);
    }
    std::cout << r << std::endl;

    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;
 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define nl cout<<endl
#define P 1000000007
#define MOD(x) ((x%P)+P)%P
#define NMAX 100100

#define INF 100000000
int mod=1e9;

int main() 
{

    int n,w;
    cin>>n>>w;

    ll wg[n],v[n];

    for(int i=0;i<n;i++)
    {
        cin>>wg[i]>>v[i];
    }

    ll dp[n+1][w+1];

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i ==0 || j == 0)
                dp[i][j] = 0;
            else if(wg[i-1] <= j)
            {
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-wg[i-1]]+v[i-1]);
            }
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][w];

	return 0;
    	
}

Measured memory_bytes: 79104
' Imports System.Collections.Generic
' Imports System.Globalization
' Imports System.IO
' Imports System.Linq
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim S As String = Console.ReadLine()
        Dim flg As Boolean = False
        For i As Integer = 1 To S.Length - 1
            If S(i - 1) = S(i)
                flg = True
                Exit For
            End If
        Next
        Console.WriteLine(If(flg, "Bad", "Good"))
        Return
    End Sub
End Class

Measured memory_bytes: 25772
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] num = new int[6];
		int n =Integer.parseInt(sc.nextLine());
		Dice[] dice = new Dice[n];
		boolean flag=true;
		
		for(int i=0;i<n;i++){
			String[] line = sc.nextLine().split(" ");
			for(int j=0;j<6;j++){
				num[j]=Integer.parseInt(line[j]);
			}
			dice[i]=new Dice(num);
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<i;j++){			
				int[][] numSet=new int[3][2];
				numSet[0][0]=dice[i].lavel1;
				numSet[0][1]=dice[i].lavel6;
				numSet[1][0]=dice[i].lavel2;
				numSet[1][1]=dice[i].lavel5;
				numSet[2][0]=dice[i].lavel3;
				numSet[2][1]=dice[i].lavel4;
			
				int[][] exNumSet=new int[3][2];
				exNumSet[0][0]=dice[j].lavel1;
				exNumSet[0][1]=dice[j].lavel6;			
				exNumSet[1][0]=dice[j].lavel2;
				exNumSet[1][1]=dice[j].lavel5;
				exNumSet[2][0]=dice[j].lavel3;
				exNumSet[2][1]=dice[j].lavel4;
				
				int count=0;
				int place=0;
				int[] set=new int[3];
				for(int k=0;k<3;k++){
					for(int m=0;m<3;m++){
						if(exNumSet[k][0]==numSet[m][0]){
							if(exNumSet[k][1]==numSet[m][1]){
								set[m]=k+1;
								numSet[m][1]=-1;
								if(!(m==k)){
									place+=1;
								}
								break;
							}
						}else if(exNumSet[k][0]==numSet[m][1]){
							if(exNumSet[k][1]==numSet[m][0]){
								set[m]=-1*(k+1);
								numSet[m][1]=-1;
								count+=1;
								if(!(m==k)){
									place+=1;
								}
								break;
							}
						}
					}
				}
				if(numSet[0][1]==-1 && numSet[1][1]==-1 && numSet[2][1]==-1){
					if((count==0 || count==2) &&(place==0 || place==3)){
						flag=false;
						break;
					}
					if((count==1 || count==3) && place==2){
						flag=false;
					}
					if((exNumSet[0][0]==exNumSet[0][1] && exNumSet[1][0]==exNumSet[1][1])||
						(exNumSet[1][0]==exNumSet[1][1] && exNumSet[2][0]==exNumSet[2][1])||
						(exNumSet[2][0]==exNumSet[2][1] && exNumSet[0][0]==exNumSet[0][1])){
							flag=false;
							break;
					}					
				}
			}
		}
		if(flag){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}
		
		
		
class Dice{
//
	final int lavel1,lavel2,lavel3,lavel4,lavel5,lavel6;
	private int w,s,e,n;
	private int upper,lower;
//	
	Dice(int[] i){
		lavel1=i[0];
		lavel2=i[1];
		lavel3=i[2];
		lavel4=i[3];
		lavel5=i[4];
		lavel6=i[5];
		
		w=lavel4;
		s=lavel2;
		e=lavel3;
		n=lavel5;
		
		upper=lavel1;
		lower=lavel6;
	}
	
	public int getUpper(){
		return upper;
	}
	public int getW(){
		return w;
	}
	public int getS(){
		return s;
	}
	public int getE(){
		return e;
	}
	public int getN(){
		return n;
	}
	public int getLower(){
		return lower;
	}
	
	public void moveW(){
		int i=lower;
		lower=w;
		w=upper;
		upper=e;
		e=i;
	}
	public void moveS(){
		int i=lower;
		lower=s;
		s=upper;
		upper=n;
		n=i;
	}
	public void moveE(){
		int i=lower;
		lower=e;
		e=upper;
		upper=w;
		w=i;
	}
	public void moveN(){
		int i=lower;
		lower=n;
		n=upper;
		upper=s;
		s=i;
	}
}


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

int main()
{
    int n , a , b , c , d;

    cin >> n >> a >> b >> c >> d;

    string s;

    cin >> s;

    string ans = "Yes";

    a--;
    b--;
    c--;
    d--;

    for(int i = b+2 ; i<=d ; i++)
    {
        if(s[i]==s[i-1] && s[i]=='#')
            ans = "No";
    }

    s[d] = '#';

    for(int i = a+2 ; i<=c ; i++)
    {
        if(s[i]==s[i-1] && s[i]=='#')
            ans = "No";
    }

    s[d] = '.';

    if(c>d)
    {
        for(int i = b+1 ; i<=d ; i++)
        {
            if(s[i-2]=='.' && s[i-1]=='.' && s[i]=='.')
                ans = "Yes";
        }
    }

    cout << ans;

    return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int N;
string S;

void dfs(int cur){
  if(S.length()==N){
    cout<<S<<endl;
  }else{
    rep(i,cur+1){
      char c='a'+i;
      S+=c;
      dfs((i==cur)?(cur+1):cur);
      S.pop_back();
    }
  }
}

int main(){
  cin>>N;
  dfs(0);
  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double mrad = 360.0 * m / 60.0;
  double hrad = 360.0 * (h * 60.0 + m) / (12.0 * 60);
  double d = (mrad + 360.0 - hrad);
  if (d > 360.0) {
    d -= 360.0;
  }
  double rad = min(abs(mrad - hrad), d);

  double w = 2 * M_PI / 360.0 * rad;
  double res = a * a + b * b - 2.0 * a * b * cos(w);
  cout << fixed << setprecision(20) << sqrt(res) << endl;
}

Measured memory_bytes: 4292
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int64_t a = 0;

int64_t gcd(int64_t n, int64_t m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int64_t r = n % m;
        a += m * (n / m * 2);
        n = m;
        m = r;
    }
    a -= n;
    return n;
}

int main() {
    int64_t n, x;
    cin >> n >> x;

    gcd(n - x, x);

    cout << n + a << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
            String str = sc.next();

            String str2 = str.toUpperCase();

            if(str.equals(str2)) System.out.println("A");
            else System.out.println("a");

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 35868
n, k = (int(x) for x in input().split())
s = input()
happy = 0

if(s[0] == 'R' and s[1] == 'R'):
    happy = happy + 1
if(s[n-1] == 'L' and s[n-2] == 'L'):
    happy = happy + 1

for i in range(1,n-1):
    if(s[i] == 'R' and s[i+1] == 'R'):
        happy = happy + 1
    if(s[i] == 'L' and s[i-1] == 'L'):
        happy = happy + 1

happy = happy + 2*k
print(min(happy, n-1))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n][3] = {0};
    for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    int dp[n][3] ={0};
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0] = a[i][0] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = a[i][1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = a[i][2] + max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  
 rep(i,n){
   cin >> v.at(i);
 }  
  int ans = 0;
  rep(i,n){
    if(v.at(v.at(i)-1) == i+1){
      ans++ ;
    }
  }
  
  cout << ans/2 << endl;


}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;

int main(){
  int N,K;
  cin >>N>>K;
  
  int ans = 1;
  rep(i,0,N){
    if(ans+K > ans*2) ans *= 2;
    else ans += K;
  }
  
  cout <<ans<< endl;
}

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

#define INF 100000000
#define ABS(a) (a<0?-(a):a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define REP(i,a) for(int i=0;i<a;i++) 

using namespace std;
int main(){
  string s;
  cin >> s;


  int al[26];
  REP(i, 26)al[i]=0;
  int ans = 100000;
  REP(i, s.length()){
    if(al[s[i]-'a'])continue;
    al[s[i]-'a'] = 1;
    int last=i;
    int po = i;
    for(int j=i+1; j < s.length(); j++){
      if(s[j] != s[i])continue;
      po = MAX(po, j-last-1);
      last = j; 
    }
    po = MAX(po, s.length()-last-1);
    ans = MIN(ans, po);
  }
  cout << ans << endl;
}


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

int main()
{
	ll X;
	cin >> X;
	ll ans = 0;
	ans += 1000 * (X / 500);
	X %= 500;
	ans += 5 * (X / 5);
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	vector<vector<int>> g(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ans = 0;
	rep(i, n) {
		int mx = 0;
		for(int t: g[i]) {
			mx = max(mx, h[t]);
		}
		if(h[i] > mx) ans++;
	}
	
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8804
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($n, $k, $s) = split / /, <STDIN>);
my $y;
if ($s == 1) {
  $y = 1e9;
} elsif ($s == 1e9) {
  $y = 1;
} else {
  $y = $s + 1
}
my @c;
for my $i (1..$n) {
  push @c, $s if $i <= $k;
  push @c, $y unless $i <= $k;
}
say join(' ', @c);

Measured memory_bytes: 12416
n, m = map(int, input().split())
l = [0]*(n + 1)
ac = 0
wa = 0

for i in range(m):
    p, s = input().split()
    p = int(p)
    if l[p] == -1:
        continue
    if s == "AC":
        ac += 1
        wa += l[p]
        l[p] = -1
    else:
        l[p] += 1

print(ac, wa)

Measured memory_bytes: 3828
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfsvisit(int);
void dfs(void);

int n,M[N][N];
int color[N],d[N],f[N];
int t;


main(){
int u,k,v;
int i,j;

scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<n;j++)M[i][j]=0;
}

for(i=0;i<n;i++){
scanf("%d%d",&u,&k);
u--;
for(j=0;j<k;j++){
scanf("%d",&v);
v--;
M[u][v]=1;
}
}

dfs();
return 0;
}

void dfsvisit(int u){
int v;
color[u]=GRAY;
d[u]=++t;
for(v=0;v<n;v++){
if(M[u][v]==0)continue;
if(color[v]==WHITE)dfsvisit(v);
}
color[u]=BLACK;
f[u]=++t;
}

void dfs(void){
int u;
for(u=0;u<n;u++)color[u]=WHITE;
t=0;

for(u=0;u<n;u++){
if(color[u]==WHITE)dfsvisit(u);
}
for(u=0;u<n;u++){
printf("%d %d %d\n",u+1,d[u],f[u]);
}
}

Measured memory_bytes: 636
#include <stdio.h>
int main() {
	int N;
	scanf("%d\n", &N);
	int count = 0;
	char color_before;
	for (int i = 0; i < N; i++) {
		char color;
		scanf("%c", &color);
		if (i == 0) {
			count++;
			color_before = color;
			continue;
		}
		if (color == color_before) {
			continue;
		}

		count++;
		color_before = color;
	}
	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 760
#include<iostream>
#include<queue>
using namespace std;
int k,dist[111111];
int main()
{
	cin>>k;
	deque<int> q;
	for(int i=0;i<=k;i++)dist[i]=1<<30;
	q.push_back(dist[1]=1);
	while(!q.empty())
	{
		auto x=q.front(),s=dist[x];q.pop_front();
		if(!x)
		{
			cout<<s<<endl;
			return 0;
		}
		if(dist[x*10%k]>s)dist[x*10%k]=s,q.push_front(x*10%k);
		if(dist[(x+1)%k]>s+1)dist[(x+1)%k]=s+1,q.push_back((x+1)%k);
	}
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}

int Combination8(int n,int k){
  return (n<=k);
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,k;
  cin>>n>>k;
  cout<<Combination8(n,k)<<endl;


}


Measured memory_bytes: 3156
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int,int>;
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int n, m, ta = 0, tp = 0;
    map<int, int> mp;
    string s;
    cin >> n >> m;
    for(int i = 0, p; i < m; ++i)
    {
        cin >> p >> s;
        if(mp.find(p) == mp.end())
        {
            mp[p] = 0;
        }
        if(mp[p] == -1)
        {
            continue;
        }
        if(s == "AC")
        {
            ++ta;
            tp += mp[p];
            mp[p] = -1;
        }
        else
        {
            mp[p] += 1;
        }
    }
    cout << ta << ' ' << tp << '\n';
}

Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define N 3005
#define ll long long
#define mod 1000000007
using namespace std;
int n,q,ny=(mod+1)/2;
int s[N],l[N],r[N];
int f[N][N],g[N][N];
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) scanf("%d",&s[i]);
	for(int i=1;i<=q;i++) scanf("%d%d",&l[i],&r[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(s[i]>s[j]) f[i][j]=1;
	int tmp=1;
	for(int i=1;i<=q;i++){
		for(int j=1;j<=n;j++) g[j][l[i]]=g[j][r[i]]=g[l[i]][j]=g[r[i]][j]=0;
		for(int j=1;j<=n;j++){
			if(j!=l[i]){
				g[j][l[i]]=(g[j][l[i]]+f[j][l[i]])%mod;
				if(j!=r[i]) g[j][l[i]]=(g[j][l[i]]+f[j][r[i]])%mod;
				else g[j][l[i]]=(g[j][l[i]]+f[l[i]][r[i]])%mod;
			}
			if(j!=r[i]){
				g[j][r[i]]=(g[j][r[i]]+f[j][r[i]])%mod;
				if(j!=l[i]) g[j][r[i]]=(g[j][r[i]]+f[j][l[i]])%mod;
				else g[j][r[i]]=(g[j][r[i]]+f[r[i]][l[i]])%mod;
			}
			if(j!=l[i]&&j!=r[i]){
				int tip=(f[l[i]][j]+f[r[i]][j])%mod;
				g[l[i]][j]=(g[l[i]][j]+tip)%mod,g[r[i]][j]=(g[r[i]][j]+tip)%mod;
			}
		}
		for(int j=1;j<=n;j++){
			f[j][l[i]]=(ll)g[j][l[i]]*ny%mod;f[j][r[i]]=(ll)g[j][r[i]]*ny%mod;
			f[l[i]][j]=(ll)g[l[i]][j]*ny%mod;f[r[i]][j]=(ll)g[r[i]][j]*ny%mod;
		}
		tmp=(ll)tmp*2%mod;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans=(ans+(ll)tmp*f[i][j]%mod)%mod;
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 70784
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <set>
#include <queue>
#include <assert.h>
#include <cmath>
#include <map>


using std::cerr;
using std::cin;
using std::cout;
using std::pair;
using std::string;
using std::vector;
//region
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b); i >= (b); --i)
#define rep(i, n) for (unsigned i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n)-1; i >= 0; --i)
#define repr1(i, n) for (int i = (n); i > 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define sz(x) (int((x).size()))
#define mset(v, n) std::memset((v), n, sizeof(v))
#define BIT(N) (1LL << (N))
#define each(i, v) for (auto&& i : (v))
#define unless(f) if(!(f))
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using vint = vector<int>;
using vlong = vector<ll>;
using vstr = vector<string>;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpll = vector<pll>;
using vvi = vector<vint>;
using vvl = vector<vlong>;
vector<string> split(const string &s, const string &delim) {
  vector<string> res;
  uint pos = 0;
  while (true) {
    const size_t found = s.find(delim, pos);
    if (found < 0) {
      res.push_back(s.substr(pos));
      break;
    }
    res.push_back(s.substr(pos, found - pos));
    pos = found + delim.size();
  }
  return res;
}
template<typename T> string join(vector<T> &vec, const string &sep) {
  size_t size = vec.size();
  if (!size) return "";
  std::stringstream ss;
  for (int i = 0; i < size - 1; i++)
    ss << vec[i] << sep;
  ss << vec[size - 1];
  return ss.str();
}
template<typename T> std::istream &operator>>(std::istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template<typename Iter> inline void print(const Iter &first, const Iter &last, const std::string &d, bool endline) {
  cout << *first;
  for (Iter iter = first + 1; iter < last; ++iter) {
    cout << d << *iter;
  }
  if (endline) cout << "\n";
}
constexpr ll powmod(ll a, ull b, uint p) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) res = res * a % p;
    a = a * a % p;
    b >>= 1u;
  }
  return res;
}
template<class T> bool chmax(T &a, const T &b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, const T &b) { return a > b ? (a = b, true) : false; }
template <typename T> void bsort(vector<T>& v) { std::sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T>& v) { std::sort(v.begin(), v.end(), std::greater<T>()); }
struct iii {
    iii() {
      cin.tie(nullptr); cout.tie(nullptr);
      std::ios::sync_with_stdio(false);
      cout << std::fixed << std::setprecision(16);
    }
} init;
//endregion

void solve();

int main() {
  int t = 1;
  // scanf("%d", &t);
  // cin >> t;
  rep(i, t) solve();
  return 0;
}

void solve() {
int N, D;
cin>>N>>D;

int m = D * 2 + 1;
printf("%d\n", (N + m - 1) / m);


  return;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

int gcd(int x, int y) {
   if(x < y) swap(x, y);
   if(x % y == 0) {
      return y;
   } else {
      return gcd(y, x % y);
   }
}

signed main()
{
   int N, K; cin >> N >> K;
   vec<int> A(N);
   rep(i, 0, N) {
      cin >> A[i];
   }

   SORT(A);
   if (A[N-1] < K) {
      cout << "IMPOSSIBLE" << endl;
      return 0;
   }

   int g = A[0];
   rep(i, 1, N) {
      g = gcd(g, A[i]);
   }
   
   if (g != 1 && K % g != 0) {
      cout << "IMPOSSIBLE" << endl;
   } else {
      cout << "POSSIBLE" << endl;
   }

   return 0;
}


Measured memory_bytes: 1024
ab=input().split()
A=int(ab[0]);B=int(ab[1])
c=False
if (A*B*1)%2==1:
    c=True
if (A*B*2)%2==1:
    c=True
if (A*B*3)%2==1:
    c=True
if c:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 3060
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner as = new Scanner(System.in);
		
		int dice1[];
		int dice2[];
		String str = "";
		Boolean breakp = null;
		
		dice1 = new int[6];
		dice2 = new int[6];
		
		for(int i=0;i<6;i++){
			
			dice1[i] = as.nextInt();
			
		}
		
		for(int i=0;i<6;i++){
			
			dice2[i] = as.nextInt();
			
		}
		
		for(int i=0;i<3;i++){
		
			for (int j=0;j<4;j++){
				
				for(int k=0; k<j; k++){
					
					dice2 = Spin.diceSpin(dice2, "x");
					//System.out.println("!!"+k);
					
				}
				
				breakp = Spin.Check(dice1, dice2, i);
				//System.out.println(i+":!");
				
				if(breakp == true){
					
					str = "Yes";
					break;
					
				}
				else{
					
					str = "No";
					
				}
				
			}
			
			
			if(breakp == true){
				
				break;
				
			}
			/*
			breakp = Spin.Check(dice1, dice2, i);
			
			if(breakp == true){
				
				str = "Yes";
				break;
				
			}
			
			dice2 = Spin.diceSpin(dice2, "x");
			breakp = Spin.Check(dice1, dice2, i);
			
			if(breakp == true){
				
				str = "Yes";
				break;
				
			}
			
			dice2 = Spin.diceSpin(dice2, "x");
			dice2 = Spin.diceSpin(dice2, "x");
			breakp = Spin.Check(dice1, dice2, i);
			
			if(breakp == true){
				
				str = "Yes";
				break;
				
			}
			
			dice2 = Spin.diceSpin(dice2, "x");
			dice2 = Spin.diceSpin(dice2, "x");
			dice2 = Spin.diceSpin(dice2, "x");
			breakp = Spin.Check(dice1, dice2, i);
			
			if(breakp == true){
				
				str = "Yes";
				break;
				
			}*/
			
		
		}
		
		System.out.println(str);

	}

}


class Spin{
	
	public static int[] diceSpin(int[] dice,String spn) {
		
	
		int tre = 0;
			
			
		switch (spn){
		case "x":
			tre = dice[4];
			dice[4] = dice[0];
			dice[0] = dice[1];
			dice[1] = dice[5];
			dice[5] = tre;
			break;
			
		case "y":
			tre = dice[3];
			dice[3] = dice[0];
			dice[0] = dice[2];
			dice[2] = dice[5];
			dice[5] = tre;
			break;
			
		case "z":
			tre = dice[2];
			dice[2] = dice[1];
			dice[1] = dice[3];
			dice[3] = dice[4];
			dice[4] = tre;
			break;
			
				
		}
			
		
			
		return dice;
		
		
		
	  }
	
	public static Boolean Samecheck(int[] dice1,int[] dice2){
		
		Boolean flag = null;
		
		for(int i=0;i<6;i++){
			
			if(dice1[i] != dice2[i]){
				
				flag = false;
				break;
			}
			else{
				
				flag = true;
				
			}
			
		}
		
		
		return flag;
		
	}
	
	public static Boolean Check(int[] dice1,int[] dice2,int sp){
		
		Boolean flag = null;
		String spn = null;
		
		switch (sp){
		case 0:
			spn = "x";
			break;
			
		case 1:
			spn = "y";
			break;
			
		case 2:
			spn = "z";
			break;
			
		}
		
		for(int j=0;j<4;j++){
			
			
			dice2 = Spin.diceSpin(dice2, spn);
			if(Spin.Samecheck(dice1, dice2)){
				
	
				flag = true;
				break;
			
			}
			flag = false;
			
		}
		
		
		return flag;
		
	}
	
	
	
}

Measured memory_bytes: 26332
S = input()

dp = [[None] * 4 for _ in range(len(S))]
dp.append([0, 0, 0, 1])
next_str = ["A", "B", "C"]
MOD = 10**9 + 7

for i, s in enumerate(reversed(S)):
    i = len(S) - i - 1
    for j in range(4):
        if j == 3:
            if s == "?":
                dp[i][j] = (3 * dp[i + 1][j]) % MOD
            else:
                dp[i][j] = dp[i + 1][j] % MOD
        else:
            if s == "?":
                m_1 = 3
                m_2 = 1
            else:
                m_1 = 1
                if s == next_str[j]:
                    m_2 = 1
                else:
                    m_2 = 0
            dp[i][j] = (m_1 * dp[i + 1][j] + m_2 * dp[i + 1][j + 1]) % MOD


print(dp[0][0])


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

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

    int G[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

    if (G[x] == G[y]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    cout << [rec_impl = [](auto f, unsigned long N, unsigned long K, unsigned long& a) -> unsigned long {
        if(N < K)return 0;
        auto ret{2 * f(f, N, K * K, a)};
        if(a >= K){
            a /= K;
            ++ret;
        }
        return ret;
    }](unsigned long N, unsigned long K){
        unsigned long a{N};
        return rec_impl(rec_impl, N, K, a) + 1;
    }(N, K) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >> N;
  int  i = 0;
  while (i < N) {
    i++;
    string arare;
    cin >> arare;
    if (arare == "Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 256
#ifndef CLion
//#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m)%m)
#define rep(i,s,e) for (int i = s; i < e; ++i)
#define mem(a,v) memset(a , v , sizeof a)
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

const int N = 1e4 + 9 , base = 26;

int solve( int n ){
    int cnt = 0;
    rep(x,1,n+1){
        int a = x*x;
        if (a > n) break;
        rep(y,x,n+1){
            int b = a + y*y + x*y;
            if ( b > n ) break;
            rep(z,y,n+1){
                int c = b + z*z + y*z + x*z;
                if ( c > n ) break;
                if ( c < n ) continue;
                if ( x == z ) ++cnt;
                else if ( x == y || y == z ) cnt += 3;
                else cnt += 6;
            }
        }
    }
    return cnt;
}
void Main(int cse , bool last){
    //cout << f(1,1,2) ; exit(0);
    //cout << solve(11); exit(0);
    int n ; cin >> n;
    rep(i,1,n + 1) cout << solve(i) << "\n";
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef CLion
    freopen( "in.txt" , "r" , stdin  );
    //freopen( "out.txt", "w" , stdout );
#endif

    int t = 1;
    //cin >> t;
    for ( int cse = 1; cse <= t; ++cse ) Main(cse, cse == t);
    return 0;
}


Measured memory_bytes: 3544
#include <iostream>

using namespace std;

int main(void){

  int N, c, a, n;
  cin >> N;
  while(N--){
    int ans = 0;
    cin >> c >> a >> n;
    while(1){
      if(c >= 1 && a >= 1 && n >= 1){
	c--;
	a--;
	n--;
	ans++;
      }else if(c >= 2 && a >= 1){
	c -= 2;
	a--;
	ans++;
      }else if(c >= 3){
	c -= 3;
	ans++;
      }else break;
    }
    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3

N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

D = {}

for i in range(M-1):
    D[(X[i],X[i+1])] = X[i+1] - X[i]

s_D = sorted(D.items(), key=lambda x:x[1])[::-1]
A = s_D[N-1:]
ans = 0
for a in A:
    ans += a[1]
print(ans)


Measured memory_bytes: 27840
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    ll sum = 0;
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            for(int k=1; k<=N; k++){
                int now = gcd(i,j);
                now = gcd(now,k);
                sum += now;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 21;
const int M = 3e6 + 10;
/*=================================================================================*/

int n, mp[N][N];
ll dp[M];

int main() {
   cin>>n;
   for0(i, n) for0(j, n) {
      scanf("%d", &mp[i][j]);
   }
   dp[0] = 1;
   for0(i, (1<<n)) {
      ll cnt = 0;
      for0(j, n) {
         if((i >> j) & 1) {
            cnt++; // 记录已经匹配完成的人数
         }
      }
      for0(j, n) {
         if(mp[cnt][j] && ((1<<j)^i) > i) {
            dp[(1<<j)^i] = (dp[(1<<j)^i] + dp[i]) % mod;
         }
      }
   }
   cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 20068
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define REP(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long LL;
typedef vector<int> VI;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int dp[1001][1001];

int main(){
	int W,N,lp=1;
	while(true){
		cin >> W;
		if(W == 0) break;

		cin >> N;
		vector<pair<int,int> > data;
		REP(i,N){
			int a,b;
			char c;
			cin >> a >> c >> b;
			data.PB(MP(a,b));
		}

		

		REP(i,N+1){
			REP(j,W+1){
				dp[i][j] = -1;
			}
		}
		dp[0][0] = 0;

		REP(i, N){
			REP(j, W+1){
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
				if(dp[i][j] != -1 && data[i].second+j <= W){
					dp[i+1][data[i].second+j] = max(dp[i+1][data[i].second+j], dp[i][j]+data[i].first);
				}
			}
		}

		int ans1=0, ans2=0;
		REP(i,W+1){
			if(ans1 < dp[N][i]){
				ans1 = dp[N][i];
				ans2 = i;
			}
		}
		cout << "Case " << lp << ":" << endl;
		cout << ans1 << endl;
		cout << ans2 << endl;
		lp++;
	}
}

Measured memory_bytes: 5128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long sum=0;
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin>>a[i];
		if(i>0){
			if(a[i-1]>a[i]){
				sum+=a[i-1]-a[i];
				a[i]=a[i-1];
			}		
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  cout<<n*m<<endl;
  return 0;
}



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

using namespace std;

int N;
bool color[8];
int high = 0;

inline void solve() {
  int ans = 0;
  for (int i = 0; i < 8; ++i) {
    if (color[i]) {
      ans++;
    }
  }

  if (high != 0) {
    cout << max(ans, 1) << " " << ans + high << endl;
  } else {
    cout << ans << " " << ans << endl;
  }
}

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

  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    if (a < 400) {
      color[0] = true;
    } else if (a < 800) {
      color[1] = true;
    } else if (a < 1200) {
      color[2] = true;
    } else if (a < 1600) {
      color[3] = true;
    } else if (a < 2000) {
      color[4] = true;
    } else if (a < 2400) {
      color[5] = true;
    } else if (a < 2800) {
      color[6] = true;
    } else if (a < 3200) {
      color[7] = true;
    } else {
      high++;
    }
  }
  solve();

  return 0;
}

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

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;

	vector<int> vec{a, b, c};
	sort(vec.begin(), vec.end());

	for (int i = 0; i < k; i++) vec[2] *= 2;
	cout << vec[0] + vec[1] + vec[2] << endl;

	return 0;
}

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

using namespace std;
const int maxn = 15;
const int inf = 0x3f3f3f3f;

int c[maxn], a[maxn][maxn], tmp[maxn];

int main() {
    int n, m, x, res = inf;
    scanf("%d%d%d", &n, &m, &x);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &c[i]);
        for (int j = 1; j <= m; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    int f = 0;

    for (int i = 0, sum, flag; i < (1 << n); i++) {
        for (int j = 1; j <= m; j++) tmp[j] = 0;
        sum = 0, flag = 1;
        for (int k = 0; k < n; k++) {
            if (i >> k & 1) {
                sum += c[k + 1];
                for (int j = 1; j <= m; j++) tmp[j] += a[k + 1][j];
            }
        }

        for (int j = 1; j <= m; j++) if (tmp[j] < x) {
            flag = 0;
            break;
        }

        if (flag) f = 1, res = min(res, sum);
    }

    printf("%d\n", (f ? res : -1));
    return 0;
}

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

int N;

int main(){
  cin >> N;
  int t = N, c =0;
  while(t>0){
    c += t%10;
    t /= 10;
  }
  if(N%c==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
int main(){
int A, B;
int flag=0;
int adna=0;
int i=0;

std::cin >> A >> B;

if(A%2-B%2!=0){
  std::cout << "IMPOSSIBLE";
}else{
  for(i=1;i<=(A+B)/2;i++){
    if(abs(A-i)-abs(B-i)==0){
      flag=1;
      adna=i;
      break;
    }
  }
  if(flag==0){
    std::cout << "IMPOSSIBLE";
  }else{
    std::cout << adna;
  }
}
  return 0;
}


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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

def main():
	n=II()
	s=input().rstrip().decode()
	li=[0]*n
	for i in range(n):
		if s[i]=="D":
			li[i]=1
		elif s[i]=="M":
			li[i]=2
		elif s[i]=="C":
			li[i]=3
	
	q=II()
	K=LI()
	for k in K:
		D=0
		M=0
		DM=0
		ans=0
		
		for i in range(n):
			if li[i]==1:
				D+=1
			elif li[i]==2:
				M+=1
				DM+=D
			elif li[i]==3:
				ans+=DM
			
			if i-k+1>=0:
				if li[i-k+1]==1:
					D-=1
					DM-=M
				elif li[i-k+1]==2:
					M-=1
		print(ans)
		


if __name__ == "__main__":
	main()


Measured memory_bytes: 82856
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> cnt(n, 0);
  rep(i, q) {
    int a;
    cin >> a;
    a--;
    cnt[a]++;
  }
  rep(i, n) {
    if (q - cnt[i] >= k) puts("No");
    else puts("Yes");
  }
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

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

    String s = sc.next();
    String t = sc.next();

    sb.append(t);
    sb.append(s);
    String ans = sb.toString();

    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <chrono>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long Int;

#define KIND 26
//#define KIND 2
Int D;
Int c[KIND];
Int s[400][KIND];
Int last[KIND];

std::chrono::time_point<std::chrono::steady_clock> start;

Int range(Int l, Int r)
{
    Int len = r - l - 1;
    return -len * (len + 1) / 2;
}

void tic()
{
    start = std::chrono::steady_clock::now();
}

double toc()
{
    auto now = std::chrono::steady_clock::now();
    std::chrono::duration<double> duration = now - start;
    return duration.count();
}

struct ContestInfo {
    set<Int> held[KIND];
    vector<Int> t;
    int D;
    Int score = 0;
    ContestInfo(int D) : D(D)
    {
        t.resize(D, -1);
        for (int i = 0; i < KIND; i++) {
            held[i].insert(-1);
            held[i].insert(D);
            score += c[i] * range(-1, D);
        }
    }

    void add(int d, int q)
    {
        if (t[d] != -1) {
            cout << "Add failed" << endl;
            exit(1);
        }
        t[d] = q;
        score += s[d][q];
        held[q].insert(d);
        auto it = held[q].find(d);
        auto rit = next(it);
        auto lit = prev(it);
        score -= c[q] * range(*lit, *rit);
        score += c[q] * range(*it, *rit);
        score += c[q] * range(*lit, *it);
    }

    void erase(int d)
    {
        if (t[d] == -1) {
            cout << "erase failed" << endl;
            exit(1);
        }
        int q = t[d];
        t[d] = -1;
        score -= s[d][q];
        auto it = held[q].find(d);
        auto rit = next(it);
        auto lit = prev(it);
        score += c[q] * range(*lit, *rit);
        score -= c[q] * range(*it, *rit);
        score -= c[q] * range(*lit, *it);
        held[q].erase(it);
    }

    void change(int d, int q)
    {
        erase(d);
        add(d, q);
    }

    void output()
    {
        for (int i = 0; i < D; i++) {
            cout << t[i] + 1 << endl;
        }
    }
};

Int calc_score(vector<Int> t)
{
    Int score = 0;
    fill(last, last + 26, -1);
    for (int d = 0; d < D; d++) {
        score += s[d][t[d]];
        last[t[d]] = d;
        for (int i = 0; i < KIND; i++) {
            score -= c[i] * (d - last[i]);
        }
        // cout << score << endl;
    }
    return score;
}

int main()
{
    tic();
    cin >> D;
    for (Int i = 0; i < KIND; i++) {
        cin >> c[i];
    }
    for (Int d = 0; d < D; d++) {
        for (Int i = 0; i < KIND; i++) {
            cin >> s[d][i];
        }
    }

    ContestInfo ci(D);

    for (int d = 0; d < D; d++) {
        Int t;
        t = rand() % KIND;
        ci.add(d, t);
    }
    Int current_score = ci.score;

    while (toc() < 1.9) {
        Int d, q;
        d = rand() % D;
        q = rand() % KIND;
        int old = ci.t[d];
        ci.change(d, q);
        Int new_score = ci.score;
        if (new_score < current_score) {
            ci.change(d, old);
        }
        else {
            current_score = new_score;
        }
    }
    ci.output();
    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<long long>>;

int main(){
	long long n,m;
	cin >> n >> m;
	Graph G(n);
	long long i;
	for(i=0;i<m;i++){
		long long a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);	
	}
	
	vector<long long> dist(n, -1);
	queue<long long> que;
	
	dist[0] = 0;
	que.push(0);
	
	map<long long ,long long> guide;
	while (!que.empty()) {
        long long v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (long long nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
			guide[nv] = v;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
	
	cout << "Yes" << endl;
	for (int v = 1; v < n; ++v)cout << guide[v]+1 << endl;
/*	int i;
	for(i=0;i<n;i++){
		
	}
*/	

}

Measured memory_bytes: 19036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll a[2005];ll x;ll dp[2005][2005];ll sum=1ll<<60ll;
int main(){
	cin>>N>>x;

	for(int i=1;i<=N;i++){
		cin>>a[i];
	}
	for(int i=1;i<=N;i++){
		dp[i][0]=a[i];
	
	for(int j=1;j<=N;j++){
		int pos=i-j;
		if(pos<=0)pos=N-abs(pos);
		dp[i][j]=min(dp[i][j-1],a[pos]);

	}
}

for(int i=0;i<=N-1;i++){
	ll ans=0;
	for(int j=1;j<=N;j++){
		ans+=dp[j][i];
		
	}
	sum=min(sum,ans+i*x);
}
	cout<<sum<<endl;
}


Measured memory_bytes: 31616
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            int[] maxFromLelt = new int[N];
            for (int i = 0; i < N; i++) {
                maxFromLelt[i] = Math.max(i - 1 >= 0 ? maxFromLelt[i - 1] : 0, A[i]);
            }
            int[] maxFromRight = new int[N];
            for (int i = N - 1; i >= 0; i--) {
                maxFromRight[i] = Math.max(i + 1 < N ? maxFromRight[i + 1] : 0, A[i]);
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (i > 0) {
                    sb.append("\n");
                }
                sb.append(Math.max(i - 1 >= 0 ? maxFromLelt[i - 1] : 0, i + 1 < N ? maxFromRight[i + 1] : 0));
            }
            System.out.println(sb.toString());
        }
    }
}


Measured memory_bytes: 70164
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, p, target, bowl;
		int[] point;
		
		while(true) {
			n = sc.nextInt();
			p = sc.nextInt();
			if(n==0 || p==0) {
				break;
			}
			
			point = new int[n];
			target = 0;
			bowl = p;
			
			for(;;) {
				if(bowl != 0) {
					point[target] ++;
					bowl --;
				} else {
					bowl = point[target];
					point[target] = 0;
				}
				
				if(point[target] == p) {
					break;
				} else {
					if(target == n-1) {
						target = 0;
					} else {
						target ++;
					}
				}
			}
			System.out.println(target);
		}
		
	}
}

Measured memory_bytes: 27220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, vector<long long> A){
	ll res = 3;
	ll r = 0, g = 0, b = 0;
	if (A[0] != 0) res = 0;
	r++;
	repn(i, N-1) {
		ll now = 0;
		if (r == A[i]) now++;
		if (g == A[i]) now++;
		if (b == A[i]) now++;
		res = (res*now)%mod;
		if (r == A[i]) r++; else if (g == A[i]) g++; else if (b == A[i]) b++;
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 1792