akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

string a1="dream";
string a2="erase";
string a3="eraser";
string a4="dreamer";

int main(){fastio
    string s;cin>>s;
    ll n=s.size();
    bool dp[n+1];memset(dp,0,sizeof(dp));
    dp[0]=true;
    rep(i,1,n){
        if(i-5>=0&&dp[i-5]){
            bool f=true;
            rep(j,i-4,i){
                if(s[j-1]!=a1[j-i+4])f=false;
            }
            if(f)dp[i]=true;
            f=true;
            rep(j,i-4,i){
                if(s[j-1]!=a2[j-i+4])f=false;
            }
            if(f)dp[i]=true;
        }
        if(i-6>=0&&dp[i-6]){
            bool f=true;
            rep(j,i-5,i){
                if(s[j-1]!=a3[j-i+5])f=false;
            }
            if(f)dp[i]=true;
        }
        if(i-7>=0&&dp[i-7]){
            bool f=true;
            rep(j,i-6,i){
                if(s[j-1]!=a4[j-i+6])f=false;
            }
            if(f)dp[i]=true;
        }
    }
    //rep(i,0,n)cout<<dp[i]<<" ";cout<<endl;
    
    if(dp[n])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

LL a[mx2];

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

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

        if(i){
            LL x = __gcd(a[i], a[i - 1]);
            a[i] /= x;
            a[i] *= a[i - 1];
        }
    }

    cout << a[n - 1] << '\n';
    return 0;
}


Measured memory_bytes: 3588
package main

import "fmt"

func main() {
	var N int
	fmt.Scanln(&N)
	var S string
	fmt.Scanln(&S)
	
	Sbar := ""
	for _, r := range S { // here r -> rune
		n := N
		for n != 0 {
			r++
			n--
		}
		if r > 90 {
			extra := r - 90
			r = 64 + extra
		}
		Sbar = Sbar + string(r)
	}
	fmt.Println(Sbar)
}

Measured memory_bytes: 6528
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,x,a,b,c,d;
int main(){
	scanf("%d%d%d%d%d%d%d",&a,&b,&x,&c,&d,&x,&x);
	if(a&&c&&d)n=!(a%2==c%2&&c%2==d%2);
	else n=a%2+c%2+d%2;
	printf("%lld\n",1ll*a+b+c+d-n);
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll arr[200005], arrDif[200005] ;

int main()
{
    ll k, n, val, ans = 0 ;
    cin >> k >> n ;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &arr[i]) ;
    }
    sort(arr, arr + n) ;
    for (int i = 1; i < n; i++) {
        arrDif[i - 1] = arr[i] - arr[i - 1] ;
    }
    arrDif[n - 1] = (k - arr[n - 1]) + arr[0] ;
    sort(arrDif, arrDif + n) ;
    for (int i = 0; i < n - 1; i++) {
        ans += arrDif[i] ;
    }

    cout << ans ;
    return 0 ;
}


Measured memory_bytes: 3328
n,m = map(int,input().split())
trap = [False for i in range(n+1)]
for i in range(m):
  trap_num = int(input())
  trap[trap_num - 1] = True

dp = [0 for i in range(n+1)]
dp[0] = 1 
if trap[0] == True:
  dp[1] = 0
else:  
  dp[1] = 1
for i in range(2,n+1):
  if trap[i-1] == True:
    dp[i] = 0
  else:
    dp[i] = dp[i-1] + dp[i-2]
    
    
print(dp[-1] % (10**9 + 7))
    
    
  
  

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

int main() {
   int A, B, C, D;
   cin >> A >> B >> C >> D;
   int L = A+B;
   int R = C+D;

   if( L>R ){
   cout << "Left" << endl;
 }
 else if (R>L){
   cout << "Right" << endl;
 }
 else{
   cout << "Balanced" << endl;
 }
}


Measured memory_bytes: 256
import numpy as np

