akhauriyash/Code-Regression huggingface dataset:
import numpy
N = int(input())
A = list(map(int, input().split()))

res = []
res.append(A[0])
for i in range(len(A)-1):
    res.append(res[i] + A[i+1])

sum = 0
for i in range(N-1):
    sum += A[i] * (res[N - 1] - res[i])

print(sum % (10**9+7))

Measured memory_bytes: 50052
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define LL                      long long
#define Ulong                   unsigned long long
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-14
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl
#define nl                      cout<<endl
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("/home/matrixcode/Desktop/in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
  register char c = getchar();x = 0;
  int neg = 0;
  for(; ((c<48 || c>57) && c != '-'); c = getchar());
  if(c=='-'){neg = 1;c = getchar();}
  for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
  if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
  long long ret = 1;
  for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 3e5+5;
int w[105];
int v[105];
LL dp[105][N];
int main()
{
  int n, W;
  in2(n,W);
  for(int i = 1; i <= n; i ++) {
    in2(w[i], v[i]);
  }
  for(int j = 0; j < N; j ++) dp[0][j] = INT_MAX;
  dp[0][0] = 0;
  for(int i = 1; i <= n; i ++ ) {
    for(int j = 0; j < N; j ++ ) {
      dp[i][j] = dp[i-1][j];
      if(v[i] <= j) {
        dp[i][j] = min(dp[i][j], dp[i-1][j - v[i]] + w[i]);
      }
    }
  }
  LL iMax = INT_MIN;
  for(int i = 0; i <= N; i ++ ) {
    if(dp[n][i] && dp[n][i] <= W) iMax = i;
  }
  cout << iMax << endl;
}


Measured memory_bytes: 237824
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib> 
#include <ctime>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
	int n, ret=0, a, x=1, nn;
	cin >> n; nn = n;
	while (n-- > 0) {
		cin >> a;
		if (a == x) x++;
		else ret++;
	}
	if (ret == nn) ret = -1;
	cout << ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

vector<ll> vll;
ll num[ten52];

int main(void)
{
    ll m,n,i,j,k,k1,d=0,d1=0,sum=0,sum2=0;
    string s,s1;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>k>>k1;
        if(k>=d && k1>=d1)
        {
            d=k;
            d1=k1;
        }
        else
        {
            m=max((d+k-1)/k,(d1+k1-1)/k1);
            d=k*m;
            d1=k1*m;
        }
    }
    cout<<d+d1;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(){

	int a, b;

	scanf("%d%d", &a, &b);

	if (a<b){
		printf("a < b\n");

	}
	else if (a>b){
		printf("a > b\n");

	}
	else{
		printf("a == b\n");
	}

	return 0;
}

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

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}

int main(){
	int h,w;
	cin >> h >> w;
	string ans = "snuke",str;
	rep(i,h){
		rep(j,w){
			cin >> str;
			if (str == ans) 
				printf("%c%d\n",j+'A',i+1);
		}
	}
	return 0;
}



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

