akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<long long> A(N+1);
  for (int i = 0; i < N+1; i++) cin >> A.at(i);
  vector<long long> num_vertex(N+1, 1);
  num_vertex.at(N) = A.at(N);
  for (int i = N-1; i > 0; i--) num_vertex.at(i) = num_vertex.at(i+1) + A.at(i);
  long long from_root = 1;
  bool exist_ans = true;
  int index = -1;
  for (int i = 1; i < N+1; i++)
  {
    from_root = 2*(from_root - A.at(i-1));
    if (from_root <= 0)
    {
      exist_ans = false;
      break;
    }
    if (from_root < num_vertex.at(i)) num_vertex.at(i) = from_root;
    else
    {
      index = i;
      break;
    }
    if (i == N) exist_ans = false;
  }
  if (N == 0)
  {
    if (A.at(0) != 1) cout << -1 << endl;
    else cout << 1 << endl;
  }
  else if (exist_ans)
  {
    if (index != -1)
    {
      for (int i = index; i > 0; i--)
      {
        if (num_vertex.at(i) < num_vertex.at(i-1) - A.at(i-1))
        {
          num_vertex.at(i-1) = num_vertex.at(i) + A.at(i-1);
        }
        else break;
      }
    }
    long long ans = 0;
    for (int i = 0; i < N+1; i++)
    {
      ans += num_vertex.at(i);
    }
    cout << ans << endl;
  }
  else cout << -1 << endl;
}

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

struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c;

long long o[1333][11111];
int l[1];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[3331];
stack<int> s;
//set<int> se;
//priority_queue<int,vector<int>,greater<int> > q;
//queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

//string r,r1;
char r[552];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    //if(a.x!=b.x)
    //   return a.x<b.x;
    return a.x+a.y>b.x+b.y;


}

long long f(int n,int m)
{
    if(m<0) return -987654321987654321;
    if(n>a) return 0;
    if(o[n][m]>=0) return o[n][m];
    return o[n][m]=max(f(n+1,min(m-u[n].x,u[n].y))+u[n].z,f(n+1,m));
}

int main()
{
    memset(o,-1,sizeof(o));
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
        scanf("%d %d %d",&u[t].x,&u[t].y,&u[t].z);
    sort(u+1,u+a+1,as);
    for(int t=1;t<=a;t++)
        x=max(x,f(t+1,u[t].y)+u[t].z);
    printf("%lld",x);
}





Measured memory_bytes: 115968
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int N;
    cin >> N;
    bool kuku[110];
    for(int i = 0; i < 110; i++) kuku[i] = false;
    
    for(int i = 1; i < 10; i++)
        for(int j = 1; j < 10; j++)
            kuku[i*j] = true;
            
            
    if(kuku[N])
        cout << "Yes" << "\n";
    else
        cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
       int i,j,n[2],p=0,r=0;
      string a,b;
      cin>>a>>b;
      n[0] = a.length();
      n[1] = b.length();
      j = n[0]+n[1];
      for(i=0;i<j;i++)
      {
          if(i%2==0)
          {
              cout<<a[p];
              p++;
          }
          else if(i%2==1)
          {
              cout<<b[r];
              r++;
          }

      }


      return 0;
      }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
   ll a,b,c,k;
   cin>>a>>b>>c>>k;
   ll sum=0;
   for(int i=1;i<=a;i++){
       sum++;
       if(k==i){
           cout<<sum<<endl;
           return 0;
      }
   }
   for(int i=1;i<=b;i++){
       if(k==a+i){
           cout<<sum<<endl;
           return 0;
       }
   }
   for(int i=1;i<=c;i++){
       sum--;
       if(k==a+b+i){
           cout<<sum<<endl;
           return 0;
       }
   }
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        vector<int> L(N);
        for(int& t : L) cin >> t;
        sort(L.begin(), L.end());
        int res = 0;
        for(int i=0;i<N;i++){
            int k = i+1;
            for(int j=i+1;j<N;j++){
                while(k < N && L[i]+L[j] > L[k]) ++k;
                res += k-j-1;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int k=sc.nextInt();
		int[] rabbits=new int[k+1];
		for(int i=0;i<k;i++)
			rabbits[i+1]=sc.nextInt();
		int count=0;
		for(int i=1;i<=k;i++){
			int tar=rabbits[i];
			int tar2=rabbits[tar];
			if(tar2==i) count++;
		}
		System.out.println(count/2);
	}
}


Measured memory_bytes: 51364
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

def splitbit(n):
    for i in range(61):
        if not n & (1 << i):
            xor_l[i] = 0

