akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vvc a(H,vc(W));
    rep(i,H){
        rep(j,W){
            cin >> a[i][j];
        }
    }
    ll dp[H][W];
    rep(i,H){
        rep(j,W){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    rep(i,H){
        rep(j,W){
            if(a[i][j]=='#')continue;
            if(i>=1&&a[i-1][j]=='.'){
                dp[i][j]+=dp[i-1][j]%MOD;
            }
            if(j>=1&&a[i][j-1]=='.'){
                dp[i][j]+=dp[i][j-1]%MOD;
            }
            dp[i][j]%=MOD;
        }
    }
    cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 12188
while 1:
 m,f,r=map(int,input().split());s=m+f
 if m==f==r<0:break
 if m*f<0 or s<30:print('F')
 elif s>79:print('A')
 elif s>64:print('B')
 elif s>49 or r>49:print('C')
 else:print('D')


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

	string s[55];
	int i,j;
	int cnt = 0;

	for (i = 0; i < h; i++)
	{
		cin >> s[i];
	}
	
	int x[8] = { -1,0,1,-1,1,-1,0,1 };
	int y[8] = { 1,1,1,0,0,-1,-1,-1 };

	for (i = 0; i < h; i++)
	{
		for (j = 0; j < w; j++)
		{
			if (s[i].at(j) == '#')continue;
			for (int k = 0; k < 8; k++)
			{
				int nx = j + x[k];
				int ny = i + y[k];
				//cout << nx << ":" << ny << endl;
				if (nx < 0 || w<= nx)continue;
				if (ny < 0 || h<= ny)continue;
				//cout << nx << ":" << ny<<endl;
				if (s[ny].at(nx) == '#')cnt++;
			}
			//cout << endl;
			s[i].at(j) = char(cnt+'0');
			cnt = 0;
		}
	}
	for (i = 0; i < h; i++)
	{
		
		cout<<s[i] << endl;
	}
}
	


/**/
/*#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define PI 3.141592653589793

int main(void) {
	return 0;
}
*/

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

int main(){
	int N, X;
	cin >> N >> X;
	vector<int> m;
	int minm = 1000;
	int num = 0;
	for (auto i = 0; i < N; i++){
		int buf;
		cin >> buf;
		m.push_back(buf);
		X -= buf;
		num++;
		if (buf < minm){
			minm = buf;
		}
	}
	while (X >= minm){
		X -= minm;
		num++;
	}
	cout << num;

	return 0;
}

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

//def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n, x, y;
    cin >> n >> x >> y;
    map<int, int> dict;
    repeat(i, 1, n + 1) {
        repeat(j, i + 1, n + 1) {
            int i_j = j - i;
            int i_x_y_j = abs(i - x) + 1 + abs(j - y);
            int dist = min(i_j, i_x_y_j);
            dict[dist]++;
        }
    }

    repeat(i, 1, n) {
        out(dict[i]);
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define mod 1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 300010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;b>>=1;
	}
	return ans;
}

