akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

		if(S.equals("SSS")){
			System.out.println(0);
		}else if(S.equals("RSS") || S.equals("SRS") || S.equals("SSR") || S.equals("RSR")){
			System.out.println(1);
		}else if(S.equals("RRS") || S.equals("SRR")){
			System.out.println(2);
		}else if(S.equals("RRR")){
			System.out.println(3);
		}

	}
}

Measured memory_bytes: 35736
import sys
from collections import deque
input = sys.stdin.readline


def main():
    X = input().rstrip()

    stack = deque()
    for s in X:
        if s == "S":
            stack.append(s)
        else:
            if len(stack) == 0 or stack[-1] == "T":
                stack.append(s)
            else:
                stack.pop()
    ans = len(stack)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5088
S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
    c = int(S[i]) if S[i] != "?" else -1
    for j in range(10):
        if c == -1 or c == j:
            for ki in range(13):
                dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]
    for j in range(13):
        dp[i+1][j] %= MOD
ans = dp[N][5]
print(ans)

Measured memory_bytes: 95920
X = int(input())
A = [a ** 5 for a in range(200)]
for b in range(200):
    B = b ** 5
    if X + B in A:
        print(A.index(X + B), b)
        break
    if X - B in A:
        print(A.index(X - B), -b)
        break


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