int main(){
  long long int a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  if(v-w>0 && (v-w)*t >= abs(a-b)){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

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

int main(){
  string s,p,c;
  int count=0;
  cin>>s>>p;

  int a=p.size();
  int b=s.size();
  s+=s;
  for(int i=0;i<b*2;i++){ 
    c=s.substr(i,a);

    if(p==c) count++;
    
  }

  if(count>0) cout<<"Yes"<<endl;
  else if(count==0) cout<<"No"<<endl;
  
  return 0;
}



Measured memory_bytes: 3196
program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,a,b,c,money
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)x
    money=1000
    c=0
    do i=1,n-1
        if(x(i)<x(i+1) .and. c==0)then
            a=x(i)
            b=money/x(i)
            c=1
        else if(x(i)>x(i+1) .and. c==1)then
            money=money+(x(i)-a)*b
            c=0
        end if
    end do
    if(c==1)then
        money=money+(x(n)-a)*b
    end if
    write(*,*)money

    
    stop
end program sample
  



Measured memory_bytes: 2864
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int 
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int h,w,n;
    cin>>h>>w>>n;
    h = max(h,w);
    cout<<(n/h)+(n%h>0)<<endl;
}
signed main()
{
    faster();
    int t=1;
    //cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 10;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> A(n);
    for(int i = 0; i < n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    ll N = A.back();
    pair<ll, ll> ans;
    ll v = INF;
    for(int i = 0; i < n; i++)
    {
        if(N <= A[i]) continue;
        ll d = abs((N + 1) / 2 - A[i]);
        if(v > d)
        {
            ans = make_pair(N, A[i]);
            v = d;
        }
    }
    cout << ans.first << " " << ans.second << endl;
    return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;

const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const ll INF = 1e18;
const ld PI = acos((ld) - 1);

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

	int l = 0, r = n - 1;
	int sol = 0;

	while (l < r) {
		if(ar[l] != ar[r] && ar[l] == 'W') {
			swap(ar[l], ar[r]);
			sol++;
			l++;
			r--;
			continue;
		}
		
		if(ar[l] == 'R') {
			l++;
		}

		if(ar[r] == 'W') {
			r--;
		}
	}

	cout << sol << '\n';
}


Measured memory_bytes: 3784
#!/usr/bin/env python

def SieveOfEratosthenes(n):
    prime_list = [True] * (n+1)
    p = 2
    while (p ** 2 <= n):
        if prime_list[p]:
            for i in range(p ** 2, n+1, p):
                prime_list[i] = False
        p += 1
    return prime_list

def main():
    X = int(input())
    N = 10 ** 6 + 500
    prime_idx = SieveOfEratosthenes(N)
    primes = [val for val, idx in zip(range(N+1), prime_idx) if idx]
    ans = [x for x in primes if x >= X]
    print(ans[0])

if __name__ == '__main__':
    main()

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

int N, M;
vector<vector<int> > g(10, vector<int>(10));

int dfs(int v/*現在の探索要素*/, int bit/*探索状態*/) {
  bit |= (1<<(v-1));

  if(bit == ((1<<N)-1)) return 1;

  int count = 0;
  for(int i = 0; i < g[v].size(); i++) {
    if(g[v][i] != 1) continue;
    if((bit>>(i-1))&1) continue; //もしも探索済みならcontinue
    count += dfs(i, bit);
  }
  return count;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;

  for(int i = 0; i < M; i++ ) {
    int a, b;
    cin >> a >> b;
    g[a][b] = 1;
    g[b][a] = 1;
  }

  cout << dfs(1, 0) << endl;


}


Measured memory_bytes: 256
n=int(input())
k=int(input())
s=len(list(str(n)))
if k==1:
    ans=(s-1)*9
    for i in range(9):
        if n>=(10**(s-1))*(i+1):
            ans+=1
elif k==2:
    ans=9*9*(s-1)*(s-2)//2
    for i in range(9):
        for j in range(s-1):
            for p in range(9):
                if n>=(10**(s-1))*(i+1)+(10**j)*(p+1):
                    ans+=1
else:
    ans=9*81*(s-1)*(s-2)*(s-3)//6
    f=int(list(str(n))[0])
    ans+=(f-1)*81*(s-1)*(s-2)//2
    for p in range(s-1):
        for q in range(s-1):
            if p<q:
                for t in range(1,10):
                    for u in range(1,10):
                        if n>=(10**(s-1))*f+(10**p)*t+(10**q)*u:
                            ans+=1
print(ans)


Measured memory_bytes: 43356
N=int(input())
dp=[0]*N
for i in range(N-1):
  C,S,F=map(int,input().split())
  for j in range(i+1):
    if dp[j]>S:
      if (dp[j]-S)%F!=0:
        dp[j]=((dp[j]-S)//F+1)*F+S
    else:
      dp[j]=S
    dp[j]+=C
for i in range(N):
  print(dp[i])

Measured memory_bytes: 9020
const toInt = x=>parseInt(x,10);
const toIntArr = arr=>arr.map(x=>toInt(x));
const abs = x=>x>0?x:-x;
function min(){let rest = arguments,val=rest[0];for(let i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){let rest = arguments,val=rest[0];for(let i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(inputText){
	let input = inputText.split('\n');
	input = input.map(e => toIntArr(e.split(' ')));
	let xs = input[0];
	for(let i = 0; i < 5; i++)if(i+1!==xs[i]){
		console.log(i+1);
		return 0;
	};
}

Measured memory_bytes: 29632
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val S, T = sc.next
    val A, B = sc.nextInt
    val U = sc.next

    var ans = ();

    if (S == U) print(s"${A - 1} ${B}")
    else print(s"${A} ${B - 1}")
  }
}

Measured memory_bytes: 27196
#include<stdio.h>

unsigned long func(unsigned long h, unsigned long l){
    unsigned long a = h%l;
    while(a != 0){
        h = l;
        l = a;
        a = h%l;
    }
    return l;
}

unsigned long sub_func(unsigned long x){
    unsigned long c = 0;
    if(x % 2 == 0){
        c++;
        while(x%2 == 0){
            x = x/2;
        }
    }
    if(x % 3 == 0){
        c++;
        while(x%3 == 0){
            x = x/3;
        }
    }
    if(x % 5 == 0){
        c++;
        while(x%5 == 0){
            x = x/5;
        }
    }
    if(x % 7 == 0){
        c++;
        while(x%7 == 0){
            x = x/7;
        }
    }
    for(unsigned long i=5; i*i<=x; i += 2){
        if(i%3 == 0 || i%5 == 0 || i%7 == 0){
            continue;
        }
        if(x%i == 0){
            c++;
            while(x%i == 0){
                x = x/i;
            }
        }
    }
    if(x>1){
        c++;
    }

    return c;
}

int main(){
    unsigned long a, b;
    scanf("%lu%lu", &a, &b);
    unsigned long h, l, g;
    if(a>b){
        h = a;
        l = b;
    }else{
        h = b;
        l = a;
    }
    g = func(h, l);
    printf("%lu", sub_func(g) + 1);

    return 0;
}

Measured memory_bytes: 128
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const [N, C, K] = lines[0].split(' ').map(Number)

    const T = []
    for (let i = 0; i < N; i++) {
      T[i] = lines[i + 1] - 0
    }
    T.sort((a, b) => a - b)

    let pas = 1
    let bus = 1
    let start = T[0]
    for (let i = 1; i < N; i++) {
        if (T[i] - start > K || pas >= C) {
            pas= 1
            bus++
            start = T[i]
        } else {
          pas++
        }
    }

    console.log(bus)

})(input)


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

int main(){
	int a,b;
	cin >> a >> b;
	for(int i=1;i<1000;i++){
		if(i*(i+1)/2-a==(i+1)*(i+2)/2-b){
			cout << i*(i+1)/2-a << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int i,k,j,N;
    scanf("%d",&N);
    int data[N][3],cnt[N][3],sum[N];
    for(i = 0; i < N; i ++ ){
        sum[i] = 0;
        for(k = 0; k < 3; k ++ ){
            scanf("%d",&data[i][k]);
        }
    }
    for(j = 0; j < 3; j ++ ){
        for(i = 0; i < N; i ++ ){
            cnt[i][j] = 0;
            for(k = 0; k < N; k ++ ){
                if(i == k)continue;
                else if(data[i][j] == data[k][j]){
                    cnt[i][j] ++;
                    //data[i][j] = 0;
                    //data[k][j] = 0;
                    // printf("%d\n",data[i][j]);
                    //break;
                }
            }
        }
    }
    for(i = 0; i < N; i ++ ){
        for(j = 0; j < 3; j ++ ){
            if(cnt[i][j] != 0)data[i][j] = 0;
            sum[i] += data[i][j];
        }
        printf("%d\n",sum[i]);
    }
    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int W = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(Math.max(a, b) <= Math.min(a + W, b + W) ? 0 : Math.min(Math.abs((a + W) - b), Math.abs((b + W) - a)));
        }
    }
}


Measured memory_bytes: 27016
using System;

class A{
	public static void Main(){


		while (true) {
			string[] input = Console.ReadLine ().Split (' ');
			int H = int.Parse (input [0]);
			int W = int.Parse (input [1]);
		 
			if (H == W && H == 0) {
				break;
			}
		
			for (int x=0; x<H; x++) {
				for (int i=0; i<W; i++) {
					Console.Write ("#");
				}
				Console.WriteLine ();
			}
			Console.WriteLine ();
		}	
	}

}

Measured memory_bytes: 8880
object Main {
  def main(args:Array[String]) = {
    val input=io.StdIn.readLine()
    println(solve(input).toString.trim())
   // print(input)
  }
 
 def solve(input:String): Int= {
  val arr = input.split(" ")map(_ .toInt)
  val ans1= arr(1)/arr(0)
   val ans =if (ans1 <= arr(2)){
   ans1
   }else{
   arr(2)
   }
   ans
  }
}

Measured memory_bytes: 27208
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N,K; cin >> N >> K;
    if(K > (N-1)*(N-2) / 2){
        cout << -1 << endl;
        return 0;
    }
    vector<Pi> ans;
    rep(i,N-1){
        ans.push_back(Pi(1,i+2));
    }
    int add = (N-1)*(N-2)/2 - K;
    vector<Pi> add_e;
    rep(i,N-2)repr(j,i+3,N+1){
        add_e.push_back(Pi(i+2,j));
    }
    rep(i,add){
        ans.push_back(add_e[i]);
    }
    int M = ans.size();
    cout << M << endl;
    rep(i,ans.size()){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

Measured memory_bytes: 384
N=int(input())
txy=[list(map(int, input().split())) for _ in range(N)]
is_No=0
for row in txy:
    if row[0]%2==0:
        if row[1]+row[2]<=row[0] and (row[1]+row[2])%2==0:
            continue
        else:
            is_No=1
            break
    elif row[0]%2==1:
        if row[1]+row[2]<=row[0] and (row[1]+row[2])%2==1:
            continue
        else:
            is_No=1
            break
    else:
        is_No=1
        break
print("No" if is_No else "Yes")


Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
  int main () {
  int X;
    
  cin >> X;
  
  if ( X == 3 || X == 5 || X == 7 ){
  cout << "YES" << endl;
  }
  
  else {
  cout << "NO" << endl;
  }
  }

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

using namespace std;

int main(void){

    int h, w;
    cin >> h >> w;

    vector<vector<char>> maps;
    for(int i=0; i<h; i++) {
        vector<char> map;
        for(int j=0; j<w; j++) {
            char temp;
            cin >> temp;
            map.push_back(temp);
        }
        maps.push_back(map);
    }
    
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            if(maps[i][j] != '#') {
                int count = 0;
                if(i-1>=0) {
                    if((j-1>=0) && maps[i-1][j-1] == '#') count++; 
                    if(maps[i-1][j] == '#') count++;
                    if((j+1<w) && maps[i-1][j+1] == '#') count++;
                } 
                if(i+1<h) {
                    if((j-1>=0) && maps[i+1][j-1] == '#') count++; 
                    if(maps[i+1][j] == '#') count++;
                    if((j+1<w) && maps[i+1][j+1] == '#') count++;
                }
                if(j-1>=0 && maps[i][j-1] == '#') count++;
                if(j+1<w && maps[i][j+1] == '#') count++;
                
                maps[i][j] = '0' + count;
            }
        }
    }

    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            cout << maps[i][j];
        }
        cout << 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;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N, M;
    cin >> N >> M;
    int ans = 0;
    ans = N*(N-1)/2+M*(M-1)/2;
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  v.back() /= 2;
  
  int sum = 0;
  for (int i : v) {
    sum += i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll ans=0;
  string S;
  cin>>S;
  for(auto x:S) {
    if(x=='+') {
ans++;
    }
    else {
ans--;
    }
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int x,a=1;
		Scanner sc = new Scanner(System.in);
		while(true){
			x=sc.nextInt();
			if(x == 0) break;
			System.out.println("Case "+ a++ +": "+x);
		}
	}
}


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

