akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

int dp[1000], w[1000], v[1000];

int main(){
    int W;
    int N;
    int c = 1;

    while(cin >> W, W != 0){
        fill(dp, dp+W+1, 0);
        cin >> N;
        for(int i=0; i<N; i++){
            scanf("%d,%d", &v[i], &w[i]);
        }

        for(int i=0; i<N; i++){
            for(int j=W; j>=0; j--){
                if(j+w[i] <= W){ //ibvUbNÉiÔÚÌi¨ªüêçêé
                    dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
                    /* dp[j+w[i]] Íj+w[i]ÜÅÌd³Åìêé¿lÌ(bè)Åål
                     * dp[j]+v[i] ÍjÜÅÌd³Åìêé¿lÌÅålÆiÔÚÌàÌð«µ½Ì
                     * ¿lðvµ½àÌ
                     * å«¢ûªj+w[i]ÜÅÌå«³Åìêé¿lÌbèÅålÉÈé
                     */
                }
            }
        }

        int max_value = 0;
        for(int i=0; i<=W; i++){
            if(dp[i] > dp[max_value]){
                max_value = i;
            }
        }

        cout << "Case " << c << ":" << endl;
        cout << dp[max_value] << endl;
        cout << max_value << endl;

        c++;
    }
    return 0;
}

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

class Program
{
    static void Main()
    {
        var mb = new ModBinom(2000);
        var NK = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NK[0];
        var K = NK[1];
        for (int i = 1; i <= K; i++)
        {
            WriteLine(mb.Binom(K - 1, i - 1) * mb.Binom(N - K + 1, i) % ((int)1e9 + 7));
        }
    }
}


class ModBinom
{
    long[] fac;
    long[] finv;
    int mod;

    public ModBinom(int N, int p = (int)1e9 + 7)//N < p  O(N)
    {
        N++;

        fac = new long[N];
        long[] inv = new long[N];
        finv = new long[N];

        fac[0] = fac[1] = 1;
        inv[1] = 1;
        finv[0] = finv[1] = 1;

        for (int i = 2; i < fac.Length; i++)
        {
            fac[i] = fac[i - 1] * i % p;
            inv[i] = p - inv[p % i] * (p / i) % p;
            finv[i] = finv[i - 1] * inv[i] % p;
        }

        mod = p;
    }

    public long Binom(int n, int k)// O(1)
    {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * finv[k] % mod * finv[n - k] % mod;
    }
}


Measured memory_bytes: 13340
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define y1 Emilia
#define forit(s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)


#define N 400400
#define dracarys ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

int n;
map<pair<int, int>, int> id;
int x[55], y[55], u[55];

void dfs(int v, int p, int q){
    int xx = x[v], yy = y[v];
    u[v] = 1;
    int nx1 = xx + p, ny1 = yy + q;
    int nx2 = xx - p, ny2 = yy - q;
    if(id.count(make_pair(nx1, ny1))){
        if(!u[id[make_pair(nx1, ny1)]] )
              dfs(id[make_pair(nx1, ny1)], p, q);
    }
    if(id.count(make_pair(nx2, ny2))){
        if(!u[id[make_pair(nx2, ny2)]] )
            dfs(id[make_pair(nx2, ny2)], p, q);
    }
}
int main(){
    dracarys
    cin >> n;
    if(n == 1){
        cout << 1 << "\n";
        return 0;
    }
    int ans = n;
    for(int i = 1; i <= n; ++i){
        cin >> x[i] >> y[i];
        id[make_pair(x[i], y[i])] = i;
    }
    
    for(int i = 1; i <= n; ++i){
        for(int j = i + 1; j <= n; ++j){
            
            for(int z = 1; z <= n; ++z) u[z] = 0;
            
            int p = x[i] - x[j], q = y[i] - y[j];
            int res = 0;
            for(int f = 1; f <= n; ++f){
                if(u[f] == 1) continue;
                u[f] = 1;
                ++res;
                dfs(f, p, q);
            }
            ans = min(ans, res);
        }
    }
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,a[2222],res=0,l;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int m=max(a[i],a[j]);
      l=a[i]+a[j];
      for(int k=j+1;k<n;k++){
        if(l+a[k]>max(m,a[k])<<1)res++;
      }
    }
  }
  cout<<res;
}


