akhauriyash/Code-Regression huggingface dataset:
def resolve():
    h, w = map(int, input().split())
    s = list(list(input().split()) for _ in range(h))
    for i, line in enumerate(s):
        if "snuke" in line:
            print("{}{}".format(chr(line.index("snuke") + 97).upper(), str(i + 1)))
            return 1


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>

struct Point {
	double x, y;
};

void kock(int n, struct Point p1, struct Point p2)
{
	if(n == 0) return;
	
	struct Point s, t, u;
	double th = M_PI * 60 / 180;
	
	s.x = (2*p1.x+1*p2.x)/3;
	s.y = (2*p1.y+1*p2.y)/3;
	t.x = (1*p1.x+2*p2.x)/3;
	t.y = (1*p1.y+2*p2.y)/3;
	u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th) + s.x;
	u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th) + s.y;
	
	kock(n-1, p1, s);
	printf("%.8f %.8f\n", s.x, s.y);
	kock(n-1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	kock(n-1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	kock(n-1, t, p2);
}

int main(void)
{
	struct Point p1, p2;
	int n;
	
	scanf("%d", &n);
	
	p1.x = 0;
	p1.y = 0;
	p2.x = 100;
	p2.y = 0;
			
	printf("%.8f %.8f\n", p1.x, p1.y);
	kock(n, p1, p2);
	printf("%.8f %.8f\n", p2.x, p2.y);
	
	return 0;
}


Measured memory_bytes: 2088
import sys
from copy import deepcopy
def check(data):
    return reduce(lambda a, b: a+b, data).count("?")

def calc(seq):
    if "?" not in seq or not(0 <= seq.count("?") <= 1) :
        return seq
    if seq[-1] == "?":
        return seq[:-1] + sum(seq[:-1])
    a = seq[-1] - sum(s for s in seq[:-1] if s != "?")
    return [s if s != "?" else a for s in seq]

def update(data):
    data = deepcopy(data)
    for i in xrange(len(data)):
        for j, d in enumerate(calc(data[i])):
            data[i][j] = d
    t_data = zip(*data)
    for i in xrange(len(t_data)):
        for j, d in enumerate(calc(t_data[i])):
            data[j][i] = d
    return data

answer = ""
while True:
    line = raw_input()
    while line.isspace() or not line: #!?!?!!!
        line = raw_input()
    if line == "0":
        break
    P, S = map(int, line.split())
    data = [map(lambda x: int(x) if x.replace("-", "").isdigit() else x, raw_input().split())
            for _ in xrange(P+1)]
    cdata = deepcopy(data)
    for _ in xrange(check(cdata)):
        cdata = update(cdata)
    ans = ""
    if check(cdata) == 0:
        for d in zip(data, cdata):
            for e1, e2 in zip(*d):
                if e1 == "?":
                    ans += "{}\n".format(e2)
    else:
        ans += "NO\n"
    answer += ans + "\n"
print answer.strip("\n")

Measured memory_bytes: 4600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long t = sc.nextInt();
		int a[] = new int [n];
		long ans = 0;
		ans = n * t;

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n; i++) {
			if (a[i] - a[i - 1] < t) ans -= t - (a[i] - a[i - 1]);
		}

		System.out.println(ans);


		sc.close();

	}

}


Measured memory_bytes: 58952
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <utility>
#include <cmath>
#include <cstring>
#include <queue>
#include <time.h>
#include <algorithm>
#include <set>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ull> ipair;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define ln length()
#define rep(i,n) for(i=0;i<n;i++)
#define fu(i,a,n) for(i=a;i<=n;i++)
#define fd(i,n,a) for(i=n;i>=a;i--)
#define all(a)  a.begin(),a.end() 
#define gi(n) scanf("%d",&n)
#define gl(n) scanf("%lld",&n)
#define pi(n) printf("%d",n)
#define pl(n) printf("%lld",n);
#define pp printf(" ")
#define pn printf("\n")


ll c[4];
int main() {
	ll n;
	gl(n);
	ll i;
	ll k;
	fu(i, 1, n) {
		gl(k);
		c[k%4]++;
	}
	if(c[0] >= c[1] + c[3]) {
		cout << "Yes\n";
	}
	else {
		if(c[0] == c[1] + c[3] - 1) {
			if(c[2]) {
				cout << "No\n";
			}
			else {
				cout << "Yes\n";
			}
		}
		else {
			cout << "No\n";
		}
	}
	return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    string s; cin >> s;
    deque<bool> w(n);
    vector<bool> ans(n);
    for (int i = 0; i < n; i++) {
        w[i] = s[i] == 'A';
        ans[n-i-1] = (i % 2 == 0);
    }
    bool rev = false;
    while (k && !w.empty()) {
        k--;
        if (w[0] ^ rev) w[0] = !w[0];
        else {
            w.pop_front();
            rev = !rev;
        }
    }
    if (!w.empty()) {
        for (int i = 0; i < w.size(); i++) {
            ans[i] = rev ^ w[i];
        }
    } else {
        if (n & 1) {
            if (k & 1) ans[0] = !ans[0];
        }
    }
    for (int i = 0; i < n; i++) {
        if (ans[i]) cout << 'A';
        else cout << 'B';
    }
    cout << "\n";
    return 0;
}

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

int main(){
	int n, tmp, max_val=INT_MIN, min=INT_MAX;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> tmp;
		if(tmp-min>max_val) max_val = tmp-min;
		if(tmp<min) min=tmp;
	}
	cout << max_val << endl;
	return 0;
}



Measured memory_bytes: 3092
using System;
using System.Collections.Generic;

