akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
     
    using namespace std;
     
    #define all(x) x.begin(), x.end()
    typedef vector<int> vi;
    typedef pair<int,int> ii;
    typedef long long ll;
     
    const ll inf = 3e18 + 5;
     
    const int MAXN = 1 << 19;
    int N = 400000;
    int seg[2 * MAXN], A[MAXN];
    typedef vector<vi> vvi;
     
    ll a,b,x;
    
    ll f(ll n){
        if(n<0)
            return 0;
        else
            return n/x + 1;
    } 
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
     
        cin >> a >> b >> x;
        
        cout << f(b) - f(a-1);
    }

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: RGB Coloring
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300000;

typedef long long ll;
const ll MOD = 998244353;

/* typedef */

/* global variables */

ll cs[MAX_N + 1];

/* subroutines */

ll powmod(ll a, ll n) {  // a^n % MOD
  ll pm = 1;
  while (n > 0) {
    if (n & 1) pm = (pm * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return pm;
}

/* main */

int main() {
  int n;
  ll a, b, k;
  scanf("%d%lld%lld%lld", &n, &a, &b, &k);

  cs[0] = 1;
  for (int i = 1; i <= n; i++)
    cs[i] = cs[i - 1] * (n + 1 - i) % MOD * powmod(i, MOD - 2) % MOD;

  ll sum = 0;
  for (ll x = 0; x <= n && a * x <= k; x++) {
    ll by = k - a * x;
    if (by % b == 0) {
      ll y = by / b;
      if (y <= n) sum = (sum + cs[x] * cs[y] % MOD) % MOD;
    }
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 2560
def get_number(h):
    if len(h) == 0:
        return 0

    ans = 0
    a = min(h)
    h2 = list(map(lambda x: x - a, h))

    ans = ans + a
    l = []
    for i in h2:
        if i == 0:
            ans = ans + get_number(l)
            l = []
        else:
            l.append(i)
    if len(l) > 0:
        ans = ans + get_number(l)

    return ans

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

print(get_number(h))


Measured memory_bytes: 3064
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mInt = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000



int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<int> a(N),b(M);
	rep(i,N)cin>>a[i];
	rep(i,M)cin>>b[i];
	
	vector<int> c = convolution(a,b);
	
	rep(i,c.size()){
		if(i!=0)cout<<' ';
		cout<<c[i];
	}
	cout<<endl;
	
    return 0;
}

Measured memory_bytes: 19056
#include<stdio.h>
#include<string.h>//必要
#include<stdlib.h>//必要

struct Node{
  unsigned int key;
  struct Node *next;
  struct Node *prev;
};

typedef struct Node * NodePointer;
NodePointer nil;
//---------------------------------------------------

void Init(){//nilは最初と最後に存在
  nil = malloc(sizeof(struct Node));
  nil->next = nil;
  nil->prev = nil;
}

NodePointer ListSearch(int key){//keyに一致するノードがあったらそれを返す
  NodePointer p;
  for(p=nil->next;p!=nil;p=p->next){
    if(p->key==key)break; 
  }
  return p; 
}

void PrintList(){//空白で区切る
  NodePointer p = nil->next;
  int i=1;
   
  while(1){
    if ( p == nil ) break;//最後まで行った
    if ( i == 0)  printf(" ");
    printf("%d", p->key);
    
    p = p->next;
    i = 0;
  }
  printf("\n");
}

void DeleteNode(NodePointer t){
  if(t==nil)return;
  t->next->prev=t->prev;
  t->prev->next=t->next;
  free(t);
}

void DeleteFirst(){
  DeleteNode(nil->next);
}

void DeleteLast(){
  DeleteNode(nil->prev);
}
  

void Delete(int key){//keyのノード削除
  DeleteNode(ListSearch(key));
}


void Insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct Node));
  x->key = key;
  x->next=nil->next;
  x->prev=nil;
  nil->next->prev=x;
  nil->next=x;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  
  
  scanf("%d", &n);

  Init();//必要

  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ){//insert
      Insert(key);
    }
    else if ( com[0] == 'd' ){
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) DeleteFirst();//deleteF
	else if ( com[6] == 'L' ) DeleteLast();//deleteL
      }
      else{
	Delete(key);//delete
      }
      size--;
    }
  }

  PrintList();
  return 0;
}
/*
  nilは最初と最後に存在
  コマンド数
  コマンド　値
  コマンド　値
  で繰り返す

  出力　リスト内のキーを順番に出力

*/