N, K = getNM()
A = getList()

imos = copy.deepcopy(A)
imos.insert(0, 0)

for i in range(N):
    imos[i + 1] += imos[i]

num = []
for i in range(1, N + 1):
    for j in range(i, N + 1):
        num.append(imos[j] - imos[i - 1])

ans = 0
for i in range(60, -1, -1):
    cnt = 0
    for j in range(len(num)):
        if ans + (2 ** i) & num[j] == ans + (2 ** i):
            cnt += 1
    if cnt >= K:
        # okならフラグを追加する（条件が厳しくなる）
        ans += (2 ** i)
print(ans)

Measured memory_bytes: 120108
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int Max(int a, int b, int c) {
	if (a >= b) { return std::max(a, c); }
	else return std::max(b, c);
}
int main(void) {
	int a, b; cin >> a >> b;
	if (a > 8 || b > 8)cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}

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

int N;
int A[(int)(1e5 + 2)] = {0};

int main() {
    cin >> N;
    // 1 ... N
    rep(i, N) cin >> A[i + 1];

    // rep(i, N + 2) cout << A[i] << endl;
    int dist = 0;
    for (int i = 0; i <= N; i++) {
        dist += abs(A[i + 1] - A[i]);
        // cout << dist << endl;
    }
    // cout << dist << endl;
    for (int i = 1; i <= N; i++) {
        int before = abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]);
        int after = abs(A[i + 1] - A[i - 1]); 
        cout << dist - (before - after) << endl;
    }
}

Measured memory_bytes: 1664
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

// #define int long long

/* cpp template {{{ */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

bool field[56][56];
int w, h;

void dfs(int y, int x)
{
  field[y][x] = false;

  REP(i, 8){
    int nx = x + dx[i], ny = y + dy[i];
    if (!inside(ny, nx, h, w)) continue;
    if (!field[ny][nx]) continue;
    dfs(ny, nx);
  }
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  for (; cin >> w >> h, w || h; ){
    REP(i, h){
      REP(j, w){
        cin >> field[i][j];
      }
    }

    int ans = 0;
    REP(i, h){
      REP(j, w){
        if (field[i][j]){
          dfs(i, j);
          ans++;
        }
      }
    }
    print(ans);
  }

  return (0);
}

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

int main(){
  int arr[3][3];
  for(int i = 0;i<3;i++){
    for(int j = 0;j<3;j++){
   		cin>>arr[i][j];   
    }
  }
  int n;cin>>n;
  for(int k = 0;k<n;k++){
	  int ab;cin>>ab;
	for(int i = 0;i<3;i++){
		for(int j = 0;j<3;j++){
			if(ab == arr[i][j]){
				arr[i][j] = 0;
			}
		}
	}
}
  
  
  
  
  if((arr[0][0] + arr[0][1] + arr[0][2] == 0) || ( arr[1][0] + arr[1][1] + arr[1][2] == 0) || (arr[2][0] + arr[2][1] + arr[2][2] == 0)|| 
     (arr[0][0] + arr[1][0] + arr[2][0] == 0) || (arr[0][1] + arr[1][1] + arr[2][1] == 0)  || (arr[0][2] + arr[1][2] + arr[2][2] == 0)||
     (arr[0][0]+arr[1][1]+arr[2][2] == 0) || (arr[0][2]+arr[1][1]+arr[2][0] == 0) ){
		cout<<"Yes"<<endl;
	}
    else{
      cout<<"No"<<endl;
    }
     

  
 return 0; 
}


Measured memory_bytes: 256
// 161-C Replacing Integer

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return -1 * (*(int*)a - *(int*)b);
}


int main() {
    int n,i;
    //int* a;
    int a, oddCnt=0;
    scanf("%d", &n);
    //a = (int*)malloc(sizeof(int) * n);

    for (i = 0; i < n; i++) {
        scanf("%d", &a);
        if (a % 2 == 1) oddCnt++;
    }
    if (oddCnt % 2 == 1) {
        printf("NO");
    }
    else {
        printf("YES");
    }
    return 0;
}

Measured memory_bytes: 128
/*
ID: usaco.t3
TASK: test
LANG: C++14
*/

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _CRT_SECURE_NO_WARNINGS
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define pii pair<intt,intt>
#define vi vector<intt>
#define vii vector<pii>

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();
#define endl '\n'

#define wtfis(x) cerr << "at line " << __LINE__ << ": " << #x << " = " << (x) << endl

const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;

const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;

const intt INF = 2LL * 1000000001;
const intt INFLL = 9LL * 1000000000 * 1000000000;
/***************/

