akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

#define dump1(v) for(auto i:v) std::cout << i << ' '; std::cout << "\n";
#define dump2(v) for(auto i:v) { for(auto j:i) std::cout << j << ' '; std::cout << "\n"; }


signed main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > a(n,std::vector<int>(n-1));
	rep(i,n) rep(j,n-1) {
		std::cin >> a[i][j];
		a[i][j]--;
	}

	std::vector<std::vector<int> > map(n,std::vector<int>(n,-1));
	int count = 0;
	rep(i,n) rep(j,n) {
		if(i==j) {
			map[i][j]=-1;
			continue;
		}
		if(map[j][i]==-1) {
			map[i][j] = count;
			count++;
		} else {
			map[i][j] = map[j][i];
		}
	}

	std::vector<std::vector<int> > from(count,std::vector<int>());
	rep(i,n) rep(j,n-2) {
		from[map[i][a[i][j]]].emplace_back(map[i][a[i][j+1]]);
	}

	bool closed = false;
	std::vector<int> dist(count,-1);
	std::function<int(int,std::vector<int>&)> dfs = [&] (int i,std::vector<int>& went) {
		went[i] = true;
		int max = 1;
		for(auto to:from[i]) {
			if(dist[to]==-1 && went[to]) {
				closed = true;
				break;
			}
			if(dist[to]!=-1) max = std::max(max,dist[to]+1);
			else {
				max = std::max(max,dfs(to,went)+1);
			}
		}
		return dist[i] = max;
	};
	rep(i,count) {
		if(dist[i]==-1) {
			std::vector<int> went(count,false);
			dfs(i,went);
		}
		if(closed) {
			print(-1);
			return 0;
		}
	}
	int max = 0;
	for(auto i:dist) max = std::max(max,i);
	print(max);

	return 0;
}


Measured memory_bytes: 51328
#include<bits/stdc++.h>
using namespace std;
int main(){
	int d1,d2,m1,m2;
	cin>>d1>>m1;
	cin>>d2>>m2;
	if(d1==12&&d2==1){
		if(m2==1){
			printf("1\n");
		}
	}else if(d2==d1+1){
		if(m2==1){
			printf("1\n");
		}
	}else{
		printf("0\n");
	}
	return 0;
} 

Measured memory_bytes: 256
n=int(input())
a=[int(input()) for _ in range(n)]
from collections import Counter
ca=Counter(a)
ma=max(a)
if ca[ma]>1:
  ans=[ma]*n
  print(*ans,sep='\n')
else:
  ks=set(ca.keys())
  ks.discard(ma)
  maa=max(ks)
  for x in a:
    if x==ma:
      print(maa)
    else:
      print(ma)


Measured memory_bytes: 125552
import math
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)

ans = A[0]

cnt = 1
for i in range(2, N):
    if i % 2 == 0:
        ans += A[i-cnt]
    else:
        ans += A[i-cnt-1]
        cnt += 1

print(ans)

Measured memory_bytes: 32968
#include<cstdio>
using namespace std;

const int maxn=300500;

int num[maxn][5]={0};
int main(){
	int n;
	char c;
	scanf("%d%c",&n,&c);
	for (int i=1;i<=n;i++) {
		scanf("%c",&c);
		if (c=='W') num[i][1]++; else num[i][2]++;
		num[i][1]+=num[i-1][1];
		num[i][2]+=num[i-1][2];	
	}
	
	int Min=n;
	for (int i=1;i<=n;i++){
		int sum=num[i-1][1]+num[n][2]-num[i][2];
		if (sum<Min) Min=sum;
	}
	printf("%d\n",Min);
	return 0;
}

Measured memory_bytes: 6016
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<list>
#include<bitset>
#include<map>
#include<stack>
using namespace std;
#define Hamo_Rabi ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define all(v) 			((v).begin()), ((v).end())
#define ll long long int
#define f0n(n,i) for(int i=0;i<n;i++)
#define f1n(n,i) for(int i=1;i<=n;i++) 
#define endl "\n"
int main()
{
	Hamo_Rabi;
	string s; cin >> s;
	if (s[2] == s[3] && s[5] == s[4])
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N;
  int T;
  int Y;
  scanf("%d",&N);
  if(N<=9){
    printf("%d",N);
  }
  if((N>=10)&&(N<=99)){
    printf("9");
  }
  if((N>=100)&&(N<=999)){
    T=9+(N-99);
    printf("%d",T);
  }
  if((N>=1000)&&(N<=9999)){
    printf("909");
  }
  if((N>=10000)&&(N<=99999)){
    Y=909+(N-9999);
    printf("%d",Y);
  }
  if(N==100000){
    printf("90909");
  }
}
  

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PA;
const int MOD = 1000000007;
const ll INF=2e18;