void Main()
{
    int n;
    cin >> n;
    vint a(n);
    int max_val = -1;
    rep(i, n)
    {
        cin >> a[i];
        max_val = max(max_val, a[i]);
    }
    double h = max_val / 2.;

    a.erase(find(ALL(a), max_val));
    double min_diff = INF;
    int index = -1;
    rep(i, n - 1)
    {
        if (chmin(min_diff, abs(h - a[i])))
        {
            index = i;
        }
    }
    cout << max_val << " " << a[index] << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	vector<int> a;
	vector<int> b;
	rep(i,n){
		int x;
		cin >> x;
		if(x>=0) a.pb(x);
		else b.pb(-x);
	}
	reverse(b.begin(),b.end());
	int ans=1000000000,cnt=0,sum=0;
	rep(i,(int)b.size()){
		cnt=i+1;
		sum=b[i];
		if(cnt<k && a.size()>=k-cnt){
			sum+=b[i];
			sum+=a[k-cnt-1];
			cnt=k;
		}
		if(cnt==k) ans=min(ans,sum);
	}
	rep(i,(int)a.size()){
		cnt=i+1;
		sum=a[i];
		if(cnt<k && b.size()>=k-cnt){
			sum+=a[i];
			sum+=b[k-cnt-1];
			cnt=k;
		}
		if(cnt==k) ans=min(ans,sum);
	}
	cout << ans << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i=a; i<=b; ++i) {
        string tmp1 = to_string(i);
        string tmp2 = tmp1;
        reverse(tmp2.begin(), tmp2.end());
        if (tmp1 == tmp2) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(void) {
    map<char, int> chars;
    string input;

    getline(cin, input);

    for (int i = 0; i < input.size(); i++) {
        if (chars.find(input[i]) == chars.end()) {
            chars[input[i]] = 1;
        } else {
            chars[input[i]] += 1;
        }
    }

    bool beautiful = true;

    for (char c = 'a'; c <= 'z'; c++) {
        if (chars.find(c) == chars.end()) continue;
        if (chars[c] % 2 == 1) {
            beautiful = false;
            break;
        }
    }

    if (beautiful) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
X,N=list(map(int,input().split()))
if N>0:p=list(map(int,input().split()))
else:p=[]
memo=[False for i in range(105)]
for i in range(N):memo[p[i]]=True

riget,left=X+1,X-1
ans_r,ans_l=0,0

while(True):
    if memo[left]==False:
        ans_l=left
        break
    if memo[riget]==False:
        ans_r=riget
        break
    left-=1
    riget+=1

if N==0 or memo[X]==False:print(X)
elif abs(X-ans_r)>=abs(X-ans_l):print(ans_l)
else:print(ans_r)
    

Measured memory_bytes: 9224
import java.util.*;

public class Main {

  private static final long MOD = 1_000_000_007;

  public static void main(String[] args) throws Exception {
    int n = scanner.nextInt();
    int k = scanner.nextInt();
    long[] A = new long[n];
    for (int i = 0; i < n; i++) {
      A[i] = scanner.nextInt();
    }
    List<Long> pos = new ArrayList<>();
    List<Long> neg = new ArrayList<>();
    int zero = 0;
    for (long i : A) {
      if (i > 0) {
        pos.add(i);
      } else if (i < 0) {
        neg.add(i);
      } else {
        zero++;
      }
    }
    if (pos.size() + neg.size() < k || (n == k && zero > 0)) {
      System.out.println(0);
      return;
    }
    if (n == k) {
      long res = 1;
      for (long i : A) {
        res = mul(res, i);
      }
      System.out.println(Math.floorMod(res, MOD));
      return;
    }
    Arrays.sort(A);
    long res = 1;
    int j = A.length - 1;
    int i = 0;
    if (A[j] < 0 && k % 2 != 0) {
      for (; k > 0; k--, j--) {
        res = mul(res, A[j]);
      }
      System.out.println(Math.floorMod(res, MOD));
      return;
    }
    if (k % 2 != 0) {
      res = mul(res, A[j]);
      j--;
      k--;
    }
    for (; k > 0; k -= 2) {
      long lft = Math.multiplyExact(A[i], A[i + 1]);
      long rgt = Math.multiplyExact(A[j], A[j - 1]);
      if (lft > rgt) {
        res = mul(res, lft);
        i += 2;
      } else {
        res = mul(res, rgt);
        j -= 2;
      }
    }
    System.out.println(Math.floorMod(res, MOD));
  }

  private static long mul(long a, long b) {
    return (((a + MOD) % MOD) * ((b + MOD) % MOD)) % MOD;
  }

  private static final Scanner scanner = new Scanner(System.in);
}


Measured memory_bytes: 65912
//https://arc093.contest.atcoder.jp/tasks/arc093_c

#include<bits/stdc++.h>
const int N = 2005;
const int mod = 1e9 + 7;
#define int long long
using namespace std;

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

vector <iii> edge;

int po(int k){
    int x = 2, ans = 1;
    while (k){
        if (k&1) ans = 1LL * ans * x % mod;
        x = 1LL * x * x % mod;
        k >>= 1;
    }
    return ans;
}

int n, m;
long long x;

struct {
    int p[N], cnt, n;
    void init(int _n) {n = _n; for (int i = 1; i <= n; i++) p[i] = i; cnt = n;}
    int findset(int i) {return ((p[i] == i) ? i : p[i] = findset(p[i]));}
    bool dsu(int i, int j, bool x){
        i = findset(i); j = findset(j);
        if (i == j) return false;
        if (x) p[i] = j, cnt--;
        return true;
    }
} A, B;

int solve(int Max){
    B.init(m);
    for (int i = 0; i < m; i++){
        A.init(n);
        long long cost = edge[i].first;
        A.dsu(edge[i].second.first, edge[i].second.second, 1);
        for (int j = 0; j < m; j++) {
            if (A.dsu(edge[j].second.first, edge[j].second.second, 1)) {
                cost += edge[j].first;
            }
        }
        if (cost >= Max) continue;
        A.init(n);
        for (int j = 0; j < m; j++) {
            int x = edge[j].first, k = j;
            while (k < m && edge[k].first == x) {
                if (A.dsu(edge[k].second.first, edge[k].second.second, 0)) B.dsu(i+1, k+1, 1);
                k++;
            }
            while (j < m && edge[j].first == x) A.dsu(edge[j].second.first, edge[j].second.second, 1), j++; j--;
        }
    }
    return po(B.cnt);
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    cin >> x;
    for (int i = 1; i <= m; i++) {
        int u, v, c; cin >> u >> v >> c;
        edge.push_back(iii(c, ii(u, v)));
    }
    sort(edge.begin(), edge.end());
    solve(x);
    int ans = solve(x) - solve(x+1);
    if (ans < 0) ans += mod;
    cout << ans;
}


Measured memory_bytes: 512
n=int(input())
s=input()
t=list(input())

import re 


ans=s

k=-1
for i in range(n):
    tmp=''.join(t[:i+1])

    if tmp in ans:
        k=i

if k<n-1:
    ans+=''.join(t[k+1:])

print(len(ans))


Measured memory_bytes: 9904
# Input Values
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())

# The case when the last day of the month is "31st"
if M1 == 1 or M1 == 3 or M1 == 5 or M1 == 7 or M1 == 8 or M1 == 10 or M1 == 12:
	print(1 if D1 == 31 else 0)

# The case when the last day of the month is "30th"
if M1 == 4 or M1 == 6 or M1 == 9 or M1 == 11:
	print(1 if D1 == 30 else 0)

# The case when the last day of the month is "28th"
if M1 == 2:
	print(1 if D1 == 28 else 0)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	long total = 0, min, max;
	long num;
	cin >> num;
	total = num; min = num; max = num;
	for (int i = 1; i<n; i++){
		cin >> num;
		total += num;
		if (min>num)min = num;
		if (max<num)max = num;
	}
	cout << min << ' ' << max << ' ' << total << endl;
	return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
    int W, H, x, y, r; cin >> W >> H >> x >> y >> r;
    bool judge = true;
    if(x-r < 0 || x + r > W) judge = false;
    if(y -r < 0 || y + r > H) judge = false;
    
    if(judge) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3100
#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; cin>>N;
    int A[N];
    rep(i, N) cin>>A[i];

    map<int, int> v;
    rep(i, N){
        int a=i+1;
        if(a-A[i] > 0){
            v[a-A[i]]++;
        }
    }

    ll ans=0;
    rep(i, N){
        int b=i+1;
        ans+=v[b+A[i]];
    }

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

Measured memory_bytes: 14724
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#define int long long
#define uint unsigned long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

int INIT = 1000000000000000L; //10^5 * 10^9 * 10

int N;
int A[100000];
char op[100000];

int dp[100000][3];

int func(int n, int o) //括弧がo個開いている時、n番目以降を使ってつくれる最大の数
{
	if (dp[n][o] < INIT)
	{
		return dp[n][o];
	}

	int res;
	if (n == N - 1)
	{
		if (o % 2 == 0)
		{
			res = A[n];
		}
		else
		{
			res = -A[n];
		}
	}
	else
	{
		if (op[n + 1] == '+')
		{
			if (o == 0)
			{
				res = A[n] + func(n + 1, o);
			}
			else if (o == 1)
			{
				int d1 = -A[n] + func(n + 1, o);
				int d2 = -A[n] + func(n + 1, o - 1);
				res = MAX(d1, d2);
			}
			else if (o == 2)
			{
				int d1 = A[n] + func(n + 1, o);
				int d2 = A[n] + func(n + 1, o - 1);
				int d3 = A[n] + func(n + 1, o - 2);
				res = MAX(d1, MAX(d2, d3));
			}
		}
		else
		{
			if (o == 0)
			{
				res = A[n] + func(n + 1, o + 1);
			}
			else if (o == 1)
			{
				int d1 = -A[n] + func(n + 1, o + 1);
				int d2 = -A[n] + func(n + 1, o);
				res = MAX(d1, d2);
			}
			else if (o == 2)
			{
				int d1 = A[n] + func(n + 1, o);
				int d2 = A[n] + func(n + 1, o - 1);
				res = MAX(d1, d2);
			}
		}
	}

	dp[n][o] = res;
	return res;
}

signed main()
{
	cin >> N;
	op[0] = '+';
	for (int i = 0; i < N; i++)
	{
		if (i > 0)
		{
			cin >> op[i];
		}
		cin >> A[i];

		for (int j = 0; j < 3; j++) dp[i][j] = INIT;
	}
	for (int i = N - 1; i >= 0; i--)
	{
		for (int j = 0; j < 3; j++)
		{
			func(i, j);
		}
	}
	cout << func(0, 0) << endl;
}

Measured memory_bytes: 3456
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = -float('inf')
for i in range(n):
    s = []
    j = p[i]-1 
    s.append(c[j])
    while j != i:
        j = p[j]-1
        s.append(s[-1]+c[j])
    l = len(s)
    if k <= l:
        a = max(s[:k])
    elif s[-1] <= 0:
        a = max(s)
    else:
        w, r = divmod(k, l)
        a1 = s[-1]*(w-1) + max(s)
        a2 = s[-1]*w
        if r != 0:
            a2 += max(0, max(s[:r]))
        a = max(a1, a2)
    ans = max(ans, a)
print(ans)

Measured memory_bytes: 81228
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int a, b;
    cin >> a >> b;
    cout << max(0, a - b);

    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]

    """まずは縦に何連続かだけ計測"""
    dp = [[0] * W for _ in range(H)]
    # 0列目
    for j in range(W):
        if S[0][j] != '#':
            dp[0][j] = 1
    # dp-part
    for i in range(1, H):
        for j in range(W):
            if S[i][j] != '#':
                dp[i][j] = dp[i - 1][j] + 1
            else:
                num = dp[i - 1][j]
                for k in range(num):
                    dp[i - 1 - k][j] = num
    # last-line
    for j in range(W):
        num = dp[H - 1][j]
        for k in range(num):
            dp[H - 1 - k][j] = num
    
    """次に横に何連続かを計測"""

    dp2 = [[0] * W for _ in range(H)]
    # 0列目
    for i in range(H):
        if S[i][0] != '#':
            dp2[i][0] = 1
    # dp-part
    for j in range(1, W):
        for i in range(H):
            if S[i][j] != '#':
                dp2[i][j] = dp2[i][j - 1] + 1
            else:
                num = dp2[i][j - 1]
                for k in range(num):
                    dp2[i][j - 1 - k] = num
    # last-line
    for i in range(H):
        num = dp2[i][W - 1]
        for k in range(num):
            dp2[i][W - 1 - k] = num
    
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, dp[i][j] + dp2[i][j] - 1)
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 123612
#coding:utf-8