char s[N];
int dp[5][1<<4],ndp[5][1<<4];
int main(){
	//cout<<setprecision(9)<<fixed;
    int ca=0,T,m=0,k,i,j,n,K=0;
	scanf("%s",s);n=strlen(s);
	if(s[0]=='0'||s[0]=='?')dp[1][0]++;
	if(s[0]=='1'||s[0]=='?')dp[1][1]++;
	rep(i,1,n){
		memset(ndp,0,sizeof(ndp));
		rep(j,1,5)rep(k,0,(1<<j))if(dp[j][k]){
			int &w=dp[j][k];
			if(s[i]=='0'||s[i]=='?'){
				if(j==1){
					add(ndp[j+1][k<<1],w);
				}
				else if(j==2){
					if(k<=1){
						add(ndp[1][0],w);
					}
					else add(ndp[j+1][k<<1],w);	
				}
				else if(j==3){
					if(k==4)add(ndp[2][2],w);
					else if(k<7)add(ndp[j+1][k<<1],w);
					else add(ndp[2][3],w);
				}
				else{
					add(ndp[3][6],w);
				}
			}
			if(s[i]=='1'||s[i]=='?'){
				if(j==1){
					add(ndp[j+1][k<<1|1],w);
				}
				else if(j==2){
					if(k==0){
						add(ndp[1][0],w);
					}
					else if(k<=2){
						add(ndp[1][1],w);
					}
					else{
						add(ndp[3][7],w);
					}	
				}
				else if(j==3){
					if(k==4)add(ndp[2][2],w);
					else add(ndp[2][3],w);
				}
				else{
					add(ndp[3][6],w);
				}
			}
		}
		swap(dp,ndp);
	}
	int ans=(0LL+dp[1][1]+dp[3][6]+dp[3][7])%mod;
	printf("%d\n",ans);
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>

#pragma warning(disable: 4996)

#define MOD 100000

#define MAX_M 2000
#define MAX_S 3000

int N, M, S;

int dp[2][MAX_M + 1][MAX_S + 1];

int main()
{
	while (true)
	{
		scanf("%d", &N);
		scanf("%d", &M);
		scanf("%d", &S);

		if (N == 0 && M == 0 && S == 0) { break; }

		for (int i = 0; i < M; i++)
		{
			for (int j = 0; j < S; j++)
			{
				if (i == j && i != 0 && j != 0)
				{
					dp[1][i][j] = 1;
				}
				else
				{
					dp[1][i][j] = 0;
				}
			}
		}

		int A = N * N;

		for (int n = 2; n <= A; n++)
		{
			for (int i = 0; i < M; i++)
			{
				dp[n % 2][i][0] = 0;
			}

			for (int j = 0; j < S; j++)
			{
				dp[n % 2][0][j] = 0;
			}

			for (int i = 1; i <= M; i++)
			{
				for (int j = 1; j <= S; j++)
				{
					if (n % 2 == 0)
					{
						dp[0][i][j] = (dp[0][i - 1][j - 1] + (j >= i ? dp[1][i - 1][j - i] : 0)) % MOD;
					}
					else
					{
						dp[1][i][j] = (dp[1][i - 1][j - 1] + (j >= i ? dp[0][i - 1][j - i] : 0)) % MOD;
					}
				}
			}
		}

		int sum = 0;

		for (int i = 1; i <= M; i++)
		{
			sum += dp[A % 2][i][S];

			sum %= MOD;
		}

		printf("%d\n", sum);
	}

	return 0;
}

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

int main(){
  int n,T; cin>>n>>T;
  int ans=1001;
  rep(i,n){
    int c,t;cin>>c>>t;
    if(t<=T)ans=min(ans,c);
  }
  ans==1001?cout<<"TLE":cout<<ans;
}

Measured memory_bytes: 256
n = int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i,cnt])
    # 上のループを通した後にtempが1じゃなかったら、だけど、nが素数以外にそんなケースある？
    if temp!=1:
        arr.append([temp, 1])
    
    # 素数だったときの処理
    if arr == []:
        arr.append([n,1])

    return arr
fact = factorization(n)
ans = 0
for base, times in fact:
    if base == 1:
        continue
    i = 1
    while True:
        times -= i
        if times >= 0:
            ans += 1
        else:
            break
        i += 1
print(ans)





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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	string A,B,C;
	cin>>A>>B>>C;
	
	printf("%c%c%c\n",A[0]-32,B[0]-32,C[0]-32);

	return 0;
}



Measured memory_bytes: 256
class Dice:
    def __init__(self, init_values = ['1','2','3','4','5','6']):
        self.value = dict(zip(["top", "front","right","left","back","bottom"]\
                             , init_values))

    #north, south, east and west
    def roll(self, direction):
        if direction == 'N':
            self.value["top"], self.value["front"], self.value["bottom"], self.value["back"] = \
            self.value["front"], self.value["bottom"], self.value["back"], self.value["top"]
        elif direction == 'S':
            self.value["top"], self.value["back"], self.value["bottom"], self.value["front"] = \
            self.value["back"], self.value["bottom"], self.value["front"], self.value["top"]
        elif direction == 'E':
            self.value["top"], self.value["left"], self.value["bottom"], self.value["right"] = \
            self.value["left"], self.value["bottom"], self.value["right"], self.value["top"]
        elif direction == 'W':
            self.value["top"], self.value["right"], self.value["bottom"], self.value["left"] = \
            self.value["right"], self.value["bottom"], self.value["left"], self.value["top"]
        else:
            print("Error: illegal format.")

    # clockwise, counterclockwise
    def spin(self, direction):
        if direction == "CW":
            self.value["front"], self.value["right"], self.value["back"], self.value["left"] = \
            self.value["right"], self.value["back"], self.value["left"], self.value["front"]
        elif direction == "CCW":
            self.value["front"], self.value["left"], self.value["back"], self.value["right"] = \
            self.value["left"], self.value["back"], self.value["right"], self.value["front"]
        else:
            print("Error: illegal format.")
            
