akhauriyash/Code-Regression huggingface dataset:
//============================================================================
// 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

//============================================================================
struct Schdule{
    char name[20];
    long quantam;
    struct Schdule *list;
};
typedef struct Schdule TSchdule;
//============================================================================
TSchdule *top,*btm;
int Quantam;
//============================================================================
void dump(int *A, int N)
{
    int i;

    for (i=0; i<N; i++){
        if (i)
            printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}
//============================================================================
void cdump(char *str)
{
    int i;

    printf("%d:", strlen(str));;
    for (i=0; i<strlen(str); i++){
        if (i)
            printf(" ");
        printf("%02X", (unsigned char)str[i]);
    }
    printf("\n");
}
//============================================================================
int remain(TSchdule *sch, int n)
{
    long i;

    for (i=0; i<n; i++)
        if (sch[i].quantam)
            return 1;
    //printf("r%ld\n", r);
    return 0;
}
//============================================================================
int Spend(long width, long req)
{
    if (req<width)
        return req;
    return width;
}
//============================================================================
void enqueue(TSchdule *sch)
{
    if (top==NULL){
        top=sch;
        btm=sch;
    }else{
       btm->list=sch;
       btm=sch;
    }
    btm->list=NULL;
}
//============================================================================
TSchdule *dequeue()
{
    TSchdule *sch;

    if (top==NULL)
        return NULL;
    sch=top;
    top=top->list;
    return sch;
}
//============================================================================
void process()
{
    long i,tm; int spend; TSchdule *sch;

    tm=0;
    while(sch=dequeue()){
        spend=Spend(Quantam, sch->quantam);
        sch->quantam-=spend;
        tm+=spend;
        //printf("%ld tm:%ld, sp:%d, ", i, tm, spend);
        if (!sch->quantam)
            printf("%s %ld\n", sch->name, tm);
        else
            enqueue(sch);
    }
}
//============================================================================
void input()
{
    long i,n; TSchdule *sch;

    scanf("%ld", &n);
    scanf("%d%*c", &Quantam);
    //printf("n=%ld, Quantam=%d\n", n, Quantam);
    sch=malloc(n*sizeof(TSchdule));
    top=btm=NULL;
    for (i=0; i<n; i++){
        //scanf("%*s");
        scanf("%s", sch[i].name);
        scanf("%ld%*c", &sch[i].quantam);
        //sch[i].order=i;
        enqueue(&sch[i]);
    }
    //for (i=0; i<n; i++)
    //    printf("%s %ld\n", sch[i].name, sch[i].quantam);
    process();
    free(sch);
}
//============================================================================
int main(void)
{
    input();
    return 0;
}
//============================================================================

Measured memory_bytes: 2472
def main():
    K = int(input())
    A, B = map(int, input().split())
    N = B-A
    frag = 0
    for cycle in range(0,N+1) :
        value = A + cycle
        if value % K == 0 :
            print("OK")
            frag = 1
            break
    if frag == 0 :
        print("NG")

if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final int N;
    private final int M;
    private final boolean[] from1;
    private final boolean[] toN;

    public Main() {
	N = Integer.parseInt(scan.next());
	M = Integer.parseInt(scan.next());
	from1 = new boolean[N];
	toN = new boolean[N];
	for (int i = 0; i < M; i++) {
	    int a = Integer.parseInt(scan.next()) - 1;
	    int b = Integer.parseInt(scan.next()) - 1;
	    if(a == 0) from1[b] = true;
	    if(b == N-1) toN[a] = true;
	}

	scan.close();
    }

    public final void answer() {
	boolean ans = false;
	for (int i = 0; i < N; i++) {
	    if(from1[i] && toN[i]) {
		ans = true;
		break;
	    }
	}
	System.out.println(ans ? "POSSIBLE" : "IMPOSSIBLE");
    }
}


Measured memory_bytes: 64600
#include<bits/stdc++.h>
using namespace std;
long long dp[110][100010];
int n,k;
int a[101];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=0;i<=n;i++)
		dp[i][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=a[i];j++)
			dp[i][j]=(dp[i][j-1]+dp[i-1][j])%1000000007;
		for(int j=a[i]+1;j<=k;j++)
			dp[i][j]=(dp[i][j-1]+1000000007+dp[i-1][j]-dp[i-1][j-a[i]-1])%1000000007;
	}
	cout<<dp[n][k];
	return 0;
}

Measured memory_bytes: 79360
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int s = scn.nextInt();
		int w = scn.nextInt();
      	String ans="safe";
      	if(w>=s) ans="unsafe";
      	System.out.println(ans);
	}
}

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

using namespace std;

typedef long long ll;

const int MAXN = 2e5+7;
const int Inf = 0x3f3f3f3f;

int pre1[MAXN],pre2[MAXN];

int finds(int x,int *pre)
{
    return pre[x] == x? pre[x]:pre[x] = finds(pre[x],pre);
}