intt powmod (intt a, intt b, intt mod) {
    intt res = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

intt gcd (intt a, intt b) {
    while (b > 0) {
        intt t = a % b;
        a = b, b = t;
    }
    return a;
}

intt lcm (intt a, intt b) {
    return (a / gcd (a, b)) * b;
}

intt is_prime (intt n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (intt i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/**************************/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    IO;
    int a, b;
    cin >> a >> b;
    if (a + b == 15) {
        cout << '+' << endl;
    } else if (a * b == 15) {
        cout << '*' << endl;
    } else {
        cout << 'x' << endl;
    }
    return 0;
}


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

int main() {
  string s;cin>>s;
  int ans=100000;
  int a;
  for(int i=0;i<s.size()-2;++i){
    a = 753 - stoi(s.substr(i,3));
    a = abs(a);
    if(ans > a) ans = a;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    int *a = new int[n+2];
    a[0] = 0, a[n+1] = 0;

    for (int i = 1; i <= n; i++)
        cin >> a[i];

    int ans = 0;
    for (int i = 0; i < n+1; i++)
        ans += abs(a[i+1]-a[i]);

    for (int i = 1; i <= n; i++) {
        cout << ans - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

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

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

  if ( a != 1 && b != 1 ) { cout << 1 << endl; }
  if ( a != 2 && b != 2 ) { cout << 2 << endl; }
  if ( a != 3 && b != 3 ) { cout << 3 << endl; }

  return 0;
}

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

int main (){
	int A,B,C;
	cin >> A >> B >> C;
	bool ans = false;
	for(int i=1;i<B;i++){
		if(i*A%B == C){
		ans = true;
		break;
		}
	}
	if(ans) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

/*
	Dijkstra's Algorithm
	arguments		: adjacency list, start node
	note			: If graph contains negative-weighted edges, this algorithm doesn't work.
					  INF_DIJKSTRA must be greater than the sum of weights of all edges. (Equality is NOT allowed.)
	last verified	: 2020/09/15, Aizu Online Judge
		problem			: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
		submission		: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4840704
*/
#include <iostream>
#include <vector>
#include <queue>

struct edge {
	long long weight; int from, to;
}; bool operator>(edge left, edge right) {return (left.weight > right.weight);}

constexpr long long INF_DIJKSTRA = 1e10;
set<pair<int, int>> st;
std::vector<long long> dijkstra(std::vector<std::vector<edge>>& v, int start) {
	int V = v.size();
	std::vector<long long> dist(V, INF_DIJKSTRA); dist[start] = 0;
	std::priority_queue<edge, std::vector<edge>, std::greater<edge>> pq;
	for (auto i : v[start]) {
		if (dist[i.to] == INF_DIJKSTRA) pq.push(i);
	}
	while (pq.size()) {
		auto [d, s, t] = pq.top(); pq.pop();
		if (dist[t] < INF_DIJKSTRA) continue;
		else {
			dist[t] = d;
			st.insert({min(s, t), max(s, t)});
		}
		for (auto i : v[t]) {
			if (dist[i.to] == INF_DIJKSTRA) pq.push({dist[t] + i.weight, t, i.to});
		}
	}
	return dist;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1000000007;
	//constexpr ll P = 998244353;

	int n, m;
	cin >> n >> m;
	vector<vector<edge>> v(n);
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		v[a].push_back({c, a, b});
		v[b].push_back({c, b, a});
	}
	for (int i = 0; i < n; i++) dijkstra(v, i);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (auto j : v[i]) {
			if (st.find({min(j.from, j.to), max(j.from, j.to)}) == st.end()) ans++;
		}
	}
	cout << ans / 2 << endl;
}

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


void d_m_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input_dp.txt", "r", stdin);
	freopen("output_dp.txt", "w", stdout);
#endif
}

int n, d;
vector<long double> v;

int power(int n, int x)
{
	if (x == 0)
		return 1;

	int small = power(n, x / 2);
	small = (small * small);

	if (1 & x)
		small = (n * small);

	return small;
}

int frog2(int *heights, int n, int k)
{
	int dp[n + 1];
	dp[0] = dp[1] = 0;

	for (int i = 2; i <= n; i++)
	{
		dp[i] = INT_MAX;
		for (int j = 1; j <= k; j++)
		{
			if (i - j >= 0)
			{
				dp[i] = min(dp[i], abs(heights[i - 1] - heights[i - j - 1]) + dp[i - j]);
			}
		}
	}

	return dp[n];
}

int32_t main()
{
	d_m_c();

	int n, k;
	cin >> n >> k;

	int heights[n];
	for (int i = 0; i < n; i++)
		cin >> heights[i];

	cout << frog2(heights, n, k) << endl;
}

Measured memory_bytes: 5160
#include <iostream>

int main(void) {
    unsigned long long n, k, hand;

    std::cin >> n >> k;

    hand = (n+k)%k;

    if(hand > k-hand) {
        std::cout << k-(hand) << std::endl;
    }else {
        std::cout << hand << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set

//#define      ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define        fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define        f first
#define        s second
#define        pb push_back
#define        eb emplace_back
#define        mp  make_pair
#define        forn(i,n) for(int i=0;i<n;++i)
#define        show(b) for(auto const&x: b) cout<<x<<" "
#define        sshow(b) for(auto x:b) cout<<x<<" "
#define        fix(b,val)   memset(b,val,sizeof(b))
#define        pill(b,n,v)  fill(b,b+n,v)
#define        itn          int
#define        w(t)     int t;cin>>t;while(t--)
#define        mx(a,b,c) max(a,max(b,c))
#define        mn(a,b,c) min(a,min(b,c))
#define        intmax    INT_MAX
#define        intmin    INT_MIN
#define        nl        "\n"
#define        prt(val)  cout<<val<<"\n"
#define        all(v)    v.begin(),v.end()
#define        trace1(x)                cerr<<#x<<": "<<x<<endl
#define        trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define        trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define        trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define        trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define        trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef       long long int ll;
typedef       long double LD;
typedef       unsigned long long int LL;
typedef       pair<int,int> pii;
typedef       pair<long long int,int> pli;
typedef       pair<int,long long int> pil;
typedef       pair<long long int,long long int> pll;
const int N=2*1e6+10;
const int mod=1e9+7;
//mt19937 rnd(time(NULL));

/*------Global--------*/

/*-----Functions------*/
template<typename T>
void show2d(const vector<vector<T>>& adj)
{
    for(auto x:adj)
    {
        for(auto y:x)
        { 
           cout<<y<<" ";
        }
    cout<<"\n";
    }
}

ll modexp(ll a,ll b,ll mod)
{
    ll x=1;
    while(b)
    {
        if(b&1)
        x = ((x%mod) * (a%mod))%mod;
        a = ((a%mod) * (a%mod))%mod;
        b = b / 2;
    }
    return x;
}

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

int32_t main()
{
    fast;
   // rf();
    int n; cin>>n;
    int i=1;
    while((360*i) % n != 0)
    {
        ++i;
    }
    cout<<(360*i)/n<<nl;
}

Measured memory_bytes: 3636
//(u, v)の条件を出したい。a xor b, a + bの関係を調べると、
//v ≦ N, v = Σ2^i * v[i] (v[i]=0,1,2)を満たす{v[i]}を数えればよいことが分かる。
//
//大きな桁から決めていくと大小関係を上手く処理できるので大きい桁から決めるDPを考える。
//ここで、dp[i][v(暫定値)] = あとi桁. 何通り？, vは2^iの倍数
//を考えるとO(NlogN)で厳しい。しかし下i桁を取り除いたNをN_iとおき、
//(N_i - v) / 2^i = a_iに注目すると、a_i ≧ 2ならば{v[i-1],…,v[0]}を自由に決められる, かつ,
//a_iからv[i-1]の制約が分かり, a_i, v[i-1]からa_[i-1]も分かり、iから終了条件も分かるので、{i, a_i}でDPができる.
//dp[i][a_i] = あとi桁. 何通り？という感じ。こうすればa_i ≧ 2を同一視することで、O(logN)。

#include <iostream>
#define int long long
using namespace std;

int mod = 1000000007;
int n;
int dp[61][3];

signed main() {
	int i, j, v;
	
	cin >> n;
	
	dp[60][0] = 1;
	for (i = 60; i > 0; i--) {
		for (j = 0; j < 3; j++) {
			for (v = 0; v < 3; v++) {
				int nj = j * 2 + ((n >> (i - 1)) % 2) - v;
				if (nj < 0) continue;
				if (nj > 2) nj = 2;
				dp[i - 1][nj] += dp[i][j];
				dp[i - 1][nj] %= mod;
			}
		}
	}
	
	int ans = dp[0][0] + dp[0][1] + dp[0][2];
	cout << ans % mod << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

const initBufSize, maxBufSize = 10000, 1000000

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = nextInt()
	}
	return res
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(r, n int) int {
	return int(math.Pow(float64(r), float64(n)))
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initBufSize), maxBufSize)
	n := nextInt()
	staff := make([]int, n)

	for i := 0; i < n-1; i++ {
		staff[nextInt()-1]++
	}
	for i := range staff {
		fmt.Println(staff[i])
	}
}


Measured memory_bytes: 6184
import java.util.*;
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 D = B/A;
	if(D>=C) {
		D=C;
		System.out.println(D);
	}
	else if(D<C){
		System.out.println(D);
	}
	else if(D==0) {
		System.out.println(D);
	}
	}
}


