akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
    
    static final int MOD = (int)1e9 + 7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        String a = sc.next();
        boolean[] s = new boolean[n+1];
        for(int i=0; i<n; i++){
            if(a.charAt(i) == '1'){
                s[n-i] = true;
            }
        }
        
        int[] dp = new int[n+1];
        LinkedList<String> ans = new LinkedList<>();
        for(int i=0; i<n; ){
            int next = Math.min(i+m, n);
            boolean ok = false;
            for(; next>i; next--){
                if(!s[next]){
                    dp[next] = dp[i]+1;
                    ans.addFirst(String.valueOf(next-i));
                    i = next;
                    ok = true;
                    break;
                }
            }
            
            if(!ok){
                System.out.println(-1);
                return;
            }
        }
        
        System.out.println(String.join(" ", ans));
    }
    
}

Measured memory_bytes: 48356
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef unsigned long long ll;

const int MAX = 50;
int n, m;
bool graph[MAX][MAX];
bool visited[MAX];

void dfs(int n)
{
  visited[n] = true;
  for (int i = 0; i < m; i++) {
    if (!graph[n][i]) continue;
    if (visited[i]) continue;
    dfs(i);
  }
}

int main()
{
  cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

    for (int j = 0; j < n; j++) visited[j] = false;

    dfs(0);

    bool bridge = false;
    for (int j = 0; j < n; j++) if (!visited[j]) bridge = true;
    if (bridge) cnt++;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  cout << cnt << endl;
}


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


int main(){
    int n, k;
    int p[1010];
    vector<int> vec;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        vec.push_back(p[i]);
    }
    
    sort(vec.begin(), vec.end());
    
    int ret = 0;
    for(int i = 0; i < k; i++){
        ret += vec[i];
    }
    
    cout << ret << '\n';
        
    
    
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 2e5 + 10;
const ll oo = 1e18;

ll n, m;