using namespace std;

const int N = 500017;

int n, L;

bool read() {
    if (!(cin >> n >> L))
        return false;

    return true;
}

void solve() {
    long long sum = 0;

    for (int i = 0; i < n; ++i)
        sum += L + i;

    long long res = sum - L;

    for (int i = 0; i < n; ++i)
        if (abs(L + i) < abs(sum - res))
            res = sum - (L + i);

    cout << res << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test(n) cout << "test" << n << endl;
#define fixsp(n) fixed << setprecision(n)
#define defsp(n) defaultfloat << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define vector3D(K, N, M, DP) vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M)));
#define vector4D(K, N, M, O, DP) vector<vector<vector<vector<ll>>>> DP(K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O))));
#define zenbu(a) a.begin(), a.end()
#define rzenbu(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}
/* ここからコード開始 */

int main(){
  kyopro;
  ll A, B, Q;
  cin >> A >> B >> Q;
  deque<ll> s(A);
  for(auto&& i : s) cin >> i;
  s.push_front(-100000000000);
  s.push_back(100000000000);
  deque<ll> t(B);
  for(auto&& i : t) cin >> i;
  t.push_front(-100000000000);
  t.push_back(100000000000);

  rep(i, 0, Q){
    ll x;
    cin >> x;
    auto itrs = lower_bound(zenbu(s), x);
    auto itrt = lower_bound(zenbu(t), x);
    ll sw = *(itrs - 1);
    auto itrsw = lower_bound(zenbu(t), sw);
    sw = abs(x-sw) + min(abs(sw-*itrsw), abs(sw-*(itrsw-1)));
    ll se = *(itrs);
    auto itrse = lower_bound(zenbu(t), se);
    se = abs(x-se) + min(abs(se-*itrse), abs(se-*(itrse-1)));
    ll tw = *(itrt - 1);
    auto itrtw = lower_bound(zenbu(s), tw);
    tw = abs(x-tw) + min(abs(tw-*itrtw), abs(tw-*(itrtw-1)));
    ll te = *(itrt);
    auto itrte = lower_bound(zenbu(s), te);
    te = abs(x-te) + min(abs(te-*itrte), abs(te-*(itrte-1)));
    cout << min({sw, se, tw, te}) << rt;
  }
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

struct edge{ 
    int u,v,cost;
    bool operator<(const edge& e){
	return cost<e.cost;
    }
};

struct UnionFind{
    vint v;
    UnionFind(int n){ v.assign(n,-1); }
    int  find(int x){ return v[x]<0? x:v[x]=find(v[x]); }
    void unite(int x,int y){ 
        x=find(x),y=find(y); if(x==y) return;
        if(v[x]>v[y]) swap(x,y); v[x]+=v[y],v[y]=x;
    }
    int  size(int x){ return -v[find(x)]; }
    bool same(int x,int y){ return find(x)==find(y); }
    bool root(int x){ return v[x]<0; }
};

signed main()
{
    int V,E; cin>>V>>E;
    vector<edge> es(E);
    REP(i,E){
	int s,t,w; cin>>s>>t>>w;
	es[i]=(edge){s,t,w};
    }
    sort(ALL(es));

    UnionFind uf(V);
    int ans=0;
    for(auto e:es){
	if(!uf.same(e.u,e.v)){
	    uf.unite(e.u,e.v);
	    ans+=e.cost;
	}
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 5196
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  int H, W; cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++){
    cin >> S[i];
  }

  int tate[H][W], yoko[H][W];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      tate[i][j] = 0; yoko[i][j] = 0;
    }
  }
  
  for (int i = 0; i < H; i++){
    int cnt = 0;
    for (int j = 0; j < W; j++){
      if (S[i][j] == '#'){
        for (int k = 0; k < cnt; k++){
          yoko[i][j - 1 - k] = cnt;
        }
        cnt = 0;
      }else{
        cnt++;
      }
    }
    for (int k = 0; k < cnt; k++){
      yoko[i][W - 1 - k] = cnt;
    }
  }
  
  for (int j = 0; j < W; j++){
    int cnt = 0;
    for (int i = 0; i < H; i++){
      if (S[i][j] == '#'){
        for (int k = 0; k < cnt; k++){
          tate[i - 1 - k][j] = cnt;
        }
        cnt = 0;
      }else{
        cnt++;
      }
    }
    for (int k = 0; k < cnt; k++){
      tate[H - 1 - k][j] = cnt;
    }   
  }
  
  int ans = 0;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      ans = max(ans, yoko[i][j] + tate[i][j] - 1);
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN=110;

int n,a[MAXN],Ans=1<<30;

int main()
{
	scanf("%d",&n);
	int S1=0,S2=0;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),S2+=a[i];
	for(int i=1;i<=n;i++)
	{
		Ans=min(Ans,abs(S2-S1));
		S1+=a[i];S2-=a[i];
	}
	printf("%d\n",Ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
	int n,p,k = 0,tmp;
	cin >> n;
	while (n--){
		cin >> p;
		tmp = upper_bound(a,a + k,p,greater< int >()) - a;
		if (tmp == k){
			a[k] = p;
			++ k;
		}
		else a[tmp] = p;
	}
	cout << k << endl;
}

Measured memory_bytes: 640
#M-SOLUTIONS プロコンオープン-D Maximum Sum of Minimum
"""
問題：
木が与えられる。
リストCが与えられるので、各頂点に割り当てる。
全ての辺において、その辺をつなぐ2頂点をa,bとした時、min(Ca,Cb)をスコアとする。
これを最大化するスコアを求め、そのような頂点への数値の割り振りを出力せよ。
考察：
シュミレーションしてみると、
1.辺数が多い頂点に大きい数字を割り当てると良さそう
2.複数あっても適当に選んで良い
3.大きい数字は隣り合ったほうが良い
4.よって、辺数が多い頂点をrootとして、そこから幅を優先して
大きい数字を順に割り当てるのが良さそう。
5.この時には別に子の辺数を気にする必要はない。(これは、その"子"がスコアとして使用
されるのは必ず1回であることから言える)
解法：
接続する辺が最も多い頂点をrootとして、幅優先でそこから大きい値を割り振っていく。
全ての子は必ず1回づつ使われるので、実はスコアの最大値は
all(C)-(rootの値)となる。
"""
import sys
from collections import deque
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
g = [[] for _ in range(n)]
edges = [0]*n
for i in range(n-1):
    a,b = map(int,readline().split())
    a,b = a-1,b-1
    edges[a] += 1
    edges[b] += 1
    g[a].append(b)
    g[b].append(a)
C = list(map(int,readline().split()))
C.sort(reverse=True)
C = deque(C)
root = 0
res = 0
for i in range(n):
    if res < edges[i]:
        root = i
        res = edges[i]

ans = [-1]*n
ans[root] = C.popleft()
deq = deque([root])
while deq:
    fr = deq.popleft() #queue
    for go in g[fr]:
        if ans[go] != -1:
            continue
        ans[go] = C.popleft()
        deq.append(go)

print(sum(ans)-ans[root])
print(*ans)

Measured memory_bytes: 46320
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    Vector<Integer> aM; // appearMod
    int[] mod;
    int[] appearAns;
    int n, mm;

    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    if(n!=0){
		aM = new Vector<Integer>();
		appearAns = new int[(n-1)/2+1];
		mm = (n-1)/2;
		solve();
	    }
	}
    }

    void solve(){
	for(int i=1; i<n; i++){
	    int s = (i*i) % n;
	    if(!aM.contains(s)) aM.add(s);
	}

	mod = new int[aM.size()];
	for(int i=0; i<mod.length; i++)
	    mod[i] = aM.elementAt(i);

	setAns(0, -1);
	for(int i=1; i<appearAns.length; i++)
	    System.out.println(appearAns[i]);
    }


    void setAns(int level, int sum){
	if(level==mod.length) return;

	// mod[level] を使わない
	setAns(level+1, sum);	    
	// mod[level] を使う
	if(sum==-1) setAns(level+1, mod[level]);
	else{
	    int sumA = calc(sum, mod[level]);
	    int sumB = calc(mod[level], sum);
	    appearAns[sumA]++;
	    appearAns[sumB]++;
	}
    }

    int calc(int a, int b){
	int sum = a-b;
	if(sum < 0) sum += n;
	if(sum > mm) sum = n-sum;
	return sum;
    }
}

