akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
 
int main(void) {
  int N, size, start, end, *black, *white, i, min;
  char *S;
  scanf("%d",&N);
  S = (char*)malloc(sizeof(char)*(N+1));
  assert(S);
  black = (int*)malloc(sizeof(int)*N);
  assert(black);
  white = (int*)malloc(sizeof(int)*N);
  assert(white);
  for (start = 0, scanf("%s",S); start < N && S[start] == '.'; start++);
  for (end = N-1; end >= 0 && S[end] == '#'; end--);
  for (size = 0; start <= end; size++) {
    for (black[size] = 0; start <= end && S[start] == '#'; start++, black[size]++);
    for (white[size] = 0; start <= end && S[start] == '.'; start++, white[size]++);
  }
  for (i = 1; i < size; i++) {
    black[i] += black[i-1];
  }
  for (i = size-2; i >= 0; i--) {
    white[i] += white[i+1];
  }
  if (white[0] < black[size-1]) {
    min = white[0];
  } else {
    min = black[size-1];
  }
  for (i = 0; i < size-1; i++) {
    if (min > black[i]+white[i+1]) {
      min = black[i]+white[i+1];
    }
  }
  printf("%d",min);
  free(S);
  free(black);
  free(white);
  return 0;
}

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

using namespace std;

int main() {
  string orig_str;
  getline(cin, orig_str);

  if (orig_str.length() == 1) {
    cout << "0" << endl;
    return 0;
  }

  int start = orig_str.length()/2 - 1;
  int count=0;
  for (int i=start; i >= 0; i--) {
    if (orig_str[i] != orig_str[orig_str.length() - 1 - i]) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int d, m;
    d = 10 * (int(s[5]) - 48) + int(s[6]) - 48;
    m = 10 * (int(s[8]) - 48) + int(s[9]) - 48;
    if(d <= 4 && m <= 30)
    cout << "Heisei";
    else
    cout << "TBD";
    return 0;
}

Measured memory_bytes: 3592
n = int(input())
s=[]
for x in range(n):
    s.append(input())
a={"AC":0, "WA":0,"TLE":0,"RE":0}
for x in s:
    a[x]+=1
print("AC x %s" % a["AC"])
print("WA x %s" % a["WA"])
print("TLE x %s" % a["TLE"])
print("RE x %s" % a["RE"])

Measured memory_bytes: 16284
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,e,i,k=0,m=-1;
    cin >> a;
    long long res=0;
    string num="";
    for(i=1;i<=10000000;i++)
    {
        num+="7";
          res = (res*10 + (int)num[k] - '0') %a;
          k++;
          if(res==0)
          {
              m=0;
              break;
          }

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

}


Measured memory_bytes: 18628
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import math
r = inn()
print(2*math.pi*r)


Measured memory_bytes: 9188
#include <iostream>
#include <vector>
using namespace std;
typedef vector <int> IVEC;

int bubblesort(IVEC &A);

int main(void){
	IVEC A;
	int n, count;

	cin>>n;
	A.resize(n);
	
	for (int i=0; i<n; i++)
		cin>>A[i];

	count = bubblesort(A);

	for (int i=0; i<n; i++){
		if (i!=0) cout <<" ";
		cout<<A[i];
	}
	cout <<endl;
	cout << count << endl;
	return 0;
}

int bubblesort(IVEC &A){
	int lena = A.size(), count=0;
	for (int i=0; i<lena; i++){
		for (int j=lena-1; j>i; j--){
			if (A[j]<A[j-1]){
				int tmp = A[j];
				A[j] = A[j-1];
				A[j-1] = tmp;
				count++;
			}
		} 
	}
	return count;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define HAIRETU(N,A) for(int i=0;i<N;i++) cin >>A[i]
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int tmp, A[200050]={};
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        A[tmp]++;
    }

    
    sort(A, A+200050);
    reverse(A, A+200050);
    

    int i = 0, size = 0;
    while(A[i] != 0){
        size++;
        i++;
    }
    
    int total = 0;
    if (size <= K ) cout << 0 << endl;
    else {
        for (i = 0; i < size-K; i++) {
            total += A[size-i-1];
        }
        cout << total << endl;

    }
    return 0;
}



Measured memory_bytes: 1024
N = int(input())
H = [int(s) for s in input().split()]
count = 0
maximum = 0
for i, h in enumerate(H):
  if i <= N-2:
    if H[i] >= H[i+1]:
      count += 1
    else:
      count = 0
    maximum = max(maximum, count)
print(maximum)

Measured memory_bytes: 14252
n = gets.to_i
strs = Array.new(3) { gets.chomp }
sum = 0
n.times do |i|
  a = strs[0][i]
  b = strs[1][i]
  c = strs[2][i]

  sum += if a == b && b == c
           0
         elsif a == b || b == c || c == a
           1
         else
           2
         end
end
puts(sum)

Measured memory_bytes: 1788
// 1からスタンプを押していくBFS
// golangでpriority queueもってないから愚直FIFOで間に合うかどうかは正直わからん
package main

import "fmt"

