akhauriyash/Code-Regression huggingface dataset:
/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#ifndef H_int_literals
#define H_int_literals

#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

#endif  /* !defined(H_int_literals) */

#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>

class rolling_hash_l61m1 {
public:
  using size_type = size_t;
  using value_type = uintmax_t;

private:
  value_type M_b;
  std::vector<value_type> M_c, M_p;
  static size_type const S_npos = -1;
  static value_type const S_mod = (1_ju << 61) - 1;

  static value_type S_fma(value_type a, value_type b, value_type c) {
    value_type au = a >> 31;
    value_type al = a & ((1u << 31) - 1);
    value_type bu = b >> 31;
    value_type bl = b & ((1u << 31) - 1);

    value_type x = au*bl + al*bu;
    value_type xu = x >> 30;
    value_type xl = x & ((1u << 30) - 1);

    value_type y = ((au*bu) << 1) + (xu + (xl << 31)) + (al*bl);
    value_type yu = y >> 61;
    value_type yl = y & ((1_ju << 61) - 1);

    value_type z = yu + yl + c;
    if (z >= S_mod) z -= S_mod;
    return z;
  }

  void M_build() {
    for (size_type i = 1; i < M_c.size(); ++i)
      M_c[i] = S_fma(M_c[i-1], M_b, M_c[i]);
    M_c.insert(M_c.begin(), 0);

    M_p.assign(M_c.size(), 1);
    for (size_type i = 1; i < M_p.size(); ++i)
      M_p[i] = S_fma(M_p[i-1], M_b, 0);
  }

public:
  rolling_hash_l61m1() = default;

  template <typename InputIt>
  rolling_hash_l61m1(InputIt first, InputIt last, value_type base): M_b(base) {
    assign(first, last);
  }

  template <typename InputIt>
  void assign(InputIt first, InputIt last) {
    M_c.assign(first, last);
    M_build();
  }

  template <typename InputIt>
  void assign(InputIt first, InputIt last, value_type base) {
    M_b = base;
    M_c.assign(first, last);
    M_build();
  }

  value_type substr(size_type pos, size_type len = S_npos) {
    size_type n = M_c.size() - 1;
    if (len == S_npos) len = n - pos;
    size_type endpos = pos + len;
    value_type hr = M_c[endpos];
    value_type hl = M_c[pos];
    value_type hs = hr - S_fma(hl, M_p[len], 0);
    if (hs >= S_mod)  // "negative"
      hs += S_mod;
    return hs;
  }
};

#include <random>
#include <set>

int main() {
  size_t n;
  scanf("%zu", &n);

  char buf[5001];
  scanf("%s", buf);
  std::string s = buf;

  std::random_device rd;
  rolling_hash_l61m1 rh(s.begin(), s.end(), rd());

  for (size_t i = n; i--;) {
    std::set<uintmax_t> seen;
    for (size_t j = i; i+j <= n; ++j) {
      uintmax_t h0 = rh.substr(j-i, i);
      seen.insert(h0);
      uintmax_t h1 = rh.substr(j, i);
      if (seen.count(h1)) return !printf("%zu\n", i);
    }
  }
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y = x;
		if(z->key < x->key ){
			x = x->left;
		}
		else{
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL){
		root = z;
	}
	else{
		if(z->key < y->key ){
			y->left = z;
		}
		else{
			y->right = z;
		}
	}
}

Node * find(Node *u, int k){
	while( u != NIL && k != u->key ){
		if(k < u->key ) u = u->left ;
		else u = u->right ;
	}
	return u;
}

void inorder(Node *u){
	if(u == NIL) return;
	inorder(u->left );
	printf(" %d", u->key );
	inorder(u->right );
}

void preorder(Node *u){
	if(u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left );
	preorder(u->right );
}

int main(){
	int n, i, x;
	string com;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		cin >> com;
		if(com == "insert"){
			scanf("%d", &x);
			insert(x);
		}
		else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;	
}





Measured memory_bytes: 26592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace AGC23
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            var a = ReadLine().Split().Select(long.Parse).ToArray();
            var sum = new long[n + 1];
            sum[0] = 0;
            for (int i = 0; i < n; i++)
            {
                sum[i + 1] = sum[i] + a[i];
            }
            Array.Sort(sum);
            var c = new Dictionary<long, long>();
            for (int i = 1; i < n + 1; i++)
            {
                
                if(sum[i] == sum[i - 1])
                {
                    if (!c.ContainsKey(sum[i])) c[sum[i]] = 1;
                    c[sum[i]] += 1;
                }
            }
            long count = 0;
            foreach(var cc in c)
            {
                count += cc.Value * (cc.Value - 1) / 2;
            }
            WriteLine(count);
        }
    }
}

