akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

int main() {
	int a, b, c, d, e, ans;
	cin >> a >> b >> c >> d >> e;
	if (a > 0) ans = (b - a)*e;
	else ans = (a*-1)*c + d + b * e;

	cout << ans << endl;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, k;
  string s;
  cin >> n >> k >> s;

  vector<pair<char, int>> comp_s{{s.front(), 1}};
  for (int i = 1; i < s.size(); ++i) {
    auto &last_p = comp_s.back();
    if (last_p.first == s[i]) {
      last_p.second++;
    } else {
      comp_s.push_back({s[i], 1});
    }
  }

  vector<int> z_indeces;
  for (int i = 0; i < comp_s.size(); ++i) {
    if (comp_s[i].first == '0') {
      z_indeces.push_back(i);
    }
  }

  if (z_indeces.size() <= k) {
    cout << s.size() << '\n';
    return 0;
  }

  vector<int> csum{0};
  for (int i = 0; i < z_indeces.size(); i++) {
    int idx = z_indeces[i];
    int cnt = comp_s[idx].second;
    if (idx + 1 < comp_s.size()) {
      cnt += comp_s[idx + 1].second;
    }

    csum.push_back(csum.back() + cnt);
  }

  int ans = 0;
  for (int i = 0; i < csum.size() - k; ++i) {
    int cnt = csum[i + k] - csum[i];
    if (z_indeces[i] > 0) {
      int idx = z_indeces[i] - 1;
      cnt += comp_s[idx].second;
    }

    ans = max(ans, cnt);
  }

  cout << ans << '\n';
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   int a,b,ans=0; double c; cin>>a>>b;
   ans = double(a+b)/2 + 0.9;
   cout<<ans<<endl;
}


Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<usize> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();
    println!("{}", if v[0]*2 >= v[1] {v[1]/2} else {v[0]+(v[1]-v[0]*2)/4});
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define endl '\n'
#define first F
#define second S
typedef long long ll;

int pass(int m, int k){
	int cnt=0;
	while(m<k){
		m*=2;
		cnt++;
	}
	return cnt;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	double ans=0;
	for(int i=1; i<=n; i++){
		int x = 1<<pass(i, k);
		double prob = 1.0/(x*1.0);
		ans+=((1.0/n*1.0)*prob);
	}
	cout<<fixed<<setprecision(12)<<ans<<endl;
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	int A[N];
	for (int i=0; i<N; i++){
	    cin >> A[i];
	}
	int ans=100000000;
	for (int i=0; i<=100; i++){
	    int cost=0;
	    for (int j=0; j<N; j++){
	        cost+=(A[j]-i)*(A[j]-i);
	    }
	    ans=min(ans, cost);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

struct edge { ll from, to, cost; };
std::vector<P>v[100010];
edge es[2100];
ll d[1100];
ll n, m, a, b, c;

bool bellman(int s) {
	for (int i = 1;i <= n;i++)d[i] = INF2;
	d[s] = 0;
	for (int j = 0;j < n;j++) {
		for (int i = 0;i < m;i++) {
			edge e = es[i];
			if (d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				if (j == n - 1 && e.to == n)return true;
			}
		}
	}
	return false;
}

int main() {
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		cin >> a >> b >> c;
		c *= -1;
		es[i] = edge{ a,b,c };
	}
	if (bellman(1)) cout << "inf" << endl;
	else cout << d[n] * (-1) << endl;
	return 0;
}

Measured memory_bytes: 2688
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    string s;
    cin >> s;
    if (s.size() >= 3) {
        for (int i = 0; i < s.size() - 2; ++i) {
            if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
                cout << i + 1 << " " << i + 3 << endl;
                return 0;
            }
        }
    }
    else if (s.front() == s.back()) {
        cout << "1 2\n";
        return 0;
    }
    cout << "-1 -1\n";
    return 0;
}

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

#define INC(i, a, b) for(int i = a; i < b; ++i)
#define DEC(i, a, b) for(int i = a; i > b; --i)
#define REP(i, n)    for(uint i = 0; i < n; ++i)

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