void join(int x,int y,int *pre)
{
    int px = finds(x,pre);
    int py = finds(y,pre);
    if( px!=py)
    {
        pre[px] = py;
    }
}
int main()
{
    int n,k,l;
    cin>>n>>k>>l;
    for(int i = 1;i<=n;i++)
        pre1[i] = i,pre2[i] = i;
    for(int i = 1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        join(x,y,pre1);
    }
    for(int i = 1;i<=l;i++)
    {
        int x,y;
        cin>>x>>y;
        join(x,y,pre2);
    }
    for(int i = 1;i<=n;i++)
    {
        finds(i,pre1);
        finds(i,pre2);
    }
    map<pair<int,int>,int> mp;
    for(int i = 1;i<=n;i++)
    {
        //cout<<pre1[i]<<" | "<<pre2[i]<<endl;
        mp[make_pair(pre1[i],pre2[i])] ++;
    }
    for(int i = 1;i<=n;i++)
    {
        cout<<mp[make_pair(pre1[i],pre2[i])]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll a, b, c; cin >> a >> b >> c;
    if(a == b) cout << c << endl;
    if(b == c) cout << a << endl;
    if(c == a) cout << b << endl;
}

Measured memory_bytes: 256
import itertools
N = int(input())
a = list(map(int,input().split()))
a2 = itertools.accumulate(a)
b = [0]
b += list(a2)
s = 0
for i in range(N):
    s += (a[i] * (b[-1] - b[i+1]))
print(s % (10**9+7))

Measured memory_bytes: 31124
#include<stdio.h>
int main(void){
	int a[4][3][10]={},n=0,b=0,f=0,r=0,v=0;
	scanf("%d",&n);
	while(n--){
		scanf("%d%d%d%d",&b,&f,&r,&v);
		a[b-1][f-1][r-1]+=v;
		}
	for(int i=0;i<4;i++){
		if(i>0){
			printf("####################\n");
		}
		for(int i2=0;i2<3;i2++){
			for(int i3=0;i3<10;i3++){
				printf(" %d",a[i][i2][i3]);
			}
			puts("");
		}
	}

	return 0;
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
  int n;
  int sum = 0;
  cin >> n;
  vector<int> s(n);
  rep(i,n){
    int temp;
    cin >> temp;
    s[i] = temp;
    sum += temp;
  }
  if(sum % 10 != 0){
    cout << sum << endl;
  }else{
    int ans = 0;
    rep(i,n){
      if((sum - s[i]) % 10 != 0) ans = (ans < sum-s[i]) ? sum-s[i] : ans;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    char a[10];
    while(cin>>a[0]){
        for(int i=1;i<10;i++)
            cin>>a[i];
        for(int i=0;i<10;i++){
            for(int j=0;j<9-i;j++)
                a[j]=((a[j]-'0')+(a[j+1]-'0'))%10+'0';
        }
        cout<<a[0]<<endl;
    }
}

Measured memory_bytes: 1132
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	s := sc.ReadString()

	if n < 3 {
		fmt.Println(0)
		return
	}

	rgbCounts := make([]rgbNums, n)
	var rgbSize rgbNums
	{
		rgb := rgbNums{}
		for i := range rgbCounts {
			c := s[i]
			if c == 'R' {
				rgb.r++
			} else if c == 'G' {
				rgb.g++
			} else {
				rgb.b++
			}
			rgbCounts[i] = rgb
		}
		rgbSize = rgb
	}

	cnt := int64(0)
	for i := 0; i < n-2; i++ {
		ci := s[i]
		for j := i + 1; j < n-1; j++ {
			cj := s[j]
			if cj == ci {
				continue
			}

			if ci == 'R' && cj == 'G' || ci == 'G' && cj == 'R' {
				cnt += int64(rgbSize.b - rgbCounts[j].b)
			}
			if ci == 'G' && cj == 'B' || ci == 'B' && cj == 'G' {
				cnt += int64(rgbSize.r - rgbCounts[j].r)
			}
			if ci == 'B' && cj == 'R' || ci == 'R' && cj == 'B' {
				cnt += int64(rgbSize.g - rgbCounts[j].g)
			}
		}
	}

	for i := 0; i <= n-3; i++ {
		ci := s[i]
		jMax := i + 1 + (n-i-3)/2
		for j := i + 1; j <= jMax; j++ {
			cj := s[j]
			if cj == ci {
				continue
			}
			k := 2*j - i
			ck := s[k]
			if ck != ci && ck != cj {
				cnt--
			}
		}
	}

	fmt.Println(cnt)
}

type rgbNums struct {
	r int
	g int
	b int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Abs64(x int64) int64 {
	if x >= 0 {
		return x
	}
	return -x
}

func Min64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow64(base int64, exponent uint) int64 {
	answer := int64(1)
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *Scanner) ReadInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


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


int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n)
    cin >> a[i];
  int mx = -1, sec = -1;
  rep(i, n)
  {
    sec = max(sec, a[i]);
    if (mx < sec)
      swap(mx, sec);
  }
  rep(i, n)
    if (mx == a[i])
      printf("%d\n", sec);
    else
      printf("%d\n", mx);
  return 0;
}

Measured memory_bytes: 2432
nums = input()
Hp_Taka = int(nums.split(' ')[0])
Atk_Taka = int(nums.split(' ')[1])
Hp_Aoki = int(nums.split(' ')[2])
Atk_Aoki = int(nums.split(' ')[3])

while Hp_Taka > 0 and Hp_Aoki > 0:
	Hp_Aoki = Hp_Aoki - Atk_Taka
	if Hp_Aoki > 0:
		Hp_Taka = Hp_Taka - Atk_Aoki
if Hp_Taka > 0:
	print('Yes')
else:
	print('No')

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

int main(){
	int n;
	cin>>n;
	int ans=0;
	while(n>ans*2){
		ans++;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); //cinの高速化

  int N;
  IN(N);
  vector<int> A(N);
  REP(i, N) IN(A[i+1]);
  A[0] = A[1];
  
  REP(i,N-1) if(MAX(A[i],A[i+1]) != A[i+1]) A[i] = A[i+1];
  int ans=0;
  REP(i,N){
    ans += A[i];
  }
  OUT(ans);
}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	int counter = 700;
	if (s[0] == 'o') counter = counter + 100;
	if (s[1] == 'o') counter = counter + 100;
	if (s[2] == 'o') counter = counter + 100;
	cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<int> g[2019];
int c, e;

int dfs(int x, int p, int d) {
    c++;
    int f = 0;
    for (int i : g[x]) if (i != p) {
        int b = 0;
        if (d) b = dfs(i, x, d - 1), f += b;
        else b = 1, f++;
        if (x == p) e = max(e, b);
    }
    return f;
}

int main() {
    ios::sync_with_stdio(false);
    int n, k, u, v, z = 0;
    cin >> n >> k;
    for (int i = 1; i < n; i++) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    for (int i = 1; i <= n; i++) c = e = 0, dfs(i, i, k / 2), z = max(z, c + ((k % 2) ? e : 0));
    cout << n - z;
}


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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

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

	auto D=in();
	auto C=vecin(26);
	vvll S(D,vll(26));
	REP(i,D){
		REP(j,26) S[i][j]=in();
	}
	vll L(26,0);
	vll H;

	ll A=0;
	REP(i,D){
		ll d=i+1;
		ll maxB=-(1ll<<60),index=-1;
		REP(t,26){
			ll B=0;
			B += S[i][t];
			L[t] = d;
			REP(j,26){
				if(t!=j){
					B -= C[j]*(d-L[j]);
				}
			}
			if(B>maxB){
				maxB = B;
				index=t;
			}
		}
		A+=maxB;
		H.push_back(index+1);
		//out(A);
	}

	for(auto& x:H) out(x);
	return 0;
}


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


