akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,k;
    cin >> n >> k;
    if(k == 1){
        cout << 0 << endl;
    }else{
        cout << n - k<< endl;
    }
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5]){
    cout << "Yes" << endl;
  }else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int a,b; cin >> a >> b;
	for(int i=0;i<=1000;i++){
		if(i*8/100==a&&i*10/100==b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n,m;
	scanf("%d %d", &n, &m);
	int left_max = 1;
	int right_min = 100000;
	int tmp_left, tmp_right;
	for ( int i = 0; i < m; i++ ) {
		scanf("%d %d", &tmp_left, &tmp_right);
		if ( tmp_left > left_max ) left_max = tmp_left;
		if ( tmp_right < right_min ) right_min = tmp_right;
	}
	int count = 0;
	for ( int i = 1; i <= n; i++ ) {
		if ( ( i >= left_max ) && ( i <= right_min ) ) count++;
	}
	printf("%d\n", count);
  	return 0;
}

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

int main(){
	long N;
	cin >> N;
	vector<long> A(N);
	for(int i=0; i<N; i++) cin >> A.at(i);

	// 挿入ソート
	long v;
	int j;
	for(int i=1; i<N; i++){
		for(int k=0; k<N; k++){
			cout << A.at(k);
			if(k<N-1) cout << " ";
		}
		cout << endl;

		v = A.at(i);
		j = i-1;
		while(j>=0 && A.at(j)>v){
			A.at(j+1) = A.at(j);
			j--;
		}
		A.at(j+1) = v;
	}

	for(int k=0; k<N; k++){
		cout << A.at(k);
		if(k<N-1) cout << " ";
	}
	cout<< endl;
}



Measured memory_bytes: 3096
import java.util.Scanner;

/**
 * https://arc091.contest.atcoder.jp/tasks/arc091_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		sc.close();
		
		long ans = 0;
		
		if(K==0){
			ans = N*N;
		}else{
			for(long b=N; b>0; b--){
				ans+=Math.max(0, (b-K)*(N/b));
				ans+=Math.max(0, N%b-K+1);
			}
		}
		System.out.println(ans);
	}

}

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

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

	const std::string S2 = S + S;

	const bool result = S2.find(T) != S2.npos;

	std::cout << (result ? "Yes" : "No") << std::endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
 
public class Main {
    public static void main(String[] args) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        try {
            String[] str = br.readLine().split(" ");
            int a = Integer.parseInt(str[0]);
            int b = Integer.parseInt(str[1]);
            if(a < b){
            System.out.println("a < b");
            }else if(a > b){
            System.out.println("a > b");
            }else{
            System.out.println("a == b");
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 24088
#include <iostream>
#include <queue>
#include <set>
#include <utility>
#include <string>
using namespace std;

int main() {
    queue<pair<int,int>> q;
    unsigned char r[1000][1000];
    for(int i = 0;i < 1000;i++)for(int j=0;j<1000;j++)r[i][j]=0;
    int h,w;
    cin >> h >> w;
    string buf;
    for(int y = 0;y < h;y++) {
        cin >> buf;
        for(int x = 0;x < w;x++) {
            if(buf[x] == '#') {
                q.push(make_pair(0,x*1000+y));
            } else {
                r[x][y] = 1;
            }
        }
    }
    int res = 0;
    pair<int,int> c;
    int f[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
    while(!q.empty()) {
        c.first = q.front().second;
        c.second = c.first % 1000;
        c.first = c.first / 1000;
        int n = q.front().first;
        res = max(res,n);
        for(int i = 0;i < 4;i++) {
            if(c.first+f[i][0] >= 0 && c.first+f[i][0] < 1000 && 
            c.second+f[i][1] >= 0 && c.second+f[i][1] < 1000 && 
            r[c.first+f[i][0]][c.second+f[i][1]] == 1) {
                q.push(make_pair(n+1,(c.first+f[i][0])*1000+(c.second+f[i][1])));
                r[c.first+f[i][0]][c.second+f[i][1]] = 0;
            }
        }
        q.pop();
    }
    cout << res << endl;
}

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

signed main() {
  int N;
  cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  string s="first";
  string t="second";
  for(int i=0;i<N;i++)if(v[i]%2)t=s;
  cout<<t<<endl;
}


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

int main() {
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    double ans = W * H;
    ans = ans / 2.0;
    cout << ans << " ";
    if(W == x*2 && H == y*2){
        cout << 1;
    } else{
        cout << 0;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import deque

def main():
    n = II()
    cnt = 0
    dq = deque(['3', '5', '7'])
    while dq:
        d = dq.popleft()
        if int(d) > n: break
        if '7' in d and '5' in d and '3' in d:
            cnt += 1
        dq.append(d+'3')
        dq.append(d+'5')
        dq.append(d+'7')
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7532
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define rad M_PI/3
#define N 2147483647
#define Max 500000
#define NTL -1
#define min(a,b) ((a>b)?b:a)

int main(){
  char str[20];
  int i;
  scanf("%s",str);
  i=strlen(str)-1;
  for(;i>=0;i--){
    printf("%c",str[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2028
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    string s1,s2; cin>>s1>>s2;
    ll ans,cnt=0;
    if(s1[0]==s2[0]){
        ans=3; cnt++;
    }
    else{
        ans=6; cnt+=2;
    }
    while(cnt<n){
        if(s1[cnt]==s2[cnt]){
            if(s1[cnt-1]==s2[cnt-1]) ans=(ans*2)%MOD;
            cnt++;
        }
        else{
            if(s1[cnt-1]==s2[cnt-1]) ans=(ans*2)%MOD;
            else ans=(ans*3)%MOD;
            cnt+=2;
        }
    }
    cout<<ans<<endl;
}

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


int main() {
    int n, m;
    cin >> n >> m;
    int a[101];
    int votes = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        votes += a[i];
    }

    int cnt = 0;
    double limit = (double) votes / (4 * m);
    for (int i = 0; i < n; i++) {
        if (a[i] >= limit) cnt++;
    }
    if (cnt >= m) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  int s=S.size();
  vector<int> a;
  if(S[0]=='0'){a.push_back(0);}
  for(int i=0;i<s;i++){
    if(S[i]=='0'){
      int cnt=1;
      while(S[i+1]=='0'){cnt++; i++;}
      a.push_back(cnt); 
    }
    else{
      int cnt2=1;
      while(S[i+1]=='1'){cnt2++; i++;}
      a.push_back(cnt2); 
    }
  }
  a.push_back(0);
  int sum=0; 
  int A=a.size();
  for(int i=0;i<min(A,2*K+1);i++){sum+=a[i];}
  int M=sum;
  for(int i=0;i+2*K+2<a.size();i+=2){
    sum-=a[i]+a[i+1];
    sum+=a[i+2*K+1]+a[i+2*K+2];
    M=max(M,sum);
  }
  cout << M << endl;
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007

const ll INF=100000;

int main(){
  string s,t;
  cin  >> s >>t;
  string ans="No";
  rep(i,s.size()){
    if(s==t){
      ans="Yes";
      break;
    }
    s=s.back()+s.substr(0,s.size()-1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const ll INF = 1e10;

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

    ll N;
    cin >> N;
    vector<ll> h(N);
    Rep (i, N) cin >> h[i];

    vector<ll> dp(N, INF);
    dp[0] = 0;
    Rep (i, N) {
        if (i + 1 < N) dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        if (i + 2 < N) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }

    // for (auto e : dp) cout << e << "\n";

    cout << dp[N-1] << "\n";
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
int solve() {
	cin >> n;
	a.resize(n);
	vl hen;
	REP(i, n){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	REP(i, n-1){
		if(a[i] == a[i+1]){
			hen.push_back(a[i]);
			i++;
		}
	}
	if(hen.size() < 2){
		cout << 0 << endl;
		return 0;
	}
	sort(hen.begin(), hen.end(), greater<ll>());
	cout << hen[0] * hen[1] << endl;

	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 1660
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    string t;
    cin >> t;
    int cnt = 0;
    ll res = 0;
    for(int i = (int)t.size() - 1; i >= 0 ; i -- ){
        if(t[i] == 'B'){
            res += cnt;
        }
        else{
            cnt ++ ;
        }
    }
    cout << res;
    return 0;
}

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

        while(true) {
            String line = scan.nextLine();
            if("0".equals(line)) {
                break;
            }

            char[] swap = line.toCharArray();
 
            int sum = 0;
            for(int i = 0; i < swap.length; i++) {
                sum += Character.getNumericValue(swap[i]);
            }

            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26936
def min(a,b); a < b ? a : b; end
def max(a,b); a > b ? a : b; end

N, M = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }

Q = Array.new(N + 1, 0.0); Q[1] = 1.0
dp = 2.times.map{ Array.new(N + 1, 0.0) } 

M.times do
  s,t = gets.split.map(&:to_i)
  G[s] << t
end

(1 ... N).reverse_each do |s|
  dmax = 0.0
  sum = 0.0
  
  G[s].each do |t| 
    sum += dp[0][t]
    dmax = max(dp[0][t], dmax)
  end

  dp[0][s] = sum / G[s].size + 1.0

  if G[s].size == 1
    dp[1][s] = dp[0][s]
  else
    dp[1][s] = (sum - dmax) / (G[s].size - 1) + 1.0
  end
end

(1 ... N).each do |s|
  q = Q[s] / G[s].size
  G[s].each{|t| Q[t] += q }
end

ans = (1 ... N).inject(dp[0][1]) do |d_, s|
  min(d_, dp[0][1] + Q[s] * (dp[1][s] - dp[0][s]))
end

puts ans


Measured memory_bytes: 4092
#include <iostream>
#include <cstdint>
#include <cstdint>

using namespace std;

const u_int64_t R = 1'000'000'007;
bool broken[100'000];
u_int64_t way[100'000];

int main()
{
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; i++)
    {
        broken[i] = false;
    }
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        a--;
        broken[a] = true;
    }

    way[0] = broken[0] ? 0 : 1;
    way[1] = broken[1] ? 0 : way[0] + 1;

    for (int i = 2; i < n; i++)
    {
        u_int64_t w = (way[i - 1] + way[i - 2]) % R;
        way[i] = broken[i] ? 0 : w;
    }

    cout << way[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;

int main(){
    int N,W;cin >> N >> W;
    vector<LL> w(N),v(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    vector<LL> dp(200000,LINF);
    dp[0]=0;
    for (int i = 0; i < N; i++) {
        for (int j = 100000; j >= 0; j--) {
            if(j+v[i]<=100000) dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
        }
    }
    for (int i = 100000; i >= 0; i--) {
        if(dp[i]<=W){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 1792
// AOJ ALDS1_3_B Queue
// 2018.4.30 bal4u

#include <stdio.h>

#define MAX_N 100002

typedef struct { char *p; int tm; } Q;
Q que[(MAX_N<<1)+2]; int top, end;
char name[MAX_N][20];

char buf[20], *p;
int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int  n, q, tm, i;
	Q  t;

	fgets(p=buf, 20, stdin);
	n = in(), q = in();
	for (i = 0; i < n; i++) {
		fgets(p=name[i], 20, stdin);
		while (*p > ' ') p++; *p++ = 0;
		que[i].p = name[i], que[i].tm = in();
	}

	tm = 0, top = 0, end = n;
	while (top != end) {
		t = que[top]; if (++top == MAX_N) top = 0;
		if (t.tm <= q) {
			printf("%s %d\n", t.p, tm+t.tm);
			tm += t.tm;
		} else {
			t.tm -= q;
			que[end] = t; if (++end == MAX_N) end = 0;
			tm += q;
		}
	}
	return 0;
}




Measured memory_bytes: 4192
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int left_length,right_length,max,tmp,left_start,left_end,right_start,right_end,k;
	char left[4001],right[4001];

	while(scanf("%s",left) != EOF){
		scanf("%s",right);

		for(left_length = 0;left[left_length] != '\0';left_length++);
		for(right_length = 0; right[right_length] != '\0';right_length++);

		max = 0;
		if(right_length > left_length){

			for(right_end = 1;right_end <= left_length;right_end++){
				tmp = 0;
				for(left_start = left_length-right_end,k=0; k < right_end; k++){
					if(left[left_start+k] == right[k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			for(right_end = left_length;right_end < right_length;right_end++){
				tmp = 0;
				for(right_start = right_end-left_length,k=0;right_start + k < right_end; k++){
					if(left[k] == right[right_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			for(left_end = left_length-1;left_end >= 1; left_end--){
				tmp = 0;
				for(right_start = right_length-left_end,k=0;k < left_end; k++){
					if(left[k] == right[right_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			printf("%d\n",max);

		}else{

			for(left_end = 1;left_end <= right_length;left_end++){
				tmp = 0;
				for(right_start = right_length-left_end,k=0; k < left_end; k++){
					if(right[right_start+k] == left[k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			for(left_end = right_length;left_end < left_length;left_end++){
				tmp = 0;
				for(left_start = left_end-right_length,k=0;left_start + k < left_end; k++){
					if(right[k] == left[left_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			for(right_end = right_length-1;right_end >= 1; right_end--){
				tmp = 0;
				for(left_start = left_length-right_end,k=0;left_start + k < left_length; k++){
					if(right[k] == left[left_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			printf("%d\n",max);
		}
	}

	return 0;
}

Measured memory_bytes: 2668
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N, M, Q = map(int, input().split())
    S = [[0] * (N+1) for _ in range(N+1)]
    for i in range(M):
        L, R = map(int, input().split())
        S[L][R] += 1

    for i in range(1,N+1):
        for j in range(1,N+1):
            S[i][j] += S[i-1][j] + S[i][j-1] - S[i-1][j-1]

    for i in range(Q):
        p, q = map(int, input().split())
        ans = S[q][q] - S[q][p-1] - S[p-1][q] + S[p-1][p-1]
        print(ans)
    



main()

Measured memory_bytes: 55132
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main()
{
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 0){
        cout << (a + b) / 2 << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)

Int N;
Int F[100][5][2];
Int P[100][11];
Int eigyo[5][2];

Int solve(Int x,Int y){ //x:カウント y:営業
	eigyo[x/2][x%2]=y;
	if(x==9){
		Int check =0;
		for(Int j=0;j<10;j++){
			if(eigyo[j/2][j%2] ==0)
			check+=1;
		}
		if (check ==10)return -1000000000000;


		Int reword =0;
		for(Int i=0;i<N;i++){
			Int count =0;
			for(Int j=0;j<10;j++){
				if(eigyo[j/2][j%2] ==1 && F[i][j/2][j%2]==1)
				count+=1;
			}
			reword+=P[i][count];
		}
		return reword;
	}else{
		return max(solve(x+1,0),solve(x+1,1));
	}

}

int main(){
	
	cin >> N;

	for(Int i=0;i<N;i++){
		for(Int j=0;j<5;j++){
			cin >> F[i][j][0]>> F[i][j][1];
		}
	}
	
	for(Int i=0;i<N;i++){
		for(Int j=0;j<=10;j++){
			cin >> P[i][j];
		}
	}
	
	Int res = max(solve(0,0),solve(0,1));
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  vii A(H,vi(W));
  rep(i,0,H){
    cin>>S[i];
    int count=0;
    rep(j,0,W){
      if(S[i][j]=='.')
        count++;
      else{
        rep(k,j-count,j)
          A[i][k]=count;
        count=0;
        }
      }
    rep(k,W-count,W)
      A[i][k]=count;
    }
  rep(i,0,W){
    int count=0;
    rep(j,0,H){
      if(S[j][i]=='.')
        count++;
      else{
        rep(k,j-count,j)
          A[k][i]+=count;
        count=0;
        }
      }
     rep(k,H-count,H)
        A[k][i]+=count;
    }
  int ans=0;
  rep(i,0,H){
    rep(j,0,W)
      ans=max(ans,A[i][j]-1);
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

vector<ll> bit(ll n){
    ll div = 2;
    vector<ll> rtn(50,0);
    int i = 0;
    int cnt = 0;
    while(cnt==0){
        if(n/div==0)cnt++;
        ll k = (n/div)*div/2 + (n%div>div/2?n%div-div/2:0);
        rtn[i] = k;
        i++;
        div *= 2;
    }
    return rtn;
}


int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    vector<ll> A = bit(a);
    vector<ll> B = bit(b+1);
    for(int i = 0; i < 50; i++){
        if((B[i]-A[i])%2==1) ans += pow(2,i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
H, W, A, B = map(int, input().split())
MOD = 10**9 + 7

class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

comb = Combination(H + W + 100)

ans = 0

for b in range(B + 1, W + 1):
    ans += comb.ncr(H - A - 1 + b - 1, b - 1) * comb.ncr(A - 1 + W - b, A - 1)
    ans %= MOD

print(ans)

Measured memory_bytes: 28340
#D
N=int(input())
mylist=list(map(int, input().split()))
i=1
j=0
count=0

while j<N:
    if mylist[j]==i:
        count+=1
        i+=1
        j+=1
        #print("if"+str(i)+","+str(j))
    else:
        j+=1
        #print("else"+str(i)+","+str(j))

if count==0:
    print(-1)
else:
    print(N-count)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  vi arr(n);
  rep(i,n) cin >> arr[i];

  sort(all(arr));

  int ans = 0;
  int count = 1;

  rep(i,n-1) {
    if (arr[i+1] == arr[i]) ++count;
    else {
      if (arr[i] > count) ans += count;
      else if (arr[i] < count) ans += count - arr[i];
      count = 1;
    }
  }

  if (arr[n-1] > count) ans += count;
  else if (arr[n-1] < count) ans += count - arr[n-1];

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


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

int main(){
  int n, x = 0, res = 0;
  string s;
  cin >> n >> s;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I') x++;
    if(s[i] == 'D') x--;
    res = max(res, x);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

ll comb(ll num){
  if(num<=1)return 0LL;
  return (num*(num-1))/2;
}

int main(){
  int n, m;cin>>n>>m;
  vector<int> a(n), s(n);
  map<int, int> cnt;
  rep(i, n){
  	int tmp;cin>>tmp;
    a[i]=tmp%m;
    if(i==0)s[i]=a[i];
    else s[i]=(s[i-1]+a[i])%m;
    cnt[s[i]]++;
  }
  ll ans=0LL;
  ans+=cnt[0];
  for(auto itr=cnt.begin();itr!=cnt.end();itr++){
    // cout<<itr->first<<" "<<itr->second<<" ->"<<comb(ll(itr->second))<<endl;
  	ans+=comb(ll(itr->second));
  }
  cout<<ans<<endl;
  return 0;
}



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

void bubbleSort(string array[],int n){
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(array[j][1]<array[j-1][1]){
				string tmp;
				tmp = array[j-1];
				array[j-1]=array[j];
				array[j]=tmp;
			}
		}
	}
}

void selectionSort(string array[],int n){
	for(int i=0;i<n;i++){
		int minj=i;
		for(int j=i;j<n;j++){
			if(array[minj][1]>array[j][1]){
				minj=j;
			}
		}
		if(minj!=i){
			string tmp;
			tmp = array[minj];
			array[minj]=array[i];
			array[i]=tmp;
		}
	}
}

bool is_stable(string card[],string array[],int n){
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int a=0;a<n;a++){
				for(int b=a+1;b<n;b++){
					if((card[i][1]==card[j][1])&&(card[i]==array[b])
					&&(card[j]==array[a])){
						return false;
					}
				}
			}
		}
	}
	return true;
}

int main() {
	// your code goes here
	int n;
	cin>>n;
	string card[36];
	string cardb[36];
	string cards[36];
	//input
	for(int i=0;i<n;i++){
		cin>>card[i];
		cards[i]=card[i];
		cardb[i]=card[i];
	}
	//BubbleSort
	bubbleSort(cardb,n);
	//output
	for(int i=0;i<n;i++){
		if(i>0){
			cout<<" ";
		}
		cout<<cardb[i];
	}
	cout<<endl;
	
	if(is_stable(card,cardb,n)){
		cout<<"Stable"<<endl;
	}else{
		cout<<"Not stable"<<endl;
	}
	//SelectionSort
	selectionSort(cards,n);
	//output
	for(int i=0;i<n;i++){
		if(i>0){
			cout<<" ";
		}
		cout<<cards[i];
	}
	cout<<endl;
	
	if(is_stable(card,cards,n)){
		cout<<"Stable"<<endl;
	}else{
		cout<<"Not stable"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include<string>//...........................
#include<cstdio>//....../%/........./%/......
#include<iostream>//.../%/........./%/.......
#include<algorithm>//./%/........./%/........
#include<cmath>//..../%/........./%/.........
#include<cstring>//./%/_______../%/_______...
#include<queue>//../=========/./=========/...
#include<set>//.....................½ñ¤¬×î¸ß£¡
#define mem(s,t) memset(s,t,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define MAXINT 0x7fffffff
#define INF 0x3f3f3f3f
typedef long long LL;
using namespace std;
//define begin
const int MAXN=100010;
const int MAXM=200010;


//define end
//function begin



//function end

int main()
{
    int a,b,c,x,y,t,ans;
    while(cin>>a>>b>>c>>x>>y){
        if(2*c>a+b){
            cout<<a*x+b*y<<endl;
        }
        else {
            ans=a*(x-min(x,y))+b*(y-min(x,y))+2*c*min(x,y);
            if(ans>2*c*max(x,y))ans=2*c*max(x,y);
            cout<<ans<<endl;
        }
    }

    return 0;
}
















/* ¦Ì'sic forever! */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    map<string,int> s;
    rep(i,n){
        string t;
        cin >> t;
        s[t]++;
    }
    int mx=0;
    for(auto x:s)chmax(mx,x.S);
    for(auto x:s){
        if(x.S==mx)cout << x.F << endl;
    }
    


}