Measured memory_bytes: 41056
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    set<int> st;
    rep(i,n){
        int a;
        cin>>a;
        st.insert(a);
    }
    cout<<st.size()<<endl;
}


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

 int main() {
     ll N;
     cin >> N;
     vector<ll> Acnt(N);

     rep(i, 0, N) {
       ll tmp;
       cin >> tmp;
       Acnt.at(tmp)++;
     }

     if (N % 2 == 1) {
       bool ok = true;
       if (Acnt.at(0) == 0) ok = false;
       for (int i = 1; i <= N - 1; i++) {
         if (i % 2 == 1 && Acnt.at(i) != 0) ok = false;
         if (i % 2 == 0 && Acnt.at(i) != 2) ok = false;
       }
       if (ok) {
         int ans = 1;
         rep(i, 0, (N - 1) / 2) ans = ans * 2 % MOD;
         cout << ans << endl;
       }
       else cout << 0 << endl;
     }

     else {
       bool ok = true;
       for (int i = 1; i <= N - 1; i++) {
         if (i % 2 == 1 && Acnt.at(i) != 2) ok = false;
         if (i % 2 == 0 && Acnt.at(i) != 0) ok = false;
       }
       if (ok) {
         int ans = 1;
         rep(i, 0, N / 2) ans = ans * 2 % MOD;
         cout << ans << endl;
       }
       else cout << 0 << endl;
     }
 }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  ll h,w;cin >> h >> w;
  if(h%3 == 0 || w%3 == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = INF;
  if(h%2 == 0){
    ll htemp = h/2;
    for(int wtemp = 1;wtemp <= w;wtemp++) ans = min(ans,abs(htemp*ll(wtemp)-h*(w-ll(wtemp))));
  }else{
    ll htemp = h/2+1;
    for(int wtemp = 1;wtemp <= w;wtemp++){
      ll temp = 0;
      temp = max(abs(htemp*ll(wtemp)-h*(w-ll(wtemp))),abs((htemp-1)*ll(wtemp)-h*(w-ll(wtemp))));
      temp = max(temp,ll(wtemp));
      ans = min(ans,temp);
    }
  }
  //cout << ans << endl;

  if(w%2 == 0){
    ll wtemp = w/2;
    for(int htemp = 1;htemp <= h;htemp++) ans = min(ans,abs(wtemp*ll(htemp)-w*(h-ll(htemp))));
  }else{
    ll wtemp = w/2+1;
    for(int htemp = 1;htemp <= h;htemp++){
      ll temp = 0;
      temp = max(abs(wtemp*ll(htemp)-w*(h-ll(htemp))),abs((wtemp-1)*ll(htemp)-w*(h-ll(htemp))));
      temp = max(temp,ll(htemp));
      ans = min(ans,temp);
    }
  }
    ans = min(ans,h);
    ans = min(ans,w);
    cout << ans << endl;
}

Measured memory_bytes: 3556
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<chrono>
#include<random>
#include<cstdio>
#include<set>
#include<map>
#include<numeric>
#define MAX_N 100
#define MAX_M 100
#define INF 10000000
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;


int main(){
    string s;
    cin>>s;
    if(s=="SUN"){
        cout<<7;
        return 0;
    }
    if(s=="SAT"){
        cout<<1;
        return 0;
    }
    if(s=="MON"){
        cout<<6;
        return 0;
    }
    if(s=="TUE"){
        cout<<5;
        return 0;
    }
    if(s=="WED"){
        cout<<4;
        return 0;
    }
    if(s=="THU"){
        cout<<3;
        return 0;
    }
    if(s=="FRI"){
        cout<<2;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B;cin>>A>>B;
  
  vector<int> x(3);
  x[0]=A+B;x[1]=A-B;x[2]=A*B;
  
  sort(x.begin(),x.end());
  
  cout<<x[2]<<endl;
}

Measured memory_bytes: 3596
import scala.io.StdIn
import scala.math._

object Main {

  def convert(c: Char): Boolean = if (c == '1') true else false

  type State = Tuple2[Int, Boolean]

  def main(args: Array[String]): Unit = {
    val s = StdIn.readLine.toList.map(convert)

    val res = s.foldLeft((0, true))((state, b) => if (state._2 ^ b) (state._1 + 1, !state._2) else (state._1, !state._2))

    println(if (res._1 > s.size - res._1) s.size - res._1 else res._1)

  }
}

Measured memory_bytes: 39920
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))



def main():
    count = 0
    A,B,C = inpl()
    K = int(input())
    for i in range(K+1):
        for j in range(K+1-i):
            k = K-i-j
            a = A*(2**i)
            b = B*(2**j)
            c = C*(2**k)
            if a < b < c:
                print('Yes')
                return

    print('No')
    """while True:
        if A < B < C:
            print('Yes')
            return
        if B < A:
            B *= 2
            count += 1
            if count == K and not(A < B < C):
                print('No')
                return
        if C < B:
            C *= 2
            count += 1
            if count == K and not(A < B < C):
                print('No')
                return"""
main()


Measured memory_bytes: 69104
<?php
fscanf(STDIN, "%d %d", $n, $k);

if ($k === 0) {
	echo $n**2, "\n";
	return;
}