Measured memory_bytes: 384
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if(H == 0 && W == 0) {
				break;
			}
			for(int i = 0; i < H; ++i) {
				for(int j = 0; j < W; ++j) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 34728
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    long long N;
    cin >> N;
    cout << N*(N-1)/2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int top=0;
int S[101];
void push(int x){
  top++;
  S[top]=x;
}
int pop(){
  top--;
  return S[top+1];
}
int main(){
  char a[100];
  int t,s;
    while(scanf("%s",&a)!=EOF){
      if(a[0]=='+') push(pop()+pop());
      else if(a[0]=='-'){
	t=pop();
	s=pop();
	push(s-t);
      }
      else if(a[0]=='*') push(pop()*pop());

	      else push(atoi(a));
    }     
  printf("%d\n",pop());
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using Int = int64_t;
const Int inf = 1LL << 53;

int main() {
   for(;;) {
      Int n, m;
      std::cin >> n >> m;
      if( n == 0 && m == 0 ) {
         break;
      }
      auto xss = std::vector<std::string>(n);
      for(Int i = 0; i < n; ++i) {
         std::string ss;
         std::cin >> ss;
         xss[i] = ss;
      }
      if( n <= 20 ) {
         Int res = 0;
         for(Int i = 0; i < (1<<n); ++i) {
            std::string ss(m, '0');
            Int num = 0;
            for(Int k = 0; k < n; ++k) {
               if( (i & (1 << k)) != 0 ) {
                  num += 1;
                  for(Int j = 0; j < m; ++j) {
                     ss[j] = ss[j] == xss[k][j] ? '0' : '1';
                  }
               }
            }
            bool valid = true;
            for(Int j = 0; j < m; ++j) {
               if( ss[j] != '0' ) {
                  valid = false;
               }
            }
            if( valid ) {
               res = std::max(res, num);
            }
         }
         std::cout << res << std::endl;
      }
      else {
         auto ys = std::vector<Int>(n);
         for(Int i = 0; i < n; ++i) {
            Int t = 0;
            for(Int k = 0; k < m; ++k) {
               if( xss[i][k] == '1' ) {
                  t |= 1 << k;
               }
            }
            ys[i] = t;
         }
         std::vector<Int> dp(1<<m, -inf);
         std::vector<Int> dp2(1<<m, -inf);
         dp[0] = 0;
         for(Int i = 0; i < n; ++i) {
            for(Int k = 0; k < 1<<m; ++k) {
               dp2[k] = std::max(dp[k], dp[k^ys[i]]+1);
            }
            std::swap(dp, dp2);
         }
         std::cout << dp[0] << std::endl;
      }
   }
}



Measured memory_bytes: 137992
import java.util.Scanner;

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

        Double N = sc.nextDouble();
        Double D = sc.nextDouble();
        int ans = (int)Math.ceil(N / (2 * D + 1));
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 25044
#include <stdio.h>

int main(){
    int a, b, c, t;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a > b){
        t = a;
        a = b;
        b = t;
    }
    
    if(b > c){
        t = b;
        b = c;
        c = t;
    }
    
    if(a > b){
        t = a;
        a = b;
        b = t;
    }
    
    printf("%d %d %d\n", a, b, c);
    
    return 0;
}


Measured memory_bytes: 2104
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	var ans float64
	for i := 0; i < n; i++ {
		var a float64
		var b string
		fmt.Scan(&a, &b)
		if b == "JPY" {
			ans += a
		} else {
			ans += a * 380000
		}
	}
	fmt.Println(ans) // output for debug
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
 
int main(void){
  int i,n = 0;
  char w[11], t[1001];
 
  scanf("%s", w);
 
  do{
    scanf("%s",t);
    if(!strcmp(t,"END_OF_TEXT")) break;
      for(i=0;t[i]!='\0';i++)
        if(t[i]<91) t[i] += 32;
    if( !strcmp(w,t) ) n++;
  }while(1);
 
  printf("%d\n",n);
 
  return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
ll gcd(ll, ll);
//
int main(){
    ll a, b;
    cin >> a >> b;
    ll c = gcd(a, b);
    int ans = 0;
    for(int i = 2; i <= sqrt(c); i++){
        if(c % i == 0){
            ++ans;
            while(!(c % i)) c /= i;
        }
    }
    if(c != 1) ans++;
    cout << ans + 1;
}
/*⠀⠀⠀⠀⠀⢀⣀⣀⣀    
⠀⠀⠀⠰⡿⠿⠛⠛⠻⠿⣷
⠀⠀⠀⠀⠀⠀⣀⣄⡀⠀⠀⠀⠀⢀⣀⣀⣤⣄⣀⡀
⠀⠀⠀⠀⠀⢸⣿⣿⣷⠀⠀⠀⠀⠛⠛⣿⣿⣿⡛⠿⠷
⠀⠀⠀⠀⠀⠘⠿⠿⠋⠀⠀⠀⠀⠀⠀⣿⣿⣿⠇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠁

⠀⠀⠀⠀⣿⣷⣄⠀⢶⣶⣷⣶⣶⣤⣀
⠀⠀⠀⠀⣿⣿⣿⠀⠀⠀⠀⠀⠈⠙⠻⠗
⠀⠀⠀⣰⣿⣿⣿⠀⠀⠀⠀⢀⣀⣠⣤⣴⣶⡄
⠀⣠⣾⣿⣿⣿⣥⣶⣶⣿⣿⣿⣿⣿⠿⠿⠛⠃
⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄
⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡁
⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁
⠀⠀⠛⢿⣿⣿⣿⣿⣿⣿⡿⠟
⠀⠀⠀⠀⠀⠉⠉⠉
*/

//library//
ll mod_fact(ll a, ll mod){
    ll ans = 1;
    while(a > 1){
        ans = ans * a % mod;
        a--;
    }
    return ans; 
}
ll mod_pow(ll a, ll b, ll mod){
    ll ans = 1;
    while(b > 0){
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod - 2, mod);
}
ll gcd(ll a, ll b){
    while(a % b){
        return gcd(b, a % b);
    }
    return b;
}
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int n = Integer.parseInt(first[0]);
        int m = Integer.parseInt(first[1]);
        UnionFindTree uft = new UnionFindTree(n);
        for (int i = 0; i < m; i++) {
            String[] line = br.readLine().split(" ", 3);
            int a = Integer.parseInt(line[0]) - 1;
            int b = Integer.parseInt(line[1]) - 1;
            uft.unite(a, b);
        }
        System.out.println(uft.getCount());
    }
    
    static class UnionFindTree {
        int[] parents;

        public UnionFindTree(int size) {
            parents = new int[size];
            for (int i = 0; i < size; i++) {
                parents[i] = i;
            }
        }
        
        public int find(int x) {
            if (parents[x] == x) {
                return x;
            } else {
                return parents[x] = find(parents[x]);
            }
        }
        
        public void unite(int x, int y) {
            int xx = find(x);
            int yy = find(y);
            if (xx == yy) {
                return;
            } 
            parents[xx] = yy;
        }
        
        public int getCount() {
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < parents.length; i++) {
                set.add(find(i));
            }
            return set.size();
        }
    }
}

