akhauriyash/Code-Regression huggingface dataset:
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>

using namespace std;


int main() {
    int h,w;
    cin >> h >> w;
    vector<string> a(h);

    for (int i = 0; i < h; i++) {
        cin >> a[i];
    }

    vector<bool> row(h, false);
    vector<bool> col(w,false);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;  
            }
        }
    }
    for (int i = 0; i < h; i++) {
        if (row[i]) {
            for (int j = 0; j < w; j++) {
                if (col[j]) {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

const int MAX_C=13000;
using bs=bitset<MAX_C>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    vector<vector<int>> A(H,vector<int>(W)),B(H,vector<int>(W)),C(H,vector<int>(W));
    rep(i,H) rep(j,W) cin >> A[i][j];
    rep(i,H) rep(j,W) cin >> B[i][j];
    rep(i,H) rep(j,W) C[i][j]=abs(A[i][j]-B[i][j]);
    vector<vector<bs>> dp(H,vector<bs>(W,bs(0)));
    dp[0][0].set(abs(C[0][0]));
    rep(i,H) rep(j,W){
        if (i-1>=0){
            dp[i][j]|=(dp[i-1][j]<<C[i][j]);
            dp[i][j]|=(dp[i-1][j]>>C[i][j]);
            rep(k,MAX_C) if (dp[i-1][j].test(k)&&k<C[i][j]) dp[i][j].set(C[i][j]-k);
        }
        if (j-1>=0){
            dp[i][j]|=(dp[i][j-1]<<C[i][j]);
            dp[i][j]|=(dp[i][j-1]>>C[i][j]);
            rep(k,MAX_C) if (dp[i][j-1].test(k)&&k<C[i][j]) dp[i][j].set(C[i][j]-k);
        }
    }
    int ans=MAX_C;
    rep(i,MAX_C) if (dp[H-1][W-1].test(i)) chmin(ans,(int)i);
    cout << ans << endl;
}

Measured memory_bytes: 10624
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    L = ii()
    print((L/3)**3)



main()







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

const int INF = 1 << 30;

int N, x[100009][3];
int dp[100009][3];

int main() {
    cin >> N;
    for(int i = 0; i < N; i++)
        for(int j = 0; j < 3; j++)
            cin >> x[i][j];

    for(int i = 0; i < 100009; i++)
        for(int j = 0; j < 3; j++)
            dp[i][j] = -INF;

    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for(int i = 0; i < N; i++)
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
                if(j != k) dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + x[i][j]);

    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;

    return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  int length = s.size();
  rep(i,length){
    int tmp = s[i] - 'A';
    tmp = (tmp+n)%26;
    putchar('A'+tmp);
  }
}

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


int main(){
    int P,Q,N;
    int ans;
    cin >> P >> Q >> N;
    //max(P,Q,N);
    if(1){

    }
   
    ans = P+Q+N-max(P,max(Q,N));
  
    cout << ans <<"\n";
    
    
    return 0;
}

Measured memory_bytes: 256
N=int(input())
s=input()
A=[]
for i in range(N):
    A.append(s[i])

cntW=0
for i in range(N):
    if A[i]=="W":
        cntW+=1
cntR=N-cntW

changeW=0
changeR=0
for i in range(cntR):
    if A[i]=="W":
        changeW+=1
for i in range(cntR,N):
    if A[i]=="R":
        changeR+=1

if changeR==changeW:
    ans=changeW
else:
    #minN=min(changeW,changeR)
    maxN=max(changeR,changeW)
    ans=maxN
print(ans)

Measured memory_bytes: 10844
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, i, flag = 0, temp, j, mark=1;

    scanf("%d", &n);

    int nsort[n];

    if(n >= 2 && n <= 50)
    {
        for(i = 0; i < n; i++)
        {
            scanf("%d", &nsort[i]);
        }
    }

    else
    {
        exit(0);
    }

    for(i = 0; i < n; i++)
    {
        if(nsort[i] == mark)
        {
            mark++;
            continue;
        }
        else
        {
            for(j = i+1; j < n; j++)
            {
                if(nsort[j] == mark)
                {
                    flag = 1;
                    temp = nsort[i];
                    nsort[i] = nsort[j];
                    nsort[j] = temp;
                    mark = 1;
                    break;
                }
            }
        }
        if(flag == 1)
        {
            break;
        }

    }
    if(flag == 1)
{
    for(i = 0; i < n; i++)
    {
        if(nsort[i] == mark)
        {
            mark++;
            continue;
        }
        else
        {
            flag = 2;
            break;

        }
        if(flag == 2)
        {
            break;
        }

    }
}

    if (flag == 1)
    {
        printf("YES");
    }
    else if (flag == 0)
    {
        printf("YES");
    }
    else if (flag == 2)
    {
        printf("NO");
    }



  return 0;
}


Measured memory_bytes: 1736
#include <stdio.h>
#include <math.h>
using namespace std;

/*
int log10(int n) {
	int keta = 0;
	do{
		n /= 10;
		keta++;
	} while (n > 0);
	return keta;
}
*/

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		scanf("%d", &N);
		if (!N)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				scanf("%d", &table[i][j]);
			}
		}

		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				table[i][N] += table[i][j];
				table[N][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-((table[i][j]==0)? 1 : log10(table[i][j]) + 1);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 1076
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;

    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    vector<int> num(100000);
    for (int i = 0; i < N; i++) {
        num[a[i]]++;
    }

    vector<int> sum(100000);
    for (int i = 0; i < 100000; i++) {
        sum[i] = num[i] + num[i + 1] + num[i + 2];
    }

    sort(sum.begin(), sum.end());
    reverse(sum.begin(), sum.end());
    cout << sum[0] << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

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 long long INF = 1LL << 60;

#define MAX_N 1010
#define MAX_M 200000100

int main(){
    ll n;
    cin >> n;
    for (ll i=0;i<2;++i){
        for (ll j=0;j<2;j++){
            for (ll k=0;k<2;k++){
                ll a=n/1000,b=(n/100)%10,c=(n/10)%10,d=n%10;
                char a1,b1,c1;
                if (i==0){
                    a+=b;
                    a1='+';
                }else{
                    a-=b;
                    a1='-';
                }
                if (j==0){
                    a+=c;
                    b1='+';
                }else{
                    a-=c;
                    b1='-';
                }
                if (k==0){
                    a+=d;
                    c1='+';
                }else{
                    a-=d;
                    c1='-';
                }
                if (a==7){
                    cout << n/1000 << a1 << b << b1 << c << c1 << d << "=7" << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
program main
 implicit none
 character*1 A,B
 integer N,k,i
 
 read(*,*) N
 read(*, '(A1)', advance='no' ) A 
 
 k=1
 do i=2,N
  read(*, '(A1)', advance='no' ) B
  if (A/=B) then
   k = k+1
  end if
  A = B
 end do
 
 write(*,*) k
end program main

Measured memory_bytes: 256
#dfs試す
n,m,q=map(int, input().split( ))
qs=tuple(tuple(map(int, input().split( ))) for _ in range(q))
def dfs(ll):
    if len(ll)==n+1:
        sm=0
        for ai,bi,ci,di in qs:
            if ll[bi]-ll[ai]==ci:
                sm+=di 
        return sm
    res=[]
    for i in range(ll[-1],m):#+1
        ll2=ll+[i]
        res.append(dfs(ll2))
    return(max(res))
l=[0]
print(dfs(l))


Measured memory_bytes: 73088
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};



int main(){
    IOS;
    make2(ll,n,k);
    makevec(ll,a,n);
    ll ans=0;
    fr(i,n) ans=max(ans,a[i]);
    ll l=1;
    ll r=9e9+2;
    ll mid;
    while(l<=r){
        mid=(l+r)/2;
        ll c=0;
        fr(i,n){
            if(mid!=0) c+=max(0ll,(ll)ceil(((double)a[i])/(double)mid)-1ll);
            else c+=2*(a[i]);
        }
       // cout<<mid<<" "<<c<<" "<<l<<" "<<r<<endl;
        if(c<=k) {ans=mid; r=mid-1;}
        else l=mid+1;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4668
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
string A,B,C;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin>>N>>A>>B>>C;
  int s = 0;
  rep(i, N) {
    if(A[i]==B[i]&&B[i]==C[i]) s+=0;
    else if (A[i]==B[i]||A[i]==C[i]||B[i]==C[i]) s+=1;
    else s+=2;
  }
  cout << s << "\n";
  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 INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
typedef long long ll;
bool isPali(string s){
  string rev = s; 
  reverse(ALL(s));
  return rev==s;
}
int main() {
  string s;
  cin >> s;
  int n=s.length();
  bool ans = isPali(s)&&isPali(s.substr(0,(n-1)/2))&&isPali(s.substr((n+1)/2));
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
import math
a,b,c,d = map(int,input().split())
ao_hp = math.ceil(c/b)
taka_hp = math.ceil(a/d)
#(taka_hp,ao_hp)
if(taka_hp > ao_hp):
    print('Yes')
elif(taka_hp < ao_hp):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9116
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int min = 999999;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            min = Math.min(a[i], min);
        }

        int breakPoint = 0;
        if (min > 1) {
            System.out.println(-1);
        } else {
            int tmp = min;
            for (int i = 0; i < n; i++) {
                if (a[i] != tmp) {
                    breakPoint++;
                    continue;
                }

                tmp++;
            }
            System.out.println(breakPoint);
        }
    }
}


Measured memory_bytes: 66852
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 入力
// 入力
int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
queue<pair<int, int>> que;

int main() {

    int N, M;
    cin >> N >> M;
    int count = 0;

    vector<pair<int, int>> kukan(M);

    REP(i, M) cin >> kukan[i].second >> kukan[i].first;
    sort(kukan.begin(), kukan.end());
    REP(i, M) swap(kukan[i].first, kukan[i].second);

    int pos = 0;
    REP(i, M){
        if(pos <= kukan[i].first){
            pos = kukan[i].second;
            count++;
        }
    }

    cout << count << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

class Program
{
    static void Main(string[] args)
    {
        var arr = arrInt();
        int h = arr[0];
        int w = arr[1];
        int k = arr[2];
        var mapMoto = mapChar(h);
        int count = 0;
        for (int bit = 0; bit < (1 << h+w); bit++)
        {
            //mapのクローンを作成する。
            List<char[]> map = mapCharCopy(mapMoto);
            for (int i = 0; i < h+w; i++)
            {
                if ((bit & (1 << i)) > 0)
                {
                    if(i < h)
                    {
                        //i行目を変換
                        changeGyou(w, i, map);
                    } else
                    {
                        //i列目を変換
                        changeRetu(h, i - h , map);
                    }
                }
            }
            //数がk個か数える
            if (equalK(h, w, k, map)) count++;
        }
        Console.WriteLine(count);


    }

    static void changeGyou(int w , int gyou , List<char[]> map)
    {
        for (int i = 0; i < w; i++) map[gyou][i] = '.';
    }

    static void changeRetu(int h, int retu, List<char[]> map)
    {
        for (int i = 0; i < h; i++) map[i][retu] = '.';
    }

    static bool equalK(int h, int w, int k , List<char[]> map)
    {
        int count = 0;
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                if (map[i][j] == '#') count++;
            }
        }
        if (count == k) return true;
        return false;
    }



    //入力受け取り用
    static string crS() { return Console.ReadLine(); }
    static int crI() { return int.Parse(Console.ReadLine()); }
    static int[] arrInt(){return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();}
    static long[] arrLong(){ return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr(){return Console.ReadLine().Split(' ').ToArray();}
    static List<int[]> mapInt(int h)
    {
        List<int[]> mapInt = new List<int[]>();
        for (int i = 0; i < h; i++)
        {
            mapInt.Add(arrInt());
        }
        return mapInt;
    }

    static List<char[]> mapChar(int h)
    {
        List<char[]> mapChar = new List<char[]>();
        for (int i = 0; i < h; i++)
        {
            string s = crS();
            mapChar.Add(s.ToCharArray());
        }
        return mapChar;
    }

    static List<char[]> mapCharCopy(List<char[]> map)
    {
        List<char[]> copyMap = new List<char[]>();
        foreach (var arr in map)
        {
            List<char> list = new List<char>();
            foreach (var ele in arr)
            {
                list.Add(ele);
            }
            copyMap.Add(list.ToArray());
        }
        return copyMap;
    }
}

Measured memory_bytes: 32312
n, k = map(int,input().split())
if k == n + 1:
    print(1)
else:
    mi_n = ((k-1)*k)//2#０からKこ選んだ和。k個選ぶ時の最小。0~k-1。
    ma_x = ((n+n-k+1)*k)//2#NからKこ選んだ和。ｋ個選んだ時の最大。n~n-k+1。
    ans = ma_x - mi_n + 1
    for i in range(k,n,1):
        mi_n += i
        ma_x += n - i
        ans += ma_x - mi_n + 1

    ans += 1

    print(ans%(10**9 + 7))


Measured memory_bytes: 9164
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    long long int a , b , n ;
    cin >> n >> a >> b ;
    long long int ans = 0;
    ans += (n / (a + b)) *a ;
    long long int add ;
    add = n % (a + b) ;
    if(add>a){
        ans += a ;
    }else{
        ans +=  add ;
    }

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<stack>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n,a=1,b=1;
string s;
//-------------------関数----------------------//

ll res(ll i,ll one,ll goukei) {
	if (i == n-1) { return goukei+one+(ll)(s[i])-(ll)'0'; }//最後は10倍できない
	ll cnt=0;//足しておくため
	one += (ll)s[i]-(ll)'0';//一の位
	cnt += res(i + 1, one * 10,goukei);//十倍
	cnt += res(i + 1, 0,goukei+one);//足し算いれとく
	return cnt;//返す
}

int main() {
	cin >> s;//代入
	n = s.size();
	cout << res(0, 0,0) << endl;//出力
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;

string toLower( string s ) {
    for( int i = 0; i < s.length(); ++i ) {
        if( s[i] >= 'A' && s[i] <= 'Z' ) s[i] += 32;
    }
    return s;
}

int main( void ) {
    string s, ss;
    cin >> s;
    s = toLower( s );
    int ans = 0;
    while( cin >> ss && ss != "END_OF_TEXT" ) {
        ss = toLower( ss );
        if( s == ss ) ++ans;
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 3212
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

template <typename Tlist, typename Tfunc>
void __combination(
Tlist const& list, typename Tlist::size_type const n, Tfunc const& func,
Tlist& tmp, typename Tlist::size_type const i, typename Tlist::size_type const j)
{
    if (i == n)
    {
        func(tmp);
        return;
    }

    for (typename Tlist::size_type k = j; k != list.size() + (1 + i- n); ++k)
    {
        tmp[i] = list[k];
        __combination(list, n, func, tmp, i + 1, k + 1);
    }
}

template <typename Tlist, typename Tfunc>
void combination(
    Tlist const& list, typename Tlist::size_type const n, Tfunc const& func)
{
    Tlist tmp(n);
    __combination(list, n, func, tmp, 0, 0);
}

/*
  uint64_t sum = 0;
  combination(inis, 3, [&sum](auto& v) {
  sum += std::accumulate(std::begin(v), std::end(v), 1ULL, [](auto acc, auto nn) {
  return acc*nn;
  });
  });
*/


int main()
{
    size_t N;
    std::cin >> N;

    std::vector<int64_t> P(5);

    for (size_t i = 0; i < N; ++i) {
        std::string s;
        std::cin >> s;

        switch (s[0]) {
        case 'M':
            P[0]++;
            break;
        case 'A':
            P[1]++;
            break;
        case 'R':
            P[2]++;
            break;
        case 'C':
            P[3]++;
            break;
        case 'H':
            P[4]++;
            break;
        default:
            break;
        }
    }

    int64_t count = 0;
    combination(P, 3, [&count](auto& v) {
            count += std::accumulate(std::begin(v), std::end(v), 1ULL, [](auto acc, auto nn) {
                    return acc*nn;
                });
        });

    #if 0
    // MAR--
    count += P[0]*P[1]*P[2];
    // MA-C-
    count += P[0]*P[1]*P[3];
    // MA--H
    count += P[0]*P[1]*P[4];
    // M-RC-
    count += P[0]*P[2]*P[3];
    // M-R-H
    count += P[0]*P[2]*P[4];
    // M--CH
    count += P[0]*P[3]*P[4];
    // -ARC-
    count += P[1]*P[2]*P[3];
    // -AR-H
    count += P[1]*P[2]*P[4];
    // -A-CH
    count += P[1]*P[3]*P[4];
    // --RCH
    count += P[2]*P[3]*P[4];
    #endif

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
def resolve():
    import sys
    n,x=map(int, input().split())
    l=list(map(int, input().split()))
    l.sort()
    cnt=0
    for i in range(n):
        if l[i]<=x:
            x-=l[i]
            cnt+=1
        else:
            break
    if cnt==n and x>0:
        cnt-=1
    print(cnt)
resolve()


Measured memory_bytes: 3060
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = Convert.ToInt32(line[0], 16);
        var y = Convert.ToInt32(line[1], 16);
        if (x < y) Console.WriteLine('<');
        else if (x == y) Console.WriteLine('=');
        else Console.WriteLine('>');
    }
}


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

using namespace std;

int n;

int main()
{
  cin >> n;

  int p;
  int l[n+1];
  fill_n(l, n+1, 0);
  for (int i = 0; i < n; i++) {
    cin >> p;
    l[p] = l[p-1] + 1;
  }

  int m = *max_element(l, l+n+1);

  cout << n - m << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
int k;
  cin>>k;
  int a,b,j,i;
  cin>>a>>b;
  for(i=a;i<=b;i++){
    for(j=0;j<=b;j++){
    if(k*j>=a&&k*j<=b){
      cout<<"OK"<<endl;
      return 0;
    }
    }
  }
  cout<<"NG"<<endl;
  return 0;
}


Measured memory_bytes: 3636
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
now = []
for i in range(n):
  j = raw[i][cnt[i]]
  if raw[j][cnt[j]] == i and i < j:
    now.append([i,j])
ans = 0
while now:
  #print(now)
  last = now
  now = []
  for x in last:
    i,j = x[0],x[1]
    cnt[i] += 1
    cnt[j] += 1
    if cnt[i] < n-1:
      k = raw[i][cnt[i]]
      if raw[k][cnt[k]] == i:
        now.append([i,k])
    if cnt[j] < n-1:
      k = raw[j][cnt[j]]
      if raw[k][cnt[k]] == j:
        now.append([j,k])
  ans += 1
if all( cnt[i] == n-1 for i in range(n) ):
  print(ans)
else:
  print(-1)

Measured memory_bytes: 37108
#include <iostream>
#include <stdio.h>
#define MAX 50
using namespace std;

int main(int argc, char *argv[])
{
    int n;
    int fib[MAX] = {0};
    fib[0] = 1;
    fib[1] = 1;
    scanf("%d", &n);
    if (n < 2)
    {
        printf("%d\n", 1);
        return 0;
    }

    for (int i = 2; i <= n; i++)
    {
        fib[i] = fib[i - 1] + fib[i - 2];
    }
    printf("%d\n", fib[n]);
    return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)(x).size()
#define ll long long
using namespace std;

ll verif(ll* a , int n){
      ll ans = 0;
      while(a[n] >= n){
            a[n] -= n;
            for(int i = 1; i <= n - 1; ++i) ++a[i];
            sort(a + 1 , a + n + 1);
            ++ans;
      }
      return ans;
}

int32_t main(){
      ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll k; cin >>k;
      int n = 50;
	ll a[n + 1]; for(int i = 1; i <= n; ++i) a[i] = k / n  +  i - 1;

	k %= n;
	while(k--){
            a[1] += n;
            for(int i = 2; i <= n; ++i) --a[i];

            sort(a + 1 , a + n + 1);
	}

	cout << n << '\n';
	for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
	cout << '\n';

      return 0;
}


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

using namespace std;

const int N = 100002;

vector<int> g[N];
int part[N];

int main() {
    memset(part, 255, sizeof(part));

    int n, m;
    scanf("%d%d", &n, &m);

    for (int i = 0; i < m; i++) {
        int a,b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    if (n < 4) {
        cout << 0 << endl;
        return 0;
    }

    int head = 0;
    vector<int> q;
    q.push_back(0);
    part[0] = 0;

    bool is2 = true;
    while ((head < q.size()) && is2) {
        int curr = q[head];
        head++;
        for (int j = 0; j < g[curr].size(); j++) {
            int next = g[curr][j];
            if (part[next] == -1) {
                part[next] = 1 - part[curr];
                q.push_back(next);
            } else {
                if (part[next] != (1 - part[curr])) {
                    is2 = false;
                    break;
                }
            }
        }
    }

    if (is2) {
        int cnt1 = 0;
        for (int i = 0; i < n; i++) {
            cnt1 += part[i];
            if (part[i] == -1) {
                cerr << i << " failed!" << endl;
            }
        }
        int cnt0 = n - cnt1;
        printf("%lld\n", 1LL * cnt0 * cnt1 - m);
    } else {
        printf("%lld\n", 1LL * n * (n-1) / 2 - m);
    }

    return 0;
}


Measured memory_bytes: 6784
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;

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


int main() {
	int n, m;
	cin >> n >> m;
	VI a(m);
	VI b(m);

	VI list1(0);
	VI list2(0);

	VI result(0);

	REP(i, m) {
		cin >> a[i];
		cin >> b[i];
		if (a[i] == 1) {
			list1.push_back(b[i]);
		}
		if (b[i] == n) {
			list2.push_back(a[i]);
		}
	}

	SORT(list1);
	SORT(list2);

	set_intersection(list1.begin(), list1.end(), list2.begin(), list2.end(), inserter(result, result.end()));

	if (result.size() == 0) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << "POSSIBLE" << endl;
	}

	return 0;
}



Measured memory_bytes: 2812
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 100010
#define MO 1000000007
#define LL long long
int x[MAXN],n,m;
bool vis[MAXN];
void task1()
{
	static int dp[100010][3];
	dp[0][0]=1;
	for(int i=1;i<=m;i++)
		vis[x[i]]=1;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0];
		dp[i][1]=(dp[i-1][0]+dp[i-1][1])%MO;
		dp[i][2]=((dp[i-1][0]+dp[i-1][1])%MO+(dp[i-1][1]+dp[i-1][2])%MO)%MO;
		if(!vis[i-1])
		{
			dp[i][0]=(dp[i][0]+dp[i-1][2])%MO;
			dp[i][1]=(dp[i][1]+dp[i-1][2])%MO;
			dp[i][2]=(dp[i][2]+dp[i-1][2])%MO;
		}
	}
	printf("%d\n",dp[n][2]);
}
struct node
{
	LL a[3][3];
}A,B,C,a,b,c,tmp;
void Mul(node &ret,node X,node Y)
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			tmp.a[i][j]=0;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
				tmp.a[i][j]=(tmp.a[i][j]+X.a[i][k]*Y.a[k][j]%MO)%MO;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			ret.a[i][j]=tmp.a[i][j];
}
void Pow(int X)
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			c.a[i][j]=C.a[i][j];
	while(X)
	{
		if(X&1) Mul(a,a,c);
		Mul(c,c,c);
		X>>=1;
	}
}
int f[3],g[3];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&x[i]);
	memset(A.a,0,sizeof A.a);
	memset(B.a,0,sizeof B.a);
	memset(C.a,0,sizeof C.a);
	A.a[0][0]=A.a[1][1]=A.a[2][2]=A.a[1][2]=A.a[0][2]=1;
	A.a[0][1]=2;
	B.a[0][0]=B.a[1][1]=B.a[2][2]=B.a[2][0]=1;
	Mul(C,A,B);
	f[0]=1;
	x[++m]=n;
	for(int l=1,pos=0;l<=m;l++)
	{
		int k=x[l]-pos-1;
		memset(b.a,0,sizeof b.a);
		memset(a.a,0,sizeof a.a);
		for(int i=0;i<3;i++)
			a.a[i][i]=1;
		if(k) Pow(k);
		Mul(b,a,A);
		for(int i=0;i<3;i++)
		{
			g[i]=0;
			for(int j=0;j<3;j++)
				g[i]=(g[i]+f[j]*b.a[j][i]%MO)%MO;
		}
		for(int i=0;i<3;i++)
			f[i]=g[i];
		pos=x[l];
	}
	printf("%d\n",f[2]);
}

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  
  if(b.at(0) == a.at(a.size()-1) && c.at(0) == b.at(b.size()-1)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
open Printf
open Scanf

let solve s =
  let l = [("SUN", 7);("MON", 6);("TUE", 5);("WED", 4);("THU", 3);("FRI",2);("SAT",1)] in
  List.assoc s l

let () =
  scanf "%s" solve |> printf "%d\n"


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using R = double;

// Combination Table
ll C[51][51];  // C[n][k] -> nCk

void comb_table(int N) {
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0 or j == i) {
        C[i][j] = 1LL;
      } else {
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
      }
    }
  }
}

