akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

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

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int a, b;
	cin >> a >> b;
	if (a < b) swap(a, b);
	while (a--) cout << b;
	cout << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	X, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}
	grade500 := (X / 500) * 1000
	grade5 := ((X % 500) / 5) * 5

	fmt.Println(grade500 + grade5)
}


Measured memory_bytes: 1832
A,B,C = (int(i) for i in input().split())

times =  0

if A%2==1 or B%2==1 or C%2==1:
    times = 0
else:
    while True:
        times += 1
        A = A / 2
        B = B / 2
        C = C / 2
       # print(A,B,C)
        if A==B and C==A:
            times = -1
            break
        elif A%2==1 and B%2==1 and C%2==1:
            continue
        elif A%2==1 or B%2==1 or C%2==1:
            break
        #ここを追加したよ！さっきは変なことしてごめんなさい。
        elif A%1!=0 or B%1!=0 or C%1!=0:
            break
        elif A<=1 or B<=1 or C<=1:
            break
        

print(times)

Measured memory_bytes: 3064
#include<iostream>

int main() {
	int day, target, x, y;
	std::cin >> day >> target >> x >> y;

	if (day < target) {
		std::cout << day*x << std::endl;
	}
	else {
		std::cout << target*x + (day-target)*y;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
ll n,a[200010];
int main(){
	cin>>n;
	ll sum=0;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	ll rui=0;
	ll ans=1e17;
	rep(i,n){
		rui+=a[i];
		ll x=sum-rui;
		ll y=rui;
		if(x<y)swap(x,y);
		chmin(ans,x-y);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, U, V = lr()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

def dijkstra(start):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[start] = 0
    que = [(0, start)]
    while que:
        d, prev = heappop(que)
        if dist[prev] < d:
            continue
        for next in graph[prev]:
            d1 = d + 1
            if dist[next] > d1:
                dist[next] = d1
                heappush(que, (d1, next))
    return dist

dist_U = dijkstra(U)
dist_V = dijkstra(V)
answer = max(v for u, v in zip(dist_U, dist_V) if v > u) - 1
print(answer)
# 25

Measured memory_bytes: 32460
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b;
	cin>>a>>b;
	if ((a+b)%3==0&&(a+b)>=3) cout<<"Possible"<<endl;
	else if(a>=3&&a%3==0) cout<<"Possible"<<endl;
	else if(b>=3&&b%3==0) cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int K = in.nextInt();
            String S = in.next();
            S += '-';
            char[] cs = S.toCharArray();

            int max = 0;
            int sum = 0;
            int size0 = 0;
            LinkedList<Integer> l = new LinkedList<>();
            for (int i = 0, count1 = 0, count0 = 0; i < cs.length; i++) {
                if (cs[i] == '0') {
                    count0++;
                    if (count1 > 0) {
                        l.add(count1);
                        sum += count1;
                        count1 = 0;
                        max = Math.max(max, sum);
//                        Utils.debug(i, max, sum);
                    }
                } else if (cs[i] == '1') {
                    count1++;
                    if (count0 > 0) {
                        l.add(count0);
                        size0++;
                        sum += count0;
                        count0 = 0;
                        if (size0 > K) {
                            if (l.size() % 2 == 0) {
                                int count12 = l.pollFirst();
                                sum -= count12;
                                int count02 = l.pollFirst();
                                sum -= count02;
                            } else {
                                int count02 = l.pollFirst();
                                sum -= count02;
                            }
                            size0--;
                        }
                        max = Math.max(max, sum);
//                        Utils.debug(i, max, sum);
                    }
                } else {
                    if (count1 > 0) {
                        l.add(count1);
                        sum += count1;
                        count1 = 0;
                        max = Math.max(max, sum);
//                        Utils.debug(i, max, sum);
                    }
                    if (count0 > 0) {
                        l.add(count0);
                        size0++;
                        sum += count0;
                        count0 = 0;
                        if (size0 > K) {
                            if (l.size() % 2 == 0) {
                                int count12 = l.pollFirst();
                                sum -= count12;
                                int count02 = l.pollFirst();
                                sum -= count02;
                            } else {
                                int count02 = l.pollFirst();
                                sum -= count02;
                            }
                            size0--;
                        }
                        max = Math.max(max, sum);
//                        Utils.debug(i, max, sum);
                    }
                }
            }

            System.out.println(max);

        }
    }
}


Measured memory_bytes: 28668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll mod=1000000007; // 998244353 = (119<<23)+1
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// head
const int nax=1e5+7;
int A,B,q;
ll a[nax],b[nax];
int main() {
	  ios::sync_with_stdio(false);
  	cin.tie(0);
		cin>>A>>B>>q;
		rep(i,0,A) cin>>a[i];
		rep(i,0,B) cin>>b[i];
		sort(a,a+A);
		sort(b,b+B);
		rep(i,0,q) {
			ll x,ans=1e17;
			cin>>x;
			int p1=lower_bound(a,a+A,x)-a;
			int p2=lower_bound(b,b+B,x)-b;
			if(p1>0&&p2>0) ans=min(ans,x-min(a[p1-1],b[p2-1]));
			if(p1<A&&p2<B) ans=min(ans,max(a[p1],b[p2])-x);
			if(p1>0&&p2<B) ans=min(ans,min(abs(x-a[p1-1]),abs(x-b[p2]))*2+max(abs(x-a[p1-1]),abs(x-b[p2])));
			if(p2>0&&p1<A) ans=min(ans,min(abs(x-a[p1]),abs(x-b[p2-1]))*2+max(abs(x-b[p2-1]),abs(x-a[p1])));
			cout<<ans<<'\n';
		}
		return 0;
}


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

using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " "

const int MAX = 1000000;
int s, w;

int main() {
	cin >> s >> w;
	if (w >= s) {
		cout << "unsafe";
	} else {
		cout << "safe";
	}

	return 0;
}

Measured memory_bytes: 3632
K,A,B = map(int,input().split())
ans = A
if (B-A <= 2):
  ans = K+1
else:
  if (K <= A):
    ans = K+1
  else:
    a = (K-A+1) // 2
    b = (K-A+1) % 2
    ans += (B-A)*a + b
print(ans)
  

Measured memory_bytes: 38256
program main
  implicit none
  integer A, B, C
  read(*, *) A, B, C
  if (C<A .and. C<B) then
    write(*,'(A)') 'No'
  elseif (C>A .and. C>B) then
    write(*,'(A)') 'No'
  else
    write(*,'(A)') 'Yes'
  end if
end program main


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define int long long
using namespace std;


 main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin>>k;
    string ans = "";
    string s;
    cin>>s;
   int n=  s.size();
   if(n <=k){
    cout<<s<<endl;
    return 0;
   }
   for(int i =0; i<k; i++)
    ans+=s[i];
    ans+="...";
    cout<<ans;
   cout<<endl;





    return 0;
}


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

