akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n, m; scan(n, m);

    int[][] ms;
    for (int i = 0; i < m; i++) {
        auto ss = readints;
        ms ~= ss[1..$].map!(e => e - 1).array;
    }
    auto ps = readints;

    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        auto state = new bool[n];
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) state[j] = true;
        }

        bool ok = true;
        for (int j = 0; j < m; j++) {
            int p = 0;
            foreach (k; ms[j]) {
                if (state[k]) p++;
            }
            if (p % 2 != ps[j]) {
                ok = false;
                break;
            }
        }
        if (ok) ans++;
    }
    writeln(ans);
}


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

using static Input;
using static Util;
class Program
{
    static int N;
    static void INPUT()
    {
        N = NextInt();
    }
    static void OUT()
    {
        var b = false;
        for (int i = 1; i <= 9; i++)
        {
            if (N % i == 0)
            {
                if (N / i <= 9)
                {
                    b = true;
                    break;
                }
            }
        }

        Console.WriteLine(b ? "Yes" : "No");
    }
    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
        //INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
        N = 1;
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    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(); }
}

class Util
{
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstring>
#include<string>

using namespace std;

int n,q;
int A[30];

bool solve(int i,int m)
{
	if(m==0)return true;
	if(i>=n)return false;
	return solve(i+1,m)||solve(i+1,m-A[i]);//
}

int main()
{
	memset(A,0,sizeof(A));
	cin>>n;
	for(int i=0;i<n;i++)cin>>A[i];
	cin>>q;
	for(int i=0;i<q;i++){
		int m;
		cin>>m;
		if(solve(0,m)){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

int use[10];
int a[10],b[10],ans1,ans2,per[10];
int now=0;int n;

int fin(int tmp){
    if (tmp==n){
        now++;
        //for (int i=0;i<n;++i) printf("%d",per[i]);printf("\n");
        int flag=1;
        for (int i=0;i<n;++i)
            if (a[i]!=per[i])
                flag=0;
        if (flag) ans1=now;
        flag=1;
        for (int i=0;i<n;++i)
            if (b[i]!=per[i])
                flag=0;
         if (flag) ans2=now;
        return 0;
    }
    for (int i=1;i<=n;++i){
        if (use[i]==0){
            use[i]=1;
            per[tmp]=i;
            fin(tmp+1);
            use[i]=0;
        }
    }
}


int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;++i) scanf("%d",&a[i]);
    for (int j=0;j<n;++j) scanf("%d",&b[j]);
    fin(0);
    int ans=ans1-ans2;if (ans<0) ans=-ans;
    printf("%d",ans);


}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;


unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,T,k,q;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const ll MAXN = 3001;



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

    //freopen("input.txt","r",stdin);
   // freopen("autput.txt","w",stdout);

    ll a,b,c,d;

    cin >> n >> k;
    cout << (n-k)*(k > 1) << "\n";

    return 0;
}


Measured memory_bytes: 764
x = gets.chomp!.split("").map(&:to_s)


stack = []

x.length.times do |i|
	if x[i]=="S"
		stack.push(x[i])
	elsif x[i]=="T"&&(stack.last=="T"||stack.empty?)
		stack.push(x[i])
	else
		stack.pop
	end
end

puts stack.length




Measured memory_bytes: 19708
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2013
from itertools import accumulate
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    while True:
        n = int(readline())
        if n == 0:
            break

        table = [0] * 87000
        for _ in range(n):
            s_hms, t_hms = readline().split()
            s = int(s_hms[0:2]) * 3600 + int(s_hms[3:5]) * 60 + int(s_hms[6:8])
            t = int(t_hms[0:2]) * 3600 + int(t_hms[3:5]) * 60 + int(t_hms[6:8])

            table[s] += 1
            table[t] -= 1
        
        A = accumulate(table)
        ans = max(list(A))
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10224
import java.util.*;

public class Main {

    private static final int INF = 2_000_000_000;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }
        // 0: i+1, 1: i+2
        int[][] dp = new int[N][2];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < 2; j++) {
                dp[i][j] = INF;
            }
        }
        dp[0][0] = 0;
        dp[0][1] = 0;
        for (int i = 0; i < N; i++) {
            if (i >= 1) {
                dp[i][0] = Math.min(dp[i-1][0], dp[i-1][1]) + Math.abs(h[i]-h[i-1]);
            }
            if (i >= 2) {
                dp[i][1] = Math.min(dp[i-2][0], dp[i-2][1]) + Math.abs(h[i]-h[i-2]);
            }
        }
        System.out.println(Math.min(dp[N-1][0], dp[N-1][1]));
    }
}