from fractions import gcd
n = int(input())
a = list(map(int, input().split(' ')))

mod = 10 ** 9 + 7

#最小公倍数を取得
g = a[0]
for num in a[1:]:
    g = g * num // gcd(num, g)

ans = 0
#計算後なのでmodオッケー
l = g % mod
for num in a:
    ans += l * pow(num, mod-2, mod)
    ans %= mod
print(ans % mod)

Measured memory_bytes: 6200
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(X) begin(X), end(X)
typedef pair<int, int> pii;
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
typedef pair<int, bool> edge;
vector<vector<pair<int, edge>>> G;
vector<int> lvl, E, cur;
queue<int> q;
stack<int> st;
vector<edge> ste;
inline int getC(edge p){ return p.ss?E[p.ff]-cur[p.ff]:cur[p.ff]; }
inline void modify(edge p, int c){ cur[p.ff] += (p.ss?1:-1)*c; }
int dfs(int i, int t, int mins = INT_MAX){
    if(mins == 0 || i == t)return mins;
    int acc = 0;
    for(auto j: G[i]){
        if(lvl[j.ff] != lvl[i] + 1)continue;
        int ans = dfs(j.ff, t, min(mins - acc, getC(j.ss)));
        modify(j.ss, ans);
        acc += ans;
    }
    return acc;
}