int main() {
int N;
  cin >> N;
  vector<int> renga(N);
  int count = 1;
  for(int i = 0; i < N; i++){
  	cin >> renga[i];
    if(renga[i] == count){
    	count++;
    }
  }
  if(count == 1){
  cout << -1 << endl;
  }
  else{
  int ans = N-count+1;
  cout << ans << endl;
  }
}

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

using namespace std;
typedef long long int ll;

int main(){
    int L;
    scanf("%d", &L);
    ll A[L];
    for(int i=0;i<L;i++)
        scanf("%lld", &A[i]);
    ll dp[L+1][5];
    for(int j=0;j<5;j++) dp[0][j] = 0;
    for(int i=1;i<L+1;i++){
        ll A_is_zero = 0;
        if (A[i-1] == 0) A_is_zero = 2;
        dp[i][0] = dp[i-1][0] + A[i-1];
        dp[i][1] = min(dp[i][0], dp[i-1][1] +  A[i-1]%2 + A_is_zero);
        dp[i][2] = min(dp[i][1], dp[i-1][2] + (A[i-1]+1)%2);
        dp[i][3] = min(dp[i][2], dp[i-1][3] +  A[i-1]%2 + A_is_zero);
        dp[i][4] = min(dp[i][3], dp[i-1][4] +  A[i-1]);
    }
    printf("%lld\n", dp[L][4]);
    return 0;
}


