akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <ctime>
#include <random>

using namespace std;

const int INF = 100100100;

int N = 55555;
int arr[1000000];
vector<int> p;

void eratosthenes()
{
    for (int i = 0; i < N; i++)
    {
        arr[i] = 1;
    }
    for (int i = 2; i < sqrt(N); i++)
    {
        if (arr[i])
        {
            for (int j = 0; i * (j + 2) < N; j++)
            {
                arr[i * (j + 2)] = 0;
            }
        }
    }
}

int GetRandom(int min, int max)
{
    return min + (int)(rand() * (max - min + 1.0) / (1.0 + RAND_MAX));
}

vector<int> ans;

int main()
{
    int n;

    cin >> n;

    p.clear();
    eratosthenes();

    for (int i = 2; i < N; i++)
    {
        if(arr[i] && i % 5 == 1)
        {
            p.push_back(i);
        }
    }

    for (int i = 0; i < n;i++)
    {
        if(i == n - 1)
        {
            cout << p[i] << endl;
        }
        else
        {
            cout << p[i] << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

#define MAX 500000
#define INFTY 2000000000

int L[(MAX/2)+2],R[(MAX/2)+2],count;

void merge(int A[], int n, int left, int mid, int right){

  int i,j,k,n1,n2;

  n1 = mid - left;
  n2 = right - mid;

  for(i=0;i<n1;i++){
    L[i] = A[left + i];
  }

  for(i=0;i<n2;i++){
    R[i] = A[mid + i];
  }

  L[n1] = R[n2] = INFTY;

  i = j = 0;

  for(k=left;k<right;k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
  }
}

void mergeSort(int A[], int n, int left, int right){

  int mid;

  if((left + 1) < right){
    mid = (left + right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int main(){

  int A[MAX], n ,i;

  scanf("%d",&n);

  count = 0;
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(A[i] >= INFTY){
      return 1;
    } 
  }

  mergeSort(A,n,0,n);

  for(i=0;i<n;i++){
    if(i){
      printf(" ");
    }
    printf("%d",A[i]);
  }
  printf("\n");

  printf("%d\n",count);

  return 0;

}



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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  int e =a/d;
  if(a%d!=0){
    e++;
  }
  int f = c/b;
    if(c%b!=0){
      f++;
    }
  if(e<f){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll l, r;
  cin >> l >> r;
  if (r - l > 2100) {
    cout << 0 << "\n";
    return 0;
  }

  ll ans = 2018;
  FOR(i, l, r + 1) FOR(j, i + 1, r + 1) { ans = min(ans, (i * j) % 2019); }
  cout << ans << "\n";
}

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> p(m);
    vector<string> s(m);
    vector<int> cnt(1000005,0);
    vector<int> ans(1000005,0);
    vector<int> num(1000005,0);
    rep(i,m) cin>>p[i]>>s[i];
    
    int i=0;
    rep(i,m){
        if(s[i]=="WA") cnt[p[i]]++;
        else if(s[i]=="AC"){
            if(num[p[i]]==0){
                ans[p[i]]+=cnt[p[i]];
                num[p[i]]++;
            }
        }
    }
    
    cout<<accumulate(num.begin(),num.end(),0)<<" "<<accumulate(ans.begin(),ans.end(),0);
    return 0;
}

Measured memory_bytes: 18536
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  a += b;
  istringstream st;
  int n;
  st = istringstream(a);
  st >> n;
  double i = sqrt(n);
  cout << (floor(i)==i ?"Yes" :"No") << "\n";
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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


  ll n,k;
  cin>>n>>k;

  vll h(n);
  REP(i,n)
    cin>>h[i];

  vll dp(n+1,LLINF);
  dp[0]=0;
  REP(i,n){
    for(ll j=1; j<=k; j++){
      if(i+j<n)
        dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }

  cout << dp[n-1] << endl;

}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <limits>
#define inf 998244353

using namespace std;

typedef long long ll;

int main ()
{
    char c;
    cin >> c;
    printf("%c\n",c+1);
    return 0;
}


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

int card[255][14] = {{0}};

int main(void){
    // Your code here!
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        char c; /* 0~255 */
        int num;
        cin >> c >>num;
        card[(int)c][num] = 1; //発見
    }
    /* Sを探す*/
    for(int i=1; i<=13; i++){
        if(card[(int)'S'][i] == 0){
            cout << "S" << " " << i << endl;
        }
    }
    /* Hを探す　*/
    for(int i=1; i<=13; i++){
        if(card[(int)'H'][i] == 0){
            cout << "H" << " " << i << endl;
        }
    }
    for(int i=1; i<=13; i++){
        if(card[(int)'C'][i] == 0){
            cout << "C" << " " << i << endl;
        }
    }
    for(int i=1; i<=13; i++){
        if(card[(int)'D'][i] == 0){
            cout << "D" << " " << i << endl;
        }
    }
}


Measured memory_bytes: 3080
#include <stdio.h>
int main()
{
    int i,j;
     
    scanf("%d%d",&i,&j);
    
    if(i>=13)
    {
        printf("%d",j);
    }
    else if(6<=i&&i<=12)
    {
        printf("%d",j/2);
    }
    else if(i<=5)
    {
        printf("0");
    }
}

Measured memory_bytes: 128
def 眠い():
	N,K=[int(_) for _ in input().split()]
	aS = [0]*N
	iS = 0
	iC = 0
	for s in input():
		if s == '0' :
			if iS % 2:
				aS[iS] = iC
				iS += 1
				iC = 1
			else:
				iC += 1
		else:
			if iS % 2:
				iC += 1
			else:
				aS[iS] = iC
				iS += 1
				iC = 1

	if iC:
		if s == '0' :
			if iS % 2:
				aS[iS]=0
				iS+=1
				aS[iS]=iC
			else:
				if len(aS) < iS +1 :
					aS.append(0)
					aS[iS]=iC
				else:
					aS[iS]=iC
		else:
			if iS % 2:
				if len(aS) < iS +1:
					aS.append(0)	
					aS[iS]=iC
				else:
					aS[iS]=iC
			else:
				aS[iS]=0
				iS +=1
				aS[iS]=iC
	aS=aS[:iS+1]
	iL = len(aS)
	iLP = iL // 2
	if iL % 2:
		iLP += 1
		if iLP <= K:
			print(N)
		else:
			iD = sum(aS[:2*K])
			iMax = iD
			for i in range(1,iLP -K+1):
				if i == 1:
					iD -= aS[0]
				else:
					j = (i-1)*2
					iD -= sum(aS[j-1:j+1])
				if i == iLP -K :
					iD += aS[-1]
				else:
					j = (i+K-1)*2
					iD +=  sum(aS[j:j+2])
				if iMax < iD:
					iMax = iD
			print(iMax)
	else:
		if iLP <= K:
			print(N)
		else:
			iD = sum(aS[:2*K])
			iMax = iD
			for i in range(1,iLP -K+1):
				if i == 1:
					iD -= aS[0]
				else:
					j = (i-1)*2
					iD -= sum(aS[j-1:j+1])
				j = (i+K-1)*2
				iD +=  sum(aS[j:j+2])
				if iMax < iD:
					iMax = iD
			print(iMax)

眠い()







Measured memory_bytes: 4832
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
 
class Program{
    static void Main(){
        int N = int.Parse(Console.ReadLine());
        long[] a = new long[N];
        for(int i = 0; i < N; i++){
            a[i] = long.Parse(Console.ReadLine());
        }

        long cnt = 0;
        for(int i = 0; i < N; i++){
            Console.Error.Write("a[{0}] = {1} ", i, a[i]);
            if(a[i] >= 2){
                cnt += a[i] / 2;
                a[i] = a[i] % 2;
            }
            if(a[i] != 0 && a[i] % 2 == 1){
                if(i > 0 && a[i - 1] > 0 && a[i] > 0){
                    long tmp = Math.Min(a[i - 1], a[i]);
                    cnt += tmp;
                    a[i - 1] -= tmp;
                    a[i] -= tmp;
                }
                if(i < a.Length - 1 && a[i + 1] > 0 && a[i] > 0){
                    long tmp = Math.Min(a[i + 1], a[i]);
                    cnt += tmp;
                    a[i] -= tmp;
                    a[i + 1] -= tmp;
                }
            }
            Console.Error.WriteLine("-> {0}, cnt {1}", a[i], cnt);
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 7636
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,a[N],dp[N],m;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i],dp[i]=1e9;
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(int i=2;i<n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i-j<0)break;
			dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define INF 1e+8
int main() {
	int n,m;
	while(scanf("%d%d",&n,&m),(n|m)) {
		int d[101][101][2];
		for(int i = 0; i < 101; i++) {
			for(int j = 0; j < 101; j++) {
				d[i][j][0] = INF;
				d[i][j][1] = INF;
			}
		}
		for(int i = 0; i < n; i++) {
			int a,b,cost,time;
			scanf("%d%d%d%d",&a,&b,&cost,&time);
			a--;b--;
			d[a][b][0] = cost;
			d[b][a][0] = cost;
			d[a][b][1] = time;
			d[b][a][1] = time;
		}
		for(int k = 0; k < m; k++) {
			for(int i = 0; i < m; i++) {
				for(int j = 0; j < m; j++) {
					for(int l = 0; l < 2; l++) {
						d[i][j][l] = min(d[i][j][l],d[i][k][l] + d[k][j][l]);		
						d[j][i][l] = min(d[j][i][l],d[j][k][l] + d[k][i][l]);		
					}
				}
			}
		}
		int k;
		scanf("%d",&k);
		for(int i = 0; i < k; i++) {
			int p,q,r;
			scanf("%d%d%d",&p,&q,&r);
			p--;q--;
			printf("%d\n",d[p][q][r]);
		}
	}
	return 0;
}

Measured memory_bytes: 1268
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ {
	class Program {
		static void Main(string[] args) {
			int N = Utils.GetInt();
			while (N != 0) {
				new Calc().Solve(N);
				N = Utils.GetInt();
			}
		}

		public class Calc {
			public void Solve() {
				return;
			}
			public void Solve(int N) {
				var box = new int[24*3600+1];
				for (int i = 0; i < N; i++) {
					var line = Console.ReadLine().Split().Select(_ => _.Split(':').Select(int.Parse).ToList()).Select(_ => _[0] * 3600 + _[1] * 60 + _[2]).ToList();
					box[line[0]]++;
					box[line[1]]--;
				}
				for (int i = 1; i < box.Length; i++) {
					box[i] += box[i - 1];
				}
				box.Max().WL();
				return;
			}
		}
	}

	public static class Utils {
		public static int GetInt() {
			return int.Parse(Console.ReadLine());
		}
		public static long GetLong() {
			return long.Parse(Console.ReadLine());
		}
		public static void WL(this object obj) { Console.WriteLine(obj); }
		public static void WL(this string obj) {
			Console.WriteLine(obj);
		}
		public static void WL<T>(this IEnumerable<T> ie) {
			foreach (var item in ie) {
				item.WL();
			}
		}
		public static List<int> GetLineInts() {
			return Console.ReadLine().Split().Select(int.Parse).ToList();
		}
	}
}


Measured memory_bytes: 11428
from collections import Counter

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

cnt = Counter(a)

cnt_items = list(cnt.items())

cnt_values = [i[1] for i in cnt_items]

sum = sum([j*(j-1)//2 for j in cnt_values])

for k in a:
    p = cnt[k]
    print(sum- p*(p-1)//2 + (p-1)*(p-2)//2)

Measured memory_bytes: 29884
#include <stdio.h>

int main(void)
{
	int d;
	int i;
	int S;
	
	while (scanf("%d", &d) != EOF){
		S = 0;
		for (i = 0; i < 600; i += d){
			S += (d * i * i);
		}
		printf("%d\n", S);
	}
	
	return (0);
}

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


int main()
{
	int table[101][101] = {0};
	int r,c;
	cin>>r>>c;
	for(int i = 0; i < r ; i++){
		for(int j = 0 ; j < c; j++ ){
			cin>>table[i][j];
			table[i][c] += table[i][j];
			table[r][j] += table[i][j];
		}
		table[r][c] += table[i][c];
	}
	for(int i = 0; i <= r; i++){
		for(int j=0; j <= c ; j++){
			if( j != c){
				cout<<table[i][j]<<" ";
			}else{
				cout<<table[i][j]<<endl;
			}
		}
	}
	return 0;
}

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

int main() {
    string s; cin >> s;
    deque<int> d;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        d.push_back(s[i]-'0');
        if (d.size() > 1) {
            if (d[d.size()-2] != d[d.size()-1]) {
                ans += 2;
                d.pop_back();
                d.pop_back();
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
const int S = (1 << 17);

vector <int> G[S];
bool odw[S];
int n, m, x, y, z, ans;

void dfs(int node){
	odw[node] = true;
	for (auto e : G[node])
		if (!odw[e])
			dfs(e);
}

int main(){

	cin >> n >> m;
	for (int i = 0; i < m; i ++){
		cin >> x >> y >> z;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for (int i = 1; i <= n; i ++)
		if (!odw[i]){
			ans ++;
			dfs(i);
		}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9728
#include <iostream>
using namespace std;
int n;
int A[20];
bool solve(int i,int m){
  if(i >= n && m > 0) return false;
  if(A[i] == m) return true;
  if(m > A[i] && solve(i+1,m-A[i])) return true;
  return solve(i+1,m);
}
int main()
{
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> A[i];
  }
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    int j;
    cin >> j;
    if(solve(0,j)) cout << "yes";
    else cout << "no";
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()


ans_reverse = 0
for i in range(N):
    ans_reverse += 1 / A[i]
print(1/ans_reverse)


Measured memory_bytes: 6668
N = str(input())

if(N[-1]=="3"):
    print("bon")
    
if(N[-1]=="0" or N[-1]=="1" or N[-1]=="6" or N[-1]=="8"):
    print("pon")
    
if(N[-1]=="2" or N[-1]=="4" or N[-1]=="5" or N[-1]=="7" or N[-1]=="9"):
    print("hon")

Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for (int i=0; i< (int)(n); i++)
const int INF = 100010001;
int main()
{
  int n; cin >> n;
  vector<int>dp(n+10,INF);
  dp[0] = 0;
  for (int i=1; i<=n; i++) {
    dp[i] = 1 + dp[i-1];
    
    for (int p=6; p<=i; p *= 6) {
      dp[i] = min(dp[i], dp[i-p]+1);
    }
    for (int p=9; p<=i; p *= 9) {
      dp[i] = min (dp[i], dp[i-p] +1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 640
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    a = LI()

    b = [0] * N
    is_ok = True
    for i in range(N):
        if N // (N - i) == 1:
            b[N-1-i] = a[N-1-i]
        else:
            # (N-1-i)*2以降を全部足したのをaから引く
            tmp = 0
            for j in range(N - 1 - i, N, N - i):
                tmp += b[j]
            b[N-1-i] = (tmp + a[N-1-i]) % 2

    m = b.count(1)
    print(m)
    if m >= 1:
        ans = []
        for i, e in enumerate(b):
            if e == 1:
                ans.append(i + 1)
        print(*ans)

if __name__ == '__main__':
    resolve()


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

int main() {
  int n, a;
  cin >> n;
  a = n % 10;
  if (a == 3) {
    cout << "bon\n";
  } else if (a == 0 || a == 1 || a == 6 || a == 8) {
    cout << "pon\n";
  } else {
    cout << "hon\n";
  }
}


Measured memory_bytes: 3552
/*
ID: jerrywcy
TASK: AtCoder ABC 109 Problem C
LINK: https://abc109.contest.atcoder.jp/tasks/abc109_c
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n,x;
int a[100010];
int ans;

int gcd(int x,int y){
	if (y==0)return x;
	else return gcd(y,x%y);
}

int main()
{
	cin>>n>>x;
	int i,j;
	for (i=1;i<=n;i++)cin>>a[i];
	a[n+1]=x;
	sort(a+1,a+n+2);
	for (i=n+1;i>=2;i--)a[i]-=a[i-1];
	ans=a[2];
	for (i=3;i<=n+1;i++)ans=gcd(ans,a[i]);
	
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 640
import math

a, b = (int(i) for i in input().split())
_n = 10**9 + 7
if abs(a-b) == 1:
    ab = math.factorial(a) * math.factorial(b)
elif a == b:
    ab = 2*(math.factorial(a) * math.factorial(b))
else:
    ab = 0

print(ab%_n)

Measured memory_bytes: 5172
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

}

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

int main() {
  int N;
  int d[110];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> d[i];
  
  int num[110] = {0};
  for (int i = 0; i < N; i++) {
    num[d[i]]++;
  } 
  
  int res = 0;
  for (int i = 1; i <= 100; i++) {
    if (num[i]) {
      ++res;
    }
  }
  cout << res << endl;
  
}

  

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

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

int main()
{
	int N;
	std::cin >> N;
	std::vector<int> v;
	int a;
	for (int i = 0; i < N; i++) {
		std::cin >> a;
		v.push_back(a);
	}
	std::sort(v.begin(), v.end());
	int s, e;
	s = v[N / 2 - 1];
	e = v[N / 2];
	int result = e - s ;
	std::cout << result;
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<sstream>
#include<string>
#include<utility>
#include<unordered_map>
#include<iterator>
#include<vector>
#include<math.h>
#include<algorithm>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
int main(void)
{
	IOS
		int n;
	cin >> n;
	vector <int> a(n);
	for (int &i : a)
		cin >> i;
	vector <int> dp(n);
	dp[n - 1] = 0;
	dp[n - 2] = abs(a[n - 1] - a[n - 2]);
	for (int i = n - 3; i >= 0; --i)
	{
		int x = i + 1;
		int y = i + 2;
		dp[i] = min((dp[x] + abs(a[i] - a[x])), (dp[y] + abs(a[i] - a[y])));
	}
	cout << dp[0] << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#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()
{    
    string s;
    cin >> s;
    int p = 700;
    rep(i,3) if(s.substr(i,1)=="o") p += 100;
    cout << p << endl;
    return 0;
}

Measured memory_bytes: 256
N, M=map(int, input().split())

S=[list(map(int, input().split())) for i in range(M)]

num=["a"]*N
ans=True
for s in S:
  if (num[s[0]-1]!="a") and (num[s[0]-1]!=s[1]):
    ans=False
    break
  else:
    num[s[0]-1]=s[1]
    
if num[0]==0 and len(num)>1:
  ans=False
    
if ans:
  if len(num)==1:
    if num[0]=="a":
      print(0)
    else:
      print(num[0])
  else:
    for i in range(N):
      if num[i]=="a":
        if i==0:
          print(1, end="")
        else:
          print(0, end="")
      else:
        print(num[i], end="")
else:
  print(-1)
  
  

Measured memory_bytes: 3064
N,K=map(int,input().split())
l=list(map(int,input().split()))
L=[0]
for i in range(N):
    L.append(L[-1]+l[i])
#print(L)
A=[]
for i in range(N):
    for j in range(i+1,N+1):
        A.append(L[j]-L[i])
#print(A)
B=[]
for i in range(len(A)):
    B.append(format(A[i],'040b'))
#print(B)


for i in range(40):
    cnt=0
    for j in B:
        if j[i]=="1":
            cnt+=1
    if cnt>=K:
        S=i
        break

ans=2**(39-S)
C=[]
for j in B:
    if j[S]=="1":
        C.append(j)
        
#print(ans)
#print(C)

for i in range(S+1,40):
    D=[]
    for j in C:
        if j[i]=="1":
            D.append(j)
    if len(D)>=K:
        ans+=2**(39-i)
        C=D
print(ans)


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

using namespace std;
typedef long long ll;
typedef long double ld;

int n, m;
vector<int> vec[100010];
queue<int> q;
int chk[100010];
int all, bll;

int main(void)
{
	scanf("%d %d", &n, &m);
	
	for(int i = 0 ; i < m ; i++)
	{
		scanf("%d %d", &all, &bll);
		vec[all].push_back(bll);
		vec[bll].push_back(all);
	}
	
	q.push(1);
	chk[1] = 1;
	
	while(!q.empty())
	{
		int qq = q.front();
		q.pop();
		
		for(int i = 0 ; i < vec[qq].size() ; i++)
		{
			if(chk[vec[qq][i]])
				continue;
			
			chk[vec[qq][i]] = qq;
			q.push(vec[qq][i]);
		}
	}
	
	for(int i = 2 ; i <= n ; i++)
	{
		if(chk[i] == 0)
		{
			printf("No");
			return 0;
		}
	}
	
	printf("Yes\n");
	
	for(int i = 2 ; i <= n ; i++)
		printf("%d\n", chk[i]);
	
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int a, b, c;
	cin >> a >> b >> c;

	int ans = 0;
	while (ans < c && b - a >= 0) {
		b -= a;
		ans++;
	}

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


Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define ABS(a) ((a)>0 ? (a) : (a * -1))


int A[1000000], n;
int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while (left < right ) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

int prime(int x) {
	if (x < 2) return 0;
	if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (int i = 3; i*i <= x; i+=2) {
		if (x % i == 0) return 0;
	}
	return 1;
}

int gcd(int x, int y) {
	int r;
	if (x < y) swap(x, y);
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main(){
	ll n, ans;
	ll a = 0;
	cin >> n;
	for (int i = 1; i <= (n/2)+1; i++) {
		a = a + i;
		if (a >= n) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;
}


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

using namespace std;
inline int read(){int x=0,f=1;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;}

const int maxn = 1e5 + 50;

int n , a[maxn] ;
long long b[maxn] , value[maxn];
vector < long long > seq;

int main( int argc , char * argv[] ){
	n = read();
	long long sum = 0;
	for(int i = 1 ; i <= n ; ++ i) a[i] = read() , sum += a[i];
	if( n == 1 ){
		puts("YES");
		return 0;
	}
	if( sum % ( 1LL * n * (n + 1) / 2) ){
		puts("NO");
		return 0;
	}
	long long opt = sum / ( 1LL * n * (n + 1) / 2LL );
	for(int i = 2 ; i <= n ; ++ i) seq.emplace_back( a[i] - a[i - 1] ) ;
	sort( seq.begin() , seq.end() );
	long long delta = 0 , ts = 0;
	for(int i = 0 ; i < seq.size() ; ++ i){
		long long x = seq[i] - delta;
		if( x < 0 ){
			long long add = ( abs( x ) + n - 2 )  / ( n - 1 );
			delta += add;
			ts += add;
			value[i] = add;
			b[i] = x + 1LL * add * (n - 1);
		}else b[i] = x;
	}
	long long cur = 0;
	for(int i = seq.size() - 1 ; i >= 0 ; -- i){
		b[i] -= cur;
		cur += value[i];
	}
	int ok = 1;
	for(int i = 1 ; i < seq.size() ; ++ i)
		if( b[i] != b[i - 1] )
			ok = 0;
	ts += b[0];
	if( ok && ts == opt )
		puts("YES");
	else
		puts("NO");
	return 0;
}

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

int main(){
    char s[305];
    int esp1 = -1, esp2 = -1;

    scanf("%[^\n]", s);
    //printf("%s %lu\n", s, strlen(s));

    for(int i = 0; i < strlen(s); ++i){
        if ((s[i] == ' ') && (esp1 == -1)){
            esp1 = i;
        }
        else if ((s[i] == ' ') && (esp2 == -1)){
            esp2 = i;
        }
    }
    if ((s[esp1-1] == s[esp1+1]) && (s[esp2-1] == s[esp2+1])){
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    //printf("%d %d\n", esp1, esp2);

    return 0;
}


Measured memory_bytes: 128
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	string n; cin >> n;
    int k; cin >> k;
    int m = (int)n.size();
    int dp[110][6][2];
    rep(i, 110) {
        rep(j, 6) {
            rep(l, 2) {
                dp[i][j][l] = 0;
            }
        }
    }
    dp[0][0][0] = 1;
    rep(i, m) {
        int s = n[i] - '0';
        for(int j = 0; j <= 3; ++j) {
            for(int nxt = 0; nxt <= 9; ++nxt) {
                    rep(flag2, 2) {
                        int nf2 = flag2 | (nxt < s);
                        //int nf1 = flag1 | (nxt != 0);
                        int nj = j + (nxt != 0);
                        if(flag2 == 1) dp[i + 1][nj][nf2] += dp[i][j][flag2];
                        if(flag2 == 0 && nxt <= s) dp[i + 1][nj][nf2] += dp[i][j][flag2];
                    }
                
            }
        }
    }
    cout << dp[m][k][0] + dp[m][k][1] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N,M=map(int,input().split())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
z=[0 for i in range(N)]
for i in range(N):
    x[i],y[i],z[i]=map(int,input().split())
x=np.array(x)
y=np.array(y)
z=np.array(z)
xyz=np.array([x,y,z])
d=[]
for i in range(8):
    buf=np.zeros(N)
    for j in range(3):
        if i & (1<<j):
            buf=buf+-1*xyz[j]
            continue
        buf=buf+xyz[j]
    buf.sort()
    d.append(sum(buf[N-M:]))
print(int(max(d)))


Measured memory_bytes: 14288
main = do
  getLine
  as <- map read . words <$> getLine :: IO [Int]
  bs <- map read . words <$> getLine :: IO [Int]
  cs <- map read . words <$> getLine :: IO [Int]
  print $ eat (-1:as) bs cs

eat :: [Int] -> [Int] -> [Int] -> Int
eat [] _ _ = 0 
eat [_] _ _ = 0
eat (x:y:xs) bs cs 
  | y-x == 1 = bs !! (y-1) + cs !! (x-1) + eat (y:xs) bs cs
  | otherwise = bs !! (y-1) + eat (y:xs) bs cs

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


int main() {

	ll l, r;
	cin >> l >> r;

	// 2019で割ったあまりの最小値

	// 全探索したいなぁ

	ll ans = inf;

	for (ll i = l; i <= r && i <= l + (ll)2019; i++) {
		for (ll j = i + 1; j <= r && j <= l + (ll)2020 ; j++) {
			ans = min(ans, (i * j) % (ll)2019);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,j, a, b, c, k, ans;
bool cond;
int main()
{
    //I am Monim, a tiny creature of Allah
    cin >> a >> b >> c >> k;
    temp = min(a,k);
    ans = temp;
    if(temp<k)
        temp += min(b,k-a);
    if(temp<k)
    {
        temp += min(c, k-(a+b));
        ans -= min(c, k-(a+b));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] abt = sc.nextLine().split(" ");
        int A = Integer.parseInt(abt[0]);
        int B = Integer.parseInt(abt[1]);

        boolean isMatch = false;
        for (int i = 0; i < Math.max(A, B); i++) {

            if (Math.abs(A - i) == Math.abs(B - i)) {
                System.out.println(i);
                isMatch = true;
            }
        }
        if (!isMatch) {
            System.out.println("IMPOSSIBLE");

        }
    }

}


Measured memory_bytes: 22100
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll int i=a;i<=b;++i)
#define rep(i,n) for(ll int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
ll int MOD=1e9+7;
int INF=1e6;
ll int MAX_N=1e18;
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

ll int inv[1000000]={};
void calc_inv(ll int s){
    inv[1]=1;
    rep2(i,2,s-1){
        inv[i]=(MOD-(MOD/i)*inv[MOD%i]%MOD);
    }
}

main(){
    ll int n;
    calc_inv(200000);
    cin>>n;
    ll int a[200000];
    ll int count[200000]={};
    ll int left,right;
    rep(i,n+1){
        scanf("%lld",&a[i]);
        if(!count[a[i]]) count[a[i]]=1;
        else right=i;
    }
    rep(i,n+1){
        if(a[i]==a[right]){ left=i; break;}
    }
    ll int comb1[110000],comb3[110000];
    comb1[0]=1,comb3[0]=1;
    rep2(i,1,n+2){
        comb1[i]=comb1[i-1]*(n+2-i)%MOD;
        comb1[i]=comb1[i]*inv[i]%MOD;
        comb3[i]=comb3[i-1]*(n+1-right+left-i)%MOD;
        comb3[i]=comb3[i]*inv[i]%MOD;
    }
    rep2(i,1,n+1){
        ll int ans=0;
        ans+=comb1[i];
        ans-=comb3[i-1];
        ans%=MOD;
        cout<<(comb1[i]-comb3[i-1]+MOD)%MOD<<endl;         
    }
    return 0;
}


Measured memory_bytes: 7552
import itertools

N = int(input())
L = list(map(int, input().split()))
count=0
iterL = list(itertools.combinations(L,3))

for LL in iterL:
    if LL[0]==LL[1] or LL[0]==LL[2] or LL[2]==LL[1]:
        continue
    LLL = list(LL)
    LLL = sorted(LLL)

    if LLL[0]+LLL[1]>LLL[2]:
        count+=1

print(count)

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int x;
  cin >> x;
  cout << x * x * x + x * x + x << endl;
}

Measured memory_bytes: 3604
n = int(input())
dp = [10**9]*30000000
dp[0] = 0
pow6 = [6**i for i in range(10) if 6**i <= n]
pow9 = [9**i for i in range(10) if 9**i <= n]

for i in range(n):
    for p6 in pow6:
        dp[i+p6] = min(dp[i+p6], dp[i]+1)
    for p9 in pow9:
        dp[i+p9] = min(dp[i+p9], dp[i]+1)
print(dp[n])


Measured memory_bytes: 237428
#include<iostream>
#include<bits/stdc++.h>
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define li long int
#define pp pair<int,int>
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i,x,n) for(int i=x;i<n;i++)
#define fr first
#define ss second
#define mod 1000000007
using namespace std;
int main()
{
    int k;
    cin>>k;
    if(__gcd(360,k)==k)
        cout<<360/k<<endl;
    else
    {
        int x=__gcd(360,k);
        cout<<360/x<<endl;
    }
}


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

int n, m, a[1005], b, c[1005], d[1<<12];
int main() {
	int i, j, t;
	cin >> n >> m;
	for(i=0; i<m; i++) {
		cin >> a[i] >> b;
		while(b--) {
			cin >> t;
			t--;
			c[i] |= (1<<t);
		}
	}
	for(i=1; i<1<<n; i++) d[i] = 1e9;
	for(i=0; i<1<<n; i++) {
		for(j=0; j<m; j++) {
			d[i|c[j]] = min(d[i|c[j]], d[i] + a[j]);
		}
	}
	t = d[(1<<n)-1];
	cout << (t==1e9 ? -1 : t) << endl;
	return 0;
}

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


/*
int solve(int i){
	if(i == 0) return 0;
	if(i == 1) return 0;
	if(memo[i] != -1) return memo[i];
	int m = INT_MAX;
	for(int d = 1; d <= k; d++){
		if(i - d < 0) break;
		m = min(solve(i-d, k)+abs(h[i]-h[i-d]), m);
	}
	return memo[i] = m;
}*/

string s, t;
int dp[3000][3000];
int solve(int i, int j){
	if(i == s.size() || j == t.size()) return 0;
	if(dp[i][j] != -1) return dp[i][j];
	int ret = -1;
	ret = max(ret, solve(i+1,j));
	ret = max(ret, solve(i,j+1));
	if(s[i] == t[j]) ret = max(ret, solve(i+1,j+1)+1);
	return dp[i][j] = ret;
}

void restore(int i, int j){
	if(i == s.size() || j == t.size()) return;
	if(dp[i][j] == solve(i+1,j)) restore(i+1,j);
	else if(dp[i][j] == solve(i,j+1)) restore(i,j+1);
	else if(s[i] == t[j] && dp[i][j] == solve(i+1,j+1)+1){
		cout << s[i];
		restore(i+1,j+1);
	}
}

int main(){

	cin >> s >> t;
	for(int i=0; i<s.size(); i++)
		for(int j=0; j<t.size(); j++)
			dp[i][j] = -1;
	solve(0,0);
	restore(0,0);

    return 0;
}


Measured memory_bytes: 35840
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

typedef long long llong;
typedef unsigned long long ullong;

//?´???°??????
bool isPrime(int x) {
	if (x < 2)return 0;
	else if (x == 2)return 1;
	if (x % 2 == 0)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}

//??¨????????????????????????
//n??\????????£??´??°????´???°???????????°???????????????is_prime[]???????´?
void eratos(int n, bool is_prime[]) {
	fill(is_prime, is_prime + n, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i*i <= n; i++) {
		if (is_prime[i]) {
			int j = i + i;
			while (j <= n) {
				is_prime[j] = false;
				j = j + i;
			}
		}
	}
}

//?????§??¬?´???°
int gcd(int x, int y) {
	return y ? gcd(y, x%y) : x;
}

//???????´???? ??°??????????????????
llong mod_pow(ullong x, ullong n) {
	ullong res = 1;
	while (n > 0) {
		if (n & 1)res = res*x%MOD;
		x = x*x%MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	ullong m, n; cin >> m >> n;
	cout << mod_pow(m, n) << endl;
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;
const ll inf = 1000000000000000;

#define pi acos(-1)
#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define all(x) x.begin(),x.end()
#define vsort(x) sort(all(x))
#define vrev(x) reverse(all(x));
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define opsp(x) cout<<x<<' '
#define opy cout<<"YES\n"
#define opn cout<<"NO\n"
#define flush fflush(stdout)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define reprev(i,a,b) for(int i=a;i>=b;i--)



#define p(a,b) cout<<a<<' '<<b<<'\n';
void print(int n) {p(n,n-1);p(n,n);p(n,n+1);}


void solve(){
	int n;cin>>n;	
	int ans=0;
	ll angle=0;
	while(1){
		angle+=n;
		ans++;
		if(angle>=360) angle=angle-360;
		if(angle==0) break;
	}
	cout<<ans;
		

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    //test{solve();}
	solve();
    return 0;
}
	


Measured memory_bytes: 3644
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int[] a = new int[n+1];

		for ( int i=1; i<n; i++ ) {
			int aa = sc.nextInt();
			a[aa]++;
		}

		for ( int i=1; i<=n; i++ ) {
			System.out.println(a[i]);
		}
	}
}

Measured memory_bytes: 53972
#!/usr/bin/env python
from math import *

while True:
    r, n = map(int, raw_input().split())
    if r == 0:
        break

    m = {}
    for i in range(-50, 50):
        m[i] = 0

    for loop in range(n):
        x1, x2, h = map(int, raw_input().split())
        for i in range(x1, x2):
            m[i] = max(m[i], h)

    ans = 100
    for i in range(-r, 0):
        rem = r - sqrt(r * r - (i + 1) * (i + 1)) + m[i]
        ans = min(rem, ans)

    for i in range(0, r):
        rem = r - sqrt(r * r - i * i) + m[i]
        ans = min(rem, ans)

    print ans



Measured memory_bytes: 4776
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=2e5+5;
int main()
{
	int n;
	cin >> n;
	ll x[MAXN];
	ll ans=0;
	for(int i=0;i<n;i++){
		cin >> x[i];
		if(i!=0){
			if(x[i]<x[i-1]){
				ans=ans+x[i-1]-x[i];
				x[i]=x[i-1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4692
#pragma warning(disable:4996)
#include "bits/stdc++.h"
using namespace std;

//macro
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,a,b) for(int i=(int)(b) - 1;i>=(int)(a);i--)
#define rrep(i,n) RREP(i,0,n)
#define each(i, ctn) for (auto &&i : (ctn))
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define INFL 1145148100000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define equals(a,b)(fabs((a)-(b))<EPS)

//alias
using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using P = pair<ll, ll>;
template<class T> using heap = priority_queue<T>;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H);	rep(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n)os << v[i] << (i == n - 1 ? "\n" : " "); return os; }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template<class T> inline void print(const T &x) { cout << x << '\n'; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;

int main() {
	int x, y;
	x = in();
	y = in();
	print((int)ceil((x+y)/2.0));
	return 0;
}


Measured memory_bytes: 896
/*=======================
Author    : Shounak Dey
Filename  : d.cpp
=======================	*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define PB push_back
#define MK make_pair 
#define SZ(a) (int)(sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define read(n) scanf("%d",&n)
#define readl(n) scanf("%lld",&n)
#define readul(n) scanf("%llu",&n);


#define SORTV(a) sort(a.begin(),a.end())
#define TEST int Test;cin >> Test;while(Test--)
#define gcd(a,b) __gcd(a,b)
#define ffs(a) __builtin_ffs(a) // find first set
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)


#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c))
		v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

int main()
{
	fast_io;
	ll n;
	cin >> n;
	vector<ll> arr(n);
	REP(i,n)
		cin >> arr[i];
	map<ll,ll> c;
	REP(i,n)
		c[arr[i]]++;
	ll ans=0;
	for(auto it: c)
		ans += (it.S * (it.S-1))/2;
	REP(i,n){
		ll x = c[arr[i]];
		ll t = ans - (x*(x-1))/2;
		x--;
		t += (x*(x-1))/2;
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define    boost        ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define    nl           "\n"
#define    ll           long long
#define    pb           push_back
#define    mpr          make_pair
#define    fr(i,a,n)    for(ll i=a;i<n;++i)
#define    fr0(i,n)     for(ll i=0;i<n;++i)
#define    pii          pair<int, int>
#define    FO           find_by_order
#define    OK           order_of_key
#define    mem(a)       memset(a,0,sizeof(a))
#define    ff           first
#define    ss           second


typedef tree <
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update >
set_t;


void fio()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
	double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
	time_taken *= 1e-9;
	cout << "\nExecuted in: " << fixed
	     << time_taken << setprecision(9);
	cout << " sec";
#endif
}

///----------------------------- | START | --------------------------------------///

/*
	LCS Problem
https://atcoder.jp/contests/dp/tasks/dp_f
*/


void solve()
{
	string s, t;
	cin >> s >> t;
	int m = s.size(), n = t.size();
	int dp[m + 5][n + 5];
	mem(dp);
	char path[m + 5][n + 5];
	mem(path);
	fr(i, 1, m + 1) fr(j, 1, n + 1)
	{
		if (s[i - 1] == t[j - 1])
		{
			dp[i][j] = 1 + dp[i - 1][j - 1];
			path[i][j] = 'x';
		}

		else
		{
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if (dp[i][j] == dp[i - 1][j])
				path[i][j] = 'd';
			else path[i][j] = 'l';
		}
	}
	string ans;
	int i = m, j = n;
	while (i != 0 && j != 0)
	{
		if (path[i][j] == 'x')
		{
			ans.pb(s[i - 1]);
			i--, j--;
		}
		else if (path[i][j] == 'd')	i--;
		else j--;
	}

	reverse(ans.begin(), ans.end());
	cout << ans << nl;
}




int32_t main()
{
	auto start = chrono::high_resolution_clock::now();
	boost;
	fio();
	int t;
	t = 1;
	//cin >> t;
	while (t--) solve();
	auto end = chrono::high_resolution_clock::now();
	TIME(start, end);
	return 0;
}




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

using namespace std;

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int64_t n, min;
    cin >> n >> min;
    int64_t sum = (2 * min + n - 1) * n / 2;
    if (min >= 0) {
        sum -= min;
    } else {
        if (n - 1 + min < 0) {
            sum -= n - 1 + min;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
import math
from collections import defaultdict

def input_ints():
    return list(map(int, input().split()))

def solve():
    n, k = input_ints()
    c = (n - 1) * (n - 2) / 2
    if k > c:
        print(-1)
        return
    ans = []
    for i in range(1, n):
        ans.append((i, n))
    for x in range(1, n):
        for y in range(x + 1, n):
            if c > k:
                ans.append((x, y))
                c -= 1
    print(len(ans))
    for p in ans:
        print(p[0], p[1])

if __name__ == '__main__':
    solve()


Measured memory_bytes: 4256