Measured memory_bytes: 48588
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  cin >> s;
  int g = 0, p = 0;
  for (char x : s) {
    g += x == 'g';
    p += x == 'p';
  }
  int c = 0;
  while (p + 1 <= g - 1) p++, g--, c++;
  cout << c << endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    long long x;
    cin >> x;
    long long s = 100;
    for(int i = 1; ; i++){
        s *= 1.01;
        if(s >= x){
            cout << i;
            return 0;
        }
    }
    return 0;
}

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

#define pb push_back
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pf push_front

using namespace std;

typedef long long llong;

const int MXN = (int)1e6 + 7;
const llong INF = (llong)1e18 + 7;
const int MOD = (int)1e9 + 7;

string s;

int main()
{
  cin >> s;
  for(int i = 0; i < sz(s); i++){
    cout << 'x';
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long
//cout << fixed << setprecision (10);   小数点以下１０桁まで

int main() {
  int  a,b,c,d,e,k;
  cin >>a>>b>>c>>d>>e>>k;

  cout << (e-a<=k ? "Yay!":":(");
}


Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 110000
#define L 100000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline int read()
{
	char ch=0;
	int x=0,flag=1;
	while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*flag;
}
int main()
{
	int n=read(),k=read();
	if((n+1)/2>=k)printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, K;
        public long MOD = 1000000007;
        public int[] H;
        public long[] DP;
        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                K = line[1];
            }
            H = Input.ReadIntArray();
            DP = new long[N];
            DP[0] = 0;
            for (int i = 1; i < N; i++)
            {
                DP[i] = long.MaxValue;
                for (int k = 1; k <= K; k++)
                {
                    if (i < k) continue;
                    DP[i] = Math.Min(DP[i - k] + Math.Abs(H[i] - H[i - k]), DP[i]);
                }
            }
            Console.WriteLine(DP[N - 1]);
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 20576
#include<iostream>
#include<set>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int n,k;
int a[10];
set<string> s;
bool used[10];

void add(int depth,string str){
	if(depth==k){
		s.insert(str);
		return;
	}
	for(int i=0;i<n;i++){
		if(!used[i]){
			used[i]=true;
			string t;
			if(9<a[i])t += a[i]/10+'0';
			t += a[i]%10+'0';
			add(depth+1,str+t);
			used[i]=false;
		}
	}
}

int main(){
	while(cin>>n>>k,n||k){
		for(int i=0;i<n;i++)cin>>a[i];
		memset(used,false,sizeof(used));
		s.clear();
		add(0,"");
		cout<<s.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1460
#include <bits/stdc++.h>
//#include <atcoder/all>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define show(x) cerr << #x << " = " << x << "\n";
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define pb(x) push_back(x)
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
//using namespace atcoder;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
//using mint = modint998244353;
//ll mod = 998244353;
//using mint = modint1000000007;
ll mod = 1000000007;
 
void Main(){

	ll sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	rep(i, ty - sy) cout << "U";
	rep(i, tx - sx) cout << "R";
	rep(i, ty - sy) cout << "D";
	rep(i, tx - sx) cout << "L";

	cout << "L";
	rep(i, ty - sy + 1) cout << "U";
	rep(i, tx - sx + 1) cout << "R";
	cout << "D";

	cout << "R";
	rep(i, ty - sy + 1) cout << "D";
	rep(i, tx - sx + 1) cout << "L";
	cout << "U" << endl;

}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin >> t;
	rep(i, t) Main();
	return 0;
	
}





Measured memory_bytes: 3616
#include<stdio.h>
int main(){
  int n,nn,i;
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    if(i%3==0||i%10==3||i/10==3||(i/10-3)%10==0||(i/100-3)%10==0||(i/1000-3)%10==0) printf(" %d",i);
  }
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 596
def C(n, r):
    return fact[n]*inv_table[r]*inv_table[n-r]
    
def g(r, c):
    res = 0
    
    for i in range(1, r+2):
        res += C(i+c, c)
        res %= MOD
    
    return res

r1, c1, r2, c2 = map(int, input().split())
MOD = 10**9+7
fact = [1]

for i in range(1, 2*10**6+100):
    fact.append(fact[-1]*i%MOD)
    
inv_table = [pow(fact[-1], MOD-2, MOD)]

for i in range(1, 2*10**6+100)[::-1]:
    inv_table.append(inv_table[-1]*i%MOD)

inv_table.reverse()

print((g(r2, c2)-g(r2, c1-1)-g(r1-1, c2)+g(r1-1, c1-1))%MOD)

Measured memory_bytes: 126976
N, M = map(int, input().split())
P=0
AC = [0]*(N+1)
WA = [0]*(N+1)
for i in range(M):
    p, s =input().split()
    if s == "AC":
        AC[int(p)] = 1
    else:
        if AC[int(p)] == 1:
            continue
        else:
            WA[int(p)] += 1
for i in range(N+1):
    if AC[i] == 0:
        WA[i] = 0
print(sum(AC), sum(WA))

Measured memory_bytes: 47380
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		boolean[] jdg = new boolean[n+1];
		long mod = 1000000007;
		for(int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			jdg[a[i]] = true;
		}
		long[] dp = new long[n+1];
		dp[0] = 1;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j <= Math.min(n, i+2); j++) {
				if(jdg[j] == false) {
					dp[j] += dp[i];
					dp[j] %= mod;
				}
			}
		}
		System.out.println(dp[n]);
	}
}