Measured memory_bytes: 23636
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <bitset>
using namespace std;

//i本のマッチで表せる最大桁数
int dp[10001];

//数字iを作るのに必要なマッチの本数
int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

vector<int> enable;

int n, m;

int main()
{

    cin >> n >> m;

    for (int i = 0; i < m; i++)
    {
        int tmp;
        cin >> tmp;
        enable.push_back(tmp);
    }

    sort(enable.begin(), enable.end(), greater<int>());

    for (int i = 0; i <= n; i++)
    {
        dp[i] = -10000000;
    }

    dp[0] = 0;

    for (int i = 1; i <= n; i++)
    {
        int tmp = -10000000;
        for (auto e : enable)
        {
            //最上位桁にeを使ったときにi本で何桁の数字をつくれるか
            //num[e] : eを作るのに必要な本数
            if (i - num[e] >= 0)
            {
                tmp = max(tmp, dp[i - num[e]] + 1);
            }
        }
        dp[i] = tmp;
    }

    //cout << dp[n] << endl;

    vector<int> res;

    //使ったマッチの本数
    int ct = 0;

    for (int i = 0; i < dp[n]; i++)
    {
        for (auto e : enable)
        {
            //大きい順に全探索
            //上からi桁目にeを使ったときにdp[n]桁の数字をつくれるか
            if (n - ct - num[e] >= 0 && dp[n - ct - num[e]] == dp[n] - i - 1)
            {
                //cout << dp[n - ct - num[e]] << " " << dp[n] - i - 1 << " " << ct + num[e] << " " << e << endl;
                ct += num[e];
                //cout << ct << endl;
                cout << e;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
//#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int x, y, z;
int main()
{
	scanf("%d%d%d", &x, &y, &z);
	
	int temp;
	temp = x;
	x = y;
	y = temp;
	
	temp = x;
	x = z;
	z = temp;
	
	printf("%d %d %d\n", x, y, z);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull		unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}



void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
const int Max=3e3+1;
int Dp[Max][Max];

int32_t main()
{
	c_p_p();
	string s,t;
	cin>>s>>t;
	int n=s.size(),m=t.size();
	rep(i,1,n+1)
	{
		rep(j,1,m+1)
		{
			if(s[i-1]==t[j-1])
				Dp[i][j]=Dp[i-1][j-1]+1;
			else
				Dp[i][j]=max(Dp[i-1][j],Dp[i][j-1]);
		}
	}
	string ans="";
	while(n>0 && m>0)
	{
		if(s[n-1]==t[m-1])
		{
			char ch=s[n-1];
			ans+=ch;
			n-=1,m-=1;
			
		}
		else
		{
			if(Dp[n][m-1]>Dp[n-1][m])
				m-=1;
			else
				n-=1;
		}
	}
	reverse(all(ans));
	cout<<ans;

	return 0;
}
	

Measured memory_bytes: 74012
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int W, H, N;
    cin >> W >> H >> N;
    int upper = H;
    int lower = 0;
    int right = W;
    int left = 0;
    for (int i = 0; i < N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        switch (a) {
            case 1:
                left = max(left, x);
                break;
            case 2:
                right = min(right, x);
                break;
            case 3:
                lower = max(lower, y);
                break;
            default:
                upper = min(upper, y);
        }
    }
    if (left >= right || lower >= upper) {
        cout << 0 << endl;
    }
    else {
        cout << (right - left) * (upper - lower) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, count = 0;
    
    cin >> n;
    
    for (int i = 1; i <= n; i++ ) {
        string str = to_string(i);
        if ( str.size() % 2 != 0 ) {
            count++;
        }
    }
    
    cout << count << endl;
    
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
struct edge {
	int to;
	ll cost;
	edge(int to,ll cost) : to(to),cost(cost){}

};
vector<edge> es[100010];
int x[100010], y[100010];
ll d[100010];
void dija(int s) {
	fill(d, d + 100010, INF * INF);
	d[s] = 0;
	priority_queue<pll, vector<pll>, greater<pll>> q;
	q.push(pll(0, s));
	while (!q.empty())
	{
		pll p = q.top();
		q.pop();
		if (p.first > d[p.second]) continue;
		for (auto it : es[p.second]) {
			if (d[it.to] > d[p.second] + it.cost) {
				d[it.to] = d[p.second] + it.cost;
				q.push(pll(d[it.to],it.to));
			}
		}
	}
}
ll cost[210][210];
int ra[10];
int n, m, r;
bool use[10];

ll calc(int x,int from) {

	if (x == r) return 0;

	ll res = INF;
	for (size_t i = 0; i < r; i++)
	{
		if (use[i]) continue;
		use[i] = true;
		res = min(res,calc(x + 1,ra[i]) + cost[from][ra[i]]);
		use[i] = false;
	}
	return res;
}
void solv() {
	cin >> n >> m >> r;
	for (size_t i = 0; i < r; i++)
	{
		cin >> ra[i];
	}
	
	for (size_t i = 1; i <= n; i++)
	{
		cost[0][i] = 0;
		for (size_t j = 1; j <= n; j++)
		{
			cost[i][j] = INF;
		}
	}
	for (size_t i = 0; i < m; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		cost[a][b] = c;
		cost[b][a] = c;
	}
	for (size_t i = 1; i <= n; i++)
	{
		for (size_t j = 1; j <= n; j++)
		{
			for (size_t k = 1; k <= n; k++)
			{
				if (cost[j][k] > (cost[j][i] + cost[i][k])) {
					cost[j][k] = (cost[j][i] + cost[i][k]);
				}
			}
		}
	}
	cout << calc(0,0) << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  int N; cin >> N;
  vector<int> v(N, N+1); v[1] = 1;

  queue<int> z, o;
  z.push(1); o.push(1);
  vector<bool> ok(N,false);
  while(v[0]==N+1) { 
    if (!z.empty()){
      int n = z.front();
      z.pop();
      if (!ok[(n*10)%N]) {
        v[(n*10)%N] = v[n];
        z.push((n*10)%N);
        o.push((n*10)%N);
        ok[n] = true;
      }
    }
    else {
      int n = o.front();
      o.pop();
      if (!ok[(n+1)%N]) {
        v[(n+1)%N] = v[n]+1;
        z.push((n+1)%N);
        o.push((n+1)%N);
        ok[n] = true;
      }
    }
  }

  cout << v[0] << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        if(s.equals("Sunny")) System.out.println("Cloudy");
        else if(s.equals("Cloudy")) System.out.println("Rainy");
        else System.out.println("Sunny");
    }

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


Measured memory_bytes: 35608
using System;
public class Hello{
    public static void Main(){
        // Here your code !
        string line = Console.ReadLine();
        string []ab = line.Split(' ');
        int n = Convert.ToInt32(ab[0]);
        for(int i = 1; i<=n;i++){
            if(i%3==0 || i%10==3 || 
            (i/10)%10 == 3 ||
            (i/100)%10 == 3 ||
            (i/1000)%10 == 3 ||
            (i/10000)%10 == 3 
            ){
                Console.Write(" {0}",i);
            }
        }
        Console.WriteLine();
    }
}

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

class Program
{
    static void Main(string[] args)
    {
        char[] input = Console.ReadLine().ToArray();
        int count = 0;
        for (int i = 0; i < input.Count(); i++)
        {
            if (i % 2 == 0 && input[i] == '0')
            {
                count++;
            }
            else if(i % 2 == 1 && input[i] == '1') { count++; }
        }
        int count1 = 0;
        for (int i = 0; i < input.Count(); i++)
        {
            if (i % 2 == 0 && input[i] == '1')
            {
                count1++;
            }
            else if (i % 2 == 1 && input[i] == '0') { count1++; }
        }
        if (count > count1) { Console.WriteLine(count1); }
        else { Console.WriteLine(count); }
    }
}

Measured memory_bytes: 13268
MOD = 10**9 + 7
S = input()

dp0 = 1 # ''
dp1 = 0 # 'a'
dp2 = 0 # 'ab'
dp3 = 0 # 'abc'

for c in S:
    if c == 'A':
        dp1 = (dp0+dp1)%MOD
    elif c == 'B':
        dp2 = (dp1+dp2)%MOD
    elif c == 'C':
        dp3 = (dp2+dp3)%MOD
    else:
        dp3 = (dp3*3+dp2)%MOD
        dp2 = (dp2*3+dp1)%MOD
        dp1 = (dp1*3+dp0)%MOD
        dp0 = (dp0*3)%MOD
print(dp3)


Measured memory_bytes: 73332
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;

int main() {
    // input
    int n; cin >> n;
    vector<vector<pair<int, int> > > g(n);
    REP (i, n - 1) {
        int a, b; cin >> a >> b;
        -- a;
        -- b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }

    // solve
    vector<int> c(n - 1, -1);
    function<void (int, int, int)> go = [&](int x, int parent, int last) {
        int next = 0;
        for (auto edge : g[x]) {
            int y, i; tie(y, i) = edge;
            if (y == parent) continue;
            if (next == last) next ++;
            c[i] = next ++;
            go(y, x, c[i]);
        }
    };
    go(0, -1, -1);

    // output
    cout << *max_element(ALL(c)) + 1 << endl;
    REP (i, n - 1) {
        cout << c[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 9216
def is_ym(a, b):
    if 1 <= int(b) and int(b) <= 12:
        return True
    return False

def solve(s):
    a = s[:2]
    b = s[2:]
    if is_ym(a, b):
        if is_ym(b, a):
            print("AMBIGUOUS")
        else:
            print("YYMM")
    else:
        if is_ym(b, a):
            print("MMYY")
        else:
            print("NA")
            
s = input()
solve(s)

Measured memory_bytes: 38256
while True:
	s = raw_input().rstrip().split(" ")
	a = int(s[0])
	b = int(s[2])
	if s[1]=="?":break
	if s[1]=="+":print a+b
	if s[1]=="-":print a-b
	if s[1]=="*":print a*b
	if s[1]=="/":print a//b

Measured memory_bytes: 6296
// https://atcoder.jp/contests/abc105/tasks/abc105_d

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)

const int N_MAX = 1e5;
const int M_MAX = 1e9;
const int A_I_MAX = 1e9;

int N, M;
int A[N_MAX];
map<int, ll> mp;

void solve() {
  int acc = 0;
  mp[acc] = 1;
  REP(i, N) {
    acc = (acc + A[i]) % M;
    if (mp.count(acc) == 0) mp[acc] = 1;
    else mp[acc]++;
  }
  ll ans = 0;
  ITR(mp, it) {
    ll v = it->second;
    ans += v * (v - 1) / 2;
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, N) scanf("%d", A + i);
}

int main() {
  input();
  solve();
  return 0;
}


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

signed main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif
  string s;
  ll k;
  cin >> s >> k;
  int n = (int) s.size();
  vector<int> b;
  for (int l = 0; l < n; ++l) {
    int r = l;
    while (r < (int) s.size() && s[l] == s[r]) {
      ++r;
    }
    b.push_back(r - l);
    l = r - 1;
  }
  if ((int) b.size() == 1) {
    cout << n * k / 2 << '\n';
    return 0;
  }
  ll res = 0;
  for (auto x : b) {
    res += (x / 2) * k;
  }
  if (s.front() == s.back()) {
    res += ((b.front() + b.back()) / 2 - b.front() / 2 - b.back() / 2) * (k - 1);
  }
  cout << res << '\n';
}


Measured memory_bytes: 256
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder str = new StringBuilder();
		StringBuilder sb = new StringBuilder();
		str.append(br.readLine());
		int q = Integer.parseInt(br.readLine());
		for (int i = 0; i < q; i++) {
			String[] cmd = br.readLine().split(" ");
			int a = Integer.parseInt(cmd[1]);
			int b = Integer.parseInt(cmd[2]);
			if (cmd[0].equals("print")) System.out.println(str.substring(a, b + 1));
			else if (cmd[0].equals("reverse")) {
				sb.append(str.substring(a, b + 1));
				sb.reverse();
				str.insert(a, sb);
				str.delete(b + 1, b + sb.length() + 1);
				sb.delete(0, sb.length());
			} else if (cmd[0].equals("replace")) {
				str.insert(a, cmd[3]);
				str.delete(b + 1, b + cmd[3].length() + 1);
			}
		}
	}
}

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

int main()
{
    int H, W;
    cin >> H >> W;

    string bar = "";
    for (int i = 0; i < W + 2; i++)
    {
        bar += "#";
    }

    cout << bar << endl;

    string a;
    for (int i = 0; i < H; i++)
    {
        cin >> a;
        cout << "#" + a + "#" << endl;
    }

    cout << bar << endl;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if (a <= b) {
    rep(i,0,b) {
      cout << a;
    }
  } else {
    rep(i,0,a) {
      cout << b;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3548
#include <stdio.h>
int main(void){
int A,B;
scanf ("%d %d",&A,&B);
if (B+2<=A) printf ("%d",A+(A-1));
if (A+2<=B) printf ("%d",B+(B-1));
else {
    if (A==B+1||B==A+1||A==B) printf ("%d",A+B);
}
}


Measured memory_bytes: 1732
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  ss <- replicateM n BS.getLine

  let countMarch :: Int -> Int -> Int -> Int -> Int -> [BS.ByteString] -> [Int]
      countMarch m a r c h [] = [m,a,r,c,h]
      countMarch m a r c h (s:ss') = case BS.index s 0 of
        'M' -> countMarch (m+1) a r c h ss'
        'A' -> countMarch m (a+1) r c h ss'
        'R' -> countMarch m a (r+1) c h ss'
        'C' -> countMarch m a r (c+1) h ss'
        'H' -> countMarch m a r c (h+1) ss'
        _   -> countMarch m a r c h ss'

      march = countMarch 0 0 0 0 0 ss

      ans = sum $ fmap
            (\(i, j, k) -> (march !! i) * (march !! j) * (march !! k))
            [(x, y, z) | x <- [0..2], y <- [(x+1)..3], z <- [(y+1)..4]]

  print ans

Measured memory_bytes: 21372
# -*- 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,M=map(int,input().split())
    if N%2==1:
        left=1
        right=N-1
        for _ in range(M):
            print(left,right)
            left+=1
            right-=1
    else:
        for right in [N,N-1]:
            ans=[]
            f=True
            left=1
            for i in range(1,M+1):
                if (right-left)*2==N:
                    break
                ans.append((left,right))
                left+=1
                right-=1
                if right-left<=N//2 and f:
                    right-=1
                    f=False
            else:
                for a in ans:
                    print(*a)
                exit()
            
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 73456
L=list(map(int, input().split()))
N=L[0]
M=L[1]
A=list(map(int, input().split()))

tf=0
sum=0

for h in range(N):
    sum += A[h]

list.sort(A,reverse=True)

for i in range(M):
    if A[i]<(sum/(4*M)):
        tf = 1
        break

if tf == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
 
int main (void){
  int n,m;
  int Is_exist_s[100];
  int Is_exist_t[100];
  char s[100][11],t[100][11];
  int max;
  int i,j;
  int point;
  max=0;
  point=0;
  
  
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    Is_exist_s[i]=1;
    scanf("%s",s[i]);
  }
 
  scanf("%d",&m);
  for(i=0;i<m;i++){
    Is_exist_t[i]=1;
    scanf("%s",t[i]);
  }
  
  for(i=0;i<n;i++)for(j=0;j<m;j++){
    if(Is_exist_s[i]!=0 && Is_exist_t[j]!=0 && strcmp(s[i],t[j])==0){
      Is_exist_s[i]=0;
      Is_exist_t[j]=0;
    }
   }
  
   for(i=0;i<n;i++,point=0)for(j=0;j<n;j++){
     if(Is_exist_s[i]!=0 && Is_exist_s[j]!=0 && strcmp(s[i],s[j])==0) point++;
     if(max<point)max=point;
   }
     
     
     
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define vii vector<int,int>

using namespace std;


int main(){
    int a,b;
    string s;
    cin >> a >> b >> s;
    
    bool ans = 0;
    int ct = 0;
    int mk = 0;
    rep(i,s.size()){
        if(s[i] == '-'){
            ct++;
            mk = i;
        }
    }
    
    if(ct == 1){
        if(mk == a && s.size()-mk-1 == b) ans = true;
    }
    
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
  int i, j, n, out, hit, score;
  char stack[50][100][10];

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    out = 0;
    for (j = 0; j < 100; j++) {
      if (out == 3)
        break;
      scanf("%s", stack[i][j]);
      if (strcmp(stack[i][j], "OUT")==0)out++;
    }
  }

  for (i = 0; i < n; i++) {
    score = 0;
    hit = 0;
    for (j = 0; j < 100; j++) {
      if (strcmp(stack[i][j], "HOMERUN")==0) {
        score++;
        score += hit;
        hit = 0;
      }
      if (strcmp(stack[i][j], "HIT")==0)
        hit++;
      if (hit == 4) {
        hit = 3;
        score++;
      }
    }
    printf("%d\n", score);
  }

  return 0;
}

Measured memory_bytes: 2580
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
s = 0
sa = sum(A)
ans = float("inf")
for i in range(n-1):
    s += A[i]
    ans = min(ans, abs(s-(sa-s)))
    # print(s,sa-s)
print(ans)

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    ll x, y; cin >> x >> y;
    if(x % y == 0) cout << -1 << endl;
    else {
        cout << x * (y-1) << endl;
    }
    
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3640