akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

	int n;
	cin >> n;

	vector<vector<int>> v(n, vector<int>(3));
	vector<vector<int>> dp(n, vector<int>(3));
	int result = -1;

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

	for (int i = 0; i < 3; i++)
	{
		dp[0][i] = v[0][i];
	}

	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			int m = -1;
			for (int k = 0; k < 3; k++)
			{
				if (j != k)
				{
					m = max(m, dp[i - 1][k]);
				}
			}
			dp[i][j] = v[i][j] + m;
		}
	}

	for (int j = 0; j < 3; j++)
	{
		result = max(result, dp[n - 1][j]);
	}

	// int pos = max_element(dp[n - 1].begin(), dp[n - 1].end()) - dp[n - 1].begin();
	// int result = dp[pos];
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t> B(N-1);
    for(int i=0; i<N-1; i++)
    {
        cin >> B.at(i);
    }
    int64_t sum=0;
    for(int i=0; i<N-2; i++)
    {
        sum+=min(B.at(i),B.at(i+1));
    }
    cout << sum+B.at(0)+B.at(N-2) << endl;
}


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

using namespace std;

typedef long long ll;

ll MOD = 1000000007;
//ll INF = 1LL<<60;
int INF = std::numeric_limits<int>::max();

int main(int, char**) {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> C;
	vector<vector<int>> A(n, vector<int>(m));
	for (int i=0; i<n; i++) {
		int c; cin >> c;
		C.push_back(c);
		for (int j=0; j<m; j++) {
			int a; cin >> a;
			A[i][j] = a;
		}
	}

	int ret = INF;
	for (int bit=0; bit < (1<<n); ++bit) {
		vector<int> M(m, 0);
		int nowcost = 0;
		for (int i=0; i<n; i++) {
			if (bit & (1<<i)){
				nowcost += C[i];
				for (int j=0; j<m; j++) {
					M[j] += A[i][j];
				}
			}
		}

		bool flag = true;
		for (int j=0; j<m; j++) {
			if (M[j] < x) flag = false;
		}

		if (flag) ret = min(ret, nowcost);
	}
	if (ret==INF) ret = -1;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3620
Q, H, S, D = map(int, input().split())
N = int(input())
kouho = []
mv = int(1e9)

if N % 2 == 0:
    for i, j in zip([Q, H, S, D], [0.25, 0.5, 1, 2]):
        kouho.append(int((N // j)*i))
else:
    for i, j in zip([Q, H, S, D], [0.25, 0.5, 1, 2]):
        kouho.append(int((N // j)*i))

    for i, j in zip([Q, H, S], [0.25, 0.5, 1]):
        mv = int(min(i // j, mv))
    kouho[-1] += mv
print(min(kouho))


Measured memory_bytes: 3064
import numpy as np
n,w = map(int,input().split())
dp = np.array([0]*(w+1))

for i in range(n):
    we,va = map(int, input().split())
    dp[we:] = np.maximum(dp[we:],dp[:-we]+va)

print(int(dp[-1]))

# n = 3 w = 8
# dp [0,1,2,3,4,5,6,7,8] = [0,0,0,0,0,0,0,0]
# we = 3 va = 30
# dp[3,4,5,6,7,8] = max(dp[3,4,5,6,7,8],dp[0,1,2,3,4,5]+30)
# dp [0:9] = [0,0,0,30s,30,30,30,30,30] 
# we = 4 va = 50
# dp[4,5,6,7,8] = max(dp[4,5,6,7,8],dp[0,1,2,3,4]+50)
# dp[4,5,6,7,8] = max(dp[4,5,6,7,8],dp[0,1,2,3,4]+50)
# dp[0:9] = [0,0,0,30,50,50,50,80,80]
# we = 5 va = 60
# dp[5,6,7,8] = max(dp[5,6,7,8],dp[0,1,2,3]+60)
# dp[0:9] = [0,0,0,30,50,60,60,80,90]

Measured memory_bytes: 14800
def gcd(a,b):
  if b == 0:return a
  return gcd(b,a%b)

N=int(input())
T=[]
if N==1:
  print(input())
  exit()
for i in range(N):
  t = int(input())
  T.append(t)
  if i == 0:continue
  elif i == 1:
    lcm = T[-2]*T[-1]//gcd(T[-2],T[-1])
  else:
    lcm = lcm * T[-1]//gcd(lcm,T[-1])

print(lcm)

Measured memory_bytes: 9044
import bisect


N, T = map(int, raw_input().split())

pairs = []
for i in range(N):
	_c, _t = map(int, raw_input().split())
	pair = [_c, _t]
	pairs.append(pair)

pairs = sorted(pairs, key=lambda x:x[1])
idx = bisect.bisect_right([i[1] for i in pairs], T)
res = sorted(pairs[:idx], key=lambda x:x[0])
if res == []:
	print "TLE"
else:
	print res[0][0]


Measured memory_bytes: 2688
c = gets.split(" ").map(&:to_i)
val = [1, 5, 10, 50, 100, 500]
res = 0
i = 5
sum = 0
while i >= 0
  sum += c[i]*val[i]
  (res = 1; break) if sum >= 1000
  i -= 1
end
puts res

Measured memory_bytes: 8640
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int A,B,ans;
    cin >> A >> B;

    if(A!=B){

        ans = max(A,B) * 2 -1;

    }else{

        ans = A+B;

    }

    cout << ans;

    return 0;
}

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int C = A + B;
    int news_min;
    if (C > N) news_min = C - N;
    else news_min = 0;
    if (A > B) cout << B << " " << news_min << endl;
    else cout << A << " " << news_min << endl;
}


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

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad
#define bad gooood

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 2e5 + 10;
const int M = (int) 20;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int ALPHA = 26;
const int mod = INF + 2;
const double PI = 3.14159265359;
const ld EPS = (ld) 1e-12;

const int nx[4] = {0, 0, -1, 1};
const int ny[4] = {1, -1, 0, 0};

int n;
vec a;

int main() {
  #define fn "saddle"
  #ifdef witch
      freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  #else
      //freopen(fn".in", "r", stdin);
      //freopen(fn".out", "w", stdout);
  #endif
  cin >> n;
  a.resize(n);
  int mn = 0, mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[mn] > a[i]) mn = i;
    if (a[mx] < a[i]) mx = i;
  } 
  vector<pii> ans;
  if (a[mx] > 0 && a[mn] < 0) {
    if (-a[mn] > a[mx]) {
      for (int i = 0; i < n; i++) {
        int d = a[mn];
        ans.pb(mp(mn, i));
        a[i] += d;
      }      
    } else {
      for (int i = 0; i < n; i++) {
        int d = a[mx];
        ans.pb(mp(mx, i));
        a[i] += d;
      }      
    } 
  }
  bool all_neg = 1, all_pos = 1;
  for (int i = 0; i < n; i++) {
    all_neg &= (a[i] <= 0);
    all_pos &= (a[i] >= 0);
  }
  if (all_neg) {
    for (int i = n - 2; i >= 0; i--) {
      ans.pb(mp(i + 1, i));
    }
  } else {
    assert(all_pos);
    for (int i = 1; i < n; i++) {
      ans.pb(mp(i - 1, i));
    }
  }
  cout << sz(ans) << endl;
  for (auto it : ans) cout << it.f + 1 << ' ' << it.s + 1 << endl; 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.mv", "r", stdin);
	string str = "";
	map <int, int> a;

	while ( getline (cin, str ) ){
		int n;
		stringstream ss(str);
		ss >> n;
		++a[n];
	} // end for
	multimap <int, int, greater<int> > order;
	map <int, int>::iterator it = a.begin();
	
	for (; it != a.end(); ++it){
		order.insert (make_pair ((*it).second, (*it).first ) );
	} // end for

	it = a.begin();
	multimap <int, int, greater<int> >::iterator ito = order.begin();
	int num = (int)order.count ((*it).second );
	for (int i = 0; i < num; ++i, ++ito){
		cout << (*ito).second << endl;
	} // end for
		
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main() {

	int i = 0, j = 0;

	for(i = 1; i <= 9; i++) {
		for(j = 1; j <= 9; j++) {
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}

	return 0;
}

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

int main(int argc, char *argv[])
{
    int N, M;
    std::cin >> N >> M;
    int diff = N - M;

    int ans = (1900*M + 100*diff) * std::pow(2, M);
    std::cout << ans << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,m:usize,
    }

    let mut v = vec![vec![0; n]; m]; //電球iと関連のあるswitch j
    for i in 0..m {
        input! {
        k:usize,
        s:[Usize1;k],}
        for j in 0..k {
            v[i][s[j]] = 1;
        }
    }
    input! {
        p:[usize;m],
    }

    let mut ans = 0;
    for switch_b in 0..1 << n {
        let mut ok = true;
        for denkyu in 0..m {
            let mut cnt = 0;
            for switch in 0..n {
                if switch_b >> switch & 1 == 1 {
                    cnt += v[denkyu][switch];
                }
            }
            if p[denkyu] != cnt % 2 {
                ok = false;
                break;
            }
        }
        if ok {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2208
use std::io;

fn main() {
    let N=get_int();
    match N {
        3|5|7 => println!("YES"),
        other => println!("NO"),
    }
}

fn get_String()->String{
    let mut s =String::new();
    io::stdin().read_line(&mut s).expect("Fail!");        
    s.trim().to_string()
}

fn get_int()->i32{
    let mut input =String::new();
    io::stdin().read_line(&mut input).expect("Fail!");
    input.trim().to_string().parse().unwrap()
}


Measured memory_bytes: 4352
from collections import defaultdict
import heapq
import sys
input = sys.stdin.readline
 
 
def main():
    N = int(input())

    D = []
    d = defaultdict(list)
    for i in range(1, N+1):
        s, p = input().split()
        D.append([s, int(p)*(-1), i])
    D.sort()

    for d in D:
        print(d[2])
        
 
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
"use strict";

function Main(input) {
  let lines = input.split('\n');
  // 数字列の長さ（今回は使用せず）
  let amount = lines[0]*1;
  // 検索対象の数字列
  let nums = lines[1];
  let ans = 0;
  // 999まで網羅できるか確認
  for(let i = 0; i < 1000; i++){
    // このループでの検索すべき配列
  	let baseNum = ("00" + String(i)).slice(-3);
    
    // ループごとに加工する値
    let row = nums;
    // カウント対象なのかを判定するフラグ
    let isOK = true;
    for(let j = 0; j < 3; j++){
      // 判定用のフラグ
      if(row.indexOf(baseNum[j]) != -1){
         row = row.substr( row.indexOf(baseNum[j]) + 1);
      } else {
        // 該当しなかったらフラグを切り替えてループ中止
        isOK = false;
        break;
      }
    }
    // ループを終了できたらカウント対象に入れる
    if(isOK){
      	ans++;
    }
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 8100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			if(b - a == c - b) {
				out.println("YES");
			} else {
				out.println("NO");
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}


Measured memory_bytes: 22612
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
#define MAXN 100
#define pii pair<int,int>

using namespace std;
char s[MAXN+80];
int main()
{
	int x=0,Max=0,n,i;
	scanf("%d",&n);
	getchar();
	fgets(s,108,stdin);
	for(i=0;i<n;i++)
	{
		x+=s[i]=='I';
		x-=s[i]=='D';
		Max=max(x,Max);
	}
	printf("%d",Max);
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aman Kumar Singh
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BRollerCoaster solver = new BRollerCoaster();
        solver.solve(1, in, out);
        out.close();
    }

    static class BRollerCoaster {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int n = ni(), k = ni();
            int cnt = 0, i = 0;
            for (i = 0; i < n; i++) {
                if (ni() >= k)
                    cnt++;
            }
            pn(cnt);
        }

        int ni() {
            return in.nextInt();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 34816
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        double r = sc.nextDouble();

        double a = (r*r)*(Math.PI);
        double c = 2*r*(Math.PI);
        
        System.out.println(String.format("%.6f", a)+" "+ (String.format("%.6f", c)));
        
        
    }
}





Measured memory_bytes: 28356
from collections import Counter
n = int(input())
lst = list(map(int, input().split()))
odd = Counter(lst[::2])
even = Counter(lst[1::2])
#print(odd, even)
omax = odd.most_common()[0]
emax = even.most_common()[0]
if len(odd) >= 2:
  osec = odd.most_common()[1]
if len(even) >= 2:
  esec = even.most_common()[1]
#print(omax, emax)

if omax[0] == emax[0]:
  if len(even) == 1 and len(odd) == 1:
    print(n // 2)
  elif len(even) == 1:
    print(n - emax[1] - osec[1])
  elif len(odd) == 1:
    print(n - omax[1] - esec[1])
  else:
    print(min(n - emax[1] - osec[1], n - omax[1] - esec[1]))
else:
  print(n - omax[1] - emax[1])

Measured memory_bytes: 24284
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int S;
	cin >> S;
	REP(hoge, S) {
		unsigned int num[9];
		REP(i, 9) {
			scanf("%x", &num[i]);
		}

		unsigned int ans = 0;
		REP(i, 32) {
			unsigned int sum = 0, mask = 1<<i;
			REP(j, 8) {
				sum += num[j];
			}
			if((sum&mask) != (num[8]&mask)) {
				ans |= mask;
			}
			REP(j, 9) {
				num[j] ^= (ans&mask);
			}
		}

		printf("%x\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1232
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int k,x;
    cin >> k >> x;
    FOR(i,x-k+1,x+k+1)
    {
        if(i!=x+k)
            cout << i << " ";
        else
            cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

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

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

int main() {
  int W, H;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (S[y][x] == '#') {
        continue;
      }
      int cnt = 0;
      for (int d = 0; d < 8; d++) {
        int nx = x + dx[d];
        int ny = y + dy[d];
        if (nx < 0 || nx >= W) {
          continue;
        }
        if (ny < 0 || ny >= H) {
          continue;
        }

        if (S[ny][nx] == '#') {
          cnt++;
        }
      }
      S[y][x] = '0' + cnt;
    }
  }

  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      cout << S[y][x];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
nlist = list(map(int, input().split()))
def BubbleSort(C, n):
    c = 0
    for i in range(n-1):
        for w in range(i+1, n):
            j = n-w+i
            if (C[j] < C[j-1]):
                a = C[j]
                C[j] = C[j-1]
                C[j-1] = a
                c += 1
    C.append(c)
BubbleSort(nlist, n)
for i in range(n):
    if (i == n-1):
        print('{}'.format(nlist[i]), end = '')
    else : 
        print('{}'.format(nlist[i]), end = ' ')
print()
print(nlist[-1])


Measured memory_bytes: 5612
#include <iostream>

void swap(int*, int*);

using namespace std;

int main(){
	int i, n, A[100000], cnt = -1;
	
	cin >> n;
	for(i=0;i<n;++i)cin >> A[i];
	for(i=0;i<n;++i){
		if(A[i] <= A[n-1]){
			cnt++;
			swap(&A[cnt], &A[i]);
		}
	}
	
	for(i=0;i<n;++i){
		if(i == cnt) cout << "[";
		cout << A[i];
		if(i == cnt) cout << "]";
		if(i != n-1) cout << " ";
	}
	cout << "\n";
	
	return 0;
}

void swap(int* a, int* b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}


Measured memory_bytes: 3428
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include <vector>
#include <cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b,c;
  	ci(a>>b>>c);
  ll x,y;
  	ci(x>>y);
  ll ans=INF;
  ll z=0;
  FOR(i,0,100001){
	chmin(ans,i*2*c+a*max(z,x-i)+b*max(z,y-i));
  }
  co(ans)
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	scanf("%d", &n);
	int ans=0;
	for(int i=0; i<n; i++){
		int a;
		scanf("%d", &a);
		while(a%2==0){
			a/=2;
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define ld long double
#define pp pair<ll,pair<ll,ll> >
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell 1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree< ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve() 
{
    ll n , m , c , ans = 0 ,x ;
    cin >> n >> m >> c ;
    vector<ll> v[n] , b(m) ;
    rep( i , 0 , m )
        cin >> b[i] ;
    rep( i , 0 , n )
    {
        ll cur = 0 ;
        rep( i , 0 , m )
        {
            cin >> x ;
            cur += x * b[i] ;
        }
        if(cur+c>0)ans++;
    }
    cout << ans ;
}   
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

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

int32_t main() {
IOS;
int n,state=1;
cin>>n;
deque<int> q;
    for (int i = 0; i < n; ++i) {
        int a;
        cin>>a;
        if(state)q.push_back(a);
        else q.push_front(a);
        state^=1;
    }
  if(!state){
      for(auto x=q.rbegin();x!=q.rend();x++){
          cout<<*x<<' ';
      }
  }else{
      for(auto x:q)cout<<x<<' ';
  }
}

Measured memory_bytes: 3840
#include <stdio.h>
#define SIZE 100
int main(void){
	int array[SIZE], *p, i, j, work, index, N;
	char str[6];
	
	fscanf(stdin, "%d", &N);
	
	p = array;
	while (p < (array + N)) fscanf(stdin, "%d", p++);
	
	// output stdout
	p = array;
	while (p < array +N -1) fprintf(stdout, "%d ", *p++);
	fprintf(stdout, "%d\n", *p);
	
	i = 1;
	while (i < N) {
		for (work = array[i], j = i -1; j >= 0 && array[j] > work; j--) array[j +1] = array[j];
		array[j +1] = work;
		
		// output stdout
		p = array;
		while (p < array +N -1) fprintf(stdout, "%d ", *p++);
		fprintf(stdout, "%d\n", *p);
		
		i++;
	}
	
	return 0;
}

Measured memory_bytes: 604
var
	A,B,C,K:Longint;
begin
	read(A,B,C,K);
	while A>=B do begin
		dec(K);
		B:=B*2;
	end;
	while B>=C do begin
		dec(K);
		C:=C*2;
	end;
	if K<0 then writeln('No')else writeln('Yes');
end.

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

int main() {
int a,b,c,s,t;
cin>>a>>b>>c;
s=max(a,b)-min(a,b);
t=max(a,c)-min(a,c);
if(s>=t){
  cout  <<  "B"  <<  endl;
}
else{
cout <<"A"<<endl;
}
}

Measured memory_bytes: 256
MOD = 10**9 + 7
def mul(A, B):
    return [[sum(A[i][k] * B[k][j] for k in range(N)) % MOD for j in range(N)] for i in range(N)]

N, K = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]

R = [[i==j for i in range(N)] for j in range(N)]
while K:
    if K & 1:
        R = mul(R, A)
    A = mul(A, A)
    K >>= 1
print(sum(sum(r) for r in R) % MOD)

Measured memory_bytes: 73436
# アルファベットから数値への変換
alpha2num = lambda c: ord(c) - ord('a') + 1

s = input()
t = input()

s_indexs = []
t_indexs = []

for i in range(len(s)):
    s_indexs.append(alpha2num(s[i]))

for i in range(len(t)):
    t_indexs.append(alpha2num(t[i]))

s_indexs.sort()
t_indexs.sort(reverse = True)

length = min(len(s),len(t))
for i in range(length):
    if s_indexs[i] < t_indexs[i]:
        print("Yes")
        exit()
    elif s_indexs[i] > t_indexs[i]:
        print("No")
        exit()

if len(s) < len(t):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    ll n,k;
    cin >> n >> k;
    cout << fixed << setprecision(0) << k*pow(k-1,n-1) << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <stdio.h>
 
long w[100];
int m,n;
long minhaba=1500000L;
 
long meyasuhaba;
 
int okeruka(int haba){
        int i;
        int dan=0;
        int danhaba=0;
 
        for(i=0;i<n;i++){
                if(w[i]>haba)return 0;
                if(danhaba+w[i]>haba){
                        dan++;
                        danhaba=0;
                }
                danhaba+=w[i];
        }
        return dan<m ? 1 : 0;
}
 
main(){
        long i;
        int sum;
        long  head,tail;
        while(1){
                scanf("%d %d",&m,&n);
                if(m==0)break;
                for(i=0;i<n;i++)scanf("%ld",&w[i]);
                head=0;
                tail=1500000L;
                do{
                        //printf("head,tail %ld,%ld\n",head,tail);
                        i=(head+tail)/2;
                        if(okeruka(i))
                                tail=i-1;
                        else
                                head=i+1;
                }while(tail-head>=0);
                i--;
                while(!okeruka(i))i++;
                printf("%ld\n",i);
        }
 
        return 0;
}

Measured memory_bytes: 600
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();

		boolean[] primes = new boolean[100010];
		int[] primeCount = new int[100010];

		Arrays.fill(primes, true);
		primes[0] = primes[1] = false;
		for (int i = 2; i < Math.sqrt(primes.length); i++) {
			for (int j = i; j < primes.length; j = j+i) {
				if (j == i) continue;
				primes[j] = false;
			}
		}

		for (int i = 1; i < primeCount.length; i++) {
			primeCount[i] = primeCount[i-1];
			if (primes[i] && primes[(i+1)/2]) primeCount[i]++;
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			System.out.println(primeCount[r] - primeCount[l-1]);
		}
	}

}

Measured memory_bytes: 67100
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
minus = Counter([i - a[i] for i in range(n)])
plus = Counter([i + a[i] for i in range(n)])

cnt = 0
for i in minus:
    if i in plus:
        cnt += minus[i] * plus[i]
print(cnt)


Measured memory_bytes: 61564
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

ll A[200010];
vector<ll> S;
int main()
{
	int N; cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	ll ans = 0, sum = 0;
	S.push_back(0);
	for (int i = 0; i < N; i++) {
		sum += A[i];
		S.push_back(sum);
	}
	sort(S.begin(), S.end());
	ll cnt = 0;
	for (int i = 0; i < S.size() - 1; i++) {
		if (S[i] == S[i + 1]) {
			cnt++;
		}
		else {
			ans += (cnt * (cnt + 1)) / 2;
			cnt = 0;
		}
	}
	ans += (cnt * (cnt + 1)) / 2;
	cout << ans << endl;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define int long long
#define sz(s) (int)(s).size() 
 
using namespace std;
const int hell = 1e9+7;

void solve(){
	int n , a = 0 ;
	cin >> n ;
	vector<int>arr(n);
	for(int i = 0 ; i < n ; i++ ) cin >> arr[i];
	for(int i =0 ; 	i <n ; i++) for( int j = i+1 ; j < n ;j++ )  a += arr[i]*arr[j];
	cout << a << endl; 
}
 
int32_t main(){                                    
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    	cout.precision(10);
    	cout << fixed;
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt","w",stdout);
#endif
        int q=1;
        //cin>>q;
        while(q--){
            solve();
        }
               
#ifdef LOCAL
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
 
	return 0;
}	
 

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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if (x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        for (int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for (int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for (int i = 1; i <= N; i++) {
            if (!(bits & (1 << (i - 1)))) continue;
            for (int j = 1; j <= A[i]; j++) {
                if (((bits >> (x[i][j] - 1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if (ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}

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


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

const ll INF = 1LL << 60;
struct Edge {int to, a, b;};

int main() {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	vector<vector<Edge>> g(n + 1);
	rep(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		g[u].push_back({v, a, b});
		g[v].push_back({u, a, b});
	}
	vector<ll> a(n + 1, INF);
	a[s] = 0;
	priority_queue<pll, vector<pll>, greater<pll>> q;
	q.push({0, s});
	while (!q.empty()) {
		pll p = q.top();
		q.pop();
		int v = p.second;
		if (a[v] < p.first) continue;
		for (Edge &e : g[v]) {
			if (a[v] + e.a < a[e.to]) {
				a[e.to] = a[v] + e.a;
				q.push({a[e.to], e.to});
			}
		}
	}
	vector<ll> b(n + 1, INF);
	b[t] = 0;
	q.push({0, t});
	while (!q.empty()) {
		pll p = q.top();
		q.pop();
		int v = p.second;
		if (b[v] < p.first) continue;
		for (Edge &e : g[v]) {
			if (b[v] + e.b < b[e.to]) {
				b[e.to] = b[v] + e.b;
				q.push({b[e.to], e.to});
			}
		}
	}
	vector<ll> ans(n + 2, 0);
	for (int i = n; i > 0; i--) {
		ans[i] = max(ans[i + 1], (ll)1e15 - (a[i] - a[s] + b[i] - b[t]));
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 12764
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
using Int = long long;
using namespace std;
const int MOD = 1000000007;
int main()
{
    int N; cin >> N;
    vector<int> primes;
    for (int i = 2; i <= N; i++) {
        for (int p : primes) {
            if (i % p == 0) {
                goto NEXT;
            }
        }
        primes.push_back(i);
        NEXT:;
    }
    int ans = 1;
    for (int p : primes) {
        int cnt = 0;
        for (int i = 1; i <= N; i++) {
            int t = i;
            while (t % p == 0) {
                t /= p;
                cnt++;
            }
        }
        ans = ((Int)ans * (cnt + 1)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;

#define MAX_N (2*100000)
int main() {
    cout.precision(15);
    cout << fixed;
    int A,B,H,M;
    ld t;
    cin >> A >> B>>H>>M;
    t=60*H+M;
    ld theta=M_PI*2*t/720;
    ld phi=M_PI*2*t/60;
    while(phi>M_PI*2)
        phi-=M_PI*2;
    ld d=abs(theta-phi);
    if(d>M_PI){
        d=2*M_PI-d;
    }
    ld ans=A*A+B*B-2*A*B*cos(d);
    cout<<sqrt(ans)<<endl;

}


Measured memory_bytes: 4152
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int x[1000][50000], n, m, a, b, c, s[100000], t[1000][2], sum, MAX;
int main() {
    memset(x, 127, sizeof(x));
    x[0][0] = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) { cin >> s[i]; sum += s[i]; }
    for (int i = 1; i <= m; i++) {
        cin >> t[i][0] >> t[i][1];
        for (int j = 0; j <= n; j++) {
            x[i][j] = min(x[i][j], x[i - 1][j]);
            a = min(t[i][0], n - j); c = 1;
            if (t[i][0] == 10000) { c = 10000; }
			else if (t[i][0] > 3000 && n == 10000) { c = t[i][0] / 2;}
            if (sum == n && n == 10000) { c = 10000; }
            for (int k = c; k <= a; k++) {
                x[i][j + k] = min(x[i][j + k], x[i - 1][j] + t[i][1]);
            }
        }
    }
    sort(s, s + n); sum = 0;
    for (int i = 0; i <= n; i++) {
        MAX = max(MAX, sum - x[m][i]);
        if (i != n) { sum += s[n - i - 1]; }
    }
    cout << MAX << endl;
    return 0;
}

Measured memory_bytes: 198472
import java.util.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      	String ans = "Yes";
		String[] w = new String[n];
		for(int i=0; i<w.length; ++i){
			w[i] = scn.next();
		}
      	String[] ww = new String[n];
      	for(int i=0; i<w.length; ++i){
			ww[i] = w[i];
		}
      	Arrays.sort(ww);
      	for(int i=1; i<w.length; ++i){
			if(ww[i].equals(ww[i-1])){
              ans = "No";
            }
		}
      	for(int i=1; i<w.length; ++i){
          char[] last = w[i-1].toCharArray();
          char[] first = w[i].toCharArray();
          if(last[last.length-1] != first[0]){
            ans = "No";
          }
        }
      	System.out.println(ans);
	}
}


Measured memory_bytes: 35992
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)



int main(){
	int a,b;
	cin >> a >> b;
	cout << a*b << endl;
	
	
	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int x[1000000],y[1000000];
int main(){
  int w,h,n;
  int i,j,t,r,s=0;
  int X[]={0,1,0,-1};
  int Y[]={1,0,-1,0};
  char m[1000][1001]={0};
  scanf("%d %d %d\n",&h,&w,&n);
  for(i=0;i<h;i++){
    for(j=0;j<=w;j++){
      scanf("%c",&m[i][j]);
      if(m[i][j]=='S'){
	x[0]=j;
	y[0]=i;
      }
    }
  }
  for(i=0;i<n;i++){
    t=0;
    r=1;
    int c[1000][1000]={0};
    for(t=0;m[y[r-1]][x[r-1]]!='0'+i+1;t++){
      for(j=0;j<4;j++){
	if(0<=x[t]+X[j]&&x[t]+X[j]<w&&
	   0<=y[t]+Y[j]&&y[t]+Y[j]<h&&
	   c[y[t]+Y[j]][x[t]+X[j]]==0&&
	   m[y[t]+Y[j]][x[t]+X[j]]!='X'){
	  x[r]=x[t]+X[j];
	  y[r]=y[t]+Y[j];
	  c[y[r]][x[r]]=c[y[t]][x[t]]+1;
	  r++;
	}
	if(m[y[r-1]][x[r-1]]=='0'+i+1)break;
      }
    }
    s+=c[y[r-1]][x[r-1]];//printf("%d\n",s);
    x[0]=x[r-1];
    y[0]=y[r-1];
  }
  printf("%d\n",s);
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> dp(n+1);
  dp[0] = 2;
  dp[1] = 1;

  for(int i = 2; i <= n; i++) {
    dp[i] = dp[i - 1] + dp[i - 2];
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 768
def main():
    mm,dd=map(int, input().split())
    cnt=0
    for m in range(1,mm+1):
        for d in range(22,dd+1):
            d1=d%10
            d10=d//10
            if d1<2 or d10<2:continue
            if d1*d10==m:cnt+=1
    print(cnt)
main()

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

using namespace std;

const int mxn = 2e5;

int a[mxn + 11];

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", a + i);
	}
	sort(a, a + n);
	long long ans = 0;
	for (int i = 0; i < n - k; i++){
		ans += a[i];
	}
	printf("%lld\n", ans);
	return 0;
}


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

struct state{
  int top, front, right;
  int tmp;

  state(){};
  state(int t, int f, int r){ top=t, front=f, right=r; }

  void north(){    tmp = top;
    top = front;
    front = 7 - tmp;
  }
  void east(){ tmp = top;
    top = 7 - right;
    right = tmp;
  }
  void west(){ tmp = top;
    top= right;
    right = 7- tmp;
  }
  void south(){ tmp=top;
    top=7-front;
    front = tmp;
  }
  void Right(){ tmp=front;
    front = right;
    right = 7-tmp;
  }
  void Left(){ tmp = front;
    front = 7-right;
    right = tmp;
  }
};

int main(){
  int n;
  state s;
  string str;

  while( cin >> n && n){
    s = state(1,2,3);

    int sum = 1;
    while( n-- ){
      cin >> str;
      if( str == "North" )	s.north();
      else if( str == "East")   s.east();
      else if( str == "West")   s.west();
      else if( str == "South")  s.south();
      else if( str == "Right")  s.Right();
      else                      s.Left();

      sum += s.top;
    }
    cout << sum << endl;

  }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans = ((h2 - h1) * 60 + m2 - m1) - k;
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	cin >> s;
	
	if( s.back() == '2' || s.back() == '4' || s.back() == '5' || s.back() == '7' || s.back() == '9' ) {
		cout << "hon" << endl;
	} else if( s.back() == '0' || s.back() == '1' || s.back() == '6' || s.back() == '8' ) {
		cout << "pon" << endl;
	} else {
		cout << "bon" << endl;
	}
	
	return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 1;
    int direction = 0;
    for (int i = 1; i < n; i++) {
        if (direction == 0) {
            if (a[i-1] == a[i]) continue;
            else if (a[i-1] < a[i]) direction = 1;
            else direction = -1;
        }
        else if (direction == 1) {
            if (a[i-1] <= a[i]) continue;
            ans++;
            direction = 0;
        }
        else { // direction == -1
            if (a[i-1] >= a[i]) continue;
            ans++;
            direction = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3756
<?php
[$N, $c['A'], $c['B'], $c['C']] = array_map('intval',explode(' ',trim(fgets(STDIN))));;
for($i = 0; $i < $N; $i++){
    $S[] = trim(fgets(STDIN));
}
$path = [];
dfs(0, $c);
echo "No\n"; // ゴールインできなかったらだめです！
function dfs($d, $c){ // &は参照渡し。そうしないと値の複製O(N)が実行され、全体でO(N^2)になる
    global $S, $N, $path; // PHPで関数外の変数を参照するにはこうやればよい
    if($d == $N){ // ゴールイン！
        echo "Yes\n";
        echo implode("\n", $path);
        exit;
    }
    $s = $S[$d];
    for($i = 0; $i < 2; $i++){ //1文字目と2文字目をそれぞれ試す
        if($c[$s[$i]] > 0){ 
            $path[] = $s[1-$i]; //経路を追加
            $c[$s[$i]]--; //片方をへらす
            $c[$s[1-$i]]++; //他方を増やす
            dfs($d+1, $c);
            $c[$s[$i]]++; // 元に戻す
            $c[$s[1-$i]]--; // 元に戻す
            array_pop($path); // 元に戻す
        }
    }
}


Measured memory_bytes: 129760
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int A, B, X;
	cin >> A >> B >> X;
	if(A <= X && X <= A + B){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// 080 B - Harshad Number 2017/12/03
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    uint64 a; cin >> a;
    uint64 sum=0;
    uint64 n=a;
    while(n/10>=0){
        sum+=n%10;
        if(n==0) break;
        n/=10;
    }
    if(a%sum==0) cout << "Yes";
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int h[100000];

int main() {
    int n, i;
    scanf("%d", &n);
    for(i = 0; i < n; i++) scanf("%d", &h[i]);
    for(i = n - 2; i >= 0; i--) {
        if(h[i] == h[i + 1] + 1) {
            h[i] -= 1;
        } else if(h[i] > h[i + 1]) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 512
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())

#dp[i][j]は、品数i,重さjのときの価値
dp =[[0 for i in range(W+1)] for j in range(N+1)] 
#表で表す

for i in range(N):#これは品数.i番目の品のオンオフ
    for j in range(W+1):#これは許容される重さの合計
        #選ぶ場合
        if j - w[i]>=0:
            dp[i+1][j]=max(dp[i][j],(dp[i][j-w[i]]+v[i]))
        #選ばない場合と比較
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])

print(dp[N][W])

Measured memory_bytes: 171784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		System.out.println(Math.max(a + b, Math.max(a * b, a - b)));
	}
}


Measured memory_bytes: 23764
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;

int num[3];

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

	num[0]=-1;
	num[1]=-1;
	num[2]=-1;
	long long ans = 1;
	for(int i=0;i<N;i++){
		int m=0;
		int p;
		for(int j=0;j<3;j++){
			if(A[i]-1 ==num[j]){
				m += 1;
				p = j;
			}
		}
		ans = (ans * m)%1000000007;
		num[p] = A[i];
	}
	cout << ans << "\n";
}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[][] a = new int[n+1][n+1];
		for(int i = 0; i < n; i++) {
			
			String[] str = br.readLine().split(" ");
			int u = Integer.parseInt(str[0]);
			for(int j = 2; j < str.length; j++){
				a[u][Integer.parseInt(str[j])] = 1;
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(j > 1){
					sb.append(" ");
				}
				sb.append(a[i][j]);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}

}

Measured memory_bytes: 25480
W, H, N = map(int, input().split())
xl, xh = (0, W)
yl, yh = (0, H)
for i in range(N):
    x, y, a = map(int, input().split())
    xl = max(xl, x) if (a==1) else xl
    xh = min(xh, x) if (a==2) else xh
    yl = max(yl, y) if (a==3) else yl
    yh = min(yh, y) if (a==4) else yh
print(max(xh-xl, 0)*max(yh-yl, 0))

Measured memory_bytes: 3064
//---------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                        NEVER  GIVE  UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//------------------------------------------------------------------------------------------------------------------------------

int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("C:/Users/DELL/Desktop/input.txt", "r", stdin);
	#endif

	fast;
	int n;
	cin>>n;
	cout<<!n;
	return 0;
}


Measured memory_bytes: 3592