akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;
ll n,m,x;
ll cost[20];
ll inc[20][20];

ll rec(ll i, ll know[],ll minCost){
    if(i==n){
        bool flag=true;
        for(ll j=0;j<m;j++){
            if(know[j]<x){
                flag=false;
                break;
            }
        }
        if(flag) return minCost;
        else return LLONG_MAX;
    }

    ll know0[m],know1[m];
    for(ll j=0;j<m;j++){
        know0[j]=know[j];
    }
    for(ll j=0;j<m;j++){
        know1[j]=know[j]+inc[i][j];
    }

    ll temp0=rec(i+1,know0,minCost);
    ll temp1=rec(i+1,know1,minCost+cost[i]);

    return min(temp0,temp1);
}


int main()
{
    //cout << "Hello world!" << endl;

    cin>>n>>m>>x;

    for(ll i=0;i<n;i++){
        cin>>cost[i];
        for(ll j=0;j<m;j++){
            cin>>inc[i][j];
        }
    }

    ll know[m];
    memset(know,0,sizeof(know));
    ll tmp=rec(0,know,0);
    if(tmp==LLONG_MAX){
        cout<<"-1"<<endl;
    }else{
        cout<<tmp<<endl;
    }




    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 4e18;
const double INFD = 1e30;
const double EPS = 1e-10;
const long double PI = acosl(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 205;
const int MAXV = 60;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
char text[MAXN];
int cnt[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int x, t;
    scanf("%d%d%d", &n, &x, &t);
    printf("%lld\n", (ll)t * ((n + x - 1) / x));
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n + 2];
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	a[0] = 0;
	a[n + 1] = 0;
	int sum = 0;
	for(int i = 0; i <= n; i++){
		sum += abs(a[i] - a[i + 1]);
	}
	for(int i = 1; i <= n; i++){
		if(((a[i - 1] <= a[i])&&(a[i] <= a[i + 1])) || ((a[i - 1] >= a[i])&&(a[i] >= a[i + 1]))){
			cout << sum << endl;
		}else{
			cout << sum - min(abs(a[i- 1] - a[i]), abs(a[i] - a[i + 1])) * 2 << endl;
		}
	}
}

Measured memory_bytes: 1664
import java.util.*;
	import java.io.*;
class Main{
		static int n,arr[][],k	;
		static long dp[][],W;
		public static void main(String[] args) throws IOException{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			int t=1;
	//		Integer.parseInt(br.readLine().trim());
			StringBuilder printans=new StringBuilder();
			while(t-->0)
			{
				StringTokenizer tok=new StringTokenizer(br.readLine()," ");
				n=Integer.parseInt(tok.nextToken());
				W=0;
				arr=new int[n][3];
				
				for(int i=0;i<n;i++) {
					tok=new StringTokenizer(br.readLine()," ");
					arr[i][0]=Integer.parseInt(tok.nextToken());
					arr[i][1]=Integer.parseInt(tok.nextToken());
					arr[i][2]=Integer.parseInt(tok.nextToken());
				
				}
				dp=new long[n][3];
				memset();
				call(n-2);
				printans.append(Math.max(dp[0][0], Math.max(dp[0][1],dp[0][2])));
			    
			}
			System.out.println(printans);
			
		}
		static void memset() {
			for(long a[]:dp) {
				Arrays.fill(a, -1);
			}
			dp[n-1][0]=arr[n-1][0];
			dp[n-1][1]=arr[n-1][1];
			dp[n-1][2]=arr[n-1][2];
		}
		static void call(int i) {
			if(i<0) {
				return;
			}
			
			long ans=0;
			
			
			dp[i][0]=arr[i][0]+Math.max(dp[i+1][1],dp[i+1][2]);
			dp[i][1]=arr[i][1]+Math.max(dp[i+1][0],dp[i+1][2]);
			dp[i][2]=arr[i][2]+Math.max(dp[i+1][0],dp[i+1][1]);
			call(i-1);
			
			
			
			
		}
			
			
	}


Measured memory_bytes: 61348
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
int dp[4000][4000],g[4000],head[4000];
int n,k,ans;
bool visited[4000];
vector<int> graph[4000];
void dfs(int x)
{
	dp[x][0]=1;
	for (int j=1;j<=k+1;j++)
	{
		dp[x][j]=0;
	}
	visited[x]=1;
	for(int second : graph[x])
	{
		if(!visited[second])
		{
			dfs(second);
			g[0]=dp[x][0];
			for (int j=1;j<=k+1;j++)
            {
            	g[j]=min(g[j-1],dp[x][j]);
            }
			for (int j=1;j<=k+1;j++)
            {
            	dp[x][j]=n;
            }
			for (int j=1;j<=min(k+1,dp[x][0]);j++)
            {
				for (int w=0;w<=min(k,dp[second][0]);w++)
                {
					if (j-1+w<=k)
                    {
                    	dp[x][max(j,w+1)]=min(dp[x][max(j,w+1)],g[j]+dp[second][w]);
                    }
                }
            }
			dp[x][0]+=dp[second][0];
		}
	}
	for (int j=1;j<=k+1;j++)
    {
    	dp[x][j]=min(dp[x][j],dp[x][j-1]);
    }
	ans=min(ans,n-dp[x][0]+dp[x][k+1]);
}

int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	memset(visited,0,sizeof(visited));
	ans=n;
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 27684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    ll a[n],min0=2e9,ans=0,c=0;
    rep(0,i,n){
        cin>>a[i];
        ans+=abs(a[i]);
        min0=min(min0,abs(a[i]));
        if(a[i]<0)++c;
        
    }
    //cout<<ans<<endl;
    //cout<<min0<<endl;
    if(c%2==0){
        cout<<ans<<endl;
    }else{
        cout<<ans-2*min0<<endl;
    }
}


