akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0;i<(n);i++)

int cmpint(const void *a,const void *b){
  return *(int *)b-*(int *)a;
}

int main(){
  int c[3][3];
  rep(i,3){
    //printf("\n");
    rep(j,3){
      scanf("%d",&c[i][j]);
      //printf("%d",c[i][j]);
    }
  }
  int a[3],b[3];
  a[0]=0;
  rep(j,3){
    b[j]=c[0][j]-a[0];
    if(j>0){
      a[j]=c[j][0]-b[0];
    }
  }
  rep(i,3){
    rep(j,3){
      if(c[i][j]!=a[i]+b[j]){
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

const int MAXN = 410;
const int MAXM = 100100;

int a[MAXM];
int b[MAXM];

int g[MAXN][MAXN];
bool ok[MAXN];

int main() {
#ifdef LOCAL
  freopen("e.in", "r", stdin);
  freopen("e.out", "w", stdout);
#endif

  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &a[i], &b[i]);
      --a[i], --b[i];
    }
    for (int v = 0; v < n; v++) {
      vector<bool> protect(n);
      protect[v] = true;
      ok[v] = true;
      for (int i = m - 1; i >= 0; i--) {
        if (protect[a[i]] && protect[b[i]]) {
          ok[v] = false;
          break;
        }
        if (protect[a[i]] || protect[b[i]]) {
          protect[a[i]] = protect[b[i]] = true;
        }
      }
      for (int i = 0; i < n; i++) {
        g[v][i] = protect[i];
      }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        bool can = ok[i] && ok[j];
        for (int k = 0; k < n; k++) {
          if (g[i][k] && g[j][k]) {
            can = false;
          }
        }
        if (can) ans++;
      }
    }
    printf("%d\n", ans);
  }

  return 0;
}


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

int N, a[3009];

long long dp[3009][3009];

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

    for(int bit = 0; bit < N; bit++) {
        for(int l = 0; l + bit < N; l++) {
            int r = l + bit;
            dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
        }
    }

    cout << dp[0][N - 1] << endl;

    return 0;
}

Measured memory_bytes: 70016
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n, m, x;
    cin >> n >> m >> x;

    set<int> a;
    vector<int> maze(n+1,0);
    for(int i=0;i<m;i++){
        int y;
        cin >> y;
        a.insert(y);
    }

    for(int i=1;i<n+1;i++){
        maze[i]=maze[i]+maze[i-1];
        if(a.count(i))maze[i]++;
    }

    int ans = min(maze[x],maze[n]-maze[x]);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
void spin1(int a[]);
void spin2(int a[]);
void spin3(int a[]);

int main(void){
	int d[6],q,u,f,i;
	for(i=0;i<6;i++){
		scanf("%d",&d[i]);
	}
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&u,&f);
		if(d[0]==u||d[1]==u||d[5]==u||d[4]==u){
			while(d[0]!=u)
				spin1(d);
			while(d[1]!=f)
				spin2(d);
		}
		else{
			while(d[0]!=u)
				spin3(d);
			while(d[1]!=f)
				spin2(d);
		}
		printf("%d\n",d[2]);
	}
	
	return 0;
}

