akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <bitset>

using std::ios_base;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::fixed;

using std::vector;
using std::string;
using std::stack;
using std::queue;
using std::deque;
using std::map;
using std::set;
using std::unordered_map;
using std::unordered_set;
using std::bitset;

using std::tuple;
using std::make_tuple;
using std::pair;
using std::make_pair;

using std::sort;
using std::reverse;
using std::nth_element;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

const int MAXN = 300005;
const int INF = 1e9;
const int MOD = 1e9+7;
const int64_t L_INF = 4e18;

int n, m;
vector<int> g[MAXN];
int p[MAXN];
int indeg[MAXN];

void dfs(int v) {
    for (int u : g[v]) {
        indeg[u]--;
    }
    for (int u : g[v]) {
        if (indeg[u] == 0 && p[u] == -1) {
            p[u] = v;
            dfs(u);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    cin >> n >> m;
    for (int i = 0; i < n + m - 1; i++) {
        int v, u;
        cin >> v >> u;
        v--, u--;
        g[v].pb(u);
        indeg[u]++;
    }

    int root = -1;
    for (int i = 0; i < n; i++) {
        if (indeg[i] == 0) {
            root = i;
            break;
        }
    }

    memset(p, -1, sizeof p);
    dfs(root);

    for (int i = 0; i < n; i++) {
        cout << p[i] + 1 << '\n';
    }

    #ifdef LOCAL
        cerr << "\n== " << 1.0 * clock() / CLOCKS_PER_SEC << " sec.\n";
    #endif
    return 0;
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n, m;
    cin >> n >> m;
    vector <int> qw (101);
    for (int i=0; i<m; ++i)
    {
        int f;
        cin >> f;
        qw[f]=1;
    }
    if (qw[n]==0)
        cout << n << endl;
    else
    {
        int r=n-1;
        while (r!=0 && qw[r]!=0)
            r-=1;
        int rr=n+1;
        while (rr!=101 && qw[rr]!=0)
            rr+=1;
        if (rr-n>=n-r)
            cout << r << endl;
        else
            cout << rr << endl;
    }
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define ld long double
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;
typedef vector<double> vd;


const int mod = 100000007;
const int inf = 100000005;
const int N = 200005, M = N;
int i,j,n,m;

ll cnt , idx;
vi temp;


void solve() {
  ll n,k;
  cin>>n>>k;

  vi vec(n);
  ld ans = 0.0 , s = 0.0;
  fo(i,0,n) cin>>vec[i];

  fo(i,0,k) {
    s+= ((vec[i]*(vec[i]+1)/2) / (ld)(vec[i]));
  }
  ans = max(ans , s);
  fo(i,k,n) {
    s-=((vec[i -k]*(vec[i - k]+1)/2) / (ld)(vec[i - k]));
    s+=((vec[i]*(vec[i]+1)/2) / (ld)(vec[i]));
    ans = max(ans , s);
  }
  cout<<fixed<<setprecision(15)<<ans<<"\n";
}

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

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}




Measured memory_bytes: 3924
//
// tested with : g++ (GCC) 8.3.0
//

#include <iostream>
#include <string>
using namespace std;

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

    bool result = false;
    for (int i = 0; i <= 25; i++) { //0からAまでが大切(通りでは)
        for (int j = 0; j <= 15; j++) {
            if (n == (4 * i) + (7 * j)) {
                result = true;
            }
        }
    }
    if (result == true) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Daice{
	int mas[];
	Daice(int[] mas){
		this.mas = mas;
	}

	void north() {
		int temp = mas[4];
		mas[4] = mas[0];
		mas[0] = mas[1];
		mas[1] = mas[5];
		mas[5] = temp;
	}

	void south() {
		int temp = mas[0];
		mas[0] = mas[4];
		mas[4] = mas[5];
		mas[5] = mas[1];
		mas[1] = temp;
	}

	void east() {
		int temp = mas[0];
		mas[0] = mas[3];
		mas[3] = mas[5];
		mas[5] = mas[2];
		mas[2] = temp;
	}

	void west() {
		int temp = mas[0];
		mas[0] = mas[2];
		mas[2] = mas[5];
		mas[5] = mas[3];
		mas[3] = temp;
	}

	int umen(int usam, int msam) {
		int u = 0;
		int m = 0;
		for(int i = 0; i < this.mas.length; i++) {
			if(this.mas[i] == usam) {
				u = i + 1;
			}
		}

		for(int i = 0; i < this.mas.length; i++) {
			if(this.mas[i] == msam) {
				m = i + 1;
			}
		}

		if(u == 1) {
			if(m == 2) {
				return 3;
			}else if(m == 3) {
				return 5;
			}else if(m == 4) {
				return 2;
			}else {
				return 4;
			}
		}else if(u == 2) {
			if(m == 1) {
				return 4;
			}else if(m == 3) {
				return 1;
			}else if(m == 4) {
				return 6;
			}else {
				return 3;
			}
		}else if(u == 3) {
			if(m == 1) {
				return 2;
			}else if(m == 2) {
				return 6;
			}else if(m == 5) {
				return 1;
			}else {
				return 5;
			}
		}else if(u == 4) {
			if(m == 1) {
				return 5;
			}else if(m == 2) {
				return 1;
			}else if(m == 5) {
				return 6;
			}else {
				return 2;
			}
		}else if(u == 5) {
			if(m == 1) {
				return 3;
			}else if(m == 3) {
				return 6;
			}else if(m == 4) {
				return 1;
			}else {
				return 4;
			}
		}else {
			if(m == 2) {
				return 4;
			}else if(m == 3) {
				return 2;
			}else if(m == 4) {
				return 5;
			}else {
				return 3;
			}
		}
	}
}

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int m[] = {sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt()};

		Daice d = new Daice(m);

		int count = sc.nextInt();

		for(int i = 0; i < count; i++) {
			System.out.println(d.mas[d.umen(sc.nextInt(), sc.nextInt()) - 1]);
		}
	}
}


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

