akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
int key;
struct node *prev, *next;
};

struct node *nil;

void insert(int);
void delete(struct node*);
struct node* search(int);
void listPrint(void);

int main(){
  int n,i,x;
  char str[15];

  scanf("%d",&n);
  nil = (struct node*)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;

  for(i = 0; i<n;i++){
    scanf("%s",str);
    if(str[0]== 'i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='d'){
      if(str[6]=='\0'){
        scanf("%d",&x);
        delete(search(x));
      }else if(str[6]=='F'){
        delete(nil->next);
      }else{
        delete(nil->prev);
      }
    }
  }
  listPrint();
  return 0;
}




void insert(int key){
  struct node* newnode = (struct node*)malloc(sizeof(struct node));
  newnode->key = key;
  newnode->next = nil->next;
  nil->next->prev = newnode;
  nil->next = newnode;
  newnode->prev = nil;
 }

void delete(struct node* delnode){
  if(delnode == nil){;
  }else{
    delnode->prev->next = delnode->next;
    delnode->next->prev = delnode->prev;
    free(delnode);
  }
}

struct node* search(int key){
  struct node* searchnode = nil->next;
  while(searchnode != nil && searchnode->key != key){
    searchnode = searchnode->next;
  }
return searchnode;
}


void listPrint(){
  int i = 0;
  struct node* n= nil->next;
  while(1){
    if(n==nil)break;
    if(i>0)printf(" ");
    i++;
    printf("%d",n->key);
    n=n->next;
  }
  printf("\n");
}

Measured memory_bytes: 33024
h,w=map(int,input().split())
m=[]
m.append(['x']*(w+2))
for i in range(h):
    s=list(input())
    m.append(['x']+s+['x'])
m.append(['x']*(w+2))

for i in range(1,h+1):
    for j in range(1,w+1):
        if m[i][j]=='.':
            c=0
            for a in [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]:
                if m[i+a[0]][j+a[1]]=='#':
                    c+=1
            m[i][j]=str(c)
for i in range(1,h+1):
    ans=''
    for j in range(1,w+1):
        ans+=m[i][j]
    print(ans)




Measured memory_bytes: 3188
n=int(input())
lst1=[]
lst2=[]
count=0
for _ in range(n):
    m,k=[int(x) for x in input().split()]
    lst1.append(m)
    lst2.append(k)
for i in range(n-2):
    if(lst1[i]==lst2[i] and lst1[i+1]==lst2[i+1] and lst1[i+2]==lst2[i+2]):
        count=3
        break
if(count==3):
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 9192
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int counter = 1;
        int x = sc.nextInt();
        while(x != 0){
            System.out.println("Case " + counter + ": " + x);
            x = sc.nextInt();
            counter++;
        }
    }
}


Measured memory_bytes: 41220
#include <cstdio>

int main()
{

    int count[26];
    for (int i = 0; i < 26; i++)
    {
        count[i] = 0;
    }
    char s[1300];
    while (fgets(s, 1300, stdin) != NULL)
    {
        for (int i = 0; s[i] != '\0'; i++)
        {
            if (s[i] >= 'A' && s[i] <= 'Z')
            {
                count[s[i] - 'A']++;
            }
            if (s[i] >= 'a' && s[i] <= 'z')
            {
                count[s[i] - 'a']++;
            }
        }
    }

    for (int i = 0; i < 26; i++)
    {
        printf("%c : %d\n", 'a' + i, count[i]);
    }
    return 0;
}


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

int n, s, i, a[105];
int main() {
	cin >> n;
	for(i=0; i<n; i++) cin >> a[i];
	sort(a, a+n, greater<int>());
	for(i=0; i<n; i++) i%2 ? s-=a[i] : s+=a[i];
	cout << s;
	return 0;
}

Measured memory_bytes: 256
"use strict";

