akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ll long long

using namespace std;

vector<ll> a;

int main()
{
    int n;
    cin >> n;
    a.resize(n);
    for (int i = n - 1; i >= 0; i--)
        cin >> a[i];
    if (a[0] > 2)
    {
        cout << -1 << endl;
        return 0;
    }
    ll MIN = 2;
    ll MAX = 2 + (a[0] - 1);
    for (int i = 1; i < n; i++)
    {
        ll mn = (MIN / a[i]) * a[i];
        if (MIN % a[i] != 0)
            mn += a[i];
        if (mn > MAX)
        {
            cout << -1 << endl;
            return 0;
        }
        ll mx = (MAX / a[i]) * a[i];

        if (mx < MIN)
        {
            cout << -1 << endl;
            return 0;
        }
        MIN = mn;
        MAX = mx + a[i] - 1;
    }
    cout << MIN << " " << MAX << endl;
}


Measured memory_bytes: 1024
n,m = map(int,input().split())

A = []
b = []
total = 0

for i in range(n):
    A.append(list(map(int,input().split())))

for i in range(m):
    b.append(int(input()))

for i in range(n):
    for j in range(m):
        total += A[i][j] * b[j]
    print(total)
    total = 0


Measured memory_bytes: 6012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll length = 0;
    repi(i, N, 0)
    {
        cin >> A[i];
        length += A.at(i);
    }
    
    ll t1 = A.at(0),t2 = length - A.at(0);
    ll ans = abs(t1 - t2);
    repi(i,N,1){
        t1 += A.at(i);
        t2 -= A.at(i);
        ans = min(ans,abs(t1-t2));
        
    }
    cout << ans << endl;
    return 0;
}

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

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

  vector<int> C(26);
  for (int i = 0; i < 26; i++) cin >> C.at(i);

  vector<vector<int>> S(D, vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> S.at(i).at(j);
    }
  }

  for (int i = 0; i < D; i++) {
    cout << 1 << endl;
  }
}


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

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
	int a,c,b,d;
	cin >> a>>b>>c>>d;
	if (a + b > c + d) cout << "Left" << endl;
	else if (a + b == c + d) cout << "Balanced" << endl;
	else cout << "Right" << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()


int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i + 1;
	}
  sort(all(a));
  ll ans = 0;
  for(int i = 0; i < n; i++) {
		ans += abs(a[i] - a[n / 2]);
  }
  cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
lint n,a[100010],b[100010];
int main() {
	std::cin>>n;
	for(int i=0;i<n;i++)std::cin>>a[i]>>b[i];
	lint ans=0;
	for(int i=n-1;i>=0;i--){
		a[i]+=ans;
		ans+=(a[i]+b[i]-1)/b[i]*b[i]-a[i];
	}
	std::cout<<ans<<std::endl;
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define DIM (long long)3007
#define INF (long long)100000007

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pairll;

ll n,m,i,j,k,sum,f1,f2,v1,v2;
string s,t,res;
ll a[DIM][DIM];
ll dp[DIM][DIM];
ll used1[DIM];
ll used2[DIM];
pair<ll,ll> par[DIM][DIM];

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

    cin >> s >> t;
    s='%'+s;
    t='%'+t;
    n=s.size()-1;
    m=t.size()-1;
    for(i=1; i<=n; i++){
        for(j=1; j<=m; j++){
            if(s[i]==t[j]){
                //a[i][j]=max(a[i][j],dp[i-1][j-1]+1);
                if(dp[i-1][j-1]+1>a[i][j]){
                    a[i][j]=dp[i-1][j-1]+1;
                    par[i][j]={i-1,j-1};
                }
            }

            //dp[i][j]=max({a[i][j],dp[i-1][j-1],dp[i-1][j],dp[i][j-1]});
            if(dp[i-1][j-1]>dp[i][j]){
                dp[i][j]=dp[i-1][j-1];
                par[i][j]={i-1,j-1};
            }
            if(dp[i][j-1]>dp[i][j]){
                dp[i][j]=dp[i][j-1];
                par[i][j]={i,j-1};
            }
            if(dp[i-1][j]>dp[i][j]){
                dp[i][j]=dp[i-1][j];
                par[i][j]={i-1,j};
            }
            if(a[i][j]>dp[i][j]){
                dp[i][j]=a[i][j];
            }
        }
    }
    i=n;
    j=m;
    ll i1,j1;
    while(1){
        if(s[i]==t[j] && used1[i]==0 && used2[j]==0) {
            used1[i]=1;
            used2[j]=1;
            res+=s[i];
        }
        i1=par[i][j].first;
        j1=par[i][j].second;
        //cout << i << " " << j << " " << i1 << " " << j1 << endl;
        if(i1<=0 || j1<=0) break;
        i=i1;
        j=j1;
    }
    reverse(res.begin(),res.end());
    cout << res << endl;



    return 0;
}