Measured memory_bytes: 9600
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool found = false;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0) found = true;
  }
  if (found) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int D,T,S;
  cin>>D>>T>>S;
  if(D>T*S){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
  return 0;
}
  

Measured memory_bytes: 3536
from typing import List
from typing import Tuple
from sys import setrecursionlimit

setrecursionlimit(100000)

def articulation_points(adj, n):
    low_link = [None for _ in range(n)]
    mark = [False for _ in range(n)]
    id = [-1 for _ in range(n + 1)]
    points = []

    for v in range(n):
        if mark[v]:
            continue
        dfs(v, -1, adj, id, low_link, mark, points)
    points.sort()
    return points

def dfs(v: int, p: int, adj: List[List[int]], id: List[int], low_link: List[int], mark: List[bool], points: List[int]) -> None:
    mark[v] = True
    id[-1] += 1
    id[v] = id[-1]
    low_link[v] = id[v]

    is_articulation_point = False
    childs = 1 if p != -1 else 0 

    for a_v in adj[v]:
        if a_v == p: continue
        if not mark[a_v]:
            childs += 1
            dfs(a_v, v, adj, id, low_link, mark, points)
            low_link[v] = min(low_link[v], low_link[a_v])
            if childs > 1 and id[v] <= low_link[a_v]:
                is_articulation_point = True
        else:
            low_link[v] = min(low_link[v], id[a_v])
    if is_articulation_point:
        points.append(v)

def read() -> Tuple[List[List[int]], int]:
    v, e = tuple([int(i) for i in input().split()])

    adj = [[] for _ in range(v)]

    for i in range(e):
        v1, v2 = tuple([int(j) for j in input().split()])
        adj[v1].append(v2)
        adj[v2].append(v1)
    
    return adj, v

def write(point_list):
    for point in point_list:
        print(point)

adj, n = read()
articulation_point_list = articulation_points(adj, n)
write(articulation_point_list)



Measured memory_bytes: 21388
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  ll n, a, b;
  cin >> n >> a >> b;
  if(abs(a - b) % 2 == 0) {
    ans = abs(a - b) / 2;
  }
  else {
    ll edge = min(min(a, b) - 1, n - max(a, b));
    ll dis = abs(a - b);
    ans = min(edge + dis, edge + 1 + (dis - 1) / 2);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c; cin >> a >> b >> c;
  int tmp = a;
  rep(i, b) {
    if(tmp%b==c) {
      cout << "YES\n";
      return 0;
    }
    tmp += a;
  }
  cout << "NO\n";
  return 0;
}


Measured memory_bytes: 3648
package main

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

type memo struct {
	s []byte
	c int
}

func main() {
	f := bufio.NewScanner(os.Stdin)
	f.Split(bufio.ScanWords)

	s := read(f)
	t := read(f)

	dp := make([][]int, len(s)+1)
	for i := range dp {
		dp[i] = make([]int, len(t)+1)
		for j := range dp[i] {
			if i == len(s) || j == len(t) {
				dp[i][j] = 0
			} else {
				dp[i][j] = -1
			}
		}
	}

	var dfs func(int, int) int
	dfs = func(i, j int) int {
		if dp[i][j] >= 0 {
			return dp[i][j]
		}

		matched := 0
		if s[i] == t[j] {
			matched = 1
		}

		res := dfs(i+1, j+1) + matched
		if next := dfs(i+1, j); next > res {
			res = next
		}

		if next := dfs(i, j+1); next > res {
			res = next
		}

		dp[i][j] = res
		return res
	}

	dfs(0, 0)

	m := min(len(s), len(t))
	lcs := make([]byte, 0, m)

	i := 0
	j := 0
	for i < len(s) && j < len(t) {
		if dp[i][j] == dp[i+1][j] {
			i += 1
			continue
		}

		if dp[i][j] == dp[i][j+1] {
			j += 1
			continue
		}

		if dp[i][j] == dp[i+1][j+1]+1 {
			lcs = append(lcs, s[i])
			i += 1
			j += 1
			continue
		}
	}

	fmt.Println(string(lcs))
}

