akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int n,m,i,j,k;
int num,id,cnt;

char A[10];
char B[10];
char tmp;

int flg[1001];

int main(){
  A[1]='o';
  
  while(1){
    scanf("%d %d",&m,&n);
    if(m==0&&n==0)break;
    
    for(i=1;i<=m;i++)flg[i]=0;
    id=1;
    cnt=m;
    
    for(i=1;i<=n;i++){

      if(i%15==0){
        strcpy(A,"FizzBuzz");
      }else if(i%5==0){
        strcpy(A,"Buzz");
      }else if(i%3==0){
        strcpy(A,"Fizz");
      }else{
        
        sprintf(A,"%d",i);
        
        /*
          j=0;
          while(num>0){
          A[j]=num%10+'0';
          j++;
          num/=10;
          }
          for(k=0;k<j/2;k++){
          tmp=A[k];
          A[k]=A[j-1-k];
          A[j-1-k]=tmp;
          }
          A[j]='\0';
        */
        
      }
      
      scanf("%s",B);
      
      if(cnt==1)continue;

      if(strcmp(A,B)!=0){
        flg[id]=1;
        cnt--;
      }
      
      while(1){
        id++;
        if(id==m+1)id=1;
        if(flg[id]==0)break;
      }
      
    }
    
    j=0;
    for(i=1;i<=m;i++){
      if(flg[i]==0){
        if(j!=0)printf(" ");
        j=1;
        printf("%d",i);
      }
    }
    printf("\n");
    
  }
  return 0;
}

Measured memory_bytes: 636
s = gets.chomp.to_s
if s[0..1].to_i >= 1 && s[0..1].to_i <= 12
    if s[2..3].to_i >= 1 && s[2..3].to_i <= 12
        puts  'AMBIGUOUS'
    else
        puts 'MMYY'
    end
elsif s[2..3].to_i >= 1 && s[2..3].to_i <= 12
    puts 'YYMM'
else
    puts 'NA'
end


Measured memory_bytes: 1788
use std::io::*;

fn check(x: u64, n: u64) -> u64 {
    let mut m = n / x;
    while m % x == 0 {
        m /= x;
    }
    if m % x == 1 {
        1
    } else {
        0
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: u64 = itr.next().unwrap().parse().unwrap();
    let m = n - 1;

    let mut ans = 0;
    let mut i = 1u64;
    // 足すだけ: 1 + x * Kを満たすxがあるか
    while i * i <= m {
        if m % i == 0 {
            ans += 1;
            if m / i != i {
                ans += 1;
            }
        }
        i += 1;
    }
    // 一度でもかけるとKの倍数
    // N mod K == 0 => N + K mod K == 0
    i = 2u64;
    while i * i <= n {
        if n % i == 0 {
            ans += check(i, n);
            if n / i != i {
                ans += check(n / i, n);
            }
        }
        i += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int x = scan.nextInt();
        System.out.println(x == 0 ? 1 : 0);
    }
}


Measured memory_bytes: 35636
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=input()
    YesNo(int(N[:3])%111==0 or int(N[1:])%111==0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
;;; compare
(defun read-num (&optional (stream *standard-input*))
  (parse-integer (read-line stream)))

(defun solve (a b)
  (cond ((> a b) (format t "GREATER~%"))
	((< a b) (format t "LESS~%"))
	(t (format t "EQUAL~%"))))
(solve (read-num) (read-num))

Measured memory_bytes: 11236
a,b = map(int,input().split(" "))
ar = [[] for i in range(a+1)]
for i in range(b):
    l = list(map(int,input().split(" ")))
    ar[l[0]].append(l[1])
    ar[l[1]].append(l[0])
for r in ar[1]:
    if a in ar[r]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Measured memory_bytes: 50096
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define NUM 210


struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_cost,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		cost = arg_cost;
		rev_index = arg_rev_index;
	}

	int to,capacity,cost,rev_index;
};

int V;
vector<Edge> G[NUM];
int dist[NUM];
int pre_node[NUM],pre_edge[NUM];