Measured memory_bytes: 27236
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int a=vec.at(n/2-1);
  int b=vec.at(n/2);
  cout <<b-a << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  ll o = 0;
  for(ll i = 1; i <= n; i++) o += i * (n / i + 1) * (n / i) / 2;
  printf("%lld\n", o);
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    rep(i,0,h){
        rep(j,0,w){
            string s;
            cin>>s;
            if(s=="snuke") cout<<(char)(j+'A')<<i+1<<endl;
        }
    }
}


Measured memory_bytes: 256
main(r,t,D,a,b,c,d,e,A,B,C){for(;scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&A,&B,&C)>7;printf("%d\n",r)){
	r=a*A+b*B+c*C;
	r=C>=d?a*A+b*B+e*C:(D=d,d-=C,t=B<d?B:d,B-=t,d-=t,t=A<d?A:d,A-=t,d-=t,r>(t=a*A+b*B+e*D))?t:r;
}exit(0);}

Measured memory_bytes: 600
#include<iostream>

using namespace std;



int main(){
  int n;
  cin >> n;
  long long dp[n][21];

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 21; j++){
      dp[i][j] = 0;
    }
  }

  int num;
  cin >> num;
  dp[0][num] = 1;

  /*for(int j = 0; j < 21; j++){
    cout << j << " ";
  }
  cout << endl;

  for(int j = 0; j < 21; j++){
    cout << dp[0][j] << " ";
  }
  cout << endl;*/


  for(int i = 1; i < n-1; i++){
    cin >> num;
    for(int j = 0; j < 21; j++){
      //if(dp[i-1][j] != 0){
        if(j+num <= 20) dp[i][j+num] += dp[i-1][j];
        if(j-num >= 0)  dp[i][j-num] += dp[i-1][j];
      //}
    }
  }

  cin >> num;
  cout << dp[n-2][num] << endl;
}