Measured memory_bytes: 48996
"use strict";


const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    // 差が2以上あると交互に並べられない
    if(Math.abs(N - M) > 1) {
        console.log(0);
        return;
    }
    
    const MOD = 1e9 + 7;
    let answer = 1;
    
    for(let i=1; i<=N; i++) {
        answer = (answer % MOD) * (i % MOD);
    }
    
    for(let i=1; i<=M; i++) {
        answer = (answer % MOD) * (i % MOD);
    }
    
    /* -----------------------------------------------------
       差が0のときは、組み合わせが2通り 例：犬猿犬猿, 猿犬猿犬
       差が1のときは、組み合わせが1通り 例：犬猿犬猿犬
       それによって答えを2倍にするかどうか分ける
    --------------------------------------------------------*/
    console.log(answer * ((N == M) + 1) % MOD);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 13004
#include<stdio.h>

int main(){
	int b,f,r,v,n;
	int array[4][3][10];
	for(int i=0; i<4; i++){
			for(int t=0; t<3; t++){
				for(int j=0; j<10; j++){
					array[i][t][j]=0;
				}
			}
		}
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		array[b-1][f-1][r-1] += v;
	}
	for(int i=0; i<4; i++){
		for(int t=0; t<3; t++){
			for(int j=0; j<10; j++){
				if(array[i][t][j]==0){
					printf(" 0");
				}else{
					printf(" %d",array[i][t][j]);
				}
			}
			printf("\n");
		}
		if(i<3){
		printf("####################\n");
		}
	}
}



Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int a, b, k;
  cin >> a >> b >> k;
  int gc = __gcd(a, b);
  vector<int> ans;
  for(int i = 1; i * i <= gc; i++){
  	if(gc % i == 0){
  		ans.push_back(i);
  		if(i * i != gc){
  			ans.push_back(gc / i);
  		}
  	}
  }
  sort(ans.rbegin(), ans.rend());
  cout << ans[k - 1];
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	int point[5];
	int k;
	for(int i=0;i<5;i++) cin >> point[i];
	cin >> k;	
	bool ans = true;
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if (i==j) continue;
			if (abs(point[j] - point[i]) > k) ans = false;	
		}	
	}
	if(ans) cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;

}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<ctime>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const int INF = 100;

int  N, K, G, TY, PA;
string T;

int main() {
	scanf("%d%d%d%d%d", &N, &K, &G, &TY, &PA);
	cin >> T;
	string history;
	ll ans = 0;
	R(i, K) {
		if (T[i] == 'r') {
			ans += PA;
			history.push_back('p');
		}
		else if (T[i] == 's') {
			ans += G;
			history.push_back('r');
		}
		else {
			ans += TY;
			history.push_back('s');
		}
	}
	for (int i = K; i < N; i++) {
		if (T[i] == 'r') {
			if (history[i - K] != 'p') {
				ans += PA;
				history.push_back('p');
			}
			else {
				if(i + K < N){
					if (T[i + K] == 's') history.push_back('s');
					else history.push_back('r');
				}
			}
		}else if (T[i] == 's') {
			if (history[i - K] != 'r') {
				ans += G;
				history.push_back('r');
			}
			else {
				if (i + K < N) {
					if (T[i + K] == 'r') history.push_back('s');
					else history.push_back('p');
				}
			}
		}
		else {
			if (history[i - K] != 's') {
				ans += TY;
				history.push_back('s');
			}
			else {
				if (i + K < N) {
					if (T[i + K] == 'r') history.push_back('r');
					else history.push_back('p');
				}
			}
		}
	}
	printf("%lld", ans);
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <cmath>
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b) gcd(b, a);
	long long  r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

long long modinv(long long a, long long mod) {
	long long b = mod, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t*b; swap(a, b);
		u -= t*v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}