int main()
{
        int n;
        cin>>n;
        double a[n];
        for(int i=0;i<n;i++)
        {
                cin>>a[i];
        }
        sort(a,a+n);
        //reverse(a,a+n);
        double sum=a[0];
        for(int i=1;i<n;i++)
        {
                sum=(sum+a[i])/2;
        }
        cout<<sum<<endl;
}

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

using namespace std;

struct ALF {
    string  s;
    int     cnt;
}
alfa[26]
{
    { "a", 0 },
    { "b", 0 },
    { "c", 0 },
    { "d", 0 },
    { "e", 0 },
    { "f", 0 },
    { "g", 0 },
    { "h", 0 },
    { "i", 0 },
    { "j", 0 },
    { "k", 0 },
    { "l", 0 },
    { "m", 0 },
    { "n", 0 },
    { "o", 0 },
    { "p", 0 },
    { "q", 0 },
    { "r", 0 },
    { "s", 0 },
    { "t", 0 },
    { "u", 0 },
    { "v", 0 },
    { "w", 0 },
    { "x", 0 },
    { "y", 0 },
    { "z", 0 },
};

int main() {
    string str;

    while(getline(cin, str)){
        for (int i = 0; i < str.size(); i++) {
            if(str[i] >= 0x41 && str[i] <= 0x5a){
                alfa[str[i] - 'A'].cnt++;
            }
            else if (str[i] >= 0x61 && str[i] <= 0x7a) {
                alfa[str[i] - 'a'].cnt++;
            }
        } 
    }

    for (int j = 0; j < 26; j++) {
        cout << alfa[j].s << " : " << alfa[j].cnt << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pii pair<int, int>


int main() {


    string s,t;int n;
    cin>>n>>s>>t;


    for(int i = 0;i < n;i++) {
        bool eq = true;
        for(int j = i; j < n;j++) {
            if(s[j] != t[j-i]) {
                eq = false;
                break;
            }
        }

        if(eq) {
            cout<<n-i + 2*i;
            return 0;
        }
    }

    cout<<2*n;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int D;
	cin>>D;
	if(D==25)
	cout<<"Christmas"<<endl;
	if(D==24)
	cout<<"Christmas Eve"<<endl;
	if(D==23)
	cout<<"Christmas Eve Eve"<<endl;
	if(D==22)
	cout<<"Christmas Eve Eve Eve"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    for (int i = 0; i <= len - 1; i++) {
        for (int j = 0; j <= len - i; j++) {
            string str = s;
            str.erase(i, j);
            if (str == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


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

 //bool dp[2][4000001];

signed main(){
   int n,l,t,x,w;
   cin >>n>>l>>t;
   vector<int> x1,x2;
   for(int i=0;i<n;i++){
       cin>>x>>w;
       if(w==1)x2.push_back(x);
       else x1.push_back(x);
   }
   int i0=0,i1=0;
   while(i0<x1.size()&&x1[i0]<=t%l-1)i0++;
   while(i1<x2.size()&&x2[x2.size()-1-i1]>=l-t%l)i1++;
   int num=i0-i1+(x1.size()-x2.size())*(t/l);
   while(num<0)num+=n;
   num=num%n;
   priority_queue< int, vector<int>, greater<int> > q;
   int p;
   for(int i=0;i<x1.size();i++){
       p=x1[i]-t;
       while(p<0)p+=l;
       q.push(p);
   }
   for(int i=0;i<x2.size();i++){
     q.push((x2[i]+t)%l);
   }
   int ans[n];
   for(int i=0;i<n;i++){
       ans[(num+i)%n]=q.top();
       q.pop();
   }
   for(int i=0;i<n;i++)cout <<ans[i]<<endl;



    return 0;
}


Measured memory_bytes: 3696
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int checkMove(int time, int x, int y){
  
  if(time == 0){
    if(x == 0 && y == 0) return 0;
    else return -1;
  }
  
  if(x == 0 && y == 0){
    if(time % 2 == 0) return 0;
    else return -1;
  }
  
  int rc = -1;
  if(x > 0){
  	rc = checkMove(time - 1, x - 1, y);
  	if(rc == 0) return rc;
  }
  else if(x < 0){
  	rc = checkMove(time - 1, x + 1, y);
  	if(rc == 0) return rc;
  }
  else if(y > 0){
  	rc = checkMove(time - 1, x, y - 1);
  	if(rc == 0) return rc;
  }
  else{
  	rc = checkMove(time - 1, x, y + 1);
  	if(rc == 0) return rc;   
  }
  
  return rc;
}

int main(void){
  char buf[32] = { 0 };
  int N;
  int x[131072] = { 0 };
  int y[131072] = { 0 };
  int t[131072] = { 0 };
  
  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d", &N);
  
  for(int i = 1; i < N + 1; i++){
    memset(buf, 0, sizeof(buf));
    fgets(buf, sizeof(buf), stdin);
  	sscanf(buf, "%d %d %d", &t[i], &x[i], &y[i]);
  }
  
  //for(int i = 0; i < N + 1; i++) printf("%d %d %d\n", t[i], x[i], y[i]);
  
  int rc = 0;
  for(int i = 1; i < N + 1; i++){
    rc = checkMove(t[i] - t[i-1], x[i] - x[i-1], y[i] - y[i-1]);
    if(rc != 0) break;
  }
  
  if(rc != 0) printf("No\n");
  else printf("Yes\n");
  
  return 0;
}


Measured memory_bytes: 3188
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll n;
  cin>>n;
  ll n1=n-1;
  set <ll> f,f1;
  ll sq=sqrt(n),sq1=sqrt(n1);
  rep(i,1,sq1+1){
    if(n1%i==0)
      f1.insert(i),f1.insert(n1/i);
  } 
  rep(i,1,sq+1){
    if(n%i==0)
      f.insert(i),f.insert(n/i);
  }
  f.erase(1);
  f1.erase(1);
  ll ans=sz(f1);
  // cout<<ans<<endl;
  for(auto j:f)
  {
    ll x=n;
    while((x%j)==0) x/=j;
    if((x%j)==1) ans++;
  }
  cout<<ans;
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 512
import java.io.*;
    import java.util.*;
    import java.util.LinkedList;

    public class Main {

        public static void main(String[] args) throws IOException {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
            BufferedReader reader = new BufferedReader(new InputReader(System.in));

            int a = in.nextInt();
            int b = in.nextInt();
            int gcd = gcd(a,b);
            long ans = (long) a*b/gcd;
            out.println(ans);
            out.flush();
        }
        private static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b,a%b);
        }
    }

    class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }
        public Long nextLong() {
            return  Long.valueOf(next());
        }
        public Double nextDouble () {
            return Double.valueOf(next());
        }


        static class OutputWriter extends PrintWriter {
            public OutputWriter(OutputStream outputStream) {
                super(outputStream);
            }

            public OutputWriter(Writer writer) {
                super(writer);
            }

            public OutputWriter(String filename) throws FileNotFoundException {
                super(filename);
            }

            public void close() {
                super.close();
            }
        }
    }


Measured memory_bytes: 23252
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, k  = MAP()
p = LIST()

def kitai(a):
    tmp = 0
    # for a in A:
    tmp = 1/a * (1/2 * a * (a+1))
    return tmp
acc = [0] * n

# それぞれの期待値を先に求めて，それから和を求める
for i in range(n):
    acc[i] = (p[i] + 1) / 2
ruiseki = [0] * n
ruiseki[0] = acc[0]
for i in range(n-1):
    ruiseki[i+1] = ruiseki[i] + acc[i+1]
ruiseki.insert(0, 0)
# print(ruiseki)

ans = 0
for i in range(n-k+1):
    m = ruiseki[k+i] - ruiseki[i]
    # print(m)
    ans = max(ans, m)
print(ans)

    
    # if i == 0:
    #     ruiseki[k]
    # else:
    #     ruiseki[k+i] - ruiseki[i]
    # ans = max(ans, acc[i+k]-acc[i])



Measured memory_bytes: 27916
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		String s=stdIn.next();
		int timeg=0,timep=0;
		for(int i=0;i<s.length();i++){
			if(s.charAt(i)=='p')timep++;
			else if(s.charAt(i)=='g')timeg++;
			}
		if(s.length()%2==0)
			System.out.println((timeg-timep)/2);
		else 
			System.out.println((timeg-timep-1)/2);
	}

}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vll = V<ll>;
using VVll = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

