akhauriyash/Code-Regression huggingface dataset:
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
  
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( char *X, char *Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout<<lcs; 
} 
  
/* Driver program to test above function */
int main() 
{ 
  char X[3005];
  char Y[3005];
  cin>>X>>Y;
  int m = strlen(X); 
  int n = strlen(Y); 
  lcs(X, Y, m, n); 
  return 0; 
} 

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

vector<int>E[200000];
int d[200000];
int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);E[b].push_back(a);
	}
	memset(d,-1,sizeof(d));
	d[0]=0;
	queue<int>que;
	que.push(0);
	while(!que.empty()){
		int p=que.front();que.pop();
		for(int v:E[p]){
			if(d[v]==-1){
				d[v]=d[p]+1;que.push(v);
			}
		}
	}
	puts(d[n-1]==2?"POSSIBLE":"IMPOSSIBLE");
}

Measured memory_bytes: 13168
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// mod
const int mod = 1e9 + 7;

int H, W;
vector<string> a;

// dp table
int dp[1010][1010] = {0};

// add
void add(int &a, int b){
    a += b;
    if (a >= mod) a -= mod;
}

int main(){
    cin >> H >> W;
    
    a.resize(H);
    for (int i = 0; i < H; i++) cin >> a[i];
    
    dp[0][0] = 1;
    
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            if (i+1 < H && a[i+1][j] == '.') add(dp[i+1][j], dp[i][j]);
            if (j+1 < W && a[i][j+1] =='.') add(dp[i][j+1], dp[i][j]);
        }
    }
    cout << dp[H-1][W-1] << endl;
    
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (R > L)
    cout << "Right" << endl;
  else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
#include <tuple>
#include <functional>
#include <set>

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        vector<tuple<int, int, int>> camels;
        camels.reserve(n);
        for (int i = 0; i < n; ++i) {
            int k, l, r;
            cin >> k >> l >> r;
            camels.emplace_back(k, l, r);
        }

        long long ans = 0LL;
        vector<pair<int, int>> l_camels, r_camels;
        for (auto &[k, l, r] : camels) {
            int d = l - r;
            if (d > 0) {
                l_camels.emplace_back(d, k);
            } else if (d < 0) {
                r_camels.emplace_back(-d, n - k);
            }
            ans += min(l, r);
        }
        sort(l_camels.begin(), l_camels.end(), greater<pair<int, int>>());
        sort(r_camels.begin(), r_camels.end(), greater<pair<int, int>>());

        for (auto & cams : {l_camels, r_camels}) {
            set<int, greater<int>> available;
            for (int i = 1; i <= n; ++i) {
                available.insert(i);
            }
            for (auto &[d, k] : cams) {
                auto it = available.lower_bound(k);
                if (it != available.end()) {
                    available.erase(it);
                    ans += d;
                }
            }
        }

        cout << ans << endl;

    }
    
    return 0;
}


Measured memory_bytes: 17888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  ll N,sum=0,sum11=0,sum12,sum21=0,sum22;
  cin>>N;
  vector<ll> vec(N);
  for(ll i=0;i<N;i++){
    cin>>vec.at(i);
    sum+=vec.at(i);
  }
  for(ll i=0;i<N;i++){
    sum11+=vec.at(i);
    if(2*sum11==sum){cout<<0<<endl;return 0;}
    if(2*sum11>sum){sum12=sum-sum11;break;}
  }
  for(ll i=0;i<N;i++){
    sum21+=vec.at(N-1-i);
    if(2*sum21>sum){sum22=sum-sum21;break;}
  }
  //cout<<sum11<<" "<<sum12<<" "<<sum21<<" "<<sum22<<endl;
  if(sum12<sum22){sum11=sum21;sum12=sum22;}
  cout<<sum11-sum12<<endl;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    for (auto& in : x) {
        cin >> in;
    }
    for (auto& in : y) {
        cin >> in;
    }
    ll x_sum = 0, y_sum = 0;
    for (int i = 0; i < n; i++) {
        (x_sum += (i * x[i] - (n - 1 - i) * x[i] + mod) % mod) %= mod;
    }
    for (int i = 0; i < m; i++) {
        (y_sum += (i * y[i] - (m - 1 - i) * y[i] + mod) % mod) %= mod;
    }
    ll ret = x_sum * y_sum % mod;
    cout << ret << endl;
    //system("pause");
}