Measured memory_bytes: 1024
function main() {
  var
  i = 0, j, y, x,
  xy, cells, answers = {},
  dummy = [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2];
  for (;;) {
    xy = input[i++].split(' ').map(parseFloat);
    cells = [];
    if (xy[0] === 0 && xy[1] === 0) break;
    
    for (j = 0; j < xy[1]; j++) {
      cells.push(input[i++].split(' ').map(parseFloat));
    }
    cells.push(dummy);
    
    answer = 0;
    answers = {};
    for (x = 0; x < xy[0]; x++) answers[[x, 0]] = cells[0][x] === 0 ? 1 : 0;
    for (y = 0; y < xy[1]; y++) {
      for (x = 0; x < xy[0]; x++) {
        answers[[x, y]] = answers[[x, y]] || 0;
        switch (cells[y][x]) {
        case 0:
          if (cells[y + 1][x - 1] !== 2) answers[[x - 1, y + 1]] = (answers[[x - 1, y + 1]] || 0) + answers[[x, y]];
          answers[[x, y + 1]] = (answers[[x, y + 1]] || 0) + answers[[x, y]];
          if (cells[y + 1][x + 1] !== 2) answers[[x + 1, y + 1]] = (answers[[x + 1, y + 1]] || 0) + answers[[x, y]];
          break;
        case 1:
          break;
        case 2:
          answers[[x, y + 2]] = (answers[[x, y + 2]] || 0) + answers[[x, y]];
          break;
        }
      }
    }

//    show(xy, answers);

    for (y = xy[1]; y <= xy[1] + 1; y++) {
      for(x = 0; x < xy[0]; x++) {
        answer += answers[[x, y]] || 0;
      }
    }

    console.log(answer);
  }
}


function show(xy, answers) {
  var
  x, y, line;
  for (y = 0; y <= xy[1]; y++) {
    line = [];
    for (x = 0; x < xy[0]; x++) {
      line.push(answers[[x, y]] || 0);
    }
    console.log(line.join(' '));
  }
}


var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 10956
from fractions import gcd

n=int(input())
a=list(map(int,input().split()))
ans=10**18
t=0
for i in range(1,n):
  if i==1:
    t=gcd(a[0],a[1])
    ans=min(ans,t)
    continue
  t=gcd(t,a[i])
  ans=min(t,ans)
print(ans)


Measured memory_bytes: 16240
#52c
import math
import collections

MODBY = 7 + 10**9

N = int(input()) #10**3

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pf_dict = dict()

for i in range(2,N+1):
    c = collections.Counter(prime_factorize(i))
    for j in c.items():
        if j[0] not in pf_dict:
            pf_dict[j[0]] = j[1]
        else:
            pf_dict[j[0]] += j[1]

ans = 1
for i in  pf_dict.values():
    ans = ans*(i+1)
    
print(ans%MODBY)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
//Auther: Arin Roday
#define vec vector
#define i64 long long
#define endl '\n'
#define sz(x) (x).size()
#define times(n) for(int i = 0; i < (n); ++i)
#define bits(x) __builtin_popcount(x)
 
int test_case_number = 1;

void print_case(){
    #ifdef LOCAL
    cout << "Case #" << test_case_number++ << ": ";
    #endif
}

void solve(){
    int k;
    cin >> k;
    set<int> s;
    int r = 7 % k;
    int c = 1;
    while(true){
        if(r == 0){
            cout << c << endl;
            return;
        }
        if(s.count(r) == 1){
            cout << -1 << endl;
            return;
        }
        s.insert(r);
        c++;
        r = (r * 10 + 7) % k;
    }

}
 
int main(){
    solve();
}

Measured memory_bytes: 50452
import numpy as np
import sys
i4 = np.int32

