akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  int SP = 0,SW = 0,SG = 0,SY = 0;
  cin >> N;
  for(int i = 0;i<N;i++){
    cin >> S;
//    cout << i << ":" << S << endl;
   if(S == "P"){
     SP = 1;
   }else if(S == "W"){
      SW = 1;
   }else if(S == "G"){
      SG = 1; 
   }else if(S == "Y"){
      SY = 1; 
   }
  }
//  cout << SP << SW << SG << SY << endl;
  if(SP == 1 && SW == 1 && SG == 1){
    if(SY == 1){
     cout << "Four" << endl; 
    }else{
     cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
    string S;
    cin >> S;
    char c;
    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
        cin >> c;
        if (S[i] == c) cnt++;
    }
    cout << cnt << endl;
}

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

vector<int> Z_Algorithm(string &s) {
    vector<int> ret(s.size());
    for (int i = 1, j = 0; i < s.size(); i++) {
        if (i + ret[i-j] < j + ret[j]) {
            ret[i] = ret[i-j];
        } else {
            int k = max(0, j + ret[j] - i);
            while (i+k < s.size() && s[k] == s[i+k]) k++;   
            ret[i] = k; j = i;
        }
    }
    ret[0] = s.size();
    return ret;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        string t = s.substr(i);
        auto v = Z_Algorithm(t);
        for (int i = 0; i < v.size(); i++) {
            ans = max(ans, min(v[i], i));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, a, n) for (int i = a; i < n; ++i)
 
void solve() {
	string s; cin >> s;
	ll sum = 0;
	for (char i : s) {
		sum += (int)i - 48;
	}
	cout << (sum % 9 == 0 ? "Yes" : "No");
}
 
int main() {
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}
 
	return 0;
}

Measured memory_bytes: 3724
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int M = 1e6 + 5;
const int N = 2e5 + 5;

int i,j,n,a[N],yes[M],ans=0;

void solve()
{
    cin>>n;
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
        yes[a[i]]++;
    }
    for(i=1;i<=n;++i)
    {
        int ok=0;
        yes[a[i]]--;
        for(j=1;j*j<=a[i];++j)
        {
            if(a[i]%j==0)
            {
                if(yes[j])
                    ok=1;
                if(j!=a[i]/j && yes[a[i]/j])
                    ok=1;
            }
        }
        ans+=ok^1;
        yes[a[i]]++;
    }
    cout<<ans;
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 12988
N = int(input())
H = list(int(x) for x in input().split())

f_inf = float('infinity')
dp = [f_inf] * N
dp[0] = 0

for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1] + abs(H[i] - H[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2] + abs(H[i] - H[i-2]))

print(dp[N-1])


Measured memory_bytes: 13980
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r = sc.nextInt();

    if (n < 10) {
      System.out.println(r+100*(10-n));
    } else {
      System.out.println(r);
    }
  }

}


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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n, k, a[2010], b[2010];
    V g[2010];

    cin >> n >> k;
    REP(i, n - 1)
    {
        cin >> a[i] >> b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    int res = INT_MAX;

    for (int i = 1; i <= n; i++)
    {
        for (int l : g[i])
        {
            int cnt = 1 + k % 2;

            queue<int> q;
            q.push(i);
            if (k % 2)
                q.push(l);

            int dis[2100];
            fill(dis, dis + n + 1, -1);

            dis[i] = 0;
            if (k % 2)
                dis[l] = 0;

            while (q.size())
            {
                int p = q.front();
                q.pop();
                for (int j : g[p])
                {
                    if (dis[p] + 1 <= k / 2 && dis[j] == -1)
                    {
                        cnt++;
                        dis[j] = dis[p] + 1;

                        if (dis[p] + 1 < k / 2)
                            q.push(j);
                    }
                }
            }

            res = min(n - cnt, res);

            if (!(k % 2))
                break;
        }
    }

    /*
    if (k % 2 == 1 && res > 0)
        res--;
        */

    cout << res << endl;

    return 0;
}

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

int main()
{
  i64 n, m;
  cin >> n >> m;
  vector<i64> p(m);
  vector<string> s(m);
  for (i64 i = 0; i < m; i++)
    cin >> p[i] >> s[i];
  vector<i64> cnt(n);
  vector<bool> ac(n, false);
  for (i64 i = 0; i < m; i++)
    if (ac[p[i] - 1] == false)
    {
      if (s[i] == "AC")
        ac[p[i] - 1] = true;
      else
        cnt[p[i] - 1]++;
    }
  i64 ans[2] = {};
  for (i64 i = 0; i < n; i++)
    if (ac[i])
    {
      ans[0]++;
      ans[1] += cnt[i];
    }
  cout << ans[0] << " " << ans[1] << endl;
  return 0;
}