dice1 = Dice(input().split())
dice2 = Dice(input().split())

result = "No"
for direction in 'SESESE':
    dice2.roll(direction)
    if dice1.value["top"] == dice2.value["top"]:
        for j in range(4):
            dice2.spin("CW")
            if dice1.value == dice2.value:
                result = "Yes"
                break

print(result)

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;

  vector<pair<ld, ld>> c(n);
  rep(i, n) {
    cin >> c[i].first >> c[i].second;
  }

  auto hikaku = [](const pair<ld, ld> &lhs, const pair<ld, ld> &rhs) {
    if (lhs.first == rhs.first) {
      return lhs.second > rhs.second;
    }
    return lhs.first > rhs.first;
  };

  sort(all(c), hikaku);

  ld ans = 0;
  ll ptn = 0;

  do {
    // do
    REP(i, n) {
      ld x = c[i].first - c[i - 1].first;
      ld y = c[i].second - c[i - 1].second;
      ans += sqrt(x * x + y * y);
    }
    ptn++;
  } while (next_permutation(all(c), hikaku));

  ans /= ptn;

  cout << ans << endl;

  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 rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  int N; cin >> N;
  vi T(N);
  rep(i,N){int a; cin >> a; T[i] = a;}
  int M; cin >> M;
  vvi chg(M, vi(2));
  rep(i,M){ int a, b; cin >> a >> b; chg[i][0]=a; chg[i][1]=b;}
  int tsum = 0;
  rep(i,N) tsum += T[i];

  rep(i,M) cout << tsum - T[chg[i][0]-1] + chg[i][1] << endl;
  return 0;
}

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

int main(){
    string S, T;
    cin >> S >> T;
    bool chk = true;
    for(int i=0;i<(int)S.length();i++){
        if(S[i] != T[i]) chk = false;
    }
    if(chk) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r1 = ReadSplit();
            var n = r1[0].ToLong();
            var max = r1[1].ToLong();

            var dp = new long[110][];
            var w = new long[n];
            var v = new long[n];
            var INF = 999999999999;
            for (int i = 0; i < 110; i++)
            {
                dp[i] = new long[110000];
                for (int j = 0; j < 110000; j++)
                {
                    dp[i][j] = INF;
                }
            }
            for (int i = 0; i < n; i++)
            {
                var r2 = ReadSplit();
                w[i] = r2[0].ToLong();
                v[i] = r2[1].ToLong();
            }

            var mV = v.Sum();
            dp[0][0] = 0;
            for (int i = 0; i < n; i++)
            {
                for (long s = 0; s <= mV; s++)
                {
                    if (s - v[i] >= 0)
                    {
                        ChangeMin(ref dp[i + 1][s], dp[i][s - v[i]] + w[i]);
                    }
                    ChangeMin(ref dp[i + 1][s], dp[i][s]);
                }
            }
            long ans = 0;
            for (int i = 1; i <= mV; i++)
            {
                if (dp[n][i] <= max) ans = i;
            }
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int ToInt32(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long ToLong(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))


        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 112756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,k,n) for(ll i = k;i<n;i++)
#define mo unordered_map<ll,ll> 
#define mi map<ll,map<ll,ll>>


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll a[m+2];
    ll b[m+2];
    fr(i,0,m){
    	cin>>a[i]>>b[i];
    }
    unordered_map<ll,ll> dp;
    fr(i,0,n+2){
    	dp[i] =  pow(10,10);
    }
    dp[0] = 0;
  //  memset(dp,LLONG_MAX,sizeof(dp));