void spin1(int a[]){
	int t=a[0];
	a[0]=a[4];
	a[4]=a[5];
	a[5]=a[1];
	a[1]=t;
}
void spin2(int a[]){
	int t=a[1];
	a[1]=a[2];
	a[2]=a[4];
	a[4]=a[3];
	a[3]=t;
}
void spin3(int a[]){
	int t=a[0];
	a[0]=a[2];
	a[2]=a[5];
	a[5]=a[3];
	a[3]=t;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

int main() {
    int N;
    while(cin >> N) {
        bool first = true;
        for(int i = 1; i <= N; i <<= 1) {
            if(N & i) {
                if(!first) cout << ' ';
                cout << i;
                first = false;
            }
        }
        cout << endl;
    }
    return 0;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll n;cin>>n;
  ll a[100005];
  for(ll i=0;i<n;i++)cin>>a[i];
  a[n]=0;
  ll sum=0;ll pos = 0;
  for(ll i=0;i<=n;i++){
    ll amount = abs(a[i]-pos);
    sum += amount;
    pos = a[i];
  }
  for(int i=0;i<n;i++){
    int pos=0;if(i>0)pos=a[i-1];
    // まんなか
    bool p1 = (pos<=a[i]&&a[i]<=a[i+1]) || (pos>=a[i]&&a[i]>=a[i+1]);
    // 外側同じ向き
    bool p2 = (pos<=a[i+1]&&a[i+1]<=a[i]) || (pos>=a[i+1]&&a[i+1]>=a[i]);
    // cout<<i<<':'<<pos<<':'<<a[i]<<':'<<a[i+1]<<':'<<p1<<':'<<p2<<endl;
    if(p1){cout<<sum<<endl;}
    else if (p2) {cout<<sum-(2*abs(a[i+1]-a[i]))<<endl;}
    else {cout<<sum-(2*abs(pos-a[i]))<<endl;}
  }

  return 0;
}


Measured memory_bytes: 2048
/*  ex4_3
    kosaq       */

#include <stdio.h>

int snow_height(int height_west, int height_east);//プロトタイプ宣言をする

int main(void){
    int height_a, height_b;//それぞれ西の塔、東の塔の、雪に埋もれていない部分の高さ
    int ans;//出力する答え（雪の高さ）

    scanf("%d %d", &height_a, &height_b);//西の塔、東の塔の、雪に埋もれていない部分の高さ　を入力
    ans = snow_height(height_a, height_b);// 関数から得られる値をansに代入

    printf("%d\n", ans);//答えとなる雪の高さを出力
    return 0;
}

/*
以下は関数を定義*/

int snow_height(int height_west, int height_east){//関数を定義する
    int totalheight_a;//西の塔の本当の高さ
    int difference;//西の塔と東の塔の高さの差
    int height_snow;//雪の高さ

    difference = height_east - height_west;//西の塔と東の塔の高さの差を計算
    totalheight_a = (difference - 1) * difference / 2;//西の塔の本当の高さを計算
    height_snow = totalheight_a - height_west;//雪の高さを計算（埋もれている部分の計算）

    return (height_snow);//返り値の値をreturnで返す
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void) {
    int array[512];
    int num;
    int value;
    int i;
    int j;

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

    for ( i = 1 ; i < num  ; i++ ){
        for ( j = 0 ; j < num ; j++ ) {
            printf( "%d", array[j]);
            if ( j < num - 1) {
                printf( " " );
            }
        }

        printf("\n");

        value = array[i];
        j = i - 1;
        for ( j = j ; j >= 0 && ( array[ j ] > value ) ; j-- ) {
            array[ j + 1 ] = array[ j ];

        }
        array[ j + 1 ] = value;
    }

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

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


Measured memory_bytes: 1904
package main

import (
	"fmt"
)

func main() {
	var k, n int
	fmt.Scanf("%d %d", &k, &n)

	a := scanNums(n)

	fmt.Println(answer(k, n, a))
}

func answer(k int, n int, a *[]int) int {
	var maxDistance int = 0
	var distance int = 0
	for i := 0; i < n-1; i++ {
		distance = (*a)[i+1] - (*a)[i]
		if maxDistance < distance {
			maxDistance = distance
		}
	}
	distance = k - (*a)[n-1] + (*a)[0]
	if maxDistance < distance {
		maxDistance = distance
	}

	return k-maxDistance
}

func scanNums(len int) *[]int {
	var num int
	nums := make([]int, len)
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums[i] = num
	}
	return &nums
}

Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
} 


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

    map<string, ll> m;
    m["AC"] = 0;
    m["TLE"] = 0;
    m["WA"] = 0;
    m["RE"] = 0;
    for(ll i = 0; i < N; i++) {
        string S;
        cin >> S;
        m[S]++;
    }


    cout << "AC x " << m["AC"] <<endl;
    cout << "WA x " << m["WA"] <<endl;
    cout << "TLE x " << m["TLE"] <<endl;
    cout << "RE x " << m["RE"] <<endl;
    
    return 0;    
}




Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
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; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
    ll N;
    cin >> N;
    vector<mint> A(N),S(N+1);
    ll a;
    rep(i,N){
        cin >> a;
        A[i] = a;
    }
    for(ll i=N-1;i>=0;i--){
        S[i] = S[i+1] + A[i];
    }
    mint ans = 0;
    rep(i,N){
        ans += A[i]*S[i+1];
    }
    cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int n = s.size();
    
    for (int i = 0; i < n; i++) {
        if ((s.substr(i, 7) == "remaerd") && (i + 6 < n)) {
            i += 6;
            continue;
        }
        else {
            if ((s.substr(i, 5) == "maerd") && (i + 4 < n)) {
                i += 4;
                continue;
            }
            else {
                if ((s.substr(i, 6) == "resare") && (i + 5 < n)) {
                    i += 5;
                    continue;
                }
                else {
                    if ((s.substr(i, 5) == "esare") && (i + 4 < n)) {
                        i += 4;
                        continue;
                    }
                    else {
                        cout << "NO" << endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

char c[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> c[i];

    sort(c, c + n);
    n = unique(c, c + n) - c;
    if (n == 3)
        cout << "Three";
    else
        cout << "Four";
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,i,j,a;
	int flg;
	flg=0;
	scanf("%d",&n);
	for(i=0;i<26;i++){
		for(j=0;j<18;j++){
			if(i*4+j*7==n){
				flg=1;
			}
		}
	}
	if(flg==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
using namespace std;

int main(void)
{
	char S[100];
	int p=0;
	scanf("%s", S);
	int count[26] = { 0 };
	int i = 0;
	while (S[i] !='\0') {
		count[S[i] - 'a']++;
		if (count[S[i] - 'a'] % 2 == 1) {
			p += 1;
		}
		else
			p -= 1;
		i++;
	}
	if (p == 0) {
		printf("Yes");
	}
	else
		printf("No");
	
	return 0;
}

Measured memory_bytes: 760
n=int(input())
h=list(map(int,input().split()))
h[0]-=1
pre=h[0]
for i in range(n):
    if pre > h[i]:
        print('No')
        break
    if h[i] > pre:
        h[i]-=1
    pre=h[i]
else:
    print('Yes')


Measured memory_bytes: 15020
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();
        
        if (a + b == 15) {
          // 出力
		  System.out.println("+");
        } else if (a * b == 15) {
          // 出力
		  System.out.println("*");
        } else {
          // 出力
		  System.out.println("x");
        }
	}
}

Measured memory_bytes: 22996
def LI():return list(map(int,input().split()))
def MI():return map(int,open(0).read().split())
def I():return int(input())
def yes():print("Yes")
def no():print("No")

from collections import deque, Counter
from heapq import heappop, heappush
INF=float("inf")
# import math
# pi=math.pi

# import numpy as np

x=LI()
ans=x.index(0)
print(ans+1)

Measured memory_bytes: 64652
S=input()

def ans141(S:str):
    judge=0

    for i in range(0,len(S)):
        if (i+1)%2==1:
            if S[i]=="R" or S[i]=="U" or S[i]=="D":
                continue
            else:
                judge+=1
        else:
            if S[i]=="L" or S[i]=="U" or S[i]=="D":
                continue
            else:
                judge+=1
    if judge>0:
        return "No"
    else:
        return "Yes"

print(ans141(S))

Measured memory_bytes: 9072
//Roller Coaster
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] h=new int[n];
    int count=0;

    for (int i=0;i<n;i++) {
     h[i]=sc.nextInt();
    }

    for (int i=0;i<n;i++) {
      if (h[i]>=k) {
        count++;
      }
    }

    System.out.println(count);

  }
}


Measured memory_bytes: 48104
#include<stdio.h>

void insertionSort(int a[], int n){
  int i,j,k,x;

  /*for(i=0; i<n-1; i++){
      printf("&d ",a[i]);
  }
  printf("%d\n",a[i]);*/

  for(i=0; i<n; i++){
    x = a[i];
    j = i - 1;
    while((j>=0) && (a[j]>x)){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = x;

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

int main(void){

  int n;
  scanf("%d",&n);

  int a[n];

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

  insertionSort(a,n);

  return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

char cc(char x) {
    if (x == 'a')
        return 'Z';
    if (x == 'A')
        return 'z';
    return --x;
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    int a, b, c;
    cin >> a >> b >> c;
    int mins = 0;
    for (int q = 0; q < 120; q++) {
        if (mins % 60 == c) {
            cout << mins << endl;
            return 0;
        }
        for (int i = 0; i < a; i++) {
            ++mins;
            if (mins % 60 == c) {
                cout << mins << endl;
                return 0;
            }
        }
        for (int j = 0; j < b; j++) {
            ++mins;
        }
    }
    cout << -1 << endl;
}



Measured memory_bytes: 3236
#include<iostream>
#include<queue>

using namespace std;
static const int N=100;
static const int INFTY=(1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
  queue<int>q;
  q.push(s);
  for(int i=0;i<n;i++)d[i]=INFTY;
  d[s]=0;
  int u;
  while(!q.empty()){
    u=q.front();q.pop();
    for(int v=0;v<n;v++){
      if(M[u][v]==0)continue;
      if(d[v]!=INFTY)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<( (d[i]==INFTY) ? (-1):d[i] ) << endl;
  }
}
int main(){
  int u,k,v;

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

 for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
 bfs(0);
	
  return	 0;

}




Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

    double ans = 0;
    REP(i, n) ans += 1. / a[i];

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

    return 0;
}


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

int main(){
  int n,m;
  cin>> n>>m;
  int sum= 0;
  for (int i =0; i<m;i++){
    int a;
    cin>>a;
    sum += a;
  }
  if(sum>n){
    cout <<-1 <<endl;
  } else {
    cout << n-sum <<endl;
  }
}



Measured memory_bytes: 3636
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;


public class Main {
	public static class FastReader {
			BufferedReader br;
			StringTokenizer root;
			
	 
			public FastReader() {
				br = new BufferedReader(new InputStreamReader(System.in));
			}
	 
			String next() {
				while (root == null || !root.hasMoreTokens()) {
					try {
						root = new StringTokenizer(br.readLine());
					} catch (Exception addd) {
						addd.printStackTrace();
					}
				}
				return root.nextToken();
			}
	 
			int nextInt() {
				return Integer.parseInt(next());
			}
	 
			double nextDouble() {
				return Double.parseDouble(next());
			}
	 
			long nextLong() {
				return Long.parseLong(next());
			}
	 
			String nextLine() {
				String str = "";
				try {
					str = br.readLine();
				} catch (Exception addd) {
					addd.printStackTrace();
				}
				return str;
			}
		}
	 
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static FastReader sc = new FastReader();
 
	static long mod = (int) (1000000000),MAX=(int)(1e5+10);
	
	public static void main(String[] args) throws IOException{
	    
char[] s = sc.next().toCharArray();
char[] t = sc.next().toCharArray();
int ans = 0;
for(int i=0;i<s.length;++i) if(s[i] != t[i]) ++ans;
out.print(ans);
		
        
        out.close();
    }
	
}





Measured memory_bytes: 37540
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=min(a,b);i>=1;i--){
        if(a%i==0&&b%i==0){
            k--;
            if(k==0){
                cout<<i<<endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int a[3];

	for (int i = 0; i < 3; ++i)
		cin >> a[i];
	sort(a, a + 3);
	printf("%d\n", a[0] + a[1]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int64_t f(int64_t x) {
  if (x==1) return 1;
  else if (x>1) return 1+2*f(x/2);
}
int main() {
  int64_t h;
  cin>>h;
  cout<<f(h)<<endl;
}

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

using namespace std;

int N;
string S;
string a[4] = {"SS","SW","WS","WW"};
char N1,N2;
bool is;

int main() {
  cin >> N >> S;
  for(int i = 0; i < 4; i++) {
    string tmp = a[i];
    N2 = tmp[0];
    if(S[0] == 'o') {
      if(tmp[0] == 'S') N1 = tmp[1];
      else if(tmp[1] == 'W') N1 ='S';
      else N1 = 'W';
    }
    else {
      if(tmp[0] == 'S') {
	if(tmp[1] == 'W')N1 = 'S';
	else N1 = 'W';
      }
      else N1 = tmp[1];
    }

    for(int j = 1; j < N; j++) {
      if(S[j] == 'o') {
	if(tmp[j] == 'S') tmp.push_back(tmp[j-1]);
	else if(tmp[j-1] == 'S') tmp.push_back('W');
	else tmp.push_back('S');
      }
      else {
	if(tmp[j] == 'S') {
	  if(tmp[j-1] == 'W')tmp.push_back('S');
	  else tmp.push_back('W');
	}
	else tmp.push_back(tmp[j-1]);
      }
    }

    if(tmp[N-1] == N1 && tmp[N] == N2) {
      cout << tmp.substr(0,N)<<endl; return 0;
    }

  }

  cout << "-1"<<endl;
}
					 
  
  

  


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int ans=0;
	int n=s.size();
	int i=1;
	while(i<s.size()){
		if(s[i]==s[i-1])
		{
			ans++;
			i+=3;
		}
		else i++;
	}
	cout << n-ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#include <chrono>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    // scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        int n; scanf("%d", &n);
        vector<int> v(n);
        for(int &x : v) scanf("%d", &x);
        map<int, int> cnt;
        long long ans = 0;
        for(int i = 0; i < n; i++) {
            ans += cnt[i - v[i]];
            cnt[i + v[i]]++;
        }
        printf("%lld\n", ans);
    }  
    return 0;
}

Measured memory_bytes: 21084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;

LL modpow(LL x, LL n){
	LL r=1;
	while(n){
		if(n&1) r=r*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return r;
}

int main(){
	int N;
	cin >> N;
	LL zero=0;
	vector<LL> A, B;
	rep(i,N){
		LL a, b;
		cin >> a >> b;
		if(a==0 && b==0){
			zero++;
			continue;
		}
		A.emplace_back(a);
		B.emplace_back(b);
	}
	N=A.size();
	LL a_zero=0, b_zero=0;
	rep(i,N){
		if(A[i]==0) a_zero++;
		if(B[i]==0) b_zero++;
	}
	map<P,LL> m;
	rep(i,N){
		LL a=A[i], b=B[i];
		if(a==0 || b==0) continue;
		LL div=__gcd(a,b);
		a/=div, b/=div;
		if(a<0) a*=-1, b*=-1;
		P p=P(a,b);
		m[p]++;
	}
	LL ans=zero, res=1;
	for(auto itr:m){
		LL n1=itr.second;
		if(!n1) continue;
		LL a=itr.first.first, b=itr.first.second;
		P p;
		if(b>0) p=P(b,-a);
		else p=P(-b,a);
		LL n2=m[p];
		if(n2 && b<0) continue;
		res*=modpow(2,n1)+modpow(2,n2)-1;
		res%=mod;
	}
	res*=modpow(2,a_zero)+modpow(2,b_zero)-1;
	res%=mod;
	ans+=res-1, ans%=mod;
	while(ans<0) ans+=mod;
	cout << ans << endl;

	return 0;
}

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

#define is_uruu leapyear
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,a) for(int i=0;i<(a);++i)


	
int main(){
	
	int n, m;
	cin >> n >> m;
	
	cout << (100*n+1800*m)*pow(2, m) << endl; 
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;


class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(),n=sc.nextInt();
        if(n==0){
            System.out.println(x);
        }else {
            ArrayList<Integer> list = new ArrayList<Integer>();
            for(int i = 0;i<n;i++){
                list.add(sc.nextInt());
            }
            int ans =1001001001;
            for(int i = 0;i<=1000;i++){
                if(!list.contains(i)&&Math.abs(x-i)<Math.abs(x-ans)){
                    ans = i;
                }
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 36840
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt(scanner)
	b := getNextInt(scanner)
	if a == b {
		for i := 0; i < a; i++ {
			fmt.Fprint(writer, a)
		}
		fmt.Fprintln(writer, "")
		return
	}
	if a < b {
		for i := 0; i < b; i++ {
			fmt.Fprint(writer, a)
		}
		fmt.Fprintln(writer, "")
		return
	}
	for i := 0; i < a; i++ {
		fmt.Fprint(writer, b)
	}
	fmt.Fprintln(writer, "")
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }
using Weight = int;
using Flow = int;
struct Edge {
	int s, d; Weight w; Flow c; int id;
	Edge() {};
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, M; cin >> N >> M;
	Graph g(N);
	loop(M) {
		int a, b; cin >> a >> b;
		a--, b--;
		addArc(g, a, b);
	}
	double ans = INF;
	rep(k, 0, N) {
		vector<double>dp(N);
		dp.back() = 0;
		rrep(i, 0, N - 1) {
			vector<double>v;
			for (auto e : g[i]) {
				v.eb(dp[e.d] + 1);
			}
			double sum = accumulate(all(v), 0.0);
			dp[i] = sum / (double)(v.size());
			if (i == k and v.size() > 1) {
				dump(k);
				dump(v);
				auto a = *max_element(all(v));
				chmin(dp[i], (sum - a) / (v.size() - 1));
			}
		}
		dump(dp);
		chmin(ans, dp.front());
	}
	cout << ans << endl;
	
	return 0;
}


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

// -------
// Mod int
// -------
const int64_t MOD = 1e9 + 7;
struct mint
{
    int64_t x;
    mint(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += MOD - a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(int64_t n) const
    {
        if (n == 0)
            return 1;
        mint t = pow(n >> 1);
        t *= t;
        if (n & 1)
            t *= *this;
        return t;
    }
    mint inv() const { return pow(MOD - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

// ----------------------------
// Number of combinations (nCk)
// ----------------------------
vector<mint> fac;
vector<mint> fac_inv;
vector<mint> inv;
void init_comb(int mx)
{
    fac = vector<mint>(mx + 1), fac_inv = vector<mint>(mx + 1), inv = vector<mint>(mx + 1);
    fac.at(0) = fac.at(1) = 1;
    fac_inv.at(0) = fac_inv.at(1) = 1;
    inv.at(1) = 1;
    for (int i = 2; i <= mx; i++)
    {
        fac.at(i) = fac.at(i - 1) * i;
        inv.at(i) = -inv.at(MOD % i) * (MOD / i);
        fac_inv.at(i) = fac_inv.at(i - 1) * inv.at(i);
    }
}
mint comb(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac.at(n) * fac_inv.at(k) * fac_inv.at(n - k);
}

int main()
{
    init_comb(1e5);

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

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

    mint res = 0;
    for (int i = 0; i < N; i++)
    {
        if (i < K - 1)
            continue;
        mint c = comb(i, K - 1);
        res += c * A.at(i);
    }
    for (int i = 0; i < N; i++)
    {
        if (N - i - 1 < K - 1)
            continue;
        mint c = comb(N - i - 1, K - 1);
        res -= c * A.at(i);
    }
    cout << res.x << endl;
}

Measured memory_bytes: 2944
n = gets.to_i
m = Math.log2(n+1).ceil
mod = 10**9+7
dp = Array.new(m).map{Array.new(3,0)}
dp[0][0] = dp[0][1] = 1

for i in 1..m-1
    dp[i][0] += dp[i-1][0]
    dp[i][1] += dp[i-1][1]
    dp[i][2] += dp[i-1][2]*3+dp[i-1][1]
    if n[m-i-1] == 0
        dp[i][0] += dp[i-1][1]
    else
        dp[i][1] += dp[i-1][0]
        dp[i][2] += dp[i-1][1]
    end
    for j in 0..2
        dp[i][j] %= mod
    end
end
p dp[m-1].inject(:+)%mod

Measured memory_bytes: 3836
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    ll ans = n*(n-1)/2;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;vector<ll>arr;
int main(void){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    in(n);
    vl a,b,c;
    for(int i=0;i<n;i++){
        in(temp1);in(temp2);in(temp3);
        a.push_back(temp1);b.push_back(temp2);c.push_back(temp3);
    }
    for(int i=1;i<n;i++){
        a[i]+=max(b[i-1],c[i-1]);
        b[i]+=max(c[i-1],a[i-1]);
        c[i]+=max(b[i-1],a[i-1]);
    }
    cout<<max(a[n-1],max(b[n-1],c[n-1]))<<endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int a,b,c;
	string s;

	cin >> a >> b >> c;
	
	if (a > b) {
		swap(a, b);
	}

	if (b > c) {
		swap(b, c);
	}

	if (a > b) {
		swap(a, b);
	}

	cout << a << " " <<  b << " " <<  c << endl;

	return 0;
}



Measured memory_bytes: 3096
using System;

namespace ITP1_10_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            double x1 = double.Parse(strs[0]);
            double y1 = double.Parse(strs[1]);
            double x2 = double.Parse(strs[2]);
            double y2 = double.Parse(strs[3]);
            Console.WriteLine(Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)).ToString());
        }
    }
}

Measured memory_bytes: 9176
import collections
import itertools

h, w = map(int, input().split())
sy, sx = map(lambda x:int(x) - 1, input().split())
gy, gx = map(lambda x:int(x) - 1, input().split())
maze = [list(input()) for _ in range(h)]

seen = [[-1] * w for _ in range(h)]
seen[sy][sx] = 0
que = collections.deque()
que.append((sy, sx))
tmp2 = [(sy, sx)]
cnt = 0
while True:
    tmp1 = []
    for sy, sx in tmp2:
        if maze[sy][sx] == ".":
            que.append((sy,sx))
            tmp1.append((sy, sx))
            while que:
                py, px = que.popleft()
                for dy, dx in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
                    ny = py + dy
                    nx = px + dx
                    if 0 <= ny < h and 0 <= nx < w and maze[ny][nx] == "." and seen[ny][nx] == -1:
                        seen[ny][nx] = cnt
                        que.append((ny, nx))
                        tmp1.append((ny, nx))
                        maze[sy][sx] = "#"
                        
    if seen[gy][gx] != -1:
        break

    flag = True
    d = [-2, -1, 0, 1, 2]
    tmp2 = []
    for py, px in tmp1:
        for i in range(5):
            for j in range(5):
                ny = py + d[i]
                nx = px + d[j]
                if 0 <= ny < h and 0 <= nx < w and maze[ny][nx] == "." and seen[ny][nx] == -1:
                    seen[ny][nx] = cnt + 1
                    que.append((ny, nx))
                    flag = False
                    tmp2.append((ny, nx))
    cnt += 1
    if flag:
        break
    if seen[gy][gx] != -1:
        break

print(seen[gy][gx])

Measured memory_bytes: 128956
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>
#include <map>


using namespace std;

int main() {
    cin.tie(0);
    int n;cin>>n;
    cout<<(n-2)*180<<endl;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

n = inp()
x = ip()
dp = [0]*n
dp[1] = abs(x[0]-x[1])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(x[i-1]-x[i]),dp[i-2]+abs(x[i-2]-x[i]))
print(dp[-1])


Measured memory_bytes: 85060
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    map<string,int>a;
    int n;
    cin>>n;
    string st;
    for(int i = 0;i<n;i++)
    {
        cin>>st;
        a[st]++;
    }
    vector<pair<int,string>>vec;
    for(auto x:a)
    {
        vec.push_back({x.second,x.first});
    }
    sort(vec.rbegin(),vec.rend());
    vector<string>ret;
    ret.push_back(vec[0].second);
    for(int i = 1;i<vec.size();i++)
    {
        if(vec[i].first==vec[i-1].first)
        {
            ret.push_back(vec[i].second);

        }
        else
        {
            break;
        }
    }
    sort(ret.begin(),ret.end());
    for(auto x:ret)
    {
        cout<<x<<"\n";
    }
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  ll x[N],y[N];
  vll vx,vy;
  for(ll i=0;i<N;i++){
    cin>>x[i]>>y[i];
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  sort(vx.begin(),vx.end());
  sort(vy.begin(),vy.end());
  vx.erase(unique(vx.begin(),vx.end()),vx.end());
  vy.erase(unique(vy.begin(),vy.end()),vy.end());
  map<ll,ll> idx,idy;
  for(ll i=0;i<(ll)vx.size();i++){
    idx[vx[i]]=i;
  }
  for(ll i=0;i<(ll)vy.size();i++){
    idy[vy[i]]=i;
  }
  vll g[vx.size()+vy.size()];
  for(ll i=0;i<N;i++){
    g[idx[x[i]]].push_back(vx.size()+idy[y[i]]);
    g[vx.size()+idy[y[i]]].push_back(idx[x[i]]);
  }
  ll ans = 0;
  bool used[vx.size()+vy.size()]={};
  for(ll i=0;i<(ll)vx.size();i++){
    if(used[i])continue;
    //debug(i);
    queue<pair<ll,ll> > Q;
    Q.push({i,-1});
    ll l=0,r=0;
    while(!Q.empty()){
      ll v,p;tie(v,p)=Q.front();Q.pop();
      if(used[v])continue;
      used[v]=true;
      //debug(v);
      (v<(ll)vx.size()? l:r)+=1;
      //debug(g[v].size());
      for(ll u:g[v])if(u!=p){
        //debug(u);
        Q.push({u,v});
      }
    }
    ans += l*r;
  }
  //debug(ans);
  ans -= N;
  cout<<ans<<endl;
}


Measured memory_bytes: 15724
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;cin>>N;
  vector<vector<pair<long,long>>>A(N);
  for(long i=0;i<N-1;i++){
    long a,b;cin>>a>>b;
    A[a-1].push_back(pair<long,long>(b-1,i));
    A[b-1].push_back(pair<long,long>(a-1,i));
  }
  long M;cin>>M;
  vector<long>U(M),V(M);
  for(long i=0;i<M;i++)cin>>U[i]>>V[i];
  
  
  vector<bitset<50>>B(M);
  for(long i=0;i<M;i++){
    queue<long>q;q.push(U[i]-1);
    vector<bitset<50>>P(N);
    while(q.size()){
      long f=q.front();q.pop();
      for(auto n:A[f])if(P[n.first].none()&&n.first!=U[i]-1){
        P[n.first]=P[f];P[n.first].set(n.second);
        q.push(n.first);
      }
    }
    B[i]=P[V[i]-1];
  }
  long ans=0;
  for(long i=0;i<(1<<M);i++){
    bitset<50>b(i),c;
    for(long j=0;j<M;j++)if(b.test(j))c|=B[j];
    ans+=(1L-((long)b.count()%2L)*2L)*(1L<<(N-1L-c.count()));  
    assert(1L<<(N-1L-c.count())>0);
  }
  cout<<ans;
  assert(ans>=0);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define pque(type) priority_queue<type,vector<type>,greater<type> >

int main(void){
	ll t=0;
	ll ans[50]={};
	cin >> t;
	rep(j,t){
		ll n=1000000;
		ll k=1000000;
		ll sum=0;
		ll sum2=0;
		cin >> n >> k;
		if(k>n)k=n;
		ll x[n];
		ll d[n];
		rep(i,n){
			cin >> x[i];
			if(i>=1){
				d[i-1]=x[i]-x[i-1];
				sum+=d[i-1];
			}
		}
		sort(d,d+n-1,greater<ll>());
		rep(i,k-1)sum2+=d[i];
		ans[j]=sum-sum2;
	}
	rep(i,t){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4624
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n;
  ll t;
  cin >> n >> t;
  ll a[200000];
  REP(i, n)
  {
    cin >> a[i];
  }

  ll ans = a[n - 1] + t;
  FOR(i, 1, n)
  {
    if (a[i] - a[i - 1] > t)
    {
      ans -= a[i] - a[i - 1] - t;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int N,NP,NM,indP,indM;
ll K,A[202020];

ll solve(ll X){
  // X以下の数
  ll sum=0;
  rep(i,N){
    if(A[i]>0){
      if(A[i]*A[0]>X) continue;
      int ok=0,ng=N;
      while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        if(A[i]*A[mid]<=X) ok=mid;
        else ng=mid;
      }
      sum+=ok+1;
      if(A[i]*A[i]<=X) sum--;
    }
    if(A[i]==0){
      if(X>=0) sum+=N-1;
    }
    if(A[i]<0){
      if(A[i]*A[N-1]>X) continue;
      int ok=N-1,ng=-1;
      while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        if(A[i]*A[mid]<=X) ok=mid;
        else ng=mid;
      }
      sum+=N-ok;
      if(A[i]*A[i]<=X) sum--;
    }
  }
  if(sum>=2*K) return 1;
  else return 0;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin>>N>>K;
  rep(i,N){
    cin>>A[i];
  }
  
  sort(A,A+N);

  ll ok=1e18,ng=-1e18;

  while(ok-ng>1){
    ll mid=(ok+ng)/2;
    if(solve(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
  return 0;
}

Measured memory_bytes: 1792
def main():
    H, W = map(int, input().split())
    N = int(input())
    A = list(map(int, input().split()))
    retval = [[0] * W for _ in range(H)]
    index = 0
    for i in range(N):
        count = A[i]
        while count:
            y = int(index / W)
            if y % 2 == 0:
                x = index % W
            else:
                x = (W - 1) - index % W
            retval[y][x] = i+1
            count -= 1
            index += 1
    for row in retval:
        print(" ".join(map(str, row)))


if __name__ == "__main__":
    main()


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

n=int(input())
G=[[] for _ in range(n+1)]
for _ in range(n-1):
    u,v,w=map(int,input().split())
    G[u].append((v,w))
    G[v].append((u,w))

D=[-1 for _ in range(n+1)]
D[1]=0
L=deque()
L.append(1)

while L:
    p=L.popleft()
    for i in G[p]:
        if D[i[0]]==-1:
            D[i[0]]=D[p]+i[1]
            L.append(i[0])

for m in range(1,n+1):
    print(D[m]%2)

Measured memory_bytes: 43140
#!/usr/bin/env python                                                                                                                   
inputlist = map(str,raw_input().split())
numberlist = []
for a in inputlist:
    if a == "+":
        b = numberlist[-2]
	c = numberlist[-1]
	numberlist[-2:]=[]
	d = int(b) + int(c)
	numberlist.append(d)
    elif a == "-":
        b = numberlist[-2]
        c = numberlist[-1]
        numberlist[-2:]=[]
        d = int(b) - int(c)
        numberlist.append(d)
    elif a == "*":
	b = numberlist[-2]
        c = numberlist[-1]
        numberlist[-2:]=[]
        d = int(b) * int(c)
	numberlist.append(d)
    else:
        numberlist.append(a)
print(numberlist[0])

Measured memory_bytes: 4244
def ABC_swap():
    # 入力
    X, Y, Z = map(int, input().split())
    A = X
    B = Y
    C = Z
    # 入れ替え処理
    A, B = B, A
    A, C = C, A
    # 表示
    print(A, B, C)

ABC_swap()

Measured memory_bytes: 9112