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

pattern = []
for _ in range(N):
    pattern.append(None)


nums = []
for _ in range(M):
    nums.append(list(map(int, input().split())))


cant_bool = False

for keta, num in nums:
    if pattern[keta - 1] == None:
        pattern[keta - 1] = num
    else:
        if pattern[keta - 1] == num:
            continue
        else:
            cant_bool = True

if cant_bool and not (len(nums) == 0):
    print(-1)
else:
    if pattern[0] == 0 and len(pattern) > 1:
        print(-1)
    else:
        pattern = [(0 if (num == None) else num) for num in pattern]
        if pattern[0] == 0 and len(pattern) > 1:
            pattern[0] = 1
        print(''.join(map(str, pattern)))


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

int i,j,n,step,set,safe;
int x,y,spr[15][2],mark[15][3][3],mat[30][30];

void check(int x,int y){
	if(abs(spr[step][0]-x)<2 && abs(spr[step][1]-y)<2){
		mark[step][x-spr[step][0]+1][y-spr[step][1]+1]=set;
		safe=1;
	}
}

void marking(int x,int y){
	int k;
	for(k=-1;k<2;k++){
		check(x+2,y+k);
		check(x-2,y+k);
		check(x+k,y+2);
		check(x+k,y-2);
	}
}

int main(){
	while(scanf("%d %d",&y,&x)*(x+y)){
		scanf("%d",&n);
		set++;
		for(i=0;i<n;i++){scanf("%d %d",&spr[i][1],&spr[i][0]);}
		spr[n][1]=spr[0][1];spr[n][0]=spr[0][0];
		for(step=0;step<n;step++){
			safe=0;
			if(step==0)marking(x,y);
			else{
				for(i=0;i<3;i++){
					for(j=0;j<3;j++){
						if(mark[step-1][i][j]==set)marking(spr[step-1][0]+i-1,spr[step-1][1]+j-1);
					}
				}
			}
			if(safe==0)break;
		}
		if(step>=n) printf("OK\n"); else printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 588
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		while (scanner.hasNext()) {

			long tempA = input();
			long tempB = input();

			long a;
			long b;
			long r;
			long lcm;

			if (tempB <= tempA) {

				a = tempA;
				b = tempB;

			} else {

				a = tempB;
				b = tempA;

			}

			while ((r = a % b) != 0) {

				a = b;
				b = r;

			}

			lcm = tempA * tempB / b;

			System.out.print(b);
			System.out.print(" ");
			System.out.println(lcm);

		}

		close();

	}

	public static long input() {

		return scanner.nextLong();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 26308
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll Q;
    cin >> Q;
    ll res = 0;
    priority_queue<ll, vector<ll>, less<ll> > pq_less;
    priority_queue<ll, vector<ll>, greater<ll> > pq_greater;
    ll sum_less = 0, sum_greater = 0;
    ll val = 0;
    while(Q--){
        ll q;
        cin >> q;
        if(q == 1){
            ll a,b;
            cin >> a >> b;
            res += b;
            if(pq_less.size() == 0){
                pq_less.push(a);
                sum_less += a;
            }else{
                if(pq_greater.size() == 0){
                    val += abs(pq_less.top() - a);
                    if(pq_less.top() <= a){
                        pq_greater.push(a);
                        sum_greater += a;
                    }else{
                        sum_less += a - pq_less.top();
                        sum_greater += pq_less.top();
                        pq_greater.push(pq_less.top());
                        pq_less.pop();
                        pq_less.push(a);
                    }
                }else{
                    ll v1 = pq_less.top();
                    ll v2 = pq_greater.top();
                    ll sz = pq_less.size() + pq_greater.size();
                    if(sz % 2 == 0){
                        if(a < v1 || v2 < a) val += min(abs(v1 - a), abs(a - v2));
                        if(a <= v2){
                            pq_less.push(a);
                            sum_less += a;
                        }else{
                            pq_less.push(v2);
                            pq_greater.pop();
                            pq_greater.push(a);
                            sum_less += v2;
                            sum_greater += a - v2;
                        }
                    }else{
                        val += abs(v1 - a);
                        if(a <= v1){
                            pq_greater.push(v1);
                            pq_less.pop();
                            pq_less.push(a);
                            sum_greater += v1;
                            sum_less += a - v1;
                        }else{
                            pq_greater.push(a);
                            sum_greater += a;
                        }
                    }


                }
            }

        }else{
            // print(pq_less.top(), val+res);
            ll mid = pq_less.top();
            ll ans = mid * (ll)pq_less.size() - sum_less;
            ans += sum_greater - mid * (ll)pq_greater.size();
            print(mid, ans + res);
        }
    }

}

Measured memory_bytes: 3828
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n;
  std::cin>>n;

  std::vector<ll> x(n);
  rep(i,0,n)std::cin>>x[i];

  ll ans=1;

  std::stack<ll> bot;

  rep(i,0,n){
    bot.push(i);
    ll k=bot.size();
    if(x[i]<2*k-1){
      ans=(ans*k)%MOD;
      bot.pop();
    }
  }

  ll k=bot.size();

  rep(i,1,k+1)ans=(ans*i)%MOD;

  std::cout<<ans;

  return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
using namespace std;

class Dice{
    public:
    int face[6];
    Dice(){}
    int roll(int a, int b, int c, int d){
        int temp = face[a]; face[a] = face[b]; face[b] = face[c]; face[c] = face[d]; face[d] = temp;
        return 0;
    }
    int move(char c){
        if (c == 'W') roll(0, 2, 5, 3);
        if (c == 'E') roll(0, 3, 5, 2);
        if (c == 'S') roll(0, 4, 5, 1);
        if (c == 'N') roll(0, 1, 5, 4);
        return 0;
    }
};

int right(Dice dice, int top, int front){
    for (int i = 0; i <= 6; i++){
        if (dice.face[1] == front){
            for (int j = 0; j < 4; j++){
                if (dice.face[0] == top){
                    printf("%d\n", dice.face[2]);
                    return 0;
                }
                else dice.move('W');
            }
        }
        else{
            if (i == 3) dice.move('W');
            dice.move('N');
        }
    }
    return 0;
}

int samedice(Dice dice1, Dice dice2){
    for (int i = 0; i <= 6; i++){
        if (dice1.face[1] == dice2.face[1]){
            for (int j = 0; j < 4; j++){
                if (dice1.face[0] == dice2.face[0]){
                    if (dice1.face[2] == dice2.face[2] && dice1.face[3] == dice2.face[3] && dice1.face[4] == dice2.face[4] && dice1.face[5] == dice2.face[5]){
                        printf("Yes\n");
                        return 0;
                    } 
                }
                else dice1.move('W');
            }
        }
        else{
            if (i == 3) dice1.move('W');
            dice1.move('N');
        }
    }
    printf("No\n");
    return 0;
}


int main(void){
    Dice dice1, dice2;
    scanf("%d%d%d%d%d%d", &dice1.face[0], &dice1.face[1], &dice1.face[2], &dice1.face[3], &dice1.face[4], &dice1.face[5]);
    scanf("%d%d%d%d%d%d", &dice2.face[0], &dice2.face[1], &dice2.face[2], &dice2.face[3], &dice2.face[4], &dice2.face[5]);
    samedice(dice1, dice2);
    return 0;
}

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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    cout << setprecision(16) << fixed;

    ll n;
    cin >> n;

    vector<ll> dp(3);
    while(n--) {
        vector<ll> pre(3);
        swap(dp, pre);

        ll a, b, c;
        cin >> a >> b >> c;
        dp[0] = a + max(pre[1], pre[2]);
        dp[1] = b + max(pre[2], pre[0]);
        dp[2] = c + max(pre[0], pre[1]);
    }
    cout << max({dp[0], dp[1], dp[2]}) << endl;
}