fr(i,0,m){
	fr(j,0,n){
		dp[min(j+a[i],n)] = min(dp[j]+b[i],	dp[min(j+a[i],n)]);
	}
	
	
}
cout<<dp[n]<<"\n";
    
    
    }

Measured memory_bytes: 768
//##MohK
//15/2/2020 .....8,40
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,n,max=-9999,min=9999;
    cin>>a;
    for(ll i=0;i<a;i++){
        cin>>n;
        if(n>max)max=n;
        if(n<min)min=n;
    }
    cout<<max-min<<endl;

return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

const int INF = 2e9;

vector<vector<int>> dp;
vector<vector<int>> dist;
int n;

int rec(int S, int v) {
    if (dp[S][v] >= 0) return dp[S][v];
    if (S == (1<<n)-1 && v == 0) return dp[S][v] = 0;
    
    int res = INF;
    REP(i,n) {
        if (!(S>>i & 1) && dist[v][i] >= 0) {
            // ith vertex is not in S
            // move from v to i
            res = min(res, rec(S | 1<<i, i) + dist[v][i]);
        }
    }
    return dp[S][v] = res;
}

int main() {
    int V, E;
    cin >> V >> E;
    n = V;
    dist = vector<vector<int>>(V,vector<int>(V,-1));
    REP(i,E) {
        int s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }
    
    dp = vector<vector<int>>(1<<V,vector<int>(V+1,-1));
    // dp[S][j] denotes the minimum distance from jth vertex to 0th vertex passing all unpassed vertices
    
    int ans = rec(0,0);
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6320
#include <iostream>

int main() {
  int A, B, C, D;
  std::cin >> A >> B >> C >> D;

  int left = A + B;
  int right = C + D;
  if ( left > right ) {
    std::cout << "Left" << std::endl;
  } else if ( left < right ) {
    std::cout << "Right" << std::endl;
  } else {
    std::cout << "Balanced" << std::endl;
  }

  return 0;
}


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

int main() {
  int N;
  cin>>N;
  int C0,C1,C2,C3;
  C0=0;C1=0;C2=0;C3=0;
  
  vector<string> answer(N);
  for(int i=0; i<N; i++){
    cin>>answer.at(i);
  }
  for(int i=0; i<N; i++){
    if(answer.at(i)=="AC"){
      C0++;
    }
    else if(answer.at(i)=="WA"){
      C1++;
    }
    else if(answer.at(i)=="TLE"){
      C2++;
    }
    else if(answer.at(i)=="RE"){
      C3++;
    }
    else{
    }
  }
    cout<<"AC x "<< C0<<endl;
    cout<<"WA x "<< C1<<endl;
    cout<<"TLE x "<< C2<<endl;
    cout<<"RE x "<< C3<<endl;
}

Measured memory_bytes: 6368
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    for ( int i = 0 ; i < n ; i++ ) cin >> a[i];
    sort( a , a + n );
    if ( n % 2 == 1 ) {
        bool y = 1;
        for ( int i = 0 ; i < n ; i++ ) {
            if ( i % 2 == 1 ) {
                if ( a[i] != i + 1 ) y = 0;
            } else {
                if ( a[i] != i ) y = 0;
            }
        }
        if ( y ) {
            int b = 1;
            for ( int i = 0 ; i < n / 2 ; i++ ) {
                b = ( b * 2 ) % 1000000007;
            }
            cout << b;
        } else cout << 0;
    } else {
        bool y = 1;
        for ( int i = 0 ; i < n ; i++ ) {
            if ( i % 2 == 0 ) {
                if ( a[i] != i + 1 ) y = 0;
            } else {
                if ( a[i] != i ) y = 0;
            }
        }
        if ( y ) {
            int b = 1;
            for ( int i = 0 ; i < n / 2 ; i++ ) {
                b = ( b * 2 ) % 1000000007;
            }
            cout << b;
        } else cout << 0;
    }
}

Measured memory_bytes: 640
x,n = map(int,input().split(" "))
if n == 0:
  print(x)