Measured memory_bytes: 1792
#include <iostream>

using ll = long long;

int main() {
    ll a, b;
    std::string ans;
    std::cin >> a >> b;
    if (a > 0 && b > 0) {
        ans = "Positive";
    } else if (a <= 0 && b >= 0) {
        ans = "Zero";
    } else {
        if ( (b-a+1) % 2 == 0 ) {
            ans = "Positive";
        } else {
            ans = "Negative";
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

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

int main(){
    int n, d, num[100001] = {}, ans;
    cin >> n; 
    
    for ( int i = 0; i < n; i++ ) {
        cin >> d;
        num[d]++;
    } 
    
    for ( int i = 0; i < 100000; i++ ) {
        num[i+1] += num[i];
    }
    
    ans = 0;
    for ( int i = 1; i < 100000; i++ ) {
        if ( num[100000] - num[i] == num[i] ) {
            ans ++;
        }
    } 
    
    cout << ans << endl;
    
    return (0);
}

Measured memory_bytes: 4028
#include <iostream>
#include <cstring>
#include <cstdio>
#include<algorithm>
#include <queue>
#include <cmath>
#include <limits>
#include <map>
#include <iomanip>
using namespace std;
#define ll long long int


int main () {
  map<string, int> get;
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++)
  {
    cin >> s;
    get[s]++;
  }
  cout << get.size() << endl;

  return 0;
}

Measured memory_bytes: 18732
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    rep(i, 0, S.size()) {
        S = S.substr(S.size() - 1, 1) + S.substr(0, S.size() - 1);
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
program main
    implicit none
    integer k,now,i,ch
    read(*,*)k
    now=7
    ch=1
    do i=1,k
        if(mod(now,k)==0) then
            write(*,*)i
            ch=0
            exit
        else
            now=mod(10*now+7,k)
        endif
    enddo
    if(ch==1)then
        write(*,*) -1
    endif

end program main

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

int gcd(int a, int b){
  int x=a, y=b, z;
  if(x < y){
    swap(x, y);
  }
  while( y > 0 ){
      z = x % y;
      x = y;
      y =z;
  }
  return x;
}

int main(){
  int a, b;
  cin >> a >> b;
  cout << gcd(a, b) << endl;
  return 0;
}
  


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  ll H;
  cin >> N >> H;
  ll a[N],b[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  ll top_a = 0;
  vector<ll> throw_(0);
  for (int i = 0; i < N; i++) {
    top_a = max(top_a , a[i]);
  }
  for (int i = 0; i < N; i++) {
    if (b[i] > top_a) {
      throw_.push_back(b[i]);
    }
  }
  sort(throw_.begin(),throw_.end());
  reverse(throw_.begin(),throw_.end());
  ll sum = 0;
  ll cnt = 0;
  for (int i = 0; i < (int)throw_.size(); i++) {
    sum += throw_[i];
    cnt++;
    if (sum >= H) {
      break;
    }
  }
  if (sum >= H) {
    cout << cnt << endl;
  } else {
    cnt += (H - sum + (top_a - 1)) / top_a;
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 5868
def main():
    s = input()
    n = len(s)

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for j in reversed(range(n)):
        for i in reversed(range(j)):
            if s[i] == s[j]:
                dp[i][j] = min(
                    dp[i + 1][j + 1] + 1,
                    j - i
                )
            else:
                dp[i][j] = 0

    ans = max(x * 2 for x in dp[0] if x * 2 < n)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector <ll> v(n);

    ll i;
    ll maxm = 0;
    for(i = 0; i < n; i ++)
    {
    	cin >> v[i];
    	maxm = max(maxm, v[i]);
    }

    ll minAns = 999999999;
    for(ll j = 1; j <= maxm; j ++)
    {
    	ll ans = 0;
	    for(i = 0; i < n; i ++)
	    {
	    	ans = ans + (v[i] - j) * (v[i] - j);
	    }
	    minAns = min(minAns, ans);
    }

    cout << minAns << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//next_permutationの実装
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  //adjacent_list
  vector<vector<int>> al(N+1);
  //入力
  for(int i = 0; i < M; i++){
    cin >> a.at(i) >> b.at(i);
    //隣接リストの作成
    al.at(a.at(i)).push_back(b.at(i));
    al.at(b.at(i)).push_back(a.at(i));
  }

  //頂点を代入していく。(sort済み)
  vector<int> v = {1};
  for(int i = 2; i <= N; i++){
    v.push_back(i);
  }

  // for(int i = 0; i < N; i++){
  //   cout << v.at(i) <<endl;
  // }

  int ans = 0;
  //先頭が1の順列を全て調べあげる。
  while(v.at(0)==1){
    //vが頂点の列
    int counter = 0;
    //N-1本の辺が実際に存在するかを確かめる。
    while(counter < N-1){
      //v.at(counter+1)がal.at(v.at(counter)に含まれているかを確認する。)
      vector<int> ajl = al.at(v.at(counter));
      auto itr = find(ajl.begin(),ajl.end(),v.at(counter+1));
      //辺が含まれていなければ次の順列へ
      if(itr==ajl.end()) break;
      counter++;
    }
    if(counter==N-1)ans++;
    // for(auto i:v)cout<<i;
    // cout<<endl;
    next_permutation(v.begin(),v.end());
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define INF 1e9
using ll = std::int64_t;

template <class T>bool chmax(T &a, const T &b);
template <class T>bool chmin(T &a, const T &b);
//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b);
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb);
//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str);
//素数判定
bool is_prime(std::int64_t n);
// 約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n);
// 素因数分解
std::map<std::int64_t,std::int64_t> prime_factor(std::int64_t n);

//10^9 + 7
#define yojo 1000000007
#define MAX_NUM 200001

int dp[100001];

void Main()
{
  int a, b;
  cin >> a >> b;
  std::cout << (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? 
  "Possible" : "Impossible") << std::endl;

  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

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

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

//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b)
{
  // a >= b && b != 0
  std::int64_t c;
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//最大公約数安全版
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb)
{
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0)
  {
    return -1;
  }
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str)
{
  std::vector<std::pair<char, std::int64_t>> data;
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++)
  {
    if (i == str.size())
    {
      data.push_back(make_pair(str[i - 1], count));
      break;
    }
    else if (now != str[i])
    {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return data;
}

//素数判定
bool is_prime(std::int64_t n)
{
  for (std::int64_t i = 0; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      return false;
    }
  }
  
  return n != 1;
}

//約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n)
{
  std::vector<std::int64_t> res;
  for (int i = 0; i < n; i++)
  {
    if(n % i == 0){
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

// 素因数分解
std::map<std::int64_t, std::int64_t> prime_factor(std::int64_t n)
{
  std::map<std::int64_t, std::int64_t> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      ++res[i];
      n /= i;
    }
  }

  if (n != 1)
  {
    res[n] = 1;
  }
  
  return res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
signed main(){
	string s;
	int n;
	cin >> n >> s;
	int x=0;
	int ma=0;
	for(int i=0;i<n;i++){
		if(s[i]=='I'){
			x++;
			ma=max(ma, x);
		}else{
			x--;
			ma=max(ma, x);
		}
	}
	cout << ma << endl;
 
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		double x,h,ans,tri;
		
		while(true){
			x = scan.nextDouble();
			h = scan.nextDouble();
			if(x==0&&h==0){
				break;
			}
			
			tri = Math.sqrt(x/2*x/2+h*h);
			
			ans = x*x + 4*(tri*x/2);
			System.out.printf("%.6f\n",ans);
		}
	}
}

Measured memory_bytes: 19052
def partition(A, p, r):
    x = int(A[r][1])
    i = p-1
    for j in range(p, r):
        if int(A[j][1]) <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)


def is_stable(cards):
    for i in range(1, len(cards)):
        if cards[i-1][1] == cards[i][1]:
            if cards[i-1][2] > cards[i][2]:
                return False
    return True


n = int(input())
cards = []
for i in range(n):
    cards.append(input().split() + [i])
quicksort(cards, 0, n - 1)
print("Stable" if is_stable(cards) else "Not stable")
for card in cards:
    print(card[0], card[1])

Measured memory_bytes: 26888
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}


int main(){
    string s; cin >> s;
    
    int ans = 700;
    rep(i,3){
        if(s[i] == 'o') ans += 100;
    }
    cout << ans << endl;
}







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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, M;
int A[200];

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

    std::cin >> N >> M;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    for(int i=1;i<=M;++i){
        for(int j=0;j+1<N;++j){
            if(A[j] % i > A[j+1] % i){
                swap(A[j], A[j+1]);
            }
        }
    }

    for(int i=0;i<N;++i){
        std::cout << A[i] << std::endl;
    }
}



Measured memory_bytes: 3116
from collections import deque

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

"""
グラフの最短経路問題
１からたどる
最短経路の時，たどる前にいた点を答えとして収納すれば良い
"""
ans = [0] * (N + 1)
neighbor = [[] for _ in range(N+1)]

for a,b in AB:
    neighbor[a].append(b)
    neighbor[b].append(a)

que = deque([1])
while len(que) > 0:
    s = que.popleft()
    
    for i in neighbor[s]:
        if ans[i] == 0:
            ans[i] = s
            que.append(i)

if 0 not in ans[2:]:
    print("Yes")
else:
    print("No")
    exit()

for i in ans[2:]:
    print(i)

Measured memory_bytes: 120888
#include<iostream>
#include<string>
using namespace std;
int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;
    int S2[99][26]={0};
    int sum=0;
    int max=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=i;j++){
            for(int k=i+1;k<N;k++){
                if(S[j]==S[k]){
                    S2[i][S[j]-97]=1;
                }
            }
        }
        for(int l=0;l<26;l++){
            if(S2[i][l]==1){
                sum=sum+1;
            }
        }
        if(sum>max){
            max=sum;
        }
        sum=0;
    }
    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
int n,r,p1,c;
int huda[51],huda2[51];
int main(){
        while(1) {
                cin>>n>>r;
                if(n==0 && r==0) {
                        return 0;
                }
                for(int i=0; i<n; i++) {
                        huda[i]=n-i;
                        huda2[i]=huda[i];
                }
                for(int i=0; i<r; i++) {
                        cin>>p1>>c;
                        for(int j=0; j<c; j++) {
                                huda[j]=huda[p1-1+j];
                        }
                        for(int j=0; j<p1-1; j++) {
                                huda[c+j]=huda2[j];
                        }
                        for(int j=0; j<51; j++) {
                                huda2[j]=huda[j];
                        }
                }
                cout<<huda[0]<<endl;
        }
}

Measured memory_bytes: 2992
#include <iostream>
#include <cstring>

using namespace std;

int main(void){
	int n;
	bool isp[1000001];
	
	//但多
	memset(isp,true,sizeof(isp));
	isp[0] = false;
	isp[1] = false;
	for(int i=2;i<1000001;i++){
		if(isp[i]){
			for(int j=2;i*j<1000001;j++){
				isp[i*j] = false;
			}
		}
	}
	
	while(cin >> n && n){
		int ret=0;
		for(int i=2;i<=n/2;i++){
			if(isp[i] && isp[n-i]) ret++;
		}
		cout << ret << endl;
	}
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll N, M, V, P;
ll A[100005];

//! スコアがn以上のものをp個以内に抑えることができる？
bool check(ll n) {
    ll m = M * V;
    vector<ll> v;
    REP(i, N) {
        v.push_back(A[i]);
    }

    REP(i, P - 1) {
        v[i] += M;
        m -= M;
    }
    FOR(i, N, P) {
        if (m > 0) {
            m -= std::min(M, std::max(n - A[i], 0LL));
        }
    }
    m = std::max(m, 0LL);
    return v[P - 1] + m <= n;
}

int main() {
    cin >> N >> M >> V >> P;
    REP(i, N) {
        cin >> A[i];
    }
    sort(A, A + N, [](ll a, ll b) { return a > b; });

    ll ok = INF, ng = -1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }

    //! okまでは大丈夫
    ll ans = 0;
    REP(i, N) {
        if (A[i] + M >= ok)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int sumofdigits(int x){
  int sum=0;
  while(x>0){
    sum+=x%10;
    x/=10;
  }

  return sum;
}//各桁の和を計算する関数
 
int main() {
  
  int N,min=100000;

  cin >> N; 

  for(int i=1;i<N;i++){
    int x = sumofdigits(i) + sumofdigits(N-i);
    if(x<min) min=x;
  }
 
  cout << min << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int N;
	string s1, s2;
	cin >> N >> s1 >> s2;

	int mod = (int)1e9 + 7;
	int i;
	long long ans;


	if (s1[0] == s2[0]) ans = 3, i = 1;
	else ans = 6, i = 2;

	while (i < N) {
		if (s1[i - 1] == s2[i - 1]) {
			ans *= 2;
			if (s1[i] == s2[i])i++;
			else	i += 2;
		}
		else {
			if (s1[i] == s2[i]) {
				ans *= 1;
				i++;
			}
			else {
				ans *= 3;
				i += 2;
			}
		}
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する



int cnt[26];
vector<char>v;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	if (s.size() != 26) {
		rep(i, s.size())cnt[s[i] - 'a']++;
		rep(i, 26) {
			if (cnt[i] != 1) {
				cout << s << (char)('a' + i) << endl;
				return 0;
			}
		}
	}
	v.push_back(s[25]);
	for (int i = 24; i >= 0; i--) {
		sort(v.begin(), v.end());
		if (s[i] < s[i + 1]) {
			if (i == 0) {
				cout << (char)(s[0] + 1) << endl;
				return 0;
			}
			cout << s.substr(0, i);
			rep(j, v.size()) {
				if (s[i] < v[j]) {
					cout << v[j] << endl;
					return 0;
				}
			}
		}
		v.push_back(s[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include<math.h>
    #define rep(i,n) for (int i = 0; i < (n) ; ++i)
    using namespace std;
    using ll = long long ;
    using P = pair<int , int> ;
    #define PI 3.14159265358979323846264338327950
    #define INF 1e18 
     
    int main(){
        int n, m ,k ;
        cin >> n >> m >> k ;
        vector<int> a (n) ;
        vector<ll> b (m) ;
        rep(i, n) cin >> a[i] ;
        rep(i, m) cin >> b[i] ;
        ll sum = 0 ;
        rep(i, n){
            sum += a[i] ;
        }
        rep(i, m - 1) {
            b[i+1] += b[i] ;
        }

        int ans = 0 ;
        int f = n ;
        ll o = k - sum ;

        if(o >= 0) {
            int pp = lower_bound(b.begin(), b.end(), o) - b.begin() ;
            if(b[pp] == o){
                 pp++ ;
            }
            ans= max(ans, pp + f) ;
        }
        for(int i = n - 1 ; i >= 0 ; i--){
            f-- ;
            sum -= a[i] ;
            ll t = k - sum ; 
            if(t <= 0){
                continue ;
            }
            else {
                int p = lower_bound(b.begin(), b.end(),t) - b.begin() ;
                if(b[p] == t){
                    p++ ;
                }
                ans= max(ans, p + f) ;
            }
        }
        cout << ans << endl ;
        return 0 ;
    }

Measured memory_bytes: 5644
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func sum(a ...int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, x, m := nextInt3()

	before, loop := make([]int, 0), make([]int, 0)
	a := x
	checked := map[int]bool{}
	for !checked[a] {
		checked[a] = true
		a = (a * a) % m
	}
	loopBegin := a
	a = x
	for loopBegin != a {
		before = append(before, a)
		a = (a * a) % m
	}
	for {
		loop = append(loop, a)
		a = (a * a) % m
		if a == loopBegin {
			break
		}
	}

	// ループに入らないとき
	if n <= len(before) {
		ans := sum(before[:n]...)
		puts(ans)
		return
	}

	ans := sum(before...) + sum(loop...)*((n-len(before))/len(loop)) + sum(loop[:(n-len(before))%len(loop)]...)
	puts(ans)
}


Measured memory_bytes: 6060
import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int x=s.nextInt();
int y=s.nextInt();
int max=x>y?y:x;
int min=x+y-n>0?x+y-n:0;
System.out.println(max+" "+min);
}
}

Measured memory_bytes: 21332
<?php
  $n = trim(fgets(STDIN));
  $min = PHP_INT_MAX;
  $min = min($min,trim(fgets(STDIN)));
  $min = min($min,trim(fgets(STDIN)));
  $min = min($min,trim(fgets(STDIN)));
  $min = min($min,trim(fgets(STDIN)));
  $min = min($min,trim(fgets(STDIN)));
  
  $ans = 5+intdiv($n,$min);
  if($n%$min==0){
      $ans--;
  }else if($min == $n){
      $ans = 5;
  }
  echo $ans;

Measured memory_bytes: 4604
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
#include<unordered_map>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(int i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
/* Coding Space*/
int main(){
  int n,z,w; cin >> n >> z >> w;
  
  vi a(n);
  rep(i,n)cin >> a[i];
  if(n==1){
    cout << abs(a[0] - w) << endl;
    return 0;
  }
  int ans = max(abs(w-a[n-1]),abs(a[n-1]-a[n-2]));
  cout << ans << endl;
}

Measured memory_bytes: 256
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n,m;
cin>>n>>m;
if(n==m)
{
    cout<<"Yes"<<endl;
}else
{
    cout<<"No"<<endl;
}
return 0;
}


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

using namespace std;

int c[10][10];

int main()
{
	cin.tie(nullptr);
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			cin >> c[i][j];
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			for (int k = 0; k < 10; k++)
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
	int r = 0, a;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a;
			if (a > -1)
				r += c[a][1];
		}
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	set<string> s;
	rep(i,n){
		string t;
		cin >> t;
		s.insert(t);
	}
	cout << s.size() << endl;
	return 0;
}

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

const int mod = 1e9+7;
long long h, w;
char grid[1010][1010];


long long mem[1010][1010];
long long DP(int i, int j){

    if(i == h-1 && j == w-1)  return 1;
    if(mem[i][j] != -1) return mem[i][j];
    ///bottom
    long long opt1 = (i < h-1 && grid[i+1][j] != '#') ? DP(i+1, j) : 0;
    ///right
    long long opt2 = (j < w-1 && grid[i][j+1] != '#') ? DP(i, j+1) : 0;

    return mem[i][j] = (opt1%mod + opt2%mod)%mod;

}

int main(){
    memset(mem, -1, sizeof mem);
    scanf(" %lld %lld ", &h, &w);
    for(int i = 0 ; i < h ; ++i){ scanf("%s", grid + i); }
    printf("%lld", DP(0,0));


return 0;
}


Measured memory_bytes: 9344
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define INF 1000000001;
using namespace std;
struct Edge{int from, to, cost;};

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

    int h,w;
    char maze[54][54];
    string s[54];
    cin >> h >> w;

    REP(i, 54){
        REP(j, 54){
            maze[i][j] = 'a';
        }
    }
    RREP(i, 1, h+1){
        RREP(j, 1, w+1){
            cin >> maze[i][j];
        }
    }
    //string a = to_string(1);
    //s[0] += a;
    //cout << "yaya" << endl;
    //cout << s[0] << endl;

    RREP(i, 1, h+1){
        RREP(j, 1,w +1){
            int cnt = 0;
            if(maze[i][j] == '#'){
                s[i] += "#";
                continue;
            }

            if(maze[i-1][j-1] == '#') cnt++;
            if(maze[i-1][j+1] == '#') cnt++;
            if(maze[i-1][j] == '#') cnt++;
            if(maze[i][j+1] == '#') cnt++;
            if(maze[i][j-1] == '#') cnt++;
            if(maze[i+1][j-1] == '#') cnt++;
            if(maze[i+1][j] == '#') cnt++;
            if(maze[i+1][j+1] == '#')cnt++;

            //cout << cnt << endl;
            s[i] += to_string(cnt);
        }
        //cout << s[i] << endl;
    }

    RREP(i, 1, h+1){
        cout << s[i] << endl;
    }

    //cout << maze[1][1] << endl;

    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  string ans;
  cin >> A >> B >> C >> D;
  if (A+B>C+D)
  ans = "Left";
  else if (C+D>A+B)
  ans = "Right";
  else
  ans = "Balanced";
  cout << ans << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a >= b && a >= c)
    cout << a * 10 + b + c << endl;
  else if(b >= a && b >= c)
    cout << b * 10 + a + c << endl;
  else
    cout << c * 10 + a + b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio> 
const int MAXN=0x7ffffff;
int a[MAXN];
using namespace std;
void push(int n){
	if(n%2==1){
		printf("%d",a[n]);
        for(int i=n-2;i>=1;i-=2){
            printf(" ");
            printf("%d",a[i]);
        }
        for(int j=2;j<=n-1;j+=2){
        	printf(" ");
        	printf("%d",a[j]);
    	}
    }
	else{
        printf("%d",a[n]);
    	for(int i=n-2;i>=1;i-=2){
            printf(" ");
            printf("%d",a[i]);
        }
        for(int j=1;j<=n-1;j+=2){
        	printf(" ");
        	printf("%d",a[j]);
    	}
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%d",&a[i]);
        push(n);
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <cstdlib> // abs() for integer
#include <cmath>   // abs() for float, and fabs()
using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    char s, t;
    int count = 0;
    for (int i = 0; i < S.length(); i++)
    {
        s = S[i];
        t = T[i];
        if (s!=t)
        {
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 3916
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
 
class DandA {
    static void Main(string[] args) {
        int x = ReadLineInt();
        while (!IsPrime(x)) {
            x++;
        }
        Console.WriteLine(x);
    }

    public static bool IsPrime(int num) {
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
}

Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

const int MAX=10100;
const int INF=1<<25;

class edge
{
public:
	int to,cap,cost,rev;
	edge(){}
	edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
};

int V;
vector<edge> G[MAX];
int dist[MAX];
int prevv[MAX],preve[MAX];

void add_edge(int from,int to,int cap,int cost)
{
	G[from].push_back(edge(to,cap,cost,G[to].size()));
	G[to].push_back(edge(from,0,-cost,G[from].size()-1));
	return;
}

int mincostflow(int s,int t,int f)
{
	int res=0;
	while(f>0)
	{
		fill(dist,dist+V,INF);
		dist[s]=0;
		bool update=true;
		while(update)
		{
			update=false;
			for(int v=0;v<V;v++)
			{
				if(dist[v]==INF)continue;
				for(int i=0;i<G[v].size();i++)
				{
					edge &e=G[v][i];
					if(e.cap>0&&dist[e.to]>dist[v]+e.cost)
					{
						dist[e.to]=dist[v]+e.cost;
						prevv[e.to]=v;
						preve[e.to]=i;
						update=true;
					}
				}
			}
		}
		
		if(dist[t]==INF)return -1;
		
		int d=f;
		for(int v=t;v!=s;v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
		f-=d;
		res+=d*dist[t];
		
		for(int v=t;v!=s;v=prevv[v])
		{
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}

int main()
{
	int m,n,k;
	cin>>m>>n>>k;
	V=k+1;
	int w[MAX];
	for(int i=0;i<n;i++)cin>>w[i];
	int prev[MAX];
	memset(prev,-1,sizeof(prev));
	int ans=0;
	for(int i=0;i<k;i++)
	{
		int a;
		cin>>a;
		a--;
		
		add_edge(i,i+1,INF,0);
		
		ans+=w[a];
		
		if(prev[a]!=-1)
		{
			if(prev[a]+1==i)
			{
				ans-=w[a];
			}
			else
			{
				add_edge(prev[a]+1,i,1,-w[a]);
			}
		}
		
		prev[a]=i;
	}
	
	cout<<ans+mincostflow(0,k,m-1)<<endl;
	return 0;
}

Measured memory_bytes: 4296
#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;
const int MAX_ab = 18;
ll dp[MAX_ab][MAX_ab];
bool z[MAX_ab][MAX_ab];

void init()
{
	rep(i,MAX_ab)
	{
		rep(j,MAX_ab)
		{
			z[i][j] = true;
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
}

int main()
{
	int a,b,n,x,y;
	while((cin >> a >> b) && (a != 0) && (b != 0))
	{
		init();
		cin >> n;
		for (int i = 0; i < n; ++i)
		{
			cin >> x >> y;
			z[x-1][y-1] = false;
		}

		for (int i = 0; i < a; ++i)
		{
			if (z[i][0] == false) break;
			else dp[i][0] = 1;
		}
		for (int i = 0; i < b; ++i)
		{
			if (z[0][i] == false) break;
			else dp[0][i] = 1;
		}


		for (int i = 1; i < a; ++i)
		{
			for (int j = 1; j < b; ++j)
			{
				if (z[i][j]) dp[i][j] = dp[i-1][j] + dp[i][j-1];
			}
		}

		cout << dp[a-1][b-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
L = []
for i in range(5):
    L.append(int(input()))

L1 = [x for x in L if x%10 == 0]
L2 = [x for x in L if x%10 != 0]
L3 = [(x%10,x//10) for x in L2]

ans = sum(L1)
if len(L3)>0:
  L3.sort(reverse = True)
  for i in range(len(L3)-1):
    ans += (L3[i][1]+1)*10
  ans += L3[-1][1]*10+L3[-1][0]
print(ans) 

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> is(26);
    for (auto i = 0; i < s.size(); i++) { is[s[i] - 'a'].insert(i); }

    for (int i = 0; i < q; i++) {
        int type;
        cin >> type;
        if (type == 1) {
            int iq;
            char cq;
            cin >> iq >> cq;
            iq--;
            is[s[iq] - 'a'].erase(iq);
            s[iq] = cq;
            is[cq - 'a'].insert(iq);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int ans = 0;
            for (auto a = 0; a < 26; a++) {
                auto it = is[a].lower_bound(l);
                if (it != is[a].end() && *it < r) { ans++; }
            }
            cout << ans << endl;
        }
    }
    return 0;
}

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

int comb(int n, int r){
     int x = 0;
     int c = 1;
    if (n < r) {return 0;}
    else {
     while( x < r ) {
        c = c * (n - x) / ( x+1 );
        x = x + 1;
    }
    return c;}
}

int main() {
  int n;
  cin >> n ;
  int a[n-1];
  int i = 0;
  while (i < n){
    cin >> a[i] ;
    i = i + 1;
  }
 sort(a, a+n);  

  int j = 0;
  int c = 2147483647;
  int p;
int x;
  while ( j < n-1 ){
    x = a[j]-(a[n-1])/2-(a[n-1])%2;
    if ( c > std::max( x, -x ) ) {
    p = a[j];
    c = std::max( x, -x) ;}
    j = j + 1;
}

cout << a[n-1] << " " << p << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int k,sum=0;
    cin>>k;
    for(int i=1;i<=2000000;i++){
        sum=(sum*10+7)%k;
        if(!sum)return cout<<i,0;
    }
    return cout<<-1,0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int main(int argc, const char * argv[]) {
    // source code
    int n;
    cin >> n;
    vector<int> L(n);
    rep (i, n) cin >> L[i];
    std::sort(L.begin(), L.end());
    int a, b, c;
    int total = 0;
    rep (i, n) repd (j, i + 1, n) {
        a = L[i];
        b = L[j];
        int low = lower_bound(L.begin() + j + 1 , L.end(), b) - L.begin(); 
        int high = lower_bound(L.begin() + j + 1, L.end(), a + b) - L.begin() - 1; 
        total += (high - low) + 1;
    } 
    cout << total;
    return 0;
}


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

LL N,a[100010],b[100010];

int main(){
    cin >> N;

    LL i; LL cr=0;
    for (i=1; i<=N; i++)
        cin >> a[i] >> b[i];


    for (i=N; i>0; i--){
        a[i]+=cr;
        cr+=b[i]*((a[i]+b[i]-1)/b[i])-a[i];
    }

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


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    string s,t; cin >> s >> t;
    cout << t << s;
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, K := sc.nextInt(), sc.nextInt()
	set := make(map[int]bool)
	for i := 0; i < K; i++ {
		set[sc.nextInt()] = true
	}
	use := make(map[int]bool)
	for i := 0; i <= 9; i++ {
		if !set[i] {
			use[i] = true
		}
	}
	ans := N
	for {
		n := ans
		all := true
		for n > 0 {
			if !use[n%10] {
				all = false
			}
			n /= 10
		}
		if all {
			break
		}
		ans++
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    int n;cin>>n;
    int i = 1,sum=0;
    while(i<=n){
        int num;cin>>num;
        if(num%2!=0 && i%2!=0)
            sum++;
        i++;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3596
let width a b =
  min ((abs a) + (abs (a-b))) ((abs b) + (abs (a-b)))

let make_list f t step =
  let rec make_list_inner c t lst =
    if c >= t then lst else make_list_inner (c+step) t (c::lst)
  in
  List.rev (make_list_inner f t [])
  
let solve n k list = match list with
  | x::[] -> x
  | _ ->
     let arr = Array.of_list list in
     let widths = List.map (fun s ->width arr.(s) arr.(s + k - 1)) (make_list 0 (n-k+1) 1) in
     List.fold_left (fun x acc -> min x acc) (max_int) widths

let read_list_of_int () =
  let rec read_list_of_int_inner lst =
    try let ans = (Scanf.scanf "%d " (fun x->x)) in
        read_list_of_int_inner (ans::lst)
    with End_of_file ->
      List.rev lst
  in
  read_list_of_int_inner []

let () =
  let n, k = (Scanf.scanf "%d %d\n" (fun x y -> x,y)) in
  let list = read_list_of_int () in
  let ans = solve n k list in
  Printf.printf "%d\n" ans;
;;


Measured memory_bytes: 12544