class Era
{
public:
	string n;
	int s,y;

	Era()
	{}

	Era(string n, int y, int s)
		:n(n),y(y),s(s)
	{}
};

int main()
{
	int N,Q;
	while(cin >> N >> Q, (N||Q)) {
		Era era[1005];

		for(int i=0; i<N; i++) {
			string n;
			int y,s;
			cin >> n >> y >> s;
			era[i] = Era(n, y, s - y);
		}

		while(Q--) {
			bool f = false;
			int y;
			cin >> y;

			for(int i=0; i<N; i++) {
				if(y > era[i].s && y <= era[i].s + era[i].y) {
					f = true;
					cout << era[i].n << " " << y - era[i].s << endl;
					break;
				}
			}

			if(!f) {
				cout << "Unknown" << endl;
			}

		}
	}
}

Measured memory_bytes: 1280
// ITP1_9_A Finding a Word
import java.io.*;

class Main {

   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String W;
      String T;
      int cnt = 0;

      try {
         W = br.readLine();
         T = br.readLine();
         while (!(T.equals("END_OF_TEXT"))) { 
            String[] Ti = T.split(" ");
            for (int i = 0; i < Ti.length; i++) {
               if (Ti[i].equalsIgnoreCase(W))
                  cnt++;
            }
            T = br.readLine();
         }
         System.out.println(cnt);
      }

      catch (Exception e) {
         System.err.println(e);
      }

   }
}

Measured memory_bytes: 16916
n=int(input())
l=[int(x) for x in input().split()]
dp=[0]*n
for i in range(n):
    if i==0:
        dp[i]=0
    elif i==1:
        dp[i]=abs(l[i]-l[i-1])
    else:
	    dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
print(dp[n-1])


Measured memory_bytes: 20608
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
using namespace std;