Measured memory_bytes: 3084
#include <stdio.h>
int main(){

  int h,w,a,b,blank;

  scanf("%d %d",&h,&w);

  if(h%3 == 0 || w%3 == 0){

    printf("0\n");
    return 0;

  }

  if(h%2 == 0 && h == w){

    printf("%d\n",h/2);
    return 0;

  }

  if(h%2 == 1 && h == w){

    printf("%d\n",h-1);
    return 0;

  }


  if(h > w){

    blank=h;
    h=w;
    w=blank;

  }

  if(h%2 == 0){

    if(w%2 == 1 && w < h/2) printf("%d\n",w);
    else printf("%d\n",h/2);
    return 0;

  }

  if(h%2 == 1){

    if(w%2 == 0 && w/2 < h) printf("%d\n",w/2);
    else printf("%d\n",h);
    return 0;

  }

}

Measured memory_bytes: 128
H,W=map(int,input().split())
A=[]
for _ in range(H):
    a=list(input())
    if sum(list(map(ord, a)))==ord(".")*W:
        continue
    A.append(a)

B=[]
for a in zip(*A):
    if sum(list(map(ord, a)))==ord(".")*len(a):
        continue
    B.append(a)

for b in zip(*B):
    print("".join(b))

Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int n;
int ans;


ll ni(ll a,ll b){
    if(b==0) return 1;
    else if(b%2==0) return ni(a,b/2)*ni(a,b/2);
    else return ni(a,b-1)*a;
}

