akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<set>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;

bool find(vector<int> p,int u){
    rep(i,0,p.size()){
        if(p[i]==u) return true;
    }
    return false;
}

int main(){
    //A
    /*
    vector<int> x(5);
    int p;
    rep(i,0,5) {
        cin>>x[i];
        if(x[i]==0){
            p=i;
            break;
        }
    }
    cout<<p+1<<endl;
    */
   //B?
   /*
   int x,y;
   cin>>x>>y;
   int total=4*x;
   while(total!=y){
       if(total<y){
           cout<<"No"<<endl;
           return 0;
       }
       total-=2;
       //cout<<total<<endl;
   }
    if(total==y){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
   //cout<<"a"<<endl;
   */
  //C
  int x,n;cin>>x>>n;
  vector<int> p(n);
  rep(i,0,n) cin>>p[i];
  if(n==0){ 
    cout<<x<<endl;
    return 0;
  }
  sort(p.begin(),p.end());
  int u=x;
  int l=x;
  while(u>0||l<=100){
      if(find(p,u)==true){
          u--;
          if(find(p,l)==true){
              l++;
          }
          else {
              cout<<l<<endl;
              return 0;
          }
      }
      else{
          cout<<u<<endl;
          return 0;
      }
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string S, T; cin >> S >> T;
    vector<vector<int>> cor(26, vector<int>(26));

    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < 26; j++) {
            cor[i][j] = 0;
        }
    }

    int N = S.size();
    for (int i = 0; i < N; i++) {
        char s = S[i];
        char t = T[i];
        if (cor[s - 'a'][t - 'a'] == 0) cor[s - 'a'][t - 'a']++;
    }

    string ans = "Yes";
    for (int i = 0; i < 26; i++) {
        int sum_row = 0;
        int sum_colomn = 0;
        for (int j = 0; j < 26; j++) {
            sum_row += cor[i][j];
            sum_colomn += cor[j][i];
        }
        if (sum_row > 1 || sum_colomn > 1) {
            ans = "No";
            break;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		int n; cin >> n;
		ll h[n];
		for (auto &i : h) cin >> i;
		ll dp[n];
		dp[0] = 0;
		dp[1] = abs(h[0] - h[1]);
		for (int i = 2; i < n; i++) {
			dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
		}
		cout << dp[n - 1] << "\n";
	}
	return 0;
}

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

long long X,Y,ans;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    cin>>X>>Y;
    while(X <= Y){
        X *= 2;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>
#include <set>

#include <stdio.h>
#include <string.h>

using namespace std;

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

typedef pair<int, int> P;

// 素集合データ構造
struct UnionFind
{
	// par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
	vector<int> par;
	// sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		// 最初は全てのデータiがグループiに存在するものとして初期化
		rep(i, n) par[i] = i;
	}

	// データxが属する木の根を得る
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		// sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};

// 頂点a, bをつなぐコストcostの（無向）辺
struct Edge
{
	int a, b, cost;

	// コストの大小で順序定義
	bool operator<(const Edge& o) const {
		return cost < o.cost;
	}
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
	int n;  // 頂点数
	vector<Edge> es;  // 辺集合

					  // クラスカル法で無向最小全域木のコストの和を計算する
					  // グラフが非連結のときは最小全域森のコストの和となる
	int kruskal() {
		// コストが小さい順にソート
		sort(es.begin(), es.end());

		UnionFind uf(n);
		int min_cost = 0;

		rep(ei, es.size()) {
			Edge e = es[ei];
			if (!uf.same(e.a, e.b)) {
				// 辺を追加しても閉路ができないなら、その辺を採用する
				min_cost += e.cost;
				uf.unite(e.a, e.b);
			}
		}

		return min_cost;
	}
};


int main(int argc, char* argv[])
{
	int N;
	cin >> N;
	vector<P> x(N), y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i].first >> y[i].first;
		x[i].second = y[i].second = i;
	}

	// 最小全域木を求めるのに辺が多すぎるので、必要な辺だけを残す
	sort(x.begin(), x.end()); sort(y.begin(), y.end());

	Graph g;
	g.n = N;
	Edge e;
	for (int i = 0; i < N - 1; i++) {
		e.a = x[i].second; e.b = x[i + 1].second; e.cost = x[i + 1].first - x[i].first;
		g.es.push_back(e);
		e.a = y[i].second; e.b = y[i + 1].second; e.cost = y[i + 1].first - y[i].first;
		g.es.push_back(e);
	}

	cout << g.kruskal() << endl;

	return 0;
}

Measured memory_bytes: 6516
import sys
from itertools import combinations
#input=sys.stdin.readline

n=int(input())
s={}
for i in range(n):
    tmp=input()[0]
    if tmp in ['M','A','R','C','H']:
        s[tmp]=s.get(tmp,0)+1

ans=0

cmb=list(combinations(s.values(),3))