type Pos struct {
	cur, pre int
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	T := make([][]int, N+1)
	for i := 1; i <= N; i++ {
		T[i] = []int{}
	}
	for i := 0; i < M; i++ {
		var A, B int
		fmt.Scan(&A, &B)
		T[A] = append(T[A], B)
		T[B] = append(T[B], A)
	}
	passed := make([]int, N+1)
	passed[1] = -1
	queue := []Pos{Pos{cur: 1, pre: 0}}
	for len(queue) > 0 {
		nex_queue := []Pos{}
		for i := 0; i < len(queue); i++ {
			now := queue[i]
			for _, nex := range T[now.cur] {
				if passed[nex] == 0 {
					nexPos := Pos{cur: nex, pre: now.cur}
					passed[nex] = now.cur
					nex_queue = append(nex_queue, nexPos)
				}
			}
		}
		queue = nex_queue
	}
	fmt.Println("Yes")
	for _, ans := range passed[2:] {
		fmt.Println(ans)
	}
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int A, B;
	cin >> A >> B;
	int ans = 1;
	int AA = A;
	if (B==1) {
		ce(0)
	}
	else {
		while (A<B) {
			A += AA - 1;
			ans++;
		}
		ce(ans)
	}
    return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  string s;
  cin >> s;
  string t = "abcdefghijklmnopqrstuvwxyz";

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  bool cannot = true;
  re(i, 26) {
    if(t[i] != s[i]) {
      cout << t[i] << endl;
      cannot = false;
      break;
    }
  }

  if(cannot) cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename T>
class SegmentTree {
   public:
    SegmentTree(vector<T> &base, function<T(T, T)> fn_, T e_) {
        fn = fn_;
        e = e_;
        n = 1;
        while (n < base.size()) n *= 2;

        node.resize(2 * n - 1, e);
        REP(i, 0, base.size())
        node[n - 1 + i] = base[i];
        for (int i = n - 2; i >= 0; i--) node[i] = fn(node[2 * i + 1], node[2 * i + 2]);
    }

    // 0-origin
    void update(int i, T x) {
        i += n - 1;
        node[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            node[i] = fn(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    // 0-origin, [a, b)
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return e;
        if (a <= l && r <= b) return node[k];

        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return fn(vl, vr);
    }

    int find_leftest(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l || node[k] > x) return b;
        if (k >= n - 1) return k - (n - 1);
        int idx = find_leftest(a, b, x, 2 * k + 1, l, (l + r) / 2);
        if (idx == b) idx = find_leftest(a, b, x, 2 * k + 2, (l + r) / 2, r);
        return idx;
    }

    int find_rightest(int a, int b, T x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l || node[k] > x) return a - 1;
        if (k >= n - 1) return k - (n - 1);
        int idx = find_rightest(a, b, x, 2 * k + 2, (l + r) / 2, r);
        if (idx == a - 1) idx = find_rightest(a, b, x, 2 * k + 1, l, (l + r) / 2);
        return idx;
    }

    void print(int w = 4) {
        int prev = 0;
        for (int i = 1; i <= n; i *= 2) {
            for (int j = prev; j < prev + i; j++) {
                cout << setw(n * w / i) << setfill(' ') << node[j];
            }
            cout << endl;
            prev += i;
        }
    }

   private:
    int n;
    vector<T> node;
    function<T(T, T)> fn;
    T e;
};

int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];
    SegmentTree<int> seg(A, [](auto l, auto r) { return min(l, r); }, INT32_MAX);

    ll ans = 0;
    REP(i, 0, N) {
        int l = seg.find_rightest(0, i, A[i]);
        int r = seg.find_leftest(i + 1, N, A[i]);
        ans += (ll)A[i] * (i - l) * (r - i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3072
n = int(input())
c = input()

d = list(c)

i = 0
j = n - 1
result = 0
while True:
    while i < n and d[i] != "W":
        i += 1
    while j > 0 and d[j] != "R":
        j -= 1
    if i == n or j == -1 or i >= j:
        break
    d[i] = "R"
    d[j] = "W"
    result += 1
print(result)

Measured memory_bytes: 10784
#include <stdio.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main(){
    int h,w;scanf("%d%d",&h,&w);
    char c[105][105],ans[105][105],dh[105],dw[105];
    rep(i,h) scanf("%s",&c[i]);
    rep(i,h){
        dh[i]=1;
        rep(j,w){
            if(c[i][j]=='#'){
                dh[i]=0;
                break;
            }
        }
    }
    rep(j,w){
        dw[j]=1;
        rep(i,h){
            if(c[i][j]=='#'){
                dw[j]=0;
                break;
            }
        }
    }
    int idxi=0,idxj=0,nh=h,nw=w;
    rep(i,h){
        idxj=0;
        if(dh[i]) {nh--;continue;}
        rep(j,w){
            if(dw[j]) continue;
            ans[idxi][idxj]=c[i][j];
            idxj++;
        }
        ans[idxi][idxj]=0;
        idxi++;
    }

    rep(i,nh) {
        printf("%s",ans[i]);
        puts("");
    }
}

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

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
//        int n = sc.nextInt();
//        int a = sc.nextInt();
//        int b = sc.nextInt();
//        int c = sc.nextInt();
        String s = sc.next();
//        Long x = sc.nextLong();
        char ch[] = s.toCharArray();
        int count = 0;

        for(int i=0;i<ch.length/2;i++){
            if(ch[i] != ch[ch.length-i-1]){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22608
#include <iostream>

int main(){
    int S;
    int h,m,s;
    std::cin>>S;
    if(0<=S&S<86400){
    s=S%60;
    m=(S-s)%3600;
    h=(S-m-s)/3600;
    
    
    std::cout<<h<<':'<<m/60<<':'<<s<<std::endl;
    }
}



Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <utility>
#include <tuple>
using namespace std;
using AnsType = long long int;

const int dx[] = {-1, 1};
AnsType N, L;

struct Elem {
  AnsType idx, h, t;
  Elem() {}
  Elem(AnsType a, AnsType b, AnsType c) : idx(a), h(b), t(c) {}
  bool operator<(const Elem &e) const {
    AnsType vl = (L -   h) +   t;
    AnsType vr = (L - e.h) + e.t;
    return vl > vr;
  }
};

bool is_valid_idx(int x) {
  if(x == 0 and x == N+1) return false;
  return true;
}

int main() {
  cin >> N >> L;
  vector<AnsType> H(N+2);
  for(int i=1; i<=N; i++) {
    cin >> H[i];
  }

  priority_queue<Elem> que;
  for(int i=1; i<=N; i++) {
    if(H[i-1] < H[i] and H[i+1] < H[i]) {
      que.emplace(i, H[i], 0);
    }
  }

  AnsType ans = 0;
  while(que.size()) {
    Elem cur = que.top(); que.pop();
    AnsType idx = cur.idx, h = cur.h, t = cur.t;
    AnsType tend = (L - h) + t;
    ans = max(ans, tend);
    H[idx] = 0;

    for(int k=0; k<2; k++) {
      AnsType nidx = idx + dx[k];
      if(!is_valid_idx(nidx)) continue;
      if(H[nidx-1] < H[nidx] and H[nidx+1] < H[nidx]) {
        que.emplace(nidx, H[nidx], tend);
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 5320
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;

	int arr[n+10];
	int arr2[n+10];

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

	sort(arr2,arr2+n);
	int beda=0;

	for(int i=0;i<n;i++){
		if(arr[i]!=arr2[i]){
			beda++;
		}
		if(beda>2){
			break;
		}
	}

	if(beda==0 || beda==2){
		cout << "YES\n";
	}
	else{
		cout << "NO\n";
	}
}


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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 5e5 + 123;                                          
const int LIM = 52;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
ll n;
ll pw2[66];
ll pw3[66];
int dp[LIM][N];
bool u[LIM][N];

inline ll solve (ll s, int b) {
	if (s < 0) return 0;
	if (s == 0 && b == 0) {
	//	cout << "was: 1" << '\n';
		return 1;
	}
	if (2ll * (pw2[b] - 1) <= s) {
	//	cout << "was: 2" << '\n';
		return pw3[b];
	}  

	if (s >= N || b >= LIM) {
		//cout << (b > LIM) << '\n';
		int res = (solve(s, b-1) + solve(s - pw2[b], b-1) + solve(s - pw2[b-1], b-1)) % mod;

		return res;
	}

	int &res = dp[b][s];
	//cout << res << ":\n";
	if (u[b][s]) return res;
	u[b][s] = 1;

	res = (solve(s, b-1) + solve(s - pw2[b], b-1) + solve(s - pw2[b-1], b-1)) % mod;
	return res; 
}

int main () {
	SpeedForce;
	cin >> n;
	pw2[0] = pw3[0] = 1;
	for (int i = 1; i <= 61; i++) {
		pw2[i] = (1ll << i);
		pw3[i] = (pw3[i-1] * 3ll) % mod;
	}

	cout << solve(n, 60) << '\n';

   	return Accepted;
}

// B...a

Measured memory_bytes: 125184
a, b, k = map(int, input().split())

lower_list = [i for i in range(a, a + k)]
upper_list = [i for i in range(b, b - k, -1)]

out_list = sorted(set(lower_list + upper_list))
for out in out_list:
    if a <= out <= b:
        print(out)

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

struct State {
  int x, y, e;
};

const int INF = (1<<28);
const int MAXH = 51;
const int MAXW = 51;
const int MAXP = 11;

const string dc[] = {"R","D","L","U"};
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};

int H, W;
char G[MAXH][MAXW];
int P;
vector<string> S;
int E[105][4];
int cost[MAXH][MAXW][105];

int bfs(int sx, int sy, int gx, int gy, int e) {
  queue<State> que;
  State s = {sx, sy, e};
  fill(cost[0][0], cost[MAXH][0], INF);
  cost[s.y][s.x][s.e] = 0;
  que.push(s);
  while(!que.empty()) {
    s = que.front();
    que.pop();
    for(int i = 0; i < 4; ++i) {
      int nx = s.x + dx[i]; 
      int ny = s.y + dy[i]; 
      int ne = E[s.e][i];
      if(ne == -1) continue;
      if(nx < 0 || nx >= W) continue;
      if(ny < 0 || ny >= H) continue;
      if(G[ny][nx] == '#') continue;
      if(cost[ny][nx][ne] != INF) continue;
      cost[ny][nx][ne] = cost[s.y][s.x][s.e] + 1;
      que.push((State){nx, ny, ne});
      if(nx == gx && ny == gy) {
        return cost[ny][nx][ne];
      }
    }
  }
  return INF;
}

int main() {
  while(cin >> H >> W && (H|W)) {
    int sx, sy, gx, gy;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
        if(G[i][j] == 'S') {
          sx = j;
          sy = i;
        }
        if(G[i][j] == 'G') {
          gx = j;
          gy = i;
        }
      }
    }
    cin >> P;
    S.resize(P);
    for(int i = 0; i < P; ++i) {
      cin >> S[i];
    }

    vector<string> v;
    v.push_back("");
    for(int i = 0; i < P; ++i) {
      for(int j = 1; j < S[i].size(); ++j) {
        string s = S[i].substr(0, j);
        bool flag = true;
        for(int k = 0; k < S.size(); ++k) {
          if(s.find(S[k]) != string::npos) {
            flag = false;
            break;
          }
        }
        if(flag){
          v.push_back(s);
        }
      }
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    fill(E[0], E[105], -1);
    for(int i = 0; i < v.size(); ++i) {
      for(int j = 0; j < 4; ++j) {
        string s = v[i] + dc[j];
        bool flag = true;
        for(int k = 0; k < S.size(); ++k) {
          if(s.find(S[k]) != string::npos) {
            flag = false;
            break;
          }
        }
        if(!flag) continue;
        s = v[i] + dc[j];
        while(1) {
          int p = lower_bound(v.begin(), v.end(), s) - v.begin();
          if(p < v.size() && v[p] == s) {
            E[i][j] = p;
            break;
          }
          s = s.substr(1);
        }
      }
    }

    int ans = bfs(sx, sy, gx, gy, 0);
    if(ans == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2360
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end
def inli()
  n = gets.to_i
  as = []
  n.times {
    as << gets.split.map(&:to_i)
  }
  [n, as]
end
class Array
  def sum
    total = 0
    self.each do |item|
      total += item
    end
    total
  end
end

def eratosthenes(size)
  prime_list = []
  is_prime = Array.new(size, true)
  is_prime[0] = false
  is_prime[1] = false

  2.upto(size-1){|i|
    if is_prime[i]
      prime_list << i
      (2).upto((size.to_f/i).ceil-1){|j|
        is_prime[j*i] = false
      }
    end
  }
  [prime_list, is_prime]
end

def dijkstra(s, e, cost)
  size = cost.length
  if s==e
    return 0
  end
  dp = {}
  dp[s] = 0
  undefined_node = {}
  size.times{|i|
    if i != s
      undefined_node[i] = cost[s][i]
    end
  }
  while undefined_node.length != 0
    min = undefined_node.min_by{|_, v| v}
    stock = {}
    temp = undefined_node.clone
    temp.each{|k, v|
      if min[1] == v
        undefined_node.delete(k)
        if k == e
          return v
        end
        dp[k] = v
        stock[k] = v
      end
    }

    stock.each{|k, v|
      undefined_node.each{|k2, v2|
        undefined_node[k2] = v + cost[k][k2] < v2 ?  v + cost[k][k2] : v2
      }
    }
  end
end

def get_bits(len)
  res =  []
  (2**len).times{|i|
    res << i.to_s(2).rjust(len, '0')
  }
  res
end

def get_GCD(m, n)
  tmp = [n, m].max
  n = [n, m].min
  m = tmp
  while n != 0
    tmp = m % n
    m = n
    n = tmp
  end
  m
end

w, h, x, y = li()

if w%2 == 0 && w/2 == x && h %2 == 0 && h/2 == y
  puts [w*h/2.to_f, 1].join(" ")
else
  puts [w*h/2.to_f, 0].join(" ")
end


Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using namespace std;
int R, C;
char mas[20][20];
int dy[] = { 0, 0, -1, 1}, dx[] = { -1, 1, 0, 0};
int used[20][20][4][16];

void move( int& x, int& y, int pos){
  x += dx[pos], y += dy[pos];
  //printf("%d %d\n", x, y);
  if(x == -1) x = C - 1;
  if(x == C) x = 0;
  if(y == -1) y = R - 1;
  if(y == R) y = 0;
  return;
}

bool dfs(int x, int y, int pos, int memory){
  move( x, y, pos); //うごく！！！！！
  if(used[x][y][pos][memory]) return false;
  used[x][y][pos][memory] = true;
  if(mas[y][x] == '<') return dfs( x, y, 0, memory);
  if(mas[y][x] == '>') return dfs( x, y, 1, memory);
  if(mas[y][x] == '^') return dfs( x, y, 2, memory);
  if(mas[y][x] == 'v') return dfs( x, y, 3, memory);
  if(mas[y][x] == '_') {
    if(memory == 0) return dfs( x, y, 1, memory);
    else return dfs( x, y, 0, memory);
  }
  if(mas[y][x] == '|'){
    if(memory == 0) return dfs( x, y, 3, memory);
    else return dfs( x, y, 2, memory);
  }
  if(mas[y][x] == '?'){
    for(int i = 0; i < 4; i++){
      if(dfs( x, y, i, memory)) return true;
    }
    return false;
  }
  if(mas[y][x] == '.') return dfs( x, y, pos, memory);
  if(mas[y][x] == '@') return true;
  if(mas[y][x] == '0') return dfs( x, y, pos, 0);
  if(mas[y][x] == '1') return dfs( x, y, pos, 1);
  if(mas[y][x] == '2') return dfs( x, y, pos, 2);
  if(mas[y][x] == '3') return dfs( x, y, pos, 3);
  if(mas[y][x] == '4') return dfs( x, y, pos, 4);
  if(mas[y][x] == '5') return dfs( x, y, pos, 5);
  if(mas[y][x] == '6') return dfs( x, y, pos, 6);
  if(mas[y][x] == '7') return dfs( x, y, pos, 7);
  if(mas[y][x] == '8') return dfs( x, y, pos, 8);
  if(mas[y][x] == '9') return dfs( x, y, pos, 9);
  if(mas[y][x] == '+'){
    if(memory == 15) return dfs( x, y, pos, 0);
    else return dfs( x, y, pos, memory + 1);
  }
  if(mas[y][x] == '-'){
    if(memory == 0) return dfs( x, y, pos, 15);
    else return dfs( x, y, pos, memory - 1);
  }
  used[x][y][pos][memory] = false;
}


int main(){
  cin >> R >> C;
  for(int i = 0; i < R; i++){
    for(int j = 0; j < C; j++){
      cin >> mas[i][j];
    }
  }
  cout << (dfs( -1, 0, 1, 0) ? "YES" : "NO") << endl; 
}

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

int main(){
    double k =0;
    double x = 0 ;
    cin >> k >> x ;
    double a = x-k+1 ;
    if ( k == 1)
    {
        cout << x << endl;
    }
    else
    {
    
    for (size_t i = 0; i < 2*k-2; i++)
    {
        cout << a+i << " " ;
    }
    cout << x+k-1 << endl ;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll x,y;
    cin >> x >> y;
    cout << (x % y == 0 ? -1 : x) << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;

	int count = 0;

	for (int i = a; i <= b; ++i)
	{
		if (c % i == 0)
		{
			++count;
		}
	}

	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
//const int INF=1e9+5; 
int main()
{
	fastio;
	int n;
	cin>>n;
	vector<int>dp(3,0);
	vector<int>newdp(3,0);
	vector<int>c(3);
	for(int day=0;day<n;day++)
	{
		cin>>c[0]>>c[1]>>c[2];
		fill(newdp.begin(),newdp.end(),0);
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				if(i!=j)
				{
					newdp[j]=max(newdp[j],dp[i]+c[j]);
				}
			}
		}
		dp=newdp;
	}	
	cout<<max({dp[0],dp[1],dp[2]});
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
int main()
{
	using namespace std;
	int n;
	while(cin>>n){
		vector<int> vec(n),res_vec;
		for(int i=0;i<n;i++) cin>>vec[i];
		int length=0;
		for(int i=1;i<n;i++)
		if(vec[i]<=vec[i-1])
		length++;
		else{
			res_vec.push_back(length);
			length=0;
		}
		res_vec.push_back(length);
		vector<int>::iterator res=max_element(res_vec.begin(),res_vec.end());
		cout<<*res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 105;

int n;
long long x[N], y[N];
int per[N];

int main()
{
  cin >> n;
  for(int i = 0 ; i < n ; i++)
    cin >> x[i] >> y[i];
  for(int i = 0 ; i < n ; i++)
    per[i] = i;
  sort(per, per + n, [&](int i, int j){
    double alp1 = atan2(y[i], x[i]);
    double alp2 = atan2(y[j], x[j]);
    return alp1 < alp2;
  });
  long long best = 0;
  for(int i = 0 ; i < n ; i++){
    long long cur_x = 0, cur_y = 0;
    for(int j = i ; j < i + n ; j++){
      cur_x += x[per[j % n]];
      cur_y += y[per[j % n]];
      best = max(best, cur_x * cur_x + cur_y * cur_y);
    }
  }
  cout << fixed << setprecision(15) << sqrt((long double)best) << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()

t = s.replace("dreameraser","1")
t = t.replace("dreamerase","2")
t = t.replace("dreamer","3")
t = t.replace("eraser","4")
t = t.replace("dream","5")
t = t.replace("erase","6")

try:
    int(t)
    print("YES")
except :
    print("NO")

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int ct1 = 0, ct2 = 0, ct3 = 0, ct4 = 0;
        string s;

        for (int i = 0; i < n; ++i)
        {
            cin >> s;
            if (s == "AC")
            {
                ct1++;
            }

            if (s == "WA")
            {
                ct2++;
            }

            if (s == "TLE")
            {
                ct3++;
            }

            if (s == "RE")
            {
                ct4++;
            }
        }
        cout << "AC x " << ct1 << "\n";
        cout << "WA x " << ct2 << "\n";
        cout << "TLE x " << ct3 << "\n";
        cout << "RE x " << ct4 << "\n";
    }
}

Measured memory_bytes: 3656
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

n = int(input())
s = input()

x = [0]

for i in range(n):
    if (s[i] == "I"):
        x.append(x[i] + 1)
    else:
        x.append(x[i] - 1)
#print(x)
print(max(x))


Measured memory_bytes: 9068
import sys
n = int(input())
a = list(map(int, input().split()))
limit = 10 ** 18
res = 1

if 0 in a:
    print(0)
    sys.exit()

for i in range(n):
    res *= a[i]
    if res > limit:
        print(-1)
        sys.exit()

print(res)

Measured memory_bytes: 21588
//#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
///////////////////////////
//区間最小
struct RMQ{
    ll n;
    vector<l_l>data;
    RMQ(ll vs){
        n=1;
        while(n<vs)n*=2;
        data.resize(2*n-1,l_l(inf,-1));
    }
    void update(ll k,ll a){
        k+=n-1;
        data[k]=l_l(a,k-(n-1));
        while(k>0){
            k=(k-1)/2;
            data[k]=min(data[2*k+1],data[2*k+2]);
        }
    }
    l_l query(ll a,ll b,ll k,ll l,ll r){
        if(r<=a||b<=l)return l_l(inf,-1);
        if(a<=l&&r<=b){
            return data[k];
        }else{
            l_l vl=query(a,b,2*k+1,l,(l+r)/2);
            l_l vr=query(a,b,2*k+2,(l+r)/2,r);
            return min(vl,vr);
        }
    }
    l_l query(ll a,ll b){return query(a,b,0,0,n);}//[a,b)の最小値
};
//////////////////////////////////////////////////////

#define N 200005
ll n;
ll p[N];
RMQ od(N),ev(N);
void dfs(ll l,ll r,vector<l_l>&ans){
    if(l>r)return;
    if(l+1==r){
        ans.pb({p[l],p[r]});
        return;
    }
    ll sl=l,sr=l+1;
    if(l%2==0){
        sl=ev.query(l,r+1).se;
    }else{
        sl=od.query(l,r+1).se;
    }
    if(l%2==1){
        sr=ev.query(sl,r+1).se;
    }else{
        sr=od.query(sl,r+1).se;
    }
    ans.pb({p[sl],p[sr]});
    if(sl==l&&sr==l+1){
        dfs(l+2,r,ans);return;
    }
    if(sl==l&&sr==r){
        dfs(l+1,r-1,ans);return;
    }
    if(sl==r-1&&sr==r){
        dfs(l,r-2,ans);return;
    }
    vector<l_l>v[3];
    dfs(l,sl-1,v[0]);
    dfs(sl+1,sr-1,v[1]);
    dfs(sr+1,r,v[2]);
    ll sz[3];rep(i,0,2)sz[i]=v[i].size();
    ll pos[3];rep(i,0,2)pos[i]=0;
    
    
    while(1){
        ll minid=-1;
        rep(i,0,2){
            if(pos[i]<=sz[i]-1){
                if(minid==-1)minid=i;
                else if(v[i][pos[i]]<v[minid][pos[minid]])minid=i;
            }
        }
        if(minid==-1)break;
        ans.pb(v[minid][pos[minid]]);
        pos[minid]++;
    }
}
int main(){fastio
    cin>>n;
    rep(i,0,n-1)cin>>p[i];
    rep(i,0,n-1){
        if(i%2==0)ev.update(i,p[i]);
        else od.update(i,p[i]);
    }
    vector<l_l>ans;
    dfs(0,n-1,ans);
    for(auto x:ans)cout<<x.fi<<" "<<x.se<<" ";
    
    return 0;
}


Measured memory_bytes: 57080
#include<iostream>
using namespace std;
long long a,b,c,x,y;
long long ans=0;
int main()
{
	cin>>a>>b>>c;
	cin>>x>>y;
	ans=min(a*x+b*y,min(2*c*max(x,y),2*c*min(x,y)+a*(x-min(x,y))+b*(y-min(x,y))));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    str S;
    cin >> S;
    rep(i,S.size()){
        S[i]='x';
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,arr[4],i,j,ans=0;
	cin>>arr[0]>>arr[1]>>arr[2]>>arr[3];
	for(i=0;i<3;i++)
	{
		if(i==0)
		{
			ans += min(arr[i],arr[3]);
			arr[3]-=min(arr[i],arr[3]);
		}
		else if(i==1)
		{
			arr[3]-=min(arr[i],arr[3]);
		}
		else
		{
			ans += -1*min(arr[i],arr[3]);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3656
s=list(input())
if s[len(s)-1]=='2' or s[len(s)-1]=='4' or s[len(s)-1]=='5' or s[len(s)-1]=='7' or s[len(s)-1]=='9':
  print('hon')
elif s[len(s)-1]=='3':
  print('bon')
else:
  print('pon')

Measured memory_bytes: 9040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Volume0022
{
    class Program
    {
        static void Main(string[] args)
        {
            int numOfTerms = 0;
            while ((numOfTerms = int.Parse(Console.ReadLine())) != 0)
            {
                long[] termArray = new long[numOfTerms];
                List<long> sumTermsList = new List<long>();
                for (int i = 0; i < numOfTerms; ++i)
                {
                    termArray[i] = long.Parse(Console.ReadLine());
                }
                for (int i = 0; i < numOfTerms; ++i)
                {
                    long sumTerms = 0;
                    for (int j = i; j < numOfTerms; ++j)
                    {
                        sumTerms += termArray[j];
                        sumTermsList.Add(sumTerms);
                    }
                }
                Console.WriteLine(sumTermsList.Max());
            }
        }
    }
}



Measured memory_bytes: 100572
import java.util.*;
public class Main {
	public static void main(String [] args) {
		Scanner s = new Scanner(System.in);
		while (true) {
			int r = s.nextInt();
			int c = s.nextInt();
			int q = s.nextInt();
			if (r == 0) break;
			boolean [] r_used = new boolean[r];
			boolean [] c_used = new boolean[c];
			int r_cnt = c;
			int c_cnt = r;
			int [] alst = new int[q];
			int [] blst = new int[q];
			int [] olst = new int[q];
			for (int i=0;i<q;i++) {
				alst[q - i - 1] = s.nextInt();
				blst[q - i - 1] = s.nextInt();
				olst[q - i - 1] = s.nextInt();
			}
			int ans = 0;
			for (int i=0;i<q;i++) {
				int a = alst[i];
				int b = blst[i];
				int o = olst[i];
				if (a == 0) {
					if (o == 0) {
						if (!r_used[b]) {
							r_used[b] = true;
							c_cnt -= 1;
						}
					} else {
						if (!r_used[b]) {
							ans += r_cnt;
							r_used[b] = true;
							c_cnt -= 1;
						}
					}
				} else {
					if (o == 0) {
						if (!c_used[b]) {
							c_used[b] = true;
							r_cnt -= 1;
						}
					} else {
						if (!c_used[b]) {
							ans += c_cnt;
							c_used[b] = true;
							r_cnt -= 1;
						}
					}
				}
			}
			System.out.println(ans);
			
		}
	}
}


Measured memory_bytes: 446256
def dfs(A):
    global ans
    if len(A) == n + 1:
        now = 0
        for j in range(q):
            if A[b[j]] - A[a[j]] == c[j]:
                now += d[j]
        ans = max(ans, now)
        return

    B = list(A)
    B.append(A[-1])
    while B[-1] <= m:
        dfs(tuple(B))
        B[-1] += 1


n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
ans = 0

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

dfs(tuple([1]))

print(ans)


Measured memory_bytes: 9236
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void){

	int n,x;
	int ans;

	while(1){
		cin>>n>>x;
		if(n==0&x==0) break;
		ans=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					if(i!=j&&j!=k&&i!=k){
						if(i+j+k==x){
							ans++;
						}
					}
				}
			}
		}
		cout<<ans/6<<endl;
	}

	return 0;
}

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

int main() {
    int n, q, ans=0;
    cin >> n;
    int S[n];
    for(int i=0; i<n; i++) {
        cin >> S[i];
    }
    cin >> q;
    int T[q];
    for(int i=0; i<q; i++) {
        cin >> T[i];
    }
    for(int i=0; i<q; i++) {
        for(int j=0; j<n; j++) {
            if(S[j]==T[i]) {
                ans++;
                break;
            }
        }
    }
    cout << ans;
    cout << '\n';
}


Measured memory_bytes: 3072
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 200006
using namespace std;
struct arr{int x,y;}e[N];
int n,mi,ma,mima,mami;long long ans;
bool cmp(arr x,arr y)
{
	if(x.x==y.x)return x.y<y.y;
	return x.x<y.x;
}
int main()
{
	scanf("%d",&n);
	mi=mami=1000000000;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&e[i].x,&e[i].y);
		if(e[i].x>e[i].y)swap(e[i].x,e[i].y);
		mi=min(mi,e[i].x);ma=max(ma,e[i].y);
		mima=max(mima,e[i].x);mami=min(mami,e[i].y);
	}
	sort(e+1,e+n+1,cmp);ans=1LL*(mima-mi)*(ma-mami);
	for(int i=1;i<=n;i++){
		if(e[i].x>mami){
			ans=min(ans,1LL*(ma-mi)*(mima-mami));
			break;
		}
		ans=min(ans,1LL*(ma-mi)*(mima-e[i].x));
		mima=max(mima,e[i].y);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i < (int)(b);++i)


int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        vector<string> s(n);
        int cnt = 0;
        rep(i,n) {
            cin >> s[i];
        }
        int j = 0;
        while((j+1) < n) {
            if (s[j][0] != s[j+1][0]) {
                cnt++;
            }
            j += 2;
        }
        cout <<  cnt <<  endl;
    }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n; cin >> n;
    ll l[n];
    rep(i,n) cin >> l[i];
    sort(l,l+n);
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[k] + l[j] > l[i] && l[i] != l[j] && l[j] != l[k] && l[i] != l[k]) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
N, M = gets.split.map(&:to_i)
LRDs = readlines.map{|l| l.split.map(&:to_i)}

@g = Array.new(N){[]}
@x = Array.new(N, 0)
@v = Array.new(N, false)

LRDs.each do |l, r, d|
  l -= 1; r -= 1
  @g[l] << [r, d]
  @g[r] << [l, -d]
end
(0 ... N).each do |i|
  unless @v[i]
    @v[i] = true
    q = [i]
    while !q.empty?
      u = q.pop
      @g[u].each do |v, d|
        if @v[v]
          (puts 'No'; exit) if @x[v] != @x[u] + d
        else
          @x[v] = @x[u] + d
          @v[v] = true
          q << v
        end
      end
    end
  end
end
puts 'Yes'

Measured memory_bytes: 58236
#include <iostream>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

int main() {
  int N, Q;
  cin >> N >> Q;
  dsu d(N);
  for (int i = 0; i < Q; ++i) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      d.merge(u, v);
    } else {
      if (d.same(u, v)) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
  return 0;
}

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

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


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

int main() {
  int N; cin >> N;
  string ans = "No";
  for (int i = 0; i <= 100 / 4; i++)
    for (int j = 0; j <= 100 / 7; j++) if (4 * i + 7 * j == N) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int main(){
    int sum=0;
    for(int i=0;i<10;i++){
        int a;cin>>a;
        sum+=a;
    }
    cout<<sum<<endl;
    return 0;
}



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

typedef long long ll;
typedef long double ld;
const ll init = 1e9+7;

#define mkp make_pair
#define pb push_back
#define pq priority_queue
#define minpq priority_queue <int, vector<int>, greater<int> >
#define vi vector <int> 
#define vll vector <ll>
#define pii pair<int,int>

ll dp[1010][1010];
vector<string> v(1010);

ll find_dp(int i,int j){
	if(i<=0 || j<=0){
		return 0;
	}
	if(v[i-1][j-1]=='#'){
		dp[i][j]=0;
	}
	if(dp[i][j]==-1){
		dp[i][j] = (find_dp(i-1,j)+find_dp(i,j-1))%init;
	}
	return dp[i][j];
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int h,w; cin>>h>>w;
	for (int i = 0; i < h; ++i) cin>>v[i];
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			dp[i+1][j+1]=-1;
		}
	}
	dp[1][1]=1;
	ll ans=find_dp(h,w);
	cout<<ans<<endl;
    return 0;
} 

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

using namespace std;

void solve(int N, int K, vector<int> x) {
  int sum = 0;
  rep(i, N)
    sum += min(x[i], K - x[i]);
  cout << 2 * sum << endl;
}

int main(){
  // int 3E4
  // long 2E9
  // long long 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for(int i = 0 ; i < N ; i++){
    cin >> x[i];
  }
  solve(N, K, move(x));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template<typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
int check(int h, int w, int now1, int to1, const vvi &g) {
  queue<P> que;
  vi bfs(h*w, INF);
  que.push({0, now1});
  bfs[now1] = 0;
  while(!que.empty()) {
    int d, now;
    tie(d, now) = que.front(); que.pop();
    for(auto &to: g[now]) {
      if(now == now1 && to == to1) continue;
      if(bfs[to] > d + 1) {
        bfs[to] = d + 1;
        que.push({d + 1, to});
      }
    }
  }
  return bfs[h*w - 1];
}
bool solve() {
  int h, w;
  cin >> h >> w;
  if (h == 0 && w == 0) return false;
  vvi g(h*w);
  for(int i=0;i<(2 * h - 1);++i) {
    if (i % 2 == 0) {
      int r = i / 2;
      for(int j=0;j<(w - 1);++j) {
        int c; cin >> c;
        if(c == 0) {
          g[r * w + j].push_back(r * w + j + 1);
          g[r * w + j + 1].push_back(r * w + j);
        }
      }
    } else {
      int r = i / 2;
      for(int j=0;j<(w);++j) {
        int c; cin >> c;
        if(c == 0) {
          g[r * w + j].push_back((r + 1) * w + j);
          g[(r + 1) * w + j].push_back(r * w + j);
        }
      }
    }
  }
  int l = 0, r = 10000;
  while(r - l > 1) {
    int mid = (l + r) / 2;
    queue<P> que;
    vi bfs(h * w, INF);
    que.push({0, 0});
    bfs[0] = 0;
    while (!que.empty()) {
      int d, now;
      tie(d, now) = que.front();
      que.pop();
      for (auto &to: g[now]) {
        int ch = check(h, w, now, to, g);
        if(d + ch > mid) continue;
        if (bfs[to] > d + 1 && d + 1 <= mid) {
          bfs[to] = d + 1;
          que.push({d + 1, to});
        }
      }
    }
    if(bfs[h*w-1] == INF) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << (r == 10000 ? -1 : r) << endl;
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while (solve()) {}
}



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

using namespace std;

int func(int h[], int n)
{
  if (n == 1)	return 0;
  
  int dp[n];
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  
  for (auto i = 2; i < n; i++) {
    dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1],
                abs(h[i] - h[i - 2]) + dp[i - 2]);
  }
  
  return dp[n - 1];
}

int main()
{
  int n;
  cin >> n;
  
  int h[n];
  for (auto i = 0; i < n; i++)
    cin >> h[i];
	
  cout << func(h, n) << endl;
  
  return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int, input().split()))
ans=0
mn=10**9
hu=0
for i in range(n):
    if(a[i]<0):
        hu+=1
    tmp=abs(a[i])
    ans+=tmp
    mn=min(mn,tmp)
if(hu%2==1):
    ans-=mn*2
print(ans)

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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int n, k;

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin >> n >> k;
	int num = 0;
	int a = 1;
	while (a <= n)
	{
		a *= k;
		num++;
	}
	cout << num << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 50;

ll dist[160][10][80];

struct S {
	int x, y, jump;
	ll d;
	bool operator <(const S& x) const {
		return d > x.d;
	}
};

ll rec(S s) {
	return dist[s.y][s.x][s.jump];
}

void save(S s) {
	dist[s.y][s.x][s.jump] = s.d;
}

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

	int n, m;
	while(cin >> n >> m, n) {
		vector<ll> c[160];
		vector<ll> x[160];
		for(int i = 0; i < n; i++) {
			int k;
			cin >> k;
			for(int j = 0; j < k; j++) {
				ll xx, cc;
				cin >> xx >> cc;
				xx--;
				x[i].push_back(xx);
				c[i].push_back(cc);
			}
		}

		fill((ll*)begin(dist), (ll*)end(dist), INF);
		priority_queue<S> q;
		for(int i = 0; i < x[0].size(); i++) {
			S s = { i, 0, 0, 0 };
			q.push(s);
			save(s);
		}
		if(m > 0) {
			for(int i = 0; i < x[1].size(); i++) {
				S s = { i, 1, 1, 0 };
				q.push(s);
				save(s);
			}
		}


		ll ans = 0;
		while(q.size()) {
			S s = q.top();
			q.pop();
			if(rec(s) < s.d) continue;
			if(s.y == n) {
				ans = s.d;
				break;
			}
			for(int i = 1; i <= 2; i++) {
				if(s.jump == m && i == 2) break;
				if(s.y + i > n) break;
				int nj = s.jump + (i == 2);
				if(s.y + i == n) {
					S ns = { 0, s.y + i, nj, s.d };
					if(rec(ns) > s.d) {
						q.push(ns);
						save(ns);
					}
				}
				else {
					for(int j = 0; j < x[s.y + i].size(); j++) {
						int nx = x[s.y + i][j];
						ll cost = (c[s.y][s.x] + c[s.y + i][j]) * abs(x[s.y][s.x] - nx);
						S ns = { j, s.y + i, nj, s.d + cost };
						if(rec(ns) > ns.d) {
							q.push(ns);
							save(ns);
						}
					}
				}
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 7020