Measured memory_bytes: 256
// ProblemURL : https://atcoder.jp/contests/abc067/tasks/arc078_a
// ---------------------------------------------
package main

import "fmt"

const inf = 1 << 60

func diff(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}
func chmin(a *int, b int) {
	if *a > b {
		*a = b
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	c := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		c[i] = c[i-1] + a[i-1]
	}

	minDiff := inf
	for i := 1; i <= n-1; i++ {
		sumL := c[i] - c[0]
		sumR := c[n] - c[i]
		chmin(&minDiff, diff(sumL, sumR))
	}
	fmt.Println(minDiff)
}


Measured memory_bytes: 6656
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


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

const ll MOD = 1e9 + 7;


int main() {

	ll m, k;
	cin >> m >> k;


	if (m == 0)
	{
		if (k == 0)
		{
			cout << "0 0" << endl;
		}
		else
		{
			cout << "-1" << endl;
		}
		return 0;
	}

	if (m == 1)
	{
		if (k != 0)
		{
			cout << "-1" << endl;
		}
		else
		{
			cout << "0 0 1 1" << endl;

		}
		return 0;
	}

	if (k >= (1LL << m)) {
		cout << "-1" << endl;
		return 0;
	}

	vector<ll> ans;
	ll maxi = 1LL << m;

	for (ll i = 0; i < maxi; i++)
	{
		if (i != k)
		{
			ans.push_back(i);
		}
	}
	ans.push_back(k);

	for (ll i = maxi - 1; i >= 0; i--)
	{
		if (i != k)
		{
			ans.push_back(i);
		}
	}
	ans.push_back(k);

	for (int i = 0; i < ans.size(); i++)
	{
		if (i == 0)
		{
			cout << ans[i];
		}
		else
		{
			cout << " " << ans[i];
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3952
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
    
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
if (true)                                                                    \
cerr
     
using namespace std;
     
typedef long long ll;
typedef unsigned long long ull;
     
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;
     
// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}
     
void solve(long long N, long long M) {
  ll ret = min(N, M / 2);
  M -= ret * 2;
  ret += M / 4;
 
  cout << ret << endl;
}
     
int main() {
  ios::sync_with_stdio(false);
     
  int n;

  cin >> n;

  cout << "ABC" << n << endl;

     
  return 0;
}

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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}
    
int main()
{    
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        li a,b;

        cin>>a>>b;

        cout<<max(0ll,a-2*b);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
int K;
int dfs(const vector<int>& a, int d, int pos) {
    if(pos == K) return d;
    if(a[pos] == 0) return dfs(a, d, pos + 1);
    int res = INF;
    vector<int> temp = a;
    REP(i, pos, K) {
        temp[i] -= a[pos];
        if(temp[i] < 0) temp[i] += 10;
        res = min(res, dfs(temp, d + 1, pos + 1));
    }
    return res;
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    while(cin >> K && K) {
        string s1, s2; cin >> s1 >> s2;
        vector<int> a(K);
        rep(i, K) a[i] = (int)(s2[i] - s1[i]);
        for(int& k : a) if(k < 0) k += 10;
        cout << dfs(a, 0, 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>
#include <math.h>

int cnt;

void insertionSort( int A[], int n, int g )
{
    int v;
    int j;
    
    for ( int i = g; i < n; i++ ) {
        v = A[i];
        j = i - g;
        while ( j >= 0 && A[j] > v ) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort( int A[], int n )
{
    cnt = 0;
    int m;
    m = log10(2 * n + 1) / log10(3.0);
    int G[100] = {0};

    G[m - 1] = 1;
    for ( int i = m - 2; i >= 0; i-- ) {
        G[i] = 3 * G[i + 1] + 1;
    }

    printf("%d\n", m);

    for ( int i = 0; i < m; i++ ) {
        printf("%d", G[i]);
        if ( i != m - 1 ) {
            printf(" ");
        } else {
            printf("\n");
        }
    }
    for ( int i = 0; i < m; i++ ) {
        insertionSort( A, n, G[i]);
    }

}

int main(void)
{
    int n;
    static int A[1000000];
    
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &A[i]);
    }
    
    shellSort( A, n );
   
    printf("%d\n", cnt);

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


Measured memory_bytes: 5908
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple

int gcd(int a,int b)
{
    if(b>a) return gcd(b,a);
    if(b==0) return a;
    return gcd(b,a%b);
}

char C(char a, char b)
{
    int f[3]={0};
    if(a==b) return 'D';
    if(a=='R') f[0]++;
    else if(a=='G') f[1]++;
    else f[2]++;
    if(b=='R') f[0]++;
    else if(b=='G') f[1]++;
    else f[2]++;
    if(f[0]==0) return 'R';
    else if(f[1]==0) return 'G';
    else return 'B';
}

int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	string s; cin>>s;
	vector <int> r,b,g;
	for(int i=0;i<n;i++)
	{
	    if(s[i]=='R') r.pb(i);
	    else if(s[i]=='G') g.pb(i);
	    else b.pb(i);
	}
	int l1=r.size(), l2=g.size(), l3=b.size();
	ll ans = 0;
	for(int i=0;i<n-2;i++)
	{
	    for(int j=i+1;j<n-1;j++)
	    {
	        //if(s[i]==s[j]) continue;
	        char c = C(s[i],s[j]);
	        if(c=='D') continue;
	        int d=j-i;
	        if(c=='R')
	        {
	            auto it = lower_bound(r.begin(),r.end(),j);
	            ll pp = (ll)(it - r.begin());
	            pp = l1 - pp;
	            auto it1 = find(r.begin(),r.end(),j+d);
	            if(it1!=r.end()) pp--;
	            if(pp>0) ans+=pp;
	        }
	        if(c=='G')
	        {
	            auto it = lower_bound(g.begin(),g.end(),j);
	            ll pp = (ll)(it - g.begin());
	            pp = l2 - pp;
	            auto it1 = find(g.begin(),g.end(),j+d);
	            if(it1!=g.end()) pp--;
	            if(pp>0) ans+=pp;
	        }
	        if(c=='B')
	        {
	            auto it = lower_bound(b.begin(),b.end(),j);
	            ll pp = (ll)(it - b.begin());
	            pp = l3 - pp;
	            auto it1 = find(b.begin(),b.end(),j+d);
	            if(it1!=b.end()) pp--;
	            if(pp>0) ans+=pp;
	        }
	        
	    }
	}
	cout<<ans;
	
	
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a<=c&&c<=b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;
public class Main {
	static int A,B,C;
	//static String ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		A=sc.nextInt();
		B=sc.nextInt();
		C=sc.nextInt();
		int i=0;
		for(;i<C;i++) {
			B-=A;
			if(B<0)break;
		}
		System.out.println(i);
	}
}

Measured memory_bytes: 21460
n,m=list(map(int,input().split()))
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort()
drink,yen=m,0
for store in a:
    if drink<=store[1]:
        yen+=store[0]*drink
        break
    else:
        yen+=store[0]*store[1]
        drink-=store[1]
print(yen)

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

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


Measured memory_bytes: 3620
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int temp=a;
    a=b;
    b=temp;
    temp=a;
    a=c;
    c=temp;
    System.out.println(a+" "+b+" "+c);
  }
}

Measured memory_bytes: 22612
#include <cstdlib>
#include <iostream>
#include <string>


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

  std::string s, t;
  std::cin >> s >> t;

  for (decltype(s)::size_type i = 0; i < s.length(); i++) {
    std::string::size_type j = 0;
    auto flag = true;
    for (decltype(i) k = i; k < s.length(); k++) {
      if (t[j++] != s[k]) {
        flag = false;
        break;
      }
    }
    for (decltype(i) k = 0; k < i; k++) {
      if (t[j++] != s[k]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      std::cout << "Yes" << std::endl;
      return EXIT_SUCCESS;
    }
  }
  std::cout << "No" << std::endl;

  return EXIT_SUCCESS;
}


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

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

    vector< pair<int64_t, int64_t> > a(n);
    for(int i = 0; i < n; i++) {
        a[i].first = i + 1;
        cin >> a[i].second;
    }
    
    // j - i = h_i + h_j
    // => i + h_i = j - h_j
    vector<int64_t> l(n), r(n);
    for(int i = 0; i < n; i++) {
        l[i] = a[i].first + a[i].second;
        r[i] = a[i].first - a[i].second;
    }

    map<int64_t, int64_t> m;
    for(int i = 0; i < n; i++) {
        if(m.find(l[i]) != m.end()) m[l[i]]++;
        else                        m[l[i]] = 1;
    }

    int64_t ans = 0;
    for(int i = 0; i < n; i++) {
        if(m.find(r[i]) != m.end()) ans += m[r[i]];
    }
    cout << ans << endl;

    return 0;
}


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

int main(void) {
    int n, m;
    cin >> n >> m;

    vector<vector<long>> v(8, vector<long>(n));
    for(int i=0; i<n; i++) {
        long x, y, z;
        cin >> x >> y >> z;

        for(int j=0; j<8; j++)
            v[j][i] = (j%2?1:-1)*x + (j/2%2?1:-1)*y + (j/4%2?1:-1)*z;
    }

    for(int j=0; j<8; j++)
        sort(v[j].rbegin(), v[j].rend());

    long res = 0;
    for(int j=0; j<8; j++) {
        long r = 0;
        for(int i=0; i<m; i++)
            r += v[j][i];
        res = max(res, abs(r));
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(n / 2);
	x %= mod;
	x *= x;
	x %= mod;
	if (n % 2 == 1)x *= 10;
	x %= mod;
	return x;
}

int main(){
	llint a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	if (a%2==0&&a == b && b == c&&a==c)ans = -1;
	else {
		for (int i=0;;i++) {
			if (i == 1000000000) {
				ans = -1;
				break;
			}
			if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
				ans = i;
				break;
			}
			llint Na = (b + c) / 2;
			llint Nb = (a + c) / 2;
			llint Nc = (a + b) / 2;
			a = Na;
			b = Nb;
			c = Nc;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <map>
 
using namespace std;
 
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
 
int main(){
	cin.tie(0);                       
   	ios::sync_with_stdio(false);
   	vector<string> C;
      for(int i = 0;i < 2;i++){
         string str;
         cin >> str;
         C.push_back(str);
      }


      bool flag = true;
      for(int i = 0;i < 3;i++){
         if(C[0][i] != C[1][3-i-1]){
            flag = false;
            break;
         }
      }
      if(flag){
         cout << "YES" << endl;
      }else{
         cout << "NO" << endl;
      }
   	
   	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void Judge_if_Rectangle_include_Circle(int W, int H, int x, int y, int r)
{
	if (((x - r >= 0) && (x + r <= W)) && ((y - r >= 0) && (y + r <= H)))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
}

int main(void)
{
	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	Judge_if_Rectangle_include_Circle(W, H, x, y, r);

	return 0;
}


Measured memory_bytes: 2140
sx,sy,tx,ty=map(int,input().split())

# 1往復目
for _ in range(ty-sy):
    print("U",end='')
for _ in range(tx-sx):
    print("R",end='')
for _ in range(ty-sy):
    print("D",end='')
for _ in range(tx-sx):
    print("L",end='')

# 2往復目
print("L",end='')
for _ in range(ty-sy+1):
    print("U",end='')
for _ in range(tx-sx+1):
    print("R",end='')
print("D",end='')
print("R",end='')
for _ in range(ty-sy+1):
    print("D",end='')
for _ in range(tx-sx+1):
    print("L",end='')
print("U",end='')
print()

Measured memory_bytes: 4468
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
   ll n,ans=0;
   cin>>n;
   vll a(n);
   rep(i,n){
       cin>>a.at(i);
       if(i+1!=a.at(i))ans++;
   }
   if(ans>2)cout<<"NO"<<endl;
   else cout<<"YES"<<endl;
}
   



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int H, W, a[500][500];
  int eoflag = 1, cnt = 0, lrflag = -1;

  scanf("%d%d", &H, &W);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 0; i < H; i++) {
    lrflag *= -1;
    for (int j = 0; j < W; j++) {
      if (a[i][(lrflag == 1) ? j : (W - j - 1)] % 2 == 1) {
        eoflag *= -1;
      }
      if (eoflag < 0 && !(i == H - 1 && j == W - 1)) {
        cnt++;
      }
    }
  }

  printf("%d\n", cnt);

  eoflag = 1;
  lrflag = -1;

  for (int i = 0; i < H; i++) {
    lrflag *= -1;
    for (int j = 0; j < W; j++) {
      if (a[i][(lrflag == 1) ? j : (W - j - 1)] % 2 == 1) {
        eoflag *= -1;
      }
      if (eoflag < 0 && !(i == H - 1 && j == W - 1)) {
        printf("%d %d %d %d\n",
               i + 1,
               ((lrflag == 1) ? j : (W - j - 1)) + 1,
               (j == W - 1) ? (i + 2) : (i + 1),
               (j == W - 1) ? (((lrflag == 1) ? j : (W - j - 1)) + 1) : (((lrflag == 1) ? j : (W - j - 1)) + 1) + lrflag);
      }
    }
  }

  return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int money=100000;
		for(int i=0;i<a;i++){
			money*=1.05;
			int amari=money%1000;
			money-=amari;
			money+=amari==0 ? 0 : 1000;
		}
		System.out.println(money);
	}
}

Measured memory_bytes: 17156
#include <iostream>
#include <algorithm>
#define MAX 1000

using namespace std;

int compute( char c[MAX][MAX] , int n ){
  
  int a[MAX][MAX];
  
  for( int i = 0 ; i < n ; i++ ){
    a[0][i] = ( c[0][i] == '*' ) ? 0 : 1;
    a[i][0] = ( c[i][0] == '*' ) ? 0 : 1;
  }
  
  int ans = 0;
  for( int i = 1 ; i < n ; i++ ){
    for( int j = 1 ; j < n ; j++ ){
      if( c[i][j] == '*' ) a[i][j] = 0;
      else{
	// a[i][j - 1] a[i - 1][j - 1] a[i - 1][j]
	// の３つうち最も小さいものを選び+1する
	a[i][j] = min( a[i - 1][j - 1] , min( a[i - 1][j] , a[i][j - 1] ) ) + 1;
	ans = max( ans , a[i][j] );
      }
      //   cout << a[i][j] << " ";      
    }
    //cout << endl;
  }
  return ans;
}
int main(void){
  
  char c[MAX][MAX];
  int n;
  
  while( cin >> n , n ){

    for( int i = 0 ; i < n ; i++ )
      for( int j = 0 ; j < n ; j++ )
	cin >> c[i][j];  // 読み込み
    
    cout << compute( c , n ) << endl;
  }
  return 0;
}

Measured memory_bytes: 6040
n,a,b,c,*l=`dd`.split.map &:to_i
r=1e9
[*0...4].repeated_permutation(n){|s|
	x=0,0,0
	m=0
	n.times{|i|
		s[i]<3&&(x[s[i]]>0&&m+=10; x[s[i]]+=l[i])
	}
	if x&[0]==[]
		r=[r,m+(x[0]-a).abs+(x[1]-b).abs+(x[2]-c).abs].min
	end
}
p r

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<char> v;
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    v.push_back(s[i]);
  }
  sort(v.begin(), v.end());
  if (v[0] == v[1] && v[2] == v[3] && v[0] != v[2]) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

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

int n, m, c, tmp, cnt;
int a[20][20], b[20];


int main(){

	cin >> n >> m >> c;

	for (int i = 0; i < m; i++)cin >> b[i];

	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			tmp += a[i][j] * b[j];
		}
		if (tmp + c > 0)cnt++;
		tmp = 0;
	}
	cout << cnt << endl;

	return 0;
}

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

