akhauriyash/Code-Regression huggingface dataset:
// Last Change: 05/24/2019 19:18:52.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N, M;
  cin >> N >> M;

  vector<ll> yakusu;
  ll sqrtM = sqrt(M) + 1;
  for (ll i = 1; i < sqrtM; ++i) {
    if (M % i == 0) {
      yakusu.push_back(i);
      if (M / i != i) {
        yakusu.push_back(M / i);
      }
    }
  }

  ll ans = 1;
  for (auto &&e : yakusu) {
    if (e * N <= M) {
      ans = max(ans, e);
    }
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  int ans = 0;
  for(int i = 0; i < n; i++){
   if(x >= a.at(i)){
     ans++;
     x -= a.at(i);
   }
  }
  
  if(ans == n && x > 0){
    ans--;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    na = [-1 for _ in range(2*n)]
    nk = n * k

    prevai = {}
    for i, _a in enumerate(a+a):
        if _a in prevai:
            na[prevai[_a]] = (i-prevai[_a])%n + 1
            if na[prevai[_a]] == 1:
                na[prevai[_a]] = n+1
        prevai[_a] = i

    doubling = [[0 for _ in range(n)] for _ in range(61)]
    for i in range(n):
        doubling[0][i] = na[i]
    for i in range(1, 61):
        for j in range(n):
            doubling[i][j] = min(doubling[i-1][j] + doubling[i-1][(j+doubling[i-1][j])%n], nk+5)

    tmp = 0
    for i in range(60, -1, -1):
        if nk - tmp >= doubling[i][tmp%n]:
            tmp += doubling[i][tmp%n]

    if tmp == nk:
        return
    
    ans  = []
    adict = {}
    for i in range(tmp%n, n):
        if a[i] in adict and adict[a[i]] > 0:
            while True:
                _a = ans.pop()
                adict[_a] = 0
                if _a == a[i]:
                    break
        else:
            ans.append(a[i])
            adict[a[i]] = 1
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 254480
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

bool field[21][21];

int main(){

  while(true){
    int n,m;
    cin >> n;
    if(n==0) break;

    rep(i,21){
      rep(j,21) field[i][j]=false;
    }

    rep(i,n){
      int x,y;
      scanf("%d %d", &x, &y);
      field[x][y]=true;
    }

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

    int x=10, y=10;
    rep(i,m){
      char c; int d;
      scanf("%c %d\n", &c, &d);
      int dx=0,dy=0;
      switch(c){
      case 'N': dy=1; break;
      case 'E': dx=1; break;
      case 'S': dy=-1; break;
      case 'W': dx=-1; break;
      }
      rep(j,d){
	x+=dx; y+=dy;
	if(field[x][y]){
	  n--;
	  field[x][y]=false;
	}
      }
    }

    if(n==0) cout << "Yes" << endl;
    else cout << "No" << endl;

  }

}

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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin >>n;
    vector<int> a(n);

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

    int i=0;
    int t=1,br=0;
    while (i < n){
        while (a[i] != t && i < n){
            //cout <<a[i]<<endl;

            ++br;
            ++i;
        }
        //cout <<a[i] <<"  !!!"<<endl;

        ++t;
        ++i;
    }

    if(br == n)br=-1;
    
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << br << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

template <typename T> T lcm(T a, T b) {
	return a * b / __gcd(a, b);
}

long long prefix(long long n, int a, int b) {
	return n - n / a - n / b + n / lcm<long long>(a, b);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto a = load<long long>();
	auto b = load<long long>();
	auto c = load<int>();
	auto d = load<int>();
	auto r = prefix(b, c, d) - prefix(a-1, c, d);
	cout << r << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <string>
#include <map>
#include <cstring>
#include <vector>
#include <stack>

int memo[55][55][6][1030];

std::string map[51];
std::string prog;
int back[1010];

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

int main() {
    int h, w;
    int y, x, gy, gx;

    std::cin >> h >> w;

    for(int i = 0; i < h; ++i) {
        std::cin >> map[i];

        for(int j = 0; j < w; ++j) {
            if(map[i][j] == 's') {
                y = i, x = j;
            }else if(map[i][j] == 'g') {
                gy = i, gx = j;
            }
        }
    }
    std::stack<int> st;
    std::cin >> prog;

    for(int i = 0; i < prog.size(); ++i) {
        if(prog[i] == '{' || prog[i] == '[') {
            st.push(i);
        }else if(prog[i] == '}' || prog[i] == ']') {
            auto s = st.top();
            st.pop();

            back[i] = s;
            back[s] = i;
        }
    }

    int ptr = 0;
    int dir = 0;

    auto calcState = [&](char c) {
        if(c == 'C') {
            return map[y + dy[dir]][x + dx[dir]] == '#';
        }else if(c == 'T') {
            return true;
        }else if(c == 'N'){
            return dir == 0;
        }else if(c == 'E'){
            return dir == 1;
        }else if(c == 'S'){
            return dir == 2;
        }else if(c == 'W'){
            return dir == 3;
        }
        assert(false);
        return false;
    };
    int step = 0;
    while(1) {
        // std::cout << y << " " << x << " " << dir << " " << ptr << std::endl;
        if(map[y][x] == 'g') {
            std::cout << step << std::endl;

            return 0;
        }
        if(ptr == prog.size()) {
            std::cout << -1 << std::endl;

            return 0;
        }
        if(memo[y][x][dir][ptr] == 1) {
            std::cout << -1 << std::endl;
            return 0;
        }
        memo[y][x][dir][ptr] = 1;

        if(prog[ptr] == '^') {
            ++step;
            if(map[y + dy[dir]][x + dx[dir]] == '#') {
                goto END;
            }
            y += dy[dir];
            x += dx[dir];
        }else if (prog[ptr] == 'v') {
            ++step;
            if(map[y - dy[dir]][x - dx[dir]] == '#') {
                goto END;
            }
            y -= dy[dir];
            x -= dx[dir];
        }else if (prog[ptr] == '<') {
            dir = (dir - 1 + 4) % 4;
            ++step;
        }else if (prog[ptr] == '>') {
            dir = (dir + 1) % 4;
            ++step;
        }else if (prog[ptr] == '[' || prog[ptr] == '{') {
            bool stat;
            int prev = ptr;
            if (prog[ptr + 1] == '~') {
                stat = !calcState(prog[ptr + 2]);
                ptr += 2;
            }else {
                stat = calcState(prog[ptr + 1]);
                ptr += 1;
            }

            if(!stat) {
                ptr = back[prev];
            }
        }else if (prog[ptr] == '}') {
            ptr = back[ptr] - 1;
        }

        END:;
        ++ptr;
    }
}


Measured memory_bytes: 43048
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret, p = [], 2

    while p*p <= n:
        if n % p != 0:
            p += 1
            continue

        exp = 0
        while n%p == 0:
            exp += 1
            n //= p
        ret.append( [ret, exp] )

        p += 1

    if n != 1: ret.append( [n, 1] )

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print( len(prime_factor(g)) + 1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
//#define ONLINE_JUDGE
vector< int > lp;
vector< vector<int> > edges;
int longestPath(int N){
	if(edges[N].size()==0){
		return 0;
	}
	if(lp[N]==-1){
		for(int i=0;i<edges[N].size();i++){
			lp[N] = max(lp[N],1+longestPath(edges[N][i]));
		}
	}
	return lp[N];
}
int main()
{
	/*
		Jainam Shah's Code
	*/
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int N,M;
	cin>>N>>M;
	edges.resize(N+1);
	lp.resize(N+1,-1);
	for(int i=0;i<M;i++){
		int u,v;
		cin>>u>>v;
		edges[v].push_back(u);
	}
	int ans = 0;
	for(int i=1;i<N+1;i++){
		ans = max(ans,longestPath(i));
	}
	cout<<ans<<endl;
	//cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
}


Measured memory_bytes: 13356
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(n):
        for j in range(1,k+1):
            if i+j >= n:
                break
            dp[i+j] = min([dp[i+j], dp[i]+abs(h[i]-h[i+j])])
    print(dp[n-1])

if __name__ == "__main__":
    main()

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

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

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y; cin >> x >> y;
	cout << (abs(x - y) <= 1 ? "Brown" : "Alice") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n;
signed main(){
	cin>>n;
	int o=(n+1)/2;
	printf("%.12lf\n",(double)o/n);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
if max(a) != min(a):
    while a.count(0) != len(a)-1:
        a.sort()
        b = [a[0]]
        for i in a[1:]:
            if i%a[0] != 0:
                b.append(i%a[0])
        a = b
    print(max(a))
else:
    print(a[0])

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

int main() {
  int n, k, x, i, ans=0;
  cin >> n;
  cin >> k;
  
  for (i=0; i<n; i++) {
    cin >> x;
    ans += min(x, k-x) * 2;
  }
  cout << ans << endl;
  
  return 0;
}

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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	ll n;
	  cin>>n;
	  vector<ll>vect(n+1);
	  vector<ll>hero(n);

	  f(i,0,n+1)
	  	cin>>vect[i];
	  f(i,0,n)
	  	cin>>hero[i];

	  ll ans=0;

	  for(ll i=0;i<n;i++)
	  {
	  	ans+=min(vect[i],hero[i]);
	  	hero[i]= max(hero[i]-vect[i],0ll);
	  	int x= min(hero[i],vect[i+1]);
	  	ans+=x;
	  	vect[i+1]-=x;
	  	///error(ans);
	  }

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

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

using namespace std;

int main()
{
	unsigned int N, K, X, Y, sum = 0;
	cin >> N >> K >> X >> Y;
	if (N > K)
	{
		for (size_t i = 1; i <= K; i++)
		{
			sum += X;
		}
		for (size_t i = K + 1; i <= N; i++)
		{
			sum += Y;
		}
	}
	else
	{
		for (size_t i = 1; i <= N; i++)
		{
			sum += X;
		}
	}
	cout << sum << endl;
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int a=0;
  int b=0;
  
  rep(i,n){
    if((i+1)%2==1 && s.at(i)=='0'){
      a=a+1;
    }
    if((i+1)%2==0 && s.at(i)=='1'){
      a=a+1;
    }
  }
  rep(i,n){
     if((i+1)%2==1 && s.at(i)=='1'){
      b++;
    }
    if((i+1)%2==0 && s.at(i)=='0'){
      b++;
    }
  }
  cout<<min(a,b)<<endl;
  
  
  return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a > b) swap(a,b);
  if(b > c) swap(b,c);
  if(a > b) swap(a,b);
  cout << a << " " << b << " " << c <<endl;
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define ios ios::sync_with_stdio(0);cin.tie(0);


int main(){
    ios;

    ll N;
    cin >> N;
    vector<int> h(N+1);
    h[0] = 0;
    rep(i,N) cin >> h[i+1];

    vector<int> dp(N+1,0);
    dp[2] = abs(h[2]-h[1]);
    for(int i=3;i<N+1;i++)
        dp[i] = min( dp[i-2]+abs(h[i]-h[i-2]) , dp[i-1]+abs(h[i]-h[i-1]) );

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
#define ll long long
using namespace std;

int main(){
  ll n;
  cin>>n;
  
  ll h[n];
  
  for(ll i=0;i<n;i++){
   cin>>h[i]; 
  }
  
  ll dp[n];
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  
  for(ll i=2;i<n;i++){
   dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])); 
  }
  
  cout<<dp[n-1]<<endl;
  
  
 return 0; 
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> edges;
    int j;
    if (n % 2 == 1) {
        j = n - 1;
    } else {
        j = n;
    }
    for (int i = 1; i < j; i++, j--) {
        for (int k = 1; k <= n; k++) {
            if (k != j && k != i) {
                if (i < k) {
                    edges.emplace_back(i, k);
                }
                if (j < k) {
                    edges.emplace_back(j, k);
                }
            }
        }
    }
    cout << edges.size() << '\n';
    for (auto& e : edges) {
        cout << e.first << ' ' << e.second << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

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

typedef long long ll;


int main(void) {
    int n,r;
    while (cin>>n>>r && n){
        vector<int> a(n);
        REP(i,n){
            a[i] = i+1;
        }
        while(r--){
            int p,c;
            cin >> p >> c;
            REP(i,c){
                int k=a[n-p-c+1];
                a.erase(a.begin()+n-p-c+1);
                a.push_back(k);
            }
        }
        cout << a[n-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  while(a > 0 && c > 0){
  	if(0 >= (c = c - b)){
    	printf("Yes\n");
        return 0;    
    }
    if(0 >= (a = a - d)){
    	printf("No\n");
  		return 0;    
    }
  }
}

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

int main() {
        int EW, SN;
        int best = 2147483647;
        cin >> EW >> SN;


        vector<vector<int>> P(EW, vector<int>(SN));

        rep(ew, EW) {
                rep(sn, SN) {
                        cin >> P.at(ew).at(sn);
                }
        }

        rep(kew, EW) {
                rep(ksn, SN) {
                        int total = 0;
                        rep(ew, EW) {
                                rep(sn, SN) {
                                        total += P.at(ew).at(sn) * min(abs(kew - ew), abs(ksn - sn));
                                }
                        }
                        if (best > total) {
                                best = total;
                        }
                }
        }

        cout << best << endl;
        return 0;
}



Measured memory_bytes: 3156
#include<stdio.h>
#define g getchar()
inline void r(int *x){
	*x=0;
	char c=g;
	while(c<'0')c=g;
	while(c>='0'){*x=*x*10+c-48;c=g;}
}
static int x[100000];
int main(){
	int n,a,b;r(&n);r(&a);r(&b);long d=0;r(&x[0]);
	for(int i=1;i<n;i++){
		r(&x[i]);
		d+=(long)a*(x[i]-x[i-1])>b?b:(long)a*(x[i]-x[i-1]);
	}
	printf("%ld\n",d);
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#define findmax(a,b) (a)>(b)?(a):(b)
#define findmin(a,b) (a)<(b)?(a):(b)
#define inout freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
#define swap(a,b) (a)+=(b);(b)=(a)-(b);(a)-=(b)
#define quicksort(a,n) qsort(a,n,sizeof(a[0]),cmp)
#define inputarr(a,n) for(int i=0;i<n;i++){scanf("%d",&a[i]);}
#define printarr(a,n) for(int i=0;i<n;i++){printf("%d ",a[i]);}puts("");
int cmp(const void *a,const void *b){return *(int *)a - *(int *)b;}

int main(){ 

	int n;

	char s[105];

	scanf("%d %s", &n, s);

	int len = strlen(s);

	if(n >= len){
		printf("%s", s);
	}

	else{
		s[n] = '\0';
		printf("%s...", s);
	}

}

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

vector<ll>par(1e5+10);
void init(ll n) {
  for(ll i=0;i<n;i++) {
    par[i]=i;
  }
}

ll root(ll x) {
  if(par[x]==x) {
    return x;
  }
  else {
    return par[x]=root(par[x]);
  }
}

bool same(ll x, ll y) {
  return root(x)==root(y);
}

void unite(ll x, ll y) {
  if(same(x,y)) return;
  par[root(x)]=root(y);
}

int main() {
  ll n,m;
  cin >> n >> m;
  init(n);
  vector<ll> p(n);
  for(ll i=0;i<n;i++) {
    cin >> p[i];
    p[i]--;
  }
  for(ll i=0;i<m;i++) {
    ll x,y;
    cin >> x >> y;
    x--;
    y--;
    unite(x,y);
  }
  ll ans=0;
  for(ll i=0;i<n;i++) {
    if(same(p[i],i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(void)
{

	int a, b, n;
	while (1) {
		scanf("%d%d", &a, &b);
		if ((a == 0) && (b == 0))
			break;

		if (a > b) {
			n = a;
			a = b;
			b = n;
		}

			printf("%d %d\n", a, b);
			

		

		 
	}
	return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    LL n,t;cin >> n >> t;
    vector<P> v;
    vector<LL> z;
    for (int i = 0; i < n; i++) {
        LL a,b;cin >> a >> b;
        if(a) v.pb(mp(a, b));
        else z.pb(b);
    }
    sort(ALL(v),[](P &l, P &r){
            return r.fs * (l.sc + 1) < l.fs * (r.sc + 1);
        });
    vector<LL> dp(31,t+1);
    dp[0] = 0;
    for (int i = 0; i < v.size(); i++) {
        for (int j = 29; j >= 0; j--) {
            chmin(dp[j+1], dp[j] + 1 + v[i].fs * (dp[j]+1) + v[i].sc);
        }
    }
    z.pb(t+1);
    sort(ALL(z));
    int ans = 0;
    for (int i = 0; i <= 30; i++) {
        if(dp[i] > t) continue;
        LL x = dp[i];
        for (int j = 0; j < z.size(); j++) {
            x += z[j] + 1;
            if(x > t){
                chmax(ans, i + j);
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索
// 偶奇，逆から，ソート
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int N; cin >> N;
// バケット
VI A(N), cntA(100001, 0);
rep(i, 0, N) {
    cin >> A[i];
    ++cntA[A[i]];
}
int cnt = 0 ;
for (int i : cntA) {
    if (i > 0) ++cnt;
}
if ((N - cnt) % 2) cout << cnt - 1 << "\n";
else cout << cnt << "\n";

}

// 境界，出力文字列 チェック



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

int main() {
  int N,d[2000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>d[i];
  sort(d,d+N);
  ll cnt(0);
  for (int i(0);i<N;i++){
    for (int j(i+1);j<N;j++){
      int sum=d[i]+d[j];
      if (sum<=d[N-1]){
        int ptr=lower_bound(d,d+N,sum)-d;
        //cout <<ptr << " "<< ptr -j-1<< endl;
        cnt+=max(0,ptr-j-1);
      }else{
        cnt+=(N-1-j);
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
def main():
    n, k = map(int,input().split())
    if n<k:
        amari = n
        absu = abs(n-k)
    else:
        amari = n%k
        absu = abs(amari-k)
    if amari<=absu:
        print(amari)
    else:
        print(absu)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		X -= A;
		int t = X / B;
		int res = X - t * B;
		System.out.println(res);
	}
}

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

int main() {
  int N,K,Z=0;
  cin>>N>>K;
  vector<int> p(N);
  for (int i=0;i<N;i++) {
  cin>>p.at(i);
}
  sort(p.begin(), p.end());
  for(int i=0;i<K;i++){
    Z+=p.at(i);
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3624
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 100005;
const int MAXM = 1000005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
#define endl "\n"
#define de(x) cout<<#x<<"="<<x<<endl
int p[MAXN], q[MAXN], r[MAXN];

int main()
{
    ios::sync_with_stdio(0);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    for (int i = 1; i <= a; ++i)
        cin >> p[i];
    for (int i = 1; i <= b; ++i)
        cin >> q[i];
    for (int i = 1; i <= c; ++i)
        cin >> r[i];
    sort(p + 1, p + a + 1);
    reverse(p + 1, p + a + 1);
    sort(q + 1, q + b + 1);
    reverse(q + 1, q + b + 1);
    sort(r + 1, r + c + 1);
    reverse(r + 1, r + c + 1);
    priority_queue<int,vector<int>,greater<int>> pq;
    for (int i = 1; i <= x; ++i)
        pq.push(p[i]);
    for (int i = 1; i <= y; ++i)
        pq.push(q[i]);
    for (int i = 1; i <= c; ++i)
    {
        if (r[i] > pq.top())
        {
            pq.pop();
            pq.push(r[i]);
        }
        else
            break;
    }
    ll sum = 0;
    while (!pq.empty())
    {
        sum += pq.top();
        pq.pop();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    for (int i = a; i < b+1; ++i) {
        if (c%i==0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <cstdlib>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define SORTR(v) sort((v).begin(),(v).end(),greater<int>())
const ll INF = (1LL << 40);
typedef pair<int, int> P;
const int MOD = 1000000007;

int main() {

	int l;
	cin >> l;

	long double maxv = (long double)l / 3;

	cout <<setprecision(10) <<maxv * maxv*maxv << endl;


	return 0;

}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		String s = scan.next();

		s = s.replace(",", " ");
		System.out.println(s);
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 26816
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

struct edge {
    int v1;
    int v2;
    int weigh;
};

#define VERTEX_MAX 10000
#define EDGES_MAX 100000

int asc(const void *a1, const void *a2) {
    struct edge *e1 = (struct edge*)a1;
    struct edge *e2 = (struct edge*)a2;
    return e1->weigh - e2->weigh;
}

struct ufind {
    int parent;
    int depth;
};

#define UPOOL_MAX (VERTEX_MAX+EDGES_MAX+10)
struct ufind upool[UPOOL_MAX];
int uidx;


struct ufind *create_union_find(int vs) {
    struct ufind *ufind = &upool[uidx];
    int i;
    uidx += vs;
    for(i = 0; i < vs; i++) {
        ufind[i].parent = i;
        ufind[i].depth = 1;
    }
    return ufind;
}

int get_root(struct ufind *ufind, int node) {
    struct ufind *v = &ufind[node];
    int base = node;
    while(base != v->parent) {
        // update
        base = v->parent;
        v = &ufind[base];
    }
    return base;
}

int is_same(struct ufind *ufind, int v1, int v2) {
    return get_root(ufind, v1) == get_root(ufind, v2);
}

// assume that v1 and v2 are separated.
void connect(struct ufind *ufind, int v1, int v2) {
    int b1 = get_root(ufind, v1);
    int b2 = get_root(ufind, v2);
    struct ufind *root1 = &ufind[b1];
    struct ufind *root2 = &ufind[b2];
    if(root1->depth >= root2->depth) { // root1 <- root2
        if(root1->depth == root2->depth) {
            root1->depth++;
        }
        // update
        root2->depth = root1->depth;
        root2->parent = b1;
    } else {
        // update
        root1->depth = root2->depth;
        root1->parent = b2;
    }
    return;
}

int main(void) {
    int vs, es;
    get_int2(&vs, &es);
    int i;
    struct edge edges[EDGES_MAX];
    for(i = 0; i < es; i++) {
        // 0-indexed
        get_int3(&edges[i].v1, &edges[i].v2, &edges[i].weigh);
    }

    qsort(edges, es, sizeof(struct edge), asc);
    int ans = 0;
    struct ufind *ufind = create_union_find(vs);
    int cnt = 0;
    for(i = 0 ; i< es; i++) {
        int v1 = edges[i].v1; int v2 = edges[i].v2;
        if(!is_same(ufind, v1, v2)) {
            connect(ufind, v1, v2);
            ans += edges[i].weigh;
            cnt++;
        }
        // Is tree configured?
        if(cnt == vs-1) break;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3892
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int A= gi();
	    int B= gi();
	    int C= gi();

	    if ((A==5 && B== 5 && C==7)
	    || (A==5 && B== 7 && C==5)
	    || (A==7 && B== 5 && C==5)) {
            System.out.print("YES");
	    }else {
	    	System.out.print("NO");
	    }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

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

int main(){
    string o,e;   cin>>o>>e;
    string ans;

    int minl=min(o.length(),e.length());

    for(int i=0;i<minl;i++){
        ans+=o[i];
        ans+=e[i];
    }

    if(o.length()!=e.length()){
        if(minl==o.length())ans+=e[e.length()-1];
        else ans+=o[o.length()-1];
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
      int A,B,C,D;
      
      std::cin >> A >> B >> C >> D;
      
      if((A+B)-(C+D) == 0)std::cout << "Balanced" << std::endl;

      else std::cout << ((A+B)-(C+D) > 0 ? "Left":"Right" ) << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX], n;

    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> R[i];
    int maxv = -2000000000;
    int minv = R[0];

    for(int i = 1; i < n; i++)
    {   
        if(maxv < R[i] - minv)
            maxv = R[i] - minv;
        if(minv > R[i])
            minv = R[i];
    }   
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MAXN = 100010;
int fa[MAXN];
void make_set(int n)
{
	for (int i = 1; i <= n; i++)fa[i] =  i;
}
int find(int x)
{
	return (x == fa[x]) ? x : fa[x] = find(fa[x]);
}
void merge(int x, int y)
{
	int xx = find(x), yy = find(y);
	fa[xx] = yy;
}
#define no second
#define w first
pair <int, int> node[MAXN];
priority_queue <pair <int, int>, vector <pair <int, int> >, greater <pair <int, int> > > component[MAXN];
int vis[MAXN];
int main()
{
	cin >> n >> m;
	if (m == n - 1)
	{
		cout << 0 << endl;
		return 0;
	}
	if (n < 2 * (n - m - 1))
	{
		cout << "Impossible" << endl;
		return 0;
	} 
	for (int i = 0; i < n; i++)
	{
		node[i].no = i;
		cin >> node[i].w;
	}
	sort(node, node + n);
	make_set(n);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		merge(u, v);
	}
	long long res = 0, cnt = 0;
	set <int> s;
	for (int i = 0; i < n; i++)
	{
		component[find(node[i].no)].push(node[i]);
		if (!s.count(find(node[i].no)))s.insert(find(node[i].no)), cnt++;
	}
	for (int i = 0; i < n; i++)
	{
		pair <int, int> now = component[find(node[i].no)].top();
		if (!vis[now.no])
		{
			res += now.w;
		//	cerr << now.w << endl;
			vis[now.no] = true;
		}
	}
//	for (int i = 0; i < n; i++)cerr << find(node[i].no) << endl;
	int i, j;
	for (i = 0, j = 1; i < n && j <= 2 * (n - m - 1) - cnt; i++)
		if (!vis[node[i].no])res += node[i].w, j++;
	if (j < 2 * (n - m - 1) - cnt)
	{
		cout << "Impossible" << endl;
		return 0;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 9216
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 1000050

struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b); }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};

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

    int n;ll c;
    cin>>n>>c;
    ll a[n];
    ifr(i,0,n) cin>>a[i];
    LineContainer li;
    ll dp[n];
    dp[0] = 0;
    li.add(2*a[0],-a[0]*a[0]);
    ifr(i,1,n) {
        dp[i] = c + a[i]*a[i] - li.query(a[i]);
        // cout<<-li.query(a[i])<<" "<<dp[i]<<endl;
        li.add(2*a[i],-1*(a[i]*a[i]+dp[i]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 15872
#include <cstdio>
#include <utility>

const int N = 1e2 + 10, M = 1e4 + 10;
int h, w, n, a[M], ans[N][N];

inline std::pair<int, int> next(std::pair<int, int> x) {
    if (x.first & 1) {
        if (x.second == w)
            return std::make_pair(x.first + 1, w);
        else
            return std::make_pair(x.first, x.second + 1);
    } else {
        if (x.second == 1)
            return std::make_pair(x.first + 1, 1);
        else
            return std::make_pair(x.first, x.second - 1);
    }
}

int main() {
    scanf("%d%d%d", &h, &w, &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    static int cur;
    for (auto i = std::make_pair(1, 1); i.first <= h; i = next(i)) {
        if (!a[cur])
            cur++;
        a[cur]--;
        ans[i.first][i.second] = cur;
    }
    for (int i = 1; i <= h; i++) {
        printf("%d", ans[i][1]);
        for (int j = 2; j <= w; j++)
            printf(" %d", ans[i][j]);
        putchar('\n');
    }
    return 0;
}



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

using namespace std;

int main(void){
    int a,b;
    int ans, dec;

    cin >> a >> b;

    ans = min(a,b);
    dec = max(a,b);

    for(int i=0; i<dec; i++){
        cout << ans;
    }

    cout << endl;
    

    return 0;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	int K;

	cin >> K;

	int curr = 7 % K;
	int pos = 1;

	vi vis(K);

	while (true) {
		if (!curr) {
			cout << pos << '\n';
			return 0;
		}
		if (vis[curr]) {
			cout << -1 << '\n';
			return 0;
		}
		vis[curr] = true;
		curr = (curr * 10 + 7) % K;
		++pos;
	}


	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
	return 0;
}


Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+45;

int n,m;
ll a[N];

class cmp{
public:
    bool operator ()(int i,int j){
        return (a[i]-a[i]/2) < (a[j]-a[j]/2);
    }
};

priority_queue <int,vector<int>,cmp> pq;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pq.push(i);
    }
    while(!pq.empty() && m--){
        int x = pq.top();
        pq.pop();
        a[x] = a[x]/2;
        pq.push(x);
    }
    ll s = 0;
    for(int i = 1; i <= n; i++){
        s += a[i];
    }
    cout << s << endl;
}


Measured memory_bytes: 1528
#include <stdio.h>
int main()
{
	int a[20],i,j,t;
	for(i=1;i<=10;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=1;i<=10;i++)
	{
		for(j=i+1;j<=10;j++)
		{
			if(a[i]<a[j])
			{
				t=a[i];
				a[i]=a[j];
				a[j]=t;
			}
		}
	}
	for(i=1;i<=3;i++)
	{
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cmath>
#include <iomanip>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int k, a, b;

bool flag=false;

int main() {

	cin >> k >> a >> b;

	for (int i = a; i <= b; i++) {
		if (i % k == 0)flag = true;
	}

	if (flag)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;

	return 0;

}

Measured memory_bytes: 3636
import itertools
import numpy as np
import math

N = int(input())

area_list = []
for _ in range(N):
    x, y = map(int, input().split())
    area_list.append((x, y))


def calc_dist(bef, aft):
    dist = np.sqrt((bef[0] - aft[0])**2 + (bef[1] - aft[1])**2)
    return dist

total_dist = 0
for one_root in itertools.permutations(area_list, N):
    for i in range(N-1):
        tmp_dist = calc_dist(one_root[i], one_root[i+1])
        total_dist += tmp_dist

ans = total_dist / math.factorial(N) 
print(ans)

Measured memory_bytes: 14508
#include <iostream>

using namespace std;

int main(){

  int a, b;
  int first, second, third;

  while(cin >> a >> b){
    first = a+b;
    second = a-b;
    third = a*b;

    if(first > second){
      if(first > third) cout << first << endl;
      else cout << third << endl;
    }
    else{
      if(second > third) cout << second << endl;
      else cout << third << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 256
while 1:
    n = int(input())
    if n == 0:
        break
    else:
        change = 1000-n
        sum_coin = 0
        coin = [500,100,50,10,5,1]

        for i in coin:
            r = change // i
            change %= i
            sum_coin += r
    
        print(sum_coin)


Measured memory_bytes: 5596
N = int(input())
S = [input() for i in range(N)]

import collections

c = collections.Counter(S)

#最頻値の個数
mx = c.most_common()[0][1]#c[max(c)]


L = set()
for s in S:
    if c[s] == mx:
        L.add(s)

L = list(L)
L.sort()
for l in L:
    print(l)



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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N, M;
    string tmp;
    map<string, int> Ns, Ms;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        Ns[tmp]++;
    }
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> tmp;
        Ms[tmp]++;
    }
    int ans = 0;
    for (auto x : Ns)
    {
        int tmp = x.second - Ms[x.first];
        ans = max(ans, tmp);
    }
    cout << ans;
}

Measured memory_bytes: 256
N = int(input())
str_input = list(input().split())
T1 = [(S[0],int(S[1])) for S in str_input]
T2 = [(S[0],int(S[1])) for S in str_input]

def bubble_sort(N,T):
    for i in range(N):
        flag = True
        while flag:
            flag = False
            for j in range(N-1, i, -1):
                if T[j][1] < T[j-1][1]:
                    tmp = T[j]
                    T[j] = T[j-1]
                    T[j-1] = tmp
                    flag = True
    return T

def selection_sort(N,T):
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if (T[j][1] < T[min_index][1]):
                min_index = j
        if (min_index != i):
            tmp = T[i]
            T[i] = T[min_index]
            T[min_index] = tmp
    return T

def is_stable(bT, sT):
    for i, st in enumerate(sT):
        if(st[0] != bT[i][0]):
            return False
    return True

def print_trump(T):
    strT = ['{}{}'.format(t[0],t[1]) for t in T]
    print(str(strT).replace(',','').replace('[','').replace(']','').replace("'",''))
    
bT = bubble_sort(N, T1)
sT = selection_sort(N, T2)
print_trump(bT)
print('Stable')
print_trump(sT)
stability = 'Stable' if is_stable(bT,sT) else 'Not stable'
print(stability)


Measured memory_bytes: 5612
import sys
si = sys.stdin.readline


def main():
    n = int(si())
    ans = [0 for _ in range(10000+1)]
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 100):
                v = ((x+y+z)**2+x**2+y**2+z**2)//2
                if v > 10000:
                    break
                ans[v] += 1

    for i in range(n):
        print(ans[i+1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9208