akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>

int weather[201],cloth[201][3],dp[201][201];

bool can[201][201];

int main(){
	int day,wear;
	std::cin>>day>>wear;
	for(int i=1;i<=day;i++){
		std::cin>>weather[i];
	}
	for(int i=1;i<=wear;i++){
		std::cin>>cloth[i][0]>>cloth[i][1]>>cloth[i][2];
	}
	for(int i=1;i<=day;i++){
		for(int j=1;j<=wear;j++){
			if(cloth[j][0]<=weather[i]&&weather[i]<=cloth[j][1])can[i][j]=true;
		}
	}
	for(int i=2;i<=day;i++){
		for(int j=1;j<=wear;j++){
			for(int k=1;k<=wear;k++){
				if(can[i][j]&&can[i-1][k]){
					dp[i][j]=std::max(dp[i][j],dp[i-1][k]+std::abs(cloth[k][2]-cloth[j][2]));
				}
			}
		}
	}
	int max=0;
	for(int i=1;i<=wear;i++){
		max=std::max(dp[day][i],max);
	}
	std::cout<<max<<std::endl;
	return 0;
}

Measured memory_bytes: 1360
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            for (int i = 0; i < s[0]; i++)
            {
                var あ = ReadLine();
                WriteLine(あ);
                WriteLine(あ);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>

int main(){
        int array[50],temp[50];
        int n,r;
        int i,j;
        int p,c;
        while(1){
                scanf("%d %d",&n,&r);
                if(n==0&&r==0)break;
                for(i=0;i<n;i++){
                        array[i]=n-(i);
                }
                for(i=0;i<r;i++){
                        scanf("%d %d",&p,&c);
                        p=p-1;
                        for(j=p;j<(p+c);j++){
                                temp[j-p]=array[j];
                        }
                        for(j=0;j<p;j++){
                                temp[j+c]=array[j];
                        }
                        for(j=(p+c);j<n;j++){
                                        temp[j]=array[j];
                        }
                        for(j=0;j<n;j++){
                                array[j]=temp[j];
                        }
                }
                printf("%d\n",array[0]);
        }
        return 0;
}

Measured memory_bytes: 600
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val a = new Array[Int](n)
  for (i <- 0 until n) {
    a(i) = sc.nextInt()
  }
  if (!a.contains(1)) {
    println(-1)
  } else {
    var breakCount = 0
    var currentNum = 1
    for (i <- 0 until n) {
      if (a(i) == currentNum) {
        currentNum += 1
      } else {
        breakCount += 1
      }
    }
    println(breakCount)
  }
}


Measured memory_bytes: 70516
/*
Main AC Solution
*/

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

const int MN = TEN(6);
const int MM = (MN - 1) / 2;
const ll MA = TEN(9);

V<ll> input() {
    int n;
    assert(scanf("%d", &n));
    assert(1 <= n && n <= MN);
    V<ll> v(n);
    for (int i = 0; i < n; i++) assert(scanf("%lld", &(v[i])));
    return v;
}

mt19937 gen;
void reseed(ll seed) {
    gen = mt19937(seed);
    for (int i = 0; i < 10000; i++) {
        gen(); // skip
    }
}

ll rand_int(ll l, ll r) { //[l, r]
    using D = uniform_int_distribution<ll>;
    assert(l <= r);
    return D(l, r)(gen);
}

int main() {
    V<ll> v = input();
    int n = int(v.size());

    ll sm = 0;
    for (auto d: v) sm += d;

    if (n % 2 == 0) {
        //odd
        ll buf[2] = {0, 0};
        for (int i = 0; i < n; i++) buf[i%2] += v[i];
        if (buf[0] < buf[1]) swap(buf[0], buf[1]);
        cout << buf[0] << " " << buf[1] << endl;
        return 0;
    }

    int m = n/2;
    V<ll> l(m), r(m);
    l[0] = v[1] - v[0];
    for (int i = 1; i < m; i++) l[i] = l[i-1] + v[2*i+1] - v[2*i];
    r[m-1] = v[n-2] - v[n-1];
    for (int i = m-2; i >= 0; i--) r[i] = r[i+1] + v[2*i+1] - v[2*i+2];

    auto check = [&](ll md) {
        ll l_off = 0;
        for (int i = 0; i < m; i++) {
            if (r[i] < md || l[i] + l_off < 0) continue;
            else {
                md -= l[i] + l_off;
                l_off -= l[i] + l_off;
                if (md <= 0) return true;
            }
        }
        return false;
    };
    ll lw = 0, up = TEN(18);
    while (up - lw > 1) {
        ll md = (lw + up) / 2;
        if (check(md)) {
            lw = md;
        } else {
            up = md;
        }
    }
    ll ans = lw;
    for (int i = 0; i < n; i+=2) ans += v[i];
    cout << ans << " " << sm - ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef complex<int> ci;
typedef complex<double> cd;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define ft front()
#define bk back()
#define ins insert
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define FORI(a, b) for (auto(a) = (b).begin(); (a) != (b).end(); ++(a))
#define ROFI(a, b) for (auto(a) = (b).rbegin(); (a) != (b).rend(); ++(a))
#define CEIL(a, b) ((a) + (b)-1) / (b)
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <typename t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}

