akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define each(i,v) for(auto &(i):(v))
#define all(c) (c).begin(),(c).end()
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n, m, x, y, z, res;
vector<int> e[100100];
bool ok[100100];

void rec(int v, int p) {
    ok[v] = 1;
    each(i,e[v]) if (i!=p && !ok[i]) rec(i,v);
}

signed main() {
    cin >> n >> m;
    rep(i,m) {
        cin >> x >> y >> z;
        x--, y--;
        e[x].push_back(y), e[y].push_back(x);
    }
    rep(i,n) if (!ok[i]) res++, rec(i,-1);
    cout << res << endl;
}


Measured memory_bytes: 10496
import java.util.*;

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

        long ret = 0;

        for (int mask = 0; mask < (1 << (len - 1)); mask++) {
            String str = S;

            int accumulatedNum = 0;

            for (int j = 0; j < len - 1; j++) {
                if (((mask >> j) & 1) == 1) {
                    String substracted = str.substring(str.length() - 1 - accumulatedNum, str.length());
                    str = str.substring(0, str.length() - 1 - accumulatedNum);
                    accumulatedNum = 0;
                    ret += Long.parseLong(substracted);
                } else {
                    accumulatedNum++;
                }
            }

            ret += Long.parseLong(str);
        }

        System.out.println(ret);
    }
}

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

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

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i)
        cin >> a[i];
    int ans = 0,light = 1;
    for (int i = 0; i < N; ++i)
    {
        ++ans;
        light = a[light - 1];
        if (light == 2)
        {
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3680
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = []

for i in range(n):
  s.append((a[i], 1))

for _ in range(m):
  b, c = map(int, input().split())
  s.append((c, b))
#  for j in range(b):
#    a.append(c)

s.sort(reverse=True)
idx = 0
sum = 0
for i in range(n):
  if idx + s[i][1] > n:
    sum += s[i][0] * (n-idx)
    break

  sum += s[i][0] * s[i][1]
  idx += s[i][1]


# for i in range(l-n, l):
#  sum += a[i]

print(sum)



Measured memory_bytes: 34704
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int[] nums = new int[]{a,b,c};
		
		Arrays.sort(nums);
		
		System.out.print(nums[0]);
		for (int i = 1; i < nums.length; i++)
			System.out.print(" " + nums[i]);
		
		System.out.println();
		
		sc.close();

	}

}

Measured memory_bytes: 26324
import sys

MOD = 10 ** 9 + 7

n, m, *a = map(int, sys.stdin.read().split())
broken = set(a)

def main():
    res = [None] * (n + 1)
    res[0] = 1
    res[1] = 0 if 1 in broken else 1
    
    for i in range(2, n+1):
        if i in broken:
            res[i] = 0
        else:
            res[i] = res[i-2] + res[i-1]
            res[i] %= MOD
    
    return res[n]
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 14308
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int N;
    cin >> N;

    map<string, int> mp;
    REP(i,N){
        string s;
        cin >> s;
        mp[s]++; 
    }

    int M;
    cin >> M;

    REP(i,M){
        string s;
        cin >> s;
        mp[s]--; 
    }
    
    int maxval = 0;
    string optkey;
    for(auto x:mp){
        string key=x.first;
        int val = x.second;
        maxval = max(maxval, val);
    }

    cout << maxval << endl;

   return 0;
}

Measured memory_bytes: 256
c = [list(map(int, input().split())) for _ in range(3)]
flag = True
for i in range(3):
  x = [0]*3
  y = [0]*3
  for j in range(3):
    x[j] = c[i-1][j] - c[i][j]
    y[j] = c[j][i-1] - c[j][i]
  if len(set(x)) != 1 or len(set(y)) != 1:
    flag = False
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 65784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,dp[105][100005],v[105],w[105],m,ans;
int main(void){
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)scanf("%lld%lld",w+i,v+i);
    for(int i=0;i<=n;i++)for(int j=0;j<=100000;j++)dp[i][j]=INF;
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        for(ll j=100000;j>=0;j--){
            if(j-v[i]>=0)dp[i][j]=min(dp[i-1][j-v[i]]+w[i],dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];
            if(dp[i][j]<=m)ans=max(ans,j);
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 80128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		sc.close();

		boolean check = false;
		if(N >= 4) {
			for(int i = 0; i <= N / 7; i++) {
				int rest = N - 7 * i;
				if(rest % 4 == 0) {
					check = true;
					break;
				}else {
					continue;
				}
			}
		}
		if(check) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 22996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


public class Main {
	
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		m.input();
		m.solve();
		m.output();
	}
	
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	//InputUtil in = new InputUtil();
	PrintWriter out = new PrintWriter(System.out);

	String S = null;
	boolean ans = false;
	
	public void input() throws IOException {
		S = br.readLine();
	}

	public void solve() throws IOException {
		ans = (S.indexOf("AC") >= 0);
	}
	
	
	public void output() {
		out.println(ans ? "Yes" : "No");
		out.flush();
		
	}
}