inline long long mod(long long a, long long m) {
	return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
long long extGcd(long long a, long long b, long long &p, long long &q) {
	if (b == 0) { p = 1; q = 0; return a; }
	long long d = extGcd(b, a%b, q, p);
	q -= a / b * p;
	return d;
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
//amari,mod,amari,mod
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
	long long p, q;
	long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
	if ((b2 - b1) % d != 0) return make_pair(0, -1);
	long long m = m1 * (m2 / d); // lcm of (m1, m2)
	long long tmp = (b2 - b1) / d * p % (m2 / d);
	long long r = mod(b1 + m1 * tmp, m);
	return make_pair(r, m);
}
typedef pair<long long,long long>p;
vector<int>graph[100004];
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int a, b;
	int x, y;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
		x = a;
		y = b;
	}
	int used[100004] = { 0 };
	used[x] = used[y] = 1;
	int done[2] = { 0 };
	deque<int>deq;
	deq.push_back(x);
	deq.push_back(y);
	while (1){
		if (done[0] == 0) {
			int judge = 0;
			for (int i = 0; i < graph[x].size(); i++) {
				if (used[graph[x][i]] == 0) {
					judge = 1;
					x = graph[x][i];
					deq.push_front(x);
					used[x] = 1;
					break;
				}
			}
			if (judge == 0)done[0] = 1;
		}
		else {
			if (done[1] == 0) {
				int judge = 0;
				for (int i = 0; i < graph[y].size(); i++) {
					if (used[graph[y][i]] == 0) {
						judge = 1;
						y = graph[y][i];
						deq.push_back(y);
						used[y] = 1;
						break;
					}
				}
				if (judge == 0)done[1] = 1;
			}
			else {
				break;
			}
		}
	}
	cout << deq.size()<<"\n";
	for (int i = 0; i < deq.size(); i++) {
		cout << deq[i] << " ";
	}
}


Measured memory_bytes: 7168
N = int(input())
S = str(input())
x = S[1:].count('E')
ans = x
for i in range(1, N):
    if S[i] == 'E':
        x -= 1
    if S[i - 1] == 'W':
        x += 1
    ans = min(ans, x)
print(ans)


Measured memory_bytes: 3700
s=gets
i=0
scnt=0
ncnt=0
wcnt=0
ecnt=0
while i<s.length
  if s[i]=='S'
    scnt+=1
  elsif s[i]=='W'
    wcnt+=1
  elsif s[i]=='E'
    ecnt+=1
  elsif s[i]=='N'
    ncnt+=1
  end
  i+=1
end
#puts "#{scnt} #{ncnt} #{wcnt} #{ecnt}"
if(scnt>0 && ncnt>0  || scnt==0 && ncnt==0)
  if(wcnt>0 && ecnt>0 || wcnt==0 && ecnt==0)
    puts "Yes"
  else
    puts "No"
  end
else
  puts "No"
end


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

namespace ConsoleApp14
{
    class Class33
    {
        static void Main()
        {
            var NKQ = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NKQ[0];
            int K = NKQ[1];
            int Q = NKQ[2];
            Dictionary<int, int> Table = new Dictionary<int, int>();
            for(int i = 0; i < N; i++) { Table[i] = K; }
            for(int i = 0; i < Q; i++)
            {
                int a = int.Parse(Console.ReadLine());
                Table[a-1] ++;
            }
            var ans = Table.Select(x => x.Value - Q);
            foreach(int i in ans)
            {
                Console.WriteLine(i > 0 ? "Yes" : "No");
            }
        }
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    int ans = n*(n+1)/2;

    cout << ans << endl;
}


Measured memory_bytes: 256
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
n = N % 10
if (n == 3) {
    a = "bon"
} else if ([0,1,6,8].indexOf(n) >= 0) {
    a = "pon"
} else {
    a = "hon"
}
console.log(a)

Measured memory_bytes: 29620
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict

n, m = li()
a = list(li())

dic = defaultdict(int)

for ai in a:
    dic[ai] += 1

for _ in range(m):
    b, c = li()
    dic[c] += b

keys = sorted(list(dic.keys()), reverse=True)

rest = n
ans = 0
for ki in keys:
    if dic[ki] > rest:
        ans += ki * rest
        rest = 0

    elif dic[ki] == rest:
        ans += ki * dic[ki]
        rest = 0

    else:
        ans += ki * dic[ki]
        rest -= dic[ki]