void solve(string s,int kurai){
    ll now=0;
    int sl=s.length();
    bool c3,c5,c7;
    c3=c5=c7=false;
    rep(i,sl){
        int keta=s[i]-'0';
        now+=keta*ni(10,sl-i-1);
        if(keta==3) c3=true;
        if(keta==5) c5=true;
        if(keta==7) c7=true;
    }
    //cout << now << endl;
    if(now>n) return;
    if(c3 && c5 && c7) ans++;
    s[kurai]='3';
    solve(s,kurai-1);
    s[kurai]='5';
    solve(s,kurai-1);
    s[kurai]='7';
    solve(s,kurai-1);
}

int main(){
    cin >> n;
    solve("0000000000",9);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll h, w, k, ans;
vector<vector<int> > s(20, vector<int>(2000));

void func(vector<int>& v){
  bool saigo = false;
  vector<int> one(h - 1, 1);
  if(v == one){
    saigo = true;
  }
  ll cnt = 1, ret = 0;
  for(int i = 0; i < v.size(); i++){
    if(v[i] == 1) cnt++;
  }
  vector<ll> sum(cnt, 0), zero(cnt, 0);
  int mj = -1;
  for(int j = 0; j < w; j++){
    int id = 0;
    for(int i = 0; i < h; i++){
      sum[id] += s[i][j];
      if(sum[id] > k){
        //if(saigo) cout << j << " ";
        j--;
        if(j == mj){
          return;
        }
        mj = j;
        ret++;
        sum = zero;
        break;
      }
      if(i < h - 1 && v[i] == 1){
        id++;
      }
    }
  }
  ans = min(ans, ret + cnt - 1);
  //if(saigo) cout << ans << endl;
  return;
}

void zentan(vector<int>& v){
  if(v.size() == h - 1){
    //for(int i = 0; i < v.size(); i++) cout << v[i]; cout << endl;
    func(v);
    return;
  }
  v.push_back(0);
  zentan(v);
  v.pop_back();
  v.push_back(1);
  zentan(v);
  v.pop_back();
  return;
}

void solve(){
  cin >> h >> w >> k;
  ans = (h - 1) + (w - 1);
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      char c; cin >> c;
      s[i][j] = c - '0';
    }
  }
  vector<int> v;
  zentan(v);
  cout << ans << endl;
  return;
}

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


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

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

  int H,W;
  cin >> H >> W;
  vector<string> a(H);
  for(int i = 0; i < H; i++){
    cin >> a[i];
  }
  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(j == 0){
        cout << "#";
      }
      cout << a[i][j];
      if(j == W - 1){
        cout << "#";
      }
    }
    cout << endl;
  }

  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
}

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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=1;