#pragma GCC optimize ("-O2")
#define ll long long
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define testcase(t) int t;cin>>t;while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define what_is(x)  cerr << #x << " is " << x << endl;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

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

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

int main(){

	IOS;

	ll k, ans=0;
	cin>>k;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int x=1;x<=k;x++){
				ans+=(gcd(i,gcd(j,x)));
			}
		}
	}

	cout<<ans<<endl;






	return 0;
}
 
/*

*/









Measured memory_bytes: 3620
#include<iostream>
#include<numeric>
using namespace std;
int main(){
int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  // result 
  cout << accumulate(arr,arr+n,-n)<<'\n';

	return 0;
}

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

vector<vector<int>> G(1e5+5);
vector<int> df(1e5+5,-1),ds(1e5+5,-1);

void bfs(int r,vector<int> &d) {
  queue<int> Q;
  Q.push(r);
  d[r]=0;
  int u;
  while(!Q.empty()) {
    u=Q.front(); Q.pop();
    for(auto next:G[u]) {
      if(d[next]==-1) {
        Q.push(next);
        d[next]=d[u]+1;
      }
    }
  }
}

int main() {
  int f=0,s=0;
  int a,b;
  int n; cin>>n;
  for(int i=0;i<n-1;i++) {
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bfs(1,df);
  bfs(n,ds);
  
  for(int i=1;i<=n;i++) {
    if(df[i]<=ds[i]) f++;
    else s++;
  }
  if(f>s) cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;
ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) return mod_pow(x * x % MOD, n / 2) % MOD;
    else return x * mod_pow(x, (n - 1)) % MOD;
}
ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;
    ll ret = 1;
    while (n) if (n & 1) ret = ret * x % MOD; x = x * x % MOD; n /= 2;
    return ret;
}
ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) ret *= (i + 1); ret %= MOD;
    return ret;
}
ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);
    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    int s, w;
    cin >> s >> w;
    bool ret = false;
    if (s > w) ret = true;
    if (ret) cout << "safe";
    else cout << "unsafe";
}

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

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//けんちょん写経
int main(){
ll N; cin >> N;
  vector<ll> A(N); vector<ll> sum(N+1);  sum[0] = 0LL;
  for(ll i = 0; i < N; i++){ cin >> A[i]; sum[i+1] = sum[i] + A[i];} 
  ll res = 1LL << 60;
  
  for(ll i = 0LL; i <= N; i++){ 
    //しきりiはA[i-1]とA[i]との間にある
    ll left = 0LL; ll right = i;
    while( right - left > 1){
      ll mid = left + (right-left)/2;
      if(sum[mid] >= sum[i] - sum[mid]){ //左側が大き過ぎた
        right = mid;}
      else{ left = mid;}
    }
      ll P,Q;
      ll P1 = min(sum[left],sum[i]-sum[left]); 
      ll Q1 = max(sum[left],sum[i]-sum[left]);
      ll P2 = min(sum[right],sum[i]-sum[right]);
      ll Q2 = max(sum[right],sum[i]-sum[right]);
      
      if( Q1-P1 <= Q2-P2){ P = P1; Q = Q1;}
      else{ P = P2; Q = Q2;}
      
      left = i; right = N;
         
      while(right - left > 1){
        ll mid = left + (right-left)/2;
        if( sum[mid] - sum[i] >= sum[N]-sum[mid]){ right = mid;}
        else{ left = mid;}
      }
      
      ll R,S; 
      ll R1 = min(sum[left]-sum[i],sum[N]-sum[left]);
      ll S1 = max(sum[left]-sum[i],sum[N]-sum[left]);
      ll R2 = min(sum[right]-sum[i], sum[N]-sum[right]);
      ll S2 = max(sum[right]-sum[i], sum[N]-sum[right]);
      
      if(S1-R1 <= S2-R2){ R = R1; S = S1;}
      else{ R = R2; S = S2;}
      
      ll M = max(Q,S); ll m = min(P,R);
      ll tmp = M-m;
      res = min(res, tmp);
    }
    
    cout << res << endl; return 0;}
      
                 