if __name__ == "__main__":
	N,K = map(int,input().split())
	P = [ int(p)-1 for p in input().split() ]
	C = list(map(int,input().split()))
	cycleIDs = np.full( N, -1, np.int64 )
	cycleInfs = []
	cycleID = 0
	procCnt = 0
	for n in range(N):
		v = n
		if cycleIDs[v] != -1:
			continue
		else:
			currentCycleCosts = []
			while True:
				currentCycleCosts.append( C[v] )
				cycleIDs[v] = cycleID

				v = P[v]
				if cycleIDs[v] != -1:
					procCnt = K % len( currentCycleCosts )
					if len( currentCycleCosts ) + procCnt <= K:
						procCnt += len( currentCycleCosts )
					cycleInfs.append( ( procCnt, len(currentCycleCosts), np.array( currentCycleCosts + currentCycleCosts ) ) )
					cycleID += 1
					break
	ans = -10 ** 9
	for procCnt, currentCycleSize, currentCycleCosts in cycleInfs:
		loopScore = 0
		if np.sum(currentCycleCosts) > 0:
			cycleLoopCnt =  ( K - procCnt ) // currentCycleSize
			loopScore = cycleLoopCnt * np.sum(currentCycleCosts[:currentCycleSize])

		for i in range(currentCycleSize):
			ans = max( ans, np.roll( currentCycleCosts, i ).cumsum()[:procCnt].max() + loopScore )

	print(ans)


Measured memory_bytes: 28240
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
  
    ll k,i,j;
    cin>>k>>i;
    ll ha = 1,ans=0;
    for(i=1;i<=(5*k+10);i++){
    	ans = (ans + (7 * ha)%k)%k;
    	ha = (ha * 10)%k;
    	if(ans==0)
    	{
    		cout<<i;
    		return 0;
    	}
    }
    cout<<"-1";

}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,d;
    cin >> n >> d;
    cout << (n + 2 * d) / (2 * d + 1) << endl;
    return 0;
}

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

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

  double ans{};
  for (int i{}; i < N; ++i) {
    int A; cin >> A;
    ans += 1.0 / A;
  }

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


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <math.h>           // fabs()
#include <stdbool.h>

int
main(int argc, char **argv)
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		int mp = n;
		double mbmi = 200.0;
		for (int i = 0; i < n; ++i)
		{
			int p, h, w;
			scanf("%d%d%d", &p, &h, &w);
			double m = h / 100.0;
			double rbmi = fabs(w / (m * m) - 22.0);
			if (rbmi < mbmi)
			{
				mbmi = rbmi;
				mp = p;
			}
			else if (rbmi == mbmi && p < mp)
				mp = p;
		}

		printf("%d\n", mp);
	}

	return 0;
}


Measured memory_bytes: 1724
import java.util.Scanner;

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

		Scanner scanner = new Scanner(System.in);

		scanner.hasNext();

		double r = scanner.nextDouble();

		double circle = r * r * Math.PI;

		double ans2 = 2 * Math.PI * r;

		String circleAreaAns = String.format("%.6f", circle);

		String lengthCircumference = String.format("%.6f", ans2);

		System.out.print(circleAreaAns + " ");

		System.out.println(lengthCircumference);

	}
}