Measured memory_bytes: 7296
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	fast();
	ll x,ans=0;
	cin>>x;
	ll t=x/500;
	ans+=(1000LL*t);
	x=x%500;
	t=x/5;
	ans+=(5LL*t);
	cout<<ans;
}

Measured memory_bytes: 384
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ll X, Y; cin >> X >> Y;
	if (abs(X - Y) <= 1) {
		cout << "Brown" << endl;
	}
	else
		cout << "Alice" << endl;
	return 0;
}

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

int main() {
    int x,y;
    cin>>x>>y;
    vector<int> z={1,3,1,2,1,2,1,1,2,1,2,1};
    if (z[x-1]==z[y-1]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
x,n = [int(i) for i in input().split()]
a = []
if n != 0:
    a = [int(i) for i in input().split()]
d = {}
dis = 0
for i in a:
    d[i] = 1
for i in range(102):
    if i in d:
        continue
    if abs(x - dis) > abs(x-i):
        dis = i
print(dis)


Measured memory_bytes: 9188
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] w = new int[n];
        int x = 10000;
        for(int i = 0; i < n; i++){
            w[i] = Integer.parseInt(sc.next());
            if(w[i] < x) x = w[i];
        }
        
        int[] w2 = w.clone();
        Arrays.sort(w2);
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++){
            map.put(w2[i], i);
        }
        
        int ans = 0;
        boolean[] done = new boolean[n];
        for(int i = 0; i < n; i++){
            if(done[i]) continue;
            List<Integer> list = new ArrayList<>();
            list.add(i);
            done[i] = true;
            int j = map.get(w[i]);
            while(j != i){
                list.add(j);
                done[j] = true;
                j = map.get(w[j]);
            }
            int sum = 0;
            int min = 10000;
            for (Integer k : list) {
                sum += w[k];
                if(w[k] < min) min = w[k];
            }
            ans += Math.min(sum + (list.size()-2) * min, sum + min + (list.size()+1) * x);
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 29612
#include <bits/stdc++.h>
#define ll long long
#define sz size
#define pb push_back
#define mper make_pair
#define all(x) x.begin(), x.end()
#define fe first
#define se second
#define erba continue
using namespace std;

const ll MAXN = 1e5 + 100;
ll n, a[MAXN];

map <ll, int> mp;
vector <ll> g;

int main() {

cin >> n;

for(int i = 1; i <= n; ++i) {

    cin >> a[i];
    mp[a[i]]++;
    if(mp[a[i]] == 1) {g.pb(a[i]);}

}

sort(all(g));

if(g.sz() == 1 && g[0] == 0) {cout << "Yes";return 0;}

if(n % 3 != 0) {cout << "No";return 0;}

if(g.sz() == 2 && g[0] == 0 && mp[g[0]] == n / 3) {cout << "Yes";return 0;}

if(g.sz() != 3) {cout << "No"; return 0;}


if(mp[g[0]] == mp[g[1]] && mp[g[0]] == mp[g[2]] && (ll)(g[0] ^ g[2] ^ g[1]) == 0) {cout << "Yes";}
else {cout << "No";}


return 0;
}





Measured memory_bytes: 6260
import java.io.*;
import java.util.*;


public class Main {
    static final int UNCALC = -1;
    static final int INF = (int) 1e9;
    static ArrayList<Integer> adjList[];
    static int memo[];

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
        int m = sc.nextInt();
        int[] p = new int[n];
        while (m-- > 0) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            adjList[x].add(y);
            p[y]++;
        }
        Queue<Integer> roots = new LinkedList<>();
        for (int i = 0; i < n; i++)
            if (p[i] == 0) roots.add(i);
        int max = 0;
        memo = new int[n];
        Arrays.fill(memo, UNCALC);
        while (!roots.isEmpty())
            max = Math.max(max, dp(roots.remove()));
        out.println(max);
        out.flush();
        out.close();

    }

    static int dp(int node) {
        if (memo[node] != UNCALC) return memo[node];
        int max = 0;
        for (int v : adjList[node])
            max = Math.max(max, 1 + dp(v));
        return memo[node] = max;
    }


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

    }
}

