akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  ll h;
  cin >> h;
  ll ans = 0, cnt = 1;
  while (h > 0) {
    ans += cnt;
    h /= 2;
    cnt *= 2;
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<vector<int>> g(N, vector<int>(N, 1));
  for(int i = 0; i < N; i++) g[i][i] = 0;
  for(int i = 0; i < (N / 2) * 2; i++) g[(N / 2) * 2 - 1 - i][i] = 0;
  
  vector<pair<int, int>> ans;
  for(int i = 0; i < N; i++){
    for(int j = i; j < N; j++){
      if(g[i][j] == 1) ans.push_back(make_pair(i + 1, j + 1));
    }
  }
  
  cout << ans.size() << endl;
  for(int i = 0; i < ans.size(); i++){
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
  
  return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
S = input()[:-1]


def solve():
    dp = [[0]*(N+1) for _ in range(N+1)]
    for i, c in enumerate(S, 1):
        for j, k in enumerate(S, 1):
            if c == k:
                dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1 if i +
                               dp[i-1][j-1] < j else 0)
    print(max([max(v) for v in dp]))


solve()


Measured memory_bytes: 231560
import java.util.*;

public class Main {
  // constant
  static final double INF = Double.POSITIVE_INFINITY;
  static final int MAX_V = 30;

  // global variables
  static double[][][] times;

  // inner classes
  static class Node implements Comparable<Node> {
    int n, f, v;

    Node(int n, int f, int v) {
      this.n = n;
      this.f = f;
      this.v = v;
    }

    public boolean equals(Node nd) {
      return (n == nd.n && f == nd.f && v == nd.v);
    }

    public int compareTo(Node nd) {
      double t = times[n][f][v] - times[nd.n][nd.f][nd.v];
      return ((t < 0.0) ? -1 : (t > 0.0) ? 1 : 0);
    }
  }

  static class Edge {
    double d;
    int c;
    
    Edge(double d, int c) {
      this.d = d;
      this.c = c;
    }
  }
  
  // main
  public static final void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);

    for (;;) {
      int n = sc.nextInt();
      int m = sc.nextInt();
      if ((n | m) == 0) break;

      int st = sc.nextInt() - 1;
      int gl = sc.nextInt() - 1;

      Edge[][] edges = new Edge[n][n];

      ArrayList<ArrayList<Integer>> nbrs = new ArrayList<ArrayList<Integer>>();
      for (int i = 0; i < n; i++) nbrs.add(new ArrayList<Integer>());

      for (int i = 0; i < m; i++) {
	int xi = sc.nextInt() - 1;
	int yi = sc.nextInt() - 1;
	double di = sc.nextDouble();
	int ci = sc.nextInt();

	edges[xi][yi] = edges[yi][xi] = new Edge(di, ci);
	nbrs.get(xi).add(yi);
	nbrs.get(yi).add(xi);
      }

      times = new double[n][n][MAX_V + 1];
      for (int i = 0; i < n; i++)
	for (int j = 0; j < n; j++)
	  for (int k = 0; k <= MAX_V; k++)
	    times[i][j][k] = INF;
      times[st][st][0] = 0.0;

      PriorityQueue<Node> q = new PriorityQueue<Node>();
      q.add(new Node(st, st, 0));

      double min_t = INF;
  
      while (! q.isEmpty()) {
	Node u = q.poll();

	int un = u.n;
	int uf = u.f;
	int uv = u.v;
	double ut = times[un][uf][uv];

	if (un == gl && uv == 1) {
	  if (min_t > ut) min_t = ut;
	  continue;
	}

	for (int vn: nbrs.get(un)) {
	  if (vn == uf) continue;

	  Edge ve = edges[un][vn];
	  double vd = ve.d;
	  int vc = ve.c;
	  if (uv - 1 > vc) continue;
      
	  for (int vv = uv - 1; vv <= uv + 1; vv++) {
	    if (vv <= 0 || vv > vc) continue;

	    double nvt = ut + vd / vv;
	    double vt = times[vn][un][vv];

	    if (vt > nvt) {
	      Node v = new Node(vn, un, vv);
	      if (vt < INF) q.remove(v);
	      times[vn][un][vv] = nvt;
	      q.add(v);
	    }
	  }
	}
      }

      if (min_t >= INF)
	System.out.println("unreachable");
      else
	System.out.printf("%.5f\n", min_t);
    }
  }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String line = br.readLine();

	        int n = Integer.parseInt(line);

	        if(n == 0) break;

	        Dice dice = new Dice();

	        for(int i = 0; i < n; i++){
	        	dice.move(br.readLine());

	        }

	        System.out.println(dice.getSum());

		}
	}

}

class Dice {
	//??????????????????????\\??????????????????
	private int[] numbers = {1,2,3,5,4,6};
	private int sum = 1;