Measured memory_bytes: 18920
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
#define NON string::npos
int main(){
  int n;
  (cin >> n).ignore();
  while(n--){
    string str;
    getline( cin, str);
    for(int i = 0 ; i < 26 ; i++ ){
      for(int j = 0 ; j < 26 ; j++ ){
        string ret = str;
        for(int k = 0 ; k < ret.size() ; k++ ){
          if(islower(ret[k])) ret[k] = ((ret[k] - 'a') * i + j) % 26 + 'a';
        }
        if(ret.find("that") != NON || ret.find("this") != NON){
          cout << ret << endl;
          i = j = 27;
        }
      }
    }
  }
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,m;
ll x[125252];
pair<pii,int> es[125252];

int dat[125252];
ll sumx[125252];
int maxeid[125252];

vector<pii> datUpd[125252], maxUpd[125252];
vector<pll> sumxUpd[125252];

int root(int x){
  return dat[x] < 0 ? x : root(dat[x]);
}
void unite(int t, int a, int b, int y){
  a = root(a); b = root(b);
  if(a != b){
    if(dat[a] > dat[b])swap(a,b);
    datUpd[t].push_back(pii(a,dat[a]));
    datUpd[t].push_back(pii(b,dat[b]));
    sumxUpd[t].push_back(pll(a,sumx[a]));
    dat[a] += dat[b];
    dat[b] = a;
    sumx[a] += sumx[b];
    if(maxeid[a]==-1 || (maxeid[b]!=-1 && es[maxeid[a]].second <= es[maxeid[b]].second)){
      maxUpd[t].push_back(pii(a,maxeid[a]));
      maxeid[a] = maxeid[b];
    }
  }
  if(maxeid[a]==-1 || es[maxeid[a]].second <= y){
    maxUpd[t].push_back(pii(a,maxeid[a]));
    maxeid[a] = t;
    reverse(ALL(maxUpd[t]));
  }
}

int main(){
  scanf("%d%d",&n,&m);
  REP(i,n)scanf("%lld",x+i);
  REP(i,m){
    int a,b,y;
    scanf("%d%d%d",&a,&b,&y); --a; --b;
    es[i] = make_pair(pii(a,b),y);
  }
  sort(es,es+m,[&](pair<pii,int> a, pair<pii,int> b){return a.second < b.second;});
  fill(dat,dat+n,-1);
  REP(i,n)sumx[i] = x[i];
  fill(maxeid,maxeid+n,-1);
  REP(i,m){
    unite(i,es[i].first.first,es[i].first.second,es[i].second);
    // REP(j,n)printf("%d%c",dat[j]," \n"[j==n-1]);
    // REP(j,n)printf("%lld%c",sumx[j]," \n"[j==n-1]);
    // REP(j,n)printf("%d%c",maxeid[j]," \n"[j==n-1]);
  }
  int ans = 0;
  stack<int> S;
  S.push(root(0));
  while(S.size()){
    int r = S.top(); S.pop();
    if(maxeid[r]==-1 || es[maxeid[r]].second <= sumx[r])continue;
    ans++;
    // revert
    int t = maxeid[r];
    int a = es[t].first.first;
    int b = es[t].first.second;
    // DEBUG(t);
    // DEBUG(a);
    // DEBUG(b);
    // DEBUG(es[t].second);
    for(pii P : datUpd[t]){
      dat[P.first] = P.second;
    }
    for(pll P : sumxUpd[t]){
      sumx[P.first] = P.second;
    }
    for(pii P : maxUpd[t]){
      maxeid[P.first] = P.second;
    }
    // REP(i,n)if(i==root(i)){
    //   printf("%d: %lld, %d\n",i,sumx[i],maxeid[i]);
    // }
    // REP(j,n)printf("%d%c",dat[j]," \n"[j==n-1]);
    // REP(j,n)printf("%lld%c",sumx[j]," \n"[j==n-1]);
    // REP(j,n)printf("%d%c",maxeid[j]," \n"[j==n-1]);
    // REP(j,n)DEBUG(dat[j]);
    // REP(j,n)DEBUG(sumx[j]);
    // REP(j,n)DEBUG(maxeid[j]);
    if(root(a) != root(b)){
      S.push(root(a));
      S.push(root(b));
    }else{
      S.push(root(a));
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 22784
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
    int n, m, c;
    cin >> n >> m >> c;
    int b[m];
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }

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

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int count[];
		int ans[];
		Scanner scanner = new Scanner(System.in);
		
		count = new int[100];
		ans = new int[100];
		
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		while(n != 0 || m != 0) {
			for(int i = 0; i < m; i++) {
				count[i] = 0;
				ans[i] = i + 1;
			}
			
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < m; j++) {
					int wish = scanner.nextInt();
					if(wish == 1) {
						count[j]++;
					}
				}
			}
			
			for(int i = 1; i < m; i++) {
				int j = i;
				while ((j > 0) && (count[j - 1] < count[j])) {
					int a = count[j - 1];
					count[j - 1] = count[j];
					count[j] = a;
						
					a = ans[j - 1];
					ans[j - 1] = ans[j];
					ans[j] = a;
						
					j--;
				}
			}
			
			System.out.print(ans[0]);
			for(int i = 1; i < m; i++) {
				System.out.print(" " + ans[i]);
			}
			System.out.println();
			
			n = scanner.nextInt();
			m = scanner.nextInt();
		}
	}
}

