akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
int n;
vi depth;
vvi v;
void dfs(int i){
  vi k;int a=0;
  for(int x:v[i]){
    if(depth[x]==inf)dfs(x);
    k.pb(depth[x]);
  }
  sort(all(k));
  reverse(all(k));
  rep(i,k.size())chmax(a,k[i]+i+1);
  depth[i]=a;
}

int main(){
    cin>>n;
  v=vvi(n);
  REP(i,1,n){
    int a;cin>>a;a--;
    v[a].pb(i);
  }
  depth=vi(n);
  rep(i,n)depth[i]=inf;
  dfs(0);
  cout<<depth[0]<<endl;
}

Measured memory_bytes: 14336
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f

let util = ABC(stdin)

let rec gcd a b =
  if b > a 
  then gcd b a
  else if b = 0 // 0とのGCDをこう定義しても通常のGCDに影響を与えない
  then a
  else match a % b with
       | 0 -> b
       | c -> gcd b c

let N = util.Scan1 int
let xs = util.ScanVecH int

let Ls = Array.scan gcd xs.[0] xs
let Rs = xs |> Array.rev |> Array.scan gcd xs.[N-1] |> Array.rev
Array.set Ls 0 0
Array.set Rs N 0

[0..N-1]
|> List.map (fun i -> gcd Ls.[i] Rs.[i+1])
|> List.max
|> printfn "%d"


Measured memory_bytes: 40788
#include <iostream>
using namespace std;
 