    if rest <= 0:
        break

print(ans)


Measured memory_bytes: 32448
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
long long mod=1000000007;
int g[110][110];
pair<int,pair<int,int> > edge[11000];
int UF[110];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int conv[110];
int ind[110];
vector<int>v[10];
long long getinv(long long a){
	long long ret=1;
	int t=mod-2;
	while(t){
		if(t%2)ret=ret*a%mod;
		a=a*a%mod;
		t/=2;
	}
	return ret;
}
long long mat[110][110];
long long calc(vector<int>p){
	int n=p.size();
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)mat[i][j]=0;
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
		if(g[p[i]][p[j]]){
			mat[i][j]=mat[j][i]=mod-1;
			mat[i][i]++;
			mat[j][j]++;
		}
	}
	//for(int i=0;i<n-1;i++){
	//	for(int j=0;j<n-1;j++)printf("%lld ",mat[i][j]);
	//	printf("\n");
	//}
	long long ret=1;
	for(int i=0;i<n-1;i++){
		int at=-1;
		for(int j=i;j<n-1;j++){
			if(mat[j][i]){
				at=j;break;
			}
		}
		if(!~at)return 0;
		if(at!=i)ret=(mod-ret)%mod;
		for(int j=0;j<n-1;j++)swap(mat[at][j],mat[i][j]);
		ret=ret*mat[i][i]%mod;
		long long ks=getinv(mat[i][i]);
		for(int j=0;j<n-1;j++)mat[i][j]=mat[i][j]*ks%mod;
		for(int j=i+1;j<n-1;j++){
			long long tmp=mat[j][i];
			for(int k=0;k<n-1;k++)mat[j][k]=(mat[j][k]+mod-tmp*mat[i][k]%mod)%mod;
		}
	}
	return ret;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q,r;
		scanf("%d%d%d",&p,&q,&r);
		p--;q--;
		g[p][q]=g[q][p]=1;
		edge[i]=make_pair(r,make_pair(p,q));
	}
	std::sort(edge,edge+b);
	for(int i=0;i<a;i++)UF[i]=-1;
	int dist=0;
	for(int i=0;i<b;i++){
		UNION(edge[i].second.first,edge[i].second.second);
		if(UF[FIND(0)]==-a){
			dist=edge[i].first;break;
		}
	}
	for(int i=0;i<a;i++)UF[i]=-1;
	for(int i=0;i<b;i++){
		if(dist>edge[i].first)UNION(edge[i].second.first,edge[i].second.second);
	}
	int n=0;
	for(int i=0;i<a;i++)if(UF[i]<0)conv[i]=n++;
	for(int i=0;i<a;i++)if(UF[i]>=0)conv[i]=conv[FIND(i)];
	for(int i=0;i<a;i++){
		ind[i]=v[conv[i]].size();
		v[conv[i]].push_back(i);
	}
	//for(int i=0;i<a;i++)printf("%d\n",conv[i]);
	long long ret=0;
	for(int i=0;i<(1<<n);i++){
		if(i==0||i==(1<<n)-1)continue;
		vector<int>L;
		vector<int>R;
		for(int j=0;j<a;j++){
			if(i&(1<<(conv[j])))L.push_back(j);
			else R.push_back(j);
		}
		ret=(ret+calc(L)*calc(R))%mod;
	}
	printf("%d %lld\n",dist,ret);
}