Measured memory_bytes: 68856
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    a, b = na[0], na[1]

    r = b - a
    t = 0
    for i in range(1, r + 1):
        t += i
    t -= b

    print(t)


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    double a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f){
        double x,y;
        x=(c-b*(a*f-c*d)/(a*e-b*d))/a;
        y=(a*f-c*d)/(a*e-b*d);
        printf("%.3f %.3f\n",x,y);
    }
}

Measured memory_bytes: 1236
/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.08.25
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int x[maxn];

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i = 0; i < n; i++) scanf("%d",x + i);
	int ans = INF;
	for(int i = 0; i <= n - k; i++) {
		int j = i + k - 1;
		int li = abs(x[i]);
		int lj = abs(x[j]);
		if(x[j] <= 0) ans = min(ans,li);
		else if(x[i] >= 0) ans = min(ans,lj);
		else ans = min(ans,min(2 * li + lj,li + 2 * lj));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
#! /usr/bin/python

if __name__ == "__main__":
	n = int(raw_input())
	array = map(int, raw_input().split())
	for i in range(1, n):
		print " ".join(map(str, array))
		key = array[i]
		j = i - 1 
		while j >= 0 and array[j] > key:
			array[j+1] = array[j]
			j -= 1
		array[j+1] = key

	print " ".join(map(str, array))

Measured memory_bytes: 4220
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          string s = Input.ScanStr();
          if(s.Length==2)
            Console.WriteLine(s);
          else
            Console.WriteLine($"{s[2]}{s[1]}{s[0]}");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <string>
#include <list>

using namespace std;

#define CVector CPoint
typedef long long LL;
typedef unsigned long long ULL;

const LL mod=1e9+7;
const double PI=acos(-1);
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}

int a[100005];

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int n,k;cin>>n>>k;
    bool fg=false;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int a0=a[1];
    for(int i=1;i<=n;i++){
        a0=__gcd(a[i],a0);
    }
    for(int i=1;i<=n;i++){
        if(a[i]>=k&&!((a[i]-k)%a0)){
            fg=true;
            break;
        }
    }
    cout<<(fg?"POSSIBLE":"IMPOSSIBLE")<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define N 100010
using namespace std;

ll f[N],g[N],a[N];
char op,lst;

int main(){
	int n,x,y=0,i,cnt=0;
	cin>>n;
	ll ans=0;
	for(i=1;i<=n;++i){
		cin>>x;lst=op;
		if(i<n) cin>>op;
		if(lst=='-'){
			x=-x;
			a[++cnt]=x;
		}
		if(y<=0 && x>0) cnt++,a[cnt]=x;
		if(y>0 && x>0) a[cnt]+=x;
		y=x;
	} f[1]=a[1];
	for(i=cnt;i>=1;--i) g[i]=g[i+1]+abs(a[i]);
	for(i=2;i<=cnt;++i) f[i]=f[i-1]+a[i];
	ans=f[cnt];
	for(i=1;i<cnt;++i)
		if(a[i+1]<0) ans=max(ans,f[i+1]-a[i+2]+g[i+3]);
 	cout<<ans; 
} 

Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split()))
ans = 0
pre = 0

for i in range(n-1):
    if a[i] == a[i+1]:
        if pre != 1:
            pre = 1
            ans += 1
        else:
            pre = 0
    else:
        pre = 0

print(ans)

Measured memory_bytes: 3060
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,m,x = map(int,readline().split())
lst1 = []
for i in range(n):
    lst1.append(list(map(int,readline().split())))
