akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solve()
{
   ll x,y,a,b,c;
   cin>>x>>y>>a>>b>>c;
   priority_queue<ll,vector<ll>,greater<ll>> ae1;
   ll e1;
   ll ea1=0;
   for(int i=0;i<a;i++)
   {
       cin>>e1;
       ea1+=e1;
       ae1.push(e1);
   }
   priority_queue<ll,vector<ll>,greater<ll>> ae2;
   ll e2;
   ll ea2=0;
   for(int i=0;i<b;i++)
   {
       cin>>e2;
       ea2+=e2;
       ae2.push(e2);
   }
   priority_queue<ll> ae3;
   ll e3;
   ll ea3=0;
   for(int i=0;i<c;i++)
   {
       cin>>e3;
       ea3+=e3;
       ae3.push(e3);
   }
   while(ae1.size()>x)
   {   ea1-=ae1.top();
       ae1.pop();}
    while(ae2.size()>y)
   {   ea2-=ae2.top();
       ae2.pop();}
    while(!ae3.empty())
    {
        if(ae1.top()>ae2.top())
        {
            if(ae3.top()>ae2.top())
            {   ea2-=ae2.top();
                ae2.pop();
                ea2+=ae3.top();
                ae2.push(ae3.top());
                ae3.pop();
            }
            else
                break;
        }
        else
        {
            if(ae3.top()>ae1.top())
            {
                 ea1-=ae1.top();
                ae1.pop();
                ea1+=ae3.top();
                ae1.push(ae3.top());
                ae3.pop();
            }
            else
                break;
        }
    }
    cout<<ea1+ea2;
}
int main()
{
  ll t=1;
 // cin>>t;
  while(t--)
  {
    solve();
  }
}


Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int table[] = new int[128];
        String work[] = new String[2];
        String outPut[] = {"S","H","C","D"};
 
        table['S'] = 0;
        table['H'] = 1;
        table['C'] = 2;
        table['D'] = 3;
 
        boolean check[][] = new boolean[4][14];
        for(int row = 0; row < 4; row++){
            for(int col = 1; col <= 13; col++)check[row][col] = false;
        }
 
        try {
            int N = Integer.parseInt(br.readLine());
 
            for(int loop = 0; loop < N; loop++){
                work = br.readLine().split("\\s+");
                check[table[work[0].charAt(0)]][Integer.parseInt(work[1])] = true;
            }
 
            for(int row = 0; row < 4; row++){
                for(int col = 1; col <= 13; col++){
                    if(!check[row][col]){
                        System.out.printf("%s %d\n", outPut[row],col);
                    }
                }
            }
 
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24820
def calc(n, mod):
	f = 1
	fac = [1]
	for i in range(1, n + 1):
		f *= i
		f %= mod
		fac.append(f)
	inv = pow(f, mod - 2, mod)
	invs = [1] * (n + 1)
	invs[n] = inv
	for i in range(n, 1, -1):
		inv *= i
		inv %= mod
		invs[i - 1] = inv
	return fac, invs

def cnk(n, r, mod, fac, inv):
	return fac[n] * inv[n - r] * inv[r] % mod


n = int(input())

mod = 998244353

f, inv = calc(n + 10, mod)
ans = pow(3, n, mod)
p = [1]

for i in range(n // 2 + 10):
	p.append(p[-1] * 2 % mod)
for k in range(n // 2 + 1, n + 1):
	cur = 2 * cnk(n, k, mod, f, inv) * p[n - k]
	ans -= cur
	ans %= mod
print(ans)

Measured memory_bytes: 395052
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    
    int n,m;
    cin>>n>>m;
    int res=0;
    if(n>=2)    res += (n*(n-1)/2);
    if(m>=2)    res += (m*(m-1)/2);
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

//最大公約数の計算(ユークリッドの互除法)
long long int gcd(long long int a, long long int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> coord(n);
    for (int i = 0; i < n; i++) {
        cin >> coord[i];
        coord[i] = abs(coord[i] - x);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = gcd(ans, coord[i]);
    }
    cout << ans << endl;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int x[N];
  for(int i=0;i<N;i++){
    cin >> x[i];
  }
  int mina=1000000000;
  for(int i=0;i<N-K+1;i++){
    int mi=min(abs(x[i])+x[i+K-1]-x[i],abs(x[i+K-1])+x[i+K-1]-x[i]);
    if(mi<mina)mina=mi;
  }
  cout << mina;
}


Measured memory_bytes: 640
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n,m,v,p;
int a[100005];

bool bisa(int x)
{
  if (a[x] >= a[p-1]) return true;
  if (a[x] + m < a[p-1]) return false;
  int sisa = v - 1 - (p - 1);
  if (sisa <= 0) return true;
  LL kasih = 0;
  FOR(i,p-1,n) if (i != x) kasih += min(m,a[x]+m-a[i]);
  // VALUE(kasih);
  // VALUE(sisa);
  return kasih >= (LL)m * sisa;
}

int main()
{
  scanf("%d %d %d %d",&n,&m,&v,&p);
  REP(i,n) scanf("%d",&a[i]);
  SORTA(a,n);
  REVERSEA(a,n);
  int L = 0;
  int R = n - 1;
  int risan = 0;
  // VALUE(bisa(3));
  // return 0;
  while (L <= R)
  {
    int M = (L + R) >> 1;
    if (bisa(M))
    {
      risan = M + 1;
      L = M + 1;
    } else R = M - 1;
  }
  printf("%d\n",risan);
  return 0;
}











Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a[6],ans;
    for(int i=1;i<=5;i++){
        cin>>a[i];
        if(a[i]==0){ ans=i; break;}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=n-1;(i)>=0;(i)--)

#define ll long long

using namespace std;
const ll MOD = 1e9+7;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll powmod(ll a, ll b){
    ll c = 1;
    ll ans = 1;
    while(c <= b){
        if(c & b){
            ans *= a;
            ans %= MOD;
        }
        c <<= 1;
        a *= a;
        a %= MOD;
    }
    return ans;
}

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    ll ans = powmod(2,N)-1;
    ll U=1, D=1;
    rep(i,A){
        U *= (N-i)%MOD;
        U %= MOD;
        D *= i+1;
        D %= MOD;
    }
    ans -= U*powmod(D,MOD-2)%MOD;
    U=1; D=1;
    rep(i,B){
        U *= (N-i)%MOD;
        U %= MOD;
        D *= i+1;
        D %= MOD;
    }
    ans -= U*powmod(D,MOD-2)%MOD;

    cout << (ans+MOD*10)%MOD << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
 int arr[3];
 char ar[2];
cin>>arr[0]>>ar[0]>>arr[1]>>ar[1]>>arr[2];
if(arr[0]>2019 || arr[1]>4 || arr[2]>30)
    cout<<"TBD";
else cout<<"Heisei";

 return 0;
}


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

int main()
{
  long long N, w[100], sum = 0;

  cin >> N;

  for (int i = 0; i < N; i++)
  {
    cin >> w[i];
    sum += w[i];
  }

  long long abscontainer ,sub = 0;

  

  sub += w[0];
  sum = sum - w[0];
  abscontainer = abs(sub-sum);

  for (int i = 1; i < N; i++)
  {
    sub += w[i];
    sum = sum - w[i];
    if (abscontainer >= abs(sub-sum))
    {
      abscontainer = abs(sub - sum);
    }
 }

  cout << abscontainer << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N, A, B;
int main() {
    while (cin >> N >> A >> B) {
        cout << min(A, B) << " " << max(A + B - N, 0) << endl;
    }
}














Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	int n;
	int[] a;

	void run() {
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			// n = 200000;
			a = new int[n];

			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				// a[i] = (int) (Math.random() * 1000000000);
			}

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

	String fnc() {

		Map<Long, Integer> map = new HashMap<Long, Integer>();

		long sumIn = 0L;
		long cnt = 0;
		for (int i = 0; i <= n; i++) {
			if (i > 0) {
				sumIn += a[i - 1];
			}

			map.merge(sumIn, 1, Integer::sum);
			cnt += map.get(sumIn) - 1;
		}

		return "" + cnt;
	}

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

}


Measured memory_bytes: 94500
#include<bits/stdc++.h>
#include<cstdlib>
#include<cmath>
using namespace std; 
int main(){
  int X; int N; cin>>X>>N;
  if(N==0)
    cout<<X<<endl;
  else{
  vector<int>V(N);
  for(int i=0; i<N; i++){
cin>>V.at(i);
  }
    int K=1000;
    int Z=0;
    int Ans=0;
    for(int i=0; i<2*X; i++){
      for(int j=0; j<N; j++){
        if(V.at(j)==i)
          Z++;
      else continue;
      }
      if(Z!=0){
        Z=0;
        continue;
      }
      else{
      if(abs(i-X)<K){
        K=abs(i-X);
              Ans=i;
              }
              else continue;
              }
     
    }
    cout<<Ans<<endl;
    
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n;
  cin >> n;
  if (n % 2) cout << 2 * n << endl;
  else cout << n << endl;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())

for x in range(0, 2001):
    for y in range(0, 2001):
        if x + y > N:
            break
        z = N - (x + y)
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)



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

const int M = 1000000007;
int n, a, b, c, d, cm[1010][1010], dp[1010][1010], chk[1010][1010], inv[1010];

int pw(int x, int k){
	if(k == 1) return x;
	return 1LL * (k % 2 ? x : 1) * pw(1LL * x * x % M, k / 2) % M;
}

int f(int x, int y){
	if(y > b) return !x;
	if(x && x < y) return 0;
	if(chk[x][y]) return dp[x][y];
	int cur = 1;
	dp[x][y] = f(x, y + 1);
	for(int k = 1; k <= d; k++){
		if(x - k * y < 0) break;
		cur = 1LL * cur * cm[x - (k - 1) * y][y] % M * inv[k] % M;
		if(c <= k) dp[x][y] = (dp[x][y] + 1LL * cur * f(x - k * y, y + 1) % M) % M;
	}
	chk[x][y] = 1;
	return dp[x][y];
}

int main(){
	scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	for(int i = 0; i <= n; i++){
		if(i) inv[i] = pw(i, M - 2);
		cm[i][0] = 1;
		for(int j = 1; j <= i; j++){
			cm[i][j] = (cm[i - 1][j] + cm[i - 1][j - 1]) % M;
		}
	}
	printf("%d\n", f(n, a));
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()

int main()
{
  int N; cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i];

  vector<bool> color(8, false);
  int over3200 = 0;
  for (int i = 0; i < N; ++i) {
    if (1 <= a[i] && a[i] <= 399) {
      color[0] = true;
    } else if (400 <= a[i] && a[i] <= 799) {
      color[1] = true;
    } else if (800 <= a[i] && a[i] <= 1199) {
      color[2] = true;
    } else if (1200 <= a[i] && a[i] <= 1599) {
      color[3] = true;
    } else if (1600 <= a[i] && a[i] <= 1999) {
      color[4] = true;
    } else if (2000 <= a[i] && a[i] <= 2399) {
      color[5] = true;
    } else if (2400 <= a[i] && a[i] <= 2799) {
      color[6] = true;
    } else if (2800 <= a[i] && a[i] <= 3199) {
      color[7] = true;
    } else {
      over3200++;
    }
  }

  int cnt = count(ALL(color), true);
  int minc = (cnt == 0 ? 1 : cnt);
  int maxc = cnt+over3200;

  cout << minc << " " << maxc << endl;
}

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

int main() {
    int x, y, t;

    while (1) {
        cin >> x >> y;
        
        if ( x == 0 && y == 0) break;
        
        if ( x > y ) {
            t = x;
            x = y;
            y = t;
            cout << x << " " << y << endl; 
        } else {
            cout << x << " " << y << endl;
        }
        
    }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  string s;
  cin>>s;
  int n = s.size();
  int num[n];
  bool flag = true;
  REP(i,n){
    num[i] = s[i] - '0';
    if(i == 0)continue;
    if(num[i] == 9)continue;
    flag = false;
  }
  int ans;
  ans = num[0] + 9*(n-1);
  if(flag){
    cout<<ans<<endl;
  }else{
    ans--;
    cout<<ans<<endl;
  }
  
  return 0; 
}


Measured memory_bytes: 256
# frozen_string_literal: true
N, K = gets.chomp.split.map(&:to_i)
if N < K
  puts 1
  exit
end
count = 0
(K..N + 1).each do |k|
  min = (k - 1)*(k) / 2
  max = (N - k + 1)*k + ((k - 1)*(k) / 2)
  count += (max - min + 1)
end
p count % (10**9 + 7)


Measured memory_bytes: 14288
n = int(input())
x=n
lol=[int(n) for n in input().split()]

ans = 0
lol.sort()
lol.reverse()
z=lol.copy()
ans +=lol[0]
lol.remove(max(lol))
n=n-2

if(n%2==0):
    for i in range(int(n/2)):
        ans+=(2*lol[i])
    print(ans)
else:
    for i in range(int((n-1)/2)):
        ans+=(2*lol[i])
    ans+=(z[int(x/2)])
    print(ans)
    


    
    
    


Measured memory_bytes: 31620
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;



int n, p[20000], a[20000], b[20000], apb[20000];

int main() {
	cin >> n;
	lp(n) {
		cin >> p[i];
		a[i] = 22222 * (i + 1);
		b[i] = 22222 * (n - i);
	}
	lp(n) {
		b[p[i]-1] += i + 1;
	}
	lp(n) {
		cout << a[i] << sp;
	}
	cout << endl;
	lp(n) {
		cout << b[i] << sp;
	}
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<list>
#include<map>
#define ll long long
#define INF 2000000000
#define NINF -2000000000
#define MOD 1000000007
#define br '\n'
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	int x;
	int a[100001]={0};
	for(int i=0;i<n;i++)
	{
		cin>>x;
		a[x]++;
	}
	int sum=0;
	for(int i=1;i<=100000;i++)
	{
		if(a[i]>1)
			sum+=a[i]-1;
	}
	if(sum%2==0)
		cout<<n-sum<<br;
	else
		cout<<n-sum-1<<br;
	return 0;
}


Measured memory_bytes: 640
rect :: [String] -> [String]
rect (h:w:_) =  (\(x:y:_) -> replicate x (replicate y '#')) $ [read h, read w] 

main=do
    xs <- fmap (map words . lines) getContents
    mapM putStrLn . map unlines . map rect $ takeWhile (\(h:_:_) -> h/="0") xs


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

int main() {
  int64_t N,K;
  cin>>N>>K;
  int64_t i = N%K;
  if(N<K){
    if(abs(N-K)>N){
      cout<<N<<endl;
    }
    else{
      cout<<abs(N-K)<<endl;
    }
  }
  else if(N>=K){
    if(abs(i-K)>i){
      cout<<i<<endl;
    }
    else{
      cout<<abs(i-K)<<endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); //入力

		int Integer_number = sc.nextInt();  //整数の数
		int[] number = new int[Integer_number]; //整数
		String[] kindOfNumber = new String[Integer_number]; //偶数か奇数か

		int numberofDividing = 0; //割った回数

		for(int i = 0 ;i < Integer_number;i++) { //整数を3つ入力する。
			number[i] =  sc.nextInt(); //整数入力
		}

loop: //ループを抜け出す。
		while(true) {
			for(int j = 0; j < Integer_number; j++) {

				if(number[j] % 2 == 0) {
					number[j] = number[j] / 2;
				}else {
					break loop;
				}
				if(j + 1 == Integer_number) {
					numberofDividing++;
				}
			}
		}

		System.out.println(numberofDividing);
	}
}

Measured memory_bytes: 23124
k = int(input())
ans = 0
if k % 7 == 0:
    L = int((9 * k) / 7)
else:
    L = 9 * k
if L % 2 == 0 or L % 5 == 0:
    print(-1)
else:
    a = 1 % L
    for i in range(L):
        if (a * 10) % L == 1:
            ans = i + 1
            print(ans)
            break
        a = (a * 10) % L
    if ans == 0:
        print(-1)


Measured memory_bytes: 9104
#include <stdio.h>

int gcd(int a, int b)
{
    return a == 0 ? b: gcd(b%a, a);
}

int main()
{
    int x;
    scanf("%d", &x);
    int d = gcd(x, 180);
    int nx = x / d, ny = 180 / d;
    if (nx & 1) ny *= 2;
    printf("%d", ny);
    return 0;
}


Measured memory_bytes: 1708
#include<iostream>
#include<utility>
using namespace std;
int main(){
  long long h,w,d,q,sum,bx,by;
  cin >> h >> w >> d;
  int a[h][w];
  pair<int,int> num[100000];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
      num[a[i][j]] = make_pair(i,j);
    }
  }
  cin >> q;
  int l,r;
  int di[100000]={};
  pair<int,int> tmp0,tmp1;
  for(int i=d+1;i<=h*w;i++){
    tmp0 = num[i];
    tmp1 = num[i-d];
    di[i] = di[i-d]+abs(tmp0.first-tmp1.first)+abs(tmp0.second-tmp1.second);
  }
  for(int i=0;i<q;i++){
    cin >> l>>r;
    cout << di[r]-di[l] <<endl;
  }
}