Measured memory_bytes: 3328
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args){
		try(Scanner scan = new Scanner(System.in)){
			String S = scan.nextLine();
			
			int max = (int) Math.pow(2,S.length()-1);
			long ans = 0;
			
			for(int bit = 0; bit<max; bit++){
				int left = 0;
				for(int i = 0; i < S.length()-1; i++){
					if( ((bit >> i) & 1) > 0){
						ans += Long.valueOf(S.substring(left, i+1));
						left = i+1;
					}
				}
				ans+=Long.valueOf(S.substring(left, S.length()));
			}
			
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 21076
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];
    auto us = new int[][](H, W);
    auto ds = new int[][](H, W);
    auto ls = new int[][](H, W);
    auto rs = new int[][](H, W);
    foreach (i; 0..H) {
        foreach (j, c; readln.chomp) if (c == '#') {
            us[i][j] = -1;
            ds[i][j] = -1;
            ls[i][j] = -1;
            rs[i][j] = -1;
        }
    }
    foreach (i; 0..H) {
        foreach (j; 0..W) {
            if (i+1 < H && ds[i+1][j] != -1) ds[i+1][j] = ds[i][j] + 1;
            auto ii = H-i-1;
            if (ii-1 >= 0 && us[ii-1][j] != -1) us[ii-1][j] = us[ii][j] + 1;

            if (j+1 < W && rs[i][j+1] != -1) rs[i][j+1] = rs[i][j] + 1;
            auto jj = W-j-1;
            if (jj-1 >= 0 && ls[i][jj-1] != -1) ls[i][jj-1] = ls[i][jj] + 1;
        }
    }
    int r;
    foreach (i; 0..H) foreach (j; 0..W) if (us[i][j] != -1) r = max(r, us[i][j] + ds[i][j] + ls[i][j] + rs[i][j] + 1);
    writeln(r);
}