Measured memory_bytes: 47240
/*
    Problem 17
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_13_A
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 8;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class Chess {
public:
    int boardsize;
    vector<bool> row, col, rObl, lObl;
    vector<vector<bool>> Q;
    Chess (int n) : boardsize(n)
    {
        Q.resize(boardsize, vector<bool>(boardsize));
        row.resize(boardsize); col.resize(boardsize);
        rObl.resize(boardsize * 2);
        lObl.resize(boardsize * 2);
    }
    void init() {
        int n; cin >> n;
        for (int i = 0; i < n; i++) {
            int r, c; cin >> r >> c;
            row[r] = true, col[c] = true, rObl[r+c] = true, lObl[r-c+boardsize-1] = true;
            Q[r][c] = true;
        }
    }
    bool checkR(int r) { return row[r]; }
    bool checkQ(int r, int c) {
        if (row[r] || col[c] || rObl[r+c] || lObl[r-c+boardsize-1]) return false;
        return true;
    }
    void putQ(int r, int c) {
        row[r] = true, col[c] = true, rObl[r+c] = true, lObl[r-c+boardsize-1] = true;
        Q[r][c] = true;
    }
    void delQ(int r, int c) {
        row[r] = false, col[c] = false, rObl[r+c] = false, lObl[r-c+boardsize-1] = false;
        Q[r][c] = false;
    }
    void printTable() {
        for (int r = 0; r < boardsize; r++) {
            for (int c = 0; c < boardsize; c++) {
                cout << (Q[r][c] ? 'Q' : '.');
            }
            cout << '\n';
        }
    }
    // dfs & backtrack
    // R = rの中で1つ置くことに成功したら R = r+1に移動
    // if (success) true
    // else false
    bool solve(int r) {
        if (r >= boardsize) { return true; }  // 解けた!
        if (checkR(r)) return solve(r + 1);  // すでに置いてある行はパス
        for (int c = 0; c < boardsize; c++) {
            if (checkQ(r, c)) {  // 置けるかどうかChek
                putQ(r, c);  // 置く
                if (solve(r + 1)) return true;  // r+1で解けるか
                delQ(r, c);  // 解けなければQを取り除く
            }
        }
        return false;
    }
};
/* main */
int main(){
    Chess cs = Chess(MAX);
    cs.init();
    cs.solve(0);
    cs.printTable();
}


Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int h,w,x,y;
int main(){
  cin>>h>>w>>x>>y;
  if(h%x==0&&w%y==0)cout<<"No"<<endl;
  else{
    cout<<"Yes"<<endl;
    if(w%y==0){
      lol(i,h){
	lol(j,w){
	  if(j)cout<<" ";
	  if(i%x==0)cout<<"600";
	  else if(i%x==x-1)cout<<"-601";
	  else cout<<"0";
	}
	cout<<endl;
      }
    }
    else{
      lol(i,h){
	lol(j,w){
	  if(j)cout<<" ";
	  if(j%y==0)cout<<"600";
	  else if(j%y==y-1)cout<<"-601";
	  else cout<<"0";
	}
	cout<<endl;
      }
    }
  }
 return 0; 
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int a[3];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);

    cout << (a[2] == a[0] + a[1] ? "Yes" : "No") << endl;

    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<int> a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];

    vector<P> c;
    REP(i, n){
        c.push_back(make_pair(a[i], 0));
        c.push_back(make_pair(b[i], 1));
    }
    sort(all(c));

    int cnt[2] = {0};
    
    LL ans = 1;
    for(auto x : c){
        if (cnt[x.second xor 1] != 0)
        {
            ans = ans * cnt[x.second xor 1] % MOD;
            cnt[x.second xor 1]--;
        }
        else
        {
            cnt[x.second]++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8048
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

template <typename T>
std::vector<T> eratosthenes(const T upperbound)
{
    std::vector<bool> is_prime(upperbound + 1, true);
    std::vector<T> result;

    for (T val = 2; val * val <= upperbound; val++)
    {
        if (is_prime[val])
        {
            for (T nonprime = val * val; nonprime <= upperbound; nonprime += val)
            {
                is_prime[nonprime] = false;
            }
        }
    }
    for (T val = 2; val <= upperbound; val++)
    {
        if (is_prime[val])
        {
            result.push_back(val);
        }
    }
    return result;
}

int main()
{
    int n;
    cin >> n;
    auto primes = eratosthenes<int>(55555);

    vector<vector<int>> mod5(5);

    for (auto p : primes)
    {
        mod5[p % 5].push_back(p);
    }
    for (int i = 1; i <= 5; i++)
    {
        if (mod5[i].size() >= n)
        {
            for (int j = 0; j < n; j++)
            {
                if (j > 0)
                {
                    cout << " ";
                }
                cout << mod5[i][j];
            }
            cout << endl;
            break;
        }
    }
}

Measured memory_bytes: 384
import math

def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b
M, N = getMN()

yakusuu = []
for i in range(1,int(math.sqrt(N))+2):
    if N % i == 0:
        yakusuu.append(i)
        yakusuu.append(N//i)

yakusuu = (sorted(yakusuu))
for y in yakusuu[::-1]:
    #print(y)
    if y * M <= N:
        print(y)
        break


Measured memory_bytes: 3188
while True:
    try:
        a,b,c,d,e,f=[int(i) for i in input().split()]
        x=(c*e-f*b)/(a*e-b*d)
        y=(a*f-d*c)/(a*e-b*d)
        if abs(x)<1e-4:
            x=0.0
        if abs(y)<1e-4:
            y=0.0
        print("{:.3f} {:.3f}".format(x,y))
    except:
        break


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n, 0);
    vector<vector<int>> to(n);
    rep(i, m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        to[x].push_back(y);
        cnt[y]++;
    }
    vector<int> sorted;
    queue<int> que;
    rep(i, n)if(cnt[i] == 0)que.push(i);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        sorted.push_back(v);
        for(int t : to[v]){
            cnt[t]--;
            if(cnt[t] == 0){
                que.push(t);
            }
        }
    }
    vector<int> dp(n, 0);
    rep(i, n){
        for(int t : to[sorted[i]]){
            dp[t] = max(dp[t], dp[sorted[i]] + 1);
        }
    }
    int ans = 0;
    rep(i, n)ans = max(ans, dp[i]);
    cout << ans << endl;
}