Measured memory_bytes: 1316
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int N=1e5+7;
int main()
{
    int n,a[1001],b[10];
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
            cin>>a[i];
        int ans=0;
        for(int i=1;i<=n-2;i++)
        {
            for(int j=1,k=i;j<=3;j++,k++)
                b[j]=a[k];
            sort(b+1,b+4);
            if(b[2]==a[i+1])
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

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

int main() {
  int N; cin>>N;
  vector<int> primes(1,2);
  for(int i = 3; i <= 200; i+=2) {
    if(pr(i)) primes.push_back(i);
  }
  //  REP(i,primes.size()) {                                                       
  //    cout << primes[i] << endl;                                                 
  //  }                                                                            
  vector<int> cnt(primes.size(), 0);
  for(int i = 2; i <= N; i++) {
    int m = i;
    //    cout << m << endl;                                                       
    for(int j = 0; j < primes.size(); j++) {
      if(m <= 1) break;
      while(m % primes[j] == 0) {
	cnt[j]++;
        m /= primes[j];
      }
    }
  }
  int n74=0, n24=0, n14=0, n4=0, n2=0;
  REP(i, cnt.size()) {
    if(cnt[i] > 0) {
      //      cout << i << " " << primes[i] << " " << cnt[i] << endl;              
    }
    if(cnt[i] >= 74) n74++;
    if(cnt[i] >= 24) n24++;
    if(cnt[i] >= 14) n14++;
    if(cnt[i] >= 4) n4++;
    if(cnt[i] >= 2) n2++;

  }
  //  cout << n74 << " " << n24 << " " << n14 << " " << n4 << " " << n2 << endl;   
  int ans = n74;
  ans += (n2 - 1) * (n24);
  ans += (n4 - 1) * (n14);
  ans += (n4 * (n4 - 1)) / 2 * (n2 - 2);
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int N, M;
char S[100000], T[100000];

int main() {
  int i;
  scanf("%d%d", &N, &M);
  scanf("%s%s", S, T);
  
  // 最大公約数を計算
  int g = __gcd(N, M);
  int stepS = N / g;
  int stepT = M / g;
  for (i = 0; i < g; ++i) {
    if (S[stepS * i] != T[stepT * i]) {
      puts("-1");
      return 0;
    }
  }
  printf("%lld", 1ll * N / g * M);
  return 0;
}

Measured memory_bytes: 384
/*
A - Day of Takahashi

Time limit : 2sec / Memory limit : 256MB
Score: 100 points
Problem Statement
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.
For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. 
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
How many days from 2018-1-1 through 2018-a-b are Takahashi?
Constraints
a is an integer between 1 and 12 (inclusive).
b is an integer between 1 and 31 (inclusive).
2018-a-b is a valid date in Gregorian calendar.
*/ 

#include<iostream>
using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	{
		if(a<=b)
			cout<<a<<endl;
		else
			cout<<a-1<<endl;
	}
	return 0;
 } 


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

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
num = int(input())
maxi = -1000001
mini = 1000001
total = 0
curr = 0
z = input()
for item in z.split():
    curr = int(item)
    if curr > maxi:
        maxi = curr
    if curr < mini:
        mini = curr
    total += curr
print (str(mini) + " " + str(maxi) + " " + str(total))



Measured memory_bytes: 6244
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main() {
  int n,cnt = 0,m;
  string s,t,u;
  cin >> s;
  n = s.size();
  m = n;
  n /= 2;
  for (int i = 0; i < n; i++){
    t += s[i];
  }
  if (m % 2 == 1){
   n++;
   for (int i = n; i < n*2-1; i++){
    u += s[i];
   }
  }
  else{
   for (int i = n; i < n*2; i++){
    u += s[i];
   }
  }
  reverse(u.begin(), u.end());
  for (int i = 0; i < n; i++){
    if (t[i] != u[i]){
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 16 20:36:58 2019

@author: Yamazaki Kenichi
"""

N = int(input())
C = [int(input()) for i in range(N)]
mod = 10**9+7
T = [[0] for i in range(2*10**5+1)]
ans = [1 for i in range(N+1)]
for i in range(N): 
    if i == 0 or C[i] != C[i-1]:
        T[C[i]][0] += 1
        T[C[i]].append(i)
        if T[C[i]][0] >=2:
            ans[i] = (ans[i-1] + ans[T[C[i]][-2]])%mod
        else:
            ans[i] = ans[i-1]%mod
    else:
        ans[i] = ans[i-1]%mod
        
print(ans[N-1]%mod)

Measured memory_bytes: 46076
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    double a, b, c, d, e, f;
    double y;
    while(cin>>a>>b>>c>>d>>e>>f){
        y = (c*d-a*f)/(b*d-a*e);
        cout<<fixed;
        cout<<setprecision(3)<<(c-b*y)/a<<" " <<y<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>

using namespace std;


int main()
{
	int A, B, answer = 0;
	cin >> A >> B;

	for(int i = 0; i < 2; i++)
	{
		if(A > B)
		{
			answer += A;
			A--;
		}
		else
		{
			answer += B;
			B--;
		}
	}

	cout << answer << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> A(H+2);
    A[0] = string(W+2, '#');
    A[H+1] = string(W+2, '$');
    REP(i,1,H+1) {
        string s;
        cin >> s;
        A[i] = "#" + s + "#";
    }

    queue<pll> Q;
    mat D(H+2, vec(W+2, -1));
    REP(i,1,H+1) {
        REP(j,1,W+1) {
            if(A[i][j] == '#') {
                Q.push({i, j});
                D[i][j] = 0;
            }
        }
    }

    vector<pll> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
    while(!Q.empty()) {
        pll p = Q.front(); Q.pop();
        ll i = p.first, j = p.second;
        FORR(d,dir) {
            ll k = i + d.first, l = j + d.second;
            if(A[k][l] == '.' && D[k][l] == -1) {
                D[k][l] = D[i][j] + 1;
                Q.push({k, l});
            }
        }
    }

    ll m = 0;
    REP(i,1,H+1) {
        REP(j,1,W+1) {
            m = MAX(m,D[i][j]);
        }
    }
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 29180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int dfs(int sv,vector<int> *adj_list,vector<bool> &visited,vector<int> &dp){
	int maxm = 0;
	visited[sv] = true;
	for(int x:adj_list[sv]){
		if(!visited[x]){
			maxm = max(maxm,1+dfs(x,adj_list,visited,dp));
		}
		else{
			maxm = max(maxm,1+dp[x]);
		}
	}
	return dp[sv] = maxm;
}
int main(int argc,char const* argv[]){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m;
	cin>>n>>m;
	vector<int> *adj_list = new vector<int>[n+1];
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		adj_list[u].push_back(v);
	}
	vector<bool> visited(n+1,false);
	vector<int> dp(n+1,0);
	int maxm = 0;
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			maxm = max(maxm,dfs(i,adj_list,visited,dp));
		}
	}
	cout<<maxm<<endl;
	delete []adj_list;
	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Say(a) cout <<(a);
#define Sal(a) cout <<(a)<<endl;

const ll MOD = 1e9+7;
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    ll N,can=1,cnt=0;
    cin >>N;
    vll a(N);
    vll b(N,0);
    FOR(i,0,N-1){
        cin >>a[i];
    }
    
    if(a[0]!=0) can=0;
    if(a[0]==0){
        FOR(i,0,N-1){
            if(i>0){
                if(a[i]-a[i-1]>1) can=0;
            }
            if(can==0) break;
            if(a[i]>=1){
                if(b[i-a[i]]<a[i]) b[i-a[i]]=a[i];
            }
        }
        if(can==1){
            FOR(i,0,N-1){
                cnt+=b[i];
            }
        }
    }
    
    if(can==0) Sal(-1);
    if(can==1) Sal(cnt);
    
    return 0;
}

Measured memory_bytes: 3328
from collections import deque

H, W = map(int, input().split())
maze = [list(input()) for i in range(H)]
# print(maze)

# (sx, sy) から (gx, gy) への最短距離を求める
# 辿り着けないと INF
def bfs(sy, sx):
    # すべての点を INF で初期化
    d = [[float("inf")] * W for i in range(H)]

    # 移動4方向のベクトル
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    # for i in range(n):
    #     for j in range(m):
    #         # スタートとゴールの座標を探す
    #         if maze[i][j] == "S":
    #             sx = i
    #             sy = j
    #         if maze[i][j] == "G":
    #             gx = i
    #             gy = j

    # スタート地点をキューに入れ、その点の距離を0にする
    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0
    
    max_root = 0
    # キューが空になるまでループ
    while que:
        # キューの先頭を取り出す
        p = que.popleft()
        # 取り出してきた状態がゴールなら探索をやめる
        # if p[0] == gx and p[1] == gy:
        #     break
        # 移動4方向をループ
        for i in range(4):
            # 移動した後の点を (nx, ny) とする
            nx = p[1] + dx[i]
            ny = p[0] + dy[i]

            # 移動が可能かの判定とすでに訪れたことがあるかの判定
            # d[nx][ny] != INF なら訪れたことがある
            if 0 <= nx < W and 0 <= ny < H and maze[ny][nx] != "#" and d[ny][nx] == float("inf"):
                # 移動できるならキューに入れ、その点の距離を p からの距離 +1 で確定する
                que.append((ny, nx))
                d[ny][nx] = d[p[0]][p[1]] + 1
                max_root = max(max_root, d[ny][nx])    
    return max_root



ans = 0
for h in range(H):
    for w in range(W):
        if maze[h][w] == ".":
            ans = max(bfs(h, w), ans)
print(ans)

# print(ans)
# print(bfs())      




Measured memory_bytes: 3436
# AOJ 2800: Mod!Mod!
# Python3 2018.7.11 bal4u

n = int(input())
a = list(map(int, input().split()))
c = [0]*3
for i in a:	c[i%3] += 1
if (c[1]|c[2]) == 0: ans = 1
else:
	ans, n = c[0], n-c[0]
	if n <= 3: ans += n
	else:
		t = max(-3, min(3, c[1]-c[2]))
		if t > 0: ans += 2*c[2]+t
		else: ans += 2*c[1]-t
print(ans) 


Measured memory_bytes: 15032
#include <iostream>

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int sum = 0;
  while(m--) {
    int a;
    scanf("%d", &a);
    sum += a;
  }
  if(sum <= n) printf("%d\n", n-sum);
  else printf("%d\n", -1);
  return 0;
}

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


int main()
{
	int A, B,C,X;
	cin >> A >> B>>C>>X;
	int res=0;
	for (int a = 0; a <= A; a++)
	{
		for (int b = 0; b <= B; b++)
		{
			for (int c = 0; c <= C; c++)
			{
				int total = 500 * a + 100 * b + 50 * c;
				if (total == X)
				{
					res++;
				}
			}
		}
	}
	

	cout << res<< endl;


}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int horieyui;
	int asumikana;
	int amamiyasora;
	int morikubosyotaro;
} tudaminami;

int main(void) {
	static tudaminami kitamuraeri[200000];
	int kugimiyarie;
	int tokuisora;
	int mimorisuzuko;
	int satourina;
	int mizuhasikaori;
	int oogameasuka;
	int igutiyuka;
	if(scanf("%d%d%d",&kugimiyarie,&tokuisora,&mimorisuzuko)!=3)return 1;
	for(satourina=0;satourina<kugimiyarie;satourina++) {
		kitamuraeri[satourina].horieyui=satourina;
		kitamuraeri[satourina].asumikana=1;
		kitamuraeri[satourina].amamiyasora=satourina-1;
		kitamuraeri[satourina].morikubosyotaro=satourina+1;
	}
	kitamuraeri[0].amamiyasora=kugimiyarie-1;
	kitamuraeri[kugimiyarie-1].morikubosyotaro=0;
	mizuhasikaori=0;
	for(satourina=0;satourina<tokuisora;satourina++) {
		if(scanf("%d",&oogameasuka)!=1)return 1;
		if(oogameasuka%2==0) {
			for(igutiyuka=0;igutiyuka<oogameasuka;igutiyuka++) {
				mizuhasikaori=kitamuraeri[mizuhasikaori].morikubosyotaro;
			}
		} else {	
			for(igutiyuka=0;igutiyuka<oogameasuka;igutiyuka++) {
				mizuhasikaori=kitamuraeri[mizuhasikaori].amamiyasora;
			}
		}
		kitamuraeri[mizuhasikaori].asumikana=0;
		kitamuraeri[kitamuraeri[mizuhasikaori].amamiyasora].morikubosyotaro
			=kitamuraeri[mizuhasikaori].morikubosyotaro;
		kitamuraeri[kitamuraeri[mizuhasikaori].morikubosyotaro].amamiyasora
			=kitamuraeri[mizuhasikaori].amamiyasora;
		mizuhasikaori=kitamuraeri[mizuhasikaori].morikubosyotaro;
	}
	for(satourina=0;satourina<mimorisuzuko;satourina++) {
		if(scanf("%d",&oogameasuka)!=1)return 1;
		printf("%d\n",kitamuraeri[oogameasuka].asumikana);
	}
	return 0;
}

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

from collections import deque
def main():
    H,W = map(int,input().split())
    S = ["#"*(W+2)]+["#"+input()+"#" for _ in range(H)]+["#"*(W+2)]

    vector = [(1,0),(-1,0),(0,1),(0,-1)]
    answer = 0
    for i in range(H+2):
        for j in range(W+2):
            if S[i][j] == "#":
                continue

            queue = deque()
            queue.append((i,j,0))
            max_dist = 0
            isVisited = [[False]*(W+2) for _ in range(H+2)]

            while queue:
                x,y,dist = queue.popleft()
                if S[x][y] == "." and isVisited[x][y] == False:
                    isVisited[x][y] = True
                    max_dist = dist

                    for lr,ud in vector:
                            queue.append((x+lr,y+ud,dist+1))
                
            answer = max(answer,max_dist)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
 
using namespace std;
 
#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
 
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int M = 1e3 + 10;
 
int main() {
	deque<char>dq;
	int l,q,cn=0;
	string s,res="";
	cin>>s>>q;
	l=s.length();
	for(int i=0;i<l;i++){
		dq.push_back(s[i]);
	}
	for(int i=0;i<q;i++){
		int t,f;
		char ch;
		cin>>t;
		if(t==1){
			cn++;
		}
		else{
			cin>>f>>ch;
			if(cn&1) f=3-f;
			if(f==1) dq.push_front(ch);
			else dq.push_back(ch);
		}
	}
	for(auto x:dq)
	res+=x;
	if(cn&1) reverse(res.begin(),res.end());
	cout<<res;
	return 0;
}

Measured memory_bytes: 1412
#include<stdio.h>
#include<string.h>
int main(void){
  char n[100];
  int len;
  int a = 0;
  scanf("%s",n);
  len = strlen(n);
  for(int i=0;i<len;i++){
    if((i%2==0&&n[i]=='L')||(i%2!=0&&n[i]=='R')){
      printf("No");
      a=1;
      break;
    }
  }
  if(a==0){
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
/*************************************
 *プログラム名：A.c
 *
 *************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include <pthread.h>

//<<<<<>>>>>//

int main(void)
{
	int a, b;
	
	scanf("%d", &a);
	scanf("%d", &b);
	
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		puts("Possible");
	}
	else {
		puts("Impossible");
	}
	
	return (0);
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int K;
	cin >> K;

	string S;
	cin >> S;

	if (S.length() <= K)
	{
		cout << S;
	}
	else
	{
		cout << S.substr(0, K);
		cout << "...";
	}

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int a, b;
};
bool operator<(const ST& a, const ST& b){
  if(a.a == b.a) return a.b > b.b;
  return a.a < b.a;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<ST> v;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    v.push_back((ST){a,b});
  }
  
  sort(ALLOF(v));

  int ret = 0;
  int last = N+1;
  rep(i,M){
    if(last <= v[i].a){
      ret++;
      last = v[i].b;
    }else{
      last = min(last, v[i].b);
    }
  }
  ret++;

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 1400