Measured memory_bytes: 33112
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var s = cin.next();

            var p = n / 2;
            var mae = "";
            var ushiro = "";
            for (int i = 0; i < n; i++)
            {
                if (i < p)
                {
                    mae += s[i];
                }
                else
                {
                    ushiro += s[i];
                }
            }
            Console.WriteLine(mae == ushiro ? "Yes" : "No" );
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N+ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }   

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
def solve():
    N = int(input())
    h = list(map(int, input().split()))
    dp = [float("inf")] * N
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])
    h_2 = h[0]
    h_1 = h[1]

    for i in range(2, N):
        x = h[i]
        dp[i] = min(
            dp[i - 1] + abs(x - h_1),
            dp[i - 2] + abs(x - h_2)
        )
        h_2 = h_1
        h_1 = x
    return dp[-1]


if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 13980
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
int fa[100001];
int u[100001];
int in[100001][2];
vector<pair<int,pair<int,int> > > value;
int Find(int x){
    return (x==fa[x])?x:(fa[x]=Find(fa[x]));
}
int Union(int x,int y){
    fa[Find(x)]=Find(y);
}
bool cmp1(int a,int b){
    return in[a][0]<in[b][0];
}
bool cmp2(int a,int b){
    return in[a][1]<in[b][1];
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>in[i][0]>>in[i][1],u[i]=fa[i]=i;
    sort(u+1,u+n+1,cmp1);
    for(int i=1;i<n;i++)
        value.push_back(mp(in[u[i+1]][0]-in[u[i]][0],mp(u[i],u[i+1])));
    sort(u+1,u+n+1,cmp2);
    for(int i=1;i<n;i++)
        value.push_back(mp(in[u[i+1]][1]-in[u[i]][1],mp(u[i],u[i+1])));
    sort(value.begin(),value.end());
    int ans=0;
    for(int i=0;i<value.size();i++){
        pair<int,pair<int,int> > it=value[i];
        if(Find(it.second.first)==Find(it.second.second))
            continue;
        ans+=it.first;
        Union(it.second.first,it.second.second);
    }
    cout<<ans<<endl;
    return 0;
}

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


int main() {
	int N;
	cin >> N;
	int counter1 = 0;
	for(int i = 1; i <= N; i++){
		if(to_string(i).size() % 2 == 1){
			counter1++;
		}
	}
	cout << counter1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  static int N;
  static int count;

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    N = sc.nextInt();
    sc.close();

    count = 0;

    System.out.println(dfs(0));

  }

  public static int dfs(long x){

    if (100 < x && x <= N) {
      String s = String.valueOf(x);
      if (s.indexOf("3") != -1) {
        if (s.indexOf("5") != -1) {
          if (s.indexOf("7") != -1) {
            count++;
          }
        }
      }
    } else if (N < x){
      return count;
    }

    if (x <= 1000000000) {
      dfs(10 * x + 3);
      dfs(10 * x + 5);
      dfs(10 * x + 7);
    }

    return count;
    
  }

}

Measured memory_bytes: 24912
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#define INF 100000000000000
using namespace std;

int main() {
    long long N;
    cin >> N;
    vector<long long>  R(N);
    for(int i=0; i<N; i++){
        cin >> R.at(i);
    }
    long long maxv=INF*-1;
    long long minv=R.at(0);
    for(int i=1; i<N ;i++){
        maxv = max(maxv, R.at(i)-minv);
        minv = min(minv, R.at(i));
    }
    cout << maxv << endl;
}



Measured memory_bytes: 4432
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var A = G;
		var l = new int[N + 1];
		for (var i = 0; i < N; i++) l[i + 1] = GCD(l[i], A[i]);
		var r = new int[N + 1];
		for (var i = N - 1; i >= 0; i--) r[i] = GCD(r[i + 1], A[i]);
		var max = 1;
		for (var i = 0; i < N; i++)
		{
			var g = GCD(l[i], r[i + 1]);
			max = Max(max, g);
		}
		WriteLine(max);
	}
	public static int GCD(int n, int m)
	{
		var a = Math.Abs(n);
		var b = Math.Abs(m);
		if (a < b) { var c = a; a = b; b = c; }
		while (b > 0)
		{
			var c = a % b;
			a = b;
			b = c;
		}
		return a;
	}
}