const double PI = acos(-1);
const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int h, n;
    cin >> h >> n;

    ll sum = 0;
    REP(i, n) {
        int x;
        cin >> x;
        sum += x;
    }

    if (h <= sum) {
        std::cout << "Yes" << '\n';
    } else {
        std::cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
A,B,C,D=map(int,input().split())
if C<=A and A<=D and D<=B:
    print(D-A)
elif C<=A and B<=D:
    print(B-A)
elif A<=C and C<=B and B<=D:
    print(B-C)
elif A<=C and D<=B:
    print(D-C)
else:
    print(0)

Measured memory_bytes: 61836
#include <stdio.h>
#include <stdlib.h>
#define MAX_N 10001
#define INF (1<<28);
#define QUEUE_SIZE 20001;

typedef struct Node * NodePointer;

typedef struct Node {
  NodePointer next;
  int v, c;
} Node;

int N;
NodePointer E[MAX_N] = {};
NodePointer tail[MAX_N] = {};
int cost[MAX_N];

NodePointer makeNode(int v, int c) {
  NodePointer node = (NodePointer)malloc(sizeof(Node));
  node->next = NULL;
  node->v = v;
  node->c = c;
  return node;
}

void init() {
  int i;
  for(i = 0; i < MAX_N; ++i) {
    E[i] = makeNode(-1,-1);
    tail[i] = E[i];
  }
}

void addEdge(int u, int v, int c) {
  tail[u]->next = makeNode(v,c);
  tail[u] = tail[u]->next;
}

int daiku() {
  int i, j;
  int mini, id;
  int vis[MAX_N];
  NodePointer np;
  for(i = 0; i < N; ++i) {
    cost[i] = INF;
    vis[i] = 0;
  }
  cost[0] = 0;
  while(1) {
    mini = INF;
    id = -1;
    for(i = 0; i < N; ++i) {
      if(vis[i]) continue;
      if(cost[i] < mini) {
        mini = cost[i];
        id = i;
      }
    }
    if(id == -1) break;
    vis[id] = 1;
    for(np = E[id]->next; np != NULL; np = np->next) {
      if(vis[np->v]) continue;
      j = cost[id] + np->c;
      if(j < cost[np->v]) cost[np->v] = j;
    }
  }
}

int main() {
  int i, j, k;
  int id, v, c;
  int tmp;

  init();

  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    scanf("%d %d", &id, &k);
    while(k--) {
      scanf("%d %d", &v, &c);
      addEdge(id,v,c);
    }
  }

  daiku();

  for(i = 0; i < N; ++i) {
    printf("%d %d\n", i, cost[i]);
  }

  return 0;
}

