akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    ll N,M;
    cin>>N>>M;
    vector<vector<ll>> G(N);
    vector<ll> a(M),b(M);
    rep(i,M){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        //es[i]=(edge){a[i],b[i],-1};
        G[a[i]].push_back(b[i]);
    }
    bool ok=0;
    ll cnt=INF;
    vector<ll> S;
    for(int i=0;i<N;i++){
        vector<ll> dist(N,-1);
        queue<ll> que;
        vector<ll> pr(N);
        dist[i]=0;
        que.push(i);
        while(!que.empty()){
            ll v=que.front();
            que.pop();
            for(ll nv:G[v]){
                if(nv==i){
                    ok=1;
                    if(dist[v]+1<cnt){
                        cnt=dist[v]+1;
                        vector<ll> path;
                        path.push_back(v);
                        while(true){
                            ll nn=path.size();
                            ll mm=pr[path[nn-1]];
                            path.push_back(mm);
                            if(mm==i) break;
                        }
                        S=path;
                    }
                    goto l;
                }
                if(dist[nv]!=-1) continue;
                dist[nv]=dist[v]+1;
                    pr[nv]=v;
            que.push(nv);
            }
            
        }
        l:
        continue;
    }
    if(ok){
        cout<<S.size()<<'\n';
        for(ll u:S) cout<<u+1<<'\n';
    }else cout<<-1<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
   long long int t,n,x,y,a[100001];
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   string s;
   cin>>s;
   if(s[2]==s[3] && s[4]==s[5])
      cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;