int main(){
  
  int n,a,b; cin >> n >> a >> b;
  cout << min(n*a, b);
 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
#define pi pair<int, int>
#define vi vector<int>
#define REP(a,b)  for (int i = int(a); i < int(b); i++)
#define endl "\n"
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define w(tc) int tc; cin>>tc; while(tc--)
using namespace std;


int main() {
	IOS
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, t, x;
	cin >> n >> x >> t;

	if (n % x == 0)cout << t*(n / x) << endl;
	else cout << t*((n / x) + 1) << endl;

	return 0;

}



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

#define N 100000
#define check cout<<"-----"<<endl;

class Card {
public:
    char sign;
    int number;
};

void quickSort(Card *, int, int);
void marge(Card *, int, int, int);
void margeSort(Card *, int, int);

int main() {

    int n;
    cin>>n;
    Card a[N], b[N];
    for(int i = 0; i < n; i++) {
        cin>>a[i].sign>>a[i].number;
        b[i] = a[i];
    }

    quickSort(a, 0, n-1);
    margeSort(b, 0, n);

    int i;
    for(i = 0; i < n; i++) {
        if(a[i].sign != b[i].sign) break;
    }
    if(i == n) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    for(int i = 0; i < n; i++) cout<<a[i].sign<<' '<<a[i].number<<endl;
    
    return 0;
}

void quickSort(Card *a, int p, int r) {

    if(p < r) {
          
        int j = p-1;
        for(int i = p; i < r; i++) {
            if(a[i].number <= a[r].number) {
                j++;
                if(i != j) {
                    Card temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }
        Card tmp = a[j+1];
        a[j+1] = a[r];
        a[r] = tmp;
        
        int q = j+1;
        quickSort(a, p, q-1);
        quickSort(a, q+1, r);
    }
}

void marge(Card *a, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    Card L[ n1+1 ], R[ n2+1 ];
    int i, j;
    for(i = 0; i < n1; i++) L[i] = a[ left+i ] ;
    for(j = 0; j < n2; j++) R[j] = a[ mid+j ];
    
    L[n1].number = INT_MAX;
    R[n2].number = INT_MAX;
    
    i = 0;
    j = 0;
    for(int k = left; k < right; k++) {
        if (L[i].number <= R[j].number) {
            a[k] = L[i];
            i++;
        } else {
            a[k] = R[j];
            j++;
        }
    }
}

void margeSort(Card *a, int left, int right) {
    if(left+1 < right) {
        int mid = (left + right) /2;
        margeSort(a, left, mid);
        margeSort(a, mid, right);
        marge(a, left, mid, right);
    }
}



Measured memory_bytes: 5356
#include<stdio.h>
int main()
{
	int n,i,j,a,x,y,b,p,r,t;
	scanf("%d",&n);
	for(;n--;)
	{
		scanf("%d%d%d%d",&x,&y,&b,&p);
		for(i=b,r=20000;i<7;i++)
			for(j=p;j<7;j++)
			{
				t=(double)(x*i+y*j)*(i>4&&j>1?0.8:1.0);
				r=r>t?t:r;
			}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 600
n = int(input())
a = list(map(int, input().split()))
a.sort()
amax = a[-1] + 1
dp = [True] * amax
ans_set = set()
remove_set = set()
for e in a:
  if dp[e]:
    if e in ans_set:
      remove_set.add(e)
    else:
      ans_set.add(e)
      for i in range(e*2, amax, e):
        dp[i] = False
print(len(ans_set - remove_set))


Measured memory_bytes: 43616
n, a, b = map(int, input().split())
p = 10**9+7

max_r = b

# nCrでnがでかすぎる時は直接O(r)で計算した方がいい
# 1<=n<=10**9, 1<=k<=10**7くらいのとき

def make_mod_inv(l,p): # lまでの逆元を作る
    mod_inv = [0, 1] + [0] * (l+3) # inv[n] = n^(-1) mod p, 0! = 1　だけど便宜上inv[0]=0にしてる
    for i in range(2, l+5):
        mod_inv[i] = -mod_inv[p % i] * (p // i) % p
    return mod_inv

mod_inv = make_mod_inv(max_r,p)

def NCr_mod_p(N, r, p):
    ret = 1
    for i in range(r):
        ret *= (N-i)%p
        ret *= mod_inv[i+1]
        ret %= p
    return ret

ans = pow(2,n,p) - 1 - NCr_mod_p(n,a,p) - NCr_mod_p(n,b,p)
print(ans%p)

Measured memory_bytes: 10840
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int[] array;
    public static void main(String[] args) {
        read();
        solve();
    }

    static void read(){
        array = new int[10];
        for(int i = 0; i < 10; i++){
            array[i] = sc.nextInt();
        }
    }

    static void solve(){
        Arrays.sort(array);
        System.out.println(array[9]);
        System.out.println(array[8]);
        System.out.println(array[7]);
    }

}

Measured memory_bytes: 26168
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

int main() {
    
    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;

        if (x == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3148
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    string S; cin >> S;
    int y = atoi(S.substr(0, 4).c_str());
    int m = atoi(S.substr(5, 2).c_str());
    int d = atoi(S.substr(8, 2).c_str());

    bool heisei = false;
    if (y < 2019) {
        heisei = true;
    } else if (y == 2019 && m <= 4) {
        heisei = true;
    }

    cout << (heisei ? "Heisei" : "TBD") << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

def f(a, b):
    a, b = str(a), str(b)
    return len(a) if len(a) > len(b) else len(b)

def isPrime(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    else:
        for i in range(2, int(n**(1/2))+1):
            if n%i == 0:
                return False
        return True

if isPrime(N):
    print(f(N, 1))
else:
    ans = 10**20
    for i in range(1, int(N**(1/2))+1)[::-1]:
        if N%i == 0:
            ans = min(ans, f(N//i, i))
    print(ans)

Measured memory_bytes: 38896
#include<iostream>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int main()
{
	string s;
	cin >> s;
	int t=0;
	REP(i, 3)
	{
		if (s[i] == '1')t++;
	}
	cout << t << endl;
	return 0;
}

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

int main() {
	int n; cin >> n;
	int64_t a[n], b[n]; for(int i = 0; i < n; ++i) cin >> a[i] >> b[i];
	sort(a, a + n);
	sort(b, b + n);
	if(n % 2 == 0) {
		cout << (b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1]) + 1 << '\n';
	} else {
		cout << b[n / 2] - a[n / 2] + 1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 6748
N = int(input())
A = list(map(int, input().split()))

current = 1000
kabu = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        kabu += current // A[i]
        current = current % A[i]
    elif A[i] > A[i+1]:
        current += kabu * A[i]
        kabu = 0
else:
    current += kabu * A[-1]

print(current)

Measured memory_bytes: 9096
k = int(input())
a = list(map(int,input().split()))
a = a[::-1]

c = 2 #min
d = 2 #max
res = 1 #判定

for i in range(k):
    if d < a[i]:
        res = -1
        break
    if i != k-1:
        if c % a[i] != 0 or d % a[i] != 0:
            res = -1
            break
        else:
            d = d + a[i] -1
            p = c%a[i+1]
            q = d%a[i+1]
            if p == 0:
                c2 = c
            else:
                c2 = c + a[i+1]-p
            d2 = d-q
            
            if c2 <= d2:
                c = c2
                d = d2
            else:
                res = -1
                break
    else:
        d = d + a[i] -1
            
        
    
    
if res == -1:
    print(-1)
else:
    print(str(c) + ' ' + str(d))

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

using namespace std;

bool solve()
{
	int ns[9];
	char cs[9];
	for(int i=0;i<9;i++) cin>>ns[i];
	for(int i=0;i<9;i++) cin>>cs[i];
	int p[9];
	for(int i=0;i<9;i++) p[i]=i;
	do{
		bool ok=1;
		for(int i=0;i<9;i+=3){
			int x=p[i],y=p[i+1],z=p[i+2];
			ok&=cs[x]==cs[y] && cs[y]==cs[z] &&
				((ns[x]==ns[y] && ns[y]==ns[z]) || (ns[x]+1==ns[y] && ns[y]+1==ns[z]));
		}
		if(ok) return true;
	}while(next_permutation(p,p+9));
	return false;
}

int main()
{
	int tc; cin>>tc;
	while(tc--)
		cout<<solve()<<endl;
	
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder {
    public class Program {
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(' ');
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }

        static void Main() {
            var Keys = getKeys(' ');
            int Min = 0;
            if (Keys[2] + Keys[1] > Keys[0]) {
                Min = -Keys[0] + Keys[1] + Keys[2];
            } int Max = Math.Min(Keys[1], Keys[2]);
            Console.WriteLine(Max + " " + Min);
        }
    }
}



Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,z,a,b,c;
        cin>>x>>y>>z;
        a=x;
        b=y;
        c=z;
        swap(a,b);
        swap(a,c);
        cout<<a<<" "<<b<<" "<<c<<endl;

}




Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/17/20 20:48:52
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  int m = n;
  int k = 2;
  int sum = 0;
  vector<int> ans;
  if (m==3) {
    ans = {2,3,25};
  } else if (m == 4) {
    ans = {2,3,25,30};
  } else {
    while (m) {
      while (k%2!=0 and k%3!=0)
        k++;
      ans.push_back(k);
      sum += k;
      k++;
      m--;
    }
    if (sum%6==2) {
      while (k%6!=0)
        k++;
      ans[0] = k;
    } else if (sum%6==3) {
      while (k%6!=0)
        k++;
      ans[1] = k;
    } else if (sum%6==5) {
      while (k%6!=3)
        k++;
      ans[4] = k;
    }
  }
  for (auto v:ans)
    cout<<v<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include <bits/stdc++.h>

using namespace std;

typedef pair<long long,bool> Pair;
const long long INF = 1LL<<60;

int main(){

string S;

cin >> S;

if(S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
else cout << "No" << endl;

return 0;


}   


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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#pragma endregion

int main(){
    char ans = 'A';
    char a;
    cin >> a;
    if (a-'a' >= 0) {
        ans = 'a';
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
import queue
n,x,y=map(int,input().split())
edge=[[i-1,i+1] for i in range(n)]
edge[0],edge[-1]=[1],[n-2]
edge[x-1].append(y-1)
edge[y-1].append(x-1)
inf=10**6
ans=[0]*n
for i in range(n):
    q=queue.deque([i])
    dist=[inf]*n
    dist[i]=1
    while q:
        a=q.pop()
        for e in edge[a]:
            if dist[e]==inf:
                q.appendleft(e)
                dist[e]=dist[a]+1
    for v in dist:
        ans[v-1]+=1
for i in range(n-1):
    print(ans[i+1]//2)

Measured memory_bytes: 77404
#include <stdio.h>

int main(){
  int N=0;
  long int sum=0;
  scanf("%d", &N);
  
  for(int i=1; i<=N; i++){
    if((i%3) != 0 && (i%5) != 0){
      sum += i;
    }
  }
  printf("%ld",sum);
}

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

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int s = 0;
    for (int i = 0; i < n; i++) s += a[i];
    s = s * s;
    for (int i = 0; i < n; i++) s -= a[i] * a[i];
    s /= 2;
    cout << s;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[] x = new int[h * w + 1];
        int[] y = new int[h * w + 1];
        int[] cost = new int[h*w + 1];
        
        int d = sc.nextInt();

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int in = sc.nextInt();
                x[in] = i + 1;
                y[in] = j + 1;
            }
        }
        
        for (int i = d+1; i <= h*w; i++) {
            cost[i] = cost[i-d] + Math.abs(x[i] - x[i-d]) + Math.abs(y[i] - y[i-d]);
        }

        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int xIn = sc.nextInt();
            int r = sc.nextInt();
            
            System.out.println(cost[r] - cost[xIn]);
        }
    }
}

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

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    auto F = factorize(accumulate(A.begin(), A.end(), 0));
    sort(F.begin(), F.end(), greater<int>());

    for (const auto &f: F){
        auto res = [&](const auto &f){
        vector<int> B(n);
        int border = 0;
        for (int i = 0; i < n; i++){
            B[i] = A[i] % f;
            border += min(B[i], f - B[i]);
            if (border > k + k)
                return false;
        }
        const auto S = accumulate(B.begin(), B.end(), 0);
        const auto i = S / f;
        nth_element(B.begin(), B.begin() + (n - i), B.end());
        if (max(accumulate(B.begin(), B.begin() + (n - i), 0), S - accumulate(B.begin() + (n - i), B.end(), 0)) <= k){
            return true;
        }}(f);

        if (res){
            printf("%d\n", f);
            return 0;
        }
    }

    puts("0");
}

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

int main() {
    lint n, p;
    cin >> n >> p;

    map<lint, lint> pf;
    for(lint i=2; i*i<=p; i++) {
        while(p%i == 0)  pf[i]++, p/=i;
    }
    if(p != 1)  pf[p] = 1;

    lint ans = 1;
    for(auto e : pf) {
        lint c = e.second / n;
        if(c)  ans *= pow(e.first, c);
    }
    cout << ans << endl;
}

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

int main() {
	int a, b, c, x;
	char r[10000];
	for (int i = 0;; i++) {
		cin >> a >> b >> c;
		if (a == b&&b == c&&c == -1){
			x = i;
			break;
		}
		else if (a == -1 || b == -1){
			r[i] = 'F';
		}else if (a + b >= 80){
			r[i] = 'A';
		}else if (65 <= a + b) {
			r[i] = 'B';
		}else if (50 <= a + b) {
			r[i] = 'C';
		}else if (30 <= a + b) {
			if (c >= 50) {
				r[i] = 'C';
			}else r[i] = 'D';
		}
		else  r[i] = 'F';
	}
	for (int i = 0; i < x; i++){
		cout << r[i] << endl;
	}
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a<=b && b<=c) cout << b-a+c-b << endl;
  else if(a<=c && c<=b) cout << c-a+b-c << endl;
  else if(b<=a && a<=c) cout << a-b+c-a << endl;
  else if(b<=c && c<=a) cout << c-b+a-c << endl;
  else if(c<=a && a<=b) cout << a-c+b-a << endl;
  else cout << b-c+a-b << endl;
  
  
  
  
}

Measured memory_bytes: 256
//made by Sert
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 34;
const int N = (int)1e6 + 34;

typedef long long ll;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int mid = 0; mid <= n; mid++) {
        set<char> sl, sr;
        for (int i = 0; i < mid; i++) sl.insert(s[i]);
        for (int i = mid; i < n; i++) sr.insert(s[i]);
        int cur = 0;
        for (char ch: sl) if (sr.find(ch) != sr.end()) cur++;
        ans = max(ans, cur);
    }
    cout << ans << "\n";
}

int main() {
#ifdef SERT
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    solve();
    solve();
    //solve();
    //solve();
#endif
    solve();
    return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    int a,b,c;cin>>a>>b>>c;
    ll ans=inf;
    int MAX=max({a,b,c});

    for (int i=MAX;i<MAX+1000;i++) {
        int D=3*i-a-b-c;
        if(D%2!=0){
            continue;
        }
        ans=D/2;
        break;
    }

    cout<<ans<<endl;

}



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

int main() {
  string s;
  cin >> s;
  vector<string> p(1, s.substr(0, 1));
  int i;
  for (i = 1; i < s.size()-1; i++) {
    if (p[p.size()-1].size() == 2)
      p.push_back(s.substr(i, 1));
    else if (p[p.size()-1][0] != s[i])
      p.push_back(s.substr(i, 1));
    else
      p.push_back(s.substr(i++, 2));
  }
  if (i == s.size()-1 && (p[p.size()-1].size() == 2 || p[p.size()-1][0] != s[i]))
    cout << p.size()+1 << endl;
  else
    cout << p.size() << endl;
}

Measured memory_bytes: 10996
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if(A==B) cout<<C<<endl;
    if(B==C) cout<<A<<endl;
    if(A==C) cout<<B<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int k, n, in, ans = 0;
	vector<int> pos,dis;
	cin >> k >> n;
	for (int i = 0; i < n; ++i) {
		cin >> in;
		pos.push_back(in);
		if (i == 0) {}
		else {
			dis.push_back(in - pos[i - 1]);
		}
	}
	dis.push_back(pos[0] + k - pos[pos.size()-1]);
	sort(dis.begin(), dis.end());
	ans = k - dis[dis.size() - 1];
	cout << ans;
	return 0;
}

Measured memory_bytes: 2036
#include <iostream>

using namespace std;

int F(int n, int r, int m) {
    if (n < 0) return 0;
    if (n == 0) return 1;
    if (r == 0) return 0;
    int c = 0;
    for (int i = m; i*i <= n; i++) {
        c += F(n-i*i, r-1, i);
    }
    return c;
}

int main() {
    int n;
    while (cin >> n, n != 0) {
        cout << F(n, 4, 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
/*
   * * * * *       *        * * * * * * * * * * * * * * * * * * * * * * * *     * * * * * * *               * *               * * * * * * * * * *
   * * * * *      * *       * * * * * * * * * * * * * * * * * * * * * *    *    * * * * * * *              * * *             * ** * * * * * * * * *
   * *           * * *            * *     * *     * *      * *          * * *   * * *       *             * * * *           * * * *       * *    * *
   * * * * *    * * * *           * *     * *     * *       * * * * * * *  * *  * * * * * * *            * * * * *         * *  * *       * * * * *
   * * * * *   * * * * *          * *     * *     * *        * * * * ** *   * * * * * * * * *           * * * * * *       * *   * * * *   * * * *
         * *  * * * * * *   * *   * *     * *     * *       * * * * * * *    * ** *     * * *          * * * * * * *     * *    * * * *   * *  * *
         * * * *       * *  * *   * *     * *     * *      * *          *     * * *     * * *         * *       * * *   * *     * *       * *   * *
   * * * * ** *         * * * * * * * * * * * * * * * * * * * * * * * * *      *  * * * * * * * * * ** *         * * * * *      * * * * * * *    * *
   * * * * * *           * ** * * * * * * * * * * * * * * * * * * * * * *       * * * * * * * * * * * *           * * * *       * * * * * * *     * *
*/

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <set>
#define ll long long
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define sz(a) int((a).size())
#define shit while(t--)
#define fr for(int i=0;i<n;i++)
int maxo=1e9+7;
using namespace std;
int arr[95];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    char a[4],b[4],c[4];
    for(int i=0;i<3;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<a[0]<<b[1]<<c[2];
    return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    if(N == 2) {
        cout << X[1] << endl;
        cout << X[0] << endl;
        return 0;
    }
    vector<int> cp = X;
    sort(All(cp));
    int m = cp[N / 2 - 1];
    int M = cp[N / 2];
    rep(i, N) {
        if(X[i] <= m) {
            cout << M << endl;
        } else if(X[i] >= M) {
            cout << m << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3712
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU
import Data.List ((\\))
import Data.Function (on)

main :: IO ()
main = do
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  hs <- VU.fromList . map unsafeTextToInt . T.words <$> T.getLine :: IO (VU.Vector Int)
  let
    loser :: (Int, Int) -> [Int]
    loser (i, j) = case (compare `on` (hs VU.!)) i j of
                     LT -> [i]
                     GT -> [j]
                     _  -> [i, j]
  abs <- sequence . replicate m $ unsafeListToPair . map (pred . unsafeTextToInt) . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    losers = VU.accum (flip const) (VU.replicate n True) . map (flip (,) False) . concatMap loser $ abs :: VU.Vector Bool
  print . VU.length . VU.filter id $ losers

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 42960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll valu[maxn];
int fa[maxn];
int fs[maxn];
struct node{
	int u;
	int v;
	ll valu;
}no[maxn];
bool cmp(node a,node b)
{
	return a.valu<b.valu;
}
int find(int x)
{
	if(fa[x]==x)
		return x;
	return fa[x]=find(fa[x]);
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>valu[i];
	for(int i=0;i<m;i++)
		cin>>no[i].u>>no[i].v>>no[i].valu;
	sort(no,no+m,cmp);
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=0;i<m;i++)
	{
		int f1=find(no[i].u);
		int f2=find(no[i].v);
		if(f1!=f2)
		{
			fa[f1]=f2;
			valu[f2]+=valu[f1];
			fs[f2]+=fs[f1];
		}
		fs[f2]++;
		if(valu[f2]>=no[i].valu)
			fs[f2]=0;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
		if(find(i)==i)
			ans+=fs[i];
	cout<<ans<<"\n";
	return 0;
} 

Measured memory_bytes: 3840
#繰り上がりごとに各桁の総和は9減る
#9*最初の桁数+最初の総和がそれで減る
#それは順番によらない

m = int(input())
sm=  0
d = []
c = []
for i in range(m):
    di,ci = map(int, input().split( ))
    d.append(di)
    c.append(ci)
    sm += di*ci

x = sum(c)*9 + sm
y =  x%9
if y==0:
    y = 9
    
print((x-y)//9-1)


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

Measured memory_bytes: 4596
def solve(a,b,c,turn):
	if turn == "a":
		if a == "":
			return "A"
		else:
			next_turn = a[0]
			a = a[1:]
	elif turn == "b":
		if b == "":
			return "B"
		else:
			next_turn = b[0]
			b = b[1:]
	else:
		if c == "":
			return "C"
		else:
			next_turn = c[0]
			c = c[1:]
	return solve(a,b,c, next_turn)
a=input().strip()
b=input().strip()
c=input().strip()
print(solve(a,b,c,"a"))


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

using ll = long long; 
using P = pair<int,int>;

int main() {

  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int ans = 0;
  int num, rem;
  if (A+B > C*2) {
    num = min(X, Y);
    ans += num * C * 2;
    if (X > Y){
      rem = X - Y;
      if (A < 2*C){
        ans += A * rem;
      }
      else { 
        ans += C * rem *2;
      }
    } 
    else { 
      rem = Y - X;
      if (B <2*C){
        ans += B * rem;
      }
      else {
        ans += C * rem * 2;
      }
    }
  } 
  else {
    ans += A * X + B * Y;
  }
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin >> n;
    if(n==0){
        cout << 0 << endl;
    }else{
        string s;
        long long int loop = 1;
        while(n!=0){
            if(n%(long long int)pow(2,loop)){
                s.push_back('1');
                n -= pow(-2, loop-1);
            }else{
                s.push_back('0');
            }


            loop++;
        }
        reverse(s.begin(),s.end());
        cout << s << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
loop do
  l=gets.split.map(&:to_i).sort!
  break if l[0]==0
  min_rad=((l[0]*0.5)**2+(l[1]*0.5)**2)**0.5
  gets.to_i.times do
    puts gets.to_i>min_rad ? "OK" : "NA"
  end
end

Measured memory_bytes: 8788
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < A.length; ++i) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(A));

        sc.close();
    }

    static long solve(int[] A) {
        long prefixSum = 0;
        long[] prefixSums = new long[A.length];
        for (int i = 0; i < prefixSums.length; ++i) {
            prefixSum += A[i];
            prefixSums[i] = prefixSum;
        }

        long result = Long.MAX_VALUE;
        for (int middleIndex = 1; middleIndex + 2 < A.length; ++middleIndex) {
            List<long[]> leftNearestPairs = findNearestPairs(prefixSums, 0, 0, middleIndex);
            List<long[]> rightNearestPairs = findNearestPairs(prefixSums, prefixSums[middleIndex], middleIndex + 1,
                    A.length - 1);

            for (long[] leftNearestPair : leftNearestPairs) {
                for (long[] rightNearestPair : rightNearestPairs) {
                    long[] sorted = LongStream.concat(Arrays.stream(leftNearestPair), Arrays.stream(rightNearestPair))
                            .sorted().toArray();

                    result = Math.min(result, sorted[sorted.length - 1] - sorted[0]);
                }
            }
        }

        return result;
    }

    static List<long[]> findNearestPairs(long[] prefixSums, long basePrefixSum, int beginIndex, int endIndex) {
        long total = prefixSums[endIndex] - basePrefixSum;

        int leftIndex = beginIndex - 1;
        int lower = beginIndex;
        int upper = endIndex;
        while (lower <= upper) {
            int middle = (lower + upper) / 2;
            long leftSum = prefixSums[middle] - basePrefixSum;
            long rightSum = total - leftSum;

            if (leftSum <= rightSum) {
                leftIndex = middle;
                lower = middle + 1;
            } else {
                upper = middle - 1;
            }
        }

        List<long[]> result = new ArrayList<>();
        if (leftIndex >= beginIndex && leftIndex < endIndex) {
            long leftSum = prefixSums[leftIndex] - basePrefixSum;

            result.add(new long[] { leftSum, total - leftSum });
        }
        if (leftIndex + 1 >= beginIndex && leftIndex + 1 < endIndex) {
            long leftSum = prefixSums[leftIndex + 1] - basePrefixSum;

            result.add(new long[] { leftSum, total - leftSum });
        }

        return result;
    }
}

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

long long dp[200000][4];

int main(void){
    string t;
    int n,k,r,s,p;
    cin >> n >> k >> r >> s >> p >> t;
    
    //r = 0,s = 1,p = 2
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 3;j++){
            if(j != 0)dp[i+k][j] = max(dp[i+k][j],dp[i][0]);
            if(j != 1)dp[i+k][j] = max(dp[i+k][j],dp[i][1]);
            if(j != 2)dp[i+k][j] = max(dp[i+k][j],dp[i][2]);
        }
        if(t[i] == 'r')dp[i+k][2] += p;
        if(t[i] == 's')dp[i+k][0] += r;
        if(t[i] == 'p')dp[i+k][1] += s;
    }
    
    long long ans = 0;
    for(int i = n;i < n+k;i++){
        ans += max(dp[i][0],max(dp[i][1],dp[i][2]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 6868
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w==0 && h==0) break;

			int[][] map = new int[h+2][w+2];
			int[][] wall_l = new int[h][w+1];
			int[][] wall_r = new int[h+1][w];
			Deque<Point> q = new ArrayDeque<Point>();

			for(int i=0; i<2*h-1; i++){
				for(int j=0; j<=w; j++){
					if(i%2==0 && j>0 && j<w){
						wall_l[i/2][0] = wall_l[i/2][w] = 1;
						wall_l[i/2][j] = sc.nextInt();
					}else if(i%2==1 && j<w){
						wall_r[0][j] = wall_r[h][j] = 1;
						wall_r[(i+1)/2][j] = sc.nextInt();
					}
				}
			}

			q.offer(new Point(1, 1, 1));
			map[1][1] = 1;
			while(!q.isEmpty()){
				if(map[h][w]!=0) break;
				Point p = q.poll();
				p.cnt++;

				if(wall_r[p.y][p.x-1]==0 && map[p.y+1][p.x]==0){
					map[p.y+1][p.x] = p.cnt;
					q.offer(new Point(p.x, p.y+1, p.cnt));
				}
				if(wall_l[p.y-1][p.x]==0 && map[p.y][p.x+1]==0){
					map[p.y][p.x+1] = p.cnt;
					q.offer(new Point(p.x+1, p.y, p.cnt));
				}
				if(wall_r[p.y-1][p.x-1]==0 && map[p.y-1][p.x]==0){
					map[p.y-1][p.x] = p.cnt;
					q.offer(new Point(p.x, p.y-1, p.cnt));
				}
				if(wall_l[p.y-1][p.x-1]==0 && map[p.y][p.x-1]==0){
					map[p.y][p.x-1] = p.cnt;
					q.offer(new Point(p.x-1, p.y, p.cnt));
				}
			}

			System.out.println((map[h][w]!=0) ? map[h][w] : 0);
		}
	}

	static class Point{
		int x, y, cnt;
		Point(int a, int b, int c){
			x = a;
			y = b;
			cnt = c;
		}
	}
}

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

int N;
int main(){
	while(cin >> N && N>0){
		vector<int> A(N,0),B(N,0),C(N,0);
		long long ans = 0;
		for(int i=0;i<N;i++){
			cin >> A[i];
		}
		sort(A.begin(),A.end());
		for(int i=0;i<N;i++){
			cin >> B[i];
		}
		for(int i=0;i<N;i++){
			cin >> C[i];
		}
		sort(C.begin(),C.end());
		for(int j=0;j<N;j++){
			decltype(A)::iterator it = lower_bound(A.begin(), A.end(), B[j]);
			decltype(C)::iterator it2 = upper_bound(C.begin(), C.end(), B[j]);
			ans += (it-A.begin())*(C.end()-it2);
		}
		cout << ans << endl;
	}
}

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

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String str = s.next();
        int ans=0;
        if(str.equals("SAT"))
        ans=1;
        if(str.equals("SUN"))
        ans=7;
        if(str.equals("MON"))
        ans=6;
        if(str.equals("TUE"))
        ans=5;
        if(str.equals("WED"))
        ans=4;
        if(str.equals("THU"))
        ans=3;
        if(str.equals("FRI"))
        ans=2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21076
import datetime


def actual(s):
    try:
        is_valid_yymm = bool(datetime.datetime.strptime(s, '%y%m'))
    except ValueError:
        is_valid_yymm = False

    try:
        is_valid_mmyy = bool(datetime.datetime.strptime(s, '%m%y'))
    except ValueError:
        is_valid_mmyy = False

    if is_valid_yymm and is_valid_mmyy:
        return 'AMBIGUOUS'

    if is_valid_yymm and not is_valid_mmyy:
        return 'YYMM'

    if not is_valid_yymm and is_valid_mmyy:
        return 'MMYY'

    return 'NA'

s = input()
print(actual(s))

Measured memory_bytes: 4952
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int start,end;
	long long len=0;
	bool foundA=false;
	bool foundZ=false;
	getline(cin,s);
	long long x=s.length();
	if(x>=1 && x<=200000){
		for(int i=0;i<x;i++){
			if(s[i]=='A' && foundA==false && foundZ==false){
				start=i;
				foundA=true;
			}
			else if(s[i]=='Z'){
				end=i;
			}
		}
		
		len=((end+1)-(start+1))+1;
	}
	printf("%lli",len);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    rep(i, m) {
        int k;
        cin >> k;
        s[i].resize(k);
        rep(j, k) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];
    int ans = 0;
    
    rep(i, 1<<n) {
        vector<bool> on(n);
        rep(j, n) {
            if (i>>j&1) on[j] = true;
        }
        bool ok = true;
        rep(j, m) {
            int sum = 0;
            for (int e: s[j]) {
                if (on[e]) sum++;
            }
            if (sum%2!=p[j]) ok = false;
        }
        if (ok) ans++;
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;

int main(){
    char boa[8][8];
    while(1){
        
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                if(!(cin>>boa[i][j]))
                    return 0;
            }
        }
        int bo[8][8];
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                bo[i][j]=boa[i][j]-'0';
            }
        }
            
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                if(bo[i][j]==1){
                    if(i<7&&j<7){
                        if(bo[i+1][j]==1&&bo[i][j+1]==1&&bo[i+1][j+1]){
                            cout<<"A"<<endl;
                            goto next;
                        }
                    }
                    if(j<5){
                        if(bo[i][j+1]&&bo[i][j+2]&&bo[j+3]){
                            cout<<"C"<<endl;goto next;
                        }
                            
                    }
                    if(i<5){
                        if(bo[i+1][j]&&bo[i+2][j]&&bo[i+3][j]){
                            cout<<"B"<<endl;goto next;
                        }
                        
                    }
                    if(i<7&&i>0&&j<7){
                        if(bo[i+1][j]&&bo[i][j+1]&&bo[i-1][j+1]){
                            cout<<"D"<<endl;goto next;
                        }
                    }
                    if(i<7&&j<6){
                        if(bo[i][j+1]&&bo[i+1][j+1]&&bo[i+1][j+2]){
                            cout<<"E"<<endl;goto next;
                        }
                    }
                    if(i<6&&j<7){
                        if(bo[i+1][j]&&bo[i+1][j+1]&&bo[i+2][j+1]){
                            cout<<"F"<<endl;goto next;
                        }
                    }
                    if(i<7&&j>0&&j<7){
                        if(bo[i+1][j]&&bo[i+1][j-1]&&bo[i][j+1]){
                            cout<<"G"<<endl;goto next;
                        }
                    }
                    
                }
            }
        }
        
    next:;
    }
    
    return 0;
}

Measured memory_bytes: 1136