ans = 10**12
for i in range(1<<n):
    res = [0]*m
    cost = 0
    for j in range(n):
        if i>>j&1:
            cost += lst1[j][0]
            for idx,k in enumerate(lst1[j][1:]):
                res[idx] += k


    if min(res) >= x:
        ans = min(ans,cost)

print(ans if ans != 10**12 else -1)

Measured memory_bytes: 68620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,a,zero=0; cin>>N;
  vector<vector<ll>>keep(3,vector<ll>(2,-1));
  bool finish=false;
  for(int i=0; i<N; i++){
    cin>>a;
    if(a==0){
      zero++;
      continue;
    }
    for(int j=0; j<3; j++){
      if(keep[j][0]==-1){
        keep[j][0]=a;
        keep[j][1]=1;
        break;
      }
      if(keep[j][0]==a){
        keep[j][1]++;
        break;
      }
      if(j==2) finish=true;
    }
    if(finish){
      cout<<"No"<<endl;
      return 0;
    }
  }
  
  if(zero==N){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(N%3==0){
    ll z=N/3;
    if(zero==z && keep[0][1]==2*z){
      cout<<"Yes"<<endl;
      return 0;
    }
    if(zero==0){
      if(keep[0][1]==z && keep[1][1]==z && keep[2][1]==z){
        if(((keep[0][0]^keep[1][0])^keep[2][0])==0){
          cout<<"Yes"<<endl;
          return 0;
        }
      }
    }
  }     
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    int maxi=0; int mini=INF;
    rep(i,n){
        int temp;cin>>temp;
        cmax(maxi,temp);
        cmin(mini,temp);
    }
    cout<<maxi-mini<<endl;
}

Measured memory_bytes: 256
#define LOCAL0
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    #ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    ll x;
    cin>>x;
    ll now=100;
    ll ans=0;
    for(;now<x;ans++){
        ll t=floor((double)now*0.01);
        now+=t;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3740
#include <stdio.h>

#define N 100

int main()
{

  int i, j, A[N], n, minj, tmp, count = 0;

  scanf("%d", &n);

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

  for(i=0; i<=n-1; i++){
    minj = i;
    for(j=i; j<=n-1; j++){
      if(A[j] < A[minj]) minj = j;
    }
    if(A[i]>A[minj]){
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    count++;
    }
  }

  for(j=0; j<n-1; j++){
    printf("%d ", A[j]);
  }

  printf("%d", A[n-1]);
  printf("\n");
  printf("%d\n", count);

  return 0;
}

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

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

    int cnt = 0;
    for(int i = 1; i <= n; i += 2){
        cnt++;
    }
    if(cnt >= k){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, sum, k, q;
int aru[1000000 + 10];

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

  cin >> n;
  rep(i, n) cin >> a[i], aru[a[i]]++;
  rep(i, n) {
    vector<ll> y = divisor(a[i]);
    int ok = 1;
    rep(j, Size(y) - 1) {
      // debug(y[j]);
      if (aru[y[j]]) ok = 0;
    }
    if (!ok) continue;
    if (aru[a[i]] >= 2) continue;
    ans++;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 8984
s,t = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a = a1-b1
b = a2-b2
if a*b>0:print(0);exit()
if abs(a)*s ==abs(b)*t:print('infinity');exit()
elif abs(a)*s >abs(b)*t:print(0);exit()
if (abs(a)*s)%(abs(b)*t-abs(a)*s):
    print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*2+1)
else:
    print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*2)


Measured memory_bytes: 61932
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		double r = scanner.nextDouble();
		double pi = 3.14159265359;
		System.out.printf("%1$.6f %2$.6f", pi*r*r, 2*r*pi);
	}
}

Measured memory_bytes: 28148
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()

def main():
	x = int(rl())
	for a in range(-200, 201):
		for b in range(-200, 201):
			if a**5-b**5 == x:
				ans = " ".join([str(a), str(b)])
				stdout.write(ans);stdout.write("\n")
				stdout.close()
				return 