Measured memory_bytes: 68148
#include <stdio.h>
#define M 1000000007
#define N 200016

unsigned long ulget();
inline unsigned long ulget()
{
    register unsigned long t = 0;
    register char c;
    while((c = getchar() - '0') >= 0)
    {
        t = t * 10 + c;
    }
    return t;
}

unsigned int colorlastdp[N];
int main()
{
    unsigned int dp[N];
    unsigned int n = ulget();
    dp[0] = 0; dp[1] = 1;
    unsigned int color, lastcolor;
    lastcolor = ulget();
    colorlastdp[lastcolor] = 1;
    for (unsigned int i = 2; i <= n; i++)
    {
        color = ulget();
        dp[i] = dp[i-1];
        if (color != lastcolor)
            dp[i] = (dp[i] + colorlastdp[color]) % M;
        colorlastdp[color] = dp[i];
        lastcolor = color;
        //printf("%d %d %d\n", i, color, dp[i]);
    }
    printf("%u", dp[n]);
}


Measured memory_bytes: 3168
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int h, w;
	cin >> h >> w;
	long long int ans = 9999999;

	for (long long int i = 1; i < h; i++) {
		if (i < h - 1) {
			long long int a = i*w;
			long long int b = (h - i) / 2 * w;
			long long int c = (h - (h - i) / 2 - i)*w;

			long long int x = min(a, min(b, c));
			long long int y = max(a, max(b, c));
			ans = min(ans, y - x);
		}
		long long int a = i*w;
		long long int b = (h - i)  *( w/2);
		long long int c = (h - i)*(w-(w/2));
	//	cout << h-i<<w/2<<""<<(h-i)*(w/2)<< endl;
		long long int x = min(a, min(b, c));
		long long int y = max(a, max(b, c));
		ans = min(ans, y - x);
	//	cout << b<<y<<endl;

	}

	for(long long int i=1;i<w;i++) {
		if (i < w - 1) {
			long long int a = i*h;
			long long int b = (w - i) / 2 * h;
			long long int c = (w - (w - i) / 2 - i)*h;

			long long int x = min(a, min(b, c));
			long long int y = max(a, max(b, c));
			ans = min(ans, y - x);
		}
		long long int a = i*h;
		long long int b = (w - i)  *(h / 2);
		long long int c = (w - i)*(h - (h / 2));
		//	cout << h-i<<w/2<<""<<(h-i)*(w/2)<< endl;
		long long int x = min(a, min(b, c));
		long long int y = max(a, max(b, c));
		ans = min(ans, y - x);
		//	cout << b<<y<<endl;

	}

	cout << ans << endl;

		return 0;

}




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
    cin>>n;
    int a[200020];
    ll c[200020]={};
    ll d[200020];
    for(int i=0; i<n; i++){
        cin>>a[i];
        c[a[i]]++;
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        d[i]=c[i]*(c[i]-1)/2;
        ans+=d[i];
    }
    for(int i=0; i<n; i++){
        cout<<ans-d[a[i]]+(c[a[i]]-1)*(c[a[i]]-2)/2<<endl;
    }
	return 0;
}


Measured memory_bytes: 6528
using System;

class Program
{
    public static void Main()
    {
        int tempSec = int.Parse(Console.ReadLine());
        int tempMin = tempSec / 60;
        //Console.WriteLine(tempMin);

        int h = tempMin / 60;
        //Console.WriteLine(h);

        int actualMin = tempMin % 60;
        //Console.WriteLine(actualMin);

        int actualSec = tempSec % 60;
        //Console.WriteLine(actualSec);

        Console.WriteLine(h + ":" + actualMin + ":" + actualSec);

    }
}


Measured memory_bytes: 17828
n,ma,mb=map(int,input().split())
dp=[[0]*401 for _ in range(401)]
for _ in range(n):
  a,b,c=map(int,input().split())
  for i in range(400,-1,-1):
    for j in range(400,-1,-1):
      if i-a<0 or j-b<0:
        continue
      else:
        if dp[i-a][j-b]==0:
          continue
        else:
          if dp[i][j]==0:
            dp[i][j]=dp[i-a][j-b]+c
          else:
            dp[i][j]=min(dp[i][j],dp[i-a][j-b]+c)
  if dp[a][b]==0:
    dp[a][b]=c
  else:
    dp[a][b]=min(dp[a][b],c)