typedef vector<ll> vll;

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

    int a, b, c, x, y;
    cin >> x >> y >> a >> b >> c;

    vll p(a), q(b), r(c);
    F0R (i, a)
        cin >> p[i];
    F0R (i, b)
        cin >> q[i];
    F0R (i, c)
        cin >> r[i];

    sort(ALL(p));
    sort(ALL(q));
    sort(ALL(r));

    vll solution(x + y);
    F0R (i, x)
        solution[i] = p[a - x + i];
    F0R (i, y)
        solution[x + i] = q[b - y + i];
    sort(ALL(solution));
    for (int i = x + y - 2; i >= 0; --i) solution[i] += solution[i + 1];
    for (int i = c - 2; i >= 0; --i) r[i] += r[i + 1];
    ll sum = solution[0];
    F0R (i, min(c, x + y))
        ckmax(sum, r[c - i - 1] + solution[i + 1]);

    // for (int pc = c - 1, ps = x + y - 1, end = 0;
    //      pc >= max(0, c - (x + y)) && end <= ps;) {
    //     if (solution[ps] < r[pc])
    //         sum += r[pc--] - solution[end++];
    //     else
    //         --ps;
    // }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0 ; i < m ; i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        int count = 0;
        for (int i = 0 ; i < m ; i++) {
            UnionFindTree uf = new UnionFindTree(n);
            for (int j = 0 ; j < m ; j++) {
                if (i != j) {
                    uf.union(a[j], b[j]);
                }
            }
            if (!uf.same(a[i], b[i])) count++;
        }

        System.out.println(count);

    }

}

class UnionFindTree {
    int[] parent;
    int[] rank;

    public UnionFindTree(int size) {
        this.parent = new int[size];
        this.rank = new int[size];

        for (int i = 0 ; i < size ; i++) {
            makeSet(i);
        }
    }
    /*
     * UnionFindを初期化
     * はじめはすべての頂点が根
     * はじめはすべての高さは1
     */
    public void makeSet(int i) {
        parent[i] = i;
        rank[i] = 0;
    }

    /*
     * 引数の属する木のルートのIDを返す
     */
    public int find(int i) {
        if (i != parent[i]) {
            parent[i] = find(parent[i]);
        }
        return parent[i];
    }

    /*
     * 引数を同じ集合に追加する。
     * その際に木構造もいい感じにいじくる。
     */
    public void union(int x, int y) {
        int xRoot = find(x);
        int yRoot = find(y);

        if (rank[xRoot] > rank[yRoot]) {
            parent[yRoot] = xRoot;
        } else if (rank[xRoot] < rank[yRoot]) {
            parent[xRoot] = yRoot;
        } else if (xRoot != yRoot) {
            parent[yRoot] = xRoot;
            rank[xRoot]++;
        }
    }

    /*
     * 同じ木に属しているか
     */
    public boolean same(int x, int y) {
        return find(x) == find(y);
    }
}

Measured memory_bytes: 23636
def main():
    X, K, D = map(int, input().split())
    X = abs(X)
    a = X // D
    ans = 0
    if a <= K:
        K -= a
        ans = X - D * a
        if K % 2 != 0:
            ans = abs(ans - D)
    else:
        ans = X - D * K
    print(ans)



if __name__ == "__main__":
    main()

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n;
int main() {
	cin >> n;
	int a[n];
	rep(i,0,n){
		cin >> a[i];
	}
	int ans = INT_MAX;
	rep(i,-100,101){
		int sum = 0;
		rep(j,0,n){
			sum += (a[j]-i)*(a[j]-i);
		}
		ans = min(sum,ans);
	}
	pout(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int n;
struct P { double x, y;};
vector<P> p;
 
double dist(P a, P b) {
  double dx = a.x-b.x;
  double dy = a.y-b.y;
  return sqrt(dx*dx + dy*dy);
}
double f(double x, double y) {
  double res = 0;
  rep(i,n) {
    res = max(res, dist((P){x,y}, p[i]));
  }
  return res;
}
 
double g(double x) {
  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (f(x,c1) > f(x,c2)) l = c1; else r = c2;
  }
  return f(x,l);
}
 
int main() {
  cin >> n;
  p = vector<P>(n);
  rep(i,n) cin >> p[i].x >> p[i].y;
 
  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (g(c1) > g(c2)) l = c1; else r = c2;
  }
 
  double ans = g(l);
  printf("%.10f\n", ans);
  return 0;
}

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

int top,S[1000];