int main() {
  int N, C;
  cin >> N >> C;
  vector<vector<int>> D(C,vector<int>(C));
  vector<vector<int>> c(N,vector<int>(N));
  rep(i, 0, C) rep(j, 0, C) cin >> D[i][j];
  rep(i, 0, N) rep(j, 0, N) cin >> c[i][j];
  rep(i, 0, N) rep(j, 0, N) c[i][j]--;
  vector<vector<int>> cnt(3,vector<int>(C));
  rep(i, 0, N) rep(j, 0, N) {
    cnt[(i+j)%3][c[i][j]]++;
  }
  int ans = 1e9;
  rep(i, 0, C) rep(j, 0, C) rep(k, 0, C) {
    if(i == j || j == k || k == i) continue;
    int tmp = 0;
    rep(l, 0, C) tmp += cnt[0][l] * D[l][i];
    rep(l, 0, C) tmp += cnt[1][l] * D[l][j];
    rep(l, 0, C) tmp += cnt[2][l] * D[l][k];
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N;
	cin >> N;
	vector<int>W(N);
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}
	int S1, S2;
	S1 = W[0];
	S2 = 0;
	for (int i = 1; i < N; i++) {
		S2 += W[i];
	}
	int ans = abs(S1 - S2);
	for (int i = 1; i < N; i++) {
		S1 += W[i];
		S2 -= W[i];
		chmin(ans, abs(S1 - S2));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b, c, n;

	scanf("%d%d%d", &a, &b, &c);
	for (n = 1; n <= 100; n++)
		if (n * a % b == c) {
			printf("YES\n");
			return 0;
		}
	printf("NO\n");
	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int t = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			Arrays.sort(data);
			long sum = 1;
			long mod = 1000000007L;
			for(int i = 1; i < n; i++){
				int ind = bLowerSearch(data, data[i] - t);
				sum = (sum * (i - ind + 1)) % mod;
			}
			System.out.println(sum);
		}
	}
	
	private int bLowerSearch(int a[], int patt){
		int mid, left = 0, right = a.length - 1;
		while(left < right){
			mid = (right + left) / 2;
			if(a[mid] < patt){
				left = mid + 1;
			}
			else{
				right = mid;
			}
		}
		if(a[left] == patt){
			return left;
		}
		else{
			return right;
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 64516
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll N;
    cin >> N;
    ll ans = 0;
    rep1(i, 9)rep1(j, 9)if(i * j == N)ans = 1;
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

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

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

vector<ll> divisor(ll n) {
	vector<ll> res;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}

signed main() {
	string s;
	ll k;

	cin >> s >> k;

	ll now = 0;

	while (k > 0) {
		if (s[now] == '1') {
			if (k == 1) {
				cout << 1 << endl;
				break;
			}
			else {
				k--;
				now++;
			}
		}
		else {
			cout << s[now] << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }

        Arrays.sort(h);
        int smallest = Integer.MAX_VALUE;
        for (int i = 0; i <= n - k; i++) {
            smallest = Math.min(smallest, h[i + k - 1] - h[i]);
        }
        System.out.println(smallest);
    }
}


Measured memory_bytes: 49780
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);



void solve() {
	int n; cin >> n;
	vector<int> s(1 << n);
	int ma = 0;
	rep(i, (1 << n)) {
		cin >> s[i];
		ma = max(ma, s[i]);
	}
	multiset<int> r;
	vector<int> g;
	int c = 0;
	rep(i, (1 << n)) {
		r.insert(s[i]);
		if (ma == s[i])c++;
	}
	if (c >= 2) {
		cout << "No" << endl; return;
	}
	g.push_back(ma);
	r.erase(ma);
	rep(i, n) {
		int len = g.size();
		rep(j, len) {
			int val = g[j];
			if (r.count(val - 1)) {
				g.push_back(val - 1);
				r.erase(r.find(val - 1));
			}
			else {
				r.insert(val - 1);
				auto itr = r.find(val - 1);
				if (itr == r.begin()) {
					cout << "No" << endl; return;
				}
				itr--;
				int z = *itr;
				g.push_back(z);
				r.erase(r.find(z));
				r.erase(r.find(val - 1));
			}
		}
		sort(g.begin(), g.end(),greater<int>());
	}
	cout << "Yes" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(50);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
		return 0;
}


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

// template {{{
/* vim: set foldmethod=marker: */

// constant
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double PI = acos(-1);
#define EPS 1e-14

// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

// input
inline int inputi(){ int x; scanf("%d", &x); return x; }
inline double inputd(){ double x; scanf("%lf", &x); return x; }
inline string inputs(){ string x; cin >> x; return x; }

// short
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define REPit(type, i, obj) for (type::iterator i = (obj).begin(); i != (obj).end(); i++)
#define RREPit(type, i, obj) for (type::iterator i = (obj).rbegin(); i != (obj).rend(); i++)

// container util
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define sz(obj) ((int)(obj).size())
#define sort(obj) sort(all(obj))
#define exist(obj, key) ((obj).find(key) != (obj).end())
#define clear(array) memset((array), 0, sizeof(array))

// print util
#define print(x) cout << (x) << endl
template <class T> inline void printall(vector<T> v){ REP(i, sz(v)) cout << v[i] << "\n "[i < sz(v) - 1]; }
#define dump(x) cerr << #x << ": " << (x) << endl
#define debug(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << endl

//template }}}

int main()
{
    ll n, a, b, c, x;

    while (cin >> n >> a >> b >> c >> x, n){
        int y[n];
        REP(i, n) cin >> y[i];

        int cnt = 0;
        REP(i, 10001){
            if (x == y[cnt]){
                cnt++;
            }
            if (cnt == n){
                print(i);
                break;
            }
            x = (a * x + b) % c;
        }
        if (cnt < n) puts("-1");
    }

    return 0;
}

Measured memory_bytes: 1168
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
    
    
public class Main {
	static int INF = 2 << 27;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int[] x = new int[n];
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int[][] dp = new int[n+1][l+1];
		BinaryIndexedTree[] bit = new BinaryIndexedTree[n+1];
		for(int i = 0; i < n+1; i++) {
			bit[i] = new BinaryIndexedTree(l+2,l+2);
		}
		bit[n].add(1, 1);
		for(int i = n - 1; i >= 0; i--) {
			for(int j = 0; ; j++) {
				if(a[i] == 0) {
					bit[i].add(l + 1 - x[i], bit[i+1].sum(l + 1 - x[i] + 1) % 1000000007);
					break;
				}
				else {
					if(a[i] * j + x[i] > l) break;
					bit[i].add(l + 1 - (x[i] + a[i] * j), bit[i+1].sum(l + 1 - (x[i] + a[i] * j + 1)) % 1000000007);
				}
			}
		}
		
		System.out.println(bit[0].sum(l+1));
		
		
		
		
	}
	
	
	
}

class BinaryIndexedTree {
	int MAX_N;
	int[] bit = new int[MAX_N+1];
	int n;
	
	BinaryIndexedTree(int MAX_N, int n) {
		this.MAX_N = MAX_N;
		this.bit = new int[MAX_N+1];
		this.n = n;
	}
	
	
	int sum(int i) {
		int s = 0;
		while(i > 0) {
			s += bit[i];
			s %= 1000000007;
			i -= i & -i;
		}
		return s;
	}
	
	void add(int i , int x) {
		while(i <= n) {
			bit[i] += x ;
			bit[i] %= 1000000007;
			i += i & -i;
		}
	}
}