using namespace std;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        cout << T << endl;
    }else{
        cout << F << endl;
    }
}
int min(int a, int b){
    return a < b? a: b;
}
int main(){
    int N, gates, start; cin >> N >> gates >> start;
    int g = 0;
    int temp;

    REP(i, gates){
        cin >> temp;
        if(temp < start){
            g++;
        }else{
            break;
        }
    }
    cout << min(gates - g, g) <<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 16:40:33 2020

@author: shinba
"""
from collections import deque

s = deque(input())
t = deque(input())

for i in range(len(s)):
    s.rotate()
    if s == t:
        print("Yes")
        break
else:
    print("No")


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

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    long long x, k, d;
    std::cin >> x >> k >> d;
    x = std::abs(x);
    long long steps = std::min(k, x / d);
    x -= steps * d;
    k -= steps;
    if (k % 2 == 0) {
        std::cout << x;
    } else {
        std::cout << std::abs(x - d);
    }
}


Measured memory_bytes: 3644
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cctype>
using namespace std;
typedef long long ll;

const int N = 2010;
int n, k;
int a[N][N], b[N][N];
char ch[5];

inline int sum(int a[N][N], int i, int j, int x, int y) {
	return a[x][y]-a[x][j-1]-a[i-1][y]+a[i-1][j-1];
}
inline int cal(int a[N][N], int i, int j) {
	int ret = sum(a, i, j, i+k-1, j+k-1)+sum(a, 1, 1, i-1, j-1)+sum(a, i+k, j+k, k<<1, k<<1);
	ret += sum(a, i+k, 1, k<<1, j-1)+sum(a, 1, j+k, i-1, k<<1);
	return ret;
}
int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i ++) {
		int x, y; scanf("%d%d%s", &x, &y, ch);
		x %= (k<<1); y %= (k<<1); x ++, y ++;
		//printf("%d %d\n", x, y);
		if(ch[0] == 'W') a[x][y] ++; else b[x][y] ++;
	}
	for(int i = 1; i <= k<<1; i ++)
		for(int j = 1; j <= k<<1; j ++) {
			a[i][j] += a[i][j-1] + a[i-1][j] - a[i-1][j-1];
			b[i][j] += b[i][j-1] + b[i-1][j] - b[i-1][j-1];
		} int ans = 0;
	//printf("%d\n", cal(b, 2, 2));
	for(int i = 1; i <= k; i ++)
		for(int j = 1; j <= k; j ++) {
			//(i,j)~(k,k)全白/黑 
			int tmp = cal(a, i, j);
			int tmpp = cal(b, i, j);
			tmpp = b[k<<1][k<<1] - tmpp;
			ans = max(ans, tmp+tmpp);
			tmp = cal(b, i, j);
			tmpp = cal(a, i, j);
			tmpp = a[k<<1][k<<1] - tmpp;
			ans = max(ans, tmp+tmpp);
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 31744
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <deque>

using namespace std;

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

	int n;
	cin >> n;

	if (n % 111 == 0) {
		cout << n << endl;
	} else {
		int t = n / 111;
		cout << (t + 1) * 111 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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 under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s(h);
	rep(i, h) {
		cin >> s[i];
	}
	VV ans(h, V(w, -1));
	vector<P<int>> pla;
	int num = 1;
	rep(i, h) rep(j, w) {
		if (s[i][j] == '#') {
			ans[i][j] = num;
			num++;
			queue<P<int>> que;
			int dy[2] = { 1,-1 };
			que.push(make_pair(i, j));
			while (!que.empty()) {
				int y = que.front().first;
				int x = que.front().second;
				que.pop();
				rep(dir, 2) {
					int ny = y + dy[dir];
					if (ny < 0 || ny >= h) continue;
					if (ans[ny][x] != -1) continue;
					if (s[ny][x] == '#') continue;
					ans[ny][x] = ans[y][x];
					que.push(make_pair(ny, x));
				}
			}
		}
	}
	rep(i, h) rep(j, w) {
		if (ans[i][j] == -1) {
			if (j == 0) ans[i][j] = ans[i][j + 1];
			else ans[i][j] = ans[i][j - 1];
		}
	}
	rep(i, h) for (int j = w - 1; j > 0; j--) {
		if (ans[i][j - 1] == -1) ans[i][j - 1] = ans[i][j];
	}
	rep(i, h) {
		rep(j, w) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    unsigned long long ans = 0;
    for(int i = 1; i <= n; ++i){
        ll N = n / i;
        ll cnt = (N * (2 * i + (N - 1) * i)) / 2;
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(), m = scanner.nextInt();
		int[][] matrix = new int[n][m];
		int[] vector = new int[n];

		for (int i = 0; i < n; i++) {
			for (int i2 = 0; i2 < m; i2++) {
				matrix[i][i2] = scanner.nextInt();
			}
		}

		for (int i = 0; i < m; i++) {
			int number = scanner.nextInt();

			for (int i2 = 0; i2 < n; i2++) {
				vector[i2] += matrix[i2][i] * number;
			}
		}

		for (int i = 0; i < n; i++) {
			System.out.println(vector[i]);
		}
	}
}

Measured memory_bytes: 41268
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    sort(a, a + n);
    ll b[n];
    b[n / 2] = a[0];
    int now = 0;
    int t;
    for(int i = n / 2; i < n; i += 2){
        b[i] = a[now];
        now += 2;
        t = i;
    }
    int u = n - 1;
    if(t == n - 1) u = n - 2;
    for(int i = u; i > n / 2; i -= 2){
        b[i] = a[now];
        now += 2;
    }
    now = 1;
    for(int i = n / 2 - 2; i >= 0; i -= 2){
        b[i] = a[now];
        now += 2;
        t = i;
    }
    u = 0;
    if(t == 0) u = 1;
    for(int i = u; i < n / 2; i += 2){
        b[i] = a[now];
        now += 2;
    }
    ll ans1 = 0;
    REP(i,n - 1){
        ans1 += abs(b[i + 1] - b[i]);
    }
    reverse(a, a + n);
    b[n / 2] = a[0];
    now = 0;
    t;
    for(int i = n / 2; i < n; i += 2){
        b[i] = a[now];
        now += 2;
        t = i;
    }
    u = n - 1;
    if(t == n - 1) u = n - 2;
    for(int i = u; i > n / 2; i -= 2){
        b[i] = a[now];
        now += 2;
    }
    now = 1;
    for(int i = n / 2 - 2; i >= 0; i -= 2){
        b[i] = a[now];
        now += 2;
        t = i;
    }
    u = 0;
    if(t == 0) u = 1;
    for(int i = u; i < n / 2; i += 2){
        b[i] = a[now];
        now += 2;
    }
    ll ans2 = 0;
    REP(i,n - 1){
        ans2 += abs(b[i + 1] - b[i]);
    }
    cout << max(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 1916
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_2-C: Stable Sort

#include <cstring>
#include <algorithm>
#include <iostream>

struct Card {
  char suit;
  unsigned int rank;
  bool operator<(const Card& rhs) { return rank < rhs.rank; }
  bool same(const Card& rhs) { return rank == rhs.rank && suit == rhs.suit; }
};

std::ostream& operator<<(std::ostream& os, const Card& card)
{
  return os << card.suit << card.rank;
}

std::istream& operator>>(std::istream& is, Card& card)
{
  return is >> card.suit >> card.rank;
}

static void print_cards(const Card cards[], const unsigned int n)
{
  const char* sep = "";
  for (unsigned int i = 0u; i < n; ++i) {
    std::cout << sep << cards[i];
    sep = " ";
  }
  std::cout << std::endl;
}

static void bubble_sort(Card cards[], const unsigned int n)
{
  for (unsigned int j = 0u; j < n-1; ++j) {
    for (unsigned int i = n-1; i > j; --i) {
      if (cards[i] < cards[i-1]) {
        std::swap(cards[i], cards[i-1]);
      }
    }
  }
}

static void selection_sort(Card cards[], const unsigned int n)
{
  for (unsigned int i = 0u; i < n-1; ++i) {
    unsigned int min_j = i;
    for (unsigned int j = i+1; j < n; ++j) {
      if (cards[j] < cards[min_j]) {
        min_j = j;
      }
    }
    if (i != min_j) {
      std::swap(cards[i], cards[min_j]);
    }
  }
}

int main()
{
  unsigned int n;
  std::cin >> n;
  Card cards1[n], cards2[n];
  for (unsigned int i = 0u; i < n; ++i) {
    std::cin >> cards1[i];
  }
  std::memcpy(cards2, cards1, sizeof(cards1));
  /*
  for (unsigned int i = 0u; i < n; ++i) {
    cards2[i] = cards1[i];
  }
  */
  bubble_sort(cards1, n);
  print_cards(cards1, n);
  std::cout << "Stable" << std::endl; // bubble sort is stable

  selection_sort(cards2, n);
  print_cards(cards2, n);
  /*
  if (std::memcmp(cards1, cards2, sizeof(cards1)) == 0) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }
  */
  for (unsigned int i = 0u; i < n; ++i) {
    /*
    if (!(cards2[i].rank == cards1[i].rank &&
          cards2[i].suit == cards1[i].suit)) {
    */
    if (!cards2[i].same(cards1[i])) {
      std::cout << "Not stable" << std::endl;
      return 0;
    }
  }
  std::cout << "Stable" << std::endl;
}

// eof

Measured memory_bytes: 3152
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int m, n;
	int sx, sy, gx, gy;
	int[][] a;

	void run(){
		for(;;){
			m=sc.nextInt();
			n=sc.nextInt();
			if((m|n)==0){
				break;
			}
			a=new int[n][m];
			for(int j=0; j<n; j++){
				for(int i=0; i<m; i++){
					a[j][i]=sc.nextInt();
					// 0:Ç
					// 1:ó
					// 2:ú
					// 3:S[
					// 4:H¢¨
					if(a[j][i]==2){
						sx=i;
						sy=j;
						a[j][i]=1;
					}else if(a[j][i]==3){
						gx=i;
						gy=j;
						a[j][i]=1;
					}
				}
			}
			solve();
		}
	}

	void solve(){
		int max=7;
		int[][][] d=new int[n][m][max];
		boolean[][][] visited=new boolean[n][m][max];
		LinkedList<P> que=new LinkedList<P>();

		for(int j=0; j<n; j++){
			for(int i=0; i<m; i++){
				fill(d[j][i], INF);
			}
		}

		que.offer(new P(sx, sy, 6));
		d[sy][sx][6]=0;
		visited[sy][sx][6]=true;

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

		for(; !que.isEmpty();){
			P p=que.poll();
			// debug(p.x, p.y, p.hp);
			for(int i=0; i<4; i++){
				P q=new P(p.x+dx[i], p.y+dy[i], p.hp-1);
				// debug(q.x, q.y, q.hp);
				if(q.x>=0&&q.x<m&&q.y>=0&&q.y<n&&a[q.y][q.x]!=0&&q.hp>0){
					if(a[q.y][q.x]==4){
						q.hp=6;
					}
					if(!visited[q.y][q.x][q.hp]){
						que.offer(q);
						d[q.y][q.x][q.hp]=d[p.y][p.x][p.hp]+1;
						visited[q.y][q.x][q.hp]=true;
					}
				}
			}
		}

		for(int j=0; j<n; j++){
			for(int i=0; i<m; i++){
				// debug(i, j, d[j][i]);
			}
		}

		// debug(d[gy][gx]);

		int ans=INF;
		for(int k=0; k<max; k++){
			ans=min(ans, d[gy][gx][k]);
		}
		println((ans!=INF?ans:-1)+"");
	}

	class P{
		int x, y, hp;

		P(int x, int y, int hp){
			this.x=x;
			this.y=y;
			this.hp=hp;
		}
	}

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

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	string s;
	cin >> s;
	int ans = 0;
	int dir = 0;
	int target = 0;
	REP(i, s.length()) {
		if (dir == 0) {
			target = 0;
		}
		if (s[i] == 'R') {
			if (dir == 0) {
				target = 1;
			}
			else if (dir == 3) {
				ans += target;
			}
			dir++;
			dir %= 4;
		}
		else {
			dir--;
			dir += 4;
			dir %= 4;
		}
	}
	cout << ans << endl;
}

#undef int
int main() {
	init();
	solve();
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B, X;
    cin >> A >> B >> X;
    if (A * A * B == X)
    {
        cout << 0 << endl;
        return 0;
    }

    if (A * A * B >= 2 * X)
    {
        double t = 2.0 * (double)X / (double)(A * B);
        double theta = std::atan((double)B / t) * 180.0 / M_PI;
        cout << OF64 << theta << endl;
    }
    else
    {

        double t = 2.0 * B - 2.0 * ((double)X / (double)(A * A));

        double theta = std::atan(t / (double)A) * 180.0 / M_PI;

        cout << OF64 << theta << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool used[1000005];

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a[0];
    ll g = a[0];
    for(int i = 1; i < n; ++i){
        cin >> a[i];
        g = gcd(g, a[i]);
    }
    bool flag = true;
    for(int i = n-1; i >= 0; --i){
        for(auto p : divisor(a[i])){
            if(p == 1) continue;
            if(used[p]){
                flag = false;
                break;
            }
            used[p] = true;
        }
        if(!flag) break;
    }
    if(g == 1 && flag) cout << "pairwise coprime" << endl;
    else if(g == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    return 0;
}


Measured memory_bytes: 11104
import java.util.*;

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

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

int main() {
	int S, X[4];
	cin >> S;
	int a, b, c, d;
	a = S % 10;
	b = S % 100 - a;
	c = S % 1000 - a - b;
	d = S - a - b - c;
	if (10 * a != b && 10 * b != c && 10 * c != d) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <climits>
#include <set>
#include <queue>
#include <unordered_set>
using namespace std;

#define ll long long

const ll mod = 1e9 + 7;

class Solver
{
public:
	ll n;
	ll m;
	vector<ll> x;
	vector<ll> y;
	vector<ll> x_dif;
	vector<ll> y_dif;
	Solver();

	void exec();
};

Solver::Solver(){
	cin >> n >> m;
	x.resize(n);
	y.resize(m);
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	for (int i = 1; i < n; ++i)
	{
		x_dif.push_back(x[i] - x[i-1]);
	}
	for (int i = 0; i < m; ++i)
	{
		cin >> y[i];
	}
	for (int i = 1; i < m; ++i)
	{
		y_dif.push_back(y[i] - y[i-1]);
	}
}

void Solver::exec(){
	ll x_sum = 0;
	ll y_sum = 0;
	for (int i = 0; i < n-1; ++i)
	{
		x_sum = (x_sum + (x_dif[i] % mod * ((i+1) * (n-1-i)) % mod) % mod) % mod;
	}
	for (int i = 0; i < m-1; ++i)
	{
		y_sum = (y_sum + (y_dif[i] % mod * ((i+1) * (m-1-i)) % mod) % mod) % mod;
	}
	cout << (x_sum * y_sum) % mod << endl;
}

int main(){
	Solver solution = Solver();
	solution.exec();
}


Measured memory_bytes: 4084
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string> 
#include <vector> 
using namespace std;
  
int main(){
    /*??£???????????????????????????
            int a[2];
            cin >> a[1] >> a[2];
            cout << "[+] " << a[1] + a[2] << endl;
            cout << "[-] " << a[1] - a[2] << endl;
            cout << "[*] " << a[1] * a[2] << endl;
            cout << "[/] " << a[1] / a[2] << endl;
    */

    int a,ans[2];
    while(cin >> a){
    if(a == 0){break;}
    int p[a][3];
    for(int i = 1;a >= i;i++){
        cin  >> p[i][0] >> p[i][1] >> p[i][2];
        if(i == 1){
            ans[0] = p[i][0];
            ans[1] = p[i][1] + p[i][2];            
        }       
        for(int ii = 1;i > ii;ii++){
            if(ans[1] < p[i][1] + p[i][2]){
                ans[0] = p[i][0];
                ans[1] = p[i][1] + p[i][2];
            }
        }
    }
    cout << ans[0] << " " <<  ans[1] << endl;

    }
}

Measured memory_bytes: 1276
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let a = sc.read_vec::<usize>(n);

    let mut cum = vec![0; n + 1];
    for i in 0..n {
        cum[i + 1] = cum[i] + a[i];
    }

    let mut mods = BTreeMap::new();
    for i in 0..=n {
        let m = cum[i] % m;
        mods.entry(m).and_modify(|x| *x += 1).or_insert(1usize);
    }

    let ans = mods
        .into_iter()
        .map(|(_, v)| v * (v - 1) / 2)
        .sum::<usize>();
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 4716
#include<stdio.h>
#include<string.h>
int main()
{
	char c[100];
	int f,l,n=0;
	for(;scanf("%s",c)!=EOF;)
	{
		f=0,l=strlen(c)-1;
		do
			if(c[f]!=c[l])
				break;
		while(f++<=l--);
		if(f>l)
			n++;
	}
	printf("%d\n",n);
	return 0;
}

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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)


int main(){
    int n;
    cin>>n;
    if(n<1000){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A[3][3];
    int N,B;
    int flag=0;
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> A[i][j];
        }
    }
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> B;
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(B==A[j][k]){
                    A[j][k]=0;
                }
            }
        }
    }
    for(int i=0; i<3; i++){
        if(
            (A[i][0]==A[i][1]&&A[i][1]==A[i][2]) ||
            (A[0][i]==A[1][i]&&A[1][i]==A[2][i])
        ){
            flag=1;
        }
    }
    if(
        (A[0][2]==A[1][1]&&A[1][1]==A[2][0]) ||
        (A[0][0]==A[1][1]&&A[1][1]==A[2][2])
    ){
        flag=1;
    }
    if(flag){
        cout << "Yes";
    }else{
        cout << "No";
    }
    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 a = sc.nextInt();
        String s = sc.next();
        sc.close();
        if(a >= 3200){
            System.out.println(s);
        }else{
            System.out.println("red");
        }
    }
}

Measured memory_bytes: 35668
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class abc177_c {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            long[] A = new long[N];
            long mod = 1000000007;
            for (int i = 0; i < N; i++) {
                A[i] = in.nextLong();
            }
            long sum = 0;
            long ans = 0;
            for (int i = 0; i < N; i++) {
                ans = (ans + (A[i] * sum)) % mod;
                sum = (sum + A[i]) % mod;
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 61524
N = int(input())
ts = []
for _ in range(N):
    x, l = map(int,input().split())
    t = min(x+l,10**9)
    s = max(x-l,0)
    ts.append([t,s])

ts.sort()

tmp = 0
count = 0
for n in ts:
    if tmp<=n[1]:
        count += 1
        tmp = n[0]

print(count)

Measured memory_bytes: 20104
#include <iostream>
#include <queue>
#define MAX_NUM 100001
#define INF 2147483647
using namespace std;

typedef struct node {
    int id;
    int dist;
    node* next;

    node(int inpId, long long int inpDist, node* inpNext = NULL): id(inpId), dist(inpDist), next(inpNext) {}
}* nodeptr;

class chain {
public:
    nodeptr head;
    nodeptr tail;

    chain(): head(NULL), tail(NULL) {}

    void push(int id, long long int dist) {
        nodeptr tmp = new node(id, dist);
        if (this->tail != NULL) {
            this->tail->next = tmp;
            this->tail = tmp;
        } else {
            this->head = this->tail = tmp;
        }
    }
};

typedef pair<long long int, int> pii;

int V, E, r;
int si, ti;
long long int di;
int S[MAX_NUM];
long long int d[MAX_NUM];
chain* adjacencyList[MAX_NUM];
priority_queue<pii, vector<pii>, greater<pii> > q;

void dijkstra() {
    nodeptr tmp;

    while (!q.empty()) {
        pii u = q.top(); q.pop();
        int x = u.second;
        if (S[x]) {continue;}
        S[x] = 1;

        tmp = adjacencyList[x]->head;
        while (1) {
            if (tmp != NULL) {
                if (tmp->dist + d[x] < d[tmp->id]) {
                    d[tmp->id] = tmp->dist + d[x];
                    q.push(make_pair(d[tmp->id], tmp->id));
                }
                tmp = tmp->next;
            } else {
                break;
            }
        }
    }
}

int main() {
//    freopen("in.txt", "r", stdin);

    cin >> V >> E >> r;
    for (int i = 0; i < MAX_NUM; ++i) {
        adjacencyList[i] = new chain();
        S[i] = 0;
        d[i] = i == r ? 0 : INF;
    }


    for (int i = 0; i < E; ++i) {
        cin >> si >> ti >> di;
        adjacencyList[si]->push(ti, di);
    }
    q.push(make_pair(d[r], r));

    dijkstra();

    for (int i = 0; i < V; ++i) {
        if (d[i] < INF) {
            cout << d[i] << endl;
        } else {
            cout << "INF" << endl;
        }
    }
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arrll(a,n);

  sortall(a);
  reverse(all(a));

  ll tmp=-1;
  ll ans[2]={};
  int id=0;
  rep(i,n){
    if(tmp==a[i] && id<2) {
      ans[id]=a[i];
      tmp=-1;
      id++;
    } else {
      tmp = a[i];
    }
  }

  prt(ans[0]*ans[1]);
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

string str[100] = { "KIHBR","AKIHBR","KIHABR","KIHBAR","KIHBRA","AKIHABR",
"AKIHBAR","AKIHBRA","KIHABAR","KIHABRA","KIHBARA",
"AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA","AKIHABARA" }, s;

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	for (int i = 0; i < 16; i++)
		if (s == str[i])
			return cout << "YES\n", 0;
	cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    vector<int> solve(int n, int X, int Y) {
        vector<int> res(n - 1, 0);
        const int INF = 1 << 20;
        vector<vector<int>> dis(n, vector<int>(n, INF));

        vector<int> que(n + 123);
        vector<int> adj(n + 123);
        for (int i = 0; i < n; ++i) {
            dis[i][i] = 0;
            int sz = 0;
            int s = i;
            que[sz++] = i;
            for (int j = 0; j < sz; ++j) {
                int u = que[j];
                int nd = dis[s][u] + 1;
                int sz2 = 0;
                if (u - 1 >= 0) {
                    adj[sz2++] = u - 1;
                }
                if (u + 1 < n) {
                    adj[sz2++] = u + 1;
                }
                if (u == X) {
                    adj[sz2++] = Y;
                }
                if (u == Y) {
                    adj[sz2++] = X;
                }

                for (int k = 0; k < sz2; ++k) {
                    int v = adj[k];
                    if (dis[s][v] > nd) {
                        dis[s][v] = nd;
                        que[sz++] = v;
                    }
                }
            }
        }

        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                res[dis[i][j] - 1] += 1;
            }
        }
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x, y;
    cin >> n >> x >> y;
    --x, --y;
    Solution sol;
    auto res = sol.solve(n, x, y);
    for (int i = 0; i < n - 1; ++i) {
        cout << res[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 16000
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))

def main():
    s = input()
    ans = ""
    for i in range(len(s)):
        if s[i] == '0':
            ans += '0'
        elif s[i] == '1':
            ans += '1'
        else:
            ans = ans[:-1]
    print(ans)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5276
#include<iostream>
#include<vector>
#include<string>
#include<set>

int main(){
    std::string S, T;
    std::cin >> S >> T;
    std::vector<int> possible;
    std::set<std::string> st;

    
    for(int i = 0; i < S.size() - T.size() + 1; i++){
        // i startでTを作れるか調査
        int j;
        for(j = 0; j < T.size(); j++){
            if(S[i + j] != '?' && S[i + j] != T[j]) break;
        }

        if(j == T.size()) possible.push_back(i);
    }

    // 作れない
    if(possible.empty()){
        std::cout << "UNRESTORABLE" << std::endl;
        return 0;
    }
    // 各候補点から辞書順で最小のものを作る
    for(int i = 0; i < possible.size(); i++){
        std::string out = S;
        for(int j = 0; j < T.size(); j++){
            out[j + possible[i]] = T[j];
        }

        // ?の場所をaで埋める
        for(int i = 0; i < out.size(); i++){
            if(out[i] == '?') out[i] = 'a';
        }

        st.insert(out);
    }

    for(auto s : st){
        std::cout << s << std::endl;
        return 0;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int d[6];
string r;
void Dice(int x,int y,int z,int o){
    int t;t=d[x];d[x]=d[y];d[y]=d[z];d[z]=d[o];d[o]=t;
}
int main(){
    for(int i=0;i<6;i++) cin>>d[i];
    cin>>r;
    for(int i=0;i<r.size();i++){
        if(r[i]=='N') Dice(0,1,5,4);
        if(r[i]=='S') Dice(0,4,5,1);
        if(r[i]=='E') Dice(0,3,5,2);
        if(r[i]=='W') Dice(0,2,5,3);
    }
    cout<<d[0]<<endl;
    return 0;
}


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

using namespace std;

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

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

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

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

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

int main()
{
    string s;
    cin >> s;

    int k;
    cin >> k;

    int L = s.size();
    set<string> st;

    for(int l = 1; l <= 5; l++){
        for(int i = 0; i <= L - l; i++)
            st.In(s.substr(i, l));
    }

    int it = 1;
    for(auto i: st){
        if(it == k)
            return cout << i << '\n', 0;
        it++;
    }
    return 0;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define rin(i,a,b) for(register int i=(a);i<=(b);++i)
#define irin(i,a,b) for(register int i=(a);i>=(b);--i)
#define trav(i,a) for(register int i=head[a];i;i=e[i].nxt)
typedef long long LL;
using std::cin;
using std::cout;
using std::endl;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=200005;
const LL MOD=1e9+7;

int n,a[MAXN],nxt[MAXN],aft[MAXN];
LL f[MAXN];

int main(){
	n=read();
	rin(i,1,n) a[i]=read();
	rin(i,1,200000) aft[i]=n+1;
	irin(i,n,1){
		nxt[i]=aft[a[i]];
		aft[a[i]]=i;
	}
	f[1]=1;
	rin(i,1,n){
		if(nxt[i]==i+1) f[i+1]=(f[i+1]+f[i])%MOD;
		else{
			f[i+1]=(f[i+1]+f[i])%MOD;
			if(nxt[i]!=n+1) f[nxt[i]]=(f[nxt[i]]+f[i])%MOD;
		}
	}
	printf("%lld\n",f[n+1]);
	return 0;
}

Measured memory_bytes: 4096
# AtCoder ABC086A - Product
def even_odd(a,b):
    if (a*b)%2 == 0:
        return "Even"
    elif (a*b)%2 == 1:
        return "Odd"
num1, num2 = map(int, input().split())
print(even_odd(num1, num2))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = unsigned long long;

#define MAX 1000000000000000000
#define ULLMAX 18446744073709551615

int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  for(int i=0; i<n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  long long res = 1;
  if(a[0] == 0) res = 0;
  else{
    for(int i=0; i<n; ++i){
      if(res > ULLMAX / a[i]){
        res = -1;
        break;
      }
      res *= a[i];
      if(res > MAX){
        res = -1;
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4056
//
//  main.cpp
//  programs
//
//  Created by Arunesh Sarker on 18/11/19.
//  Copyright © 2019 Arunesh Sarker. All rights reserved.
//

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <unordered_set>
using namespace std;

typedef long long ll;
#define mod 1000000007
    // 60 60 30 40 5 5
     
  // Function to return LCM of two numbers
 ll gcd(ll a, ll b)
 {
     if (a == 0)
         return b;
     return gcd(b % a, a);
 }
   
 // Function to find gcd of array of
 // numbers
 int findGCD(int arr[], int n)
 {
     int result = arr[0];
     for (int i = 1; i < n; i++)
     {
         result = gcd(arr[i], result);
   
         if(result == 1)
         {
            return 1;
         }
     }
     return result;
 }
// 2 3 4 4 18 24
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    string s1,s2;cin>>s1>>s2;
    string s="";
    for(int i=0;i<s1.size();i++)
    {
        s+=s1[i];s+=s2[i];
    }
    cout<<s<<"\n";
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

int32_t main(){
    IOS;
	
	int n;
	cin>>n;
	int tot = 0;
	for(int i=2;i*i<=n;i++){
		int cnt = 0;
		while(n%i==0){
			n/=i;
			cnt++;
		}
		int ans = 0;
		int j=0;
		for(j=0;ans+j<=cnt;j++){
			ans+=j;
		}
		j--;
		tot+=j;

	}
	if(n>1)
		tot++;

	cout<<tot<<endl;

    return 0;
}

Measured memory_bytes: 3640
N, A = map(int, input().split())
x = list(map(int, input().split()))

X = max(x)
if X < A:
    X = A
    
y = []
for i in x:
    y += [i-A]

dp = [[-1] * (2*N*X+1) for _ in range(N+1)]

def check(j, t):
    if dp[j][t] != -1:
        return dp[j][t]
    if  j == 0 and t == N * X:
        dp[j][t] = 1
        return 1
    if j >= 1 and (t-y[j-1] < 0 or t-y[j-1] > 2 * N * X):
        dp[j][t] = check(j-1, t)
        return dp[j][t]
    if j >= 1 and 0 <= t-y[j-1] and t-y[j-1] <= 2*N*X:
        dp[j][t] = check(j-1, t) + check(j-1, t- y[j-1])
        return dp[j][t]
    dp[j][t] = 0
    return 0

print (check(N, N*X)-1)


Measured memory_bytes: 5216
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: int):
    ans=[-1]*N
    yok=0
    for i in range(N):
        if i<K:
            ans[i]=S
        else:
            if S>N:
                ans[i]=1
                yok+=1
            else:
                ans[i]=10**9
    
    for i in range(N):
        print(ans[i],end=" ")

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int m;
    if(s[0] == s[n-1]){
        int cnt = 0;
        rep(i, n)if(s[i] == s[0])cnt++;
        m = cnt * 2 - 1;
    }else{
        int cnt1 = 0;
        int cnt2 = 0;
        rep(i, n){
            if(s[i] == s[0])cnt1++;
            else if(s[i] == s[n-1])cnt2++;
        }
        m =  2 * min(cnt1, cnt2);
    }
    if((n - m) % 2 == 0)cout << "Second" << endl;
    else cout << "First" << endl;
}

Measured memory_bytes: 512