	public void move (String command){
		if(command.equals("North")) {
			north();
		}

		else if(command.equals("South")) {
			south();
		}
		else if(command.equals("East")) {
			east();
		}
		else if(command.equals("West")) {
			west();
		}
		else if(command.equals("Right")) {
			right();
		}
		else if(command.equals("Left")) {
			left();
		}

		sum += numbers[0];
	}

	public int getSum(){
		return sum;
	}

	private void north () {
		int[] tmp = numbers.clone();
		numbers[0] = tmp[1];
		numbers[1] = tmp[5];
		numbers[3] = tmp[0];
		numbers[5] = tmp[3];
	}

	private void east () {
		int[] tmp = numbers.clone();
		numbers[0] = tmp[4];
		numbers[2] = tmp[0];
		numbers[4] = tmp[5];
		numbers[5] = tmp[2];
	}

	private void west () {
		east(); east(); east();
	}

	private void south () {
		north(); north(); north();
	}

	private void right () {
		int[] tmp = numbers.clone();
		numbers[1] = tmp[2];
		numbers[2] = tmp[3];
		numbers[3] = tmp[4];
		numbers[4] = tmp[1];
	}

	private void left () {
		right(); right(); right();
	}
}

Measured memory_bytes: 25316
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
  	int a=0;
    for(int c=1;c<10;c++){
    if(n%c==0&&(n/c)<10){
    a=1;
    }
    }
    if(a==1){
    System.out.println("Yes");
    }else{
     System.out.println("No");
    }
    }
}


Measured memory_bytes: 23636
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n-2):
  for j in range(i+1,n):
    k=2*j-i
    if k>(n-1):
      break
    if s[i]!=s[j]!=s[k]!=s[i]:
      ans-=1
print(ans)

Measured memory_bytes: 9196
//#include<bits/stdc++.h>
#define _CRT_SBCURE_NO_DEPRECATE
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
//#define UP(i,x,y) for(int i=x;i<=y;i++)
//#define DOWN(i,x,y) for(int i=x;i>=y;i--)
#define sdddd(x,y,z,k) scanf("%d%d%d%d", &x, &y, &z, &k)
#define sddd(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define sdd(x,y) scanf("%d%d", &x, &y)
#define sd(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lson k<<1
#define rson k<<1|1
#define mid (l+r)/2
#define ms(x, y) memset(x, y, sizeof x)
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
#define MOD 1000000007
const int maxn = 10050;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
int n, m, s, t;
int len;
struct road
{
    int u, v;
    double cost;
};
int arr[maxn][2];
road G[maxn<<2];
int par[maxn];
void init()
{
    for(int i = 0; i < maxn; i++) par[i] = i;
}

int Find(int x)
{
    return par[x]==x? x : par[x] = Find(par[x]);
}
bool same(int x, int y)
{
    int fx = Find(x), fy = Find(y);
    if(fx == fy)return true;
    else        return false;
}
void unite(int x, int y)
{
    int fx = Find(x), fy = Find(y);
    if(fx == fy) return;
    else{
        par[fx] = fy;
        return;
    }
}
bool cmp(road a, road b)
{
    return a.cost>b.cost;
}
double kruskal()
{
    sort(G, G+len, cmp);
    init();
    double res = 0;
    int cnt = 1;
    for(int i = 0; i < len; i++)
    {
        road e = G[i];
        if(!same(e.u, e.v))
        {
            unite(e.u, e.v);
            res+=e.cost;
            cnt++;
        }
    }
    return res;
}
double dist(double x, double y, double u, double v)
{
    return sqrt(abs(x-u)*abs(x-u) + abs(y-v)*abs(y-v));
}
set<pair<int,int> > st;
int main()
{
	//freopen("out.txt", "w", stdout);
    while(~sdd(n,m))
    {
        ms(G,0);
        len = 0;
        int ta, tb;
        for(int i = 1; i <= n; i++)
        {
            sdd(arr[i][0], arr[i][1]);
        }
        double sum = 0;
        for(int i = 1; i <= m; i++)
        {
            sdd(ta, tb);
            if(!st.count(mp(ta, tb)))
            {
                G[len].u = ta;
                G[len].v = tb;
                G[len].cost = dist(arr[ta][0],arr[ta][1],arr[tb][0],arr[tb][1]);
                sum += G[len].cost;
                len++;
                st.insert(mp(ta, tb));
                st.insert(mp(tb, ta));
            }
        }
        double ans = sum - kruskal();
        printf("%.3f\n", ans);
    }
	return 0;
}



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

void swap( int& a, int& b )
{
    int temp = a;
    a = b;
    b = temp;
}

void bubbleSort( int* a, int* b, bool judge )
{
    for( int i = 0; i < 6; i++ )
        for( int j = 5; j >= 1 + i; j-- )
        {
            if( a[j] < a[j-1] && judge == 0 )
            {
                swap( a[j], a[j-1] );
                swap( b[j], b[j-1] );
            }
            if( a[j] == a[j-1] && b[j] < b[j-1] && judge == 1 )
                swap( b[j], b[j-1] );
        }
}