Measured memory_bytes: 67324
from fractions import gcd
import sys
sys.setrecursionlimit(4100000)

def os(): return input()
def oi(): return int(input())
def oli(): return map(int, input().split())
def olai(): return list(map(int, input().split()))
def olas(): return list(input().split())
def mlai(L): return [int(input()) for _ in range(L)]
def mlas(L): return [input() for _ in range(L)]
def ar(a, b, c=-1, d=-1, INIT=0):
    if(c==-1): return [[INIT]*b for _ in range(a)]
    if(d==-1): return [[[INIT]*c for _ in range(b)] for __ in range(a)]
    return [[[[INIT]*d for _ in range(c)] for __ in range(b)] for ___ in range(a)]

def lcm(a, b): return (a*b)//gcd(a, b)
#MOD
P = 10**9 + 7
N = 200001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2, N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b or b < 0: return 0 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P

#-------------------------------------------------------------------
#全方位木dpで扱うクラス
class T:
    num = 1
    child = 0

    def __init__(self, a, b):
        self.num = a
        self.child = b

#零元
zero = T(1, 0)
#一個遷移した時の変化
def step(x):
    return T(x.num, x.child+1)
#マージ
def merge(x, y):
    if(x.num==-1): return y
    if(y.num==-1): return x
    return T((x.num*y.num*comb(x.child+y.child, x.child))%P, x.child+y.child)