/*



 */



Measured memory_bytes: 25216
n, k = map(int, input().split())
a = list(map(int, input().split()))
test_pos = 1
sub = 0
loop = 0
city = [0 for i in range(n)]
while True:
    test_pos = a[test_pos-1]
    city[test_pos-1] += 1
    sub += 1
    if city[test_pos-1] == 2:
        loop_start = test_pos
        break

while True:
    test_pos = a[test_pos-1]
    loop += 1
    if test_pos == loop_start:
        break
if k > sub:
    k -= sub
    k %= loop
    pos = loop_start
    for i in range(k):
        pos = a[pos-1]
    print(pos)
else:
    pos = 1
    for i in range(k):
        pos = a[pos - 1]
    print(pos)


Measured memory_bytes: 32284
//2017-7-10 22:54
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n, a, b, c, d;

int main(){
	while(~scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &c, &d)){
		bool flag = false;
		for(int i = 1; i <= n - 1; i++){
			LL add = i, del = (n - 1) - i;
			LL up = a, dn = a;
			up += add * d, dn += add * c;
			up -= del * c, dn -= del * d;
			if(b <= up && b >= dn) flag = true;
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}
			

Measured memory_bytes: 128
N = int(input())
a = list(map(int, input().split()))
count = 0
End = 0
while End == 0:
    for i in range(N):
        if a[i] % 2 != 0:
            End = 1
    if End == 1:
        break
    
    c = 0
    for i in range(N):
        a[i] = a[i]/2
        c += 1    
    if c == N:
        count += 1
print(count)

Measured memory_bytes: 3064
#include <stdio.h>

class Dice4{
public:
	int number[6];

	void roll(char dst){
		switch(dst){
		case 'E':
			setNumber(number[3],number[1],number[0],number[5],number[4],number[2]);
			break;
		case 'N':
			setNumber(number[1],number[5],number[2],number[3],number[0],number[4]);
			break;
		case 'S':
			setNumber(number[4],number[0],number[2],number[3],number[5],number[1]);
			break;
		case 'W':
			setNumber(number[2],number[1],number[5],number[0],number[4],number[3]);
			break;
		}
	};

	bool isSameDice(int inputed[]){
		char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < 24; i++){
			roll(order[i]);
			for(int j = 0; j < 6; j++){
				if(inputed[j] != number[j])
					break;
				if(j == 5)
					return true;
			}
		}
		return false;
	}

private:
	void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

};