Measured memory_bytes: 26972
def get_pattern(n, y):
    X = 10
    Y = 5
    Z = 1

    y //= 1000
    for nx in range(n+1):
        m = n - nx
        for ny in range(m+1):
            nz = m - ny
            sum = nx * X + ny * Y + nz * Z
            if y == sum:
                return (nx, ny, nz)
    return (-1, -1, -1)


n, y = [int(x) for x in input().split()]
a, b, c = get_pattern(n, y)
print(a, b, c)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int arr[100];
int main(){
	for(int i=0;i<10;i++){
		cin>>arr[i];
	}
	sort(arr,arr+10);
	for(int i=9;i>=7;i--){
		cout<<arr[i]<<endl;
	}
	
}

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (N, K, Q) = readLine()!!.split(" ").map(String::toInt)
    val As = Array(Q) { readLine()!!.toInt() }
    val points = As.groupBy { it }
                    .mapValues { it.value.count() }

    for (i in 1..N) {
        if (Q - points.getOrElse(i) {0} < K) {
            println("Yes")
        } else {
            println("No")
        }
    }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

//#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rrep(i,a,b) for (int i = a; i >= b; i--)



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int te=1;
	//cin>>te;
	while(te--){
        ll a,c,n,ans=0LL,q,b;
        //string ans="";
        cin>>n;
        unordered_map<int,int> um;
        rep(i,1,n){
            cin>>a;
            ans += a;
            if(um.find(a)==um.end()) um[a]=1;
            else um[a]++;
        }
        cin>>q;
        rep(i,1,q){
            cin>>b>>c;
            if(um.find(b)!=um.end()){
            ans = ans - um[b]*b + um[b]*c;

            if(um.find(c)==um.end()) {um[c]=um[b];}
            else um[c] += um[b];

            um.erase(b);
            }
            cout<<ans<<endl;
        }
    }
	return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N,K;
    cin >> N >> K;
    vector<i64> a(N);
    rep(i,0,N) cin >> a[i];

    const i64 size=100001;
    static bool memo[size];
    static bool done[size];
    fill_n((bool*)memo,size,false);
    fill_n((bool*)done,size,false);
    function<bool(i64)> rec=[&](i64 i){
        auto& res=memo[i];

        if(done[i]) return res;
        done[i]=true;

        if(i==0) return res=false;

        for(auto x:a){
            if(i-x>=0 and !rec(i-x)) return res=true;
        }
        return res=false;
    };

    rep(i,0,K+1) rec(i);

    cout << (rec(K)?"First":"Second") << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

class Program
{
    static int a, b, c, d, e, k;
    static int[] L;