if sys.argv[-1] == 'ONLINE_JUDGE':
    adjacency_list = '''
import numpy as np
from numba import njit
from collections import namedtuple

AdjacencyList = namedtuple('AdjacencyList', ['v', 'adj'])

@njit
def adjacency_list(n, a):
    """
    隣接リストの作成
    :param n: vertex の数
    :param a: 2d の ndarray, 各行は、[u, v] u: Edge の始点、v: Edge の終点
    :return: AdjacencyList
    """
    v = np.zeros(n + 1, np.int32)
    for i in range(a.shape[0]):
        v[a[i, 0] + 1] += 1
    for i in range(1, v.shape[0]):
        v[i] += v[i - 1]
    adj = np.empty(a.shape[0], np.int32)
    temp = np.zeros(n, np.int32)
    for i in range(a.shape[0]):
        from_ = a[i, 0]
        adj[v[from_] + temp[from_]] = a[i, 1]
        temp[from_] += 1
    return AdjacencyList(v, adj)


@njit
def at(gc, n):
    return gc.adj[gc.v[n]:gc.v[n + 1]]


@njit
def iter(gc, n):
    for i in range(gc.v[n], gc.v[n + 1]):
        yield gc.adj[i]        
    '''
    import os
    os.makedirs('nbacl/graphs', exist_ok=True)
    with open('nbacl/graphs/adjacency_list.py', 'w') as f:
        f.write(adjacency_list)

    abc138_d_numba = '''
import numpy as np
import nbacl.graphs.adjacency_list as tree
from numba import njit
from numba.types import Array, int32
from numba.pycc import CC
i4 = np.int32
cc = CC('abc138_d_numba')


@njit((int32, int32, Array(int32, 1, 'C'), Array(int32, 1, 'C'), Array(int32, 1, 'C'), Array(int32, 1, 'C')))
def dfs(d, prev, v, adj, u, val):
    y = val[d]
    for i in range(v[d], v[d + 1]):
        x = adj[i]
        if x == prev:
            continue
        val[x] = y + u[x]
        dfs(x, d, v, adj, u, val)


@cc.export('solve', (Array(int32, 2, 'C'), Array(int32, 2, 'C'), int32))
def solve(a, p, N):
    tr = tree.adjacency_list(N, a)
    u = np.zeros(N, i4)
    val = np.zeros(N, i4)
    for i in range(p.shape[0]):
        u[p[i, 0] - 1] += p[i, 1]
    val[0] = u[0]
    dfs(0, -1, tr.v, tr.adj, u, val)
    return val


if __name__ == '__main__':
    cc.compile()
    '''
    with open('abc138_d_numba.py', 'w') as f:
        f.write(abc138_d_numba)
    import subprocess
    cmd = "python3.8 abc138_d_numba.py"
    subprocess.run(cmd.split())
    exit(0)


from abc138_d_numba import solve

def main():
    f = open(0)
    N, Q = [int(x) for x in f.readline().split()]
    ap = np.fromstring(f.read(), i4, sep=' ').reshape((-1, 2))
    a = ap[:N - 1] - 1
    a = np.concatenate((a, a[:, ::-1]))
    p = ap[N - 1:]
    val = solve(a, p, N)
    print(*val.tolist())


if __name__ == '__main__':
    main()


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int rem = N % 500;

	if (rem <= A){
		cout << "Yes" << "\n";
	} else {
				cout << "No" << "\n";
	}

	

	return 0;
}


Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d %d", $n, $d);
  $cnt = 0;
  for($i=0; $i<$n; $i++){
      fscanf(STDIN, "%d %d", $x, $y);
      $dis = sqrt(($x**2) + ($y**2));
      if($dis <= $d){
          $cnt++;
      }
  }
  echo $cnt;

Measured memory_bytes: 16160
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		int count = 0;
		long n = y / x;
		while (n > 0) {
			n /= 2;
			count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    vi vx(x),vy(y),vz(z);
    rep(i,x)cin >> vx[i];
    rep(i,y)cin >> vy[i];
    rep(i,z)cin >> vz[i];
    vi v;
    rep(i,x)rep(j,y)v.push_back(vx[i]+vy[j]);
    sort(all(v));
    vi vv;
    rep(i,min(k,(int)v.size()))rep(j,min(k,z)){
        vv.push_back(v[v.size()-1-i]+vz[z-1-j]);
    }
    sort(all(vv));
    rep(i,k)cout << vv[vv.size()-1-i] << endl;
}


Measured memory_bytes: 43240
fun main(args: Array<String>) {

    val inLine = readLine()?.split(" ").orEmpty()
    val countN = inLine[0].toLong()
    val colorK = inLine[1].toLong()


    if(countN == 1L){
        println(colorK)
    }else{
        println( colorK * paintPattern(countN - 1,colorK - 1))
    }

}