if __name__ == "__main__":
	main()

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string n;
	cin >> n;

	string rn = n;
	reverse(rn.begin(), rn.end());
	cout << (n == rn ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') ++cnt;
    else --cnt;
  }
  if (cnt > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
c = [[0] * 3 for _ in range(3)]


for i in range(3):
    c[i] = list(map(int, input().split()))

a = [0] * 3
b = [0] * 3

a[0] = 0

b[0] = c[0][0] - a[0]
b[1] = c[0][1] - a[0]
b[2] = c[0][2] - a[0]
a[1] = c[1][0] - b[0]
a[2] = c[2][0] - b[0]

flag = True
for i in range(3):
    for j in range(3):
        if c[i][j] == a[i] + b[j]:
            pass
        else:
            flag = False


if flag:
    print('Yes')
else:
    print('No')


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

const double INF = 1e9;

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

    //1:increase, 2:decrease, 3:const
    double right1 = -INF, right2 = -INF, right3 = -INF;
    double left1 = INF, left2 = INF, left3 = INF;
    double up1 = -INF, up2 = -INF, up3 = -INF;
    double down1 = INF, down2 = INF, down3 = INF;

    for (int i = 0; i < n; i++) {
        double x, y;
        char d;
        cin >> x >> y >> d;

        if (d == 'R') {
            right1 = max(x, right1);
            left1 = min(x, left1);
            up3 = max(y, up3);
            down3 = min(y, down3);
        }
        else if (d == 'L') {
            right2 = max(x, right2);
            left2 = min(x, left2);
            up3 = max(y, up3);
            down3 = min(y, down3);
        }
        else if (d == 'U') {
            right3 = max(x, right3);
            left3 = min(x, left3);
            up1 = max(y, up1);
            down1 = min(y, down1);
        }
        else if (d == 'D') {
            right3 = max(x, right3);
            left3 = min(x, left3);
            up2 = max(y, up2);
            down2 = min(y, down2);
        }
    }

    double ans = 1e18;
    for (double t = 0.0; t <= 1e8; t += 0.5) {
        double dx = max({right1 + t, right2 - t, right3}) - min({left1 + t, left2 - t, left3});
        double dy = max({up1 + t, up2 - t, up3}) - min({down1 + t, down2 - t, down3});
        ans = min(ans, dx * dy);
    }

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 384
/*** 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 dp[301][301][301] = {};
string S;

int calc(ll i, ll j, ll k){
    int &res = dp[i][j][k];
    if(~res) return res;
    if(j - i == 0){
        return res = 0;
    }else if(j - i == 1){
        return res = 1;
    }
    res = 0;
    if(S[i] == S[j-1]){
        res = 2 + calc(i+1, j-1, k);
    }else{
        if(k > 0){
            res = 2 + calc(i+1, j-1, k-1);
        }
    }
    res = max(res, calc(i, j-1, k));
    res = max(res, calc(i+1, j, k));
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S;
    ll K;
    cin >> K;
    memset(dp, -1, sizeof(dp));
    ll N = S.size();
    ll ans = calc(0,N,K);
    print(ans);

    

}

Measured memory_bytes: 106752
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    vector<bool> v;

    for (int i = 1; i <= 52; i++) {
        v.push_back(false);
    }

    cin >> n;

    for (int i = 0; i < n; i++) {
        int num;
        char mark;
        cin >> mark >> num;
        switch(mark) {
            case 'S':
                v[num] = true;
                break;
            case 'H':
                v[num+13] = true;
                break;
            case 'C':
                v[num+26] = true;
                break;
            case 'D':
                v[num+39] = true;
                break;
            default:
                break;
        }
    }

    for (int i = 1; i <= 52; i++) {
        if (!v[i]){
            if (i <= 13) {
                cout << "S " << i << endl;
            } else if(i > 13 && i <= 26) {
                cout << "H " << i - 13 << endl;
            } else if(i > 26 && i <= 39) {
                cout << "C " << i - 26 << endl;
            } else if(i > 39) {
                cout << "D " << i - 39 << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1196
use strict;
use utf8;
use warnings;
use POSIX qw/floor/;
use feature qw/say/;

my $a = <>; chomp($a);
my $b = <>; chomp($b);
my $c = <>; chomp($c);
my $d = <>; chomp($d);
my $e = <>; chomp($e);

my @input = ($a, $b, $c, $d, $e);

sub calc_sum {
    # 渡された順番での届く時刻を返す
    my ($arr) = @_;
    my $sum = 0;
    my @new_arr = @$arr[0, 1, 2, 3];
    for (@new_arr) {
        if ($_ % 10 == 0) {
            $sum += $_;
        } else {
            $sum += 10 * ( 1 + floor ($_/10) );
        }
    }
    $sum += $arr->[scalar(@$arr) - 1];
    return $sum;
}

my $ans = 1000000;
for my $i (0..4) {
    for my $j (0..4) {
        next if $j == $i;
        for my $k (0..4) {
            next if $k == $j;
            next if $k == $i;
            for my $l (0..4) {
                next if $l == $k;
                next if $l == $j;
                next if $l == $i;
                for my $m (0..4) {
                    next if $m == $l;
                    next if $m == $k;
                    next if $m == $j;
                    next if $m == $i;
                    my $sum = calc_sum([
                        $input[$i],
                        $input[$j],
                        $input[$k],
                        $input[$l],
                        $input[$m]
                    ]);
                    $ans = $sum if $sum < $ans;
                }
            }
        }
    }
}
say $ans;


Measured memory_bytes: 1920
//Single Source Shortest Path 1
//2019-01-29
//Ebitani Akira

#include <stdio.h>
#include <stdlib.h>

#define N 128
#define MAX 100
#define INF 150000
#define F 1 //firsr
#define S 2 //second
#define Z 0 //zero

void Dijkstr();

int n;
int A[N][N];

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

  scanf("%d", &n);
  if(n < 1 || n > MAX){
    printf("頂点の数が適当ではありません。\n");
    exit(1);
  }
  for(i = 0 ; i < n ; i++){
     for(j = 0 ; j < n ; j++){
       A[i][j] = INF;
     }
  }
  
  for(i = 0 ; i < n ; i++){
    scanf("%d%d", &u, &k);
    for(j = 0 ; j < k ; j++){
      scanf("%d%d", &v, &c);
      if(c < 0 || c >= INF){
	printf("重みが適当では在りません。\n");
	exit(2);
      }
      A[u][v] = c;
    }
  }
  Dijkstr();

  return 0;
}

void Dijkstr (void){
  int min, i;
  int times[N];
  int D[N];
  int u;
  int v;

  for(i = 0 ; i < n ; i++){
      times[i] = Z;
      D[i] = INF;
  }
  D[0] = 0;
  times[0] = F;

  while(1){
    min = INF;
    u = -1;

    for(i = 0 ; i < n ; i++){
      if(min > D[i] && times[i] != S){
	u = i;
	min = D[i];
      }
    }

    if(u == -1){
      break;
    }
    times[u] = S;

    for(v = 0 ; v < n ; v++){
      if(times[v] != S && A[u][v] != INF){
	if(D[v] > D[u] + A[u][v]){
	  D[v] = D[u] + A[u][v];
	  times[v] = F;
	}
      }
    }
  }
  for(i = 0 ; i < n ; i++){
    /* if(D[i] == INF){
      D[i] = -1;
      }*/
    //D[i] = INF ? -1 : D[i];
		   
    printf("%d %d\n", i, D[i]);
  }

}
    



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int h,w,n,bc;
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	bc=max(h,w);
	if(n%bc==0)
	printf("%d",n/bc);
	else printf("%d",n/bc+1);
    return 0;
}

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