signed main(){
    int n, m, s, t;
    cin >> n >> m ;//>> s >> t;
    s = 0, t = n-1;
    G.resize(n+1);
    lvl.resize(n+1);
    E.resize(m);cur.resize(m);
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        G[a].pb({b, {i, true}});
        G[b].pb({a, {i, false}});
        E[i] = c;
    }
    int ans = 0;
    while(lvl[t] != -1){
        fill(all(lvl), -1);
        q.push(s);lvl[s] = 0;
        while (!q.empty()){
            int i = q.front();q.pop();
            for(auto j: G[i]){
                if(lvl[j.ff] != -1)continue;
                if(getC(j.ss) == 0)continue;
                lvl[j.ff] = lvl[i]+1;
                if(j.ff == t){
                    while(!q.empty())q.pop();
                    break;
                }
                q.push(j.ff);
            }
        }
        ans += dfs(s, t);
    }
    cout << ans << endl;
}
/*


     -> 1
0    -> 2
     -> 3


*/



Measured memory_bytes: 3176
_, k = map(int, raw_input().strip().split())
dictYes = {}
a = map(int, raw_input().strip().split())
for value in a:
    if value not in dictYes:
        dictYes[value] = 0
    dictYes[value] += 1
j = []
for value in dictYes:
    j.append((dictYes[value], value))
if len(j) <= k:
    print 0
else:
    j.sort()
    total = 0
    for val in j[:len(j)-k]:
        total += val[0]
    print total

Measured memory_bytes: 38544
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())