Measured memory_bytes: 297620
import itertools

n,m,q = map(int,input().split())

m_li = []
for i in range(1,m+1):
    m_li.append(i)

li = []
mx = 0

for i in range(q):
    a,b,c,d = map(int,input().split())
    li.append((a,b,c,d))

for v in itertools.combinations_with_replacement(m_li,n):
    buf = 0
    for i in range(q):
        a = li[i][0]
        b = li[i][1]
        c = li[i][2]
        d = li[i][3]
        if v[b-1] - v[a-1] == c:
            buf += d
    if buf >= mx:
        mx = buf

print(mx)


Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  string s[3];
  int num[3];
//  int cnt[3];
  rep(i,0,3){
    cin>>s[i]; 
    num[i]=s[i].size();
   // cnt[i]=0;
  }
  char ans;
  char turn='a';
  while(true){
    if(turn=='a'){

      num[0]--;
      if(num[0]<0) {
       ans='A';
        break;
      }
      turn=s[0][s[0].size()-num[0]-1];
    }
    else if(turn=='b'){
		  num[1]--;
      if(num[1]<0) {
       ans='B';
        break;
      }
      turn=s[1][s[1].size()-num[1]-1];
    }
    else {
		  num[2]--;
      if(num[2]<0) {
       ans='C';
        break;
      }
      turn=s[2][s[2].size()-num[2]-1];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    string S;
    int w;
    cin >> S >> w;
    for (int i = 0; i < S.size(); i += w){
        cout << S.at(i);
    }
    cout << endl;
}



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

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

int solve() {
	int n, k;
	cin >> n >> k;
	chmin(k, n);

	vector<int> x(n);
	for(auto &e : x) cin >> e;

	vector<int> diff(n - 1);
	for(int i = 0; i < n - 1; ++i) diff[i] = x[i + 1] - x[i];
	sort(diff.rbegin(), diff.rend());

	return accumulate(diff.begin() + k - 1, diff.end(), 0);
}

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

	int t;
	cin >> t;
	while(t--) cout << solve() << endl;

	return EXIT_SUCCESS;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x==0){
        cout<<n/x*t<<'\n';
    }else{
        cout<<((n/x)+1)*t<<'\n';
    }


return 0;


}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *   ****      *  ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***