void add_edge(int from,int to,int capacity,int cost){
	G[from].push_back(Edge(to,capacity,cost,G[to].size()));
	G[to].push_back(Edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int source,int sink,int flow){
	int ret = 0;
	while(flow > 0){
		for(int i = 0; i < V; i++)dist[i] = BIG_NUM;
		dist[source] = 0;
		bool update = true;
		while(update){
			update = false;
			for(int node_id = 0; node_id < V; node_id++){
				if(dist[node_id] == BIG_NUM)continue;
				for(int i = 0; i < G[node_id].size(); i++){
					Edge &e = G[node_id][i];
					if(e.capacity > 0 && dist[e.to] > dist[node_id]+e.cost){
						dist[e.to] = dist[node_id]+e.cost;
						pre_node[e.to] = node_id;
						pre_edge[e.to] = i;
						update = true;
					}
				}
			}
		}

		if(dist[sink] == BIG_NUM){
			return -1;
		}

		int tmp_flow = flow;
		for(int node_id = sink; node_id != source; node_id = pre_node[node_id]){
			tmp_flow = min(tmp_flow,G[pre_node[node_id]][pre_edge[node_id]].capacity);
		}
		flow -= tmp_flow;
		ret += tmp_flow*dist[sink];
		for(int node_id = sink; node_id != source; node_id = pre_node[node_id]){
			Edge &e = G[pre_node[node_id]][pre_edge[node_id]];
			e.capacity -= tmp_flow;
			G[node_id][e.rev_index].capacity += tmp_flow;
		}
	}
	return ret;
}

int main(){

	int N;
	scanf("%d",&N);

	int source = 0,sink = 1,index = 2;
	int value_table[N],first_index_table[N],final_index_table[N];


	for(int i = 0; i < N; i++){
		first_index_table[i] = index++;
		add_edge(source,first_index_table[i],1,0);
	}

	for(int i = 0; i < N; i++){
		final_index_table[i] = index++;
		add_edge(final_index_table[i],sink,1,0);
	}

	V = index;

	for(int i = 0; i < N; i++){
		scanf("%d",&value_table[i]);
		for(int k = 0; k < N; k++){
			if(k == value_table[i]-1)continue;

			add_edge(first_index_table[i],final_index_table[k],1,value_table[i]*(abs(i-k)));
		}
	}

	printf("%d\n",min_cost_flow(source,sink,N));

	return 0;
}



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

#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    string S;
    cin >> S;
  
    int ans = 0;
    string A = "0123456789";
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                string t = "";
                t += A[i];
                t += A[j];
                t += A[k];
                int index = 0;
                for (int l = 0; l < N; l++) {
                    if (index == 3) break;
                    if (t[index] == S[l]) index++;
                }
                if (index == 3) ans++;
            }
        }
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

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

const int MAXW = 25, MAXA = 10,NA = 20;
const int VOID = 0, OBJ = 1, S = 2, G = 3;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int tile[MAXW][MAXW];
int w, h;
int solve(int x, int y, int t)
{

    if(t == 10) return NA;
    int update = 0, ans = NA, obj_f = 0;
    int nextx, nexty;
    REP(4)
    {
        obj_f = 0;
        nextx = x + dx[i]; nexty = y + dy[i];

        if(nextx >= 0 && nextx < w && nexty >= 0 && nexty < h && tile[nextx][nexty] != OBJ )// search OBJ
            while(nextx >= 0 && nextx < w && nexty >= 0 && nexty < h)// search OBJ
            {
                if( tile[nextx][nexty] == G){ return t + 1;}
                if( tile[nextx][nexty] == OBJ){ obj_f = 1; break;}
                nextx += dx[i]; nexty += dy[i];

            }
        if(obj_f)
        {
            update = 1;
            tile[nextx][nexty] = VOID;
            ans = min(ans, solve(nextx - dx[i], nexty - dy[i], t + 1));
            tile[nextx][nexty] = OBJ;
        }
    }
    return ans;
}