else:
  num = list(map(int, input().split(" ")))
  num.sort()

  if x not in num:
    print(x)
  else:
    y = num.index(x)
    if y == (n-1):
      if num[y-1] == x-1:
        print(x+1)
      else:
        print(x-1)
    elif y == 0:
      print(x-1)
    else:
      for i in range(100):
        y = x-i
        if y not in num:
          under = y
          count_under = i
          break
      for j in range(100):
        y = x + j
        if y not in num:
          upper = y
          count_upper = j
          break
      
      if count_under <= count_upper:
        print(under)
      else:
        print(upper)

Measured memory_bytes: 9172
#include<stdio.h>
int main(void){
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	if(a==b || a==c || b==c){
		if(a==b && a==c){
			printf("No\n");
		}
		else{
			printf("Yes\n");
		}
	}
	else{
		printf("No\n");
	}
	return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int m = s.size(), n = t.size();
  vector<vector<int>> lcs(m + 1, vector<int>(n + 1));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      lcs.at(i + 1).at(j + 1) = max({lcs.at(i).at(j) + (s.at(i) == t.at(j)),
                                     lcs.at(i + 1).at(j),
                                     lcs.at(i).at(j + 1)});
    }
  }
  string ans;
  int k = m, l = n;
  while (k && l) {
    if (s.at(k - 1) == t.at(l - 1)) {
      assert(lcs.at(k - 1).at(l - 1) == lcs.at(k).at(l) - 1);
      ans += s.at(k - 1);
      k--; l--;
    } else if (lcs.at(k).at(l - 1) >= lcs.at(k - 1).at(l)) {
      l--;
    } else {
      k--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


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

class Program
{
    static void Main()
    {
        var S =ReadLine();
        var d = new int[26];
        for (int i = 0; i < 4; i++)
        {
            d[S[i]-'A']++;
        }
        WriteLine(d.Max()==2&&d.Count(x=>x!=0)==2?"Yes":"No");
    }
}


Measured memory_bytes: 11220
#include<stdio.h>
int main()
{
	int j, i, n, a[4][13], o;
	char s;
	for (j = 0; j < 4; j++)
	{
		for (i = 0; i < 13; i++)
		{
			a[j][i] = 0;
		}
	}

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%s %d", &s, &o);
		if (s == 'S'){
			a[0][o - 1] = 1;
		}
		else if (s == 'H'){
			a[1][o - 1] = 1;
		}
		else if (s == 'C'){
			a[2][o - 1] = 1;
		}
		else if (s == 'D'){
			a[3][o - 1] = 1;
		}
	}
	for (j = 0; j < 4; j++)
	{
		for (i = 0; i < 13; i++)
		{
			if (a[j][i] == 0){
				if (j == 0)
					printf("S %d\n", i + 1);
				else if (j == 1)
					printf("H %d\n", i + 1);
				else if (j == 2)
					printf("C %d\n", i + 1);
				else if (j == 3)
					printf("D %d\n", i + 1);
			}

		}
	}

	


	return(0);

}

Measured memory_bytes: 596
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long


//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N;
  vector<int> a;
  cin >> N;
  a.resize(N);
  for(int i = 0 ; i < N ; i++){
  	cin >> a[i];
  }
  int cur = 1;
  int stay = 0;
  for(int i = 0 ; i < N ; i++){
  	if(a[i] == cur){
  		stay++;
  		cur++;
  	}
  }
  if(stay == 0){
  	cout << -1 << endl;
  }
  else{
  	cout << N - stay << endl;
  }
  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

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


int main(){
  string S;
  cin >> S;
  string C = "CODEFESTIVAL2016";
  int ans = 0;
  for(int ii=0; ii<16; ii++){
    if(S[ii] != C[ii]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e6;
int freq[N];
vi v;
int m, k;
int mx;

bool check() {
//    for(auto val : v)cout << val << " ";cout << endl;
    loop(i, SZ(v)) {
        int x = v[i];
        range(j, i + 1, SZ(v) - 1) {
            x ^= v[j];
            if (v[i] == v[j] && x != k)return false;
        }
    }

    return true;
}

void solve(int idx = 0) {
    if (idx == 1 << (m + 1)) {
        if (check()) {
            for (auto val : v)cout << val << " ";
            cout << endl;
            exit(0);
        }
        return;
    }


    range(i, 0, mx) {
        if (freq[i] == 2)continue;
        v.pb(i);
        freq[i]++;
        solve(idx + 1);
        v.pop_back();
        freq[i]--;
    }
}

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    cin >> m >> k;

    mx = (1 << m) - 1;
    if (m <= 2) {
        solve();
        cout << -1 << endl;
        return 0;
    }

    if (k <= mx) {
        rloop(i, mx)if (i != k)cout << i << " ";
        cout << k << " ";
        loop(i, mx + 1)if (i != k)cout << i << " ";
        cout << k << endl;
        return 0;
    }


    cout << -1 << endl;


    return 0;

}


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

int r, c, q, S;
vector<ll> v[1000];

void init(int x, int y){
	rep(i,x){
		rep(j,y*4){
			v[i][j] = INF;
		}
	}
	S = 1;
	while(S <= y) S *= 2;
}

void update(int y, int x, ll t){
	x += S-1;
	v[y][x] = t;
	while(x > 0){
		x = (x-1)/2;
		v[y][x] = min(v[y][2*x+1],v[y][2*x+2]);
	}
}

ll get(int z, int a, int b, int t, int r, int l){
	if(a >= l || b <= r) return INF;
	if(a <= r && l <= b) return v[z][t];
	return min(get(z,a,b,t*2+1,r,(r+l)/2),get(z,a,b,t*2+2,(r+l)/2,l));
}

int main(){
	while(scanf("%d%d%d", &r, &c, &q), r||c||q){
		for(int i = 0; i < min(r,c); i++){
			while(v[i].size() < max(r,c)*4) v[i].push_back(0);
		}
		init(min(r,c), max(r,c));
		if(r < c){
			ll tmp;
			rep(i,r) rep(j,c){
				scanf("%lld",&tmp);
				update(i,j,tmp);
			}
			rep(i,q){
				int y1, x1, y2, x2;
				ll ans = INF;
				scanf("%d%d%d%d",&y1,&x1,&y2,&x2);
				for(int j = y1; j <= y2; j++){
					ans = min(ans,get(j,x1,x2+1,0,0,S));
				}
				printf("%lld\n",ans);
			}
		} else{
			ll tmp;
			rep(i,r) rep(j,c){
				scanf("%lld",&tmp);
				update(j,i,tmp);
			}
			swap(r,c);
			rep(i,q){
				int y1, x1, y2, x2;
				ll ans = INF;
				scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
				for(int j = y1; j <= y2; j++){
					ans = min(ans,get(j,x1,x2+1,0,0,S));
				}
				printf("%lld\n",ans);
			}
		}
	}
}

Measured memory_bytes: 42724
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n;
    ll mod = 1e9 + 7;
    ll res = 1;

    cin >> n;
    FOR(i, 1, n) {
        res = (i * (res % mod));
    }
    cout << res % mod << endl;
    return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(h, w);
    vvi table(h, vi(w));
    vvi dp(h+1, vi(w+1, 0));

    rep(i, h) {
        string st;
        cin >> st;
        rep(j, st.size()) {
            if (st[j] == '#') table[i][j] = 0;
            else table[i][j] = 1;
        }
    }

    dp[0][0] = 1;

    rep(i, h) {
        rep(j, w) {
            if (table[i][j]) {
                dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;
                dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % MOD;
            }
        }
    }
    /*
    rep(i, h) {
        rep(j, w) cout << dp[i][j] << " ";
        cout << endl;
    }
    */
    std::cout << dp[h-1][w-1] << std::endl;

    return 0;
}


Measured memory_bytes: 16000
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    s = in_s()
    N = len(s)

    cnt_g = 0
    cnt_p = 0
    score = 0

    for i in range(N):

        if s[i] == 'g':
            if cnt_p < cnt_g:
                cnt_p += 1
                score += 1
            else:
                cnt_g += 1
        else:
            if cnt_p < cnt_g:
                cnt_p += 1
            else:
                cnt_g += 1
                score -= 1

    print(score)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;

int main() {
  int N, M;
  cin >> N >> M;
  vector<P> keys(M);
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    int bitSum = 0;
    rep(j, B) {
      int C;
      cin >> C;
      --C;
      bitSum += 1<<C;
    }
    //keys[i].first = A;
    //keys[i].second = bitSum;
    keys[i] = make_pair(A, bitSum);
  }
  vector<int> dp(1<<N, INF); // dp.back()がans
  dp[0] = 0;
  for (int i = 0; i < 1<<N; i++) {
    for (auto p : keys) {
      int newPrice = dp[i] + p.first;
      int newBit = i | p.second;
      dp[newBit] = min(dp[newBit], newPrice);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

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

	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0; i<n; i++)
		cin>>a[i];
	ll sum=0;
	for(ll i=0; i<n-1;i++)
	{
		for(ll j=i+1; j<n; j++)
		{
			sum+= a[i]* a[j];
		}
	}
	cout<<sum;

	return 0;
}

Measured memory_bytes: 256
/* ex2_3
   moka223711 */

#include <stdio.h>

int main(void){
  // N * N はマス目の数を表す
  // マス目のAマスを白く塗り、残りを黒く塗る
  int N, A;
  scanf("%d%d", &N, &A);
  
  // 黒く塗るマスの数 N * N - A を出力
  printf("%d\n", N * N - A);
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int judge(int i,char *s,char *t,int lent,int lens);

int main()
{
    char s[55]={};
    char t[55]={};
    scanf("%s\n%s",s,t);
    int lens=strlen(s);
    int lent=strlen(t);
    for(int i=lens-lent;i>=0;i--)
    {
        if(judge(i,s,t,lent,lens)==1)
        {
            printf("%s",s);
            return 0;
        }
    }
    printf("UNRESTORABLE");
    return 0;
}
int judge(int i,char *s,char *t,int lent,int lens)
{
    REP(j,lent)
    {
        if(*(s+i+j)!='?' && *(s+i+j)!=*(t+j))
        {
            return 0;
        }
    }
    REP(j,lent)
    {
        *(s+i+j)=*(t+j);
    }
    REP(j,lens)if(*(s+j)=='?')*(s+j)='a';
    return 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

int main(){
	ll n, m; cin >> n >> m;
	if (n%2==1){
		FOR(i,1,m){
			cout << i << " " << n-i+1 << endl;
		}
	}
	else{
		FOR(i,1,m){
			if (i<=(n/4)){
				cout << i << " " << n-i+1 << endl;
			}
			else{
				cout << i << " " << n-i << endl;
			}
		}
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1<<29
#define MAX 
using namespace std;

void solve(){
 string s;
 cin>>s;
 int ma=0;
 FOR(i,s.size()){
  if(s[i]!='O') continue;
  int O=i;
  while(O+1<s.size()&&s[O+1]=='O') O++;
  int J=i;
  while(J&&s[J-1]=='J') J--;
  int I=O;
  while(I+1<s.size()&&s[I+1]=='I') I++;
  if(I-O-1>=O-i&&i-1-J>=O-i) ma=max(ma,O-i+1);
  i=I;
 }
 cout<<ma<<endl;
}

int main(){
 solve();
 return 0;
}

Measured memory_bytes: 2048
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}



int main() {

  long n,m;
  cin >> n >> m;
  // n:s
  // m:c

  long ans =0;

  ans = min(n , m/2);


  if (n < m/2){//cが余ってる時
    long remin_m = m - n*2;

    ans += remin_m/4;

  }


  cout << ans <<endl;


}




















Measured memory_bytes: 256
import numpy as np
n, d = map(int, input().split())
x = []
for i in range(n):
	x.append(np.array(list(map(int, input().split()))))

c = 0
for i in range(n-1):
	for j in range(i+1, n):
		if np.linalg.norm(x[i]-x[j]).is_integer():
			c += 1
print(c)

Measured memory_bytes: 19584
def MI(): return map(int, input().split())
from collections import deque
def bfs(field,s):
  q=deque([(0,s)])
  MOVE=[(-1,0),(0,-1),(1,0),(0,1)]
  dist=[[-1]*W for i in range(H)]
  d,i,j=-1,-1,-1  
  while q:
    d,(i,j)=q.popleft()
    if dist[i][j]!=-1:
      continue
    dist[i][j]=d
    for di,dj in MOVE:
      ni=i+di
      nj=j+dj
      if not 0<=ni<H or not 0<=nj<W:
        continue
      if field[ni][nj]=='#':
        continue
      if dist[ni][nj]!=-1:
        continue
      q.append((d+1,(ni,nj)))
  return d,i,j
H,W=MI()
field=[input() for _ in range(H)]
ans=0
for i in range(H):
  for j in range(W):
    if field[i][j]=='.':
      d,i,j=bfs(field,(i,j))
      ans=max(ans,d)
print(ans)


Measured memory_bytes: 9300
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n, vector<int>(0));
    int a, b;
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    rep(i, graph[0].size()) {
        rep(j, graph[graph[0][i]].size()) {
            if (graph[graph[0][i]][j] == n - 1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 14964
object Main extends App {

  import scala.io.StdIn._
  solve
  def solve: Unit = {
    val n = readLine.trim.toInt
    if (n != 0){
      println(
        Array.tabulate(n){_ ⇒
          val Array(x, y, h, w) = readLine.trim.split(' ').map(_.toInt)
          Package(x, y, h, w) match{
            case FeeRank(fee) ⇒ fee
            case _ ⇒ 0
          }
        }.sum
      )
      solve
    }
  }
  object Package {
    def apply(x: Int, y: Int, h: Int, w: Int): Package = Package(x + y + h, w)
  }
  case class Package(size: Int, weight: Int)
  object FeeRank {
    def unapply(arg: Package): Option[Int] = {
      arg match{
        case Package(size, weight) if size <= 60 && weight <= 2 ⇒ Some(600)
        case Package(size, weight) if size <= 80 && weight <= 5 ⇒ Some(800)
        case Package(size, weight) if size <= 100 && weight <= 10 ⇒ Some(1000)
        case Package(size, weight) if size <= 120 && weight <= 15 ⇒ Some(1200)
        case Package(size, weight) if size <= 140 && weight <= 20 ⇒ Some(1400)
        case Package(size, weight) if size <= 160 && weight <= 25 ⇒ Some(1600)
        case _ ⇒ None
      }
    }
  }
  implicit class ScopeFunc[T](val value:T){
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 62276
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	ll f=1;

	REP(i,N){
		f *= ((ll)(i+1)); 
	}
	out(f);
	return 0;
}


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


def solve(W: int, H: int, x: int, y: int):
    ret = W * H / 2
    tmp = 0
    if x * 2 == W and y * 2 == H:
        tmp = 1
    print(ret)
    print(tmp)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(W, H, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
(async () => {
    let input = '';
    for await (const chunk of process.stdin) input += chunk;

    if(input.split('').map(v => +v).reduce((sum, d) => sum + d, 0) % 9 == 0){
        console.log('Yes');
    }else{
        console.log('No');
    }
})();


Measured memory_bytes: 35956
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

ll inq(ll x, ll y, ll mod)
{
    if (!y) re 1 % mod;
    ll l = inq(x, y / 2, mod);
    if (y % 2) re l * l % mod * x % mod;
    re l * l % mod;
}

ll inv(ll x, ll mod)
{
    return inq(x, mod - 2, mod);
}

const int N = 405949; // 405949 is my favorite number, but it's less than 5e5
const int P = 1e9 + 97;
const int Q = 1e6 + 3;
const int INV = inv(Q, P);

int n;
int k;

signed main()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
    cin >> n >> k;
    int a = 0, b = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % k == 0) a++;
        if ((k % 2 == 0) && i % k == k / 2) b++;
    }
    cout << 1ll * a * a * a + 1ll * b * b * b;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string s;
	cin >> s;
	int a = s.length();
	vector<int> v(a, 0);
	int po = 0;
	int wl = 0;
	for (int i = a - 1; i >= 0; i--) {
		if (s[i] == 'W') {
			wl++;
		}
		else {
			v[po] = wl;
			po++;
		}
	}
	long long ans = 0;
	for (int i = 0; i < a; i++) {
		long long k = v[i];
		ans = ans + k;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1412