G = [[] for _ in range(200001)]
down_data = [zero for _ in range(200001)]
dat = [zero for _ in range(200001)]

def dfs(now, parent):
    cnt = 0
    for to in G[now]:
        if(to==parent): continue
        cnt += 1
        dfs(to, now)
        down_data[now] = merge(down_data[now], step(down_data[to]))

def dfs_rev(now, parent, rev):
    #累積
    left = []
    right = []
    cnt = 0
    for to in G[now]:
        if(to==parent): continue
        if(len(left)==0): left.append(step(down_data[to]))
        else: left.append(merge(left[cnt-1], step(down_data[to])))
        cnt += 1
    cnt = 0
    for to in reversed(G[now]):
        if(to==parent): continue
        if(len(right)==0): right.append(step(down_data[to]))
        else: right.append(merge(right[cnt-1], step(down_data[to])))
        cnt += 1
    cnt = 0
    dat[now] = merge(rev, down_data[now])

    for to in G[now]:
        if(to==parent): continue
        x = zero if cnt==0 else left[cnt-1]
        y = zero if cnt==len(right)-1 else right[len(right)-2-cnt]
        dfs_rev(to, now, step(merge(rev, merge(x, y))))
        cnt += 1
#-------------------------------------------------------------------
def main():
    n = oi()
    for i in range(n-1):
        a, b = oli()
        G[a].append(b)
        G[b].append(a)
    root = -1
    for i in range(1, n+1):
        if(len(G[i]) == 1):
            root = i
            break
    dfs(root, -1)
    dfs_rev(root, -1, zero)
    for i in range(1, n+1):
        print(dat[i].num)