int main(void) {
  int N, A, B;
  cin >> N >> A >> B;

  const int NMAX = 50;
  ll v[NMAX];

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

  comb_table(N);
  sort(v, v + N);
  reverse(v, v + N);

  R max_average = 0.0;
  for (int i = 0; i < A; ++i) {
    max_average += v[i];
  }
  max_average /= A;

  int a_th_val_num = 0, a_th_val_pos = 0;
  for (int i = 0; i < N; ++i) {
    if (v[i] == v[A - 1]) {
      a_th_val_num++;
      if (i < A) {
        a_th_val_pos++;
      }
    }
  }

  ll cnt = 0LL;
  if (a_th_val_pos == A) {
    for (a_th_val_pos = A; a_th_val_pos <= B; ++a_th_val_pos) {
      cnt += C[a_th_val_num][a_th_val_pos];
    }
  } else {
    cnt += C[a_th_val_num][a_th_val_pos];
  }

  cout << fixed << setprecision(12) << max_average << endl;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
cat<<EOF>Source.cpp

extern "C"{
int printf (const char *__restrict __format, ...);
int scanf (const char *__restrict __format, ...) ;
}
int max(int a,int b){
	return a>b?a:b;
}
int x[100000],y[100000],x_mod_k[100000],x_div_k[100000];
char s[100000][2];
int n,k;

void add(int*cnt,int x,int t){
	if((x_div_k[x]&1)==0){
		if(t==0){
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
		else{
			cnt[k-x_mod_k[x]]++;
		}
	}
	else{
		if(t==0){
			cnt[k-x_mod_k[x]]++;
		}
		else{
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
	}
}
int ans[2000];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d%d%s",&x[i],&y[i],s[i]);
		x_mod_k[i]=y[i]%k;
		x_div_k[i]=y[i]/k;
	}
	int Max=0;
	#pragma omp parallel for num_threads(2)
	for(int i=0;i<k;i++){
		int d=max(n,k);
		int cnt[d];
		for(int j=0;j<d;j++)cnt[j]=0;
		for(int j=0;j<n;j++){
			if(s[j][0]=='B'){
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,0);
				}
				else{
					add(cnt,j,1);
				}
			}
			else{
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,1);
				}
				else{
					add(cnt,j,0);
				}
			}
		}
		for(int j=0;j<k;j++){
			if(j)cnt[j]+=cnt[j-1];
			ans[i]=max(ans[i],max(cnt[j],n-cnt[j]));
		}
	}
	for(int i=0;i<k;i++)Max=max(Max,ans[i]);
	printf("%d\n",Max);
}
EOF
clang++ -Ofast Source.cpp -o Source -fopenmp -std=c++11
./Source