$minB = $k + 1;
$count = 0;
for ($b = $minB; $b <= $n; $b++) {
	$m = 0;
	$countA = 0;
	while ($m * $b <= $n) {
		if (($m + 1) * $b <= $n) {
			$countA += $b - $k;
			$m++;
			continue;
		}
		if ($m * $b + $k > $n) {
			$m++;
			continue;
		}

		$plus = $n - ($m * $b + $k) + 1;
		$countA += $plus;
		$m++;
	}
	$count += $countA;
}
echo $count, "\n";

Measured memory_bytes: 4732
N, K = map(int, input().split())
D = list(map(str, input().split()))
for i in range(N, 100000):
    s = list(str(i))
    flg = 0
    for j in s:
        if j in D:
            flg = 1
            break
    if flg == 0:
        print("".join(s))
        break

Measured memory_bytes: 40412
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int n, x[100], y[100];

double minkowski (int p) {
	double ans = 0;
	for (int i=0; i<n; i++) {
		ans += pow(abs(x[i]-y[i]), p);
	}
	return pow(ans, 1.0/p);
}

double minkowski_infinite () {
	double ans = 0;
	for (int i=0; i<n; i++) {
		if (ans < abs(x[i]-y[i])) {
			ans = abs(x[i]-y[i]);
		}
	}
	return ans;
}


int main(int argc, char const* argv[])
{
	cin >> n;
	for (int i=0; i<n; i++) cin >> x[i];
	for (int i=0; i<n; i++) cin >> y[i];

	printf ("%f\n", minkowski(1));
	printf ("%f\n", minkowski(2));
	printf ("%f\n", minkowski(3));
	printf ("%f\n", minkowski_infinite());

	return 0;
}


Measured memory_bytes: 1232
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    long nSum = 0;
    vector<int> iva(100000,0);
    for(int i = 0; i < n; i++){
        int k;
        scanf("%d", &k);
        iva[k]++;
        nSum += (long)k;
    }
  
    int q;
    scanf("%d", &q);
    
    for(int i = 0; i < q; i++){
        long b,c;
        scanf("%ld %ld", &b, &c);
        nSum += (c - b) * (long)iva[b];
        iva[c] += (int)iva[b];
        iva[b] = 0;
        printf("%ld\n", nSum);
    }
  
    return 0;
}


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

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

  int i;

  cin >> i;
  
  float p = static_cast<float>(((i-1)/2)+1)/i;

  cout << p << "\n";

  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c[4][4];