if __name__ == "__main__": main()


Measured memory_bytes: 147256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
#define min(a,b) ((a) < (b) ? (a) : (b))
using namespace std;

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

struct Point{
	int x,y; Point(){}
	Point(int x,int y): x(x),y(y){}
}s;

int n,m,K,Ans,dis[N][N];
char p[N][N]; bool vis[N][N];

queue <Point> Q;

inline void Check(Point g)
{
	int now = min(min(g.x - 1,n - g.x),min(g.y - 1,m - g.y));
	now = now % K == 0 ? now / K : now / K + 1; Ans = min(Ans,now);
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n >> m >> K; Ans = n * m;
	for (int i = 1; i <= n; i++)
	{
		scanf("%s",p[i] + 1);
		for (int j = 1; j <= m; j++)
			if (p[i][j] == 'S') s = Point(i,j);
	}
	Q.push(s); vis[s.x][s.y] = 1;
	while (!Q.empty())
	{
		Point k = Q.front(); Q.pop(); Check(k);
		if (dis[k.x][k.y] == K) continue;
		for (int i = 0; i < 4; i++)
		{
			int xx = k.x + dx[i],yy = k.y + dy[i];
			if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
			if (p[xx][yy] == '#' || vis[xx][yy]) continue;
			dis[xx][yy] = dis[k.x][k.y] + 1; vis[xx][yy] = 1; Q.push(Point(xx,yy));
		}
	}
	cout << Ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<b; i++)
#define REP(i, n)    for(int i=0; i<(n); i++)
#define REP_R(i, n)    for(int i=n-1; i>(-1); i--)
#define fst first
#define pb push_back
#define mp make_pair
#define ALL(obj) (obj).begin(), (obj).end()
using ul = unsigned long;
using ll = long long;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;

ll x, y, z;
ll k;

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

  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  REP(i, x) cin >> a[i];
  REP(i, y) cin >> b[i];
  REP(i, z) cin >> c[i];

  ll num = min(x*y, k);
  vector<ll> sum(x*y);
  ll l=0;
  REP(i, x){
    REP(j, y){
      sum[l] = a[i]+b[j];
      l++;
    }
  }
  sort(sum.rbegin(), sum.rend() );
//  REP(i, x*y) cout << sum[i] << endl;
//  cout << "\n";
  l=0;
  vector<ll> ans(num*z);
  REP(i, num){
    REP(j, z){
      ans[l] = sum[i]+c[j];
      l++;
    }
  }
  sort(ans.rbegin(), ans.rend() );
  REP(i, k) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <sstream>