Measured memory_bytes: 10784
while True:
    n=int(input())
    if n==0:
        break
    else:
        sum=0
        sum+=(1000-n)//500
        sum+=(1000-n)%500//100
        sum+=(1000-n)%500%100//50
        sum+=(1000-n)%500%100%50//10
        sum+=(1000-n)%500%100%50%10//5
        sum+=(1000-n)%500%100%50%10%5//1
        print(sum)


Measured memory_bytes: 5588
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);

    int a = s.nextInt();
    int b = s.nextInt();

    if(b % a == 0){
      System.out.println(a+b);
    }else{
      System.out.println(b-a);
    }
  }
}


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

using namespace std;
typedef long long ll;

template <typename T>
map<T, int> primeFactorize(T n) {
  map<T, int> ans;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      ans[i]++;
    }
  }
  if (n > 1) {
    ans[n]++;
  }
  return ans;
}

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

  map<ll, int> p = primeFactorize(n);

  set<ll> st;
  ll ans = 0;
  for (auto &e: p) {
    ll cur = 0;
    while (e.second >= cur) {
      cur++;
      ll tmp = pow(e.first, cur);
      if (st.find(tmp) == st.end() && n % tmp == 0) {
	e.second -= cur;
	ans++;
	n /= tmp;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}



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

int main()
{
	int n,t=0;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
		while(1==1){
		for(int i=1;i<=n;i++){
			if (a[i]%2==1){
				cout<<t<<endl;
				return 0;
			}
			a[i]/=2;
		}
		t++;
	}                                                                                
}

Measured memory_bytes: 256
$dice1 = gets.split.map(&:to_i)
$dice2 = gets.split.map(&:to_i)

movelist = ["NNN", "", "W", "WWW", "NN", "N"]

def dicemove(i)
	if i == "N"
		temp = $dice2[0]
		$dice2[0] = $dice2[1]
		$dice2[1] = $dice2[5]
		$dice2[5] = $dice2[4]
		$dice2[4] = temp
	elsif i == "W"
		temp = $dice2[3]
		$dice2[3] = $dice2[1]
		$dice2[1] = $dice2[2]
		$dice2[2] = $dice2[4]
		$dice2[4] = temp
	end
end

#=begin
# Dice1 と 中央を揃える
cenidx = $dice2.index($dice1[1])

if cenidx == -1
	puts "No"
	exit
else
	moving = movelist[cenidx]
end

moving.chars do |i|
	dicemove(i)
end

# 背面が等しい値か、チェックする。
if $dice1[4] != $dice2[4]
	puts "No"
	exit
end

# 東西南北が等しい値か、チェックする
cross1 = [$dice1[0], $dice1[3], $dice1[5], $dice1[2]]	# 北, 西, 南, 東
cross2 = [$dice2[0], $dice2[3], $dice2[5], $dice2[2]]

cross2.rotate!(cross2.index(cross1[0]))

if cross1 == cross2
	puts "Yes"
else
	puts "No"
end





Measured memory_bytes: 6880
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;

int main()
{
    ll a,b,c;
    while(cin>>a>>b>>c)
    {
        set <ll> s;
        s.insert(a);
        s.insert(b);
        s.insert(c);
        if(s.size()==2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	int x = (h2 - h1) * 60 + (m2 - m1) - k;
	cout << x << endl;

	return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sfl(i,a,n) for (int i=a;i<n;i++)
#define ufl(i,a,n) for (int i=n-1;i>=a;i--)
#define SZ(x) ((int)(x).size())
#define endl '\n'
typedef long long ll;

ll power(ll a, ll b){
    ll res = 1;
    for(int i = 0; i<b; i++)
        res *= a;

    return res;
}

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main()
{
    init();
    long long n;
    cin>>n;
    long long ans=n*(n+1);
    cout <<ans/2;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,z;
pair<int,int> a[200010];//last,num
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)a[i].first=-1,a[i].second=n-i;
	for(int i=0;i<m;i++){
		cin>>z;z--;
		a[z].first=i;
	}
	sort(a,a+n);
	for(int i=n-1;i>=0;i--)cout<<n-a[i].second+1<<endl;
	return 0;
}

Measured memory_bytes: 4660
import sys
input = sys.stdin.readline

def main():
	n, k = map(int, input().strip().split())
	h = [0] * n
	for i in range(n):
		h[i] = int(input().strip())
	H = sorted(h)
	ans = 10**9
	for i in range(n-k+1):
		ans = min(ans, H[i+k-1]-H[i])
	print(ans)


if __name__ == '__main__':
	main()


Measured memory_bytes: 42460
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

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

int h, w;
vector<vector<char>> s;

void solve() {
	cin >> h >> w;
    s.assign(h, vector<char>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> s[i][j];
        }
    }
    int ans = 0;
    rep(i, h) {
        rep(j, w) {
            if(s[i][j] == '#') continue;
            vector<vector<int>> d(h, vector<int>(w, inf));
            d[i][j] = 0;
            queue<P> que;
            que.push(make_pair(i, j));
            while(que.size()) {
                P p = que.front(); que.pop();
                int x = p.fr, y = p.sc;
                rep(i, 4) {
                    int nx = x + dx[i], ny = y + dy[i];
                    if(0 <= nx && nx < h && 0 <= ny && ny < w && d[nx][ny] == inf && s[nx][ny] == '.') {
                        que.push(make_pair(nx, ny));
                        chmin(d[nx][ny], d[x][y] + 1);
                    }
                }
            }
            rep(x, h) {
                rep(y, w) {
                    if(d[x][y] != inf) chmax(ans, d[x][y]);
                }
            }
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0200();
	}
	
	class AOJ0200{
		int[] list;
		int cost[][]; //コスト
		int money[][];
		int time[][];
		int d[];//頂点sからの最短距離
		boolean used[];//素手に使用されたかのフラグ
		int V;//頂点数
		int INF;
		void dijkstra(int s,int k){
			if(k==0)cost = money;
			else cost = time;
			INF = Integer.MAX_VALUE;
			d = new int[V+1];
			used = new boolean[V+1];
			Arrays.fill(d,INF);
			Arrays.fill(used, false);
			d[s] = 0;
			while(true){
				int v=-1;
				for(int u=1;u<V+1;u++)if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
				if(v==-1)break;
				used[v]=true;
				for(int u=1;u<V+1;u++)d[u] = Math.min(d[u],d[v]+cost[v][u]);
			}
//			for(int i=1;i<d.length;i++)System.out.println(d[i]);
		}
		public AOJ0200() {
			while(true){
				int lines = in.nextInt();
				int station = in.nextInt();
				if(lines==0&&station==0)break;
				V = station;
				money = new int[V+1][V+1];
				time = new int[V+1][V+1];
				for(int i=0;i<V+1;i++){
					Arrays.fill(money[i],Integer.MAX_VALUE/2);
					Arrays.fill(time[i],Integer.MAX_VALUE/2);
				}
				for(int i=0;i<lines;i++){
					int a = in.nextInt();
					int b = in.nextInt();
					money[a][b] = money[b][a] = in.nextInt();
					time[a][b] = time[b][a] = in.nextInt();
				}
//				
//				for(int i=1;i<V+1;i++){
//					for(int s=1;s<V+1;s++)System.out.print(money[i][s]+" ");
//					System.out.println();
//				}
				
				int k = in.nextInt();
				for(int s=0;s<k;s++){
					int start = in.nextInt();
					int end = in.nextInt();
					int sw = in.nextInt();
					dijkstra(start, sw);
					System.out.println(d[end]);
				}
			}
		}
	}
	

	class ACR007{
		public ACR007() {
			String input = in.next();
			int N = input.length();
			boolean[] pattn = new boolean[N];
			for(int i=0;i<N;i++)pattn[i]= input.charAt(i)=='o'? true:false;
			int result = 0;
			for(int s = 0;s < (1<<N); s++){
				
			}
		}
	}

}

Measured memory_bytes: 95176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c=='a' || c=='e' || c=='i' || c=='o'|| c=='u'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3560
from sys import stdin
input = stdin.readline

n = int(input())
a = [int(x) for x in input().split()]
chk = [0] * 100001
now = sum(a)

for x in a:
    chk[x] += 1

for _ in range(int(input())):
    b, c = map(int, input().split())
    now = now - chk[b] * b + chk[b] * c
    chk[c] += chk[b]
    chk[b] = 0

    print(now)

Measured memory_bytes: 20328
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define N 5010
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
priority_queue<pii> q;
vector<int> g[N];int vis[N],a[N];
int gcd(int a,int b) { return a?gcd(b%a,a):b; }
int dfs(int x,int n)
{
	for(int y=1;y<=n;y++)
		if(!vis[y]&&gcd(a[x],a[y])>1)
			vis[y]=1,dfs(y,n),g[x].push_back(y);
	return 0;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);while(!q.empty()) q.pop();
	for(int i=1;i<=n;i++)
		if(!vis[i]) vis[i]=1,dfs(i,n),q.push(mp(a[i],i));
	while(!q.empty())
	{
		int x=q.top().second;
		q.pop(),printf("%d ",a[x]);
		for(int i=0;i<(int)g[x].size();i++)
			q.push(mp(a[g[x][i]],g[x][i]));
	}
	return !printf("\n");
}

Measured memory_bytes: 640