func read(s *bufio.Scanner) []byte {
	s.Scan()
	return []byte(s.Text())
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}


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


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

    vector<long long> H(100010, 0);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
    }

    int ans = 0;
    int cnt = 0;
    for (int j = 0; j < N; ++j) {
        if (H[j] >= H[j+1] && H[j+1] != 0) {
            cnt++;
            ans = max(ans, cnt);
        } else {
            cnt = 0;
        }
    }


    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<pii,int> ppiii ;
typedef unsigned long long ull ;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;

int main(){
	int h,w;
	cin>>h>>w;
	int cnt=0;
	string hoge[10];
	for(int i=0;i<h;i++){
		cin>>hoge[i];
		for(int j=0;j<w;j++){
			if(hoge[i][j]=='#')cnt++;
		}
	}
	int x=0,y=0;
	bool flag=true;
	if(cnt!=h+w-1)flag=false;
	if(flag)cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
from math import factorial

n, m = map(int, input().split())

mod = 10**9+7
if abs(n - m) == 0:
    print(((((factorial(n) % mod)**2) % mod) * 2) % mod)
elif abs(n - m) == 1:
    print(((factorial(n) % mod) * factorial(m)) % mod)
else:
    print(0)


Measured memory_bytes: 4096
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n"
using namespace std;
using ll=long long;
using ld=long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vlll = vector<vector<vector<ll>>>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) {
            for (auto vvv : vv) cout << vvv << " ";
            cout << endl;
        }
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

dbg::Debug debug;

class CGacha {
public:
	void solve(std::istream& in, std::ostream& out) {
		ll n;
		in >> n;
		set<string> st;
		for(int i=0; i<n; i++){
			string s;
			in >> s;
			st.insert(s);
		}

		out << st.size() << enl;
	}
};


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	CGacha solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n; cin >> n;
  vi32 a(n); cin >> a;
  int sum = accumulate(all(a), 0);
  int ans = -1, ma = 1e9;
  rep(i, n) {
    if (ma > abs(a[i] * n - sum)) {
      ans = i, ma = abs(a[i] * n - sum);
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def main():
    a,b,c,d = map(int,input().split())
    c_mul_count = b//c - (a-1)//c
    d_mul_count = b//d - (a-1)//d
    cd_lcm = lcm(c, d)
    lcm_mul_count = b//cd_lcm - (a-1)//cd_lcm
    s = b-a+1
    print(s-c_mul_count-d_mul_count+lcm_mul_count)



if __name__ == '__main__':
    main()


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

template<typename T>T gcd(T a,T b){while(1){swap(a,b);if(a==0)return b;if(b==0)return a;a%=b;}}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}

int main(){

  ll n,m;
  cin>>n>>m;
  vector<ll> a(n);
  cin>>a;

  vector<ll> b = a;
  rep(i,n)b[i]/=2;

  ll tb = 1;
  rep(i,n)tb=lcm(tb,b[i]);
  ll ta = 1;
  rep(i,n)ta=lcm(ta,a[i]);

  vector<ll> c(n);
  rep(i,n)c[i]=tb/b[i];

  bool ok=true;
  rep(i,n)if(c[i]%2==0)ok=false;

  if(ok)cout<<(m/tb-m/ta)<<endl;
  else cout<<0<<endl;

}


Measured memory_bytes: 2560
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int dice[];
		int tre = 0;
		String mei;
		String han;
		String str;
		
		mei = "";
		dice = new int[6];
		
		for(int i=0;i<6;i++){
			
			dice[i] = as.nextInt();
			
		}
		
		mei = as.next();
		
		for(int i=0;i<mei.length();i++){
			
			han = String.valueOf(mei.charAt(i));
			
			switch (han){
				case "E":
					tre = dice[0];
					dice[0] = dice[3];
					dice[3] = dice[5];
					dice[5] = dice[2];
					dice[2] = tre;
					break;
					
				case "N":
					tre = dice[0];
					dice[0] = dice[1];
					dice[1] = dice[5];
					dice[5] = dice[4];
					dice[4] = tre;
					break;
					
				case "S":
					tre = dice[0];
					dice[0] = dice[4];
					dice[4] = dice[5];
					dice[5] = dice[1];
					dice[1] = tre;
					break;
					
				case "W":
					tre = dice[0];
					dice[0] = dice[2];
					dice[2] = dice[5];
					dice[5] = dice[3];
					dice[3] = tre;
					break;
					
					
			}
			
		}
		
		str = String.valueOf(dice[0]);
		System.out.println(str);

	}

}

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