ans=10**10
for i in range(401):
  if i*ma>400 or i*mb>400:
    break
  if dp[i*ma][i*mb]==0:
    continue
  else:
    ans=min(ans,dp[i*ma][i*mb])
if ans==10**10:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 45036
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
   cin>>t;
   map<string,ll>lol;
    for(int ok=1;ok<=t;ok++)
    {
        string s;
     cin>>s;
     lol[s]++;
    }
    cout<<lol.size();
    return 0;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;

int main() {
	
	uint N;
	cin >> N;
	
	vector<uint> a(N);
	for(uint i=0; i<N; i++) {
		cin >> a[i];	
	}
	
	vector<uint> b(N);
	for(uint i=0; i<N; i++) {
		cin >> b[i];
	}
	
	uint tmpa = a[0];
	uint tmpb = b[0];
	
	vector<uint> x(N);
	
	for(uint i=0; i<N-1; i++) {
		x[i] = a[i] ^ tmpb;
		a[i] = a[i] ^ a[i+1];
		b[i] = b[i] ^ b[i+1];
	}
	
	x[N-1] = a[N-1] ^ tmpb;
	a[N-1] = a[N-1] ^ tmpa;
	b[N-1] = b[N-1] ^ tmpb;
	
	//for(uint i=0; i<N; i++) cout << a[i] << " "; cout << endl;
	//for(uint i=0; i<N; i++) cout << b[i] << " "; cout << endl;
	
	vector<int> T(N, 0);
	T[0] = -1;
	T[1] = 0;
	uint j = 0;
	
	for(uint i=2; i<N; i++) {
		if(b[i-1] == b[j]) {
			T[i] = j + 1;
			j++;
		} else if(j > 0) {
			j = T[j];
		}
	}
	
	//for(uint i=0; i<N; i++) cout << T[i] << endl;
	uint i = 0;
	uint k = 0;
	
	while(k < N) {
		if(b[i] == a[(k+i)%N]) { 
			if(i < N - 1) {
				i++;
			} else {
				cout << k << " " << x[k] << endl;
				k += i - T[i];
				i = max(0, T[i]);
			}
		} else {
			k += i - T[i];
			i = max(0, T[i]);
		}
	}
	
	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include<set>
using namespace std;
int main(void){
    // Your code here!
#define ar array

int ar[3][3];
set<int> s;
int count=0,d1=0, d2=0;
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++){
            cin>>ar[i][j];
        }
        
 int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        s.insert(a);
    }
    
    for(int i=0;i<3;i++){
        count=0;
        for(int j=0;j<3;j++){
            if(s.find(ar[i][j])!=s.end()){
                count++;
            }
                
        }
        if(count==3)
            {
                cout<<"Yes";
                return 0;
            }
    }
    
    
 for(int i=0;i<3;i++){
     count=0;
        for(int j=0;j<3;j++){
            if(s.find(ar[j][i])!=s.end()){
                count++;
            }
                
        }
        if(count==3)
            {
                cout<<"Yes";
                return 0;
            }
    }    

count=0;
for(int i=0,j=0;i<3&&j<3;i++,j++)
         if(s.find(ar[j][i])!=s.end()){
                count++;
            }
            
 if(count==3)
{
    cout<<"Yes";
    return 0;
}

count=0;
for(int i=0,j=2;i<3&&j>=0;i++,j--)
         if(s.find(ar[i][j])!=s.end()){
                count++;
            }
            
 if(count==3)
{
    cout<<"Yes";
    return 0;
}

cout<<"No";
    
}


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

int abs(int x) { return (x < 0)?-x:x; }

int main() {
    int a,b,c,ret;
    std::cin >> a >> b >> c;
    std::cout << std::min({abs(b - a) + abs(c - b), abs(c - a) + abs(b - c), abs(a - b) + abs(c - a)}) << std::endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}
int main(){
  ll n,m; cin >> n >> m; ll nowsum = 0; ll cnt = 0;
  map<ll,ll> summod;
  
  summod[0]++;
 
  rep(i,n){
    ll x; cin >> x;
    nowsum += x;
    nowsum %= m;
    summod[nowsum]++;
  }
  
  for(auto p : summod){
    ll x = p.second;
    cnt += x*(x-1)/2;
  }
  
  cout << cnt << endl;
  
  
}

Measured memory_bytes: 4224
n,m = map(int, input().split())