int main()
{
    long double d,t,s;
    cin>>d>>t>>s;
    long double ans=d/s;
    if(ans <= t){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 3716
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	bool N=false,S=false,E=false,W=false;
	for(int i=1;i<=s.size();i++)
	{
		if(s[i-1]=='N')N=true;
		if(s[i-1]=='W')W=true;
		if(s[i-1]=='S')S=true;
		if(s[i-1]=='E')E=true;
	}
	cout << (N==S and W==E ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;


int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int a[200000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int max = a + b;
	if (max < a - b)max = a - b;
	if (max < a*b)max = a*b;
	PRINTD(max);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
string s;

int main(){
	cin >> s;

	stack<char> st; int c=0; st.push('U');
	REP(i,0,s.size()){
		if(st.top()=='S' and s[i]=='T') st.pop(),c++;
		else st.push(s[i]);
	}
	
	cout << s.size()-2*c << endl;
	return 0;
}



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

#define MAX 100000

int main() {
  int i;
  int curr;
  int n;
  int buf, trial;
  vector<int> x(MAX);
  
  cin >> n;
  
  for (i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  
  curr = 1;
  trial = 1;
  for (i = 0; i < n; i++) {
    buf = x.at(curr - 1);
    if (buf == 2) {
      cout << trial << endl;
      return 0;
    } else {
      curr = buf;
      trial++;
    }
  }
  
  cout << -1 << endl;
}

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

int main()
{
  int k, sum;
  cin >> k >> sum;
  int result = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (0 <= sum - x - y && sum - x - y <= k) {
        result++;
      }
    }
  }
  cout << result << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <climits>
typedef long long ll;

const int max_t = 20;
ll dist[max_t][max_t];

int main() {
	//freopen("aoj0189.txt", "r", stdin);
	while (1) {
		int n, t = 0;
		scanf("%d", &n);
		if (n == 0) break;
		
		for (int i = 0; i < max_t; i++) {
			std::fill(dist[i], dist[i] + max_t, INT_MAX);
		}
		for (int i = 0; i < n; i++) {
			int from, to;
			ll d;
			scanf("%d%d%lld", &from, &to, &d);
			t = std::max(t, from);
			t = std::max(t, to);
			dist[from][to] = d;
			dist[to][from] = d;
		}
		for (int i = 0; i <= t; i++) {
			dist[i][i] = 0;
		}

		for (int k = 0; k <= t; k++) {
		for (int i = 0; i <= t; i++) {
			for (int j = 0; j <= t; j++) {
						dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}

		ll min_len = INT_MAX;
		int start = -1;
		for (int i = 0; i <= t; i++) {
			ll len = 0;
			for (int j = 0; j <= t; j++) {
				if (j == i) continue;

				len += dist[i][j];
			}
			if (len < min_len) {
				min_len = len;
				start = i;
			}
		}

		printf("%d %lld\n", start, min_len);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        if(i!=n-1)cout << a[n-i-1] << " " << flush;
        else cout << a[0] << endl;
    }
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int tot, prime[MAXN], f[MAXN];
void sieve(int n) {
	for (int i = 2; i <= n; i++) {
		if (f[i] == 0) prime[++tot] = f[i] = i;
		for (int j = 1; j <= tot && prime[j] <= f[i]; j++) {
			int tmp = prime[j] * i;
			if (tmp > n) break;
			f[tmp] = prime[j];
		}
	}
}
set <int> ans;
int n, gcd, a[MAXN];
void factor(int x) {
	for (int i = 2; i * i <= x; i++)
		while (x % i == 0) {
			x /= i;
			ans.insert(i);
		}
	if (x != 1) ans.insert(x);
}
void update(int &x, int y, int p) {
	x = (x + y) % p;
}
void test(int p) {
	static int sum[MAXN];
	for (int i = 0; i <= p - 2; i++)
		sum[i] = 0;
	for (int i = 0; i <= n; i++)
		update(sum[i % (p - 1)], a[i], p);
	for (int i = 0; i <= p - 2; i++)
		if (sum[i] != 0) return;
	ans.insert(p);
}
int main() {
	read(n), sieve(n);
	for (int i = n; i >= 0; i--) {
		read(a[i]);
		if (a[i] != 0) {
			int tmp = a[i];
			if (tmp < 0) tmp = -tmp;
			if (gcd == 0) gcd = tmp;
			else gcd = __gcd(gcd, tmp);
		}
	}
	factor(gcd);
	for (int i = 1; i <= tot; i++)
		if (a[0] % prime[i] == 0) test(prime[i]);
	for (auto x : ans)
		writeln(x);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 200005
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    ll n=a.size(),m=b.size();
    ll ans=100000000000;
    for (int i = 0; i <= n-m; ++i)
    {
    	ll cnt=0;
    	for (int j = 0; j < m; ++j)
    	{
    		if(a[i+j]!=b[j])++cnt;
    	}
    	ans=min(ans,cnt);
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
		int b = scn.nextInt();
		if(a >8 || b>8) {
			System.out.println(":(");
		}else {
			System.out.println("Yay!");
		}
		scn.close();
	}
}

Measured memory_bytes: 23124
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	char x,y;
	int A,B,C,D,E,F;
	scanf(" %c %c",&x,&y);
	A=10;
	B=11;
	C=12;
	D=13;
	E=14;
	F=15;
	if(x<y)
		printf(" %c\n",'<');
	else if(x>y)
		printf(" %c\n",'>');
	else
	{
		printf(" %c\n",'=');
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define mod 998244353
int main() 
{
   
    // LL N;
    // cin>>N;
    // string S;
    // cin>>S;
    LL A,B,M;
    cin>>A>>B>>M;
    if (A% M == 0) 
        cout<<(B / M) - (A / M) + 1;
    else
    cout<<(B / M) - (A / M);
}


Measured memory_bytes: 3620
ary1 = []
n = gets.to_i
n.times do
    a = gets.split.map(&:to_s)
    ary1 << a
end

ary2 = []
["S","H","C","D"].each do |mark|
    (1..13).each do |i|
        arr = [mark, i.to_s]
        ary2 << arr
    end
end
ary3 = ary2 - ary1
ary3.each do |arr|
    puts arr[0] +" "+ arr[1]
end



Measured memory_bytes: 6860
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < S.length() - 2; ++i) {
			String tmp = S.substring(i, i + 3);
			if (Math.abs(Integer.parseInt(tmp) - 753) < min) min = Math.abs(Integer.parseInt(tmp) - 753);
		}
		System.out.print(min);
	}
}

Measured memory_bytes: 20948
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    ll n,m;
    std::cin >> n>>m;
    vector<vector<ll>> a(n,vector<ll>(m));
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            std::cin >> a[i][j];
            a[i][j]--;
        }
    }
    
    ll ans = 400;
    
    vector<ll> now(n,0);
    
    ll rem = m;
    
    vector<bool> doo(m,true);
    
    while(rem>0){
        map<ll,ll> ma;
        for (int j = 0; j < n; j++) {
            ma[ a[j][now[j]] ]++;
        }
        
        ll tmp_max=0;
        
        
        for (auto e : ma) {
            tmp_max = max(tmp_max, e.second);
        }
        
        ans = min(ans, tmp_max);
        
        for (auto e : ma) {
            if(e.second == tmp_max){
                rem--;
                doo[e.first]=false;
            }
        }
        
        for (int i = 0; i < n; i++) {
            while(!doo[ a[i][now[i]] ] ){
                now[i]++;
                if(now[i]==m)break;
            }
        }
    }
    
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

#print(l)
dic={}
for i in range(1,m+1):
  dic[i]=0
ans=0
for i in range(n):
  k=l[i][0]
  templ=l[i][1:k+1]
  for a in templ:
    dic[a]=dic[a]+1
for v in dic.values():
  if v==n:
    ans+=1
print(ans)

Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Integer[] array = new Integer[n];
    for(int i = 0; i < n; i++) {
    	array[i] = sc.nextInt();
    }
    
    //降順にソート
    Arrays.sort(array, Collections.reverseOrder());
    
    int a = 0; //アリス
    int b = 0; //ボブ
    for(int i = 1; i <= n; i++) {
    	if(i % 2 == 1) {
        	a += array[i-1];
        } else {
        	b += array[i-1];
        }
    }
    System.out.println(a-b);
  }
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  vector<ll> v(N);
  for(int i = 0; i < N; i++){
    cin >> v[i];
  }

  ll ans = 0;

  for(int i = 0; i < N-2; i++){
    for(int j = i+1; j < N-1; j++){
      for(int k = j+1; k < N; k++){
        ll a,b,c; 
        a = v[i];
        b = v[j];
        c = v[k];

        if(a == b || b == c || c == a){
          continue;
        }

        if(abs(a-b) < c && c < a+b){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3564
s = input()
q = int(input())

for qi in range(q):
    command = input().split()

    a = int(command[1])
    b = int(command[2])
    if command[0] == 'print':
        print(s[a:b + 1])
    elif command[0] == 'reverse':
        s = s[:a] + s[a:b + 1][::-1] + s[b + 1:]
    else:
        p = command[3]
        s = s[:a] + p + s[b + 1:]

Measured memory_bytes: 7680