int	main()
{
	int	N;
	cin >> N;
	int64_t	A;
	int64_t	max_A, min_A;
	cin >> A;
	max_A = min_A = A;
	for (int i = 1; i < N; ++i) {
		cin >> A;
		if (max_A < A) max_A = A;
		if (min_A > A) min_A = A;
	}
	cout << max_A - min_A << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
    #define REP(i,n) rep(i,0,n)
    #define ll long long
    #define ull unsigned long 
     
    bool dfs(vector<vector<ll> >& g,ll v,vector<bool>& check) //V子、P親
    {
      check[v]=true;
      for(auto next:g[v])
         if(!(check[next]))
      	   dfs(g,next,check);
    	 
      for(auto i:check)
        if(!i)
        {
          return true;
        }
        return false;
    }
     
    int main()
    { 
      ll n,m;
      cin >> n >> m;
      ll A[55][2];
      REP(i,m)
      	cin >> A[i][0] >> A[i][1];
      ll ans=0;
     REP(i,m)
     {
       //構築
     vector<vector<ll> >  Ginf(n);
     REP(j,m)
       if(j != i)
     {
       ll a,b;
       a = A[j][0];
       b = A[j][1];
       a--;
       b--;
       Ginf[a].push_back(b);
       Ginf[b].push_back(a);
     }
       
       vector<bool> check(n,false);
       if(dfs(Ginf,0,check)) ans++;
        
     }
      cout << ans << endl;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int calc(int x){
    int ans;
    for (int i=x;;i++) {
        bool flag = true;
        for (int j=2; j*j<=x; j++){
            if (i%j==0) flag = false;
        }
        if (flag){ans = i; break;}
    }
    return ans;
}

int main(){
    int x; cin >> x;
    cout << calc(x) << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[525252];
int s[525252];
int c[525252];
vi xs[1<<20];

int main(){
    scanf("%d",&n);
    REP(i,n)scanf("%d",a+i);
    REP(i,n)s[i+1]=s[i]^a[i];
    REP(i,n+1)c[i+1]=c[i]+(s[i]==0);
    REP(i,n+1)xs[s[i]].push_back(i);
    ll ans = 0;
    // 0
    if(s[n]==0){
        int x = xs[0].size()-2;
        ll add = 1;
        while(x--)add=add*2%MOD;
        ans += add;
        ans %= MOD;
    }
    // >0
    FOR(v,1,1<<20)if(xs[v].size()){
        // dp
        int p = 0;
        ll dp0 = 1, dp1 = 0;
        for(int x : xs[v]){
            ll c0 = c[x] - c[p];
            ll ndp0 = (dp0 + dp1 * c0 % MOD) % MOD;
            ll ndp1 = dp1;
            dp0 = ndp0;
            dp1 = (ndp1 + ndp0) % MOD;
            p = x;
        }
        if(s[n]==0){
            ans += dp1;
        }else if(s[n]==v){
            ans += dp0;
        }
        // if(s[n]==0){
        //     ans += dp1;
        // }else if(s[n]==v){
        //     ans += dp0;
        // }
        ans %= MOD;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 40564
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        solve2440();
    }

    public static void solve2440() {
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(0 == n){
                break;
            }
            int[] s = new int[n];
            int sum = 0;
            int max = 0;
            int min = 1000;
            int avg = 0;
            for(int i=0; i<n; i++){
                s[i] = sc.nextInt();
                if(s[i]>max){
                    max = s[i];
                }
                if(s[i]<min){
                    min = s[i];
                }
                sum += s[i];
            }
            sum -= (max + min);
            avg = sum /(n-2);
            System.out.println(avg);
        }
    }
}



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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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

ll N;
vl a;
vector<vl> G;
vl dp;
vl ans;

void dfs(ll r, ll p)
{
    int index = lower_bound(ALL(dp), a[r])-dp.begin();
    ll tmp = dp[index]; 
    dp[index] = a[r];
    for(int n : G[r])
    {
        if(n == p) continue;
        dfs(n, r);
    }
    ans[r] = lower_bound(ALL(dp), INF)-dp.begin();
    dp[index] = tmp;
}

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

    cin >> N;
    a.resize(N); REP(i, N) cin >> a[i];
    G.resize(N);
    ans.resize(N);
    dp.resize(N, INF);
    REP(i, N-1)
    {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].pb(v);
        G[v].pb(u);
    }

    dfs(0, -1);
    REP(i, N) cout << ans[i] << endl;
}

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    vector<string> D = {"SUN","MON","TUE","WED","THU","FRI","SAT"}; 
    string S;
    cin >> S;
    int ans=0;
    lp0(i,0,7)
    if(D[i]==S) 
        ans = 7-i;
    cout << ans << endl;
}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int[] array = new int[3];
		for (int i = 0; i < a; i++) {
			array[0] = scan.nextInt();
			array[1] = scan.nextInt();
			array[2] = scan.nextInt();
			java.util.Arrays.sort(array);
			int result = (array[2] * array[2])
					- ((array[1] * array[1]) + (array[0] * array[0]));
			if (result == 0) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

	}
}

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