void push(int x){
    S[++top]=x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(void){
    int a,b;
    top=0;
    char s[100];

    while(scanf("%s",s)!=EOF){
	if(s[0]=='+'){
	    a=pop();
	    b=pop();
	    push(a+b);
	}else if(s[0]=='-'){
	    b=pop();
	    a=pop();
	    push(a-b);
	}else if(s[0]=='*'){
	    a=pop();
	    b=pop();
	    push(a*b);
	}else{
	    push(atoi(s));
	}
    }
    printf("%d\n",pop());

    return 0;
}

Measured memory_bytes: 548
import sys
from sys import stdin
H, W = [int(_) for _ in stdin.readline().rstrip().split()]
data = [list(stdin.readline().rstrip()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if data[i][j] == '#':
            if i==0:
                if j==0:
                    if data[i][j+1] == '.' and data[i+1][j] == '.':
                        print('No')
                        sys.exit()
                elif j==W-1:
                    if data[i][j-1] == '.' and data[i+1][j] == '.':
                        print('No')
                        sys.exit()
                else:
                    if data[i][j+1] == '.' and data[i][j-1] == '.' and data[i+1][j] == '.':
                        print('No')
                        sys.exit()
            elif i==H-1:
                if j==0:
                    if data[i][j+1] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
                elif j==W-1:
                    if data[i][j-1] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
                else:
                    if data[i][j+1] == '.' and data[i][j-1] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
            else:
                if j==0:
                    if data[i][j+1] == '.' and data[i+1][j] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
                elif j==W-1:
                    if data[i+1][j] == '.' and data[i][j-1] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
                else:
                    if data[i][j+1] == '.' and data[i][j-1] == '.' and data[i-1][j] == '.' and data[i+1][j] == '.':
                        print('No')
                        sys.exit()
print('Yes')


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

int n;
double a[1000000], ans, whole, above, bottom;

int main(void){
    // Here your code !
    scanf("%d", &n);
    whole = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%lf", &a[i]);
      whole += a[i];
    }
    if (n == 2) {
      ans = a[0] - a[1];
      printf("%d\n", (int)abs(ans));
    }
    else{
      ans = 2147483647;
      above = 0; bottom = 0;
      for (int i = 0; i < n; ++i){
        if (i == (n - 1)) break;
        above += a[i];
        bottom = whole - above;
        ans = min(abs(above - bottom), ans);
      }
      printf("%d\n", (int)ans);
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    static int h;
    static int w;
    static int dp[][];
    static Scanner sc;

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        h = sc.nextInt();
        w = sc.nextInt();
        sc.nextLine();
        dp = new int[h][w];
        ArrayDeque<Point> p = new ArrayDeque<>();
        for (int i = 0; i < h; i++) {
            String tmp = sc.nextLine();
            for (int j = 0; j < w; j++) {
                char s = tmp.charAt(j);
                if(s == '#') {
                    dp[i][j] = 0;
                    p.add(new Point(i, j));
                }
                else {
                    dp[i][j] = -1;
                }
            }
        }
        while(!p.isEmpty()) {
            Point n = p.poll();
            if(n.x != 0) {
                if(dp[n.x-1][n.y] == -1) {
                    p.add(new Point(n.x-1, n.y));
                    dp[n.x-1][n.y] = dp[n.x][n.y] + 1;
                }
            }
            if(n.x < h-1) {
                if(dp[n.x+1][n.y] == -1) {
                    p.add(new Point(n.x+1, n.y));
                    dp[n.x+1][n.y] = dp[n.x][n.y] + 1;
                }
            }
            if(n.y != 0) {
                if(dp[n.x][n.y-1] == -1) {
                    p.add(new Point(n.x, n.y-1));
                    dp[n.x][n.y-1] = dp[n.x][n.y] + 1;
                }
            }
            if(n.y < w-1) {
                if(dp[n.x][n.y+1] == -1) {
                    p.add(new Point(n.x, n.y+1));
                    dp[n.x][n.y+1] = dp[n.x][n.y] + 1;
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                ans = Math.max(ans, dp[i][j]);
            }
        }
        System.out.println(ans);

    }
    static class Point {
        int x;
        int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Point point = (Point) o;
            return x == point.x &&
                    y == point.y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }
    }
}



Measured memory_bytes: 67316
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long> A(N);
	for (auto& x : A) cin >> x;
	long long sum = 0;
	for (auto& x : A) sum += x;
	long long r = 1LL<<60;
	long s = 0;
	for (auto& x : A) {
		s += x;
		r = min(r, abs(sum - s - s));
	}
	cout << r << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
#include<utility>
#include<list>
#include<queue>
using namespace std;
using ll = long long;

int main(){
  ll n,x,y;
  cin >> n >> x >> y;
  vector<int> ans(n);
  for(int k=1;k<=n;k++){
    vector<bool> flag(n+2);
    vector<int> dist(n+1);
    for(int i=1;i<=n;i++)  dist[i] = 0;
    flag[0] = true;
    flag[n+1] = true;
    for(int i=1;i<=n;i++) flag[i]=false;
    flag[k] = true;  
    queue<int> q;
    q.push(k);
    while(1){
      int i = q.front();
      q.pop();

      if(flag[i-1] == false){
        flag[i-1] = true;
        dist[i-1] = dist[i]+1;
        q.push(i-1);
      }  
      if(flag[i+1] == false){
        flag[i+1] = true;
        dist[i+1] = dist[i]+1;
        q.push(i+1);
      }
      if(i==x&&flag[y] == false){
        flag[y] = true;
        dist[y] = dist[i]+1;
        q.push(y);
      }
      if(i==y&&flag[x] == false){
        flag[x] = true;
        dist[x] = dist[i]+1;
        q.push(x);
      }
      if(q.empty()) break;
    }
    for(int i=1;i<=n;i++){
      ans[dist[i]]++;
    }
  }
  for(int i=1;i<=n-1;i++) cout << ans[i]/2 << endl;
  return 0;
}

Measured memory_bytes: 256
n = input()
a = ((len(n) - 1)//2)
b = ((len(n) + 3)//2)-1
if n == n[::-1]:
    if n[:a] == n[-a::]:
        if n[b:] == n[:-b]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3060
(defun takoyaki (n a)
  (let* ((ret 0))
    (loop :for i :from 0 :below (- n 1) 
          collect (loop :for j :from (+ i 1) :below n
                        do (setq ret (+ ret (* (aref a i) (aref a j))))))
    ret))
  
(defun create-data ()
  (let* ((n (read))
         (a (make-array `(,n))))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (values n a)))

(multiple-value-bind (n a) (create-data)
  (format t "~A~%" (takoyaki n a)))
 

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

int main() {
	int a, b, c, d, l, r;
	cin >> a >> b >> c >> d;
	l = a + b;
	r = c + d;
	if (l < r) {
		cout << "Right" << endl;
	}else if(l > r) {
		cout << "Left";
	}
	else {
		cout << "Balanced";
	}
	return 0;
}

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

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> x(n),y(n);
    set<int> xs,ys;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        xs.insert(x[i]);
        ys.insert(y[i]);
    }
    xs.insert(-1e9-1),ys.insert(-1e9-1);
    xs.insert(1e9+1),ys.insert(1e9+1);
    map<int,int> dicx;
    map<int,int> dicy;
    int index=0;
    for(auto it=xs.begin();it!=xs.end();it++){
    
        dicx[*it]=index;
        index++;
    }
    index=0;
    for(auto it=ys.begin();it!=ys.end();it++){
        dicy[*it]=index;
        index++;
    }
     
    vector<vector<int>> field(xs.size(),vector<int>(ys.size(),0));
    for(int i=0;i<n;i++){
        field[dicx[x[i]]][dicy[y[i]]]++;
    }
    vector<vector<int>> sum(xs.size(),vector<int>(ys.size(),0));
    for(int i=1;i<xs.size();i++){
        for(int j=1;j<ys.size();j++){
            sum[i][j]=field[i][j]+sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1];
        }
    }

    for(int i=0;i<m;i++){
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        swap(x1,x2);
        swap(y1,y2);
        auto it=xs.upper_bound(x1);
        it--;
        x1=*it;
        it=ys.upper_bound(y1);
        it--;
        y1=*it;
        it=xs.lower_bound(x2);
        it--;
        x2=*it;
        it=ys.lower_bound(y2);
        it--;
        y2=*it;
        cout<<sum[dicx[x1]][dicy[y1]]-sum[dicx[x1]][dicy[y2]]-sum[dicx[x2]][dicy[y1]]+sum[dicx[x2]][dicy[y2]]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 199560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
void solve(){
    double r;
    cin >> r;
    cout << r*r;
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    while(t--) solve();
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr LL kInf = 1e18;
typedef pair<LL, pair<int, LL>> P;  // dist, id, coin
struct Edge {
  int to;
  LL coin;
  LL dist;
  Edge(int v, LL a, LL b) : to(v), coin(a), dist(b) {}
};

vector<vector<LL>> dijkstra(const pair<int, LL>& s, const vector<vector<Edge>>& G, int max_coin) {
  vector<vector<LL>> d(G.size(), vector<LL>(max_coin+1, kInf));
  priority_queue<P, vector<P>, greater<P>> que;

  d[s.first][s.second] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    auto p = que.top(); que.pop();
    LL dist = p.first;
    auto [v, c] = p.second;
//    cout << v + 1 << "," << c << ":" << dist << endl;

    if (d[v][c] < dist) continue;
    for (const auto& e : G[v]) {
      LL next_coin = min<LL>(c - e.coin, max_coin);
      if (next_coin < 0) continue;
//      cout << "check: " << e.to + 1 << "," << next_coin << "," << d[e.to][next_coin] << "v.s." << d[v][c] + e.dist << endl;

      if (d[e.to][next_coin] > d[v][c] + e.dist) {
        d[e.to][next_coin] = d[v][c] + e.dist;
        que.push(P(d[e.to][next_coin], {e.to, next_coin}));
//        cout << "push: " << e.to + 1 << "," << next_coin << endl;
      }
    }
//    cout << "----------" << endl;
  }

  return d;
}

int main() {
  int N, M, S; cin >> N >> M >> S;
  vector<vector<Edge>> G(N);
  int Amax = 0;
  for (int i = 0; i < M; ++i) {
    int u, v, a, b; cin >> u >> v >> a >> b;
    --u; --v;
    G[u].push_back(Edge(v, a, b));
    G[v].push_back(Edge(u, a, b));
    Amax = max(Amax, a);
  }
  for (int i = 0; i < N; ++i) {
    int c, d; cin >> c >> d;
    G[i].push_back(Edge(i, -c, d));
  }


  int max_coin = Amax * (N-1);
  int first_coin = min(S, max_coin);
  auto d = dijkstra({0, first_coin}, G, max_coin);

  for (int i = 1; i < N; ++i) {
    LL min_dist = 1e18;
    for (LL dist : d[i]) min_dist = min(min_dist, dist);
    cout << min_dist << endl;
  }
}


Measured memory_bytes: 7292
#include <iostream>
#include <vector>

using namespace std;

int main(){
   
    int a,b,c;
    
    cin >> a >> b >> c;
    
    int counter = 0;
    
    for (int d = a; d < b + 1; ++d) {
        if(c % d == 0){
            counter++;
        }
    }
    
    cout << counter << endl;
    
    return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    string S;
    cin >> N >> S;

    int ans = 0;

    for(int i = 1; i < N; i++) {
        vector<bool> X(26);
        vector<bool> Y(26);

        for(int j = 0; j < i; j++) {
            X[S[j] - 'a'] = true;
        }

        for(int j = i; j < N; j++) {
            Y[S[j] - 'a'] = true;
        }

        int count = 0;

        for(int j = 0; j < 26; j++) {
            if(X[j] && Y[j]) count++;
        }

        ans = max(ans, count);
    }

    cout << ans << endl;
}

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

#define int long long

using namespace std;

int a[100001];
int b[100001];

 main () {
	int n, ans = 0;
	cin >> n;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i] >> b[i];
	}
	reverse (a + 1, a + n + 1);
	reverse (b + 1, b + n + 1);
	for (int i = 1;i <= n;i ++) {
		int x = a[i], y = b[i];
		x += ans;
		if (x % y == 0) continue;
		int v = (x / y + 1) * y - x;
		ans += v;
	}
	cout << ans;
    return 0;           		
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int ll;
const long long int n=(int)1e6 + 77;
int main()
{
    int i,x,p=0;
    for(i=0;i<5;i++)
    {
        cin>>x;
        if(x==0)
            p=i+1;
    }
    cout<<p<<"\n";
    cerr << "\nTime ela psed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(){
  int a[3];
  int b;
  int c;
  scanf("%d",&a[0]);
  scanf("%d",&a[1]);
  b = a[0]/(2*a[1]+1);
  c = a[0]%(2*a[1]+1);
  if(c == 0){
    printf("%d",b);
  }else{
    printf("%d",b+1);
  }
}

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

int main(void){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    const int dx=tx-sx,dy=ty-sy;

    // Path 1
    cout << string(dy,'U') << string(dx,'R');
    
    // Path 2
    cout << string(dy,'D') << string(dx,'L');
        
    // Path 3
    cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';
    
    // Path 4
    cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U';
        
    // EndLine
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <ctime>
using namespace std;

long long N, M, A[200009], B[200009], C[200009], dist[200009];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i] >> C[i];
	}
	int ti = clock(); dist[1] = 0; for (int i = 2; i <= N; i++) dist[i] = -(1LL << 60);
	long long rem = 0, ans = 0;

	while (clock() - ti <= 3 * CLOCKS_PER_SEC / 2) {
		for (int i = 1; i <= M; i++) {
			dist[B[i]] = max(dist[B[i]], dist[A[i]] + C[i]);
		}
		rem++;
		if (rem == 5 * N) ans = dist[N];
	}
	if (ans != dist[N]) cout << "inf" << endl;
	else cout << dist[N] << endl;
	return 0;
}

Measured memory_bytes: 4352
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()

print((N)*(N-1)//2+M*(M-1)//2)

Measured memory_bytes: 5740
ans=[]
while True:
    a,b=map(int,raw_input().split())
    if (a,b)==(0,0):
        break
    t=[y for y in xrange(a,b+1) if (y%4==0 and not y%100==0) or y%400==0]
    if not t:
        ans.append("NA")
    else:
        ans.append("\n".join(map(str,t)))
print "\n\n".join(ans).strip()

Measured memory_bytes: 4268
from fractions import gcd

V = 1003
G = []
visited = []
match = []

def add_edge(u,v):
    G[u].append(v)
    G[v].append(u)

def dfs(v):
    visited[v] = True
    for u in G[v]:
        w = match[u]
        if w < 0 or not visited[w] and dfs(w):
            match[v] = u
            match[u] = v
            return True

def bipartite_matching():
    global match,visited
    res = 0
    match = [-1]*V
    for v in xrange(V):
        if match[v] < 0:
            visited = [False]*V
            if dfs(v):
                res += 1
    return res

while True:
    m,n = map(int,raw_input().split())
    if (m,n) == (0,0):
        break
    V = m+n+2
    G = [[] for _ in xrange(V)]
    visited = [True] * V
    data = []
    while len(data) < n+m:
        data += map(int,raw_input().split())
    blue = data[:m]
    red = data[m:]
    for i,b in enumerate(blue):
        for j,r in enumerate(red,m):
            if gcd(b,r) != 1:
                add_edge(i,j)
    print bipartite_matching()

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

using ll=long long;
const int INF=1e9+7;

int main() {
    int N,i,c=0,m=INF,mi=-1;
    ll r=0;
    cin >> N;
    vector<int> A(N);

    for(i=0; i<N; i++) {
        cin >> A.at(i);
        if(A.at(i)<0)
            c++;
        if(abs(A.at(i)) < m) {
            m = abs(A.at(i));
            mi = i;
        }
    }

    if(c%2) {
        for(i=0; i<N; i++) {
            if(i != mi)
                r += abs(A.at(i));
            else
                r -= abs(A.at(i));
        }
    } else {
        for(i=0; i<N; i++)
            r += abs(A.at(i));
    }

    cout << r << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	if (A < C){
		if (B > C){
			cout << "Yes" << endl;
			return 0;
		}
	}
	else if (A > C){
		if (B < C){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
//template
import java.util.*;
import java.util.stream.*;
import java.io.*;
public class Main{
	static BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	
	private static final int HUNDRED = 100;
	public static void main(String[] args) throws IOException{
		
		if(Integer.parseInt(in.readLine())>=30)
			out.append("Yes\n");
		else
			out.append("No\n");
		
		out.flush();
		in.close();
		out.close();
	}
	public static long ans(long a,long b,long x,long y,long n) {
		long diff=Math.min(n, a-x);
		n-=diff;
		a-=diff;
		b=Math.max(y, b-n);
		return a*b;
	}
	public static int mcm(long num1,long num2) {
		int mcm=1;
		int i=2;
		while(i <= num1 || i <= num2)
        {
            if(num1%i==0 || num2%i==0)
            {
            mcm=mcm*i;
            if(num1%i==0) num1=num1/i;
            if(num2%i==0) num2=num2/i;
            }
            else
                i=i+1;               
        }                       
		return mcm;
	}
	public static long MCD(long a, long b) {
	       if(b==0)
	           return a;
	       else
	           return MCD(b, a % b);
	}
	private static int modulo(int S, int N) { return ((S) & (N - 1)); } // returns S % N, where N is a power of 2
	private static int isPowerOfTwo(int S) { return (S & (S - 1)) == 0 ? 1 : 0; }
	private static int[] readInts() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
	}
	private static int readInt() throws IOException {
		return Integer.parseInt(in.readLine());
	}
	private static long[] readLongs() throws IOException {
		return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
	}
	private static long readLong() throws IOException {
		return Long.parseLong(in.readLine());
	}
	 
}


Measured memory_bytes: 32972
#include <stdio.h>



int main(){
  int W,H,j=0;
  int n = 0;
  int d[10000][2];
  while(j == 0){
    scanf("%d %d",&H,&W);
    if(W == 0 && H == 0){
      j = 1;
    }else{
      d[n][0] = H;
      d[n][1] = W;
      n++;
    }
  }
  for(int i = 0;i < n;i++){ //???????????????????????°??????
    for(int q = 0;q < d[i][0];q++){
      for(j = 0;j < d[i][1];j++){
        if(q == 0 || j == 0 || q == d[i][0]-1 || j == d[i][1]-1){
          printf("#");
        }else{
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
set<ll> A;

int main() {
    cin >> N;
    REP(i, N) {
        LCIN(a);
        if(A.find(a) != A.end())
            A.erase(a);
        else
            A.insert(a);
    }
    cout << A.size() << "\n";
}

Measured memory_bytes: 4864
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cassert>
#include<climits>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<bitset>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 12
 
using namespace std;
 
int h,w,sp,sdir;
char G[MAX][MAX];
int dx[] = {+0,+1,+0,-1};
int dy[] = {-1,+0,+1,+0};
int leaf[MAX*MAX];
int lpos[31],lindex;
vector<int> move[31][4];
int bitlist[31];
 
inline int getDir(char c){
  if(c == 'U')return 0;
  if(c == 'R')return 1;
  if(c == 'D')return 2;
  return 3;
}
 
inline char getCDir(int i){
  if(i == 0)return 'U';
  if(i == 1)return 'R';
  if(i == 2)return 'D';
  return 'L';
}
 
void INIT(){
 
  rep(y,h){
    rep(x,w){
      if(G[y][x] == '.')continue;
 
      rep(k,4){
      int nx = x, ny = y;
    while(true){
      nx += dx[k], ny += dy[k];
      if(!( 0 <= nx && nx < w && 0 <= ny && ny < h ))break;
      if(G[ny][nx] != '.'){
        move[leaf[x+y*w]][k].push_back(leaf[nx+ny*w]); 
        bitlist[leaf[x+y*w]] |= (1<<leaf[nx+ny*w]);
      }
    }
      }
    }
  }
 
}
 
bool dfs(int cur,int dir,int used,deque<char>& deq){
  //bitset<10> bt(used);
  //cout << "cur = " << cur << " " << getCDir(dir) << " " << bt << endl;
  if(used == (1<<lindex)-1){
    rep(i,deq.size()){
      cout << getCDir(deq[i]);
    }
    cout << endl;
    return true;
  }
 
  for(int k = -1; k <= 1; k++){
 
    int ndir = ( dir + 4 + k ) % 4;
 
    rep(i,move[cur][ndir].size()){
      int next = move[cur][ndir][i];
      if( (used>>next) & 1 )continue;
      deq.push_back(ndir);
      if(dfs(next,ndir,used|(1<<next),deq)){
    return true;
      }
      deq.pop_back();
      break;
    }
 
  }
  return false;
}
 
void compute(){
  deque<char> deq;
  dfs(leaf[sp],getDir(G[sp/w][sp%w]),(1<<leaf[sp]),deq);
}
 
int main(){
  cin >> h >> w;
  lindex = 0;
  rep(y,h){
    rep(x,w){
      cin >> G[y][x];
      if(G[y][x] != '.' && G[y][x] != 'o'){
    sp = x + y * w;
    lpos[lindex] = x + y * w;
    leaf[x+y*w] = lindex++;
      }
      else if(G[y][x] != '.'){
    lpos[lindex] = x + y * w;
    leaf[x+y*w] = lindex++;
      }
    }
  }
 
  INIT();

  compute();
 
  return 0;
}

Measured memory_bytes: 1220
N, M = map(int, input().split())
X = [int(i) for i in input().split()]
num = []
X.sort()

for i in range(len(X) - 1):
    num.append(abs(X[i] - X[i + 1]))
num.sort(reverse = True)

print(sum(num[N - 1:]))

Measured memory_bytes: 13840
#include<stdio.h>

int main()
{
    int A, B, sum;

    scanf("%d", &A);
    scanf("%d", &B);

    if((A%3==0) || (B%3==0) || (A+B)%3==0){
        printf("Possible");
    }else{
        printf("Impossible");
    }

    return 0;
}

Measured memory_bytes: 128
a=-1,A=65,d;
char
*N="GKSOCNWLDFVTBRXHAJUPEMQI",
*E="PHLTIDOXQAGWECSUMBKVJFNR",
*R="BCDAFGHEJKLINOPMRSTQVWXU",
s[9];
main(c)
{
for(;c-48&&scanf("%s",s);a+=d/4+1)
{
(c=*s)<A?~a&&printf("%d\n",a),a=d=0:0;
d=(c==78?d=N[d]:
c==69?d=E[d]:
c==82?d=R[d]:
c==83?d=N[N[N[d]-A]-A]:
c==87?d=E[E[E[d]-A]-A]:d+A)-A;
d=c==76?d=R[R[R[d]-A]-A]-A:d;
}}

Measured memory_bytes: 0
#include <string>
#include <stack>
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
    string word;
    stack<int> S;
    while(cin >> word){
        if(word == "+"){
            int x = S.top();
            S.pop();
            int y = S.top();
            S.pop();
            S.push(y + x);
        }
        else if(word == "-"){
            int x = S.top();
            S.pop();
            int y = S.top();
            S.pop();
            S.push(y - x);
        }
        else if(word == "*"){
            int x = S.top();
            S.pop();
            int y = S.top();
            S.pop();
            S.push(y * x);
        }
        else{
            int i;
            sscanf(word.c_str(), "%d", &i);
            S.push(i);
        }
    }
    printf("%d\n", S.top());
}

Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, x, k, sum = 0;
	priority_queue<int>q;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> x;
		q.push(x);
	}
	for(int i = 1; i <= k; i++){
		x = q.top();
		sum = sum + x;
		q.pop();
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;


int main() {

    double N, D;
    cin >> N >> D;

    double answer = ceil(N / (2 * D + 1));
    cout << answer << endl;

    return 0;
}

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

int main(){
    int N; cin >> N;
    long ans = 0;
    long max_p = 0;
    for (int i = 0; i < N; i++)
    {
        long  p; cin >> p;
        ans += p;
        max_p = max(max_p, p);
    }
    ans -= max_p/2;

    cout << ans << endl;
    
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int blue = 0;
    int red = 0;
    for(int i = 0; i < N; ++i){
    	if(S[i] == '0') red++;
    	else blue++;
    }
    cout << 2 * min(blue, red) << endl;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

typedef long long ll;
typedef pair<int,int> p;

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

int main(){
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
        return 0;
    }
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef long long ll;
#define loop(i,n) for(int i=0;i<n;i++)
#define INF 10000000000 //10^10
#define PI 3.141592

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

    if(B-A<K*2){
        for(int i=A;i<=B;i++){
            cout << i << endl;
        }
    }else{
        for(int i=A;i<A+K;i++){
            cout << i << endl;
        }
        for(int i=B-K+1;i<=B;i++){
            cout << i << endl;
        }
    }
}


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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    ll s;
    cin >> s;

    ll cnt[10005];
    m0(cnt);
    for(int i = 3; i < 10000; i++) {
        cnt[i] = 1;
    }

    for(ll i = 3; i <= s; i++) {
        for(ll j = 3; j <= s - 3; j++) {
            cnt[i + j] += cnt[i];
            cnt[i + j] = cnt[i + j] % mod;
        }
    }

    cout << cnt[s] << endl;

    return 0;
}

Measured memory_bytes: 3712
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,x,n) for(int i=x;i<n;i++)
#define breps(i,x,n) for(int i=x;i>=n;i--)
#define exrep(x,vec) for(auto&& x : vec);
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

/**
* ------------- ここからコード -------------
*/


int main(void) {

	string N;
	ll ans = 0;

	cin >> N;
	for (int i = 0; i < N.size(); i++) {
		if (N[i] == '1') ans += 1;
		if (N[i] == '2') ans += 2;
		if (N[i] == '3') ans += 3;
		if (N[i] == '4') ans += 4;
		if (N[i] == '5') ans += 5;
		if (N[i] == '6') ans += 6;
		if (N[i] == '7') ans += 7;
		if (N[i] == '8') ans += 8;
		if (N[i] == '9') ans += 9;
		if (N[i] == '0') ans += 0;
	}

	cout << (ans%9==0?"Yes":"No") << endl;
	return 0;
}


Measured memory_bytes: 3716
s = list(input())

div = 10 ** 9 + 7

n = len(s)

all_q = s.count('?')

a0 = 0
a1 = 0
b0 = 0
b1 = 0
b2 = 0
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for x in s:
    if x == 'A':
        a0 += 1
    elif x == 'B':
        b0 += a0
        b1 += a1
    elif x == 'C':
        c0 += b0
        c1 += b1
        c2 += b2
    else:
        c1 += b0
        c2 += b1
        c3 += b2
        b1 += a0
        b2 += a1
        a1 += 1

c = 0
temp = 3 ** all_q
if c3 > 0:
    c += c3 * (temp // 27)
if c2 > 0:
    c += c2 * (temp // 9)
if c1 > 0:
    c += c1 * (temp // 3)
c += c0 * temp

print(c % div)


Measured memory_bytes: 4084
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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


struct Combination {

	vector<ll> fact, rfact;

	Combination(ll sz) : fact(sz + 1), rfact(sz + 1) {

		fact[0] = 1;
		for (ll i = 1; i < fact.size(); i++) {
			fact[i] = fact[i - 1] * i % MOD;
		}
		//逆元
		rfact[sz] = inv(fact[sz]);
		for (ll i = sz - 1; i >= 0; i--) {
			rfact[i] = rfact[i + 1] * (i + 1) % MOD;
		}
	}

	ll inv(ll x) {
		//modpow
		return pow(x, MOD - 2);
	}
	ll pow(ll x, ll n) {
		//累乗
		ll ret = 1;
		while (n > 0) {
			if (n & 1) (ret *= x) %= MOD;
			(x *= x) %= MOD;
			n >>= 1;
		}
		return (ret);
	}
	ll P(ll n, ll r) {
		//順列
		if (r < 0 || n < r) return (0);
		return (fact[n] * rfact[n - r] % MOD);
	}

	ll C(ll p, ll q) {
		//組み合わせ
		if (q < 0 || p < q) return (0);
		return (fact[p] * rfact[q] % MOD * rfact[p - q] % MOD);
	}

	ll H(ll n, ll r) {
		//重複組み合わせ
		if (n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};


/******************************************************************************************/



int main() {

	int n, k;
	while (cin >> n >> k, n|k) {

		vector<string> a(n);
		set<string> st;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}

		sort(a.begin(), a.end());


		do {

			string tmp;
			for (int i = 0; i < k; i++)
			{
				tmp += a[i];
			}
			st.insert(tmp);
		} while (next_permutation(a.begin(), a.end()));

		cout << st.size() << endl;
		st.clear();
		a.shrink_to_fit();


	}



	return 0;
}



Measured memory_bytes: 3320