akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,A,B;
vl a;

bool f(ll x){
	ll num=0;
	for(int i=0;i<n;i++){
		ll tmp=a[i]-x*B;
		if(tmp>0) num+=(tmp+A-B-1)/(A-B);
	}
	return num<=x;
}

int main(){
	cin>>n>>A>>B;
	a=vl(n);
	for(int i=0;i<n;i++) cin>>a[i];
	ll s=0,t=inf;
	while(t-s>1){
		ll m=(s+t)/2;
		if(f(m)) t=m;
		else s=m;
	}
	cout<<t<<endl;
}

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

const int MAXN = 500 + 3;
int H[MAXN][MAXN];
bool occ[MAXN][MAXN];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void dfs(int x, int y) {
    int z = H[x][y] + occ[x][y];
    for (int t = 0; t < 4; t++) {
        int x1 = x + dx[t], y1 = y + dy[t];
        if (H[x1][y1] > z) {
            H[x1][y1] = z;
            dfs(x1, y1);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    
    for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) {
        H[i][j] = min(min(i, N+1-i), min(j, N+1-j)) - 1;
        occ[i][j] = true;
    }

    int res = 0;
    for (int it = 0; it < N*N; it++) {
        int id;
        cin >> id;
        int x = (id+N-1)/N;
        int y = id % N;
        if (y == 0) y += N;
        res += H[x][y];
        occ[x][y] = false;
        dfs(x, y);
    }
    cout << res << "\n";
    
}


Measured memory_bytes: 20300
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numN = nextInt();
		int numM = nextInt();

		out.println((numN - 1) * (numM - 1));
	}

	private void solveB() {
		int numN = nextInt();

		out.println("");
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

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

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

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

Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int a,b,c,d;
    cin >> a >> b;
    
    if(a*b%2==0){
        put("Even");
    }else{
        put("Odd");
    }
    return 0;
}


Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,j,h,w;
    cin>>h>>w;
    cout<<(h-1)*(w-1);




    return 0;
}





Measured memory_bytes: 3596
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    ll a; cin>>a;
    vec<int> m(a);
    for(int q=0; q<a; q++) cin>>m[q];
    vec<int> o;
    for(int q=a-1; q>=0; q--){
        int c = q+1, p=0;
        for(int w = c; w<=a; w+=c) p+=m[w-1];
        if(p%2!=m[q]) m[q]^=1;
        if(m[q]==1) o.pb(q+1);
    }
    cout<<o.size()<<"\n";
    for(int i : o) cout<<i<<" ";
}

Measured memory_bytes: 2424
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R


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

	cin >> H >> W >> L >> R;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	int sy, sx, gy, gx;
	vector<vector<int>>v(H + 2, vector<int>(W + 2, -1));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == 's') {
				sy = i, sx = j;
				s[i][j] = '.';
			}
			else if (s[i][j] == 'g') {
				s[i][j] = '.';
				gy = i;
				gx = j;
			}
			if (s[i][j] == '.')v[i + 1][j + 1] = 0;
			if (s[i][j] == '#')v[i + 1][j + 1] = 1;
			if (s[i][j] == '*')v[i + 1][j + 1] = -2;
		}
	}
	sx++, sy++, gx++, gy++;
	int diry[] = { 1,1,1,0,-1,-1,-1,0 };
	int dirx[] = { 1,0,-1,-1,-1,0,1,1 };
	vector<vector<long long int>>dp(H + 2, vector<long long int>(W + 2, MOD*MOD));
	dp[sy][sx] = 0;
	queue<pair<int, int>>Q;
	Q.push({ sy,sx });
	while (!Q.empty()) {
		int cy = Q.front().first;
		int cx = Q.front().second;
	//	cout << cy << " " << cx << endl;
		Q.pop();
		for (int i = 0; i < 8; i++) {
			int ny = cy + diry[i];
			int nx = cx + dirx[i];
			if (v[ny][nx] == -1)continue;
			if (abs(diry[i]) + abs(dirx[i]) == 2 && (v[ny][nx] == 0 || v[ny][nx] == -2))continue;
			//cout << ny << " " << nx << endl;
			if (v[ny][nx] == 1) {
				bool flag = true;
				if (v[cy][cx] == -2)flag = false;
				for (int j = 0; j < 8; j++) {
					int nny = cy + diry[j];
					int nnx = cx + dirx[j];
					if (v[nny][nnx] == -2)flag = false;
				}
				if (flag) {
					if (dp[ny][nx] > dp[cy][cx] + R + L * (abs(diry[i]) + abs(dirx[i]))) {
						dp[ny][nx] = dp[cy][cx] + R + L * (abs(diry[i]) + abs(dirx[i]));
						Q.push({ ny,nx });
						//cout << ny << " " << nx << " " << dp[ny][nx] << " ei1333" << endl;
					}
				}
			}
			else {
				if (dp[ny][nx] > dp[cy][cx] + L) {
					dp[ny][nx] = dp[cy][cx] + L;
					Q.push({ ny,nx });
				}
			}
		}
	}
	//cout << "hoge" << endl;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
	//		cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	if (dp[gy][gx] == MOD * MOD) {
		cout << "INF\n";
		return 0;
	}
	cout << dp[gy][gx] << endl;
} 