Measured memory_bytes: 282752
#include <iostream>
using namespace std;
int main(void){
    
    int r, g, b;
    cin >> r >> g >> b;
    
    int num = ( r *100) + (g *10)+ b;
     if (num % 4== 0){
         cout << "YES" <<endl;
     }
     else {
         cout << "NO" << endl;
     }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);


int main(){
  often();
  int a,b,c;
  cin >> a >> b >> c;
  cout << ((c > (a - b)) ? c - (a - b) : 0) << endl;
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;

int cnt;
int n;
int ans;
int h[100000];

int main(){
    cin >> n;
    rep(i,n){
        cin >> h[i];
    }
    rep(i,n-1){
        if(h[i] < h[i+1] ){
            ans = max(ans,cnt);
            cnt = 0;
            continue;
        }
        cnt++;
        if(i == n-2){
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;


return 0;
}

Measured memory_bytes: 3940
using System;

class Program
{
    static void Main()
    {
        var line = Console.ReadLine();

        byte cnt = 0;

        var len = line.Length;

        if (len == 1)
        {
            Console.WriteLine("0");
            return;
        }

        var half = len / 2;
        len -= 1;

        for (byte i = 0; i < half; i++)
        {
            var a = line[i];
            var b = line[len - i];

            if (a != b)
            {
                cnt++;
            }
        }

        Console.WriteLine(cnt);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, n, s) for (int i = s; i < n; i++)
#define graph map<int, vector<int>>
#define field vector<vector<int>>
#define ll long long
using namespace std;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n, 0);
    rep(i, n, 0)
    {
        cin >> a[i];
    }
    rep(i, n - k, 0)
    {
        if (a[i] < a[i + k])
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4840
function main(input){
  var line = input[0];
  var keyence = 'keyence';
  var keyi = 0;
  var mark = 0;
  var markr = 0;
  if (line===keyence) {
    console.log('YES');
    return;
  }
  
  for(var i =0; i<line.length; i++) {
    if (line[i] === keyence[keyi] && keyi !== keyence.length) {
      keyi++;
    } else {
      mark = i;
      break;
    }
  }

  line = line.split('').reverse().join('');
  keyence = keyence.split('').reverse().join('');
  keyi=0;

  for(var i =0; i<line.length; i++) {
    if (line[i] === keyence[keyi] && keyi !== keyence.length) {
      keyi++;
    } else {
      markr = i;
      break;
    }
  }
  
  if ((mark + markr) >= keyence.length) {
    console.log('YES');
  } else {
    console.log('NO');
  }
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});


Measured memory_bytes: 9548
unittest
{
	assert( [ "5", "1 2", "6 6", "4 4", "3 3", "3 2" ].solve == "Yes" );
	assert( [ "5", "1 1", "2 2", "3 4", "5 5", "6 6" ].solve == "No" );
	assert( [ "6", "1 1", "2 2", "3 3", "4 4", "5 5", "6 6" ].solve == "Yes" );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto dss = new long[ 2 ][ n ];
	foreach( ref ds; dss )
	{
		input.popFront;
		ds = input.front.split.to!( long[] );
	}
	
	auto ans = "No";
	auto c = 0L;
	foreach( ds; dss )
	{
		if( ds[ 0 ] == ds[ 1 ] )
		{
			c++;
			if( 3 <= c ) ans = "Yes";
		}
		else
		{
			c = 0;
		}
	}
	return ans;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll m = 100;
    ll y = 0;
    while (m < x)
    {
        m *= 1.01;
        y++;
    }
    cout << y << endl;
}


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


int main(){
    int n;
    cin>>n;
    long long sum=0;
    for(int i=1;i<=n;i++){
        if(i%3&&i%5)
            sum+=i;
    }
    cout<<sum<<endl;
    return 0;


}




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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N)  cin >> A.at(i);

  int g=0;
  rep(i,N)  g=gcd(g,A.at(i));
  if(g!=1){
    cout << "not coprime" << endl;
    return 0;
  }

  int MA=1000001;
  vector<int> prime(MA);
  rep(i,MA) prime.at(i)=i;
  REP(i,2,MA){
    if(prime.at(i)!=i)  continue;
    for(int j=i+i;j<MA;j+=i){
      if(prime.at(j)==j)  prime.at(j)=i;
    }
  }

  vector<int> cnt(MA,0);
  rep(i,N){
    int a=A.at(i);
    while(prime.at(a)!=a){
      int div=prime.at(a);
      while(a%div==0) a/=div;
      cnt.at(div)++;
    }
    if(a!=1)  cnt.at(a)++;
  }
  REP(i,2,MA){
    if(cnt.at(i)>1){
      cout << "setwise coprime" << endl;
      return 0;
    }
  }
  cout << "pairwise coprime" << endl;

  return 0;
}

Measured memory_bytes: 15048
import math
def resolve():
    A, B = map(int, input().split())

    for x in range(1, 100*100):
        a = math.floor(x * 0.08)
        b = math.floor(x * 0.1)
        if a == A and b == B:
            print(x)
            return
    
    print(-1)
    return

if __name__ == "__main__":
    resolve()

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

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

typedef long long int lli;

const int msz = 1e5+1;
vector<int> g[msz];
vector<bool> visited(msz);
vector<int> dp(msz);

void dfs(int s)
{
    visited[s] = true;
    for(int u : g[s])
    {
        if(!visited[u]) dfs(u);
        dp[s] = max(dp[s], 1+dp[u]);
    }
}

int main()
{
    fio;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
    }
    for(int i=1;i<=n;i++)
    {
        if(!visited[i]) dfs(i);
    }
    int ans = 0;
    for(int i=1;i<=n;i++) ans = max(ans, dp[i]);
    cout<<ans<<endl;
    cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s" << "\n";
    return 0;
}