int main()
{
    while(cin >> w >> h && w)
    {
        int x, y;
        rep(j, h)rep(i, w){ cin >> tile[i][j]; if(tile[i][j] == S){ x = i; y = j;} }

        int ans = solve(x, y, 0);
        if(ans != NA) cout << ans << endl;
        else cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<cctype>
#include<ctime>
#define pi acos(-1.0)
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[105];
	int maxn=-1000,minn=1000;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>maxn) maxn=a[i];
		if(a[i]<minn) minn=a[i];
	}
	//printf("%d %d\n",maxn,minn);
	int sum=0,mm=1000000;
	for(int i=minn;i<=maxn;i++)
	{
		sum=0;
		for(int j=0;j<n;j++)
		{
			sum+=(a[j]-i)*(a[j]-i);
		}
		//printf("%d\n",sum);
		if(mm>sum) mm=sum;
	}
	printf("%d\n",mm);
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio> 
using namespace std;
int main(){
    vector<int> v;
    int n;
    cin>>n;
    int s[n+10];
    int sum=0;
    for(int i=0;i<n;i++)
    {    
        cin>>s[i];
        sum+=s[i];
        if(s[i]%10==0) v.push_back(s[i]);
    }
    if(v.size()==n)
    {
        cout<<"0";
        return 0;
    }
    if(sum%10!=0)
    {
        cout<<sum;
        return 0;
    }
    else
    {
        sort(s,s+n);
        for(int i=0;i<n;i++)
        {
            if(s[i]%10!=0)
            {
               cout<<sum-s[i];
               return 0;
            }
        }
    }
}

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

int main(){
	vector<string> T{"Sunny", "Cloudy", "Rainy"};
	string s; cin>>s;
	cout<< (s[0]=='S'? T[1]: s[0]=='C'? T[2]: T[0]) <<endl;
}

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

using namespace std;

const int MAXN = 1E5;