Measured memory_bytes: 21076
N = int(input())
S = str(input()) 

r = S.count('R')
g = S.count('G')
b = S.count('B')
total = r * g * b

k = 0
count = 0
for i in range(N):
    for j in range(N):
        k = 2 * j - i
        if(i>=j or j >=k or i >=k): continue
        if(i==j or j==k or k==i or k<0 or k>=N): continue
        if(S[i] == S[j] or S[j] == S[k] or S[k] == S[i]): continue
        
        count += 1
        
print(total - count)


Measured memory_bytes: 68236
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    String x = sc.next();

    Deque<Character> stack = new LinkedList<>();
    for (int i = 0; i < x.length(); i++) {
      char c = x.charAt(i);
      if (!stack.isEmpty() && stack.peek() == 'S' && c == 'T') {
        stack.pop();
      } else {
        stack.push(c);
      }
    }

    os.println(stack.size());
  }

  private static class Scanner {

    private final InputStream is;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    Scanner(InputStream is) {
      this.is = is;
    }

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = is.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) {
        return buffer[ptr++];
      } else {
        return -1;
      }
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
        ptr++;
      }
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
        throw new NumberFormatException();
      }
      return (int) nl;
    }

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


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

int main() {
    int N; cin >> N;
    int arr[N];
    int q[] = {0, 0, 0, 0};
    for (int i=0; i<N; i++) {
        scanf("%d", arr+i);
        q[arr[i]] ++;
    }
    
    double ans[N+1][N+1][N+1];
    ans[0][0][0] = 0;
    for (int three=0; three<=N; three++) {
        for (int two=0; two<=N; two++) {
            for (int one=0; one<=N; one++) {
                if (one == 0 && two == 0 && three == 0)
                    continue;
                
                ans[three][two][one] = 1;
                double p0 = (N-three-two-one)/(double)N;
    
                if (one > 0)
                    ans[three][two][one] += (double)one/N * ans[three][two][one-1];
                if (two > 0)
                    ans[three][two][one] += (double)two/N * ans[three][two-1][one+1];
                if (three > 0)
                    ans[three][two][one] += (double)three/N * ans[three-1][two+1][one];
    
                ans[three][two][one] /= (1-p0);
            }
        }
    }

    cout << setprecision(10) << ans[q[3]][q[2]][q[1]] << endl;
    return 0;
}

Measured memory_bytes: 213248
Public Class Program
  Shared Sub Main()
    Dim n As Long = Long.Parse(Console.ReadLine())
    Dim arrayA As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
    Dim arrayB As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
    Dim remainder As Long = arrayA(0)
    Dim output As Long = 0
    For i As Long = 0 To n - 1
      remainder += arrayA(i + 1)
      remainder -= arrayB(i)
      If remainder < 0 Then 
        output += (arrayB(i) + remainder)
        remainder = 0
      Else
        output += arrayB(i)
      End If
      If remainder - arrayA(i + 1) > 0 Then remainder = arrayA(i + 1)
    Next
    Console.WriteLine(output.ToString())
  End Sub
End Class

Measured memory_bytes: 35748
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long long
#define ll long long
#define ld long double

int isr(ll n) {
  ll a=n/10;
  while (a) {
    if (abs((a%10)-(n%10))>1) return 0;
    a/=10;n/=10;
  }
  return 1;
}

ll bfs(ll ct,ll tn,ll cn) {
  ll bd=cn%10;
  ll nn1=cn*10+bd-1,nn2=cn*10+bd+1;
  if (ct+1==tn) return nn1;
  if (ct+2==tn) return nn2;
}