int main()
{
    int a[6], b[6], m[1001][1001] = {{}};

    for( int i = 0; i < 6; i++ )
    {
        cin >> a[i] >> b[i];
        if( a[i] > b[i] )
            swap( a[i], b[i] );
        m[a[i]][b[i]]++;
    }

    bubbleSort( a, b, 0 );
    bubbleSort( a, b, 1 );

    int c[7] = {};
    for( int i = 0; i < 1001; i++ )
        for( int j = 0; j < 1001; j++ )
            c[m[i][j]]++;

    bool judge = false;
    int p[1001] = {};
    if( c[2] == 3 )
    {
        if( a[0] == b[0] && a[2] == b[2] && a[4] == b[4] );
        else
        {
            p[a[0]]++; p[b[0]]++;
            p[a[2]]++; p[b[2]]++;
            p[a[5]]++; p[b[5]]++;
            int cnt = 0;
            for( int i = 0; i < 1001; i++ )
                if( p[i] == 2 )
                    cnt++;
            judge = cnt == 3 ? 1 : 0;
        }
        
    }
    else if( c[2] == 1 && c[4] == 1 )
        if( a[0] == b[0] && ( a[0] == a[4] || a[0] == b[4] ) || a[4] == b[4] && ( a[4] == a[0] || a[4] == b[0] ) )
            judge = true;
    else
        if( a[0] == b[0] )
            judge = true;

    if( judge == true )
        cout << "yes" << endl;
    else
        cout << "no" << endl;

    return 0;
}


Measured memory_bytes: 7008
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = Array(n) { readLine()!!.toLong() }.sorted()
    val mins = a.take(n / 2)
    val maxs = a.takeLast(n / 2)
    println((maxs.sum() - mins.sum()) * 2 +
            if (n % 2 == 1) Math.max(mins.last() - a[n / 2], a[n / 2] - maxs.first())
            else mins.last() - maxs.first()
    )
}


Measured memory_bytes: 43736
# -*- coding: utf-8 -*-

n, m = map(int, raw_input().split())

like = [0] * m
for i in range(n):
    inpt = map(int, raw_input().split())
    for j in range(inpt[0]):
        like[inpt[j+1] - 1] += 1

ans = 0
for i in range(m):
    if like[i] == n:
        ans += 1

print ans