Measured memory_bytes: 8504
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    LL h,w;cin >> w >> h;
    vector<P> v(h+w);
    for (int i = 0; i < w; i++) {
        cin >> v[i].fs;
        v[i].sc = 0;
    }
    for (int i = 0; i < h; i++) {
        cin >> v[i+w].fs;
        v[i+w].sc = 1;
    }
    sort(ALL(v));
    LL ans = 0;
    LL a = w + 1, b = h + 1;
    for (int i = 0; i < h+w; i++) {
        if(v[i].sc == 1){
            ans += v[i].fs * a;
            b--;
        }
        else{
            ans += v[i].fs * b;
            a--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
 
int main() {
  int a, b, c;
 
  cin >> a;
  cin >> b;
  cin >> c;
 
  if (a < b && b < c) {
    cout << "Yes" << endl;
  } else {
    cout << "No"  << endl;
  }
 
  return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

    // auto table = prime_table(1000000);
    // bool pair = false;
    // for(int k=1; k<=1000000; k++) {
    //     if(!table[k]) continue;
    //     bool flag = false;
    //     for(int i=0; i<N; i++) {
    //         if(flag && A[i] % k == 0) {
    //             pair = true;
    //             break;
    //         } else if(A[i] % k == 0) {
    //             flag = true;
    //         }
    //     }
    // }

    // int p = A[0];
    // bool pair = false;
    // for(int i=1; i<N; i++) {
    //     if(gcd(p, A[i]) > 1) {
    //         pair = true;
    //         break;
    //     } else {
    //         p *= A[i];
    //     }
    // }

    bool pair = false;
    vector<int> v(1000001);
    for(int i=0; i<N; i++) {
        if(pair) break;
        for(auto e: prime_factor(A[i])) {
            v[e.first]++;
            if(v[e.first] > 1) pair = true;
        }
    }

    int tmp = 0;
    for(int i=0; i<N; i++) {
        tmp = gcd(tmp, A[i]);
    }

    if(pair && tmp == 1) {
        cout << "setwise coprime" << endl;
    } else if(pair) {
        cout << "not coprime" << endl;
    } else {
        cout << "pairwise coprime" << endl;
    }
    return 0;
}


Measured memory_bytes: 11112
// AOJ 0553
#include<cstdio>
#include<algorithm>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )

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

int N, H;
int d[100000], h[100000];
std::priority_queue<P> pque;

ll data[1<<18], datb[1<<18];

void add( int a, int b, int x, int k, int l, int r )
{
	if( a <= l && r <= b )
	{
		datb[k] += x;

		while( k )
		{
			k = (k-1)>>1;
			data[k] = std::max( data[(k<<1)+1]+datb[(k<<1)+1], data[(k<<1)+2]+datb[(k<<1)+2] );
		}
	}
	else if( l < b && a < r )
	{
		add( a, b, x, (k<<1)+1, l, (l+r)>>1 );
		add( a, b, x, (k<<1)+2, (l+r)>>1, r );
	}

	return;
}

int query( int a, int b, int k, int l, int r )
{
	if( b <= l || r <= a )
		return 0;
	else if( a <= l && r <= b )
		return data[k]+datb[k];
	else
		return std::max( query( a, b, (k<<1)+1, l, (l+r)>>1 ), query( a, b, (k<<1)+2, (l+r)>>1, r ) ) + datb[k];	
}

int main()
{
	scanf( "%d%d", &N, &H );
	rep( i, N-1 )
		scanf( "%d%d", d+i, h+i );

	int hp = H;
	ll ans = 0;
	rep( i, N-1 )
	{
		add( i, i+1, hp, 0, 0, 1<<17 );

		hp -= d[i];
		pque.push( P( h[i], i ) );

		while( hp <= 0 )
		{
			P p = pque.top(); pque.pop();
			int heal = p.first, ma = query( p.second, i+1, 0, 0, 1<<17 );

			if( heal+ma > H )
			{
				p.first = H-ma;
				pque.push( p );
				continue;
			}

			int cnt = std::min( -hp/heal+1, (H-ma)/heal );
			ans += cnt;
			hp += cnt*heal;

			add( p.second, i+1, cnt*heal, 0, 0, 1<<17 );
			pque.push( p );
		}
	}

	printf( "%lld\n", ans );

	return 0;
}

Measured memory_bytes: 5980
n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

sum = 0
k.times do |i|
  sum += a[i]
end

max = sum

(n-k).times do |i|
  sum -= a[i]
  sum += a[i+k]
  max = sum if max < sum
end

puts (max + k).to_f / 2

Measured memory_bytes: 15876
def FACTOR(DICT, N):
    FACT = DICT
    LIM = int(N**0.5)+2
    for i in range(2, LIM):
        if N%i == 0:
            FACT[i] = 0
        while N%i == 0:
            FACT[i] += 1
            N //= i
    if len(FACT) == len(DICT):
        if N != 1:
            FACT[N] = 1
        return FACT
    return FACTOR(FACT, N)

n, p = map(int, input().split())
fact = FACTOR({}, p)
ans = 1

for i in fact:
    ans *= i**(fact[i]//n)
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<(x)<<endl
#define Divhim() cout<<">>>>>>>>>>>>>>>"<<endl
#define Divher() cout<<"<<<<<<<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!!!!!!"<<endl

template<typename T> bool GetMin(T &a,T b)
{
	return ((a<=b)?false:(a=b,true));
}

template<typename T> bool GetMax(T &a,T b)
{
	return ((a>=b)?false:(a=b,true));
}

/*
	 -<Unlimited Blade Works>-
 */

#define Pir pair<int,int>
#define fir first
#define sec second

const int N=5e5;
const int MOD=1e9+7;

void SU(int &x,int y)
{
	((x+=y)>=MOD)?(x-=MOD):0;
}

int n,m,ax[N],ay[N];
Pir p[N];int tot;

int ls[N],ed;

int C[N];

void Add(int x,int y)
{
	for(;x<=ed;x+=x&(-x))
		SU(C[x],y);
}

int Query(int x)
{
	int res=0;
	for(;x;x&=x-1)
		SU(res,C[x]);
	return res;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		scanf("%d",ax+i);
	for(int i=1;i<=m;++i)
		scanf("%d",ay+i);
	for(int i=1,id;i<=n;++i)
	{
		if(ax[i]<=ay[1]||ax[i]>=ay[m])
			continue;
		id=lower_bound(ay+1,ay+m+1,ax[i])-ay;
		if(ay[id]==ax[i])
			continue;
		p[++tot]=Pir(ax[i]-ay[id-1],ay[id]-ax[i]);
	}
	sort(p+1,p+tot+1);
	tot=unique(p+1,p+tot+1)-p-1;
	for(int i=1;i<=tot;++i)
	{
		ls[++ed]=p[i].fir;
		ls[++ed]=p[i].sec;
	}
	sort(ls+1,ls+ed+1);
	ed=unique(ls+1,ls+ed+1)-ls-1;
	for(int i=1;i<=tot;++i)
	{
		p[i].fir=lower_bound(ls+1,ls+ed+1,p[i].fir)-ls;
		p[i].sec=lower_bound(ls+1,ls+ed+1,p[i].sec)-ls;
	}
	sort(p+1,p+tot+1,
			[](auto a,auto b)
			{
				return a.fir!=b.fir?a.fir<b.fir:a.sec>b.sec;
			});
	//for(int i=1;i<=tot;++i)
	//	cout<<p[i].fir<<","<<p[i].sec<<endl;
	int ans=1;
	for(int i=1,t;i<=tot;++i)
	{
		t=1;
		SU(t,Query(p[i].sec-1));
		SU(ans,t);
		Add(p[i].sec,t);
	}
	printf("%d",ans);
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    vector<int> acc(n + 1, 0);
    acc[0] = 1e9;
    for (int i = 0; i < n; i++) acc[i + 1] = min(acc[i], p[i]);
    int ans = 0;
    for (int i = 0; i < n; i++){
        if (p[i] <= acc[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

if __name__ == "__main__":
    n,p = map(int, input().split())
    x = factorize(p)
    ans=1
    for i in x:
        if i[1]>=n:
            ans = ans*(i[0]**(i[1]//n))
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    SORT(a);
    cout << a[0] * a[1]/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)
 
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  for (ll i = 0; i < t; i++) {
    if (a < b) {
      a += v;
      b += w;
      if (a >= b) {
        cout << "YES" << '\n';
        return 0;
      }
    }
    else if (a > b) {
      a -= v;
      b -= w;
      if (a <= b) {
      cout << "YES" << '\n';
      return 0;
      }
    }
  }
  cout << "NO" << '\n';
}

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

using namespace std;

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

const int MOD = 1000000007;

int n ;
ll a[310][310];

int main() {
	//freopen("input.txt", "r", stdin);
	scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		for(int j = 0; j < n ; ++j){
			scanf("%lld",&a[i][j]);
		}
	}
	for(int k = 0 ; k < n ; k++){
		for(int i = 0 ; i < n ; ++i){
			for(int j = 0 ; j < n ; ++j){
				if(a[i][k] + a[k][j] < a[i][j]){
					puts("-1");
					return 0;
				}
			}
		}
	}
	ll total = 0;
	for (int i = 0; i < n; ++i){
		for(int j = 0; j < n ; ++j){
			bool important = true;
			for(int k = 0 ; k < n ; ++k){
				if(k==i || k == j)continue;
				if(a[i][k]+a[k][j] == a[i][j]){
					important = false;
				}
			}
			if(important){
				total += a[i][j];
			}
		}
	}

	printf("%lld\n", total/2);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll factorial(ll a){return a < 2 ? 1 : factorial(a - 1) * a;}
ll summation(ll a){return a < 1 ? 0 : (a * a + a) / 2;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const string ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//ll dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll n, m, x, y, z, w, h;
string s, t;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        ll ans = 0, tmp = 0, cnt = 0, mx = -INF, mn = INF;
        ll a[] = {}, b[] = {}, c[] = {};
        pll v[n];
        rep(i, n){
            cin >> x >> y;
            v[n - 1 - i] = mp(x, y);
        }
        each(p, v){
            if((p.fir + cnt) % p.sec){
                cnt += p.sec - (p.fir + cnt) % p.sec;
            }
        }
        print(cnt);
    }
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

const int MOD = 1000000007;
const int MAXN = 1000;
char grid[MAXN + 5][MAXN + 5];
int dp[MAXN + 5][MAXN + 5];

auto add(auto& a, auto b){a = ((ll) a + b) % MOD;}

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

  int r, c;
  cin >> r >> c;
  rep(i, 0, r) rep(j, 0, c)
    cin >> grid[i][j];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  rep(i, 0, r) {
    rep(j, 0, c) {
      if (i == 0 and j == 0) continue;

      if (i - 1 >= 0 and grid[i - 1][j] != '#')
	add(dp[i][j], dp[i - 1][j]);
      if (j - 1 >= 0 and grid[i][j - 1] != '#')
	add(dp[i][j], dp[i][j - 1]);
    }
  }
  cout << dp[r - 1][c - 1] << '\n';
}


Measured memory_bytes: 5248
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string>

using namespace std;

int main(){
  long long int a,b,c,t;
  long long int ans;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&t);
  t %= 2;
  ans = (a-b)*pow(-1,t);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;
typedef long long int ll;

int main(){
    int n;
    while (cin >> n) {
        int ans=0;
        for (int i=0; i<=9; i++) {
            for (int j=0; j<=9; j++) {
                for (int k=0; k<=9; k++) {
                    for (int l=0; l<=9; l++) {
                        if(i+j+k+l==n) ans++;
                    }
                }
            }
        }
        cout << ans <<endl;
    }
}

Measured memory_bytes: 1160
N=int(input())
P=10**9+7
s_10=1
for i in range(N):
  s_10=(s_10*10)%P
s_9=1
for i in range(N):
  s_9=(s_9*9)%P
s_9=(s_9*2)%P
s_8=1
for i in range(N):
  s_8=(s_8*8)%P
print ((s_10-s_9+s_8)%P)

Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int a,b;
signed main(){
	cin>>a>>b;
	if(a==b)cout<<0<<endl;
	else{
		int c=a+b;
		if(c%2)puts("IMPOSSIBLE");
		else cout<<c/2<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
import math
from enum import Enum

while True:
    n=int(input())
    if n==0:
        break
    s=list(map(int,input().split()))
    
    sum1=0
    for i in range(len(s)):
        sum1+=s[i]
    a=sum1/len(s)
    
    sum2=0
    for i in range(len(s)):
        sum2+=s[i]*s[i]
    b=sum2/len(s)
    
    print("%.10f"%(math.sqrt(b-a*a)))


Measured memory_bytes: 6392
// https://atcoder.jp/contests/abc134/tasks/abc134_d

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
#define DUMP2D(a) REP(_i, a.size()) DUMP(a[_i]); cout << endl

const int N_MAX = 2*1e5;
const int MOD = 2;

int N;
vector<int> a;
int M;
vector<int> b;

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

  M = 0;
  b = vector<int>(N, 0);
  for (int i = N; i > 0; i--) {
    b[i - 1] = a[i - 1];
    for(int j = i * 2; j <= N; j += i) {
      b[i - 1] ^= b[j - 1];
    }
    M += b[i - 1];
  }

  cout << M << endl;
  REP(i, N) if(b[i]) cout << (i + 1) << endl;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100001;

int n, q, cnt[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    ll sum = 0;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        cnt[x]++;
        sum += x;
    }
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        sum -= 1LL * cnt[b] * b;
        sum -= 1LL * cnt[c] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        sum += 1LL * cnt[c] * c;
        cout << sum << "\n";
    }
}


Measured memory_bytes: 4028
while 1
    n, m = gets.split.map(&:to_i)
    break if n == 0
    hash = { 0 => 0 }
    n.times do
        x = gets.to_i(2)
        new_hash = Hash.new(0)
        hash.each do |y, k|
            new_hash[y] = k if k >= new_hash[y]
            z = y ^ x
            new_hash[z] = k + 1 if k + 1 >= new_hash[z]
        end
        hash = new_hash
    end
    p hash[0]
end


Measured memory_bytes: 136508
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int n = sc.nextInt();
      	int kaisuu = 0;
      
      
		for(int i = 0 ; i < n ; i++){
        	int n1 = sc.nextInt();
        	int n2 = sc.nextInt();
          
          if(n1==n2){
              kaisuu += 1;
            }else{
            kaisuu = 0;
            }
          
         if(kaisuu ==3){
         	break;
         }
        }

		if(kaisuu ==3){
			// 出力
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
	}
}

Measured memory_bytes: 35924