Measured memory_bytes: 2688
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N, M, C := sc.NextInt(), sc.NextInt(), sc.NextInt()
	B := sc.NextIntArray()
	cnt := 0
	for a := 0; a < N; a++ {
		A := sc.NextIntArray()
		total := C
		for i := 0; i < M; i++ {
			total += A[i] * B[i]
		}
		if total > 0 {
			cnt++
		}
	}

	fmt.Println(cnt)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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


int main(){
  int n;
  string s,t;

  cin >> n;
  cin >> s;
  cin >> t;

  int ans=2*n;
  int i,j;
  for(j=0;j<n;++j){
    for(i=0;i<n;++i){
      if(s[i]==t[j]){
        if(t.compare(0,n-i,s,i,n-i)==0){
          ans=ans-(n-i);
          cout << ans << endl;
          return 0;
        }
        }
      }
    }


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n, m;
    cin >> n;
    string s[n];
    rep(i, n) cin >> s[i];
    cin >> m;
    string t[m];
    rep(i, m) cin >> t[i];
    int ans = 0;
    rep(i, n) {
        int cou = 0;
        rep(j, n) {
            if(s[i] == s[j]) cou++;
        }
        rep(j, m) {
            if(s[i] == t[j]) cou--;
        }
        ans = max(ans, cou);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
const long long N=2e3+10;
const long long MOD=1e9+7;
long long a[N];
long long s,ans;
int main(){
	scanf("%lld",&s);
	a[3]=1;
	for(int i=4;i<=s;i++)
		a[i]=(a[i-1]%MOD+a[i-3]%MOD)%MOD;
	printf("%lld",a[s]);
	return 0;
}

Measured memory_bytes: 3732
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

double table[100][100];

double dp[100][100]; // dp[times][cur]

signed main()
{
	int N, M;
	
	while (cin >> N >> M, N || M) {
		memset(dp, 0, sizeof(dp));

		rep(i, N) rep(j, N) cin >> table[i][j];

		rep(i, N) dp[0][i] = 1.0;

		for (int i = 1; i < M; ++i) {
			for (int j = 0; j < N; ++j) {
                for (int k = 0; k < N; ++k) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] * table[k][j]);
                }
			}
		}

        double ans = 0;

        rep(i, N) ans = max(ans, dp[M - 1][i]);

        printf("%.2f\n", ans);
	}
}