Measured memory_bytes: 8192
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define PI 3.1415926535897932384626433832795
#define pii pair <int, int>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define N 100010

using namespace std;

int a, b, c, x, y;

int main()
{
	cin >> a >> b >> c >> x >> y;
	
	int ans = 1e9;
	for(int i = 0; i <= 200000; i += 2) {
		int sum = i*c;
		
		if(i / 2 <= x) sum += (x - i / 2)*a;
		if(i / 2 <= y) sum += (y - i / 2)*b;
		
		ans = min(ans, sum);
	}
	
	cout << ans;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static long mod = 1000000007;

    static long modinv(long a, long m) {
        long b = m;
        long u = 1;
        long v = 0;
        while (b != 0) {
            long t = a / b;

            a -= t * b;
            long tmp = b;
            b = a;
            a = tmp;
            u -= t * v;
            tmp = v;
            v = u;
            u = tmp;
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        long[] doubleA = new long[N];
        long ans = 0;

        for(int i=0;i<N;i++){
            A[i] = sc.nextLong();
            doubleA[i]  = A[i] * A[i] % mod;
            ans += A[i];
            ans %= mod;
        }

        long doubleSum =0;
        for(int i=0;i<N;i++){
            doubleSum += doubleA[i];
            doubleSum %= mod;
        }
        ans = ((ans * ans) % mod - doubleSum % mod) % mod;
        ans = ans * modinv(2,mod) % mod;
        if(ans<0){
            ans+= mod;
        }

        System.out.println(ans);


    }

}




Measured memory_bytes: 65096
MOD=int(1e9+7)
n,m=map(int,input().split())
stairs=[True]*(n+10) #0階を含む
a=[]
for i in range(m):
  s=int(input())
  a.append(s)
for j in a:
  stairs[j]=False
dp=[-1]*(n+10)
dp[0]=1
dp[1]=dp[0]*stairs[1]
for k in range(0,n):
  dp[k+2]=(dp[k+1]+dp[k])*stairs[k+2]%MOD

print(dp[n])

Measured memory_bytes: 8600
#include <bits/stdc++.h>
using namespace std;
int main() {
    int l,r,d,i,count=0;
    cin>>l>>r>>d;
    for(i=l;i<=r;i++)
    {
        if(i%d==0)
            count++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3592
Stack=[]
def push(x):
    Stack.append(x)

def pop():
    return Stack.pop()

def solve():
    s_list=raw_input().split()
    for i in range(len(s_list)):
        if s_list[i]=='+':
            b=pop()
            a=pop()
            push(a+b)
        elif s_list[i]=='-':
            b=pop()
            a=pop()
            push(a-b)
        elif s_list[i]=='*':
            b=pop()
            a=pop()
            push(a*b)
        else:
            push(int(s_list[i]))
    print(pop())

def main():
    if __name__=="__main__":
        solve()

main()

Measured memory_bytes: 6344
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    ans = 0
    for i in range(K):
        p = 'z'
        for c in T[i::K]:
            if c == p:
                p = 'z'
                continue
            if c == 'r':
                ans += P
            elif c == 's':
                ans += R
            else:
                ans += S
            p = c
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>

using namespace std;
using ll = long long;

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

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

// dp[桁][未満フラグ][決定した桁の数字の総和をdで割った余り]
ll dp[10000][2][110];

int main() {
    string s; cin >> s;
    int d; cin >> d;

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    int len = s.size();
    ll mod = 1e9+7;

    for (int i = 0;i < len; i++) {
        int p = s[i] - '0';
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < d; k++) {
                for (int l = 0; l <= (j ? 9 : p); l++) {
                    int nextK = (k+l)%d;
                    dp[i+1][j || (l<p)][nextK] += dp[i][j][k];
                    dp[i+1][j || (l<p)][nextK] %= mod;
                }
            }
        }
    }
    ll ans = (dp[len][0][0] + dp[len][1][0])%mod - 1;
    if (ans < 0) {
        ans += mod;
    }
    cout << ans << endl;
    return 0;
}

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

int zettai(int a){
  if(a<0){
    a= 0-a;
  }
  return a;
}

int main(){
  long long int n,l,min=1000000007,A;
  cin>>n>>l;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    a.at(i)=l+i;
    if(a[i]<0){
      a.at(i)=-a.at(i);
    }
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    int a,b;
    a=l+i;
    if(a<=0){
      b=-a;
    }
    else{
      b=a;
    }
    
    if(zettai(min)>b){
      min=a;
    }
  }
  A=(n*n+((2*l)-1)*n)/2-min;
  cout<<A<<endl;
}

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