function main(input) {
  input = input.split(" ");
  input[0] = parseInt(input[0]);
  input[1] = parseInt(input[1]);
  input[2] = parseInt(input[2]);
  let num = parseInt(input[3]);
  let result = 0;

  for (let i = 0; i < 3; i++) {
    let num2 = num;
    num = num - input[i];
    if (num > 0) {
      // 継続
      if (i === 0) {
        result = result + input[i];
      } else if (i === 1) {
        //何もしない
      } else if (i === 2) {
        result = result - input[2];
      }
    } else {
      if (i === 0) {
        result = result + num2;
      } else if (i === 1) {
        //何もしない
      } else if (i === 2) {
        result = result - num2;
      }
      console.log(result);
      return;
    }
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


Measured memory_bytes: 30108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringTokenizer st;

		int rectangle = 0, rhombus = 0;
		int[] sides = new int[3];
		
		while ((line = br.readLine()) != null) {
			st = new StringTokenizer(line, ",");
			for (int i = 0; i < 3; i++) {
				sides[i] = Integer.parseInt(st.nextToken());
			}
			if (sides[2] * sides[2] == sides[0] * sides[0] + sides[1]
					* sides[1])
				rectangle++;
			else if (sides[0] == sides[1])
				rhombus++;
		}
		System.out.println(rectangle + "\n" + rhombus);
	}
}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n), bigger(n), smaller(n);
    for(auto& x : v) cin >> x;
    for(int i = 1; i < n; ++i){
        if(v[i] - v[i-1] > 0) bigger[i] = 1;
        else if(v[i] - v[i-1] < 0) smaller[i] = 1; }
    partial_sum(begin(bigger), end(bigger), begin(bigger));
    partial_sum(begin(smaller), end(smaller), begin(smaller));

    vector<int> d(n, 0);
    d[0] = 1;
    for(int st = 0, dr = 1; dr < n; ++dr){
        while(bigger[dr] != bigger[st] && smaller[dr] != smaller[st]) ++st;
        d[dr] = (st == 0 ? 1 : d[st-1] + 1); }
    cout << d.back() << endl;
    return 0; }


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