Measured memory_bytes: 9808
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,d;
   cin>>n>>d;
   int c=0;
   while(n--)
   {
       long long x,y;
       cin>>x>>y;
       double sum=0;
       sum=sqrt(x*x+y*y);
       if(sum<=d)
       c++;
   }
   cout<<c<<endl;
   return 0;
    
}

Measured memory_bytes: 3516
import sys
from io import StringIO
import unittest
import math

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


def resolve():
    q = int(input())
    lr = [list(map(int, input().split())) for _ in range(q)]

    # 素数のlist
    prime_list = primes(10 ** 5 + 1) # setにしないと、ものすごい遅い

    """
    # 10^5 * 10 ^ 5なので✗
    for l, r in lr:
        tmp = 0
        for i in range(l, r + 1):
            if i in prime_list and (i + 1)/2 in prime_list:
                tmp += 1
        print(tmp)
    """

    cum_2017 = [0, 0]
    # 累積和的に、2017に似た数カウントをする
    tmp = 0
    for i in range(2, 10 ** 5 + 1, 1):
        if i in prime_list and (i + 1) // 2 in prime_list: # (i + 1) // 2 でなく、(i + 1) / 2にすると遅い
            tmp += 1
            cum_2017.append(tmp)
        else:
            cum_2017.append(tmp)

    for l, r in lr:
        print(cum_2017[r] - cum_2017[l - 1])



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1
3 7"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
13 13
7 11
7 11
2017 2017"""
        output = """1
0
0
1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6
1 53
13 91
37 55
19 51
73 91
13 49"""
        output = """4
4
1
1
1
2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 81748
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	vector<int> even, odd;
	for (int i = 1; i <= M; ++i) {
		if (i % 2) odd.push_back(i);
		else even.push_back(i);
	}
	reverse(odd.begin(), odd.end());
	reverse(even.begin(), even.end());
	for (int i = 0; i < odd.size(); ++i) printf("%d %d\n", i + 1, i + odd[i] + 1);
	for (int i = 0; i < even.size(); ++i) printf("%d %d\n", N - i, N - i - even[i]);
}

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

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int mod     = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int a = input() - 1, b = input() - 1;

  cout << a * b << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
		int n;
		cin>>n;
		int a[n],b[n],c[n];
		for(int i=0;i<n;i++)
		{
				cin>>a[i];
				a[i]--;
		}
		for(int i=0;i<n;i++)
		{
				cin>>b[i];
		}
		for(int i=0;i<n-1;i++)
		{
				cin>>c[i];
		}
		int prev=a[0];
		int sat=0;
		sat+=b[prev];
		for(int i=1;i<n;i++)
		{
				sat+=b[a[i]];
				if(prev==a[i]-1)
				{
						sat+=c[prev];
				}
				prev=a[i];
		}
		cout<<sat;
}

Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._
    
    val Array(r, d, x2000) = readLine().split(" ").map(_.toInt)

    val x = new Array[Int](11)
    x(0) = x2000
    (1 to 10) foreach { i =>
      x(i) = r * x(i-1) - d
    }
    x.tail.foreach(println)
  }

}