int main(){
	int t;
	int sum;
	int ret;
	
	while(cin >> sum && sum){
		ret = 0;
		for(int i=0;i<9;i++){
			cin >> t;
			ret+=t;
		}
		cout << sum-ret << endl;	
	}
}

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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k > a + b) {
    cout << a - (k - a - b) << endl;
  } else if (k < a) {
    cout << k << endl;
  } else {
    cout << a << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, A[101010];
int B[101010];

void solve() {
    int cnt = 0;
    bool flag = true;
    int SUM = 0;
    FOR (i, 0, N)
        SUM += A[i];
    int time = SUM / (N * (N + 1) / 2);
    if (time * N * (N + 1) / 2 != SUM) {
        NO();
        return;
    }
    SUM = 0;
    FOR (i, 0, N) {
        int nxt = (i + 1) % N;
        B[i] = (A[i] - A[nxt] + time);
        if (B[i] % N == 0 && B[i] >= 0) {
            B[i] /= N;
            SUM += B[i];
        } else {
            NO();
            return;
        }
    }
    flag = ((time - SUM) >= 0 && ((time - SUM) % N == 0));
    YES(flag);
}

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

    cin >> N;
    FOR (N)
        cin >> A[i];

    solve();
    return 0;
}


Measured memory_bytes: 1792
H,W,i,j,t;
main(){
    for(;scanf("%d %d",&H,&W),H;puts("")){
        for(i=0;H--;i++){
            for(j=0,t=W;t--;j++){
                printf("%s%s",i>0&&H!=0&&j>0&&t!=0?".":"#",t==0?"\n":"");
            }
        }
    }
}