enum suit
{
Spade, Heart, Club, Diamond
}

class Program
 {


     
     static void Main(string[] args)
     {
         int data0 = 0, data1 = 0, data2 = 0;

         String nyuryoku;
         string[] data = new string[2];
         int[,] card = new int[4,13];

         nyuryoku = Console.ReadLine();
         data0 = int.Parse(nyuryoku);
         string [] value = new string[4] {"S","H","C","D"};

         for (int i = 0 ; i < data0 ; i++)
         {
             nyuryoku = Console.ReadLine();
             data = nyuryoku.Split(' ');
             switch(data[0])
             {
                 case "S":
                     card[(int)suit.Spade,int.Parse(data[1])-1]=1;
                     break;
                 case "H":
                     card[(int)suit.Heart, int.Parse(data[1])-1] = 1;
                     break;
                 case "C":
                     card[(int)suit.Club, int.Parse(data[1])-1] = 1;
                     break;
                 case "D":
                     card[(int)suit.Diamond, int.Parse(data[1])-1] = 1;
                     break;
             }

         }

         for (int i = 0; i < 4; i++)
             for (int j = 0; j < 13; j++)
                 if (card[i, j] == 0)
                     Console.WriteLine("{0} {1}", value[i], j+1);
      }
 }



Measured memory_bytes: 17992
#include <iostream>
using namespace std;
int n, m;
const int ma = 2e3 + 10;
char s[ma][ma];
int u[ma][ma], d[ma][ma], l[ma][ma], r[ma][ma];
main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> s[i]+1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            u[i][j] = (u[i - 1][j] + 1) * (s[i][j] == '.');
            l[i][j] = (l[i][j - 1] + 1) * (s[i][j] == '.');
        }
    }
    for (int i = n; i > 0; i--)
    {
        for (int j = m; j; j--)
        {
            d[i][j] = (d[i + 1][j] + 1) * (s[i][j] == '.');
            r[i][j] = (r[i][j + 1] + 1) * (s[i][j] == '.');
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            ans = max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3);
    cout << ans << '\n';
}

Measured memory_bytes: 67328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }

int main() {
  ull d;
  cin >> d;

  auto diff = 25 - d;
  cout << "Christmas";

  each(i, diff) {
    cout << " Eve";
  }

  cout << endl;
 
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	int flag = 0;
	int answer = 0;
	for(int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		if(a == b){
			flag++;
		}
		else{
			flag = 0;
		}
		if(flag == 3){
			answer = 1;
		}

	}
	if(answer == 1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}
	

Measured memory_bytes: 3620
# your code goes here

import math

N = int(input())

exp = [1]
for i in range(2,int(math.sqrt(N))+1):
	if pow(i,int(math.log(N,i))+1) <= N:
		exp.append(pow(i,int(math.log(N,i))+1))
	else:
		exp.append(pow(i,int(math.log(N,i))))
print(max(exp))
	
	

Measured memory_bytes: 3060
// ABC 161
function Main(input) {
  input = input.split(" ");
  var A = parseInt(input[2],10);
  var B = parseInt(input[0],10);
  var C = parseInt(input[1],10);
  console.log(A + " " + B + " " + C)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

int res, n, k;

int main(){
  cin >> n >> k;
  if (n<k) cout << 1;
  else {
    res=0;
    while (n>0) {
  	res++;
    n/=k;
  }
  cout << res;
  }
 
  return 0;
}

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

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

    string s;
    cin >> s;

    int n = s.length();

    if(n <= k){
        cout << s << endl;
    }else{
        cout << s.substr(0, k) << "..." << endl;
    }
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  if(N%10==3)printf("bon");
  else if(N%10==0 || N%10==1 || N%10==6 ||N%10==8)printf("pon");
  else printf("hon");
  
  return 0;
}

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

int n, c;
string s;

int main(){
	cin >> n >> s;
	c = 0;
	for (int i = 0; i < n-2; ++i){
		if (s.substr(i, 3) == "ABC") c++;
	}
	cout << c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#define re register
using namespace std;
#define gc getchar
inline int read(){
	int t=0,f=0;
	char v=gc();
	while(v<'0')f|=(v=='-'),v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=gc();
	return f?-t:t;
}
int n;
signed main(){
	scanf("%d",&n);
	puts((n>=30)?"Yes":"No"); 
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;

  ll ans=0;
  map<pair<string,string>,ll> mp;
  for(ll i=0;i<(1<<n);i++){
    ll tmp=i,count=n;
    string v,w;
    while(count<2*n){
      if(tmp%2) v=v+s[count];
      else w=s[count]+w;
      count++;
      tmp/=2;
    }
    //if(v.size()!=n||v.size()!=w.size()) continue;

    mp[make_pair(v,w)]++;
    reverse(v.begin(),v.end());
    reverse(w.begin(),w.end());
    mp[make_pair(w,v)]++;
  }

  for(ll i=0;i<(1<<n);i++){
    ll tmp=i,count=0;
    string v,w;
    while(count<n){
      if(tmp%2) v=v+s[count];
      else w=s[count]+w;
      count++;
      tmp/=2;
    }
    //if(v.size()!=n||v.size()!=w.size()) continue;

    if(mp[make_pair(w,v)]>0) ans+=mp[make_pair(w,v)];
    reverse(w.begin(),w.end());
    reverse(v.begin(),v.end());
    if(mp[make_pair(v,w)]>0) ans+=mp[make_pair(v,w)];
  }

  cout<<ans/4<<endl;

  return 0;
}


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

int main(){
	int n,m;
	int a[13]={2,3,4,5,6,7,8,9,10,11,12,13,1};
	cin>>n>>m;
	int t=-1,f=-1,i;
	for(i=0;i<13;i++){
		if(n==a[i]){
			t=i;
			break;
		}
	}
	for(i=0;i<13;i++){
		if(m==a[i]){
			f=i;
			break;
		}
	}
	if(t>f)
	cout<<"Alice"<<endl;
	else if(t==f)
	cout<<"Draw"<<endl;
	else
	cout<<"Bob"<<endl;
	return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    int n=b-a;
    int p=0;
    rep(i,n){
        p+=i+1;
    }
    cout << p-b << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a,b,c,tm,tm2,count=0;
    int i,j;
    int ar[3];
    scanf("%d%d%d",&a,&b,&c);
    ar[0]=a;
    ar[1]=b;
    ar[2]=c;
    for(i=0; i<2; i++)
    {
        for(j=0; j<2; j++){
                if(ar[i]<ar[j+1]){
                tm=ar[j+1];
                ar[j+1]=ar[i];
                ar[i]=tm;
            }
        }
    }
    a=ar[0];
    b=ar[1];
    c=ar[2];
    for(i=b; i<a; i++)
    {
        b++;
        c++;
        count++;
    }
    if(a==b)
    {
        for(i=c; i<a; i+=2){
            c+=2;
            count++;
        }
        if(a==b && a==c-1)
        {
            a++;b++;
            count++;
        }

    }
    printf("%d\n",count);
    return 0;
}


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

vector<int> di;			//下りるときに消費する体力
vector<int> hi;			//その階の泉の回復量

int main(){
	int n;
	int h;
	cin >> n >> h;
	int k = 0;
	for ( int i = 0; i < n - 1; i++ ) {
		cin >> k;
		di.push_back(k);
		cin >> k;
		hi.push_back(k);
	}
	k = 0;				//今いる階
	int l = h;			//今の体力
	int s = 0;			//泉を使った回数
	while(true) {
		int x = l;		//どこまで下にいけるか調べるための仮の体力
		int y = 0;		//何回下まで行くか
		int z = 0;		//その目的の階での回復量
		for ( int i = 0; true; i++ ) {
			if ( k + i == n - 1 ) {		//今の体力で一番下まで行けるなら終わり
				y = i;
				break;
			}
			if ( min( h-x, hi[ k+i ] ) >= z ) {
				y = i;
				z = min( h-x, hi[ k+i ] );
			}
			if ( x <= di[ k+i ] ) break;
			x -= di[ k+i ];
		}
		if ( k + y == n-1 ) break;
		for ( int i = 0; i < y; i++ ) {
			l -= di[ k+i ];
		}
		k += y;
		l = min( h, l + hi[k] );
		s++;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 2144
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    AB = sorted(AB, key=lambda x: x[0])

    ans = 0
    for a, b in AB:
        if M > b:
            M -= b
            ans += a * b
        else:
            ans += a * M
            print(ans)
            exit()

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	
	int n, k;
	cin>>n>>k;
	vector < int > v(n);
	
	for (int i = 0; i < n; i++)
		cin>>v[i];
		
	int curr = 0, best = 0;
	for (int i = 0; i < k; i++)
		curr += v[i], best += v[i];
		
	for (int i = 0; i + k < n; i++) {
		curr += v[i + k] - v[i];
		best = max(best, curr);
	}
	
	double res = (best + k) / 2.0;
	
	printf("%0.13lf\n", res);
	
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
const long long mod = 1000000007;
//const long long mod = 998244353;
double dist(double x1, double y1, double x2, double y2) {
	return sqrt(((x1)-(x2))*((x1)-(x2)) + ((y1)-(y2))*((y1)-(y2)));
}

double R(double x1, double y1, double x2, double y2, int*xs, int*ys, int N) {
	double cx = (x1 + x2) / 2;
	double cy = (y1 + y2) / 2;
	double r = dist(x1, y1, x2, y2) / 2;
	for (int i = 0; i < N; i++) {
		if (dist(xs[i], ys[i], cx, cy) > r*(1.0000001)) {
			return -1;
		}
	}
	return r;
}
double R(double x1, double y1, double x2, double y2, double x3, double y3, int*xs, int*ys, int N) {
	double a = x1 - x2;
	double b = y1 - y2;
	double c = x2 - x3;
	double d = y2 - y3;
	double l1 = (x1*x1 + y1 * y1);
	double l2 = (x2*x2 + y2 * y2);
	double l3 = (x3*x3 + y3 * y3);
	double v1 = l1 - l2;
	double v2 = l2 - l3;
	double q = a * d - c * b;
	if (q == 0)return -1;
	double cx = (d*v1 - b * v2) / (2 * q);
	double cy = (-c * v1 + a * v2) / (2 * q);
	double r = sqrt((x1 - cx)*(x1 - cx) + (y1 - cy) * (y1 - cy));
	//printf("%f %f %f \n", cx, cy, r);
	for (int i = 0; i < N; i++) {
		if (dist(xs[i], ys[i], cx, cy) > r*(1.0000001)) {
			return -1;
		}
	}
	return r;
}

int main() {
	int N;
	scanf("%d", &N);
	int*x = new int[N];
	int*y = new int[N];
	for (int i = 0; i < N; i++)scanf("%d %d", x + i, y + i);
	double min = 200000;
	if (N == 2) {
		min = sqrt((x[0] - x[1])*(x[0] - x[1]) + (y[0] - y[1])*(y[0] - y[1])) / 2;
	}
	else {
		for (int i1 = 0; i1 < N; i1++) {
			for (int i2 = i1 + 1; i2 < N; i2++) {
				for (int i3 = i2 + 1; i3 < N; i3++) {
					double r = R(x[i1], y[i1], x[i2], y[i2], x[i3], y[i3], x, y, N);
					//printf("%f\n", r);
					if (r != -1) {
						min = r < min ? r : min;
					}
				}
				double r = R(x[i1], y[i1], x[i2], y[i2], x, y, N);
				if (r != -1) {
					min = r < min ? r : min;
				}
			}
		}
	}
	printf("%lf", min);
	return 0;
}

Measured memory_bytes: 256
require 'set'
n = gets.to_i
ws = $<.map(&:chomp)
unless ws.size == ws.uniq.size
  puts "No"
  exit
end
c = nil
ws.each do |w|
  if c && w[0] != c
    puts "No"
    exit
  end
  c = w[-1]
end
puts "Yes"

Measured memory_bytes: 1916
# 写経
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + (10 if a > 0 else 0)
    ret2 = dfs(cur + 1, a, b + l[cur], c) + (10 if b > 0 else 0)
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + (10 if c > 0 else 0)
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

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

int main(){
  long long A, B;
  cin >> A >> B;

  if((A + B) % 2 == 0){
    long long ans = (A + B) / 2;
    cout << ans << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# ARC069C - Scc Puzzle
def main():
    n, m = list(map(int, input().rstrip().split()))
    if n * 2 <= m:
        ans = n + (m - n * 2) // 4
    else:
        ans = m // 2
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N;
  cin>>N;
  int X=sqrt(N*2);
  string ans="No";
  if(X*(X+1)/2==N){
    ans="Yes";
    cout<<ans<<endl<<X+1<<endl;
    vii A(X+1,vi(X));
    int K=1;
    rep(i,0,X){
      rep(j,0+i,X){
        A[i][j]=K;
        K++;
        }
      }
    rep(i,1,X+1){
      rep(j,0,i)
        A[i][j]=A[j][i-1];
      }
    rep(i,0,X+1){
      cout<<X<<" ";
      rep(j,0,X) cout<<A[i][j]<<" ";
      cout<<endl;
      }
    }
  else cout<<ans<<endl;
  }



Measured memory_bytes: 2944
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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

const int Maxn = 2010;
const ll INF = (ll) 1e15;

int n;
ll x;
ll a[Maxn], minv[Maxn];

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

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

    fill(minv, minv + n, INF);
    ll ans = INF;
    for (int k = 0; k < n; ++k) {
        ll cost = x * k;
        for (int i = 0; i < n; ++i) {
            minv[i] = min(minv[i], a[(i - k + n) % n]);
            cost += minv[i];
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main(){
	string str;
	while(getline(cin, str)){
		if(str==".") break;
		stack<char> st;
		for(int i=0;i<str.size();i++){
			if(str[i]=='('||str[i]=='[') st.push(str[i]);
			if(str[i]==')'){
				if(!st.empty()&&st.top()=='(') st.pop();
				else                           st.push(')');
			}
			if(str[i]==']'){
				if(!st.empty()&&st.top()=='[') st.pop();
				else                           st.push(']');
			}
		}
		cout << (st.empty() ? "yes" : "no") << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#define INF 1e18
using namespace std;
struct edge{
    int from;
    int to;
    long long cost;
    edge(int a, int b, long long c){
        from=a;
        to=b;
        cost=c;
    }
};

struct BF{
    vector<edge> e;
    long long d[10000];
    bool neg[10000];
    void add_edge(int from, int to, long long cost){
        e.push_back(edge(from, to, cost));
    }

    void bellman_ford(int n, int s){
        fill(d, d+n, INF);
        fill(neg, neg+n, false);
        d[s]=0;
        bool update=true;
        int m=e.size(),count=0;
        for(int j=0;j<n&&update;j++){
            update=false;
            for(int i=0;i<m;i++){
                if(d[e[i].from]!=INF&&d[e[i].from]+e[i].cost<d[e[i].to]){
                    d[e[i].to]=d[e[i].from]+e[i].cost;
                    update=true;
                }
            }
        }
        for(int j=0;j<n;j++){
            for(int i=0;i<m;i++){
                if(d[e[i].from]!=INF&&d[e[i].from]+e[i].cost<d[e[i].to]){
                    d[e[i].to]=d[e[i].from]+e[i].cost;
                    neg[e[i].to]=true;
                }
                if(neg[e[i].from])neg[e[i].to]=true;
            }
        }
    }
};


int main(void){
    int n, m, p;
    BF bf;
    cin >> n >> m >> p;
    for(int i=0;i<m;i++){
        int a, b, c;
        cin >> a >> b >> c;
        bf.add_edge(--a, --b, -c+p);
    }
    bf.bellman_ford(n, 0);
    /*for(int i=0;i<n;i++){
        cout << i << " : " << bf.d[i] << endl;
    }*/
    if(bf.neg[n-1]){
        cout << -1 << endl;
    }else{
        cout << max((long long)0, -bf.d[n-1]) << endl;
    }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,  int>;

const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int MAX_DIGIT = 50;
long long dp[100][2]; // dp[上から i 桁まで][ smaller ]

int main(){
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){cin >> a[i];}
    memset(dp,-1,sizeof(dp));
    dp[0][0] = 0;
    for(int i = 0; i < 50; ++i){
        ll mask = (1LL << (49-i));
        
        int num=0;
        for(int j = 0; j< n; ++j){
            if(a[j]&mask){++num; }
        }
        ll cost0 = mask * num;
        ll cost1 = mask* (n-num);
        
        // smaller -> smaller
        if (dp[i][1] != -1) {
            dp[i+1][1]=max(dp[i+1][1], dp[i][1] + max(cost0, cost1)); // 0 でも 1 でも自在に大きい方
        }
        
         // exact -> smaller
        if (dp[i][0] != -1) {
            if (k & mask) { // K の i 桁目が 1 だったら、X の i 桁目は 0 にする
                dp[i+1][1] = max(dp[i+1][1], dp[i][0] + cost0);
            }
        }
        
         // exact -> exact (K にぴったり合わせる)
        if (dp[i][0] != -1) {
            if (k & mask) {
                 dp[i+1][0]=max(dp[i+1][0], dp[i][0] + cost1);
            }
            else dp[i+1][0]=max(dp[i+1][0], dp[i][0] + cost0);
        }
        
    }
    cout << max(dp[50][0], dp[50][1]) << endl;
    return 0; 
}


Measured memory_bytes: 1024
n = int(input())
b = list(map(int, input().split()))
ans = 0
a = [0]*n
a[0]=b[0]
for i in range(1,n-1):
  a[i] = min(b[i],b[i-1])
a[n-1]=b[n-2]
ans=sum(a) 
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>

using namespace std;
typedef long long ll;
ll n, a, train, taxi;
int main()
{
	cin >> n >> a >> train;
	taxi = a * n;
	if (taxi <= train)
	{
		cout << taxi << "\n";
	}
	else
	{
		cout << train << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#import numpy as np
import sys
input=sys.stdin.readline

n,k=map(int,input().split())

#p=np.array(list(map(int,input().split())))
func=lambda x: ((int(x)+1.)/2.)
p=list(map(func,input().split()))

#p=(p+1.)/2.
s=sum(p[0:k])
max_p=s

#for i in range(n-k+1):
for i in range(n-k):
    #s=np.sum(p[i:i+k])
    s=s-p[i]+p[i+k]
    if  max_p < s:
        max_p=s

print(max_p)

Measured memory_bytes: 68080
#include <stdio.h>
#include <math.h>

int main(void){
  int N, D;
  scanf("%d%d", &N, &D);

  int X[N][D];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      scanf("%d", &X[i][j]);
    }
  }

  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    for (int j = i+1; j < N; j++) {
      int num = 0;
      for (int k = 0; k < D; k++) {
        num += pow(X[i][k]-X[j][k], 2);
      }
      for (int l = 0; l <= 200; l++) {
        if(num == l*l) ans++;
      }
    }
  }

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

  return 0;
}

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

using namespace std;


const int DIM = 2e5 + 7;


vector <int> l[DIM];

bool viz[DIM];

int p[DIM];

void bfs(int x)
{
   viz[x] = true;

   queue <int> c;

   c.push(x);
   while(!c.empty())
   {
       int nod = c.front();
       c.pop();

       for(int i = 0; i < l[nod].size(); i++)
       {
           int vec = l[nod][i];

           if(viz[vec] == false)
           {
               viz[vec] = true;
               p[vec] = nod;
               c.push(vec);
           }
       }
   }
}

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


    int n, m;
    cin >> n >> m;

    for(int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;

        l[x].push_back(y);
        l[y].push_back(x);
    }
    bfs(1);

    for(int i = 2; i <= n; i++)
        if(p[i] == 0)
        {
            cout <<"No";
            return 0;
        }

    cout << "Yes"<<'\n';

    for(int i = 2; i <= n; i++)
        cout << p[i] <<'\n';
    return 0;
}


Measured memory_bytes: 12912
#include<stdio.h>

int main(){
  int A[100],N,i,j,a,count=0,temp;
  scanf("%d",&N);
  for(a=0;a<N;a++){
    scanf("%d",&A[a]);
  }
    for(i=0;i<N;i++){
      for(j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	count++;
      }
     
    }
      if(i!=N-1){
       printf("%d ",A[i]);
      }
      else printf("%d",A[i]);
  }
    printf("\n%d",count);
    printf("\n");
  return 0;
}



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

int main(void){
    int n;
    cin >> n;
    vector<pair<int,int>> r(n),b(n);
    for(int i=0;i<n;i++){
        int a,c;
        cin >> a >> c;
        r[i] = {a,c};
    }
    for(int i=0;i<n;i++){
        int a,c;
        cin >> a >> c;
        b[i] = {a,c};
    }

    sort(r.begin(),r.end());
    sort(b.begin(),b.end());

    vector<bool> used(n,false);
    int count = 0;
    for(int i=0;i<n;i++){
        int maxy = -1;
        int posr = -1;
        for(int j=0;j<r.size();j++){
            if(r[j].first>=b[i].first) break;
            if(r[j].second>=b[i].second) continue;
            if(used[j]) continue;
            
            if(maxy<r[j].second){
                maxy = r[j].second;
                posr = j;
            }
        }

        if(posr==-1) continue;
        else{
            count++;
            used[posr] = true;
        }
    }

    cout << count << endl;
}

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

imos = [0] * (n + 1)
for _ in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    imos[l] += 1
    imos[r + 1] -= 1

for i in range(n):
    imos[i + 1] += imos[i]

ans = 0
for i in range(n):
    if imos[i] == m:
        ans += 1

print(ans)

Measured memory_bytes: 6900
#ifdef loc
    #include "../codes/loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define sz(a) int(a.size())
const int N = 100005;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    ll k;
    cin>>s>>k;
    bool last_changed = false;
    int n = sz(s);
    int cur1 = 0, cur2 = 0;
    for(int i=1; i<n; i++) {
        if(s[i]==s[i-1]) {
            i++;
            cur1++;
            if(i==n) last_changed = true;
        }
    }
    ll ans = 0;
    if(last_changed || s[n-1]!=s[0]) ans = cur1*k;
    else {
        cur2 = 1;
        last_changed = (n==1);
        for(int i=2; i<n; i++) {
            if(s[i]==s[i-1]) {
                i++;
                cur2++;
                if(i==n) last_changed = true;
            }
        }
        if(last_changed) ans = (k/2)*cur2+((k+1)/2)*cur1;
        else ans = cur1+(k-1)*cur2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 105;

int n,m,c;
int a[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n>>m>>c;
  for(int i=0;i<m;i++)cin>>a[i];
  int ret = 0;
  while(n--){
    int tt = 0;
    for(int i=0;i<m;i++){
      int x;
      cin>>x;
      tt+=x*a[i];
    }
    if(tt+c>0)ret++;
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
#include<list>
using namespace std;
int main(){
	int n; cin>>n;
	int ans=0;
	for(int i=1;i<sqrt(n+0.5);i++){
		ans = i*i;
		if(ans>n){
			ans = (i-1)*(i-1);
			break;
		}
	}

	cout<< ans <<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int h,w,n,a,x,y;
	cin>>w>>h>>n;
	int d[4]={0,w,0,h};
	for(int i=0;i<n;i++){
		cin>>x>>y>>a;a--;
		if(a==0)d[a]=max(d[a],x);
		if(a==2)d[a]=max(d[a],y);
		if(a==1)d[a]=min(d[a],x);
		if(a==3)d[a]=min(d[a],y);
	}
	cout<<max(0,(d[1]-d[0]))*max(0,(d[3]-d[2]))<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b,c;
  cin >> a;
  cin >>b;
  cin >>c;
  
  cout << (a-b)%c <<endl;
  
   return 0;
}


Measured memory_bytes: 256
#include<math.h>
#include<iostream>
using namespace std;
int main()
{
  int n,d,count=0;
  double x,y,res;
  cin>>n>>d;
  for(int i=0;i<n;i++)
  {
    cin>>x>>y;
    res=sqrt((x*x)+(y*y));
    if(res<=d)
      count++;
  }
  cout<<count;
  return 0;
} 

Measured memory_bytes: 3224
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

int main()
{
  uint64_t N;
  cin >> N;

  vector<uint64_t> A(N);
  N_TIMES(n, N) { cin >> A[n]; }
  sort(A.begin(), A.end());

  vector<uint64_t> S(N + 1, 0);
  N_TIMES(n, N) { S[n + 1] = S[n] + A[n]; }

  uint64_t t = 0;
  N_TIMES(n, N) {
    if (2 * S[n] < A[n]) {
      t = n;
    }
  }
  cout << (N - t) << endl;

  return 0;
}

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

using namespace std;

int main() {
  int n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  int gcd = __gcd(n, m);
  for (int i = 0, j = 0; i < n && j < m; i += n / gcd, j += m / gcd) {
    if (s[i] != t[j]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (long long)n * m / gcd << endl;
  return 0;
}

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

int main() {
  long long n, ans = 0;
  cin >> n;
  for (long long i = 2; i * i < n; i++) {
    if (n % i > 0 || i + 1 == n / i) { continue; }
    ans += n / i - 1;
  }
  if (n > 2) { ans += n - 1; }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 888
n=int(input())
s=input()
d=[0,0]
for i in s:
    if i=="(": d[0]+=1
    if i==")" and d[0]>0: d[0]-=1
for i in s[::-1]:
    if i==")": d[1]+=1
    if i=="(" and d[1]>0: d[1]-=1
s="("*d[1]+s+")"*d[0]
print(s)

Measured memory_bytes: 38384
S = input()
T = input()
S = [i for i in S]
T = [i for i in T]
Cnt = []
for i in range(len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j]!=T[j]:
            cnt += 1
    Cnt.append(cnt)
Cnt.sort()
print(Cnt[0])

Measured memory_bytes: 9080
n,m,c = map(int,input().split())
a = input().split()
a = [int(x) for x in a]
     
d = 0
e = 0
for i in range(n):
    b = input().split()
    b = [int(x) for x in b]
    for j in range(m):
        d += b[j]*a[j]
        #print(d)
    if d + c >0:
        e += 1
    d = 0
print(e)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

bool sieve[100010];

int main(void)
{
    int N;
    cin >> N;
    vector<int> prime;

    for (int i = 0; i < 100010; ++i)
        sieve[i] = true;

    sieve[0] = sieve[1] = false;

    for (int i = 2; i * i < 100010; ++i)
    {
        if (sieve[i])
        {
            for (int j = 2; i * j < 100010; ++j)
            {
                sieve[i * j] = false;
            }
        }
    }
    for (int i = 0; i <= 55555; ++i)
    {
        if (sieve[i] && i % 5 == 1)
            prime.push_back(i);
    }

    for (int i = 0; i < N; ++i)
    {
        if (i)
            cout << " ";
        cout << prime[i];
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
long long gcd(long long a, long long b) {
    // O(log min(a,b))
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int A[505][505];

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

    int H, W;
    cin >> H >> W;

    REP(i, H) {
        REP(j, W) { cin >> A[i][j]; }
    }

    vector<tuple<int, int, int, int>> ans;
    REP(i, H) {
        REP(j, W) {
            if (A[i][j] % 2 == 0) {
                continue;
            } else {
                if (i >= H - 1 && j >= W - 1) {
                    break;
                } else if (i < H - 1 && j == W - 1) {
                    vector<int> tmp;
                    A[i][j]--;
                    A[i + 1][j]++;
                    ans.push_back(make_tuple(i, j, i + 1, j));
                } else {
                    vector<int> tmp;
                    A[i][j]--;
                    A[i][j + 1]++;
                    ans.push_back(make_tuple(i, j, i, j + 1));
                }
            }
        }
    }

    cout << ans.size() << endl;

    for (auto t : ans) {
        int a, b, c, d;
        tie(a, b, c, d) = t;
        printf("%d %d %d %d\n", a + 1, b + 1, c + 1, d + 1);
    }

    return 0;
}


Measured memory_bytes: 5232
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

const int N = 1e6 + 50;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    vector <bool> used(N);
    forn (i, 0, n) {
        int t;
        cin >> t;
        used[t] = true;
        a[i] = t;
    }
    vector <bool> ans(N, true);
    forn (i, 1, N) {
        if (used[i]) {
            for (int j = 2 * i; j < N; j += i) {
                ans[j] = false;
            }
        }
    }
    map <int, int> numbers;
    forn (i, 0, n)
        numbers[a[i]]++; 
    int cnt = 0;
    forn (i, 0, n)
        if (numbers[a[i]] == 1 && ans[a[i]])
            cnt++;
    cout << cnt;
    return 0;
}

Measured memory_bytes: 13728
#include<iostream>
#include<string>

using namespace std;

int lic(string X,string Y) {
	int c[1001][1001];
	int m = X.size();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 0;i < m;i++) {
		c[i][0] = 0;
	}
	for (int j = 0;j < n;j++) {
		c[0][j] = 0;
	}
	for (int i = 1;i <=m;i++) {
		for (int j = 1;j <= n;j++) {
			if(X[i]==Y[j]) {
				c[i][j] = c[i - 1][j-1]+1;
			}
			else {
			c[i][j]=max(c[i-1][j],c[i][j-1]);
			}
		maxl=max(maxl,c[i][j]);
		}
	}
	return maxl;
}

int main() {
	string X, Y;
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> X >> Y;
		cout << lic(X, Y)<<endl;
	}
	return 0;
}




Measured memory_bytes: 7096
import sys
sys.setrecursionlimit(10 ** 6)

n = int(input())
edges = [list(map(int, input().split())) for _ in range(n - 1)]
bw = [-1 for i in range(n + 1)]
bw[1] = 0

new_edges = [[] for _ in range(n + 1)]

for e in edges:
	new_edges[e[0]].append([e[1], e[2]]) 
	new_edges[e[1]].append([e[0], e[2]]) 

def dfs(frm, now):
	for ne in new_edges[now]:
		if ne[0] == frm:
			continue
		else:
			if ne[1] % 2 == 0:
				bw[ne[0]] = bw[now]
			else:
				bw[ne[0]] = abs(1 - bw[now])
			dfs(now, ne[0])

dfs(0, 1)

for i in range(1, n + 1):
	print(bw[i])


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

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;


int N, K;
int a[11000];
bool dp1[5100][5100];
bool dp2[5100][5100];
int sum[5100][5100];

int main() {
  while (cin >> N >> K) {
	for (int i = 0; i < N; ++i) cin >> a[i];
	memset(dp1, 0, sizeof(dp1));
	memset(dp2, 0, sizeof(dp2));

	dp1[0][0] = true;
	dp2[N][0] = true;
	for (int i = 0; i < N; ++i) {
	  for (int w = 0; w <= K; ++w) {
		if (!dp1[i][w]) continue;
		dp1[i+1][w] = true;
		if (w + a[i] <= K) dp1[i+1][w+a[i]] = true;
	  }
	}
	for (int i = N; i > 0; --i) {
	  for (int w = 0; w <= K; ++w) {
		if (!dp2[i][w]) continue;
		dp2[i-1][w] = true;
		if (w + a[i-1] <= K) dp2[i-1][w+a[i-1]] = true;
	  }
	}

	for (int i = 0; i <= N; ++i) {
	  sum[i][0] = 0;
	  for (int j = 0; j <= K; ++j) {
		sum[i][j+1] = sum[i][j] + (dp2[i][j] ? 1 : 0);
	  }
	}

	int res = 0;
	for (int i = 0; i < N; ++i) {
	  bool need = false;
	  for (int w = 0; w <= K; ++w) {
		if (!dp1[i][w]) continue;
		int left = max(0, K - a[i] - w);
		int right = max(0, K - w);

		//cout << i << ", " << w << ";; " << left << ", " << right << ": " << sum[i+1][right] << ", " <<  sum[i+1][left] << endl;
		
		if (sum[i+1][right] - sum[i+1][left] >= 1) need = true;
	  }
	  if (!need) ++res;
	}

	cout << res << endl;
  }
}
  



Measured memory_bytes: 152704
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<math.h> 
using namespace std;
struct edge{
    long long v,ty,next;
    edge(long long v=0,long long ty=0,long long next=0):v(v),ty(ty),next(next){}
}e[1000003<<1];
long long n,m,col[1000003],cnt[3],siz;
long long tot=0,head[1000003];
bool flag;
inline void add(long long u,long long v,long long ty){
	e[++tot]=edge(v,ty,head[u]),head[u]=tot;
}
void dfs(long long u){
    cnt[col[u]]++;
    for(long long i=head[u];i;i=e[i].next){
		long long v=e[i].v,ty=e[i].ty;
		siz+=(ty==1);
		if(col[v]>=0){
			flag|=(col[v]!=(col[u]+ty)%3);
		}else{
			col[v]=(col[u]+ty)%3,dfs(v);
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		long long x,y;
		cin>>x>>y;
		add(x,y,1),add(y,x,2);
	}
    memset(col,-1,sizeof(col));
    long long ans=0;
    for(int i=1;i<=n;i++){
    	if(col[i]>=0){
    		continue;
		}
        cnt[col[i]=0]=cnt[1]=cnt[2]=siz=flag=0;
        dfs(i);
        if(flag){
        	ans+=(cnt[0]+cnt[1]+cnt[2])*(cnt[0]+cnt[1]+cnt[2]);
		}else if(cnt[0]&&cnt[1]&&cnt[2]){
        	ans+=cnt[0]*cnt[1]+cnt[1]*cnt[2]+cnt[2]*cnt[0];
		}else{
        	ans+=siz;
		}
	}
	cout<<ans<<endl;
    return 0;
}

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

int main(){
    string str;
    int num;
    priority_queue<int> maxqu;
    while(true){
        cin >> str;
        if (str[2] == 'd') break;
        if (str[0] == 'i'){
            cin >> num;
            maxqu.push(num);
        } else {
            cout << maxqu.top() << endl;
            maxqu.pop();
        }
    }
}

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

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

string devide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    REP(i, 4) reverse(devide[i].begin(), devide[i].end());

    for(int i = 0; i < S.size();) {
        bool flag = false;
        REP(j, 4) {
            string d = devide[j];
            if(S.substr(i, d.size()) == d) {
                i += d.size();
                flag = true;
            }
        }
        if(!flag) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int n;

/* subroutines */

int ch2int(char ch) {
  if (ch >= '0' && ch <= '9') return ch - '0';
  if (ch >= 'A' && ch <= 'Z') return ch - 'A' + 10;
  if (ch >= 'a' && ch <= 'z') return ch - 'a' + 36;
  return -1;
}

int str2int(int pi, string mi) {
  int d = 0;

  for (int i = 0; i < mi.size(); i++)
    d = d * pi + ch2int(mi[i]);
  return d;
}

/* main */

int main() {
  cin >> n;

  int bits = 0;
  
  while (n--) {
    int pi;
    string mi;
    cin >> pi >> mi;

    int d = str2int(pi, mi);
    bits ^= d;
  }

  cout << (bits != 0 ? "win" : "lose") << endl;
  
  return 0;
}

Measured memory_bytes: 1204
H,W=(int(x) for x in input().split())
while H!=0 or W!=0:
    for i in range(H):
        if i%2==0:
            if W%2==0:
                print("#."*int((W/2)))
            else:
                print("#."*(int(W/2))+"#")
        elif i%2==1:
            if W%2==0:
                print(".#"*int((W/2)))
            else:
                print(".#"*(int(W/2))+".")
    print("")
    H,W=(int(x) for x in input().split())


Measured memory_bytes: 5628
import sys
readline=sys.stdin.readline

S = int(readline())

# 最も多い箱の数は、N = S // 3個
# Nから1個の箱i個に対して、残った数値（S - 3 * i）を分ける場合の数を足し合わせる

N = S // 3

DIV = 10 ** 9 + 7

from functools import reduce
def nCr(n,r,DIV):
  if r < n - r:
    r = n - r
  if r == 0:
    return 1
  f = lambda x,y:x*y%DIV
  X = reduce(f,range(n-r+1, n+1))
  Y = reduce(f,range(1, r+1))
  return X * pow(Y, DIV - 2, DIV) % DIV

ans = 0
for i in range(N, 0, -1):
  rest = S - 3 * i
  if rest <= 0:
    ans += 1
    continue
  # rest個をi個の箱に分ける
  # rest + i - 1 C min(rest, i - 1)
  ans += nCr(rest + i - 1, rest, DIV)
  ans %= DIV
  
print(ans)


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

int main() {
  int k;
  cin >> k;
  int result = 0;
  
  for(int i = 1; i <= k; ++i) {
    for(int j = 1; j <= k; ++j) {
      for(int l = 1; l <= k; ++l) {
        result += gcd(gcd(i, j), l);
      }
    }
  }
  
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;

int main() {
  int n;
  cin >> n;
  int Max = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    Max = max(Max, l);
    sum += l;
  }
  if (sum - Max > Max)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits>
#include <map>
#define MOD 1000000007
#include <algorithm>
#include <math.h>
#include <utility>

using namespace std;
    long long int dp[305][305][305];

int main(){
    int n,k;
    cin >> n >> k;
    n++;

    vector<int> h(n);
    h[0] = 0;
    for(int i = 1; n - 1 >= i;i++){
        cin >> h[i];
    }

    for(int i = 0; n + 1 > i; i++)
        for(int j = 0; n + 1 + 1> j; j++)
            for(int l = 0; k + 1 > l; l++) dp[i][j][l] = 100000000000000LL;
    
    dp[0][0][k] = 0;

    for(int i = 0; n - 1> i; i++){
        for(int j = 0; i >= j; j++){
            for(int l = 0; k >= l; l++){
                if(dp[i][j][l] == 100000000000000LL) continue;
                dp[i + 1][i + 1][l] = min(dp[i + 1][i + 1][l], dp[i][j][l] + max(0, h[i + 1] - h[j]));
                if(l)
                    dp[i + 1][j][l-1] = min(dp[i + 1][j][l - 1], dp[i][j][l]);
            }
        }
    }

    long long int ans = 100000000000000LL;
        for(int j = 0; n > j; j++){
            for(int l = 0; k >= l; l++){
                ans = min(ans, dp[n-1][j][l]);
            }
        }
        cout << ans << endl;
    return 0;
}

Measured memory_bytes: 221440