int main()
{
    for(int i=1;i<=3;i++)
        for(int j=1;j<=3;j++)
        scanf("%d",&c[i][j]);
    int a1=0,a2=0,a3=0,b1=0,b2=0,b3=0;
    int ans=0;
    for(a1=0;a1<=c[1][1];a1++)
    {
        b1=c[1][1]-a1;
        b2=c[1][2]-a1;
        b3=c[1][3]-a1;
        a2=c[2][1]-b1;
        if((c[2][2]-b2)!=a2)
            continue;
        if((c[2][3]-b3)!=a2)
            continue;
        a3=c[3][1]-b1;
        if((c[3][2]-b2)!=a3)
            continue;
        if((c[3][3]-b3)!=a3)
            continue;
        ans++;
    }
    if(ans>=1)
        printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

ll get_ll(char* s, int size) {
    char tmp = s[size];
    s[size] = '\0';
    ll res = atoll(s);
    s[size] = tmp;
    return res;
}

int main(){
    string s;
    cin >> s;
    ll ans = 0LL;
    for (int i=0; i<(1<<(s.size()-1)); i++) {
        int bit = i | (1<<(s.size()-1));
        int prev = -1;
        for (int j=0; j<s.size(); j++) {
            if ((bit>>j)&1) {
                ans += get_ll(&s[prev+1], j-prev);
                prev = j;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,x,mod = map(int,input().split())
num = []
ans = cnt = 0
ch = x
while True:
    if ch not in num:
        num.append(ch)
    else:
        st = ch
        break
    ch *= ch
    ch %= mod

index = num.index(st)

if (len(num)-index) != 0:
    rest = (n-index)%(len(num)-index)
    qu = (n-index)//(len(num)-index)
else:
    rest = n
    qu = 0
if n <= index + 1:
    ans = sum(num[:n])
else:
    ans = sum(num[:index]) + sum(num[index:index+rest]) + sum(num[index:])*qu
print(ans)

Measured memory_bytes: 67860
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 3005;
const int mod = 998244353;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int x;
  cin>>x;
  int ret = x / 500 * 1000;
  ret += (x%500/5 * 5);
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int A, B;
  int C, D, E;

  cin >> A >> B;
 
  C = A - 1;
  D = B + C;
  E = B - C;

  while(E <= D)
  {
	cout << E << " "; 
    E++;
  }
   cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static double eps=1.0E-14;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long a =scn.nextLong();
		long b =(long)((eps+scn.nextDouble())*100);
		long c =a*b/100;
		System.out.println(c);

	}

}

Measured memory_bytes: 37508
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//pow(x,n) == x^n
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

int n;
cin >> n;
string s,t;
cin >> s >> t;
rep(i,n) cout << s[i] << t[i];




//////////////////////////////////////////////////////
return 0;}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	bool ok = false;
	vector<int> AA = A;
	do {
		if (A == B) {
			ok = true;
			break;
		}
		res++;
	} while (next_permutation(A.begin(), A.end()));

	if (!ok) {
		A = AA;
		res = 0;
		do {
			if (A == B) {
				ok = true;
				break;
			}
			res++;
		} while (next_permutation(B.begin(), B.end()));
	}
	cout << res << endl;
}

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


int main()
{
    ios_base::sync_with_stdio(false);
    long long int a,b,c,i,j,k,v,n;
    cin>>n;
    vector <long long int> v1;
    vector <long long int>::iterator it;
    k=1;
    c=0;
    for(i=0;i<n;i++)
    {
        cin>>v;
        if(v==k){
        v1.push_back(v);
        k++;
        }
        else
        {
            c++;
        }
    }


    if(v1.size()==0)
        c=-1;

    cout<<c<<"\n";
    return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>
int main()
{
    int a,b,sum;
    char op;
    scanf("%d %c %d",&a,&op,&b);
    if(a>=1&&b>=1)
    {
        if(op=='+')
        {
            sum=a+b;
        printf("%d",sum);
        }
        if(op=='-')
        {
            sum=a-b;
        printf("%d",sum);
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <ctime> 
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define LL long long
#define Rg register
#define RI register int
#define RC register char
#define ed puts("") 
#define pair pair<LL,LL>
#define space putchar(' ') 
#define lson l,mid,rt<<1 
#define rson mid+1,r,rt<<1|1  
using namespace std;   
const LL maxn=250005;  
template <typename tp> inline void read(tp & x) 
{	
    x=0;
    RI f=1; 
    RC c=getchar();  
    while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar(); } 
    while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();} 
 	x*=f;
} 	
    	
template <typename Tp> inline void print(Tp x)  
{			
    if(x<0) x=-x,putchar('-'); 
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

LL s;
LL ss;
LL sss;

int main()
{
	read(s);
	ss=sqrt(s);
	if(ss*ss!=s)
		ss++;
	s=ss*ss-s;
	LL a=sqrt(s);
	LL b;
	for(;a>0;--a)
	{
		if(s%a==0)
		{
			b=s/a;
			break;	
		}
	}
	print(0),space,print(0),space,print(ss),space,print(a),space,print(b),space,print(ss);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using vi  = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> sp;
  rep(i, N) {
    string s;
    int p;
    cin >> s >> p;
    sp.push_back(make_tuple(s, p*-1, i+1));
  }
  sort(sp.begin(), sp.end());
  for (auto x : sp) {
    cout << get<2>(x) << endl;
  }
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char s1[10],s2[10];
    int dec = 0,i,len=0,root=0;;

    cin>>s1>>s2;
    strcat(s1,s2);
   // cout<<s1<<endl;

    len=strlen(s1);
    s1[len]='\0';

    for(i=0; s1[i]!='\0'; i++)
    {
        dec = dec * 10 + ( s1[i] - '0' );
    }
    root= int( sqrt((double) dec));
  //  cout<<dec<<endl;
  //  cout<<sqrtl(double(dec))<<endl;
    if(dec==(root*root)) cout<<"Yes"<<endl;
    else                           cout<<"No"<<endl;
    return 0;
}


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

int main(){
	// sengen
	string s;
	// nyuryoku
	cin >> s;
	map<char,int> mp;
	// keisan
	for(int i=0;i<4;i++){
		mp[s[i]]++;
	}
	// syutsuryoku
	int ok = 1;
	for(auto x:mp){
		if(x.second != 2){
			ok = 0;
		}
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
	int H,W;
	while(1){
		cin>>H>>W;
		for(int i=1;i<=H;i++){
			for(int j=1;j<=W;j++){
				if(i==1||j==1||i==H||j==W){
					cout<<"#";
				}
				else{cout<<".";}
			}cout<<endl;
		}
		if(H==0&&W==0)break;
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3120
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        n: usize,
        c: usize,
        k: i64,
        mut ts: [i64; n],
    }
    ts.sort();
    let mut ans = 0;
    let mut i = 0usize;
    while i < n {
        let psgs = min(c, ts[i..].iter().copied().position(|t| t > ts[i] + k).unwrap_or(n - i));
        i += psgs;
        ans += 1;
    }
    println!("{}", ans);
}


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

long n, a[101010];

int main(){
    cin >> n; for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a+n);
    
    long ans = 0, sum = 0;
    for(int i = 0; i < n; ++i) {
        sum += a[i];
        ++ans;

        if(a[i+1] > sum*2) {
            ans = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define INF 10000000000
#define MOD 1000000007

using namespace std;

int main()
{
    char a, b;
    cin >> a >> b;
    if(a == b) cout << 'H' << endl;
    else cout << 'D' << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll N,p; cin >> N;
  string s;
  map<string, map<ll,ll> > smap;
  for (ll i = 0; i < N; ++i) {
    cin >> s >> p;
    (smap[s])[100-p] = i;
  }
  for (auto smap_itr = smap.begin(); smap_itr != smap.end(); ++smap_itr) {
    map<ll,ll> pmap = smap_itr->second;
    for (auto pmap_itr = pmap.begin(); pmap_itr != pmap.end(); ++pmap_itr)
      cout << pmap_itr->second + 1<< endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;

namespace ALDS1_6_A {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');

            int[] A = new int[n + 1];
            int[] B = new int[n + 1];
            int[] C = new int[10001];
            int max = 0;

            for(int i = 1; i <= n; i++) {
                int temp = int.Parse(input[i - 1]);
                A[i] = temp;
                C[temp]++;
                max = Math.Max(max, temp);
            }

            for(int i = 1; i <= max; i++) {
                C[i] += C[i - 1];
            }

            for(int i = n; i > 0; i--) {
                int temp = A[i];
                B[C[temp]] = temp;
                C[temp]--;
            }

            StringBuilder sb = new StringBuilder();
            foreach (int b in B.Skip(1))
                sb.AppendFormat(" {0}", b);
            Console.WriteLine(sb.ToString().TrimStart());
        }
    }
}

Measured memory_bytes: 231752
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    cout<<max(a*c,max(a*d,max(b*c,b*d)))<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3648
from collections import Counter


N, K = map(int, input().split())
if K > 2 * N:
    print(0)
    exit()
else:
    x0 = N // K
    x2 = (N - K // 2) // K  + 1 if K % 2 == 0 else 0

    ans = 0
    ans += x0 ** 3
    # print(ans)
    ans += x2 ** 3
    print(ans)



Measured memory_bytes: 3316
def main():
    from sys import stdin, setrecursionlimit
    setrecursionlimit(10**6)
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]

    #res = 0
    #a, b, c = map(int, r.split())
    res = sorted(list(r))
    if "".join(res) == 'abc':
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()



Measured memory_bytes: 38384
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<cstdlib>
#include<ctime>
#include<cctype>

using namespace std;

int n, W;
int w[110]; 
int v[110];
long long dp[100010];
int main()
{
	cin >> n >> W;
	for(int i = 1; i <= n; i++)
	{
		cin >> w[i] >> v[i];
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = W; j >= w[i]; j--)
		{
			dp[j] = max(dp[j - w[i]] + v[i], dp[j]);
		}
	}
	long long  ans = 0;
	for(int i = 1; i <= W; i++)
	{
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1000010
#define int long long
#define mxf(x,y) (x>y?x:y)
#define mif(x,y) (x<y?x:y)
#define rep(i,x,y) for(register int i=x;i<=y;++i)
#define dwn(i,x,y) for(register int i=x;i>=y;--i)
using namespace std;
int n,m,aor,bor,ans,num,a[N],aa[N],b[N],bb[N],fa[N],date[N];
inline int read(){
	int fl=1,sum=0;char w=getchar();
	while(w>'9'||w<'0'){if(w=='-')fl=-1;w=getchar();}
	while(w>='0'&&w<='9'){sum=sum*10+w-'0';w=getchar();}
	return fl*sum;
}
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void merge(int x,int y){fa[find(x)]=find(y);}
signed main(){
//	freopen("duliu.in","r",stdin);
//	freopen("duliu.out","w",stdout);
	n=read();
	rep(i,1,n) a[i]=read(),aa[i]=a[i],aor^=a[i];
	rep(i,1,n) b[i]=read(),bb[i]=b[i],bor^=b[i];
	n++;a[n]=aa[n]=aor,b[n]=bb[n]=bor;
    sort(aa+1,aa+n+1);sort(bb+1,bb+n+1);
    rep(i,1,n-1) if(aa[i]!=bb[i]){puts("-1");return 0;}
    rep(i,1,n) if(a[i]!=b[i]||(i==n)){
        date[++num]=a[i];date[++num]=b[i];
        if(i<n) ans++;
    }
    if(!ans){puts("0");return 0;}
    sort(date+1,date+num+1);
    num=unique(date+1,date+num+1)-date-1;
    rep(i,1,num) fa[i]=i;
    rep(i,1,n) if(a[i]!=b[i]){
        a[i]=lower_bound(date+1,date+num+1,a[i])-date,
        b[i]=lower_bound(date+1,date+num+1,b[i])-date;
        merge(a[i],b[i]);
    }
    rep(i,1,num) if(fa[i]==i) ans++;
    printf("%lld",ans-1);
	return 0;
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
const int Maxn=2e5+1;
int a[Maxn],n,qzh[Maxn][21];

bool judge(int l,int r){
	bool f=true;
	for(int i=1;i<=20;i++)
		if(qzh[r][i]-qzh[l-1][i]>1){
			f=false;
			break;
		}
	return f;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=20;j++)
			qzh[i][j]=qzh[i-1][j]+int((a[i]&1<<j-1)>>(j-1));
	
	int r=1;
	long long ans=0;
	for(int i=1;i<=n;i++){
		if(r<i)r=i;
		while(r<=n&&judge(i,r)==true)r++;
		r--;
		//cout<<r<<endl;
		ans+=r-i+1;
	}
	cout<<ans;
} 

Measured memory_bytes: 17408
nb=4
nf=3
nr=10
d = {}
n = int(input())
for i in range(n):
    [b,f,r,v] = map(int, input().split())
    key = "%2d %2d %2d"  % (b,f,r)
    if key in d:
        d[key] += v
    else:
        d[key] = v

for b in range(1,nb+1):
    for f in range(1,nf+1):
        for r in range(1,nr+1):
            key = "%2d %2d %2d" % (b,f,r)
            if key in d:
                print(" "+str(d[key]),end="")
            else:
                print(" "+str(0),end="")
            if r==nr:
                print()
            if r==nr and f==nf and b != nb:
                print('####################')

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	string s;
	cin>>s;
	int w[n];
	int r[n];
	if(s[0]=='W') w[0]=1;
	if(s[n-1]=='R') r[n-1]=1;
	for(int i=1;i<n;i++)
	 {
	 	w[i]=w[i-1];
	 	if(s[i]=='W') w[i]++;
	 }
	for(int i=n-2;i>=0;i--)
	 {
	 	r[i]=r[i+1];
	 	if(s[i]=='R') r[i]++;
	 }
	 int op=INT_MAX;
	 for(int i=0;i<n;i++)
	 {
	 	if(i+1<n) op=min(op,max(w[i],r[i+1]));
	 	else op=min(op,w[i]);
	 }
	 op=min(op,r[0]);
	 cout<<op<<endl;
	return 0;
}

Measured memory_bytes: 5312
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            count += 1
    print(*A)
    print(count)
        


Measured memory_bytes: 5608
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
import std.typecons;

alias Edge = Tuple!(int, "from", int, "to", long, "cost");

Edge[] edges = new Edge[](0);
int[][] ordg;
int[][] revg;
bool[] isOk;
bool[] isRevOk;

void main() {
	int n = read.to!int;
	int m = read.to!int;
	long p = read.to!long;
	ordg = new int[][](n, 0);
	revg = new int[][](n, 0);
	isOk = new bool[](n);
	isRevOk = new bool[](n);
	foreach (i; 0..m) {
		auto f = read.to!int-1;
		auto t = read.to!int-1;
		edges ~= Edge(f, t, - (read.to!long - p));
		ordg[f] ~= t;
		revg[t] ~= f;
	}
	dfs(0);
	rdfs(n-1);
	auto d = new long[](n);
	fill(d, long.max);
	d[0] = 0;
	int step = 0;
	while(true) {
		bool update = false;
		foreach (i; 0..m) {
			if (! (isOk[edges[i].from] && isRevOk[edges[i].from])) continue;
			if (! (isOk[edges[i].to] && isRevOk[edges[i].to])) continue;
			if (d[edges[i].from] != long.max && d[edges[i].from] + edges[i].cost < d[edges[i].to]) {
				update = true;
				d[edges[i].to] = d[edges[i].from] + edges[i].cost;
			}
		}
		step++;
		if (step > n) {
			writeln(-1);
			return;
		}
		if (!update) break;
	}
	auto ret = -d[n-1];
	writeln(max(0, ret));
}

void dfs(int v) {
	if (isOk[v]) return;
	isOk[v] = true;
	foreach (e; ordg[v]) {
		dfs(e);
	}
}

void rdfs(int v) {
	if (isRevOk[v]) return;
	isRevOk[v] = true;
	foreach (e; revg[v]) {
		rdfs(e);
	}
}

string read() {
	static string[] ss;
	while (!ss.length) ss = readln.chomp.split;
	auto res = ss[0];
	ss.popFront;
	return res;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> state;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int ceil(int a,int b){
  // a/bの切り上げを考える
  return (a+b-1)/b;
}


int main(){ 
  int n;
  cin >> n;
  int ans[n];
  rep(i,n)ans[i] = 0;

  for(int x = 1;x < pow(n,0.5);x++){
    for(int y = 1;y < pow(n,0.5);y++){
      for(int z = 1;z < pow(n,0.5);z++){
        int temp = x * x + y * y + z * z + x * y + x * z + y * z;
        if(n >= temp)ans[temp-1]++;
      }
    }
  }
  rep(i,n)cout << ans[i] << endl;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n;cin>>n;
    vl h(n),a(n);
    rep(i,n)cin>>h[i];

    ll res = 0;
    while(1){
        bool is_check = false;
        rep(i,n){
            if(h[i]>a[i]){
                is_check = true;
                while(i<n && h[i] > a[i]){
                    a[i]++;
                    i++;
                }
                res++;
                break;
            }
        }
        if(is_check == false){
                out(res);
                return 0;
        }
    }
}



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

int main()
{
  ll n;
  cin>>n;
  ll p=floor(sqrt(n));
  ll ans=0;
  ll m;
  // cout<<"a "<<floor(sqrt(n))<<'\n';
  // cout<<"b "<<p<<'\n';
  for(m=1; m<=p; m++)
  {
    ans+=m*(m+ floor(n/m)) * (floor(n/m) + 1 - m) - floor(sqrt(n));
    //ans+=m/2 * (n/m) * (1+ n/m);
  }
  p-=1;
  ans-= p*(p+1)*(2*p + 1)/6;
  cout<<ans<<'\n';
}

Measured memory_bytes: 3716
#include <stdio.h>
typedef struct
{
	char name[10];
	int time;	
}queue; 

queue a[100001];
int head,tail,n,q;

void enqueue(queue u)
{
	a[tail]=u;
	tail=(tail+1)%(n+1);	
}

queue dequeue()
{
	queue copy=a[head];
	head=(head+1)%(n+1);
	return copy;		
}

int main(int argc, char *argv[])
{
	int i,totaltime=0;
	queue u;
	scanf("%d%d",&n,&q);
	for(i=0;i<n;i++)
	scanf("%s%d",a[i].name,&a[i].time);
	head=0,tail=n;
	while(head!=tail)
	{
		u=dequeue();
		if(u.time<=q)
		{
			totaltime=totaltime+u.time;
			printf("%s %d\n",u.name,totaltime);		
		}
		else
		{
			totaltime=totaltime+q;
			u.time=u.time-q;
			enqueue(u);
		}
	}
	return 0;
}

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

const int LIM = 100000;
int n, m, p[LIM], y[LIM];
vector<int> yd[LIM+1];

int main() {
    cin >> n >> m;
    rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
    rep(i, n) sort(yd[i+1].begin(), yd[i+1].end());
    rep(i, m) printf("%012lld\n", (ll)p[i] * 1e6 + 
        lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin() + 1);
    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
using namespace std;
#include<queue>
#define INF 100000

int w,h,m[30][30],costmap[30][30][4],c[4],ans;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool check[30][30][4];

struct State{
	int x,y,d,cost;
};

bool operator < (State x,State y){
	return x.cost>y.cost;
}

void solve()
{
	ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>m[i][j];
			for(int z=0;z<4;z++){
				costmap[i][j][z]=INF;
				check[i][j][z]=false;
			}
		}
	}
	for(int i=0;i<4;i++)
		cin>>c[i];

	State first;
	first.x=0;
	first.y=0;
	first.d=0;
	first.cost=0;
	costmap[0][0][0]=0;

	priority_queue<State> Q;
	Q.push(first);

	State temp;
	while(!Q.empty()){
		temp=Q.top();
		Q.pop();
		if(temp.x==w-1 && temp.y ==h-1){
			ans=temp.cost;
			return;
		}
		if(check[temp.y][temp.x][temp.d]==true)
			continue;
		check[temp.y][temp.x][temp.d]=true;
		for(int s=0;s<4;s++){
			State temp2=temp;
			if(m[temp2.y][temp2.x]!=s)
				temp2.cost+=c[s];
			int nextd=(s+temp2.d)%4;
			temp2.x+=dx[nextd];
			temp2.y+=dy[nextd];
			temp2.d=nextd;
			if(temp2.x<0 || temp2.y<0 || temp2.x>=w || temp2.y>=h)
				continue;
			if(check[temp2.y][temp2.x][temp2.d]==true)
				continue;
			if(temp2.cost<costmap[temp2.y][temp2.x][temp2.d]){
				costmap[temp2.y][temp2.x][temp2.d]=temp2.cost;
				Q.push(temp2);
			}
		}
	}
	cout<<"error\n";
}



int main()
{
	cin>>w>>h;
	while(w!=0){
		solve();
		cout<<ans<<"\n";
		cin>>w>>h;
	}
	return 0;
}

Measured memory_bytes: 0
# coding: utf-8
# Your code here!
s = input().split()
N = int(s[0])#num
W = int(s[1])#weight
values = []
weights = []

for n in range(N):
    s = input().split()
    values.append(int(s[0]))
    weights.append(int(s[1]))

max_value = [0 for i in range(W)]
contents = [[] for i in range(W)]

for i in range(W):
    if i == 0:
        buf = 0
    else:
        buf = max_value[i-1]
    for j in range(N):
        if i+1 < weights[j]:continue
        if i+1 == weights[j]:
            if buf < values[j]:
                contents[i] = [j]
                buf = values[j]
        if j in contents[i-weights[j]]:continue
        if buf < max_value[i-weights[j]]+values[j]:
            contents[i] = contents[i-weights[j]] + [j]
            buf = max_value[i-weights[j]]+values[j]
        
    if buf == max_value[i-1]:
        contents[i] = contents[i-1]
    max_value[i] = buf
    
print(max_value[W-1])


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

int main(void){
  int w;
  cin >> w;

  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  if (a + w < b) {
    ans = b - (a + w);
  }
  else if (a > b + w) {
    ans = a - (b + w);
  }
  else {
    ans = 0;
  }
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,x = map(int,input().split())
a = list(map(int,input().split()))
cost = deepcopy(a)
ret = sum(a)
for i in range(1,n):
    for j in range(n):
        cost[j] = min(cost[j],a[j-i])
    ret = min(ret,sum(cost)+x*i)
print(ret)


Measured memory_bytes: 44140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
int a,b;
char op;
cin >> a >> op >> b;
if (op == '+')
{
    cout << a+b << endl;
}else
{
    cout << a-b << endl;
}










  
 
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
    self.weight = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      r = self.Find_Root(self.root[x])
      self.weight[x] += self.weight[self.root[x]]
      self.root[x] = r
      return r
  def GetWeight(self, x):
    self.Find_Root(x)
    return self.weight[x]
  def Unite(self, x, y, w):
    w += self.GetWeight(x)
    w -= self.GetWeight(y)
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return False
    if self.rnk[x] < self.rnk[y]:
      x, y = y, x
      w = -w
    if self.rnk[x] == self.rnk[y]:
      self.rnk[x] += 1
    self.root[y] = x
    self.weight[y] = w
    return True
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x):
    return -self.root[self.Find_Root(x)]
  def Diff(self, x, y):
    return self.GetWeight(y) - self.GetWeight(x)

n, m = map(int, input().split())
lrd = [list(map(int, input().split())) for _ in range(m)]
uf = UnionFind(n+1)
for l, r, d in lrd:
  if not uf.isSameGroup(l, r):
    uf.Unite(l, r, d)
  else:
    if uf.Diff(l, r) != d:
      print('No')
      exit()

print('Yes')


Measured memory_bytes: 58000
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define AC(x,t) accumulate(ALL(x),t)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N, K, res{};
vector<int> vc;
vector<vector<vector<int>>> visited( 50 + 1, vector<vector<int>>( 10000 + 1, vector<int>( 50 + 1, -1 )));
bool dfs( int i, int sum, int cnt )
{
    int &memo = visited[ i ][ sum ][ cnt ];
    if( memo != -1 )
    {
        return memo;
    }
    if( cnt == K )
    {
        res = max( res, sum );
        return 0;
    }
    if( i == N )
    {
        return 0;
    }
    return ( memo = dfs( i + 1, sum, cnt ) || dfs( i + 1, sum + vc[ i ], cnt + 1 ) );
}
int main()
{
    cin >> N >> K;
    vc.resize( N );
    for( auto &x : vc )
    {
        cin >> x;
    }
    dfs( 0, 0, 0 );
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 126336
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] array = new char[h][];
        for (int i = 0; i < h; i++) {
            array[i] = sc.next().toCharArray();
        }

        int[][] dp = new int[h][w];
        if (array[0][0] == '#') {
            dp[0][0]++;
        }

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

        boolean[][] visited = new boolean[h][w];

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                for (int k = 0; k < 2; k++) {
                    int x = j + dx[k];
                    int y = i + dy[k];
                    if (x >= w || y >= h) {
                        continue;
                    }
                    int add = 0;
                    if (array[y][x] == '#' && array[i][j] == '.') {
                        add = 1;
                    }
                    if (!visited[y][x] && dp[y][x] == 0) {
                        dp[y][x] =  dp[i][j] + add;
                    } else {
                        dp[y][x] = Math.min(dp[y][x], dp[i][j] + add);
                    }
                    visited[y][x] = true;
                }
            }
        }

        System.out.println(dp[h - 1][w - 1]);
    }
}

Measured memory_bytes: 37332
# set cards
cards = [[False for i in range(13)] for j in range(4)] 

# set patterns
pattern = ["S", "H", "C", "D"]

# input
n = int(input())
for cnt in range(n):
    mark, rank = map(str, input().split())
    rank = int(rank)
    # set true
    cards[pattern.index(mark)][rank-1] = True

# output
for i in range(len(cards)):
    for j in range(len(cards[0])):
        if cards[i][j] == False:
            print(pattern[i], j+1)




Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mkp make_pair
#define mod 1000000007
#define F first
#define S second
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b)) / gcd((a),(b))
#define ld long double
#define f(i,l,f,n) for(i=(l); i<(n) && !(f); i++)
#define endl "\n"
char grid[1000][1000];
ll dp[1001][1001];

ll power(ll a, ll b)
{
    ll res=1;
    a = (a%mod);\
    while(b>0)
    {
        if(b&1)
        res = (res*a)%mod;
        b/=2;
        a = (a*a)%mod;
    }
    return res;
}


ll travel(int row, int col)
{
    //cout<<row<<" "<<col<<" "<<dp[row][col]<<endl;
    if(row==0 && col==0)
    dp[row][col]=1;
    else if(dp[row][col]!=-1)
    return dp[row][col];
    else if(grid[row][col]=='#')
    dp[row][col]=0;
    else if(row==0)
    dp[row][col]=travel(row, col-1);
    else if(col==0)
    dp[row][col]=travel(row-1, col);
    else
    dp[row][col]=(travel(row-1, col)%mod + travel(row, col-1)%mod)%mod ;

    return dp[row][col];
}

void solve()
{
    int i, j=-1, k=0, l=0, f=0, ans=0;
    int h, w;
    cin>>h>>w;
    f(i,0,0,h)
    {
        f(j,0,0,w)
        cin>>grid[i][j];
    }
    //cin>>grid[i];
    memset(dp, -1, sizeof(dp));
    cout<<travel(h-1,w-1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1, i=0;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 9216