Measured memory_bytes: 1404
//Atcoder
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        pw.println("aeiou".contains(sc.next()) ? "vowel" : "consonant");

        pw.close();
    }
}


Measured memory_bytes: 21332
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 10000005; 
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n,k;
    cin >> n >> k;
    ll a[n];
    for(ll i=0;i<n;i++)    cin >> a[i];
    ll low = 1,high = 1e9,ans;
    while(low<=high)
    {
        ll mid = (low + high)/2;
        ll sum = 0;
        for(ll i=0;i<n;i++)
        {
            sum += ceil(a[i]/(ld)mid);
            sum--;
        }
        if(sum<=k)    
        {
            ans = mid;
            high = mid - 1;
        }
        else   low = mid + 1;
    }
    cout<<ans;
}

int main()
{
    ll t = 1;
 //   cin >> t;
    while(t--)
    {
        solve();
    }
}

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

int p,q,a,n;
int ans;

int dfs(int deep,int bs,int bb,int x){
	//cout<<deep<<" "<<bs<<" "<<bb<<endl;
	if(p*bb==q*bs){
		//cout<<bs<<" "<<bb<<endl;
		ans++;
	}
	if(deep!=n){
		//cout<<deep<<" "<<bs<<" "<<bb<<endl;
		for(int i=x;i<=a;i++){
			int nbs=bb+bs*i;
			int nbb=bb*i;
			if(nbb>a)return 0;
			/*
			if(nbs%p==0&&nbb%q==0&&nbs/p==nbb/q){
				cout<<nbs<<" "<<nbb<<endl;
				ans++;
			}else if(p%nbs==0&&q%nbb==0&&p/nbs==q/nbb){
				ans++;
			}
			*/
			dfs(deep+1,nbs,nbb,i);
		}
	}
}