Measured memory_bytes: 27448
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) throws Exception {

    String S = sc.next();

    SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd");
    Date d = sdFormat.parse(S);

    Date d2 = sdFormat.parse("2019/04/30");

    if (d.compareTo(d2) <= 0) {
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }

  }

}

Measured memory_bytes: 21968
sx, sy, tx, ty = map(int, input().split())
X = ["L", "R"]
Y = ["D", "U"]
if sx == tx or sy == ty:
    if sy == ty:
        X, Y = Y, X
        sy, ty = sx, tx
    dy = abs(ty - sy)
    d = sy < ty
    nd = sy > ty
    ans = Y[d]*(dy+1)+X[0]*2+Y[nd]*(dy+2)+X[1]*2+Y[d]+X[0]+Y[d]*dy+X[1]*2+Y[nd]*dy+X[0]
else:
    dx = abs(tx-sx)
    dy = abs(ty-sy)
    xd = sx < tx
    yd = sy < ty
    ans = Y[yd]*dy+X[xd]*dx+Y[not yd]*dy+X[not xd]*(dx+1)+Y[yd]*(dy+1)+X[xd]*(dx+1)+Y[not yd]+X[xd]+Y[not yd]*(dy+1)+X[not xd]*(dx+1)+Y[yd]
print(ans)