int main()
{
  ll k;
  cin>>k;

  ll a[2][10];
  ll ct=0,ans;

  queue<ll> qc,qn;
  for (int i = 1; i < 10; i++)
  {
    qc.push(i);
    ct++;
    if (ct==k) {
      ans=i;
      break;
    }
  }
  while (ct<k)
  {
    while (qc.size())
    {
      ll cpn=qc.front();
      ll nn0=cpn*10+cpn%10;
      if (cpn % 10 > 0)
      {
        ct++;
        qn.push(nn0 - 1);
        if (ct==k) {
          ans=nn0-1;
          break;
        }
      }
      ct++;
      qn.push(nn0);
      if (ct == k)
      {
        ans = nn0;
        break;
      }

      if (cpn % 10 < 9)
      {
        ct++;
        qn.push(nn0 + 1);
        if (ct == k)
        {
          ans = nn0 + 1;
          break;
        }
      }
      qc.pop();
    }
    swap(qc,qn);
  }
    
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 768
// Linear Search
#include <stdio.h>

int linearSearch(int*, int, int);

int main(){
  int i, n, q, S[10000], T[10000], count=0;

  // 数列Tに含まれる整数の数と、その内容を入力
  scanf("%d", &n);
  for(i=0; i < n; i++){
    scanf("%d", &S[i]);
  }

  // 数列Sに含まれる整数の数と、その内容を入力
  scanf("%d", &q);
  for(i=0; i < q; i++){
    scanf("%d", &T[i]);
  }

  // 線形探索を実行
  for(i=0; i < q; i++){
    if(linearSearch(S, n, T[i]))count++;
  }

  // 結果の個数を表示
  printf("%d\n", count);

  return 0;
}

int linearSearch(int *A, int n, int key){
  int i=0;
  A[n] = key; // 配列の最後に番兵を設置

  // 配列Aのn番目には番兵であるkeyが入っているためwhileループは必ず終了する
  while(A[i] != key){
    i++;
  }
  if(i == n)return 0;
  return 1;
}



Measured memory_bytes: 2128
#include "./bits/stdc++.h"
using namespace std;
int N,M;

int main(){
    cin>>N>>M;
    int m[M];
    int d[M-1];
    for(int i=0;i<M;i++){
        cin >> m[i];
    }

    if(N>=M){
        cout << 0 << endl;
    }else{
        sort(m,m+M);
        for(int i=0;i<M-1;i++){
            d[i]=abs(m[i+1]-m[i]);
        }
        sort(d,d+M-1);
        int sum = 0;        
        for(int i=0;i<N-1;i++){
            sum+=d[M-2-i];
        }        
        cout << abs(m[0]-m[M-1])-sum << endl;
    }
    return 0;
}

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

int main()
{
	int a,b,n;
	while(cin>>a>>b,a){
	cin>>n;
	bool out[17][17];
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)out[i][j]=true;
	int u,v;
	for(int i=0;i<n;i++)
	{
		cin>>u>>v;
		u--;v--;
		out[u][v]=false;
	}
	int dp[17][17]={};
	if(out[0][0])dp[0][0]=1;
	for(int i=1;i<a;i++)if(out[i][0])dp[i][0]=dp[i-1][0];
	for(int i=1;i<b;i++)if(out[0][i])dp[0][i]=dp[0][i-1];
	for(int i=1;i<a;i++)
	{
		for(int j=1;j<b;j++)
		{
			if(out[i][j])
			{
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
			}
			else dp[i][j]=0;
		}
	}
	cout<<dp[a-1][b-1]<<endl;}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(void)
{
    char s[11];
    char t[4];

    cin >> s;

    int min = 0;
    for (int i = 0; i < 11; i++) {
        if (s[i+2] == '\0') {
            break;
        }
        t[0] = s[i];
        t[1] = s[i+1];
        t[2] = s[i+2];
        t[3] = '\0';
        if (i == 0 || (min > abs(753 - atoi(t)))) {
            min = abs(753 - atoi(t));
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    A, B, C = sorted(map(int, input().split()))
    print(C * 10 + A + B)

main()


Measured memory_bytes: 63988
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
	s[i]+=N;
	if(s[i]>'Z')
	    s[i]-='Z'-'A'+1;
    }
    cout << s << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void err() {
  cout << -1 << endl;
  exit(0);
}
void dfs (int crr, int dpt, vector<vector<int>>& grh, long long& cnt) {
  cnt += dpt;
  for (int nxt : grh[crr]) {
    dfs(nxt, dpt + 1, grh, cnt);
  }
}
int main() {
  int n;
  cin >> n;
  vector<long long> d(n);
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    mp[d[i]] = i;
  }
  sort(d.begin(), d.end());
  vector<long long> sz(n, 1);
  vector<vector<int>> grh(n);
  vector<pair<int, int>> edg;
  for (auto it = d.rbegin(); next(it) != d.rend(); it++) {
    auto i = mp.rbegin()->second;
    long long wnt = *it - n + 2 * sz[i];
    if (mp.find(wnt) == mp.end()) err();
    auto p = mp[wnt];
    sz[p] += sz[i];
    grh[p].push_back(i);
    edg.emplace_back(i, p);
    mp.erase(--mp.end());
  }
  int rt = mp.begin()->second;
  long long cnt = 0;
  dfs(rt, 0, grh, cnt);
  if (d[0] != cnt) err();
  for (auto const& e : edg) {
    cout << e.first + 1 << ' ' << e.second + 1 << endl;
  }
  return 0;
}


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



int main() {
    string s;
    cin>>s;
    int n=0,m=0;
    for(int i=1;i<s.size();i++) {
        if (s.at(i) == s.at(i - 1)) {
            n++;
        } else {
            n = 0;
        }
        if (n > m) {
            m = n;
        }
    }

    if(m>=2){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

}






Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  bool can=false;
  for(int i=7;i>=0;i--){
    string sub=s.substr(0,i);
    if(sub=="keyence") {
      cout<<"YES";
      return 0;
    }
    if(sub=="keyenc"){
      string sub2=s.substr(s.size()-(7-i),7-i);
      if(sub2=="e"){
        cout<<"YES";
        return 0;
      }
    }
    if(sub=="keyen"){
      string sub2=s.substr(s.size()-(7-i),7-i);
      if(sub2=="ce"){
        cout<<"YES";
        return 0;
      }
    }
    if(sub=="keye"){
      string sub2=s.substr(s.size()-(7-i),7-i);
      if(sub2=="nce"){
        cout<<"YES";
        return 0;
      }
    }
    if(sub=="key"){
      string sub2=s.substr(s.size()-(7-i),7-i);
      if(sub2=="ence"){
        cout<<"YES";
        return 0;
      }
    }
    if(sub=="ke"){
      string sub2=s.substr(s.size()-(7-i),7-i);
      if(sub2=="yence"){
        cout<<"YES";
        return 0;
      }
    }
    if(sub=="k"){
      string sub2=s.substr(s.size()-(7-i),7-i);
      if(sub2=="eyence"){
        cout<<"YES";
        return 0;
      }
    }
    string sub2=s.substr(s.size()-(7-i),7-i);
    if(sub2=="keyence"){
      cout<<"YES";
      return 0;
    }
  }
  cout<<"NO";
}

Measured memory_bytes: 256
#include <stdio.h>

////(-"-;)ミスッテ…タ…////

void s(int x, int y, int pap[][10])
{
	int i, j;
	int x_dif, y_dif;
	
	for (j = 0; j < 3; j++){
		for (i = 0; i < 3; i++){
			x_dif = x + (i % 3) - 1;
			y_dif = y + (j - 1);
			
			if (x_dif >= 0 && x_dif < 10){
				if (y_dif >= 0 && y_dif < 10){
					if ((i % 3) - 1 == 0 || (j - 1) == 0){
						pap[y_dif][x_dif]++;
					}
				}
			}
		}
	}
	
}

void m(int x, int y, int pap[][10])
{
	int i, j;
	int x_dif, y_dif;
	
	for (j = 0; j < 3; j++){
		for (i = 0; i < 3; i++){
			x_dif = x + (i % 3) - 1;
			y_dif = y + (j - 1);
			
			if (x_dif >= 0 && x_dif < 10){
				if (y_dif >= 0 && y_dif < 10){
					pap[y_dif][x_dif]++;
				}
			}
		}
	}
	
}

void l(int x, int y, int pap[][10])
{
	int i, j;
	int x_dif, y_dif;
	
	for (j = 0; j < 3; j++){
		for (i = 0; i < 3; i++){
			x_dif = x + (i % 3) - 1;
			y_dif = y + (j - 1);
			
			if (x_dif >= 0 && x_dif < 10){
				if (y_dif >= 0 && y_dif < 10){
					pap[y_dif][x_dif]++;
				}
			}
		}
	}
	if (x - 2 >= 0){
		pap[y][x - 2]++;
	}
	if (x + 2 < 10){
		pap[y][x + 2]++;
	}
	
	if (y - 2 >= 0){
		pap[y - 2][x]++;
	}
	if (y + 2 < 10){
		pap[y + 2][x]++;
	}
}

int main(void)
{
	int pap[10][10] = {0};
	int x, y , size, i, j;
	int big, count;
	
	big = 0;
	count = 0;
	
	while (scanf("%d,%d,%d", &x, &y, &size) != EOF){
		switch (size){
		  case 1:
		  	s(x, y, pap);
			break;
		  case 2:
		  	m(x, y, pap);
		  	break;
		  case 3:
		  	l(x, y, pap);
			break;
			
		}
		
		
		/*グラフィカルー
		for (i = 0; i < 10; i++){
			for (j = 0; j < 10; j++){
				printf("%d", pap[i][j]);
			}
			printf("\n");
		}
		*/
	}
	
	for (i = 0; i < 10; i++){
		for (j = 0; j < 10; j++){
			if (pap[i][j] > big){
				big = pap[i][j];
			}
			if (pap[i][j] == 0){
				count++;
			}
		}
	}
	printf("%d\n%d\n", count, big);
	
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000;
int main(){
  int N, S;
  cin >> N >> S;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  int ans = INF;
  int s = 0, t = 0, sum = 0;
  //[s,t)の和が0
  while (1){
    while (t < N && sum < S){
      sum += a[t];
      t++;
//      cout << "s=" << s << ", t=" << t << endl;
    }
    if (sum < S){
      break;
    }
    ans = min(ans, t - s);
    sum -= a[s];
    s++;
//    cout << "s=" << s << ", t=" << t << endl;
  }
  if (ans == INF){
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 3148
import sys
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))
L.sort()
total = 0
for i in range(N):
  for j in range(i + 1, N):
    a = L[i] + L[j]
    total += max(bisect_left(L, a) - j - 1, 0)

print(total)

Measured memory_bytes: 3188
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
int single[200001] = {};
int target[200001] = {};

void solve(){
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return;
		vector<int> hp(n);
		REP(i, n) {
			cin >> hp[i];
		}
		REP(i, 200001) {
			single[i] = 1e9;
			target[i] = 1e9;
		}
		single[0] = 0;
		target[0] = 0;
		int m;
		cin >> m;
		REP(i, m) {
			string t;
			cin >> t;
			int a, b;
			string c;
			cin >> a >> c >> b;
			b = min(b, 100000LL);
			if (c == "Single") {
				for (int q = 0; q < 100000; ++q) {
					single[q + b] = min(single[q + b], single[q] + a);
				}
			}
			else {
				for (int q = 0; q < 100000; ++q) {
					target[q + b] = min(target[q + b], target[q] + a);
				}
			}
		}
		for (int q = 200000 - 1; q >= 0; --q) {
			target[q] = min(target[q], target[q + 1]);
			single[q] = min(single[q], single[q + 1]);
		}
		int ans = 1e9;
		for (int q = 0; q <= 100000; ++q) {
			int tmp = target[q];
			REP(i, n) {
				int hoge = max(hp[i] - q, 0LL);
				tmp += single[hoge];
			}
			ans = min(ans, tmp);
		}
		cout << ans << endl;
	}
}

#undef int
int main() {
	init();

	solve();
}


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

using namespace std;

int a[100001];

int main() {
	int i, j, n, r = 1;
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n);
	reverse(a, a + n);
	for (i = 0; a[i + 1] > i + 1; i++);
	if ((a[i] - i) % 2 == 0) r = 0;
	for (j = i + 1; a[j] > i; j++);
	if ((j - i) % 2 == 0) r = 0;
	puts(r ? "Second" : "First");
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second

using namespace std;

typedef long long LL;
typedef double db;
typedef pair<LL,LL> pir;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 131077;
const int L = 17;

pir key[N*L*2];
int h[N],tot,nxt[N*L*2];
int ls[N],rs[N];
int n;
int val[N];
LL lim;
int siz[N];
pir t[N*2],np[N*2];
int k,u;

void inse(int x){nxt[tot]=h[x];h[x]=tot;}

bool cmp(pir a,pir b){return a.fi<b.fi;}

void dfs(int x){
	if (!ls[x]){
		key[++tot]=make_pair(val[x],val[x]);
		inse(x);
		siz[x]=1;
		return;
	}
	dfs(ls[x]),dfs(rs[x]);
	if (siz[ls[x]]>siz[rs[x]])swap(ls[x],rs[x]);
	int l=ls[x],r=rs[x];
	k=u=0;
	for(int i=h[l];i;i=nxt[i])t[++k]=key[i];
	int w=h[r];
	fd(i,k,1){
		while(w&&nxt[w]&&key[nxt[w]].fi+t[i].fi<=lim)w=nxt[w];
		if (key[w].fi+t[i].fi<=lim)np[++u]=make_pair(t[i].se+val[x],key[w].se+val[x]);
	}
	if (u){
		fo(i,1,u)np[u+i]=make_pair(np[i].se,np[i].fi);
		u<<=1;
		sort(np+1,np+1+u,cmp);
		int u_=1;
		LL pre=np[1].se;
		fo(i,2,u){
			if (pre<=np[i].se)continue;
			pre=np[i].se;
			np[++u_]=np[i];
		}
		siz[x]=u_;
		fd(i,u_,1){
			key[++tot]=np[i];
			inse(x);
		}
	}
	else siz[x]=0;
}

bool check(){
	tot=0;
	fo(i,1,n)h[i]=0;
	dfs(1);
	return siz[1]>0;
}

int main(){
	n=get();
	fo(i,2,n){
		int x=get();
		val[i]=get();
		if (!ls[x])ls[x]=i;else rs[x]=i;
	}
	LL l=0,r=1e+9,ans=0;
	lim=6;check();
	while(l<=r){
		lim=(l+r)/2;
		if (check())ans=lim,r=lim-1;
		else l=lim+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 32000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string t = "CODEFESTIVAL2016";

int main(){
	string s;
	cin >> s;
	int ans = 0;
	REP(i, s.size()){
		if (t[i] != s[i])ans++;
	}
	cout << ans << endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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

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

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

	int N=in();
	vector<int> A=vecin(N);
	set<int> S;
	int J=0;

	REP(i,N){
		int V=A[i]/400;
		if(V>=8) J++;
		else S.insert(V);
	}

	int minC = S.empty()?1:S.size();
	int maxC = S.size()+J;
	out(minC,maxC);
	
	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 k=sc.nextInt(),s=sc.nextInt();
	int count=0;
	for(int x=0;x<=k;x++)
		for(int y=0;y<=k;y++)
			if(s-x-y<=k&&0<=s-x-y)count++;
			
	System.out.print(count);
	sc.close();
  }
}


Measured memory_bytes: 35568
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	long long n;
	cin >> n;
	vector<long long> a(n);
	for(long long i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	vector<int> check(a[n-1]+10,0);
	for(long long i=0;i<n;i++){
		for(long long j=1;j*a[i]<=check.size();j++){
			check[j*a[i]]++;
		}
	}	
	long long ans=0;
	for(long long i=0;i<n;i++){
		if(check[a[i]]==1){
			ans++;
			//cout << a[i] << endl;
		}
	}	
	cout << ans << endl;
	return 0;
}


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

typedef long long int ll ;

ll gcd(ll aaa,ll bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

ll lcm(ll m,ll n)
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}

int main() { 

	int N,K,Kcou=0,cou=0;
	cin >> N >> K;
	map<int,int>m;
	pair<int,int>p[N];
	int a[N];
	for(int i = 0; i < N; i++) {
		cin >> a[i];
		p[i] = make_pair(a[i],i+1);
	}
	sort(p,p+N);
	reverse(p,p+N);

	while(K != -1) {
		if(Kcou == 0) {
			for(int i = 0; i < N; i++) {
				p[i].first--;
				m[cou] = p[i].second;
				cou++;
			}
			K--;
			Kcou++;
		}else {
			int is = 0;
			if(Kcou % 2) {
				sort(p,p+N-1);
				for(int i = N-2; i >= 0; i--) {
					if(p[i].first == 0) {
						cout << -1 << endl;
						return 0;
					}
					p[i].first--;
					m[cou] = p[i].second;
					cou++;
				}
				K--;
				Kcou++;
			}else {
				sort(p+1,p+N);
				reverse(p+1,p+N);
				for(int i = 1; i < N; i++) {
					if(p[i].first == 0) {
						cout << -1 << endl;
						return 0;
					}
					p[i].first--;
					m[cou] = p[i].second;
					cou++;
					if(p[i].first <= 0) {
						is = 1;
					}
				}
				K--;
				Kcou++;
			}
		}
	}
	cout << cou << endl;
	for(int i = 0; i < cou; i++) {
		cout << m[i];
		if(i != cou-1){
			cout << ' ';
		}
	}
	cout << endl;
  	
	return 0;
}


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

const int MAX_M = 200;

int n, m;
set<pair<int, int> > stars;
pair<int, int> constellation[MAX_M + 1];

void solve() {
	for (set<pair<int, int> >::iterator it = stars.begin(); it != stars.end(); ++it) {
		const int dx = it->first - constellation[0].first;
		const int dy = it->second - constellation[0].second;
		for (int i = 0; i < m; i++) {
			int newX = constellation[i].first + dx;
			int newY = constellation[i].second + dy;
			if (stars.find(make_pair(newX, newY)) == stars.end()) {
				goto NEXT;
			}
		}
		cout << dx << ' ' << dy << endl;
		return;
NEXT:
		continue;
	}
}

int main () {
	int x, y;
	while (cin >> m, m) {
		stars.clear();
		for (int i = 0; i < m; i++) {
			cin >> x >> y;
			constellation[i] = make_pair(x, y);
		}
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> x >> y;
			stars.insert(make_pair(x, y));
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	if(a+b<24)
	{
        c=a+b;
		printf("%d",c);
	}
	else if(a+b>24)
	{
		c=(a+b)%24;
        printf("%d",c);
	}
	else
	{
		printf("0");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {

  int n, m, ans = 1e9, bad = 0;
  int popp;
  cin >> m >> n;
  for(int i = 1;i <= n;i++){
    cin >> popp >> m;
    ans = min(ans, m);
    bad = max(bad, popp);
  }
  cout << max(0, ans - bad + 1);
  return 0;
}


Measured memory_bytes: 3628
n = int(input())
x = [int(i) for i in input().split()]
a,b,c = 0,0,0
for i in x:
	if i%4==0: a += 1
	elif i%2==0: b += 1
	else: c += 1
if b != 0:
	if a>=c: print("Yes")
	else: print("No")
else:
	if a>=c-1: print("Yes")
	else: print("No")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
const int inf = INT_MAX;
const ll INF = 1LL >> 60;
const ll mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 754;
    rep(i, n-2){
        int tmp = (s[i] - '0')*100 + (s[i+1] - '0')*10 + (s[i+2] - '0');
        chmin(ans, abs(tmp-753));
    }

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

Measured memory_bytes: 256
#![allow(non_snake_case,unused_variables,dead_code)]
use std::io::{self, BufRead};
use std::str;

fn main() {
    let stdin = io::stdin();
    let mut s = String::new();
    let _ = stdin.read_line(&mut s);
    let vec: Vec<i64> = s.split_whitespace().map(|v| str::parse::<i64>(v).unwrap()).collect();

    let mut N = vec[0];
    let mut M = vec[1];

    let mut res = 0;
    while N >= 1 && M >= 2 {
        N -= 1;
        M -= 2;
        res += 1;
    }
    res += M / 4;
    println!("{}", res);
}


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

int main() {
  char zi;
  cin >> zi;
  if(zi == 'a' || zi == 'i' || zi == 'u' || zi == 'e' || zi == 'o') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
a=gets.to_i
array=[]
a.times{
  array << gets.to_i
  }
#p array
array=array.sort
b = array.inject{|sum,y| sum+=y}
check=1
if b%10 != 0
  puts b
else
  array.each do |n|
      if (b - n)%10!=0
        puts b-n
        check=0
        break
      end
  end
  if check==1
  	puts 0
  end
end

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  ll n,c=0LL;cin>>n;
  reps(i,1,n+1){
    if(i%3&&i%5)c+=i;
  }
  cout<<c;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  private static final String[] days = new String[] {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String day = sc.nextLine();
    sc.close();
    int dayIndex = Arrays.asList(days).indexOf(day);
    System.out.println(7 - dayIndex);
  }
}


Measured memory_bytes: 23252
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()

def add(m):
    m -= 1
    if m and n % m == n // m:
        return m
    return 0

i = 1
ans = 0
while i * i <= n:
    ans += add(i)
    if i * i != n:
        ans += add(n // i)
    i += 1
    
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;


int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n+2); // 0 v[1] v[2] ... v[n] 0
    int dsum = 0;
    REP(i,n) {
        cin >> v.at(i+1);
        dsum += abs(v.at(i+1) - v.at(i));
    }
    dsum += abs(v.at(n));

    REP(i,n) {
        int d1 = abs(v.at(i+1) - v.at(i));
        int d2 = abs(v.at(i+2) - v.at(i+1));
        int d3 = abs(v.at(i+2) - v.at(i));
        int ans = dsum - d1 - d2 + d3;
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <unordered_map>
#include <queue>
#include <vector>

using namespace std;
int main(){
  int u, i, id, k, j;
  cin >> u;
  unordered_map<int, vector<int> > mymap;
  queue<vector<int> > myqueue;
  for (i = 0; i < u; ++i){
    cin >> id >> k;
    vector<int> points;
    for (j = 0; j < k; ++j){
      int a;
      cin >> a;
      points.push_back(a);
    }
    mymap[id] = points;
    if(id == 1){
      myqueue.push(points);
    }
  }
  
  bool visited[u+1];
  for (j = 1; j <= u; ++j){
    visited[j] = false;
  }
  visited[1] = true;

  int dist[u+1];
  for (j = 1; j <= u; ++j){
    dist[j] = -1;
  }
  dist[1] = 0;
  int d = 1;

  while(!myqueue.empty()){
    vector<int> combined;
    for (i = 0; i < myqueue.front().size(); ++i){
      if(!visited[myqueue.front()[i]]){
        dist[myqueue.front()[i]] = d;
        visited[myqueue.front()[i]] = true;
        if(combined.empty()){
          combined = mymap[myqueue.front()[i]];
        }else{
          combined.insert(combined.end(), mymap[myqueue.front()[i]].begin(), mymap[myqueue.front()[i]].end());
        }
      }
    }
    if(!combined.empty()){
      myqueue.push(combined);
    }
    myqueue.pop();
    d++;
  }

  for (j = 1; j <= u; ++j){
    cout << j << " " << dist[j] << endl;
  }

}

Measured memory_bytes: 1240
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            String[] arr = line.split(" ");
            int a = Integer.parseInt(arr[0]);
            String op = arr[1];
            int b = Integer.parseInt(arr[2]);
            if ("?".equals(op))
                break;
 
            if ("+".equals(op))
                System.out.println(a + b);
            else if ("-".equals(op))
                System.out.println(a - b);
            else if ("*".equals(op))
                System.out.println(a * b);
            else if ("/".equals(op))
                System.out.println(a / b);
        }
    }
}

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

int main(){
    int n,m;
    cin>>n>>m;
    //vector<int> cnt(m+1,0);
    map<int,int> cnt;
    rep(i,n){
        int k;
        cin>>k;
        rep(i,k){
            int a;
            cin>>a;
            cnt[a]++;
        }
    }

    int ans=0;
    /*for(int i=1;i<=m;i++){
        if(cnt[i]==n) ans++;
    }*/
    for(auto iter=cnt.begin();iter!=cnt.end();iter++){
        if(iter->second==n) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}

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


int main() {

  int N;
  cin >> N;

  vector<int> p(N), q(N);
  
  for (int i = 0; i < N ; i++) cin >> p[i], p[i]--;
  for (int i = 0; i < N; i++) cin >> q[i], q[i]--;
  
  
  map<vector<int>, int> ord;
  int iter = 0;
  
  vector<int> v(N);
  for (int i = 0; i < N; i++) v[i] = i;
  
  do {
    ord[v] = iter++;
  } while(next_permutation(v.begin(), v.end()));
  

  cout << abs(ord[p] - ord[q]) << endl;
  
  
  
  
  
  
}



Measured memory_bytes: 5248
//#include <climits>
#include <vector>
#include <iostream>
using namespace std;

void swap(int *x, int *y) {
    int tmp = *x;
    *x = *y;
    *y = tmp;
}

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

    vector<int> A(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> A[i];
    }

    //選択ソート
    int count = 0;
    for (int i = 0; i < N; ++i)
    {
        int minj = i;
        for (int j = i; j < N; ++j)
        {
            if(A[j] < A[minj]) {
                minj = j;
            }
        }

        if(i != minj) {
            swap(A[i], A[minj]);
            count++; //交換回数
        }
    }

    //出力
    for (int i = 0; i < N; ++i)
    {
        cout << A[i];
        if(i < N-1) {
            cout << " ";
        }
    }
    cout << endl;

    cout << count << endl;
   
    return 0;
}


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

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

N = int(input())
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, 1))
    # 無向グラフなのでこっちも入れる
    nodes[b].append((a, 1))

fennec = [float('inf')] * (N+1)
snuke = [float('inf')] * (N+1)
# 木の最短経路を算出するDFS
def dfs(memo: list, cur: int, prev: int, dist: int) -> None:
    memo[cur] = dist
    for nxt, cost in nodes[cur]:
        if nxt == prev:
            continue
        dfs(memo, nxt, cur, dist+cost)

dfs(fennec, 1, -1, 0)
dfs(snuke, N, -1, 0)

fn = sn = 0
for i in range(2, N):
    # 距離の近い方がそのマスを取れる(同じ距離なら先手が取る)
    if fennec[i] <= snuke[i]:
        fn += 1
    else:
        sn += 1
# 取れるマスの多い方(同点だと後手が勝つ)
if fn > sn:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 137204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int k= 1;
        HashMap<String,Integer> hashMap = new HashMap<>();
        hashMap.put("SUN",7);
        hashMap.put("MON",6);
        hashMap.put("TUE",5);
        hashMap.put("WED",4);
        hashMap.put("THU",3);
        hashMap.put("FRI",2);
        hashMap.put("SAT",1);
        String s1;
        int a,b;
        while(k-->0){
            a=s.nextInt();
            b=s.nextInt();
            System.out.println(6-a-b);
        }
    }

    private static int binary_search(
            int arr[], int l,
            int h, int x)
    {
        while (l <= h) {
            int mid = (l + h) / 2;
            if (arr[mid] <= x)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }
    static int gcd(int a, int b)
    {
        if(b==0) {
            return a;
        }
        return gcd(b,a%b);
    }
    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 27096
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define repvin(V,N) for(int i = 0; i < N; i++) {int tmpdummy; cin >> tmpdummy; V.push_back(tmpdummy);}

using namespace std;

int main(){

    int n,d;

    cin >> n >> d;

    vector<vector<int>> x;

    rep(i,n){
        vector<int> tmpv;
        rep(j,d){
            int tmp;
            cin >> tmp;
            tmpv.push_back(tmp);
        }
        x.push_back(tmpv);
    }

    vector<int> squ;

    int tmp = 1;

    while(tmp * tmp <= 16000){
        squ.push_back(tmp * tmp);
        tmp++;
    }

    int ans = 0;

    rep(i,n - 1){
        for(int j = i + 1; j < n; j++){
            int sum = 0;
            rep(k,d){
                tmp = x[i][k] - x[j][k];

                sum = sum + tmp * tmp;
            }
            rep(l,squ.size()){
                if(sum == squ[l]){
                    ans++;
                    break;
                }
            }
        }
    }

    cout << ans << endl;


    
    return 0;
}

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

def main():
    """Function."""
    p1 = list(map(int, input().split()))
    p2 = list(map(int, input().split()))
    p3 = list(map(int, input().split()))

    counter = [0, 0, 0, 0]
    for l in [p1, p2, p3]:
        for i in l:
            if i == 1:
                counter[0] += 1
            elif i == 2:
                counter[1] += 1
            elif i == 3:
                counter[2] += 1
            elif i == 4:
                counter[3] += 1

    counter.sort()
    if counter == [1, 1, 2, 2]:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064