int main()
{
    int n;
    cin >> n;
    vector<int> a, b;
    for (int i = 0; 2 * i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        a.push_back(x);
        b.push_back(y);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<pair<int, int>> v1, v2;
    for (int i = 0; 2 * i < n; )
    {
        int j = i;
        while (2 * j < n && a[i] == a[j])
            j++;
        v1.push_back({j - i, a[i]});
        i = j;
    }
    for (int i = 0; 2 * i < n; )
    {
        int j = i;
        while (2 * j < n && b[i] == b[j])
            j++;
        v2.push_back({j - i, b[i]});
        i = j;
    }
    v1.push_back({0, MAXN + 5});
    v2.push_back({0, MAXN + 5});
    sort(v1.rbegin(), v1.rend());
    sort(v2.rbegin(), v2.rend());
    if (v1[0].second != v2[0].second)
        cout << n - (v1[0].first + v2[0].first) << endl;
    else
        cout << n - max(v1[0].first + v2[1].first, v1[1].first + v2[0].first) << endl;
    return 0;
}


Measured memory_bytes: 1784
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n,ans = 0;
	cin >> n;
	
	REP(i,n+1)
	{
		ans += i;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
visited = {'1': 0}
route = [1]
next_id = 0
count = 0
while count < K:
    count += 1
    if A[next_id] in visited.keys():
        route = route[visited[A[next_id]]:]
        K -= count
        break
    visited[A[next_id]] = count
    route.append(A[next_id])
    next_id = A[next_id] - 1
print(route[K % len(route)])


Measured memory_bytes: 32376
S['= r'],m[4]['= r'],z,d[4]={0,-2},k,i;f(i){m[k][i]=S[i]+47?0:m[k][i]?:1+f(d[k]-~i);}main(t){for(scanf("%*d%d",d),d[2]=-*d-2;S[++i-~*d]=~getchar(););for(;--i;z=fmax(z,1-t))for(t=k=4;k--;)t-=f(i-~*d);printf("%d",z);}

Measured memory_bytes: 78464
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	const string w[] = { "apple", "peach" };
	const string t[] = { "_ALE_", "_PEH_" };
//	cut here before submit 
//	freopen("testcase.applepeach", "r", stdin);
	string str = "";
	int i;

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		vector <int> dot;
		vector <int> camma;
		int i;
		str = ' ' + str + ' ';

		while ( str.find ('.') != string::npos ){
			dot.push_back ((int)str.find('.') );
			str.replace (str.find('.'), 1, " " );
		} // end while
		while ( str.find (',') != string::npos ){
			camma.push_back ((int)str.find(',') );
			str.replace (str.find (','), 1, " " );
		} // end while

		while (str.find(w[0] ) != string::npos || str.find(w[1]) != string::npos  ){
			if (str.find (w[0] ) != string::npos){
				str = str.replace (str.find (w[0]), w[0].length(),t[0] );
			} // end if
			if (str.find (w[1] ) != string::npos){
				str = str.replace (str.find (w[1]), w[1].length(),t[1] );
			} // end if
		} // end while

		while (str.find (t[0] ) != string::npos || str.find (t[1]) != string::npos  ){
			if (str.find (t[0] ) != string::npos){
				str = str.replace (str.find (t[0]), t[0].length(),w[1] );
			} // end if
			if (str.find (t[1] ) != string::npos){
				str = str.replace (str.find (t[1]), t[1].length(),w[0] );
			} // end if
		} // end while
		if (!dot.empty() ){
			for (i = 0; i < dot.size(); ++i){
				str = str.replace (dot[i], 1, "." );
			} // end for
		} // end if
		if (!camma.empty() ){
			for (i = 0; i < camma.size(); ++i){
				str = str.replace (camma[i], 1, "," );
			} // end for
		} // end if

		cout << str.substr(1, str.length() - 2) << endl;	
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
    int N;
    cin >> N;
    int ans = 0, B[N-1];
    REP(i, N-1){
        cin >> B[i];
    }
    ans += B[0];
    REP(i, N-2){
        ans += min(B[i], B[i+1]);
    }
    ans += B[N-2];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int N;
  char cr;
  string S;
  cin >> N >> S;
  for (char c : S)
  {
    cr = (c - 'A' + N) % 26 + 'A';
    cout << cr;
  }
  cout << endl;
}


Measured memory_bytes: 3124
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    h, n = input_int_list()
    A = input_int_list()
    if sum(A) >= h:
        print("Yes")
    else:
        print("No")
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 83760
n = int(input())
a = []
for i in range(n):
    temp = int(input())
    a.append(temp)

counter = 0
for i in range(n):
    counter += a[i]//2
    a[i] = a[i]%2
    if a[i] == 1:
        if i != n-1 and a[i+1] > 0:
            a[i] += -1
            a[i+1] += -1
            counter += 1
print(counter)

Measured memory_bytes: 7076
#include<stdio.h>
int main(void){
  int N,M,C,i,j,sum=0,count=0;
  int A[100][100],B[100];
  scanf("%d %d %d",&N,&M,&C);
  for(i=0;i<M;i++){
    scanf("%d",&B[i]);
  }
  for(i=0;i<N;i++){
    for(j=0;j<M;j++){
      scanf("%d",&A[i][j]);
      sum+=A[i][j]*B[j];
    }
    if(sum+C>0){
      count++;
    }
    sum=0;
  }
  printf("%d\n",count);
  return 0;
}

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

int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
	int k;
	cin>>k;
    cout<<a[k-1]<<endl;
	return 0;
} 

Measured memory_bytes: 256
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
   int n;
   cin>>n;
   if(n%1000 != 0) cout<<1000-(n%1000);
   else cout<<0;

}

int main(){
    fastio;
    int t;
    t = 1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}



Measured memory_bytes: 3644
while True:
    M, F, R = list(map(int, input().split()))
    total = M + F
    if M == -1 and F == -1 and R == -1:
        break
    if M == -1 or F == -1:
        print('F')
    elif total >= 80:
        print('A')
    elif  total >= 65 and total < 80:
        print('B')
    elif total >= 50 and total < 65:
        print('C')
    elif total >= 30 and total < 50 and R >= 50:
        print('C')
    elif total >= 30 and total < 50:
        print('D')
    else:
        print('F')



Measured memory_bytes: 5596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int value = a + b + c;
		int product = a * b * c;
		if (value == 17 & product == 175) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 22996
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = io.NextInt()
		}
		ans := 0
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] <= m {
					ans = intMax(a[i]+a[j], ans)
				}
			}
		}
		if ans == 0 {
			io.Println("NONE")
		} else {
			io.Println(ans)
		}
	}
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



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