for a,b,c in cmb:
    ans+=a*b*c

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	int d;
	while (scanf("%d", &d) != EOF) {
		long sum = 0;
		for (int i=d; i<600; i+=d) {
			sum += d*pow(i, 2);
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int min = 0;
		int max = 0;
		long sum = 0;
		for(int i = 0; i < n; i++){
			int a = scan.nextInt();
			sum += a;
			if(i == 0){
				min = a;
				max = a;
			}
			if(min > a){
				min = a;
			}
			if(max < a){
				max = a;
			}
		}
		System.out.printf("%d %d %d\n", min, max, sum);
	}
}

Measured memory_bytes: 42508
/* 
 * File:   main.cpp
 * Author: æè¯º
 *
 * Created on 2011å¹´8æ27æ¥, ä¸å12:34
 */

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <cassert>
using namespace std;
class Page;

struct Point {
    int x, y;
};

class Rectangle {
public:
    int left, right;
    int buttom, top;

    Rectangle() { }

    Rectangle(int l, int t, int r, int b) : left(l), top(t), right(r), buttom(b) {
        if (left > right)swap(left, right);
        if (top > buttom)swap(top, buttom);
    }

    bool in(const Point &p) {
        //cerr << left << right << top << buttom << endl;
        //cerr << p.x << p.y << endl;
        return left <= p.x && p.x <= right && top <= p.y && p.y <= buttom;
    }
};

class Link {
public:
    Rectangle dest;
    string destname;

    Link() { }

    Link(const Rectangle & rect, const string & s) : dest(rect), destname(s) { }
};

class Page {
public:
    string name;
    vector<Link>link;

    string operator[](const Point & p) {
        int i;
        for (i = 0; i < link.size(); ++i) {
            if (link[i].dest.in(p))break;
        }
        if (link.begin() + i == link.end())return "";
        return link[i].destname;
    }
};

int main(int argc, char** argv) {
    int pageNumber, maxWidth, maxHeight;
    while (cin >> pageNumber && pageNumber) {
        cin >> maxWidth >> maxHeight;
        vector<Page>pages(pageNumber);
        map<string, Page*>PageCast;
        for (int i = 0; i < pageNumber; ++i) {
            int count;
            cin >> pages[i].name >> count;
            while (count--) {
                int a, b, c, d;
                string s;
                cin >> a >> b >> c >> d >> s;
                pages[i].link.push_back(Link(Rectangle(a, b, c, d), s));
            }
            PageCast[pages[i].name] = &pages[i];
        }
        int operatorCount;
        stack<Page*>UrlHistory;
        stack<Page*>ForwardPages;
        UrlHistory.push(&pages[0]);
        cin >> operatorCount;
        while (operatorCount--) {
            string opt;
            cin >> opt;
            if (opt == "click") {
                Point point;
                cin >> point.x >> point.y;
                //if (UrlHistory.empty())continue;
                string next = (*UrlHistory.top())[point];
                if (next == "")continue;
                while (!ForwardPages.empty())
                    ForwardPages.pop();
                UrlHistory.push(PageCast[next]);
            } else if (opt == "show") {
                if (UrlHistory.empty())continue;
                cout << (*UrlHistory.top()).name << endl;
            } else if (opt == "back") {
                if (UrlHistory.size() <= 1)continue;
                ForwardPages.push(UrlHistory.top());
                UrlHistory.pop();
            } else if (opt == "forward") {
                if (ForwardPages.empty())continue;
                UrlHistory.push(ForwardPages.top());
                ForwardPages.pop();
            } else assert(false);
        }
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
    Scanner in = new Scanner(System.in);

    void solve(){
        int n;
        while((n = in.nextInt()) != 0){
            int ans = Integer.MAX_VALUE;
            for(int a = 0; a < 50; a++){
                for(int b = 0; b < 50; b++){
                    for(int c = 0; c < 50; c++){
                        int sum = 0;
                        sum += (a / 5 * 5) * 380 * 0.8  + a % 5 * 380;
                        sum += (b / 4 * 4) * 550 * 0.85 + b % 4 * 550;
                        sum += (c / 3 * 3) * 850 * 0.88 + c % 3 * 850;
                        if(200 * a + 300 * b + 500 * c == n){
                            ans = Math.min(ans, sum);
                        }
                    }
                }
            }
            System.out.println(ans);
        }
    }
    
    public static void main(String[] args){
        new Main().solve();    
    }
}

Measured memory_bytes: 26316
fun main() {
    val n = readLine()!!.toLong()

    fun f(n: Long): MutableMap<Long, Long> {
        var x = n
        val fs = mutableMapOf<Long, Long>()
        var i = 2L
        while (i * i <= x) {
            if (x % i == 0L) {
                fs[i] = (fs[i] ?: 0) + 1
                x /= i
                continue
            }
            i++
        }
        if (x > 1) fs[x] = (fs[x] ?: 0) + 1
        return fs
    }

    val fs = f(n)

    var ans = 0
    var i = 1L
    while (true) {
        var flag = true

        for ((x, cnt) in fs) {
            if (cnt >= i) {
                ans++
                fs[x] = cnt - i
                flag = false
            }
        }

        i++
        if (flag) break
    }

    println(ans)
}


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

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

    if (0 <= a.at(0) - 'A' && 0 <= 'Z' - a.at(0))
        cout << "A" << endl;
    else
        cout << "a" << endl;
    return 0;
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st = new StringTokenizer(br.readLine());
		int n1 = Integer.parseInt(st.nextToken()), n2 = Integer.parseInt(st.nextToken());

		if (n1 > 9 || n2 > 9) {
			System.out.println("-1");
		} else {
			System.out.println(n1 * n2);
		}
	}
}


