akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

    int N = sc.nextInt();
    String str = sc.next();
    int max_count = 0;
    int count;
    char alphabet;

    for (int i = 0; i <= N; i++) {
      count = 0;
      alphabet = 'a';

      String str1 = str.substring(0, i);
      String str2 = str.substring(i, N);

      for (int j = 0; j <= 25; j++) {
        char tmp_alpha = alphabet++;
        if (str1.contains(String.valueOf(tmp_alpha)) && str2.contains(String.valueOf(tmp_alpha))) {
          count += 1;
        }
      }

      max_count = Math.max(max_count, count);
    }

    System.out.println(max_count);
  }
}


Measured memory_bytes: 21844
import java.lang.Long.*

inline fun str() = readLine()!!
inline fun int() = str().toInt()
inline fun long() = str().toLong()

inline fun read(d:String = " ") = str().split(d)
inline fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
inline fun list() = list {toLong()}.toLongArray()

inline fun <T> T.print() = this.also(::println)

fun main() {
	abc000X()
}

fun abc000X() {
	val n = int()
	val leaf = list()
	val notleaf = LongArray(n+1) {0L}
	val leafsum = LongArray(n+1) {0L}

	fun lim(i:Int) = if(i>=60) Long.MAX_VALUE else 1L shl i

	for(i in n downTo 0) {
		if(leaf[i]+notleaf[i]>lim(i)) {
			println(-1)
			return
		}

		if(i>0) {
			notleaf[i-1] += (leaf[i]+notleaf[i]+1)/2
			leafsum[i-1] += leafsum[i]+leaf[i]
		}
	}

	for(i in 1..n)
		notleaf[i] = min(notleaf[i-1]*2-leaf[i],leafsum[i])

	//	System.err.println(leaf.joinToString())
	//	System.err.println(notleaf.joinToString())
	//	System.err.println(sum.joinToString())
	println(leaf.sum()+notleaf.sum())
}


Measured memory_bytes: 57436
<?php
    fscanf(STDIN, "%d", $n);
    $w = [];
    for($i = 0; $i < $n; $i++){
        $w[] = trim(fgets(STDIN));
    }
$ac = 0;
$wa = 0;
$tle = 0;
$re = 0;
    for($i = 0; $i<count($w); $i++){
        switch($w[$i]){
            case 'AC';
                $ac += 1;
                break;
            case 'WA';
                $wa += 1;
                break;
            case 'TLE';
                $tle += 1;
                break;
            case 'RE';
                $re += 1;
                break;
        }
    }

    echo 'AC'.' '.'x'.' '.$ac;
	echo PHP_EOL;
    echo 'WA'.' '.'x'.' '.$wa;
	echo PHP_EOL;
    echo 'TLE'.' '.'x'.' '.$tle;
	echo PHP_EOL;
    echo 'RE'.' '.'x'.' '.$re;

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

long solve(long n, long p) {
    if (n == 1) {
        return p;
    }
    long res = 1, count = 0;
    for (long i = 2; i * i <= p; i++) {
        while (p % i == 0) {
            count++;
            p /= i;
            if (count >= n) {
                res *= i;
                count = 0;
            }
        }
        count = 0;
    }
    return res;
}