class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  void init(ll n) {
    par.resize(n, 1); rank.resize(n, 0);
  }
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};

ll N,M;
ll a[100010],b[100010];
ll ans[100010];
int main(){
    cin>>N>>M;
    for(ll i=0;i<M;i++){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    UnionFind UF;
    UF.init(N);
    ans[M-1]=N*(N-1)/2;
    for(ll i=M-1;i>=1;i--){
        ans[i-1]=ans[i];
        if(!UF.isSame(a[i],b[i])){
            ans[i-1] -=(UF.getSize(a[i])*UF.getSize(b[i]));
            UF.merge(a[i],b[i]);
        }
    }
    for(ll i=0;i<M;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5248
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        foreach (var n in Enumerable.Range(0, int.MaxValue).Select(x => Console.ReadLine()).TakeWhile(x => !string.IsNullOrEmpty(x)).Select(int.Parse))
        {
            var set = from a in Enumerable.Range(0, 10)
                      from b in Enumerable.Range(0, 10)
                      from c in Enumerable.Range(0, 10)
                      from d in Enumerable.Range(0, 10)
                      select a + b + c + d;
            Console.WriteLine(set.Where(x => x == n).Count());
        }
    }
}

Measured memory_bytes: 6116
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
0 0
3 1
2 3
0 3
3
2 1
0 2
3 2

output:
2
1
0
"""

import sys

EPS = 1e-9


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def check_contains(g, p):
    flag = False
    for j in range(edges):
        a, b = g[j] - p, g[(j + 1) % edges] - p
        if abs(cross(a, b)) < EPS and dot(a, b) < EPS:
            return 1
        elif a.imag > b.imag:
            a, b = b, a

        if a.imag < EPS < b.imag and cross(a, b) > EPS:
            flag = not flag
    return 2 if flag else 0


def solve(_p_info):
    for point in _p_info:
        px, py = map(float, point)
        p = px + py * 1j
        print(check_contains(polygon, p))
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    edges = int(_input[0])
    e_info = map(lambda x: x.split(), _input[1:edges + 1])
    points = int(_input[edges + 1])
    p_info = map(lambda x: x.split(), _input[edges + 2:])

    polygon = [float(x) + float(y) * 1j for x, y in e_info]
    solve(p_info)

Measured memory_bytes: 7868
#include <stdio.h>

int main()
{
	int A,B;
	scanf("%d%d",&A, &B);
	int TOWER = 0;
	for (int i = 1; i < B - A; i++)
	{
		TOWER += i;
	}
	//左側のタワーの高さが求まった
	printf("%d",TOWER - A);
    return 0;
}



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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;

#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	string s, t;
	while (cin >>s >> t) {
		int co = 0;
		for (int i = 0; i < 3; ++i) {
			if(s[i] == t[i]) co++;
		}
		cout << co << '\n';
	}
}



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

int main(){
  int n; cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    /* code */
    cin >> a[i];
  }
  sort( a.begin(), a.end() );
  reverse(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < n; i += 2) {
    /* code */
    ans += a[i];
  }
  for (int i = 1; i < n; i += 2) {
    /* code */
    ans -= a[i];
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(10);
    ll K;
    cin >> K;
    vector<ll> lunlun;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(int i = 1; i <= 9; i++) {
        que.push(i);
        lunlun.push_back(i);
    }
    ll pushnum = 9;
    while(pushnum < 3234566667) {
        ll pre = que.top();
        que.pop();
        int endn = pre%10;
        for (int i = -1; i <= 1; i++){
            if(endn==0&&i==-1) {
                continue;
            } else if(endn==9&&i==1) {
                continue;
            } else {
                pushnum = pre*10+(endn+i);
            }
            que.push(pushnum);
            lunlun.push_back(pushnum);
        }
    }
    cout << lunlun.at(K-1) << endl;
}

Measured memory_bytes: 2288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

int main() {

	string S;
	cin >> S;

	int N = stoi(S);

	int F = 0;
	rep(i, S.size()) {
		F += S[i] - '0';
	}
	if(N % F) co("No");
	else co("Yes");

	Would you please return 0;
}

Measured memory_bytes: 384
n = int(input())
R = [int(input()) for i in range(n)]

minv = R[0]
maxv = R[1] - R[0]
for j in range(1, n):
	if (maxv < R[j] - minv):
		maxv = R[j] - minv
	if (R[j] < minv):
		minv = R[j]
    
print(maxv)



Measured memory_bytes: 13600
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	for i := 1; i <= n; i++ {
		var x int = i
		if x % 3 == 0 {
			fmt.Printf(" %d", i)
		} else {
			for ; x != 0; {
				if x % 10 == 3 {
					fmt.Printf(" %d", i)
					break
				}
				x /= 10
			}
		}
	}
	fmt.Println("")
}




Measured memory_bytes: 1164
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <chrono>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <cassert>
# include <array>
# include <tuple>
# include <cctype>
# include <unistd.h>
# include <unordered_map>
# include <unordered_set>
using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define fast_work {ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

const ll INF = 1e18 + 5, NMAX = 1e6 + 5, MOD = 1000000007, N = 1e9 + 5, LOG = 25;
const ld EPS = 1e-8, pi = 3.14159265358979323846;

signed main() {
    fast_work

    int n;
    cin >> n;

    int answer = 0;

    for(int a = 1; a <= n; ++a)
        for(int b = 1; b * a < n; ++b) {
            ++answer;
        }

    cout << answer;
}


Measured memory_bytes: 3632
s = input()
if s[0] == s[1]:
  print(1,2)
  exit()
for i in range(2,len(s)):
  if s[i] == s[i-1] or s[i] == s[i-2]:
    print(i-1,i+1)
    break
else:
  print(-1,-1)

Measured memory_bytes: 3188
from collections import deque

h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['#'*w]
for _ in range(h-2):
    MAZE.append('#'+input()+'#')
else:
    MAZE.append('#'*w)

total = 0
for i in range(h):
    for j in range(w):
        if MAZE[i][j] == '.':
            total += 1

# よく考えたらBFSでOKだった
i, j = (1, 1)
INF = 10**18
dist = [[INF] * w for _ in range(h)]
dist[i][j] = 1
next_v = deque([[i, j]])
while next_v:
    i, j = next_v.popleft()
    direction = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for di, dj in direction:
        x, y = i+di, j+dj
        if MAZE[x][y] == "#":
            continue
        if dist[x][y] <= dist[i][j] + 1:
            continue
        dist[x][y] = dist[i][j] + 1
        next_v.append((x, y))

last = dist[h-2][w-2]
if last != INF:
    ans = total - last
else:
    ans = -1
print(ans)


Measured memory_bytes: 40816
#include<stdio.h>
int main()
{
    int p,q,r,m,n,l;
    scanf("%d%d%d",&p,&q,&r);
    m=p+q;
    n=p+r;
    l=q+r;
    if(m<=n&&m<=l)
        printf("%d\n",m);
    else if(n<=m&&n<=l)
        printf("%d\n",n);
    else  printf("%d\n",l);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#include<iostream>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=130;
int askv;
vector<char> vec[MAXN],V;
int query(vector<char> A)
{
	++askv;assert(askv<=850);
	printf("? ");for(auto p:A)putchar(p);puts("");
	fflush(stdout);
	int S=read();return S;
}
int N;
vector<char> merge(vector<char> &A,vector<char> &B)
{
	vector<char> ret;ret.clear();
	vector<char> ask;
	int n=SZ(A),m=SZ(B),i=0,j=0;
	for(;i<n&&j<m;)
	{
		ask.clear();
		for(auto p:ret)ask.emplace_back(p);
		ask.emplace_back(A[i]);
		for(int k=j;k<m;k++)ask.emplace_back(B[k]);
		int len=query(ask);
		if(N-len==SZ(ret)+m-j+1)ret.emplace_back(A[i++]);
		else ret.emplace_back(B[j++]);
	}
	for(;i<n;i++)ret.emplace_back(A[i]);
	for(;j<m;j++)ret.emplace_back(B[j]);
	return ret;
}
priority_queue<pii,vector<pii>,greater<pii>> hp;
int main()
{
	#ifdef Rose
		double BeginJudgeTime=clock();
	#endif
	int L=0;
	for(int i=1;i<=26;i++)
	{
		vector<char> ask;ask.clear();
		for(int j=1;j<=128;j++)ask.emplace_back('A'+i-1);
		int len=query(ask);++L;N+=128-len;
		for(int j=1;j<=128-len;j++)vec[L].emplace_back('A'+i-1);
		if(128-len)hp.push(mp(128-len,L));
	}
	for(int i=1;i<=26;i++)
	{
		vector<char> ask;ask.clear();
		for(int j=1;j<=128;j++)ask.emplace_back('a'+i-1);
		int len=query(ask);++L;N+=128-len;
		for(int j=1;j<=128-len;j++)vec[L].emplace_back('a'+i-1);
		if(128-len)hp.push(mp(128-len,L));
	}
	for(int i=1;i<=10;i++)
	{
		vector<char> ask;ask.clear();
		for(int j=1;j<=128;j++)ask.emplace_back('0'+i-1);
		int len=query(ask);++L;N+=128-len;
		for(int j=1;j<=128-len;j++)vec[L].emplace_back('0'+i-1);
		if(128-len)hp.push(mp(128-len,L));
	}
	while(SZ(hp)!=1)
	{
		pii u=hp.top();hp.pop();
		pii v=hp.top();hp.pop();
		V=merge(vec[u.second],vec[v.second]);
		vec[v.second].clear();vec[u.second]=V;
		hp.push(mp(SZ(vec[u.second]),u.second));
	}
	printf("! ");int ps=hp.top().second;
	for(auto p:vec[ps])putchar(p);puts("");
	fflush(stdout);
	#ifdef Rose
		double EndJudgeTime=clock();
		cerr<<"JudgeTime is"<<" ";
		cerr<<(EndJudgeTime-BeginJudgeTime)/CLOCKS_PER_SEC<<endl;
	#endif
	return 0;
}


Measured memory_bytes: 3776
import java.util.*;

public class Main{



	public static void main(String[] args) {
		
		int input;
		ArrayList<Integer> tempList;
		tempList = new ArrayList<Integer>();

		Scanner s = new Scanner(System.in);

		for (int i=0; i<3; i++){
			input = s.nextInt();
			tempList.add(input);
		}

		Collections.sort(tempList);

		int a,b,c;

		a = tempList.get(0);
		b = tempList.get(1);
		c = tempList.get(2);

		if ((b-a) == (c-b)){

			System.out.println("YES");

		}
		else{
			System.out.println("NO");
		}

	}

}

Measured memory_bytes: 22100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#define mp make_pair

using namespace std;
const int MAXN = 2e5 + 10;
const int INF = 1e9+ 7;
int a[310][310];
int b[310][310];
int main() {
  int n;
  set <pair <int, pair <int, int> > > roads;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      if (i < j)
        roads.insert(mp(a[i][j], mp(i, j)));
      b[i][j] = INF;
    }
    b[i][i] = 0;
  }
  long long ans = 0;
  while (!roads.empty()) {
    int x = roads.begin()->second.first;
    int y = roads.begin()->second.second;
    int len = roads.begin()->first;
    roads.erase(roads.begin());
    if (b[x][y] > len) {
      ans += len;
      //cout << x << ' ' << y << endl;
      b[x][y] = len;
      b[y][x] = len;
      for (int i = 1; i <= n; i++) {
        b[x][i] = min(b[x][i], b[y][i] + len);
        b[i][x] = min(b[i][x], b[x][i]);
        b[y][i] = min(b[y][i], b[x][i] + len);
        b[i][y] = min(b[i][y], b[y][i]); 
      }
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          b[i][j] = min(b[i][j], b[i][x] + b[x][j]);
          b[i][j] = min(b[i][j], b[i][y] + b[y][j]);
          b[j][i] = b[i][j];
        }
      }
      // for (int i = 1; i <= n; i++) {
      //   for(int j = 1; j <= n;j++) {
      //     if (b[i][j] == INF) {
      //       cout << "* ";
      //     } else {
      //       cout << b[i][j] << ' ';
      //     }
      //   }
      //   cout << endl;
      // }
      // cout << endl;
    }
  }
  // for (int k = 1; k <= n; k++) {
  //   for (int i = 1; i <= n; i++) {
  //     for (int j = 1; j <= n; j++) {
  //       b[i][j] = min(b[i][j], b[i][k] + b[])
  //     }
  //   }
  // }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] != b[i][j]) {
        cout<< -1;
        return 0;
      }
    }
  }
  cout << ans;
  return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(i + h - 1 > n) continue;
        for(int j = 1; j <= n; j++){
            if(j + w - 1 > n) continue;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/07/07  Problem: soundhound2018_master_qual B / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	string s;
	int w;
	cin >> s >> w;
	string ans = "";
	for (int i = 0; i < SZ(s); i += w) {
		ans += string(1, s[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  ll n;cin >> n;
  ll x = (ll)sqrt((double)n);
  ll out;
  while(x){
    if(n%x==0){
      out = x+ (n/x)-2LL;
      break;
    }
    --x;
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
int main()
{
	int N,i,j,x[30],y[30],max=-1,tmp;
	string S;
	cin >> N >> S;
 
	for(i=1; i<N; i++){
		tmp = 0;
		for(j=0; j<26; j++){
			x[j] = 0;
			y[j] = 0;
		}
		for(j=0; j<i; j++){
			x[S[j] - 'a']++;
		}
		for(j=i; j<N; j++){
			y[S[j] - 'a']++;
		}
		for(j=0; j<26; j++){
			if(x[j] > 0 && y[j] > 0)
				tmp++;
		}
		if(max < tmp)
			max = tmp;
	}
	cout << max ;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int A, B;
    cin >> A >> B;

    int cnt = 0;
    for (int i = 1; i <= N; i++){
        int a = i / 10000;
        int b = (i - a * 10000) / 1000;
        int c = (i - a * 10000 - b * 1000) / 100;
        int d = (i - a * 10000 - b * 1000 - c * 100) / 10;
        int e = i % 10;

        if (a + b + c + d + e >= A && a + b + c + d + e <= B){
            cnt += i;
        }
    }
    cout << cnt << endl;
}

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

using ll = long long;
using ull = unsigned long long;

using namespace std;

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

    ll n, x, i;

    cin>>n;

    for(i=0; i<n; i++)
    {
        cin>>x;
        if(x%2 == 0)
        {
            if(x%3==0 or x%5==0)
            {
                continue;
            }
            else
            {
                cout<<"DENIED\n";
                break;
            }
        }
    }
    if(i == n) cout<<"APPROVED\n";
    return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

int main(void)
{
	ll h,n;
	cin >> h >> n;
	vector<P> vs(n);
	rep(i, n) {
		cin >> vs[i].first >> vs[i].second;
	}
	vector<ll> dp(h + 10, INF);
	dp[0] = 0;
	rep(i, h + 1) {
		rep(j, n) {
			ll a = vs[j].first;
			ll b = vs[j].second;
			ll c = max(i - a, 0LL);
			dp[i] = min(dp[i], dp[c] + b);
		}
	}
	cout << dp[h] << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,f[2005][2005],g[2005],len[2005];
vector<int> bi[2005];
void dfs(int x,int fa)
{
	int i,j;
	memset(f[x],-0x3f,sizeof(f[x]));
	f[x][0]=1;
	len[x]=0;
	ff(bi[x],it){
		if(*it==fa)continue;
		dfs(*it,x);
		memcpy(g,f[x],sizeof(g));
		fd0g(i,len[x]){
			fd0g(j,len[*it])if(i+j+1<=m){
				g[max(i,j+1)]=max(g[max(i,j+1)],f[x][i]+f[*it][j]);
			}
		}
		memcpy(f[x],g,sizeof(g));
		len[x]=max(len[x],len[*it]+1);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	dfs(1,0);
	int ans=0;
	fz1(j,n)fz0g(i,m){
		ans=max(ans,f[j][i]);
	}
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 16128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

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

int main(){
    ll m; cin >> m;
    string c; cin >> c;
    vl num(10,0);
    vl nxt;
    ll n = c.size();
    for(ll i=n-1; i>=0; i--){
        num[c[i]-'0'] += mod_pow(10,n-1-i,MOD);
        num[c[i]-'0'] %= MOD;
    }
    rep(i,10){
        nxt.push_back(i);
    }
    bool flag = false;
    do{
        ll res = 0;
        rep(i,10){
            res += (nxt[i] * num[i]) % MOD;
            res %= MOD;
        }
        if(res == m){
            if(nxt[c[0]-'0']==0 && n>1) continue;
            rep(i,n){
                cout << (char)(nxt[c[i]-'0']+'0');
            }
            cout << endl;
            flag = true;
            break;
        }
    }while(next_permutation(all(nxt)));
    if(!flag) puts("-1");
}



Measured memory_bytes: 3328
#!/usr/bin/env python3
import math

N, M = list(map(int, input().split()))

# 偶数だけ
# 奇数だけ


def C(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


t = 0
if N >= 2:
    t += C(N, 2)
if M >= 2:
    t += C(M, 2)
ans = t
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int g[205][205];

int main()
{
    int k;
    cin >> k;
    ll sol = 0;
    for (int a = 1; a <= k; ++a)
        for (int b = 1; b <= k; ++b)
            g[a][b] = gcd(a, b);
    for (int a = 1; a <= k; ++a)
        for (int b = 1; b <= k; ++b)
            for (int c = 1; c <= k; ++c)
                sol += g[a][g[b][c]];
    cout << sol;
}


Measured memory_bytes: 3780
#include<stdio.h>
#include <string.h>

char lower(char c);

int main(){
  int i,count,s_l;
  char s[1001]={},word[11]={};

  count = 0;
  memset(word,'\0',11);
  scanf("%s",word);
  while(1){
    memset(s,'\0',1001);
    scanf("%s",s);
    if(strcmp(s,"END_OF_TEXT")==0){
      break;
    }
    s_l = strlen(s);
    for(i=0;i<s_l;i++){
      s[i] = lower(s[i]);
    }
    if(strcmp(s,word)==0){
      count++;
    }
  }
  printf("%d\n",count);

  return 0;
}


char lower(char c){
  if(c>='A' && c<='Z'){
    return c+'a'-'A';
  }
  else{
    return c;
  }
}



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

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

  int n, m;
  cin >> n >> m;
  int a[n];
  int sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  int selected = 0;
  rep(i, n) {
    if ((double)a[i] >= ((double)sum / (double)(4 * m))) {
      selected++;
    }
  }
  cout << ((selected >= m) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){
  int N;
  string s;
  cin>>N;
  cin>>s;
  int mmin=N;
  int temp_min=0;
  int no_east=0;
  int no_west;

  for(int j=1;j<N;j++){
    if(s[j] != 'W' ) temp_min++;
  }
  no_west=temp_min;
  //cout << no_east << "," << no_west << endl;
  mmin=no_east+no_west;
  for(int i=1;i<N;i++){
    if( s[i-1] != 'E' ) no_east++;
    if( s[i] == 'E' ) no_west--;
    if(mmin > no_east+no_west) mmin = no_east+no_west ;
    //cout << no_east << "," << no_west << endl;
  }


  cout << mmin << endl;

  return 0;
}


Measured memory_bytes: 900
n=int(input())

a=list(map(int,input().split()))

bit=[0 for _ in range(30)]
b=[]

for x in a:
  y=[0 for _ in range(30)]
  for i in range(30):
    if (x>>i)&1:
      y[i]+=1
      bit[i]+=1
  b.append(y)
     
ans1=[]
for g in b:
  ans=0
  for j in range(30):
    if (bit[j]%2)!=(g[j]):
      ans+=2**j
  ans1.append(str(ans))
  
print(' '.join(ans1))

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

int kaijo(int n)
{
  int r = 1;
  for (int i = 2; i <= n; i++)
  {
    r *= i;
  }
  return r;
}

int main()
{
  int n, p[8], q[8], a = 0, b = 0;
  vector<int> al = {},bl = {};
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
    int t = p[i];
    for (auto r : al)
    {
      if (p[i] > r)
      {
        t--;
      }
    }
    a += kaijo(n - i - 1) * t;
    al.push_back(p[i]);
  }
  for (int i = 0; i < n; i++)
  {
    cin >> q[i];
    int t = q[i];
    for (auto r : bl)
    {
      if (q[i] > r)
      {
        t--;
      }
    }
    b += kaijo(n - i - 1) * t;
    bl.push_back(q[i]);
  }
  cout <<abs(a-b)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;
int h[maxn], sum[maxn];
vector<int >son[maxn];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i =1; i <= n; i++)
	{
		cin >> h[i];
	}
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		if (h[u]>h[v])
			sum[u]++;
		if (h[u]<h[v])
			sum[v]++;
		son[u].push_back(v);
		son[v].push_back(u);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (sum[i] == son[i].size())
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9476
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;
typedef long long int64;
inline int64 read(int f = 1, int64 x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
pair<int64, int64> f[4];
int64 n, ans;
int main()
{
    f[0].first = 8*read(), f[0].second = 1;
    f[1].first = 4*read(), f[1].second = 2;
    f[2].first = 2*read(), f[2].second = 4;
    f[3].first = read(), f[3].second = 8;
    n = read()*4, sort(f, f+4);
    for(int i = 0; i < 4&&n; ++i) ans += (n/f[i].second)*(f[i].first/(8/f[i].second)), n %= f[i].second;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int N, C;
int s[100050];
int t[100050];
int c[100050];

bool canRecord(vi& order, int k) {
	vector<pii> a(k);
	rep(i,0,k) {
		a[i] = mp(0,0);
	}
	rep(i,0,N) {
		int idx = order[i];
		int l = s[idx];
		int r = t[idx];
		int x = c[idx];
		bool flag = false;
		rep(j,0,k) {
			if(a[j].S == 0 || a[j].S == x) {
				if(a[j].F <= l) {
					a[j].F = r;
					a[j].S = x;
					flag = true;
				}
			} else {
				if(a[j].F+1 <= l) {
					a[j].F = r;
					a[j].S = x;
					flag = true;
				}
			}

			if(flag) {
				break;
			}
		}
		if(!flag) {
			return false;
		}
	}
	return true;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> N >> C;
	rep(i,0,N) {
		cin >> s[i] >> t[i] >> c[i];
	}
	vi order(N);
	rep(i,0,N) {
		order[i] = i;
	}
	sort(all(order), [&](int x, int y) {
		if(s[x] == s[y]) return t[x] < t[y];
		return s[x] < s[y];
	});

	int low = 1; 
	int hig = C;
	while(low < hig) {
		int mid = (low + hig) / 2;
		if(canRecord(order, mid)) {
			hig = mid;
		} else {
			low = mid+1;
		}
	}
	cout << low << '\n';
	return 0;
}


Measured memory_bytes: 1792
from itertools import permutations

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

nums =[i for i in range(1,N+1)]
pers =permutations(nums,N)
count = 0
for i in pers:
  count += 1
  if P == list(i):
    a = count
  if Q == list(i):
    b = count

print(abs(a-b))

Measured memory_bytes: 9204
from collections import Counter
dic = {}


def add(x):
    if x[0] not in dic:
        dic[x[0]] = Counter()

    dic[x[0]][x] += 1

while 1:
    dic = {}
    n = int(input())
    if n == 0:break
    for l in [input() for i in range(n)]:
        for w in l.split():
            add(w)
    k = input()
    if k not in dic:
        print('NA')
    else:
        print(' '.join(map(lambda x:x[0],sorted(dic[k].items(), key=lambda x: (-x[1],x[0]))[:5])))

Measured memory_bytes: 6724
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=-INF;
static int t=1e5;
class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int evaluate(){
    int sum=0;
    vector<int> l(ntype+1,0);
    for(int day=1;day<=D;++day){
        int type=ans[day];
        sum+=contest[type].s[day];
        l[type]=day;
        for(int t=1;t<=ntype;++t){
            sum-=contest[t].c*(day-l[t]);
        }
    }
    return sum;   
}

void Output(){
    for(int d=1;d<=D;++d) cout<<ans[d]<<endl;
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void solve(int time){
    bool seen[D+1][ntype+1];
    for(int i=0;i<=D;++i){
        for(int j=0;j<=ntype;++j) seen[D][ntype]=false;
    }
    max_score=evaluate();
    for(int i=0;i<time;++i){
        int p=rand()%D+1;
        int change=rand()%ntype+1;
        if(seen[p][change]) continue;
        seen[p][change]=true;
        int temp=ans[p];
        ans[p]=change;
        int temp_score=evaluate();
        if(max_score<temp_score){
            max_score=temp_score;
        }
        else ans[p]=temp;
    }
}

int main(){
    srand(seed);
    Input();
    Greedy();
    solve(t);
    Output();
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int twice(int x, int k)
{
    if (!k)
        return x;
    return twice(2 * x, k - 1);
}

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = twice(max({a, b, c}), k);
    cout << ans + a + b + c - max({a, b, c}) << '\n';
    return (0);
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            final int n = Integer.parseInt(br.readLine());
            if (n == 0) { break; }
             
            Map<String, Long> data = new HashMap<>(n);
            int cnt = 0;
            for (int i=1; i <= n; i++) {
                StringTokenizer st = new StringTokenizer(br.readLine());
                String e = st.nextToken();
                Long total = data.getOrDefault(e, 0L);
                if (total == null) continue;
                
                Long p = Long.parseLong(st.nextToken());
                Long q = Long.parseLong(st.nextToken());
                total += p * q;
                if (total >= 1_000_000L) {
                    System.out.println(e);
                    total = null;
                    cnt++;
                }
                data.put(e, total);
            }
            if (cnt == 0) {
                System.out.println("NA");
            }
        }
    }
}

Measured memory_bytes: 25984
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

ret = int(input())
r=make_divisors(ret)
if(len(r)%2==1):
    print(r[-1]*2-2)
else:
    for i in range(0,int(len(r)/2)):
        if(r[i*2]+r[i*2+1]-2<ret):
            ret=r[i*2]+r[i*2+1]-2
    print(ret)


Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    cout << (x == 3 or x == 5 or x == 7 ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static String g;
	static String[] a, b;
	static final int INF = 999;
	static int N, M, A, B, C, T;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			M = sc.nextInt();
			A = sc.nextInt();
			B = sc.nextInt();
			C = sc.nextInt();
			T = sc.nextInt();
			int[] ans = solve();
			for (int i = 0; i < N; ++i) {
				if (i != 0) System.out.print(" ");
				System.out.print(ans[i]);
			}
			System.out.println();
		}
	}

	static int[] solve() {
		int[] v = new int[N];
		for (int i = 0; i < N; ++i) {
			v[i] = sc.nextInt();
		}
		int[][][] cnt = new int[30][N + 2][N + 2];
		for (int i = 1; i <= N; ++i) {
			cnt[0][i][i - 1] = C;
			cnt[0][i][i] = B;
			cnt[0][i][i + 1] = A;
		}
		for (int i = 1; (1 << i) <= T; ++i) {
			for (int j = 1; j <= N; ++j) {
				for (int k = 1; k <= N; ++k) {
					for (int l = 1; l <= N; ++l) {
						cnt[i][j][k] += cnt[i - 1][j][l] * cnt[i - 1][l][k];
					}
					cnt[i][j][k] %= M;
				}
			}
		}
		int[][] c = new int[2][N + 2];
		for (int i = 1; i <= N; ++i) {
			c[0][i] = v[i - 1];
		}
		int t = 0;
		for (int i = 0; (1 << i) <= T; ++i) {
			if ((T & (1 << i)) != 0) {
				for (int j = 1; j <= N; ++j) {
					c[1 - t][j] = 0;
				}
				for (int j = 1; j <= N; ++j) {
					for (int k = 1; k <= N; ++k) {
						c[1 - t][k] += c[t][j] * cnt[i][j][k];
					}
				}
				for (int j = 1; j <= N; ++j) {
					c[1 - t][j] %= M;
				}
				t = 1 - t;
			}
		}
		for (int i = 0; i < N; ++i) {
			v[i] = c[t][i + 1];
		}
		return v;
	}
}

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

int main() {
  ll N;
  cin >> N;
  bool is_continue = true;
  for (ll i = 1; i < 10; ++i) {
    for (ll j = 1; j < 10; ++j) {
      if (i*j == N) {
        is_continue = false;
        break;
      }
    }
    if (!is_continue) break;
  }
  if(is_continue) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}

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

using namespace std;

template <class T> void chkmax(T& x, T y) {
  x = x > y ? x : y;
}

template <class T> void chkmin(T& x, T y) {
  x = x < y ? x : y;
}

template <class T> void read(T& x) {
  x = 0; char ch = 0; int f = 1;
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  x *= f;
}

template <class T> void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}

template <class T> void writeln(T x) {
  write(x), puts("");
}

const int N = 5e5 + 5;

vector<int> g[N];
int n;
char s[N];
int indeg[N], res[N];

void dfs(int u, int num) {
  chkmax(res[u], num);
  for (auto v : g[u]) {
    dfs(v, num + 1);
  }
}

int main() {
  memset(res, 0, sizeof res);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == '<') {
      g[i].push_back(i + 1);
      indeg[i + 1]++;
    } else {
      g[i + 1].push_back(i);
      indeg[i]++;
    }
  }
  n++;
  for (int i = 1; i <= n; i++) {
    if (indeg[i] == 0) {
      dfs(i, 0);
    }
  }
  long long Ans = 0;
  for (int i = 1; i <= n; i++) {
    Ans += res[i];
  }
  writeln(Ans);
  return 0; 
}

Measured memory_bytes: 47616
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = 1000000007;
class mint {
public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

ll modpow(ll a, ll n){
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

void Main(){
	
	string S;
	ll K;
	cin >> S >> K;
	
	ll dp[110][2][4] = {0};
	// dp[i][j][k]
	// i: 上位 bit
	// j: tight
	// k: 0でない数字の個数
	dp[0][1][0] = 1;
	rep(i, 100) rep(a, 10){
		
		ll cur = S[i] - '0';
		
		if(a == 0){
			
			if(cur != 0){
				for(ll k = 3; k >= 0; k--){
					dp[i + 1][0][k] += dp[i][0][k] + dp[i][1][k];
				}
			}
			
			else{
				for(ll k = 3; k >= 0; k--){
					dp[i + 1][0][k] += dp[i][0][k];
					dp[i + 1][1][k] += dp[i][1][k];
				}
			}
			
		}
		
		else{
			
			if(cur > a){
				for(ll k = 2; k >= 0; k--){
					dp[i + 1][0][k + 1] += dp[i][0][k] + dp[i][1][k];
				}
			}
			
			else if(cur == a){
				for(ll k = 2; k >= 0; k--){
					dp[i + 1][0][k + 1] += dp[i][0][k];
					dp[i + 1][1][k + 1] += dp[i][1][k];
				}
			}
			
			else{
				for(ll k = 2; k >= 0; k--){
					dp[i + 1][0][k + 1] += dp[i][0][k];
				}
			}
			
		}
		
	}
	
	ll length = S.size();
	ll ans = dp[length][0][K] + dp[length][1][K];
	print(ans);				
		
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
	
}





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


int main(){
	long long N;
	cin >> N;
	long long A,right,left;
	map<long long,long long> lt;
	long long loop,ans=0;
	for(loop=0;loop<N;loop++){
		cin >> A;
		right=loop-A+1;
		if(lt.count(right)){
			ans+=lt[right];
		}
		left=loop+A+1;
		if(lt.count(left)){
			lt[left]++;
		}else{
			lt[left]=1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15920
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static boolean solve() {
		int n = in.nextInt();
		if (n == -1) return false;

		double x = 1, y = 0, r = Math.PI;
		for (int i=1; i<n; i++) {
			r -= Math.PI/2;
			x += Math.cos(r);
			y += Math.sin(r);
			r = Math.atan2(y,x) - Math.PI;
		}

		out.println(x);
		out.println(y);

		return true;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 26348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    string s; cin >> s;
    for(int i=0; i<3; i++){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;
}

Measured memory_bytes: 256