Measured memory_bytes: 2568
#include<stdio.h>
int main(){
  int h,w;
  int i;
  scanf("%d %d",&h,&w);
  char kigo[h+1][w+1];
  for(i=0;i<h;i++){
    scanf("%s",kigo[i]);
  }
  for(i=0;i<h;i++){
    printf("%s\n%s\n",kigo[i],kigo[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>

int min(int a,int b){ return a>b?b:a; }

int answer[300005];

int main(){
    long long n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    if(a>n || b>n || a+b>n+1){ 
        printf("-1\n");
        return 0;
    }
    int tag = 0;
    if(a<b){
        tag = a;
        a = b;
        b = tag;
        tag = 1;
    }
    long long left = n-a;
    if(a*(b-1)<left) printf("-1\n");
    else{
        int need = left;
        int size = 0; int index = 0;
        for(int i = 1; i <= a; i++){
            int give = min(b-1,need);
            need -= give;
            int next = size+give+1;
            for(int j = 0; j < give; j++){
                answer[next--] = ++index;
            }
            answer[size+1] = ++index;
            size += give+1;
        }
        for(int i = 1; i <= size; i++){
            if(tag) printf("%d ",(int)n-answer[i]+1);
            else printf("%d ",answer[i]);
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 3372
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = long.Parse(Console.ReadLine());

        var array = Console.ReadLine().Split(' ');

        var Q = long.Parse(Console.ReadLine());

        var dict = new Dictionary<long, long>();

        for(long i = 1; i<= 100000; i++)
        {
            dict.Add(i, 0);
        }

        long sum = 0;

        foreach (var n in array)
        {
            dict[long.Parse(n)] += 1;
            sum += long.Parse(n);
        }

        for(long i = 0; i < Q; i++)
        {
            var nums = Console.ReadLine().Split(' ');
            var b = long.Parse(nums[0]);
            var c = long.Parse(nums[1]);

            var count = dict[b];
            var minus = count * b;
            var plus = count * c;
            sum = sum - minus + plus;            

            dict[b] = 0;
            dict[c] += count;

            Console.WriteLine(sum);
        }



 
        Console.ReadLine();

    }
}

Measured memory_bytes: 36432
#include <array>
#include <iostream>

struct Dice {
  std::array<int, 7> num;

  void rotate(char n) {
    int tmp;
    switch (n) {
    case 'E':
      tmp = num[1];
      num[1] = num[4];
      num[4] = num[6];
      num[6] = num[3];
      num[3] = tmp;
      break;
    case 'N':
      tmp = num[1];
      num[1] = num[2];
      num[2] = num[6];
      num[6] = num[5];
      num[5] = tmp;
      break;
    case 'S':
      tmp = num[1];
      num[1] = num[5];
      num[5] = num[6];
      num[6] = num[2];
      num[2] = tmp;
      break;
    case 'W':
      tmp = num[1];
      num[1] = num[3];
      num[3] = num[6];
      num[6] = num[4];
      num[4] = tmp;
      break;
    default:
      throw;
    }
  }

  void print() {
    std::cout << "\t" << num[1] << std::endl;
    std::cout << num[4] << " " << num[2] << " " << num[3] << " " << num[5] << std::endl;
    std::cout << "\t" << num[6] << std::endl;
  }
};

int main() {
  std::array<int, 7> num;
  for (int i = 1; i <= 6; i++) {
    std::cin >> num[i];
  }

  Dice d = {num};
  // d.print();
  char a;
  while (std::cin >> a) {
    // std::cout << a << std::endl;
    d.rotate(a);
    // d.print();
  }
  std::cout << d.num[1] << std::endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

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

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


int main(){
    int N, T, A, ans = 1;
    long double tmp, dif, last = INF;
    cin >> N >> T >> A;
    for(int i = 1; i <= N; ++i){
        int H;
        cin >> H;
        tmp = T - H * 0.006;
        dif = abs(A - tmp);
        if(last > dif) {
            last = dif;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int N = s.size();
    vector<int> num(N + 1, 0);
    ll ans = 0;
    rep(1, i, N + 1)
    {
        if (s.at(i - 1) == 'B')
        {
            num.at(i) = num.at(i - 1) + 1;
        }
        else
        {
            num.at(i) = num.at(i - 1);
            ans += num.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1412
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
ll pow2(ll x, ll n) { //x^n 計算量O(logn)
	ll ans = 1ll;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

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

	string s;
	cin >> s;
	ll n = s.size();
	ll ans = 0;
	for (ll bit = 0; bit < (1LL << n - 1); bit++) {
		//cout << bitset<3>( bit) << endl;
		ll sum = 0;
		ll x = s[0] - '0';
		REP(i, n-1) {
			if ((bit & (1LL << i)) != 0) {
				sum += x;
				x = s[i + 1] - '0';
				//cout << x << endl;
			}
			else {
				x = 10 * x + s[i + 1] - '0';
				//cout << x << endl;
			}
		}
		sum += x;
		ans += sum;
		//cout << sum << endl;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = 2000
mod = 10 ** 9 + 7

fact = [1]
fact_inv = [0] * (n+1)
for i in range(n):
    fact.append(fact[-1] * (i+1) % mod)
fact_inv[-1] = pow(fact[-1], mod-2, mod)
for i in range(n-1, -1, -1):
    fact_inv[i] = fact_inv[i+1] * (i+1) % mod

def mod_comb_k(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    else:
        return fact[n] * fact_inv[k] * fact_inv[n-k] % mod


N, K = map(int, input().split())

for i in range(1, K+1):
    print(mod_comb_k(N-K+1, i) * mod_comb_k(K-1, i-1) % mod)

Measured memory_bytes: 42736
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int E = sc.nextInt();

		Integer[] a = new Integer[] { A, B, C, D, E };
		Arrays.sort(a, Comparator.comparingInt(i -> i % 10 == 0 ? 11 : i % 10));

		long sum = a[0];
		for (int i = 1; i < a.length; i++) {
			sum += (int) Math.ceil(a[i] / 10.0) * 10;
		}

		System.out.println(sum);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Pair {
		private int A;
		private int B;

		public Pair(int a, int b) {
			super();
			A = a;
			B = b;
		}

		public int getA() {
			return A;
		}

		public int getB() {
			return B;
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


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

string S, T;
long long t[200009][26];

int main() {
	cin >> S >> T; S = S + S;
	for (int i = 0; i <= S.size(); i++) {
		for (int j = 0; j < 26; j++) t[i][j] = (1 << 30);
	}
	for (int i = 0; i < S.size(); i++) t[i][S[i] - 'a'] = i;
	for (int i = S.size() - 1; i >= 0; i--) {
		for (int j = 0; j < 26; j++) t[i][j] = min(t[i][j], t[i + 1][j]);
	}

	long long ret = 0, V = S.size() / 2;
	for (int i = 0; i < T.size(); i++) {
		if (t[ret % V][T[i] - 'a'] == (1 << 30)) {
			cout << "-1" << endl;
			return 0;
		}
		ret = ((ret / V) * V) + t[ret % V][T[i] - 'a'];
		ret++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 41344
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

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

  long long x,y;
  cin >> x >> y;
  long long i=x,ans=0;
  while(i<=y){
      i = i*2;
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int q =sc.nextInt();
		String s=sc.next();
		char[][] p=new char[q][2];
		for(int i=0; i<q; i++){
			String t=sc.next();
			p[i][0]=t.charAt(0);
			String k=sc.next();
			p[i][1]=k.charAt(0);
		}
		int countl=-1;
		for(int i=q-1; i>=0; i--){
			if(p[i][1]=='L'){
				if(countl+1==n){
					System.out.println(0);
					return;
				}
				if(p[i][0]==s.charAt(countl+1)){
					countl++;
				}
			}else{
				if(countl!=-1 && p[i][0]==s.charAt(countl)){
					countl=Math.max(-1,countl-1);
				}
			}
		}
		int countr=n;
		for(int i=q-1; i>=0; i--){
			if(p[i][1]=='L'){
				if(countr!=n && p[i][0]==s.charAt(countr)){
					countr=Math.min(n,countr+1);
				}
			}else{
				if(countr-1==-1){
					System.out.println(0);
					return;
				}
				if(p[i][0]==s.charAt(countr-1)){
					countr--;
				}
			}
		}
	
		System.out.println(n-countl-1-(n-countr));
	}
}


Measured memory_bytes: 74840
#include <cstdio>

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define NR 510

int n, m;
char s[NR][NR];

int main() {
	scanf("%d%d", &n, &m);
	iter(i, n) scanf("%s", s[i] + 1);
	
	iter(i, n) {
		iter(j, m) putchar((i % 2 == 1 || s[i][j] == '#' || j == 1) && j != m ? '#' : '.');
		putchar('\n');
	}
	iter(i, n) {
		iter(j, m) putchar((i % 2 == 0 || s[i][j] == '#' || j == m) && j != 1 ? '#' : '.');
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 896
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    vec ind(n+1);
    rep(i,n) ind[a[i]]=i;
    multiset<int> se;
    se.insert(-1);se.insert(n);
    se.insert(-1);se.insert(n);
    se.insert(ind[n]);
    ll ans=0;
    
    for(int d=n-1;d>=1;d--){ // nは選ばれないので省略
        int doko=ind[d];
        auto it=se.lower_bound(doko);
        int r=*it;
        it++;
        int rr=*it;
        it--;it--;
        int l=*it;
        it--;
        int ll=*it;
        // cout<<ll<<" "<<l<<" "<<r<<" "<<rr<<endl;
        int memo=0;
        if(r!=n&&l!=-1){
            memo+=d*((l-ll)*(r-doko)+(rr-r)*(doko-l));
            //debug((l-ll)*(r-doko)+(rr-r)*(doko-l));
        }
        else if(r==n){
            memo+=d*(l-ll)*(n-doko);
        }
        else if(l==-1){
            memo+=d*(doko+1)*(rr-r);
        }
        se.insert(doko);
        ans+=memo;
        // cout<<memo<<endl;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& oj);
};

ostream& operator<<(ostream& os, const mint& oj){
    os << oj.x;
    return os;
}

mint factorial(int n){
    mint res = 1;
for(int i=1;i<=n;++i){
        res *= i;
    }
    return res;
}

mint nCr(int n,int r){
    mint numerator = 1;
    if(r > n - r) r = n - r;
    for(int i=n;i>n-r;--i){
        numerator *= i;
    }
    mint denominator = 1;
    for(int i=1;i<=r;++i){
        denominator *= i;
    }
    return numerator/denominator;
}

int main(){
    string s;cin >> s;
    int n = s.size();
    vector<vector<mint>> dp(n+1, vector<mint>(2));
    dp[0][0] = 1;
    for(int i=0;i<n;++i){
        int D = s[i] -'0';
        for(int j=0;j<2;++j){
            for(int k=0;k<=(j? 1 : D);++k){
                if(k){
                    dp[i+1][j || (k<D)] += dp[i][j] * 2;
                }else{
                    dp[i+1][j || (k<D)] += dp[i][j];
                }
            }
        }
    }
    mint ans = dp[n][0] + dp[n][1];
    cout << ans << "\n";
}

Measured memory_bytes: 5760
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    s = len(input())
    x = ['x']*s
    print(''.join(x))

if __name__=='__main__':
    main()


Measured memory_bytes: 5768
#include<cstdio>
#include<algorithm>
using namespace std;

#define INF (1<<28)
#define REP(i,n) for(int i=0;i<n;i++)

int a[110][110],wf[30][110][110],p[30],q[30][100],r[30][100];
int n,m,c,s,g,x,y,d,id,tmp;

int main(){
  while(scanf("%d%d%d%d%d",&n,&m,&c,&s,&g),n){
    REP(i,n)REP(j,n){
      a[i][j] = INF;
      REP(k,c)wf[k][i][j] = INF;
    }
    
    REP(i,m){
      scanf("%d%d%d%d",&x,&y,&d,&id);
      x--; y--; id--;
      wf[id][x][y] = min(wf[id][x][y],d);
      wf[id][y][x] = min(wf[id][y][x],d);
    }
    
    REP(l,c){
      scanf("%d",&p[l]);
      REP(k,n)REP(i,n)REP(j,n)
	wf[l][i][j] = min(wf[l][i][j],wf[l][i][k] + wf[l][k][j]);
    }

    REP(k,c){
      q[k][0] = 0;
      REP(i,p[k]-1)scanf("%d",&q[k][i+1]);
      q[k][p[k]] = INF;
      REP(i,p[k])scanf("%d",&r[k][i]);

      REP(i,n)for(int j=i;j<n;j++){
	if(wf[k][i][j] < INF){
	  tmp = 0;
	  REP(l,p[k]){
	    if(wf[k][i][j] <= q[k][l+1]){
	      tmp += r[k][l]*(wf[k][i][j] - q[k][l]);
	      break;
	    }else tmp += r[k][l]*(q[k][l+1] - q[k][l]);
	  }
	  a[i][j] = a[j][i] = min(a[i][j],tmp);
	}
      }
    }

    REP(k,n)REP(i,n)REP(j,n)a[i][j] = min(a[i][j],a[i][k] + a[k][j]);

    if(a[s-1][g-1]>=INF)printf("-1\n");
    else printf("%d\n",a[s-1][g-1]);
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i=0; i<N; ++i) cin >> d.at(i);
  
  vector<int> n(110, 0);
  for (int i=0; i<N; ++i) {
    n.at(d.at(i))++;
  }
  
  int res = 0;
  for (int i=0; i<=100; ++i) {
    if (n.at(i) != 0) ++res;
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
for($i = 1; $i <= $n; $i++){
  $count[$i] = 0;
}
for($i = 0; $i < $n-1; $i++){
  fscanf(STDIN, "%d%d", $a, $b);
  $count[$a]++;
  $count[$b]++;
  $g[$a][] = $b;
  $g[$b][] = $a;
  $aArray[] = $a;
  $bArray[] = $b;
}
$max = max($count);
$root = array_search($max, $count);
dfs(-1, $root, 0);
echo $max,"\n";
for($i = 0; $i < $n-1; $i++){
  echo $color[$aArray[$i]][$bArray[$i]],"\n";
}

function dfs($before, $from, $prevColor){
  global $g, $color;
  $c = 1;
  foreach($g[$from] as $to){
    if($to != $before){
      while($c == $prevColor)$c++;
      $color[$from][$to] = $color[$to][$from] = $c;
      dfs($from, $to, $c);
      $c++;
    }
  }
}

Measured memory_bytes: 98032
#include<iostream>

using namespace std;

int N;
int main () {
    cin >> N;
    string s = "";
    int n = N;
    while(n!=0) {
        if(n%2) {
            s = '1' + s;
            n--;
            n/= -2;
        } else {
            s = '0' + s;
            n/= -2;
        }
    }
    if(N == 0) cout << 0 << endl;
    else cout << s << endl;
    return 0;
}


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

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

	string s; cin >> s;
	if(s=="ABC") cout << "ARC";
	else cout << "ABC";	
	
	

}


Measured memory_bytes: 3580
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

a = ni()
b = ni()

if a>b:
    print("GREATER")
elif a<b:
    print("LESS")
else:
    print("EQUAL")

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

int main(){

    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    if(!a)
        cout << 1;
    else if(!b)
        cout << 2;
    else if(!c)
        cout << 3;
    else if(!d)
        cout << 4;
        else
            cout << 5;

    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  const int N = 55;
  lli nck[N][N];
  fill(&nck[0][0], &nck[N - 1][N - 1] + 1, 0);
  for (int i = 0; i < N; ++i) {
    nck[i][i] = nck[i][0] = 1;
  }
  for (int n = 1; n < N; ++n) {
    for (int k = 1; k < N; ++k) {
      nck[n][k] = nck[n - 1][k - 1] + nck[n - 1][k];
    }
  }

  int n, a, b;
  while (cin >> n >> a >> b) {
    vector<lli> v(n);
    each (i, v) cin >> i;
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    
    map<lli, lli> freq;
    each (i, v) ++freq[i];

    map<lli, lli> used;
    double sum = 0;
    for (int i = 0; i < a; ++i) {
      sum += v[i];
      ++used[v[i]];
    }
    double ave = sum / a;
    printf("%.10lf\n", ave);

    if (used.size() == 1) {
      lli patt = 0;
      lli x = min<lli>(freq[v.front()], b);
      for (int i = a; i <= x; ++i) {
        int n = freq[v.front()];
        int k = i;
        patt += nck[n][k];
      }
      printf("%lld\n", patt);
    } else {
      lli patt = 1;
      each (i, used) {
        int n = freq[i.first];
        int k = i.second;
        patt *= nck[n][k];
      }
      printf("%lld\n", patt);
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <ios>
#include <iomanip>

constexpr long double INF = 1e20;

template<class T>
void chmin (T &a, T b) {
	if (a > b) a = b;
}

template<class T>
void chmax (T &a, T b) {
	if (a < b) a = b;
}

int main() {
	std::size_t n;
	std::cin >> n;
	std::vector<int> x(n), y(n), dx(n, 0), dy(n, 0);
	
	for (std::size_t i = 0; i < n; i++) {
		char c;
		std::cin >> x[i] >> y[i] >> c;
		if (c == 'U') dy[i] = 1;
		else if (c == 'D') dy[i] = -1;
		else if (c == 'L') dx[i] = -1;
		else dx[i] = 1;
	}
	
	auto f = [&](long double t) -> long double {
		long double x_max = -INF, x_min = INF;
		long double y_max = -INF, y_min = INF;
		
		for (std::size_t i = 0; i < n; i++) {
			long double cur_x = (0.0 + (t * dx[i]) + x[i]);
			long double cur_y = (0.0 + (t * dy[i]) + y[i]);
			chmax(x_max, cur_x); chmin(x_min, cur_x);
			chmax(y_max, cur_y); chmin(y_min, cur_y);
		}
		
		long double h = x_max - x_min, w = y_max - y_min;
		return (h * w);
	};
	
	int loop = 1000;
	long double l = 0.0, r = 1e18;
	while (loop--) {
		long double c1 = (l + l + r) / 3.0;
		long double c2 = (l + r + r) / 3.0;
		if (f(c1) >= f(c2)) l = c1;
		else r = c2;
	}
	
	std::cout << std::fixed << std::setprecision(12) << f(l) << '\n';
	
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    string s4;
    s4 = char(s1[0]-'a'+'A');
    s4+=char(s2[0]-'a'+'A');
    s4+=char(s3[0]-'a'+'A');
    cout<<s4<<endl;
    
    
 
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

bool ok(int num){
  if(1 <= num and num <= 12)return true;
  else return false;
}

bool solve(int a, int b){
  if(ok(b))return true;
  else return false;
}

signed main(){
  int s;cin >> s;
  int a = s/100, b = s%100;
  if(solve(a, b) and solve(b, a))cout << "AMBIGUOUS" << endl;
  else if(solve(a, b))cout << "YYMM" << endl;
  else if(solve(b, a))cout << "MMYY" << endl;
  else cout << "NA" << endl;
  return 0;
}






Measured memory_bytes: 256
n, m = map(int, raw_input().split())
c = map(int, raw_input().split())

INF = 1000000000

t = [INF] * (n + 1)
t[0] = 0

for i in range(m):
    for j in range(c[i], n + 1):
        t[j] = min([t[j], t[j - c[i]] + 1])

print(t[n])

Measured memory_bytes: 9320
#include<iostream>
#include<algorithm>
#include<vector>
#include <cmath>
#include <limits>
#include <iomanip>
using namespace std;
const long long INF=20000000000;
int main(){
	long long n,K;
	
	cin>>n>>K;
	long long h[n];
	for(long long i=0;i<n;i++)cin>>h[i];
	vector<long long>dp(2*n,INF);
	dp[0]=0;
	for(long long i=1;i<n;i++){
		long long k=1;
		while(i-k>=0&&k<=K){
			dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]));
			k++;
		}
	}
	
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 600005, P = 924844033, G = 5;
int n, head[MAXN], nxt[MAXN<<1], to[MAXN<<1], cnt;
inline void insert(int u, int v) { nxt[++cnt] = head[u]; to[cnt] = v; head[u] = cnt; }

int A[MAXN], B[MAXN], ans[MAXN], fac[MAXN], inv[MAXN], rev[MAXN], size[MAXN];
inline int QuickPow(int x, int k) {
	int res = 1;
	for(; k; k >>= 1, x = 1LL * x * x % P) if(k & 1) res = 1LL * res * x % P;
	return res;
}

inline void dfs(int u, int fa) {
	size[u] = 1;
	for(int v, i = head[u]; i; i = nxt[i]) if((v = to[i]) != fa) {
		dfs(v, u);
		size[u] += size[v];
		if(--A[size[v]] < 0) A[size[v]] += P;
	}
	if(--A[n-size[u]] < 0) A[n-size[u]] += P;
	if(++A[n] >= P) A[n] -= P;
}

inline void NTT(int* x, int len, int d) {
	for(int i = 0; i < len; ++i) rev[i] = rev[i>>1] >> 1 | ((i & 1) ? (len>>1) : 0);
	for(int i = 0; i < len; ++i) if(rev[i] > i) swap(x[i], x[rev[i]]);
	
	for(int h = 2; h <= len; h <<= 1) {
		int wn = QuickPow(G, (P - 1 + d * (P - 1) / h) % (P - 1));
		for(int j = 0; j < len; j += h) {
			int w = 1;
			for(int k = j; k < j + h / 2; ++k) {
				int u = x[k], v = 1LL * w * x[k+h/2] % P;
				x[k] = (u + v) % P;
				x[k+h/2] = (u - v + P) % P;
				w = 1LL * w * wn % P;
			}
		}
	}
	if(d > 0) return;
	int Inv = QuickPow(len, P - 2);
	for(int i = 0; i < len; ++i) x[i] = 1LL * x[i] * Inv % P;
}

inline void Mul() {
	int len = n << 1 | 1;
	while(len != (len&-len)) len += (len&-len);
	NTT(A, len, 1); NTT(B, len, 1);
	for(int i = 0; i < len; ++i) A[i] = 1LL * A[i] * B[i] % P;
	NTT(A, len, -1);
	for(int i = 1; i <= n; ++i) ans[i] = 1LL * inv[i] * A[n+i] % P;
}

int main() {
	scanf("%d", &n);
	for(int u, v, i = n; --i; ) {
		scanf("%d%d", &u, &v);
		insert(u, v);
		insert(v, u);
	}
	dfs(1, 0);
	
	fac[0] = fac[1] = inv[0] = inv[1] = 1;
	for(int i = 2; i <= n; ++i) {
		fac[i] = 1LL * i * fac[i-1] % P;
		inv[i] = 1LL * (P - P / i) * inv[P % i] % P;
	}
	for(int i = 2; i <= n; ++i) inv[i] = 1LL * inv[i] * inv[i-1] % P;
	for(int i = 0; i <= n; ++i) {
		A[i] = 1LL * A[i] * fac[i] % P;
		B[i] = inv[n-i];
	}
	
	Mul();
	
	for(int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
	return 0;
}

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

int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<char> t(q);
    vector<int> d(q);
    for (int i = 0; i < q; i++) {
        char c;
        cin >> t[i] >> c;
        d[i] = (c == 'L' ? -1 : 1);
    }

    auto simulation = [&] (int cur) {
        bool flag = false;
        for (int i = 0; i < q; i++) {
            if (s[cur] == t[i]) cur += d[i];
            if (cur == n or cur == -1) {
                flag = (cur == -1);
                break;
            }
        }
        return flag;
    };

    int ans = n;
    for (int _ = 0; _ < 2; _++) {
        reverse(s.begin(), s.end());
        for (int i = 0; i < q; i++) d[i] *= -1;
        if (not simulation(0)) continue;
        int ok = 0, ng = n;
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (simulation(mid)) ok = mid;
            else ng = mid;
        }
        ans -= (ok + 1);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 1540
import heapq

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

que=[(-B[i],i) for i in range(N)]
heapq.heapify(que)
count=0
while que:
    val,index=heapq.heappop(que)
    if val>0:
        break
    if index!=N-1:
        a,b,c=B[index-1],B[index],B[index+1]
        if a==A[index-1] and c==A[index+1]:
            if B[index]%(a+c)==A[index]%(a+c):
                count+=(B[index]-A[index])//(a+c)
                B[index]=A[index]
            else:
                count=-1
                break
        else:
            if B[index]>a+c:
                count+=B[index]//(a+c)
                B[index]%=a+c
                heapq.heappush(que,(-B[index],index))
    else:
        a,b,c=B[index-1],B[index],B[0]
        if a==A[index-1] and c==A[0]:
            if B[index]%(a+c)==A[index]%(a+c):
                count+=(B[index]-A[index])//(a+c)
                B[index]=A[index]
            else:
                count=-1
                break
        else:
            if B[index]>a+c:
                count+=B[index]//(a+c)
                B[index]%=a+c
                heapq.heappush(que,(-B[index],index))

if A==B:
    print(count)
else:
    print(-1)


Measured memory_bytes: 133700
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,K=map(int,input().split())
A = list(map(int,input().split()))
for i in range(n):
    A[i]-=1
B=[0]+A[:]
for i in range(n):
    B[i+1]=(B[i+1]+B[i])%K
C=collections.Counter(B[:K])
for ci in C.values():
    ans+=ci*(ci-1)//2
for i in range(K,n+1):
    # print(ans)
    C[B[i-K]]-=1
    ans+=C[B[i]]
    C[B[i]]+=1
# print(B)
# print(C)
print(ans)


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A.at(i);
    rep(i, N) B.at(i) = A.at(i);

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

    int max_v = B.at(N-1);
    int second_v = B.at(N-2);

    for (int a : A) {
        if (a == max_v) cout << second_v << endl;
        else cout << max_v << endl;
    }
}


Measured memory_bytes: 3200
def main():
    N = int(input())
    T = [x for x in map(int, input().split())]
    M = int(input())
    total = sum(T)
    for _ in range(M):
        p, x = map(int, input().split())
        print(total - T[p-1] + x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384