#define ll long long
#define F first
#define S second
#define endl '\n'
#define pb push_back

using namespace std;

const ll limit = 266666333332 ;

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

  int k ;
  cin >> k ;
  int sum = 0 ;
  for(int i = 1 ; i <= k ; i++){
    for(int j = 1 ; j <= k ; j++){
      for(int l = 1 ; l <= k ; l++){
        int g = __gcd(i , j) ;
        g = __gcd(g , l) ;
        sum += g ; 
      }
    }
  }
  cout << sum << endl ;
  return 0 ;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> d(N);
	rep(i,N)cin>>d[i];
	sort(all(d));
	print(d);
	int ans = 0;
	if(N%2 == 0){
		ans = d[N/2] - d[N/2-1];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }

ll a[5][5];
bool flag[5][5];
int main(){
    ll n,m;
    mem(flag,false);
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    cin>>n;
    while(n--){
        ll x;
        cin>>x;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(x==a[i][j]) flag[i][j]=true;
            }
        }
    }
    if(flag[0][0]&&flag[0][1]&&flag[0][2]) cout<<"Yes"<<endl;
        else if(flag[1][0]&&flag[1][1]&&flag[1][2]) cout<<"Yes"<<endl;
        else if(flag[2][0]&&flag[2][1]&&flag[2][2]) cout<<"Yes"<<endl;
        else if(flag[0][1]&&flag[1][1]&&flag[2][1]) cout<<"Yes"<<endl;
        else if(flag[0][0]&&flag[1][0]&&flag[2][0]) cout<<"Yes"<<endl;
        else if(flag[0][2]&&flag[1][2]&&flag[2][2]) cout<<"Yes"<<endl;
        else if(flag[0][0]&&flag[1][1]&&flag[2][2]) cout<<"Yes"<<endl;
        else if(flag[0][2]&&flag[1][1]&&flag[2][0]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
	int N, T, cost, time;
	int cost_min = 1000;
	bool found_route = false;

	std::cin >> N >> T;
	for( int i=0; i<N; ++i ){
		std::cin >> cost >> time;
		if( time > T ){
			continue;
		}
		found_route = true;
		if( cost < cost_min ){
			cost_min = cost;
		}
	}
	if( found_route ){
		std::cout << cost_min << std::endl;
	} else{
		std::cout << "TLE" << std::endl;
	}
}


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

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

  sort(A, &A[N]);

  int ans = 1;
  for (int i = 1; i < N; ++i) {
    if (A[i] == A[i-1]) continue;
    ++ans;
  }

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