Measured memory_bytes: 15860
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var nmp=(Arr.shift()).split(" ").map(Number);
   if(nmp[0]==0 && nmp[1]==0 && nmp[2]==0)break;
   var n=nmp[0];
   var m=nmp[1]-1;
   var p=nmp[2];
   var arr=[];
   var sum=0;
   for(var i=0;i<n;i++){
      var v=Arr.shift()-0;
      arr.push(v);
      sum+=(v*100);
   }
   sum=sum*(100-p)/100;
   var ans=0;
   if(arr[m]!=0)ans=Math.floor(sum/arr[m]);
   console.log(ans);
}

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

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> s(h, vector<char>(w));
	int cnt_black = 0;
	rep(i, h) rep(j, w){
		cin >> s[i][j];
		if(s[i][j] == '#') cnt_black++;
	}
	
	vector<vector<int>> dist(h, vector<int>(w, -1));
	dist[0][0] = 0;
	queue<pair<int, int>> que;
	que.push(make_pair(0, 0));
	
	// bfs
	while(!que.empty()){
		pair<int, int> current_pos = que.front();
		int x = current_pos.first;
		int y = current_pos.second;
		que.pop();
		for(int dir = 0; dir < 4; dir++){
			int next_x = x + dx[dir];
			int next_y = y + dy[dir];
			if(next_x < 0 || next_x >= h || next_y < 0 || next_y >= w) continue;
			if(s[next_x][next_y] == '#') continue;
			if(dist[next_x][next_y] == -1){
				que.push(make_pair(next_x, next_y));
				dist[next_x][next_y] = dist[x][y] + 1;
			}
		}
	}
	
	if(dist[h-1][w-1] == -1) cout << -1 << endl;
	else cout << h * w - dist[h-1][w-1] - cnt_black - 1 << endl;
	// rep(i, h){
	// 	rep(j, w){
	// 		if(dist[i][j] == -1) printf("  #  ");
	// 		else printf(" %3d ", dist[i][j]);
	// 	}
	// 	printf("\n");
	// }
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	vector<int>h(n); for(auto&i:h)cin>>i;
	vector<vector<int>>ab(n);
	for(int i=0;i<m;++i){
		int A,B; cin>>A>>B; --A,--B;
		ab.at(A).emplace_back(B);
		ab.at(B).emplace_back(A);
	}
	int ans=0;
	for(int i=0;i<ab.size();++i){
		int A=h.at(i); bool yes=true;
		for(int j=0;j<ab.at(i).size();++j){
			if(A<=h.at(ab.at(i).at(j))){
				yes=false;
			}
		}
		if(yes)++ans;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 8744
from copy import copy
N=int(input())
K=100

Data=[]
for i in range(N):
    x,y,h=map(int,input().split())
    Data.append((x,y,h))

Data.sort(key=lambda x:-x[-1])
for i in range(N):
    x,y,h=Data[i]

    if i==0:
        C=[]
        for X in range(K+1):
            for Y in range(K+1):
                H=h+abs(x-X)+abs(y-Y)
                if H>0:
                    C.append((X,Y,H))
    else:
        D=[]
        for (X,Y,H) in C:
            if max(H-abs(x-X)-abs(y-Y),0)==h:
                D.append((X,Y,H))
        C=copy(D)

X,Y,H=C[0]
print(X,Y,H)

Measured memory_bytes: 75640
l = [list(map(int,input().split())) for _ in range(3)]
# print(l)
l1 = []
for i in range(3):
    l1.append(tuple(j - min(l[i]) for j in l[i]))
if len(set(l1)) != 1:
    print('No')
    exit()

k = [[0]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        k[j][i] = l[i][j]
k1 = []
for i in range(3):
    k1.append(tuple(j - min(k[i]) for j in k[i]))
if len(set(k1)) != 1:
    print('No')
    exit()

print('Yes')

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

int main()
{
	int N, K;
	int A[100005];
	int minv;

	cin >> N >> K;
	cin >> A[0];

	minv = A[0];
	for ( int i = 1; i < N; i++ ) {
		cin >> A[i];
		minv = min(minv, A[i]);
	}
	
	int big = 0;
	for ( int i = 0; i < N; i++ ) {
		if ( minv < A[i] ) big++;
	}
	K--;	
	cout << (big + K - 1) / K << endl;

	return ( 0 );
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MAX (ll)(3e5 + 7)
#define INF (ll)(1e5 + 7)
#define MOD (ll)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;

int main () {
	int h, w, kk;
	cin >> h >> w >> kk;
	char ma[h][w];
	for (int i = 0; i < h; i++) {	
		for (int j = 0; j < w; j++) {
			cin >> ma[i][j];
		}
	}
	int ans = h + w - 2;
	int n = (1 << (h - 1));
	for (int i = 0; i < n; i++) {
		int cc = 0, pr = 0, ff = 1;
		vector<pair<int, int>> pp;
		for (int j = 0; j < (h - 1); j++) {
			if ((i >> j) & 1) {
				cc++;
				pp.push_back (make_pair (pr, j));
				pr = j + 1;
			}
		}
		pp.push_back (make_pair (pr, h - 1));
		int x = pp.size ();
		int ar[x] = {}, cu[x] = {};
		for (int l = 0; l < w; l++) {
			bool fl = 0;
			for (int k = 0; k < x; k++) {
				for (int j = pp[k].first; j <= pp[k].second; j++) {
					cu[k] += ma[j][l] == '1';
				}
				if (ar[k] + cu[k] > kk) {
					fl = 1;
				}
			}
			if (fl) {
				cc++;
				for (int i = 0; i < x; i++) {
					ar[i] = 0;
				}
			}
			for (int i = 0; i < x; i++) {
				if (cu[i] > kk) {
					ff = 0;
					break;
				}
				ar[i] += cu[i];
				cu[i] = 0;
			}
		}
		if (ff) {
			ans = min (cc, ans);	
		}
	}
	cout << ans << "\n";
}
			


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

int main() {
	clog << "Ready\n";
	
	int n, d;
	cin >> n >> d;
	if (n % (2 * d + 1) == 0)
		cout << n / (2 * d + 1) << '\n';
	else
		cout << n / (2 * d + 1) + 1;
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class AtCoder
{
    const int MOD = 1000000007;
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        int ln = int.Parse(inputs[0]);
        int rn = int.Parse(inputs[1]);
        int count = Math.Min(2019, rn - ln + 1);
        long ans = 2018;
        foreach(int num in Enumerable.Range(ln, count - 1))
            foreach(int num2 in Enumerable.Range(ln, count).Skip(ln - num + 1))
            {
                ans = Math.Min(ans, (long)num * num2 % 2019);
            }
        Console.WriteLine(ans);
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

Measured memory_bytes: 11220
import java.io.PrintWriter;
import java.util.Scanner;

public class Main
{
	static Scanner in;
	static PrintWriter out;
	static void solve()
	{
		String str = in.nextLine();
		int n = str.length();
		out.print(str.charAt(0));
		out.print(n - 2);
		out.println(str.charAt(n - 1));
	}
	public static void main(String[] args)
	{
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
		out.close();
		in.close();
	}
}

Measured memory_bytes: 21844
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, key, value)
  index = queue.index{|target, _| target >= key}
  return queue[index][1] if index && queue[index][0] == key
  return nil if index && index > 0 && !key.start_with?(queue[index - 1][0])
  queue.insert(index || queue.size, [key, value])
  value
end

def collect(n, arrows, goal)
  come_from = Array.new(n){[]}
  arrows.each do |arrow|
    come_from[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    come_from[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end
  reachable_from
end

def work(n, arrows, start, goal)
  reachable_from = collect(n, arrows, goal)
  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  go = Array.new(n){[]}
  arrows.each do |arrow|
    go[arrow.source] << arrow
  end

  max = n * arrows.map{|arrow| arrow.label.size}.max

  queue = [['', {start => true}]]
  until queue.empty?
    spell, map = queue.shift
    return spell if map[goal]

    return nil if spell.size > max

    map.each do |node, unused|
      go[node].each do |arrow|
        t = push(queue, spell + arrow.label, {})
        t[arrow.sink] = true if t
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = (0...a).map do |i|
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  end

  puts work(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 9844
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )

using namespace std;

string s;

int cnt = 0, cur, ans;

main ()
{
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (cnt == 0)
            cur = 0, cnt++;
        else
            cur = 1, cnt--;

        if (s[i] == 'g' && cur == 1)
            ans++;
        if (s[i] == 'p' && cur == 0)
            ans--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int D;
array<int, 26> C;
vector<array<int, 26>> S;
pair<int, int> search(int depth, vector<int>& last, int d) {
    int minus = 0;
    for (int t = 0; t < 26; t++) {
        minus += C[t] * (d + 1 - last[t]);
    }
    if (depth == 0 || d == D - 1) {
        int vmax = -1e9;
        int tmax = 0;
        for (int t = 0; t < 26; t++) {
            int v2 = -minus + S[d][t] + C[t] * (d + 1 - last[t]);
            if (v2 > vmax) {
                vmax = v2;
                tmax = t;
            }
        }
        return {tmax, vmax};
    }
    int vmax = -1e9;
    int tmax = 0;
    for (int t = 0; t < 26; t++) {
        int v2 = -minus + S[d][t] + C[t] * (d + 1 - last[t]);
        int tmp = last[t];
        last[t] = d + 1;
        auto [t2, v3] = search(depth - 1, last, d - 1);
        v2 += v3;
        last[t] = tmp;
        if (v2 > vmax) {
            vmax = v2;
            tmax = t;
        }
    }
    return {tmax, vmax};
}
int main() {
    cin >> D;
    for (auto &c : C) cin >> c;
    S.resize(D);
    for (auto &row : S) for (auto &s : row) cin >> s;
    vector<int> last(26);
    for (int d = 0; d < D; d++) {
        auto [t, v] = search(3, last, d);
        last[t] = d + 1;
        cout << t + 1 << '\n';
    }
    return 0;
}


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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
string n;
ll k;
ll dp[105][105][2];
ll f(ll i,ll cnt,ll flag)
{
  if(cnt>k) return 0;
  if(i==(ll)n.size())
  {
    if(cnt==k) return 1;
    else return 0;
  }
  if(dp[i][cnt][flag]!=-1) return dp[i][cnt][flag];
  ll ans=0;
  ll lmt=9;
  if(flag==0)
  {
    lmt=(n[i]-'0');
  }
  for(ll dig=0;dig<=lmt;dig++)
  {
    if(dig<(n[i]-'0'))
    {
      if(dig==0) ans+=f(i+1,cnt+1,1);
      else ans+=f(i+1,cnt,1);
    }
    else
    {
      if(dig==0) ans+=f(i+1,cnt+1,flag);
      else ans+=f(i+1,cnt,flag);
    }
  }
  return dp[i][cnt][flag]=ans;
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    cin>>n;
    cin>>k;
    k=(ll)n.length()-k;
    memset(dp,-1,sizeof(dp));
    ll ans=f(0,0,0);
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3836
import sys
readline = sys.stdin.buffer.readline

n=int(readline())
x2i=[0]*n
i2y=[0]*n
for i in range(n):
	a,b=map(int,readline().split())
	x2i[n-a]=i
	i2y[i]=b-1

ans=[0]*n

pre=0
mx=0
for x in range(n):
	i=x2i[x]
	y=i2y[i]
	mx=max(mx,y)
	if mx==x:
		for p in range(pre,x+1):
			ans[x2i[p]]=x+1-pre
		pre=x+1

print(*ans,sep='\n')


Measured memory_bytes: 81504
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());
		char[][] S = new char[n][];
		var ans = new StringBuilder();
        for(var i = 0; i < n; i++)
		{
			S[i] = Console.ReadLine().ToCharArray();
			Array.Sort(S[i]);
		}
        
        for(var i = 0; i < S[0].Length; i++)
		{
			if (i > 0 && S[0][i] == S[0][i-1]) { continue; }
			else
			{
				int min = 1000;
                for(var j = 0; j < n; j++)
				{
					int sn = S[j].Where(x => x == S[0][i]).Count();
					if (sn < min) { min = sn; }
				}
				if (min == 0) { continue; }
                for(var j = 0; j < min; j++)
				{
					ans.Append(S[0][i]);
				}
             

                   
			}
		}

		Console.WriteLine(ans);
	}
}

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

typedef long long ll;

int main (void) {
    int n, h[100010], ans = 1;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
        if (i == 0 || h[i] > h[i - 1]) h[i]--;
        if (i && h[i] < h[i - 1]) ans = 0;
    }

    printf(ans ? "Yes" : "No");
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
	map<int,int> M;
	int n,T;cin>>n>>T;
	std::vector<int> price(n+1);
	for(int i=1;i<=n;i++) cin>>price[i];
	int mn=price[1],mx=0;
	for(int i=2;i<=n;i++) {
		mn=min(mn,price[i]);
		mx=max(price[i]-mn,mx);
	}
	if(mx==0) return 0*puts("0");
	int ans=0;mn=price[1];
	for(int i=2;i<=n;i++) {
		mn=min(mn,price[i]);
		if(price[i]-mn==mx) ans++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3728
S = list(input())
T = list(input())

S1 = S[::-1]
T1 = T[::-1]
count = 0
for i in range(len(S)-len(T)+1):
    count = 0

    for j in range(len(T1)):
        
        if S1[i+j] == "?" or S1[i+j] == T1[j]:
            

            count += 1

    
    if count == len(T1):
        
        for k in range(len(T1)):
            S1[k+i] = T1[k]
            
        S2 = S1[::-1]

        for i in S2:
            if i == "?":
                print("a",end="")
            else:
                print(i,end="")
        exit()

print("UNRESTORABLE")   






Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

void solve(){
  double a,b,x;
  cin>>a>>b>>x;
  double s=x/a;
  double h=2*(a*b-s)/a;
  double w=2*s/b;
  if(s>a*b/2)cout<<(180/PI)*atan2(h,a);
  else cout<<(180/PI)*atan2(b,w);
}

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


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

signed main(){
  int N, K; cin >> N >> K;
  long long ans = 0;
  for(int b = 1; b <= N; b++){
    int p = N/b;
    int r = N - p*b + 1;
    ans += (p * max(0, b - K) + max(0, r - K)) - (K == 0);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
from sys import stdin
nii=lambda:map(int,stdin.readline().split())

n=int(input())
l=[list(nii()) for i in range(n-1)]

tree=[[] for i in range(n)]
for a,b in l:
  a-=1
  b-=1
  tree[a].append(b)
  tree[b].append(a)

ans_num=0
for i in tree:
  ans_num=max(ans_num,len(i))

col=[-1 for i in range(n)]
col[0]=0

que=deque()
que.append(0)

ans_dict={}
while que:
  x=que.popleft()

  t_col=1
  for i in tree[x]:
    if col[i]!=-1:
      continue
    if t_col==col[x]:
      t_col+=1
    que.append(i)
    col[i]=t_col
    ans_dict[(x+1,i+1)]=t_col
    ans_dict[(i+1,x+1)]=t_col
    t_col+=1

print(ans_num)
for i in l:
  print(ans_dict[tuple(i)])

Measured memory_bytes: 82952
#include <bits/stdc++.h>
//#pragma GCC optimize ("Ofast")

using namespace std;
#define ms(x,a) memset(x,a,sizeof x)
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7,seed=131,MAXN=0;

map<int,int> m;

int main(){
    //cin.tie(0)->sync_with_stdio(0);
    ll n; cin >> n;
    for (ll i=2;n!=1,i*i<=n;++i){
        while (n%i==0) n/=i, m[i]++;
    }
    ll tot=n!=1;
    int a;
    for (auto x:m){
        a=2;
        for (int i=1;;a++){
            if (i>x.second){ tot+=a-2; break; }
            i+=a;
        }
    }
    cout << tot << '\n';
}

Measured memory_bytes: 3648
#include <iostream>
#include <array>
#include<stdlib.h>
#include<algorithm>
using namespace std;
 int main(){
   array<int, 100> w;
   int n,s1,s2,ans;
   cin>>n;
   for(int i = 0; i<n; i++){
     cin>>w.at(i);
   }
   ans = 10000;
   int i;
   for(i = 1; i < n; i++){
     s1 = 0;
     s2 = 0;
     for(int j = 0; j < i; j++){
       s1 = s1 + w.at(j);
     }
     for(int j = i;j < n; j++){
       s2 = s2 + w.at(j);
     }
     if(ans > abs(s2-s1)){
       ans = abs(s2-s1);
     }
   }
   cout<<ans<<endl;
 }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int,int> P;

class Prim {
	struct node {
		bool done;
		vi to, dist;
		int id, from;
		ll d;
		int depth;
		bool operator<(const node & another) const {
			return !(d != another.d ? d < another.d : id < another.id);
		}
	};
public:
	vector<node> nodes;
	int n;
	Prim(int N) {
		n = N;
		nodes.resize(n);
	}
	void mainfunc(){
		priority_queue<node> pq;
		nodes[0].d = 0;
		pq.push(nodes[0]);
		while (pq.size()) {
			node focus = pq.top(); pq.pop();
			if (nodes[focus.id].done) continue;
			Loop(i, focus.to.size()) {
				int b = focus.to[i];
				if (!nodes[b].done && focus.dist[i] < nodes[b].d) {
					nodes[b].d = focus.dist[i];
					nodes[b].from = focus.id;
					nodes[b].depth = focus.depth + 1;
					pq.push(nodes[focus.to[i]]);
				}
			}
			nodes[focus.id].done = true;
		}
		return;
	}
	//sとtをつなぐパスの中で最もコストの大きい辺のコストを返す
	ll max_path_between(int s, int t) {
		ll ret = 0;
		while (nodes[s].depth > nodes[t].depth) {
			ret = max(ret, nodes[s].d);
			s = nodes[s].from;
		}
		while (nodes[s].depth < nodes[t].depth) {
			ret = max(ret, nodes[t].d);
			t = nodes[t].from;
		}
		while (s != t) {
			ret = max(ret, max(nodes[s].d, nodes[t].d));
			s = nodes[s].from;
			t = nodes[t].from;
		}
		return ret;
	}
};

int main() {
	int n, m; cin >> n >> m;
	Prim prim(n);
	Loop(i, n) prim.nodes[i] = { false,{},{}, i, -1, INFLL, 0 };
	Loop(i, m) {
		int s, t, d; cin >> s >> t >> d;
		s--; t--;
		prim.nodes[s].to.push_back(t);
		prim.nodes[s].dist.push_back(d);
		prim.nodes[t].to.push_back(s);
		prim.nodes[t].dist.push_back(d);
	}
	prim.mainfunc();
	ll sum = 0;
	Loop(i, n) sum += prim.nodes[i].d;
	int q; cin >> q;
	Loop(i, q) {
		int s, t; cin >> s >> t;
		s--; t--;
		cout << sum - prim.max_path_between(s, t) << endl;
	}
	return 0;
}

Measured memory_bytes: 40592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first < y.first;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int q; cin >> q;
    vector<ll> v;
    REP(i, q){
        int a; cin >> a;
        if(a==0){
            int b; cin >> b;
            v.push_back(b);
        }
        if(a==1){
            int b; cin >> b;
            cout << v[b] << endl;
        }
        if(a==2){
            v.pop_back();
        }
    }
            
	return 0;
}


Measured memory_bytes: 4908
def prison(N: int, M: int, queries: list)->list:
    l, r = 1, N

    for L, R in queries:
        l = max(l, L)
        r = min(r, R)

    return max(0, r-l+1)


if __name__ == "__main__":
    M = 0
    N, M = map(int, input().split())
    queries = [tuple(int(s) for s in input().split()) for _ in range(M)]

    ans = prison(N, M, queries)
    print(ans)


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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

vector<vi> g(maxn);


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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

	int n;
	cin >> n;
	map<string,int>m;
	while(n--)
	{
		string s;
		cin >> s;
		m[s]++;
	}
	
	cout << "AC x " << m["AC"];
	cout << endl;

	
	cout << "WA x " << m["WA"];
	cout << endl;
	
	
	cout << "TLE x " << m["TLE"];
	cout << endl;
	
	
	cout << "RE x " << m["RE"];
	cout << endl;
	return 0;
}



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

#ifdef LOCAL
        #include "debug.h"
        #define input freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#else
        #define debug(...) 4
        #define input 4
#endif

using ll = long long;
constexpr int N = 2e5+ 5;
constexpr int mod = 1e9 + 7;

int main() {
    input;
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);
    reverse(a, a + n);
    ll ans = 0;
    ans += a[0];
    for(int i = 1; i <= (n - 1) / 2; i++) {
        ans += a[i] + a[i];
    }
    if(n % 2)
        ans -= a[(n - 1) / 2];
    cout << ans;
}




Measured memory_bytes: 4384
a,b,c = input().split(" ")
if int(a) > int(b):
    if int(a) > int(c):
        print("A")
    else:
        if int(b) > int(c):
            print("B")
        else:
            print("C")
else:
    if int(b) > int(c):
        print("B")
    else:
        print("C")


Measured memory_bytes: 5596
import sys
input = sys.stdin.readline
import bisect

N_ken,M_si = map(int,input().split())
ken_year_map = {}
for i in range(1,N_ken+1):ken_year_map[i]=[]

ken_list = [0]*M_si
year_list = [0]*M_si

for si in range(M_si):
    ken_list[si],year_list[si] = map(int,input().split())
    ken_year_map[ken_list[si]] += [year_list[si]]
        
for i in ken_year_map:
    ken_year_map[i].sort()

for ken,year in zip(ken_list,year_list):
    print('{:06}{:06}'.format(ken,bisect.bisect_right(ken_year_map[ken], year)))


Measured memory_bytes: 32616
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstring>
using namespace std;

char a[8];
int L;
vector<int> appered;

void init() {
	appered.clear();
}

bool input() {
	scanf("%s %d", a, &L);
	if(!atoi(a) && !L)
		return false;
	return true;
}

void solve() {
	int m, M;

	m = atoi(a);
	appered.push_back(m);

	while(1) {
		for(int i = strlen(a); i < L; i++)
			a[i] = '0';
		a[L] = '\0';

		sort(a, a + L);
		m = atoi(a);

		char tmp[8];
		for(int i = 0; i < L; i++) {
			tmp[L - i - 1] = a[i];
		}
		tmp[L] = '\0';
		M = atoi(tmp);

		for(int i = 0; i < appered.size(); i++) {
			if(appered[i] == M - m) {
				cout << i << " " << M - m << " " << appered.size() - i << endl;
/*
				for(int j = 0; j < appered.size(); j++) {
					cout << "appered[" << j << "] : " << appered[j] << endl;
				}
// */
				return;
			}
		}

		appered.push_back(M - m);
		sprintf(a, "%d", M - m);
	}
}

int main() {
	while(init(), input()) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1272
#include <stdio.h>

int main(void){
  int a, b;
  scanf("%d %d\n", &a,&b);
  if(a<b){
    printf("a < b\n");
  }else if(a>b){
    printf("a > b\n");
  }else{
    printf("a == b\n");
  }
  return 0;
}





Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define input freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const ll N = 1e5+10;

const ll mod=1e9+7;
ll n;
// vis[N];
ll dp[N][2];
vector<ll> v[N];
auto addmod(auto a,auto b)
{
	ll res=(a%mod + b%mod)%mod;
	return (res<0)?(res+mod):res%mod;
}
ll go(ll src,ll val,ll par)
{
	if(dp[src][val]!=-1)
		return dp[src][val];
	ll res=1;
	for(auto i:v[src])
	{
		if(i==par)
		continue;	
		if(val==0)
		{
			res=(res*(go(i,0,src)+go(i,1,src)))%mod;
		}
		else
		{
			res=(res*go(i,0,src))%mod;
		}
	}
	return dp[src][val]=res;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	// input;
	fast;
	cin>>n;
	// vector<ll> v[n+1];
	for(ll i=1;i<n;i++)
	{
		// vis[i]=false;
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);	
		v[b].push_back(a);
	}
	cout<<addmod(go(1,0,-1),go(1,1,-1));
}

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

int main()
{
    string n;
    cin>>n;
    int i,j,k,sum=0;
    for(i=0;i<n.size();i++)
    {
        sum+=(n[i]-'0');
    }
    if(sum%9==0)
    cout<<"Yes\n";
    else
    cout<<"No\n";
}


Measured memory_bytes: 3712
open Batteries

let read_two () = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))

let read_three () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> (a, b, c))

let read_four () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c d -> (a, b, c, d))

let read_list () =
  read_line () |> String.split_on_char ' '
  |> List.map (fun s -> int_of_string s)

(* a**x *)
let pow a x =
  let rec aux acc = function 0 -> acc | n -> aux (acc * a) (n - 1) in
  aux 1 x

let rec pow2 n = if n mod 2 = 0 then 1 + pow2 (n / 2) else 0

let rec f acc = function
  | [] -> acc
  | x :: rest ->
      let new_gu = (acc +. float_of_int x) /. 2. in
      f new_gu rest

let () =
  let _ = read_int () in
  let ls = read_list () |> List.sort compare in
  let (a :: b :: rest) = ls in
  let acc = (float_of_int a +. float_of_int b) /. 2. in
  let ans = f acc rest in
  print_float ans;
  print_newline ()


Measured memory_bytes: 3072
import sys
from io import StringIO
import unittest


def resolve():
    # s = input()
    n = int(input())
    a = list(map(int, input().split()))

    sum_a = sum(a)
    ans = 0

    for aa in a:
        sum_a -= aa
        ans += aa * sum_a

    print(ans % (10 ** 9 + 7))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1 2 3"""
        output = """11"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
141421356 17320508 22360679 244949"""
        output = """437235829"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    map<string,int> m;
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        string s;
        cin>>s;
        m[s]++;
    }
    cout << "AC x "<<m["AC"] << endl;
    cout << "WA x "<<m["WA"] << endl;
    cout << "TLE x "<<m["TLE"] << endl;
    cout << "RE x "<<m["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
    int tasks[3] = {};
    int costs[6] = {};
    
    cin >> tasks[0] >> tasks[1] >> tasks[2];
    
    /* 1-2-3 */
    costs[0] += abs(tasks[1] - tasks[0]);
    costs[0] += abs(tasks[2] - tasks[1]);

    /* 1-3-2 */    
    costs[1] += abs(tasks[2] - tasks[0]);
    costs[1] += abs(tasks[1] - tasks[2]);

    /* 2-1-3 */ 
    costs[2] += abs(tasks[0] - tasks[1]);
    costs[2] += abs(tasks[2] - tasks[0]);

    /* 2-3-1 */     
    costs[3] += abs(tasks[2] - tasks[1]);
    costs[3] += abs(tasks[0] - tasks[2]);
    
    /* 3-1-2 */     
    costs[4] += abs(tasks[0] - tasks[2]);
    costs[4] += abs(tasks[1] - tasks[0]);
    
    /* 3-2-1 */     
    costs[5] += abs(tasks[1] - tasks[2]);
    costs[5] += abs(tasks[0] - tasks[1]);
    
    std::sort(costs, costs + 5);
    
    cout << costs[0] << endl;
}
    


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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n;
//ll a[maxn];