int main() {
    int n;
    std::string s;
    std::cin >> n >> s;
    int ret = 0;
    for (int i = 0; i < n; i++) {
        if (s.substr(i, 3) == "ABC") ret++;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxx 3000
double dp[maxx][maxx];
double profit[maxx];
#define ll long long int
ll n;
double prob(ll i,ll x)
{
    if(x==0)
    {
        return 1.0;
    }
    if(i==0)
    {
        return 0.0;
    }
    if(dp[i][x]!=-1.0)
    {
        return dp[i][x];
    }
    return dp[i][x] = profit[i]*prob(i-1,x-1) + (1-profit[i])*prob(i-1,x);
}


int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>profit[i];
    }
    int x = (n+1)/2;
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=x;j++)
        {
            dp[i][j]=-1;
        }
    }
    cout<<fixed<<setprecision(10)<<prob(n,x);
}


Measured memory_bytes: 51024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[100002];

int main() {
    int n,k,x;
    cin>>n>>k;
    int id = -1;
    for(int i = 0; i < n; ++i) {
        cin>>x;
        if(x == 1) id = i;
    }
    int ans = 0, ct = 0;
    for(int i = 0; i < n;) {
        if(i + k - 1 < n - 1)
            i += k - 1, ct ++;
        else {
            ct++;
            break;
        }
    }
    
    cout<<ct<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cctype>

int main() {
    std::vector< int > cnt(26);

    std::string s;
    while (std::getline(std::cin, s)) {
        for (auto &c: s) c = tolower(c);

        for (auto &c: s) {
            if (!isalpha(c)) continue;
            cnt[c - 'a']++;
        }
    }

    for (int c = 'a'; c <= 'z'; ++c) {
        std::cout << char(c) << " : " << cnt[c - 'a'] << std::endl;
    }
}



Measured memory_bytes: 3216
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(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)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int N; cin >> N;
    vector<int> W(N);
    rep (i, N)
    {
        cin >> W[i];
    }

    int sum_W = 0;

    rep (i, N)
    {
        sum_W += W[i];
    }

    int before = sum_W;
    int sum_W_ = 0;
    int after = 100000000;
    int ans;
    rep (i, N)
    {
        before -= W[i];
        sum_W_ += W[i];
        if (abs(before - sum_W_) > after)
        {
            ans = std::min(abs(before - sum_W_), after);
            break;
        }
        after = abs(before - sum_W_);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int a[5];
  int b[5];
  int i,j,hit,blow;

  while(scanf("%d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3])!=EOF){
    hit=blow=0;
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
        if(a[i]==b[j]){
          if(i==j){
            hit++;
          }else{
            blow++;
          }
        }
      }
    }
    printf("%d %d\n",hit,blow);
  }
  return 0;
}