A = set()
for _ in range(m):
  A.add(int(input())) 

dp = [1]+[0]*(n)

for i in range(1, n+1):
  
  if i==1:
    dp[i] = dp[i-1]
  elif i>=2:
    dp[i] = (dp[i-1]+dp[i-2])%1000000007
    
  if i in A:
    dp[i] = 0
  
print(dp.pop())

Measured memory_bytes: 11884
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()
	ps := getIntSlice(n)

	ans := 0
	for i := 1; i < n-1; i++ {
		if (ps[i] > ps[i-1] && ps[i] < ps[i+1]) || (ps[i] > ps[i+1] && ps[i] < ps[i-1]) {
			ans++
		}
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MOD = 1e9 + 7, MAX_N = 1e3 + 10;

int notP[MAX_N];
vector<int> Ps;
int main() {
	int N; cin >> N;
	ll ans = 1;
	notP[0] = notP[1] = true;
	for(int i=2; i<=N; i++) if(not notP[i]) {
		Ps.emplace_back(i);
		for(int j=i+i; j<=N; j+=i) notP[j] = true;
	}
	for(int p: Ps) {
		int now = 0;
		for(int d=p; d<=N; d*=p) {
			now += N / d;
		}
		ans *= (now + 1);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int* f = new int[n + 1];
	for (int i = 1;i <= n;i++) {
		f[i] = 0;
	}
	for (int i = 1;i <= sqrt(n);i++) {
		for (int j = 1;j <= sqrt(n);j++) {
			for (int k = 1;k <= sqrt(n);k++) {
				int ans = i * i + j * j + k * k + i * j + i * k + j * k;
				if (ans <= n)f[ans]++;
			} 
		}
	}
	for (int i = 1;i <= n;i++) {
		cout << f[i] << endl;
	}
}

Measured memory_bytes: 3112
def draw_chessboard(h, w)
  h.times do |i|
    w.times do |j|
      if (i + j).even?
        print "#"
      else
        print "."
      end
    end
    print "\n"
  end
  print "\n"
end

loop do
  h, w = gets.chomp.split(" ").map(&:to_i)
  break if h == 0 && w == 0
  draw_chessboard(h,w)
end

Measured memory_bytes: 8860
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int main()
{
	int n,maxn=0;
	string a;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		mp[a]++;
	}
	map<string,int>::iterator iter;
    iter = mp.begin();
    for(iter=mp.begin();iter!=mp.end();iter++)
		maxn=max(maxn,iter->second);
	for(iter=mp.begin();iter!=mp.end();iter++)
		if(iter->second==maxn)
			cout<<iter->first<<endl;
}

Measured memory_bytes: 25216
s = input()

res=True
for i in range(len(s)//2):
  if s[i] != s[len(s)-i-1]:
    res = False

for i in range(len(s)//2):
  if s[i] != s[(len(s)-1)//2-1-i]:
    res = False
for i in range(len(s)//2):
  if s[(len(s)+1)//2+i] != s[len(s)-i-1]:
    res = False
if res:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
str=input()
k=int(input())
lst=list(str)
flag=True
pos=0
for x in lst:
    if x!="1":
        flag=False
        break
    pos+=1


if flag:
    print(1)
elif k<=pos:
    print(1)
else:
    for x in lst:
        if x!='1':
            print(x)
            break


Measured memory_bytes: 2940
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
  string N;    
  cin >> N;
  
  
  int sum=0;
  for(int i=0;i<N.length();i++)
  {
//    cout << atoi(N[i]) << " ";
    
    int m = (int)N[i] -48;

//    cout << m  << " ";

    sum += m;
    sum = sum%9;
  }

  if(sum%9==0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  

  return 0 ;
  
}
  

Measured memory_bytes: 3708
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
template<typename T>
bool all_same(vector<T> v1,vector<T> v2)
{
    sort(ALL(v1));
    sort(ALL(v2),greater<T>());
    return v1 == v2;
}
   
// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;

int main(){
    ll a,b,n,m,l,w,sum=0,sum2=0,ans=0;
    string s,t;
    bool f=false;
    cin >> s >> t;
    map<char,char> ma;
    map<char,char> mb;

    rep(i,s.size()){  
        if(ma.find(s[i]) != ma.end()){
            if(t[i] != ma.find(s[i])->second){
                cout << "No" << endl;
                return 0;
            }
            else{
                continue;
            }
        }
        else{
            ma.insert(make_pair(s[i],t[i]));
        }
    }

    rep(i,t.size()){
        if(mb.find(t[i]) != mb.end()){
            if(s[i] != mb.find(t[i])->second){
                cout << "No" << endl;
                return 0;
            }
            else{
                continue;
            }
        }
        else{
            mb.insert(make_pair(t[i],s[i]));
        }
    }
    cout << "Yes" << endl;
   
    return 0;
}

Measured memory_bytes: 776
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define int ll

signed main(){
    vector<ll> dp[11];
    dp[0].pb(0);
    
    string s;
    cin>>s;
    
    rep(i,s.size()){
        for(int j=i+1;j<=s.size();j++){
            int num = stoll(s.substr(i,j-i));
            for(auto &e:dp[i]){
                dp[j].pb(e+num);
            }
        }
    }
    int ans = 0;
    for(auto &e:dp[s.size()])ans+=e;
    
    cout<<ans<<endl;
}

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

long long max = 1e18;

int main(){
    int N;
    std::cin >> N;
    std::vector< long long > A(N);
    bool zero = false;
    for(int i=0; i<N; i++){
        std::cin >> A[i];
        if(A[i] == 0){
            zero = true;
        }
    }
    
    if(zero){
        std::cout << 0 << std::endl;
        return 0;
    }
    long long ans = 1;
    
    for(int i=0; i<N; i++){
        if(ans > max / A[i]){
            std::cout << -1 << std::endl;
            return 0;
        }
        ans *= A[i];
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}



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

#define ll long long
#define ar array
#define vi vector<int>
#define INF 1000000000

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	bool hasSeven = false;
	for(int i=0; i < 3; i++){
		int d = n % 10;
		n /= 10;
		if(d == 7){
			hasSeven = true;
			break;
		}
	}	
	if(hasSeven) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>

using namespace std;

#define int long long
#define ll long long
#define double long double
#define pii pair<int, int>
#define vec vector
#define u_map unordered_map
#define u_set unordered_set
#define str string
#define all(el) el.begin(), el.end()
#define allr(el) el.rbegin(), el.rend()
#define sz(el) (int)el.size()
#define f first
#define s second
#define pb push_back
#define in insert
#define mp make_pair
#define endl "\n"
#define forn(i, n) for (int i = 0; i < n; ++i)

inline int maxi(int &a, int b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(int &a, int b) { if (b < a) { a = b; return 1; } return 0; }

inline int maxi(double &a, double b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(double &a, double b) { if (b < a) { a = b; return 1; } return 0; }

int bin_pow(int x, int p) {
    if (p < 0) {
        return 0;
    }
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int ans = bin_pow(x, p / 2);
        return ans * ans;
    }
    return x * bin_pow(x, p - 1);
}

int gcd(int a, int b) {
    if (!b) {
        return a;
    }
    return gcd(b, a % b);
}

signed main() {

    int n;
    cin >> n;
    vec<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    u_map<int, int> hv;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += hv[a[i] - i];

        hv[-a[i] - i]++;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 20040
#include <bits/stdc++.h>
using namespace std;
int g[17][17];
long long dp[1 << 17];
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      cin >> g[i][j];
  for(int i = 0; i < n; i++)
    for(int j = i + 1; j < n; j++)
      for(int mask = 1; mask < (1 << n); mask++)
        if((mask & (1 << i)) && (mask & (1 << j)))
          dp[mask] += g[i][j];
  for(int mask = 0; mask < (1 << n); mask++)
    for(int i = mask; i > 0; --i &= mask)
      dp[mask] = max(dp[mask], dp[i] + dp[mask - i]);
  cout << dp[(1 << n) - 1] << '\n';
  return 0;
}


Measured memory_bytes: 768
h_1,m_1,h_2,m_2,k=map(int,input().split())
if h_1>h_2 and m_1>m_2:
  a=((h_2+12)-h_1)*60
  a=a-60
  b=60-(m_1-m_2)
elif h_1<h_2 and m_1>m_2:
  a=(h_2-h_1)*60
  a=a-60
  b=60-(m_1-m_2)

elif h_1>h_2 and m_1<m_2:
  a=((h_2+12)-h_1)*60
  b=m_2-m_1
else :
  a=(h_2-h_1)*60
  b=m_2-m_1
culc=b+a
result=culc-k

print(result)

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		cout << (x = r*x-d) << ende;
	}
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll a,b;
    cin >> a >> b;

    cout << max(max(a+a-1,a+b),b+b-1) << endl;

    return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
if a>=b:
    str=""
    for i in range(a):
        print(b,end="")
#        str=str+str(b)
    print()
else:
    str=""
    for i in range(b):
        print(a,end="")
#        str=str+str(b)
    print()

Measured memory_bytes: 2940
N,  M = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]
ans = []

for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            total = []
            for l in range(N):
                total.append(lst[l][0]*i + lst[l][1]*j + lst[l][2]*k)
            total.sort(reverse=True)
            ans.append(sum(total[:M]))

print(max(ans))

Measured memory_bytes: 3316
N = int(input())
name = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
  S = input()
  if S[0] in 'MARCH':
    name[S[0]] += 1
cnt = 0
for k1, v1 in name.items():
  for k2, v2 in name.items():
    for k3, v3 in name.items():
      if k1 != k2 and k2 != k3 and k3 != k1:
        cnt += v1 * v2 * v3
print(cnt // 6)

Measured memory_bytes: 3064
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		byte[] cc = sc.next().getBytes();
		int n = cc.length;
		int ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			int d = cc[i] - '0';
			if (d != 5) {
				if (d > 5) {
					ans += 10 - d;
					if (i > 0)
						cc[i - 1]++;
					else
						ans++;
				} else
					ans += d;
			} else {
				if (i > 0 && cc[i - 1] >= '5') {
					ans += 10 - d;
					cc[i - 1]++;
				} else
					ans += d;
			}
		}
		println(ans);
	}
}


Measured memory_bytes: 46664
/*  -*- coding: utf-8 -*-
 *
 * 3051.cc: 
 */

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

/* constant */

const int N = 3;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int as[N];
  for (int i = 0; i < N; i++) scanf("%d", as + i);

  int maxa = as[0], maxi = 0;
  for (int i = 1; i < N; i++)
    if (maxa < as[i]) maxa = as[i], maxi = i;

  printf("%c\n", 'A' + maxi);
  return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <algorithm>
#include <vector>

std::vector <std::vector<int>> dp(3005, std::vector<int>(3005));

int main()
{
    std::string s, t;

    std:: cin >> s >> t;
    int N = s.size();
    int M = t.size();

    for (int i = 0; i <= N; i++) 
    {
        for (int j = 0; j <= M; j++) 
        {
            if(i == 0 || j == 0)
            {
              dp[i][j] = 0;
              continue;
            }
            if(s[i - 1] == t[j - 1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else 
            {
                dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    int i = N;
    int j = M;

    std::string ans = "";
    while(i && j)
    {
        if(s[i-1] == t[j-1])
        {
            ans+=s[i-1];
            i--; j--;
        }
        else
        {
            if(dp[i-1][j] > dp[i][j-1])
            {
                i--;
            }
            else 
            {
                j--;
            }
        }
    }
    
    reverse(ans.begin(), ans.end());
    std::cout << ans;
  	return 0;
}

Measured memory_bytes: 35712
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;

int h, w;
char s[50][51];
int cost[50][50];
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}


void solve(int x, int y)
{
	int i, j, k;
	int current;

	current = cost[y][x];

	if (current < 0) {
		return;
	}

	for (k = 0; k<4; k++) {
		i = y + diff[k][1];
		j = x + diff[k][0];
		//bounds
		if (i < 0 || j < 0 || i >= h| j >= w) {
			continue;
		}
		//wall
		if (s[i][j] == '#') {
			continue;
		}
		//update
		if (cost[i][j] < 0 || current + 1 < cost[i][j]) {
			cost[i][j] = current + 1;
			solve(j, i);
		}
	}
}

int main() {
	scanf("%d %d", &h, &w);
	int cnt = 0;
	memset(cost, -1, sizeof(cost));
	REP(i, h) {
		REP(j, w) {
			scanf(" %c", &s[i][j]);
			if (s[i][j] == '.')cnt++;
		}
	}
	cost[0][0] = 0;
	solve(0, 0);

	int i, j;
	if (cost[h - 1][w - 1] == -1) {
		PRINTD(-1);
		return 0;
	}
	PRINTD(cnt-(cost[h - 1][w - 1]+1));
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        int N = readInt();
        int M = readInt();

        HashSet<Integer>[] adj = new HashSet[N + 1];
        for (int i = 1; i <= N; i++) {
            adj[i] = new HashSet<>();
        }
        for (int i = 0; i < M; i++) {
            int a = readInt();
            int b = readInt();
            adj[a].add(b);
            adj[b].add(a);
        }

        int res = -1;
        boolean[] visited = new boolean[N+1];
        for (int i = 1; i <= N; i++) {
            if (!visited[i]) {
                Stack<Integer> todo = new Stack<>();
                todo.add(i);
                visited[i] = true;
                int count = 1;
                while(!todo.isEmpty())
                {
                    int cur = todo.pop();
                    for(int n : adj[cur]) {
                        if (!visited[n])
                        {
                            visited[n] = true;
                            count++;
                            todo.push(n);
                        }
                    }
                }
                res = Math.max(res, count);
            }
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 105132
#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define n 300000
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
struct edge{
	int to, weight;
};
void solve();
int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}
vector<edge> V[n + 50];
int a, b, c, d, e, f;
int arr[n + 50], arr1[n + 50], arr2[n + 50];
string str, str1, str2;

void solve()
{
	string str;
	cin >> str;
	int ans;
	if(str == "MON") 		ans = 6;
	else if(str == "TUE")   ans = 5;
	else if(str == "WED") 	ans = 4;
	else if(str == "THU")	ans = 3;
	else if(str == "FRI")	ans = 2;
	else if(str == "SAT")	ans = 1;
	else					ans = 7;
	cout << ans << '\n';
}

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

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

  string s; cin >> s;
  vector<int> al(26, 0);
  for (int i = 0; i < s.size(); i++) {
    al[s[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (al[i] == 0) {
      char c = 'a' + i;
      cout << c << '\n';
      return 0;
    }
  }
  cout << "None" << '\n';
  return 0;
}

Measured memory_bytes: 512
from itertools import *
from collections import *
from bisect import *
s=list(input())
t=input()
sets=set(s)
"""
a=len(s)*len(t)
maxcount=len(s)
for i in range(100):
    if maxcount<a:
        maxcount**=10
    else:
        break
"""

for T in t:
    if not T in sets:
        print(-1)
        exit()
N=len(s)
dic={}
for i in range(N):
    if not s[i] in dic:
        dic.update({s[i]:[i]})
    else:
        dic[s[i]].append(i)

count=0
prei=0
for i in range(len(t)):
    idx=bisect_left(dic[t[i]],prei)
    if idx<len(dic[t[i]]):
        prei=dic[t[i]][idx]+1
    else:
        prei=dic[t[i]][0]+1
        count+=N
    if i==len(t)-1:
        count+=prei



if count<=len(s)*(10**100):
    print(count)
else:
    print(-1)


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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        mp[a]++;
    }
    if((int)mp.size() > 2)cout << "No";
    else{
        vector<pair<int, int>> v;
        for(auto e: mp)v.push_back(e);
        if((int)v.size() == 1){
            bool flag = false;
            for(int m=v[0].first;m<=v[0].first+1;++m){
                int a = max(0, 2-(n-2*(m-1)));
                int b = (n-(m-1) > 1 ? m-1 : m);
                if(mp[m-1] >= a && mp[m-1] <= b){
                    flag = true;
                    break;
                }
            }
            if(flag)cout << "Yes";
            else cout << "No";
        }else{
            int m = v[1].first;
            int a = max(0, 2-(n-2*(m-1)));
            int b = (n-(m-1) > 1 ? m-1 : m);
            if(mp[m-1] < a || mp[m-1] > b)cout << "No";
            else cout << "Yes";
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 4992
//

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define MAX -210000000
#define MIN 210000000

int main(){
	
	int a,b,c[4],d[4],e,f;
	
	scanf("%d %d",&a,&b);
	
	while(a!=0 && b!=0){
		for(int i=1;i<5;i++) scanf("%d %d",&c[i],&d[i]);
		
		e=a+b;
		f=0;
		
		for(int i=1;i<5;i++){
			if(e<c[i]+d[i]){
				e=c[i]+d[i];
				f=i;
			}
		}
		
		if(f==0){
			printf("A %d\n",e);
		}else if(f==1){
			printf("B %d\n",e);
		}else if(f==2){
			printf("C %d\n",e);
		}else if(f==3){
			printf("D %d\n",e);
		}else if(f==4){
			printf("E %d\n",e);
		}
		scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 1188