fun paintPattern(n: Long, k:Long): Long{
    if(n <= 1) return k
    return k * paintPattern(n - 1, k)

}

Measured memory_bytes: 37692
def main():
    n = int(input())

    l = []
    for i in range(n):
        l.append(list(map(int, input().split())))

    l.sort(key = lambda x:-x[2])

    for cx in range(0, 101):
        for cy in range(0, 101):
            for i, xyh in enumerate(l):
                x,y,h = xyh
                if i == 0:
                    H = h + abs(x-cx) + abs(y-cy)
                    if H < 1 or H != int(H):
                        break
                    continue
                if h != max((H - abs(x-cx) - abs(y-cy)), 0):
                    break
                if i == n-1:
                    print(cx,cy,H)
                    return

if __name__ == "__main__":
    main()

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

sum_=0
A =list(map(int,input().split()))
j=0
ans=0
sum_=0
for i in range(N):
    k=0
    while j<N and sum_+A[j]==sum_^A[j]:
        sum_+=A[j]
        ans+=j-i+1
        j+=1
    sum_-=A[i]
print(ans)

Measured memory_bytes: 24840
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(n):
  if a[i]>b[i]:
    c.append(a[i]-b[i])
  elif a[i]<b[i]:
    d.append(b[i]-a[i])
c.sort(reverse=True)
if sum(c)<sum(d):
  print(-1)
elif sum(c)==sum(d):
  print(len(c)+len(d))
else:
  ans=0
  if len(c)==1:
    print(1+len(d))
  else:
    for i in range(len(c)):
      if sum(c[:i])>=sum(d):
        ans=i
        break
    print(ans+len(d))

Measured memory_bytes: 121784
def main():
    n = int(input())
    a = list(map(int, input().split()))
    last = a[0]
    money = 1000
    kabu = 0
    for i, kabuka in enumerate(a):
        if i == len(a)-1:
            break
        if a[i+1] > a[i]:
            kabu = money//a[i]
            money += (a[i+1] - a[i]) * kabu
    print(money)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9132
#include <iostream>

using namespace std;

int main() {

    string S;
    cin >> S;

    int a1=0,a2=0;
    int T=0;

    for(int i = 0; i < S.size(); i++) {

        if(S[i] == 'g') {
            if(a1 < a2) {
                a1++;
                T++;
            } else {
                a2++;
            }
        } else {
            if(a1 < a2) {
                a1++;
            } else {
                a2++;
                T--;
            }
        }

    }

    cout << T;

    return 0;
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}

template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}

template <typename T> void print(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void print(const T &value, const Args&... args){std::cout << value << " ";print(args...);}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;

  while(cin >> N){
    int ans;

    FORE(i,1,100000){
      if((N * i) % 360 == 0){
        ans = i;
        break;
      }
    }


    print(ans);
  }

  return 0;
}


Measured memory_bytes: 3648
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")
 
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
 
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;
 
// #define X first
// #define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
 
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);
 
const int INF = 1E18;
const int mod = 1E9 + 7;
const int maxn = 1E5 + 5;

vector<int> adj[maxn], vis(maxn, 0);
deque<int> deck;

void dfs(int now, int root) {
    vis[now] = 1;
    for (auto x : adj[now]) {
        if (!vis[x]) {
            vis[x] = 1;
            
            if (root == -1) deck.push_front(x);
            else deck.push_back(x);
            
            dfs(x, root);
            
            if (now != root) return;
            else root = -1;
        }
    }
}