#include <iterator>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <cmath>

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)

using namespace std;

long long GCD(long long x, long long y) {
	return y ? GCD(y, x % y) : x;
}

long long LCM(long long x, long long y) {
	return x * y / GCD(x, y);
}

double sqdist(int x1, int y1, int x2, int y2) {
	return pow(x1 - x2, 2) + pow(y1 - y2, 2);
}

double dist(int x1, int y1, int x2, int y2) {
	return sqrt(sqdist(x1, y1, x2, y2));
}

int Main() {
	int ans = 0;
	int a, b, c;

	scani(a);
	scani(b);
	scani(c);

	printi(c);
	printf(" ");
	printi(a);
	printf(" ");
	printi(b);



	return 0;
}

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


Measured memory_bytes: 256
while True:
    a=sorted(list(map(int,input().split())))
    if sum(a)==0:
        break
    s=min(a[0]**2+a[1]**2,a[1]**2+a[2]**2,a[0]**2+a[2]**2)
    n=int(input())
    for i in range(n):
        r=int(input())
        print("OK" if (r*2)**2>s else "NA")


Measured memory_bytes: 5588
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
	int m,n,t = 0;
	cin>>m>>n;
	if(m>1)
		while(m>1)
		{
			m--;
			t+=m;
		}
	if(n>1)
		while(n>1)
		{
			n--;
			t+=n;
		}	
	cout<<t<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int min(int a, int b) {
  return a < b ? a : b;
}

int main() {
  int n, p[N + 1], m[N + 1][N + 1];
  int i, j , k, l;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &p[i - 1], &p[i]);
  }

  for (i = 1; i <= n; i++) {
    m[i][i] = 0;
  }
  for(i = 2; i <= n; i++) {
    for (j = 1; j <= n - i + 1; j++) {
      l = i + j - 1;
      m[j][l] = 100000000;
      for (k = j; k <= l - 1; k++) {
        m[j][l] = min(m[j][l], m[j][k] + m[k + 1][l] + p[j - 1] * p[k] * p[l]);
      }
    }
  }
  printf("%d\n", m[1][n]);

  return 0;
}



Measured memory_bytes: 2100
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define INF 1200000000


int main(){
    
    long long H,tot,atcnt;//atcntは指数
    cin>>H;
    H=H/2;
    tot=1;
    atcnt=1;
    while(H!=0){
        tot+=pow(2,atcnt);
        atcnt++;
        H=H/2;
    }
    
    cout<<tot<<endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
  int N; 
  cin>>N;
  for(ll h=1;h<=3500;h++){
    for(ll n=2;n<=3500;n++){
      ll tmp1=h*N*n;
      ll tmp2=4*h*n-N*(h+n);
       if(tmp2>0&&(tmp1%tmp2)==0){
        cout<<h<<" "<<n<<" "<<tmp1/tmp2<<endl;
        return 0;
       }
    }
  }
  return 0;
}

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

int main (){
    /*
    int N, M;    // N個の商品から人気商品M個を選ぶ
    cin >> N >> M;

    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    sort(A.begin(), A.end());   // Aを大きい順にソート
    reverse(A.begin(), A.end()); 

    bool hantei = true;
    int A_sum = 0;

    for(int i = 0; i < N; i++){
        A_sum += A.at(i);
    }

    if(A.at(M-1) < A_sum * 1 / (4 * M)){
        hantei = false;
    }

    if(hantei == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    */

   int N, M;
   cin >> N >> M;

   vector<int> A(N);
   double A_sum;

   for(int i = 0; i < N; i++){
       cin >> A.at(i);
       A_sum += A.at(i);
   }

   sort(A.begin(), A.end());
   reverse(A.begin(), A.end());

   bool hantei;

   if(A.at(M-1) < A_sum / (4 * M)){
       hantei = false;
   }else{
       hantei = true;
   }

    if(hantei == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	int cnt=0;
	for(int i=0;i<a.size();i++){
		if(a[i]=='C'){
			cnt=1;
		}
		if(a[i]=='F'&&cnt==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
a = []
b = []
for i in range(5):
    a.append(int(input()))
k = int(input())
for i in range(len(a)):
    for j in range(len(a)):
        ans = abs(a[i] - a[j])
        b.append(ans)
        
for i in b:
    if k < i:
        print(":(")
        exit()
print('Yay!')

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) throws IOException {

BufferedReader br =new BufferedReader (new InputStreamReader (System.in));

String line = br.readLine( );
int a = Integer.parseInt(line);

System. out. println(800*a-a/15*200);

}}

Measured memory_bytes: 21332
def main():
    while True:
        n = int(input())
        if n:
            aa,ba = 0,0
            a,b = [None]*n,[None]*n
            for i in range(n):
                a[i],b[i] = map(int, input().split())
                if a[i] > b[i]:
                    aa += (a[i]+b[i])
                elif a[i] < b[i]:
                    ba += (a[i]+b[i])
                else:
                    aa += a[i]
                    ba += b[i]
            print(aa,ba)
        else:
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 7916