int main()
{
    int num,prmnum[21786],k=0,ans1,ans2;
    num = 3;
    prmnum[0] = 2;
    while (num < 246912) {
        for (int i = 0; i <= k; i++) {
            if (num % prmnum[i] == 0) {
                break;
            }
            if (k == i) {
                k++;
                prmnum[k] = num;
            }
        }
        num += 2;
    }
    while (cin >> num) {
        if (num == 0) break;
        for (int i = 0; i < k; i++) {
            if (num < prmnum[i]) {
                ans1 = i;
                break;
            }
        }
        for (int i = k; i >= 0; i--) {
            if (num*2 >= prmnum[i]) {
                ans2 = i;
                break;
            }
        }
        ans1 = ans2 - ans1 + 1;
        cout << ans1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1244
n = int(input())
a = list(map(int, input().split()))
 
xs = [0] * (max(a) + 1)
 
for v in a:
    if xs[v] == 0:
        for j in range(v, len(xs), v):
            xs[j] += 1
    else:
        xs[v] += 1
print(len(list(filter(lambda v: xs[v] == 1, a))))

Measured memory_bytes: 116664
s='1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
puts s.gsub(',','').split.map(&:to_i)[gets.to_i-1]

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int N;
    string S, T, U;
    cin >> N >> S >> T;

    for (int i = 0; i < N; i++)
    {
        U.push_back(S[i]);
        U.push_back(T[i]);
    }
    
    cout << U << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// DON'T USE THESE MACROS DURING ICPC PRACTICE
#define For(i,n) for (int i=0; i<n; i++)
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define Down(i,n) for (int i=n-1; i>=0; i--)
#define DOWN(i,a,b) for (int i=b; i>=a; i--)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<int> vi;

const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(10);

	int n, k;
	cin >> n >> k;
	int a[n];
	For(i,n) {
		cin >> a[i];
	}

	int dp[n];
	dp[0] = 0;
	FOR(i,1,n-1) {
		dp[i] = dp[i-1] + abs(a[i]-a[i-1]);
		For(j,k && i-1-j>=0) {
			dp[i] = min(dp[i], dp[i-1-j] + abs(a[i]-a[i-1-j]));
		}
	}
	cout << dp[n-1] << nl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    string n; cin >> n;
    if ((n[0] == n[1] && n[1] == n[2])||(n[1] == n[2] && n[2] == n[3])) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string S;
ll A[MAX_N][2];
ll D[MAX_N][2];
ll B[2];

int popcount(int v) {
	if(v == 0) return 0;
	else return popcount(v % (__builtin_popcount(v))) + 1;
}

void solve() {
	cin >> N;
	cin >> S;
	int sum = 0;
	rep(i, 0, N) {
		sum += S[i] == '1';
	}
	reverse(all(S));
	B[0] = sum - 1; B[1] = sum + 1;
	A[0][0] = A[0][1] = 1;
	rep(i, 0, N) {
		rep(j, 0, 2) {
			if(B[j] <= 0) continue;
			A[i + 1][j] = A[i][j] * 2 % B[j];
			D[i + 1][j] = (D[i][j] + A[i][j] * (S[i] == '1')) % B[j];
		}
	}
	rer(i, N, 0) {
		int j = (S[i] == '0');
		if(B[j] == 0) {
			cout << 0 << "\n";
		}
		else {
			ll v = (D[i][j] + D[N][j] - D[i + 1][j] + A[i][j] * (j == 1) + B[j]) % B[j];
			cout << popcount(v) + 1 << "\n";
		}
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}




Measured memory_bytes: 10160
s = input()

is_palindrome = s == s[::-1]

first_sub_string = s[:int((len(s)-1)/2)]
first_is_palindrome = first_sub_string == first_sub_string[::-1]

second_sub_string = s[int((len(s)+3)/2)-1:]
second_is_palindrome = second_sub_string == second_sub_string[::-1]

if all([is_palindrome, first_is_palindrome, second_is_palindrome]):
    print("Yes")
else:
    print("No")

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

int n;
vector<int> v;

int solve(){
  bool f[10000];
  fill(f, f+10000, false);

  for(int i=1;i<=n;i++){
    for(int j=0;j<(int)v.size()-i+1;j++){
      int num = 0;
      for(int k=j;k<j+i;k++){
        num *= 10;
        num += v[k];
        if(num >= 10000) break;
      }
      if(num >= 10000) continue;
      f[num] = true;
    }
  }

  for(int i=0;i<10000;i++){
    if(!f[i]) return i;
  }
  return 10000;
}

int main(){
  while(cin >> n){
    v.clear();
    for(int i=0;i<n;i++){
      int x;
      cin >> x;
      v.push_back(x);
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1232
import math

def main():
    a, b, x = map(int, input().split())

    if x > a * a * b * 0.5:
        theta = math.atan(2*(a*a*b-x)/(a*a*a))
    else:
        theta = math.atan(a*b*b/(2*x))

    print(theta*180/math.pi)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38768
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;



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

	string s, t;
	cin >> s >> t;
	N = s.size();
	M = t.size();
	string ans;
	for (int i = 0; i <= N - M; i++) {
		string box = s;
		for (int j = 0; j < N; j++) {
			if (s[j] == '?') {
				box[j] = 'a';
			}
		}
		for (int j = i; j < i + M; j++) {
			box[j] = t[j-i];
		}
		bool flag = true;
		for (int j = 0; j < N; j++) {
			if (s[j] != box[j] && s[j] != '?') {
				flag = false;
			}
		}
		if (flag) {
			if(ans.empty()){
				ans = box;
			}
			else {
				ans = min(ans, box);
			}
		}
	}
	if (ans.empty()) {
		cout << "UNRESTORABLE\n";
		return 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int string_to_int(char a){
    if (a == '1') return 1;
    if (a == '2') return 2;
    if (a == '3') return 3;
    if (a == '4') return 4;
    if (a == '5') return 5;
    if (a == '6') return 6;
    if (a == '7') return 7;
    if (a == '8') return 8;
    if (a == '9') return 9;
    if (a == '0') return 0;
}

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<int> > dp(n+1, vector<int>(10, n));
  
    repr(i, n-1){
        rep(j, 10) dp[i][j] = dp[i+1][j];
        int num = string_to_int(s[i]);
        dp[i][num] = i;
    }
  
    int ans = 0;
    int judge;
    rep(i, 10)rep(j, 10)rep(k, 10){
        vector<int> key = {i, j, k};
        bool flag = true;
        judge = 0;
        rep(l, 3){
            judge = dp[judge][key[l]];
            if (judge == n) {
                flag = false;
                break;
            }
            judge++;
        }
        if (flag == true) ans++;
    }

    printf("%d", ans);
    return 0;
}



Measured memory_bytes: 5372
#include <iostream>
#include <string>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
 
using namespace std;
 
#define FOR(var,start,end) for(int var=start; var<end; var++)
#define REP(var,cnt) FOR(var,0,cnt)

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int retu[100010];
int pos[100010];

int main(void) {
	int N, M;
	cin >> N >> M;
	UnionFind uf(N+10);
	
	REP(i,N){
		int x;
		cin >> x;
		
		x--;
		retu[i] = x;
		pos[x] = i;
	}
	REP(i,M){
		int a,b;
		cin >> a >> b;
		uf.unionSet(a-1, b-1);
	}
	
	int ret = 0;
	REP(i,N) {
		if ( uf.findSet(i, pos[i]) ) {
			ret++;
		}
	}
	
	cout << ret << endl;
}


Measured memory_bytes: 1408
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();

		int ans = 0;
		for (int i = 0; i <=A; i++) {	
			for (int j = 0; j <=B; j++) {
				for (int k = 0; k <=C; k++) {
					int total = i*500+j*100+50*k;
					if (total == X) {
						ans++;
					}
				}
			}
		}
		out.println(ans);
		out.close();
	}

	//-----------http://codeforces.com/blog/entry/7018---------------------------------
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	//--------------------------------------------------------

}



Measured memory_bytes: 21204
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }


  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
     if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  bool operator == (Mint &a) const {
    return x==a.x;
  }

  bool operator != (Mint &a) const {
    return x!=a.x;
  }
};

struct data {
    long long d;
    int i;
    int j;
};

bool compareByLength(const data &a, const data &b)
{
    return a.d < b.d;
}

std::vector<std::pair<int, long long> > edge[304];

long long A[304][304];
long long D[304][304];
bool use[304][304];

int main(){
  int N;
  scanf("%d", &N);
  for (int i=0; i<N; i++){
    for (int j=0; j<N; j++){
      scanf("%lld", &A[i][j]);
      use[i][j] = true;
    }
  }
  //printf("hoge\n");
  for (int i=0; i<N; i++){
    for (int j=0; j<N; j++){
      for (int k=0; k<N; k++){
	if (i==j || j==k || i==k) continue;
	if (A[i][k]+A[k][j]<A[i][j]){
	  printf("-1\n");
	  return 0;
	}
      }
    }
  }
  //printf("aho\n");
  for (int k=0; k<N; k++){
    for (int i=0; i<N; i++){
      for (int j=0; j<N; j++){
	if (i==j || j==k || i==k) continue;
	if (A[i][k]+A[k][j]==A[i][j]){
	  use[i][j]=false;
	  //printf("use[%d][%d] false\n", i, j);
	}
      }
    }
  }
  //printf("ikuso\n");
  long long ans = 0;
  for (int i=0; i<N; i++){
    for (int j=i+1; j<N; j++){
      if (use[i][j]) ans += A[i][j];
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;


int main() {

	ll n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2 << endl;
	}
	else {
		ll ans = a;
		ll aa = 1;
		ll bb = b - a;
		ll ansa = (bb - aa) / 2 + ans;
		ans = n - b + 1;
		aa = a + n - b + 1;
		bb = n;
		ansa = min(ansa, (bb - aa) / 2 + ans);
		cout << ansa << endl;
		return 0;
	}
}

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

int dp[100010];

void dfs(vector<vector<int>> &G, int key){
    dp[key]=0;
    for(int i=0; i<G[key].size(); ++i){
        if(dp[G[key][i]]<0) dfs(G, G[key][i]);
        dp[key]=max(dp[key], dp[G[key][i]]+1);
    }
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g(N+1), revg(N+1);
	for(int i=0; i<M; ++i){
	    int x, y;
	    cin >> x >> y;
	    g[x].push_back(y);
	    revg[y].push_back(x);
	}
	vector<int> hc;
	for(int i=1; i<=N; ++i){
	    dp[i]=-1;
	    if(revg[i].size()<1) hc.push_back(i);
	}
	for(int i=0; i<hc.size(); ++i) dfs(g, hc[i]);
	int ans=0;
	for(int i=1; i<=N; ++i) ans=max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 16256
// https://atcoder.jp/contests/abc051/tasks/abc051_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    // 文字列の全置換
    replace(ALL(s), ',', ' ');
    cout << s << endl;
    return 0;
}

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

int main() {
    int n, h, w, ans = 0;
    vector<int> a, b;

    cin >> n >> h >> w;

    a.resize(n);
    b.resize(n);

    for (int i = 0; i < n; i++) 
        cin >> a.at(i) >> b.at(i);
    
    for (int i = 0; i < n; i++) {
        if (a.at(i) >= h && b.at(i) >= w)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    ll n, m;
    cin >> n >> m;
    if (m < n)
        swap(n, m);
    if (n == 1)
    {
        if (m == 1)
        {
            cout << 1 << endl;
            return 0;
        }
        cout << m - 2 << endl;
        return 0;
    }
    if (n == 2)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << (n - 2) * (m - 2) << endl;
    return 0;
}


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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n < 1200)
      System.out.println("ABC");
      else if (n < 2800)
      System.out.println("ARC");
      else
      System.out.println("AGC");
  }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int A[22],P[22];

int f[1<<20];

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>A[i];
    rep(i,N)cin>>P[i];

    rep(i,1<<N){
        int l=1;
        rep(j,N){
            if(!(i>>j&1))continue;
            int g=__gcd(l,A[j]);
            int u=A[j]/g;
            if(1.0*u*l<=M)l*=u;
            else l=M+1;
        }
        f[i]=M/l;
    }


    rep(i, N) rep(j, 1 << N) if(j & 1 << i) f[j] -= f[j ^ 1 << i];


    double ans=0.0;
    rep(i,1<<N){
        int tmp=abs(f[i]);
        double p=1.0;
        rep(j,N){
            if(i>>j&1)p*=P[j]/100.0;
            else p*=(100-P[j])/100.0;
        }
        ans+=p*(M-tmp);
    }
    printf("%.20f\n",ans);
    return 0;
}



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

int N;
int L[110];

int main()
{
  cin >> N;
  int maxi = 0;
  int sum = 0;
  REP(i,0,N) {
    cin >> L[i];
    maxi = max(maxi, L[i]);
    sum += L[i];
  }

  string ans;
  if (maxi < sum - maxi) ans = "Yes";
  else ans = "No";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

//const int N = 2000;

string lcs(string a, string b){
  int size = (int)a.size();
  vector< vector<int> > dp(size+1, vector<int>(size+1));
  vector< vector<int> > p(size+1, vector<int>(size+1));
  if(size > 2000) while(1);
  //int dp[N+1][N+1];
  //int p[N+1][N+1];
  //fill(dp[0], dp[N+1], 0);
  //fill(p[0], p[N+1], 0);
  for(int i=0;i<size;++i){
    for(int j=0;j<size;++j){
      if(a[i] == b[j]){
	dp[i+1][j+1] = dp[i][j] + 1;
	p[i+1][j+1] = 0;
      }else if(dp[i+1][j] < dp[i][j+1]){
	dp[i+1][j+1] = dp[i][j+1];
	p[i+1][j+1] = 1;
      }else{
	dp[i+1][j+1] = dp[i+1][j];
	p[i+1][j+1] = -1;
      }
    }
  }
  string res;
  for(int i=size, j=size;i>0 && j>0;){
    if(p[i][j] > 0) --i;
    else if(p[i][j] < 0) --j;
    else{
      res += a[i-1];
      --i;
      --j;
    }
  }
  reverse(res.begin(), res.end());
  return res;
}

main(){
  string input;
  while(cin >> input){
    string tmp = input;
    reverse(tmp.begin(), tmp.end());
    cout << lcs(input, tmp) << endl;
  }
  return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<","<<#y":"<<x<<","<<y<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int N;

int main(){
    cin >> N;
    vector<int> L(2*N);
    rep(i,2*N) cin >> L[i];

    sort(ALL(L));
    int sum=0;
    for(int i=0;i<2*N;i+=2){
        sum += L[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
from itertools import combinations as comb
from math import sqrt
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]


s = sum(sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2) for i,j in comb(range(n), 2))
print(s * 2 / n)

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

int main(){
    ll N;
    cin >> N;
    vector<ll> T(N), A(N);
    rep(i, 0, N) cin >> T[i] >> A[i];

    rep(i, 1, N){
        ll n = max((ll)((T[i-1]+T[i]-1)/T[i]), (ll)((A[i-1]+A[i]-1)/A[i]));
        T[i] *= n;
        A[i] *= n; 
    }

    cout << T[N-1] + A[N-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    ll a, b, c;
    cin >> a >> b >> c;

    if (c-a-b > 0 && 4*a*b < (c-a-b) * (c-a-b)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, x = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    
    if (S == "Y") {
      x++;
      break;
    }
  }
  
  if (x == 0)
    cout << "Three" << endl;
  
  else if (x == 1)
    cout << "Four" << endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
#define ll long long
static const int MAX = 1000010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;


int main() {

  int N;
  int ans;

  cin >> N;


  ans = N / 2 ;
  if( N % 2 == 0 ){
    ans--;
  }



  cout << ans << endl;


  return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100000], n, k, m, r;
inline void Div(int l, int s) {
	int p = l * 10, q = s;
	for (int i = 0; i < r + 10; i++) {
		a[i] += p / q; p = p%q; p *= 10;
	}
}
int main() {
	while (true) {
		for (int i = 0; i < 10200; i++)a[i] = 0;
		cin >> n >> k >> m >> r; if (n == 0)break;
		Div(1, n);
		if (m == 1) { for (int i = 1; i < n; i++) { Div(1, n*i); } }
		for (int i = r + 10; i >= 1; i--) {
			if (a[i] >= 10) { a[i - 1] += a[i] / 10; a[i] %= 10; }
		}
		cout << a[0] / 10 << '.'; for (int i = 0; i < r; i++)cout << a[i] % 10; cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
using namespace std;

int main(){
	int n, a;
	scanf("%d%d", &n, &a);
	printf("%d\n", n*n-a);
	return 0;
}

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

using namespace std;

int main(){
  int q,a,b;
  string str,s;

  cin >> str >> q;
  while(q--){
    cin >> s >> a >> b;
    if(s == "replace"){
      cin >> s;
      str.replace(str.begin()+a, str.begin()+b+1, s);
    }else if(s == "reverse"){
      reverse(str.begin()+a, str.begin()+b+1);
    }else{
      cout << str.substr(a, b-a+1) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3196
import java.math.BigInteger;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ


	    //入力数字の数を入力
		Scanner sc=new Scanner(System.in);

	    int count=sc.nextInt();

		boolean isOverflow = false;  // 桁あふれしたかフラグ
		BigInteger result=BigInteger.ZERO;
		BigInteger max=BigInteger.valueOf((long)Math.pow(10, 18));

	    //入力処理
		for(int i = 0; i < count; i++) {
			long a = sc.nextLong();

			// 桁あふれしている時は、それ以降ゼロが現れるかチェックする
			if (isOverflow) {
				// 桁あふれ後にゼロが出てきたとき
				if (a == (long)0) {
					// 求める値はゼロになる
					result = BigInteger.ZERO;
					isOverflow = false;
					break;
				}
				// 次の値を処理する
				continue;
			}

			// 積を求める
			BigInteger nyuryoku=BigInteger.valueOf(a);
			result= i==0 ? result.add(nyuryoku):result.multiply(nyuryoku);
			// 桁あふれしているか？
			if (result.compareTo(max) > 0) {
				isOverflow = true;
			}
		}

		// 結果を出力する
		if(isOverflow) {
			// 桁あふれ時は「-1」
			System.out.println(-1);
		} else {
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 48908
import java.util.*;
import java.io.*;
public class Main
{
    static BufferedReader br;
    static BufferedWriter bw;
    static void solve()throws Exception
    {
        int nmx[] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int n = nmx[0];
        int m = nmx[1];
        int x = nmx[2];
        int A[][] = new int[n][m+1];
        for(int i=0;i<n;i++)
        {
            A[i] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        }
        int ans = Integer.MAX_VALUE;
        for(int i=0;i<(1<<n);i++)
        {
            ArrayList<Integer> al = new ArrayList<Integer>();
            for(int j=0;j<n;j++)
            {
                if(((i>>j)&1)==1)
                al.add(j);
            }
            int cost = 0;
            ArrayList<Integer> tem = new ArrayList<Integer>();
            for(int j=0;j<m;j++)
            tem.add(0);
            for(int j =0 ;j<al.size();j++)
            {
                int temp = al.get(j);
                cost+=A[temp][0];
                for(int k=1;k<=m;k++)
                {
                    tem.set(k-1,tem.get(k-1)+A[temp][k]);
                }
            }
            boolean flag =true;
            for(int j=0;j<tem.size();j++)
            {
                if(tem.get(j)<x)
                {
                    flag = false;
                    break;
                }
            }
            if(flag)
            ans = Math.min(ans,cost);
        }
        if(ans == Integer.MAX_VALUE)
        ans = -1;
        bw.write(Integer.toString(ans));
    }
    public static void main(String []args)throws Exception
    {
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));
        solve();
        br.close();
        bw.close();
    }
}

Measured memory_bytes: 38368
#include <stdio.h>
#include <iostream>
#include <map>

std::map<char,char> hyou;


bool init()
{
	hyou.clear();
	int n;
	std::cin >> n;
	if(n==0)
		return false;
	for(int i=0; i<n; i++)
	{
		char c,d;
		std::cin >> c >> d;
		hyou[c] = d;
	}
	return true;
}

void solve()
{
	char dust[500];
	int n;
	std::cin >> n;
	std::cin.getline(dust,sizeof(dust));
	for(int i=0; i<n; i++)
	{
		char out;
		out = (char)getchar();
		if(hyou.find(out) != hyou.end())
			out = hyou[out];
		putchar((int)out);
		std::cin.getline(dust,sizeof(dust));
	}
	std::cout << std::endl;

	return;
}

int main(void) {
	while(init())
		solve();
	return 0;
}

Measured memory_bytes: 1176
import java.util.*;
import java.io.*;

public class Main {
    static long[] sodArr;

    public static void main(String[] args)throws Exception {
        InputReader in = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        // write your code here //
        int x = in.nextInt();
        genSOD(x);
        long sum = 0;
        for (int i = 1; i <= x; i++) {
            sum += sodArr[i] * i;
        }
        pw.println(sum);
        pw.close();
    }

    static void genSOD(long N) {
        sodArr = new long[10000000 + 1];
        for(int i = 1; i <= N; i++) {
            for(int j = i; j <= N; j += i) {
                sodArr[j]++;
            }
        }
    }

    /******************************
     ** IO STUFF STARTS FROM HERE**
     ******************************/

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

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

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

        //InputReader in = new InputReader(new FileReader("File_Name"));
        public InputReader(FileReader file) {
            reader = new BufferedReader(file);
            tokenizer = null;
        }

        public String next() {

            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens())
                    tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                return null;
            }

            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = null;
                line =  reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public boolean hasNext(){
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens())
                    tokenizer = new StringTokenizer(reader.readLine());
            }
            catch (Exception e) {
                return false;
            }
            return true;
        }
    }
}

Measured memory_bytes: 112552
nm = list(map(int, (input().split())))
if nm[1] == 0:
    print(0, 0)

else:    
    ans_dict = {}
    ans_list = [input().split() for i in range(nm[1])]
    for i in range(len(ans_list)):
        key_val = ans_list[i][0]

        try:
            ans_dict[key_val].append(ans_list[i][1])
        except:
            ans_dict[key_val] = [ans_list[i][1]]
    ans_cnt = 0
    wa_cnt = 0
    for key_val in ans_dict.keys():
        check_list = ans_dict[key_val]

        if "AC" in check_list:
            ans_cnt += 1
        else:
            pass
        try:
            wa_cnt += len(check_list[:check_list.index("AC")])
        except:
            pass
    print(ans_cnt, wa_cnt)    

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

int main(){
  int x,a,b;
  cin >>x >>a >>b;
  int fir = x-a;
  cout << fir%b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

map<pair<int,int>,int> mp;
int cx[300010], cy[300010];
int xmax, ymax;
vector<int> xlist, ylist;

int main(){
    int h, w, m;
    cin >> h >> w >> m;
    rep(i, m) {
        int x, y;
        cin >> y >> x;
        mp[{x,y}]++;
        cx[x]++, cy[y]++;
    }
    rep(i, 300010) xmax = max(xmax, cx[i]);
    rep(i, 300010) ymax = max(ymax, cy[i]);
    rep(i, 300010) if (cx[i] == xmax) xlist.push_back(i);
    rep(i, 300010) if (cy[i] == ymax) ylist.push_back(i);

    for(auto x : xlist){
        for(auto y : ylist){
            if (mp[{x,y}] == 0){
                cout << xmax + ymax << endl;
                return 0;
            }
        }
    }
    cout << xmax + ymax - 1 << endl;
    return 0;
}


Measured memory_bytes: 28468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;
  int N_org = N;
  int sum = 0;
  while (N>0){
    int v = N%10;
    N/=10;
    sum += v;
    //cout << v <<", "<< sum << endl;
  }
  
  if (N_org % sum == 0) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def resolve():
    n,m=map(int, input().split())
    l=list(map(int, input().split()))
    sou=sum(l)
    cnt=0
    l.sort(reverse=True)
    if l[m-1]>=sou*1/(4*m):
        print('Yes')
    else:
        print('No')
resolve()

Measured memory_bytes: 3060
import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Map as M
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  [h, w] <- readInts
  when ((h, w) /= (0, 0)) $ do
    forM_ [1..h] $ \_ -> do
      putStrLn $ replicate w '#'
    putChar '\n'
    main



Measured memory_bytes: 4080
#include <iostream>
#include <vector>
#include <cstring>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <climits>

using namespace std;
#define inf 0x3f3f3f3f
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
//const int mod=1e9+7;
const int N=1e5+7;
int a,b;
string s[10];

int main(){
    fast;
    int t=1;
    //cin>>t;
    while(t--){
        int x=0;
        cin>>a>>b;
        forn(i,a){
            cin>>s[i];
            forn(j,b){
                x+=(s[i][j]=='#');
            }
        }
        if(x==(a+b-1)) cout<<"Possible"<<endl;
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = list(map(int, input().split()))

S = []

for m in range(M):
    A, B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    s = 0
    for c in C:
        s |= 1 << (c-1)
    S.append((s, A))

DP = [float("inf")] * (1 << N)
DP[0] = 0

for i in range(1 << N):
    for s, a in S:
        t = i | s
        DP[t] = min(DP[t], DP[i] + a)

if DP[-1] == float("inf"):
    print(-1)
    sys.exit(0)

print(DP[-1])


Measured memory_bytes: 42588
import math
n, s = [int(input()) for _ in range(2)]


def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n // b) + n % b


if n == s:
    print(n + 1)
    exit()

for i in range(2, int(math.sqrt(n)) + 1):
    if f(i, n) == s:
        print(i)
        exit()

for p in range(int(math.sqrt(n)) + 1, 0, -1):
    if (n - s) % p == 0:
        b = (n - s) // p + 1
        if b >= 2 and f(b, n) == s:
            print(b)
            exit()

print(-1)


Measured memory_bytes: 3188
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val r = sc.nextInt()
    val d = sc.nextInt()
    val x = sc.nextInt()

    abc127b(r, d, x)
}

fun abc127b(r: Int, d: Int, x: Int){
    var xi = x
    for (i in 1..10) {
        xi = calc(r, xi, d)
        println(xi)
    }
}

private fun calc(r: Int, xi: Int, d: Int): Int {
    return r * xi - d
}

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

int main(){
	int n;
	while (cin >> n && n != 0){
		int t = 1, s = 2, e = 3;
		int total = 1;
		for (int i = 0; i < n; i++){
			string word;
			cin >> word;
			if (word == "North"){
				swap(t, s);
				s = 7 - s;
			}
			if (word == "East"){
				swap(t, e);
				t = 7 - t;
			}
			if (word == "West"){
				swap(t, e);
				e = 7 - e;
			}
			if (word == "South"){
				swap(t, s);
				t = 7 - t;
			}
			if (word == "Right"){
				swap(s, e);
				e = 7 - e;
			}
			if (word == "Left"){
				swap(s, e);
				s = 7 - s;
			}
			total += t;
		}
		cout << total << endl;
	}
}




Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#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];

    vector<int> rev(N);
    rep(i, N) rev[A[i]-1] = i + 1;
    rep(i, N) cout << rev[i] << endl;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
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; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main(){
	int n;
	cin >> n;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		mp[a]++;
	}
	int ans = 0;
	for (auto c : mp) {
		if (c.second % 2 != 0) ans++;
	}
	cout << ans;
	return(0);
}

Measured memory_bytes: 4992
#include<iostream>

using namespace std;

int main(){
    int a,b; 
    cin>>a>>b;
    if(a>=b){
        for(int i=0;i<a;i++)cout<<b;
    }else if(a<b){
        for(int i=0;i<b;i++)cout<<a;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
  int n,l;
  cin>>n>>l;
  int m=abs(l),sum=0;
  for(int i=1;i<=n;i++){
    sum+=l+i-1;
    if(abs(l+i-1)<abs(m))m=l+i-1;
  }
  cout<<sum-m<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 100000;
int N;
ll A[3*Nmax];

int main(){
	cin >> N;
	for(int i=0; i<3*N; i++) cin >> A[i];
	sort(A, A+3*N);

	ll ans = 0;
	for(int i=0; i<N; i++){
		ans += A[N+2*i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];
        Console.WriteLine(m * (m - 1) / 2 + n * (n - 1) / 2);
    }
}


Measured memory_bytes: 13268
package main

import (
	"bufio"
	"fmt"
	"io"
	"math/bits"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	_ = io.NextInt()
	s := io.Next()
	ans := solve2(s)
	for _, v := range ans {
		io.Println(v)
	}
}

// pcが変わるのでdrを再利用できない

func solve2(s string) []int {
	n := len(s)
	x := make([]int, n)
	for i := range s {
		x[i] = int(s[i] - '0')
	}
	pc0 := 0
	for i := range x {
		pc0 += x[i]
	}

	ans := make([]int, n)
	// 桁の値でforを回す。
	// 2n回ループを回すが、if文に引っかかるのはn回のみ。
	// 桁の値が同じものをまとめて処理することで、dr%pcを再利用できる
	for b := 0; b < 2; b++ {
		pc := pc0
		if b == 0 {
			pc++
		} else {
			pc--
		}
		if pc <= 0 {
			continue
		}
		r0 := 0
		for i := 0; i < n; i++ {
			r0 = (r0 * 2) % pc
			r0 += x[i]
		}
		dr := 1
		for i := n - 1; i >= 0; i-- {
			r := r0
			if x[i] == b {
				if b == 0 {
					r = (r + dr) % pc
				} else {
					r = (r - dr + pc) % pc
				}
				ans[i] = f(r) + 1
			}
			// 0->1を一括で処理
			// 1->0を一括で処理
			dr = (dr * 2) % pc
		}
	}
	return ans
}

func f(x int) int {
	if x == 0 {
		return 0
	}
	return f(x%pcnt(x)) + 1
}

func pcnt(x int) int {
	return bits.OnesCount(uint(x))
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

ll n, m, ans;

int main() {
  cin >> n >> m;
  vector<P> drink(n);
  rep (i, n) {
    cin >> drink[i].first >> drink[i].second;
  }
  sort(drink.begin(), drink.end());
  ans = 0;
  rep (i, n) {
    if (m <= drink[i].second) {
      ans += m * drink[i].first;
      break;
    } else {
      ans += drink[i].second * drink[i].first;
      m -= drink[i].second;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4820
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	long long a,b,c;
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0)
	cout<<0<<"\n";
	else
	cout<<min(a*b,min(a*c,b*c));
	return 0;
}

Measured memory_bytes: 256
/**
 *      ABC 82 B 
 *      author  : kyomukyomupurin
 *      created : 2018-09-02 05:40:02
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t; cin >> s >> t;
    vector<char> ss, tt;
    int sizes = s.size(); int sizet = t.size();
    for (int i = 0; i < sizes; ++i) {
        ss.push_back(s[i]);
    }
    for (int i = 0; i < sizet; ++i) {
        tt.push_back(t[i]);
    }

    sort(ss.begin(), ss.end()); sort(tt.begin(), tt.end()); reverse(tt.begin(), tt.end());

    string sss, ttt;
    for (int i = 0; i < sizes; ++i){
        sss.push_back(ss[i]);
    }
    for (int i = 0; i < sizet; ++i) {
        ttt.push_back(tt[i]);
    }

    sss < ttt ? cout << "Yes" : cout << "No";

    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string o, e;
    cin >> o >> e;
    string ans;
    for (int i = 0; i < o.size() + e.size(); ++i)
    {
        if (i % 2 == 0)
            ans.push_back(o[i / 2]);
        else
            ans.push_back(e[i / 2]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256