int main() {
    long n, p;
    cin >> n >> p;
    cout << solve(n, p) << endl;
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = []
l = []
r = []
u = []
d = []
for i in range(h):
  s.append(input())
  l.append([0 for j in range(w)])
  r.append([0 for j in range(w)])
  u.append([0 for j in range(w)])
  d.append([0 for j in range(w)])
  
# lみる
for x in range(w):
  for y in range(h):
    if s[y][x] == '.':
      if x == 0:
        l[y][x] = 1
      else:
        l[y][x] = l[y][x-1] + 1
 
# rみる
for x in range(w-1, -1, -1):
  for y in range(h-1, -1, -1):
    if s[y][x] == '.':
      if x == w-1:
        r[y][x] = 1
      else:
        r[y][x] = r[y][x+1] + 1
 
# uみる
for y in range(h):
  for x in range(w):
    if s[y][x] == '.':
      if y == 0:
        u[y][x] = 1
      else:
        u[y][x] = u[y-1][x] + 1
 
# dみる
for y in range(h-1, -1, -1):
  for x in range(w-1, -1, -1):
    if s[y][x] == '.':
      if y == h-1:
        d[y][x] = 1
      else:
        d[y][x] = d[y+1][x] + 1
 
 
max_all = 0
for y in range(h):
  for x in range(w):
    max_tmp = l[y][x] + r[y][x] + u[y][x] + d[y][x]
    if max_tmp > max_all:
      max_all = max_tmp
      
print(max_all - 3)

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

int main(){
  double min;
  double t,y;
  int i;

  while( cin>>min ){
    t = min/9.8;
    y = 4.9*t*t;

    i=0;
    while( y > 5*i-5 ) i++;
    cout << i << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926536;

int main(){
  long double a,b,x, theta;
  cin >> a >> b >> x;
  
  if(2*x/(a*b) < a){
    long double h = 2*x/(a*b);
    theta = 180*atan2(b,h)/pi;
  }
  else{
    long double h = 2*(b-x/pow(a,2));
    theta = 180*atan2(h, a)/pi;
  }
  cout << setprecision(10) << theta << endl;
}
    
    
    




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  map < string, int >
    wordTable;
  string  longest = "";
  string  popular = "";
  int     freqctr = 0;

  while ( true )
  {
    string __tmp;

    if ( !( cin >> __tmp ) ) break;

    if ( wordTable.count ( __tmp ) )
    {
      wordTable[ __tmp ] = wordTable[ __tmp ] + 1;
      if ( wordTable[ __tmp ] > freqctr )
      {
        freqctr = wordTable[ __tmp ];
        popular = __tmp;
      }
    }
    else
    {
      wordTable[ __tmp ] = 1;
    }

    if ( __tmp.length ( ) > longest.length ( ) )
    {
      longest = __tmp;
    }
  }

  cout << popular << " " << longest << endl;

  return ( 0 );
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = { 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 x = sc.nextInt();
		System.out.println(a[x - 1]);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
signed main(){
	string s;
	int a, b;
	cin >>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'){
			a=i;
			break;
		}
	}
	for(int i=0;i<s.size();i++){
		if(s[s.size()-i]=='Z'){
			b=s.size()-i;
			break;
		}
	}
	cout << b-a+1 << endl;
	

return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int q[N],p[N],ans[N],invq[N],invp[N],ansinv[N],s[N],b[N];
int n,k;
void la(int *a,int *b)
{
	for (int i=1;i<=n;i++) a[i]=b[a[i]];
}
void mul(int *a)
{
	for (int i=1;i<=n;i++) b[i]=a[i];
	for (int i=1;i<=n;i++) a[i]=b[a[i]];
}
void ksm(int y)
{
	if (y==0) return;
	for (int i=1;i<=n;i++) s[i]=i;
	la(s,invq); la(s,p); la(s,q); la(s,invp);
	for (;y;y>>=1,mul(s)) if (y&1) la(ans,s);	
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&p[i]);
	for (int i=1;i<=n;i++) scanf("%d",&q[i]);
	for (int i=1;i<=n;i++) invp[p[i]]=i;
	for (int i=1;i<=n;i++) invq[q[i]]=i;
    for (int i=1;i<=n;i++) ans[i]=i;	
    ksm((k-1)/6);
    if (k%6==4) la(ans,invq);
    else if (k%6==5||k%6==0) la(ans,invq),la(ans,p);
    for (int i=1;i<=n;i++) ansinv[ans[i]]=i;
    if (k%6==1) la(ans,p);
    else if (k%6==2) la(ans,q);
    else if (k%6==3) la(ans,invp),la(ans,q);
    else if (k%6==4) la(ans,invp);
    else if (k%6==5) la(ans,invq);
    else la(ans,p),la(ans,invq);
    la(ans,ansinv);
	for (int i=1;i<=n;i++) printf("%d ",ans[i]);	
}

Measured memory_bytes: 3968
#include <iostream>
#include <string>

using namespace std;

class Dice{
public:
    Dice() : top(1), south(2), east(3){}
    int get_top(){return top;}

    void to_north(){int temp = top; top = south; south = 7 - temp;}
    void to_south(){int temp = south; south = top; top = 7 - temp;}
    void to_west(){int temp = top; top = east; east = 7 - temp;}
    void to_east(){int temp = east; east = top; top = 7 - temp;}
    void turn_right(){int temp = south; south = east; east = 7 - temp;}
    void turn_left(){int temp = east; east = south; south = 7 - temp;}
private:
    int top;
    int south;
    int east;
};

int main()
{
    int loop;
    while(cin >> loop && loop != 0)
    {
        Dice dice;
        int sum = 1;
        string command;
        for(int i = 0; i < loop; ++i)
        {
            cin >> command;
            if(command == "South")
                dice.to_south();
            else if(command == "North")
                dice.to_north();
            else if(command == "East")
                dice.to_east();
            else if(command == "West")
                dice.to_west();
            else if(command == "Right")
                dice.turn_right();
            else if(command == "Left")
                dice.turn_left();
            sum += dice.get_top();
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 1212
from collections import defaultdict

parameter = list(map(int, input().split()))
n, k = parameter[0], parameter[1]

balls = list(map(int, input().split()))

numbers = defaultdict(lambda: 0)
for b in balls:
    numbers[b] += 1

k = min(k, len(numbers))

sort_number = sorted(numbers.items(), key=lambda x:x[1], reverse=True)
answer = n - sum([sort_number[i][1] for i in range(k)])
print(answer)

Measured memory_bytes: 39336
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int a,b; cin >> a >> b;
  int c[100000000][1900000000];
  c[1000][11110] = a;
  cout << max(a - 2*b, 0) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

vector<vector<int>> edge(100000);
vector<int> dp(100000, -1);

int dfs(int v){
  if(dp[v] != -1)return dp[v];
  int ret = 0;
  for(int u : edge[v]){
    chmax(ret, dfs(u));
  }
  ret++;
  dp[v] = ret;
  return ret;
}

int main(void){
  int n, m;
  cin >> n >> m;
  
  edge.resize(n);

  REP(i, m){
    int x, y;
    cin >> x >> y;
    x--; y--;
    edge[x].emplace_back(y);
  }

  int ans = 0;
  REP(i, n) chmax(ans, dfs(i));

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

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

N = N % 10

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

Measured memory_bytes: 9160
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <complex>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#define test
using namespace std;
typedef long long ll;
int main()
{
#ifdef test
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  int R;
  cin>>R;
  if (R<1200) puts("ABC");
  else if (R<2800) puts("ARC");
  else puts("AGC");
  //system("pause");
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
void SieveOfEratosthenes(ll n);
ll fastpowMOD(ll a, ll p,ll MOD);
ll lcm(ll a, ll b);
const int LIM = 1e5+5, MOD =  1e9+7;
ll mod = 998244353;
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
bool seive[LIM];
 
void SieveOfEratosthenes(ll n)
{ memset(seive, true, sizeof(seive));
seive[0] = false;
seive[1] = false;
 for (ll p=2; p*p<=n; p++) if (seive[p] == true) for (ll i=p*p; i<=n; i += p) seive[i] = false; }
 
 
 ll combo(ll n, ll k){
 	if(k==0) return 1;
 	ll N=1,D=1;
 	for(ll i = 1;i<=k;i++){
 		N = (((n-i+1)%MOD)*N)%MOD;
 		D = (D*i)%MOD;
	 }
	 
	 return (N*fastpowMOD(D,MOD-2,MOD))%MOD;
 }
 
 
ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 } 
/*********************************************/

int main(){
	fastio;
	char c;
	cin>>c;
	cout<<char((int)(c+1))<<"\n";
	 
}


















Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int num;
   char temp;
   map<string,int> mm;
   string type;
   while(cin>>num>>temp>>type)
   {
     mm[type]++;                             
   }
   cout<<mm["A"]<<endl;
   cout<<mm["B"]<<endl;
   cout<<mm["AB"]<<endl;
   cout<<mm["O"]<<endl;
   //while(1);
   return 0;
 }

 
 

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

typedef long long ll;

int main(){
    ll N;
    cin>>N;
    
    vector<ll> A(N),B(N);
    for(ll i=0;i<N;i++){
        cin>>A[i]>>B[i];
    }
    
    ll count=0;
    for(ll i=N-1;i>=0;i--){
        A[i]+=count;
        if(A[i]%B[i]!=0){
            count+=B[i]-A[i]%B[i];
        }
    }
    
    cout<<count<<endl;
    
}

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

int main(){
  int N;
  cin >> N;
  priority_queue<int,vector<int>,greater<int>> A1;
  vector<long long> A2(N),sum1(N+1),sum2(N+1);
  priority_queue<int> A3;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    A1.push(a);
    sum1[0] += a;
  } 
  for(int i=0;i<N;i++) cin >> A2[i];
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    A3.push(a);
    sum2[N] += a;
  }
  
  for(int i=1;i<=N;i++){
    sum1[i] = sum1[i-1];
    sum1[i] += A2[i-1];
    A1.push(A2[i-1]);
    sum1[i] -= A1.top();
    A1.pop();
  }
  for(int i=N-1;i>=0;i--){
    sum2[i] = sum2[i+1];
    sum2[i] += A2[i];
    A3.push(A2[i]);
    sum2[i] -= A3.top();
    A3.pop();
  }
  
  long long ans = sum1[0]-sum2[0];
  for(int i=1;i<=N;i++) ans = max(ans,sum1[i]-sum2[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3704
#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 <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;
ll gcd(ll a, ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
int main() {
	ll K;
	cin >> K;
	ll ans = 0;
	for (int a = 1; a <= K; a++) {
		for (int b = 1; b <= K; b++) {
			for (int c = 1; c <= K; c++) {
				ans += gcd(a, gcd(b, c));
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3608
def solve():
    n = int(input())
    task = [0]*n
    for i in range(n):
        a,b = map(int,input().split())
        task[i] = [a,b]
    
    task = sorted(task, key= lambda x : x[1])
    time = 0
    due = 0

    for i in range(n):
        time += task[i][0]
        due = max(due,task[i][1])
        if time > due:
            print('No')
            exit()
    
    print('Yes')
    return 0

solve()

Measured memory_bytes: 39660
#include <stdio.h>
#include <stdlib.h>

typedef struct node_s node;

struct node_s{
  int key;
  node *prev;
  node *next;
};

node *head;

void insert(int x){
  node *t=malloc(sizeof(node));
  t->key=x;
  t->next=head->next;
  t->prev=head;
  head->next->prev=t;
  head->next=t;
}
void delete(node *n){
  if (n==NULL)return;
  n->prev->next=n->next;
  n->next->prev=n->prev;
  free(n);
}

node *find(int key){
  node *p;
  for (p=head->next;p->key!=-1;p=p->next){
    if (p->key==key){
      return p;
    }
  }
  return NULL;
}

int main(){
  int i,n,x;
  char cmd[16];
  node *tp;
    
  head = malloc(sizeof(node));
  head->key=-1;
  head->prev=head;
  head->next=head;
  
  scanf("%d",&n);

  for (i=0;i<n;i++){
    scanf("%s", &cmd);
    if (cmd[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if (cmd[0]=='d'&&cmd[6]=='\0'){
      scanf("%d",&x);
      delete(find(x));
    }else if (cmd[0]=='d'&&cmd[6]=='F'){
      delete(head->next);
    }else if (cmd[0]=='d'&&cmd[6]=='L'){
      delete(head->prev);
    }
  }
  for (tp=head->next;tp->next->key!=-1;tp=tp->next)
    printf("%d " ,tp->key);
  printf("%d\n" ,tp->key);
  
  return 0;
}

Measured memory_bytes: 31788
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

const ll solve(const ll C, const vector<ll>& x, const vector<ll>& v) {
  const int N = x.size();
  vector<ll> dp(N + 1);
  ll acc = 0, pre = 0;
  for (int i = 0; i < N; i++) {
    acc += v[i] - (x[i] - pre);
    pre = x[i];
    dp[i + 1] = max(dp[i], acc);
  }
  ll res = *max_element(dp.begin(), dp.end());
  acc = 0, pre = C;
  for (int i = N - 1; i >= 0; i--) {
    acc += v[i] - (pre - x[i]);
    pre = x[i];
    res = max(res, acc - (C - x[i]) + dp[i]);
  }
  return res;
}

int main() {
  int N;
  ll C;
  while (cin >> N >> C) {
    vector<ll> x(N), v(N);
    for (int i = 0; i < N; i++) {
      cin >> x[i] >> v[i];
    }
    ll res = 0;
    res = max(res, solve(C, x, v));
    reverse(x.begin(), x.end());
    reverse(v.begin(), v.end());
    for (auto& y : x) {
      y = C - y;
    }
    res = max(res, solve(C, x, v));
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N), B(N);
    REP(i, N) cin >> A[i];
    REP(i, N-1) B[i] = A[i+1] - A[i];
    B[N-1] = A[0] + K - A[N-1];
    sort(ALL(B));
    cout << K - B[N-1] << endl;
    return 0;
}

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

int n, ans = 0, now = 0;
string s;

int main() {
  cin >> n >> s;
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] == 'I')
      ++now;
    else
      --now;
    ans = max(now, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,K,M,A[200303],B[200203]={},res=0,sum=0,cou=0,ten=1;
string S,T;

int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>K;
    
    for(long long int i = K; i <= N+1; i++){
        res+=i*N-i*(i-1)+1;
        res%=mod;
    }
    cout<<res%mod<<endl;
}    


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define ms_valtype int

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a - b;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int bound(int k, int N, int *b){
	int l = -1, h, r = N;
	while(r - l > 1){
		h = (l + r) / 2;
		if(b[h] < k){
			l = h;
		}
		else{
			r = h;
		}
	}
	return r;
}

signed main(){
	int N, i, j, ans = 0, xor, bound1, bound2, bound3;
	scanf("%lld", &N);
	int *a = (int *)malloc(sizeof(int) * N);
	int *b = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &a[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%lld", &b[i]);
	}
	for(i = 28; i >= 0; i--){
//		printf("i = %d\n", i);
		for(j = 0; j < N; j++){
			a[j] &= ((int)1 << (i + 1)) - 1;
			b[j] &= ((int)1 << (i + 1)) - 1;
		}
		sort(b, N);
/*		for(j = 0; j < N; j++){
			printf("b[%d] = %d\n", j, b[j]);
		}
*/		bound1 = 0;
		bound2 = 0;
		bound3 = 0;
		for(j = 0; j < N; j++){
			bound1 += bound(1 * ((int)1 << i) - a[j], N, b);
			bound2 += bound(2 * ((int)1 << i) - a[j], N, b);
			bound3 += bound(3 * ((int)1 << i) - a[j], N, b);
		}
//		printf("bound1 = %d\n", bound1);
//		printf("bound2 = %d\n", bound2);
//		printf("bound3 = %d\n", bound3);
		xor = (N - bound3 + bound2 - bound1) & (int)1;
//		printf("xor = %d\n", xor);
		ans |= (xor << i);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <cstdlib>
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; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100010];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5076
// https://atcoder.jp/contests/dp/tasks/
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);
    int n, r, i;
    cin >> n >> r;

    if (n >= 10) {
        i = r;
    } else {
        i = r + 100 * (10 - n);
    }

    cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops"
#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;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , a[maxN] , cnt[maxN];
void solve(){
	cin>> n ;
	for(ll i=0;i<n ;i++)cin>>a[i] , cnt[a[i]]++;
	ll mx=*max_element(a , a+n);
	 if(a[0] != 0 || cnt[0] != 1) {
        cout << 0 << endl;
        return ;
    }
	
	ll ans=1;
	for(ll i=0;i < mx; i++){
		for(ll j=1 ; j<=cnt[i+1] ; j++){
			ans = (ans * cnt[i])%MOD;
		}
	}
	cout<<ans<<endl;
}

int main(){
	mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 5284
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

using namespace std;

typedef long long ll;

int main(){

   int H, A;
    int i, TF;
    cin >> H >> A;
    i = 1;
    TF=0;
   while(1){
       TF = H - A*i;
        if(TF <= 0) break; 
        else i++;

   }

   cout << i;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

var (
	finv, inv, fac [MAX]int
)

func COM(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func init() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for 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
	}
}

const (
	MOD = 1000000007
	MAX = 510000
)

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int64) int64 {
	return a * b / GCD(a, b)
}

type Po struct {
	i       int
	cnt     int
	counter int
}

func main() {
	var A, B, C, D int64
	fmt.Scanf("%d %d %d %d\n", &A, &B, &C, &D)

	lcm := LCM(C, D)
	L := B - (B/C + B/D - B/lcm)
	R := (A - 1) - ((A-1)/C + (A-1)/D - (A-1)/lcm)
	fmt.Println(L - R)

}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 12416
#include <iostream>
#include <string>

using namespace std;

int main () {
    string S,T;
        cin >> S >> T;
        char X=T[T.length()-1];
        if (S+X==T){
            cout<<"Yes";
        }
        else
            cout<<"No";
    // enter your code here

    return 0;
}


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        boolean isPossible = false;
        for(int i = a;i <= b;i++) {
            if(i % n == 0) {
                isPossible = true;
                break;
            }
        }

        String ans = isPossible ? "OK" : "NG";
        System.out.println(ans);
    }
}

Measured memory_bytes: 35888
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

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

int main(){
  ll n; cin>>n;
  // vector<ll> a(n);
  // rep(i,n){
  //   cin>>a[i];
  // }
  
  ll a=n%10;
  string ans="hon";
  if(a==3){
    ans="bon";
  }else if(a==1 || a==0 || a==6 || a==8){
    ans="pon";
  }

  cout<<ans;

    
  
  
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    if (n == 3) {
        cout << "2 5 63" << endl;
        return 0;
    }
    if (n == 4) {
        cout << "2 5 20 63" << endl;
        return 0;
    }
    if (n == 5) {
        cout << "2 3 4 6 9" << endl;
        return 0;
    }
    if (n == 6) {
        cout << "2 3 4 6 9 12" << endl;
        return 0;
    }
    if (n == 7) {
        cout << "2 3 4 6 9 12 18" << endl;
        return 0;
    }

    vector<int> ans = {2, 3, 4, 6, 8, 9, 10, 12};
    int k = 2;
    for (; 8 * k <= n; k++) {
        rep(i, 12) {
            if (i % 2 == 0 || i % 3 == 0) {
                ans.push_back(12 * k - i);
            }
        }
    }
    if (n % 8 == 1) {
        ans.insert(ans.end(), {12 * k});
    }
    if (n % 8 == 2) {
        ans.insert(ans.end(), {12 * k - 9, 12 * k - 3});
    }
    if (n % 8 == 3) {
        ans.insert(ans.end(), {12 * k - 9, 12 * k - 3, 12 * k});
    }
    if (n % 8 == 4) {
        ans.insert(ans.end(),
                   {12 * k - 9, 12 * k - 3, 12 * k - 10, 12 * k - 2});
    }
    if (n % 8 == 5) {
        ans.insert(ans.end(),
                   {12 * k - 9, 12 * k - 3, 12 * k - 10, 12 * k - 2, 12 * k});
    }
    if (n % 8 == 6) {
        ans.insert(ans.end(), {12 * k - 9, 12 * k - 3, 12 * k - 10, 12 * k - 2,
                               12 * k - 4, 12 * k - 8});
    }
    if (n % 8 == 7) {
        ans.insert(ans.end(), {12 * k - 9, 12 * k - 3, 12 * k - 10, 12 * k - 2,
                               12 * k - 4, 12 * k - 8, 12 * k});
    }

    sort(all(ans));
    rep(i, n) cout << ans[i] << " \n"[i == n - 1];
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int a, b; cin >> a >> b;
    int d = b - a;
    int k = 0;
    while(d > 0)
    {
        k += d;
        d--;
    }
    cout << k - b << endl;
}

Measured memory_bytes: 3588
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    T=LI()
    A=LI()
    B=LI()
    
    SA=T[1]*A[1]+T[0]*A[0]
    SB=T[1]*B[1]+T[0]*B[0]
    
    if SA == SB:
        print("infinity")
    else:
        #t1+t2分後に確実にAが先行するように．
        if SB>SA:
            SB,SA=SA,SB
            A,B=B,A
        
        if A[0]>=B[0]:
            print(0)
        else:
            diff1=(B[0]-A[0])*T[0]
            diff2=SA-SB
            cnt=(diff1//diff2+1)
            ans=(cnt)*2-1
            #基本，1ループで2回，初回は0,0のため-1
            #さらに，cnt回目のループでぎり1回だけという場合があるので，その場合は1ひく
            if diff2*(cnt-1) == diff1:
                ans-=1
            print(ans)

main()


Measured memory_bytes: 38384
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

/*
 * ??\??????Prim??????????????°??????
 * ?¢???????????????????X?????????????????¢???????????????X???????????????????????¨??§????°???¨?????¨????±???????
 */

#define MAX_E 10001
#define MAX_V 100001
#define INF INT_MAX

typedef struct edge {
    int from;
    int to;
    int cost;
}edge;

// cost???????????????
struct cost_cmp {
    bool operator()(edge x, edge y) const {
        return (x.cost) > (y.cost);
    }
};

vector<edge> G[MAX_V];

//?????????i?????¢???X??????????????????????????????????????¨???????????°
bool used[MAX_V];

/*
 * start:????§??????????
 */
int Prim(int start) {
    
    int res = 0;
    edge e = {0, 0, 0};
    
    //????????????????????\??????cost???????????????????????????
    priority_queue<edge, vector<edge>,cost_cmp> que;
    
    //?????????
    que.push(e);
    
    while(!que.empty()) {
        edge p = que.top(); que.pop();
        
        //v????¬?????¢????????????????X??????????????????
        int v = p.to;
        
        /*
         * v?????¢????¢???????????????????X???????????????????????´???????????????????????????
         */
        if(used[v]) continue;
        
        //v?????????X???????????????????¢??????????????????°????????????
        used[v] = true;
        
        res += p.cost;
        
        /*
         * v?????????????????¨???????????????????????¨????????????to????¢?????????????????????§????????????
         * ??????????????\????????¨?????????????´???????
         */
        for (int i = 0; i < G[v].size(); i++) {
            int to = G[v][i].to;
            if (!used[to]) que.push(G[v][i]);
        }
    }
    return res;
}

int main( ){
    
    int i, V, E, u, v, c, ans;
    cin >> V >> E;
    edge tmp;

    for (i = 0; i < E; i++) {
        cin >> u >> v >> c;
        edge tmp;
        tmp.from = u;
        tmp.to = v;
        tmp.cost = c;
        G[u].push_back(tmp);
        
        tmp.from = v;
        tmp.to = u;
        G[v].push_back(tmp);
        
    }
    
    ans = Prim(0);
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 9044
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    int from, to; ll cost;
};
vector<edge> G(2550);
vector<int> checkgraph[3000];
bool visited[3000];

void dfs(int now){
    if (visited[now]) return;
    visited[now] = true;
    for (auto next : checkgraph[now]){
        dfs(next);
    }
}
int main(){
    ll N,M,P; cin >> N >> M >> P;
    const int s = 0, g = N-1;
    for (int i = 0; i < M; i++){
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        G.push_back((edge){a,b,P-c});
        checkgraph[a].push_back(b);
    }
    dfs(0);
    vector<ll> dist(N,1e15);
    dist[0] = 0;
    int k = N-1;
    while (k--){
        for (auto e : G){
            if (!visited[e.from]) continue;
            dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
        }
    }
    bool checknegative[2550]; fill(checknegative, checknegative + 2550, false);
    for (auto e : G){
        if (!visited[e.from]) continue;
        if (dist[e.to] > dist[e.from] + e.cost){
            dist[e.to] = dist[e.from] + e.cost;
            checknegative[e.to] = true;
        }
    }
    k = N;
    while (k--){
        for (auto e : G){
            if (!visited[e.from]) continue;
            if (checknegative[e.from]) checknegative[e.to] = true;
        }
    }
    if (checknegative[g]) cout << -1 << endl;
    else cout << max(0LL,-dist[g]) << endl;
}


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

void solve()
{
    int n;
    cin >> n;
    int h[n];
    for(int i=1;i<=n;i++)
        cin >> h[i];
    int dp[n]={0};
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n] ;
}

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

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int L,R;
  L = A+B;
  R = C+D;
  if (L==R) {
    cout << "Balanced" << endl;
  }
  else if (L<R) {
    cout << "Right" << endl;
  }
  else {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
def main():
    K = int(input())
    cnt = 1
    a = 7%K
    s = {a}
    for i in range(K):
        if a%K == 0:
            print(cnt)
            return
        a = a*10 + 7
        a = a % K
        if a in s:
            print(-1)
            return
        s.add(a)
        cnt += 1

if __name__ == "__main__":
    main()

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

typedef vector<int> vi;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(),(c).end()

int const M=1000000+10;

vi init(){
    int n=1;
    vi hs;
    hs.reserve(2<<20);
    for(int x=1;x<M;x*=2){
        for(int y=1;x*y<M;y*=3){
            for(int z=1;x*y*z<M;z*=5){
                hs.emplace_back(x*y*z);
            }
        }
    }
    return hs;
}

int main(){
    int m,n;
    vi hs=init();
    sort(all(hs));
    while(cin>>m>>n && m){
        auto x=lower_bound(all(hs),m);
        auto y=upper_bound(all(hs),n);
        cout<<y-x<<endl;
    }
}

Measured memory_bytes: 1196
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
const int P=924844033;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
    R int res=1;
    for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
    return res;
}
const int N=2005;
int n,k,res,len,f[N][3],g[N][3],s[N],t[N],fac[N];
void calc(R int x){
//	printf("%d\n",x);
	memset(f,0,sizeof(f));
	f[0][0]=1;
	R int p=0;
	for(;x<=n;x+=(k<<1)){
		fp(i,0,p){
			g[i][0]=f[i][0],g[i][1]=f[i][1],g[i][2]=f[i][2];
			f[i][0]=f[i][1]=f[i][2]=0;
		}
		fp(i,0,p){
			R int s=add(g[i][0],add(g[i][1],g[i][2]));
			upd(f[i][0],s);
//			printf("%d %d %d\n",x,x-k,x+k);
			if(x>k)upd(f[i+1][1],dec(s,g[i][2]));
			if(x+k<=n)upd(f[i+1][2],s);
		}
		++p;
	}
//	fp(i,0,p)printf("%d %d\n",i,f[i][0]+f[i][1]+f[i][2]);
	memset(t,0,sizeof(t));
	fp(i,0,len)fp(j,0,p)upd(t[i+j],mul(s[i],add(f[j][0],add(f[j][1],f[j][2]))));
	len+=p;
	fp(i,0,len)s[i]=t[i];
//	fp(i,0,len)printf("%d %d\n",i,s[i]);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d",&n,&k);
	fac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	s[0]=1;
	fp(i,1,min(k<<1,n))calc(i);
	fp(i,0,len)upd(res,i&1?dec(0,mul(fac[n-i],s[i])):mul(fac[n-i],s[i]));
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main(){
    input!{
        n:i64,
        s:chars,
    }
    let mut ans = 0;
    let mut count = 0;
    for c in &s {
        if *c == 'I'{
            count += 1;
        } else {
            count -= 1;
        }
        ans = std::cmp::max(ans, count);
    }
    println!("{}",ans);
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

int s1[1000];
int s2[1000];

signed main(){
	int a,b;
	cin>>a>>b;

	int x[a][b];
	r(i,a)r(j,b)cin>>x[i][j];

	for(int i=0;i<a;i++){
		for(int j=i;j<a;j++){
			for(int k=i;k<=j;k++){
				s1[k]++;
			}
		}
	}

	for(int i=0;i<b;i++){
		for(int j=i;j<b;j++){
			for(int k=i;k<=j;k++){
				s2[k]++;
			}
		}
	}

	int s=0;

	r(i,a){
		r(j,b){
			s+=x[i][j]*s1[i]*s2[j];
		}
	}
	cout<<s<<endl;
}


Measured memory_bytes: 5072