typedef int Weight;
struct Edge {
  int src;
  int dest;
  Weight weight;
  Edge(int src, int dest, Weight weight) : src(src), dest(dest), weight(weight) {;}
  bool operator<(const Edge &rhs) const {
    if (weight != rhs.weight) { return weight > rhs.weight; }
    if (src != rhs.src) { return src < rhs.src; }
    return dest < rhs.dest;
  }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void printMatrix(const Matrix &matrix) {
  for (int y = 0; y < (int)matrix.size(); y++) {
    for (int x = 0; x < (int)matrix[y].size(); x++) {
      printf("%d ", matrix[y][x]);
    }
    puts("");
  }
}

double check[110];
Array dist;

Weight Dijkstra(const Graph &g, int s, int t) {
  MEMSET(check, 0);
  const int n = g.size();
  vector<bool> visit(n, false);
  dist = Array(n, 1000000000LL);
  priority_queue<Edge> que;
  que.push(Edge(s, s, 0));
  Weight ans = -1;
  while (!que.empty()) {
    Edge edge = que.top();
    que.pop();
    int from = edge.dest;
    if (edge.weight == dist[from]) {
      check[from] += check[edge.src];
    }
    check[s] = 1;
    if (visit[from]) { continue; }
    visit[from] = true;
    dist[from] = edge.weight;
    for (int i = 0; i < (int)g[from].size(); i++) {
      int to = g[from][i].dest;
      Weight ncost = edge.weight + g[from][i].weight;
      if (ncost > dist[to]) { continue; }
      dist[to] = ncost;
      que.push(Edge(from, to, ncost));
    }
  }
  return ans;
}

double cnt[2][110];

int n, m, p;
int main() {
  while (scanf("%d %d %d", &n, &m, &p), n|m|p) {
    Graph g(n);
    REP(i, m) {
      int f, t, c;
      scanf("%d %d %d", &f, &t, &c);
      g[f].push_back(Edge(f, t, c));
      g[t].push_back(Edge(t, f, c));
    }
    priority_queue<Edge> que;
    Dijkstra(g, 0, n - 1);
    memcpy(cnt[0], check, sizeof(check));
    Array d1 = dist;
    Dijkstra(g, n - 1, 0);
    memcpy(cnt[1], check, sizeof(check));
    Array d2 = dist;
    REP(i, p) {
      int index;
      scanf("%d", &index);
      double q = cnt[0][index] * cnt[1][index] / cnt[0][n - 1];
      if (d1[index] + d2[index] != d1[n - 1]) {
        q = 0.0;
      }
      printf("%.8lf\n", q);
      assert(0.0 <= q && q <= 1.0);
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
/**
 * Author RDP
 * 
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#define endl '\n'
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0);
typedef long long ll;
using namespace std;

void test_case()
{
    FAST_IO
    double r;
    cin >> r;
    cout <<6.28318530717958623200 * r <<endl;
    return ;
}
int main()
{
    FAST_IO
    test_case();
    return 0;
}

Measured memory_bytes: 3776
<?php
$A = strtoupper(trim(fgets(STDIN)));
$B = strtoupper(trim(fgets(STDIN)));
$C = strtoupper(trim(fgets(STDIN)));

$data = [
    'A' => str_split($A),
    'B' => str_split($B),
    'C' => str_split($C),
];

$turn = 'A';

while(true) {
    if (empty($data[$turn])) {
        break;
    }
    $turn = array_shift($data[$turn]);
}

echo "$turn\n";

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    priority_queue<ll> q;
    vector<pair<ll, ll> > works;
    ll N, M;
    ll A, B;
    cin>>N>>M;
    rep(i, N){
        cin>>A>>B;
        if(M>=A) works.push_back({A, B});
    }
    sort(all(works));
    ll index=0;
    ll count=0;
    rep1(i, M){
        //cout<<"#"<<i<<endl;
        //cout<<index<<endl;
        while(true){
            //cout<<works[index].second<<"$"<<endl;
            if(index>=works.size()) break;
            if(i!=works[index].first) break;
            q.push(works[index].second);
            index++;
        }
        //cout<<"And we will come back home, home again ..."<<endl;
        if(q.size()!=0){
            count+=q.top();
            //cout<<count<<endl;
            q.pop();
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 4080
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;


fn main() {
    input! {
    a:usize,
    b:usize,
    mut c:[usize;a],
    }
    c.sort();
    c.reverse();
    let mut d=0;
    for i in 0..b {
        d+=c[i]
    }
    println!("{}",d)
}

Measured memory_bytes: 2188
# coding:utf-8
n, m = map(int, input().split())
shop = [list(map(int, input().split())) for _ in range(n)]

shop_s = sorted(shop, key=lambda x: x[0])
price = 0
drink = 0

for i in range(n):
    m -= shop_s[i][1]
    if m < 0:
        drink = shop_s[i][1] + m
        price += shop_s[i][0] * drink
        break
    else:
        drink = shop_s[i][1]
        price += shop_s[i][0] * drink

print(price)


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

using namespace std;
using ll = long long;

const int INF = 1e9;

#define REP(i, n) for (int i = 0; i < (n); i++)

vector<bool> matching(string x, string y) {
    int nx = x.size();
    int ny = y.size();

    vector<bool> res(6010, true);

    REP(st, nx) {
        for (int i = 0; st + i < nx && i < ny; i++) {
            if (x[st + i] == '?') continue;
            if (y[i] == '?') continue;
            if (x[st + i] != y[i]) res[st] = false;
        }
    }

    return res;
}

int solve(string A, string B, string C) {
    int na = A.size();
    int nb = B.size();
    int nc = C.size();

    auto ab = matching(A, B);
    auto bc = matching(B, C);
    auto ac = matching(A, C);

    int ans = INF;
    REP(a, na + 1) {
        REP (b, max(na, nb) + 1) {
            if (ab[a] && bc[b] && ac[a + b]) {
                if (ans > max({na, a + nb, a + b + nc})) {
                    ans = max({na, a + nb, a + b + nc});
                }
            }
        }
    }
    return ans;
}


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

    vector<string> v;
    REP(i, 3) {
        string s; cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end());

    int ans = INF;

    do {
        if (ans > solve(v[0], v[1], v[2])) {
            ans = solve(v[0], v[1], v[2]);
        }
    } while (next_permutation(v.begin(), v.end()));

    cout << ans << endl;

    return 0;
}

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

int main(){
    int64_t N;
    cin >> N;
    vector<int64_t> A(N),B(N,0);
    
    for(int i=1;i<N;i++){
        cin >> A.at(i);
        B.at(A.at(i)-1)++;
    }
    for(int i=0;i<N;i++){
        cout << B.at(i) << endl;
    }

    
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll h, w, a;
  in2(h, w);
  vector<vector<ll>> c(h, vector<ll>(w));
  vector<ll> s, t, u, v;
  rep(i, h){
    rep(j, w)
      in(c[i][j]);
  }
  rep(i, h){
    rep(j, w - 1){
      if(c[i][j] % 2 == 0){
        continue;
      }
      else{
        c[i][j + 1]++;
        s.pb(i + 1);
        t.pb(j + 1);
        u.pb(i + 1);
        v.pb(j + 2);
      }
    }
  }
  rep(i, h - 1){
    if(c[i][w - 1] % 2 == 1){
      c[i + 1][w - 1]++;
      s.pb(i + 1);
      t.pb(w);
      u.pb(i + 2);
      v.pb(w);
    }
  }
  out(s.size());
  memi;
  rep(i, s.size()){
    out(s[i]);
    hina;
    out(t[i]);
    hina;
    out(u[i]);
    hina;
    out(v[i]);
    memi;
  }
}

Measured memory_bytes: 9944
import bisect
n,m = map(int,input().split())

al = list(map(int,input().split()))
al = sorted(al)


cbl = []
for _ in range(m):
    b,c = map(int,input().split())
    cbl.append((c,b))

sumal = [0]
suma = 0
for a in al:
    suma += a
    sumal.append(suma)
    
cbl = sorted(cbl, reverse=True)

topn = [0 for i in range(n)]
pos = 0
for c,b in cbl:
    for _ in range(b):
        topn[pos] = c
        pos += 1
        if pos == n:
            break
    else:
        continue
    break

sumtopn = [0]
sumtop = 0
for t in topn:
    sumtop += t
    sumtopn.append(sumtop)
ans = 0
for i in range(n+1):
    left = sumal[-1] - sumal[i]
    right = sumtopn[i]
    tmp = left + right
    if tmp > ans:
        ans = tmp
        
print(ans)
    

Measured memory_bytes: 81560
def main():
    c = [list(map(int, input().split(' '))) for _ in range(3)]
    for i in range(3):
        next_i = (i + 1) % 3
        d = [c[i][j] - c[next_i][j] for j in range(3)]
        if len(set(d)) > 1:
            print('No')
            return
    for j in range(3):
        next_j = (j + 1) % 3
        d = [c[i][j] - c[i][next_j] for i in range(3)]
        if len(set(d)) > 1:
            print('No')
            return
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

struct UnionFind {
  vector<int> p;
  UnionFind(int n){
    p.resize(n, -1);
  }


  int find(int x) { //再起関数で親の添え字を返す
    if(p[x] < 0) return x;
      else return p[x] = find(p[x]);
  }
  
  void unite(int x, int y) { //くっつける
    x = find(x);
    y = find(y); //それぞれの親の添え字を召喚
    if(-p[x] > -p[y]) { //サイズが大きいほうにくっつける
      p[x] += p[y];
      p[y] = x;
    } else {
      p[y] += p[x];
      p[x] = y;
    }
  }
  
  int size(int x) {
    x = find(x);
    return -p[x];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    if(uf.find(x) != uf.find(y)) uf.unite(x, y);
  }
  int mx = 0;
  rep(i, 0, n) {
    int a = uf.size(i);
    if(mx < a) mx = a;
  }
  cout << mx << "\n";
    /*rep(i, q) {
        cin >> com >> x >> y;
        if(com == 0) { //x,yをくっつける unite
            if(uf.find(x) != uf.find(y)) uf.unite(x, y);
        } else { //x,yの親が同じか判定する same
            if(uf.find(x) == uf.find(y)) cout << "Yes" << "\n";
            else cout << "No" << "\n";
        }
    }*/
}

Measured memory_bytes: 4048
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return(b);
    }
    else {
        return(gcd(b, a % b));
    }
}

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

int main(void) {
    int n;
    cin >> n;
    cout << 1 - n;

}



Measured memory_bytes: 3620
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

#include <vector>
#include <algorithm>

#define MOD 2019

using namespace std;

int main()
{
    long long L, R;
    cin >> L >> R;
    
    long long ans = 2200;
    for(long long i = L; i < min(R, L+3000); i++){
        for(long long j = i+1; j <= min(R, L+3000); j++){
            ans = min(ans, (i*j) % MOD);
        }
    }
    
    cout << ans << endl;
     
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
import itertools
import sys
input = sys.stdin.readline


def main():
    N = input()[:-1]

    cnt = 0
    for i in range(1, len(N)+1):
        for C in itertools.product(['7','5','3'], repeat=i):
            if ('7' not in C) or ('5' not in C) or ('3' not in C):
                continue
            M = ''.join(C)
            if int(M)<=int(N):
                cnt += 1
    
    print(cnt)
        


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define elif else if
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int N,M,O,P=0,count=0,count2=0,crash=0,nowtab=1;
  double d;
  char C,c;
  str S,T;
  vint v(0);
  cin>>S>>T;
  cout<<T+S<<endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/
vii dp;

/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    string s,t,ans; cin >> s >> t;
    dp.resize(3001, vi(3001, 0));
    int ssiz = s.size();
    int tsiz = t.size();

    for(int i = 0; i < ssiz; ++i) {
        for(int j = 0; j < tsiz; ++j) {
            if(s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    while(ssiz > 0 && tsiz > 0) {
        // ここのif文の順序は大事
        if(dp[ssiz][tsiz] == dp[ssiz][tsiz-1]) {
            --tsiz;
        }
        else if(dp[ssiz][tsiz] == dp[ssiz-1][tsiz]) {
            --ssiz;
        }
        else if(dp[ssiz][tsiz] == dp[ssiz-1][tsiz-1] + 1) {
            ans = s[ssiz-1] + ans;
            --ssiz; --tsiz;
        }
    }
    cout << ans << '\n';
}

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

int main() {
	string s;
	cin >> s;

	int a = 0; int b = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'A') a += 1;
		else b += 1;
	}
	if (a * b) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

int main() {
    int A,B,K;
    cin >> A >> B >> K;
    vector<int> retu(101);

    for(int i = 1;i<101;i++){
        if(A%i == 0){
            if(B%i == 0){
                retu.at(i) = i;
            }
        }
    }
    sort(retu.begin(),retu.end());
    reverse(retu.begin(),retu.end());
    cout << retu.at(K-1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

typedef unsigned int u_int;

int main(void){
  u_int i,j,k,l,c=0;
  char str[16];
  fgets(str,sizeof(str)/sizeof(str[0]),stdin);
  l=strlen(str);
  str[l-1]='\0';
  l--;
  for(i=0;i<l/2;i++){
    if(str[i]=='(' && str[l-i-1]==')' ) continue;
    if(str[i]==')' && str[l-i-1]=='(' ) continue;
    if(str[i]=='i' && str[l-i-1]=='i' ) continue;
    if(str[i]=='w' && str[l-i-1]=='w' ) continue;
    c++;
  }
  if(l%2!=0)  if(str[(l-1)/2]!='i' && str[(l-1)/2]!='w') c++;
  printf("%u\n",c);
  return 0;
}

Measured memory_bytes: 0
import queue

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
H, W = map(int, input().split())
field = [input() for _ in range(H)]

dist = [[-1] * W for _ in range(H)]
que = queue.Queue()
que.put((0, 0))
dist[0][0] = 0

while not que.empty():
  y, x = que.get()
  for i in range(4):
    ny, nx = y + dy[i], x + dx[i]
    if nx < 0 or nx >= W or ny < 0 or ny >= H:
      continue
    if field[ny][nx] == '#':
      continue
    if dist[ny][nx] != -1:
      continue
    dist[ny][nx] = dist[y][x] + 1
    que.put((ny, nx))
    
count = sum([f.count('#') for f in field])
      
if dist[H - 1][W - 1] != -1:
  print(H * W - count - dist[H - 1][W - 1] - 1)
else:
  print(-1)


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
const int maxn=200005;
ll n,k,a[maxn];
int main()
{
    //IOS;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=k+1;i<=n;i++)
    {
        if(a[i-k]<a[i])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}
/*

*/


Measured memory_bytes: 5180
#include<stdio.h>
#include<algorithm>
int main() {
	int W,H,x,y,r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if (x-r < 0 || y-r < 0 || W < r + x || H < r + y)
		puts("No");
	else
		puts("Yes");
	return 0;
}

Measured memory_bytes: 2688
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int absx = Math.abs(x);
        int absy = Math.abs(y);
        if(absx > absy){
            if(x > 0 && y>0){
                System.out.println(absx-absy+2);
            }else if (x > 0){
                System.out.println(absx-absy+1);
            }else if(x < 0 && y>0){
                System.out.println(absx-absy+1);
            }else if(x < 0){
                System.out.println(absx-absy);
            }

        }else if(absx < absy){
            if(y > 0 && x>=0){
                System.out.println(absy-absx);
            }else if (y > 0){
                System.out.println(absy-absx+1);
            }else if(y < 0 && x >= 0 ){
                System.out.println(absy-absx+1);
            }else if(y < 0){
                System.out.println(absy-absx+2);
            }
        }else {
            if(x!=y){
                System.out.println(1);
            }else{
                System.out.println(0);
            }
        }
    }
}


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

int push(int& a, int& b) {
  int ans = 0;
  if(a > b) {
    ans = a;
    a--;
  } else {
    ans = b;
    b--;
  }
  return ans;
}
int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  ans += push(A, B);
  ans += push(A, B);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String aeg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int sum=0;
			for(int i=0; i<(n*(n-1))/2;i++)
				sum+=in.nextInt();
			System.out.println(sum/(n-1));
		}
	}
}

Measured memory_bytes: 12000
from queue import Queue

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break