//        ********                                 . O .
//      *           *                               . .
//     *            * *       * ********
//    * ***********    *    *  *         *
//    *                 * *      *********
//                      *                 *
//                 *   *
//                   *  *
//                     **
//                   *  **  *
//              *  *    * **
//                *     ** * *
//            *   **   ** * *  * *
//           *    * * * * * *   **
//          **************************

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010;
int tt=1;
int head[N],in[N],to[N*3],nxt[N*3],w[N*3],fr[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline void dfs(int x) {
    for(int &i=head[x];i;i=nxt[i])
	if(!w[i]) {
	    w[i]=1,w[i^1]=-1;
	    dfs(to[i]);
	}
}
inline void lnk(int x,int y) {
    to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
    to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
}
int main() {
    int n,A,B;
    cin>>n;
    for(int i=1;i<=n;i++) {
	int x=gi();
	if(x==-1) A=i;
	else lnk(x,i),in[x]^=1;
    }
    for(int i=1;i<=n;i++) {
	int x=gi();
	if(x==-1) B=i+n;
	else lnk(x+n,i+n),in[x+n]^=1;
    }
    for(int i=1;i<=n;i++) {
	if(in[i]!=in[i+n]) return puts("IMPOSSIBLE"),0;
	if(!in[i]) lnk(i,i+n),fr[i]=tt;
    }
    lnk(A,0),lnk(0,B);
    dfs(0);
    puts("POSSIBLE");
    for(int i=1;i<=n;i++) {
	if(!fr[i]) printf("0 ");
	else printf("%d ",w[fr[i]]);
    }
    return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int n = (int)S.size();
  int ans = 0;
  for (int i = 0; i < n; i ++) {
    ans += (int)S[i] - (int)'0';
    ans %= 9;
  }
  cout << (ans == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3748
#include <algorithm>
#include <iostream>
using namespace std;
int a,b,c,cnt=0,t[3];
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>t[0]>>t[1]>>t[2];
	sort(t,t+3);
	a=t[0],b=t[1],c=t[2];
	int x=c-b;
	b+=x;a+=x;cnt+=x;
	x=(b-a)/2;
	cnt+=x;
	a+=x*2;
	if (a!=b) cnt+=2;
	cout<<cnt<<endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector <int> v(n);
  rep(i,n) cin >> v[i];
  int max = *max_element(v.begin(), v.end());
  auto maxit = max_element(v.begin(), v.end());  
  int max_ele = distance(v.begin(), maxit);
  v[max_ele] = 0;
  int nmax = *max_element(v.begin(), v.end());
  // cout << endl;
  // cout << max << endl;
  // cout << max_ele << endl;
  // cout << nmax << endl;
  // cout << endl;

  rep(i,n){
    if(i != max_ele)
      cout << max << endl;
    else
      cout << nmax << endl;    
  }
  return 0;
}


Measured memory_bytes: 2432
# frozen_string_literal: true

n = gets.to_i
a = gets.split.map &:to_i
check = 0
a.each do |i|
  next unless i.even?
  next if i%3 == 0 || i%5 == 0
  check = 1
  break
end

if check == 1
  puts 'DENIED'
else
  puts 'APPROVED'
end


Measured memory_bytes: 3836
import sys

sys.setrecursionlimit(10 ** 9 + 7)

N = int(input())
visited = [False] * N
edges = [[] for _ in range(N)]
AB = []
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append((a, b))
    edges[a].append(b)
    edges[b].append(a)
C = list(map(int, input().split()))
C.sort(reverse=True)
scores = [-1] * N
i = 0

def dfs(v):
    if visited[v]:
        return

    visited[v] = True
    global i
    scores[v] = C[i]
    i += 1
    for e in edges[v]:
        if visited[e]:
            continue

        dfs(e)

dfs(0)

total = 0
for a, b in AB:
    total += min(scores[a], scores[b])
print(total)
print(*scores)

Measured memory_bytes: 14320
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  string S;
  cin >> S;
  int N = S.size();
  string T = "";
  for (auto i = 0; i < (N+1)/2; ++i) {
    T += "g";
  }
  for (auto i = (N+1)/2; i < N; ++i) {
    T += "p";
  }
  int ans = 0;
  for (auto i = 0; i < N; ++i) {
    if (S[i] < T[i]) ++ans;
    else if (S[i] > T[i]) --ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define fastio                        \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(NULL);
#define pb push_back
#define mp make_pair

typedef long long ll;

using namespace std;
struct route{
    int cost, time;
};

int main()
{
    fastio;
    int N, T;
    cin>>N>>T;
    route r[101];
    for(int i=0;i<N;i++){
        cin>>r[i].cost>>r[i].time;
    }
    sort(r, r+N, [&](struct route a, struct route b){
        int x = a.time; int y = b. time;
        return x<y;
    });
    bool flag = false;
    int mc = INT_MAX;
    int i=0;
    for(i=0;i<N;i++){
        if(r[i].time>T){
            break;
        }
        mc = min(mc, r[i].cost);
    }
    if(mc == INT_MAX) cout<<"TLE"<<'\n';
    else cout<<mc<<'\n';
    
    
    return 0;
}

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

int main()
{
  int n, sum = 0;
  cin >> n;
  int b[n - 1], a[n];
  rep(i, n - 1) cin >> b[i];
  //aの先頭要素は必ずbの先頭要素
  a[0] = b[0];
  for(int i = 1; i <= n - 2; i++) 
  {
    //小さい方をたす
    a[i] = min(b[i], b[i - 1]);
  }
  //aの末尾要素は必ずbの末尾要素
  a[n - 1] = b[n - 2];
  int ans = 0;
  rep(i, n) ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long int lli;
const int inf = 0xfffffff;
const lli llinf = 0xfffffffffffffff;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a + (b / 2) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

void solve(){
    int a, b;
    cin >> a >> b;

    if(a > b){
        cout << "a > b" << endl;
    }else if(a < b){
        cout << "a < b" << endl;
    }else{
        cout << "a == b" << endl;
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3068
import java.util.*;
public class Main{
   

  public static long ways(char matrix[][],int n,int m,int i,int j,long dp[][])
  {
	  
	  if(matrix[i][j]=='#') {
		  dp[i][j]=0;
		  return 0;}
	  if(i==n-1&&j==m-1)
		  return 1;
	  
	  if(dp[i][j]==-1) {
		  
	  long op1=0,op2=0;
	  if((i+1)<n&&j<m)
	  {
		op1=(ways(matrix,n,m,i+1,j,dp))%1000000007;
	  }
	  if(i<n&&j+1<m)
	  {
			op2=ways(matrix,n,m,i,j+1,dp)%1000000007;
		
	  }
	  dp[i][j]=(op1+op2)%1000000007;
	 
	  }
	  return dp[i][j];
  }
	
  public static void main(String[] args)
  {
     
  Scanner s=new Scanner(System.in);
  int n=s.nextInt();
  int m=s.nextInt();
  char matrix[][]=new char[n][m];
  for(int i=0;i<n;i++)
  {
	String line=s.next();
	String str[]=line.split("");
	  for(int j=0;j<m;j++) {
		  matrix[i][j]=str[j].charAt(0);}
  }
  long dp[][]=new long[n][m];
  for(int i=0;i<n;i++)
  {
	  for(int j=0;j<m;j++)
	  {
		  dp[i][j]=-1;
	  }
  }

  System.out.println( ways(matrix,n,m,0,0,dp));
  
  s.close();
    
  }
}


Measured memory_bytes: 64572
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 800000000000000000
int main() {
	string s;
	cin >> s;
	int cnt = 0;
	int now[200] = {};
	for (int i = 0;i < s.length();++i) {
		if (s[i] == 'B') {
			cnt--;
			cnt = max(cnt, 0);
			now[cnt] = 0;
		}
		else {
			now[cnt] = s[i] - '0' + 1;
			cnt++;
		}
	}
	for (int i = 0;i < cnt;++i) {
		cout << now[i] - 1;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int a;
    stack<int> s;
    while(cin >> a){
        if(a)s.push(a);
        else{
            cout << s.top() << endl;
            s.pop();
        }
    }
}

Measured memory_bytes: 3068
n,c,*x=`dd`.split.map &:to_i;*s=0
x.map{|e|s<<s[-1]+e}
r=[]
(1..n).map{|k|t=5*s[n]+(k+n)*c;o=n-k*2;(t+=2*s[o];o-=k)while o>0;r<<t}
p r.min

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

#define pb push_back
#define fst first
#define snd second
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {FIN;
   int n;cin>>n;
   int arr[n];
   int mi = 400; int ma=-200;
   fore(i,0,n){
        int cur;cin>>cur;arr[i]=cur;
        mi=min(mi,cur);ma = max(ma,cur);
   }
   ll mini = 1e9;
   fore(i,mi,ma+1){
    ll cal = 0;
    fore(j,0,n){
        cal+=pow(arr[j]-i,2);
    }
    mini=min(mini,cal);
   }
   cout<<mini<<"\n";
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
  double ans;
  int n;
  cin >> n;
  if (n % 2 == 0)
    ans = 0.5;
  else
    ans = (n / 2 + 1) / double(n);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){
    
    ll L , R;
    cin >> L >> R;

    //cout << L % 2019 << " " << R % 2019 << endl;
    ll cnt = 0;
    vector<ll> md(2019, 1145141919191919);
    vector<pair<ll, ll > > mm;
    for(ll i = L; i <= R; i++){
        //cout << i << endl;
        mm.push_back(make_pair(i % 2019, i));
        //cout << i % 2019 << endl;
        if(mm.size() == 2019){
            break;
        }
    }
    ll ans = 1145141919191919;
    for(ll i = 0; i < mm.size(); i++){
        for(ll j = i + 1; j < mm.size(); j++){
            ans = min(ans, mm[i].second * mm[j].second % 2019);
            //cout <<  mm[i].second * mm[j].second % 2019 << endl;
        }
    }
    //sort(mm.begin(), mm.end());
    //cout << mm[0].second << " " << mm[1].second << endl;
    cout << ans << endl;
} 

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<numeric>
#include<cassert>
#include<algorithm>
using namespace std;

int main(){
  int n,i,a,max=-1000000,min=1000000;
  long long int sum=0;

  cin >> n;
  for(i=0;i< n;i++){
    cin >> a;
    sum+=a;
if(a>max){
   max = a;
 }
if(a<min){
   min=a;
 }
}

  cout  << min << " " << max << " " <<  sum << endl;

return 0;
}



Measured memory_bytes: 3116
package main

import (
	"fmt"
	"math"
)

func main() {
	var h int
	fmt.Scanf("%d", &h)

	var a int = 1
	for 1 < h {
		a++
		h = h / 2
	}

	var result int
	for i := 0; i < a; i++ {
		result += int(math.Pow(2, float64(i)))
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
import heapq

N = int(input())
Vs = list(map(int, input().split(" ")))

heapq.heapify(Vs)

for _ in range(N-1):
    tmp = (heapq.heappop(Vs) + heapq.heappop(Vs))/2
    heapq.heappush(Vs, tmp)
    
print(heapq.heappop(Vs))

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int64_t calc_bit_in_period(int64_t a, int64_t b, int64_t d)
{
    const int64_t m = 1ll << d;
    if (b < m)
    {
        return 0;
    }
    else
    {
        return b - max(a, m) + 1;
    }
}

int64_t calc_bit(int64_t a, int64_t b, int64_t d)
{
    const int64_t period = 2ll << d;
    const int64_t la = (a / period) * period;
    const int64_t ra = la + period;
    if (la <= b && b < ra)
    {
        return calc_bit_in_period(a % period, b % period, d) % 2;
    }
    else
    {
        const int64_t a1 = calc_bit_in_period(a % period, period - 1, d);
        const int64_t a2 = calc_bit_in_period(0, b % period, d);

        const int64_t num_range = b / period - a / period - 1;
        return (a1 + a2 + num_range * (period / 2ll)) % 2;
    }
}

int main()
{
    int64_t a, b;
    cin >> a >> b;
    int64_t ans = 0;
    for (int d = 0; d <= 50; d++)
    {
        ans += (calc_bit(a, b, d) << d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  double ans = 0;
  while(n--) {
    double x; cin >> x;
    string u; cin >> u;
    if (u == "JPY") {
      ans += x;
    } else {
      ans += x*380000;
    }
  }
  cout << setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  sort(all(v));
  long long low = 0;
  long long high = v.sz-1;

  while(low < high){
    long long mid = (high + low) >> 1;

    int flag = 1;
    if(mid != v.sz-1){
      ll a = 0;
      rep(i,0,mid+1){
        a += v[i];
      }
      rep(i,mid+1,v.sz){
        if(a*2>=v[i]){
          a += v[i];
        }
        else{
          flag = 0;
        }
      }
    }
    if(flag == 1){
      high = mid;
    }
    else{
      low = mid + 1;
    }
  }
  cout << n-low << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 char x,y;
 cin >> x >>y;
 int a=x-'A';
 int b=y-'A';
 if(a<b)cout << '<' <<endl;
 if(a>b)cout << '>' << endl;
 if(a==b)cout << '=' << endl;
}

Measured memory_bytes: 3632
import Data.List
import Data.Char
import Control.Monad
import Data.Ord
  
gen n = [read x|i<-[3..n],x<-sequence $ replicate i "357",null $ "753" \\ x]

main = do
  n <- readLn::IO Int
  let aa = takeWhile (<= n) $ gen $ length $ show n
  putStrLn $ show $ length aa

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 1000000007
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define sz(x) int(x.size())
int main(){
	int n;
	cin>>n;
	ll ans;
	ans=(ll)n*(n-1)/2;
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    while(true){
        int n;
        cin>>n;
        if(n==0) return 0;
        vector<int> c(n);
        rep(i,n){
            char a;
            cin>> a;
            c[i]=(int)a-65;
        }
        vector<int> vec(26,0);
        Pii f(0,0),s(0,0);
        rep(i,n){
            vec[c[i]]++;
            if(f.second<vec[c[i]]){
                if(f.first!=c[i]&&f.first!=s.first) s=f;
                f=make_pair(c[i],vec[c[i]]);
            }
            else if(s.second<vec[c[i]]){
                s=make_pair(c[i],vec[c[i]]);
            }
        //    cout<<f.first<<" "<<f.second<<" "<<s.first<<" "<<s.second<<endl;
            if(f.second==s.second&&i!=n-1) continue;
            else if(f.second>s.second+n-i-1){
                cout<<(char)(f.first+65)<<" "<<i+1<<endl;
                break;
            }
            else if(i==n-1) cout<<"TIE"<<endl;
        }
    }
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  sort(S.begin(), S.end());
  cout <<
  ((S[0]==S[1] && S[1]!=S[2] && S[2]==S[3])?
    "Yes":
    "No")
       << endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
k=int(input())

sb=set()
for i in range(len(s)):
    for ii in range(i,i+k):
        if ii<len(s):
#            print(s[i:ii+1])            
            sb.add(s[i:ii+1])
sb2=list(sb)
sb2.sort()
print(sb2[k-1])


Measured memory_bytes: 4464
N = int(input())
ans = N
result = []
nishin = ''
if(N == 0):
    nishin = '0'
    print(nishin)
    exit()
while ans != 0:
    if(ans % 2 == 1):
        ans = (ans-1)/(-2)
        result.append(1)
    else:
        ans = ans/(-2)
        result.append(0)

result.reverse()
for i in range(len(result)):
    nishin = nishin+str(result[i])
print(nishin)

Measured memory_bytes: 3064
s = input()
if (s[-1]=="2" or s[-1]=="4" or s[-1]=="5" or s[-1]=="7" or s[-1]=="9"):
  print("hon")
elif (s[-1]=="0" or s[-1]=="1" or s[-1]=="6" or s[-1]=="8"):
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9032
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;



int main() {
	//fios;
	string n;
	cin >> n;
	int sum = 0;
	for(char ch: n) sum = (sum + ch - '0') % 9;
	if(sum % 9 == 0) cout << "Yes";
	else cout << "No";

	cout << endl;


}

Measured memory_bytes: 3688
s = str(input())
ans = 0
for i in range(len(s)-1):
    if s[i] == s[i+1] and s[i] == "0":
        ans += 1
        s = s[:i+1] + "1" + s[i+2:]
    elif s[i] == s[i+1] and s[i] == "1":
        ans += 1
        s = s[:i+1] + "0" + s[i+2:]   
print(ans)

Measured memory_bytes: 10512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;cin>>s;
    int rev=0;
    string head,tail;
    int n;cin>>n;
    rep(i,1,n){
        int op=0;
        cin>>op;
        if(op==1)rev=!rev;
        else{
            int flag;
            char c;
            cin>>flag>>c;
            if(flag==1&&rev==0||flag==2&&rev==1){head+=(char)c;}
            else tail+=(char)c;
        }  
    }
    reverse(head.begin(),head.end());
    s=head+s;
    s+=tail;
    if(rev)reverse(s.begin(),s.end());
    cout<<s<<endl;
}
/* 
a
4
2 1 p
1
2 2 c
1
 */

Measured memory_bytes: 1200
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
const ll Mod=1000000007;
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
ll f(ll a,ll b)
{
    if(b==0) return 1;
    else{
        ll qian=(0+b-1)*b/2;
        ll hou=(a+a-b+1)*b/2;
        return hou-qian+1;
    }
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	ll n=read();
	ll k=read();
	ll sum=0;
	for(ll i=k;i<=n+1;i++) sum=(sum%Mod+f(n,i))%Mod;
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int w = sc.nextInt();
      int n = sc.nextInt();
      int[] values = new int[w];

      for(int i=0; i < values.length;i++){
      	values[i] = i+1;
      }

      for(int i = 0; i < n;i++){
      	String str = sc.next();
      	String[] ab = str.split(",");
      	int a = Integer.parseInt(ab[0]) - 1;
        int b = Integer.parseInt(ab[1]) - 1;
      	
      	int c = values[a];
      	values[a] = values[b];
      	values[b] = c;
      }
      
      for(int i=0; i < values.length;i++){
      	System.out.println(values[i]);
      }

    }

}

Measured memory_bytes: 26120
import java.util.*;
public class Main {
  	public static void main(String[] args) {
      	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      if((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0) {
        System.out.println("Possible");
      } else {
        System.out.println("Impossible");
      }
    }
}

Measured memory_bytes: 23124
from collections import Counter

N, K = map(int, input().split())

l = []
counter = 0

for k in range(K):
    d = int(input())
    A = map(int, input().split())
    l.extend(A)

for i in range(1,N+1):
    if Counter(l)[i]==0:
        counter += 1
    else:
        continue

print(counter)

Measured memory_bytes: 9608
import scala.io.StdIn.readInt
  
object Main extends App {
  val (x,minv) = (readInt, readInt)

  val m = (1 until x).map(_=>readInt).foldLeft((minv,Int.MinValue)) { (x, r) =>
      (r.min(x._1), (r-x._1).max(x._2))
    }._2
  println(m)

}


Measured memory_bytes: 75852
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<bits/stdc++.h>
#define Foru(i,a,b) for(int i=(a);i<=(b);++i)
#define File ifstream fin("G:\\QtCode\\data\\in.txt")
using namespace std;
void slove(int num_question)
{
    while (num_question--)
    {
        map<string,int>ans;
        ans["SUN"]=7;
        ans["MON"]=6;
        ans["TUE"]=5;
        ans["WED"]=4;
        ans["THU"]=3;
        ans["FRI"]=2;
        ans["SAT"]=1;
        string x;cin>>x;
        cout<<ans[x]<<endl;
    }
    return;
}
int main()
{
    //int n;cin>>n;
    slove(1);
    return 0;
}


Measured memory_bytes: 256
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  ull x;
  cin >> x;
  double b = 0.01;
  double res = 100, days = 0;
  while(res < x) {
    double comp = floor(res * b);
    res += comp;
    days++;
  }
  cout << days << endl;
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 3800
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] h = new int[n];
                for(int i = 0 ; i < n ; i++){
                        h[i] = sc.nextInt();
                }
                sc.close();
                int[] q = new int[n];
                Arrays.fill(q , 0);
                q[1] = Math.abs(h[1] - h[0]);
                for(int i = 2 ; i < n ; i++){
                        q[i] = Math.min(q[i - 1] + Math.abs(h[i - 1] - h[i]) , q[i - 2] + Math.abs(h[i - 2] - Math.abs(h[i])));
                }
                System.out.println(q[n - 1]);
        }
}

Measured memory_bytes: 59752
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#include <math.h>
#include <set>
using namespace std;
#define rep(i,n) for(int i = 0; i < n ; i++)
#define pb push_back
const static int INF = 100000;


int string_to_int(std::string str){
  int ret;
  std::stringstream ss;
  ss << str;
  ss >> ret;
  return ret;
}

//文字列を任意の文字で分割できる
//split("文字列","分解したい文字",入れる変数)
template <typename List>
void split(const std::string& s, const std::string& delim, List& result)
{
    result.clear();

    using string = std::string;
    string::size_type pos = 0;

    while(pos != string::npos )
    {
        string::size_type p = s.find(delim, pos);

        if(p == string::npos)
        {
            result.push_back(s.substr(pos));
            break;
        }
        else {
            result.push_back(s.substr(pos, p - pos));
        }

        pos = p + delim.size();
    }
}


int main() {
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  vector<string> result;
  int quadrant;string a,b,c,d;
  if(sx < tx && sy < ty)
    quadrant = 0;
  if(tx < sx && sy < ty)
    quadrant = 1;
  if(tx < sx && ty < sy)
    quadrant = 2;
  if(sx < tx && ty < sy)
    quadrant = 3;

  switch(quadrant){
    case 0:
      a = "R";
      b = "U";
      c = "L";
      d = "D";
      break;
    case 1:
      a = "L";
      b = "U";
      c = "R";
      d = "D";
      break;
    case 2:
      a = "L";
      b = "D";
      c = "R";
      d = "U";
      break;
    case 3:
      a = "R";
      b = "D";
      c = "L";
      d = "U";
      break;
  }

  rep(i,abs(tx-sx))
    result.pb(a);
  rep(i,abs(ty-sy))
    result.pb(b);
  rep(i,abs(tx-sx))
    result.pb(c);
  rep(i,abs(ty-sy))
    result.pb(d);

  result.pb(d);
  rep(i,abs(tx-sx)+1)
    result.pb(a);
  rep(i,abs(ty-sy)+1)
    result.pb(b);
  result.pb(c);
  result.pb(b);
  rep(i,abs(tx-sx)+1)
      result.pb(c);
  rep(i,abs(ty-sy)+1)
      result.pb(d);
  result.pb(a);

  rep(i,result.size()){
    cout << result[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 512
from collections import Counter

N=int(input())
L=list(map(int,input().split()))
Z=[]
M=Counter(L)
for i,j in M.items():
	if j>=2:
		Z.append(i)
	if j>=4:
		Z.append(i)
V=sorted(Z)
if len(V)<2:
	print(0)
else:
	print(V[-1]*V[-2])

Measured memory_bytes: 18592
#include <stdio.h>

int main()
{
    int M[101][101] = {0};
    int i, j;

    int n, u, k, v;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        for (j = 0; j < k; j++) {
            scanf("%d", &v);
            M[i][v-1] = 1;
        }
    }

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

    return 0;
}

Measured memory_bytes: 1784
# E - Coprime
from math import gcd

N = int(input())
A = list(map(int,input().split()))
MAX = 10**6
p = [0]*(MAX+1)

for i in range(2,MAX+1):
    if p[i]>0:
        continue
    tmp = i
    while tmp<=MAX:
        p[tmp] = i
        tmp += i

pairwise = True
g = -1
q = [-1]*(MAX+1)

for i in range(N):
    a = A[i]
    g = a if g<0 else gcd(g,a)
    while pairwise and a>1:
        pairwise = True if q[p[a]] in [-1,i] else False
        q[p[a]] = i
        a //= p[a]

if pairwise:
    print('pairwise coprime')
elif g==1:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 189236