int32_t main() {
    fastIO();
    
    int n, m, u, v;
    cin >> n >> m;
    
    while (m--) cin >> u >> v, adj[u].eb(v), adj[v].eb(u);
    
    deck.push_back(1), dfs(1, 1);
    
    cout << deck.size() << "\n";
    while (!deck.empty()) {cout << deck.front() << " "; deck.pop_front();}
    
    return 0;
}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace  std;
string str[1005];
bool cmp(string a, string b){
    return a+b<b+a;
}
int main(){
    int n,t;
    cin>>n>>t;
    for(int i=0;i<n;i++){
        cin>>str[i];
    }
    sort(str,str+n,cmp);
    for(int i=0;i<n;i++){
        cout<<str[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

#define COMB_MAX (int)1e6 + 10
ll f[COMB_MAX], rf[COMB_MAX];
ll inv(ll x) {
	ll res = 1;
	ll k = mod - 2;
	ll y = x;
	while (k) {
		if (k & 1) res = (res * y) % mod;
		y = (y * y) % mod;
		k /= 2;
	}
	return res;
}
void init() {
	f[0] = 1;
	rep(i, 1, COMB_MAX) f[i] = (f[i - 1] * i) % mod;
	rep(i, 0, COMB_MAX) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
	if (k<0 || k>n || n < 0)return 0;
	ll a = f[n]; // = n!
	ll b = rf[n - k]; // = (n-k)!
	ll c = rf[k]; // = k!

	ll bc = (b * c) % mod;

	return (a * bc) % mod;
}
int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, 0, n)cin >> a[i];
	sort(all(a));
	init();
	ll ans = 0;
	rep(r, 0, n)ans += a[r] * C(r, k - 1) % mod, ans %= mod;
	rep(l, 0, n)ans += mod - a[l] * C(n - l - 1, k - 1) % mod, ans %= mod;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 19312
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.min;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		int n = scanInt();
		boolean have[][] = new boolean[n + 2][n + 2];
		int dist[][] = new int[n + 2][n + 2];
		for (int i = 1; i <= n; i++) {
			fill(have[i], 1, n + 1, true);
			for (int j = 1; j <= n; j++) {
				dist[i][j] = min(min(i, n + 1 - i), min(j, n + 1 - j));
			}
		}
		int queue[] = new int[4 * n * n];
		int ans = 0;
		for (int it = 0; it < n * n; it++) {
			int cur = scanInt() - 1;
			int si = cur / n + 1, sj = cur % n + 1;
			have[si][sj] = false;
			ans += --dist[si][sj];
			int queueHead = 2 * n * n, queueTail = queueHead + 2;
			queue[queueHead] = si;
			queue[queueHead + 1] = sj;
			do {
				int i = queue[queueHead++], j = queue[queueHead++], d = dist[i][j];
				if (have[i - 1][j]) {
					if (dist[i - 1][j] > d + 1) {
						dist[i - 1][j] = d + 1;
						queue[queueTail++] = i - 1;
						queue[queueTail++] = j;
					}
				} else {
					if (dist[i - 1][j] > d) {
						dist[i - 1][j] = d;
						queue[--queueHead] = j;
						queue[--queueHead] = i - 1;
					}
				}
				if (have[i + 1][j]) {
					if (dist[i + 1][j] > d + 1) {
						dist[i + 1][j] = d + 1;
						queue[queueTail++] = i + 1;
						queue[queueTail++] = j;
					}
				} else {
					if (dist[i + 1][j] > d) {
						dist[i + 1][j] = d;
						queue[--queueHead] = j;
						queue[--queueHead] = i + 1;
					}
				}
				if (have[i][j - 1]) {
					if (dist[i][j - 1] > d + 1) {
						dist[i][j - 1] = d + 1;
						queue[queueTail++] = i;
						queue[queueTail++] = j - 1;
					}
				} else {
					if (dist[i][j - 1] > d) {
						dist[i][j - 1] = d;
						queue[--queueHead] = j - 1;
						queue[--queueHead] = i;
					}
				}
				if (have[i][j + 1]) {
					if (dist[i][j + 1] > d + 1) {
						dist[i][j + 1] = d + 1;
						queue[queueTail++] = i;
						queue[queueTail++] = j + 1;
					}
				} else {
					if (dist[i][j + 1] > d) {
						dist[i][j + 1] = d;
						queue[--queueHead] = j + 1;
						queue[--queueHead] = i;
					}
				}
			} while (queueHead < queueTail);
		}
		out.print(ans);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 58632
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

n = sum(b) - sum(a)
c = 0
for i in range(N):
    if a[i] < b[i]:
        c += (b[i] - a[i] + 2 - 1) // 2
print('Yes' if c <= n else 'No')


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }

ll mod=1e9+7;
ll MAX=1e5+5;
vector<ll> fact(MAX),fact_inv(MAX);
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
ll comb(ll n, ll r){
    if(n<r || n<0 || r<0) return 0;
    if(r==0) return 1;
    return(fact[n]*fact_inv[r])%mod*fact_inv[n-r]%mod;
}

int main(){
    ll n; cin>>n;
    ll d;
    vector<ll> used(100010, -1);
    rep(i,n+1){
        ll a; cin>>a;
        if(used[a]!=-1) d=i-used[a];
        used[a]=i;
    }
    fact[0]=1;
    rep(i,n+1)fact[i+1]=fact[i]*(i+1)%mod;
    fact_inv[n+1]=power(fact[n+1],mod-2);
    rep(i,n+1)fact_inv[n-i]=fact_inv[n+1-i]*(n+1-i)%mod;
    for(ll k=1; k<=n+1; k++){
        ll res=comb(n+1, k);
        res-=comb(n-d, k-1);
        res%=mod;
        if(res<0) res+=mod;
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 3584
n = int(input())
h = list(map(int, input().split()))
ans = 0
count = 0
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        count += 1
    else:
        ans = max(ans, count)
        count = 0
ans = max(ans, count)
print(ans)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll summ(ll x){
	return (x*(x+1))/2;
}
int main(){
	
	ll n; cin>>n;
	vector<string> v;
	string s;
	for(int i = 0; i < n; i++){
		cin>>s;
		sort(s.begin(), s.end());
		v.push_back(s);
	}
	ll co = 1;
	ll best = 0;
	sort(v.begin(),v.end());
	vector<int> ans;
	for(int i = 1; i < n; i++){
		if(v[i] == v[i-1]){
			co++;
		}
		else{
			ans.push_back(co);
			co = 1;
		}
	}
	ans.push_back(co);
	ll ff = 0;
	for(auto xx : ans) ff += summ((xx-1));
	cout<<ff<<"\n";
	
	
	
	
	
	
	
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int i,j;
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

}

Measured memory_bytes: 256
use std::collections::VecDeque;

fn main() {
    let (n,m) = read_pair();
    let neighbors = {
        let mut neighbors = vec![Vec::new(); n];
        for _ in 0..m {
            let (u,v): (usize,usize) = read_pair();
            neighbors[u-1].push(v-1);
        }
        neighbors
    };
    let (s,t): (usize,usize) = {
        let (s,t): (usize, usize) = read_pair();
        (s-1,t-1)
    };

    let mut stack = VecDeque::new();
    let mut dist = vec![-3; 3*n];

    stack.push_back((s,0));
    dist[3*s] = 0;
    while let Some((v, a)) = stack.pop_front() {
        let b = (a+1)%3;
        for &w in &neighbors[v] {
            if dist[3*w+b] == -3
                || dist[3*w+b] > dist[3*v+a] + 1 {
                dist[3*w+b] = dist[3*v+a] + 1;
                stack.push_back((w,b));
            }
        }
    }

    println!("{}", dist[3*t] / 3);
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}
fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_pair<T: std::str::FromStr + Copy>() -> (T,T){
    let v:Vec<T> = read_vec(); (v[0], v[1])
}

Measured memory_bytes: 12540
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll x; cin >> x;
	ll ans = x / 500 * 1000;
	ans += (x % 500) / 5 * 5;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int n;
  char c;
  long int array[10000];
  long int i = 0, max, min;
  long int total;
  
  scanf("%d", &n);
  while(i < 10000) {
    scanf("%ld%c", &array[i], &c);
    i++;
    if(c == '\n')
      break;
  }

  max = array[0];
  min = array[0];
  total = 0;
  for(i = 0; i < n; i++) {
    total += array[i];
    if(max < array[i])
      max = array[i];
    if(min > array[i])
      min = array[i];
  }

  printf("%ld %ld %ld\n", min, max, total);
  
  return 0;
}


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

int main() {
  int n, m, c;
  cin >> n >> m >> c;

  int b[21];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  int corrects = 0;
  int a[21];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[j];
    }

    int sum = c;
    for (int j = 0; j < m; j++) {
      sum += a[j] * b[j];
    }

    if (sum > 0) {
      corrects++;
    }
  }

  cout << corrects << endl;
  return 0;
}