int main() {
  int N;
  cin>>N;
  vector<long long> a(N);
  for(long long &x: a) cin>>x;
  int ans=1,start=0;
  if(N==1) {cout<<1<<endl; return 0;}
  for(int i=0;i<N-1;i++){
   if(a[i]!=a[i+1]) {start=i; break;}
    if(i=N-1) {cout<<1<<endl; return 0;}
  }
  bool sw=false,sw_1=false;
  if(a[start]<a[start+1]) sw=true;
  for(int i=start;i<N-1;i++){
    if(sw_1&&a[i]>a[i+1]){
      sw_1=false;
      sw=false;
    }
    if(sw_1&&a[i]<a[i+1]){
      sw_1=false;
      sw=true;
    }
    if(sw==true&&a[i]>a[i+1]) {
      sw_1=true;
      ans++;
    }
    else if(sw==false&&a[i]<a[i+1]){
      sw_1=true;
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  long N,A,B;
  cin >> N >> A >> B;
  long T = N/(A+B);
  if(N<=A){
    cout << N << endl;
  }
  else if (N%(A+B)<A){
    cout << T*A+N-T*(A+B) << endl;
  }
  else {
    cout << T*A+A << endl;
  }
  return 0;
}
  

Measured memory_bytes: 256
c = [list(map(int,input().split())) for i in range(3)]
if [c[0][0]-c[0][1],c[0][1]-c[0][2]] == [c[1][0]-c[1][1],c[1][1]-c[1][2]] == [c[2][0]-c[2][1],c[2][1]-c[2][2]]:
  if [c[0][0]-c[1][0],c[1][0]-c[2][0]] == [c[0][1]-c[1][1],c[1][1]-c[2][1]] == [c[0][2]-c[1][2],c[1][2]-c[2][2]]:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 38504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll H,W,K;
    cin >> H >> W >> K;
    vc<string> S(H);
    rep(i, H) cin >> S[i];
    ll cnt = 0;
    rep(i, H) rep(j, W) if (S[i][j] == '1') cnt++;
    if(H==1){
        cout << (cnt - 1) / K << endl;
        return 0;
    }

    ll ans = INF;

    rep(bit,1<<(H-1)){
        vc<ll> d = {0};
        rep(i, H - 1) if ((1 << i) & bit) d.eb(i+1);
        d.eb(H);
        ll dn = d.size()-1, tmpans = d.size() - 2;
        
        bool isok = true;
        vl esum(dn);
        rep(w,W){
            vl tmpsum(dn);
            rep(i,dn){
                repe(h,d[i],d[i+1]){
                    if (S[h][w] == '1') tmpsum[i]++;
                }
                if(tmpsum[i]>K){
                    isok = false;
                }
            }

            bool isover = false;
            rep(i, dn) if (esum[i] + tmpsum[i] > K) isover = true;
            if(isover){
                tmpans++;
                rep(i, dn) esum[i] = tmpsum[i];
            }
            else{
                rep(i, dn) esum[i] += tmpsum[i];
            }
        }

        if (isok)chmin(ans, tmpans);
    }

    cout << ans << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> p(N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		ans += p[i];
	}
	sort(p.begin(), p.end());
	cout << ans - p[N - 1] / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

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

int main(){
  int i,j,k,n;
  double a,s[11],sum;

  while(scanf("%lf",&a) != EOF){
    sum = 0;
    s[0] = a;
    REP(i,1,10){
      if(i%2 == 1) s[i] = s[i-1] * 2;
      if(i%2 == 0) s[i] = s[i-1] / 3;
    }
    rep(i,10) sum += s[i];

    printf("%.8lf\n",sum);
  }

  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define szof(x) int32_t((x).size())
#define str(x) to_string(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;
const int MOD998 = 998244353;
const int INF = 1e9;
const ll LLINF = 1e18;

mt19937_64 rng((uint) chrono::steady_clock::now().time_since_epoch().count());

template <class T>
T rnd(T l, T r) {
	return uniform_int_distribution<T>(l, r)(rng);
}

void run() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << 1LL * max(0, n - h + 1) * max(0, n - w + 1) << "\n";
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout.precision(10); cout << fixed;
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		run();
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    ll cntm = 0;
    ll cntz = 0;
    ll ans = 0;

    rep(i,n){
        cin >> a[i];
        b[i] = abs(a[i]);
        if(a[i] < 0) cntm++;
        if(a[i] == 0) cntz++;
        ans += b[i];
    }

    sort(all(b));


    if(cntz >= 1 || cntm %2 == 0){
        cout << ans << endl;
        return 0;
    }

    cout << ans - b[0]*2 << endl;
}

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

typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;

const int INF = 1<<28;


int Find(int p, vec& par) {
    if (p == par[p]) return (p);
    return (par[p] = Find(par[p], par));
}

void Merge(int x, int y, vec& par) {
    x = Find(x, par), y = Find(y, par);
    if (x != y) {
        par[x] = y;
    }
}

void dfs(int now, int p, vec& par, mat& T, vec& MarkedTime) {
    if (MarkedTime[now] != MarkedTime[p] && MarkedTime[now] != INF) return ;
    par[now] = p;
    for (int i = 0; i < T[now].size(); i++) {
        dfs(T[now][i], p, par, T, MarkedTime);
    }
}

void solve(int N, int Q) {
    mat T(N+1);
    vec Tr(N+1);
    Tr[1] = 1;
    for (int i = 2; i <= N; i++) {
        int v; cin >> v;
        T[v].push_back(i);
        Tr[i] = v;
    }

    vec MarkedTime(N+1, INF);
    vec TimeToMarkedVertex(Q+1);
    vec QueryTimeToVertex(Q+1);
    MarkedTime[1] = -1;
    for (int i = 0; i < Q; i++) {
        char q;
        int v;
        cin >> q >> v;
        if (q == 'M') MarkedTime[v] = min(MarkedTime[v], i), TimeToMarkedVertex[i] = v;
        else QueryTimeToVertex[i] = v;
    }

    vec par(N+1);
    for (int i = 1; i <= N; i++) par[i] = i;
    for (int i = 1; i <= N; i++) {
        if (MarkedTime[i] == INF) continue;
        dfs(i, i, par, T, MarkedTime);
    }

    long long int cost = 0LL;
    for (int i = Q - 1; i > -1; i--) {
        if (QueryTimeToVertex[i] > 0) cost += Find(par[QueryTimeToVertex[i]], par);
        else if (i == MarkedTime[TimeToMarkedVertex[i]])
            Merge(TimeToMarkedVertex[i], Tr[TimeToMarkedVertex[i]], par);
    }

    cout << cost << endl;
}

int main() {
    int N, Q;
    while (cin >> N >> Q, N || Q) solve(N, Q);

    return 0;
}

Measured memory_bytes: 8364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 1001001001;
ll n,a,b;

int main(){
  cin >> n >> a >> b;
  if((b-a)%2 == 0){
    cout << (b-a)/2 << endl;
    return 0;
  }
  ll ans = 0;
  if(a-1>=n-b){
    ans += n-b+1+((b-a-1)/2);
  }else{
    ans += a-1+1+((b-a-1)/2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
  int H,W,K;cin>>H>>W>>K;
  vector<string> field(H);
  rep(i,H) cin>>field[i];
  vector<vector<int>> sum(H+1,vector<int>(W+1,0));
  rep(i,H) {
    rep(j,W) {
      int one = 0;
      if(field[i][j] == '1') one = 1;
      sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + one;
    }
  }
  int ans = 100000;
  for(int i = 0;i < (1<<(H - 1)) ;i++) {
    int cnt = 0;
    vector<int> div;
    rep(j,H-1) {
      if((i>>j) & 1) {
	div.push_back(j);
	cnt++;
      }
    }
    //    cout << "i " << i << " cnt " << cnt << endl;
    int j = 0,pre_h = -1,pre_w = -1;
    div.push_back(H-1);
    bool cannot = false;
    while(j<W) {
      bool ok = true;
      for(auto nxt : div) {
	int num = sum[nxt+1][j+1] - sum[nxt+1][pre_h+1] - sum[pre_w+1][j+1] + sum[pre_w+1][pre_h+1];
	//	cout<< "num " << num <<endl;
	if(num > K) {
	  if(pre_h == j - 1) {
	    cannot = true;
	  }
	  pre_h = j-1;
	  pre_w = -1;
	  cnt++;
	  ok = false;
	  break;
	} else {
	  pre_w = nxt;
	}
      }
      if(ok){
	j++;
	pre_w = -1;
      } else {
	if(cannot) {
	  break;
	} 
	if(cnt >= ans) break;
      }
    }
    if(!cannot) ans = min(ans,cnt);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3668
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N, X = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]

numbers.append(X)
numbers = sorted(numbers)

diff_numbers = []

for i in range(len(numbers)-1):
    diff_numbers.append(abs(numbers[i] - numbers[i+1]))

gcd_num = gcd_list(diff_numbers)

print(gcd_num)

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

typedef long long ll;
using namespace std;
int main()
{
  string s1,s2,s3;
  cin>>s1>>s2>>s3;

  cout<<char('A'+(s1[0]-'a'))<<char('A'+(s2[0]-'a'))<<char('A'+(s3[0]-'a'))<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000;

using ll = long long;
using namespace std;

int main(){
    int n, sum_price;
    cin >> n;
    bool flag=false;
    rep(i, 100){
        rep(j, 100){
            sum_price = 4*i+7*j;
            if (sum_price==n) flag = true;
        }
    }
    if (flag==true) cout << "Yes" << endl;
    else cout << "No" << endl;
    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n,r[]={5,3,3,3,3,3,4,3,4};
char c[][5]={{},{'.',',','!','?',' '},{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};
string s;

int main(){
	cin>>n;
	while(n--){
		cin>>s;
		int cur1=0,cur2=0;
		rep(i,s.size()){
			int m=s[i]-'0';
			if(!m){
				if(cur1){cout<<c[cur1][cur2];cur1=0;}
			}
			else{
				if(!cur1){cur1=m;cur2=0;}
				else cur2=(cur2+1)%r[cur1-1];
			}
		}
		cout<<endl;
	}
}

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

int main() {
	for( int i = 1; i <= 10000; ++i ) {
		int x;
		cin >> x;

		if( x == 0 ) {
			break;
		}

		cout << "Case " << i << ": " << x << endl;
	}
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)

int main()
{
    string a, b;
    cin >> a >> b;
    (int)sqrt(stod(a + b)) == sqrt(stod(a + b)) ? cout << "Yes" : cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
vector<int64_t> s;
priority_queue<int64_t, vector<int64_t>, greater<int64_t>> q;
queue <int64_t> Q;
int k;
void dfs(int64_t t,int l){
    if(l>9){
        return ;
    }
    s.push_back(t); 
    //q.push(t);
    //cout<<t<<endl;
    dfs(10*t+(t%10),l+1);
    if(t%10 !=0){
        dfs(10*t+(t%10-1),l+1);
    }
    if(t%10 !=9){
        dfs(10*t+(t%10+1),l+1);
    }

}
int main(){

    cin>>k;
    int64_t i=1;
    int count=0;
    dfs(1,0);
    dfs(2,0);
    dfs(3,0);
    dfs(4,0);
    dfs(5,0);
    dfs(6,0);
    dfs(7,0);
    dfs(8,0);
    dfs(9,0);
    all(s);
    //cout<<s.size()<<endl;
    /*
    rep(i,k){
        cout<<s[i]<<" ";
    }
    */
   cout<<s[k-1]<<endl;

    //cout<<"ans is "<<s[k-2]<<endl;
}

Measured memory_bytes: 3444
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    bool cards[4][14];
    int n, rank;
    char suit;
    
    for(int s=0; s<4; s++)
        for(int r=1; r<=13; r++)
            cards[s][r]=0;
            
    cin >>n;
    for(int i=0; i<n; i++){
        cin >> suit >> rank;
        if(suit == 'S')cards[0][rank]=1;
        if(suit == 'H')cards[1][rank]=1;
        if(suit == 'C')cards[2][rank]=1;
        if(suit == 'D')cards[3][rank]=1;
        
        
    }
    
    for(int s=0; s<4; s++){
        for(int r=1; r<=13; r++){
            if( cards[s][r])continue;
            if(s==0) suit = 'S';
            if(s==1) suit = 'H';
            if(s==2) suit = 'C';
            if(s==3) suit = 'D';
            cout << suit << " " << r << endl;
        }
    }
    return 0;
}



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

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

    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    int res = 0;
    
    if(N <= K) cout << N * X << endl;
    else cout << K * X + (N - K) * Y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;
  if (N == K || K == 1) {
    cout << 0 << endl;
  } else {
    ll ans = N - K;
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

const int maxn = 200010, mod = 998244353;
int n, x, y, ans, k;
long long int dp[maxn], sum[maxn];
struct fn{
	int l, r;
}f[maxn];

int read(){
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*w;
}

signed main()
{
    #ifndef ONLINE_JUDGE
  	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
    #endif  

    n = read(); k = read();
	for(int i = 1; i <= k; i ++) {
		f[i].l = read(); f[i].r = read();
	}
	dp[1] = 1;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= k; j ++) {
			if(i <= f[j].l) continue;
			dp[i] += sum[i - f[j].l] - sum[max(i - f[j].r, 1) - 1] + mod;
			dp[i] %= mod;
		}
		sum[i] = dp[i] + sum[i - 1];
		sum[i] %= mod;
	}
	printf("%lld", dp[n]);

    return 0;
}

Measured memory_bytes: 6832
#include<iostream>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)

int main(){
    int w, h;
    while(cin >> w >> h, w+h){
       int di = 1, dj = 0; 
       string op;
       int k, i = 0, j = 0;

       while(cin >> op, op != "STOP"){
           if(op.length() < 6){
               if(op == "LEFT"){
                   swap(di, dj);
                   dj = -dj;
               }else if(op == "RIGHT"){
                   swap(di, dj);
                   di = -di;
               }
           }else{
               cin >> k;
               int bias = (op == "FORWARD") ? 1 : -1;

               for(int x = 0; x < k; x++){
                   i += bias*di, j += bias*dj;
                   if(!inRange(i,0,h) || !inRange(j,0,w))   i -= bias*di, j -= bias*dj;
               }
           }
       }

       cout << j+1 << " " << i+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3060
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<50);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

void solve(){
  ld t,x;cin>>t>>x;
  cout<<t/x<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	solve();
}


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

int SLEN;

long long  dfs(int n, long long csum, string s){
    //cout <<">> n:" <<  n << " csum:" << csum << " s:" << s<< endl;
    if (s.size() == 0) {
        //cout <<"<<<<<< n:" <<  n << " csum:" << csum << " s:" << s<< endl;

        return csum + stoll(s);
        }
    
    long long sum=csum + stoll(s);
    //cout << "sum== " <<sum<< endl;
    int slen =s.size();
    for (int i = 1; i < slen; i++){
        string ls = s.substr(0, i);
        //cout << ">>>> ls:" << ls << " rs:";
        long long lsval = stoll(ls);
        string rs = s.substr(i);
        //cout << rs << endl;
        long long csum2 = csum+lsval;
        long long sumval= dfs(n+i, csum2, rs);
        sum += sumval;
        //cout << "+= " <<sumval<< " sum= " << sum<<  endl;


    }
    
    return sum;
}
int main()
{
    string s;
    cin >> s;
    SLEN = s.size();
    //cout << SLEN << endl;
    cout << dfs(0, 0, s) << endl;

   return 0;
}

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

int DP[1010][1010];

int main() {
  string A, B;
  cin >> A >> B;
  int LA = (int) A.size();
  int LB = (int) B.size();
  fill(&DP[0][0], &DP[0][0]+1010*1010, 0);
  for (auto i=-1; i<LA; i++) {
    for (auto j=-1; j<LB; j++) {
      if (i == -1) {
        DP[i+1][j+1] = j+1;
      } else if (j == -1) {
        DP[i+1][j+1] = i+1;
      } else if (A[i] == B[j]) {
        DP[i+1][j+1] = DP[i][j];
      } else {
        // A[i] と B[j] が異なるならば、
        // B[j]を挿入するか、A[i]を削除するか、A[i]をB[j]に置換するか
        // のどれかは必ず実行しなくてはならない。
        // 残りの編集作業回数は、それぞれDP[i+1][j]、DP[i][j+1]、DP[i][j]
        // となる。それぞれが最善である例をつくることができる。
        DP[i+1][j+1] = min({DP[i+1][j], DP[i][j+1], DP[i][j]}) + 1;
      }
    }
  }
  cout << DP[LA][LB] << endl;
}

Measured memory_bytes: 5172
# https://atcoder.jp/contests/abc092/tasks/abc092_b

import itertools
import collections
import bisect

def main():
    N = int(input())
    D, X = map(int, input().split())
    choco = 0
    for _ in range(N):
        a = int(input())
        choco += (D - 1) // a + 1
    print(choco + X)


if __name__ == '__main__':
    main()
    

Measured memory_bytes: 3444
l = [0, 0, 0, 0]

for i in range(3):
    a, b = map(int, input().split())
    l[a - 1] += 1
    l[b-1] += 1

for i in l:
    if i == 0 or i >= 3:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  vector<ll> a(n);for(ll i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  ll cnt=0;
  ll num=a[0];
  vector<pair<ll,ll>>v;
  for(ll i=0;i<n-1;i++){
    cnt++;
    if(a[i]!=a[i+1]){
      v.push_back(make_pair(num,cnt));
      num=a[i+1];
      cnt=0;
    }
  }
  v.push_back(make_pair(num,cnt+1));
  ll ans=0;
  for(ll i=0;i<v.size();i++){
    ll x=v[i].first;
    ll y=v[i].second;
    if(y<x)ans+=y;
    else ans+=y-x;
  }
  cout<<ans<<endl;
}
           
            

Measured memory_bytes: 3188
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    s = S()
    N = len(s)

    for i in range(2):
        for j in range(2):
            for k in range(2):
                A = int(s[0])
                B = int(s[1])
                C = int(s[2])
                D = int(s[3])
                ans = A
                op1 = '+' if i == 0 else '-'
                op2 = '+' if j == 0 else '-'
                op3 = '+' if k == 0 else '-'
                ans = ans + B if i == 0 else ans - B
                ans = ans + C if j == 0 else ans - C
                ans = ans + D if k == 0 else ans - D
                if ans == 7:
                    print(s[0] + op1 + s[1] + op2 + s[2] + op3 + s[3] + '=7')
                    return

    print(-1)


if __name__ == '__main__':
    main()


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


int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> arr(n);
  arr[0] = 0;
  int ac = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == 'A' && s[i + 1] =='C') ++ac;
    arr[i + 1] = ac;
  }
  for (int i = 0; i < q; ++i) {
    int left, right;
    cin >> left >> right;
    cout << arr[right - 1] - arr[left - 1] << endl;
  }
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    deque<string> deq;
    bool reverse=false;
    
    string S;
    cin>>S;
    ll Q;
    cin>>Q;
    
    deq.push_front(S);
    
    rep(i,Q){
        ll T;
        cin>>T;
        if(T==1) reverse=!reverse;
        else{
            ll F;
            cin>>F;
            string C;
            cin>>C;
            if(F==1 && !reverse) deq.push_front(C);
            if(F==1 && reverse) deq.push_back(C);
            if(F==2 && !reverse) deq.push_back(C);
            if(F==2 && reverse) deq.push_front(C);
        }
    }
    if(!reverse){
        while(!deq.empty()){
            cout<<deq.front();
            deq.pop_front();
        }
        cout<<endl;
    }
    else{
        while(!deq.empty()){
            string an=deq.back();
            rep(i,an.size()) cout<<an.at(an.size()-1-i);
            deq.pop_back();
        }
        cout<<endl;
    }
  
    return 0;
}


Measured memory_bytes: 12288
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using i64 = long long;

template <class T = long long int>
class Bit {
    private:
    unsigned len;
    T init;
    std::vector<T> arr;

    public:
    Bit(unsigned length, T initialValue = 0): len(length), init(initialValue), arr(len + 1, init) {}
    void update(unsigned a, T newval) {
        for (unsigned x = a; x <= len; x += x & -x) arr[x] += newval;
    }
    T query(unsigned a) const {
        T ret = init;
        for (unsigned x = a; x > 0; x -= x & -x) ret += arr[x];
        return ret;
    }
};

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::tuple<int, int, int>> evs;

    for (int i = 0; i < n; i++) {
        int l, r;
        std::cin >> l >> r;
        ++r;
        evs.emplace_back(r - l, l, r);
    }

    std::sort(evs.begin(), evs.end());

    Bit<int> bit(m + 2);
    auto it = evs.begin();
    for (int i = 1; i <= m; i++) {
        int ret = evs.end() - it;
        for (int j = i; j <= m; j += i) {
            ret += bit.query(j);
        }
        while (it != evs.end() && std::get<0>(*it) == i) {
            bit.update(std::get<1>(*it), 1);
            bit.update(std::get<2>(*it), -1);
            it++;
        }
        printf("%d\n", ret);
    }

    return 0;
}


Measured memory_bytes: 8560
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
inline LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
const int N=708;
int n,m;
int x,y;
bool w[N][N];
int vis[N],t[3];
//bool f[2][N];
bitset<N> f;
inline bool dfs(int x)
{
	++t[vis[x]];
	for(int i=1;i<=n;++i){
		if(i!=x&&!w[x][i]){
			if(vis[i]==vis[x]){
				return 0;
			}
			if(!vis[i]){
				vis[i]=3-vis[x];
				if(!dfs(i))	return 0;
			}
		}
	}
	return 1;
}
int ans,pre,now;
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i){
		x=read();y=read();
		w[x][y]=w[y][x]=1;
	}
	/*for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(i!=j){
				w[i][j]^=1;
			}
		}
	}*/
	//f[0][0]=1;
	f[0]=1;
	//now=1;
	for(int i=1;i<=n;++i){
		if(!vis[i]){
			t[1]=t[2]=0;
			vis[i]=1;
			if(!dfs(i)){
				puts("-1");
				return 0;
			}
			/*memset(f[now],0,sizeof(f[now])); 
			for(int j=n;j;--j){
				if(j>=t[1]){
					f[now][j]|=f[pre][j-t[1]];
				}
				if(j>=t[2]){
					f[now][j]|=f[pre][j-t[2]];
				}
			}
			swap(now,pre);*/
			f=(f<<t[1])|(f<<t[2]);
		}
	}
	ans=n;
	for(int i=1;i+i<=n;++i){
		if(f[i]&&f[n-i])	ans=min(ans,n-i-i);
	}
	
	x=(n+ans)>>1;
	y=(n-ans)>>1;
	printf("%d",(x*(x-1)+y*(y-1))/2); 
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main() {
	long int n; cin >> n;
	int x = n;
	int y = 1;
	int fx = 0;
	while(x!=0){
		y = x%10;
		fx += y;
		x = x/10;
	}
	if(n%fx==0){
		cout << "Yes" << endl;
		return 0;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int alice = 0, bob = 0;
    int i = N - 1, j = N - 2;
    while(i >= 0) {
        alice += a[i];
        i -= 2;
    }
    while(j >= 0) {
        bob += a[j];
        j -= 2;
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 3676
n, m = list(map(int, input().split()))
a = []
for i in range(n):
  a.append([int(j) for j in input().split()])
b = []
for i in range(m):
  b.append(int(input()))
for i in range(n):
  s = 0
  for j in range(m):
    s += a[i][j] * b[j]
  print(s)


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    set<string> s;
    while(n--){
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size();
    return 0;
}



Measured memory_bytes: 19196
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

int check(int start,int goal){
  int cnt=0;
  while(start<goal){
    start *= 2;
    cnt++;
  }
  return cnt;
}

int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  double ans = 0;
  vector<ll> p(20);
  p[0] = 1;
  rep(i, 20) p[i + 1] = p[i] * 2;
  for (int i = 1; i <= n; i++){
    int m = i,cnt=0;
    while(m<k){
      m *= 2;
      cnt++;
    }
    double q = p[cnt]*n;
    ans += 1 / q;
  }
  printf("%.11f", ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define ABS(a) ((a)>(0)? a :-(a))

int asc(const void *a, const void *b) {
   return *(int *)a - *(int *)b;
}


int main(void) {
   int N, M;
   int L[100000+1];
   scanf("%d%d", &N, &M);
   for (int i = 0; i < M; i++) {
      scanf("%d", &L[i]);
   }
   qsort(L, M,sizeof (L[0]), asc);
   for (int i = 0; i < M - 1; i++) {
      L[i] = abs(L[i] - L[i+1]);
   }
   int ans = 0;
   qsort(L,M - 1,sizeof (L[0]), asc);
   for (int i = 0; i < M - 1 - (N - 1); i++) {
      ans += L[i];
   }
   printf("%d\n", ans);
   return 0;
}


Measured memory_bytes: 1012
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(200000)

def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", Q: int, K: int, x: "List[int]", y: "List[int]"):
    edges = [[] for _ in range(N+1)]
    for aa, bb, cc in zip(a, b, c):
        edges[aa].append((bb, cc))
        edges[bb].append((aa, cc))
    costs = [None] * (N + 1)
    def dfs(n, cost):
        if costs[n] is not None:
            return
        costs[n] = cost
        for nn, cc in edges[n]:
            dfs(nn, cost+cc)
    dfs(K, 0)
    for xx, yy in zip(x, y):
        print(costs[xx]+costs[yy])
    return

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    c = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (Q)  # type: "List[int]"
    y = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, a, b, c, Q, K, x, y)

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 160688
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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



Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int S(int a) {
	int res = 0;
	while (a > 0) {
		res += a % 10;
		a /= 10;
	}
	return res;
}
int keta(int a) {
	int res = 0;
	while (a > 0) {
		res++;
		a /= 10;
	}
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> X;
	int mna = 1e16;
	int mnb = 1;
	int st = (int)1e15;
	//cout << st << endl;
	int pow10[17];
	pow10[0] = 1;
	for (int i = 1; i < 17; i++) {
		pow10[i] = pow10[i - 1] * 10;
	}
	st-- ;
	for (int i = st; i >= 1;) {
		//cerr << i << " " << keta(i) << endl;
		int a = i;
		int b = S(i);
		if (mna * b >= a * mnb) {
			mna = a;
			mnb = b;
			X.push_back(i);
		}
		i -= pow10[max((int)0, keta(i) - 3)];
	}
	sort(X.begin(), X.end());
	for (int i = 0; i < N; i++) {
		cout << X[i] << endl;
	}
	
	//for (int i = 0; i < res.size(); i++) {
	//	cout << res[i] << endl;
	//}
	//cout << res << endl;
}

Measured memory_bytes: 256
let divi = 1000000000 + 7

let solve n =
  let rec aux c ret = if c = n then
                        (ret * n) mod divi else
                        aux (c+1) ((ret * c) mod divi)
  in
  aux 1 1

let () =
  let rec read () =
    try let ans = (Scanf.scanf "%d\n" solve) in
        Printf.printf "%d\n" ans
    with End_of_file -> ()
  in
  read ()
;;


Measured memory_bytes: 384
s = list(input())
t = list(input())
for i in range(len(s)):
    tmp = s[-1]
    for j in range(len(s)-1)[::-1]:
        s[j+1] = s[j]
    s[0]=tmp
    if s == t:
        print("Yes")
        break
else:
    print("No")

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

int main()
{
	int x;
	int a;
	int b;

	cin >> x >> a >> b;

	if (a >= b)
	{
		cout << "delicious";
	}
	else
	{
		if (b - a > x)
		{
			cout << "dangerous";
		}
		else if (b - a <= x)
		{
			cout << "safe";
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <complex>

#define fs first
#define sc second

using namespace std;

typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
const D EPS=1e-12;


namespace std{
  bool operator<(const P &a, const P &b){
    return real(a)==real(b)?imag(a)<imag(b):real(a)<real(b);
  }
}

D cross(P x, P y){return imag(conj(x)*y);}

bool para(L a, L b){return abs(cross(a.fs - a.sc, b.fs-b.sc))<EPS;}

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    D x1, y1, x2, y2, x3, y3, x4, y4;
    cin >>  x1 >> y1 >> x2 >> y2 >>  x3>> y3>> x4>> y4;
    P A = P(x1, y1);
    P B = P(x2, y2);
    P C = P(x3, y3);
    P D = P(x4, y4);
    L AB = L(A, B);
    L CD = L(C, D);
    if(para(AB, CD)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}





Measured memory_bytes: 3220
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,m,q;
  cin>>n>>m>>q;
  vector<int> a(q);
  rep(i,q){
    cin>>a[i]; --a[i];
  }
  reverse(all(a));
  vector<int> fin; fin.reserve(m);
  vector<int> inv(m,-1),cnt(m);
  for(int x:a){
    if(inv[x]<0){
      inv[x]=fin.size();
      fin.pb(x);
    }
    ++cnt[inv[x]];
    if(inv[x] && cnt[inv[x]-1]<cnt[inv[x]]){
      --cnt[inv[x]];
    }
  }
  rep(i,m) if(inv[i]<0){
    inv[i]=fin.size();
    fin.pb(i);
  }
  //cout<<cnt<<fin;
  rep(i,m-1) if(cnt[i]<n && fin[i]>fin[i+1]){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 100005
int a[maxn];
int _partition(int p,int r)
{
    int x=a[r];
    int i=p-1;
    for(int j=p;j<r;++j)
    {
        if(a[j]<=x)
        {
            ++i;
            int k=a[i];
            a[i]=a[j];
            a[j]=k;
        }
    }
    int k=a[i+1]; a[i+1]=a[r]; a[r]=k;
    return i+1;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>a[i];
    int q=_partition(0,n-1);
    for(int i=0;i<n;i++)
    {
        if(i) printf(" ");
        if(i==q)
            printf("[");
        printf("%d",a[i]);
        if(i==q)
            printf("]");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3500
def main():
    N = int(input())
    a = list(map(int, input().split()))
    inf = 10 ** 13
    dp = [[0]*N for i in range(N)]
    s = [0]*(N+1)
    for i, x in enumerate(a):
        s[i+1] = s[i]+a[i]
        dp[i][i] = 0
    for i in range(N-2, -1, -1):
        DP = dp[i]
        si = s[i]
        for j in range(i+1, N):
            tmp = s[j+1] - si
            D = inf
            for k in range(i, j):
                cost = DP[k]+dp[k+1][j]
                if D > cost:
                    D = cost
            DP[j] = D + tmp
    print(dp[0][N-1])
main()


Measured memory_bytes: 7496
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

int main() {
  int x;
  cin >> x;
  cout << (x < 1200 ? "ABC" : "ARC") << endl;
  return 0;
}

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

int main(){
  double  w,h,x,y;
  cin >> w >> h >> x >> y;
  double ans = (double)w*h/2;
  int num = (w == x*2 && h == y*2) ? 1 : 0;

  printf("%.10f %d\n",ans,num);
  return 0;
}

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

int main(){
  long long n, m;
  cin >> n >> m;
  if(n==1){
    if(m==1){
      cout << 1;
    }
    else{
      cout << m-2;
    }
  }
  else if(m==1){
    if(n==1){
      cout << 1;
    }
    else{
      cout << n-2;
    }
  }
  else{
    cout << (m-2)*(n-2);
  }
}


Measured memory_bytes: 256