int main(){
    int N;
    string S;
    cin >> N >> S;
    int x = 0, y = 0;
    for(char c : S){
        if('A' <= c && c <= 'M') x++;
        if('N' <= c && c <= 'Z') x--;
        if('a' <= c && c <= 'm') y++;
        if('n' <= c && c <= 'z') y--;
    }
    string ans;
    while(x > 0) ans.push_back('A'), x--;
    while(x < 0) ans.push_back('N'), x++;
    while(y > 0) ans.push_back('a'), y--;
    while(y < 0) ans.push_back('n'), y++;
    cout << ans.size() << endl << ans << endl;
    return 0;
}



Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
const LL MOD = 1e9+7;
LL a[200005], ans = 0, n, sf[200005];

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

	cin >> n;
	FOR(i, n) cin >> a[i];
	FOR(i, n) a[i] %= MOD;
	for(int i = n; i>=1; i--){
		sf[i] = a[i];
		sf[i] += sf[i+1];
		sf[i] %= MOD;
		//cout << i << " " << sf[i] << endl;
	}
	FOR(i, n-1){
		ans += (a[i] * (sf[i+1]))%MOD;
		ans %= MOD;
	}

	cout << ans << endl;

	cout.flush();
	return 0;
}

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

int main(){
  int N=0;
  cin >>N;
  int A[N]={};
  
  for(int i=0;i<N;i++){
    cin >>A[i];
  }
  
  int count=0;
  bool flag=1;
  while(flag){
   for(int i=0;i<N;i++){
     if(A[i]%2!=0)
       flag=0;
   }
   if(flag){
     count++;
     for(int i=0;i<N;i++)
       A[i]/=2;
   }
  }

  cout <<count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// int dx[4]    = {1, 0, -1, 0};
// int dy[4]    = {0, 1, 0, -1};
// ll pas[5001][5002];

ll n;

int main() {
	IOS();
	cin >> n;
	vector<pair<ll, P>> a(n);
	for (int i = 0; i < n; ++i) {
		ll x, b;
		cin >> x >> b;
		a[i] = make_pair(x + b, P(x, b));
	}
	sort(a.begin(), a.end(), greater<pair<ll, P>>());

	ll ans = 0;

	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0)
			ans += a[i].second.first;
		else
			ans -= a[i].second.second;
	}
	dump(ans);
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		for(int i=0;i<n;i++){
			int[] a = new int[10];
			for(int j=0;j<10;j++){
				a[j] = sc.nextInt();
			}
			int b=0;
			int c=0;
			boolean clear = true;
			for(int j=0;j<10;j++){
				int x = a[j];
				if(j==0){
					b=x;
				}else if(x < b && x < c){
					clear = false;
				}else if(x > b && x < c){
					b=x;
				}else if(x < b && x > c){
					c=x;
				}else{
					if(x-b>x-c){
						c=x;
					}else if(x-c>x-b){
						b=x;
					}
				}
			}
			if(clear==true){
				System.out.println("YES");
			}else if(clear==false){
				System.out.println("NO");
			}
		}
	
	}
}

Measured memory_bytes: 18132
x1,y1,x2,y2 = map(int,input().split())
difx = x2-x1
dify = y2-y1
x3 = x2 - dify
y3 = y2 + difx
x4 = x3 - difx
y4 = y3 - dify
print("{a} {b} {c} {d}".format(a=x3,b=y3,c=x4,d=y4))

Measured memory_bytes: 61732
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,t){e.exports=function(e){for(var t=Number(e[0]),n=e[1].split(" ").map(function(e){return Number(e)}),r=0,o=1e10,u=0,i=0;i<t;i++)n[i]<0&&r++,Math.abs(n[i])<o&&(o=Math.abs(n[i])),u+=Math.abs(n[i]);r%2==0?console.log(u):console.log(u-2*o)}},function(e,t){e.exports=require("fs")}]);

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
    
    
    int x;
    cin>>x;
    for(int i=1;i<400;i++){
      if((x*i)%360==0){
        cout<<i<<endl;
        return;
      }
    }
    
    
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 7812
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
#include <vector>