Measured memory_bytes: 888
#include<iostream>

using namespace std ;

int main()
{
	int h ,w ;
	while( cin >> h >> w ,h )
	{
		for( ; h > 0 ; h-- )
		{
			for( int i = w ; i > 0 ; i-- )
				cout << "#" ;
			cout << endl ;
		}
		cout << endl ;
	}
	return 0 ;
}

Measured memory_bytes: 3088
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
inline constexpr ll intpow(ll a,ll b){if(b==0) return 1;ll ans=intpow(a,b/2);return ans*ans*(b&1?a:1);}


int main(){
    ll h,w;
    cin>>h>>w;
    vector<string>s(h);
    rep(i,0,h)cin>>s[i];
    vector<ll>cnt1(h),cnt2(w);
    rep(i,0,h)rep(j,0,w)if(s[i][j]=='#'){
        cnt1[i]++;
        cnt2[j]++;
    }
    rep(i,0,h)if(cnt1[i]){
        rep(j,0,w)if(cnt2[j])cout<<s[i][j];
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

// 二部グラフ判定
vector<int> color;
bool dfs(const Graph &G, int v, int cur = 0) {
    color[v] = cur;
    for (auto next_v : G[v]) {
        // 隣接頂点がすでに色確定していた場合
        if (color[next_v] != -1) {
            if (color[next_v] == cur) return false; // 同じ色が隣接したらダメ
            continue;
        }

        // 隣接頂点の色を変えて、再帰的に探索 (一回でも false が返ってきたら false)
        if (!dfs(G, next_v , 1 - cur)) return false;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    int ans = 0;
    Graph g(n);
    rep(i,n){
        string iinfo;
        cin >> iinfo;
        rep(j,n){
            if(iinfo[j]=='1'){
                g[i].pb(j);
                g[j].pb(i);
            }
        }
    }
    color.assign(n, -1);
    bool is_bipartite = true;
    for (int v = 0; v < n; ++v) {
        if (color[v] != -1) continue; // v が探索済みだったらスルー
        if (!dfs(g, v)) is_bipartite = false;
    }
    if(!is_bipartite){
        ans = -1;
    }else{
        vector<vector<int>> dist(n,vector<int>(n));

        // Floyd-Warshall の初期化: dist[i][i] = 0 に注意
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) dist[i][j] = 10000000;
            dist[i][i] = 0;
        }
        
        // 入力と Floyd-Warshall
        rep(i,n){
            int isize = g[i].size();
            rep(j,isize){
                int from = i;
                int to = g[i][j];
                dist[from][to] = 1;
                dist[to][from] = 1;
            }
        }

        for (int k = 0; k < n; ++k)
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        
        int max_dist = 0;
        rep(i,n){
            rep(j,n){
                if(dist[i][j] > max_dist){
                    max_dist = dist[i][j];
                }
            }
        }
        ans = max_dist + 1;
    }
    cout << ans;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit multiset<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,m,k,pre[200005],dp1[200005],suf[200005],dp2[200005];
char s[200005];
multiset<int> st;
int getmx(){
    sit it = st.end();
    it--;
    return *it;
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    scanf("%s",s+1);
    if(k == 0){
        int cnt = 0;
        rep(i,1,n) cnt += s[i] == 'o';
        if(cnt == m) rep(i,1,n) if(s[i] == 'o') printf("%d\n",i);
        return 0;
    }
    rep(i,1,n) {
        if(s[i] == 'o') {
            dp1[i] = pre[i-1];
            if(i - k - 1 >= 0) dp1[i] = max(dp1[i], pre[i - k - 1] + 1);
            else dp1[i] = max(dp1[i], 1);
        }
        else dp1[i] = -inf;
        pre[i] = max(pre[i - 1],dp1[i]);
    }
    per(i,n,1){
        if(s[i] == 'o') {
            dp2[i] = suf[i+1];
            if(i + k + 1 <= n + 1) dp2[i] = max(dp2[i], suf[i + k + 1] + 1);
            else dp2[i] = max(dp2[i], 1);
        }
        else dp2[i] = -inf;
        suf[i] = max(suf[i + 1],dp2[i]);
    }
    rep(i,1-k,0) st.insert((i > 0 ? pre[i-1] : 0) + (i + k > n ? 0 : suf[i + k]));
    rep(i,1,n){
        st.insert(pre[i-1] + (i + k > n ? 0 : suf[i + k]));
        int fr = i - k;
        st.erase(st.find((fr > 0 ? pre[fr-1] : 0) + (fr + k > n ? 0 : suf[fr + k])));
        if(s[i] == 'o' && getmx() < m) printf("%d\n",i);
    }
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int c[5002][5002];
int main(){
    int i(0), n, mx(0); string s; cin >> n >> s;
    for (int j=i+1; j<n; j++) c[i][j]=(s[i]==s[j]);
    for (int i=1; i<n; i++){
        for (int j=i+1; j<n; j++) {
            c[i][j] = (c[i - 1][j - 1] + 1)*(s[i] == s[j] && j - i > c[i - 1][j - 1]);
            mx=max(mx,c[i][j]);
        }
    }
    cout << mx;
}

Measured memory_bytes: 96768
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,x,y=map(int,input().split())
    x-=1; y-=1
    E1=[[] for _ in range(n)]
    E2=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1; v-=1
        E1[u].append(v)
        E1[v].append(u)
    E2=E1

    # E2 において、y-rooted tree とみて、depth,par を計算
    par=[None]*n # x の必勝頂点を判定するのに必要
    par[y]=y
    depth2=[None]*n
    depth2[y]=0
    Q=[y]
    while(Q):
        v=Q.pop()
        for nv in E2[v]:
            if(depth2[nv] is not None): continue
            depth2[nv]=depth2[v]+1
            par[nv]=v
            Q.append(nv)

    # E1の辺で、E2での距離が 3 以上のものは必勝
    win=[0]*n
    for v in range(n):
        for nv in E1[v]:
            if(par[v]==nv or par[nv]==v or par[v]==par[nv] or par[par[v]]==nv or par[par[nv]]==v): continue
            win[nv]=win[v]=1

    # E1 において、x-rooted tree とみて探索
    # depth1 < depth2 -> 以降も探索できる
    # depth1 = depth2 -> そこで捕まる
    ans=depth2[x]
    depth1=[None]*n
    depth1[x]=0
    Q=[x]
    while(Q):
        v=Q.pop()
        if(win[v]): # 探索できる状態 & 必勝頂点にいれば勝ち
            print(-1)
            return
        for nv in E1[v]:
            if(depth1[nv] is not None): continue
            depth1[nv]=depth1[v]+1
            ans=max(ans,depth2[nv])
            if(depth1[nv]<depth2[nv]): Q.append(nv)

    print(ans-1)
resolve()

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

int main(){
  int n;
  cin >> n;
  int d[n];
  for(int i=0;i<n;i++)
    cin >> d[i];
  sort(d,d+n);
  cout << d[n/2]-d[n/2-1] << endl;
}

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

int main()
{
	int n = 0, k = 0;
	vector<long> a;
	long t = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> t;
		if (t > 100000)
			k++;
		else
			a.push_back(t);
	}

	sort(a.begin(), a.end());

	for (int j = 100000; j > 0; j--) {
		int c = 0;
		while (a.size() > 0 && a[a.size() - 1] == j) {
			c++;
			a.pop_back();
		}
		if (c >= j)
			k += c - j;
		else
			k += c;
	}

	cout << k << endl;

	return 0;
}

Measured memory_bytes: 1400
#まだ
N,M=map(int,input().split())
a_l=[]
b_l=[]
for i in range(N):
    a_l.append(list(input()))
for i in range(M):
    b_l.extend(input())
count=0
for t in range (N-M+1):
    for k in range(N-M+1):
        tmp=[]
        for i in range(M):
            for j in range(M):
                tmp.append(a_l[t+i][k+j])
        if tmp == b_l:
            break
    if tmp == b_l:
        print('Yes')
        count=1
        break
    else:
        continue
if count==0:
    print('No')


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

const int INF = 0x3f3f3f3f, MAX_N=1e5+10;
int N;
int a[MAX_N], b[MAX_N], c[MAX_N];
int dp[MAX_N][3];

void solve()
{
	memset(dp, 0, sizeof(dp));
	dp[0][0]=a[0], dp[0][1]=b[0], dp[0][2] = c[0];
	for(int i=1;i<N;++i){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a[i];
		dp[i][1] = max(dp[i-1][2], dp[i-1][0])+b[i];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
	}
	int ans = max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2]));
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i) cin >> a[i] >> b[i] >> c[i];
	solve();
	return 0;
}