Measured memory_bytes: 596
/* 駄実装の典型 皆さんはstackではなくてn進法を使いましょう */
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <set>
#include <deque>
#include <algorithm>

using namespace std;

int main() {
    while (1) {
        int n;
        int k;
        vector<string> element_strings;
        set<string> generated_strings;
        deque<int> stack;
    
        scanf("%d", &n);
        scanf("%d", &k);
    
        if (n == 0 && k == 0) return 0;
 
        for (int i=0; i<n; i++) {
            char number[3];
            scanf("%s", number);
            element_strings.push_back(string(number));
        }
    
        sort(element_strings.begin(), element_strings.end());
    
        while (1) {
            char has_appeared[11];
            char not_count = 0;
            string new_string = "";
            int next_ind;
    
            while (stack.size() != k) {
                stack.push_back(0);
            }

            memset(has_appeared, 0, sizeof(has_appeared));

            for (deque<int>::iterator itr=stack.begin(); itr != stack.end(); itr++) {
                if (has_appeared[*itr]) {
                    not_count = 1;
                    break;
                }
                has_appeared[*itr] = 1;
                new_string += element_strings[*itr];
            }

            if (!not_count && generated_strings.count(new_string) == 0) { 
                generated_strings.insert(new_string);
            }
    
            while (!stack.empty() && stack.back() == element_strings.size()-1) {
                stack.pop_back();
            }
    
            if (stack.empty()) {
                break;
            }
    
            next_ind = stack.back() + 1;
            stack.pop_back();
            stack.push_back(next_ind);
        }
    
        printf("%lu\n", generated_strings.size());
    }
}

Measured memory_bytes: 1340
import bisect

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)

Measured memory_bytes: 16168
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
int a[101]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
	int b;
	scanf("%d",&b);
	printf("%d\n",a[b]);
	return 0;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = input()
    hugo = ['+', '-']
    for a in hugo:
        for b in hugo:
            for c in hugo:
                N = eval(S[0]+a+S[1]+b+S[2]+c+S[3])
                if N == 7:
                    ans = S[0]+a+S[1]+b+S[2]+c+S[3]+'=7'
                    break
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(input())
    a = input_to_int_tuple()

    from collections import defaultdict
    l = defaultdict(int)
    r = defaultdict(int)
    for i, h in enumerate(a):
        no = i + 1
        l[no + h] += 1
        r[no - h] += 1

    ret = 0
    for i in range(1, n + 1):
        ret += (l.get(i, 0) * r.get(i, 0))

    return ret


if __name__ == "__main__":
    print(main())


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

dic = {}
for i in range(1, N+1):
    s, p = map(str, input().split())
    p = int(p)
    if dic.get(s) is None:
        dic[s] = [(i, p)]
    else:
        dic[s].append((i, p))

for k in dic:
    tmp = sorted(dic[k][:], key=lambda x: -x[1])
    dic[k] = tmp

inds = []
ind = 1
for k in sorted(dic.keys()):
    for t in dic[k]:
        inds.append((t[0], ind))
        ind += 1

for ind in sorted(inds, key=lambda x: x[1]):
    print(ind[0])

Measured memory_bytes: 3064