    tile = [input() for i in range(h)]
    for x, col in enumerate(tile):
        if '@' in col:
            y = col.index('@')
            s = (x, y)
            break

    visit = [[False for i in range(w)] for j in range(h)]
    dx = (0, -1, 1, 0)
    dy = (1, 0, 0, -1)
    que = Queue()
    que.put(s)
    while not que.empty():
        x, y = que.get()
        if visit[x][y]:
            continue

        visit[x][y] = True
        for j in range(4):
            sx = x + dx[j]
            sy = y + dy[j]
            if sx < 0 or sx >= h or sy < 0 or sy >= w:
                continue
            if tile[sx][sy] != '#':
                que.put((sx, sy))

    ans = 0
    for col in visit:
        ans += col.count(True)

    print(ans)


Measured memory_bytes: 6852
#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;
int n;
int times[18][18];
int dp[1<<18][18];
int dfs(int bit, int now)
{
    if(__builtin_popcount(bit) == n) return 0;
    if(dp[bit][now]) return dp[bit][now];
    int res = INF;
    for(int v = 1; v <= n; v++)
    {
        if(bit & (1<<v)) continue;
        int num = times[v][0];
        for(int i = 1; i <= n; i++)
        {
            if(not (bit & (1<<i))) continue;
            num = min(num, times[v][i]);
        }
        res = min(res, dfs(bit | (1<<v), v) + num);
    }
    return dp[bit][now] = res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n, n)
    {
        memset(dp, 0, sizeof(dp));
        for(int i = 1; i <= n; i++)
        {
            for(int j = 0; j <= n; j++) cin >> times[i][j];
        }
        cout << dfs(0, 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 21572
#include <iostream>
using namespace std;
using llong = long long;

llong sum = 1 ^ 2 ^ 3 ^ 4 ^ 5;
llong a;

int main() {
    for (int i = 0; i < 5; i++) {
        cin >> a;
        sum ^= a;
    }

    cout << sum << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
ll n, q;
ll a[100005];
vector< ll > v;
ll s[100005];
ll es[100005];
// fuck this problem man for real tho!
bool ok(ll x, ll len, ll rgt, ll bd)
{
        if(len > ((n+1)/2)) return false;
        if(len <= ((rgt+1)/2) ) return true;
        if(len > rgt) return false;
        ll nxt = n-1-len+1;
        ll remm = len - (rgt-len);
        bd -= remm;
        //bd = n-1-len-len;
        //if(bd == -2 && (n%2 == 1) && (len == ((n+1)/2))) return true;
        if(bd < -1) return false;
        //if(remm >= 2){
        if(abs(x - v[bd+2]) <= abs(v[nxt] - x)) return true;
        return false;
        /*}else {
                ll bdo = bd + remm;
                ll tk = len - remm;
                ll xx = bdo + tk;
                //if(remm==0) xx--;
                if(x - v[bdo] <= v[xx] - x) return false;
                return true;
        }*/
}
ll solve(ll x)
{
        if(n==1) return x;
        if(x >= v.back()) {

                ll tot = s[n-1];
                ll ret=0;
                if(n%2 == 0) {
                        ret = es[n-2];
                        return tot - ret;
                }else {
                        return es[n-1];
                }
                return 0;
        }else if(x < v[0]) {
                ll A = n/2;
                return s[n-1] - s[A-1];
        }
        if(abs(v[n/2] - x) >= abs(x - v[0])) {
                return s[n-1] - s[(n/2) - 1];
        }
        auto it = upper_bound(v.begin() , v.end(), x) - v.begin();
        ll bd = it-1;
        ll rgt = n - 1 - bd;
        //if(rgt==1)
        /*if((rgt+1)/2 >= (n+1)/2) {
                return s[n-1] - s[(n/2) - 1];
        }*/
        ll lo = (rgt+1)/2;
        lo=1;
        ll hi = rgt;
        //hi=min(hi , (n+1)/2 + 1);
        while(hi > lo) {
                ll mid = lo + (hi - lo + 1)/2;
        //cout << mid << endl;
                if(ok(x,mid,rgt, bd)) lo=mid;
                else hi = mid-1;
                //cout << lo << " **** " << hi << endl;

        }
        //cout << "**** " << ok(x,hi,rgt,bd) << endl;
        //while(ok(x,hi+1,rgt,bd)==true) hi++;
        //while(ok(x,hi,rgt,bd)==false) hi--;
        //cout << bd << " " << hi << endl;
        ll ret = s[n-1] - s[n-1-hi];
        ll rem = hi - rgt + hi;
        bd = bd - rem;
        ll N = bd+1;
        if(N%2 == 0) {
                ret += (s[bd] - es[bd-1]);
        }else {
                ret += es[bd];
        }
        return ret;
}
int main()
{
        cin >> n >> q;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
                v.pb(a[i]);
                s[i-1] = a[i];
                if(i-1 > 0) s[i-1] += s[i-2];
        }
        es[0]=v[0];
        for(ll i=2;i<n;i += 2) es[i] = v[i] + es[i-2];
        while(q--) {

                ll x;
                cin >> x;
                cout << solve(x) << "\n";
        }
        return 0;
}


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

int main() {
  int n;
  cin>>n;
  long long mod = 1e9 + 7;
  long long ans = 1;
  for (int i=2; i<=n; i++) {
    ans *= i;
    ans %= mod;
  }
  cout<<ans<<endl;
}

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

const int N=510;
int a[N*N],X[N],n;
int c[N],cnt[N];
int pos[N][N],num[N];

bool check()
{
    for(int i=1;i<=n*n;i++)
        pos[a[i]][++num[a[i]]]=i;
    for(int i=1;i<=n;i++)
        if(pos[i][i]!=X[i]) return 0;
    return 1;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",X+i);
    for(int i=1;i<=n;i++) c[i]=i,a[X[i]]=i;
    sort(c+1,c+1+n,[](int x,int y){return X[x]<X[y];});
    for(int i=1;i<=n;i++) cnt[i]=i-1;
    for(int i=1;i<=n*n;i++)
    {
        if(a[i]) continue;
        for(int j=1;j<=n;j++)
            if(cnt[c[j]]){a[i]=c[j];cnt[c[j]]--;break;}
    }
    for(int i=1;i<=n;i++) cnt[i]=n-i;
    for(int i=n*n;i>=1;i--)
    {
        if(a[i]) continue;
        for(int j=n;j>=1;j--)
            if(cnt[c[j]]){a[i]=c[j];cnt[c[j]]--;break;}
    }
    if(check())
    {
        puts("Yes");
        for(int i=1;i<=n*n;i++)
            printf("%d ",a[i]);
    }
    else puts("No");
    return 0;
}

Measured memory_bytes: 3200