Measured memory_bytes: 256
using System;

class ITP1
{
    static void Main()
    {
        var str = Console.ReadLine().ToCharArray();
        for(int i=0;i<str.Length;i++){
            if(char.IsLower(str[i])){
                str[i]=char.ToUpper(str[i]);
            }
            else if (char.IsUpper(str[i]))
            {
                str[i] = char.ToLower(str[i]);
            }
        }
                    Console.WriteLine(str);
    }
}

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

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

  string c = a + b;
  int ans = 0;
  for (int i = 0; i < c.size(); i++) {
    ans *= 10;
    ans += c[i] -'0';
  }

  if ((int)sqrt(ans) * (int)sqrt(ans) == ans)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C){
  if((A <= C && C <= B) || (A >= C && C >= B)){
    cout << "Yes" << endl;
    return;
  }
  cout << "No" << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N; cin >> N;
	long long sum = N;
	long long j = 1, num = 0;
	vector<long long>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
		if (A.at(i) == j) {
			num++;
			j++;
		}
	}
	if (num == 0) {
		cout << -1 << endl;
		return 0;
	}
	sum -= num;
	cout << sum << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<tuple>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
int main(){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<min(a, b)+min(c, d)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a, b;
	cin >> a >> b;
	vector<char> t (3);
	t.at(2) = b.at(0);
	t.at(1) = b.at(1);
	t.at(0) = b.at(2);
	if(t.at(0) == a.at(0) && t.at(1) == a.at(1) && t.at(2) == a.at(2)){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in reversed(range(n)):
  if b[i]>=a[i+1]:
    a[i+1], b[i], ans = 0, b[i]-a[i+1], ans+a[i+1]
  else:
    a[i+1], b[i], ans = a[i+1]-b[i], 0, ans+b[i]
  if b[i]>=a[i]:
    a[i], b[i], ans = 0, b[i]-a[i], ans+a[i]
  else:
    a[i], b[i], ans = a[i]-b[i], 0, ans+b[i]
print(ans)

Measured memory_bytes: 18476