Measured memory_bytes: 22484
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    final Scanner sc = new Scanner(System.in);
    final String s = sc.nextLine();
    final String t = sc.nextLine();
    int min_diff = s.length();

    for (int i = 0; i <= (s.length() - t.length()); i++) {
      int j = 0;
      int diff = 0;
      while (j < t.length()) {
        if (s.charAt(i + j) != t.charAt(j)) {
          diff++;
        }
        j++;
      }

      if (min_diff > diff) {
        min_diff = diff;
      }
    }

    System.out.println(min_diff);
  }
}

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

using namespace std;

const long long MOD = 1000000007;

int main(){
	int n,m,q;
	cin >> n >> m >> q;
	vector<int> A(50,0),B(50,0),C(50,0),D(50,0);
	
	for(int i=0;i<q;i++){
		cin >> A[i] >> B[i] >> C[i] >> D[i];	
	}
	
	int mx=m;
	vector<int> X(10);
	long long point=0,ans=0;
	
	for(int a=1;a<=mx;a++){
		X[0]=a;
		for(int b=a;b<=mx;b++){
			X[1]=b;
			for(int c=b;c<=mx;c++){
				X[2]=c;
				for(int d=c;d<=mx;d++){
					X[3]=d;
					for(int e=d;e<=mx;e++){
						X[4]=e;
						for(int f=e;f<=mx;f++){
							X[5]=f;
							for(int g=f;g<=mx;g++){
								X[6]=g;
								for(int h=g;h<=mx;h++){
									X[7]=h;
									for(int i=h;i<=mx;i++){
										X[8]=i;
										for(int j=i;j<=mx;j++){
											X[9]=j;
											point=0;
											for(int k=0;k<q;k++){
												if(X[B[k]-1]-X[A[k]-1]==C[k])point+=D[k];
												else point+=0;
											}
											ans=max(ans,point);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int a[3][3];
    REP(i,3) REP(j,3) cin >> a[i][j];
    int n; cin >> n;
    map<int, int> mp;
    REP(i,n) {
        int c;
        cin >> c;
        mp[c]++;
    }
    int b[3][3] = {0};
    REP(i, 3) REP(j,3) {
        if(mp[a[i][j]]) b[i][j] = 1;
    }
    bool f = false;
    REP(i, 3) {
        if(b[i][0] && b[i][1] && b[i][2]) f = true;
    }
    REP(i, 3) {
        if(b[0][i] && b[1][i] && b[2][i]) f = true;
    }
    if(b[0][0] && b[1][1] && b[2][2]) f = true;
    if(b[2][0] && b[1][1] && b[0][2]) f = true;
    

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 15 21:08:34 2018

@author: ogura
"""

n = int(input())

if n == 1:
    print('Hello World')
elif n == 2:
    a = int(input())
    b = int(input())
    print(a + b)
else:
    ''

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

static int32_t n;
static vector<int64_t> a;

static int64_t calcCost(bool isPlus)
{
	int64_t sum = 0, cost = 0;
	for (int32_t i = 0; i < n; i++) {
		if (isPlus && sum + a[i] < 1) {
			cost += abs(a[i] - (1 - sum));
			sum += 1 - sum;
		} else if (!isPlus && sum + a[i] > -1) {
			cost += abs(a[i] - (-1 - sum));
			sum += -1 - sum;
		} else {
			sum += a[i];
		}
		isPlus = !isPlus;
	}
	return cost;
}

int main()
{
	cin >> n;

	a.resize(n);

	for (int32_t i = 0; i < n; i++)
		cin >> a[i];

	cout << min(calcCost(true), calcCost(false)) << endl;

	return 0;
}


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

#define N ((ll)1e18)

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	ll x;
	ll ans = 1;
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		if(x == 0)
		{
			ans = 0;
			break;
		}
		if(ans == -1)
			continue;
	
		if(x > (1000000000000000000/ans))
			ans = -1;
		else
			ans *= x;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3620
N = int(input())
tops = list(map(int, input().split()))
middles = list(map(int, input().split()))
bottoms = list(map(int, input().split()))
tops.sort()
middles.sort()
bottoms.sort()
# print(tops)
# print(middles)
# print(bottoms)
# top<middle<bottomでないといけない
# middleをfor文で繰り返して、topとbottomで二分探索をする。
# そしてそれ以下の数を出して、掛け算すれば組み合わせの数を出せる


def left_binary_search(target, nums):
    left = 0
    right = len(nums) - 1
    while left <= right:
        # 0+7 /2 = 3
        # print(left, right)
        mid = int((left + right) / 2)
        # print(f'mid: {mid}')
        if nums[mid] < target:
            left = mid + 1
        elif nums[mid] > target:
            right = mid - 1
        else:
            right = mid - 1

    # 0,1,2,3,4
    # 2
    # => return 2
    # print(left, right)
    return left


def right_binary_search(target, nums):
    left = 0
    right = len(nums) - 1
    while left <= right:
        # 0+7 /2 = 3
        # print(left, right)
        mid = int((left + right) / 2)
        if nums[mid] < target:
            left = mid + 1
        elif nums[mid] > target:
            right = mid - 1
        else:
            left = mid + 1

    # 0,1,2,3,4
    # 2
    # => return 2
    # print(left, right)
    return left


count = 0
for middle in middles:
    top_index = left_binary_search(middle, tops)
    bottom_index = right_binary_search(middle, bottoms)
    # print(top_index, bottom_index, (top_index) * (len(bottoms) - bottom_index))
    count += (top_index) * (len(bottoms) - bottom_index)
print(count)


Measured memory_bytes: 105444
/**
 *		author:  zvm
 *		created: 25.09.2020 17:16:12
**/

#include <bits/stdc++.h>

using namespace std ;

typedef long long int ll ;

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

	int n ;
	cin >> n ;

	vector<ll> val(n+1);
	
	val[0] = 2 ;
	val[1] = 1 ;

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

	cout << val[n] << endl ;
}


Measured memory_bytes: 3580
using System;
using System.Linq;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int[] i;
            bool f = true;
            while((i = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray()).Sum() != 0){
                if(!f) Console.WriteLine();
                f = f ^ f;
                bool e = false;
                for(int l=i[0]; l <= i[1]; ++l)
                    if(System.DateTime.IsLeapYear(l)) {
                        Console.WriteLine(l);
                        e = true;
                    }
                if(!e) Console.WriteLine("NA");
            }
        }
    }
}

Measured memory_bytes: 6028
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;

int main(void) {
	int n, u, k, i, j, x, t, v;
	bool path[110][110];
	int d[110];
	memset(path, 0, sizeof(path));
	memset(d, -1, sizeof(d));
	cin >> n;
	for (i = 0;i<n;i++) {
		cin >> u >> k;
		u--;
		for (j = 0;j<k;j++) {
			cin >> x;
			x--;
			path[u][x] = true;
		}
	}

	queue<pair<int, int> > q;
	q.push({ 0,0 });
	while (!q.empty()) {
		v = q.front().first;
		t = q.front().second;
		q.pop();
		if (d[v] == -1)d[v] = t;
		else continue;

		t++;
		for (i = 0;i<n;i++) {
			if (path[v][i] && d[i] == -1) {
				q.push({ i,t });
			}
		}
	}

	for (i = 0;i<n;i++) {
		cout << i + 1 << " " << d[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int64_t MAXN = 100010;
int64_t N, M, ans = 0;
vector<int64_t> H(MAXN, 0);
vector<vector<int64_t>> Graph(MAXN);

void search(int n)
{
  int64_t curh = H.at(n);
  for (int i = 0; i < Graph.at(n).size(); i++)
  {
    int64_t nei = Graph.at(n).at(i);
    if (H.at(nei) >= curh)
    {
      return;
    }
  }
  ans++;
}

int main()
{
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> H.at(i);
  int64_t a, b;
  for (int i = 0; i < M; i++)
  {
    cin >> a >> b;
    a--;
    b--;
    Graph.at(a).push_back(b);
    Graph.at(b).push_back(a);
  }
  for (int i = 0; i < N; i++)
  {
    search(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 9832
//Problem *
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,k,dp[N],a[N],s;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=k;i++)
		for(int j=1;j<=n;j++)if(a[j]<=i&&!dp[i-a[j]])dp[i]=1;
	if(dp[k])printf("First");else printf("Second");
	return 0;
}

Measured memory_bytes: 640
n = int(input())
p = input().split()

 
p_int = [int(s) for s in p]
     
     
cnt = 0
     
for i in range(1,n-1):
    if( (p_int[i-1] < p_int[i] and p_int[i] <= p_int[i+1] ) or (p_int[i-1] >= p_int[i] and p_int[i] > p_int[i+1]) or (p_int[i-1] == p_int[i+1] and p_int[i] > p_int[i-1]) ):
        cnt += 1    
print(cnt)

Measured memory_bytes: 3064
// Problem : K - Stones
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_k
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define MM			1000000007
#define N			100005
#define pb 			push_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define Endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for(int i=begin;i<end;i++)
#define repr(i,begin,end) for(int i=end-1;i>=begin;i--)
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define re 			resize
 
 
 
signed main(void)
{ios
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		int n,k;
		cin>>n>>k;
		vector<bool> dp(k+1);
		int a[n];
		rep(i,0,n) cin>>a[i];
		rep(i,0,k+1)
		{
		    for(int x:a)
		    {
		        if(i-x>=0 and !dp[i-x]) dp[i]=1;
		    }
		}
		cout<<(dp[k]?"First":"Second");
	}
}

Measured memory_bytes: 3560
from collections import Counter


def main():
    N, K = map(int, input().split())
    A = [int(x) for x in input().split()]

    c = Counter()
    for a in A: c[a] += 1

    oc = sorted(c.items(), key=lambda x: x[1])
    res = 0
    for i in range(len(oc)-K):
        res += oc[i][1]

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39288
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli N,D,X,B=0;
  cin >>N>>D>>X;
  vector<int>P(N); 
  rep(i,N)cin >>P[i];
  rep(i,N){
    for(int j=0;;j++){
      if(1+j*P[i]<D+1)B++;
      else break;
    }
  }
  Out(B+X);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int n;
  cin >> n;

  int tbl[10][10];
  rep(i, 10) rep(j, 10) { tbl[i][j] = 0; }

  rep(i, n) {
    int r = i + 1;
    while (r >= 10) {
      r /= 10;
    }
    int l = (i + 1) % 10;
    tbl[r][l]++;
  }

  int64_t result = 0;
  rep(i, 9) rep(j, 9) {
    result += (int64_t)tbl[i + 1][j + 1] * tbl[j + 1][i + 1];
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std ;
int main () {
	int N , M ;
	cin >> N >> M ;
	vector <int> cnt (M);
	for ( int i = 0; i < N ; ++ i ) {
		int K;
 		cin >> K ;
		for ( int j = 0; j < K ; ++ j ) {
			int A; cin >> A ;
  			--A ;
			cnt [ A ]++;
		}
	}
	int ans = 0;
	for ( int i = 0; i < M ; ++ i ) {
		if ( cnt [ i ] == N ) {
			++ ans ;
		}
	}
	cout << ans << endl ;
}

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

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repr(i,a,b) for(int i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> P;
const int INF=1<<29;

int N;
int p[1010];

int main(){
    cin>>N;
    int ma=0;
    rep(i,0,N){
        cin>>p[i];
        ma=max(ma,p[i]);
    }
    
    cout<<accumulate(p,p+N,0)-ma/2<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){

 
  int n,m;
  cin>>n>>m;
  
  map<int,int> data;
  
  int answer=0;
  
  rep(i,m){
    int s,c;
    cin>>s>>c;
    if ( (data.count(s) and data.at(s)!=c) or (s==1 and n>=2 and c==0)){
      answer=-1;
    }
    else if (!data.count(s)){
      data[s]=c;
    }
  }
  
  for (int i=2;i<=n;i++){
    if (data.count(i) and answer!=-1 and n){
      answer+=pow(10,n-i)*data.at(i);
    }
  }
  
  if (data.count(1) and answer!=-1){
    answer+=pow(10,n-1)*data.at(1);
  }
  else if (answer!=-1 and n!=1){
    answer+=pow(10,n-1);
  }
  
  cout<<answer<<endl;
  
  
  
  
  
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n; cin >> n;
  vector<ll> v(n);
  for(auto&e:v)cin >> e;
  sort(v.begin(),v.end());
  ll ans = 1;
  for(auto e:v){
    if(ans == 0)break;
    if(e <= 1000000000000000000 / ans){
      ans *= e;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>

using namespace std;

long long int gcd(int a, int b)
{
  if (a < b) 
  {
    int tmp;
    tmp = a;
    a   = b;
    b   = tmp;
  }

  int r = a % b;
  while (r != 0)
  {
    a = b;
    b = r;
    r = a % b;
  }

  return b;
}


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

void snack()
{
  long long int a, b;
  cin >> a >> b;

  cout << lcm(a, b) << "\n";
}


bool is_prime(int n)
{
  if (n <= 1) return false;
  if (n == 2) return true;

  if (n % 2 == 0)return false;

  for (int i = 3; i * i <= n; i += 2)
  {
    if (n % i == 0) return false;
  }

  return true;
}


void next_prime()
{
  int x;
  cin >> x;

  int prime = x;
  while (!is_prime(prime)) prime++;

  cout << prime << "\n";
}


int factorial(int n)
{
  int fact = 1;
  for (int i = n; i > 0; i--) fact *= i;
  return fact;
}


int calc_order(int n, vector<int> x)
{
  int cnt = 0;
  for (int i = 0; i < n; i++)
  {
    cnt += (x[i] - 1) * factorial(n - 1 - i);
    for (int j = i + 1; j < n; j++) {
      if (x[j] > x[i]) x[j]--;
    }
  }
  return cnt;
}


void count_order()
{
  int n;
  cin >> n;

  vector<int> p(n);
  vector<int> q(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) cin >> q[i];

  int p_cnt = 0, q_cnt = 0;
  p_cnt = calc_order(n, p);
  q_cnt = calc_order(n, q);

  cout << abs(p_cnt - q_cnt);
}




int main()
{
  snack();
  //next_prime();
  //count_order();
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        System.out.println((a * b % 2 == 1) ? "Yes" : "No");
        inp.close();
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N,M;
  cin >> N >> M;
  vector<P> A(M);
  vector<P> B(M);
  REP(i,M){
    cin >> A[i].first >> A[i].second;
    A[i].first--;
    A[i].second--;
    B[i].first=A[i].second;
    B[i].second=A[i].first;
  }
  int x=-1;
  sort(ALL(B));
  int cnt = 0;
  REP(i,M){
    if(x==-1){
      x=B[i].first;
      cnt++;
    }else if(x<=B[i].second){
      x=B[i].first;
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1e9
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
ll solve(ll x){
    FOR(i,1,1e9){
        //cout << "2,i= " << llpow(2,i) << " 2,i+1= " << llpow(2,i+1) << endl;
        if(llpow(2,i) <= x and  x < llpow(2,i+1)){
            return llpow(2,i+1)-1;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    ll H; cin >> H;

    if(H==1) cout << 1 << endl;
    else cout << solve(H) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0


d = dict(collections.Counter([i + height[i] for i in range(N)]))
ans = sum([d.get(i - height[i], 0) for i in range(N)])
print(ans)

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

using namespace std;



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

	int n, m;
	cin >> n >> m;

	vector<int> ans(n, -1);

	for(int i = 0; i < m; ++i) {

		int s, c; 
		cin >> s >> c;
		
		--s;

		if (ans[s] != -1 && ans[s] != c) {
			cout << -1 << '\n';
			return 0;
		}

		ans[s] = c;

	}

	if (n == 1) {
		if (ans[0] == -1)
			ans[0] = 0;
		cout << ans[0] << '\n';
		return 0;
	}

	if (n > 1 && ans[0] == 0) 
		cout << -1 << '\n';
	else {
		ans[0] = max(ans[0], 1);

		for(int i = 0; i < n; ++i) {
			ans[i] = max(0, ans[i]);
			cout << ans[i];
		}
		cout << '\n';
	}

	return 0;	
}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))
dist = 2 * (x[-1] - x[0])
for i in range(N):
    if i + K -1 >= N:
        break
    dist = min(dist, abs(x[i]) + abs(x[i + K - 1] - x[i]),abs(x[i + K -1]) + abs(x[i + K - 1] - x[i]))
print(dist)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a,b,c;
cin>>a;
cin>>b;
cin>>c;
if( a=='a' && ( (b=='c' && c=='b') ||  (c=='c' && b=='b') ) )
printf("Yes");
else if ( b=='a' && ( (a=='c' && c=='b') ||  (c=='c' && a=='b') ) )
printf("Yes");
else if ( c=='a' && ( (b=='c' && a=='b') ||  (a=='c' && b=='b') ) )
printf("Yes");
else
printf("No");
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
    int a;
    int b;
    int z;
    int min;
    int max;
    long int sum;
    min = 1000000;
    max = -1000000;
 
    sum = 0;
 
    scanf("%d",&a);
 
    for(b=0; b<a; b++)
    {
        scanf("%d",&z);
         
        if(min > z)
        {
            min = z;
        }
        if(max < z)
        {
            max =z;
        }
        sum = sum + z;
    }
     
    printf("%d %d %ld\n",min,max,sum);
 
    return 0;
}
 

 

Measured memory_bytes: 600
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n, m, kn;
vector<int> g[MAXN];
vector<int> bad[MAXN];
int st[MAXN], sz[MAXN];

int getSet(int x) {
  if (st[x] == x)
    return x;
  st[x] = getSet(st[x]);
  return st[x];
}

void unite(int a, int b) {
  a = getSet(a); b = getSet(b);
  if (a == b) {
    return;
  }
  if (rand() & 1)
    swap(a, b);
  st[a] = b;
  sz[b] += sz[a];
}

int main() { 

  scanf("%d %d %d", &n, &m, &kn);
  for (int i = 0; i < m; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    from--; to--;
    g[from].push_back(to);
    g[to].push_back(from);
  }

  for (int i = 0; i < kn; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    from--; to--;
    bad[from].push_back(to);
    bad[to].push_back(from);
  }

  for (int i = 0; i < n; i++) {
    st[i] = i;
    sz[i] = 1;
  }

  for (int i = 0; i < n; i++) {
    for (int to : g[i]) {
      unite(i, to);
    }
  }

  for (int i = 0; i < n; i++) {
    int ans = sz[getSet(i)];
    ans--;
    ans -= sz(g[i]);
    for (int to : bad[i]) {
      if (getSet(i) == getSet(to)) {
        ans--;
      }
    }
    printf("%d ", ans);
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 12920
import java.io.PrintWriter
import java.util.*
import java.math.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    val n = readInt()
    val a = readListOfInt()
    
    val sum = a.reduce { acc, b -> acc xor b }
    println(if(sum == 0) "Yes" else "No")
    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 53836
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <queue>

int main() {
  size_t n;
  scanf("%zu", &n);

  intmax_t const max = 3234566667;

  std::vector<intmax_t> res{0};
  std::queue<intmax_t> q;
  for (int i = 1; i <= 9; ++i) q.push(i);

  auto push = [&](intmax_t x) {
    if (x <= max) q.push(x);
  };

  while (!q.empty()) {
    intmax_t x = q.front();
    q.pop();
    res.push_back(x);
    int d = x % 10;
    x *= 10;
    push(x + d);
    if (d != 0) push(x + d-1);
    if (d != 9) push(x + d+1);
  }

  std::sort(res.begin(), res.end());
  printf("%jd\n", res[n]);
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i(a); i < (b); ++i)

#define gc getchar()
struct Reader {
	template <class T> inline operator T() {
		T w; char c, p = 0;
		for(; !isdigit(c = gc); c == '-' && (p = 1));
		for(w = c & 15; isdigit(c = gc); w = w * 10 + (c & 15));
		return p ? -w : w;
	}
}rd;

template <class T> inline bool smin(T&x, const T&y) { return y < x ? x = y, 1 : 0; }
template <class T> inline bool smax(T&x, const T&y) { return x < y ? x = y, 1 : 0; }

typedef long long ll;

int n, a[16][16];
ll f[1 << 16];
int main() {
	n = rd;
	REP(i, 0, n) REP(j, 0, n) a[i][j] = rd;
	const int st = 1 << n;
	REP(s, 0, st)
		REP(i, 0, n) if(s >> i & 1)
			REP(j, i + 1, n) if(s >> j & 1)
				f[s] += a[i][j];
	
	REP(s, 1, st)
		for (int t = s & s - 1; t; t = t - 1 & s)
			smax(f[s], f[s ^ t] + f[t]);
	std::cout << f[st - 1];
	return 0;
}



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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<int >;
using P = pair<int,int>;

int main()
{
   string l[4]={"dream","dreamer","erase","eraser"};
   string s;cin >>s;

   rep(i,4)reverse(all(l[i]));
   reverse(all(s));
   int n=s.size();
   for(int i=0;i<n;){
    int k;
    bool tmp=true;
    bool flg=false;
    rep(j,4){
        if(s.substr(i,3)==l[j].substr(0,3)){
          k=j;
          flg=true;
        }
    }
    if(flg){
        int ls=l[k].size();
            if(i+ls<=n){
                if(s.substr(i,ls)==l[k])tmp=false;
            }
    }
    if(tmp){
            puts("NO");
            return 0;
    }
    else{ i+=l[k].size();
    }
   }
   puts("YES");
   return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    string S,T;
    ll A,B;
    string U;
    cin >> S >> T  >> A >> B >> U;
    if(S == U){
        cout << A -1 << ' ' << B << endl;
    }else{
        cout << A  << ' ' << B - 1<< endl;
    }
}


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

public static class Program
{
    public static void Main(string[] args)
    {
        var x = long.Parse(Console.ReadLine());
        long result = 0;
        result = (long)Math.Floor((double)x / 500) * 1000;
        x -= (result / 1000) * 500;
        result += (long)Math.Floor((double)x / 5) * 5;
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 13268
n = gets.chomp.to_i
v = gets.chomp.split.map(&:to_i)
 
ary = []
 
n.times do |i|
  ary.push(v[i])
end
arysort = ary.sort
 
(n-1).times do |i|
  sorezore_wa = (arysort[0] + arysort[1]).quo(2).to_f
  arysort.unshift(sorezore_wa)
 
  arysort.delete_at(1)
  arysort.delete_at(1)
end
 
p arysort[0]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
const string temp = "UDLR";
const int vy[] = {-1, 1, 0, 0}, vx[] = {0, 0, -1, 1};
const int INF = 1 << 30;
typedef pair< int, pair< int, int > > State;

int W, H, N;
int sx, sy, gx, gy;
int edge[2][501][501] = {{}};
int min_cost[501][501];
int Dijkstra()
{
  priority_queue< State, vector< State >, greater< State > > que;
  fill_n(*min_cost, 501 * 501, INF);
  que.push({0, {sx, sy}});
  min_cost[sx][sy] = 0;
  for(;;) {
    pair< int, int > p;
    int cost;
    tie(cost, p) = que.top(); que.pop();
    if(cost > min_cost[p.first][p.second]) continue;
    if(p == make_pair(gx, gy)) return(cost);
    for(int i = 0; i < 4; i++) {
      int nx = p.first + vx[i], ny = p.second + vy[i];
      if(nx < 0 || ny < 0 || nx > W || ny > H) continue;
      int next_cost = cost + edge[i >= 2][min(p.first, nx)][min(p.second, ny)];
      if(next_cost >= min_cost[nx][ny]) continue;
      min_cost[nx][ny] = next_cost;
      que.push({next_cost, {nx, ny}});
    }
  }
}

int main()
{
  cin >> W >> H >> N;
  cin >> sx >> sy >> gx >> gy;
  while(N--) {
    int x, y, T;
    string S;
    cin >> x >> y;
    cin >> T >> S;
    while(T--) {
      for(char c : S) {
        int delta = temp.find(c);
        int nx = x + vx[delta], ny = y + vy[delta];
        if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
        ++edge[delta < 2][max(x, nx)][max(y, ny)];
        x = nx, y = ny;
      }
    }
  }
  cout << Dijkstra() << endl;
}

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

int main() {
  int H, W, i, j;
  
  //input
  cin >> H >> W;
  vector<vector<char>> bomb(H + 2, vector<char>(W + 2));
  for (i = 1; i < H + 1; i++){
    for (j = 1; j < W + 1; j++){
      cin >> bomb.at(i).at(j);
    }
  }
  
  for (i = 0; i < H + 2; i++){
    for (j = 0; j < W + 2; j++){
      if (bomb.at(i).at(j) == NULL) {
        bomb.at(i).at(j) = '#';
      }
      cout << bomb.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
//System.out.println("")

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cnt = 0;
        for(int i=0; i<n; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            cnt = cnt + r-l + 1;
        }
        System.out.println(cnt);
    }
}

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

using namespace std;

int main() {
    int n;
    long long a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    bool flg = false;
    for (int k = 0; k < n; ++k) {
        long long lhs = a + c * k - d * (n - k - 1);
        long long rhs = a + d * k - c * (n - k - 1);
        if (lhs <= b and b <= rhs) flg = true;
    }

    if (flg) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

int main() {
  char c ;
  cin >> c;

  if(c =='a'||c=='e'||c == 'i'||c == 'o'||c == 'u'){
    cout<<"vowel"<<endl;
  }else{
    cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007

int main(){
    int a;
    cin >> a;
    int anss = a + a*a + a*a*a;
    cout << anss << endl;
}


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

const double PI=3.141592653589793;

const int MX = 100005;

int main()
{
  int N;
  cin >> N;
  while (N > 0)
  {
    N -= 1000;
  }

  if(N<0)
    N *=(-1);
  cout << N << endl;
  return 0;
  }


Measured memory_bytes: 3608
import java.util.Scanner;

//Maximum Sum Sequence
public class Main{

	public static int cs(int[] a){
		int min = 0;
		int x = 0;
		int max = Integer.MIN_VALUE;
		for(int i=0;i<a.length;i++){
			x += a[i];
			max = Math.max(max, x-min);
			min = Math.min(min, x);
		}
		return max;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int a[] = new int[n];
			for(int i=0;i<n;i++)a[i]=sc.nextInt();
			System.out.println(cs(a));
		}
	}
}

Measured memory_bytes: 12000
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

# coding: UTF-8
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

n = readi()
mn = -1
for i in make_divisors(n):
    p = i - 2
    t = n // i
    p += t
    if mn == -1:
        mn = p
    mn = min(mn, p)
print(mn)

Measured memory_bytes: 7752
#include<stdio.h>

int main(void)
{
  //h,w入力
  int h,w;
  scanf("%d%d",&h,&w);

  //二次元配列a入力
  int i,j;
  char a[h][w];
  for(i=0;i<h;i++)
    scanf("%s",a[i]);

  int judgeh[h],judgew[w];
  //空白列の判定
  for(i=0;i<h;i++){
    judgeh[i]=0;
    for(j=0;j<w;j++)
      if(a[i][j]=='#'){
        judgeh[i]=1;
      }
  }
  //空白行の判定
  for(j=0;j<w;j++){
    judgew[j]=0;
    for(i=0;i<h;i++)
      if(a[i][j]=='#'){
        judgew[j]=1;
      }
  }

  //出力
  int n;
  for(i=0;i<h;i++){
    n=0;
    for(j=0;j<w;j++)
      if((judgeh[i]==1)&&(judgew[j]==1)){
        printf("%c",a[i][j]);
	n++;
      }
    if(n>0)
      printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1660
n, m= map(int,input().split())
a = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))

ans=0

for i in range(2**n):
    l = [False]*n
    for j in range(n):
        if(i>>j & 1):
            l[j] = True

    light = 0
    for x,aa in enumerate(a):
        cnt = 0
        for y,k in enumerate(aa):
            if y == 0:
                continue
            if l[k-1] == True:
                cnt += 1
        if cnt%2 == p[x]:
            light += 1
    if light == m:
        ans += 1
print(ans)


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

int main() {
  long long n, k;
  cin>>n>>k;
  long long a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) --a[i];
  bool seen[n];
  for (int i=0; i<n; i++) seen[i] = false;
  long long cnt[n];
  for (int i=0; i<n; i++) cnt[i] = 0;
  int pos = 0;
  seen[pos]= true;
  long long max_cnt = 0;
  while (true) {
    int prev = pos;
    pos = a[pos];
    if (seen[pos]) {
      max_cnt = cnt[prev] + 1;
      break;
    }
    seen[pos] = true;
    cnt[pos] = cnt[prev] + 1;
  }
  long long len_before_loop = cnt[pos];
  long long len_loop = max_cnt - cnt[pos];
  if (k <= len_before_loop) {
    int pos = 0;
    while (k > 0) {
      pos = a[pos];
      --k;
    }
    cout<<pos+1<<endl;
  } else {
    long long mod = (k - len_before_loop) % len_loop;
    while (mod > 0) {
      pos = a[pos];
      --mod;
    }
    cout<<pos+1<<endl;
  }
}

Measured memory_bytes: 6956
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    int n,m,X,Y,a=0,b=0,*x,*y;
    cin >> n >> m >> X >> Y;
    x=new int[n];
    y=new int[m];
    for(int i=0; i<n; i++)
        cin >> x[i];
    for(int i=0; i<m; i++)
        cin >> y[i];
    sort(x,x+n);
    sort(y,y+m);
    a=max(X,x[n-1]);
    b=min(Y,y[0]);
    if(a<b)
        cout << "No War\n";
    else
        cout << "War\n";
}

Measured memory_bytes: 256