int main(){
	int n,k,j;
	scanf("%d",&n);
	Dice4 array[n];
	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d %d %d",&array[i].number[0],&array[i].number[1],&array[i].number[2],
				&array[i].number[3],&array[i].number[4],&array[i].number[5]);
	}
	for(k = 0; k < n-1; k++){
		for(j = k+1; j < n; j++){
			if(array[k].isSameDice(array[j].number))
				break;
		}
		if(j < n) break;
	}
	if(k == n-1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}



Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
const int N=3050;
typedef long long ll;
const ll mod=1000000007;
const ll inv=500000004;
int n,q,ai[N];
ll dp[N][N],ans,pl;

inline ll KSM(ll a,ll p){
	ll ret=1;
	while(p){
		if(p&1) ret=ret*a%mod;
		a=a*a%mod;
		p>>=1;
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&q);
	pl=KSM(2,q);
	for(int i=1;i<=n;i++)
		scanf("%d",&ai[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(ai[i]>ai[j])
				dp[i][j]=1;
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		if(x>y) swap(x,y);
		dp[x][y]=dp[y][x]=((dp[x][y]+dp[y][x])%mod)*inv%mod;
		for(int i=1;i<=n;i++){
			if(i==x || i==y) continue;
			dp[i][x]=dp[i][y]=((dp[i][y]+dp[i][x])%mod)*inv%mod;
			dp[x][i]=dp[y][i]=((dp[y][i]+dp[x][i])%mod)*inv%mod;
		}
//		for(int i=1;i<=n;i++)	
//		{
//			for(int j=1;j<=n;j++)
//				cout<<dp[i][j]<<" ";
//			cout<<endl;
//		}
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans=(dp[i][j]+ans)%mod;
	ans=ans*pl%mod;
	ans=(ans+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 75296
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		char[] s = S.toCharArray();
		char[] t = T.toCharArray();
		int slen = s.length;
		int tlen = t.length;
		
		//答えansを仮置きする。
		//これが十分に大きくないと不正解となるので、
		//この値なら絶対に正しい答えが出る、という値を仮置きすること
		int ans = tlen;
		
		for(int start = 0; start <= slen-tlen; start++){
			int diff = 0;
			for(int i = 0; i < tlen; i++){
				if(t[i] != s[start+i]){
					diff++;
				}
			}
			ans = Math.min(ans, diff);
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
int const INF = 1001001001;



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

ll N;
cin >> N;

auto dig = [&](ll c) {
    ll res = 0;
    while (c) {
        c /= 10;
        ++res;
    }
    return res;
};

ll ans = dig(N);
for(ll i = 1; i * i <= N; ++i) {
    if(N%i == 0) {
        ll cur = max(dig(i), dig(N/i));
        chmin(ans, cur);
    }
}
cout << ans << endl;
return 0;
}

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

int main() {
    char s;
    cin>>s;
    if(s=='A') cout<<'T'<<endl;
    if(s=='T') cout<<'A'<<endl;
    if(s=='C') cout<<'G'<<endl;
    if(s=='G') cout<<'C'<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
lr = [] # 各アームの左端と右端の位置のペア
for _ in range(n):
    x, l = list(map(int, input().split()))
    lr.append((x-l, x+l))

# 右端位置でソート
lr.sort(key=lambda x:x[1])

ans = 0
right = -10**9
for l,r in lr:
    # 重なってないなら残す
    if l >= right:
        ans += 1
        right = r

print(ans)

Measured memory_bytes: 23860
#include <iostream>

using namespace std;

int main()
{
    int n,sidesum=0,m=0;
    int input;
    cin>>n;
    cin>>input;
    m=input;
    n-=1;
    sidesum+=input;
    while(n--){
        cin>>input;
        sidesum+=input;
        if(m<input) m=input;
    }
    if(2*m>=sidesum) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  READ(N);
  
  // main procedure
  string hon_reading;
  switch(N % 10) {
    case 3:
      hon_reading = "bon";
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      hon_reading = "pon";
      break;
    default:
      hon_reading = "hon";
      break;
  }

  // output
  WRITE_N(hon_reading);

  return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;;
ll asc_cmp(ll x,ll y){if(x<y)return -1;else if(x==y)return 0;else return 1;}
ll desc_cmp(ll x,ll y){if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    int n,k;scanf("%d %d",&n,&k);
    int p[n];for(int i=0;i<n;i++)scanf("%d",&p[i]);

    ll csum[300000]={};
    for(int i=0;i<n;i++){
        csum[i+1]=csum[i]+p[i];
    }
    int start,max;
    max=-1;
    for(int i=k;i<=n;i++){
        if(csum[i]-csum[i-k]>max){
            max=csum[i]-csum[i-k];
            start=i-k;
        }
    }
    //printf("max:%d start:%d\n",max,start);

    int sum=0;
    double ans=0;
    for(int i=start;i<start+k;i++){
        sum=0;
        for(int j=1;j<=p[i];j++)sum+=j;
        ans+=sum/(double)p[i];
    }
    printf("%.12lf\n",ans);
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
int a[600010],n;
long long s;
int main()
{
    scanf("%d",&n);
    for(int i=3*n;i;--i)scanf("%d",&a[i]);
    std::sort(a+1,a+3*n+1);
    for(int i=1;i<=n;++i)s+=a[3*n-2*i+1];
    printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 1408
def main():

    N = int(input())
    d = dict()
    for _ in range(N):
        s = input()
        d[s] = d.get(s, 0) + 1
    max_c = 0
    for s in d:
        max_c = max(max_c, d[s])
    ans = []
    for s in d:
        if d[s] == max_c:
            ans.append(s)
    ans.sort()
    for s in ans:
        print(s)


if __name__ == '__main__':
    main()


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

int main()
{
    int n;
    cin>> n;
    string s;
    cin >> s;
    
    if(s.size()<=n)
    cout << s;
    else{
        s.erase(s.begin()+n,s.end());
        s.push_back('.');
        s.push_back('.');
        s.push_back('.');
        cout << s;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
#define int long long
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    
    int n;
    cin >> n;
    
    vector<int> b(n - 1);
    for(int i = 0; i < n - 1; ++ i)
    {
        cin >> b[i];
    }
    
    vector<int> a(n);
    a[0] = b[0];
    a[n - 1] = b[n - 2];
    
    for(int i = 1; i <= n - 2; ++ i)
    {
        a[i] = min(b[i], b[i - 1]);
    }
    
    
    int sum = 0;
    for(int i = 0; i < n; ++ i)
    {
        sum += a[i];
    }
    
    cout << sum << endl;
    
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    vector< int > v(n);
    for(int i=0;i<n;i++)    cin >> v[i];
    int k = 1;
    for(int i=0;i<n;i++){
        if(v[i] == k) k++;
    }
    if(k==1)    cout << -1 << endl;
    else    cout << n - k + 1 << endl;
}


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

using namespace std;



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

	long long N, A, B;
	cin >> N >> A >> B;

	if (A == 0) {
		cout << 0 << '\n';
		return 0;
	}
	else if (B == 0) {
		cout << N << '\n';
		return 0;
	}

	long long x = N / (A + B);
	long long r = x * A; // a b a b |____|

	long long y = N % (A + B);

	r += min(y, A);

	cout << r << '\n';


	return 0;	
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Threading;
using System.Xml.Serialization;

namespace AtCoderCs
{

    class Program
    {

        const int mod = 1000000007;

        static void Main()
        {

            var res = new int[100];
            for (int i = 0; i < 100; i++)
                res[i] = i * i;

            var num = int.Parse(Console.ReadLine());

            var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var min = int.MaxValue;

            for (int j = 1, result; j <= 100; j++)
            {

                result = 0;
                for (int i = 0; i < num; i++)
                    result += res[Math.Abs(args[i] - j)];

                if (result < min) min = result;

            }

            Console.WriteLine(min);

        }



    }
}


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

int main(){
	char s;
	vector<int> num(4);
	for(int i=0; i < 4; i++) {
		scanf(" %c", &s);
		num.at(i) = s - '0';
	}
	for(int i=0; i < (1 << 3); i++) {
		int sum = num.at(0);
		string res = "";
		res += to_string(num.at(0));
		for(int j=1; j < 4; j++) {
			if(i & (1 << (j-1))) {
				sum -= num.at(j);
				res += "-" + to_string(num.at(j));
			}else{
				sum += num.at(j);
				res += "+" + to_string(num.at(j));
			}
		}
		if(sum == 7) {
			cout << res + "=7" << "\n";
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>

#define MAX_N 100

int search(int target, int end) {
  int hi = end, low = 0;
  
  while (low <= hi) {
    int mid = (hi - low) / 2 + low;
    if (target > mid) {
      low = mid + 1;
    } else if (target < mid) {
      hi = mid - 1;
    } else {
      return mid;
    }
  }
  
  return -1;
}

int main() {
  using namespace std;
  
  int K, S;
  cin >> K >> S;
  
  int n = 0;
  for(int i = 0; i <= K; ++i) {
    if (i > S) break;
    for(int j = 0; j <= K; ++j) {
      if (i + j > S) break;
      if (search(S - i - j, K) != -1) {
        ++n;
      }
    }
  }
  
  cout << n << "\n";
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <complex>
#include <utility>
#include <algorithm>
using namespace std;

typedef complex<int> Point;

int dis(Point a, Point b){ return abs(a - b); }
int compass(Point a, Point b, Point c){
  if(a.real() < b.real() && c.imag() < b.imag()){ return 1; }
  if(a.imag() < b.imag() && c.real() > b.real()){ return 1; }
  if(a.real() > b.real() && c.imag() > b.imag()){ return 1; }
  if(a.imag() > b.imag() && c.real() < b.real()){ return 1; }
  return -1;
}

int main(void){
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }
    ++n;
    
    // ??\??????????????????
    vector<vector<Point> > input(n);
    for(int i = 0; i < n; i++){
      int m;
      cin >> m;
      for(int j = 0; j < m; j++){
        int x, y;
        cin >> x >> y;
        input[i].push_back(Point(x, y));
      }
    }

    // ?????¢??¨???????????????????????????????????????
    vector<vector<int> > poly(n);
    for(int i = 0; i < n; i++){
      for(int j = 1; j < (int)input[i].size(); j++){
        poly[i].push_back(dis(input[i][j - 1], input[i][j]));
        if(j + 1 < (int)input[i].size()){
          poly[i].push_back(compass(input[i][j - 1], input[i][j], input[i][j + 1]));
        }
      }
    }

    // ?????´??????
    for(int i = 1; i < n; i++){
      if(poly[i].size() != poly[0].size()){ continue; }
      if(poly[i] == poly[0]){ cout << i << endl; }
      else{
        reverse(poly[i].begin(), poly[i].end());
        for(int j = 1; j < (int)poly[i].size(); j += 2){ poly[i][j] *= -1; }
        if(poly[i] == poly[0]){ cout << i << endl; }
      }
    }

    cout << "+++++" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3140
#include<stdio.h>

int main(){
  int h1, h2, h3;
  int d;

  h1 = h2 = h3 = 0;

  while (scanf("%d", &d) != EOF) {
    if (d > h1) {
      h3 = h2;
      h2 = h1;
      h1 = d;
    }
    else if (d > h2) {
      h3 = h2;
      h2 = d;
    }
    else if (d > h3) {
      h3 = d;
    }
  }

  printf("%d\n%d\n%d\n", h1, h2, h3);

  return 0;
}

Measured memory_bytes: 596
from collections import deque

def bfs(sx, sy, gx, gy):
  dist = [[0]*w for i in range(h)] #全頂点を未訪問
  que = deque([(sy,sx)])   #初期条件
  dist[sy][sx] = 1 #start訪問済み
  directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
  while que:
    y,x = que.popleft()
    for dirs in directions:
      ny = y + dirs[0] 
      nx = x + dirs[1]
      if not(0<=ny<h and 0<=nx<w):
        continue
      if G[ny][nx] == "#":
        continue
      if dist[ny][nx] == 0:
        dist[ny][nx] = dist[y][x] + 1
        que.append((ny, nx))
      if nx == w-1 and ny == h-1:
        return dist[gy][gx]   
  return -1

h,w = map(int,input().split())
G = [input() for i in range(h)]

cnt = 0
for i in range(h):
    cnt += G[i].count('#')
    
ans = bfs(0,0,w-1,h-1)
if ans == -1:
  print(-1)
else:
  score = h * w - cnt - ans
  print(score)


Measured memory_bytes: 3316
// う　し　た　ぷ　に　き　あ　く　ん　笑

// 問題考察
// 条件を満たすためには、特定のマスに同じ文字を書かなければならない。
// h,wを変えて小さいh,wでシミュレーションをしたところ、同じ文字でなければならないマスが何個あるかわかった。

// h,wが偶数のとき
// 同じ文字が書かれた4マス h*w/4個

// hが偶数、wが奇数（逆なら転置して）
// 同じ文字が書かれた4マス h*(w-1)/4個
// 同じ文字が書かれた2マス h*1/2個

// h,wが奇数
// 同じ文字が書かれた4マス (h-1)*(w-1)/4個
// 同じ文字が書かれた2マス (h-1+w-1)/2個
// 同じ文字が書かれた1マス 1個

// 式を簡潔に書き表す
// hh = h-h%2, ww = w-w%2
// 4 hh*ww/4
// 2 (h%2*ww+w%2*hh)/2
// 1 (h%2)*(w%2)

// 後はAの文字を数えて↑に割り当てて行けばいい
// 4マス→2マス、1マスの順で割り当てていく

#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int h, w;
    cin >> h >> w;

    array<int, 'z' - 'a' + 1> chars = {};

    for (int i = 0; i < h * w; i++) {
        char a;
        cin >> a;
        chars[a - 'a']++;
    }

    const int hh = h - h % 2, ww = w - w % 2;

    int s4 = hh * ww / 4;
    int s2 = (h % 2 * ww + w % 2 * hh) / 2;
    int s1 = (h % 2) * (w % 2);

    array<int, 3> a{4, 2, 1};
    array<int, 3> sqs{s4, s2, s1};

    priority_queue<int> pq;
    for (auto &&i : chars) {
        if (i > 0) pq.emplace(i);
    }

    for (int i = 0; i < 3; i++) {
        while (sqs[i] > 0) {
            if (pq.top() >= a[i]) {
                const int top = pq.top();
                pq.pop();
                if (top - a[i] > 0) pq.emplace(top - a[i]);
                sqs[i]--;
            } else
                break;
        }
    }

    cout << (pq.empty() ? "Yes" : "No") << endl;
}


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

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<int> A(N), B(M);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < M; i++) cin >> B[i];

    vector<ll> SA(N+1), SB(M+1);
    for (int i = 0; i < N; i++) SA[i+1] = SA[i] + A[i];
    for (int i = 0; i < M; i++) SB[i+1] = SB[i] + B[i];

    int ans = 0, j = M;
    for (int i = 0; i <= N; i++) {
        if (SA[i] > K) break;
        while (SA[i] + SB[j] > K) {
            j--;
        }
        ans = max(ans, i + j);
    } 
    cout << ans << endl;
}


Measured memory_bytes: 7960
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i_a, i_z;
  for (int i = 0; i < s.size(); ++i) {
    if (s.at(i) == 'A') {
      i_a = i;
      break;
    }
  }
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s.at(i) == 'Z') {
      i_z = i;
      break;
    }
  }
  cout << i_z - i_a + 1 << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int n;

int main() {
  cin >> n;
  vector<int> a(n);
  vector<int> acp(n);
  int maxval = 0;
  int maxcnt = 0;
  rep(i, n) {
    cin >> a[i];
    acp[i] = a[i];
    maxval = max(maxval, a[i]);
  }
  rep(i, n) if (maxval == a[i]) maxcnt++;
  int secondMax = 0;
  rep(i, n) if (a[i] != maxval) secondMax = max(secondMax, a[i]);
  if (maxcnt >= 2) {
    rep(i, n) cout << maxval << endl;
  } else {
    rep(i, n) {
      if (a[i] != maxval)
        cout << maxval << endl;
      else
        cout << secondMax << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>

int main(void)
{
	int a,b;
	while(1) {
		scanf("%d %d",&a,&b);
		if(a==0 && b==0) break;
		if(a > b) printf("%d %d\n",b,a);
		else printf("%d %d\n",a,b);
	}
	return 0;
}

Measured memory_bytes: 600