ll f(ll x, ll d) {
  if (x > d) return d;
  return (d % x) + f(x, d / x);
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  cin >> n >> m;
  ll ans = oo;
  if (m > n) return cout << -1, 0;
  if (n == m) ans = min(ans, n + 1);

  for (ll i = 2; i * i <= n; ++i) {
    if (f(i, n) == m) ans = min(ans, i);
  }
  ll k = n - m;

  for (ll p = 1; p * p <= k; ++p) {
    if (p > m) break;
    ll ret = k / p + 1;
    ll q = n - (p * ret);
    if (p + q == m && q < ret) ans = min(ans, ret);
  }

  cout << (ans == oo ? -1 : ans);
  return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;
  cin>>n;
  vector<int> v(n),c(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  for(int i=0;i<n;i++){
    cin>>c[i];
    if(v[i]-c[i]>0)sum+=v[i]-c[i];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll,ll>

using namespace std;
typedef long long ll;



int main(void) {
	int h, a,cnt=0; cin >> h >> a;
	while (h>0) {
		h -= a;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];

    int res=0;
    rep(i,n){
        int tmp=0;
        for(int j=i; j<n-1; j++){
            if(a[j]>=a[j+1]) tmp++;
            else break;
        }
        chmax(res,tmp);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3964
from collections import defaultdict as dd
w = raw_input()

countlist = dd(int)
for i in range(len(w)):
    countlist[w[i]] += 1

flag = True
for value in countlist.itervalues():
    if value % 2 != 0:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")


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

#define NIL NULL
#define INF 1000000001

using namespace std;



struct node {
    int key;
    struct node *right;
    struct node *left;
    struct node *parent;
};
typedef node * Node;



Node root = NIL;

void insert(int key){
    Node y = NIL;
    Node x = root;
    Node z;

    z = (Node)malloc(sizeof(struct node));
    z->key  = key;
    z->left = NIL;
    z->right= NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;

    if(y == NIL)root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;     
}

Node findElement(Node current_node,int v){
    if(current_node == NIL) return NIL;
    else if(current_node->key == v) return current_node;
    else if(current_node->key > v) return findElement(current_node->left, v);
    else if(current_node->key < v) return findElement(current_node->right,v);
}

Node getSuccessor(Node current_node){
    if(current_node->right != NIL){
        current_node = current_node->right;
        while(current_node->left != NIL){
            current_node = current_node->left;
        }
        return current_node;
    }
    Node y = current_node->parent;
    while(y != NIL && current_node == y->right){
        current_node = y;
        y = y->parent;
    }
    return y;
}

void deleteNode(Node current_node){
    Node y = NIL;
    if(current_node->left == NIL || current_node->right == NIL) y = current_node;
    else y = getSuccessor(current_node);
    
    Node x  = NIL;
    if(y->left != NIL) x = y->left;
    else x = y->right;
    
    if(x != NIL) x->parent = y->parent;
    if(y->parent == NIL) root = x;
    else if(y == y->parent->left) y->parent->left = x;
    else if(y == y->parent->right) y->parent->right = x;

    if(y != current_node) current_node->key = y->key;
}


void inOrder(Node current_node){
    if(current_node == NIL) return;
     inOrder(current_node->left);
    printf(" %d",current_node->key);
    inOrder(current_node->right);
}

void preOrder(Node current_node){
    printf(" %d",current_node->key);
    if(current_node->left != NIL)        preOrder(current_node->left);
    if (current_node->right != NIL) preOrder(current_node->right);
}



int main(){
    int num_query;
    char command[20];
    
    int key;
    scanf("%d",&num_query);
    for(int i = 0;i < num_query;i++){
        scanf("%s",command);
        if(command[0] == 'i'){
            scanf("%d",&key);
            insert(key);
        }else if(command[0] == 'f'){
            scanf("%d",&key);
            if(findElement(root,key)!=NIL) printf("yes\n");
            else printf("no\n");
        }else if(command[0] == 'p'){
            inOrder(root);printf("\n");
            preOrder(root);printf("\n");
        }else if(command[0] == 'd'){
            scanf("%d",&key);
            Node z = findElement(root,key);
            deleteNode(z);
        }
    }
    return 0;   
}



Measured memory_bytes: 21944
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n = in();
  vi a(n);
  rep(i,n) cin>>a[i];
  double ans = 0.0;
  rep(i,n) ans += 1.0/a[i];
  
  cout << setprecision(12) << 1.0/ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e9+7;
const int N=3010;
int n,q,a[N];
int dp[N][N];
int x[N],y[N];
int ans;
int tmp1[N],tmp2[N],tmp3[N];
void ADD(int &x,int y){
    (x+=y)>=M?x-=M:0;
}
void HALF(int &x){
    x&1?(x+=M)>>=1:x>>=1;
}
void HALFPLUS(int &x,int y){
    ADD(x,y);
    HALF(x);
}
int fp(int x,int y){
    int ret=1;
    for (; y; y>>=1,x=(ll)x*x%M)
	if (y&1) ret=(ll)ret*x%M;
    return ret;
}
int main(){
    cin>>n>>q;
    for (int i=1; i<=n; ++i) scanf("%d",&a[i]);
    for (int i=1; i<=q; ++i){
	scanf("%d%d",&x[i],&y[i]);
    }
    for (int i=1; i<=n; ++i)
	for (int j=1; j<=n; ++j){
	    dp[i][j]=(a[i]>a[j]);
	}
    for (int i=1; i<=q; ++i){
	int a=x[i],b=y[i];
	/*cerr<<a<<" "<<b<<endl;
	for (int i=1; i<=n; ++i)
	    for (int j=1; j<=n; ++j)
	    cerr<<i<<" "<<j<<" "<<dp[i][j]<<endl;*/
	//cerr<<"!!!!!!!";
	for (int i=1; i<=n; ++i) tmp1[i]=dp[a][i];
	for (int i=1; i<=n; ++i) tmp2[i]=dp[i][a];
	int ttt=dp[a][b];
	HALFPLUS(dp[a][b],dp[b][a]);
	HALFPLUS(dp[b][a],ttt);
	for (int j=1; j<=n; ++j)
	    if (j!=b&&j!=a){
		HALFPLUS(dp[a][j],dp[b][j]);
		HALFPLUS(dp[j][a],dp[j][b]);
	    }
	for (int j=1; j<=n; ++j)
	    if (j!=a&&j!=b){
		HALFPLUS(dp[b][j],tmp1[j]);
		HALFPLUS(dp[j][b],tmp2[j]);
	    }
	//don't swap
	/*for (int i=1; i<=n; ++i)
	    for (int j=1; j<=n; ++j)
		cerr<<i<<" "<<j<<" "<<dp[i][j]<<endl;*/
	//return 0;
    }
    for (int i=1; i<=n; ++i)
	for (int j=i+1; j<=n; ++j)
	    ADD(ans,dp[i][j]);
    cout<<(ll)ans*fp(2,q)%M;
}

Measured memory_bytes: 35712
// https://atcoder.jp/contests/diverta2019/tasks/diverta2019_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v(3);
    int n, ans = 0;
    cin >> v[0] >> v[1] >> v[2] >> n;
    sort(ALLR(v));
    REP(i1, n / v[0] + 1) REP(i2, n / v[1] + 1) {
        int t = i1 * v[0] + i2 * v[1];
        if (t > n) {
            break;
        } else if ((n - t) % v[2] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

constexpr int MAX_N = 6;
constexpr int MAX_V = 4 * MAX_N + 1;

enum { L = 1, M = 2, H = 3, N = 4 };

int n;
int low[MAX_N], high[MAX_N];

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

	while(cin >> n && n) {
		const int V = 4 * n + 1;

		// construct NFA
		vector<unordered_map<int, int>> G_nfa(V);
		for(int i = 0; i < n; ++i) {
			const int v = 4 * i;

			cin >> low[i] >> high[i];

			const int low_f = low[i] / 10;
			const int low_s = low[i] % 10;
			const int high_f = high[i] / 10;
			const int high_s = high[i] % 10;

			const int l_from = (low_f ? v + L : v);

			if(low_f) G_nfa[v][low_f] |= (1 << (v + L));

			if(low_f == high_f) {
				for(int j = low_s; j <= high_s; ++j) {
					G_nfa[l_from][j] |= (1 << (v + N));
				}
			}
			else {
				G_nfa[v][high_f] |= (1 << (v + H));

				for(int j = low_s; j < 10; ++j) {
					G_nfa[l_from][j] |= (1 << (v + N));
				}

				for(int j = 0; j <= high_s; ++j) {
					G_nfa[v + H][j] |= (1 << (v + N));
				}

				if(low_f + 1 < high_f) {
					for(int j = low_f + 1; j < high_f; ++j) {
						G_nfa[v][j] |= (1 << (v + M));
					}

					for(int j = 0; j < 10; ++j) {
						G_nfa[v + M][j] |= (1 << (v + N));
					}
				}
			}
		}

		// construct DFA and topological sort
		unordered_map<int, unordered_map<int, int>> G_dfa;
		unordered_map<int, int> in;
		queue<int> que;
		que.push(1);

		while(!que.empty()) {
			const int state = que.front();
			que.pop();

			for(int i = state; i > 0; i -= i & -i) {
				const int v = __builtin_ctz(i & -i);

				for(const auto &e : G_nfa[v]) {
					G_dfa[state][e.first] |= e.second;
				}
			}

			for(const auto &e : G_dfa[state]) {
				const int to_state = e.second;

				if(++in[to_state] == 1) {
					que.push(to_state);
				}
			}
		}

		// dp
		const int accept_state = (1 << 4 * n);

		long long ans = 0;
		unordered_map<int, long long> dp;

		dp[1] = 1;
		que.push(1);

		while(!que.empty()) {
			const int state = que.front();
			que.pop();

			if(state & accept_state) {
				ans += dp[state];
			}

			for(const auto &e : G_dfa[state]) {
				const int to_state = e.second;
				dp[to_state] += dp[state];

				if(--in[to_state] == 0) {
					que.push(to_state);
				}
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define rep1(i,n) for (int i=1; i<=(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fst first
#define scd second
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  int ans = 0;
  rep(i,n) {
    cin >> a[i];
    ans+=a[i];
  }
  ans -= n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool f[110][110];
int main() {
	ll n,k;
	cin>>n>>k;
	if(k>(n-1)*(n-2)/2)cout<<-1<<endl;
	else{
		ll num=n*(n-1)/2;
		ll nowl=1,nowr=2;
		for(int i=1;i<=k;i++){
			if(nowr!=n){
				f[nowl][nowr]=1;
				nowr++;
				num--;
			}
			else{
				nowl++,nowr=nowl+1;
				f[nowl][nowr]=1;
				nowr++;
				num--;
			}
		}
		cout<<num<<endl;
		for(int i=1;i<n;i++)for(int j=i+1;j<=n;j++)if(!f[i][j])cout<<i<<' '<<j<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  vector<int> v(5);
  rep(i,5){
    cin >> v[i];
    if(v[i]==0){
      cout << i+1 << endl;
    }
  }
}


Measured memory_bytes: 3584
#include<stdio.h>
int main(void){
    int count[4][3][10]={0},n=0,b,f,r,v,i;
    char sikiri[20];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        if(v>=0){
            count[b-1][f-1][r-1]+=v;
        }else{
            count[b-1][f-1][r-1]+=v;
        }
    }
    for(i=0;i<20;i++){
        sikiri[i]='#';
    }
    for(b=0;b<4;b++){
        for(f=0;f<3;f++){
            for(r=0;r<10;r++){
                printf(" %d",count[b][f][r]);
            }
            printf("\n");
        }
        if(b<3){
            for(i=0;i<20;i++){
                printf("%c",sikiri[i]);
                if(i==19){
                    printf("\n");
                }
            }
        }
    }
    return 0;
}


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

void solve(long long N, long long K)
{
    cout << min(N % K, abs(N % K - K)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    solve(N, K);
    return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    int cur = N;
    reps(i, N) {
        int s = 0;
        while (cur > 0 && N / cur == i) {
            s += cur;
            cur--;
        }
        ans += i * (i + 1) / 2 * s;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=300005;
int onX[N]{}, onY[N]={};
int has( int x, int y)
{
    return x*1000000+y;
}

void solve()
{
    int n,m,k,i=1,j,x,y,l,r,p,q,z;
    ll ans=0;
    cin>>n>>m>>k;
    int maxX=0, maxY=0;
    set<int> pairs;
    set<int> xs, ys;
    for(i=0;i<k;i++)
    {
        cin>>x>>y;
        onX[x]++;
        onY[y]++;
        if(maxX<onX[x])
            maxX=onX[x];
        if(maxY<onY[y])
            maxY=onY[y];
        pairs.insert(has(x,y));
    }
    set<int> xwant, ywant;
    ans=maxX+maxY-1;
    for(i=0;i<=n;i++)
    {
        if(onX[i]==maxX)
        {
            xwant.insert(i);
        }
    }
    for(i=0;i<=m;i++)
    {
        if(onY[i]==maxY)
        {
            ywant.insert(i);
        }
    }
    for(int x: xwant)
    {
        for(int y: ywant)
        {
            if(!pairs.count(has(x,y)))
            {
                ans++;
                cout<<ans;
                return;
            }
        }
    }
    cout<<ans;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 48084
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] dist = new boolean[N];

		int btn = 0;
		int ans = -1;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 50028
a = int(input())
b = list(map(int,input().split()))

def bublesort(b,a):
    count =0
    for j in range(len(b)-1):
        for i in range(len(b)-1,0,-1):
            if b[i-1]>b[i]:
                b[i-1],b[i]=b[i],b[i-1]
                count +=1
    return count,b

A,B =bublesort(b,a)
print(*B)
print(A)




Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    string S;cin>>S;
    int a=0,b=0;
    rep(i,S.size()){
        if(S[i]=='0')a++;
        else b++;
    }
    cout<<min(a,b)*2<<endl;
    return 0;
}

Measured memory_bytes: 512
# ABC073D - joisino's travel (218ms)
from heapq import heapify, heappop, heappush
from itertools import permutations


def dijkstra(G: "Array[Array[int]]", size: int, start: int) -> list:
    dist = [float("inf")] * size
    queue = [(0, start)]
    heapify(queue)
    while queue:
        cost, v = heappop(queue)
        if cost > dist[v]:
            continue
        dist[v] = cost
        for next_cost, u in G[v]:
            if cost + next_cost < dist[u]:
                heappush(queue, (cost + next_cost, u))
    return dist


def main():
    global G, N
    N, M, R, *RABC = map(int, open(0).read().split())
    visit, ABC = RABC[:R], RABC[R:]
    G = [[] for _ in range(N + 1)]
    for v, u, cost in zip(*[iter(ABC)] * 3):
        G[v].append((cost, u)), G[u].append((cost, v))
    dist = {v: dijkstra(G, N + 1, v) for v in visit}
    ans = float("inf")
    for perm in permutations(visit):
        cur = sum(dist[v][u] for v, u in zip(perm, perm[1:]))
        ans = min(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9828
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } else return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } else return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;

int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) cout << n << endl;
	else cout << n * 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  string t, s; cin >> s >> t;
  int sizes = s.size(), sizet = t.size(), maxsame = 0;
  for(int i = 0; i  < sizes -sizet +1; i++) {
    int counter = 0;
    for(int j = 0; j < sizet; j++) {
      if(t.at(j) == s.at(j +i)) {
        counter++;
      }
    }
    if(counter > maxsame) {
      maxsame = counter;
    }
  }
  cout << sizet - maxsame << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
	double a;
	while (cin>>a) {
		double s[10], res=a;
		s[0]=a;
		for (int i=1; i<10; i++) {
			if (i%2==0) {
				s[i]=s[i-1]/3.0;
			} else {
				s[i]=s[i-1]*2.0;
			}
			res+=s[i];
		}
		printf("%.8f\n",res);
	}
}

Measured memory_bytes: 0
N,M=map(int,input().split(" "))

if(M==0):
    if(N==1):
        print(0)
    elif(N==2):
        print(10)
    elif(N==3):
        print(100)
    exit()



listing=[]

for i in range(M):
    a=list(map(int,input().split(" ")))
    listing.append(a)


aa=list(map(list, set(map(tuple, listing))))




a1=[]
a2=[]
for i in aa:
    a1.append(i[0])
    a2.append(i[0])
if(len(a1)!=len(set(a2))):
    print(-1)
    exit()

if(N==1 and aa[0][0]==1):
    print(aa[0][1])
    exit()
num=""
#print(aa)
digit=1
digit1=1
for i in range(N):
    digit1=digit
    for j in aa:
        if(j[0]==1 and j[1]==0):
            print(-1)
            exit()
        if(j[0]==digit):
            num+=str(j[1])
            digit1=digit+1
            break
    if(digit1==digit):
        if(digit==1):
            num+="1"
        else:
            num+="0"
    digit+=1
print(num)
            


Measured memory_bytes: 3064
def l_inf_dist(x,y,x0,y0):
    return max(abs(x - x0), abs(y - y0))

N = int(input())
pts = [tuple(map(int, input().split())) for _ in range(N)]
pts_conv_x = [pts[i][1] + pts[i][0] for i in range(N)]
pts_conv_y = [pts[i][1] - pts[i][0] for i in range(N)]

x_max_ind = pts_conv_x.index(max(pts_conv_x))
x_min_ind = pts_conv_x.index(min(pts_conv_x))
y_max_ind = pts_conv_y.index(max(pts_conv_y))
y_min_ind = pts_conv_y.index(min(pts_conv_y))

x_max_pt = (pts_conv_x[x_max_ind], pts_conv_y[x_max_ind])
x_min_pt = (pts_conv_x[x_min_ind], pts_conv_y[x_min_ind])
y_max_pt = (pts_conv_x[y_max_ind], pts_conv_y[y_max_ind])
y_min_pt = (pts_conv_x[y_min_ind], pts_conv_y[y_min_ind])

dist_max = 0
for i in range(N):
    dist_max = max(dist_max, l_inf_dist(x_max_pt[0], x_max_pt[1], pts_conv_x[i], pts_conv_y[i]), l_inf_dist(x_min_pt[0], x_min_pt[1], pts_conv_x[i], pts_conv_y[i]), l_inf_dist(y_max_pt[0], y_max_pt[1], pts_conv_x[i], pts_conv_y[i]), l_inf_dist(y_min_pt[0], y_min_pt[1], pts_conv_x[i], pts_conv_y[i]))

print(dist_max)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;


ll gcd(ll a, ll b){
    if(a < b){
        swap(a, b);
    }
    if(a % b == 0){
        return b;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}
int main() {
    //cout.precision(10);
    ll n, m;
    cin >> n >> m;
    string s,t;
    cin >> s >> t;
    ll ans = lcm(n, m);
    for(ll i = 0; i < n; i++){
        ll pos = i * m;
        if(pos % n != 0){
            continue;
        }
        ll j = pos / n;
        if(s[i] != t[j]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <cstdlib> 

using namespace std;

const int maxn=2e5+1e2;
#define LL long long

int a[maxn];

int getint()
{
	char ch;int b=1;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar())if(ch=='-')b=-1;
	int num=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())num=num*10+ch-'0';
	return num*b;
}

int main()
{
	int n=getint();
	LL sum=0;
	for(int i=1;i<=n;i++){a[i]=getint();sum+=a[i];}
	LL re=0,ans=1e17;
	for(int i=1;i<n;i++)
	{
		re+=a[i];
		ans=min(ans,abs(sum-re-re));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <climits>
#include <cmath>
using namespace std;

int main() {
  int N;
  cin>>N;
  int A[N];
  int ave=0;
  for (int i=0; i<N; i++) {
    cin>>A[i];
    ave+=A[i];
  }
  ave/=N;
  bool f=false;
  for (int i=0; i<N; i++) {
    if (A[i]!=A[i+1]) {
      f=true;
    }
  }
  int ans=INT_MAX;
  for (int i=ave-1; f && i<ave+2; i++) {
    int cost=0;
    for (int j=0; j<N; j++) {
      cost+=pow(A[j]-i,2);
    }
    ans=min(ans,cost);
  }
  if (!f) {
    cout<<0<<endl;
  } else {
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll,ll> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 

int main() {
   ll n;
   cin >> n;
   vector<double> x(n);
   vector<string> u(n);
   rep(i,n) cin >> x[i] >> u[i];
   long double ans=0;
   rep(i,n){
      if(u[i]=="JPY") ans+=x[i];
      else ans+=x[i]*380000;
   }
   cout << fixed << setprecision(10);
   cout << ans << endl;
}



Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            for j in range(W):
                if (i+j) % 2 == 0:
                    print('#', end='')
                else:
                    print('.', end='')
            print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef vector<vector<int>> graph;


int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    int n,m; cin>>n>>m;
    int a=max(n,m),b=min(n,m);
    if((a-b)%2==0)cout<<b+(a-b)/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

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

ll c[20], a[20][20], tmp[15];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    ll ans = 2e18;
    for(int i = 0; i < (1 << n); i++){
        memset(tmp, 0, sizeof tmp);
        ll cost = 0;
        for(int j = 0; j < n; j++){
            if(i >> j & 1){
                cost += c[j];
                for(int k = 0; k < m; k++){
                    tmp[k] += a[j][k];
                }
            }
        }
        bool found = 0;
        for(int j = 0; j < m; j++){
            if(tmp[j] < x) found = 1;
        }
        if(!found) ans = min(ans, cost);
    }
    if(ans > 1e15) ans = -1;
    cout << ans;



    return 0;
}



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

int main(){
    long long x;
    cin >> x;

    if(x < 100){
        printf("0\n");
        return 0;
    }

    if(x <= 105){
        printf("1\n");
        return 0;
    }

    bool dp[x+1];

    for(long long i = 0; i < 100; i++){
        dp[i] = false;
    }
    dp[100] = true;
    dp[101] = true;
    dp[102] = true;
    dp[103] = true;
    dp[104] = true;
    dp[105] = true;

    for(long long i = 106; i <= x; i++){
        if(dp[i-100] == true || dp[i-101] == true || dp[i-102] == true || dp[i-103] == true || dp[i-104] == true || dp[i-105] == true){
            dp[i] = true;
        }
        else{
            dp[i] = false;
        }
    }
    if(dp[x] == true){
        printf("1\n");
    }
    else{
        printf("0\n");
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  cin >> a;
  cin >> b;
  if (a*b%2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,p=1000000007;
long long v[100020];
long long f[100020];
long long ans;
long long C(int n, int m) 
{
	return f[n]*v[m]%p*v[n-m]%p;
}
int main() {
	v[0]=v[1]=f[0]=f[1]=1;
	for(int i=2;i<=100010;i++) 
		v[i]=v[p%i]*(p-p/i)%p;
	for(int i=2;i<=100010;i++) 
	{
		f[i]=f[i-1]*i% p;
		v[i]=v[i-1]*v[i]%p;
	}
	scanf("%d%d",&n,&m);
	ans=n+1;
	for(int i=1;i<m;i++) 
	{
		if(m-i>n)
			continue;
		for(int j=1;j<=m-i;j++) 
		{
			if((m-i)+(m-i-j)>n) 
				continue;
			ans+=C(m-1,i-1)*C(m-i-1,j-1)%p*C(n-(m-i)-(m-i-j)+2,2)%p;
			ans%=p;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1920
n = int(input())
t, a = (int(i) for i in input().split())
list_h = [int(i) for i in input().split()]
tmp = 999
ans = 0
for i in range(0, n):
    if tmp > abs((t - list_h[i] * 0.006) - a):
        tmp = abs((t - list_h[i] * 0.006) - a)
        ans = i
print(ans + 1)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace  std;
#define ll long long
ll fact(ll n)
{
  ll k = sqrt(n);
  pair<ll,ll> p;
  ll m = LLONG_MAX;
  for(int i = 1 ; i <=k;i++)
  {
    if(n%i==0)
    {


    if((n/i)+i < m)
    {
      m = (n/i)+i;


    }

  }
}
  return m-2;
}
int main()
  {
  ll a;
  cin>>a;
  cout <<fact(a)<<endl;

  }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N)cin >> A[i];

    REP(i, N) {
        A[i] -= (i + 1);
    }
    sort(ALL(A));
    ll x = A[N / 2];
    ll ans = 0;
    REP(i, N) {
        ans += abs(A[i] - x);
    }

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

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

#define NMAX 2000001

int c[NMAX],n;

void CountingSort(int *, int *, int);

int main(){

  int i,*a,*b,k=0;

  scanf("%d",&n);

  a = malloc(sizeof(int)*(n+1));
  b = malloc(sizeof(int)*(n+1));

  for(i = 1 ; i <= n ; i++){
    scanf("%d",&a[i]);
    if(k < a[i]) k = a[i];
  }

  CountingSort(a, b, k);

  for(i = 1 ; i <= n ; i++){
    if(i == n) printf("%d\n",b[i]);
    else printf("%d ",b[i]);
  }
  
  return 0;

}


void CountingSort(int *a, int *b, int k){

  int i,j;

  for(i = 0 ; i <= k ; i++) c[i] = 0;

  for(j = 1 ; j <= n ; j++) c[a[j]]++;

  for(i = 1; i <= k ; i++) c[i] = c[i] + c[i-1];

  for(j = n ; j >= 1 ; j--){
    b[c[a[j]]] = a[j];
    c[a[j]]--;
  }

}

Measured memory_bytes: 16272
#include<stdio.h>
#include<stdlib.h>
long cmp(const void *a,const void *b){
  return *(long*)a - *(long*)b;
}

int main(){
  long n = 0;
  long a[100000] = {};
  long i = 0;
  long cnt = 0;
  long sum = 0;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  qsort(a,n,sizeof(long),cmp);
  for(i=0;i<n-1;i++){
    sum += a[i];
    if(2*sum < a[i+1]){
      cnt = i+1;
    }
  }
  printf("%ld",n-cnt);
  return 0;
}
      


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

long long lcm(long a,long b);

int main() {

	int count = 0;
	long c, d, u, v, w, x, y, z;
	long long min, max, lcma;

	cin >> min >> max >> c >> d;

	lcma = lcm(c, d);
	min -= 1;

	u = min / c;
	v = min / d;
	w = min / lcma;

	x = max / c;
	y = max / d;
	z = max / lcma;

	min = min - u - v + w;
	max = max - x - y + z;

	//cout << min << '-' << u << '-' << v << '+' << w << endl;

	cout << max - min << endl;

	return 0;
}

long long lcm(long a,long b) {

	long t, num;
	long long lcm;

	if (a < b) {
		t = a;
		a = b;
		b = t;
	}

	lcm = (long long)a * b;

	num = a % b;
	while (num != 0) {
		a = b;
		b = num;
		num = a % b;
	}

	lcm /= b;
	
	return  lcm;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.algorithm.comparison;
import std.algorithm.searching;

int[] a;
bool[3] b;
bool f;
uint nest = 0;
ulong maxIndex(int[] a){
	int max = a[0];
	ulong index = 0;
	foreach(i,n; a){
		if(n > max){
			max = n;
			index = i;
		}
	}
	return index;
}
ulong minIndex(int[] a){
	int min = a[0];
	ulong index = 0;
	foreach(i,n; a){
		if(n < min){
			min = n;
			index = i;
		}
	}
	return index;
}
void check(){
	b = new bool[3];
	f = false;
	if(a[0] == a[1] && a[1] == a[2]){
		return;
	}
	auto mx = a.maxIndex;
	foreach(i,n; a){
		if(i != mx && n == a[mx]){
			f = true;
			break;
		}
	}
	if(f){
		a[a.minIndex] += 2;
	}else{
		b[mx] = true;
		for(int i = 0; i < 3; ++i){
			if(!b[i]){
				a[i]++;
			}
		}
	}
	nest++;
	check();
}
void main(){
	a = new int[3];
	readf("%d %d %d", &a[0], &a[1], &a[2]);
	check();
	nest.writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

int main () {
  int n;
  string w;
  cin >> n >> w;
  if ((n & 1) == 1) {
    cout << "No" << '\n';
    return 0;
  }
  int m = n / 2;
  string a = w.substr(m);
  a += a;
  cout << (a == w ? "Yes" : "No") << '\n';
  return 0;
}


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

int max(int a,int b){
    return a>b?a:b;
}

int main(){
    int N,W;
    cin >> N >> W;
    long long v[101],w[101];
    for(int i=1;i<=N;i++) cin >> w[i] >> v[i];

    int **dp=new int*[101];
    for(int i=0;i<=100;i++) dp[i]=new int[30601];

    if(w[1]<=300){
        for(int j=0;j<=N*(w[1]+3);j++) dp[0][j]=0;
        for(int i=1;i<=N;i++){
            for(int j=0;j<=N*(w[1]+3);j++){
                if(j<w[i]) dp[i][j]=dp[i-1][j];
                else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            }
        }
        if(W>N*(w[1]+3)) cout << dp[N][N*(w[1]+3)] << endl;
        else cout << dp[N][W] << endl;
    }else{
        for(int j=0;j<=30600;j++) dp[0][j]=0;
        for(int i=1;i<=N;i++){
            for(int j=0;j<=N;j++){
                for(int k=0;k<=300;k++){
                    if(j*w[1]+k<w[i]) dp[i][j*301+k]=dp[i-1][j*301+k];
                    else if(w[i]-w[1]<=k) dp[i][j*301+k]=max(dp[i-1][j*301+k],dp[i-1][(j-1)*301+(k-(w[i]-w[1]))]+v[i]);
                    else dp[i][j*301+k]=max(dp[i-1][j*301+k],dp[i-1][(j-2)*301+300]+v[i]);
                }
            }
        }
        if(W>N*w[1]+300) cout << dp[N][N*301+300] << endl;
        else if(W%w[1]>300) cout << dp[N][W/w[1]*301+300] << endl;
        else cout << dp[N][(W/w[1])*301+(W%w[1])] << endl;
    }

    for(int i=0;i<=100;i++) delete[] dp[i]; 
    delete[] dp;
    return 0;
}

Measured memory_bytes: 12288
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    double[] x, y;
    int i;
    double sum, ax, ay, bx, by;

    n = sc.nextInt();
    x = new double[n];
    y = new double[n];

    for(i = 0;i < n;i++){
      x[i] = sc.nextDouble();
      y[i] = sc.nextDouble();
    }
    sc.close();

    sum = 0.0;
    for(i = 0;i < n - 2;i++){
      ax = x[i + 1] - x[0];
      ay = y[i + 1] - y[0];
      bx = x[i + 2] - x[0];
      by = y[i + 2] - y[0];
      sum += (ax * by - ay * bx) / 2.0;
    }

    System.out.printf("%.1f%n", sum);

  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20604
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {

    ll N;
    cin >> N;
    map<ll,ll> mp;
    vector<ll> v;
    ll A = 0;
    rep(i,N){
        cin >> A;
        if(mp.count(A)){
            mp.erase(A);
            v.push_back(A);
        }else mp.emplace(A,1);
    }
    sort(v.begin(),v.end());
    ll M = v.size();
    ll out = 0;
    if(M>1) out = v[M-1]*v[M-2];
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 6528
K = int(input())

cur = 7 % K
index = 1
for _ in range(2 * 10 ** 6):
    if cur == 0:
        break
    index += 1
    cur *= 10
    cur += 7
    cur %= K

if index > 10 ** 6 + 20:
    print(-1)
else:
    print(index)

Measured memory_bytes: 63312
#include<stdio.h>
int main(){
  int N,M,i;
  scanf("%d %d",&N,&M);
  int a[M],b[M],c[200000],d[200000];
  for(i=0;i<200000;i++){
    c[i]=0;
    d[i]=0;
  }
  for(i=0;i<M;i++){
    scanf("%d %d",&a[i],&b[i]);
  }
  for(i=0;i<M;i++){
    if(a[i]==1){
      c[b[i]]=1;
    }
    if(b[i]==N){
      d[a[i]]=1;
    }
  }
  for(i=0;i<200000;i++){
    if(d[i]==1 && c[i]==1){
      printf("POSSIBLE");
      return 0;    
    }
  }
  printf("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>

#define N 100000
#define NIL -1
typedef struct{
  int par;
  int left;
  int right;
}node_tree;


node_tree C[N];
int n;
int D[N];

//深さ
int Deep(int a){
  int d;
  for(d=0;C[a].par!=NIL;d++){
    a=C[a].par;
  }
  return d;
}



//結果出力と判定
void Printing(int a){
  int i;
  printf("node %d: parent = %d, depth = %d, ",a,C[a].par,D[a]);
  if(C[a].par==NIL){
    printf("root, ");
  }
  else if(C[a].left!=NIL){
    printf("internal node, ");
  }
  else if(C[a].left==NIL){
    printf("leaf, ");
  }
   printf("[");
  if(C[a].left!=NIL){
    printf("%d",C[a].left);
    a=C[a].left;
    if(C[a].right!=NIL) printf(", ");
     
    while(C[a].right!=NIL){
      printf("%d",C[a].right);
      a=C[a].right;
      if(C[a].right!=NIL) printf(", ");
    }
  }
  printf("]\n");
}
 





main(){
  int i,j,deg,ver,ch,l;
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    C[i].par=NIL;
    C[i].left=NIL;
    C[i].right=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&ver,&deg);
    for(j=0;j<deg;j++){
      scanf("%d",&ch);
      C[ch].par=ver;
      if(j==0) C[ver].left=ch;
      if(j>0) C[l].right=ch;
      l=ch;
    }
  }
  //深さをループで回していく
  for(i=0;i<n;i++){
    D[i]=Deep(i);
  }
  //それぞれの出力にはループを回しながら
  for(i=0;i<n;i++){
    Printing(i);
  }
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int> (m));
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            cin>>a[i][j];
        }
    }
    int money = big;
    bool ans = true;
    for(int tmp = 0;tmp<(1<<n);tmp++){
        bitset<13> bit(tmp);
        //cout<<bit<<endl;
        ans = true;
        int understand[13] = {};
        for(int i = 0;i<n;i++){ //1だったらi冊目を買う
            for(int j = 0;j<m;j++){
                if(bit.test(i)){ //i冊目を買う仮定
                    understand[j] += a[i][j];
                }
            }
        }
        rep(k,m){
            if(understand[k]<x){
                ans = false;
            }
        }
        //もし条件に合うのがひとつもなかったら、moneyは10^9+7のまま
        if(ans){
            int mo = 0;
            rep(i,n){
                if(bit.test(i)){
                    mo += c[i];
                }
            }
            money = min(money,mo);
        }
    }
    if(money==big){
        cout<<-1<<endl;
        return 0;
    }
    cout<<money<<endl;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[111100];
vector<pair<int ,int> > ii;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=1,e=1,f=0,g=1,h=1,j;
  cin >>a>>b>>c;
  a-=c,b+=c;
  cout <<a/b<<'\n';
  return (0);
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

const ll mod = 1000000007;
//const ll mod = 998244353;

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void create_table(int n) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= n;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[n] = pow_mod(fact[n],-1);
    for (int i = n;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= n;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    int n,k;
    cin >> n >> k;
    create_table(2010);
    for (int i = 0;i < k;++i) {
        cout << combi(k-1,i)*combi(n-k+1,i+1)%mod << "\n";
    }
}

Measured memory_bytes: 256