Measured memory_bytes: 2560
class Reader:
    def __init__(self, s):
        self.t = list(s)

    def __call__(self, s):
        t = s.split()
        l, r = int(t[1]), int(t[2])+1
        if t[0] == "reverse":
            for i, v in zip(range(l,r), reversed(self.t[l:r])):
                self.t[i] = v
        elif t[0] == "replace":
            for i, v in zip(range(l,r), t[3]):
                self.t[i] = v
        else:
            print("".join(self.t[l:r]))

reader = Reader(input())
n = int(input())
for _ in range(n):
    reader(input())

Measured memory_bytes: 7796
#include <stdio.h>
#define N 105
#define WHITE 0
#define BLACK 1
#define GRAY 2
void visit(int);
void dfs();
int time,n;
int M[N][N],color[N],d[N],f[N];

int main()
{
  int a,b,c,i,j;
  
  scanf("%d",&n);   //頂点数
  for (i=1;i<=n;i++){
    for (j=1;j<=n;j++){
      M[i][j] = 0;
    }
  }
  for (i=1;i<=n;i++){
    scanf("%d%d",&a,&b);    //頂点の番号,aの出次数
    for (j=1;j<=b;j++){
      scanf("%d",&c);       //aに隣接する頂点の番号
      M[a][c] = 1;
    }  
  }
  dfs();
  for (i=1;i<=n;i++)
    printf("%d %d %d\n",i,d[i],f[i]);

  return 0;
}

 

void visit(int r){
  int i;
  
  color[r]=GRAY;
  d[r]=++time;
  
  for(i=1;i<=n;i++){
    if(M[r][i]==WHITE)
      continue;
    if(color[i]==WHITE)  //通れない
      visit(i);
  }
  color[r]=BLACK;
  f[r]=++time;
}


void dfs(void){
  int j;
  for(j=1;j<=n;j++){
    color[j]=WHITE;  //初期化
  }
  time=0;

  for(j=1;j<=n;j++){   //黒になるまでまわす
    if(color[j]==WHITE)
      visit(j);
  }
}
  



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin>>n;
    vector<ll> d(n);
    rep(i,n) cin>>d[i];
    
    ll ans=0;
    rep(i,n) {
        rep(j,n) {
            if(i==j) continue;
            ans+=d[i]*d[j];
        }
    }
    cout<<ans/2<<endl;
}


Measured memory_bytes: 256