Measured memory_bytes: 3064
class Dice:
    def __init__(self, v1, v2, v3, v4, v5, v6):
        self.faces = [(v1, v6), (v2, v5), (v3, v4)]

    def rotate_left(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(top, rgt, bck, fnt, lft, btm)

    def rotate_right(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(top, lft, fnt, bck, rgt, btm)

    def turn_back(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(fnt, btm, rgt, lft, top, bck)

    def turn_front(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(bck, top, rgt, lft, btm, fnt)

    def turn_right(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(lft, fnt, top, btm, bck, rgt)

    def turn_left(self):
        (top, btm), (fnt, bck), (rgt, lft) = self.faces
        return self.__class__(rgt, fnt, btm, top, bck, lft)

    def __str__(self):
        return "<{}>".format(",".join([str(t) for t in self.faces]))

    def __eq__(self, other):
        def equals(d1, d2):
            return d1.faces == d2.faces

        (top, btm) = self.faces[0]
        if (top, btm) in other.faces:
            return (equals(self, other)
                    or equals(self.rotate_right(), other)
                    or equals(self.rotate_left(), other)
                    or equals(self.turn_right(), other)
                    or equals(self.turn_front(), other)
                    or equals(self.rotate_left().rotate_left(), other)
                    or equals(self.turn_back().rotate_left(), other)
                    or equals(self.turn_front().rotate_right(), other)
                    or equals(self.turn_right().rotate_left(), other)
                    or equals(self.turn_left().rotate_right(), other)
                    or equals(self.turn_right().turn_back().turn_back(),
                              other)
                    or equals(self.turn_front().turn_right().turn_right(),
                              other))
        elif (btm, top) in other.faces:
            return self.turn_front().turn_front() == other
        else:
            return False


def run():
    dice1 = Dice(*[int(i) for i in input().split()])
    dice2 = Dice(*[int(i) for i in input().split()])

    if dice1 == dice2:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    run()



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

using lli=long long;
lli mod=1000000007;

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

  lli dp[100004][4] = {};
  dp[0][0] = 1;

  for(int i = 0; i < S.size(); i++){
    char s = S[i];
    if(s == 'A' || s == '?'){
      (dp[i+1][0] += dp[i][0]) %= mod;
      (dp[i+1][1] += dp[i][1]+dp[i][0]) %= mod;
      (dp[i+1][2] += dp[i][2]) %= mod;
      (dp[i+1][3] += dp[i][3]) %= mod;
    }
    if(s == 'B' || s == '?'){
      (dp[i+1][0] += dp[i][0]) %= mod;
      (dp[i+1][1] += dp[i][1]) %= mod;
      (dp[i+1][2] += dp[i][2]+dp[i][1]) %= mod;
      (dp[i+1][3] += dp[i][3]) %= mod;
    }
    if(s == 'C' || s == '?'){
      (dp[i+1][0] += dp[i][0]) %= mod;
      (dp[i+1][1] += dp[i][1]) %= mod;
      (dp[i+1][2] += dp[i][2]) %= mod;
      (dp[i+1][3] += dp[i][3]+dp[i][2]) %= mod;
    }
  }
  std::cout << dp[S.size()][3] << std::endl;

  return 0;
}



Measured memory_bytes: 3584
#include <stdio.h>
int zeller(int Y,int M,int D){if(++M<4)Y-=1,M+=12;int y=Y/100,z=Y%100;return (5*y+z+y/4+z/4+13*M/5+D-1)%7;}
char *W="sunmontuewedthufrisat";
int main(){
	int n;
	scanf("%d",&n);
	printf("%.*s\n",3,W+zeller(2017,9,n)*3);
}

Measured memory_bytes: 1844
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: u64 = lines.next().unwrap().unwrap().parse().unwrap();
  let mut ans: u64 = 0;
  for i in 1..=n {
    let count = n / i;
    let end = i * count;
    ans += (i + end) * count / 2;
  }
  println!("{}", ans);
}

Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int n,l;
int sum,cnt,dif=INF,ans;
int main(){
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)
		sum+=l+i-1;
	for(int i=1;i<=n;i++){
		cnt=0;
		for(int j=1;j<=n;j++){
			if(j==i) continue;
			cnt+=l+j-1;
		}
		if(abs(cnt-sum)<dif){
			dif=abs(cnt-sum);
			ans=cnt;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    string S;
    cin >> S;
    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S.at(i) == 'R') {
            cnt++;
            ans = max(cnt, ans);
        } else {
            cnt = 0;
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3616
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[0]*m
count=0
for _ in range(n):
  a=list(map(int,input().split()))
  tot=0
  for i in range(m):
    tot+=a[i]*b[i]
  if tot>-c:
    count+=1
print(count)

Measured memory_bytes: 3064
import java.util.Scanner;

/**
 * A - Transfer
 * 容器 1 には水を A ミリリットルまで入れることができ、水が B ミリリットル入っています。
 * 容器 2 には水が C ミリリットル入っています。
 * 容器 2 から容器 1 に入るだけ水を移します。
 * 容器 2 の中には何ミリリットルの水が残るでしょうか。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 1の容器の容量
        int a = sc.nextInt();
        // 1の容器に入っている水の量
        int b = sc.nextInt();
        // 2の容器に入っている水の量
        int c = sc.nextInt();

        int add = a - b;
        if( c >= add ) {
            System.out.println( c - add );
        }
        else {
            System.out.println( 0 );
        }

        sc.close();
    }
}

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

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int h,w;cin>>h>>w;
  vector<string> s(h);
  Inparray(s,h);
  vector<vector<int>> cnt(h,vector<int>(w,0));
  //8譁ｹ蜷題ｪｿ縺ｹ繧・
  const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1},dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

  //s縺ｮ蠎ｧ讓吶↓#縺後≠繧九°
  for(int a=0;a<h;a++){
    for(int b=0;b<w;b++){
      if(s[a][b]=='#'){
        //s[a][b]縺ｮ蜻ｨ霎ｺ繧偵う繝ｳ繧ｯ繝ｪ繝｡繝ｳ繝医☆繧・
        for(int c=0;c<8;c++){
          int nx=a+dx[c],ny=b+dy[c];
          if(nx<0|| nx>=h || ny<0 || ny>=w) continue;
          //蠎ｧ讓吶＞縺ｪ縺・°
          if(s[nx][ny]=='.')cnt[nx][ny]++;
        }
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='.'){
        cout<<cnt[i][j];
      }else{
        cout<<'#';
      }
    }
    cout<<endl;
  }
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++){
      cin >> table.at(i).at(j);
    }
  }

  vector<int> H_, W_;

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(table.at(i).at(j) == '#'){
        H_.push_back(i);
        break;
      }
    }
  }
  for(int i = 0; i < W; i++){
    for(int j = 0; j < H; j++){
      if(table.at(j).at(i) == '#'){
        W_.push_back(i);
        break;
      }
    }
  } 
  
  for(int i : H_){
    for(int j : W_){
      cout << table.at(i).at(j);
    }
    cout << endl;
  }
}



Measured memory_bytes: 256
import java.util.*;

class Main {

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

    while (true) {
      int n = sc.nextInt();
      int l = sc.nextInt();
      int r = sc.nextInt();
      if (n == 0) return;
      int a[] = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = sc.nextInt();

      int count = 0;
      for (int x = l; x <= r; x++) {
        for (int i = 1; i <= n; i++) {
          if (x % a[i-1] == 0) {
            if (i % 2 == 1) {
              count++;
              break;
            }
            else break;
          }
          else if (i == n) {
            if (n % 2 == 0) count++;
          }
        }
      }
      System.out.println(count);
    }
  }
}



Measured memory_bytes: 33208
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func insertionSort(a []int, n int, g int, cnt int) int {
	for i := g; i < n; i++ {
		k := a[i]
		j := i - g
		for ; j >= 0 && k < a[j]; j = j - g {
			a[j+g] = a[j]
			cnt++
		}
		a[j+g] = k
	}
	return cnt
}

func shellSort(a []int, n int) {
	cnt := 0
	s := make([]int, 0, 20)
	for g := 1; g <= n; g = 3*g + 1 {
		s = append(s, g)
	}
	lh := len(s)
	gs := make([]int, lh)
	for i, g := range s {
		gs[lh-i-1] = g
	}
	fmt.Println(len(gs))
	print(gs)

	for _, g := range gs {
		cnt = insertionSort(a, n, g, cnt)
	}
	fmt.Println(cnt)
}

func print(s []int) {
	if len(s) == 1 {
		fmt.Println(s[0])
	} else {
		fmt.Print(s[0], " ")
		print(s[1:])
	}
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	if !s.Scan() {
		log.Fatal("scan error")
	}
	n, _ := strconv.Atoi(s.Text())
	a := make([]int, n)
	for i := 0; s.Scan(); i++ {
		a[i], _ = strconv.Atoi(s.Text())
	}
	if s.Err() != nil {
		log.Fatal(s.Err())
	}

	shellSort(a, n)

	for _, k := range a {
		fmt.Println(k)
	}
}



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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll n;
    ci(n);
  ll ans=1;
  FOR(i,1,n+1){
     ans*=i;
    ans=ans%(1000000000+7);
  }
  co(ans)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int dp[200010][25];
int cnt[200010][25];

signed main()
{
    int n;
    cin >> n;
    vector<int>a(n);
    REP(i, n)
        cin >> a[i];
    //vector dp(n+10, vector(30, 0));
        vector<vector<int>> loc(20, vector<int>());
        for (int i = 0; i < n; i++)
        {
            int x = a[i];
            int c = 0;
            while (x)
            {
                if (x & 1) cnt[i][c] = 1;
            x /= 2;
            c++;
        }
    }
    /*for (int i = 0; i < 20; i++)
    {
        loc[i].push_back(-1);
    }*/

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        int maxn = -1;
        for (int j = 0; j < 20; j++)
        {
            if(cnt[i][j]==0){
                if(loc[j].size()>=2){
                    maxn = max(loc[j][loc[j].size()-2], maxn);
                }
            }
            else{
                if(loc[j].size()>=1){
                    maxn = max(loc[j][loc[j].size() - 1], maxn);
                }
            }
        }
       // cerr <<"maxn"<< maxn << endl;
        ans += i - maxn;

        for (int j = 0; j < 20; j++)
        {
            if (cnt[i][j])
            {
                loc[j].push_back(i);
            }
        }

        //show(loc);
       // cerr << ans << endl;
    }

    cout << ans << endl;
    return 0;
}

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


int main() {
    vector<char> vs(4);
    rep(i,4)cin>>vs[i];
    sort(vs.begin(), vs.end());

    if(vs[0]==vs[1] && vs[2]==vs[3] && vs[0]!=vs[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

#define int ll

//get vector of prime numbers which is lower than or equal n
vector<int> get_primes(int n)
{
    vector<bool> is_prime(n + 1, true);
    vector<int> res;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++)
    {
        if (is_prime[i])
        {
            res.push_back(i);
            for (int j = 2 * i; j < is_prime.size(); j = j + i)
            {
                is_prime[j] = false;
            }
        }
    }
    return res;
}

vector<pair<int, int>> factorize(int n)
{
    vector<pair<int, int>> res;
    for (int i = 2; i * i <= n; i++)
    {
        int tmp = 0;
        while (n % i == 0)
        {
            tmp++;
            n /= i;
        }
        res.push_back(make_pair(i, tmp));
    }
    if (n != 1)
    {
        res.push_back(make_pair(n, 1));
    }
    return res;
}

int mpow(int x, int n)
{
    int res = 1;
    while (n != 0)
    {
        if (n & 1)
            res = res * x % INF;
        x = x * x % INF;
        n = n >> 1;
    }
    return res;
}

//mod frac
vector<int> mfrac;
void set_mfrac(int n)
{
    if (mfrac.size() == 0)
    {
        mfrac.push_back(1);
    }
    for (int i = mfrac.size(); i <= n; i++)
    {
        mfrac.push_back((i * mfrac[i - 1]) % INF);
    }
}

//get nCm mod INF
int mcomb(int n, int m)
{
    if (mfrac.size() <= n)
    {
        set_mfrac(n);
    }
    int res = mfrac[n];
    res = res * mpow(mfrac[m], INF - 2) % INF;
    res = res * mpow(mfrac[n - m], INF - 2) % INF;
    return res;
}

vector<int> get_gcd(int n)
{
    vector<int> res;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if (i * i == n)
            {
                res.push_back(i);
            }
            else
            {
                res.push_back(i);
                res.push_back(n / i);
            }
        }
    }
    return res;
}

signed main()
{
    int N;
    cin >> N;
    vector<int> d;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        d.push_back(tmp);
    }
    sort(d.begin(), d.end(), greater<int>());

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                if (d[j] + d[k] > d[i])
                {
                    ans++;
                }
                else
                {
                    break;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
from collections import Counter

# 最頻値
def mode(list):
    c = Counter(list)
    freq_scores = c.most_common()
    max_count = freq_scores[0][1]
    modes = []
    for num in freq_scores:
        if num[1] == max_count:
            modes.append(num[0])
    return(modes)

def main():
  n = int(input())
  s_list = ["a"] * n
  for i in range(n):
    s_list[i] = input()
  ans_list = mode(s_list)
  ans_list.sort()
  for i in ans_list:
    print(i)

main()

Measured memory_bytes: 55772
n,m=gets.chomp.split(" ").map{|s| s.to_i}
min=0
max=n
for i in 0..m-1
  l,r=gets.chomp.split(" ").map{|s| s.to_i}
  if min<=l
    min=l
  end

  if max>=r
    max=r
  end
end

if max-min+1>0
  puts max-min+1
else
  puts 0
end

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
typedef long long Int;
template<class T> inline T sq(T x){return x*x;}
template<class T> inline void checkmin(T &a,T b){if(b<a)a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a)a=b;}


double dp[100010];
double getP[100010]; // nツ連ツ渉淞つキツづゥツ確ツ猟ヲ
double getP2[100010]; // nツ連ツ渉淞つオツづ+1ツ嘉アツ姪堋づ閉可つッツづゥツ確ツ猟ヲ

double MakeP(int n) {
  double res = 1;
  double p = 1;
  for(int i = 1; i <= n; i++) {
    getP[i] = res;  
    p *= 0.5;
    res *= p;    
    getP2[i] = getP[i] * (1 - p);
  }
  return res;
}

int main() {
  MakeP(100002);
  dp[0] = 0;
  dp[1] = 1;
  
  for(int n = 2; n <= 100000; n++) {
    dp[n] = getP[n] * n;
        
    for(int i = 1; i <= min(n - 1, 50); i++) {
      dp[n] += getP2[i] * ( i + dp[n - i - 1] );
    }
  }
  
  for(int N; cin >> N, N; ) {
    printf("%.7f\n", dp[N]);
  }
  return 0;
}

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

#define ll long long

int main() {
    ll sum=0,ans=-1;
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<n-1;i++)
    {
        if(a[i]>=a[i+1])
        {
            sum++;
        }
        else
        {
            ans=max(ans,sum);
            sum=0;
        }
    }

    ans=max(ans,sum);
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
n, k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
accumulation = []
res = 1
k.times do |i|
    next if a[i] == 1
    res += a[i]
end
accumulation << res

(n-k).times do |i|
    if a[i+k] == 1 then
        accumulation << accumulation[i]
        next
    end
    accumulation << (accumulation[i] - a[i]) + a[i+k]
end

(1..(n-k)).each do |i|
    puts accumulation[i-1] < accumulation[i] ? "Yes" : "No"
end

Measured memory_bytes: 37368
#include<stdio.h>
int main()
{
	int n,d;
	while(~scanf("%d%d",&n,&d))
	{
	int sum;
	sum=n/(2*d+1);
	if(n%(2*d+1)==0)
	printf("%d\n",sum);
	else
	printf("%d\n",sum+1);
    }
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main {
	public static void main(String[] args) {
		ArrayList<Integer> A = new ArrayList<>();
		Scanner sc = new Scanner(System.in);
		A.add(sc.nextInt());
		A.add(sc.nextInt());
		A.add(sc.nextInt());
		sc.close();
		Collections.sort(A);
		String ans = (""+A.get(2))+A.get(1);
		System.out.println(Integer.parseInt(ans)+A.get(0));
	}
}


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

typedef long long LL;
#define int LL

const int N=5000;

int n,a[3][2];

void into(){
  scanf("%lld",&n);
  for (int i=0;i<2;++i)
	for (int j=0;j<3;++j)
	  scanf("%lld",&a[j][i]);
}

int dp[N*N+9];

void Get_dp(int opt){
  dp[0]=0;
  for (int i=0;i<3;++i){
	if (a[i][opt^1]<=a[i][opt]) continue;
	for (int j=a[i][opt];j<=n;++j) dp[j]=max(dp[j],dp[j-a[i][opt]]+a[i][opt^1]-a[i][opt]);
  }
  int mx=0;
  for (int i=0;i<=n;++i) mx=max(mx,dp[i]),dp[i]=0;
  n+=mx;
}

void work(){
  Get_dp(0);
  Get_dp(1);
}

void outo(){
  printf("%lld\n",n);
}

#undef int

int main(){
  into();
  work();
  outo();
  return 0;
}

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

int main(){
  while(1){
    int h;
    cin >> h;
    if(h==0) break;

    vector<vector<int> > board(h, vector<int>(5, 0));
    for(int i=0; i<h; i++){
      for(int j=0; j<5; j++){
        cin >> board[i][j];
      }
    }

    int point=0;
    bool flag = true;
    while(flag){
      flag = false;
      //disappear
      for(int i=0; i<h; i++){
        for(int j=0; j<3; j++){
          int col = board[i][j];
          if(col==0) continue;
          if(board[i][j+1]==col && board[i][j+2]==col){
            flag =true;
            point += col*3;
            board[i][j] = board[i][j+1] = board[i][j+2] = 0;
            if(j<=1 && board[i][j+3]==col){
              point += col;
              board[i][j+3] = 0;
            }else{
              continue;
            }
            if(j==0 && board[i][j+4]==col){
              point += col;
              board[i][j+4] = 0;
            }
          }
        }
      }
      
      //fall
      for(int i=0; i<5; i++){
        for(int j=0; j<h; j++){
          for(int k=h-1; k>j; k--){
            if(board[k][i]==0){
              swap(board[k-1][i], board[k][i]);
            }
          }
        }
      }

    }

    cout << point << endl;
  }
  return 0;
}

Measured memory_bytes: 3120