// lib/greater_by.hpp
#ifndef GREATER_BY_HPP
#define GREATER_BY_HPP


/*
usage:

std::sort(a.begin(), a.end(), tools::greater_by([](int a_i) { return std::abs(x); }));
*/

namespace tools {
  template <class T, class R>
  class greater_by {
  private:
    ::std::function<R(T)> selector;

  public:
    greater_by(const ::std::function<R(T)>& selector) : selector(selector) {
    }

    bool operator()(const T& x, const T& y) const {
      static const std::greater<R> comp;
      return comp(selector(x), selector(y));
    }

    using first_argument_type = T;
    using second_argument_type = T;
    using result_type = bool;
  };
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

class sushi {
public:
  i64 type;
  i64 score;

  friend std::istream& operator>>(std::istream& is, sushi& self) {
    return is >> self.type >> self.score;
  }
};

int main() {
  i64 N, K;
  std::cin >> N >> K;
  std::vector<sushi> sushis;
  tools::read(sushis, N);

  std::sort(sushis.begin(), sushis.end(), tools::greater_by<sushi, i64>([](const sushi& sushi) { return sushi.score; }));

  std::vector<i64> nuisances;
  std::vector<i64> talents;
  i64 x = 0;
  {
    std::unordered_set<i64> found;
    for (auto it = sushis.begin(); it != sushis.begin() + K; ++it) {
      if (found.find(it->type) == found.end()) {
        found.insert(it->type);
        ++x;
      } else {
        nuisances.push_back(it->score);
      }
    }
    for (auto it = sushis.begin() + K; it != sushis.end(); ++it) {
      if (found.find(it->type) == found.end()) {
        found.insert(it->type);
        talents.push_back(it->score);
      }
    }
  }
  std::reverse(nuisances.begin(), nuisances.end());

  i64 base_score = std::accumulate(sushis.begin(), sushis.begin() + K, static_cast<i64>(0), [](const i64& sum, const sushi& sushi) { return sum + sushi.score; });
  i64 answer = base_score + x * x;
  for (i64 i = 0; i < std::min<i64>(nuisances.size(), talents.size()); ++i) {
    base_score += talents[i] - nuisances[i];
    ++x;
    answer = std::max(answer, base_score + x * x);
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 6308
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

struct Edge {
    ll from, to, weight;
    Edge() : from(0), to(0), weight(0) {}
    Edge(ll f, ll t, ll w) : from(f), to(t), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &g, ll a, ll b, ll w = 1){
    g[a].emplace_back(a, b, w);
    g[b].emplace_back(b, a, w);
}

void add_arrow(Graph &g, ll a, ll b, ll w = 1){
    g[a].emplace_back(a, b, w);
}

//ダイクストラ法
//グラフgの1点sからの最短距離をO((E + V) log V)で構築
vector<ll> dijkstra(Graph &g, ll s){
    vector<ll> dist(g.size(), INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    
    while(!que.empty()){
        ll cost, idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]){
            auto next_cost = cost + e.weight;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

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

    ll N, M;
    cin >> N >> M;
    Graph G(N);
    rep(i, M){
        ll l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        add_arrow(G, l, r, d);
        add_arrow(G, r, l, -d);
    }

    vec visit(N, 0);
    rep(i, N){
        if(visit[i]) continue;

        map<ll, ll> d;
        stack<P> sk;
        sk.push({i, 0});
        while(!sk.empty()){
            auto now = sk.top().first;
            auto dis = sk.top().second;
            sk.pop();
            if(visit[now] == 1){
                if(d[now] != dis) drop("No");
                continue;
            }
            visit[now] = 1;
            d[now] = dis;

            for(auto e : G[now]) sk.push({e.to, dis + e.weight});
        }
    }

    print("Yes");

    return 0;
}

Measured memory_bytes: 25216
n,q=map(int,input().split())
s=input()
cnt=[0]*n
for i in range(1, n):
    cnt[i]=cnt[i-1]
    if s[i-1:i+1]=="AC":
        cnt[i]+=1
for i in range(q):
    l,r=map(int,input().split())
    print(cnt[r-1]-cnt[l-1])


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

int main(){
  int n;cin>>n;
  vector<int> b(n-1);for(int i=0;i<n-1;i++){cin>>b.at(i);}
  int ans=0;
  int a;
  
  ans+=b.at(0);
  for(int i=1;i<n-1;i++){
    a=min(b.at(i-1),b.at(i));
    ans+=a;
  }
  ans+=b.at(n-2);
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int h, w, d; cin >> h >> w >> d;
  int n = max(h, w) * 3;
  vector<vector<int>> B = vector<vector<int>>(n, vector<int>(n));
  
  vector<int> colors = {1, 2, 3, 4};

  for(int i=0;i*d<n;++i) {
    for(int j=0;j*d<n;++j) {
      for(int a=0;a<d;++a) {
        for(int b=0;b<d;++b) {
          if(i * d + a < n && j * d + b < n) {
            B[i*d + a][j*d + b] = colors[i%2*2 + j%2];
          }
        }
      }
    }
  }

  auto ans = vector<vector<int>>(h, vector<int>(w));
  auto color = " RYGB";

  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      int ni = i + j;
      int nj = i - j + w;
      cout << color[B[ni][nj]];
    }
    cout << endl;
  }
}


Measured memory_bytes: 10368
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
/* contest template */

int main()
{
	string s;
	cin >> s;
	if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) {
		cout << "Yes\n";
	}
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
int mod = 998244353;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    int N; cin >> N;
    vector<int>p(N);
    int ans = 0;
    vector<bool>A(N,false);
    rep(i, N) {
        cin >> p[i]; 
        if (p[i] == i+1) {
            ans++; A[i] = true;
        }
    }
    REP(i, N) {
        if (A[i] && A[i - 1]) { ans--; A[i] = false; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3688
#include <stdio.h>
#include <string.h>
int main(void)
{
    char s[210000];
    int i,j;
    scanf("%s",s);
    int n=(int)strlen(s);
    for(i=0;i<n;i++) if(s[i]=='A') break;
    for(j=n-1;j>=0;j--) if(s[j]=='Z') break;
    printf("%d\n",j-i+1);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int N = 888;
char s[N][N];
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
#define INF 1.01e9
pair<int,int> z(int a,int b)
{
	pair<int,int> ret;
	ret.first = a;
	ret.second = b;
	return ret;
}
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i = 0;i < n; ++i)
	{
		scanf("%s",s[i]);
	}
	int sx = -1;
	int sy = -1;
	for(int i = 0;i < n; ++i)
	{
		for(int j = 0;j < m; ++j)
		{
			if(s[i][j] == 'S')
			{
				sx = i;
				sy = j;
			}
		}
	}
	queue< pair<int,int> > q;
	q.push(z(sx,sy));
	vector< vector<int> > dist(n,vector<int>(m,INF));
	dist[sx][sy] = 0;
	while(!q.empty())
	{
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for(int i = 0;i < 4; ++i)
		{
			int xx = x + dx[i];
			int yy = y + dy[i];
			if(0 <= xx && xx < n && 0 <= yy && yy < m && s[xx][yy] == '.' && dist[xx][yy] > dist[x][y] + 1)
			{
				dist[xx][yy] = dist[x][y] + 1;
				q.push(z(xx,yy));
			}
		}
	}
	int best = INF;
	for(int i = 0;i < n; ++i)
	{
		for(int j = 0;j < m; ++j)
		{
			if(dist[i][j] <= k)
			{
				best = min(best,i);
				best = min(best,j);
				best = min(best,n - i - 1);
				best = min(best,m - j - 1);
			}
		}
	}
	if(sx == 0 || sy == 0 || sx == n - 1 || sy == m - 1)
	{
		puts("0");
	}
	else
	{
		printf("%d\n",1 + (best + k - 1) / k);
	}
	return 0;
}

Measured memory_bytes: 3584
/*
    author: Salam_35
    Created at :

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    ll n,h;
  cin >> n >> h;
  if(h>=n)cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;
    
}


Measured memory_bytes: 3624
//A code
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define f(i,x,n) for(ll i=x;i<n;i++)
#define rf(i,x,n) for(ll i = x; i >= n; i--)
#define all(c) c.begin(),c.end()
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 2e3 + 10; 
int main()
{   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a,b,c,k; cin>>a>>b>>c>>k; ll sum=0;
    	if(k<=a) {cout<<k;}
    	else if(k>a && a+b>=k) { cout<<a;}
    	else {cout<<2*a+b -k;}
}

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

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;}

#define MAX 100001
long long INF = 1ll << 62;
long long dp[MAX];
int N;

int main(){
  cin >> N;
  int h[N+1];

  dp[1] = 0;   //dp[0]とh[0]は考えるのが面倒なので無視
  int v;
  for(int i = 1; i < N+1; i++){ cin >> v; h[i] = v;}
  for(int i = 2; i < N+1; i++){ dp[i] = INF;}

  dp[2] = abs(h[2]-h[1]);   //2番目の足場に行く方法は一通りしかない

  for(int i = 3; i < N+1; i++){
    chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
    chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
  }

  cout << dp[N] << endl;
  return 0;
  
  
}

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

using namespace std;

int main()
{
    long long  n, m, d, c, i;
    cin>>n>>m;
    d=m/n;
    c=m%n;
    for(i=d; i>0 ;i--)
    {
        if(c%i==0)
        {
            cout<<i<<endl;
            return 0;
        }
        c+=n;
    }
}

Measured memory_bytes: 256
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	S = SI()
	N = len(S)
	dp = make_grid(N+1, 4, 0)
	dic = {"A": [0], "B": [1], "C": [2], "?": [0,1,2]}
	dp[0][0] = 1
	for i, s in enumerate(S):
		if s == "?":
			for j in range(4):
				if j in dic[s]:
					dp[i+1][j+1] += dp[i][j] % MOD
				dp[i+1][j] += dp[i][j] * 3 % MOD
		else:
			for j in range(4):
				if j in dic[s]:
					dp[i+1][j+1] += dp[i][j] % MOD

				dp[i+1][j] += dp[i][j] % MOD

	print(dp[N][3] % MOD)



if __name__ == "__main__":
	main()

Measured memory_bytes: 27928
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n,m = gi
mm = darray n,n, 0
rep m do |i|
a,b = gi
mm[a-1][b-1] += 1
mm[b-1][a-1] += 1
end

rep n do |i|
  ans = 0
rep n do |j|
ans += mm[i][j]
end
puts ans
end



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

const int mod = 1'000'000'007;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
int pow(int a, int b, int res = 1) {
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
	return res;
}
int dp[1 << 16];
int A[17], n, m;
const int MAXS = 1 << 16 | 10;
int fac[MAXS], inv[MAXS];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	fac[0] = fac[1] = inv[0] = inv[1] = 1;
	for (int i = 2; i != MAXS; ++i) {
		fac[i] = mul(fac[i - 1], i);
		inv[i] = mul(inv[mod % i], mod - mod / i);
	}
	for (int i = 2; i != MAXS; ++i) inv[i] = mul(inv[i], inv[i - 1]);
	std::cin >> n >> m;
	for (int i = 1; i <= m; ++i) std::cin >> A[i];
	std::sort(A + 1, A + 1 + m, std::greater<int> ());
	const int U = 1 << n;
	dp[0] = 1;
	for (int i = 1; i <= m; ++i) {
		for (int j = U - 1; ~j; --j) if (int t = dp[j]) {
			int rest = U - A[i] + 1 - j;
			for (int k = 0; k < n; ++k) if ((~j >> k & 1) && rest >= (1 << k))
				reduce(dp[j | 1 << k] += (LL) t * fac[rest - 1] % mod * inv[rest - (1 << k)] % mod * (1 << k) % mod - mod);
		}
	}
	int ans = 0;
	for (int i = 0; i != U; ++i)
		reduce(ans += (LL) fac[U - i - 1] * dp[i] % mod * (__builtin_parity(i) ? mod - 1 : 1) % mod - mod);
	ans = mul(ans, U);
	std::cout << ans << std::endl;
	// Sorry column limit
	return 0;
}


Measured memory_bytes: 1024