//check T
void solve()
{
    //cin >> n; rep(i, 0, n) cin >> a[i];
    int x, ans;
    cin >> x;
    rep(i, 1, 361)
    {
        if(i*x%360 == 0) {ans = i; break;}
    }
    cout << ans << endl;

    return;
}


//g++ -o out -std=c++11 A.cpp

signed main()
{
    fastIO();
    T = 1;
    //cin >> T; //this
    //cin >> T; //this
    rep(tc, 1, T+1)
    {
        //cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}


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

long long sum(long long x)
{
    return x * (x + 1) / 2;
}

long long calcPermutation(long long x, long long y)
{
    long long ans = 1;
    for (long long i = 0; i < y; i++)
    {
        ans *= (x - i);
    }
    return ans;
}

long long calcCombination(long long x, long long y)
{
    if (x < y)
    {
        return 0;
    }
    if ((x - y) < y)
    {
        y = x - y;
    }
    long long ans = calcPermutation(x, y);
    while (y > 0)
    {
        ans /= y;
        y--;
    }
    return ans;
}

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

    int A[M + 1] = {};
    int B[M + 1] = {};
    for (int i = 1; i <= M; i++)
    {
        cin >> A[i] >> B[i];
    }

    long long ans[M + 2] = {};
    long long root[N + 1] = {};
    long long count[N + 1] = {};
    for (int i = 1; i <= N; i++)
    {
        root[i] = i;
        count[i] = 1;
    }

    ans[M + 1] = calcCombination(N, 2);

    root[B[M]] = A[M];
    count[A[M]] += count[B[M]];
    count[B[M]] = 0;
    ans[M] = ans[M + 1] - 1;

    int a, b, b_pre;
    for (int i = M - 1; i > 0; i--)
    {
        a = A[i];
        a = root[a];
        while (a != root[a])
        {
            a = root[a];
        }

        b = B[i];
        b_pre = B[i];
        b = root[b];
        while (b != root[b])
        {
            root[b_pre] = a;
            b_pre = b;
            b = root[b];
        }

        ans[i] = ans[i + 1];
        if (a != b)
        {
            root[b] = a;
            // sum(a) + sum(b) - sum(a + b) = - a * b
            ans[i] -= count[a] * count[b];
            count[a] += count[b];
            count[b] = 0;
        }
    }

    for (int i = 2; i <= M + 1; i++)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 4480
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
char inp[100];
int main(void) {
	scanf("%s", inp);
	for (int i = 0; inp[i+1]; i++) {
		if (inp[i] == inp[i + 1]) {
			return !printf("Bad\n");
		}
	}
	return !printf("Good\n");
}

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

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

    // N-1個以上の辺が存在し, 最短距離が1の頂点対が辺の数だけ存在する
    if(N*(N-1)/2 < K + N - 1){
        cout << -1;
        return 0;
    }

    // 残りの N*(N-1)/2 - (N-1) = (N-1)(N-2)/2
    // の頂点対が最短距離2となるのは, ある1つの頂点からN-1個の全ての辺が出ている場合で,
    // このとき任意の辺を1つ追加するごとに最短距離2の辺が1つづつ減っていく
    // 最短距離が1の頂点対は辺の数だけ存在し, 最短距離が2以下の頂点対の数は一定なので

    int M = N*(N-1)/2 - K;
    cout << M << "\n";
    for (int i = 1; i < N; ++i) {
        cout << i << " " << N << "\n";
    }
    int edge = M - (N-1);
    for (int i = 1; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            if(edge == 0) return 0;
            edge--;
            cout << i << " " << j << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        for (int i = 1; i <= 10000; i++) {
            if ((i / 10) == B && (i * 8 / 100) == A) {
                System.out.println(i);
                return;
            }
        }

        System.out.println(-1);
        return;
    }

}

Measured memory_bytes: 24016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int; //任意長整数 
using Real32 = mp::number<mp::cpp_dec_float<32>>;
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
using Rat = boost::rational<Bint>;//有理数*/
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
ll mod = 1000000007;
ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    int n,k,ans=0,m;
    cin>>n>>k;
    m=(n*(n-1))/2;
    vector<vector<int>> v(n);

    for(int i=0;i < n;i++)
    {
        for(int j=i+1;j < n;j++)
        {
            v.at(i).pb(j);
        }
        reverse(v.at(i).begin(),v.at(i).end());
    }
    bool flag=false;

    for(int i=0;i < n;i++)
    {
        while(v.at(i).size()>1){
            if(ans==k){
                flag=true;
                break;
            }
            v.at(i).pop_back();
            ans++;
            m--;
            
        }
        if(ans==k){
            flag=true;
        }
        if(flag)break;
    }

    if(ans<k){
        cout << -1 << endl;
        return 0;
    }

    cout << m << endl;

    for(int i=0;i < n;i++)
    {
        while(v.at(i).size()>0){
            cout << i+1 <<" "<<(v.at(i).back()+1) << endl;
            v.at(i).pop_back();
        }
    }
}




Measured memory_bytes: 256