int main(){
	while(1){
		cin>>p>>q>>a>>n;
		if(p==0&&q==0&&a==0&&n==0)break;
		ans=0;
		for(int i=1;i<=a;i++){
			dfs(1,1,i,i);
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int ans[10];
int n , m;
int main() {
    cin >> n >> m;	
	for(int i = 1; i <= m; i++){
		int s , c;
		cin >> s >> c;
		if(s == 1 && c == 0 && n > 1){
            cout << -1;
            return 0;
        }
		else if(ans[s - 1] == 0 || ans[s - 1] == c) {
            ans[s - 1] = c;
        }
		else {
            cout << -1;
            return 0;
        }
	}
	if(n == 1) {
        cout << ans[0];
    }
	else 
	{
		if(ans[0]){
            cout << ans[0];
        }
		else {
            cout << 1;
        }
		for(int i = 1; i < n; i++) {
            cout << ans[i];
        }
	}
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		Scanner sc = new Scanner(System.in);

		ArrayList<String> str = new ArrayList<String>();
		ArrayList<Character> command = new ArrayList<Character>();
		String buf;
		int x=0, y=0;


		while(true){
			buf = sc.nextLine();
			if(buf.equals("END_OF_TEXT")){
				break;
			}
			str.add(buf);
		}
		while(true){
			buf = sc.next();
			if(buf.charAt(0) == '-'){
				break;
			}
			command.add(buf.charAt(0));
		}
		buf = "";

		for(int i=0;i<command.size();i++){
			switch(command.get(i)){
			case 'a'://ok
				x=0;
				break;

			case 'e'://ok
				x=str.get(y).length();
				break;

			case 'p'://ok
				if(y!=0){
					y--;
				}
				x=0;
				break;

			case 'n'://ok
				if(str.size() != y+1){
					y++;
				}
				x=0;
				break;

			case 'f'://ok
				if(str.get(y).length() != x){
					x++;
				}else if(str.size() != y+1){
					y++;
					x=0;
				}
				break;

			case 'b'://ok
				if(x!=0){
					x--;
				}else if(y!=0){
					y--;
					x=str.get(y).length();
				}
				break;

			case 'd'://ok
				if(x!=str.get(y).length()){
					char[] strbuf = str.get(y).toCharArray();
					String resultbuf = "";
					for(int j=0;j<strbuf.length;j++){
						if(x!=j){
							resultbuf += strbuf[j];
						}
					}
					str.set(y,resultbuf);
				}else if(str.size() != y+1){
					str.set(y, str.get(y)+str.get(y+1));
					str.remove(y+1);
				}
				break;

			case 'k'://ok
				if(x!=str.get(y).length()){
					char[] strbuf = str.get(y).toCharArray();
					String resultbuf = "";
					buf = "";
					for(int j=0;j<strbuf.length;j++){
						if(x>j){
							resultbuf += strbuf[j];
						}else{
							buf += strbuf[j];
						}
					}
					str.set(y,resultbuf);
					x = str.get(y).length();
				}else if(str.size() != y+1){
					buf = "\n";
					str.set(y, str.get(y)+str.get(y+1));
					str.remove(y+1);
				}
				break;

			case 'y':
				if(buf.equals("\n")){
					char[] strbuf = str.get(y).toCharArray();
					String resultbuf = "";
					buf = "";
					for(int j=0;j<strbuf.length;j++){
						if(x>j){
							resultbuf += strbuf[j];
						}else{
							buf += strbuf[j];
						}
					}
					str.set(y,resultbuf);
					str.add(y+1,buf);

					y++;
					x=0;
					buf="\n";
				}else if(buf.length() != 0){
					char[] strbuf = str.get(y).toCharArray();
					String resultbuf = "";
					for(int j=0;j<=strbuf.length;j++){
						if(x==j){
							resultbuf += buf;
						}
						if(j!=strbuf.length){
							resultbuf += strbuf[j];
						}
					}
					str.set(y, resultbuf);
					x+=buf.length();
				}
				break;
			}
		}
		for(int i=0;i<str.size();i++){
			System.out.println(str.get(i));
		}
	}

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC100(void);
void ABC101(void);
void ABC102(void);
void ABC103(void);
void ABC104(void);
void ABC105(void);
void ABC106(void);
void ABC107(void);
void ABC108(void);
void ABC109(void);

int main(void){
    ABC106();
}

void ABC106(){
    int n,i,j,c=0,ans=0;
    cin>>n;
    for(i=1;i<=n;i++){
        if(i%2==1){
            for(j=1;j<=i;j++){
            if(i%j==0)c++;
            }
        }
        if(c==8)ans++;
        c=0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, A, i; cin >> N; map<int, long> WA, SA; long ans=0;
for(i=1; i<=N; i++){ cin >> A; WA[i+A]++; SA[i-A]++;  }
for(i=1; i<=N; i++){ ans+=WA[i]*SA[i]; } 
cout << ans << "\n";
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    cout << min(b / a, c) << '\n';
    return 0;
}


Measured memory_bytes: 3632
import math
A,B,H,M = map(int,input().rstrip().split(" "))
pi = math.pi
ans = 0
a_x = math.cos((H * 60 + M) / 360 * pi) * A
a_y = math.sin((H * 60 + M) / 360 * pi) * A
b_x = math.cos(M / 30 * pi) * B
b_y = math.sin(M / 30 * pi) * B
ans = math.sqrt(abs(a_x - b_x) ** 2 + abs(a_y - b_y) ** 2)
print(ans)


Measured memory_bytes: 9500
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

int INF=1e8;
int dist[15][15];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  while(cin>>n,n){
    fill(dist[0],dist[0]+15*15,INF);
    int m=0,a,b,d;
    rep(i,n){
      cin>>a>>b>>d;
      dist[a][b]=dist[b][a]=min(dist[a][b],d);
      m=max({m,a,b});
    }
    ++m;
    rep(i,m) dist[i][i]=0;
    rep(k,m) rep(i,m) rep(j,m)
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

    pii re=pii(INF,-1);
    rep(i,m){
      int sum=0;
      rep(j,m) sum+=dist[i][j];
      re=min(re,pii(sum,i));
    }
    //rep(i,m){rep(j,m)cout<<dist[i][j]<<",";cout<<endl;}
    cout<<re.Y<<" "<<re.X<<endl;
  }
  return 0;
}

Measured memory_bytes: 3152
#include<stdio.h>
 
int main(void){
  int a,b,c;
 
  scanf("%d%d%d",&a,&b,&c);
  if(a==b && b!=c)
      printf("Yes");
    else if(b==c && c!=a)
      printf("Yes");
    else if(c==a && a!=b)
      printf("Yes");
    else
      printf("No");
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() { 
    int n; cin >> n;
    vector<ll> C(n-1), S(n-1), F(n-1);
    rep(i, n-1) cin >> C[i] >> S[i] >> F[i];

    vector<ll> ans(n);
    rep(i, n){
        ll time = 0, p = i;
        while(p < n-1){
            if(S[p] >= time) time = S[p];
            else if(time%F[p] != 0) time += (F[p]-(time%F[p]));
            time += C[p];
            p++;
        }
        ans[i] = time;
    }
    rep(i, n){
        cout << ans[i] << ln;
    }
}

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

int main(){
  const long long INF = 1e18;
  int N;
  cin >> N;
  vector<pair<long long,long long>> T;
  long long ans = 0;
  long long ll = 0, rr = 1e18;
  for(int i = 0; i < N; ++i){
    long long l, r;
    cin >> l >> r;
    T.emplace_back(l,r);
    ll = max(ll,l);
    rr = min(rr,r);
  }
  for(auto e : T){
    ans = max(ans, e.second-e.first+1+max(0LL,rr-ll+1));
  }
  sort(T.begin(), T.end());
  vector<long long> RR(N+1,INF);
  for(int i = N-1; i > 0; --i){
    RR[i] = min(RR[i+1],T[i].second);
  }
  long long l_max = 0;

  for(int i = 0; i+1 < N; ++i){
    l_max = T[i].first;
    long long s = max(0LL,rr-l_max+1);
    long long t = max(0LL,RR[i+1]-ll+1);
    cerr << i << " " << s << " " << t << endl;
    ans = max(ans,s+t);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2544
class SegmentTree:

    __slots__ = ["func", "e", "n", "data"]

    def __init__(self, monoid_data, func, e):
        self.func = func
        self.e = e
        self.n = len(monoid_data)
        self.data = monoid_data * 2
        for i in range(self.n-1, 0, -1):
            self.data[i] = self.func(self.data[2*i], self.data[2*i+1])

    def replace(self, index, value):
        index += self.n
        self.data[index] = value
        index //= 2
        while index > 0:
            self.data[index] = self.func(self.data[2*index], self.data[2*index+1])
            index //= 2
        
    def folded(self, l, r):
        left_folded = self.e
        right_folded = self.e
        l += self.n
        r += self.n
        while l < r:
            if l % 2:
                left_folded = self.func(left_folded, self.data[l])
                l += 1
            if r % 2:
                r -= 1
                right_folded = self.func(self.data[r], right_folded)
            l //= 2
            r //= 2
        return self.func(left_folded, right_folded)

    def __getitem__(self, index):
        return self.data[self.n + index]

import sys
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

N, K = map(int, input().split())
As = list(map(int, read().split()))

dp = SegmentTree([0] * 300001, max, 0)
for A in As:
    l = max(0, A - K)
    r = min(300001, A + K + 1)
    dp.replace(A, dp.folded(l, r) + 1)

print(dp.folded(0, 300001))

Measured memory_bytes: 103600
#ABC116B-CollatzProblem.py

s = int(input())
i = 0
A = []
m = 0

def f(n):
    if n % 2 == 0:
        return int(n/2)
    else:
        return 3*n + 1

A.append(s)

while m == 0:
    A.append(f(A[i]))
    if len(A) != len(set(A)):
        m = i+2
    i += 1

print(m)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int w, h, n, x, y, a;

int main() {
    cin >> w >> h >> n;
    int x_min = 0, x_max = w, y_min = 0, y_max = h;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y >> a;
        if (a == 1) {
            x_min = max(x_min, x);
        } else if (a == 2) {
            x_max = min(x_max, x);
        } else if (a == 3) {
            y_min = max(y_min, y);
        } else {
            y_max = min(y_max, y);
        }
    }
    cout << max(0, x_max - x_min) * max(0, y_max - y_min) << endl;
    return 0;
}


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

struct iostream_init_struct
{ 
	iostream_init_struct()
	{
		std::cin.tie(0);
		std::cin.sync_with_stdio(false);
	}
} iostream_init;

long long solve(long long k, long long s)
{
	long long count = 0;
	for (int x = 0; x <= k; ++x)
	{
		for (int y = 0; y <= k; ++y)
		{
			if (x + y > s)
				continue;
			int z = s - x - y;
			if (z >= 0 && z <= k)
				count++;
		}
	}
	return count;
}

int main()
{
	int K, S;
	cin >> K >> S;
	cout << solve(K, S) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
long long int factorial(long long int x){
  return x==0 ? 1 : x*factorial(x-1);
}
int main(){
  int i, j;
  char s[5];
  cin >> s;
  sort(s, s+4);
  if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])
    cout << "Yes";
  else cout << "No";
  return 0;
}


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

using namespace std;

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

    bool ok = true;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 and a % 5 != 0) ok = false;
        }
    }

    cout << (ok ? "APPROVED" : "DENIED") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int H;
  int A[251];
  int i;

  scanf("%d", &H);
  for(i=1;i<=H;i++)
    {
      scanf("%d", &A[i]);
    }

  for(i=1;i<=H;i++)
    {
      printf("node %d: key = %d, ", i, A[i]);
      if(i != 1)printf("parent key = %d, ", A[i/2]);
      if(2*i <= H)printf("left key = %d, ", A[2*i]);
      if(2*i+1 <= H)printf("right key = %d, ", A[2*i+1]);
      printf("\n");
    }
  
  return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>

int main(void)
{
	int w;
	int n;
	int i;
	int amida[30];
	int a, b;
	
	for(i = 0; i < 30; i++){
		amida[i] = i + 1;
	}
	
	scanf("%d", &w);
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d%*c%d",&a,&b);
		amida[a - 1] += amida[b - 1];
		amida[b - 1] = amida[a - 1] - amida[b - 1];
		amida[a - 1] = amida[a - 1] - amida[b - 1];
	}
	
	for (i = 0; i < w; i++){
		printf("%d\n",amida[i]);
	}
	
	return (0);
}

Measured memory_bytes: 0
local function gen_divisor(n)
    return coroutine.wrap(function()
        local ds = {}
        for i=1, math.floor(n^0.5) do
            if n % i == 0 then
                coroutine.yield(i)
                table.insert(ds, n // i)
            end
        end
        if n // ds[#ds] == ds[#ds] then
            table.remove(ds)
        end
        for i=#ds,1,-1 do
            coroutine.yield(ds[i])
        end
    end)
end

local N, M = io.read("n", "n")
for di in gen_divisor(M) do
    if di >= N then
        ans = M // di
        print(ans)
        return
    end
end

Measured memory_bytes: 888