    public static void Main(string[] args)
    {
        var ant = new int[5];
        for (int i = 0; i < 5; i++)
            ant[i] = Input.NextInt();
        k = Input.NextInt();

        for (int i = 0; i < ant.Length; i++)
        {
            for (int j = 0; j < ant.Length; j++)
            {
                var dif = Math.Abs(ant[i] - ant[j]);
                if (dif > k)
                {
                    Console.WriteLine(":(");
                    return;
                }
            }
        }
        Console.WriteLine("Yay!");
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 11220
import sys


list_line = sys.stdin.readlines()

for index, element in enumerate(list_line):
    list_line[index] = element.rstrip('\n')

for element in list_line:
    x_y_list = element.split(" ")
    x = int(x_y_list[0])
    y = int(x_y_list[1])
    if x == 0 and y == 0:
        sys.exit()
    if x > y:
        print(str(y) + " " + str(x))
    else:
        print(element)

Measured memory_bytes: 7892
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}





int main(){
  int N;
  cin>>N;
  int X[N];
  int Y[N];
  for(int i=0;i<N;i++){
    cin>>X[i];
    Y[i]=X[i];
  }
  sort(Y,Y+N);
  int chuo=(Y[N/2]+Y[(N/2)-1])/2;
  for(int i=0;i<N;i++){
    if(X[i]<=chuo){
      cout<<Y[N/2]<<endl;
    }else{
      cout<<Y[(N/2)-1]<<endl;
    }
  }


  



}


  
  

  

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

string s;

bool jump(const int i, const int j, VI& A)
{
    A[i] = 1;
    FOR(x,i,j) if (A[x]) {
        FOR(d,1,3) if (x+d <= j && s[x+d] != '#') 
            A[x+d] = 1;
    }
    return A[j];
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n,a,b,c,d; 
    while (cin >> n >> a >> b >> c >> d >> s) {
        s = ' ' + s;
        VI A(n+1), B(n+1);
        bool ans = jump(a,c,A) && jump(b,d,B);
        if (ans && c > d) {
            ans = false;
            FOR(i,1,n+1)
                ans |= A[i-1] && B[i] && A[i+1];
        }
        cout << (ans ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 2072
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
//#define INF 1145141919
#define INF (1LL<<60)
#define MOD 1000000007

int N;
long long dp[5001];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P2> xs;
  rep(i, N) {
    int h, p;
    cin >> h >> p;
    xs.pb(P2(h+p, P(h, p)));
  }
  sort(all(xs));
  rep(i, N+1) dp[i] = INF;
  dp[0] = 0;
  rep(i, N) {
    int h = xs[i]._2._1, p = xs[i]._2._2;
    for (int j=N; j>=0; j--) {
      if (dp[j] <= h) dp[j+1] = min(dp[j+1], dp[j]+p);
    }
  }
  int m = 0;
  rep(i, N+1) if (dp[i] != INF) m = max(m, i);
  cout << m << "\n";
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
	int x;
	cin>>x;
	if(400<=x&&x<=599)puts("8");
	if(600<=x&&x<=799)puts("7");
	if(800<=x&&x<=999)puts("6");
	if(1000<=x&&x<=1199)puts("5");
	if(1200<=x&&x<=1399)puts("4");
	if(1400<=x&&x<=1599)puts("3");
	if(1600<=x&&x<=1799)puts("2");
	if(1800<=x&&x<=1999)puts("1");
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=1000000000LL;
typedef long long ll;
typedef pair<int,string> P;
ll N,M,K;
ll A,B,C,T;
ll S[3005]={};
string str;
string n[100002];
map<string,int> m;
int main(){
	cin>>N>>M;
	for(int i=0;i<M;++i){
		cin>>A>>B;
		S[A]++;
		S[B]++;
	}
	for(int i=1;i<=N;++i){
		cout<<S[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (s[0] + s[1] == 15)
            {
                WriteLine("+");
            }
            else if (s[0] * s[1] == 15 )
            {
                WriteLine("*");
            }
            else
            {
                WriteLine("x");
            }
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
 
#define db double
using namespace std;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        string s;
        cin >> s;
        ll n = s.length();
        vector<vector<ll>> dp(n + 1, vector<ll>(2, -INF));
        vector<vector<ll>> parent(n + 1, vector<ll>(2));
        dp[0][0] = -INF, dp[0][1] = 0;
        for(i = 0 ; i < n; i++){
            if(s[i] == '?'){
                if(dp[i][0] + 2 > dp[i][1] + 1){
                    parent[i + 1][1] = 0;
                }
                else{
                    parent[i + 1][1] = 1;
                }
                dp[i + 1][1] = max(dp[i][0] + 2, dp[i][1] + 1);
                if(dp[i][1] > dp[i][0]){
                    parent[i + 1][0] = 1;
                }
                else{
                    parent[i + 1][1] = 0;
                }
                dp[i + 1][0] = max(dp[i][1], dp[i][0]);
            }
            else if(s[i] == 'P'){
                if(dp[i][0] > dp[i][1]){
                    parent[i + 1][0] = 0;
                }
                else{
                    parent[i + 1][0] = 1;
                }
                dp[i + 1][0] = max(dp[i][0], dp[i][1]);
            }
            else{
                if(dp[i][1] + 1 > dp[i][0] + 2){
                    parent[i + 1][1] = 1;
                }
                else{
                    parent[i + 1][1] = 0;
                }
                dp[i + 1][1] = max(dp[i][1] + 1, dp[i][0] + 2);
            }
        }
        ll start;
        if(dp[n][1] > dp[n][0]){
            start = 1;
        }
        else{
            start = 0;
        }
        vector<char> ans;
        ll N = n;
        while(true){
            if(start == 0){
                ans.pb('P');
            }
            else{
                ans.pb('D');
            }
            start = parent[n][start];
            n--;
            if(ans.size() == N){
                break;
            }
        }
        reverse(ans.begin(), ans.end());
        for(i =0 ; i < N; i++){
            cout << ans[i];
        }
    }
    return 0;
}

Measured memory_bytes: 25708
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if(a - 2*b < 0)
    	System.out.println(0);
    else
      System.out.println(a-2*b);
  }
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll a[100] = {};
	rep(i, 0, N) {
		cin >> a[i];
	}
	sort(a, a + N);
	reverse(a, a + N);
	ll sum = 0;
	rep(i, 0, N) {
		sum += ((i % 2 == 0) ? a[i] : -a[i]);
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
    int i,j,n,y; cin >> n >> y;
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            int k = n - i - j;
            if(k<0) continue;
            if(1000*k + 5000*j + 10000*i==y){
                cout << i << " " << j << " " << k  << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " "<< -1 << endl;
}

Measured memory_bytes: 3608
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
if lst[0] == 0 and lst[N-1] == 0:
    print ('Yes')
    exit()
if N%3 != 0:
    print ('No')
    exit()

if lst[0] ^ lst[N//3] != lst[(N//3) * 2]:
    print ('No')
    exit()

for i in range(1, N//3):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()

for i in range(1 + N//3, (N//3) * 2):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()

for i in range(1 + (N//3) * 2, (N//3) * 3):
    if lst[i-1] != lst[i]:
        print ('No')
        exit()
print ('Yes')



Measured memory_bytes: 14116
#include <stdio.h>

int main()
{
    int n,  b1, b2;

    scanf("%d", &n);
    b1 = n/10;
    b2 = n%10;

    if(b1==9)
    {
        printf("Yes");

    }
    else if(b2==9)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}

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

#include <type_traits>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

typedef long long ll;

int main() {
    int N;
    int cnt = 0;
    string S;
    cin >> N;
    cin >> S;
    int L = 0, R = N - 1;
    while (!(R <= L)) {
        if (!(S[L] == 'W')) {
            L++;
            continue;
        }

        if (!(S[R] == 'R')) {
            R--;
            continue;
        }

        S[L] = 'R';
        S[R] = 'W';
        L++;
        R--;
        cnt++;
    }
    cout << cnt << endl;
    // cout << S << endl;
    return 0;
}


Measured memory_bytes: 3744
N, K = map(int, input().split())
mod = 10**9 + 7
count = 0

for i in range(K, N+2):
    # i個選ぶ時
    #print('i=', i, end='')
    # max = N-i+1 + ... + N
    max = (N-i+1+N)*i // 2
    #print(' max=', max, end='')
    
    # min = 0+1+ ... + i-1
    min = (0 + i-1)*i // 2
    count += max-(min-1)
    #print(' min=', min)

print(count % mod)


Measured memory_bytes: 9184
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long X = stdIn.nextLong();
		long ans1 = 0;
		long ans2 = 0;
		long ans = 0;
		ans1 = X / 500;
		ans2 = (X % 500) / 5;

		ans = (ans1 * 1000) + (ans2 * 5);

		System.out.println(ans);
		stdIn.close();
	}
}

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

int N;
int arr[1 << 18];

int main() {
  cin >> N;
  for (int j = 0; j < (1 << N); ++j) { cin >> arr[j]; }
  for (int j = N; j > 0; --j) {
    for (int k = 0; k < (1 << j)/2; ++k) {
      if (arr[2*k] == arr[2*k+1]) { arr[k] = arr[2*k]; }
      else { arr[k] = abs(arr[2*k] - arr[2*k+1]); }
    }
  }
  cout << arr[0] << endl;
  return 0;
}

Measured memory_bytes: 1408
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (A1, A2, A3): (i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let ans = if A1 + A2 + A3 >= 22 { "bust" } else { "win" };

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


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n;
    s = to_string(n);
    for (int i = 0; i < (1 << (s.size()-1));i++){
        sum = 0;
        ll a = s[0] - '0';
        REP(j,s.size()-1) {
            if(i&(1<<j)){
                sum += a;
                a = 0;
            }
            a = a * 10 + s[j + 1] - '0';
        }
        sum += a;
        ans += sum;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){

  vector<string> vs;
  map<string,int> dict;

  int idx=0;
  vs.push_back("Rock");dict["Rock"]=idx++;
  vs.push_back("Fire");dict["Fire"]=idx++;
  vs.push_back("Scissors");dict["Scissors"]=idx++;
  vs.push_back("Snake");dict["Snake"]=idx++;
  vs.push_back("Human");dict["Human"]=idx++;
  vs.push_back("Tree");dict["Tree"]=idx++;
  vs.push_back("Wolf");dict["Wolf"]=idx++;
  vs.push_back("Sponge");dict["Sponge"]=idx++;
  vs.push_back("Paper");dict["Paper"]=idx++;
  vs.push_back("Air");dict["Air"]=idx++;
  vs.push_back("Water");dict["Water"]=idx++;
  vs.push_back("Dragon");dict["Dragon"]=idx++;
  vs.push_back("Devil");dict["Devil"]=idx++;
  vs.push_back("Lightning");dict["Lightning"]=idx++;
  vs.push_back("Gun");dict["Gun"]=idx++;
  int n;
  while(cin>>n&&n!=0){
    string str;
    vector<string> hands;
    for(int i = 0; i < n; i++){
      cin>>str;
      hands.push_back(str);
    }
    bool w=false;
    for(int i = 0; i < n; i++){
      int win=0;
      int lose=0;
      int drow=0;
      int iidx=dict[hands[i]];
      for(int j = 0; j < n; j++){
	if(i==j)continue;
	// jÌèÌêðTµÄ«ÄA»ÌêÉ¶Ä
	int jidx=dict[hands[j]];
	if(iidx==jidx){
	  drow++;
	  continue;
	}
	int prv,nxt;
	// är³ÌidxÌÙ¤ª¬³¢ê
	if(iidx<jidx){
	  prv=jidx-iidx;
	  nxt=iidx+1+(vs.size()-1-jidx);
	}
	else{
	  prv=vs.size()-1-iidx+jidx+1;
	  nxt=iidx-jidx;
	}
	if(prv<nxt)
	  win++;
	else{
	  lose++;
break;
}
      }
      //cout<<"win:"<<win<<"lose:"<<lose<<"draw:"<<drow<<endl;
      if(lose>0)
	continue;
      else if(win>=1){
	// win
	w=true;
	cout<<hands[i]<<endl;
	break;
      }
    }
    if(!w){
      cout<<"Draw"<<endl;
    }
  }

  return 0;
}

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

ll gcd(ll a, ll b){
  if (b > a) swap(a, b);
  if (!b) return a;
  return gcd(b, a%b);
}

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

ll lcm_list(ll *a, ll h, ll t, ll lim){
  if (t - h == 1) return a[h];
  if (t - h == 2) return lcm(a[h], a[h+1]);

  ll mid = (h+t) / 2;

  ll lcm1 = lcm_list(a, h, mid, lim);
  if (lcm1 == lim) return lim;

  ll lcm2 = lcm_list(a, mid, t, lim);
  if (lcm2 == lim) return lim;

  return min(lcm(lcm1, lcm2), lim);
}

int main(){
  ll n, m;
  cin >> n >> m;
  ll a[n];
  bool even = false, same = true;
  for (int i=0; i<n; i++){
    int b;
    cin >> b;
    b /= 2;
    a[i] = b;
    if (b%2 == 0) even = true;
    if ((a[0] / gcd(a[0], b)) % 2 == 0 || (b / gcd(a[0] , b)) % 2 == 0) same = false;
  }
  if (even && !same) cout  << 0 << endl;
  else cout << (m / lcm_list(a, 0, n, m*10) + 1) / 2 << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S,T;
  cin >> N;
  cin >> S >> T;
  for(int i=0;i<N;i++){
	cout << S.at(i);
    cout << T.at(i);
  }
  
  return(0);
}


Measured memory_bytes: 256
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 1e6;

using vvl = vector<vll>;

struct Matrix {
    vvl mat;

    Matrix(int n, int m, int e = 0) : mat(vvl(n, vll(m, e))) {}
    Matrix(int n, bool eye = false) : Matrix(n, n) {
        if (eye) {
            for (int i = 0; i < n; i++) {
                mat[i][i] = 1;
            }
        }
    }
    Matrix(vvl mat) : mat(mat) {}

    int rows() const { return mat.size(); }
    int cols() const { return mat[0].size(); }

    void operator*=(Matrix& rhs) {
        const int n = rows(), m = rhs.cols();
        vvl prod(n, vll(m, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < rhs.rows(); k++) {
                    prod[i][j] += mat[i][k] * rhs[k][j];
                    prod[i][j] %= MOD;
                }
            }
        }
        swap(mat, prod);
    }

    friend Matrix operator*(Matrix lhs, Matrix rhs) {
        lhs *= rhs;
        return lhs;
    }

    friend Matrix operator^(Matrix a, ll n) {
        Matrix res(a.cols(), true);
        for (; n; a *= a, n >>= 1)
            if (n & 1)
                res *= a;
        return res;
    }

    vll& operator[](int i) { return mat[i]; }

    friend ostream& operator<<(ostream& out, Matrix m) {
        out << '\n';
        for (auto v : m.mat) {
            for (auto e : v)
                out << e << ' ';
            out << '\n';
        }
        return out;
    }
};

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    int n;
    cin >> n;
    ll k;
    cin >> k;

    Matrix A(n), B(n, 1, 1);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> A[j][i];
        }
    }
    B = (A ^ k) * B;
    ll res = 0;
    for (int i = 0; i < n; i++) {
        (res += B[i][0]) %= MOD;
    }
    cout << res << '\n';
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int L;
    cin >> L;
    vector<bool> C(101);
    stack<int> que;
    rep(i, L) {
        int c;
        cin >> c;
        if(c > 0) {
            if(C[c] == 1) {
                cout << i + 1 << endl;
                return 0;
            } else {
                C[c] = 1;
                que.push(c);
            }
        } else {
            c = -c;
            if(C[c] == 0 || que.top() != c) {
                cout << i + 1 << endl;
                return 0;
            } else {
                que.pop();
                C[c] = 0;
            }
        }
    }
    cout << "OK" << endl;
    return 0;
}


Measured memory_bytes: 3116
#!/usr/bin/env python3


def judge(s):
    if s[0] != "A":
        return False
    a_pos = 0
    c_pos = None
    for i in range(2, len(s) - 1):
        if s[i] == "C":
            if c_pos is not None:
                return False
            c_pos = i
    if c_pos is None:
        return False
    for i, c in enumerate(s):
        if i != a_pos and i != c_pos and not c.islower():
            return False
    return True


def main():
    print("AC" if judge(input()) else "WA")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import numpy as np
import sys
input = sys.stdin.readline
def main():
    H,W = map(int,input().split())
    S = np.array([list(input().rstrip()) for _ in range(H)]) == "."
    L = np.zeros((H,W),dtype=int)
    R = np.zeros((H,W),dtype=int)
    U = np.zeros((H,W),dtype=int)
    D = np.zeros((H,W),dtype=int)
    #[-1]はインデックス内(all 0)なのでエラーを吐かない！
    for i in range(H):
        U[i] = (U[i-1]+1)*S[i]
        D[-i-1] = (D[-i]+1)*S[-i-1]  
    for j in range(W):
        L[:,j] = (L[:,j-1]+1)*S[:,j]
        R[:,-j-1] = (R[:,-j]+1)*S[:,-j-1]

    su = L+R+U+D
    #print(L,R,U,D,sep="\n")
    print(np.amax(su)-3)
if __name__ == '__main__':
    main()

Measured memory_bytes: 219812
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string jk,cd[4][13];
int check(char ld,string str){
  char num=str[0],s=str[1];
  int flg = 0;
  if(s==ld) flg = 100;
  if(s==jk[0])flg = 1000;
  if('0'<=num &&num<='9') return num-'0'+flg;
  if(num=='T') return 10+flg;
  if(num=='J') return 11+flg;
  if(num=='Q') return 12+flg;
  if(num=='K') return 13+flg;
  if(num=='A') return 14+flg;
  return 0;
}

int main() {
  while(1){
    cin >> jk;
    if(jk=="#")break;
    for(int i=0;i<4;i++)
      for(int j=0;j<13;j++) cin >> cd[i][j];

    int ld=0,cnt[4]={};
    for(int i=0;i<13;i++) {
      char t = cd[ld][i][1];
      int N=check(t,cd[0][i]);
      int E=check(t,cd[1][i]);
      int S=check(t,cd[2][i]);
      int W=check(t,cd[3][i]);
      pair <int,int> D[4];
      D[0]=make_pair(N,0);
      D[1]=make_pair(E,1);
      D[2]=make_pair(S,2);
      D[3]=make_pair(W,3);
      sort(D,D+4);
      cnt[D[3].second]++;
      ld = D[3].second;
    }
    if(cnt[0]+cnt[2]>cnt[1]+cnt[3]) cout <<"NS "<<cnt[0]+cnt[2]-6<<endl;
    else cout <<"EW "<<cnt[1]+cnt[3]-6<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define M 1000000007
typedef long long int ll;
int main()
{
  ll r,g,b,n;
  cin>>r>>g>>b>>n;
  ll i,j,k,ans=0;
  for(i=0;;i++)
  {
      if(i*r>n)
      {
          break;
      }
      else
      {
          for(j=0;;j++)
          {
              if(j*g+i*r>n)
              {
                  break;
              }
              else
              {
                  k=n-i*r-j*g;
                  if(k>=0&&k%b==0)
                  {
                      ans++;
                  }
              }
          }
      }
  }
  cout<<ans;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int pw = 31, mod1 = 5915587277, mod2 = 3267000013;
const int N = 1e6 + 1;

map<pair<int, int>, int> mp[N];

int solve(const vector<string> &v) {
	for (int i = 0; i < N; ++i) mp[i].clear();
	int ans = 0;
	for (string s : v) {
		int n = s.size();
		int cnt[26] = {0};
		for (char c : s) {
			cnt[c - 'a']++;
		}
		int hash1 = 0, hash2 = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 26; ++j) {
				int curhash1 = hash1 * pw + (j + 1), curhash2 = hash2 * pw + (j + 1);
				curhash1 %= mod1, curhash2 %= mod2;
				if (cnt[j] and mp[i + 1].count({curhash1, curhash2})) {
					ans += mp[i + 1][{curhash1, curhash2}];
				}
			}
			--cnt[s[n - i - 1] - 'a'];
			hash1 = hash1 * pw + (s[n - i - 1] - 'a') + 1;
			hash2 = hash2 * pw + (s[n - i - 1] - 'a') + 1;
			hash1 %= mod1, hash2 %= mod2;
		}
		++mp[n][{hash1, hash2}];
	}
	return ans;
}
				
int32_t main() {	
	fast_cin();  
	int n; cin >> n;
	vector<string> v(n);
	for (auto &s : v) cin >> s;
	int ans = solve(v);
	reverse(v.begin(), v.end());
	ans += solve(v);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 68936
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N,K,R,S,P;
    cin>>N>>K>>R>>S>>P;
    string T;cin>>T;
    ll ans=0;
    bool win;
    for(int k=0;k<K;k++){
        win=true;
        if(T[k]=='r'){
            ans+=P;
        }
        if(T[k]=='s'){
            ans+=R;
        }
        if(T[k]=='p'){
            ans+=S;
        }
        int i=k+K;
        while(i<N){
            if(T[i]!=T[i-K] || (T[i]==T[i-K] && !win)){
                if(T[i]=='r'){
                    ans+=P;
                }
                if(T[i]=='s'){
                    ans+=R;
                }
                if(T[i]=='p'){
                    ans+=S;
                }
                win=true;            
            }
            else{win=false;}
            i+=K;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include<vector>
#include<math.h>

using namespace std;

int gcd(int a, int b) {
	bool flag = true;
	while (flag) {
		int c = a % b;
		a = b;
		if (c == 0) {
			flag=false;
		}
		else {
			b = c;
		}
	}
	return b;
}
int main() {
	int k;
	cin >> k;
	int sum = 0;
	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			for (int c = 1; c <= k; c++) {
				int n = gcd(a, b);
				sum += gcd(n, c);
			}
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#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() {
  int n;
  cin >> n;
  for (int i = 3; i <= n; ++i) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      string s;
      s = to_string(i);
      rep(j, s.size()) if (s[j] == '3') {
        cout << " " << i;
        break;
      }
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3264