Measured memory_bytes: 1804
#include <stdio.h>
int main(){
  int i,n,q,c=0,left,right,mid;

  scanf("%d",&n);

  int S[n];
  for(i=0;i<n;i++) scanf("%d",&S[i]);

  scanf("%d",&q);

  int T[q];
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);

    left=0;
    right=n;

    while(left<right){
      mid=(left+right)/2;

      if(T[i]>S[mid]) left=mid+1;
      else if(T[i]<S[mid]) right=mid;
      
      else{
	c++;
	break;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e6 + 5, mod = 1e9 + 7;

int fact[N], inv[N];

int mul(int a, int b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return 1ll * a * b % mod;
}

int add(int a, int b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (a + b) % mod;
}

int fp(int b, int p){
    if(!p) return 1;
    ll ret = fp(b, p >> 1);
    ret = ret * ret % mod;
    if(p&1) ret = ret * b % mod;
    return ret;
}

void pre(){
    fact[0] = inv[0] = 1;
    for(int i = 1; i < N; i++){
        fact[i] = mul(fact[i - 1], i);
        inv[i] = fp(fact[i], mod - 2);
    }
}

int ncr(int n, int r){
    int ret = mul(fact[n], inv[n - r]);
    return mul(ret, inv[r]);
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    pre();
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll ans = 0;
    for(int i = r1; i <= r2; i++){
        ll kam = ncr(c2 + 1 + i, c2);
        ll z = ncr(c1 + i, c1 - 1);
        // cout << kam << ' '  << z << '\n';
        kam = add(kam, -z);
        ans = add(ans, kam);
    }
    cout << ans;

    return 0;
}




Measured memory_bytes: 19240
using System;
using System.Linq;

namespace ProgramingLearning
{
    class Program
    {
        static void Main(string[] args)
        {
            
            var n = int.Parse(Console.ReadLine());
            var d = new int[n, 2];

            for(int i = 0; i < n; i++)
            {
                var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
                d[i, 0] = inputs[0];
                d[i, 1] = inputs[1];
            }

            for (int i = 0; i < n - 2; i++)
            {
                if(d[i,0 ]== d[i,1] && d[i+1, 0] == d[i+1, 1] && d[i+2, 0] == d[i+2, 1])
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 28100
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll a, b, x;
	ll ans = 0;
	ll s, t;

	cin >> a >> b >> x;

	s = a / x;
	t = b / x;

	ans = t - s;

	if (a % x == 0) {
		ans++;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Possible");}else{puts("Impossible");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int h,w;
    scanf("%d%d",&h,&w);
    ll ans = 0;
    rep(i,h){
        string s; cin >> s;
        rep(j,w){
            if(s[j]=='#')ans++;
        }
    }

    if(ans==h-1+w-1+1)yn;
    
    
    //cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

const ll mod = 1e9+7;




void solve(){
    string s;
    cin>>s;
    bool ans=true;
    for(char i:s)
        ans&=(i!='7');
    if(ans)
        cout<<"No\n";
    else cout<<"Yes\n";
    return;
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    double disx=x2-x1;
    double disy=y2-y1;
    double dis=sqrt(disx*disx+disy*disy);
    printf("%.5f",dis);
}


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 500010, M = 26;

int n, m;
char s[N];
set<int> S[M];

int calc(int l, int r)
{
	int res = 0;
	for (int i = 0; i < M; i ++ )
	{
		auto it = S[i].lower_bound(l);
		if (*it > r || it == S[i].end()) continue;
		else res ++ ;
	}
	return res;
}

int main()
{
	scanf("%d%s", &n, s + 1);
	for (int i = 1; i <= n; i ++ ) S[s[i] - 'a'].insert(i);
	
	scanf("%d", &m);
	while (m -- )
	{
		int t;
		scanf("%d", &t);
		
		if (t == 1)
		{
			int i;
			char c[2];
			scanf("%d%s", &i, c);
			S[s[i] - 'a'].erase(i);
			S[c[0] - 'a'].insert(i);
			s[i] = c[0];
		}
		else
		{
			int l, r;
			scanf("%d%d", &l, &r);
			printf("%d\n", calc(l, r));
		}
	}
	
    return 0;
}

Measured memory_bytes: 27744
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = double.Parse(Console.ReadLine());
            double d = a * 2 * Math.PI;
            double b = a * a * Math.PI;
            Console.WriteLine("{0:F10} {1:F10}",b,d);
        }
    }
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

bool cmp(P a, P b) { return a.second < b.second; }

int a[101], b[101];
int dp[101][101][10010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;

	set<string> se;
	rep(i, n) {
		string s;
		cin >> s;
		se.insert(s);
	}

	out(sz(se));

	return 0;
}

Measured memory_bytes: 19196
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
#include<map>
using namespace std;

vector<string> L;
int size[52];
map<pair<int, int>, int> V;
map<pair<int, int>, bool> A; 

int idx(char ch){
    if ( 'a' <= ch ) return ch - 'a';
    else return ch - 'A' + 26;
}

int getInt(string str, int &p ){
    string num = "";
    while( isdigit(str[p]) ) num += str[p++];
    if ( num.size() ) return atoi(num.c_str());
    int n = idx(str[p]);
    p += 2;
    int v = getInt(str, p);
    if ( v == -1 || size[n] <= v || !A[make_pair(n, v)] ) return -1;
    return V[make_pair(n, v)];
}

int compute(){
    for ( int i = 0; i < 52; i++ ) size[i] = 0;
    V = map<pair<int, int>, int>();
    A = map<pair<int, int>, bool>();
    for ( int i = 0; i < L.size() ;i++ ) {
	string line = L[i];
	if ( line.find('=') != string::npos ) {
	    int e = 0; while( line[e] != '=' ) e++;
	    e++;
	    int r = getInt(line, e);
	    int pos = 2;
	    int li = getInt(line, pos);
	    if ( li == -1 || r == -1 || li >= size[idx(line[0])]) return i+1;
	    V[make_pair(idx(line[0]), li)] = r;
	    A[make_pair(idx(line[0]), li)] = true;
	} else {
	    int pos = 2;
	    size[idx(line[0])] = getInt(line, pos);
	}
    }
    return 0;
}

main(){
    string str;
    while( cin >> str ){
	if ( str == "." ) break;
	L.clear(); L.push_back(str);
	while( cin >> str ){
	    if ( str == "." ) break;
	    L.push_back(str);
	}
	cout << compute() << endl;
    }
}

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

int main(){
	int a,b,c;
	int ans;
	int cnt=-1;
	
	while(cin>>a>>b){
		cnt++;
		//-----test-----
		if(a<1170) break;
		
		//--------------
		c=a+b;
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
INF = 1E9

while (n = gets.to_i) && n != 0
	h = Array.new
	a = Array.new(n, +INF)
	b = Array.new(n, -INF)
	(0...n).each do |i|
		h.push(Array.new)
		gets.split.each_with_index do |k, j|
			k = k.to_i
			h[i].push(k)
			a[i] = [a[i], k].min
			b[j] = [b[j], k].max
		end
	end
	ans = 0
	for i in (0...n)
		for j in (0...n)
			k = h[i][j]
			ans = k if k == a[i] && k == b[j]
		end
	end
	puts ans
end

Measured memory_bytes: 6884
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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 <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    long long A,B,N;
    cin >> A >> B >> N;
    long long num=0;
    long long left=N;
    long long right=0;
    long long mid=min(B-1,N);
    long long ans=floor((A*mid/B))-A*floor(mid/B);
    cout << ans << endl;
    }

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

int n, m;
int a[200005];
int main()
{
	for (int i = 0; i <= n; i++)a[i] = 0;
	cin >> n;
	for (int i = 2; i <= n; i++)
	{
		int x; cin >> x;
		a[x]++;
	}
	for (int i = 1; i <= n; i++)
	{
		cout << a[i];
		if (i != n) cout << endl;
	}
}

Measured memory_bytes: 4420
#include <stdio.h>
int main(void){
    // Your code here!
    int n, a[11][11], i, j ;
    scanf("%d", &n);
    
    while(n != 0){
        //初期化
        for(i=0; i<=10; i++){
            for(j=0; j<=10; j++){
                a[i][j]=0;
            }
        }
        
        for(i=0; i<n; i++){
            for(j=0; j<n; j++){
                scanf("%d", &a[i][j]);
                a[i][n] += a[i][j];
                a[n][j] += a[i][j];
                printf("%5d", a[i][j]);
            }
            a[n][n] += a[i][n];
            printf("%5d\n", a[i][n]);
        }
        for(j=0; j<=n; j++){
            printf("%5d", a[n][j]);
        }
        printf("\n");
        scanf("%d", &n);
    }
    return 0;
}



Measured memory_bytes: 2032
n  = int(input())
ans = n
cnt = 0
for i in range(2, int((n ** 0.5))+2):
  if n % i == 0:
    cnt += 1
    if ans > i + n/i -2:
      ans = i + n/i -2

if cnt == 0:
  ans = n-1
print(int(ans))

Measured memory_bytes: 9324
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long inf = numeric_limits<long long>::max();
int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> seq(n);
  rep(i, n) {
    cin >> seq[i];
  }
  int m = 0;
  rep(i, n) {
    if (i == 0) continue;
    if (seq[i] < seq[m]) {
      m = i;
    }
  }
  if (n <= k) {
    cout << 1 << endl;
  } else {
    cout << ceil((n-1)/((k-1)*1.0));
  }

  return 0;
}

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

int main(){
    int a, b;
    int ans;
    cin >> a >> b;
    ans = max(max(a+b,a-b),a*b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n; cin >> n;
  int a[n+1],b[n+1];
  for(int i=1;i<=n;i++) cin >> a[i];
  //memorize previous index
  int p=n/2+1;
  b[p]=a[1];
  if(n%2==1){
    int idx=1;
    while(idx<=n-1){
      if(idx%2==0){
        b[p-idx]=a[idx+1];
        p=p-idx; idx++;
      }
      else{
        b[p+idx]=a[idx+1];
        p=p+idx; idx++;
      }
    }
  }else{
    int idx=1;
    while(idx<=n-1){
      if(idx%2==0){
        b[p+idx]=a[idx+1];
        p=p+idx; idx++;
      }
      else{
        b[p-idx]=a[idx+1];
        p=p-idx; idx++;
      }
    }
  }
  for(int i=1;i<=n;i++){
    if(i==n) cout << b[n] << endl;
    else cout << b[i] << " ";
  }
}

Measured memory_bytes: 3712
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n = I()
        if n == 0:
            break
        xy = [LI() for _ in range(n)]
        m = I()
        d = []
        for _ in range(m):
            s,t = S().split()
            d.append((s,int(t)))
        b = collections.defaultdict(bool)
        for x,y in xy:
            b[(x,y)] = True
        x = y = 10
        for s,t in d:
            if s == 'N':
                for _ in range(t):
                    y += 1
                    b[(x,y)] = False
            elif s == 'S':
                for _ in range(t):
                    y -= 1
                    b[(x,y)] = False
            elif s == 'W':
                for _ in range(t):
                    x -= 1
                    b[(x,y)] = False
            else:
                for _ in range(t):
                    x += 1
                    b[(x,y)] = False
        if any(b.values()):
            rr.append('No')
        else:
            rr.append('Yes')

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9064
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    string S;
    cin>>S;
    int r=0,a=0;
    if(S.size()==1){
        if(S.at(0)=='A'||S.at(0)=='C'||S.at(0)=='G'||S.at(0)=='T'){
            cout<<1<<endl;
            exit(0);
        }
    }

    for(int i=0;i<S.size()-1;i++){
        if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
            if(S.at(i+1)=='A'||S.at(i+1)=='C'||S.at(i+1)=='G'||S.at(i+1)=='T'){
                r++;
            }else{
                a=max(a,r+1);
                r=0;
            }
        }
        if(i==S.size()-2){
            if(a==0&&r==0){
                cout<<0<<endl;exit(0);
            } 
            if(a==0&&r!=0) {
                cout<<r+1<<endl;exit(0);
            }
            a=max(a,r+1);
        }
    }
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    string s[10];
    rep(i,0,H){
        cin >> s[i];
    }
    ll cnt = 0;
    rep(i,0,H){
        rep(j,0,W){
            if(s[i][j] == '#') cnt++;
        }
    }
    if(cnt == H+W-1){
        print("Possible");
    }else{
        print("Impossible");
    }

    

}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	int N;
	vector<int> L;
	
	void ans() {
		cin >> N;
		L.resize(2 * N);
		REP(i, 2 * N) cin >> L[i];
		sort(L.begin(), L.end());
		int res = 0;
		REP(i, N) res += L[2 * i];
		cout << res << "\n";
	}

};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	question q;
	q.ans();
	
	return 0;
}

Measured memory_bytes: 256